ios - 如何从braintree支付中获取卡号?
问题描述
我正在为我的项目使用braintree pod,它在获得随机数后运行良好。但我想检索卡图标和卡号的数字。
如何获取 imageView 中的卡片图标和 UILabel 中的卡号?
我使用了两个 pod 文件。
pod 'BraintreeDropIn'
pod 'BraintreeDropIn/UIKit'
我正在使用braintree文档提供的这个功能。
func showDropIn(clientTokenOrTokenizationKey: String) {
let request = BTDropInRequest()
//BTUIKAppearance.darkTheme()
//BTUIKAppearance.sharedInstance().primaryTextColor = UIColor.green
let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
{ (controller, result, error) in
if (error != nil) {
print("ERROR : \(error.debugDescription)")
} else if (result?.isCancelled == true) {
print("CANCELLED")
} else if let result = result {
// Use the BTDropInResult properties to update your UI
//result.paymentOptionType
//result.paymentMethod
//result.paymentIcon
//result.paymentDescription
if let outPut = result.paymentMethod {
print("\nNonce : \(outPut.nonce)")
self.paymentNonce = outPut.nonce
self.paymentCardType = result.paymentDescription.description
}
}
controller.dismiss(animated: true, completion: nil)
}
self.present(dropIn!, animated: true, completion: nil)
}
解决方案
全面披露:我在布伦特里工作。如果您还有其他问题,请随时联系支持人员。
目前,Braintree 的 iOS SDK 不会在结果中返回卡片品牌图标。但是,在属性中包含卡品牌图标的交易响应对象中会返回图像 URL imageUrl
。你可以查看这篇关于如何在 Swift 中显示图片 URL 的要点。或者,type
当返回 nonce 时,客户端上可用。
出于 PCI 合规性的原因,如果您使用 Drop-in UI,则不会向商家公开完整的卡号。lastTwo
相反,如果您将付款方式转换为,iOS SDK 将提供数字BTCardNonce
。斯威夫特的文档有很多关于铸造的好信息。虽然是 Objective-C,但一个例子是:
BTCardNonce *cardNonce = (BTCardNonce*)result.paymentMethod;
或者,您可以maskedNumber
从事务响应对象中获取一个,类似于图像 URL。
已编辑:用于将图像 URL 添加到 Swift 4 的更新链接
推荐阅读
- ios - 创建 textField 允许书面用户输入或用户单击 iOS 中的预填充选项
- c# - 在类库“对象引用未设置为对象的实例”中使用 MEF 导入时收到空异常?
- javascript - NodeJS Forge - 将加密的字节字符串转换为十六进制字符数组
- powershell - Powershell:如何传递变量值,该值在执行的命令变量中赋值
- python - 如何转换日期以构建图表?np.linspace
- python - 如何在 Python 中找到 fit_transform() 后编码值对应的分类名称?
- javascript - 使用命名对象定义数组的打字稿
- android - 为所有平台创建一个模块
- google-apps-script - 由非所有者授权执行 GSheet 脚本
- amazon-web-services - 如何将 ECS 服务注册到另一个堆栈中定义的目标组