PayFort
In most of the time, we have to integrate the application with the payment gateway like a payfort payment gateway. for this, we have to follow some steps to integrate a correct integration payment SDK in IOS.
1: go to that URL and download SDK.
https://docs.payfort.com/
2: for success full launch the payfort gateway we need some sample predefined data.
3: we need a signature value that is required at the time to load payfort window. to generate a signature
1 2 3 4 5 6 |
NSMutableString *post = [NSMutableString string]; [post appendFormat:@"tnraetanaeaccess_code=%@", @"3Akqd81fWPfnE5L"]; [post appendFormat:@"device_id=%@", [PayFort getUDID ]]; [post appendFormat:@"language=%@", @"en"]; [post appendFormat:@"merchant_identifier=%@", @"azPOCM"]; [post appendFormat:@"service_command=%@", @"SDK_TOKENtnraetanae"]; |
[self sha1Encode:post]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
- (NSString*)sha1Encode:(NSString*)input { const char *cstr = [input cStringUsingEncoding:NSUTF8StringEncoding]; NSData *data = [NSData dataWithBytes:cstr length:input.length]; uint8_t digest[CC_SHA256_DIGEST_LENGTH]; CC_SHA256(data.bytes, (int)data.length, digest); NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2]; for(int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) [output appendFormat:@"%02x", digest[i]]; return output; } |
4: you will get signature value now you have to make a http request to get SDK token for launching payfort controller.
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 |
NSDictionary *tmp = [[NSDictionary alloc] initWithObjectsAndKeys: @"SDK_TOKEN", @"service_command", @"azPOCM", @"merchant_identifier", @"3Akqd81fWPfnE5L", @"access_code", [self sha1Encode:post],@"signature", @"en", @"language", [PayFort getUDID ], @"device_id", nil]; NSError *error; NSData *postdata = [NSJSONSerialization dataWithJSONObject:tmp options:0 error:&error]; NSString *BaseDomain =@"https://sbpaymentservices.payfort.com/FortAPI/paymentApi"; NSString *urlString = [NSString stringWithFormat:@"%@",BaseDomain]; //NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%ld",[postdata length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postdata]; //NSLog(@"signal mname %@", signalNameFunction); NSLog(@"url string %@",urlString); NSLog(@"url post %@",tmp); // NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self]; if(connection){ webDataglobal = [NSMutableData data]; } else{ NSLog(@"The Connection is null"); } } -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ [webDataglobal setLength: 0]; } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ [webDataglobal appendData:data]; } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ NSLog(@"error %@",error); } -(void)connectionDidFinishLoading:(NSURLConnection *)connection{ id collection = [NSJSONSerialization JSONObjectWithData:webDataglobal options:0 error:nil]; NSLog(@"receive data %@",collection); sdk_token = collection[@"sdk_token"]; [self launch]; } |
above code will produce SDK token now you have to take view controller and their class name write “PayFortController” .
1 2 3 4 |
- (void)viewDidLoad { [super viewDidLoad]; PayFort = [[PayFortController alloc]initWithEnviroment:KPayFortEnviromentSandBox]; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
-(void) launch{ PayFort.delegate = self; NSMutableDictionary *request = [[NSMutableDictionary alloc]init]; [request setValue:@"10000" forKey:@"amount"]; [request setValue:@"PURCHASE" forKey:@"command"]; [request setValue:@"SAR" forKey:@"currency"]; [request setValue:@ "customer@domain.com" forKey:@"customer_email"]; [request setValue:@"en" forKey:@"language"]; [request setValue:@"XYZ9239-yu892Q78" forKey:@"merchant_reference"]; [request setValue:sdk_token forKey:@"sdk_token"]; [PayFort setPayFortRequest:request]; // Must Send [payFort callPayFort:self] PayFort.IsShowResponsePage = YES; [PayFort callPayFort:self]; } |
Now it will launch and you can take dummy card number from their site.
5: you can get a response from that method.
– (void)sdkResult:(id)response{
NSLog(@”data— %@”,response);
}