feat: Add support for listing saved payment methods in module and Stripe (#10994)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import {
|
||||
CreatePaymentProviderSession,
|
||||
IPaymentProvider,
|
||||
PaymentMethodResponse,
|
||||
PaymentProviderContext,
|
||||
PaymentProviderError,
|
||||
PaymentProviderSessionResponse,
|
||||
PaymentSessionStatus,
|
||||
@@ -623,6 +625,59 @@ export abstract class AbstractPaymentProvider<TConfig = Record<string, unknown>>
|
||||
context: UpdatePaymentProviderSession
|
||||
): Promise<PaymentProviderError | PaymentProviderSessionResponse>
|
||||
|
||||
/**
|
||||
* List the payment methods associated with the context (eg. customer) of the payment provider, if any.
|
||||
*
|
||||
* @param context - The context for which the payment methods are listed. Usually the customer should be provided.
|
||||
* @returns An object whose `payment_methods` property is set to the data returned by the payment provider.
|
||||
*
|
||||
* @example
|
||||
* // other imports...
|
||||
* import {
|
||||
* PaymentProviderContext,
|
||||
* PaymentProviderError,
|
||||
* PaymentMethodResponse
|
||||
* PaymentProviderSessionResponse,
|
||||
* } from "@medusajs/framework/types"
|
||||
*
|
||||
*
|
||||
* class MyPaymentProviderService extends AbstractPaymentProvider<
|
||||
* Options
|
||||
* > {
|
||||
* async listPaymentMethods(
|
||||
* context: PaymentProviderContext
|
||||
* ): Promise<PaymentMethodResponse> {
|
||||
* const {
|
||||
* customer,
|
||||
* } = context
|
||||
* const externalCustomerId = customer.metadata.stripe_id
|
||||
*
|
||||
* try {
|
||||
* // assuming you have a client that updates the payment
|
||||
* const response = await this.client.listPaymentMethods(
|
||||
* {customer: externalCustomerId}
|
||||
* )
|
||||
*
|
||||
* return response.map((method) => ({
|
||||
* id: method.id,
|
||||
* data: method
|
||||
* }))
|
||||
* } catch (e) {
|
||||
* return {
|
||||
* error: e,
|
||||
* code: "unknown",
|
||||
* detail: e
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // ...
|
||||
* }
|
||||
*/
|
||||
abstract listPaymentMethods(
|
||||
context: PaymentProviderContext
|
||||
): Promise<PaymentMethodResponse[]>
|
||||
|
||||
/**
|
||||
* This method is executed when a webhook event is received from the third-party payment provider. Use it
|
||||
* to process the action of the payment provider.
|
||||
|
||||
Reference in New Issue
Block a user