Adyen / adyen-ios

Adyen iOS Drop-in and Components
https://docs.adyen.com/checkout/ios
MIT License
150 stars 118 forks source link

Accessing stored payment information #60

Closed StanleyOned closed 5 years ago

StanleyOned commented 5 years ago

Hello Again,

Previously I submitted an issue regarding storing the user payment information. But I ran into another problem, how can I access the store payment information and confirm a purchase with the stored payment information.

This is what I have right now

        guard let storedDetails = paymentMethod?.storedDetails as? StoredCardPaymentDetails else {
            return
        }
        cardDetails = CardDetails(name: storedDetails.holderName,
                                  number: storedDetails.number,
                                  expiryMonth: String(storedDetails.expiryMonth),
                                  expiryYear: String(storedDetails.expiryYear),
                                  cvc: "737",
                                  shouldStoreDetails: true)

    }

I cannot send the payment because I only get back the encoded information. Also, the storedDetails.holderName doesn't quite match with what I inputted previously which was John Smith Screen Shot 2019-03-12 at 4 23 04 PM

joostvandijk commented 5 years ago

Hi @StanleyOned,

To initiate a payment with a stored payment method, simply pass the entire PaymentMethod in the selectPaymentMethod's selection handler.

The storedDetails in a stored payment method are simply for display purposes.

If the holder name is incorrect, it's likely not passed to the SDK correctly. If you don't have it yet, add the following to your /paymentSession call:

"configuration": {
    "cardHolderName": "required"
}

This will make the SDK collect the holder name field.

With kind regards,

Joost

StanleyOned commented 5 years ago

Hello @joostvandijk,

I tried passing the stored payment method but it ends up failing in the didFinish method. Heres what I have:

func selectPaymentMethod(from paymentMethods: SectionedPaymentMethods, for paymentController: PaymentController, selectionHandler: @escaping (PaymentMethod) -> ()) {
        if !paymentMethods.preferred.isEmpty {
            paymentMethod = paymentMethods.preferred.first
            selectionHandler(paymentMethod!)
            return
        } else {
            paymentMethod = paymentMethods.other.first
        }
        paymentMethodCompletion = selectionHandler
    }

Can you please provide details information, if you don't mind.

Thank you!

Stanle

joostvandijk commented 5 years ago

Hi @StanleyOned,

I think you are forgetting to set the payment details. You can check which details are being asked by looking in the payment method's details.

Note that for stored cards, you still need to ask the user to enter the CVC.

With kind regards,

Joost

StanleyOned commented 5 years ago

@joostvandijk I figured it out! Thank you for helping me!

joostvandijk commented 5 years ago

No problem! Feel free to contact us afain if you have any questions.