Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to card brands configured in merchant account in account page #1223

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { onFieldValid, onBrand } = require('./commons');
const { onFieldValid, onBrand, getPaymentMethods } = require('./commons');
const store = require('../../../store');

let checkout;
Expand All @@ -10,32 +10,44 @@ store.checkoutConfiguration.amount = {
currency: 'EUR',
};

store.checkoutConfiguration.paymentMethodsConfiguration = {
card: {
enableStoreDetails: false,
hasHolderName: true,
holderNameRequired: true,
installments: [],
onBrand,
onFieldValid,
onChange(state) {
store.isValid = state.isValid;
store.componentState = state;
async function initializeStoreConfiguration() {
const paymentMethodsData = await getPaymentMethods();
const paymentMethodsResponse = paymentMethodsData.AdyenPaymentMethods;
const cardBrands = paymentMethodsResponse.paymentMethods
.filter((method) => method.type === 'scheme')
.flatMap((method) => method.brands || []);

store.checkoutConfiguration.paymentMethodsConfiguration = {
card: {
enableStoreDetails: false,
hasHolderName: true,
holderNameRequired: true,
installments: [],
onBrand,
onFieldValid,
brands: cardBrands,
onChange(state) {
store.isValid = state.isValid;
store.componentState = state;
},
},
},
};
};
}

async function initializeCardComponent() {
const cardNode = document.getElementById('card');
checkout = await AdyenCheckout(store.checkoutConfiguration);
card = checkout.create('card').mount(cardNode);
}

// Handle Payment action
function handleAction(action) {
checkout.createFromAction(action).mount('#action-container');
$('#action-modal').modal({ backdrop: 'static', keyboard: false });
}

// confirm onAdditionalDetails event and paymentsDetails response
store.checkoutConfiguration.onAdditionalDetails = (state) => {
const requestData = JSON.stringify({
data: state.data,
});
const requestData = JSON.stringify({ data: state.data });
$.ajax({
type: 'POST',
url: window.paymentsDetailsURL,
Expand All @@ -57,12 +69,6 @@ store.checkoutConfiguration.onAdditionalDetails = (state) => {
});
};

async function initializeCardComponent() {
const cardNode = document.getElementById('card');
checkout = await AdyenCheckout(store.checkoutConfiguration);
card = checkout.create('card').mount(cardNode);
}

let formErrorsExist = false;

function submitAddCard() {
Expand All @@ -84,9 +90,11 @@ function submitAddCard() {
});
}

initializeCardComponent();
(async () => {
await initializeStoreConfiguration();
await initializeCardComponent();
})();

// Add Payment Button event handler
$('button[value="add-new-payment"]').on('click', (event) => {
if (store.isValid) {
document.querySelector('#adyenStateData').value = JSON.stringify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
};
window.redirectUrl = "${URLUtils.url('PaymentInstruments-List')}";
window.paymentsDetailsURL = "${URLUtils.https('Adyen-PaymentsDetails')}";
window.getPaymentMethodsURL = "${URLUtils.https('Adyen-GetPaymentMethods')}";
</script>
<form
action="${URLUtils.url('PaymentInstruments-SavePayment', 'UUID', pdict.UUID)}"
Expand Down
3 changes: 3 additions & 0 deletions tests/playwright/pages/CheckoutPageSFRA5.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export default class CheckoutPageSFRA5 {
await this.successMessage.waitFor({ visible: true });

await this.navigateToCheckout(locale);
if (this.consentButton.isVisible()) {
this.consentButton.click();
}
await this.checkoutGuest.click();
};

Expand Down
Loading