Skip to content

iOS SDK integration

umangarya336 edited this page Feb 14, 2020 · 6 revisions

iOS - Seamless SDK: Using your UI

NOTE : To download iOS SDK through cocoa pod,please go here first.

NOTE : To run our Sample app do the following:

  • Download latest SDK version and unzip it
  • Now unzip Release-Universal,now drag and drop the content of unzipped file into Sample App

1. Initial Setup

  • To integrate with iOS SDK, download the latest SDK from Github using link : https://github.com/payu-intrepos/iOS-SDK/releases

  • Drag and drop the extracted content (two items - a folder and a static lib) into your project

  • To import our SDK just import PayU_iOS_CoreSDK.h file as below

      #import "PayU_iOS_CoreSDK.h"
    
  • Get all the required parameters

  • Create an object of PayUModelPaymentParams and set all the parameter in it

      @property (strong, nonatomic) PayUModelPaymentParams *paymentParamForPassing;
      self.paymentParamForPassing = [PayUModelPaymentParams new];
      self.paymentParamForPassing.key = @"0MQaQP";
      self.paymentParamForPassing.transactionID = @"Ywism0Q9XC88qvy";
      self.paymentParamForPassing.amount = @"10.0";
      self.paymentParamForPassing.productInfo = @"Nokia";
      self.paymentParamForPassing.firstName = @"Ram";
      self.paymentParamForPassing.email = @"email@testsdk1.com";
      self.paymentParamForPassing.userCredentials = @"ra:ra";
      self.paymentParamForPassing.phoneNumber = @"1111111111";
      self.paymentParamForPassing.SURL = @"https://payu.herokuapp.com/ios_success";
      self.paymentParamForPassing.FURL = @"https://payu.herokuapp.com/ios_failure";
      self.paymentParamForPassing.udf1 = @"u1";
      self.paymentParamForPassing.udf2 = @"u2";
      self.paymentParamForPassing.udf3 = @"u3";
      self.paymentParamForPassing.udf4 = @"u4";
      self.paymentParamForPassing.udf5 = @"u5";
      self.paymentParamForPassing.environment= ENVIRONMENT_PRODUCTION;
      self.paymentParamForPassing.offerKey = @"offertest@1411";
    
  • You don't need to set udf1-5 in case you are not using them email and firstname can be empty strings "" if you don't want to use them For store user card feature you need to set userCredentials

      self.paymentParamForPassing.userCredentials = @"ra:ra"
    
  • For offers you need to set offerKey

      self.paymentParamForPassing.offerKey = @"offertest@1411"
    
  • For any other payment default param (like phone and others)

      self.paymentParamForPassing.phoneNumber = @"1111111111";
    
  • Get the required hashes by using your own server. Set the hashes as below

      self.paymentParamForPassing.hashes.paymentHash = @"ade84bf6dd9da35d0aab50a5bf61d6272ab0fc488b361b65c66745054aacf1900e3c60b5022d2114bae7360174ebcb3cd7185a5d472e5c99701e5e7e1eccec34";
      self.paymentParamForPassing.hashes.paymentRelatedDetailsHash = @"915299224c80eff0eb2407b945a5087556292f58baca25fd05a0bceb6826aa9eb531810001dd4b4677dd928dd60d39eecf843b2189f213f9bb82c5a9483e3aac";
      self.paymentParamForPassing.hashes.VASForMobileSDKHash = @"5c0314c2781876f7e0a53676b0d08e1457dafe904d2d15d948626b57409538d51093eef4f15c792b1b9651be7b5659efdd45926e43a1145d68cea094687011ca";
      self.paymentParamForPassing.hashes.deleteUserCardHash = @"03e10e892005755f91061121036fb1b10f46202b4138d182f153c5de5c7fd44930ed94b32fac230e59bac1e4ca123aca3297e4b9d25024bf13237db9721fec1a";
      self.paymentParamForPassing.hashes.offerHash = @"1e99fdb59bd91c1a85624104c0fcfae34d7fcb850dd17a0b75e7efe49857d15fdefc47dd0d86ca34cbc3a8b580839aea6341a573e4e60dc1ddcf7ecc32bf9cae";
    

2. Calling Webservices

3. Generating URLRequest (and post parameters) for Payment

To get request, create an object of class PayUCreateRequest as below. The callbacks give your URLRequest as well as post parameters (NSString format). You can use these post parameters to initialize Custom Browser Instance.

@property (nonatomic, strong) PayUCreateRequest *createRequest;
3.1 For CCDC

To Pay using CCDC, we need to set CCDC parameter as below:

		self.paymentParamForPassing.cardNumber = @"5123456789012346";//cardNumber
		self.paymentParamForPassing.nameOnCard = @"name";//Name on card
		self.paymentParamForPassing.expYear = @"2018";//Expiry year
		self.paymentParamForPassing.expMonth = @"11";//ExpiryMonth
		self.paymentParamForPassing.CVV = @"123";//CVV
		self.paymentParamForPassing.storeCardName = @"My TestCard";//If you want to save card then pass StoreCardName otherwise it will not save & make sure userCredentials are provided

After setting the above parameters, you can get the request by using createRequestWithPaymentParam method as below

		self.createRequest = [PayUCreateRequest new];
		[self.createRequest createRequestWithPaymentParam:self.paymentParamForPassing forPaymentType:PAYMENT_PG_CCDC withCompletionBlock:^(NSMutableURLRequest *request, NSString *postParam, NSString *error) {
    	if (error == nil) {
		//It is good to go state. You can use request parameter in webview to open Payment Page
    	}
    	else{
		//Something went wrong with Parameter, error contains the error Message string
    	}
	}];
3.2 For StoredCard

To Pay using StoredCard, we need to set StoredCard parameter as below:

	PayUModelStoredCard *modelStoredCard = [self.paymentRelatedDetail.storedCardArray objectAtIndex:indexPath.row];

	self.paymentParamForPassing.cardToken = modelStoredCard.cardToken;
	self.paymentParamForPassing.cardBin = modelStoredCard.cardBin;
	self.paymentParamForPassing.CVV = @"123";//CVV

After setting the above parameters, you can get the request by using createRequestWithPaymentParam method as below

	self.createRequest = [PayUCreateRequest new];
	[self.createRequest createRequestWithPaymentParam:self.paymentParamForPassing forPaymentType:PAYMENT_PG_STOREDCARD withCompletionBlock:^(NSMutableURLRequest *request, NSString *postParam, NSString *error) {
	if (error == nil) {
	//It is good to go state. You can use request parameter in webview to open Payment Page
	}
	else{
	//Something went wrong with Parameter, error contains the error Message string
	}
}];
3.3 For NetBanking

To Pay using NetBanking, we need to set NetBanking parameter as below:

	self.paymentParamForPassing.bankCode = @"AXIB";//BankCode

After setting the above parameters, you can get the request by using createRequestWithPaymentParam method as below

	self.createRequest = [PayUCreateRequest new];
	[self.createRequest createRequestWithPaymentParam:self.paymentParamForPassing forPaymentType:PAYMENT_PG_NET_BANKING withCompletionBlock:^(NSMutableURLRequest *request, NSString *postParam, NSString *error) {
	if (error == nil) {
	//It is good to go state. You can use request parameter in webview to open Payment Page
	}
	else{
	//Something went wrong with Parameter, error contains the error Message string
	}
}];
3.4 CashCard

To Pay using CashCard, we need to set cashcard parameter as below:

    self.paymentParamForPassing.bankCode = @"AXIB";//BankCode

After setting the above parameters, you can get the request by using createRequestWithPaymentParam method as below

    self.createRequest = [PayUCreateRequest new];
    [self.createRequest createRequestWithPaymentParam:self.paymentParamForPassing
     forPaymentType:PAYMENT_PG_CASHCARD withCompletionBlock:^(NSMutableURLRequest *request, NSString *postParam, NSString *error) {
       if (error == nil) {
          //It is good to go state. You can use request parameter in webview to open Payment Page
       }
       else{
         //Something went wrong with Parameter, error contains the error Message string
       }
    }];
3.5 EMI

To Pay using EMI, we need to set EMI parameter as below:

    self.paymentParamForPassing.bankCode = @"EMI03";//BankCode
    self.paymentParamForPassing.expiryYear = @"2019";
    self.paymentParamForPassing.expiryMonth = @"12";
    self.paymentParamForPassing.nameOnCard = @"test";
    self.paymentParamForPassing.cardNumber = @"5123456789012346";
    self.paymentParamForPassing.CVV = @"123";

After setting the above parameters, you can get the request by using createRequestWithPaymentParam method as below

self.createRequest = [PayUCreateRequest new];
[self.createRequest createRequestWithPaymentParam:self.paymentParamForPassing forPaymentType:PAYMENT_PG_EMI withCompletionBlock:^(NSMutableURLRequest *request, NSString *postParam, NSString *error) {
    if (error == nil) {
        	//It is good to go state. You can use request parameter in webview to open Payment Page
	}
	else{
	 //Something went wrong with Parameter, error contains the error Message string
   	 
	}
}];
3.6 PayUMoney

To Pay using PayUMoney, we need to set only the mandatory payment param and we can get the request by using createRequestWithPaymentParam method as below:

    PayUCreateRequest *createRequest = [PayUCreateRequest new];
    [createRequest createRequestWithPaymentParam:self.paymentParamForPassing forPaymentType:PAYMENT_PG_PAYU_MONEY withCompletionBlock:^(NSMutableURLRequest *request, NSString *postParam, NSString *error) {
	if (error == nil) {
        	//It is good to go state. You can use request parameter in webview to open Payment Page
	}
	else{
	 //Something went wrong with Parameter, error contains the error Message string
   	 
	}
}];
3.8 Subvention EMI
3.8.1 Pay via Subvention EMI

To Pay using Subvention EMI, we need to set subventionAmount parameter of paymentParams

    self.paymentParamForPassing.bankCode = @"EMI03";//BankCode
    self.paymentParamForPassing.expiryYear = @"2019";
    self.paymentParamForPassing.expiryMonth = @"12";
    self.paymentParamForPassing.nameOnCard = @"test";
    self.paymentParamForPassing.cardNumber = @"5123456789012346";
    self.paymentParamForPassing.CVV = @"123";

    self.paymentParamForPassing.subventionAmount = @"3000";

After setting the above parameters, you can get the request by using createRequestWithPaymentParam method as below:

    self.createRequest = [PayUCreateRequest new];
    [self.createRequest createRequestWithPaymentParam:self.paymentParamForPassing  forPaymentType:PAYMENT_PG_EMI withCompletionBlock:^(NSMutableURLRequest *request, NSString *postParam, NSString *error) {
    if (error == nil) {
        //It is good to go state. You can use request parameter in webview to open Payment Page
    }
    else{
    //Something went wrong with Parameter, error contains the error Message string
    }
    }];
3.8.2. Hash Calculation

If subventionAmount is passed than hash formula for payment hash will be

    sha512(key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||SALT|SubventionAmount)

Otherwise it will remain same as earlier.

3.9 LazyPay

To Pay using LazyPay, we need to set the below parameters :

Notify Url – Callback URL of merchant where a notification of transaction status will be sent on completion of transaction. It should be HTTPS.

    self.paymentParamForPassing.notifyURL= @"https://notifyURL.com";

After setting the above parameters, you can get the request by using createRequestWithPaymentParam method as below

    self.createRequest = [PayUCreateRequest new];

    [self.createRequest createRequestWithPaymentParam:self.paymentParamForPassing forPaymentType:PAYMENT_PG_LAZYPAY withCompletionBlock:^(NSMutableURLRequest *request, NSString *postParam, NSString *error) {
      if (error == nil) {
        //It is good to go. You can use request parameter in webview to open Payment Page
      }
      else{
        //Something went wrong with Parameter, error contains the error Message string
      }
    }];

Non-Seamless iOS integration: Using SDK’s Inbuilt UI

Before proceeding further, make sure you have read this document

Prerequisites:

  1. Add libz.tbd libraries into your project (Project->Build Phases->Link Binary With Libraries)

  2. Add -ObjC and $(OTHER_LDFLAGS)in Other Linker Flags in Project Build Settings(Project->Build Settings->Other Linker Flags)

  3. To run the app on iOS9, please add the below code in info.plist

       <key>NSAppTransportSecurity</key>
       <dict>
       <key>NSAllowsArbitraryLoads</key>
       <true/>
       </dict>
    

Integration steps:

  1. Drag and drop PayU folder into your App.

  2. In AppDelegate.h add the below property

    @property (weak, nonatomic) UIViewController *paymentOptionVC;

  3. Now come to checkout view controller of your app from where you want to start payment process.

1. Import the following file

        #import "PUUIPaymentOptionVC.h"

2. On the Pay button set the paymentparam as below:

        PayUModelPaymentParams *paymentParam = [[PayUModelPaymentParams alloc] init];
        PayUModelHashes *hashes = [[PayUModelHashes alloc] init];// Set the hashes here
        paymentParam.key = @"gtKFFx";
        paymentParam.transactionID = @"txnID20170220";
        paymentParam.amount = @"10";
        paymentParam.productInfo = @"iPhone";
        paymentParam.SURL = @"https://payu.herokuapp.com/success";
        paymentParam.FURL = @"https://payu.herokuapp.com/failure";
        paymentParam.firstName = @"Baalak";
        paymentParam.email = @"Baalak@gmail.com";
        paymentParam.udf1 = @"";
        paymentParam.udf2 = @"";
        paymentParam.udf3 = @"";
        paymentParam.udf4 = @"";
        paymentParam.udf5 = @"";            

        paymentParam.hashes = hashes;
          // Set this property if you want to get the stored cards:
        paymentParam.userCredentials = @"gtKFFx:Baalak@gmail.com";

        // Set the environment according to merchant key ENVIRONMENT_PRODUCTION for Production & 
        // ENVIRONMENT_TEST for test environment:
        paymentParam.environment = ENVIRONMENT_TEST;

        // Set this property if you want to give offer:
        paymentParam.offerKey = @"";


3. Now call **getPayUPaymentRelatedDetailForMobileSDK:paymentParam** method of **PayUWebServiceResponse** class to get the payment related details:

        PayUWebServiceResponse *webServiceResponse =[[PayUWebServiceResponse alloc]init];
        [webServiceResponse 
        getPayUPaymentRelatedDetailForMobileSDK:paymentParam
        withCompletionBlock:^(PayUModelPaymentRelatedDetail *paymentRelatedDetails,
        NSString *errorMessage, id extraParam) {
    
        if (!errorMessage) {
        UIStoryboard *stryBrd = [UIStoryboard
        storyboardWithName:@"PUUIMainStoryBoard" bundle:nil];
        PUUIPaymentOptionVC * paymentOptionVC = 
        [stryBrd instantiateViewControllerWithIdentifier:VC_IDENTIFIER_PAYMENT_OPTION];
        
        paymentOptionVC.paymentParam = paymentParam;
        paymentOptionVC.paymentRelatedDetail = paymentRelatedDetails;
        
        [self.navigationController pushViewController:paymentOptionVC animated:true];
        
        }
        else{
        // error occurred while creating the request
        }
        }];



4. Once the payment gets success, fails, cancel or any stored card gets deleted SDKUI fires notification to any registered observers. Add observer as below:

        [[NSNotificationCenter defaultCenter]
        addObserver:self selector:@selector(responseReceived:) 
        name:kPUUINotiPaymentResponse object:nil];

        -(void)responseReceived:(NSNotification *) notification{

        NSString *strConvertedRespone = [NSString stringWithFormat:@"%@",notification.object];
       NSLog(@"Response Received %@",strConvertedRespone);
       }   
  • Now PayUSDK is integrated.

Note: Please calculate all the hashes and assign tostrEmail paymentOptionsVC.allHashDict.Please refer Server Side Document for calculating hash.Hashes are provided to “paymentOptionsVC.allHashDict” in Key-Value Pair as below:

     e.g.:  
     {
         "check_offer_status_hash" = 22e773e2079e9c2249c230b1ee096efcc2555b214fe291293d5a109e65030dda2cd355d4db97751d9c1f43c5e055b347e3d4e2939830bdc1f5f48845899e5bf1;
         "delete_user_card_hash" = 793eed65afe4aaf1ddf89506093a57907a16fdd38e5c52050d7b5380e658c4300e221fa5f7da7b40ac213238b427e8d0dcc6a33bd5efe075d4261c01f143cb4e;
         "edit_user_card_hash" = 20d3ea6b9bc964e8548c8fd3fc1a9e3daa948a0226511abdd3679d77c8c54131775b7f6d3dc3589389f47edaec2906b2381033d88c1aef1920204b4989f636c9;
         "get_merchant_ibibo_codes_hash" = 307374123fb8d720d41361470984947f7f5c33ac4832598149bf1d108ea9b2ccefd7b46fe4ee4c021f67838a67f355a74f3c2d79bb37373d3b248a802c7159e2;
         "get_user_cards_hash" = dfac3cd3fe9599ceba79efc9ddd48e28cbd8fd47ab2e4ae8a3b5f6f5be559e9dbbc8328298fb224a4e0769b1c328d1b87f59354bbec3c4eb101acc968fde0508;
         "payment_hash" = 19c70354c7184da415a3a22c380235727e8d1e0aa3422e0b1cb6f40d9258e363a0dd37d611563e67fc8bd3be26960a54cba97de5b7588f323151f97c4f11dd06;
         "payment_related_details_for_mobile_sdk_hash" = 633369f45e3b98c100871be3cb8f5c631132a5d06b83c2fc1e6a12302ab7386fc23ca53fb9f9182518b6affca6b6fe5dad170ae087b7716b11f8ddc07899590e;
         "save_user_card_hash" = 09fb415be88e40de0d5c746f2ca4f7620dcf62eb2cf0da7cb0c2080eb36fed3290607b5b4bf890f2f8f5399bd72a41db18160c430c16079131272e7ce0c17a56;
          "vas_for_mobile_sdk_hash" = 7da0f4fef5bab0e5034f37f9503bdcbede00cc2cd0cf6cbb4e43baa9d57f05680305885199e2b0d38e8cf12895fd06f4d3dd3fb422535feeb555adc58e2cf3cc;
     }

Clone this wiki locally