Pay U Payment Gateway
Sometimes we require to integrate an application with Payu payment gateway . for this, we require to follow some steps.
1: There are two ways to integrate with Payu .( seamless and non-seamless(inbuilt UI part)).
2: Here I am defining about non-seamless Integration.
3: Go to that Url and download their SDK. https://github.com/payu-intrepos/Documentations/wiki/8.-iOS-SDK-integration
4: Drag Payu folder in your Xcode project.
5: do some changes in the project.
- Add
libz.tbd
libraries to your project (Project->Build Phases->Link Binary With Libraries) - Add
-ObjC
in Other Linker Flags in Project Build Settings(Project->Build Settings->Other Linker Flags) - To run the app on iOS9, please add the below code in info.plist
12345<key>NSAppTransportSecurity</key><dict><key>NSAllowsArbitraryLoads</key><true/></dict>
6: In AppDelegate.h add the below property
@property (weak, nonatomic) UIViewController *paymentOptionVC;
7: suppose you want to integrate into some class lets checkout class (example)
8: do some changes in .h file of checkout class
#import <UIKit/UIKit.h>
#import “PUUIBaseVC.h”
@interface checkout: PUUIBaseVC
9: Here I am giving .m file of checkout class .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
// // checkout.m // PayU // // Created by kunal prasad on 09/08/16. // Copyright © 2016 Webkul. All rights reserved. // #import "checkout.h" #import "PUUIPaymentOptionVC.h" #import "PUSAHelperClass.h" #import "iOSDefaultActivityIndicator.h" @interface checkout () @property (strong, nonatomic) PayUWebServiceResponse *webServiceResponse; @property (strong, nonatomic) iOSDefaultActivityIndicator *defaultActivityIndicator; @end //PayUModelPaymentParams *paymentParam; @implementation checkout - (void)viewDidLoad { [super viewDidLoad]; [self.buttonPressed addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside]; [self addPaymentResponseNotofication]; self.defaultActivityIndicator = [iOSDefaultActivityIndicator new]; self.paymentParam = [PayUModelPaymentParams new]; self.webServiceResponse = [PayUWebServiceResponse new]; } -(void)btnClicked:(id)sender{ [self dismissKeyboard]; [self.defaultActivityIndicator startAnimatingActivityIndicatorWithSelfView:self.view]; self.view.userInteractionEnabled = NO; //self.defaultActivityIndicator = [iOSDefaultActivityIndicator new]; //self.paymentParam = [PayUModelPaymentParams new]; //PayUModelHashes *hashes = [[PayUModelHashes alloc] init];// Set the hashes here self.paymentParam.firstName = @"Ram"; self.paymentParam.key = @"0MQaQP"; self.paymentParam.transactionID = [PUSAHelperClass getTransactionIDWithLength:15]; self.paymentParam.amount = @"110.0"; self.paymentParam.productInfo = @"Nokia"; self.paymentParam.SURL = @"https://payu.herokuapp.com/success"; self.paymentParam.FURL = @"https://payu.herokuapp.com/failure"; self.paymentParam.phoneNumber = @"1111111111"; self.paymentParam.email = @"email@testsdk1.com"; self.paymentParam.udf1 = @"u1"; self.paymentParam.udf2 = @"u2"; self.paymentParam.udf3 = @"u3"; self.paymentParam.udf4 = @"u4"; self.paymentParam.udf5 = @"u5"; self.scrollView = nil; // Set the environment according to merchant key ENVIRONMENT_PRODUCTION for Production & // ENVIRONMENT_MOBILETEST for mobiletest environment: self.paymentParam.environment = ENVIRONMENT_PRODUCTION; // Set this property if you want to give offer: self.paymentParam.offerKey = @"test123@6622"; ////bins@8427,srioffer@8428,cc2@8429,gtkffx@7236 // Set this property if you want to get the stored cards: self.paymentParam.userCredentials = @"ra:ra"; [PUSAHelperClass generateHashFromServer:self.paymentParam withCompletionBlock:^(PayUModelHashes *hashes, NSString *errorString) { [self callSDKWithHashes:hashes withError:errorString]; }]; } -(void)callSDKWithHashes:(PayUModelHashes *) allHashes withError:(NSString *) errorMessage{ if (errorMessage == nil) { self.paymentParam.hashes = allHashes; } [self callSDKWithOneTap:nil]; [self.defaultActivityIndicator stopAnimatingActivityIndicator]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:true]; } -(void) callSDKWithOneTap:(NSDictionary *)oneTapDict{ self.paymentParam.OneTapTokenDictionary = oneTapDict; PayUWebServiceResponse *respo = [PayUWebServiceResponse new]; self.webServiceResponse = [PayUWebServiceResponse new]; [self.webServiceResponse getPayUPaymentRelatedDetailForMobileSDK:self.paymentParam withCompletionBlock:^(PayUModelPaymentRelatedDetail *paymentRelatedDetails, NSString *errorMessage, id extraParam) { [self.defaultActivityIndicator stopAnimatingActivityIndicator]; if (!errorMessage) { [respo callVASForMobileSDKWithPaymentParam:self.paymentParam]; UIStoryboard *stryBrd = [UIStoryboard storyboardWithName:@"PUUIMainStoryBoard" bundle:nil]; PUUIPaymentOptionVC *paymentOptionVC = [stryBrd instantiateViewControllerWithIdentifier:VC_IDENTIFIER_PAYMENT_OPTION]; paymentOptionVC.paymentParam = self.paymentParam; paymentOptionVC.paymentRelatedDetail = paymentRelatedDetails; [self.navigationController pushViewController:paymentOptionVC animated:true]; } else{ NSLog(@" %@",errorMessage); } }]; } -(void) dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } -(void)addPaymentResponseNotofication{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(responseReceived:) name:kPUUINotiPaymentResponse object:nil]; } -(void)responseReceived:(NSNotification *) notification{ NSLog(@"Response Received message from server"); [self.navigationController popToRootViewControllerAnimated:NO]; // self.textFieldTransactionID.text = [PUSAHelperClass getTransactionIDWithLength:15]; NSString *strConvertedRespone = [NSString stringWithFormat:@"%@",notification.object]; NSLog(@"Response Received %@",strConvertedRespone); NSError *serializationError; id JSON = [NSJSONSerialization JSONObjectWithData:[strConvertedRespone dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&serializationError]; if (serializationError == nil && notification.object) { NSLog(@"%@",JSON); //PAYUALERT([JSON objectForKey:@"status"], strConvertedRespone); if ([[JSON objectForKey:@"status"] isEqual:@"success"]) { NSString *merchant_hash = [JSON objectForKey:@"merchant_hash"]; if ([[JSON objectForKey:@"card_token"] length] >1 && merchant_hash.length >1 && paymentParam) { NSLog(@"Saving merchant hash---->"); [PUSAHelperClass saveOneTapTokenForMerchantKey:paymentParam.key withCardToken:[JSON objectForKey:@"card_token"] withUserCredential:paymentParam.userCredentials andMerchantHash:merchant_hash withCompletionBlock:^(NSString *message, NSString *errorString) { if (errorString == nil) { NSLog(@"Merchant Hash saved succesfully %@",message); } else{ NSLog(@"Error while saving merchant hash %@", errorString); } }]; } } } else{ PAYUALERT(@"Response", strConvertedRespone); } } @end |
10: above value is dummy data for testing purpose.
11: Now I am attaching two file for generating Hash Value , here i am using for only dummy checking so if you want to configure for live payment then you have to write your server file for generating HASH VALUE.
live: https://github.com/payu-intrepos/Documentations/wiki/4.-Server-Side
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
// // PUSAHelperClass.m // PayUNonSeamlessTestApp #import "PUSAHelperClass.h" NSString *const URLGetHash = @"https://payu.herokuapp.com/get_hash"; NSString *const URLGetMerchantHash = @"https://payu.herokuapp.com/get_merchant_hashes"; NSString *const URLStoreMerchantHash = @"https://payu.herokuapp.com/store_merchant_hash"; @implementation PUSAHelperClass // To get Hashes from server +(void) generateHashFromServer:(PayUModelPaymentParams *) paymentParam withCompletionBlock:(hashRequestCompletionBlock)completionBlock{ void(^serverResponseForHashGenerationCallback)(PayUModelHashes *hashes, NSString *errorString) = completionBlock; NSMutableString *postParam = [NSMutableString new]; if (paymentParam.offerKey) { [postParam appendFormat:@"offer_key=%@",paymentParam.offerKey]; } if (paymentParam.key) { [postParam appendFormat:@"&key=%@",paymentParam.key]; } if (paymentParam.hashes.paymentHash) { [postParam appendFormat:@"&hash=%@",paymentParam.hashes.paymentHash]; } if (paymentParam.email) { [postParam appendFormat:@"&email=%@",paymentParam.email]; } if (paymentParam.amount) { [postParam appendFormat:@"&amount=%@",paymentParam.amount]; } if (paymentParam.firstName) { [postParam appendFormat:@"&firstname=%@",paymentParam.firstName]; } if (paymentParam.transactionID) { [postParam appendFormat:@"&txnid=%@",paymentParam.transactionID]; } if (paymentParam.userCredentials) { [postParam appendFormat:@"&user_credentials=%@",paymentParam.userCredentials]; } if (paymentParam.udf1) { [postParam appendFormat:@"&udf1=%@",paymentParam.udf1]; } if (paymentParam.udf2) { [postParam appendFormat:@"&udf2=%@",paymentParam.udf2]; } if (paymentParam.udf3) { [postParam appendFormat:@"&udf3=%@",paymentParam.udf3]; } if (paymentParam.udf4) { [postParam appendFormat:@"&udf4=%@",paymentParam.udf4]; } if (paymentParam.udf5) { [postParam appendFormat:@"&udf5=%@",paymentParam.udf5]; } if (paymentParam.productInfo) { [postParam appendFormat:@"&productinfo=%@",paymentParam.productInfo]; } NSLog(@"-->>Hash generation Post Param = %@",postParam); [PUSAWSManager getWebServiceResponse:[PUSAWSManager getURLRequestWithPostParam:postParam withURL:[NSURL URLWithString:URLGetHash]] withCompletionBlock:^(id JSON, NSString *errorMessage, id extraParam) { if (JSON) { if([[JSON objectForKey:@"message"] isEqualToString:@"successfully generated hash"]){ PayUModelHashes *payUHashes = [PayUModelHashes new]; payUHashes.paymentHash = [JSON objectForKey:@"payment_hash"]; payUHashes.paymentRelatedDetailsHash = [JSON objectForKey:@"payment_related_details_for_mobile_sdk_hash"]; payUHashes.VASForMobileSDKHash = [JSON objectForKey:@"vas_for_mobile_sdk_hash"]; payUHashes.deleteUserCardHash = [JSON objectForKey:@"delete_user_card_hash"]; payUHashes.editUserCardHash = [JSON objectForKey:@"edit_user_card_hash"]; payUHashes.saveUserCardHash = [JSON objectForKey:@"save_user_card_hash"]; payUHashes.getUserCardHash = [JSON objectForKey:@"get_user_cards_hash"]; payUHashes.offerHash = [JSON objectForKey:@"check_offer_status_hash"]; serverResponseForHashGenerationCallback(payUHashes ,nil); } else{ serverResponseForHashGenerationCallback(nil,[JSON objectForKey:@"message"]); } } else{ serverResponseForHashGenerationCallback(nil,errorMessage); } }]; } // To get transactionID +(NSString *) getTransactionIDWithLength:(int) len { NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; NSMutableString *randomString = [NSMutableString stringWithCapacity: len]; for (int i=0; i<len; i++) { [randomString appendFormat: @"%C", [letters characterAtIndex: arc4random_uniform((u_int32_t)[letters length])]]; } return randomString; } @end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
// // PUSAWSManager.m // PayUNonSeamlessTestApp // // Created by Umang Arya on 04/01/16. // Copyright © 2016 PayU. All rights reserved. // #import "PUSAWSManager.h" @implementation PUSAWSManager +(NSMutableURLRequest *)getURLRequestWithPostParam:(NSString *) postParam withURL:(NSURL *) paramURL{ NSMutableURLRequest *request; request = [NSMutableURLRequest requestWithURL:paramURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; if (postParam) { request.HTTPMethod = @"POST"; [request setHTTPBody:[postParam dataUsingEncoding:NSUTF8StringEncoding]]; } else{ request.HTTPMethod = @"GET"; } return request; } +(void)getWebServiceResponse:(NSMutableURLRequest *) webServiceRequest withCompletionBlock:(completionBlockForWebServiceResponse) completionBlock{ void(^callBackForWebServiceResponse)(id JSON ,NSString *errorMessage, id extraParam) = completionBlock; NSURLSession *defaultSession = [NSURLSession sharedSession]; NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:webServiceRequest completionHandler:^(NSData * data, NSURLResponse * response, NSError * error) { if (error == nil) { NSError *parseError = nil; id object = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&parseError]; NSLog(@"Response after hitting webService --> %@",object); if (parseError == nil) { callBackForWebServiceResponse(object,nil,nil); } else{ NSLog(@"Parse Error: %@",parseError.localizedDescription); callBackForWebServiceResponse(nil,parseError.localizedDescription,nil); } } else{ NSLog(@"Parse Error: %@",error.localizedDescription); callBackForWebServiceResponse(nil,error.localizedDescription,nil); } }]; [dataTask resume]; } @end |
12: Now its works fine and you can set according to your need.