如何在签证结账时使用文本字段数据作为货币金额

时间:2017-11-01 10:21:26

标签: ios swift checkout braintree

我无法在签证结帐时使用UITextfield数据作为currencyAmount。 我将CurrencyAmount的变量作为a并将itemMoney文本设置为此变量。

我在代码中尝试的是什么: -

class ViewController: UIViewController {

@IBOutlet weak var itemMoney:UITextField!
@IBOutlet weak var lbl1:UILabel!
var a :Double = 0

@IBOutlet weak var checkoutButton:VisaCheckoutButton!
override func viewDidLoad() {
    super.viewDidLoad()

    a = Double(itemMoney.text!)!
    let purschaseInfo = PurchaseInfo(total: a, currency: .usd)
    purschaseInfo.reviewAction = .pay


    checkoutButton.onCheckout(purchaseInfo: purschaseInfo) { result in

        switch result.statusCode {
        case .success:
            print("Encrypted key: \(String(describing: result.encryptedKey))")
            print("Payment Data \(String(describing: result.encryptedPaymentData))")
            self.lbl1.text = "Payment sucessfull"
        case .userCancelled:
            print("Payment cancelled by user")
        default:
            break
    }
}
  

错误: - 参数标签'(_:)'不匹配任何可用的重载

请帮帮我

1 个答案:

答案 0 :(得分:2)

您正在传递Double,但我从规范中看到PurchaseInfo期望CurrencyAmount类型的对象(请参阅{指定付款明细并启动Visa Checkout“一节) {3}})。

let total = CurrencyAmount(string: "1.00")
let purchaseInfo = PurchaseInfo(total: total, currency: .usd)