In this exercise, you will configure billing in Red Hat 3scale API Management to prepaid mode to automatically generate invoices for the paid plans for your API.
Outcomes
You should be able to:
Configure 3scale API Management to prepaid mode.
Change an account to a paid application plan.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command:
Deploys the application you will use in this exercise.
Configures a 3scale API Management product and backend.
[student@workstation ~]$ lab start monetizing-billing
Procedure 7.1. Instructions
Set billing to prepaid mode in the Admin Portal.
In a web browser, log in to the the 3scale API Management Admin Portal as the admin user.
From the page, navigate to and click .
When a prompt shows asking for confirmation, click .
Create a monthly plan with a set-up fee of $30 and a monthly fee of $10.
[student@workstation ~]$ 3scale application-plan create --publish \
--approval-required=false --cost-per-month=10.0 --setup-fee=30.0 \
3scale-tenant monetizing_billing "monthly_plan"
Created application plan id: 11. Default: false; Disabled: falseCreate an application for the john user account and subscribe to the monthly_plan.
[student@workstation ~]$ 3scale application create 3scale-tenant \
john monetizing_billing monthly_plan monetizing_billing_app
Created application id: 7Update the 3scale API Management billing process to run every minute.
Examine the /home/student/DO240/labs/monetizing-billing/sidekiq_schedule.yml file.
It contains the job scheduling configuration for the billing process.
Every cron field has a * character to run the billing job every minute.
The sidekiq_shcedule.yml file for this exercise is intentionally incomplete and contains only the cron definition for billing jobs. If you leave this configuration other types of jobs will not execute.
Log in to Red Hat OpenShift Container Platform (RHOCP) as the admin user.
[student@workstation ~]$ oc login -u=admin -p=redhat \
--server=https://api.ocp4.example.com:6443
Login successful.Patch the system configmap to include the new schedule for the billing job.
[student@workstation ~]$ oc -n 3scale patch cm system --type merge \
--patch-file /home/student/DO240/labs/monetizing-billing/sidekiq_schedule.yml
configmap/system patchedPatch the system-sidekiq deploymentconfig object to add the sidekiq_schedule.yml to the files that override the default configuration.
[student@workstation ~]$ oc -n 3scale patch dc system-sidekiq \
--patch-file /home/student/DO240/labs/monetizing-billing/system-volumes.yml
deploymentconfig.apps.openshift.io/system-sidekiq patchedRun the /home/student/DO240/labs/monetizing-billing/update_trial_dates.sh script to set the trial expiration date of monetizing_billing_app to yesterday.
The billing process generates invoices the day after the free trial expires.
[student@workstation ~]$ sh \
/home/student/DO240/labs/monetizing-billing/update_trial_dates.sh
mysql: [Warning] Using a password on the command line interface can be insecure.Verify that the billing process generates an invoice for the Developer account.
Navigate to the page in the Admin Portal. Then click → .
Verify that the billing process generated an invoice for the Developer account and that the invoice state is set to Finalized.
The billing process job could take a minute until it runs again. Refresh the page if the invoice list is empty.
Navigate to the invoice details by clicking the invoice number. Then verify that two line items show in the section:
Fixed fee ('monthly_plan') with a max value of $10 depending on how close today is to the beginning of the month.
Setup fee ('monthly_plan') with a value of $30.
This concludes the guided exercise.