IPaymentProvider
Methods#
initiatePayment#
Parameters
The data used initiate a payment in a provider when a payment
session is created.
Returns
Promise
Promise<InitiatePaymentOutput>
Promise
Promise<InitiatePaymentOutput>updatePayment#
Parameters
The attributes to update a payment related to a payment session in a provider.
Returns
Promise
Promise<UpdatePaymentOutput>
Promise
Promise<UpdatePaymentOutput>deletePayment#
Parameters
The data to delete a payment.
Returns
Promise
Promise<DeletePaymentOutput>
Promise
Promise<DeletePaymentOutput>authorizePayment#
Parameters
The data to authorize a payment.
Returns
Promise
Promise<AuthorizePaymentOutput>
Promise
Promise<AuthorizePaymentOutput>capturePayment#
Parameters
The data to capture a payment.
Returns
Promise
Promise<CapturePaymentOutput>
Promise
Promise<CapturePaymentOutput>refundPayment#
Parameters
The data to refund a payment.
Returns
Promise
Promise<RefundPaymentOutput>
Promise
Promise<RefundPaymentOutput>retrievePayment#
Parameters
The data to retrieve a payment.
Returns
Promise
Promise<RetrievePaymentOutput>
Promise
Promise<RetrievePaymentOutput>cancelPayment#
Parameters
The data to cancel a payment.
Returns
Promise
Promise<CancelPaymentOutput>
Promise
Promise<CancelPaymentOutput>createAccountHolder#
This method is used when creating an account holder in Medusa, allowing you to create the equivalent account in the third-party payment provider. An account holder is useful to later save payment methods, such as credit cards, for a customer in the third-party payment provider using the savePaymentMethod method.
The returned data will be stored in the account holder created in Medusa. For example,
the returned id
property will be stored in the account holder's external_id
property.
Medusa creates an account holder when a payment session initialized for a registered customer.
v2.5.0
.Example
1import { MedusaError } from "@medusajs/framework/utils"2 3class MyPaymentProviderService extends AbstractPaymentProvider<4 Options5> {6 async createAccountHolder({ context, data }: CreateAccountHolderInput) {7 const { account_holder, customer } = context8 9 if (account_holder?.data?.id) {10 return { id: account_holder.data.id as string }11 }12 13 if (!customer) {14 throw new MedusaError(15 MedusaError.Types.INVALID_DATA,16 "Missing customer data."17 )18 }19 20 // assuming you have a client that creates the account holder21 const providerAccountHolder = await this.client.createAccountHolder({22 email: customer.email,23 ...data24 })25 26 return {27 id: providerAccountHolder.id,28 data: providerAccountHolder as unknown as Record<string, unknown>29 }30}
Parameters
Input data including the details of the account holder to create.
Returns
Promise
Promise<CreateAccountHolderOutput>The result of creating the account holder. If an error occurs, throw it.
Promise
Promise<CreateAccountHolderOutput>updateAccountHolder#
This method is used when updating an account holder in Medusa, allowing you to update the equivalent account in the third-party payment provider.
The returned data will be stored in the account holder created in Medusa. For example,
the returned id
property will be stored in the account holder's external_id
property.
v2.5.1
.Example
1import { MedusaError } from "@medusajs/framework/utils"2 3class MyPaymentProviderService extends AbstractPaymentProvider<4 Options5> {6 async updateAccountHolder({ context, data }: UpdateAccountHolderInput) {7 const { account_holder, customer } = context8 9 if (!account_holder?.data?.id) {10 throw new MedusaError(11 MedusaError.Types.INVALID_DATA,12 "Missing account holder ID."13 )14 }15 16 // assuming you have a client that updates the account holder17 const providerAccountHolder = await this.client.updateAccountHolder({18 id: account_holder.data.id,19 ...data20 })21 22 return {23 id: providerAccountHolder.id,24 data: providerAccountHolder as unknown as Record<string, unknown>25 }26}
Parameters
Input data including the details of the account holder to update.
Returns
Promise
Promise<UpdateAccountHolderOutput>The result of updating the account holder. If an error occurs, throw it.
Promise
Promise<UpdateAccountHolderOutput>deleteAccountHolder#
This method is used when an account holder is deleted in Medusa, allowing you to also delete the equivalent account holder in the third-party payment provider.
v2.5.0
.Example
1import { MedusaError } from "@medusajs/framework/utils"2 3class MyPaymentProviderService extends AbstractPaymentProvider<4 Options5> {6 async deleteAccountHolder({ context }: DeleteAccountHolderInput) {7 const { account_holder } = context8 const accountHolderId = account_holder?.data?.id as string | undefined9 if (!accountHolderId) {10 throw new MedusaError(11 MedusaError.Types.INVALID_DATA,12 "Missing account holder ID."13 )14 }15 16 // assuming you have a client that deletes the account holder17 await this.client.deleteAccountHolder({18 id: accountHolderId19 })20 21 return {}22 }23}
Parameters
Input data including the details of the account holder to delete.
Returns
Promise
Promise<DeleteAccountHolderOutput>The result of deleting the account holder. If an error occurs, throw it.
Promise
Promise<DeleteAccountHolderOutput>listPaymentMethods#
This method is used to retrieve the list of saved payment methods for an account holder in the third-party payment provider. A payment provider that supports saving payment methods must implement this method.
v2.5.0
.Example
1import { MedusaError } from "@medusajs/framework/utils"2 3class MyPaymentProviderService extends AbstractPaymentProvider<4 Options5> {6 async listPaymentMethods({ context }: ListPaymentMethodsInput) {7 const { account_holder } = context8 const accountHolderId = account_holder?.data?.id as string | undefined9 10 if (!accountHolderId) {11 throw new MedusaError(12 MedusaError.Types.INVALID_DATA,13 "Missing account holder ID."14 )15 }16 17 // assuming you have a client that lists the payment methods18 const paymentMethods = await this.client.listPaymentMethods({19 customer_id: accountHolderId20 })21 22 return paymentMethods.map((pm) => ({23 id: pm.id,24 data: pm as unknown as Record<string, unknown>25 }))26 }27}
Parameters
Input data including the details of the account holder to list payment methods for.
Returns
Promise
Promise<ListPaymentMethodsOutput>The list of payment methods saved for the account holder. If an error occurs, throw it.
Promise
Promise<ListPaymentMethodsOutput>savePaymentMethod#
This method is used to save a customer's payment method, such as a credit card, in the third-party payment provider. A payment provider that supports saving payment methods must implement this method.
v2.5.0
.Example
1import { MedusaError } from "@medusajs/framework/utils"2 3class MyPaymentProviderService extends AbstractPaymentProvider<4 Options5> {6 async savePaymentMethod({ context, data }: SavePaymentMethodInput) { *7 const accountHolderId = context?.account_holder?.data?.id as8 | string9 | undefined10 11 if (!accountHolderId) {12 throw new MedusaError(13 MedusaError.Types.INVALID_DATA,14 "Missing account holder ID."15 )16 }17 18 // assuming you have a client that saves the payment method19 const paymentMethod = await this.client.savePaymentMethod({20 customer_id: accountHolderId,21 ...data22 })23 24 return {25 id: paymentMethod.id,26 data: paymentMethod as unknown as Record<string, unknown>27 }28 }29}
Parameters
The details of the payment method to save.
Returns
Promise
Promise<SavePaymentMethodOutput>The result of saving the payment method. If an error occurs, throw it.
Promise
Promise<SavePaymentMethodOutput>getPaymentStatus#
Parameters
The data to get the payment status.
Returns
Promise
Promise<GetPaymentStatusOutput>
Promise
Promise<GetPaymentStatusOutput>getWebhookActionAndData#
Parameters
data
objectReturns
Promise
Promise<WebhookActionResult>
Promise
Promise<WebhookActionResult>