【发布时间】:2015-01-03 07:40:25
【问题描述】:
我们正在开发允许用户通过贝宝添加用户信用的应用程序。为了在 iOS 中做到这一点,我们这样做:
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
float value = [[numberFormatter numberFromString:self.tfBalance.text] floatValue];
value = value * 1.04;
// Create a PayPalPayment
PayPalPayment *payment = [[PayPalPayment alloc] init];
// Amount, currency, and description
payment.amount = [[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%.2f", value]];
payment.currencyCode = @"EUR";
payment.shortDescription = [NSString stringWithFormat:@"Añadir Saldo: %@+4%% comisión PayPal", self.tfBalance.text];
payment.intent = PayPalPaymentIntentSale;
PayPalPaymentViewController *paymentViewController;
paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment
configuration:self.payPalConfiguration
delegate:self];
// Present the PayPalPaymentViewController.
[self presentViewController:paymentViewController animated:YES completion:nil];
还有代表:
#pragma mark - PayPal delegate
- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController
didCompletePayment:(PayPalPayment *)completedPayment {
// Payment was processed successfully; send to server for verification and fulfillment.
[self verifyCompletedPayment:completedPayment];
// Dismiss the PayPalPaymentViewController.
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
// The payment was canceled; dismiss the PayPalPaymentViewController.
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)verifyCompletedPayment:(PayPalPayment *)completedPayment {
// Verificamos en el servidor si se ha realizado el pago
NSDictionary* response = [completedPayment.confirmation objectForKey:@"response"];
NSString* paypalId = [response objectForKey:@"id"];
[[MMApplicationModel sharedInstance].restManager createPayPalOperation:paypalId amount:[completedPayment.amount stringValue] completionHandler:^(bool verified) {
if(verified){
[self.tfBalance setText:@""];
[self performSelectorInBackground:@selector(refreshBalance) withObject:nil];
}
else{
//Mostramos el error
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
[self showMessage:NSLocalizedString(@"topup_error_creating_operation", nil) withTitle:NSLocalizedString(@"error", nil) andTag:0];
}
}];
}
问题是,在 PayPal SDK 文档中,他们说:
使用 MSDK 2.x 成功付款后,MSDK 会向您的应用返回有关付款的数据(由 MSDK 从 REST API 接收)。
{
"client": {
"environment": "sandbox",
"paypal_sdk_version": "2.0.0",
"platform": "iOS",
"product_name": "PayPal iOS SDK;"
},
"response": {
"create_time": "2014-02-12T22:29:49Z",
"id": "PAY-564191241M8701234KL57LXI",
"intent": "sale",
"state": "approved"
},
"response_type": "payment"
}
您的服务器可以存储来自上述响应的唯一支付 ID 值。
因为 paypal id 是在服务器中检查 paypal 操作的标识符。但是适用于 iOS 的 PayPal-SDK 总是返回相同的 id(在 Android 中运行良好),所以我不知道这是沙盒问题还是我做错了什么。
有人遇到过同样的问题吗?
提前致谢
【问题讨论】:
标签: ios paypal paypal-sandbox