我已经使用 PayPal MPL 库成功地将 PayPal 集成到我的 iOS 应用程序中。但问题是如何从我从 PayPal 的回调方法获得的 paykey 获取交易 ID。
我已经尝试过这种方式,但收到无效请求的错误。
- (void)paymentSuccessWithKey:(NSString *)payKey andStatus:(PayPalPaymentStatus)paymentStatus
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://svcs.paypal.com/AdaptivePayments/PaymentDetails"]];
//NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails"]];
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:url];
NSString *parameterString = [NSString stringWithFormat:@"payKey=%@&requestEnvelope.errorLanguage=%@",payKey,@"en_US"];
NSString *msgLength = [NSString stringWithFormat:@"%d", [parameterString length]];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
//do post request for parameter passing
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
//passing key as a http header request
[theRequest addValue:api_username forHTTPHeaderField:@"X-PAYPAL-SECURITY-USERID"];
//passing key as a http header request
[theRequest addValue:api_password forHTTPHeaderField:@"X-PAYPAL-SECURITY-PASSWORD"];
[theRequest addValue:api_signature forHTTPHeaderField:@"X-PAYPAL-SECURITY-SIGNATURE"];
[theRequest addValue:@"JSON" forHTTPHeaderField:@"X-PAYPAL-REQUEST-DATA-FORMAT"];
[theRequest addValue:@"JSON" forHTTPHeaderField:@"X-PAYPAL-RESPONSE-DATA-FORMAT"];
[theRequest addValue:app_id forHTTPHeaderField:@"X-PAYPAL-APPLICATION-ID"];
[theRequest setHTTPBody: [parameterString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err];
NSString* s = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *result = [s JSONValue] ;
}
我需要将事务 ID 保存在我的应用程序后端以供将来参考。需要知道如何尽快得到它。任何帮助,将不胜感激。
感谢和问候 Pankaj