Promise
Promise<InitiatePaymentOutput>Promise
Promise<UpdatePaymentOutput>Promise
Promise<DeletePaymentOutput>Promise
Promise<AuthorizePaymentOutput>Promise
Promise<CapturePaymentOutput>Promise
Promise<RefundPaymentOutput>Promise
Promise<RetrievePaymentOutput>Promise
Promise<CancelPaymentOutput>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
.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}
Promise
Promise<CreateAccountHolderOutput>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
.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}
Promise
Promise<UpdateAccountHolderOutput>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
.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}
Promise
Promise<DeleteAccountHolderOutput>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
.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}
Promise
Promise<ListPaymentMethodsOutput>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
.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}
Promise
Promise<SavePaymentMethodOutput>Promise
Promise<GetPaymentStatusOutput>data
objectPromise
Promise<WebhookActionResult>