Reputation: 53
I am using PayPal SDK for adaptive payment...I get PayPal Payment Success message in
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
NSLog(@"PayPal Payment Success!");
[self sendCompletedPaymentToServer:completedPayment]; // Payment was processed successfully; send to server for verification and fulfillment
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)sendCompletedPaymentToServer:(PayPalPayment *)completedPayment {
// TODO: Send completedPayment.confirmation to server
NSLog(@"Here is your proof of payment:\n\n%@\n\nSend this to your server for confirmation and fulfillment.", completedPayment.confirmation);
payId=[[completedPayment.confirmation objectForKey:@"response"] objectForKey:@"id"];
[self callForAccessToken]; ///////calll webservice to get access token
}
- (void)callForAccessToken {
NSString *shippingURL=[NSString stringWithFormat:@"https://api.sandbox.paypal.com/v1/oauth2/token"];
ASIFormDataRequest *shippingRequest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:shippingURL]];
[shippingRequest setRequestMethod:@"POST"];
shippingRequest.tag=1010;
[shippingRequest setPostValue:@"application/json" forKey:@"Accept"];
[shippingRequest setPostValue:@"en_US" forKey:@"Accept-Language"];
NSString *clientIDSecret=[NSString stringWithFormat:@"kClientID:kClientsecret"];
[shippingRequest setPostValue:clientIDSecret forKey:@"clientId:secret"];
[shippingRequest setPostValue:@"client_credentials" forKey:@"grant_type"];
[shippingRequest setDelegate:self];
[shippingRequest setDidFinishSelector:@selector(uploadFinishedLocation:)];
[shippingRequest setDidFailSelector:@selector(uploadFailLocation:)];
[shippingRequest startAsynchronous];
}
- (void)uploadFinishedLocation:(ASIHTTPRequest *)requestObj {
NSString *response = [requestObj responseString];
NSLog(@"\n\nReq tag %ld Response string in Payment Didload %@\n\n",(long)requestObj.tag,response);
}
- (void)uploadFailLocation:(ASIHTTPRequest *)requestObj {
NSLog(@"%@",requestObj.error.description);
}
When I execute code uploadFailLocation
is called...
And I get error:
" Authentication needed "
I got reference to pass all data in post form in key-valuse combination by this link.
So have I pass client id and secredt right way or something is missing....... Or is there any other way to do this things.....
Upvotes: 1
Views: 496
Reputation: 1081
The generating of an access token is a server to server call and is not done from your App itself. Also, when doing so, the client ID and secret are sent in the headers and not just posted as key>value. The steps to verify a mobile payment can be found here.
Upvotes: 1