swift如何获得Stripe令牌?

时间:2018-03-23 06:25:12

标签: ios swift stripe-payments

我想实施 Stripe 付款网关。并且需要生成令牌并将其传递给后端。

     import Stripe
       class AppDelegate: UIResponder, UIApplicationDelegate{

       // var navCon: UINavigationController?
        var window: UIWindow?
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application la
             STPPaymentConfiguration.shared().publishableKey = "pk_test_DSFDSFSDFDFSDFSDFDSDSF"

            return true
        }
}

1 个答案:

答案 0 :(得分:3)

确保您需要添加条纹 publishableKey(实时/测试)

AppDelegate.swift

STPPaymentCardTextFieldDelegate

在我的 PaymentView.swift

注意:使用class PaymentView: UIViewController,STPPaymentCardTextFieldDelegate { @IBOutlet weak var paymentCardTextField = STPPaymentCardTextField() } private func getToken(){ let cardParams = STPCardParams() cardParams.number = paymentCardTextField?.cardNumber cardParams.expMonth = (paymentCardTextField?.expirationMonth)! cardParams.expYear = (paymentCardTextField?.expirationYear)! cardParams.cvc = paymentCardTextField?.cvc STPAPIClient.shared().createToken(withCard: cardParams) { (token: STPToken?, error: Error?) in guard let token = token, error == nil else { // Present error to user... return } self.dictPayData["stripe_token"] = token.tokenId print(self.dictPayData) } } 进行卡片验证。

  <span data-toggle="modal" data-target="#forgot-pin-popup" data-dismiss="modal">Forgot password?</span>