- [HTTP request](https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#body.HTTP_TEMPLATE)
- [Request body](https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#body.request_body)
  - [JSON representation](https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#body.request_body.SCHEMA_REPRESENTATION)
- [Response body](https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#body.response_body)
- [RefundResponse](https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#RefundResponse)
  - [JSON representation](https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#RefundResponse.SCHEMA_REPRESENTATION)
- [RefundResultCode](https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#RefundResultCode)
- [RawResult](https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#RawResult)
  - [JSON representation](https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#RawResult.SCHEMA_REPRESENTATION)

Refunds a portion of or the entire transaction initiated through `generateReferenceNumber`. The `requestId` within the header is the idempotency key, which uniquely identifies this transaction.

If the endpoint encounters an error while processing the request, the response body from this endpoint should be of type `https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/ErrorResponse`.

An example request looks like:


    {
      "requestHeader": {
        "protocolVersion": {
          "major": 1,
          "minor": 0,
          "revision": 0
        },
        "requestId": "bWVyY2hhbnQgdHJhbnNhY3Rpb24gaWQ",
        "requestTimestamp": "1502223797000"
      },
      "paymentIntegratorAccountId": "InvisiCashUSA_USD",
      "generateReferenceNumberRequestId": "aW50ZWdyYXRvciB0cmFuc2FjdGlvbiBpZA",
      "currencyCode": "USD",
      "refundAmount": "10000000",
      "pixEndToEndIdToRefund": "E28315987135981735987351",
      "refundId": "006"
    }

An example response looks like:


    {
      "responseHeader": {
        "responseTimestamp": "1481900013178"
      },
      "result": "SUCCESS",
      "paymentIntegratorRefundId": "cmVmdW5kIGlkZW50aWZpZXINCg"
    }

### HTTP request

`POST https://www.integratorhost.example.com/integrator-base-path/refundable-one-time-payment-code-v1/refund`

### Request body

The request body contains data with the following structure:

| JSON representation |
|---|
| ``` { "requestHeader": { object (`https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/RequestHeader`) }, "paymentIntegratorAccountId": string, "generateReferenceNumberRequestId": string, "currencyCode": string, "refundAmount": string, "refundId": string, // The following is a list of mutually exclusive fields. At most one of the // fields will be set in a response: "pixEndToEndIdToRefund": string // End of mutually exclusive fields. } ``` |

| Fields ||
|---|---|
| `requestHeader` | ``object (`https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/RequestHeader`)`` **REQUIRED**: Common header for all requests. |
| `paymentIntegratorAccountId` | `string` **REQUIRED**: This is the payment integrator account identifier on which the reference number was created. |
| `generateReferenceNumberRequestId` | `string` **REQUIRED** : Request ID of the `generateReferenceNumber` request to be refunded. |
| `currencyCode` | `string` **REQUIRED**: ISO 4217 3-letter currency code. |
| `refundAmount` | `string (https://developers.google.com/discovery/v1/type-format format)` **REQUIRED** : The amount of the refund, a positive number of [micros](https://developers.google.com/pay/refundable-one-time-payment-code-v1/reference/glossary#micros "What are micros?") of the currency unit. |
| `refundId` | `string` **OPTIONAL** : Identifies this particular refund request since multiple partial refunds are possible. This ID is 1:1 with the `requestId` in the `requestHeader`, but is shorter and structured. Format: three numerical digits (e.g. "001", "004", "999"). <br /> > [!NOTE] > **Note:** This field will transition to be required once it is being set in all cases. <br /> |
| **OPTIONAL**: Identifier specific for a network. This identifies the payment that needs to be refunded. <br /> > [!NOTE] > **Note:** This field will transition to be required once it is being set in all cases. The following is a list of mutually exclusive fields. At most one of the fields will be set in a response: <br /> ||
| `pixEndToEndIdToRefund` | `string` This ID was created by Banco Central do Brasil (BCB) for the Brazilian instant payment ecosystem (Pix). This ID is used to identify the payment that needs to be refunded. |
| End of mutually exclusive fields. ||

### Response body

This method supports multiple return types. For additional information about what 4XX or 5XX HTTP status code to return with an `ErrorResponse`, consult the `ErrorResponse` object and [HTTP status codes documentation](https://developers.google.com/pay/refundable-one-time-payment-code-v1/guides/connectivity/protocol-standards#http_status_codes).

| Possible response messages ||
|---|---|
| HTTP 200 Status | ``object (`https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#RefundResponse`)`` |
| HTTP 4XX / 5XX Status | ``object (`https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/ErrorResponse`)`` |
| End of mutually exclusive fields. ||

## RefundResponse

Response object for the `refund` method.

| JSON representation |
|---|
| ``` { "responseHeader": { object (`https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/ResponseHeader`) }, "paymentIntegratorRefundId": string, "result": enum (`https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#RefundResultCode`), "rawResult": { object (`https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#RawResult`) }, // The following is a list of mutually exclusive fields. At most one of the // fields will be set in a response: "pixEndToEndId": string // End of mutually exclusive fields. } ``` |

| Fields ||
|---|---|
| `responseHeader` | ``object (`https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/ResponseHeader`)`` **REQUIRED**: Common header for all responses. |
| `paymentIntegratorRefundId` | `string` **OPTIONAL**: This identifier is specific to the integrator and is generated by the integrator. This is the identifier that the integrator knows this refund by. For convenience, this identifier is included with in the remittance details |
| `result` | ``enum (`https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#RefundResultCode`)`` **REQUIRED**: Result of this refund. |
| `rawResult` | ``object (`https://developers.google.com/pay/refundable-one-time-payment-code-v1/payment-integrator-refundable-one-time-payment-code-api/refund#RawResult`)`` **OPTIONAL** : Raw result of this refund. Used to help inform Google's risk engine and analytics. In decline code--mapping situations, data is sometimes lost. The integrator can choose to give Google a raw code. For example, a credit card gateway (the integrator) may use this field to communicate to Google the exact decline code that was received from the VISA network. In that case, the `scope` would be "visa" and the `rawCode` would be whatever the VISA network returned. This value is **required** if the `result` is not `SUCCESS`. |
| **OPTIONAL**: Identifier specific for a network. The following is a list of mutually exclusive fields. At most one of the fields will be set in a response: ||
| `pixEndToEndId` | `string` This ID is created by Banco Central do Brasil (BCB) for the Brazilian instant payment ecosystem (Pix). This ID is used to identify the operation on a transaction, in this case it identifies the refund operation. |
| End of mutually exclusive fields. ||

## RefundResultCode

The unique result codes refunds.

| Enums ||
|---|---|
| `UNKNOWN_RESULT` | Do not ever set this default value! |
| `SUCCESS` | Successful refund. |
| `NO_MONEY_LEFT_ON_TRANSACTION` | refundable-one-time-payment-code-v1.refund failed, there is no money left on the transaction. Typically this represents bug between the integrator and Google. Google should not ask to refund an amount greater than the original capture. |
| `ACCOUNT_CLOSED` | The account held with the integrator has been closed. Returning this value will cause the user's instrument to be closed with Google. The user will be forced to add a new instrument by going through the association flow again. |
| `ACCOUNT_CLOSED_ACCOUNT_TAKEN_OVER` | The user's account with the integrator has been closed, suspected account take over. Returning this value will cause the user's instrument to be closed with Google. The user will be forced to add a new instrument by going through the association flow again. |
| `ACCOUNT_CLOSED_FRAUD` | The user's account held with the integrator has been closed because of fraud. Returning this value will cause the user's instrument to be closed with Google. The user will be forced to add a new instrument by going through the association flow again. |
| `ACCOUNT_ON_HOLD` | The user's account is currently on hold and cannot accept the refund, but the user's account may later be able to accept the refund. Google may request another refund in the future, but will do so with a new `requestId`, so this request should be considered finished. |
| `REFUND_EXCEEDS_MAXIMUM_BALANCE` | The refund cannot be processed at the current time, because doing so would cause the user's balance to exceed the maximum allowed amount. Google may request another refund in the future, but will do so with a new `requestId`, so this request should be considered finished. |
| `REFUND_WINDOW_EXCEEDED` | The refund cannot be processed because the request is outside of the allowed refund period. |
| `CAPTURE_USED_PROMOTIONAL_BALANCE` | The amount used in the purchased was earned through cashback and refunds are not allowed. |
| `ISSUER_DOES_NOT_SUPPORT_REFUND` | The refund cannot be processed because the issuer does not support refunds. |
| `GOOGLE_PAYMENT_TOKEN_INVALIDATED_BY_USER` | Returning this value will cause the user's instrument to be closed with Google. The user will be forced to add a new instrument by going through the association flow again. |

## RawResult

Raw result object.

| JSON representation |
|---|
| ``` { "scope": string, "rawCode": string } ``` |

| Fields ||
|---|---|
| `scope` | `string` **OPTIONAL**: Scope of the rawCode, can be empty. |
| `rawCode` | `string` **REQUIRED**: Raw code from the integrator or subsystems within it. |