image Testing Refunds

Testing requires you to make API calls in the Sandbox environment:

Make sure you have credentials for the API Sandbox.
Remember to use the Sandbox environment for all tests:
https://api-platform-sandbox.flywire.com/

1. Prepare your test.

To test refunds, you have to create one refund bundle with two refunds:

  1. The first refund contains a magic value to move the refund to a specific status.

  2. The second refund contains a magic value to make the bundle reach the cut-off time (simply to speed up the test).

Note that a refund can only use one magic value, which is why you have to create two refunds.

Since a refund requires a payment and every payment can only have one active refund, you also have to create two payments:

  • Both payments must be for the same recipient (this ensures that both refunds will be in the same bundle).

  • Both payments must be in status Delivered (this ensures a refund can be created for the payment).

How to create test payments for refunds

If you already have suitable test payments, use Getting a List of all Payments and filter it to one recipient and delivered payments.

For all integrations: You can use Testing Payment Flows to quickly create two payments that move into delivered with the magic value SANDBOX_TO_DELIVERED_STATUS.

For imageElements: Alternatively, you can tokenize a card or bank account with the magic value PAYMENT DELIVERED and create two payments with the token you receive.

For 529 payments with the imageFlywire API: You can create two test payments with the magic value SANDBOX_TO_DELIVERED_STATUS.

2. Create a refund for the first payment.

This is the refund that will be moved to a specific status.

Use the following parameters:

amount integer

Any amount lower or exactly like the original payment amount.

external_reference string

Depends on which status you want to move the refund to:

Move Refund to Status...external_reference

Received

#SANDBOX_TO_RECEIVED_STATUS

Finished

#SANDBOX_TO_FINISHED_STATUS

notifications_url string (url)

A URL where you can receive callbacks to test the notifications.

Since you are testing status notifications, make sure to provide a notifications URL where you can receive the notifications via callbacks.

Testing requires you to make API calls in the Sandbox environment:

Make sure you have credentials for the API Sandbox.
Remember to use the Sandbox environment for all tests:
https://api-platform-sandbox.flywire.com/

POST/payments/v1/payments/{paymentID}/refunds

https://api-platform-sandbox.flywire.com/payments/v1/payments/FWU125675432/refunds
  -X POST
  -H "Content-Type: application/json"
  -H "X-Authentication-Key: {api_key}"
  -d '{
		“amount”: 10000,
		“external_reference”: “My test refund#SANDBOX_TO_RECEIVED_STATUS”,
		“notifications_url”: “https://webhooks/notifications/refunds”
}

3. Check the notifications.

You created a refund which automatically also created a refund bundle. You'll receive the following notifications:

image Refund initiated

image Refund bundle pending

5. Create a refund for the second payment.

This is the refund that makes the bundle reach the cut-off time.

The refunds won't move forward in the process yet, since the refund bundle must reach its cut-off time first. You could just wait until the cut-off time is reached, but you probably want to use a magic value to fast forward time and make the bundle reach the cut-off time immediately.

Use the following parameters:

amount integer

Any amount lower or exactly like the original payment amount.

external_reference string

Must be #SANDBOX_CUT_OFF_REACHED

notifications_url string (url)

A URL where you can receive callbacks to test the notifications.

Since you are testing status notifications, make sure to provide a notifications URL where you can receive the notifications via callbacks.

Testing requires you to make API calls in the Sandbox environment:

Make sure you have credentials for the API Sandbox.
Remember to use the Sandbox environment for all tests:
https://api-platform-sandbox.flywire.com/

POST/payments/v1/payments/{paymentID}/refunds

https://api-platform-sandbox.flywire.com/payments/v1/payments/FWU125675444/refunds
	-X POST
	-H "Content-Type: application/json"
	-H "X-Authentication-Key: {api_key}"
	-d '{
		“amount”: 10000,
		“external_reference”: “My test refund to reach the cut-off time#SANDBOX_CUT_OFF_REACHED”,
		“notifications_url”: “https://webhooks/notifications/refunds”
		}

5. Check the notifications.

Now that the bundle has reached the cut-off time you'll receive the following notifications:

image Refund bundle pending - marked for approval (Only for manual approvals. For automatic approvals, no notification is sent.)

6. Approve the bundle if needed.

Depending on the settings for the recipient of the refund, the approval either happens automatically or you have to manually approve it.

If you are not sure if you need to approve the bundle manually, check the approval settings for the recipient, see Recipients - Refunds: Cut-off time and Approval.

7. Check the notifications.

Now that the bundle is approved you'll receive the following notifications:

image Refund bundle approved

Within 5 minutes, the refund will move into the status you chose and you'll get more notifications:

image Refund received

image Refund bundle received

This is the end of this scenario.

If there are more refunds in the bundle, all refunds in the bundle will change their status from initiated to received.

image Refund received

image Refund bundle received

image Refund finished

image Payment reversed

This is the end of this scenario.

Only the refund you created will change its status from received to finished.
If there are other refunds in the bundle, they will change their status to received.