将 Paypal ios sdk 与 swift 5 集成时出错

Posted

技术标签:

【中文标题】将 Paypal ios sdk 与 swift 5 集成时出错【英文标题】:Getting error in integrating Paypal ios sdk with swift 5 【发布时间】:2020-06-04 10:05:19 【问题描述】:

我正在尝试将 paypal sdk 集成到 swift 5 中。我已经编写了所有代码,但仍然显示“不允许向该商家付款(无效的客户 ID)”,而相同的客户 ID 运行良好在安卓中。任何帮助深表感谢。 在 Appdelegate 我写道 PayPalMobile.initializeWithClientIds(forEnvironments: [PayPalEnvironmentProduction: "test",

    PayPalEnvironmentSandbox : "test"])
[![enter image description here][1]][1]


    let item1 = PayPalItem(name: "Old jeans with holes", withQuantity: 2, withPrice: NSDecimalNumber(string: "84.99"), withCurrency: "USD", withSku: "Hip-0037")
    let item2 = PayPalItem(name: "Free rainbow patch", withQuantity: 1, withPrice: NSDecimalNumber(string: "0.00"), withCurrency: "USD", withSku: "Hip-00066")
    let item3 = PayPalItem(name: "Long-sleeve plaid shirt (mustache not included)", withQuantity: 1, withPrice: NSDecimalNumber(string: "37.99"), withCurrency: "USD", withSku: "Hip-00291")
    let items = [item1, item2, item3]
    let subtotal = PayPalItem.totalPrice(forItems: items) //This is the total price of all the items
    // Optional: include payment details
    let shipping = NSDecimalNumber(string: "5.99")
    let tax = NSDecimalNumber(string: "2.50")
    let paymentDetails = PayPalPaymentDetails(subtotal: subtotal, withShipping: shipping, withTax: tax)
    let total = subtotal.adding(shipping).adding(tax) //This is the total price including shipping and tax
    let payment = PayPalPayment(amount: total, currencyCode: "USD", shortDescription: "Weavers", intent: .sale)
    payment.items = items
    payment.paymentDetails = paymentDetails
    if (payment.processable) 
        let paymentViewController = PayPalPaymentViewController(payment: payment, configuration: payPalConfig, delegate: self)
        present(paymentViewController!, animated: true, completion: nil)
    
    else 
        // This particular payment will always be processable. If, for
        // example, the amount was negative or the shortDescription was
        // empty, this payment wouldn’t be processable, and you’d want
        // to handle that here.
        print("Payment not processalbe: (payment)")
    

【问题讨论】:

PayPal ios SDK 已被弃用很长时间。但无论如何,它可能在您的仪表板配置中。 感谢您的回复先生。你能否详细说明我如何解决这个问题。 Dashboard config 是指在 paypal 帐户中吗? 我已经在我的项目中安装了 pod ‘PayPal-iOS-SDK’ 嗨,我猜 PayPal sdk 已被弃用。所以你可以尝试实现 Braintree 它也提供 PayPal 支持。 appcoda.com/braintree-ios-integration 好的。非常感谢 【参考方案1】:

PayPal iOS SDK 已弃用,不应用于新的集成。

如果您需要原生 SDK,支持PayPal Express Checkout via the Braintree Mobile SDK。

【讨论】:

以上是关于将 Paypal ios sdk 与 swift 5 集成时出错的主要内容,如果未能解决你的问题,请参考以下文章

PayPal Checkout 直接使用 Braintree SDK - Swift

我需要我的 AppDelegate.swift 在 Objective C for PayPal SDK 中吗

将 Paypal SDK 与原生 iOS 应用程序集成

使用 cocoapods 的 PayPal-iOS-SDK 在桥接头中引发错误

我们可以使用带有最新 xcode 和 swift 版本的较低版本的 pay pal sdk

ios sdk 中的付款选项,无需应用内购买和 PayPal