我在 Swift 中尝试过,它对我来说效果很好。我附上了下面的代码检查并让我知道:
var braintree: Braintree?
braintree = Braintree(clientToken: "")
func userDidCancelPayment() {
self.dismiss(animated: true, completion: nil)
}
func drop(_ viewController: BTDropInViewController!, didSucceedWith paymentMethod: BTPaymentMethod!) {
print(paymentMethod.nonce)
// Send payment method nonce to your server
dismiss(animated: true, completion: nil)
let alert = UIAlertController(title: "Alert", message: "Send payment method nonce to your server Sucessfully", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
func tappedMyPayButton()
{
let dropInViewController = braintree!.dropInViewController(with: self)
dropInViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.cancel, target: self, action: #selector(PaymentVController.userDidCancelPayment))
let navigationController = UINavigationController(rootViewController: dropInViewController)
self.present(navigationController, animated: true, completion: nil)
}
func drop(inViewControllerDidCancel viewController: BTDropInViewController!) {
dismiss(animated: true, completion: nil)
}
签证:4242 4242 4242 4242
万事达卡:5555 5555 5555 4444
美国运通:3782 822463 10005
重要提示:在测试模式下使用任何未来的到期日期、卡上的姓名、CVC 和帐单邮编。