We recommend this method if you are PCI certified to a minimum of SAQ A-EP. Whilst card details will not be handled by your system, the payment page is displayed from your website.


In this article you will be going to know about:


Postman Endpoint Example


For the purposes of this article, you will need to use the following postman endpoint example for testing and integrating, for proceeding with this please click here.



Payment Flow

  1. Your website will display its own card entry form, however, key fields will be managed by PayTabs gateway. You will need to include a script that replaces the sensitive card data with a payment token.
  2. When the form is submitted, the paylib.js script file first will send the card details to PayTabs server for storage and to create a temporary payment token. Then this token is inserted into the form data before it is submitted to your server. 
  3. After receiving the payment token details from your payment page, you must send a payment request using the transaction API. You will need to include the token details you have within the payment request itself.


Your server will not receive the sensitive card details, these will be removed from the form.




First Step: Taking Card Details


Let's assume that the following is your typical Payment Form


<form action="https://yourserver.com/payment" id="payform" method="post">
<span id="paymentErrors"></span>  
<div class="row">    
<label>Card Number</label>    
<input type="text" name="number" size="20">  
</div>  
<div class="row">    
<label>Expiry Date (MM/YYYY)</label>    
<input type="text" name="expmonth" size="2">    
<input type="text" name="expyear" size="4">  
</div>  
<div class="row">    
<label>Security Code</label>    
<input type="text" name="cvv" size="4">  
</div> 
<input type="submit" value="Place order"> 
</form>

To modify this typical payment form to one that uses the PayTabs managed form, there are three simple steps you will need to follow:

  1. Include the paylib.js library within the page.
  2. Change the input fields for the sensitive card data to use ‘data-paylib’ instead of ‘name’. (*)
  3. Attach the paylib.js library to the form, you will need your client key as part of this.


(*) By removing the name from fields that holding sensitive card data (card number, expiry data and security code) this will lead that they will not be submitted to your server. 

Instead they must have a ‘data-paylib’ attribute, which allows the PayTabs systems to identify and manage them.



Then modify your payment form to us the paylib.js script file


<script src="https://secure-egypt.paytabs.com/payment/js/paylib.js"></script>
<form action="https://yourserver.com/payment" id="payform" method="post">  
<span id="paymentErrors"></span>  
<div class="row">    
<label>Card Number</label>    
<input type="text" data-paylib="number" size="20">  
</div>  
<div class="row">    
<label>Expiry Date (MM/YYYY)</label>    
<input type="text" data-paylib="expmonth" size="2">    
<input type="text" data-paylib="expyear" size="4">  
</div>  
<div class="row">    
<label>Security Code</label>    
<input type="text" data-paylib="cvv" size="4">  
</div>  <input type="submit" value="Place order"> 
</form> 
<script type="text/javascript"> var myform = document.getElementById('payform'); paylib.inlineForm({  'key': '-- Your client key --',  'form': myform,  'autosubmit': true,  'callback': function(response) {    document.getElementById('paymentErrors').innerHTML = '';    if (response.error) {                   paylib.handleError(document.getElementById('paymentErrors'), response);     }  } }); 
</script>

Second Step: Making Payment

With the managed form integration, the card details are transmitted to the PayTabs servers by the paylib.js library, and a temporary payment token is obtained. This token must be included in the transaction request, and the customer details must be provided as well.


Sample Request Payload

Post{{domain}}/payment/request


{
    profile_id: "58469",
    payment_token: "D2w1QKwt7x65DMVwd2r1",
    tran_type: "sale",
    tran_class: "ecom",
    cart_id: "99",
    cart_currency: "EGP",
    cart_amount: "2154",
    cart_description: "cart_1111",
    return: "https://webhook.site/4b3af623-085f-4b82-ab22-cb6cedeba218",
    callback: "https://webhook.site/4b3af623-085f-4b82-ab22-cb6cedeba218",
    customer_details: {
        name: "Aliaa AHmed",
        email: "[email protected]",
        phone: "01000002801",
        street1: "st1 near st2",
        city: "Cairo",
        state: "Cairo",
        country: "EG",
        zip: "12345",
        ip: "196.219.200.200"
    }
}


Response for non 3DS cards

In the case that the used card is non 3DS, the payment result will be returned in the API response as shown below


{
    tran_ref: "TST2110400143417",
    tran_type: "Sale",
    cart_id: "99",
    cart_description: "Cart_1111",
    cart_currency: "EGP",
    cart_amount: "2154",
    return: "https://webhook.site/4b3af623-085f-4b82-ab22-cb6cedeba218",
    customer_details: {
        name: "Aliaa AHmed",
        email: "[email protected]",
        phone: "01000002801",
        street1: "st1 near st2",
        city: "Cairo",
        state: "Cairo",
        country: "EG",
        zip: "12345",
        ip: "196.219.200.200"
    },
    payment_result: {
        response_status: "A",
        response_code: "G92939",
        response_message: "Authorised",
        transaction_time: "2021-04-14T09:35:39Z"
    },
    payment_info: {
        card_type: "Credit",
        card_scheme: "Visa",
        payment_description: "4111 11## #### 1111"
    }
}

Response for 3DS cards

In this case, the used card is 3DS enrolled, the API response will return a redirect URL, which you must navigate the cardholder to, to complete his payment.


{
    tran_ref: "TST2110200141442",
    tran_type: "sale",
    cart_id: "99",
    cart_description: "cart_1111",
    cart_currency: "EGP",
    cart_amount: "2154.00",
    return: "https://webhook.site/4b3af623-085f-4b82-ab22-cb6cedeba218",
    redirect_url: "https://secure-egypt.paytabs.com/payment/page/3F77CB0E82E417D13E7D96213F03C86472648BCFB690FC9CB9D0FB76/redirect",
    customer_details: {
        name: "Aliaa AHmed",
        email: "[email protected]",
        phone: "01000002801",
        street1: "st1 near st2",
        city: "Cairo",
        state: "C",
        country: "EG",
        zip: "12345",
        ip: "196.219.200.200"
    },
    payment_info: {
        card_type: "Credit",
        card_scheme: "Visa",
        payment_description: "4000 00## #### 0002"
    }
}