如何从 Braintree iOs SDK 获取随机数

How to get nonce from Braintree iOs SDK

我正在尝试从 Braintree 获取随机数。我没有在以下文档中找到任何文档 Braintree 提供如何从 Braintree SDK 获取随机数。

https://developers.braintreepayments.com/start/hello-client/ios/v4

请告诉我如何从 Braintree iOs SDK

获取随机数

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

获取随机数记录在您链接的页面的 Presenting Drop-in UI section 中。启用 Drop-in 后,您需要实现一个委托,以便 Drop-in 可以找到将其生成的随机数发送到的位置。如果没有指定的委托,您将不会从 Drop-in 收到随机数:

Then implement BTDropInViewControllerDelegate to obtain the payment method nonce on success, and dismiss the Drop In UI in either case:

- (void)dropInViewController:(BTDropInViewController *)viewController   
  didSucceedWithTokenization:(BTPaymentMethodNonce *)paymentMethodNonce {
    // Send payment method nonce to your server for processing
    [self postNonceToServer:paymentMethodNonce.nonce];
    [self dismissViewControllerAnimated:YES completion:nil];
}

 - (void)dropInViewControllerDidCancel:(__unused BTDropInViewController *)viewController {
     [self dismissViewControllerAnimated:YES completion:nil];
}

如果您查看第一个函数,您会看到一个变量 paymentMethodNonce(类型:BTPaymentMethodNonce)被传递到您的应用程序中。此示例代码期望您有另一个函数 (postNonceToServer) 来在您获得 nonce 后实际处理它。

您可以通过使用 让 nonce = result.paymentMethod!.nonce

示例:-

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 {

            let nonce = result.paymentMethod!.nonce

            print( nonce)

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