plugin-stripe
The plugin was designed to work with Stripe, the payment processor.
For the full Stripe Node.js documentation, visit the official docs.
The documentation of this plugin is going to be updated soon.
Installation and usage
# install the plugin
npm i --save thorin-plugin-stripe@1.x
'use strict';
// app.js entry file
const thorin = require('thorin');
thorin.addPlugin(require('thorin-plugin-stripe')); // <-- add this line
thorin.run((err) => {});
#update config/app.js with your configuration
# run to setup the models and module
node app.js --setup=plugin.stripe
Default configuration
-
publishKeyprocess.env.STRIPE_PUBLISH_KEYyour account's publishable key
-
secretKeyprocess.env.STRIPE_SECRET_KEYyour account's secret key
-
appNameStripe appthe application name that will appear in charge descriptions
-
storesqlthe name of the SQL store to use
-
mode[subscription] // the modes we will run the plugin, If no mode is set, we will not setup any db and will only be able to charge.
-
singleSubscriptiontrueEnables single subscription mode, where an account belongs to a single subscription at once.
-
models.accountaccountthe account table name that will be altered with Stripe-specific fields
-
models.planstripe_planthe stripe plan table name that will contain all your application's subscription plans
-
models.subscriptionstripe_subscriptionthe stripe subscription table name that will contain account subscriptions
-
models.chargestripe_chargethe name of the table that will hold up stripe charges.
-
fields.customerstripe_customer_keythe field an account will have that will store the stripe customer id
-
invoice.prefixnullthe prefix of your application's invoices. This will be {YOURAPP}-102393848
-
invoice.length6the max number of digits an invoice ID can have, eg: Eg: YOURAPP-000001
-
defaultPlannullif set, the default plan code to set to an account when he downgrades his account (the free plan)
-
webhook.path/webhook/stripethe PATH of your stripe's POST webhook. This is where Stripe will call with information about charges and subscriptions.
-
webhook.ips[]an array of white-listed source IPs that Stripe uses. When run in setup, this will be populated with latest data.
Plugin functionality
pluginObj.createCharge(accountObj, charge) : Promise
Charges the account with the given charge information.
-
accountObjaccountObj an instance of an accountObj that was previously registered as a stripe customer
-
charge.amountintegerthe amount of cents to charge (eg: $5 is 500 cents)
-
charge.currencystring, USD the 3-char code of the currency to use
-
charge.descriptionstringthe description that will appear in the charge statement.
-
{Additional stripe options}
Authorization middleware
stripe#charge.read
Reads the stripe charge information, based on the stripe_charge store model. It will also fetch
the charge information from Stripe.
The authorization middleware will attach to the intent's data:
-
charge
the store's chargeObj entity
-
stripeCharge
the stripe charge entity associated with the local charge
'use strict';
thorin.dispatcher.addAction('charge.view')
.authorize('stripe#charge.read') // this requests charge_id in the input
.use((intentObj, next) => {
log.info('Got charge', intentObj.data('stripeCharge'));
next();
});
stripe#charge.find
Reads all the database charges and associated stripe charge. Input values below:
-
start_datedatethe start date to filter
-
end_datedatethe end date to filter
-
limitnumberthe number of charges per page
-
next_chargestringthe next charge id, useful for pagination.
stripe#customer.create
Creates a new stripe customer and attach it to the intent's account object.
This will not attach anything to the intent data, however it will update the account instance.
Requires an accountObj under the intent's account data object.
The following input data is required
email
used if the accountObj does not have an email.
stripe_token
the stripe payment token to use
stripe_coupon
an optional stripe coupon to use
stripe#plan.find
Returns all your active stripe plans
stripe#plan.read
Reads a stripe plan by its id. Requires plan_id
in the input as a number.
The resulting planObj will be placed in the intent's plan
data.
stripe#subscription.read
Reads the current account's subscription and plan, placing it under
currentPlan
and currentSubscription
in the intent's data
Requires an accountObj in the intent's account
data field.
stripe#subscription.create
This will subscribe the given account to the given plan using the given
stripe token. Essentially, this will create a stripe customer,
using the given plan and subscription
This middleware uses stripe.plan.read to read the target plan.
It also requires the account model to be present in the intent's account
data field.
-
stripe_tokenstringthe stripe payment token to use
-
quantitynumberthe number of times to subscribe the user. Defaults to 1
-
stripe_couponstringthe stripe coupon to use
stripe#subscription.cancel
This will perform a downgrade on the current account.
The downgrade will cancel the current active subscription of the account,
proactive (at the end of the current billing cycle.
This middleware requires the account model to be present in the intent's account
data field.