こちらの手順に従っていますhttps://developers.braintreepayments.com/start/hello-client/ios/v4 iOS Swiftのbraintreeとドロップインペイメントフォームを統合するには、私のコードは次のように見えますが、私が知る限り、正確に文書にマッチします。Braintree Drop-In in iOS Swift:変数を取得する場所PaymentMethodNonce:
func fetchClientToken() {
// TODO: Switch this URL to your own authenticated API
let clientTokenURL = NSURL(string: "https://braintree-sample-merchant.herokuapp.com/client_token")!
let clientTokenRequest = NSMutableURLRequest(url: clientTokenURL as URL)
clientTokenRequest.setValue("text/plain", forHTTPHeaderField: "Accept")
URLSession.shared.dataTask(with: clientTokenRequest as URLRequest) { (data, response, error) -> Void in
// TODO: Handle errors
let clientToken = String(data: data!, encoding: String.Encoding.utf8)
// As an example, you may wish to present Drop-in at this point.
self.showDropIn(clientTokenOrTokenizationKey: clientToken!)
// Continue to the next section to learn more...
}.resume()
}
func postNonceToServer(paymentMethodNonce: String) {
// Update URL with your server
let paymentURL = URL(string: "https://your-server.example.com/payment-methods")!
let request = NSMutableURLRequest(url: paymentURL)
request.httpBody = "payment_method_nonce=\(paymentMethodNonce)".data(using: String.Encoding.utf8)
request.httpMethod = "POST"
URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error) -> Void in
// TODO: Handle success or failure
}.resume()
}
func showDropIn(clientTokenOrTokenizationKey: String) {
let request = BTDropInRequest()
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
}
controller.dismiss(animated: true, completion: nil)
}
self.present(dropIn!, animated: true, completion: nil)
}
今、私はその後、順番に、あなたが見ることができるように、すべて正常に動作され、showDropInを呼び出す関数fetchClientTokenを呼び出すことができます。
しかし、postNonceToServerを次の関数として実行するには、変数paymentMethodNonceが必要です。どこから取得するのかわからないため、ドキュメントに記載されていないと思います。したがって、私はshowDropInを実行した後に続けることができません...
私はかなり混乱していますが、簡単な修正があると確信していますが、その点に関するドキュメントは見つかりません。
cocoapodを通じてブレインをインストールしている間、私はこのエラーを取得しています。 「BraintreeDropInの仕様を見つけることができません」 – VJVJ