npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stripe-wrapper-node

v1.0.1

Published

A nodeJS wrapper for Stripe payments

Downloads

2

Readme

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.