feat: Add support for creating payment methods to payment module (#11063)
CLOSES CLO-407
This commit is contained in:
@@ -7,6 +7,8 @@ import {
|
||||
PaymentProviderError,
|
||||
PaymentProviderSessionResponse,
|
||||
ProviderWebhookPayload,
|
||||
SavePaymentMethod,
|
||||
SavePaymentMethodResponse,
|
||||
UpdatePaymentProviderSession,
|
||||
WebhookActionResult,
|
||||
} from "@medusajs/framework/types"
|
||||
@@ -319,6 +321,27 @@ abstract class StripeBase extends AbstractPaymentProvider<StripeOptions> {
|
||||
}))
|
||||
}
|
||||
|
||||
async savePaymentMethod(
|
||||
input: SavePaymentMethod
|
||||
): Promise<PaymentProviderError | SavePaymentMethodResponse> {
|
||||
const { context, data } = input
|
||||
const customer = context?.customer
|
||||
|
||||
if (!customer?.metadata?.stripe_id) {
|
||||
return this.buildError(
|
||||
"Account holder not set while saving a payment method",
|
||||
new Error("Missing account holder")
|
||||
)
|
||||
}
|
||||
|
||||
const resp = await this.stripe_.setupIntents.create({
|
||||
customer: customer.metadata.stripe_id as string,
|
||||
...data,
|
||||
})
|
||||
|
||||
return { id: resp.id, data: resp as unknown as Record<string, unknown> }
|
||||
}
|
||||
|
||||
async getWebhookActionAndData(
|
||||
webhookData: ProviderWebhookPayload["payload"]
|
||||
): Promise<WebhookActionResult> {
|
||||
|
||||
Reference in New Issue
Block a user