Skip to content

New Swift SDK Seamless

AshishPayU edited this page Jan 17, 2018 · 26 revisions

Initial set up

1).Drag & drop PayU_coreSDK_Swift.framework into your project from here.

2).Go to project settings, Build phases -> link Binaries with Libraries & make sure PayU_CoreSDK_Swift.framework is added (add in another case)

3).Go to General tab -> Embedded Binaries & add PayU_CoreSDK_Swift.Framework

Calling APIs for invoking SDK

 import PayU_coreSDK_Swift 

Now, set paymentParams as below :

let paymentParams = PayUModelPaymentParams() 
paymentParams.key = "gtKFFx" 
paymentParams.txnId = “abcdef20171009” 
paymentParams.amount = "10" 
paymentParams.productInfo = "iPhone" 
paymentParams.firstName = "Ashish" 
paymentParams.email = "[email protected]" 
paymentParams.environment = ENVIRONMENT_TEST 
paymentParams.surl = “your success URL here“ 
paymentParams.furl = “your failure URL here“ 

// optional params for payment

paymentParams.udf1 = "u1" 
paymentParams.udf2 = "u2" 
paymentParams.udf3 = "u3" 
paymentParams.udf4 = "u4" 
paymentParams.udf5 = "u5" 

pass offer key if some offer is enabled for your account

paymentParams.offerKey = "yourOfferKey" 

if you want to save some card for specific user, then

paymentParams.userCredentials = “gtKFFx:[email protected]" 

Note: Hash Generation : For every transaction request you make to PayU server requires a hash generated from your own server, refer this link from here.

to call fetchPayUPaymentOptions API, set below hash

self.paymentParams.hashes.paymentRelatedDetailsHash =“b4acc0c8ffeeaa9df5864c30b4830560a9eb3ee59e2e4963960ab7ac144d46c4e8cb25f3e5cc1e746f803fd7d6f93b053368bbeb9e6b152edef8c5cbf35595e4” 

to delete saved card, set below hash

self.paymentParams.hashes.deleteUserCardHash = “eb27383c17a57ce730261a351bd044fef763687b1fdb07626e363f147105adb664442467a30443f4518bcd51dbc687b6363a92a2e6f23ee6d5acdf8a0229f918” 

set below hash if you have some offer

self.paymentParams.hashes.offerHash  = “85eba4048b0c10e403338a29a13733db259f6d31f4cadc141c6282f7a1a2da3b9e60c260a3eeba60d937ad7a4276ee73836bf5fb02912f999e8b24d358023acd” 

For calling getVASStatus API set below hash,

self.paymentParams.hashes.VASForMobileSDKHash = “a9153e030149651114be4aa1228bef557ebd9d48ff862c39851dce31acea14b351114911a5ab6d0cc972961b0a4946e6aa4b2842465ee3f65f0b249d0f6d0ad9” 

for making a payment, set payment hash

self.paymentParams.hashes.paymentHash = “e2490bb3228d84ced094d2266e65d6df75eba9b86f22d49f09e4fbdf8accf8241969fd140cba68d0960bb0fc205f1fbb18a825c020005c781c81adcae6fbcaee” 

A).fetchPayUPaymentOptions API : This API gives you all the available payment options for your account while you signed up with PayU : so, to call this API, just make an object for it & in closure block, you will get available details in array for your account:

let webService = PayUWebService() 
webService.fetchPayUPaymentOptions(paymentParamsToFetchPaymentOptions: self.paymentParams) { (array, error) in


if (error == "")
{
print(array.availablePaymentOptions)
}
else
{
print (error)
} 
} 

Below are the data you will get while calling this API,

a) array. availablePaymentOptions ( your available payment types )
b) array.availableNetBanking
c) array.availableSavedCards
and so on…

Forced payment options : It gives you all those options which you can opt later on or if you wish to make your own UIs for every checkout separately :

array.forcedPaymentOptions

B).getVASStatus API

This API gives the status in case if some bank is down, e.g.

webService.callVAS(paymentParamsforVas: self.paymentParams)

webService.getVASStatus(bankCodeOrCardBin: AXIB) { (status, error) in 
// if error is nil, the status will give you message if some bank is down 
if (error == "")
{
// status will have the info about whether a card is down or not
print(status)
}
else
{
print (error)
} 

}  

C).getOfferStatus API: This offer gives you the status of what offer is available for your offer key, you need to pass offer key in post params for this

paymentParams.offerKey = “myOffer123” 

webService.getOfferStatus(paymentParamsForOfferAPI: paymentParams) {  
(offerStatus, error) in 

// offerStatus gives you what offer is available against any bank 
if (error == "")
{
// offer status will have the info about your particular offer running
print(offerStatus)
}
else
{
print (error)
} 
}

D).deleteSavedCard API:

Call this API to delete the saved cards

webService.deleteSavedCard(paymentParamsForDeletingSavedCard: paymentParams) { (status, error) in
if (error == "")
{
// the status tells you about a particular card being deleted
print(status)
}
else
{
print (error)
}  
   
} 

E).getCardDetails API:

Call this API to get card Details // Pass some card bin to payment params

params.cardBin = "512345"
webService.getCardTypeDetails(cardBin: params) { (cardDetails, error) in

if (error == "")
{
// the cardDetails tells you about a particular card details in Dictionary format
print(cardDetails)
}
else
{
print (error)
}  
   
} 

Making payment through SDK:

// Create an object of PayUCreateRequest() class & then call method below:

let createRequest = PayUCreateRequest() 

1).Pay through Credit/Debit Card:

// set required params for paying through card

paymentParams.cardNumber = “5123456789012346” 
paymentParams.CVV = “123” 
params.expiryMonth = “05” 
paymentParams.expiryYear = “2020” 

// if you want to save a card then pass below 

paymentParams.storeCardName = “SaveThisCard”         

createRequest.createRequest(withPaymentParam: paymentParams, forPaymentType: PAYMENT_PG_CCDC) { (request,     error) in 

// if error is empty then all set to go forward 
// open the request on web view for any bank  
if (error == "")
{
    
    let strBrd = UIStoryboard(name: "Main", bundle: nil)
    let webViewVC = strBrd.instantiateViewController(withIdentifier: "yourWebViewController") as! yourWebViewController
    
    // req here is property created in yourWebViewController
    webViewVC.req = request
    self.navigationController?.pushViewController(webViewVC, animated: true)
    
  }
 else
  {
    print(error)
  }
} 

2).Pay through NetBanking:

// set required bank code for paying through netBanking

paymentParams.bankCode = “AXIB” 

createRequest.createRequest(withPaymentParam: self.paymentParams, forPaymentType: PAYMENT_PG_NET_BANKING) {     (request, error) in 

// if error is empty then all set to go forward 
// open the request on web view for any bank 

} 

3).Pay through Saved Cards & one tap card:

// to pay through saved card just set cardToken

paymentParams.cardToken = “523456fghewertqweree3456” 

// to pay through one Tap Card, set your dictionary with cardToken & Merchant Hash as below

paymentParams.OneTapTokenDictionary = “yourDictionary” 
webRequest.createRequest(withPaymentParam: paymentParams, forPaymentType: PAYMENT_PG_STOREDCARD) { (request,     error) in 

// if error is empty then all set to go forward 
// open the request on web view for any bank 
} 

4).Pay through Cash Cards:

// set required bank code for paying through netBanking

paymentParams.bankCode = “OXICASH” 

createRequest.createRequest(withPaymentParam: paymentParams, forPaymentType: PAYMENT_PG_CASHCARD) { (request,     error) in 

// if error is empty then all set to go forward 
// open the request on web view for any bank 

} 

5).Pay through EMI

// set required params for paying through EMI

paymentParams.cardNumber = “5123456789012346” 
paymentParams.CVV = “123” 
params.expiryMonth = “05” 
paymentParams.expiryYear = “2020” 

// set required bank code

paymentParams.bankCode = “EMIIC12” 
createRequest.createRequest(withPaymentParam: self.paymentParams, forPaymentType: PAYMENT_PG_EMI) { (request,     error) in 

// if error is empty then all set to go forward 
// open the request on web view for any bank 

} 

6).Pay through PayU money :

createRequest.createRequest(withPaymentParam: paymentParams, forPaymentType: PAYMENT_PG_PAYU_MONEY) {         (request, error) in 

// if error is empty then all set to go forward 
// open the request on web view for any bank 

} 

7).Pay through Sodexo :

createRequest.createRequest(withPaymentParam: paymentParams, forPaymentType: PAYMENT_PG_SODEXO) {         (request, error) in 

// if error is empty then all set to go forward 
// open the request on web view for any bank 

} 

8).Pay through UPI : // pass VPA to payment params to pay through UPI paymentParam.vpa = "yourVPA@someBank" createRequest.createRequest(withPaymentParam: paymentParams, forPaymentType: PAYMENT_PG_UPI) { (request, error) in

// if error is empty then all set to go forward 
// open the request on web view for any bank 

}