- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试通过 PayPal 以编程方式发送付款,但它不起作用。请指教,谢谢。
我的代码在下面,下面是 PayPal 的 cURL 示例。
-(void)createPayment {
NSString *shortDescription = @"test description";
NSDecimalNumber *paymentDecimal = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%.02f", [Global sharedInstance].currentOrder.itemPrice]];
NSString *sku = [NSString stringWithFormat:@"DBAR-%i", [Global sharedInstance].currentOrder.orderNumber];
NSString *name = [NSString stringWithFormat:@"%@", [Global sharedInstance].currentOrder.boozeBrand];
PayPalItem *item = [PayPalItem itemWithName:name withQuantity:[Global sharedInstance].currentOrder.itemQuantity withPrice:paymentDecimal withCurrency:@"USD" withSku:sku];
float priceFloat = [item.price floatValue];
float totalFloat = priceFloat * item.quantity;
NSDecimalNumber *total = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%.02f", totalFloat]];
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount = total;
payment.currencyCode = @"USD";
payment.shortDescription = shortDescription;
payment.items = nil;
payment.paymentDetails = nil;
if (!payment.processable) {NSLog(@"Payment not processable.");}
NSString *token = [Global sharedInstance].accessToken;
NSString *bearerToken = [NSString stringWithFormat:@"Bearer %@", token];
NSDictionary *redirectDict = @{@"return_url":@"http://www.testurl.com",
@"cancel_url":@"http://www.testurl.com"};
NSDictionary *payerDict = @{@"payment_method":@"paypal"};
NSMutableDictionary *amountMutableDict = [[NSMutableDictionary alloc] init];
[amountMutableDict setObject:total forKey:@"total"];
[amountMutableDict setObject:@"USD" forKey:@"currency"];
NSDictionary *amountDict = [NSDictionary dictionaryWithDictionary:amountMutableDict];
NSMutableDictionary *transactionsMutableDict = [[NSMutableDictionary alloc] init];
[transactionsMutableDict setObject:amountDict forKey:@"amount"];
[transactionsMutableDict setObject:shortDescription forKey:@"description"];
NSDictionary *transactionsDict = [NSDictionary dictionaryWithDictionary:transactionsMutableDict];
NSMutableArray *transactionsMutableArray = [[NSMutableArray alloc] init];
[transactionsMutableArray addObject:transactionsDict];
NSArray *transactionsArray = [NSArray arrayWithArray:transactionsMutableArray];
NSMutableDictionary *dataMutableDict = [[NSMutableDictionary alloc] init];
[dataMutableDict setObject:@"sale" forKey:@"intent"];
[dataMutableDict setObject:redirectDict forKey:@"redirect_urls"];
[dataMutableDict setObject:payerDict forKey:@"payer"];
[dataMutableDict setObject:transactionsArray forKey:@"transactions"];
NSDictionary *dataDict = [NSDictionary dictionaryWithDictionary:dataMutableDict];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"https://api.sandbox.paypal.com/v1/payments/payment"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:bearerToken forHTTPHeaderField:@"Authorization"];
NSString *post = [NSString stringWithFormat:@"intent=sale&redirect_urls=%@&payer=%@", redirectDict, payerDict];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long [postData length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
NSURLSessionUploadTask *task = [session uploadTaskWithRequest:request fromData:postData completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error) {
NSLog(@"\nPurchase Response:\n\n%@", response.description);
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Authorization Failed" message:@"Your payment did not go through." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}];
[task resume];
}
PayPal 文档中的 cURL 示例:
curl https://api.sandbox.paypal.com/v1/payments/payment \
-v \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer accessToken' \
-d '{
"intent":"sale",
"redirect_urls":{
"return_url":"http://return_URL_here",
"cancel_url":"http://cancel_URL_here"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
},
"description":"This is the payment transaction description."
}
]
}'
这是我通过上述 NSLog 声明从 PayPal 得到的回复:
购买响应:
<NSHTTPURLResponse: 0x1512732d0> { URL: https://api.sandbox.paypal.com/v1/payments/payment } { status code: 400, headers {
"CORRELATION-ID" = c0b729159d0c7;
Connection = "close, close";
"Content-Language" = "en_US";
"Content-Length" = 200;
"Content-Type" = "application/json";
Date = "Mon, 04 Apr 2016 19:48:20 GMT";
"PROXY_SERVER_INFO" = "host=slcsbplatformapiserv3001.slc.paypal.com;threadId=675";
"Paypal-Debug-Id" = "c0b729159d0c7, c0b729159d0c7";
Server = Apache;
"Set-Cookie" = "X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D80020055; domain=.paypal.com; path=/; Secure; HttpOnly, X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT";
Vary = Authorization;
} }
有人请告诉我为什么付款没有通过。我没有收到错误(或者它不会打印响应),我知道 token 很好,因为我每次使用该应用程序时都必须登录 PayPal,但我无法弄清楚。谢谢!
C
最佳答案
您应该将 JSON 数据打印到控制台,而不是打印 NSURlResponse 描述,以便您更好地理解。将您的代码修改为如下所示:
NSURLSessionUploadTask *task = [session uploadTaskWithRequest:request fromData:postData completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error) {
NSError* jsonError;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&jsonError];
NSLog(@"\nPurchase Response:\n\n%@", json); //You will have to edit this to use the actual error object returned from the curl request.
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Authorization Failed" message:@"Your payment did not go through." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}];
完成此操作后,您应该可以更好地了解问题出在哪里。
更新:
我现在看到了更多正在发生的事情。您的请求确实格式错误:您的帖子和帖子数据值不正确;你发送的是字符串值(就像你通过 url 发送的那样)而不是 json(下面的这些行)
NSString *post = [NSString stringWithFormat:@"intent=sale&redirect_urls=%@&payer=%@", redirectDict, payerDict];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
将这两行替换为:
NSError *jsonError;
NSData *postData = [NSJSONSerialization dataWithJSONObject:dataDict options:0 error:&error];
关于objective-c - 以编程方式发送 PayPal 付款 Objective-C ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36413690/
我有一个包含交易的简单表格,我想了解每个月有多少消费者进行的交易总额大于 0,并且他们的第一笔交易不在该月。首次交易是指客户在当月首次购买。 我试图得到的结果是以下形式: +--------+----
这是一个网站,点击“Dodaję”(在波兰语中意为“添加”)后,商品进入购物篮 30 分钟:https://remix.pl/ 当元素在购物篮中时,其他人无法购买该元素。我检查了他们的 basked:
我想知道,您是否编写了一个使用 Paypal 付款作为付款方式的网站(您被重定向到他们的网站进行付款的付款方式,而不是网络付款专业版)。 我可以存储什么样的详细信息?是否只有他们的 Paypal 电子
我一直在开发需要实现触碰付款的应用程序。我能够将 HCE 服务与 NFC 终端连接。 现在我的问题是接下来的步骤是什么,用它进行实际付款? 我到处搜索,但找不到合适的文件。请帮我。 下面是我编写的将
我正在为我在学校的最终项目开发一个网站,在我的网站上您可以购买硬币来打开礼物,但我想自动付款。当客户完成付款后,他会被重定向到 success.php,我如何安排他在付款成功后自动在他的帐户中获得 X
我正在使用 Stripe 在我的应用程序中付款。我成功获得了 token 。我想知道如何收费,因为我的 Stripe 仪表板中没有反射(reflect)任何变化。我正在使用我的 Stripe 帐户 T
我的网站是用 Python 编码的,我想提供通过 paypal 在我的网站上接受付款的功能。我想使用免费的 paypal 服务(无月费)来执行此操作,用户将被重定向到 paypals 站点以登录并付款
我们正在开发一个 iOS 应用程序,它提供一些可以在应用程序内使用的积分(付费)。我们对此几乎没有疑问 - 我们能否使用第三方支付网关,如 paypal 或类似的网关,或者我们需要为此实现 IAP?
我想从我的账户处理向 PayPal 用户的 PayPal 付款。我使用 PHP 脚本从我的服务器获取表单详细信息,但是,我无法仅使用 PHP 脚本处理付款(我想 PayPal 网站要求用户在客户端使用
我正在尝试实现以下场景: 用户批准针对选定包大小的定期每周付款(订阅) 用户每周都可以:A。取消特定周的交货并避免支付本周的费用b.修改包裹尺寸,只为这次少付/多付C。除了每周套餐之外,添加其他项目并
我尝试用信用卡创建付款并从 paypal 得到回复成功 ACK 但在 IPN 中我的目标是获得和等待响应,为什么我在尝试使用此付款时收到此错误 METHOD=DoDirectPayment &VERS
您能否以某种方式要求用户批准付款并在稍后处理这笔付款?具体来说,我有一个市场,用户 A 可以在其中向其他用户 B 索取一些产品。我想在用户 A 收到他的产品时收费,但我希望用户 B 确保不会白白创造他
我正在创建一个 phonegap 应用程序,它有 2 个变量用于在 paypal.js 文件中设置 PayPalEnvironmentProduction 和 PayPalEnvironmentSan
我的问题可能看起来非常基础并且依赖于 View ,但我希望了解它的各个方面。我创建了一个移动应用程序,用户需要在其中注册才能使用该应用程序,但我的客户希望拥有网站形式的管理面板,用户可以通过 payp
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,
我在我的网站上付款,您可以在网站上赚钱。因此,用户可以选择他想向他的网站账户转账多少钱。 我希望可以选择当用户的资金少于例如 20 美元时自动启动从他的帐户转账到我的帐户并在我的网站上充值他的信用额度
我想创建一个市场,用户可以在其中列出商品并让买家直接通过 Paypal 付款。有没有办法在我们这边跟踪这些付款,以便我可以对数据进行操作(例如将订单标记为已完成)?我在想我可以让卖家将他们的 payp
我目前在我工作的网站上使用 Paypal 作为支付系统,到目前为止一切正常...除了一件事。付款完成后,Paypal 调用我提供的 IPN 页面,一切正常。但是,如果此人取消付款,我不确定我应该如何知
我有两个网站,两个网站都通过 PayPal 付款销售相同的产品。但现在我需要确定特定交易是从哪个网站进行的。我的意思是这次购买是从哪个网站进行的。那么有什么方法可以识别吗?? 非常感谢。 最佳答案 您
我想在paypal支付页面获取多个产品。我现在只得到一个单一的第一个产品。有人可以帮我解决我错的地方吗?下面是我的代码..我搜索谷歌,发现还有两件事要改变。即 _xclick 到 _cart 和一个
我是一名优秀的程序员,十分优秀!