Recurly

Recurly.js

Recurly.js allows you to easily embed a PCI compliant order form within your website. Recurly.js is a Javascript library designed to be easily embedded and customized to match your website. The library performs in-line validation, real-time total calculations, and gracefully handles errors. Your customer stays on your website while their billing information is securely sent to Recurly for approval. Because the cardholder data is sent directly to Recurly, your PCI compliance scope is dramatically reduced.

Learn more about Recurly.js and see it in action.

Set your private key

Before using Recurly.js, you must set your private key. Recurly uses the private key to create an HMAC-SHA1 hash, which is used to prevent users from tampering with sensitive data during the request.

Example

Recurly_js::$privateKey = 'abcdef01234567890abcdef01234567890';
Recurly.js.private_key = 'abcdef01234567890abcdef01234567890'
recurly.js.PRIVATE_KEY = 'abcdef01234567890abcdef01234567890'

Create a subscription

Sign the request

The request does not need to be signed to create a new subscription when using Recurly.js v1. For v2, the account_code and plan_code must be signed in your request.

Signature Parameters

Parameter Description
plan_code Plan code for the new subscription Required
account_code Account code Required

Signature Example

$signature = Recurly_js::signSubscription('plan_code', 'account_code');
Recurly.js.sign_subscription 'plan_code', 'account_code'
signature = recurly.js.sign_subscription('plan_code', 'account_code')

Validate the response

Parameter Description
signature Verification signature for the response
account_code Account code
plan_code Plan code for the new subscription
add_on_codes Array of add-ons included with the subscription
coupon_code Coupon code redeemed with the subscription

Validation Example

$recurly_js = new Recurly_js($_POST['recurly_result']);

try {
  $result = $recurly_js->verifySubscription();
} catch (Recurly_ForgedQueryStringError $e) {
  // Private key is invalid or the result was tampered with
}
begin
  Recurly.js.verify_subscription! params[:recurly_result]
rescue Recurly::JS::RequestForgery => e
  # Private key is invalid or the result was tampered with
end
try:
  recurly.js.verify_subscription(params['recurly_result'])
except RequestForgeryError:
  # Private key is invalid or the result was tampered with

Create a one-time transaction

Sign the request

Signature Parameters

Parameter Description
account_code Account code Required
amount_in_cents Amount of the transaction in cents Required
currency 3-letter currency code Required

Signature Example

$signature = Recurly_js::signTransaction(5000, 'USD', 'account_code');
Recurly.js.sign_transaction 50_00, 'USD', 'account_code'
signature = recurly.js.sign_transaction(5000, 'USD', 'account_code')

Validate the response

Parameter Description
signature Verification signature for the response
account_code Account code
plan_code Plan code for the new subscription
add_on_codes Array of add-ons included with the subscription
coupon_code Coupon code redeemed with the subscription

Validation Example

$recurly_js = new Recurly_js($_POST['recurly_result']);

try {
  $result = $recurly_js->verifyTransaction();
} catch (Recurly_ForgedQueryStringError $e) {
  // Private key is invalid or the result was tampered with
}
begin
  Recurly.js.verify_transaction! params[:recurly_result]
rescue Recurly::JS::RequestForgery => e
  # Private key is invalid or the result was tampered with
end
try:
  recurly.js.verify_transaction(params['recurly_result'])
except RequestForgeryError:
  # Private key is invalid or the result was tampered with

Update billing info

Signature Parameters

Parameter Description
account_code Account code Required

Signature Example

$signature = Recurly_js::signBillingInfoUpdate('account_code');
Recurly.js.sign_billing_info 'account_code'
signature = recurly.js.sign_billing_info_update('account_code')

Validate the response

Parameter Description
signature Verification signature for the response
account_code Account code

Validation Example

$recurly_js = new Recurly_js($_POST['recurly_result']);

try {
  $result = $recurly_js->verifyBillingInfoUpdated();
} catch (Recurly_ForgedQueryStringError $e) {
  // Private key is invalid or the result was tampered with
}
begin
  Recurly.js.verify_billing_info! params[:recurly_result]
rescue Recurly::JS::RequestForgery => e
  # Private key is invalid or the result was tampered with
end
try:
  recurly.js.verify_billing_info_update(params['recurly_result'])
except RequestForgeryError:
  # Private key is invalid or the result was tampered with

Parameter Reference

Recurly.js Parameter Reference