Closed ghost closed 5 years ago
Hi @monwa12345678,
The issue here is that getPaymentMethodHandler()
expects a PaymentMethod object, and the getOneClickPaymentMethods()
returns a list with possibly several PaymentMethods.
My suggestion would be for you to check both getOneClickPaymentMethods()
and getPaymentMethods()
, because the oneCLick is only available if the shopper has already input their credit card details previously and chose to save them, otherwise it will be empty.
Then iterate on that list and look for payment methods that have a group which is of type card. That happens because there are several types of cards but we group them together using the group reference, and that group should be used to start a generic card payment instead.
This is a quick solution you can use as reference, although it's not perfect and you can modify it as you see fit.
// inside your StartPaymentParametersHandler
PaymentMethod creditCard = getCreditCard(startPaymentParameters.getPaymentSession().getPaymentMethods());
if (creditCard != null) {
PaymentMethodHandler cardHandler = CheckoutController.getPaymentMethodHandler(MainActivity.this, startPaymentParameters.getPaymentReference(), creditCard);
if (cardHandler != null) {
cardHandler.handlePaymentMethodDetails(MainActivity.this, REQUEST_CODE_CHECKOUT);
}
}
// helper method
@Nullable
private PaymentMethod getCreditCard(List<PaymentMethod> paymentMethodList) {
for (PaymentMethod paymentMethod : paymentMethodList) {
if (paymentMethod.getGroup() != null) {
if (PaymentMethodTypes.CARD.equals(paymentMethod.getGroup().getType())) {
return paymentMethod.getGroup();
}
}
}
return null;
}
Hope this helps :)
Thanks! You are a legend. It worked!
Hi! Could I please have some assistance in reference to https://github.com/Adyen/adyen-android/issues/36. I am new to Native Android Java (Java all together)! I am trying to integrate the Adyen UI but I am having issues with the proposed solution. The error I get is;
Are you able to revisit this issue maybe with an example or illustration on how to implement. Thanks!