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

simple-stripe

v0.3.1

Published

A simple Stripe interface module, providing basic charging functionality and customer management

Downloads

5

Readme

Simple-Stripe wrapper module

The Simple-Stripe module is made with simplicity in mind, in order to provide basic Stripe Payments functionalities in the most readable API possible.

Requirements

Node 14 or higher.

Installation

Install the package with:

npm install simple-stripe --save
# or
yarn add simple-stripe

Usage

The package needs to be configured with your account's secret key, which is available in the Stripe Dashboard. Import it and create an instance like this :

import SimpleStripe, { StripeError } from "simple-stripe"
const simpleStripe = new SimpleStripe('sk_test_...')

Usage with TypeScript

Simple-Stripe provides its own type declarations

it also exposes StripeError as an export to ease Error handling

import SimpleStripe, { StripeError } from "simple-stripe"

Configuration

Initialize with config object

The package can be initialized with the usual StripeConfig parameters:


const simpleStripe = new SimpleStripe('sk_test_...', {
  apiVersion: '2019-08-08',
  maxNetworkRetries: 1,
  timeout: 1000,
  host: 'api.example.com',
  port: 123,
  telemetry: true,
});

More Information

API

paymentIntent

Exposes several methods used to handle paymentIntents

generate: async (amount: number, customer?: string, setupOffSession = false, currency = 'eur'): Promise<SimplePaymentIntent>
// creates a new paymentIntent on your Stripe Dashboard and returns it as a `SimplePaymentIntent` object
getClientSecret: async (id: paymentintent_id): Promise<string | null>
// Retreives the client secret of a payment intent
getStatus: async (id: paymentintent_id): Promise<PaymentIntentStatus>
// Retreives the status of the paymentIntent and wraps it in an enum
getDetails: async (id: paymentintent_id): Promise<PaymentIntentDetails>
// Retreives the details of a paymentIntent and provides the most interesting properties in a PaymentIntentDetails
// WIP
payOffSession: async (payment_intent: paymentintent_id, payment_method: paymentmethod_id ): Promise<SimplePaymentIntent>
// WIP
// Complete a payment of an existing paymentIntent server-side. Does not handle errors very well for now

customer

Exposes several methods used to handle customers

create: async (infos?: Stripe.CustomerCreateParams): Promise<SimpleCustomer>
// Creates a customer on your Stripe Dashboard and returns its id
// optional param "infos" are a Stripe.CustomerCreateParams object
findByEmail: async (infos?: Stripe.CustomerCreateParams): Promise<SimpleCustomer>
// Finds a list of customers based on email
getDetails: async (id: customer_id): Promise<CustomerDetails>
// Get a customer's details and wraps them inside a CustomerDetails object
getPaymentMethods: async (id: customer_id): Promise<PaymentMethod[]>
// Returns the details of a customer's PaymentMethod[]
// This could be useful to send a list of saved card to a front-end
flushDuplicatePaymentMethods: async (id: customer_id): Promise<number>
// Go through a customer's payment cards, find duplicates and detach the older ones
// This is good to call before sending payment methods infos to a front-end to prevent duplicates
charge: async (
    customer: customer_id,
    payment_method: paymentmethod_id,
    amount: number,
    currency = 'eur',): Promise<SimplePaymentIntent | void>
// This method can charge an off_session saved payment id, and returns the result in form of a SimplePaymentIntent object

Types

This module is written 100% in TypeScript, you can find the types in the src folder on the GitHub repository

Roadmap

This module is a work in progress.

First major milestome will be to wrap everything in structured classes, e.g :

class Customer{
  public id: string
  public name: string
  public created: Date
  public ...
  ...
  public paymentCards: PaymentCard[] // inherits from PaymentMethod etc..
  public paymentIntents: PaymentIntent[]

  constructor(id: string, options: tbd){
    // fetch the customer, its payment methods and intents etc...
  }

  // Static methods to create or retreive a Customer?

  // methods to charge the customer, retreive information ...
}

Following work will focus on supporting more scenarios :

  • Subscriptions
  • Card holds and captures
  • Support for SEPA transferts
  • Support for Apple Pay transactions (nothing much to do backend)

Let's keep it simple though, I don't plan on supporting everything Stripe does

Collaboration

If you want to collaborate to the project, you can fork it, create a wip/nameofyourfeature branch and pull request on the develop branch