swift STPPaymentMethod文本字段不接受任何编程卡号

5us2dqdw  于 2023-01-29  发布在  Swift
关注(0)|答案(1)|浏览(129)

我最近在我的项目中安装了pod StripeCardScan。我能够让它正常工作,但是,它不可能让STPPaymentCardTextField接受任何编程输入,从卡扫描或只是使用手动let语句。我在谷歌上搜索并回顾了几篇关于这方面的文章,但是我觉得我遗漏了一些东西。2我想知道我是否需要为这个类设置一个代理人?
下面是我尝试使用的代码,把扫描卡到号码字段:

cardScanSheet.present(from: self) { [weak self] result in
        var title = ""
        var message = ""
        
        switch result {
        case .completed(let card):
            title = "Scan Completed"
            message = card.pan
            let cardParams = STPPaymentMethodCardParams()
            cardParams.number = card.pan
            //cardParams.number = "4511554566354474".  <- Even when doing this manually, it still does not take
            self?.addCardView.cardField.paymentMethodParams.card = cardParams
            print("card [pam \(card.pan)")
        case .canceled:
            title = "Scan Canceled"
            message = "Canceled the scan"
        case .failed(let error):
            title = "Scan Failed"
            message = "Failed with error: \(error.localizedDescription)"
        }
wlzqhblo

wlzqhblo1#

我想你还需要一个STPPaymentMethodParams的示例来编程设置卡号。你试过跟随吗?

let cardParams = STPPaymentMethodCardParams()
cardParams.number = card.pan
let paymentMethodParams = STPPaymentMethodParams.init(card: cardParams, billingDetails: STPPaymentMethodBillingDetails(), metadata: [:])
self?.addCardView.cardField.paymentMethodParams = paymentMethodParams ```

相关问题