# Subscription

## Steps for Subscription

### Step 1: Get your Keys and IDs

* Go to [Stripe](https://stripe.com/) and get your Restricted Key and your Publishable Key.
* Set the following scopes:

```
PaymentIntents: Write
Customers: Write
Credit notes: Read
Subscriptions: Write
```

* Be aware that you can be in Test mode or in Live mode (you want to be in Live mode for this to really work)
* Be sure to create a **Restricted Key** and not a *Secret Key.*
* You might find [this](https://stripe.com/docs/keys) Stripe document Helpful.
* Set the One Time Price ID (for the first payment), Trial Period, and Price ID (for the payment after the trial).&#x20;

### Step 2: Go to the builder and set up the Stripe Component

* Create a new Stripe Integration component.
* Set the **Action** into the component's Option Panel to "Subscription".
* Copy and paste your Publishable Key.
* Set the One Time Price ID for first payment (you can leave it empty for a free trial), the Trial Period for the amount of days, and the Price ID with the price for after the Trial, just as you did in Stripe.
* Set the Billing Info variables with the according keys.

![](https://1421794749-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MaGcfSakhqdHaWyb0T_%2Fuploads%2F7fSbFWSuYkITeFv9HYm3%2Fsubscription.png?alt=media\&token=93d727dc-59fe-4947-b4fc-c9581cd9a87d)

​&#x20;

### Step 3: Install Stripe in your Website

* Click the Share button on the top bar of the builder
* If you already had the code snippet on your website you'll only need to add the first line that says something like: "\<script async src="[https://js.stripe.com/v3/">\\](https://js.stripe.com/v3/">\\)</script>"
* If you didn't have the flow installed, copy the whole block of code on the head of your Site.

![](https://1421794749-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MaGcfSakhqdHaWyb0T_%2Fuploads%2FuwVrwPYFWjxSWRgpX766%2Fshare2.png?alt=media\&token=05d41fb2-d7fe-4723-96dd-c87944cc6d1f)

### Step 4: Send your Restricted Key to us

* Send us a private message with your Restricted Key

### Step 5: Add our custom webhook into Stripe

* You'll need to request your custom webhook URL from us
  * It'll be in the format [https://flows.trysavvy.com/api/public/webhooks/stripe/\_\_ABCDEFG](https://flows.trysavvy.com/api/public/webhooks/stripe/reedFWgD0eZuuBjCes2d)\_\_\_
* In your Stripe dashboard go [here](https://dashboard.stripe.com/webhooks), or head to Developers -> Webhooks -> Add Endpoint
* Enter the webhook URL we gave you into "Endpoint URL"
* Under "Select events to listen to" click **"+ Select events"**
* Expand the "Invoice" section and select `invoice.payment_succeeded`
* Click "Add events" and then "Add Endpoint"

### Common Errors

* `Payment rejected due to mismatch in payment amount`
  * Likely cause: the Flow version is unsaved, or the front-end's amount does not match the backend's Flow JSON's amount.
* `Missing required secret key for...`
  * The secret key for live mode has not been added to the above environment variable.
* `Secure Payments is configured incorrectly. Please contact us and let us know!`
  * You are missing a publishable key in the saved flow JSON of the version you are using.
* `Cannot read property 'client_secret' of null`
  * A payment intent was unable to be created. Check the API key permissions to ensure they are correct.
  * Check the `price_ids` used in the transaction to ensure the sum is above the minimum amount of $1 USD (or other currency equivalent).
* `No such payment intent`
  * The `publishable_key` of the component and the `restricted_key` of the group the Flow is part of do not belong to the same account.
  * Savvy admins will be required to look into this
  * Check the groupId of the version of the Flow you are viewing, and compare it against the `restricted_key` stored in l. Ensure that the `publishable_key` 's account matches that of the `restricted_key`.
  * This error does *not* mean that a key is missing, rather, both keys exist and are valid, but belong to different accounts (and thus Stripe cannot "find" the id because it is part of a different account)
* Any other error
  * Check the permissions on the API Key
  * Contact Savvy
