Bookmark this page

Guided Exercise: Configuring Billing for APIs

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

  1. Set billing to prepaid mode in the Admin Portal.

    1. In a web browser, log in to the the 3scale API Management Admin Portal as the admin user.

    2. From the Audience page, navigate to Billing > Settings > Charging & Gateway and click Switch to PREPAID.

      When a prompt shows asking for confirmation, click OK.

  2. 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: false
  3. Create 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: 7
  4. Update the 3scale API Management billing process to run every minute.

    1. 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.

      Warning

      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.

    2. 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.
    3. 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 patched
    4. Patch 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 patched
  5. Run 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.
  6. Verify that the billing process generates an invoice for the Developer account.

    1. Navigate to the Audience page in the Admin Portal. Then click BillingInvoices.

    2. 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.

    3. Navigate to the invoice details by clicking the invoice number. Then verify that two line items show in the Line Items 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.

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish monetizing-billing

This concludes the guided exercise.

Revision: do240-2.11-40390f6