stripe / stripe-ios

Stripe iOS SDK
https://stripe.com
MIT License
2.11k stars 976 forks source link

didCreateToken method not invoked #1400

Closed greggmojica closed 4 years ago

greggmojica commented 5 years ago

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!

yuki-stripe commented 5 years ago

Hi @greggmojica,

Could you share the version of the SDK you're using? didCreateToken was deprecated in v16

greggmojica commented 5 years ago

@yuki-stripe I'm using the latest version from cocoapods. If this method is deprecated, how can one generate a token using the STPAddCardViewController currently?

yuki-stripe commented 5 years ago

@greggmojica It's no longer possible - since version 16, STPAddCardViewController and other UI components migrated from Tokens/Sources to PaymentMethods. I recommend you migrate to the Payment Methods + Payment Intents API. This is especially important if you're affected by SCA.

If you can't migrate to PaymentMethods, I recommend you use a version prior to v16.

Igorsnaki commented 4 years ago

@yuki-stripe Hi , I also have the same issue. I used 15.0.1 ios Stripe sdk and use method -

(void)addCardViewController:(STPAddCardViewController )addCardViewController didCreateToken:(STPToken )token completion:(STPErrorBlock)completion

I need token.tokenId

but starting from Xcode 11.4 - ios Stripe SDK doesn't compile.

You fix this only in 19.0.1

Could you please help me?

Can I somehow get token.tokenId ( which I get in didCreateToken method) from paymentMethod ???

abdulmanan-whizpool commented 4 years ago

// Pass it to STPAPIClient to create a Token STPAPIClient.shared().createToken(withCard: cardParams) { token, error in guard let token = token else { // Handle the error return } let tokenID = token.tokenId // Send the token identifier to your server... print(token) } this method returns token but you have to add card values Manually