Subscribe with Google


Newsletter


Survey


Rewarded Ads


Custom CTA


Using Extended Access


Syncing Publisher Entitlements to Google


Receiving Entitlements from Google


Cancelling Entitlements Plans or Making Refunds


Content examples

Cancel Entitlements Plans and Refund Orders with the Cancellation API

The Cancellation API lets you cancel entitlements (subscription plans) or refund orders for a user.

  • Offer a cancellation and refund mechanism on your website, as opposed to asking RRM subscribers to go to Payments Center to cancel their subscription.
  • This lets you create a consistent cancellation experience for all their subscribers regardless of acquisition channel

Service Account Setup

For more information on creating and configuring Service Accounts, please see the Monetization API Service Account Setup devsite article.

API Tests

publicationId input:
readerId input:
entitlementsPlansId input:
orderId input:

Button Details

  Cancel immediately

Use the Cancellation API's entitlementsPlans endpoint to cancel an entitlement for a given readerId and entitlementsPlansId.

Use the Cancellation API's refundOrder endpoint to process a refund for a given readerId and orderId.


Implementation Samples

A custom client generated rom the API discovery document

Generate a client from the API discovery document

You can use the generators to create a custom client based on the Discovery Document. Refer how to generate a client from the API Discovery Document for an example in Node.js .

Regenerate your client for the Cancellation API

The Cancellation API endpoints are newer than the Publication and Monetization API endpoints. If your client was generated before the Cancellation API was supported, you must regenerate it using the latest API Discovery Document.

Server-side code sample (Node.js)

Refer to the developer site for more details.

import subscribewithgoogle from '@googleapis/subscribewithgoogle';

/**
 * CancellationAPI
 * A sample class that uses the GoogleApis node.js client and a service
 * account for interacting with the CancellationAPI API.
 */
class CancellationAPI {
  constructor() {
    this.auth = new subscribewithgoogle.auth.GoogleAuth({
      keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
      scopes: [
        'https://www.googleapis.com/auth/subscribewithgoogle.publications.entitlements.manage'
      ],
    })
  }

  init() {
    return new subscribewithgoogle.subscribewithgoogle(
        {version: 'v1', auth: this.auth})
  }
}

/**
 * POST /publications/{publicationId}/readers/{readerId}/orders/{orderId}:refund
 */
async refundOrders(){
  const publicationId = ''; //TODO
  const readerId = ''; //TODO
  const orderId = ''; //TODO
  const name = `publications/${publicationId}/readers/${readerId}/orders/${orderId}`;
  const response = await client.publications.readers.orders.refund({
    name,
    // boolean value to decide cancel the subscription immediately, or wait for the end of the current cycle period
    cancelImmediately: false
  });
  return res.json(response.data);
}

/**
 * POST /publications/{publicationId}/readers/{readerId}/entitlementsplans/{entitlementsPlanId}:cancel
 */
async cancelEntitlementsPlans(){
  const publicationId = ''; //TODO
  const readerId = ''; //TODO
  const entitlementsPlanId = ''; //TODO
  const name = `publications/${publicationId}/readers/${readerId}/entitlementsplans/${entitlementsPlanId}`;
  const response = await client.publications.readers.orders.refund({name});
  return res.json(response.data);
}

REST API

Alternatively, you can call the REST API endpoints. Refer to the developer site section for more details.

Fork me on GitHub