1.0.7 • Published 1 year ago

lightgate-stripe-adapter v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Lightgate Stripe Adapter

This adapter converts the Stripe api into ORMs for LightGate Automation developers.

Installation and Configuration

Install using npm:

npm i lightgate-stripe-adapter

Create an instance of the adapter either in an automation or test. We are using a jest here to define a test:

import {LightgateStripeAdapter} from 'lightgate-stripe-adapter';

describe('Stripe customer tests', () => {
  let adapterInstance;

  beforeAll(async () => {
    try {
      adapterInstance = new LightgateStripeAdapter({ apiKey: process.env.STRIPE_SECRET_KEY, 
                                                     packageDir: '../../..'});
      await adapterInstance.initialize();
    } catch (error) {
      console.error('Error:', error.stack);
      expect(true).toBe(false); 
    }
  });

  test('find all customers test', async () => {
    try {
      const customers = await adapterInstance.Customer.listAll();
      expect(customers).toBeInstanceOf(Array);
      expect(customers.length).toBeGreaterThan(0);
      for (const customer of customers) {
        expect(customer).toBeInstanceOf(Customer);
      }
    } catch (error) {
      console.error('Error:', error.stack);
      expect(true).toBe(false); 
    }
  });
});

Key Features

Customers

ObjectFeatureReturnsDescription
CustomerlistAll()ArrayLists all customers
CustomerfindOne(id)ArrayFinds one customer by the id
CustomerfindOneOrCreate(data)ArrayFinds one customer by the email address and if not found creates a new customer
Customercreate(data)ArrayCreates a customer
CustomerremoveOne(id)ArrayRemoves a customer by the id
CustomerlistAllWithCharges()ArrayLists all customers with charges[] as an array for each customer
CustomergetTotalCharges()floatReturns a float of the total charges.

Charge

ObjectFeatureReturnsDescription
ChargelistAll()ArrayLists all charges

Product

ObjectFeatureReturnsDescription
ProductlistAll()ArrayLists all products
ProductfindOne(id)ArrayFinds one product by the id
Productsearch(data)ArraySearch for products by name, status, metadataorder_id
Productcreate(data)ArrayCreates a product

Price

ObjectFeatureReturnsDescription
PricelistAll()ArrayLists all prices
PricefindOne(id)ArrayFinds one prrice by the id
Pricesearch(data)ArraySearch for price by product: product_id
Pricecreate(data)ArrayCreates a price, requires product: product_id as an argument.

PaymentLink

ObjectFeatureReturnsDescription
PricelistAll()ArrayLists all prices
PricefindOne(id)ArrayFinds one prrice by the id
Pricecreate(data)ArrayCreates a paymentLink, requires price: price_id as an argument
1.0.7

1 year ago

1.0.0

1 year ago