如何解决条纹付款方式未保存-iOS和Firebase
我正试图为分行客户保存一张信用卡,但是,当我实施分行提供的测试卡时(42424242 ...),我收到消息:“您的卡已被拒绝”。
这是我试图解决的问题:
- 请确保使用我的测试密钥,而不是实时的
- 尝试过国际信用卡(因为我位于墨西哥)
- 确保我得到了临时密钥
- 尝试使用真实的信用卡进行实时测试,即使我除了输入信用卡而不要求收取任何费用外,我仍然收到消息“您的卡已被拒绝”
注意:我正在关注的教程使用了一种名为.createCardSources = true的方法,但是,我认为它已被贬值。
这是我的功能:
func setupStripeConfig() {
//2.) Create stripe payment configuration
let config = STPPaymentConfiguration.shared()
#warning(".createCard sources not appearing")
// config.createCardSources --> Doesn't show
config.requiredBillingAddressFields = .none
//1.)we need that customer context found in Stripe Api
//this will invoke the cloud function,generate the ephemeral key,pass it back and this customer context class will prefetch the stripe customer's information from it's stripe object (say saved credit cards)
let customerContext = STPCustomerContext(keyProvider: StripeApi)
//3.)now we need to create stripe payment context
paymentContext = STPPaymentContext(customerContext: customerContext,configuration: config,theme: .default())
//4.) Set payment context,payment amount
paymentContext.paymentAmount = self.stripeTotal!
//5.)Set payment context & delegate
paymentContext.delegate = self
paymentContext.hostViewController = self
}
我正在接收临时密钥,所以这不应该成为问题,但是我还将代码放在这里:
import Foundation
import Stripe
import FirebaseFunctions
let StripeApi = _StripeApi()
class _StripeApi: NSObject,STPEphemeralKeyProvider {
func createCustomerKey(withAPIVersion apiVersion: String,completion: @escaping STPJSONResponseCompletionBlock) {
//data object
let data = [
"stripe_version": apiVersion,"customer_id": UserService.user.stripeId
]
print("API VERSION: \(apiVersion)")
print("CUSTOMER ID: \(UserService.user.stripeId)")
//This will invoke our cloud function
//you need to create a data object and then pass it to this function
Functions.functions().httpsCallable("createEphemeralKey").call(data) { (result,error) in
//ephemeral key should be found in result
if let error = error {
print("Error in StripeApi.swift \(error)")
//if we have an error we will need to pass completion (nil for json) and error for error
completion(nil,error)
return
}
guard let key = result?.data as? [String: Any] else {
completion(nil,nil)
return
}
//if we do get the key,we'll pass it over in completion and put nil for error
completion(key,nil)
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。