现在已经有一个星期没有决心了。这个应用程序是一个由两部分组成的app-uber-like应用程序,带有骑手和驱动程序。 我正在尝试制作一个需要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)
}
payPalPressed:
@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.")
})
}
当我输入我的实时凭据并将..Sandbox更改为..Production时,我收到错误:字典文字有重复的键?
我安装了PayPal iOS SDK
非常感谢任何帮助。