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-lib

v0.9.0

Published

Node JS library for using the most common functionalities of stripe

Downloads

9

Readme

stripeLib

A library to make easier some simple requests to stripe. Focused on the use of cards and the storage of users with cards assigned.

Installation

npm install stripe-lib

Initialize

Server

const stripeLib = require('stripe-lib');

stripeLib.init({
    apiKey: "..." // private key
});

Client

(browser, mobile apps, etc)

const stripeLib = require('stripe-lib');

stripeLib.init({
    publishableKey: "..."
});

To use the token generation request which should be used from a client side, you must provide your PUBLISHABLE-API-KEY due to not giving away any of your private information.

The rest of the functions are server centered so you'll need to provide the private also.

If you don't initialize this parameters you won't be able to use neither the lib or stripe functions wholly.

Client side API

createTokenFromCard

Signature: createTokenFromCard(number, month, year, cvc)

Used to get a token from the minimum card information.

const token = await stripelib.createTokenFromCard({
    number: 'CARD-NUMBER-AS-A-STRING',
    month: EXPIRATION-MONTH,
    year: TWO-LAST-NUMBERS-OF-EXPIRATION-YEAR,
    cvc: CARD-CVC
});

Server side API

Paying with a random card:

First of all you'll have to create a token as showed above.

Once you have the token you can directly charge the card.

const charge = await stripelib.cardCharge(
    token.id,
    AMOUNT-OF-CURRENCY,
    CURRENCY);
//you can find the supported currency and their names here https://stripe.com/docs/currencies

WARNING: The amount of currency has to be of the currency's smallest unit e.g: to charge $10 USD, provide an amount value of 1000 (i.e, 1000 cents).

Paying through a customer's card:

createCustomer

Signature: createCustomer(email)

const customer = await stripelib.createCustomer("CUSTOMER'S-EMAIL");

createCustomerWithCard

Signature: createCustomerWithCard(email, cardToken)

const customer = await stripelib.createCustomerWithCard("CUSTOMER'S-EMAIL", CARD-TOKEN-GENERATED.id);

A customer with cards has always a default one which will receive the charge when charging the customer.

You can add more cards to a customer and can change the default card

addCardToCustomer

Signature: addCardToCustomer(customerId, cardToken)

await stripelib.addCardToCustomer(customer.id, CARD-TOKEN-GENERATED.id);

updateDefaultCard

Signature: updateDefaultCard(customerId, cardId)

await stripelib.updateDefaultCard(customer.id, NEW-DEFAULT-CARD.id);  

WARNING: The token of a card and the card are different things to see the id's of the different cards of a customer you can either get the customer or the digested information of their cards.

getCustomer

Signature: getCustomer(customerId)

const customerInfo = await stripelib.getCustomer(customer.id);

getCustomerDigestedCards

Signature: getCustomerDigestedCards(customerId)

const digestedCardsInfo = await stripelib.getCustomerDigestedCards(customer.id);

WARNING: A customer can't pay if it has no cards

customerCharge

Signature: customerCharge(customerId, amount, currency)

const charge = await stripelib.customerCharge(
    customer.id,
    AMOUNT-OF-CURRENCY,
    CURRENCY
);
//You can find the supported currency and their names here https://stripe.com/docs/currencies

WARNING: The amount of currency has to be of the currency's smallest unit e.g: to charge $10 USD, provide an amount value of 1000 (i.e, 1000 cents).

To get the info of a charge you only have to use the get function

chargeInfo

Signature: chargeInfo(chargeId)

const chargeInfo = await stripelib.chargeInfo(CREATED-GHARGE.id);

Removing

removeCardFromCustomer

Signature: removeCardFromCustomer(customerId, cardId)

await stripelib.removeCardFromCustomer(customer.id, card.id);

removeCustomer

Signature: removeCustomer(customerId)

await stripelib.removeCustomer(customer.id);

Tests

If on your own decide to make some changes over the code of the functions but want the output to keep it like right now you can alway run the verification output tests using:

npm run jasmine