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