Vue Storefront is now Alokai! Learn More
Legacy Adyen commercetools to SDK v2

Legacy Adyen commercetools to SDK v2

We created this migration guide to help you get up and running quickly with the new Adyen integration. If you have any questions, please reach out to us on Discord, or contact your dedicated Alokai Customer Support Contact.

There were breaking changes in v11. If you do not upgrade your extension and notification module to version ^11 payments will not work.

The extension and notification module versions ^11 are not compatible with @vsf-enterprise/adyen-commercetools You must manage the deployment so that compatible versions are deployed together.

See the compatibility matrix to see which versions are compatible with one another.

Prerequisites

Before you start, make sure you have a project that meets the following requirements:

1

Upgrade packages

Install new packages

yarn
yarn add @vue-storefront/sdk @vsf-enterprise/adyen-commercetools-sdk @vsf-enterprise/adyen-commercetools-api

Remove old packages

yarn
yarn remove @vsf-enterprise/adyen-commercetools

2

Update configuration

Remove payment error view

nuxt.config.js
- { 
-   name: 'adyen-payment-error',
-   path: '/adyen-payment-error',
-   component: resolve(__dirname, 'pages/AdyenPaymentError.vue')
- }

Update useRawSource configuration

nuxt.config.js
{
  useRawSource: {
-   dev: ['@vue-storefront/core', '@vsf-enterprise/commercetools', '@vsf-enterprise/adyen-commercetools'],
-   prod: ['@vue-storefront/core', '@vsf-enterprise/commercetools', '@vsf-enterprise/adyen-commercetools'],
+   dev: ['@vue-storefront/core', '@vsf-enterprise/commercetools', '@vsf-enterprise/adyen-commercetools-sdk'],
+   prod: ['@vue-storefront/core', '@vsf-enterprise/commercetools', '@vsf-enterprise/adyen-commercetools-sdk']
  }
}

Remove outdated Adyen module configuration

nuxt.config.js
- ['@vsf-enterprise/adyen-commercetools/nuxt', {
-   availablePaymentMethods: ['scheme', 'paypal', 'ideal', 'klarna', 'klarna_account', 'klarna_paynow', 'paywithgoogle'],
-   clientKey: '****',
-   environment: 'test',
-   recurringPayments: true,
-   methods: {
-     paypal: {
-       merchantId: '****',
-       intent: 'authorize'
-     }
-   }
- }],

Update Adyen commercetools integration's configuration in middleware.config.js

middleware.config.js
adyen: {
- location: '@vsf-enterprise/adyen-commercetools/server',
+ location: '@vsf-enterprise/adyen-commercetools-api/server',
  configuration: {
    ctApi: {
      apiHost: '<API_HOST>',
      authHost: '<AUTH_HOST>',
      projectKey: '<PROJECT_KEY>
      clientId: '<CLIENT_ID',
      clientSecret: '<CLIENT_SECRET>',
-     scopes: ['manage_project:<CT_PROJECT_KEY>']
+     scopes: ['manage_payments:<CT_PROJECT_KEY>', 'manage_orders:<CT_PROJECT_KEY>', 'view_types:<CT_PROJECT_KEY>']
    },
    adyenApiKey: '<ADYEN_API_KEY>',
    adyenMerchantAccount: '<ADYEN_MERCHANT_ACCOUNT>',
-   adyenRecurringApiBaseUrl: 'https://pal-test.adyen.com',
-   adyenCheckoutApiBaseUrl: '<ADYEN_CHECKOUT_API_BASE_URL>',
+   adyenEnvironment: 'TEST',
+   integrationName: 'adyen',
+   origin: 'https://my-alokai-frontend.local', // URL of frontend
-   buildRedirectUrlAfterAuth: (paymentAndOrder) => `/checkout/thank-you?paymentId=${paymentAndOrder.id}`,
-   buildRedirectUrlAfterError: () => '/adyen-payment-error'
-   buildCustomPaymentAttributes: (client: CommercetoolsClient & { cartId: string, paymentId: string }): Promise<Record<string, any>> => {},
+   buildCustomPaymentAttributes: (params: BuildCustomPaymentAttributesParams): Promise<Record<string, any>> => {},
  }
}

The signature of the buildCustomPaymentAttributes function changed. But it's still used to extend payload sent to the POST /payments.

Coming back from redirect based payment method

3

Delete pages/AdyenPaymentError.vue

Delete AdyenPaymentError.vue from pages directory

4

Initialize SDK

Create a directory and file for the SDK configuration (@/sdk/index.ts):

It's fine to still use composable to communicate with commercetools. But not for Adyen anymore. We installed both here for simplicity.

sdk/index.ts
import { initSDK, buildModule } from '@vue-storefront/sdk';
import { adyenCtModule } from '@vsf-enterprise/adyen-commercetools-sdk';

export const sdk = initSDK({
  adyen: buildModule(
    adyenCtModule, {
      apiUrl: 'http://localhost/api/adyen',
      adyenClientKey: '<ADYEN_CLIENT_KEY>',
      adyenEnvironment: '<ADYEN_ENV>'
    }
  )
});

5

Update pages/Checkout/Payment.vue

Replace PaymentAdyenProvider in template:

pages/Checkout/Payment.vue
<template>
  ...
  <PaymentAdyenProvider
      :afterPay="afterPayAndOrder"
  />
  ...
</template>

With:

pages/Checkout/Payment.vue
<template>
  ...
  <div id="adyen-payment-element"></div>
  ...
</template>

Import useRoute:

pages/Checkout/Payment.vue
- import { ref, computed, watch, onMounted, useRouter, useContext } from '@nuxtjs/composition-api';
+ import { ref, computed, watch, onMounted, useRoute, useRouter, useContext } from '@nuxtjs/composition-api';

Remove PaymentAdyenProvider import:

pages/Checkout/Payment.vue
- import PaymentAdyenProvider from '@vsf-enterprise/adyen-commercetools/src/PaymentAdyenProvider';

Import sdk:

pages/Checkout/Payment.vue
<script>
import { sdk } from '~/sdk';
</script>

Add useRoute to setup:

pages/Checkout/Payment.vue
<script>
export default {
  setup() {
    const route = useRoute();
    ...
  }
}
</script>

Replace afterPayAndOrder with createAdyenDropin in setup:

Remove afterPayAndOrder function and return statement:

pages/Checkout/Payment.vue
<script>
export default {
  setup() {
    ...
-    const afterPayAndOrder = async ({ order }) => {
-      context.root.$router.push(`/checkout/thank-you?order=${order.id}`);
-      setCart(null);
-    };

    return {
-      afterPayAndOrder,
    ...
  }
}
</script>

Fetch available payment methods and mount payment element:

You don't need to export the sdk variable for the template

Call createAdyenDropin in onMounted.

6

Update the extension and notification module to version ^11.5.1.

You have to update the extension and notification module to version ^11.5.1.

See:

Make sure you also adjusted commercetools custom types to match new shapes from the newest versions of extension and notification module.

7

Extend commercetools cart/order type

8

Setup webhook