2016-08-01 62 views
1

我指的是將PayPal-iOS-SDK與我的本機iOS應用程序集成在一起。將Paypal SDK與本機iOS應用程序集成

我已經成功地集成了應用程序(這是我的感覺)

請參閱代碼

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // Override point for customization after application launch. 
     PayPalMobile .initializeWithClientIdsForEnvironments([PayPalEnvironmentProduction: "YOUR_CLIENT_ID_FOR_PRODUCTION", 
      PayPalEnvironmentSandbox: "SANDBOX CODE"]) 
     return true 
    } 

View Controller

// 
// ViewController.swift 
// PaypalDemo 
// 

import UIKit 

class ViewController: UIViewController,PayPalPaymentDelegate { 

    var environment:String = PayPalEnvironmentNoNetwork { 
     willSet(newEnvironment) { 
      if (newEnvironment != environment) { 
       PayPalMobile.preconnectWithEnvironment(newEnvironment) 
      } 
     } 
    } 



    #if HAS_CARDIO 
    // You should use the PayPal-iOS-SDK+card-Sample-App target to enable this setting. 
    // For your apps, you will need to link to the libCardIO and dependent libraries. Please read the README.md 
    // for more details. 
    var acceptCreditCards: Bool = true { 
    didSet { 
    payPalConfig.acceptCreditCards = acceptCreditCards 
    } 
    } 
    #else 
    var acceptCreditCards: Bool = false { 
     didSet { 
      payPalConfig.acceptCreditCards = acceptCreditCards 
     } 
    } 
    #endif 


    var resultText = "" // empty 
    var payPalConfig = PayPalConfiguration() // default 



    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     // Do any additional setup after loading the view. 
     title = "PayPal SDK Demo" 
     //successView.hidden = true 

     // Set up payPalConfig 
     print("this is credit card status \(acceptCreditCards)") 
     payPalConfig.acceptCreditCards = true; 
     payPalConfig.merchantName = "Awesome Shirts, Inc." 
     payPalConfig.merchantPrivacyPolicyURL = NSURL(string: "https://www.paypal.com/webapps/mpp/ua/privacy-full") 
     payPalConfig.merchantUserAgreementURL = NSURL(string: "https://www.paypal.com/webapps/mpp/ua/useragreement-full") 



     payPalConfig.languageOrLocale = NSLocale.preferredLanguages()[0] 

     // Setting the payPalShippingAddressOption property is optional. 
     // 
     // See PayPalConfiguration.h for details. 

     payPalConfig.payPalShippingAddressOption = .PayPal; 

     print("PayPal iOS SDK Version: \(PayPalMobile.libraryVersion())") 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 


    override func viewWillAppear(animated: Bool) { 
     super.viewWillAppear(animated) 
     PayPalMobile.preconnectWithEnvironment(environment) 
    } 


    @IBAction func payByPaypal(sender: UIButton) { 
     print("integrate paypal here") 
     resultText = "" 

     // Note: For purposes of illustration, this example shows a payment that includes 
     //  both payment details (subtotal, shipping, tax) and multiple items. 
     //  You would only specify these if appropriate to your situation. 
     //  Otherwise, you can leave payment.items and/or payment.paymentDetails nil, 
     //  and simply set payment.amount to your total charge. 

     // Optional: include multiple items 
     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.totalPriceForItems(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.decimalNumberByAdding(shipping).decimalNumberByAdding(tax) 

     let payment = PayPalPayment(amount: total, currencyCode: "AUD", shortDescription: "My Shop", intent: .Sale) 

     payment.items = items 
     payment.paymentDetails = paymentDetails 

     if (payment.processable) { 
      let paymentViewController = PayPalPaymentViewController(payment: payment, configuration: payPalConfig, delegate: self) 
      presentViewController(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)") 
     } 
    } 


    func payPalPaymentDidCancel(paymentViewController: PayPalPaymentViewController) { 
     print("PayPal Payment Cancelled") 
     resultText = "" 
     // successView.hidden = true 
     paymentViewController.dismissViewControllerAnimated(true, completion: nil) 
    } 

    func payPalPaymentViewController(paymentViewController: PayPalPaymentViewController, didCompletePayment completedPayment: PayPalPayment) { 
     print("PayPal Payment Success !") 
     paymentViewController.dismissViewControllerAnimated(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.") 

      self.resultText = completedPayment.description 
      self.showSuccess(completedPayment.confirmation) 
     }) 
    } 

    func showSuccess(inputString: NSObject) { 

     print("this is done successfully :) ") 
     print("send this to server \(inputString)") 
    } 



} 

我的關於應用程序的擔憂是

1.無論使用何種登錄方式,我都可以登錄。我已經嘗試[email protected]作爲電子郵件和1234作爲密碼,但我仍然能夠登錄。

2.我嘗試使用信用卡作爲4242-4242-4242-4242,cvv 123 12/12,仍然支付成功。

3.These是響應我收到 [client: { environment = mock; "paypal_sdk_version" = "2.14.3"; platform = iOS; "product_name" = "PayPal iOS SDK"; }, response_type: payment, response: { "create_time" = "2016-08-01T09:16:40Z"; id = "PAY-NONETWORKPAYIDEXAMPLE123"; intent = sale; state = approved; }] 另外, { client = { environment = mock; "paypal_sdk_version" = "2.14.3"; platform = iOS; "product_name" = "PayPal iOS SDK"; }; response = { "create_time" = "2016-08-01T09:59:31Z"; id = "API-PAYMENT-ID-1843"; intent = sale; state = approved; }; "response_type" = payment; }

  • 是整合成功的,或者是有,我失去了一些東西,因爲從響應貝寶我沒有找到唯一的訂單ID,而不是從用戶收取的金額。
  • 編輯1 這是信息,我從

    打印( 「這也是信息(completedPayment.description)」) 正從

    func payPalPaymentViewController(paymentViewController: PayPalPaymentViewController, didCompletePayment completedPayment: PayPalPayment) 
    `CurrencyCode: AUD 
    
    Amount: 216.46 
    
    Short Description: My Shop 
    
    Intent: sale 
    
    Processable: Already processed 
    
    Display: $216.46 
    
    Confirmation: { 
    
        client =  { 
    
         environment = mock; 
    
         "paypal_sdk_version" = "2.14.3"; 
    
         platform = iOS; 
    
         "product_name" = "PayPal iOS SDK"; 
    
        }; 
    
        response =  { 
    
         "create_time" = "2016-08-01T11:05:51Z"; 
    
         id = "PAY-NONETWORKPAYIDEXAMPLE123"; 
    
         intent = sale; 
    
         state = approved; 
    
        }; 
    
        "response_type" = payment; 
    
    } 
    
    Details: Subtotal: 207.97, Shipping: 5.99, Tax: 2.5 
    
    Shipping Address: (null) 
    
    Invoice Number: (null) 
    
    Custom: (null) 
    
    Soft Descriptor: (null) 
    
    BN code: (null) 
    
    Item: '{2|Old jeans with holes|84.99|USD|Hip-0037}' 
    
    Item: '{1|Free rainbow patch|0.00|USD|Hip-00066}' 
    
    Item: '{1|Long-sleeve plaid shirt (mustache not included)|37.99|USD|Hip-00291}'` 
    

    請指正,我在哪裏我缺乏。

    +0

    您的JSON無效。請通過驗證您的JSON [此處](http://jsonlint.com/)發佈正確的JSON格式。 – Dershowitz123

    回答

    1

    如果你經過下面的代碼

    var environment:String = PayPalEnvironmentNoNetwork { 
         willSet(newEnvironment) { 
          if (newEnvironment != environment) { 
           PayPalMobile.preconnectWithEnvironment(newEnvironment) 
          } 
         } 
        } 
    

    這是沒有網絡環境,它會給你所有的時間成功。

    您需要根據您的要求更改環境。對於例如如果你有沙箱用戶註冊PayPal上,那麼你需要改變這樣的

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

    ,然後如果你與任何其他用戶嘗試,而不是註冊用戶沙箱,它會給你的錯誤。這將只適用於沙盒用戶。

    還有一個叫做生產的環境,用於生活目的,您需要向客戶詢問憑據。

    PayPalEnvironmentProduction 
    

    我希望上述信息很清楚,您一直在尋找。

    • 不要忘記改變的AppDelegate客戶端ID按照你們各自的環境

    PayPalMobile.initializeWithClientIdsForEnvironments([PayPalEnvironmentProduction: 「」,PayPalEnvironmentSandbox: 「AYP ..... 。「])

    相關問題