API Developmentrecurring-payments

Draft Cancel Billing Agreement

You must cancel a Billing Agreement when a customer or you, the merchant want to end an agreement.

The process starts with this delete:

DELETE /v2/billing-agreements/{token}

This endpoint cancels an active billing agreement.

Sample Request

1DELETE https://api-sandbox.afterpay.com/v2/billing-agreements/{token} HTTP/1.1
2Host: api-sandbox.afterpay.com
3Accept: application/json

Request Parameters

NameInTypeRequiredDescription
tokenpathstringyesThe token of the agreement to be cancelled.

Responses

StatusMeaningDescriptionSchema
200OKSuccessful. Returns the billing agreement object with a status of cancelled.Agreement
401UnauthorisedInvalid Merchant API credentials were passed in the Authorisation header.Error
404Not FoundThe agreement with the given ID could not be found.Error
405Method Not AllowedThe request used an unacceptable HTTP method. Depending on the endpoint, only PUT or POST requests are allowed. Use the OPTIONS HTTP method to decide which methods are allowed for each endpoint.Error
406Not AcceptableThe request included an Accept header for something other than application/json or ”/Error
412Precondition FailedThe agreement has already been cancelled.Error
500Internal Server ErrorA common cause of this response from PUT/POST endpoints is that the request body is missing or empty.Error

Example responses

200 Response

1{
2 "id": "_7IgXzApNiRoxpEb04LbAFQShsvdE_H3",
3 "merchantReference": "merchant-billing-agreement-1234",
4 "pageUrl": "https://merchant.com/billing-agreement",
5 "consumer": {
6 "phoneNumber": "0400 000 000",
7 "givenNames": "Joe",
8 "surname": "Customer",
9 "email": "test@example.com"
10 },
11 "createdAt": "2021-04-16T02:49:04.740Z",
12 "status": "CANCELLED",
13 "cancelledAt": "2021-07-05T11:23:07.740Z"
14}

401 Response

1{
2 "errorCode": "unauthorized",
3 "errorId": "16628d4fb02900d4",
4 "message": "Credentials are required to access this resource.",
5 "httpStatusCode": 401
6}

404 Response

1{
2 "errorCode": "not_found",
3 "errorId": "16628d4fb02900d4",
4 "message": "Not found",
5 "httpStatusCode": 404
6}

405 Response

1{
2 "errorCode": "method_not_allowed",
3 "errorId": "16628d4fb02900d4",
4 "message": "Method not allowed",
5 "httpStatusCode": 405
6}

412 Response

1{
2 "errorCode": "invalid_billing_agreement_status",
3 "errorId": "16628d4fb02900d4",
4 "message": "The billing agreement has already been cancelled.",
5 "httpStatusCode": 412
6}

500 Response

1{
2 "errorCode": "error",
3 "errorId": "16628d4fb02900d4",
4 "message": "Internal server error",
5 "httpStatusCode": 500
6}
Note

To cancel a Billing Agreement, you must be authenticated by MerchantAuthentication.

Recurring Payments - More Information