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 をアプリケーションのバックエンドに保存する必要があります。早く入手する方法を知っておく必要があります。どんな助けでも大歓迎です。
ありがとうございます。