Skip to content

Instantly share code, notes, and snippets.

@mbeale
Last active December 12, 2015 08:08
Show Gist options
  • Save mbeale/4741709 to your computer and use it in GitHub Desktop.
Save mbeale/4741709 to your computer and use it in GitHub Desktop.
Complete example for PHP Recurly.js BuildSubscriptionForm
<?php
require_once('recurlyphp/lib/recurly.php');
// Required for the API
Recurly_Client::$subdomain = 'yoursubdomain'
Recurly_Client::$apiKey = 'apikey';
Recurly_js::$privateKey = 'privatekey';
$signature = Recurly_js::sign(array('account'=>array('account_code'=>'aaa1234588'),'subscription' => array(
'plan_code' => 'plan_trial',
'currency'=>'USD',
'trial_ends_at'=>'Tuesday, January 29, 2013 12:00:00 PM GMT -8')));
?>
<html>
<head>
<link href="recurlyjs/themes/default/recurly.css" rel="stylesheet">
<script src="js/jquery.js"></script>
<script src="recurlyjs/build/recurly.js"></script>
<script>
$(function(){
Recurly.config({
subdomain: 'yoursubdomain'
, currency: 'USD' // GBP | CAD | EUR, etc...
, enableGeoIp: false
, locale : {
errors : {
invalidCoupon: "Say what? You talkin' crazy"
}
}
});
Recurly.buildSubscriptionForm({
planCode: 'plan_trial',
quantity: 1,
subscription: {
quantity: 1
},
target: '#recurly-form',
successURL: 'success.php',
signature: '<?php echo $signature;?>',
account : {
firstName: 'John',
email: '[email protected]',
lastName: 'Riggins'
},
addressRequirement: 'full',
enableCoupons: true,
billingInfo: {
firstName: 'John',
lastName: 'Smith',
address1: '1234 Some St',
city: 'SomeCity',
zip: '84098',
cardNumber: '4111111111111111',
month: '6',
CVV: '123',
country: 'GB'
},
subscription: {
couponCode: 'testplan'
},
distinguishContactFromBillingInfo: true,
afterInject: function(){
$('.submit').text('Join Playa');
$('div.check').click();
},
collectPhone: true
});
});
</script>
</head>
<body>
<h1>Test Form</h1>
<div id="recurly-form"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment