# Integration and Testing
source: https://developer.mastercard.com/digital-redemptions/documentation/integration-and-testing/index.md

## Ready to Begin Testing? {#ready-to-begin-testing}

Tip: We recommend that you begin testing in the sandbox.

Once you have created a project on Mastercard Developers, generated sandbox credentials and received approvals, you can start testing.

This page is the hub for testing the Digital Redemptions Service. It helps
you choose a testing path, walks you through a single-endpoint check and a
full checkout flow, and lists reusable positive and negative test cases with
the response you should expect from each.

## Choose a Testing Path {#choose-a-testing-path}

Pick the path that matches how you plan to integrate. All three paths use
the same Sandbox credentials and the Sandbox base URL listed on the
[API Basics](https://developer.mastercard.com/digital-redemptions/documentation/api-basics/index.md) page.

|         Path          |                                                                                               Best for                                                                                               |                                                                                                                      Where to start                                                                                                                      |
|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Generated API client  | Teams building the integration in Java or another supported language; the client handles OAuth signing and payload encryption for you                                                                | [Digital Redemptions Service Testing Tutorial](https://developer.mastercard.com/digital-redemptions/documentation/tutorials-and-guides/api-testing-tutorial/index.md)                                                                                    |
| Reference application | Seeing all endpoints wired together in a working Spring Boot project before you write your own code                                                                                                  | [Reference Application](https://developer.mastercard.com/digital-redemptions/documentation/reference-app/index.md)                                                                                                                                       |
| Postman or Insomnia   | Exploratory calls and quick checks without writing code; import the OpenAPI file from the [API Reference](https://developer.mastercard.com/digital-redemptions/documentation/api-reference/index.md) | [Postman Collection](https://developer.mastercard.com/platform/documentation/developer-tools/postman-collection/) or [Insomnia Collection](https://developer.mastercard.com/platform/documentation/developer-tools/insomnia-collection/) platform guides |

Whichever path you choose, authentication is OAuth 1.0a and
`POST /redeemers/search` requires payload encryption. Both are configured
once in the client, collection, or reference application; see
[Client authentication](https://developer.mastercard.com/digital-redemptions/documentation/api-basics/index.md#client-authentication)
before your first call.

## Digital Redemptions Service Testing Tutorial {#digital-redemptions-service-testing-tutorial}

Follow our [Digital Redemptions Service Testing Tutorial](https://developer.mastercard.com/digital-redemptions/documentation/tutorials-and-guides/api-testing-tutorial/index.md) for help. This tutorial explains the step-by-step process for testing the Digital Redemptions API by building an end-to-end application.

## Testing Workflow {#testing-workflow}

Work through the steps in order. Each step depends on the output of the
one before it.

### Step 1: Single-endpoint check {#step-1-single-endpoint-check}

1. Call `GET /redeemers/{user_id}` with your test RANAC, `user_id_type=RANAC`, and a `redemption_type` your program supports, as shown in [Make Your First Sandbox Call](https://developer.mastercard.com/digital-redemptions/documentation/quick-start-guide/index.md#make-your-first-sandbox-call).
2. Confirm HTTP `200` and a non-empty `householdInfo.pointBalance`.
3. Record the `pointBalance` value. You compare it against later results.

If this call fails, fix authentication and Sandbox access before you go on;
every later step will fail in the same way.

### Step 2: End-to-end checkout flow {#step-2-end-to-end-checkout-flow}

This sequence exercises the endpoints a merchant-hosted checkout uses, in
the order a real transaction calls them.

1. **Find the cardholder.** Call `POST /redeemers/search` with the test card number (BAN) in an encrypted body. Expect `200` and a `userId` of type `RANAC`. Keep the RANAC for every following call. [Search Redeemer Profile](https://developer.mastercard.com/digital-redemptions/documentation/use-cases/redeemers-profile/search-redeemer-profile/index.md)
2. **Show the balance.** Call `GET /redeemers/{user_id}` with the RANAC. Expect `200`; `householdInfo.pointBalance` and `cashEquivalent` are what your checkout displays. [Get Redeemer Profile](https://developer.mastercard.com/digital-redemptions/documentation/use-cases/redeemers-profile/get-redeemer-profile/index.md)
3. **Redeem points.** Call `POST /redemptions` with the RANAC, your `processedBy` user, and one item. Expect `200` and a `redemptionId`. [Create Redemptions](https://developer.mastercard.com/digital-redemptions/documentation/use-cases/redemptions/post-redemptions/index.md)
4. **Verify the deduction.** Repeat `GET /redeemers/{user_id}`. Expect `pointBalance` to have dropped by the points redeemed in step 3.
5. **Check the history.** Call `GET /redemptions` with the RANAC and a date range covering today. Expect the `redemptionId` from step 3 in the list. [Get Redemptions](https://developer.mastercard.com/digital-redemptions/documentation/use-cases/redemptions/get-redemptions/index.md)
6. **Reverse the redemption.** Call `POST /redemptions/{id}/credits` with the `redemptionId`. Expect `200` and a `pointBalance` equal to the value you recorded in step 2. [Reverse Redemption](https://developer.mastercard.com/digital-redemptions/documentation/use-cases/redemptions/reverse-redemption/index.md)

For merchandise programs, add `GET /redemptions/addresses` and
`POST /redemptions/addresses` between steps 2 and 3, and
`PUT /redemptions` after step 3 to report fulfilment status. See the
[Use Cases](https://developer.mastercard.com/digital-redemptions/documentation/use-cases/index.md) index for those flows.

## Test Cases {#test-cases}

Reuse these cases in your own test suite. Request parameters are the
minimum needed to trigger each result; full field descriptions are in the
[API Reference](https://developer.mastercard.com/digital-redemptions/documentation/api-reference/index.md).

### Positive cases {#positive-cases}

| #  |             Endpoint             |                                      Request                                       | Expected status |                                     Validation check                                     |
|----|----------------------------------|------------------------------------------------------------------------------------|-----------------|------------------------------------------------------------------------------------------|
| P1 | `GET /redeemers/{user_id}`       | Valid RANAC, `user_id_type=RANAC`, supported `redemption_type`                     | `200`           | `userIdType` is `RANAC`; `householdInfo.pointBalance` is a numeric string                |
| P2 | `POST /redeemers/search`         | Encrypted body with a test BAN and `userIdType=BAN`                                | `200`           | Response `userId` is a 30-character RANAC; `accountInfo.programId` matches your program  |
| P3 | `POST /redemptions`              | Valid RANAC, valid `processedBy`, one item with `pointsRedeemed` below the balance | `200`           | `redemptionId` is returned; a follow-up P1 shows the balance reduced by `pointsRedeemed` |
| P4 | `GET /redemptions`               | Valid RANAC, `from_date` and `to_date` covering the P3 call                        | `200`           | The P3 `redemptionId` appears in `redemptions[]`                                         |
| P5 | `POST /redemptions/{id}/credits` | P3 `redemptionId`, valid RANAC and `processedBy`, no `partialCreditPoints`         | `200`           | `pointBalance` equals the pre-P3 balance                                                 |
| P6 | `POST /redemptions/{id}/credits` | P3 `redemptionId` with `partialCreditPoints` less than the points redeemed         | `200`           | `pointBalance` increases by exactly `partialCreditPoints`                                |

### Negative cases {#negative-cases}

| #  |             Endpoint             |                                 Request                                  | Expected status |                     Expected error                      |                        Validation check                        |
|----|----------------------------------|--------------------------------------------------------------------------|-----------------|---------------------------------------------------------|----------------------------------------------------------------|
| N1 | Any                              | Wrong consumer key or unsigned request                                   | `401`           | `Unauthorized - Access Not Granted` (`Source: Gateway`) | Fix credentials; no Digital Redemptions error code is returned |
| N2 | `GET /redeemers/{user_id}`       | RANAC not enrolled in your program                                       | `400` or `404`  | `INVALID_ACCOUNT_NOT_FOUND`                             | `Recoverable` is `false`; balance is not returned              |
| N3 | `POST /redemptions`              | `pointsRedeemed` greater than the balance from P1                        | `400`           | `EXPIRED_POINTS`                                        | No `redemptionId`; a follow-up P1 shows the balance unchanged  |
| N4 | `POST /redemptions`              | Unknown `processedBy` value                                              | `400`           | `INVALID_SECURITY_USER`                                 | No `redemptionId`; balance unchanged                           |
| N5 | `POST /redemptions/{id}/credits` | `partialCreditPoints` greater than the points on the original redemption | `400`           | `INVALID_PARTIAL_CREDIT_POINTS`                         | Balance unchanged                                              |
| N6 | `GET /redemptions/addresses`     | `user_id_type=RANAC` instead of `RANCU`                                  | `400`           | `INVALID_USER_ID_TYPE_RANCU`                            | Resend with the RANCU                                          |

For the meaning of each error code, its cause, and the fix, see
[Codes and Formats](https://developer.mastercard.com/digital-redemptions/documentation/code-and-formats/index.md).

## Next Steps {#next-steps}

* You can head to our [Reference Application](https://developer.mastercard.com/digital-redemptions/documentation/reference-app/index.md) page to download our Spring Boot Application that shows a typical usage of the Digital Redemptions service.
* To learn more about any error codes you receive, head over to our [Codes and Formats](https://developer.mastercard.com/digital-redemptions/documentation/code-and-formats/index.md) section to learn about the details of all the error codes.
* When your Sandbox tests pass, follow [Move Project to Production](https://developer.mastercard.com/digital-redemptions/documentation/tutorials-and-guides/production-access-tutorial/index.md).
