Skip to main content
Skip to main content

Payments

Queries and Mutations listed here are used to send requests to the Admin Payment API Routes.

All hooks listed require authentication.

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

Mutations

useAdminPaymentsCapturePayment

This hook captures a payment.

Example

import React from "react"
import { useAdminPaymentsCapturePayment } from "medusa-react"

type Props = {
paymentId: string
}

const Payment = ({ paymentId }: Props) => {
const capture = useAdminPaymentsCapturePayment(
paymentId
)
// ...

const handleCapture = () => {
capture.mutate(void 0, {
onSuccess: ({ payment }) => {
console.log(payment.amount)
}
})
}

// ...
}

export default Payment

Hook Parameters

idstringRequired
The payment's ID.

Mutation Function Returned Data

AdminPaymentResAdminPaymentResRequired
The payment's details.

useAdminPaymentsRefundPayment

This hook refunds a payment. The payment must be captured first.

Example

import React from "react"
import { RefundReason } from "@medusajs/medusa"
import { useAdminPaymentsRefundPayment } from "medusa-react"

type Props = {
paymentId: string
}

const Payment = ({ paymentId }: Props) => {
const refund = useAdminPaymentsRefundPayment(
paymentId
)
// ...

const handleRefund = (
amount: number,
reason: RefundReason,
note: string
) => {
refund.mutate({
amount,
reason,
note
}, {
onSuccess: ({ refund }) => {
console.log(refund.amount)
}
})
}

// ...
}

export default Payment

Hook Parameters

idstringRequired
The payment's ID.

Mutation Function Parameters

AdminPostPaymentRefundsReqAdminPostPaymentRefundsReqRequired
The details of the refund to create.

Mutation Function Returned Data

AdminRefundResAdminRefundResRequired
The refund's details.

Queries

useAdminPayment

This hook retrieves a payment's details.

Example

import React from "react"
import { useAdminPayment } from "medusa-react"

type Props = {
paymentId: string
}

const Payment = ({ paymentId }: Props) => {
const {
payment,
isLoading,
} = useAdminPayment(paymentId)

return (
<div>
{isLoading && <span>Loading...</span>}
{payment && <span>{payment.amount}</span>}

</div>
)
}

export default Payment

Hook Parameters

idstringRequired
The payment's ID.

Query Returned Data

paymentPaymentRequired
Payment details
Was this section helpful?