# stripe-lib

> Node JS library for using the most common functionalities of stripe

Latest version **0.9.0** (published 2017-07-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install stripe-lib
pnpm add stripe-lib
yarn add stripe-lib
bun add stripe-lib
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2017-07-28 |
| First published | 2017-07-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| Author | Joel Moreno |
| Maintainers | joeltvrbo |
| Keywords | stripe, library, node, card, payment, wrapper, api |

## Links

- npm: https://www.npmjs.com/package/stripe-lib
- Repository: https://github.com/luffyelric/stripeLib
- Homepage: https://github.com/luffyelric/stripeLib#readme
- Issues: https://github.com/luffyelric/stripeLib/issues
- npm.io page: https://npm.io/package/stripe-lib

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.16.2
- [stripe](https://npm.io/package/stripe.md) ^4.23.1

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.9.0 (latest) — 2017-07-28
- 0.8.0 — 2017-07-24

## 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
```

---
_Source: https://npm.io/package/stripe-lib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
