Find your top customers
This is a Node.js console app to identify your top customers from Stripe. It uses the Stripe charges method to return a list of previous charges in your account.
The results (as an array) are sorted based on the customers with the highest charges by dollar amount, and then are displayed as a table with customer IDs, the total number of the customer's charges, and the total amount they have charged.
Set up and installation
These must be installed to access the app:
You need sign up for a Stripe account and get an API key from https://dashboard.stripe.com/. If you need to populate data in your account, enable test data.
Clone or download this repository, and then create a .env file containing the entry API_KEY= with your API key from your dashboard. This way, your secret key can remain protected from public view in case you publish this file.
Run the app
To run the app, open a terminal window to the folder, install the required npm packages, and type node server.js.
Note: The Stripe API uses cursor-based pagination. Because the Stripe Node library does not currently support auto-pagination, this code uses recursive functions that make multiple requests to get additional results. It may take some time to work through the results. If you find it has gone too long, modify the limits and skip the if/else statements.
The results display the number of total charges, unique customers, and a summary table.
With this information, you could use the customer IDs and feed them into the customers API to get additional information about the customer.
Technology
- JavaScript
- Node.js
- npm, including stripe, cli-table3, and numeral packages
