#0Bietnua - iOS error

1 messages · Page 1 of 1 (latest)

dim sun
#

Hello, what is your error?

junior crystal
#

I just wanna get error

#

func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreatePaymentMethod paymentMethod: STPPaymentMethod, completion: @escaping STPErrorBlock) {

#

How to use STPErrorBlock

dim sun
#

Thanks for the info. Looking in to it

junior crystal
#

Thanks so much bro

dim sun
#

Are you already using the completion handler and are trying to get the error message from inside that function?

junior crystal
#

yes

#

func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreatePaymentMethod paymentMethod: STPPaymentMethod, completion: @escaping STPErrorBlock) {
}

#

I can get paymentMethod after creating card but don't know to get the error if have

#

I found that a swift bug, but not sure what is correct way to handle the error now

limpid laurel
#

@junior crystal can I ask you to share a bit more code/context?

#

Then I can ask my team for help (I don't know our iOS SDK)

junior crystal
#

oh no worry

#

I can get error from another function

#

I just wanna know if I can get from above function

#

but seem there is a swift bug

limpid laurel
#

yeah just if you share a bit more code I can then have someone explain how to handle

junior crystal
#

class WalletViewController: AccordionViewController,
STPAddCardViewControllerDelegate {
func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
}

func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreatePaymentMethod paymentMethod: STPPaymentMethod, completion: @escaping STPErrorBlock) {
    
}

}

limpid laurel
#
func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreatePaymentMethod paymentMethod: STPPaymentMethod, completion: @escaping STPErrorBlock) {
    print(paymentMethod)
    
    // using this PaymentMethod, confirm a PaymentIntent client-side
    // set up STPPaymentIntentParams, skipped here
    
    STPAPIClient.shared.confirmPaymentIntent(with: paymentIntentParams, completion: { (paymentIntent, error) in
        // inside the callback of PaymentIntent confirm request
                                                                                     
        if let error = error {
            // an error on confirming PaymentIntent e.g. a card decline
            print(error)
            completion(error) 
            // ^this line calls the completion block on STPAddCardVC to display a UIAlertView with the error
            // https://github.com/stripe/stripe-ios/blob/master/Stripe/STPAddCardViewController.swift#L477-L493
            // so the customer can try a different card

        } else if let paymentIntent = paymentIntent {
            // check if PaymentIntent succeeded here, if so
            // dismiss Stripe's UI with line 22
            // and call delegate method's completion block with `nil` since no error occurred, everything went fine

            addCardViewController.dismiss(animated: true, completion: nil)
            completion(nil)  
        }
    })
}```