API
On this page, you can learn what public API we share.
@vsf-enterprise/adyen-commercetoolsexports a useAdyen composable.@vsf-enterprise/adyen-commercetools/src/PaymentAdyenProviderexports a VSF Payment Provider (opens new window) component as a default.
useAdyen composable
useAdyen composable contains properties and methods described below.
<script>
import { useAdyen } from '@vsf-enterprise/adyen-commercetools';
export default {
setup() {
const {
error,
loading,
paymentObject,
createContext,
buildDropinConfiguration,
payAndOrder,
submitAdditionalPaymentDetails
} = useAdyen();
}
};
</script>
Properties
error- Computed<AdyenError> - object containing errors' from asynchronous methods.loading- Computed<Boolean> - a boolean value that indicates whether any async methods are pending.paymentObject- Computed<any> - contains payment object from the commercetools. It's value is updated bycreateContext,payAndOrder,submitAdditionalPaymentDetailsmethods described below.
interface AdyenError {
submitAdditionalPaymentDetails: Error | null,
createContext: Error | null,
payAndOrder: Error | null
}
Methods
createContext- Loads a cart, then fetches available payment methods for the loaded cart and saves the response in thepaymentObjectobject.buildDropinConfiguration-(config: AdyenConfigBuilder): any- Builds a configuration object for Adyen's Web Drop-In.payAndOrder- Sets a value of the custom field namedmakePaymentRequestin the commercetools' payment object. Commercetools will send it to the Adyen and save the response in thepaymentObjectobject.submitAdditionalPaymentDetails- Sets a value of the custom field namedsubmitAdditionalPaymentDetailsRequestin the commercetools' payment object. Commercetools will send it to the Adyen and save the response in thepaymentObjectobject.
interface AdyenConfigBuilder {
paymentMethodsResponse,
onChange = (state, component) => {},
onSubmit = (state, component) => {},
onAdditionalDetails = (state, component) => {},
onError = (state) => {},
onCancel = (state) => {}
}
Components
PaymentAdyenProvider component fetches available payment methods and mounts Adyen's Web Drop-In. It takes care of the whole flow of the payment. It allows you to hook into specific events by passing functions via props:
<template>
<PaymentAdyenProvider
:afterPay="afterPayAndOrder"
/>
</template>
<script>
import {
useCart
} from '@vsf-enterprise/commercetools';
import PaymentAdyenProvider from '@vsf-enterprise/adyen-commercetools/src/PaymentAdyenProvider';
export default {
components: {
PaymentAdyenProvider
},
setup(_, context) {
const { cart, load, setCart } = useCart();
const afterPayAndOrder = async ({ order }) => {
context.root.$router.push(`/checkout/thank-you?order=${order.id}`);
setCart(null);
};
return {
afterPayAndOrder
}
}
}
</script>
beforeLoad-config => Promise<config>- Called just before creating an instance of theAdyenCheckoutand mounting a Drop-In.beforePay-(stateData, adyenHookName: 'onSubmit'|'onAdditionalDetails') => Promise<stateData>- Called just before calling apayAndOrderorsubmitAdditionalPaymentDetails. You can modify the payload inside of it before it's sent to Adyen. If you returnfalsehere then you will prevent payment.afterPay-paymentAndObject: PaymentAndOrder => Promise<void>- Called after when the result code from the Adyen isAuthorizedand an order has been placed.afterSelectedDetailsChange- Called insideonChangeof Adyen's Drop-In.onError-(data: { action: string, error: Error | string }) => Promise<void>- Called when there is an error from either Adyen or Vue Storefront API.
The component has three named slots. The first is called payment-refused. It is a message in the box that shows above Adyen's Drop-in just after you provide wrong credentials for non-3DS card (e.g. 4646 4646 4646 4644 03/30 with wrong CVC). You can use it to change the message and the whole box.
<PaymentAdyenProvider
:afterPay="afterPayAndOrder"
>
<template #payment-refused>
My custom message!
</template>
</PaymentAdyenProvider>
The second is called price-mismatch. It is a message in the box that shows above Adyen's Drop-in if price of your cart has been changed since payment has been initialized. It might happen if you modify the cart. Our integration will handle change, generate new payment object and ask user to provide payment details once again with refreshed price. You can use it to change the message and the whole box.
<PaymentAdyenProvider
:afterPay="afterPayAndOrder"
>
<template #price-mismatch>
My custom message!
</template>
</PaymentAdyenProvider>
The third is called payment-refused-by-beforePay. It is a message in the box that shows above Adyen's Drop-in just after you return false in beforePay hook.
<PaymentAdyenProvider
:afterPay="afterPayAndOrder"
>
<template #payment-refused-by-beforePay>
My custom message!
</template>
</PaymentAdyenProvider>