Android

1. Overview

In-App integration enriches your portfolio with one more payment method for your services. Users can buy your products directly in your application, which makes the process easier. It also provides added value to you.

When you enable In-App purchases you gain:

  • multi-access for your users - they can use your services on many devices

  • enhanced reporting for you - all-in-one-place reporting that can support your subscriber retention analytics and strategy building.

    Note: Churn IQ Dashboard relies on offer prices manually defined at Cleeng (the prices have to be mirrored between systems).

📘

Important

Please note that you must offer In-App payments for the services delivered in your native apps (see Google Documentation).

Please follow this guide for smooth Android In-App integration.

2. Typical System Architecture

Below you can see the overview of the typical system architecture. It shows the interaction - data exchange - between your app, Google Play, your middleware and Cleeng.

Typical System ArchitectureTypical System Architecture

Typical System Architecture

For details, see Sequence Diagram.

Subscription Receipt

Google uses Subscription Purchase Resource for providing information about the status of a user’s subscription purchase. For purposes of this tutorial, we shall refer to it as a receipt.

A receipt is a digital “document” confirming a subscription purchase. It is stored in the Cleeng database.

Receipt’s features:

  • It is provided to Cleeng during an initial purchase
  • It consists of subscription details
  • It is a single source of truth for Cleeng - verifiable at any time in Google.

3. Prerequisites

To start with the setup, please follow the steps:

  1. Set up a Google Play developer account, create an application and create your products - see Google Docs.

📘

Important Note

Products that you add must be compatible with your Cleeng offer.

Example of offer equality:

Offer EqualityOffer Equality

Offer Equality

  1. Integrate the Google Play Billing Library (for more information, see here).

4. Provide a service account key

Cleeng requires Android oAuth Client Id in JSON format (a service account key) to validate an Android receipt. The Client ID should be created with permission to use Google APIs on behalf of the end user, with privileges to view finance reports.

For more information, please refer to Google Docs.

Contact the BSS team to provide the service account key and finalize Android in-app purchase setup.

5. Implementation

Note:
We recommend using our MediaStore API (for more information see Getting started), especially for authentication (registration and login). If any of the specific functions are missing in the MediaStore API, you can fall back to JSON RPC (see more: Getting Started With JSON-RPC).

Register User

The application attempts to log in the user (see Log in User).

If the user doesn't exist, registration is required. It is recommended that the application uses the Register method to register the customer. For more information see Registration.

Log in User

If the user exists, it is recommended that the application uses the Login endpoint to log in. For more information see Login.

Make Initial Purchase

The Android application is responsible for displaying the “Buy” button that will initiate the payment. Because it is an In-App purchase, payment is made outside of Cleeng.

Once payment is completed, Google Play returns a purchase Token that must be passed to the Cleeng's payment endpoint /android/payment.

This endpoint includes a subscription transfer feature. It is triggered when:

  • we already have an active subscription for the provided receipt
  • this subscription belongs to a customer ("old customer") with a different email address than the one for which this request is being made ("new customer").

The subscription transfer feature creates a new subscription for the "new customer" (the one using the new e-mail address) and terminates the subscription assigned to the "old customer" (the one using the old email address).

6. Receipt Validation

Access to content is based on a receipt. That's why a receipt needs to be properly validated before access is granted.

Validation is done automatically by Cleeng. It might take some time.

Receipt processing is an asynchronous process. Even though most responses are within 3 seconds, they can take up to 60 seconds.

The application should poll the Cleeng API using the getAccessStatus or getAccessibleTags method every five seconds until validation is completed.

  • If access is not granted within 60 seconds, the application should assume it failed and inform the user accordingly.
  • If the transaction is confirmed, video content can be revealed.

The flowchart below shows the process:

Validating AccessValidating Access

Validating Access

7. Sequence Diagram

The diagram below provides more information about integration.

Sequence DiagramSequence Diagram

Sequence Diagram

8. Real-time developer notifications

It is direct one-way communication between Google Play and Cleeng. It provides real-time subscription updates.

The table below presents which Real-time notifications are supported:

Google Real-Time Developer Notification

Supported at Cleeng

SUBSCRIPTION_CANCELED

You need to make a pub/sub queue on Gcloud and provide a URL address for notifications.

📘

The URL you need to provide is: https://notification.cleeng.com/1.0/in_app/subscriptions/android/status_update_notification.

This will add consumer to consumer queue which will be sending notifications to Cleeng.
For information on how to make pub/sub queue, see Set up in Google Play Store.

Set up in Google Play Store

Follow these steps to configure pub/sub queue in Google:

  1. Login to your Google Cloud Account
  2. Go to the Topic List and choose your Android project.
  3. Create a topic:
Create a topicCreate a topic

Create a topic

Note:
realtime_notification topic name is not mandatory, you can choose your own topic id.

  1. Create a subscription:
Create a subscriptionCreate a subscription

Create a subscription

Note:
realtime_notification subscription id is not mandatory, you can choose your own subscription id.

  • In the Select a Cloud Pub/Sub topic menu you need to choose the one you have created in the previous step.

  • Change Delivery type from “pull” to “push” and add Cleeng notification URL: https://notification.cleeng.com/1.0/in_app/subscriptions/android/status_update_notification

  1. Come back to the Topic list and go to the View permissions submenu:
View permissionsView permissions

View permissions

  1. Click Add member and add [email protected] with Pub/Sub Publisher permission.
Add memberAdd member

Add member

  1. Go to https://play.google.com/console/ and choose your application.
  2. Go to the Monetization setup section and add your topic name in the Real-time developer notifications section. You can copy your topic name from the topic list in the Gcloud console.
  3. Click Test notification. If no errors are returned, save settings.

9. Introductory Offers

An introductory offer is a limited-time discounted price for the initial period of a subscription.

To make Cleeng’s discounts setup consistent with Introductory offers on Android, Coupons Campaign mechanisms are used. As a result, discounts can be applied to all new subscriptions that are created based on a given offer, on condition that a coupon code has been properly passed in the initial purchase.

To use the feature, you need to:

  1. Set up a proper coupon campaign that matches the discount in Android
  2. Send a proper couponCode in Initial Purchase.

Set up Proper Coupon Campaign

You need to configure a proper coupon campaign in the Cleeng Dashboard.
To do this, go to Offers & Coupons - > Coupon Management section. (For more information on coupon campaigns, visit here).

Example:
The price of an offer in Android is discounted for two months -> you need to create a coupon campaign for this offer in Cleeng with appropriate % discount (to mirror the discounted price in Android) for two billing cycles.

Make sure to create a separate coupon campaign for each offer.

Note:
Use a generic coupon campaign (in Coupon Campaign settings select: “Number of coupons: One”).

Send a Proper couponCode in Initial Purchase

If you want to use introductory offers, you need to add an additional payload parameter - couponCode - to the requests.

It is a coupon code applied for this purchase. The code shall be sourced from the coupon campaign properly created and assigned to the offer in the Cleeng dashboard.

Important Note:
If a coupon is invalid, the payment will be processed despite this, but the discount will not be applied.

📘

Good to Know

Recurring payments will use coupons automatically.

10. Testing

Please follow these steps to test the initial payment configuration:

  1. Configure testing environment in Google Play - see Google Documentation
  2. Create a Cleeng sandbox account (or log in if you already have one) and create a test offer.
  3. Make sure Google and Cleeng offers in a sandbox environment are compatible.
  4. Provide the service account key to the BSS team (see the Provide a Service Account Key section).
  5. Make an initial purchase.
  6. Make a request to Cleeng's Payment Endpoint: Sandbox URL: http://sandbox.cleeng.com/android/payment.
  7. Video should be revealed.

11. Good to Know

Any mechanisms that influence the final amounts paid by end-users (e.g. promotional offers) cause a difference between the offer price and the actual amount paid.

The way to reconcile reporting is to configure a matching offer at Cleeng. So please remember that if you use a configuration in Google that you haven't configured at Cleeng, then reporting will run out of sync.


Did this page help you?