项目作者: uniquelyparticular

项目描述 :
This Particular example demonstrates how you can track unique Usage Records for Metered Pricing Subscriptions in Stripe.
高级语言: JavaScript
项目地址: git://github.com/uniquelyparticular/stripe-distinct-usage-tracking.git
创建时间: 2019-06-03T02:00:59Z
项目社区:https://github.com/uniquelyparticular/stripe-distinct-usage-tracking

开源协议:MIT License

下载


@particular./stripe-distinct-usage-tracking

@particular./stripe-distinct-usage-tracking"">npm version semantic-release code style: prettier CircleCI dependency status: david

Stripe Metered Pricing unique usage tracking implementation to increment Subscriptions Usage Record only for distinct new entities

Built with Micro! 🤩

🛠 Setup

Create a .env at the project root with the following credentials:

  1. USAGETRACKING_ORIGIN_WHITELIST=*.mysite.com,*.mycrmplaform.io,*.mycommerceplaform.com,*.now.sh
  2. USAGETRACKING_SECRET_HEADER=x-webhook-secret-key
  3. USAGETRACKING_SECRET_KEY=zxasda
  4. STRIPE_SECRET_KEY=sk12312312312312312

USAGETRACKING_ORIGIN_WHITELIST is a comma separated list of patterns to match against the incoming requests ‘Origin’ header (ex. localhost,*.myawesomesite.com,*.now.sh)

USAGETRACKING_SECRET_HEADER will default to 'x-shared-secret' and will be used to look for a header value to use for decryption.

USAGETRACKING_SECRET_VALUE will be used for decryption in conjunction w/ the value send in the USAGETRACKING_SECRET_HEADER header’s value.

Find your STRIPE_SECRET_KEY within Stripe’s API Settings.

📦 Package

Run the following command to build the app

  1. yarn install

Start the development server

  1. yarn dev

The server will typically start on PORT 3000, if not, make a note for the next step.

Start ngrok (change ngrok port below from 3000 if yarn dev deployed locally on different port above)

  1. ngrok http 3000

Make a note of the https ngrok URL provided.

🚀 Deploy

You can easily deploy this function to now.

Contact Adam Grohs @ Particular. for any questions.