【问题标题】:Paypal iOS always returning same paypal idPaypal iOS 总是返回相同的 paypal id
【发布时间】: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


    【解决方案1】:

    看起来您使用的库是相当旧的 2.0.0,所以它是创建时间。您是否尝试过使用最新的 PayPal SDK https://github.com/paypal/PayPal-iOS-SDK/releases/tag/2.6.1 重现此行为?

    【讨论】:

    • 您看到的响应来自 PayPal 文档,我们使用的是 cocoapods 的 2.6.1。
    • 我建议您在github.com/paypal/paypal-ios-sdk/issues 此处使用实际回复打开问题,以便我们查看。
    • 完美@Romk1n 我们会做到的
    • 您可能在 Mock 中运行,但没有输出我们无法验证。
    • 谢谢@Romk1n,这确实是一个愚蠢的问题。如果您发布答案,我会给您正确的答案。
    猜你喜欢
    • 2015-03-10
    • 2016-03-12
    • 2016-10-10
    • 2012-07-29
    • 2020-09-01
    • 2011-03-29
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    相关资源
    最近更新 更多