a recurly v2 api client for node.js
This code is still in development. I don't have complete coverage of the API yet.
An example of typical usage:
var recurly = require'recurring'; // note function invocationrecurlysetAPIKey'your-api-key';var account = ;accountid = 'account-uuid';accountfetchaccountfetchSubscriptionsconsole.logsubscriptions0plan;subscriptions0cancelconsole.logupdatedstate; // will be 'canceled';;;recurlyAccountall// accounts is an array containing all customer accounts;recurlyPlanall// plans is an array containing all plans set up for your account;
Recurly is not consistent about how it names the ID fields for each data type. For some it's
uuid and for others
foo_code. Recurring hides this away: every data type has an
id property that sets the correct field name for Recurly.
DataType.create(optionsHash, function(err, object))
Create an object of the given type by POSTing to Recurly.
Fetch an item of a given type from Recurly. The item must have an id.
Destroy, delete, close, cancel, or otherwise remove the specified object. Invokes http
DELETE on the item's href. The item must have an id.
Most data types have an
update() method that changes the stored data.
Account.all(state, function(err, accounts))
Responds with an array of all accounts in the passed-in state. Defaults to 'active'.
Modifies the account data with the passed-in hash.
Alias for delete.
Reopens a closed account.
Responds with a BillingInfo object for this account.
Responds with an array of subscriptions for this account.
coupon.redeem(options, function(err, redemption))
Responds with an array of all transactions.
Transaction.create(options, function(err, transaction))
Post a transaction with the given options. Fields in the hash are named exactly as in the recurly documentation. Responds with the newly-created transaction.
If amountInCents is omitted, the transaction is refunded in full. Responds with any errors; the transaction object is updated.
All callbacks follow the node convention of reporting any error in the first parameter. If a transaction with Recurly succeeds but is rejected by Recurly for some reason-- inconsistent data, perhaps, or some other reason-- that err parameter is an instance of RecurlyError. The original transaction errors reported by Recurly are available as an array of structs in the
errors parameter. For instance, here's the result of a billing info update with an invalid, expired CC:
name: 'RecurlyError'message: '2 transaction errors'errors:field: 'billing_info.number'symbol: 'invalid'message: 'is not a valid credit card number'field: 'billing_info.number'symbol: 'expired'message: 'is expired or has an invalid expiration date'
This provides the back-end support for signing parameters for forms embedded using recurly.js. See Recurly's signature documentation for details on which parameters must be signed for each form type.
var recurly = require'recurring';var signer = 'your-private-api-key';signerset'account' account_code: 'account-id' ;var signedParameters = signertoString;
timestamp parameters are generated for you if you don't provide them. The nonce is created using node-uuid.
After Recurly handles a form submission, it posts to you a token pointing to the form results. Use a FormResponseToken object to fetch the results object represented by the token.
var recurly = require'recurring';var recurlyResponse = token 'subscription';recurlyResponseprocessif errreturn handleErrorerr;// subscription contains the new subscription data;;
Having to hint about the type of the response is clunky; TODO fix.
MIT. See accompanying LICENSE file.