Web Services for iOS Core SDK

This section provides a reference for the following Web Service APIs for Code iOS Core:

  1. Fetch Payment Option
  2. VAS
  3. Get All Offer Details
  4. Validate Offer Details
  5. Get EMI According to Interest
  6. Verify Payment
  7. Check is Domestic
  8. Get Transaction Info
  9. Get Bin Info
  10. Get Checkout Details
  11. Lookup API
  12. Tokenization

Initialise Web Service

Create an object of the PayUWebServiceResponse class and call the respective methods. You will get the result in the completion handler of the method.

 let webServiceResponse = PayUWebServiceResponse()
PayUWebServiceResponse *webServiceResponse = [PayUWebServiceResponse new];

Note: If there is an error in the parameters passed by the merchant, it will give the errorMessage string. Else, you will get the parsed object.


Fetch payment option

This API will give a payment option enabled for merchants and saved cards. Integrate this API by calling the getPayUPaymentRelatedDetailForMobileSDK

hash will be in the format of Sha512(Key|Command|Var1|Salt)

Command Name - payment_related_details_for_mobile_sdk

Var1 - userCredentials (userCredentials might be blank)

For this API, you need to set hash in the payment params similar to the following code block

self.paymentParamForPassing.hashes.paymentRelatedDetailsHash = "hash"

method:

  webServiceResponse?.getPayUPaymentRelatedDetail(forMobileSDK: paymentParamForPassing) { [weak self] (paymentRelatedDetails, errorMessage, extraParam) in

            completion(paymentRelatedDetails,errorMessage,extraParam)

             if (errorMessage) {

                // Something went wrong errorMessage is having the Detail

            }else{

                // It is good to go & paymentRelatedDetails is having the full detail of it

            }}
[webServiceResponse getPayUPaymentRelatedDetailForMobileSDK:self.paymentParamForPassing withCompletionBlock:^(PayUModelPaymentRelatedDetail *paymentRelatedDetails, NSString *errorMessage, id extraParam) {
​
if (errorMessage) {
    // Something went wrong errorMessage is having the Detail
}else{
    // It is good to go & paymentRelatedDetails is having the full detail of it
}
}];

Note:

  1. paymentRelatedDetails.availablePaymentOptionsArray gives you all the available payment options for you.
  2. paymentRelatedDetails.oneTapStoredCardArray>, paymentRelatedDetails.storedCardArray, paymentRelatedDetails.netBankingArray, paymentRelatedDetails.cashCardArray, paymentRelatedDetails.EMIArray, paymentRelatedDetails.NoCostEMIArray gives available OneTapCard,StoredCard, NetBanking, CashCard, EMI and NoCostEMI

VAS integration

This API is used to get the list of down Net Banking and down card BIN. Integrate this API by calling the callVASForMobileSDKWithPaymentParam

hash will be in the format of Sha512(Key|Command|Var1|Salt)

Command Name - vas_for_mobile_sdk

Var1 - default

For this API, you need to set hash in the payment params similar to the following code block

self.paymentParamForPassing.hashes.vasForMobileSDKHash = "hash"

method:

webServiceResponse?.callVASForMobileSDK(withPaymentParam: paymentParamForPassing, withCompletionBlock: { result, error, json in

            completion(result,error,json)

       if (errorMessage) {
                  // Something went wrong errorMessage is having the Detail
            } else {
                 // It is good to go & paymentRelatedDetails is having the full detail of it
            }
        })
[webServiceResponse getPayUPaymentRelatedDetailForMobileSDK:self.paymentParamForPassing withCompletionBlock:^(PayUModelPaymentRelatedDetail *paymentRelatedDetails, NSString *errorMessage, id extraParam) {
​
if (errorMessage) {
    // Something went wrong errorMessage is having the Detail
}else{
    // It is good to go & paymentRelatedDetails is having the full detail of it
}
}];

Note: You can check if a particular NetBanking service is down or not by just passing the bankCode or card-bin (first 6 digits of card number) and in completionBlock, the response will be fetched, for instance.

[webServiceResponse getVASStatusForCardBinOrBankCode:@"AXIB" withCompletionBlock:^(id ResponseMessage, NSString *errorMessage, id extraParam) {
    	if (errorMessage == nil) {
        		if (ResponseMessage == nil) {
			        // It means given NetBanking code or cardnumber is not down i.e. it is in good to go condition
        		}else{
            		NSString * responseMessage = [NSString new];
            		responseMessage = (NSString *) ResponseMessage;
			        // It means given NetBanking code or cardnumber is down and you can display the responseMessage if you want or you can customize it
        		}
    	}else{
		    // Something went wrong errorMessage is having the Detail
    	}
	}];

Offer API

Fetch Offer Details

Use this API to fetch all the offer list available for the merchant.

Hash Generation Logic

in completionBlockForHashGeneration you will get hash string without salt so you need to append the salt at the end of this hash string and convert using sha512 and pass that value in hash completion as passing below in the code.

For this API, you need to set amount and userToken inside your payment parameters for instance

        paymentParamForPassing.amount = "amount"
        paymentParamForPassing.offerParams = PayUModelOfferParams()
        paymentParamForPassing.offerParams?.userToken = "Any default Value"

Call the getAllOfferDetails() method to integrate this API as described in the following code block

 webServiceResponse?.getAllOfferDetails(paymentParamForPassing, completionBlockForHashGeneration: { json, hashcompletion in
                if let hashDict = json as? [String: String] {
                let hashName = hashDict["hashName"] ?? ""
                let hashStringWithoutSalt = hashDict["hashString"] ?? ""
                    let hashWithSalt = hashStringWithoutSalt.appending(kSalt)
                    let hash = hashWithSalt.sha512()
                    hashcompletion!([hashName : hash])
                }
            },
            completionBlockForAPIResponse: { [weak self] offerDetails, errorMsg, _ in
                print("offerDetails......\(offerDetails)")
            })

Validate Offer Details

Use this API to validate the offer available for the merchant.

Hash Generation Logic

in completionBlockForHashGeneration you will get hash string without salt so you need to append the salt at the end of this hash string and convert using sha512 and pass that value in hash completion as passing below in the code.

For this API, you need to set amount and userToken inside your payment parameters for instance

        paymentParamForPassing.amount = "amount"
        paymentParamForPassing.cardNumber = "Card Number"
        paymentParamForPassing.offerParams = PayUModelOfferParams()
        paymentParamForPassing.offerParams?.userToken = "Any default Value"
        paymentParamForPassing.offerParams?.offerKeys = ["Offer Key"]
        paymentParamForPassing.offerParams?.paymentCode = "CC/DC/NB"
        paymentParamForPassing.category = "CREDITCARD"

Call the validateOfferDetails() method to integrate this API as described in the following code block

webServiceResponse?.validateOfferDetails(paymentParamForPassing, completionBlockForHashGeneration: { json, hashcompletion in
            if let hashDict = json as? [String: String] {
            let hashName = hashDict["hashName"] ?? ""
            let hashStringWithoutSalt = hashDict["hashString"] ?? ""
            let hashWithSalt = hashStringWithoutSalt.appending(kSalt)
            let hash = hashWithSalt.sha512()
            hashcompletion!([hashName : hash])
            }
        }, completionBlockForAPIResponse: { [weak self] offerDetails, errorMsg, json in
            print("offerDetails......\(offerDetails)")
        })

Get EMI amount according to interest

This API helps you get details of all the available EMIs. Set the amount in the payment parameter for this API as described in the following code block.

[webServiceResponse getOfferStatus:self.paymentParamForPassing withCompletionBlock:^(PayUModelOfferStatus *offerStatus, NSString *errorMessage, id extraParam) {
    if (errorMessage == nil) {
        //It is good to go & offerStatus.discount contains the discounted amount if there is any offer & offerStatus.msg contains the message why offer is not available
    }
    else{
        // Something went wrong errorMessage is having the Detail
    }
}];

Call the getEMIAmountAccordingToInterest method to integrate this API as described in the following code block:

[webServiceResponse
getEMIAmountAccordingToInterest:self.paymentParamForPassing withCompletionBlock:^(NSDictionary *dictEMIDetails, NSString *errorMessage, id extraParam) {
      if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
      }
      else{
        // dictEMIDetails is having the EMI detail
      }
    }];

Verify payment

This web service is used to reconcile the transaction with PayU. When PayU posts back the final response to you (merchant), PayU provides a list of parameters (including the status of the transaction). For example, success, failure, etc. On a few occasions, the transaction response is initiated from our end, but it does not reach you due to network issues or user activity (like refreshing the browser, etc.).

📘

Note:

PayU strongly recommends that this API is used to reconcile with PayU’s database once you receive the response. This will protect you from any tampering by the user and help in ensuring safe and secure transaction experience.

hash will be in the format of Sha512(Key|Command|Var1|Salt)

Command Name - verify_payment

Var1 - txnId

For this API, you need to set transactionID inside your payment parameters for instance:

self.paymentParamForPassing.transactionID = "tnxID";
self.paymentParamForPassing.hashes.verifyTransactionHash = "hash";
self.paymentParamForPassing.transactionID = @"tnxID1|txnID2|txnID3";
self.paymentParamForPassing.hashes.verifyTransactionHash = @"hash";

Note: You can send multiple txnIDs (transaction IDs) using the pipe symbol(|) as a separator.

Call the verifyPayment() method to integrate this API as described in the following code block:

webServiceResponse?.verifyPayment(paymentParamForPassing, withCompletionBlock: { result, error, json in
            completion(result,error,json)
          if (error){

                // Something went wrong errorMessage is having the Detail

            }else{

                // It is good to go & paymentRelatedDetails is having the full detail of it

            }
        })
[webServiceResponse
verifyPayment:self.paymentParamForPassing withCompletionBlock:^(NSDictionary *dictVerifyPayment, NSString *errorMessage, id extraParam) {
      if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
      }
      else{
        // dictVerifyPayment is having the verifyPayment detail
      }
    }];

Check Is Domestic for iOS

The checkIsDomestic API is used to get the following using the BIN number, that is, the first six digits of a credit card or debit card:

  • BIN information
  • Detect whether a particular BIN number is international or domestic.
  • Determine the card’s issuing bank, the card type brand, that is, Visa, Master, etc.,
  • Determine the card category, that is, credit, debit, etc.

hash will be in the format of Sha512(Key|Command|Var1|Salt)

Command Name - check_isDomestic

Var1 - Card Number(Like. "5123456789012346")

For this API, you need to set cardNumber in the payment params similar to the following code block:

self.paymentParamForPassing.cardNumber = "5123456789012346";
self.paymentParamForPassing.hashes.checkIsDomesticHash = "hash";
self.paymentParamForPassing.cardNumber = @"5123456789012346";
self.paymentParamForPassing.hashes.checkIsDomesticHash = @"hash";

Call the checkIsDomestic method to integrate this API as described in the following code block:

   webServiceResponse?.checkIsDomestic(paymentParamForPassing, withCompletionBlock: { result, error, json in 
          completion(result, error, json)
            
     if (error){

                // Something went wrong errorMessage is having the Detail

            }else{

                // It is good to go & paymentRelatedDetails is having the full detail of it

            }
        })
[webServiceResponse
verifyPayment:self.paymentParamForPassing withCompletionBlock:^(NSDictionary *dictVerifyPayment, NSString *errorMessage, id extraParam) {
      if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
      }
      else{
        // dictVerifyPayment is having the verifyPayment detail
      }
    }];

Get transaction info

This API is used to extract the transaction details between two given time periods. The API takes the input as two dates and the time (initial and final) between which the transaction details are needed. The output would consist of the status of the API (success or failed) and all the transaction details in an array format. Set startTime and endTime in the payment params as described in the following code block:

self.paymentParamForPassing.startTime = @"2014-01-12 16:00:00";
self.paymentParamForPassing.endTime = @"2014-01-12 16:00:50";
self.paymentParamForPassing.hashes.getTransactionInfoHash = @"hash";

Call the getTransactionInfo method to integrate with this API as described in the following code block:

[webServiceResponse
getTransactionInfo:self.paymentParamForPassing withCompletionBlock:^(NSArray *arrOfGetTxnInfo, NSString *errorMessage, id extraParam) {
      if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
      }
      else{
        // arrOfGetTxnInfo is the array of PayUModelGetTxnInfo which is having detail of transaction
      }
    }];

GetBinInfo API – iOS

The GetBinInfo API is used to detect whether a particular BIN number is international or domestic. In addition, it is useful to determine the card’s issuing bank, the card type brand, that is, Visa, Mastercard, etc., and the card category, that is, credit card, debit card, etc. The BIN number is the first six digits of a credit or debit card. This API is also helpful in knowing whether the card BIN is eligible for Standing Instructions. For this API, you need to set the card number in the payment parameters.

hash will be in the format of Sha512(Key|Command|Var1|Salt)

Command Name - getBinInfo

Var1 - 1

Var5 - 1 //if you want to check card is SI Supported then pass the isSIInfo as true.

This API is used to get the card BIN details. For this API, you need to set the following parameter in the payment params similar to the following code block:

self.paymentParamForPassing.cardNumber = "5123456789012346"
self.paymentParamForPassing.isSIInfo = true
self.paymentParamForPassing.hashes.getBinInfoHash = "hash"
self.paymentParamForPassing.cardNumber = @"5123456789012346";
self.paymentParamForPassing.isSIInfo = @"true";
self.paymentParamForPassing.hashes.getBinInfoHash = @"hash";

Call the GetBINInfo method to integrate with this API as described in the following code block:

 webServiceResponse?.getBinInfo(paymentParamForPassing, withCompletionBlock: { result, error, json in
            completion(result, error, json)
          
     if (error){

                // Something went wrong errorMessage is having the Detail

            }else{

                // It is good to go & paymentRelatedDetails is having the full detail of it

            }

        })
[webServiceResponse
getTransactionInfo:self.paymentParamForPassing withCompletionBlock:^(NSArray *arrOfGetTxnInfo, NSString *errorMessage, id extraParam) {
      if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
      }
      else{
        // arrOfGetTxnInfo is the array of PayUModelGetTxnInfo which is having detail of transaction
      }
    }];

GetCheckoutDetails API

It provides information on additionalCharges, bankDownStatus, taxSpecification, offerDetails, customerEligibility, merchantDetails, extendedPaymentDetails, and pg id information for payment options on a merchant key. Calling this API is similar to other Web Services, the only difference is that it requires a JSON in var1. Check the following code block for more details:

{
        "useCase":{
            "getExtendedPaymentDetails":true,
            "getTaxSpecification":true,
            "checkDownStatus":true,
            "getAdditionalCharges":true,
            "getOfferDetails":true,
            "getPgIdForEachOption":true,
            "checkCustomerEligibility":true,
            "getMerchantDetails":true,
            "getPaymentDetailsWithExtraFields":true
        },
        "filters":{
            "paymentOptions":{
                "emi":{
                    "dc":"HDFC",
                    "cardless":"ZESTMON"
                },
                "bnpl":"MOBIZIP"
            }
        },
        "requestId":"iOS230113135103",
        "customerDetails":{
            "mobile":"9876543210"
        },
        "transactionDetails":{
            "amount":"1"
        }
    }

Here, requestId is a unique random number passed in the request.

For this API, you need to set amount, additionalCharges, checkDownStatus, checkTaxSpecification, checkOfferDetails, checkCustomerEligibility, getMerchantDetails, getExtendedPaymentDetails and getPgIdForEachOption in the payment parameters, for instance:

self.paymentParamForPassing.getExtendedPaymentDetails = true; 
self.paymentParamForPassing.checkTaxSpecification = true;      
self.paymentParamForPassing.checkDownStatus = true;   self.paymentParamForPassing.checkAdditionalCharges = true;      
self.paymentParamForPassing.checkOfferDetails = true;   self.paymentParamForPassing.getPgIdForEachOption = true;     self.paymentParamForPassing.checkCustomerEligibility = true;   
self.paymentParamForPassing.getMerchantDetails = true;          self.paymentParamForPassing.getPaymentDetailsWithExtraFields = true;     
self.paymentParamForPassing.amount = @"<Amount>";   self.paymentParamForPassing.hashes.getCheckoutDetailsHash = @"hash";         PayUModelGetCheckoutAPIFilters *getCheckoutAPIFilters = [PayUModelGetCheckoutAPIFilters new];         getCheckoutAPIFilters.dcEMIBankCode = @"<BankCode>";         getCheckoutAPIFilters.cardlessEMIBankCode = @"<BankCode>";         getCheckoutAPIFilters.bnplBankCode = @"<BankCode>";        self.paymentParamForPassing.getCheckoutAPIFilters = getCheckoutAPIFilters;

To integrate this API, call the getCheckoutDetail for instance:

[webServiceResponse
getCheckoutDetail:self.paymentParamForPassing withCompletionBlock:^(NSArray *paymentRelatedDetails, NSString *errorMessage, id extraParam) {
      if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
      }
      else{
        // paymentRelatedDetails object is having the required detail
      }
    }];

Lookup API

This API is used when integrating multi-currency payments. To use Lookup API for iOs, follow these subsections:

  • Prerequisites
  • Post Parameters
  • Calculate the Signature for Hash

📘

Before you begin

Connect with your Key Account Manager at PayU to get the following credentials:

  • Merchant Access Key
  • Merchant Secret Key

Lookup API needs a JSON request. Product types need to be passed either as DCC or MCP. Direct Currency Conversion (DCC) returns the conversion prices for card currency only. To get all enabled currencies on Merchant Access Key along with their conversion prices, use product type as MCP. For DCC, cardBin is mandatory, while for MCP cardBin is not required

The following example is to request for MCP as a product type:

{   
  "merchantAccessKey":"E5ABOXOWAAZNXB6JEF5Z", 
  "baseAmount":
  {     
    "value":10000.00,      
     "currency":"INR"   
   },   
    "merchantOrderId":"OBE-JU89-13151-110",   
    "productType":"MCP",   
    "signature":"be5a56667354d9e2ea5ea1c6af78b0afc1894eb2"
  }

For this API you need to set the amount, lookupAPIHash, and lookuprequestId parameters in the payment parameters for instance.

self.paymentParamForPassing.amount = @"Total amount";
self.paymentParamForPassing.hashes.lookupApiHash = @"HMACSHA1 Signature";
self.paymentParamForPassing.lookupRequestId = @"Any unique id";

Request parameters

The details of the parameters used in Lookup API are:

ParameterDescription
AmountTransaction Amount
Card BinFirst 6 digits of the card number
CurrencyBase Currency of Transaction (“INR”)
Merchant Access KeyMerchant Access Key provided by PayU
Merchant OrderIdA unique request id for the Lookup API request
Product TypeUse MCP to get all enabled currency on Merchant Access Key or DCC to get direct currency conversion for card currency
SignatureHmac SHA1 hash created with formula explained below

Calculate the signature for hash

Use the following data to calculate the signature for creating the HmacSHA1 hash.

  • Signature =HMAC-SHA1(data, key);
  • Data = baseCurrency+merchantOrderId+baseAmount
  • Key = Secret Key shared with the merchant at the time of onboarding
  • Example: INROBE-JU89-13151-11010000.00

To integrate this API, call the mcpLookup method for instance:

[webServiceResponse
mcpLookup:self.paymentParamForPassing withCompletionBlock:^(PayUModelMultiCurrencyPayment *paymentRelatedDetails, NSString *errorMessage, id extraParam) {
      if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
      }
      else{
        // PayUModelMultiCurrencyPayment object is having the required detail
      }
}];

Check Sodexo card balance

This can be used to fetch detail of the Sodexo card with the source ID:

self.paymentParamForPassing.sodexoSourceId = @"<Sodexo source id>;
self.paymentParamForPassing.hashes.checkBalanceApiHash =  @"hash";

To integrate this API call the fetchSodexoCardDetails method similar to the following code block:

[webServiceResponse
fetchSodexoCardDetails.paymentParamForPassing withCompletionBlock:^(PayUModelSodexoCardDetail *sodexoCardDetail, NSString *errorMessage, id extraParam) {
      if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
      }
      else{
        // sodexoCardDetail object is having the required detail
      }
    }];

Tokenized payment

You can store and get stored card details from the vault.

Get tokenized payment details

Get details of the stored card to make payment on another PG.

self.paymentParam.userCredentials = @"<user_credentials>";  
self.paymentParam.cardToken = @"<cardToken>";    
self.paymentParam.amount = @"100";  
self.paymentParam.currency = @"INR";
self.paymentParamForPassing.hashes.getTokenizedPaymentDetailHash = @"hash";

To integrate this API call the getTokenizedPaymentDetails method similar to the following:

[webServiceResponse getTokenizedPaymentDetails.paymentParamForPassing withCompletionBlock:^(PayUModelTokenizedPaymentDetails *tokenizedPaymentdetails,NSString *errorMessage, id extraParam) {
            if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
            }
            else{
        //It is good to go & deleteStoredCardMessage is having the full detail of it
            }
        }];

Get tokenised stored cards

This API is helpful in getting all the stored cards for a particular user. For this API, you need to set theuserCredentials in the payment params similar to the following:

self.paymentParam.userCredentials = @"<user_credentials>";  
self.paymentParamForPassing.hashes.getTokenizeddStoredCardHash = @"hash";

To integrate this API call the getTokenizedStoredCards method similar to the following:

[webServiceResponse getTokenizedStoredCards:self.paymentParamForPassing withCompletionBlock:^(NSDictionary *dictStoredCard,NSString *errorMessage, id extraParam) {
            if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
            }
            else{
        //It is good to go & deleteStoredCardMessage is having the full detail of it
            }
        }];

Delete tokenised stored cards

This API is helpful in deleting stored cards.

self.paymentParam.userCredentials = @"<user_credentials>";  
self.paymentParam.cardToken = @"<cardToken>";    
self.paymentParam.networkToken = @"<networkToken>";  
self.paymentParam.issuerToken = @"<issuerToken>";
self.paymentParamForPassing.hashes.deleteTokenizedStoredCardHash = @"hash";

To integrate this API call the deleteTokenizedStoredCard method similar to the following:

[webServiceResponse deleteTokenizedStoredCard:self.paymentParamForPassing withCompletionBlock:^(NSString *deleteStoredCardStatus, NSString *deleteStoredCardMessage, NSString *errorMessage, id extraParam) {
            if (errorMessage) {
        // Something went wrong errorMessage is having the Detail
            }
            else{
        //It is good to go & deleteStoredCardMessage is having the full detail of it
            }
        }];