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 3 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
69 changes: 69 additions & 0 deletions public/bank-redirect/sofort/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html>

<head>
<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.lvh.me:8020/build/recurly.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll want to restore this to using the production recurly.js

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely! Wanted to just get it up for now in case others wanted to use it to test out RJS changes as we make 'em

<script>window.recurlyConfig = {
publicKey: 'qa2-p14FypnEc7sShkm9ESVPia'
Copy link
Contributor

Choose a reason for hiding this comment

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

Use <script src="/config"></script> instead of hard coding this value. The /config route will cover setting this variable for you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was having trouble getting this to work previously, I'll have to play with it again!

}</script>
</head>

<body>
<h1>Bank Redirect</h1>
<form onsubmit="return false;">
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't the form actually submitting to the backend?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually took this as a base from @cyberxander90 and his ideal example. My guess is we don't actually want to be submitting a call to the backend directly, we want to call the bankRedirect.start method that makes the call and outputs our redirect window in an iframe

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

... but onsubmit could do that too? hmmm

Copy link
Contributor

Choose a reason for hiding this comment

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

it could be both ways, we can call the start() function on the submit event, my first approach was avoid the submit to avoid reload the page.

<div>
Payment Method Type:
<select id="payment_method_type" name="payment_method_type">
<option value="sofort">sofort</option>
</select>
</div>

<div>
Invoice UUID:
<input id="invoice_uuid" name="invoice_uuid">
</div>

<div>
Country:
<select id="country" name="country"></select>
</div>

<button onclick="start()">Start</button>
</form>

<script>
// Configure recurly.js -- set this to your own public key
recurly.configure(window.recurlyConfig.publicKey);

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

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

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

// load countries on the #country selector
bankRedirect.loadCountries('#country')

// Start
function start() {
const iframe = bankRedirect.start({
payment_method_type: document.querySelector('#payment_method_type').value,
invoice_uuid: document.querySelector('#invoice_uuid').value,
country_code: document.querySelector('#country').value
});
}
</script>
</body>

</html>
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