Skip to content
James Broome James Broome

Tutorial

Once you've understood how to unlock digital transformation using APIs and assessed your organization's API Maturity, the next big problem to solve is how to monetize your APIs.

In this tutorial, we walk you through this demo project, where the example revenue model defined in the monetization overview (Free, Developer, PAYG, Basic, Standard, Pro, Enterprise) has been implemented to demonstrate integrating Azure API Management with Stripe. This demo enables API consumers to browse, select, and subscribe to products via the developer portal.

We have provided detailed technical implementation about the overall architecture and process flow, as well as a step-by-step deployment guide, including the Stripe developer portal.

Transcript

The short walk of the video will describe the process of deploying and configuring the demo solution for integrating Azure API management with the Stripe payment gateway. Before you get started, you'll need the following:

  • A Stripe account, preferably a test account. If you're still evaluating this process
  • An Azure subscription with permissions to deploy resources and create service principles,
  • PowerShell, and the Azure CLI, in order to run the necessary command line scripts.

The supporting artifacts for this walkthrough are available in GitHub. In the Azure API management monetization repository under the Microsoft organization, you also need to clone or download the repository artifacts. The process that will be following this video is documented in the deployed demo with Stripe markdown file, which is referenced in the main readme document in the repository.

It's a good idea to have the associated documentation for the setup process to hand so that you can copy and paste a necessary commands that are showing the video. As we go through the later steps, we'll start by logging into our Stripe account and navigating to the developers tab in the dashboard. We're going to create two new API keys. Each key will govern a specific set of permissions that a calling application will be given. When connecting to the API, using that key, we'll call the first API key initialization key.

This will be used to initialize Stripe with products, prices, and configure Webhooks. So we need to give you right permissions on products, plans, and webhook endpoints. And then click create the key to save.

The second API key will be used to create subscriptions when customers sign up to use our API and update Stripe with API usage so that the customers can be billed for the right amount. We'll call this one, the app key, and we need to give it right permissions on checkout sessions. Subscriptions and usage records and read permissions on plans and products. And then we can create the second key.

The next stage is to create a service principle, which will act as a privileged credential that our web application will use to talk to API management. We're going to use the Azure CLI inside PowerShell. And the first thing we need to do is connect to our Azure subscription. Using the AZ login command.

If you have access to multiple subscriptions, then you can set the subscription context using the AZ account set command, passing in the relevant subscription ID.

We can now create the new service principal. This command will return some sensitive information that you'll need to temporarily copy and store for later use.

Now we want to visit the demo solution repository on GitHub. The main read me, file contains a link to the deploy demo with Stripe documentation, which is a set of instructions that we're following in this video about halfway down. The page is a deployed Azure button. Clicking. This button will initiate the process of capturing all the parameters that we need to provide to this deployment script, to deploy the resources we'll need to pick the subscription, the resource group and the region that we want to deploy.

We'll then need to set the resource name for the API management service that we're going to deploy. We'll need to provide an email address for an administrator for the API management service and the name for our company publishing the API, which will appear in places like the publisher portal. We'll need to set which SKU for API management.

We want to provision and then provide a name and skew details for the app service that hosts our demo solution.

Finally, we need to configure the payment provider details. Firstly, that we're going to be using Stripe as our payment gateway. And then we need to head back to the Stripe portal to grab the API keys that we. We need to set both the secret key and the publishable key for Stripe, and we can copy and paste the values directly from the Stripe portal into the deployment parameters.

We now need to achieve a few ID values from our service principle that we created earlier. Some of which we stored for later use using the AZ ad SP show command in the Azure CLI we can obtain the service principal's app Object ID and the app tenant ID. These can all be added to the deployment parameters along with the client secret password that was returned. When the service principle was created.

At this point, we can now review and trigger the deployment. As your API management typically takes about half an hour to deploy and we'll receive an email at the administrator address that was provided earlier when it's complete.

When the deployment is finished, the new resource group will contain an API management service, an app service plan, and an app service that's linked to the service plan.

The next stage is to publish the developer portal for API management. We can do that by going to the API management resource in Azure and selecting the developer portal option under the operations menu. There's an option to publish the website. And that takes a few seconds to complete.

We now need to switch back into PowerShell and run the Stripe initialization script. That's part of the demo repository that you should have locally on your machine. The script needs a few parameters before we can run it. The first one is the Stripe API key. This is the first API key that we created called initialization key, and we can copy the value from the Stripe portal.

The next parameter is the API management gateway URL, which we're gonna find in the Azure portal under the API management resource.

The next parameter is the API management subscription key, which can also be found in the Azure portal under the API management blade under the subscriptions menu. You can use the key for the built in default subscription and copy the value directly from the portal.

The next parameter is the Stripe web hook URL. This means the URL of the app service that we just deployed, which can be found in the Azure portal. However, we need to add slash web hook slash Stripe to the end of that base URL to point to the web hook endpoint.

Then we need to specify the name of the resource group that we deployed into. And finally the name of the app service itself. And then we can run the script. The script automates the process of creating the products in Stripe by calling the Stripe API.

Once it's finished, if you visit the Stripe dashboard, you can see those products have now all been set up. The script has also created the web hook that Stripe were listened to through events coming over from API management, with the usage metrics and subscriptions.

The final thing we're going to do is go through the developer experience of signing up to use our API. We're using an anonymous browsing session here to simulate a different person, connecting to the public facing API management developer portal. We're going to sign the developer up as a new user, providing a name, email address, and a strong password.

Once they've signed up, they're now logged into the developer portal and they can review or brow the products that are available to subscribe to the basic product. They just need to agree to the terms of use and select subscribe.

They need to provide a unique name for this subscription. And this is because there might be multiple subscriptions for the same product for different use cases.

Once they've provided that name, they're automatically directed to the strip payment portal where they can provide credit card details. Stripe provides dummy card details, which can be used for testing purposes.

Once the payment has been authorized, they're redirected back to the API management developer portal. And if they look at their profile, they can see, they now have an active subscription to the basic product, which gives them access to the API key. This is the key that they will use to authenticate against our API.

And if we switch back to the Stripe dashboard, we can now see that we have a new customer and the details of their subscription.

That's the end of this walkthrough for more details and other supporting documentation, including a similar demo solution. With the added payment provider, please refer back to the associated GitHub repository. Thank you.