需要从支付密钥 PayPal 获得交易 ID
Posted
技术标签:
【中文标题】需要从支付密钥 PayPal 获得交易 ID【英文标题】:Need to have transaction id from pay key PayPal 【发布时间】:2013-09-06 09:24:14 【问题描述】:我已使用 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 保存在我的应用程序后端以供将来参考。 需要知道如何尽快得到它。 任何帮助将不胜感激。
感谢和问候 潘卡伊
【问题讨论】:
【参考方案1】:我不了解iOS,但对于andorid,我们在类似的类中实现了PayPalResultDelegate、Serializable 接口。我正在分享我的代码:
class ResultDelegate implements PayPalResultDelegate, Serializable
private static final long serialVersionUID = 10001L;
PaypalDetailImplementation ob = new PaypalDetailImplementation() ;
public void onPaymentSucceeded(String payKey, String paymentStatus)
ob.resultTitle = "SUCCESS";
ob.resultInfo = "You have successfully completed your transaction.";
ob.resultExtra = "Key: " + payKey;
this.displayInformation("onPaymentSucceeded", ob.resultTitle, ob.resultInfo, ob.resultExtra) ;
public void onPaymentFailed(String paymentStatus, String correlationID,String payKey, String errorID, String errorMessage)
ob.resultTitle = "FAILURE";
ob.resultInfo = errorMessage;
ob.resultExtra = "Error ID: " + errorID + "\nCorrelation ID: "+ correlationID + "\nPay Key: " + payKey;
this.displayInformation("onPaymentFailed", ob.resultTitle, ob.resultInfo, ob.resultExtra) ;
public void onPaymentCanceled(String paymentStatus)
ob.resultTitle = "CANCELED";
ob.resultInfo = "The transaction has been cancelled.";
ob.resultExtra = "";
this.displayInformation("onPaymentCanceled", ob.resultTitle, ob.resultInfo, ob.resultExtra) ;
public void displayInformation ( String msg , String resultTitle , String resultInfo , String resultExtra )
Log.i("Result as message : ",msg);
Log.i(resultTitle,"tushar:onPaymentSucceeded");
Log.i(resultInfo,"tushar:onPaymentSucceeded");
Log.i(resultExtra,"tushar:onPaymentSucceeded");
【讨论】:
感谢您的回复,但据我了解,上述代码不会产生交易 ID。它提供的唯一东西是我已经拥有的 PayKey。【参考方案2】:首先,确保您发布的应用不带有 API 密码和签名,这一点至关重要。否则,恶意用户可能会反汇编您的应用程序、恢复凭据并对您的帐户执行任意操作。 Read more about verifying a payment.
但是,假设您在服务器上实现了类似的代码,它应该工作。您得到的确切错误是什么?
【讨论】:
感谢您的回复 tomwhipple,我已经这样做了,但是我的问题是如何解决的。【参考方案3】:我自己解决了这个问题。
我正在制作 JSON 类型的 X-PAYPAL-REQUEST-DATA-FORMAT,但是当我将其更改为 NV 时,我开始调整交易 ID。
感谢大家的回答。
【讨论】:
这里的 NV 是什么?正如您所说,您将请求格式从 JSON 更改为 NV。 @NishantTyagi NV 是 PayPal 支持的名称-值格式以上是关于需要从支付密钥 PayPal 获得交易 ID的主要内容,如果未能解决你的问题,请参考以下文章