fix(medusa-payment-stripe): change webhook environment variables to plugin options (#6034)
* fix(medusa-payment-stripe): change webhook environment variables to plugin options * access options through service
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"medusa-payment-stripe": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa-payment-stripe): change webhook environment variables to plugin options
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
||||||
import { constructWebhook } from "../../utils/utils"
|
import { constructWebhook } from "../../utils/utils"
|
||||||
|
import StripeProviderService from "../../../services/stripe-provider"
|
||||||
const WEBHOOK_DELAY = process.env.STRIPE_WEBHOOK_DELAY ?? 5000 // 5s
|
|
||||||
const WEBHOOK_RETRIES = process.env.STRIPE_WEBHOOK_RETRIES ?? 3
|
|
||||||
|
|
||||||
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
|
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||||
try {
|
try {
|
||||||
|
const pluginOptions = req.scope.resolve<StripeProviderService>(
|
||||||
|
"stripeProviderService"
|
||||||
|
).options
|
||||||
|
|
||||||
const event = constructWebhook({
|
const event = constructWebhook({
|
||||||
signature: req.headers["stripe-signature"],
|
signature: req.headers["stripe-signature"],
|
||||||
body: req.body,
|
body: req.body,
|
||||||
@@ -16,8 +18,8 @@ export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
|
|||||||
|
|
||||||
// we delay the processing of the event to avoid a conflict caused by a race condition
|
// we delay the processing of the event to avoid a conflict caused by a race condition
|
||||||
await eventBus.emit("medusa.stripe_payment_intent_update", event, {
|
await eventBus.emit("medusa.stripe_payment_intent_update", event, {
|
||||||
delay: WEBHOOK_DELAY,
|
delay: pluginOptions.webhook_delay || 5000,
|
||||||
attempts: WEBHOOK_RETRIES,
|
attempts: pluginOptions.webhook_retries || 3,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(400).send(`Webhook Error: ${err.message}`)
|
res.status(400).send(`Webhook Error: ${err.message}`)
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import {
|
|||||||
IdempotencyKeyService,
|
IdempotencyKeyService,
|
||||||
PostgresError,
|
PostgresError,
|
||||||
} from "@medusajs/medusa"
|
} from "@medusajs/medusa"
|
||||||
|
import { ConfigModule, MedusaContainer } from "@medusajs/types"
|
||||||
import { MedusaError } from "@medusajs/utils"
|
import { MedusaError } from "@medusajs/utils"
|
||||||
import { AwilixContainer } from "awilix"
|
import { AwilixContainer } from "awilix"
|
||||||
import { EOL } from "os"
|
import { EOL } from "os"
|
||||||
import Stripe from "stripe"
|
import Stripe from "stripe"
|
||||||
|
import { StripeOptions } from "../../types"
|
||||||
|
|
||||||
const PAYMENT_PROVIDER_KEY = "pp_stripe"
|
const PAYMENT_PROVIDER_KEY = "pp_stripe"
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ abstract class StripeBase extends AbstractPaymentProcessor {
|
|||||||
|
|
||||||
abstract get paymentIntentOptions(): PaymentIntentOptions
|
abstract get paymentIntentOptions(): PaymentIntentOptions
|
||||||
|
|
||||||
|
get options(): StripeOptions {
|
||||||
|
return this.options_
|
||||||
|
}
|
||||||
|
|
||||||
getStripe() {
|
getStripe() {
|
||||||
return this.stripe_
|
return this.stripe_
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,16 @@ export interface StripeOptions {
|
|||||||
* Set a default description on the intent if the context does not provide one
|
* Set a default description on the intent if the context does not provide one
|
||||||
*/
|
*/
|
||||||
payment_description?: string
|
payment_description?: string
|
||||||
|
/**
|
||||||
|
* The delay in milliseconds before processing the webhook event.
|
||||||
|
* @defaultValue 5000
|
||||||
|
*/
|
||||||
|
webhook_delay?: number
|
||||||
|
/**
|
||||||
|
* The number of times to retry the webhook event processing in case of an error.
|
||||||
|
* @defaultValue 3
|
||||||
|
*/
|
||||||
|
webhook_retries?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PaymentIntentOptions {
|
export interface PaymentIntentOptions {
|
||||||
|
|||||||
Reference in New Issue
Block a user