Skip to content

Instantly share code, notes, and snippets.

@em
Created September 27, 2012 22:27
Show Gist options
  • Save em/3796836 to your computer and use it in GitHub Desktop.
Save em/3796836 to your computer and use it in GitHub Desktop.
Recurly.js example using multiple signatures with a single form, so it doesn't lose the user-input
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>RecurlyJS Subscribe Example</title>
<link rel="stylesheet" href="examples.css" type="text/css" />
<link rel="stylesheet" href="../themes/default/recurly.css" type="text/css" />
<script src="../lib/jquery-1.7.1.js"></script>
<script src="../build/recurly.js"></script>
<script>
var signatures = {
a: 'sig A',
b: 'sig B',
c: 'sig C'
};
Recurly.config({
subdomain: 'recurlyjsdemo-test',
currency: 'USD',
signature: signatures.c
});
$(function() {
$('input[type=radio]').change(function() {
var planCode = $(this).val();
Recurly.settings.signature = signatures[planCode];
console.log(planCode);
});
});
Recurly.buildSubscriptionForm({
target: '#recurly-subscribe',
successURL: 'confirmation.html',
planCode: 'simpleplan',
distinguishContactFromBillingInfo: true,
collectCompany: true,
termsOfServiceURL: 'http://example.com/tos',
account: {
firstName: 'Joe',
lastName: 'User',
email: '[email protected]',
phone: '555-555-5555',
companyName: 'Acme'
},
billingInfo: {
firstName: 'Joe',
lastName: 'User',
address1: '123 somestreet',
address2: '45',
city: 'San Francisco',
zip: '94107',
state: 'CA',
country: 'US',
cardNumber: '4111-1111-1111-1111',
CVV: '123'
}
});
</script>
</head>
<body>
<h1>Subscribe to Plan</h1>
<input type="radio" name="group2" value="a"> A<br>
<input type="radio" name="group2" value="b"> B<br>
<input type="radio" name="group2" value="c" checked>C
<div id="recurly-subscribe">
</div>
</body>
</html>
@em
Copy link
Author

em commented Sep 27, 2012

It is important that buildSubscriptionForm() does not have a signature. We control the signature by overwriting Recurly.settings.signature. If there is no signature passed to buildSubscriptionForm, it delegates over to the global.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment