Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
lightrail-stripe
Advanced tools
A Javascript and Typescript library for creating Lightrail-Stripe integrated applications.
Lightrail is a modern platform for digital account credits, gift cards, promotions, and points — to learn more, visit Lightrail. The Lightrail Stripe integration provides a client library for developers to easily use Lightrail alongside Stripe in Javascript (Node).
If you are looking for specific use-cases or other languages, check out the Integrations section of the Lightrail API documentation.
This library is in beta mode and may have breaking changes before v1.0.0.
Before using this library, you'll need to configure the Lightrail Client to use your API key:
const Lightrail = require('lightrail');
Lightrail.configure({
apiKey: <LIGHTRAIL API KEY>
})
A split-tender transaction happens when a transaction is broken down into two (or more) transactions each processed by a different payment methods. In this use-case we will focus on the common case of dividing a transaction between a Lightrail Card (Gift Card or Account Card) and a credit card processed by Stripe. For example, if you are processing a $134.25 transaction and the customer would like to redeem a $30 value from their Gift Card, you need to charge $30 to the Lightrail Card and the remaining $104.25 must be charged to Stripe.
For a sample project using this library, check out the Lightrail Stripe Sample Node Web App.
If you already process Stripe payments, the interface for implementing a split tender checkout will be familiar.
You will need the following general parameters:
amount
of the transactioncurrency
of the transactionuserSuppliedId
as a unique transaction identifier to ensure idempotence (meaning that if the same request is issued more than once, it will not result in repeated actions). This is typically the order ID from your ecommerce system.metadata
(the split tender checkout process will not interfere with any metadata or other parameters that you are accustomed to sending to Stripe and will pass them on as they are provided).For Lightrail, you will need the following parameters. If you need to read more about these check out the Lightrail API Docs:
apiKey
shopperId
(ie a Contact's userSuppliedId
) to specify a customer by their shopper ID (generated by your ecommerce system)lightrailShare
For Stripe, you will need the following parameters. If you need to read more about these check out the Stripe Docs:
secretKey
or a configured Stripe
instancetoken
or customerId
to specify which credit card you are going to charge via Stripe. Note that based on Stripe's flow you have to either use one of Stripe's browser-side methods to capture the credit card information and exchange it for a token
, or use a previously-registered customerId
.const Lightrail = require('lightrail');
Lightrail.configure({
apiKey: "eyJhbGciOiJIUz.eyJnIjp7Imd1aSI6Imdv.uQR5JntsoZE_ECtIHosX"
})
const LightrailStripe = require("lightrail-stripe");
const Stripe = require("stripe")("sk_Ar32o89fe90ger63j");
const splitTenderParams = {
userSuppliedId:"order-s3xx30",
value:-6960,
currency:"USD",
metadata: {
cart: {
total: 6960,
items: [
{
id: "B009L1MF7A",
quantity: 3,
unit_price: 2320,
tags: ["apparel", "outdoor"]
}
]
}
},
shopperId: "customer-ae0a4t6mnx",
source: "token_visa"
};
LightrailStripe.createSplitTenderCharge(
splitTenderParams,
6200,
Stripe // you can also pass in your Stripe key here instead
).then(
// called asynchronously
);
The return object will have a lightrailTransaction
and a stripeCharge
containing details of their respective transactions (output simplified for ease of reading):
{ lightrailTransaction:
{ value: -6200,
userSuppliedId: 'order-s3xx30-capture',
dateCreated: '2017-11-14T23:59:58.150Z',
transactionType: 'DRAWDOWN',
cardId: 'card-c99f0cdf9',
currency: 'USD',
transactionBreakdown: [ [Object] ],
transactionId: 'transaction-89e0a',
parentTransactionId: 'transaction-372e2',
metadata:
{ cart: {
total: 6960,
items: [ {
id: "B009L1MF7A",
quantity: 3,
unit_price: 2320,
tags: ["apparel", "outdoor"]
} ]
},
_split_tender_total: 6960,
giftbit_initial_transaction_id: 'transaction-372e2',
_split_tender_partner: 'STRIPE',
_split_tender_partner_transaction_id: 'ch_1BOEJt' } },
stripeCharge:
{ id: 'ch_1BOEJt',
object: 'charge',
amount: 760,
balance_transaction: 'txn_1BOEJtE2',
captured: true,
created: 1510703997,
currency: 'usd',
metadata:
{ cart: {
total: 6960,
items: [ {
id: "B009L1MF7A",
quantity: 3,
unit_price: 2320,
tags: ["apparel", "outdoor"]
} ]
},
_split_tender_total: '6960',
_split_tender_partner: 'LIGHTRAIL',
_split_tender_partner_transaction_id: 'transaction-89e0a' },
outcome:
{ network_status: 'approved_by_network',
reason: null,
risk_level: 'normal',
seller_message: 'Payment complete.',
type: 'authorized' },
paid: true,
source:
{ id: 'card_1BOEJtE2wGcUjQW3iH0pk4Xf',
object: 'card',
brand: 'Visa',
country: 'US',
last4: '4242' },
status: 'succeeded' } }
Note that metadata items have been added to both transactions to ensure transaction traceability.
In the case that the full transaction is covered by Lightrail (ie, lightrailShare
is the full transaction amount), the stripeCharge
will be null
, and vice versa if the full transaction is covered by Stripe.
IMPORTANT: note that several environment variables are required for the tests to run. After cloning the repo, npm install
dependencies and set the following (either in a .env
file in the root directory or however you prefer to set environment variables):
LIGHTRAIL_API_KEY
: find this in to the Lightrail web app -- go to your account settings, then click 'API keys' and 'Generate Key.' Note that for running tests, you should use a test mode key.
LIGHTRAIL_SHOPPER_ID
: this is the userSuppliedId
of one of your Lightrail Contacts that has a USD Account Card with at least a few dollars on it.
STRIPE_SECRET_KEY
: find this in your Stripe dashboard -- note that for running tests, you should use a test mode secret key.
Then you can run npm test
.
Bug reports and pull requests are welcome on GitHub at https://github.com/Giftbit/lightrail-client-javascript.
This library is available as open source under the terms of the MIT License.
FAQs
A Javascript and Typescript library for creating Lightrail-Stripe integrated applications.
The npm package lightrail-stripe receives a total of 0 weekly downloads. As such, lightrail-stripe popularity was classified as not popular.
We found that lightrail-stripe demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.