Updated 26 October 2021
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:@"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);
}
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
12 comments
example — NSMutableString *post = [NSMutableString string];
[post appendFormat:@”tnraetanaeaccess_code=%@”, @”3Akqd81fWPfnE5LHz”];
[post appendFormat:@”device_id=%@”, [PayFort getUDID ]];
[post appendFormat:@”language=%@”, @”en”];
[post appendFormat:@”merchant_identifier=%@”, @”azPOC”];
[post appendFormat:@”service_command=%@”, @”SDK_TOKENtnraetanae”];
NSDictionary *tmp = [[NSDictionary alloc] initWithObjectsAndKeys:
@”SDK_TOKEN”, @”service_command”,
@”azPOC”, @”merchant_identifier”,
@”3Akqd81fWPfnE5LHz”, @”access_code”,
[self sha1Encode:post],@”signature”,
@”en”, @”language”,
[PayFort getUDID ], @”device_id”,
nil];
2018-10-30 12:58:52.316243+0530 Dietitian[8407:2161810] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[UITextField setFloatingLabelActiveTextColor:]: unrecognized selector sent to instance 0x1501b4a00’
Im Getting the above error,what is the problem and how to solve that issue,i have tried a lot but can’t solve it
example — NSMutableString *post = [NSMutableString string];
[post appendFormat:@”tnraetanaeaccess_code=%@”, @”3Akqd81fWPfnE5LHz”];
[post appendFormat:@”device_id=%@”, [PayFort getUDID ]];
[post appendFormat:@”language=%@”, @”en”];
[post appendFormat:@”merchant_identifier=%@”, @”azPOC”];
[post appendFormat:@”service_command=%@”, @”SDK_TOKENtnraetanae”];
NSDictionary *tmp = [[NSDictionary alloc] initWithObjectsAndKeys:
@”SDK_TOKEN”, @”service_command”,
@”azPOC”, @”merchant_identifier”,
@”3Akqd81fWPfnE5LHz”, @”access_code”,
[self sha1Encode:post],@”signature”,
@”en”, @”language”,
[PayFort getUDID ], @”device_id”,
nil];
UINavigationController -> currentview
UINavigationController -> currentview
We are integrating pay fort SDK for iOS from document provided by you https://docs.payfort.com/docs/mobile-sdk/build/index.html#sdk-token-urls
We are getting stuck at very first step where we need to get SDK token for payment
We are getting Signature mismatch error every time I call https://sbpaymentservices.payfort.com/FortAPI/paymentApi API
Let me give you parameters that I am passing in API :
API : https://sbpaymentservices.payfort.com/FortAPI/paymentApi API
Parameter :
“access_code” = XNEw23o2DodbqTOLR6V3;
“device_id” = “360B7CA4-ABF7-4A00-8EE8-99E3411F6994”;
language = en;
“merchant_identifier” = qxbVGjJK;
“service_command” = “SDK_TOKEN”;
signature = 0cdb4c9b705826de3fd3b548515f5916197ff3f38965a38e5527ce9654387623;
I am getting Signature mismatch error when I call above API
And for signature generation I have used same steps provided by you in documents
Can you please help me to get rid out of this or can assist us for better solution ?
Thanks
you need token from server side its just confirms that wether you are valid customer or not.
time to time payfort change their rule and regulation so better to follow update document.
you will get also dummy credential from their documentation.
for successful signature
you need to pass correct value (this one is demo value)
[request setValue:@”XYZ9239-yu892Q78″ forKey:@”merchant_reference”];
[request setValue:sdk_token forKey:@”sdk_token”];
and . this one (this is demo data)
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];
if this one is correct than it will become success.fd
you need token from server side its just confirms that wether you are valid customer or not.
time to time payfort change their rule and regulation so better to follow update document.
you will get also dummy credential from their documentation.
for successful signature
you need to pass correct value (this one is demo value)
[request setValue:@”XYZ9239-yu892Q78″ forKey:@”merchant_reference”];
[request setValue:sdk_token forKey:@”sdk_token”];
and . this one (this is demo data)
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];
if this one is correct than it will become success.