如何在iOS中使用Braintree实现支付应用程序

时间:2016-12-06 23:19:15

标签: ios swift paypal braintree

我的问题是:我创建了一个应该接受信用卡/借记卡的应用程序。我在iOS中使用Braintree 4 SDK,快速使用可可豆荚。我可以很好地呈现下降,但它只是要求一个cc数然后消失,为什么呢?因为我使用快速入门指南中的代码,它应该这样做。但它没有说什么时候调用nonce函数或显示金额或任何东西! SDK 3是一个视图控制器,我可以放置代理,几乎所有东西都可以工作,除了记住卡片。所以我的问题是我应该在iOS中调用nonce函数?应该显示总数在哪里?如何向服务器BT付款?

该页面确实缺少一切的实际信息!帮助

我的代码:

defmodule VideoChat.User do
  use VideoChat.Web, :model

  schema "users" do
    field :device_identifier, :string
    field :matches, :map

    timestamps()
  end

  @doc """
  Builds a changeset based on the `struct` and `params`.
  """
  def changeset(struct, params \\ %{}) do
    struct
    |> cast(params, [:device_identifier])
    |> validate_required([:device_identifier])
  end
end

我应该在哪里打电话给这个?:

// Mark - Braintree methods

    func showDropIn(clientTokenOrTokenizationKey: String) {

            let request =  BTDropInRequest()
            request.amount = "\(total)"
            request.currencyCode = "MXN"
//            request.
            let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
            { (controller, result, error) in
                if (error != nil) {
                    print("ERROR")
                } else if (result?.isCancelled == true) {
                    print("CANCELLED")
                } else if let result = result {
                    // Use the BTDropInResult properties to update your UI
                    // result.paymentOptionType
                    // result.paymentMethod
                    // result.paymentIcon
                    // result.paymentDescription
                    print(result)

//                    controller.
                }
                controller.dismiss(animated: true, completion: nil)
            }
            self.present(dropIn!, animated: true, completion: nil)

//        //create paymentrequest
//        let
//        paymentRequest: BTPaymentRequest = BTPaymentRequest()
//        paymentRequest.summaryTitle = "Lavado Automozo"
//        paymentRequest.summaryDescription = "$\(totalLabel.text!) precio total de los servicios solicitados."
//        paymentRequest.displayAmount = "$\(total!).00 MXN"
//        paymentRequest.currencyCode = "MXN"
//        paymentRequest.callToActionText = "Aceptar compra."
//        paymentRequest.shouldHideCallToAction = false
//        //set delegate
//        let dropInViewController = BTDropInViewController(apiClient: braintreeClient!)
//        dropInViewController.delegate = self
//        dropInViewController.paymentRequest = paymentRequest
//        //add cancel button
//        dropInViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.cancel, target: self, action: #selector(ViewController.userDidCancelPayment))
//        
//        //present view
//        let navigationController = UINavigationController(rootViewController: dropInViewController)
//        
//        present(navigationController, animated: true, completion: nil)
//        
        //        let request =  BTDropInRequest()
//        let dropIn = BTDropInController()
//        { (controller, result, error) in
//            if (error != nil) {
//                print("ERROR")
//            } else if (result?.isCancelled == true) {
//                print("CANCELLED")
//            } else if let result = result {
//                // Use the BTDropInResult properties to update your UI
//                // result.paymentOptionType
//                // result.paymentMethod
//                // result.paymentIcon
//                // result.paymentDescription
//            }
//            controller.dismiss(animated: true, completion: nil)
//        }
//        self.present(dropIn!, animated: true, completion: nil)
    }

EDIT DropIn Payment method selected

Dummy card

虚拟卡片刚关闭后。

2 个答案:

答案 0 :(得分:3)

完全披露:我在Braintree工作。如果您有任何其他问题,请随时联系support

您可以通过result中的showDropIn()对象访问付款方式nonce。您也可以拨打postNonceToServer()

func showDropIn(clientTokenOrTokenizationKey: String) {
    let request =  BTDropInRequest()
    request.amount = "\(total)"
    request.currencyCode = "MXN"
    let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
    { (controller, result, error) in
        if (error != nil) {
            print("ERROR")
        } else if (result?.isCancelled == true) {
            print("CANCELLED")
        } else if let result = result {
            let selectedPaymentMethod = result.paymentMethod! // retrieve the payment method.
            self.postNonceToServer(paymentMethodNonce: selectedPaymentMethod.nonce) // call postNonceToServer() with the nonce from the selected payment method.
        }
        controller.dismiss(animated: true, completion: nil)
    }
    self.present(dropIn!, animated: true, completion: nil)
}

成功致电postNonceToServer()后,您可以在服务器上receive the payment method noncecreate a transaction

答案 1 :(得分:1)

  

Braintree由PayPal提供

Step 1.脑树支付网关的大部分工作将由您的支持的开发人员来设置,braintree将从两端以及后端和前端进行部署。

Step 3.

如果您的应用程序安装以下Pod 吊舱“ BraintreeDropIn” pod'Braintree / PayPal' Step 3. 从后端安装braintree后,请您的后端开发人员输入网址以获取交易令牌。

Step 4.将此令牌与BTDropInRequest一起传递给BTDropInController(他们提供直接付款用户界面),在调用此方法后,我们将得到一个字符串名称现时,然后将此现时发送给服务器,以进行下一步处理。

Step 5.此API将为您提供交易状态,以响应交易是否成功