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
Show file tree
Hide file tree
Changes from 4 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
53 changes: 45 additions & 8 deletions public/bank-redirect/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>Bank Redirect Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- <script src="https://js.recurly.com/v4/recurly.js"></script> -->
<script src="https://js.recurly.com/v4/recurly.js"></script>
<script src="/config"></script>
</head>
Expand All @@ -15,6 +16,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 +27,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 +45,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,17 +89,19 @@ <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() {
let payment_type = document.querySelector('#payment_method_type').value;

let isIdeal = payment_type === 'ideal';

let isSofort = payment_type === 'sofort';

const iframe = bankRedirect.start({
payment_method_type: document.querySelector('#payment_method_type').value,
invoice_uuid: document.querySelector('#invoice_uuid').value,
issuer_id: document.querySelector('#bank').value
...(isIdeal && { issuer_id: document.querySelector('#bank').value }),
...(isSofort && { country_code: document.querySelector('#country').value })
});
}
</script>
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ <h1>Examples</h1>
<li><a href="advanced-bank-account/index.html">Advanced bank account</a></li>
<li><a href="apple-pay/index.html">Apple Pay</a></li>
<li><a href="bank-redirect/index.html">Bank Redirect</a></li>
<li><a href="bank-redirect/sofort/index.html">Sofort</a></li>
<li><a href="paypal/index.html">PayPal</a></li>
<li><a href="fraud-detection/recurly-kount.html">Fraud detection (Recurly and Kount direct integrations)</a></li>
<li><a href="fraud-detection/braintree.html">Fraud detection (Braintree integration)</a></li>
Expand Down