在 Stripe PaymentOptionViewController 中未调用添加新卡

Add new card is not being called in Stripe PaymentOptionViewController

我正在尝试在 SwiftUI 中实现 Stripe 添加付款方式。因此,用户可以从列表中添加付款方式或 select。经过多天的搜索,我能够实现一个有效的 PaymentOptionsView。但是,当单击添加新卡时,它不会显示用于输入新付款方式的 STPAddCardViewController

这是显示支付选项的代码

import Foundation
import SwiftUI
import Stripe

struct PaymentOptionsView: UIViewControllerRepresentable {
  func makeCoordinator() -> Coordinator {
    Coordinator(self)
 }

class Coordinator: NSObject, STPPaymentOptionsViewControllerDelegate {
    var control: PaymentOptionsView

    init(_ control: PaymentOptionsView) {
        self.control = control
    }

    // Implement required delegate methods here:
    func paymentOptionsViewControllerDidCancel(_ paymentOptionsViewController: STPPaymentOptionsViewController) {

    }

    func paymentOptionsViewControllerDidFinish(_ paymentOptionsViewController: STPPaymentOptionsViewController) {

    }

    func paymentOptionsViewController(_ paymentOptionsViewController: STPPaymentOptionsViewController, didFailToLoadWithError error: Error) {

    }
}

func makeUIViewController(context: UIViewControllerRepresentableContext<PaymentOptionsView>) -> STPPaymentOptionsViewController {
      let config = STPPaymentConfiguration()
      //          config.requiredBillingAddressFields = .none
      config.appleMerchantIdentifier = "dummy-merchant-id"

    return STPPaymentOptionsViewController(configuration: config, theme: STPTheme(), apiAdapter: STPCustomerContext(keyProvider: MyAPIClient()), delegate: context.coordinator)
  }


 func updateUIViewController(_ uiViewController: STPPaymentOptionsViewController, context: UIViewControllerRepresentableContext<PaymentOptionsView>) { }
 }

这里是 APIClient

class MyAPIClient: NSObject, STPCustomerEphemeralKeyProvider {


func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {

    let customerId = "cus_LoK4MNElrbzeVg"
     let url = "https://us-central1-test-mmmm.cloudfunctions.net/app/createEphemeralKey"
    
     
     AF.request(url, method: .post, parameters: [
         "api_version": "2020-08-27",
         "customerId": customerId,
         ])
         .validate(statusCode: 200..<300)
         .responseJSON { responseJSON in
             switch responseJSON.result {
             case .success(let json):
                 completion(json as? [String: AnyObject], nil)
             case .failure(let error):
                 print("Error creating customer Key (retrieving ephemeral key) with Alamofire. See: MyAPIClient - func createCustomerKey")
                 completion(nil, error)
             }
     }
  }
}

我做错了什么以及如何实现添加新卡的方法?

这段代码实际上工作正常。我最初是通过 .sheet(isPresented: 呈现 PaymentOptionsView,因此在按下添加卡按钮时不允许转换到新视图。当 PaymentOptionsView 呈现为

  .background( // add a hidden `NavigationLink` in the background
                          NavigationLink(destination:  PaymentOptionsView(), isActive: $showPaymentSheet) {EmptyView()}
                          .hidden()
                      )

一切正常。当按下添加新卡按钮时,视图完美地过渡到 STPAddCardViewController。