如何将PayPal(live)添加到我的Swift应用程序?

如何将PayPal(live)添加到我的Swift应用程序?,paypal,swift3,ios10,Paypal,Swift3,Ios10,这个应用程序由两部分组成——类似优步的应用程序,有一个车手和一个司机 我正在尝试制作一个需要PayPal的应用程序。使用应用程序的人(驱动程序)将接受应用程序其他用户的付款(附加条款)。我曾尝试过跟踪PayPal文档,但只是遇到了麻烦 AppDelegate.swift: PayPalMobile .initializeWithClientIds(forEnvironments: [PayPalEnvironmentProduction: "CLIENT ID FOR PRODU

这个应用程序由两部分组成——类似优步的应用程序,有一个车手和一个司机

我正在尝试制作一个需要PayPal的应用程序。使用应用程序的人(驱动程序)将接受应用程序其他用户的付款(附加条款)。我曾尝试过跟踪PayPal文档,但只是遇到了麻烦

AppDelegate.swift:

PayPalMobile .initializeWithClientIds(forEnvironments:
        [PayPalEnvironmentProduction: "CLIENT ID FOR PRODUCTION",
         PayPalEnvironmentSandbox: "CLIENT ID FOR SANDBOX"])
ViewController.swift:

// create PayPal object:

var payPalConfig = PayPalConfiguration()

// Declare Payment Configuration

var environment: String = PayPalEnvironmentSandbox {
    willSet(newEnvironment) {
        if (newEnvironment != environment) {
            PayPalMobile.preconnect(withEnvironment: newEnvironment)
        }
    }
}

var acceptCreditCards: Bool = true {
    didSet {
        payPalConfig.acceptCreditCards = acceptCreditCards
    }
}

override func viewDidLoad() {
    super.viewDidLoad()
    payPalConfig.acceptCreditCards = acceptCreditCards
    payPalConfig.merchantName = "DevHopes"
    payPalConfig.merchantPrivacyPolicyURL = URL(string:   "https://www.paypal.com/webapps/mpp/ua/privacy-full")
    payPalConfig.merchantUserAgreementURL = URL(string: "https://www.paypal.com/webapps/mpp/ua/useragreement-full")

    payPalConfig.languageOrLocale = Locale.preferredLanguages[0]

    payPalConfig.payPalShippingAddressOption = .both
}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    PayPalMobile.preconnect(withEnvironment: environment)
}
他说:

@IBAction func payPalPressed(_ sender: Any) {
   let item1 = PayPalItem(name: "Staying Uptown", withQuantity: 1, withPrice: NSDecimalNumber(string: "0.01"), withCurrency: "CAD", withSku: "UPTOWN")
    let item2 = PayPalItem(name: "North-South", withQuantity: 1, withPrice: NSDecimalNumber(string: "0.01"), withCurrency: "CAD", withSku: "North-South")
    let item3 = PayPalItem(name: "South-SJRH", withQuantity: 1, withPrice: NSDecimalNumber(string: "0.01"), withCurrency: "CAD", withSku: "South-SJRH")

    let items = [item1, item2, item3]
    let subtotal = PayPalItem.totalPrice(forItems: items)

    // Optional: include payment details

    let paymentDetails = PayPalPaymentDetails(subtotal: subtotal, withShipping: nil, withTax: nil)

    let total = subtotal

    let payment = PayPalPayment(amount: total, currencyCode: "CAD", shortDescription: "Transportation", 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 processable: \(payment)")
    }
}


// PayPalPaymentDelegate

func payPalPaymentDidCancel(_ paymentViewController: PayPalPaymentViewController) {
    print("PayPal Payment Cancelled")
    paymentViewController.dismiss(animated: true, completion: nil)
}

func payPalPaymentViewController(_ paymentViewController: PayPalPaymentViewController, didComplete completedPayment: PayPalPayment) {
    print("PayPal Payment Success !")
    paymentViewController.dismiss(animated: true, completion: { () -> Void in
        // send completed confirmaion to your server

        print("Here is your proof of payment:\n\n\(completedPayment.confirmation)\n\nSend this to your server for confirmation and fulfillment.")

    })
}
运行此操作时,即使客户端id正确,也会出现错误:

当我放入live凭据并将..Sandbox更改为..Production时,我得到一个错误:dictionary literal具有重复的密钥

我已经安装了PayPal iOS SDK