# Sandbox Testing
source: https://developer.mastercard.com/automatic-billing-updater/documentation/testing/index.md

ABU supports your ABU API integration by providing mock responses to simulate ABU behavior for your API calls. You must be onboarded to ABU's test environment before you can receive mock responses from ABU at your defined client endpoints.

Responses containing each possible ABU account update reason code will be generated based on the `accountNumber` used in your API request during sandbox testing.

## ABU Push Test Cases {#abu-push-test-cases}

ABU supports your ABU Push model integration testing by providing mock responses that mimic ABU behavior for subscription management and when notifying you of an account update available to an account that you have subscribed to.

In order to complete a full test scenario, from subscribing to an account to receiving notifications, it is necessary to be properly onboarded to the Push model:

* You must provide the clientId to be associated with your ICA
* You must provide a URL endpoint at which you want to receive ABU push notifications
* An mTLS certificate provided by your Mastercard implementation project manager must be used to receive notifications on the designated endpoint

#### Test cases for subscribing to an account and receiving notifications {#test-cases-for-subscribing-to-an-account-and-receiving-notifications}

When subscribing to an account number that ends with 0 -- 9, ABU's payload for the Account Subscriptions API response will include the corresponding account update reason code as detailed in the below table.

When making a subscription request using an account number that ends with --12, --22, or --32 (note that all of these test cases qualify as account numbers ending with 2), ABU supports mock notifications that simulate the notification that ABU sends when Mastercard receives an update for this account in the future. In these cases, ABU sends a `VALID` response in the account subscriptions API response indicating the account credentials submitted in the request are the most up-to-date credentials in the ABU database. Following that, a notifications API request with the mock notification corresponding to the `accountNumber` used in the subscription request will be sent shortly thereafter to your designated test endpoint.

The following table details the type of account update communicated in the notification from ABU for each account subscribed.
Warning: To receive notifications from ABU during testing, you must first be enrolled in ABU. Ensure the `ica` used in the subscription request matches the ICA you have enrolled in ABU with when you created a project and configured your client endpoints. Note: Test cases for account subscriptions API and notifications API are linked. Mock notifications that ABU sends will contain the same `accountNumber` provided in the subscription request.

| Account Subscriptions API Request Payload |                                 Account Subscriptions API Response Payload                                  |                                                                   Notifications API Request Payload                                                                   |
|-------------------------------------------|-------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `accountNumber` ending with 0 or 3        | 'Account number update' response, `responseIndicator` = `ACCOUNT_UPDATE`                                    | No mock notification will be generated during sandbox testing                                                                                                         |
| `accountNumber` ending with 1             | 'Account not found' response from a non-ABU participating issuer, `responseIndicator` = `NON_PARTICIPATING` | No mock notification will be generated during sandbox testing                                                                                                         |
| `accountNumber` ending with 2             | 'Account is up-to-date' response, `responseIndicator` = `VALID`                                             | Mock notifications supported for `accountNumber` ending with --12, --22, or --32 *Sample payloads of notifications sent by ABU are provided below, after this table.* |
| `accountNumber` ending with 4             | 'Closed account' response, `responseIndicator` = `CONTACT`                                                  | No mock notification will be generated during sandbox testing                                                                                                         |
| `accountNumber` ending with 5             | 'Expiry date update available' response, `responseIndicator` = `EXPIRY`                                     | No mock notification will be generated during sandbox testing                                                                                                         |
| `accountNumber` ending with 6             | An example error response                                                                                   | Not available                                                                                                                                                         |
| `accountNumber` ending with 7             | 'Account not found' response from an ABU-participating issuer, `responseIndicator` = `UNKNOWN`              | No mock notification will be generated during sandbox testing                                                                                                         |
| `accountNumber` ending with 8             | A prolonged response time of ten seconds to simulate a timeout                                              | No mock notification will be generated during sandbox testing                                                                                                         |
| `accountNumber` ending with 9             | Error response: 'ABU Push system not available, unable to subscribe at this time'                           | No mock notification will be generated during sandbox testing                                                                                                         |

##### Sample payloads for account subscriptions made by merchants and submerchants {#sample-payloads-for-account-subscriptions-made-by-merchants-and-submerchants}

The `requestId` data provided in the initial account subscription request is reflected in notifications that ABU sends for this account. If the initial subscription request is made by a submerchant (i.e. it contains a `subMerchantId`), then `requestId` will be nested within the submerchant information. Otherwise ABU will return `requestId` at the merchant level.

Refer to the following sample payloads to understand how `requestId` is populated differently in the notifications API payload for each scenario:

* The samples for `accountNumber` ending with --12 and --22 show subscriptions made by a merchant, where `subMerchantId` is *not* present.
  * Notice that `requestId` is populated at the `merchantId` level.
* The sample for `accountNumber` ending with --32 shows a subscription made for a submerchant, so `subMerchantId` is present.
  * Notice that `requestId` is populated at the `subMerchantId` level.

<br />

* Subscription is made by a merchant
* Notification is triggered when an expiry date update was available

<br />

**Account subscription request payload**

`accountNumber` ending with -12  

`subMerchantId` not present

```json
{
  "requestId": "323e304f-1cfc-4f0d-ac07-e6037ce09925",
  "customer": {
    "ica": "1111",
    "merchantId": "XXX000000000XXX"
  },
  "account": {
    "accountNumber": "52XXXXXXXXXXXXXX12",
    "expiryDate": "1218"
  }
}
```

\*\*Account subscription response payload\*\*

```json
{
  "responseIndicator": "VALID"
}
```

\*\*Notification request payload\*\*

Expiry notification payload

```json
{
    "abuReferenceId": "583a6cae-57fe-40a6-b520-e24e6f969d60",
    "oldAccountNumber": "52XXXXXXXXXXXXXX12",
    "oldExpirationDate": "0518",
    "newAccountNumber": "52XXXXXXXXXXXXXX12",
    "newExpirationDate": "0923",
    "reasonIdentifier": "E",
    "eventDateTime": "2021-06-22T09:14:13.512Z",
    "ica": "1111",
    "merchants": [{
        "merchantId": "XXX000000000XXX",
        "requestId": "323e304f-1cfc-4f0d-ac07-e6037ce09925"
    }]
}
```

* Subscription is made by a merchant
* Notification is triggered when an account number update was available

<br />

**Account subscription request payload**

`accountNumber` ending with -22  

`subMerchantId` not present

```json
{
  "requestId": "323e304f-1cfc-4f0d-ac07-e6037ce09925",
  "customer": {
    "ica": "1111",
    "merchantId": "XXX000000000XXX"
  },
  "account": {
    "accountNumber": "52XXXXXXXXXXXXXX22",
    "expiryDate": "1218"
  }
}
```

\*\*Account subscription response payload\*\*

```json
{
  "responseIndicator": "VALID"
}
```

\*\*Notification request payload\*\*

Update notification payload

```json
{
    "abuReferenceId": "583a6cae-57fe-40a6-b520-e24e6f969d60",
    "oldAccountNumber": "52XXXXXXXXXXXXXX12",
    "oldExpirationDate": "0518",
    "newAccountNumber": "22XXXXXXXXXXXXXX56",
    "newExpirationDate": "0923",
    "reasonIdentifier": "A",
    "eventDateTime": "2021-06-22T09:14:13.512Z",
    "ica": "1111",
    "merchants": [{
        "merchantId": "XXX000000000XXX",
        "requestId": "323e304f-1cfc-4f0d-ac07-e6037ce09925"
    }]
}
```

* Subscription is made by a payment facilitator on behalf of a submerchant
* Notification is triggered when an account was closed

<br />

**Account subscription request payload**

`accountNumber` ending with -32  

`subMerchantId` present

```json
{
  "requestId": "323e304f-1cfc-4f0d-ac07-e6037ce09925",
  "customer": {
    "ica": "1111",
    "merchantId": "XXX000000000XXX",
    "subMerchantId": "XXX100000001XXX"
  },
  "account": {
    "accountNumber": "52XXXXXXXXXXXXXX32",
    "expiryDate": "1218"
  }
}
```

\*\*Account subscription response payload\*\*

```json
{
  "responseIndicator": "VALID"
}
```

\*\*Notification request payload\*\*

Closed account notification payload

```json
{
    "abuReferenceId": "583a6cae-57fe-40a6-b520-e24e6f969d60",
    "oldAccountNumber": "52XXXXXXXXXXXXXX32",
    "oldExpirationDate": "0000",
    "newAccountNumber":null,
    "newExpirationDate":null,
    "reasonIdentifier": "C",
    "eventDateTime": "2021-06-22T09:14:13.512Z",
    "ica": "1111",
    "merchants": [{
        "merchantId": "XXX000000000XXX",
        "subMerchants": [{
            "subMerchantId": "XXX100000001XXX",
            "requestId": "323e304f-1cfc-4f0d-ac07-e6037ce09925"
        }]
    }]
}
```

#### Test cases for checking if a subscription is active {#test-cases-for-checking-if-a-subscription-is-active}

When checking a merchant's subscription status for an account by making a Subscription Inquiries API request, ABU provides a different mock response payload for the API response based on account number ending with 0 -- 3 as detailed in the following table.

| `accountNumber` Used In Subscription Inquiries API Request |            Subscription Inquiries API Response             |
|------------------------------------------------------------|------------------------------------------------------------|
| `accountNumber` ending with 0                              | Account is not subscribed, `subscribed` = `false`          |
| `accountNumber` ending with 1                              | Account is subscribed, `subscribed` = `true`               |
| `accountNumber` ending with 2                              | Internal Server Error, `ReasonCode` = `SYSTEM_ERROR`       |
| `accountNumber` ending with 3                              | Unauthorized Error, `ReasonCode` = `AUTHENTICATION_FAILED` |

#### Test cases for deleting a subscription {#test-cases-for-deleting-a-subscription}

ABU generates the same successful mock response for each successful API call with HTTP status code 200 regardless of the `accountNumber` used in the subscription deletion request.
Note: Mock responses that ABU sends for subscription inquiries API test cases are *not* linked to the test cases for account subscriptions. You do not need to use the same `accountNumber` for subscription inquiries as for account subscriptions in order to generate the desired mock responses. All successful subscription inquiries made during sandbox testing generate the same response from ABU.

| `accountNumber` Used In Subscription Deletions API Request |                   Subscription Deletions API Response                    |
|------------------------------------------------------------|--------------------------------------------------------------------------|
| `accountNumber` ending with any number                     | HTTP Status 202 indicating a successfully received subscription deletion |

## ABU Pull Test Cases {#abu-pull-test-cases}

ABU provides sample account updates through mock responses to your Account Inquiries API calls in the test environment.

#### Test cases for account inquiries {#test-cases-for-account-inquiries}

When making an account inquiry using an account number that ends with 0 -- 9, ABU's payload for the API response will include the corresponding account update reason code as detailed in the following table.

| `accountNumber` Used In Account Inquiries API Request |                                       Account Update Status Provided in Account Inquiries API Response                                       |
|-------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `accountNumber` ending with 0 or 3                    | 'Account number update' response, `responseIndicator` = `ACCOUNT_UPDATE`                                                                     |
| `accountNumber` ending with 1                         | 'Account not found' response from a non-ABU participating issuer BIN (Bank Identification Number), `responseIndicator` = `NON_PARTICIPATING` |
| `accountNumber` ending with 2 or 9                    | 'Account is up-to-date' response, `responseIndicator` = `VALID`                                                                              |
| `accountNumber` ending with 4                         | 'Closed account' response, `responseIndicator` = `CONTACT`                                                                                   |
| `accountNumber` ending with 5                         | 'Expiry date update available' response, `responseIndicator` = `EXPIRY`                                                                      |
| `accountNumber` ending with 6                         | Not applicable - this test case simulates an error Error response is provided                                                                |
| `accountNumber` ending with 7                         | 'Account not found' response from an ABU-participating issuer BIN (Bank Identification Number), `responseIndicator` = `UNKNOWN`              |
| `accountNumber` ending with 8                         | A prolonged response time of ten seconds to simulate a timeout                                                                               |

