gpt4 book ai didi

swift - 如何在 BTCard 中设置信用卡可选数据,以便 Braintree 后端在 swift 4 中提供有效 token ?

转载 作者:行者123 更新时间:2023-11-30 10:40:26 26 4
gpt4 key购买 nike

截至 2019 年 7 月的 Braintree SDK 开发人员文档提供了该标准:

let braintreeClient = BTAPIClient(authorization: "<#CLIENT_AUTHORIZATION#>")!
let cardClient = BTCardClient(apiClient: braintreeClient)
let card = BTCard(number: "4111111111111111", expirationMonth: "12", expirationYear: "2018", cvv: nil)
cardClient.tokenizeCard(card) { (tokenizedCard, error) in
// Communicate the tokenizedCard.nonce to your server, or handle error
}

但是当初始化中需要邮政编码时,该类接受 NSDictionary 参数。问题是 key 与 Braintree SDK 属性不匹配

我用过:

let cardParameters: [String: Any] = [number:"4111111111111111",expirationMonth: "12", expirationYear: "2018", cvv: "111", postalCode: "94107"]
let card = BTCard.init(parameters: cardParameters)

The errors say : "Must provide postal code" or "cvv must be provided"

最佳答案

技巧是使用内置属性初始化 BTCard 对象并匹配它们,而不是使用 NSDictionary。所以这有效:

let braintreeClient = BTAPIClient(authorization: "<#CLIENT_AUTHORIZATION#>")!
let cardClient = BTCardClient(apiClient: braintreeClient)
let card = BTCard.init()
card.number = "4111111111111111"
card.expirationMonth = "12"
card.expirationYear = "2018"
card.cvv = "111"
card.postalCode = "94107"

cardClient.tokenizeCard(card) { (tokenizedCard, error) in
// Communicate the tokenizedCard.nonce to your server, or handle error
}

这样 BTCard 对象就会返回可接受的 key ...我花了几个小时尝试不同的方法才得到这个答案。 Braintree 和他们的文档没有提供此示例,但这是对我有用的唯一方法。

(您的每个后端可能会在将数据发送到 Braintree 之前对其进行整理,但这在您集成时会有所帮助)

关于swift - 如何在 BTCard 中设置信用卡可选数据,以便 Braintree 后端在 swift 4 中提供有效 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56927610/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com