stripe-wrapper-node

1.0.1 • Public • Published

stripe-wrapper-node

NodeJS wrapper to use along with stripe.js This is a simple package that provides an easy stripe implementation as it has the most used methods needed to interact with stripe. Just pass it the stripe secret key and call the method you need.


Installation

  1. npm install stripe --save

  2. npm install stripe-wrapper-node --save

Usage

  1. import StripeWrapper from 'stripe-wrapper-node'

  2. const stripe = new StripeWrapper(require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'))

Example with async await:

// Import stripe-wrapper-node package
import StripeWrapper from 'stripe-wrapper-node'

// Use variable to create instance of stripe-node-wrapper with stripe.
const stripe = new StripeWrapper(require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2'))

export default class OrderActions {
  async submitOrder (req, res) {
    try {
      const chargeObject {
        stripeId: cus_9sdak9XImC6grB,
        source: tok_189fmH2eZvKYlo2CI3QmNyRq,
        amount = 50.00
      }

      stripeCharge = await stripe.chargeOrder(chargeObject)
      ...
    } catch (err) {
      console.log(err.message);
    }  
  }
}

Documentation

Methods:

Create a charge

createCharge(chargeDetails)

Arguments:

chargeDetails Object containing the charge details. This object has the following required key/value pairs:

stripeId, source, amount.

If no currency key is included in chargeDetails object, it will default to "usd".

Stripes requires amount to be sent as positive integer in the smallest currency unit. (e.g., 100 cents to charge $1.00).

If your currency is USD you don't have to worry about any of this, as stripe-node-wrapper will automatically convert the amount to it's cents equivalent.

{
  stripeId: "cus_9sdak9XImC6grB",
  source: "tok_189fmH2eZvKYlo2CI3QmNyRq",
  amount: 25.00
}

Any other type of currency has to be specified adding currency to the charge object and sending the amount converted to smallest currency unit.

If you want to make a two-step payment include the additional key/value pair capture: false. For all the other additional options see stripe charge documentation.

Capture a charge

captureCharge(chargeId)

This option is only for two-step payments. When capture: false is included in charge object.

Arguments:

chargeId Obtained in the response when a charge is made with the capture: false option included in the createCharge method. e.g. "ch_19YsOp2eZvKYlo2CsymIPgrt"

Create a new customer

createCustomer(source)

Arguments:

source Token sent by the front-end. e.g. "tok_189fmH2eZvKYlo2CI3QmNyRq"

Add a new card

addCard(stripeId, source)

Arguments

stripeId Id of the customer. e.g. "cus_9sdak9XImC6grB"

source token returned by stripe.js e.g. "tok_189fmH2eZvKYlo2CI3QmNyRq"

Get all user cards

getAllCards(stripeId)

Arguments:

stripeId The ID of the customer whose cards will be retrieved. e.g. "cus_9sdak9XImC6grB"

Retrieve a single card

retrieveCard(cardId)

Arguments:

cardId The ID of the card to be retrieved. e.g. "card_19YsPg2eZvKYlo2CVqNRx01d"

Delete a card

deleteCard(cardId)

Arguments:

cardId The ID of the source to be deleted. e.g. "card_19YsPg2eZvKYlo2CVqNRx01d"

Edit a card

editCard(stripeId, cardId, updateData)

Arguments:

stripeId: Stripe customer ID

cardId: Id of card to be updated

updateData: Object containing update details. See stripe update card documentation for possible options.

Issue a refund

refund(chargeId)

chargeId Charge obtained in createCharge response. e.g. "ch_19YsOp2eZvKYlo2CsymIPgrt"

Update charge details

updateCharge(chargeId, updateDetails)

Arguments:

chargeId Charge obtained in createCharge response. e.g. "ch_19YsOp2eZvKYlo2CsymIPgrt"

updateDetails Object containing information to be updated.

{
  description: "A new charge description"
}

For additional options available for charge update see stripechargeupdate documentation.

Readme

Keywords

Package Sidebar

Install

npm i stripe-wrapper-node

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • dnamic