ios - Stripe 织物 iOS 集成

标签 ios swift stripe-payments twitter-fabric

我正在尝试使用 Fabric 设置 Stripe,我的第一步当然是接受用户的信用卡信息。使用下面的代码,“提交”按钮在应该启用时启用,但在单击按钮时应用程序崩溃。错误消息是“由于未捕获的异常‘NSInvalidArgumentException’而终止应用程序,原因:‘-[Stripe3.ViewController submitCard:]:无法识别的选择器发送到实例 0x7fe83740dbd0’”

我将不胜感激任何见解!

class ViewController: UIViewController, STPPaymentCardTextFieldDelegate{

var paymentTextField: STPPaymentCardTextField! = nil
var submitButton: UIButton! = nil


override func viewDidLoad() {
    super.viewDidLoad()
    paymentTextField = STPPaymentCardTextField(frame: CGRectMake(15, 30, view.frame.width - 30, 44))
    paymentTextField.delegate = self
    view.addSubview(paymentTextField)
    submitButton = UIButton(type: UIButtonType.system)
    submitButton.frame = CGRectMake(15, 100, 100, 44)
    submitButton.isEnabled = false
    submitButton.setTitle("Submit", for: UIControlState.normal)

    submitButton.addTarget(self, action: Selector(("submitCard:")), for: UIControlEvents.touchUpInside)

    view.addSubview(submitButton)

    // Do any additional setup after loading the view, typically from a nib.
}

func paymentCardTextFieldDidChange(_ textField: STPPaymentCardTextField) {
    submitButton.isEnabled = textField.valid
}

@IBAction func submitCard(sender: AnyObject?) {
    // If you have your own form for getting credit card information, you can construct
    // your own STPCardParams from number, month, year, and CVV.
    let card = paymentTextField.card!

    STPAPIClient.shared().createToken(withCard: card) { token, error in
        guard let stripeToken = token else {
            NSLog("Error creating token: %@", error!.localizedDescription);
            return
        }

        // TODO: send the token to your server so it can create a charge
        let alert = UIAlertController(title: "Welcome to Stripe", message: "Token created: \(stripeToken)", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
        self.present(alert, animated: true, completion: nil)
    }
}

最佳答案

确保您已将按钮 Storyboard的操作正确链接到正确的 UIViewController 子类中的正确 IBAction。有时这只是 Storyboard 的场景/UI 组件复制/粘贴错误的问题。

关于ios - Stripe 织物 iOS 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40601515/

相关文章:

ios - UICollection查看一个部分中的多个行距值

ruby-on-rails - Stripe Connect - 检索访问 token

google-cloud-functions - 将 Google Secret Manager 与 Firebase Functions 和 Stripe 结合使用(顶级)

swift - 这些快速代码行有何不同?

stripe-payments - Stripe CLI 触发具有特定 ID 的支付意图

IOS - 外部 (hdmi) 输出仅占屏幕的一半,手动编码 View 时除外

ios - 在 Foursquare 的列表 API 上使用 RKDynamicMapping 来捕获列表

iphone - 配置门户上开发和分发配置文件的区别?

ios - ViewWillAppear 中的代码不起作用,为什么?

swift - 像 Apple Weather 应用程序一样的击键位置查找