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

标签 swift sdk tokenize braintree credit-card

截至 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/

相关文章:

ios - 在 iOS/Swift 中获取系统正常运行时间

swift - 在 Xcode 6.0 模式中创建环境变量并快速从代码中获取它们

ios - 将我的 Xcode 更新到最新版本会删除我以前安装的 SDK 吗?

java - Lucene,索引已经/外部标记化的标记并定义自己的分析过程

python - 处理带有前导零的标记

ios - 在 View 顶部显示警报 Controller ,Swift

java - 我的 Java SDK 应用程序可以在 BusinessObjects XIr2 中运行吗?

java - android中,开发sdk时如何保护敏感数据或如何对请求进行鉴权

python - 使用 Python 正则表达式中的排列捕获重复子模式

ios - 继续不执行