feat: Add support for creating payment methods to payment module (#11063)

CLOSES CLO-407
This commit is contained in:
Stevche Radevski
2025-01-21 12:31:44 +01:00
committed by GitHub
parent cd758067d4
commit 05c8a67d8e
11 changed files with 240 additions and 79 deletions

View File

@@ -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> {