Broadleaf Microservices
  • v1.0.0-latest-prod

Saved Payment Methods With Adyen

With current integration, saved payment methods are stored via Adyen, and no saved payment methods are stored in Broadleaf.

Create/Use a Saved Payment Method at Checkout

With our integration, we leverage Adyen’s Drop-in UI to create & gather saved payment methods for registered customers.

Once a user is logged, additional parameters will automatically be passed during session creation to declare the shopperReference. See DefaultAdyenSessionService#addSavedPaymentMethodAttributes(…​):

    protected void addSavedPaymentMethodAttributes(
            CreateCheckoutSessionRequest createCheckoutSessionRequest,
            SessionRequest request) {
        createCheckoutSessionRequest.setShopperReference(request.getCustomerId());
        createCheckoutSessionRequest.setShopperInteraction(SHOPPER_INTERACTION_ECOMMERCE);
        createCheckoutSessionRequest
                .setRecurringProcessingModel(request.getRecurringProcessingModel());
        createCheckoutSessionRequest.setStorePaymentMethodMode(request.getStorePaymentMethodMode());
    }

storedPaymentMethodMode can be either askForConsent (exposing a checkbox allowing the customer to opt-into saving the payment method), or enabled if you wish to always store payment method. From there, when executing an Authorize or AuthorizeAndCapture transaction, additional data is provided declaring the creation or usage of a saved payment method.

            if (adyenPaymentRequest.getCustomerId() != null) {
                adyenRequest.put(SHOPPER_REFERENCE, adyenPaymentRequest.getCustomerId());
                adyenRequest.put(SHOPPER_INTERACTION, SHOPPER_INTERACTION_ECOMMERCE);
                adyenRequest.put(RECURRING_PROCESSING_MODEL,
                        getRecurringProcessingModel(adyenPaymentRequest));
                if (adyenPaymentData.containsKey(STORE_PAYMENT_METHOD)) {
                    adyenRequest.put(STORE_PAYMENT_METHOD,
                            adyenPaymentData.get(STORE_PAYMENT_METHOD));
                }

                Map<String, Object> paymentMethod =
                        (Map<String, Object>) adyenPaymentData.get("paymentMethod");

                if (paymentMethod != null && paymentMethod.containsKey("storedPaymentMethodId")) {
                    // customer uses the stored payment method, set ContAuth to shopperInteraction
                    adyenRequest.put(SHOPPER_INTERACTION, SHOPPER_INTERACTION_CONT_AUTH);
                }
            }

Creating/managing saved payment methods via the "My Account" section

Customers also have the ability to manage their Adyen saved payment methods via their My Account section. For these use cases, Broadleaf provides endpoints that serve as a proxy, adding the authorized customer’s id for read & delete interactions. This proxy helps to ensure that customers can only access their own information, & do not gain access to another user’s saved payment methods.

These endpoints are mapped on adyen/saved-payment-methods and support GET and DELETE methods. See com.broadleafcommerce.adyen.web.endpoint.AdyenStoredPaymentMethodsEndpoint.

For creating a new saved payment method in a My Account context, our recommendation is that you execute a $0 Authorization using the Adyen Session flow with the Drop-in UI. Keep in mind that the Drop-in UI will want to render all available payment methods as configured with the Merchant Account. Therefore, you’ll need to override this behavior when initializing the Drop-in UI to ensure that irrelevant payment methods are not shown.