1.0.0 • Published 3 years ago

@tariche/cashjs v1.0.0

Weekly downloads
128
License
Apache-2.0
Repository
-
Last release
3 years ago

Introduction

Cashjs simplifies implementation of Stripe customer API-s in your Node.js app. By adding decorated property with @Cashable, your entity gets decored with implementation of stripe customer api methods for charges, payment intents, sources, payment methods, invoices, balance transactions.

Usage

Example of decorated class with @Cashable would be :

class User{
    @Cashable({stripe}) let cashjs;

    let stripeId; 
    let email;
}

Now our User instances automaticaly resolve Stripe customer and email when they call stripe methods over cashjs, so every instance of user is linked with one Stripe customer, their email is used for stripe invoices:

let user = new User();

user.cashjs.createStripeCustomer(); // Initializes stripeId to be used as reference to new Stripe customer 

user.cashjs.addPaymentMethod({
            type: 'card',
            card: {
                number: '4242424242424242',
                exp_month: 1,
                exp_year: 2022,
                cvc: '314',
            },
        }
);

user.cashjs.charge(500); // charges user for 500 in default currency

If you name differently properties of decorated class like email or stripeId, you should notify Cashable by passing property names as decorator parameters, or you want to change default currency when calling methods:

class User{
    // ...
    
    @Cashable({
        stripe: stripe,
        email: "contactEmail",
        currency: "EUR",
        stripeId: "customerId"
    }) let cashjs;

    let customerId;
    let contactEmail;
    
    // ...
}

Now you have your decorated intances able to call cashjs custom implementations calling stripe methods like:

As well you have available all Stripe Api for Node.js original methods, their docs is on https://stripe.com/docs/api and their implementation can be called on properties:

user.cashjs._intents
user.cashjs._charges
user.cashjs._invoices
user.cashjs._invoiceItems
user.cashjs._balacneTransactions
user.cashjs._customers
user.cashjs._sources
user.cashjs._paymentMethods

More examples of usage can be found in UseCase controller under src/controllers dir.