我想实施 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
}
}
答案 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>