- Docs
- Payments
Capture, void, and refund
Authorize now and capture later, cancel before settlement, or return money after it.
A payment captures straight away unless you say otherwise. Send capture: false and the card is only authorized: the funds are held, nothing moves, and you decide later whether to take the money or let it go.
Authorize, then capture
Section titled “Authorize, then capture”Create the payment with capture: false. It comes back as requires_capture. When the order ships, capture it. Leave the amount out to take the full authorization, or send a smaller amount to capture part of it and release the rest.
// Authorize now, capture on dispatch
const auth = await myela.gateway.payments.create({
amount: 4999,
currency: 'USD',
paymentToken,
capture: false,
});
await myela.gateway.payments.capture(auth.id); // full
await myela.gateway.payments.capture(auth.id, { amount: 2000 }); // partial — releases the rest
await myela.gateway.payments.void(auth.id); // or cancel# Capture (omit amount for the full authorization)
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/payments/{id}/capture \
-H "Authorization: Bearer myela_sk_test_…" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: capture_order_1001" \
-d '{ "amount": 4999 }'
# Void (no body)
curl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/payments/{id}/void \
-H "Authorization: Bearer myela_sk_test_…"Capture happens once. After any capture, a second one is refused, so a partial capture is final for that payment. Partial capture also depends on the account: where it isn’t available, the API answers 501 capability_not_supported, and you either capture in full or void.
An authorization you never capture doesn’t wait forever. It expires on the provider’s schedule, not Myela’s, and the payment then reads failed.
Void before it settles
Section titled “Void before it settles”Void cancels a payment that hasn’t settled, whether it’s still an authorization or already captured. It’s cheaper than a refund and the cardholder never sees a charge. Void takes no body. Once a payment has settled, void is refused with 409 conflict; refund it instead.
Refund after capture
Section titled “Refund after capture”Refund returns captured money to the original card. Leave the amount out to refund everything that’s left, or send an amount and repeat partial refunds up to the captured total. Asking for more than is left is a 409.
await myela.gateway.payments.refund(id, { amount: 2500 }); // omit amount to refund the rest
await myela.gateway.payments.retrieve(id); // confirm before any retrycurl -X POST https://payments-api-sandbox.merchantservicedepot.com/v1/payments/{id}/refund \
-H "Authorization: Bearer myela_sk_test_…" \
-H "Content-Type: application/json" \
-d '{ "amount": 2500 }'The response confirms that Myela accepted the refund. Completion arrives later as the payment.refunded webhook, and when it shows on the statement is up to the card issuer. The payment.settled and payment.refunded events don’t fire on every account yet, so read the payment if you need certainty. There’s no unlinked credit: POST /v1/credits answers 501, and refund is the way money goes back.
Statuses
Section titled “Statuses”Every operation returns the payment. Its status tells you what you can do next, and amountCaptured and amountRefunded tell you how much is left.
| status | Means | You can |
|---|---|---|
requires_capture |
Authorized, funds held. | Capture or void. |
pending_settlement |
Captured, not settled yet. | Void or refund. |
settled |
The money is yours. | Refund. |
partially_refunded |
Some money went back. | Refund the rest. |
refunded |
All captured money went back. | Nothing. |
voided |
Canceled before settlement. The cardholder was never charged. | Nothing. |
declined |
The issuer said no. | Nothing. |
failed |
Failed, or the authorization expired. | Nothing. |
Retrying safely
Section titled “Retrying safely”Send an Idempotency-Key when you create or capture, and a retry with the same key returns the same payment instead of charging twice. Void and refund don’t take a key. If either fails in a way you can’t read, a timeout or a dropped connection, fetch the payment with GET /v1/payments/{id} before you try again. More in Idempotency and retries.
Conflicts come back as 409 with a details.code you can branch on:
| details.code | When |
|---|---|
IDEMPOTENCY_KEY_REUSED |
The capture key was already used on a different payment. |
IDEMPOTENT_ATTEMPT_UNRESOLVED |
An earlier attempt hasn’t resolved. Read the payment, then decide. |
IDEMPOTENT_ATTEMPT_FAILED |
An earlier attempt with this key was rejected. |
CONCURRENT_MODIFICATION |
Another capture, void, or refund on this payment got there first. |
CAPTURE_OUTCOME_UNKNOWN |
The capture’s outcome is unknown. Sync the payment before trying again. |
VOID_OUTCOME_UNKNOWN |
The void’s outcome is unknown. Sync the payment before trying again. |
REFUND_OUTCOME_UNKNOWN |
The refund’s outcome is unknown. Sync the payment before trying again. |