The Cancellation API lets you cancel entitlements (subscription plans) or refund orders for a user.
Service Account Setup
For more information on creating and configuring Service Accounts, please see the Monetization API Service Account Setup devsite article.
publicationId
input:readerId
input:entitlementsPlansId
input:orderId
input:Button | Details |
---|---|
Cancel immediately |
Use the Cancellation API's |
Use the Cancellation API's |
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.
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);
}
Alternatively, you can call the REST API endpoints. Refer to the developer site section for more details.