来自iOS的PayPal错误580001 HTTP请求

编程入门 行业动态 更新时间:2024-10-18 23:23:36
本文介绍了来自iOS的PayPal错误580001 HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在iOS中实施自适应支付时遇到了一些困难,不幸的是,贝宝​​(PayPal)的网站或响应中的文档很少.这是代码:

Having some difficulties in implementing Adaptive payments in iOS and unfortunately there is very little documentation on PayPal's website or response. This is the code:

- (void)makePaymentSandbox{ NSError *error; //NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; //NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil]; NSURL *url = [NSURL URLWithString:@"svcs.sandbox.paypal/AdaptivePayments/Pay"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; //setting [request setHTTPMethod:@"POST"]; //headers [request addValue:@"alex-facilitator_api1.fastwebnet.it" forHTTPHeaderField:@"X-PAYPAL-SECURITY-USERID"]; [request addValue:@"FW79EZXASW69NE8X" forHTTPHeaderField:@"X-PAYPAL-SECURITY-PASSWORD"]; [request addValue:@"ABZua9nnv9oieyN4MwVt15YdgetaJHcyzqOHjkLbuM-bGRoI7WRS" forHTTPHeaderField:@"X-PAYPAL-SECURITY-SIGNATURE"]; //NV [request addValue:@"JSON" forHTTPHeaderField:@"X-PAYPAL-REQUEST-DATA-FORMAT"]; [request addValue:@"JSON" forHTTPHeaderField:@"X-PAYPAL-RESPONSE-DATA-FORMAT"]; [request addValue:@"APP-80W288712P519543T" forHTTPHeaderField:@"X-PAYPAL-APPLICATION-ID"]; [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request addValue:@"en_US" forHTTPHeaderField:@"Accept-Language"]; //data /*NSString *userUpdate =[NSString stringWithFormat:@"clientDetails.applicationId=%@&actionType=%@",@"APP-80W284485P519543T", @"PAY",nil]; NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding]; [request setHTTPBody:data1]; [request setValue: [NSString stringWithFormat:@"%lu", (unsigned long)[data1 length]] forHTTPHeaderField:@"Content-Length"];*/ NSDictionary *mapData = [[NSDictionary alloc] initWithObjectsAndKeys: @"PAY", @"actionType", @"USD", @"currencyCode", @"http:\\www.cleverlyapp", @"cancelUrl", @"http:\\www.cleverlyapp", @"returnUrl", @"ReturnAll", @"requestEnvelope.detailLevel", @"en_US", @"requestEnvelope.errorLanguage", @"seneder@email", @"senderEmail", @"0.1", @"receiverList.receiver(0).amount", @"a-buyer@fastwebnet.it", @"receiverList.receiver(0).email", @"0.1", @"receiverList.receiver(1).amount", @"a-facilitator@fastwebnet.it", @"receiverList.receiver(1).email", @"APP-80W284485P519543T", @"clientDetails.applicationId", nil]; NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error]; [request setHTTPBody:postData]; [NSURLConnection connectionWithRequest:request delegate:self]; }

以下是回复:

String: { error = ( { category = Application; domain = PLATFORM; errorId = 580001; message = "Invalid request: {0}"; severity = Error; subdomain = Application; } ); responseEnvelope = { ack = Failure; build = 17325060; correlationId = e82ede718b929; timestamp = "2015-07-14T09:50:06.222-07:00"; }; }

推荐答案

最后使它起作用.标头正确,输入数据有问题.这是正确的代码版本:

Finally got it to work. The headers are correct, the input data had some problems. This is the correct version of the code:

- (void)makePaymentSandboxWithPreapprovalToEmail:(NSString *)toEmail withCurrency:(NSString *)currency andAmount:(NSString *)moneyAmount completition:(void (^)(BOOL, NSString *))block{ NSError *error; NSURL *url = [NSURL URLWithString:@"svcs.sandbox.paypal/AdaptivePayments/Pay"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; //setting [request setHTTPMethod:@"POST"]; //headers [request addValue:@"alex.rietmann-facilitator_api1.fastwebnet.it" forHTTPHeaderField:@"X-PAYPAL-SECURITY-USERID"]; [request addValue:@"FW7ADTYZFP68XE0X" forHTTPHeaderField:@"X-PAYPAL-SECURITY-PASSWORD"]; [request addValue:@"ABSua9nnv9nnkoN4MwVt15YdgetaJHcyzqOHjkLbuM-bGRoI7JRS" forHTTPHeaderField:@"X-PAYPAL-SECURITY-SIGNATURE"]; //NV [request addValue:@"JSON" forHTTPHeaderField:@"X-PAYPAL-REQUEST-DATA-FORMAT"]; [request addValue:@"JSON" forHTTPHeaderField:@"X-PAYPAL-RESPONSE-DATA-FORMAT"]; [request addValue:@"APP-80W284485P519543T" forHTTPHeaderField:@"X-PAYPAL-APPLICATION-ID"]; [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request addValue:@"en_US" forHTTPHeaderField:@"Accept-Language"]; //other email NSDictionary *receiver0 = [[NSDictionary alloc] initWithObjectsAndKeys: toEmail, @"email", moneyAmount, @"amount", @"true", @"primary", nil]; //my account NSDictionary *receiver1 = [[NSDictionary alloc] initWithObjectsAndKeys: @"alex.rietmann-facilitator@fastwebnet.it", @"email", @"2", @"amount", nil]; NSDictionary *options0 = [[NSDictionary alloc] initWithObjectsAndKeys: [NSArray arrayWithObjects:receiver0, receiver1, nil], @"receiver", nil]; NSDictionary *mapData = [[NSDictionary alloc] initWithObjectsAndKeys: @"PAY", @"actionType", @"EACHRECEIVER", @"feesPayer", @"true", @"reverseAllParallelPaymentsOnError", currency, @"currencyCode", [PaymentManager readPaymentCode], @"preapprovalKey", [PaymentManager readPaymentEmail], @"senderEmail", @"http:\\www.apple", @"cancelUrl", @"http:\\www.google", @"returnUrl", [[NSDictionary alloc] initWithObjectsAndKeys:@"en_US", @"errorLanguage", @"detailLevel", @"ReturnAll", nil], @"requestEnvelope", //[[NSDictionary alloc] initWithObjectsAndKeys: options0, @"0", nil], @"receiverList", options0, @"receiverList", [[NSDictionary alloc] initWithObjectsAndKeys:@"APP-80W284485P519543T", @"applicationId", [self getIPAddress], @"ipAddress", nil], @"clientDetails", //@"APP-80W284485P519543T", @"clientDetails.applicationId", //[self getIPAddress], @"clientDetails.ipAddress", nil]; NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error]; [request setHTTPBody:postData]; MyConnection * connection = [[MyConnection alloc]initWithRequest:request]; [connection setCompletitionBlock:^(id obj, NSError *err) { if (!err) { NSError *error = nil; NSDictionary* revDicn =[NSDictionary dictionary]; revDicn = [NSJSONSerialization JSONObjectWithData:obj options:NSJSONReadingMutableContainers error:&error]; NSLog(@"Response: %@", revDicn); if ([[revDicn objectForKey:@"paymentExecStatus"] isEqualToString:@"COMPLETED"]) { block(YES, [revDicn objectForKey:@"payKey"]); }else{ block(NO, @""); } } else { //There was an error block(NO, @""); } }]; [connection start]; }

此行是可选的: [PaymentManager readPaymentCode],@"preapprovalKey", 它的使用取决于您是否要使用预先批准.这详细说明了预先批准的用法: developer.paypal/webapps/developer/docs/classic/adaptive-payments/ht_ap-basicPreapproval-curl-etc/.替换上面代码中的输入值,您将获得预批准密钥.

This line is optional: [PaymentManager readPaymentCode], @"preapprovalKey", The use of it depends on whether you wish to use pre-approval or not. This explains in detail the use of pre-approval: developer.paypal/webapps/developer/docs/classic/adaptive-payments/ht_ap-basicPreapproval-curl-etc/. Replace the input values in the code above and you will get the pre-approval key.

更多推荐

来自iOS的PayPal错误580001 HTTP请求

本文发布于:2023-11-28 09:55:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641929.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   PayPal   iOS   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!