Конфигурация первого выполнения чередования платежей
let configuration = STPPaymentConfiguration.shared()
configuration.additionalPaymentMethods = .all
configuration.appleMerchantIdentifier = "Your stripe identifier"
configuration.canDeletePaymentMethods = true
configuration.createCardSources = false
let customerContext = STPCustomerContext(keyProvider: MyAPIClient.sharedClient)
paymentMethodViewController = STPPaymentMethodsViewController(configuration: configuration,
theme: STPTheme.init(),
customerContext: customerContext,
delegate: self)
self.navigationController?.pushViewController(controller, animated: true)
Код Для ApiClient для генерации эфермального ключа
class MyAPIClient: NSObject, STPEphemeralKeyProvider {
static let sharedClient = MyAPIClient()
func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
let url = AppConstant.Server.EPHERMAL_KEY
let user = UserDefaultManager.shared.readUser()
let header: HTTPHeaders = ["api_token": user.apiToken ?? "",
"Content-Type": "application/json"]
Alamofire.request(url,
method: .get,
parameters: [
"api_version": apiVersion,
"id": user.id ?? -1
],
headers: header)
.validate(statusCode: 200..<300)
.responseJSON { responseJSON in
switch responseJSON.result {
case .success(let json):
completion(json as? [String: AnyObject], nil)
case .failure(let error):
completion(nil, error)
}
}
}
}
Затем в методе делегата
func paymentMethodsViewController(_ paymentMethodsViewController: STPPaymentMethodsViewController, didSelect paymentMethod: STPPaymentMethod) {
var paymentStripeId: String?
if let source = paymentMethod as? STPSource {
paymentStripeId = source.stripeID
} else if let card = paymentMethod as? STPCard {
self.stpCard = card
}
}