Stripe didCreateToken method not invoked

Viewed 354

I'm building a simple app that needs to use stripe for payments. In my viewDidLoad() method I have the following code:

let addCardViewController = STPAddCardViewController()
addCardViewController.delegate = self
navigationController?.pushViewController(addCardViewController, animated: true)

I have the following delegate methods:

extension Checkout: STPAddCardViewControllerDelegate {
    func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
        navigationController?.popViewController(animated: true)
    }

    private func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: @escaping STPErrorBlock) {
        StripeClient.shared.completeCharge(with: token, amount: 50) { result in
            switch result {
                case .success:
                    completion(nil)
                    let alertController = UIAlertController(title: "Congrats", message: "Your payment was successful!", preferredStyle: .alert)
                    let alertAction = UIAlertAction(title: "OK", style: .default, handler: { _ in
                      self.navigationController?.popViewController(animated: true)
                    })
                    alertController.addAction(alertAction)
                    self.present(alertController, animated: true)
            case .failure(let error):
                completion(error)
            }
        }
    }
}

However, the didCreateToken method is never invoked and I'm not sure why. Help would be appreciated!

0 Answers
Related