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

[FK-1277] Add recurly integration example for sofort #100

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
58 changes: 48 additions & 10 deletions public/bank-redirect/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ <h1>Bank Redirect</h1>
<div>
Payment Method Type:
<select id="payment_method_type" name="payment_method_type">
<option hidden disabled selected></option>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

<option value="sofort">sofort</option>
<option value="ideal">ideal</option>
</select>
</div>
Expand All @@ -24,7 +26,12 @@ <h1>Bank Redirect</h1>
<input id="invoice_uuid" name="invoice_uuid">
</div>

<div>
<div id="country_el" style="display: none">
Country:
<select id="country" name="country"></select>
</div>

<div id="bank_el" style="display: none">
Bank:
<select id="bank" name="bank"></select>
</div>
Expand All @@ -37,13 +44,40 @@ <h1>Bank Redirect</h1>
recurly.configure(window.recurlyConfig.publicKey);

// Create BankRedirect instance
var bankRedirect = recurly.BankRedirect();
const bankRedirect = recurly.BankRedirect();

const paymentMethod = document.getElementById('payment_method_type');

const country = document.getElementById('country_el');

const bank = document.getElementById('bank_el');

paymentMethod.addEventListener('change', () => {
if (event.target.value === 'sofort') {
country.style.display = 'block';
bank.style.display = 'none';
bankRedirect.loadCountries({
payment_method_type: document.querySelector('#payment_method_type').value
}, '#country');
} else if (event.target.value === 'ideal') {
country.style.display = 'none';
bank.style.display = 'block';
bankRedirect.loadBanks({
payment_method_type: document.querySelector('#payment_method_type').value
}, '#bank');
}
})

// If an error occurs, log it
bankRedirect.on('error', function (error) {
console.error('ERROR: ', error);
});

// Listen for successful countries response
bankRedirect.on('countries', function (countries) {
console.log('COUNTRIES: ', countries);
});

// Listen for successful banks response
bankRedirect.on('banks', function (banks) {
console.log('BANKS: ', banks);
Expand All @@ -54,18 +88,22 @@ <h1>Bank Redirect</h1>
console.error('Banks ERROR: ', error);
});

// load banks on the #bank selector
bankRedirect.loadBanks({
payment_method_type: document.querySelector('#payment_method_type').value
}, '#bank')

// Start
function start() {
const iframe = bankRedirect.start({
let payment_type = document.querySelector('#payment_method_type').value;

let isIdeal = payment_type === 'ideal';

const payload = {
payment_method_type: document.querySelector('#payment_method_type').value,
invoice_uuid: document.querySelector('#invoice_uuid').value,
issuer_id: document.querySelector('#bank').value
});
}

const addDetails = isIdeal ?
{ issuer_id: document.querySelector('#bank').value } :
{ country_code: document.querySelector('#country').value };

const iframe = bankRedirect.start(Object.assign(payload, addDetails));
}
</script>
</body>
Expand Down