Skip to main content
Skip to main content
You're viewing the documentation for v1, which isn't the latest Medusa version.Latest documentation

AdminPaymentsResource

This class is used to send requests to Admin Payment API Routes. All its method are available in the JS Client under the medusa.admin.payments property.

All methods in this class require user authentication.

A payment can be related to an order, swap, return, or more. It can be captured or refunded.

Methods​

retrieve​

Retrieve a payment's details.

Example​

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.payments.retrieve(paymentId)
.then(({ payment }) => {
console.log(payment.id);
})

Parameters​

idstringRequired
The payment's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Configurations to apply on the retrieved payment.

Returns​

ResponsePromiseResponsePromise<AdminPaymentRes>Required
Resolves to the payment's details.

capturePayment​

Capture a payment.

Example​

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.payments.capturePayment(paymentId)
.then(({ payment }) => {
console.log(payment.id);
})

Parameters​

idstringRequired
The payment's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<AdminPaymentRes>Required
Resolves to the payment's details.

refundPayment​

Refund a payment. The payment must be captured first.

Example​

import { RefundReason } from "@medusajs/medusa";
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.payments.refundPayment(paymentId, {
amount: 1000,
reason: RefundReason.RETURN,
note: "Do not like it",
})
.then(({ refund }) => {
console.log(refund.amount);
})

Parameters​

idstringRequired
The payment's ID.
The refund to be created.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<AdminRefundRes>Required
Resolves to the refund's details.
Was this section helpful?