我已使用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
答案 0 :(得分:0)
我不知道iOS但是对于android,我们在类这样的类中实现PayPal Result Delegate,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");
}
答案 1 :(得分:0)
首先,确保您不会发送带有API密码的应用程序非常重要。签名。否则,恶意用户可能会反汇编您的应用,恢复凭据并对您的帐户执行任意操作。 Read more about verifying a payment.
但是,假设您在服务器上实现了类似的代码,应工作。你得到的确切错误是什么?
答案 2 :(得分:0)
我解决了这个问题。
我正在制作JSON类型的X-PAYPAL-REQUEST-DATA-FORMAT,但当我将其更改为NV时,我开始编辑交易ID。
感谢所有人的回答。