Skip to content

Commit

Permalink
Edits to monetization guide (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcampos authored Feb 21, 2024
1 parent 60d2073 commit e71d5db
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions docs/articles/monetization-dev-portal-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ API plans.

If you don't already have a Zuplo API, you can create a new project using the
"ToDo" sample or following step 1 of the
[Getting Started quickstart](./step-1-setup-basic-gateway.md).
[Getting Started guide](./step-1-setup-basic-gateway.md).

You'll also need a Stripe account. If you don't already have one, you'll need to
[register](https://dashboard.stripe.com/register) for one.
Expand Down Expand Up @@ -102,7 +102,7 @@ Now that your Developer Portal is configured for monetization you can open it
and view the pricing page. Click the toolbar on the bottom of the Zuplo Portal
to find the URL of your Developer Portal.

![Dev Portal Link](../../public/media/monetization-dev-portal-setup/image-3a.png)
![Developer Portal Link](../../public/media/monetization-dev-portal-setup/image-3a.png)

Once you open your Developer Portal, you will find a link to the **Pricing**
page on the top right menu section. Open the **Pricing** page in your Developer
Expand Down
17 changes: 8 additions & 9 deletions docs/articles/monetization-policy-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ We will configure this using Zuplo's
[API Key Authentication Policy](/docs/policies/api-key-inbound) and the
[Monetization Inbound Policy](/docs/policies/monetization-inbound).

The Monetization Inbound Policy is what ensures that customers are only able to
call your API withing the quotas set in their Plan.

## 1/ Add API Key Authentication

In order to identify customers calling your API, you'll add the
Expand Down Expand Up @@ -46,7 +43,9 @@ endpoint.
## 2/ Add the Monetization Policy

With the user identified via the API Key Authentication policy, next you will
enforce that they are calling the API within the limits of their plan.
enforce that they are calling the API within the limits of their plan. The
[Monetization Inbound Policy](/docs/policies/monetization-inbound) is what
enables us to do that.

1. Open the **Policies** section of the same route and click **Add Policy**.

Expand Down Expand Up @@ -84,9 +83,11 @@ header.

![Successful response](../../public/media/monetization-policy-setup/image-1.png)

5. Close the API Playground and click the **Subscription** link in the Dev
Portal header. Notice the Analytics section now shows that you have consumed
some of your request quota from your plan.
5. Close the API Playground and click the **Subscription** link in the Developer
Portal header. Notice the Usage section shows that you have consumed some of
your request quota from your plan.

![Max quota status](../../public/media/monetization-policy-setup/image-2.png)

6. Return to the API Playground and click **Test** until you receive an error
response telling you that you have exhausted your quota.
Expand All @@ -98,6 +99,4 @@ earlier steps, this is going to take a while.

:::

![Max quota status](../../public/media/monetization-policy-setup/image-2.png)

Congratulations, you are now ready to monetize your API!
16 changes: 8 additions & 8 deletions docs/articles/monetization-programmatic-quotas.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ title: Monetization Programmatic Quotas
sidebar_label: Programmatic Quotas
---

Typically, when adding monetization to your API, you set the number of meters a
request will consume in the settings of the
When adding monetization to your API, you would usually set the number of meters
a request will consume in the settings of the
[Monetization Policy](https://zuplo.com/docs/policies/monetization-inbound). For
example, the policy below specifies that the request will consume 1 `requests`
example, the policy below specifies that each request will consume 1 `requests`
meter and 5 `computeUnits` meters.

```json
Expand Down Expand Up @@ -67,23 +67,23 @@ export default async function (
request: ZuploRequest,
context: ZuploContext,
options: any,
policyName: string,
policyName: string
) {
const headerValue = response.headers.get("compute-units");
let computeUnits;
let computeUnitsValue;
if (headerValue && typeof headerValue === "string") {
computeUnits = parseInt(headerValue);
computeUnitsValue = parseInt(headerValue);
}

// Throw an error if the server doesn't send compute units
// Alternatively, you could have a default value
if (!computeUnits) {
if (!computeUnitsValue) {
throw new Error("Invalid response, no compute units sent.");
}

// Set the compute units for the request
MonetizationInboundPolicy.setMeters(context, {
computeUnits,
computeUnits: computeUnitsValue,
});

return response;
Expand Down
7 changes: 4 additions & 3 deletions docs/articles/monetization-webhook-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ During the test phase, set the value of the **Max Value** to a low number like

## 2/ Set Up the Zuplo Plugin

The Zuplo `StripeMonetizationPlugin` enables your Zuplo API to listen to Stripe
Webhook subscription events. This plugin adds an endpoint that is used when
configuring the Stripe Webhook.
The Zuplo
[`StripeMonetizationPlugin`](/docs/articles/stripe-monetization-plugin.md)
enables your Zuplo API to listen to Stripe Webhook subscription events. This
plugin adds an endpoint that is used when configuring the Stripe Webhook.

1. To start, navigate to the **Code** section of your Zuplo project. On the
`modules` folder click the **+** button and select **Runtime Extension**.
Expand Down
24 changes: 12 additions & 12 deletions docs/articles/stripe-monetization-plugin.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
title: Stripe Monetization Plugin
sidebar_label: Stripe Plugin
sidebar_label: Stripe Monetization Plugin
---

The Stripe Monetization Plugin makes makes it easy to register a Stripe Webhook
in your Zuplo API that will handle Stripe subscription events.

When you register the Stripe Plugin a new route is configured on your API at the
path `/__plugins/stripe/webhook`. This route is used to receive webhooks sent by
stripe for Stripe subscription events.
The Stripe Monetization Plugin makes it easy to register a Stripe Webhook in
your Zuplo API that will handle Stripe subscription events.

The Plugin is registered in the `zuplo.runtime.ts` extension. It requires
setting the `webhooks.signingSecret` value and the `stripeSecretKey` in order to
function.

There is additional configuration if you wan to customize the path, etc, but for
most cases no additional configuration is required.
When you register the Stripe Monetization Plugin, a new route is configured on
your API at the path `/__plugins/stripe/webhook`. This route is used to receive
webhooks sent by Stripe for subscription events.

There is additional configuration if you want to customize the path, etc. In
most cases, no additional configuration is required.

```ts
import {
Expand All @@ -39,9 +39,9 @@ export function runtimeInit(runtime: RuntimeExtensions) {

## Debugging & Troubleshooting

The Runtime Plugin emits logs that show what the Webhook is doing. For example,
when a new subscription is created, the plugin will log information about the
Stripe subscription, user, etc.
The Plugin emits logs that show what the Webhook is doing. For example, when a
new subscription is created, the plugin will log information about the Stripe
subscription, user, etc.

If are having trouble with the Webhooks, reviewing the logs for the Plugin is
the place to start.
Expand Down

0 comments on commit e71d5db

Please sign in to comment.