PayTabs SDK makes the integration with the PayTabs payment gateway very easy by providing a ready-made payment screen that handles the card entry and, billing & shipping information and completes the missing details.


This article is dedicated to walking you through how to handle the payment response after performing it. Handling the response right will prevent your application from crashing on any unhandled response status or any missing case.



It is important that you MUST validate that the response you received from our end in the below PaymentSdkTransactionDetails object is genuine by comparing it to the order/cart details stored already on your server-side in order to ensure that the original data that has been sent through the Mobile Application (client-side) has not been manipulated/intercepted.




To perform such, you will need to handle events callback as shown below:


iOS:


Implement the IPaymentCallback interface to handle the payment details & events callback.


public partial class ViewController : IPaymentCallback
{
    [Export("paymentManagerWithDidFinishTransaction:error:")]
    public void PaymentManagerWithDidFinishTransaction(PaymentTransactionDetails transactionDetails, NSError error)
    {
        if (error == null)
        {
            string result = "Transaction Details:";
            result += "\nResponseCode: " + transactionDetails.PaymentResult.ResponseCode;
            result += "\nResponseMessage: " + transactionDetails.PaymentResult.ResponseMessage;
            result += "\nTransactionReference: " + transactionDetails.TransactionReference;
            if (transactionDetails.Token != null)
            {
                result += "\nToken: " + transactionDetails.Token;
            }
            Console.WriteLine(result);
        }
        else
        {
            Console.WriteLine(error.LocalizedDescription);
        }
    }

    [Export("paymentManagerWithDidCancelPayment:")]
    public void PaymentManagerWithDidCancelPayment(NSError error)
    {
        Console.WriteLine("Cancel Event Handled");
    }

    [Export("paymentManagerWithDidStartPaymentTransaction:")]
    public void PaymentManagerWithDidStartPaymentTransaction(UIViewController rootViewController)
    {
	Console.WriteLine("Payment Proccess Started");
    }
}


If the transaction is not successful you should check for the corresponding failure code you will receive the code in transactionDetails.PaymentResult.ResponseCode .. all codes can be found in Payment Response Codes.


Android:


Implement the ICallbackPaymentInterface interface to handle the payment details & events callback.


public class MainActivity : AppCompatActivity, ICallbackPaymentInterface
{
	public void OnError(PaymentSdkError error)
	{
	    Console.WriteLine(error.Msg);
	}

	public void OnPaymentCancel()
	{
 	   Console.WriteLine("OnPaymentCancel");
	}

	public void OnPaymentFinish(PaymentSdkTransactionDetails paymentSdkTransactionDetails)
	{
	    Console.WriteLine(paymentSdkTransactionDetails);
	}
}


If the transaction is not successful you should check for the corresponding failure code you will receive the code in ResponseCode .. all codes can be found in Payment Response Codes.



PaymentSdkTransactionDetails Properties


PropertyData TypeUsage
tokenStringThe sent token for the tokenized payment requests. This field is required for creating tokenized (recurring) transactions. To know more, please check our sss solution article.
transactionReferenceStringThe unique key for the transaction generated by the PayTabs. 

This field is required for creating tokenized (recurring) transactions.
transactionTypeStringThe identification of the type of transactionTo know more about these types, please check our What is the "tran_type" (transaction type)? solution article. 
To know more about the only types that are supported in this SDK, please check our 2.3 Xamarin SDK | Enums solution article.

The default passed value is ".sale".
cartIDStringIndicates the cart/order id at the merchant end to easily relate the transaction to
cartDescriptionStringIndicates the cart/order description at the merchant end to easily relate the transaction to.
cartCurrencyStringIndicates the transaction currency, which the customer will be charged with. Noting that this currency must be configured first on your PayTabs account to accept payment with.
cartAmountStringIndicates the amount of this transaction the customer is about to be charged.
paymentResultPaymentResultViewModel ObjectresponseStatusStringIndicates the status of the performed transaction, which will be one from the list clarified in our What is: Response_code vs the Response_status? solution article.
responseCodeStringIndicates the code of the performed transaction, which will be one from the list clarified in our What is: Response_code vs the Response_status? solution article.
responseMessageStringIndicate the message/description of the performed transaction.
transactionTimeString

Indicate the exact time that transaction is completed

paymentInfoPaymentInfoViewModel ObjectcardTypeString

Indicates the card type (Credit, Debit, etc)

cardSchemeString

Indicates the card Scheme (Visa, MasterCard, etc)

paymentDescriptionString

Indicates the card mask ("4000 00## #### 0002")

billingDetails
PaymentBillingDetails ObjectnameString

Indicates the customer's/cardholder's valid name

emailStringIndicates the customer's valid email address. Preferred not to pass the same email with every transaction, as blocking any for a fraud attempt will cause blocking your payments at all.
phoneStringIndicates the customer's valid phone number
addressLineStringIndicates the customer's valid address
cityStringIndicates the customer's valid city name.
stateStringIndicates the customer's valid state name. Should be ISO 3166-1 alpha-2 code (two-letter state codes)
countryCodeStringIndicates the customer's valid state name. Should be

ISO 3166-1 alpha-2 code (two-letter state codes)

zipStringIndicates the customer's valid zip code.
shippingDetails
PaymentShippingDetails ObjectnameString

Indicates the customer's valid name

emailStringIndicates the customer's valid email address.
phoneStringIndicates the customer's valid phone number
addressLineStringIndicates the customer's valid address
cityStringIndicates the customer's valid city name.
stateStringIndicates the customer's valid state name. Should be ISO 3166-1 alpha-2 code (two-letter state codes)
countryCodeStringIndicates the customer's valid state name. Should be

ISO 3166-1 alpha-2 code (two-letter state codes)

zipStringIndicates the customer's valid zip code.


It worth mentionting, that all the responses and statuses the following checkers relies on are the official supported one listed in our What is: Response_code vs the Response_status? solution article.







⌂ To get familiar with the whole process and the other steps, kindly navigate to our "The Xamarin (Bridge) SDK Integration Manual" solution article.
    
    
 And to navigate to the previous step in the integration process "Step 4 - Accepting the payment" kindly click here.
    
    
Or you can navigate to the next step in the integration process " Step 6 - Handle the post-payment responses (notifications)" kindly click here.