0
我们正在开发和允许用户通过贝宝添加用户信用的应用程序。为了做到这一点iOS中我们做的:贝宝iOS始终返回相同的贝宝ID
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];
}
}];
}
的事情是,贝宝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-564191241M87KL57LXI",
"intent": "sale",
"state": "approved"
},
"response_type": "payment"
}
您服务器可以存储值从上述反应的唯一付款ID。
由于paypal id是检查服务器中paypal操作的标识符。但是,针对iOS的PayPal-SDK总是返回相同的ID(在Android中运行良好),所以我不知道它是沙盒问题还是我做错了什么。
有没有人有同样的问题?
在此先感谢
您看到的回复来自PayPal文档,我们使用的是来自cocoapods的2.6.1。 – Kasas 2014-11-10 08:36:30
我建议你用这里的实际响应来打开问题https://github.com/paypal/paypal-ios-sdk/issues,这样我们可以看看它。 – Romk1n 2014-11-10 18:13:54
Perfect @ Romk1n我们会这样做 – Kasas 2014-11-11 08:23:38