--- displayed_sidebar: jsClientSidebar slug: /references/js-client/AdminPaymentsResource --- import ParameterTypes from "@site/src/components/ParameterTypes" # AdminPaymentsResource This class is used to send requests to [Admin Payment API Routes](https://docs.medusajs.com/api/admin#payments). All its method are available in the JS Client under the `medusa.admin.payments` property. All methods in this class require [user authentication](AdminAuthResource.mdx#createsession). A payment can be related to an order, swap, return, or more. It can be captured or refunded. ## Methods ### capturePayment Capture a payment. #### Example ```ts 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 `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "The data required for the Payment Provider to identify, modify and process the Payment. Typically this will be an object that holds an id to the external payment session, but can be an empty object if the Payment Provider doesn't hold any state.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The payment's ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "idempotency_key", "type": "`string`", "description": "Randomly generated key used to continue the completion of a payment in case of failure.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "metadata", "type": "`Record`", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "order", "type": "[Order](../internal/classes/internal.Order.mdx)", "description": "The details of the order that the payment session was potentially created for.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "order_id", "type": "`string`", "description": "The ID of the order that the payment session was potentially created for.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "provider_id", "type": "`string`", "description": "The id of the Payment Provider that is responsible for the Payment", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "swap", "type": "[Swap](../internal/classes/internal.Swap.mdx)", "description": "The details of the swap that this payment was potentially created for.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "swap_id", "type": "`string`", "description": "The ID of the swap that this payment was potentially created for.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### refundPayment Refund a payment. The payment must be captured first. #### Example ```ts 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: "return", note: "Do not like it", }) .then(({ payment }) => { console.log(payment.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "note", "type": "`string`", "description": "An optional note explaining why the amount was refunded.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "order", "type": "[Order](../internal/classes/internal.Order.mdx)", "description": "The details of the order this refund was created for.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "order_id", "type": "`string`", "description": "The ID of the order this refund was created for.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "payment", "type": "[Payment](../internal/classes/internal.Payment.mdx)", "description": "The details of the payment associated with the refund.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "payment_id", "type": "`string`", "description": "The payment's ID, if available.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "reason", "type": "`string`", "description": "The reason given for the Refund, will automatically be set when processed as part of a Swap, Claim or Return.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### retrieve Retrieve a payment's details. #### Example ```ts 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 `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "The data required for the Payment Provider to identify, modify and process the Payment. Typically this will be an object that holds an id to the external payment session, but can be an empty object if the Payment Provider doesn't hold any state.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The payment's ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "idempotency_key", "type": "`string`", "description": "Randomly generated key used to continue the completion of a payment in case of failure.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "metadata", "type": "`Record`", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "order", "type": "[Order](../internal/classes/internal.Order.mdx)", "description": "The details of the order that the payment session was potentially created for.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "order_id", "type": "`string`", "description": "The ID of the order that the payment session was potentially created for.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "provider_id", "type": "`string`", "description": "The id of the Payment Provider that is responsible for the Payment", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "swap", "type": "[Swap](../internal/classes/internal.Swap.mdx)", "description": "The details of the swap that this payment was potentially created for.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "swap_id", "type": "`string`", "description": "The ID of the swap that this payment was potentially created for.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} />