diff --git a/adyen/services/payments.js b/adyen/services/payments.js index a35d9ec..a1132d9 100644 --- a/adyen/services/payments.js +++ b/adyen/services/payments.js @@ -1,4 +1,6 @@ import AdyenCheckout from '@adyen/adyen-web' +import { formatAddressInAdyenFormat } from "../utils/formatAddress"; +import { getCurrencyValueForApi } from "../utils/parsers"; export class AdyenPaymentsService { order = null @@ -12,6 +14,7 @@ export class AdyenPaymentsService { } async submitPayment() { + const {orderTotal, currency} = this.order const checkout = await AdyenCheckout({ environment: this.adyenSession.ADYEN_ENVIRONMENT, clientKey: this.adyenSession.ADYEN_CLIENT_KEY, @@ -22,10 +25,12 @@ export class AdyenPaymentsService { }) return await checkout.session.submitPayment({ ...this.adyenStateData, + billingAddress: formatAddressInAdyenFormat(this.order.billingAddress), + deliveryAddress: formatAddressInAdyenFormat(this.order.shipments[0].shippingAddress), reference: this.order.orderNo, amount: { - value: this.order.orderTotal * 100, - currency: this.order.currency + value: getCurrencyValueForApi(orderTotal, currency), + currency } }) } diff --git a/adyen/utils/formatAddress.js b/adyen/utils/formatAddress.js new file mode 100644 index 0000000..7b4b02f --- /dev/null +++ b/adyen/utils/formatAddress.js @@ -0,0 +1,12 @@ +const formatAddressInAdyenFormat = (address) => { + return { + city: address?.city || '', + country: address?.countryCode || '', + houseNumberOrName: address?.address2 || '', + postalCode: address?.postalCode || '', + stateOrProvince: address?.stateCode || '', + street: address?.address1 || '' + } +} + +module.exports = {formatAddressInAdyenFormat} \ No newline at end of file