@vicacha-devs/medusa-payment-bold 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/.medusa/server/src/admin/index.cjs +1732 -0
  2. package/.medusa/server/src/admin/index.js +1732 -0
  3. package/.medusa/server/src/api/admin/bold/banks/route.js +15 -0
  4. package/.medusa/server/src/api/admin/bold/payment-button/route.js +44 -0
  5. package/.medusa/server/src/api/admin/bold/payment-link/route.js +61 -0
  6. package/.medusa/server/src/api/admin/bold/payment-link-methods/route.js +16 -0
  7. package/.medusa/server/src/api/admin/bold/payment-methods/route.js +17 -0
  8. package/.medusa/server/src/api/admin/bold/payment-qr/route.js +53 -0
  9. package/.medusa/server/src/api/admin/bold/payment-status/route.js +37 -0
  10. package/.medusa/server/src/api/admin/bold/payment-stream/route.js +103 -0
  11. package/.medusa/server/src/api/admin/bold/pos-push/route.js +46 -0
  12. package/.medusa/server/src/api/admin/bold/refund/route.js +37 -0
  13. package/.medusa/server/src/api/admin/bold/terminals/route.js +16 -0
  14. package/.medusa/server/src/api/admin/plugin/route.js +10 -0
  15. package/.medusa/server/src/api/hooks/payment/bold/route.js +104 -0
  16. package/.medusa/server/src/api/store/plugin/route.js +4 -0
  17. package/.medusa/server/src/hooks/index.js +10 -0
  18. package/.medusa/server/src/hooks/use-bold-checkout-handler.js +135 -0
  19. package/.medusa/server/src/hooks/use-bold-payment-methods.js +20 -0
  20. package/.medusa/server/src/hooks/use-bold-payment-status-stream.js +19 -0
  21. package/.medusa/server/src/hooks/use-bold-refund.js +19 -0
  22. package/.medusa/server/src/hooks/use-bold-terminals.js +13 -0
  23. package/.medusa/server/src/hooks/use-create-bold-button.js +19 -0
  24. package/.medusa/server/src/hooks/use-create-bold-link.js +19 -0
  25. package/.medusa/server/src/hooks/use-create-bold-qr.js +19 -0
  26. package/.medusa/server/src/hooks/use-create-bold-terminal.js +19 -0
  27. package/.medusa/server/src/index.js +21 -0
  28. package/.medusa/server/src/lib/error-utils.js +25 -0
  29. package/.medusa/server/src/lib/get-active-providers.js +34 -0
  30. package/.medusa/server/src/lib/get-provider-options.js +20 -0
  31. package/.medusa/server/src/lib/index.js +4 -0
  32. package/.medusa/server/src/lib/session-helpers.js +11 -0
  33. package/.medusa/server/src/providers/bold-button/index.js +157 -0
  34. package/.medusa/server/src/providers/bold-link/index.js +249 -0
  35. package/.medusa/server/src/providers/bold-online/index.js +169 -0
  36. package/.medusa/server/src/providers/bold-terminal/index.js +170 -0
  37. package/.medusa/server/src/rbac.js +58 -0
  38. package/.medusa/server/src/sdk/client.js +112 -0
  39. package/.medusa/server/src/sdk/query-keys.js +13 -0
  40. package/.medusa/server/src/services/bold-client.js +304 -0
  41. package/.medusa/server/src/services/integrity.js +54 -0
  42. package/.medusa/server/src/types/constants.js +55 -0
  43. package/.medusa/server/src/types/enums.js +15 -0
  44. package/.medusa/server/src/types/errors.js +80 -0
  45. package/.medusa/server/src/types/index.js +3 -0
  46. package/.medusa/server/src/workflows/create-bold-payment-link.js +7 -0
  47. package/.medusa/server/src/workflows/create-bold-refund.js +7 -0
  48. package/.medusa/server/src/workflows/get-bold-payment-methods.js +7 -0
  49. package/.medusa/server/src/workflows/get-integration-api-payment-methods.js +7 -0
  50. package/.medusa/server/src/workflows/get-payment-link-methods.js +7 -0
  51. package/.medusa/server/src/workflows/get-terminals.js +7 -0
  52. package/.medusa/server/src/workflows/index.js +7 -0
  53. package/.medusa/server/src/workflows/steps/create-bold-link.js +43 -0
  54. package/.medusa/server/src/workflows/steps/get-bold-payment-methods.js +12 -0
  55. package/.medusa/server/src/workflows/steps/get-payment-link-methods.js +12 -0
  56. package/.medusa/server/src/workflows/steps/get-terminals.js +13 -0
  57. package/.medusa/server/src/workflows/steps/refund-bold-payment.js +15 -0
  58. package/README.md +106 -2
  59. package/package.json +120 -3
  60. package/src/__tests__/bold-contract.spec.ts +40 -0
  61. package/src/__tests__/bold-qa-emulator.ts +582 -0
  62. package/src/__tests__/bold-use-cases.spec.ts +773 -0
  63. package/src/__tests__/medusa-payment-shim.mjs +334 -0
  64. package/src/__tests__/register-ts-resolver.mjs +101 -0
  65. package/src/admin/README.md +70 -0
  66. package/src/admin/components/bold-terminal-status.tsx +166 -0
  67. package/src/admin/components/icons/bold-fav.tsx +45 -0
  68. package/src/admin/components/icons/copy.tsx +23 -0
  69. package/src/admin/components/icons/index.ts +3 -0
  70. package/src/admin/components/icons/qr-code.tsx +33 -0
  71. package/src/admin/components/icons/smart-phone.tsx +23 -0
  72. package/src/admin/components/index.ts +4 -0
  73. package/src/admin/components/logos/bold.tsx +45 -0
  74. package/src/admin/components/method-item.tsx +19 -0
  75. package/src/admin/components/provider-card.tsx +21 -0
  76. package/src/admin/components/section.tsx +23 -0
  77. package/src/admin/i18n/README.md +58 -0
  78. package/src/admin/i18n/index.ts +11 -0
  79. package/src/admin/i18n/json/ar.json +99 -0
  80. package/src/admin/i18n/json/en.json +99 -0
  81. package/src/admin/i18n/json/es.json +99 -0
  82. package/src/admin/i18n/json/tr.json +99 -0
  83. package/src/admin/routes/settings/bold/components/bold-methods-sidebar.tsx +96 -0
  84. package/src/admin/routes/settings/bold/components/bold-providers-section.tsx +67 -0
  85. package/src/admin/routes/settings/bold/components/index.ts +2 -0
  86. package/src/admin/routes/settings/bold/page.tsx +109 -0
  87. package/src/admin/tsconfig.json +24 -0
  88. package/src/admin/vite-env.d.ts +1 -0
  89. package/src/admin/widgets/bold-audit-timeline.tsx +155 -0
  90. package/src/admin/widgets/bold-payment-actions/bold-payment-actions.tsx +114 -0
  91. package/src/admin/widgets/bold-payment-actions/components/bold-payment-tabs.tsx +127 -0
  92. package/src/admin/widgets/bold-payment-actions/components/bold-remote-payment-panel.tsx +104 -0
  93. package/src/admin/widgets/bold-payment-actions/components/bold-terminal-section.tsx +71 -0
  94. package/src/admin/widgets/bold-payment-actions/hooks/bold-order-balance.ts +126 -0
  95. package/src/admin/widgets/bold-payment-actions/hooks/use-bold-widget-state.tsx +181 -0
  96. package/src/admin/widgets/bold-refund-actions.tsx +151 -0
  97. package/src/admin/widgets/index.ts +12 -0
  98. package/src/api/README.md +37 -0
  99. package/src/api/admin/bold/banks/route.ts +23 -0
  100. package/src/api/admin/bold/payment-button/route.ts +57 -0
  101. package/src/api/admin/bold/payment-link/route.ts +68 -0
  102. package/src/api/admin/bold/payment-link-methods/route.ts +24 -0
  103. package/src/api/admin/bold/payment-methods/route.ts +27 -0
  104. package/src/api/admin/bold/payment-qr/route.ts +68 -0
  105. package/src/api/admin/bold/payment-status/route.ts +48 -0
  106. package/src/api/admin/bold/payment-stream/route.ts +161 -0
  107. package/src/api/admin/bold/pos-push/route.ts +59 -0
  108. package/src/api/admin/bold/refund/route.ts +51 -0
  109. package/src/api/admin/bold/terminals/route.ts +26 -0
  110. package/src/api/admin/plugin/route.ts +14 -0
  111. package/src/api/hooks/payment/bold/route.ts +156 -0
  112. package/src/api/store/plugin/route.ts +5 -0
  113. package/src/hooks/index.ts +9 -0
  114. package/src/hooks/use-bold-checkout-handler.ts +172 -0
  115. package/src/hooks/use-bold-payment-methods.ts +36 -0
  116. package/src/hooks/use-bold-payment-status-stream.ts +55 -0
  117. package/src/hooks/use-bold-refund.ts +33 -0
  118. package/src/hooks/use-bold-terminals.ts +22 -0
  119. package/src/hooks/use-create-bold-button.ts +34 -0
  120. package/src/hooks/use-create-bold-link.ts +33 -0
  121. package/src/hooks/use-create-bold-qr.ts +33 -0
  122. package/src/hooks/use-create-bold-terminal.ts +37 -0
  123. package/src/index.ts +31 -0
  124. package/src/lib/error-utils.ts +29 -0
  125. package/src/lib/get-active-providers.ts +52 -0
  126. package/src/lib/get-provider-options.ts +54 -0
  127. package/src/lib/index.ts +3 -0
  128. package/src/lib/session-helpers.ts +16 -0
  129. package/src/providers/README.md +30 -0
  130. package/src/providers/bold-button/index.ts +244 -0
  131. package/src/providers/bold-link/index.ts +350 -0
  132. package/src/providers/bold-online/index.ts +254 -0
  133. package/src/providers/bold-terminal/index.ts +258 -0
  134. package/src/rbac.ts +72 -0
  135. package/src/sdk/client.ts +157 -0
  136. package/src/sdk/query-keys.ts +13 -0
  137. package/src/services/bold-client.ts +470 -0
  138. package/src/services/integrity.ts +74 -0
  139. package/src/types/constants.ts +63 -0
  140. package/src/types/enums.ts +13 -0
  141. package/src/types/errors.ts +88 -0
  142. package/src/types/index.ts +517 -0
  143. package/src/workflows/create-bold-payment-link.ts +16 -0
  144. package/src/workflows/create-bold-refund.ts +16 -0
  145. package/src/workflows/get-bold-payment-methods.ts +13 -0
  146. package/src/workflows/get-integration-api-payment-methods.ts +13 -0
  147. package/src/workflows/get-payment-link-methods.ts +13 -0
  148. package/src/workflows/get-terminals.ts +10 -0
  149. package/src/workflows/index.ts +6 -0
  150. package/src/workflows/steps/create-bold-link.ts +74 -0
  151. package/src/workflows/steps/get-bold-payment-methods.ts +21 -0
  152. package/src/workflows/steps/get-payment-link-methods.ts +19 -0
  153. package/src/workflows/steps/get-terminals.ts +20 -0
  154. package/src/workflows/steps/refund-bold-payment.ts +28 -0
  155. package/tsconfig.json +41 -0
@@ -0,0 +1,151 @@
1
+ import { defineWidgetConfig } from "@medusajs/admin-sdk"
2
+ import {
3
+ Container,
4
+ Heading,
5
+ Button,
6
+ CurrencyInput,
7
+ Badge,
8
+ toast,
9
+ } from "@medusajs/ui"
10
+ import { useState } from "react"
11
+ import { useTranslation } from "react-i18next"
12
+
13
+ import { useBoldRefund } from "../../hooks/use-bold-refund"
14
+
15
+ const BoldRefundActionsWidget = ({ data: order }: { data: any }) => {
16
+ const { t } = useTranslation()
17
+ const [refundAmount, setRefundAmount] = useState<number | undefined>(
18
+ undefined
19
+ )
20
+ const { mutateAsync: refundPayment, isPending: loading } = useBoldRefund()
21
+
22
+ const boldPayment = order?.payment_collections
23
+ ?.flatMap((pc: any) => pc.payments || [])
24
+ ?.find((p: any) => p.provider_id?.startsWith("pp_bold") && p.captured_at)
25
+
26
+ if (!boldPayment) {
27
+ return null
28
+ }
29
+
30
+ const currencyCode = (
31
+ order?.currency_code ||
32
+ boldPayment?.currency_code ||
33
+ "COP"
34
+ ).toUpperCase()
35
+
36
+ const capturedAmount = boldPayment.amount || 0
37
+ const refundedAmount = boldPayment.refunded_amount || 0
38
+ const maxRefundable = capturedAmount - refundedAmount
39
+
40
+ if (maxRefundable <= 0) {
41
+ return (
42
+ <Container className="p-4 rounded-lg border bg-card space-y-2">
43
+ <div className="flex items-center justify-between">
44
+ <Heading level="h2" className="text-base font-semibold">
45
+ {t("bold.admin.refund.title")}
46
+ </Heading>
47
+ <Badge color="grey">{t("bold.admin.refund.fully_refunded")}</Badge>
48
+ </div>
49
+ <p className="text-xs text-ui-fg-subtle">
50
+ {t("bold.admin.refund.fully_refunded_desc", {
51
+ amount: capturedAmount.toLocaleString(),
52
+ currency: currencyCode,
53
+ })}
54
+ </p>
55
+ </Container>
56
+ )
57
+ }
58
+
59
+ const handleRefund = async () => {
60
+ const numericAmount = Number(refundAmount)
61
+
62
+ if (!numericAmount || numericAmount <= 0 || numericAmount > maxRefundable) {
63
+ toast.error(t("bold.admin.refund.invalid_amount_title"), {
64
+ description: t("bold.admin.refund.invalid_amount_desc", {
65
+ max: maxRefundable.toLocaleString(),
66
+ currency: currencyCode,
67
+ }),
68
+ })
69
+ return
70
+ }
71
+
72
+ try {
73
+ await refundPayment({
74
+ payment_id: boldPayment.id,
75
+ amount: numericAmount,
76
+ })
77
+
78
+ toast.success(t("bold.admin.refund.success_title"), {
79
+ description: t("bold.admin.refund.success_desc", {
80
+ amount: numericAmount.toLocaleString(),
81
+ currency: currencyCode,
82
+ }),
83
+ })
84
+
85
+ setRefundAmount(undefined)
86
+ window.location.reload()
87
+ } catch (err: any) {
88
+ toast.error(t("bold.admin.refund.error_title"), {
89
+ description: err.message,
90
+ })
91
+ }
92
+ }
93
+
94
+ return (
95
+ <Container className="p-4 rounded-lg border bg-card space-y-4">
96
+ <div className="flex items-center justify-between border-b pb-3">
97
+ <Heading level="h2" className="text-base font-semibold">
98
+ {t("bold.admin.refund.title")}
99
+ </Heading>
100
+ <Badge color="green">{t("bold.admin.refund.captured")}</Badge>
101
+ </div>
102
+
103
+ <div className="flex flex-col gap-y-1.5 text-xs text-ui-fg-subtle">
104
+ <div className="flex items-center justify-between">
105
+ <span>{t("bold.admin.refund.captured_total")}:</span>
106
+ <strong className="text-ui-fg-base font-mono">
107
+ ${capturedAmount.toLocaleString()} {currencyCode}
108
+ </strong>
109
+ </div>
110
+ <div className="flex items-center justify-between">
111
+ <span>{t("bold.admin.refund.remaining")}:</span>
112
+ <strong className="text-ui-fg-base font-mono">
113
+ ${maxRefundable.toLocaleString()} {currencyCode}
114
+ </strong>
115
+ </div>
116
+ </div>
117
+
118
+ <div className="space-y-3 pt-1">
119
+ <CurrencyInput
120
+ size="small"
121
+ symbol="$"
122
+ code={currencyCode}
123
+ value={refundAmount}
124
+ onValueChange={(val) =>
125
+ setRefundAmount(val ? Number(val) : undefined)
126
+ }
127
+ placeholder="0"
128
+ disabled={loading}
129
+ />
130
+
131
+ <div className="flex justify-end">
132
+ <Button
133
+ size="small"
134
+ variant="secondary"
135
+ isLoading={loading}
136
+ onClick={handleRefund}
137
+ disabled={loading || !refundAmount}
138
+ >
139
+ {t("bold.admin.refund.action")}
140
+ </Button>
141
+ </div>
142
+ </div>
143
+ </Container>
144
+ )
145
+ }
146
+
147
+ export const config = defineWidgetConfig({
148
+ zone: "order.details.side",
149
+ })
150
+
151
+ export default BoldRefundActionsWidget
@@ -0,0 +1,12 @@
1
+ export {
2
+ default as BoldPaymentActionsWidget,
3
+ config as boldPaymentActionsConfig,
4
+ } from "./bold-payment-actions/bold-payment-actions"
5
+ export {
6
+ default as BoldAuditTimelineWidget,
7
+ config as boldAuditTimelineConfig,
8
+ } from "./bold-audit-timeline"
9
+ export {
10
+ default as BoldRefundActionsWidget,
11
+ config as boldRefundActionsConfig,
12
+ } from "./bold-refund-actions"
@@ -0,0 +1,37 @@
1
+ # API Routes (`src/api`)
2
+
3
+ Admin REST endpoints and Zod validation middlewares for `@vicacha-devs/medusa-plugin-payment-bold`.
4
+
5
+ ```text
6
+ api/
7
+ ├── middlewares.ts # Registers validateAndTransformBody middlewares for /admin/bold/*
8
+ ├── validators.ts # AdminBoldPosPushSchema & AdminBoldPaymentLinkSchema
9
+ └── admin/
10
+ └── bold/
11
+ ├── terminals/
12
+ │ └── route.ts # GET /admin/bold/terminals
13
+ ├── pos-push/
14
+ │ └── route.ts # POST /admin/bold/pos-push
15
+ └── payment-link/
16
+ └── route.ts # POST /admin/bold/payment-link
17
+ ```
18
+
19
+ ---
20
+
21
+ ## Endpoints
22
+
23
+ | Method | Path | Body Schema | Description |
24
+ | :----- | :------------------------- | :--------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
25
+ | `GET` | `/admin/bold/terminals` | — | Invokes `listActiveTerminals()` on the registered Bold payment provider to list available physical POS Dataphones. |
26
+ | `POST` | `/admin/bold/pos-push` | `AdminBoldPosPushSchema` | Creates a `pp_bold-terminal_bold` payment session on `payment_collection_id` for `amount` (remaining `payableAmount`) and pushes the charge to `terminal_serial`. |
27
+ | `POST` | `/admin/bold/payment-link` | `AdminBoldPaymentLinkSchema` | Creates a `pp_bold-link_bold` payment session on `payment_collection_id` for `amount` (remaining `payableAmount`) and returns `payment_link_url` and `payment_link_id`. |
28
+
29
+ ---
30
+
31
+ ## Native Medusa Webhooks
32
+
33
+ Webhook notifications from Bold are handled natively by Medusa v2's Payment Module router via `getWebhookActionAndData` in `BoldBaseProvider`:
34
+
35
+ - `POST /hooks/payment/bold-online_bold`
36
+ - `POST /hooks/payment/bold-terminal_bold`
37
+ - `POST /hooks/payment/bold-link_bold`
@@ -0,0 +1,23 @@
1
+ import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import { BoldOnlinePaymentProviderService } from "@payment-bold/providers/bold-online"
3
+
4
+ export async function GET(
5
+ req: MedusaRequest,
6
+ res: MedusaResponse
7
+ ): Promise<void> {
8
+ try {
9
+ // Resolve the bold-online provider instance from the container
10
+ const boldOnlineService =
11
+ req.scope.resolve<BoldOnlinePaymentProviderService>("bold-online")
12
+
13
+ // Access the PSE banks list via the encapsulated client instance
14
+ const banks = await (boldOnlineService as any).client_.getPseBanks()
15
+
16
+ res.status(200).json({ banks })
17
+ } catch (error: any) {
18
+ res.status(500).json({
19
+ message:
20
+ error.message || "Failed to fetch active PSE banks from Bold API",
21
+ })
22
+ }
23
+ }
@@ -0,0 +1,57 @@
1
+ import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import { IPaymentModuleService } from "@medusajs/framework/types"
3
+ import { Modules } from "@medusajs/framework/utils"
4
+ import { z } from "@medusajs/framework/zod"
5
+ import { EMedusaFormatBoldPaymentProvider } from "@payment-bold/types/enums"
6
+
7
+ const CreateBoldButtonSchema = z.object({
8
+ paymentCollectionId: z.string().min(1),
9
+ amount: z.coerce.number().finite().positive(),
10
+ currency: z.string().min(3).max(3).default("COP"),
11
+ reference: z.string().min(1).max(255),
12
+ description: z.string().min(1).max(500).optional(),
13
+ email: z.string().email().optional(),
14
+ taxAmount: z.coerce.number().finite().min(0).optional(),
15
+ })
16
+
17
+ export async function POST(
18
+ req: MedusaRequest,
19
+ res: MedusaResponse
20
+ ): Promise<void> {
21
+ const parsed = CreateBoldButtonSchema.safeParse(req.body ?? {})
22
+ if (!parsed.success) {
23
+ res.status(400).json({
24
+ message: "Invalid payment button payload",
25
+ errors: parsed.error.flatten().fieldErrors,
26
+ })
27
+ return
28
+ }
29
+
30
+ const paymentModule: IPaymentModuleService = req.scope.resolve(
31
+ Modules.PAYMENT
32
+ )
33
+ const input = parsed.data
34
+
35
+ try {
36
+ const paymentSession = await paymentModule.createPaymentSession(
37
+ input.paymentCollectionId,
38
+ {
39
+ provider_id: EMedusaFormatBoldPaymentProvider.BUTTON,
40
+ currency_code: input.currency.toLowerCase(),
41
+ amount: input.amount,
42
+ data: {
43
+ reference: input.reference,
44
+ description: input.description,
45
+ email: input.email,
46
+ taxAmount: input.taxAmount,
47
+ },
48
+ }
49
+ )
50
+
51
+ res.status(200).json({ paymentSession })
52
+ } catch {
53
+ res
54
+ .status(500)
55
+ .json({ message: "Failed to initialize Bold payment button session" })
56
+ }
57
+ }
@@ -0,0 +1,68 @@
1
+ import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import { z } from "@medusajs/framework/zod"
3
+ import { createBoldPaymentLinkWorkflow } from "@payment-bold/workflows/create-bold-payment-link"
4
+
5
+ const CreateBoldPaymentLinkSchema = z.object({
6
+ paymentCollectionId: z.string().min(1).optional(),
7
+ amount: z.coerce.number().finite().positive(),
8
+ currency: z
9
+ .string()
10
+ .min(3)
11
+ .max(3)
12
+ .transform((s) => s.toUpperCase()),
13
+ reference: z.string().min(1).max(255),
14
+ description: z.string().min(1).max(500),
15
+ email: z.string().email(),
16
+ callbackUrl: z
17
+ .string()
18
+ .url()
19
+ .refine((u) => u.startsWith("https://") || u.startsWith("http://"), {
20
+ message: "callbackUrl must use http:// or https://",
21
+ }),
22
+ vatAmount: z.coerce.number().finite().min(0).optional().default(0),
23
+ consumptionTaxAmount: z.coerce.number().finite().min(0).optional(),
24
+ imageUrl: z
25
+ .string()
26
+ .url()
27
+ .refine((u) => u.startsWith("https://") || u.startsWith("http://"), {
28
+ message: "imageUrl must use http:// or https://",
29
+ })
30
+ .optional(),
31
+ })
32
+
33
+ export async function POST(
34
+ req: MedusaRequest,
35
+ res: MedusaResponse
36
+ ): Promise<void> {
37
+ const parsed = CreateBoldPaymentLinkSchema.safeParse(req.body ?? {})
38
+ if (!parsed.success) {
39
+ res.status(400).json({
40
+ message: "Invalid payment link payload",
41
+ errors: parsed.error.flatten().fieldErrors,
42
+ })
43
+ return
44
+ }
45
+
46
+ const input = parsed.data
47
+
48
+ try {
49
+ const { result } = await createBoldPaymentLinkWorkflow(req.scope).run({
50
+ input: {
51
+ paymentCollectionId: input.paymentCollectionId,
52
+ amount: input.amount,
53
+ currency: input.currency,
54
+ reference: input.reference,
55
+ description: input.description,
56
+ email: input.email,
57
+ callbackUrl: input.callbackUrl,
58
+ vatAmount: input.vatAmount,
59
+ consumptionTaxAmount: input.consumptionTaxAmount ?? input.vatAmount,
60
+ imageUrl: input.imageUrl,
61
+ },
62
+ })
63
+
64
+ res.status(200).json(result)
65
+ } catch {
66
+ res.status(500).json({ message: "Failed to execute payment workflow" })
67
+ }
68
+ }
@@ -0,0 +1,24 @@
1
+ import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework"
2
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
3
+ import { getPaymentLinkMethodsWorkflow } from "@payment-bold/workflows/get-payment-link-methods"
4
+
5
+ export const GET = async (
6
+ req: AuthenticatedMedusaRequest,
7
+ res: MedusaResponse
8
+ ) => {
9
+ const logger = req.scope.resolve(ContainerRegistrationKeys.LOGGER)
10
+
11
+ try {
12
+ const { result } = await getPaymentLinkMethodsWorkflow(req.scope).run()
13
+ return res.json(result)
14
+ } catch (err: any) {
15
+ logger.error(
16
+ `[Bold Payment Link Methods Route] Failed to fetch available payment methods: ${err.message}`,
17
+ err
18
+ )
19
+ return res.status(500).json({
20
+ message:
21
+ err.message || "Failed to retrieve Bold Payment Link payment methods",
22
+ })
23
+ }
24
+ }
@@ -0,0 +1,27 @@
1
+ import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework"
2
+ import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
3
+ import { getIntegrationApiPaymentMethodsWorkflow } from "@payment-bold/workflows/get-integration-api-payment-methods"
4
+
5
+ export const GET = async (
6
+ req: AuthenticatedMedusaRequest,
7
+ res: MedusaResponse
8
+ ) => {
9
+ const logger = req.scope.resolve(ContainerRegistrationKeys.LOGGER)
10
+
11
+ try {
12
+ const { result } = await getIntegrationApiPaymentMethodsWorkflow(
13
+ req.scope
14
+ ).run()
15
+ return res.json(result)
16
+ } catch (err: any) {
17
+ logger.error(
18
+ `[Bold Integration API Payment Methods Route] Failed to fetch available payment methods: ${err.message}`,
19
+ err
20
+ )
21
+ return res.status(500).json({
22
+ message:
23
+ err.message ||
24
+ "Failed to retrieve Bold Integration API payment methods",
25
+ })
26
+ }
27
+ }
@@ -0,0 +1,68 @@
1
+ import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import { IPaymentModuleService } from "@medusajs/framework/types"
3
+ import { Modules } from "@medusajs/framework/utils"
4
+ import { z } from "@medusajs/framework/zod"
5
+ import { EMedusaFormatBoldPaymentProvider } from "@payment-bold/types/enums"
6
+
7
+ const CreateBoldQrSchema = z.object({
8
+ paymentCollectionId: z.string().min(1),
9
+ amount: z.coerce.number().finite().positive(),
10
+ currency: z.string().min(3).max(3).optional(),
11
+ currency_code: z.string().min(3).max(3).optional(),
12
+ reference: z.string().min(1).max(255).optional(),
13
+ description: z.string().max(500).optional(),
14
+ callbackUrl: z.string().url().optional(),
15
+ qrFormat: z.enum(["BOLD_BASE64", "PLAIN_BASE64", "TEXT"]).optional(),
16
+ email: z.string().email().optional(),
17
+ })
18
+
19
+ export async function POST(
20
+ req: MedusaRequest,
21
+ res: MedusaResponse
22
+ ): Promise<void> {
23
+ const parsed = CreateBoldQrSchema.safeParse(req.body ?? {})
24
+ if (!parsed.success) {
25
+ res.status(400).json({
26
+ message: "Invalid QR payment payload",
27
+ errors: parsed.error.flatten().fieldErrors,
28
+ })
29
+ return
30
+ }
31
+
32
+ const paymentModule: IPaymentModuleService = req.scope.resolve(
33
+ Modules.PAYMENT
34
+ )
35
+ const input = parsed.data
36
+ const currency = (
37
+ input.currency ||
38
+ input.currency_code ||
39
+ "COP"
40
+ ).toLowerCase()
41
+
42
+ try {
43
+ const paymentSession = await paymentModule.createPaymentSession(
44
+ input.paymentCollectionId,
45
+ {
46
+ provider_id: EMedusaFormatBoldPaymentProvider.ONLINE,
47
+ currency_code: currency,
48
+ amount: input.amount,
49
+ data: {
50
+ methodType: "qr",
51
+ reference: input.reference,
52
+ description: input.description,
53
+ callbackUrl: input.callbackUrl,
54
+ qrFormat: input.qrFormat || "BOLD_BASE64",
55
+ email: input.email,
56
+ },
57
+ }
58
+ )
59
+
60
+ const sessionData = (paymentSession?.data || {}) as Record<string, unknown>
61
+ res.status(200).json({
62
+ qr_payload: (sessionData.qr_payload as string) || "",
63
+ paymentSession,
64
+ })
65
+ } catch {
66
+ res.status(500).json({ message: "Failed to generate QR payment session" })
67
+ }
68
+ }
@@ -0,0 +1,48 @@
1
+ import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import { Modules } from "@medusajs/framework/utils"
3
+ import { IPaymentModuleService } from "@medusajs/framework/types"
4
+
5
+ /**
6
+ * GET /admin/bold/payment-status
7
+ *
8
+ * Fetches the status and metadata of a payment session using Medusa v2's Payment Module.
9
+ *
10
+ * Query Parameters:
11
+ * - paymentSessionId / payment_session_id: The unique ID of the Medusa payment session.
12
+ */
13
+ export async function GET(
14
+ req: MedusaRequest,
15
+ res: MedusaResponse
16
+ ): Promise<void> {
17
+ const paymentModule: IPaymentModuleService = req.scope.resolve(
18
+ Modules.PAYMENT
19
+ )
20
+
21
+ const paymentSessionId = (req.query.paymentSessionId ||
22
+ req.query.payment_session_id) as string
23
+
24
+ if (!paymentSessionId) {
25
+ res
26
+ .status(400)
27
+ .json({ message: "Missing required 'paymentSessionId' query parameter." })
28
+ return
29
+ }
30
+
31
+ try {
32
+ // In Medusa v2, payment session details are retrieved directly from the Payment Module
33
+ const paymentSession =
34
+ await paymentModule.retrievePaymentSession(paymentSessionId)
35
+
36
+ res.status(200).json({
37
+ id: paymentSession.id,
38
+ status: paymentSession.status, // e.g., 'authorized', 'captured', 'pending', 'canceled'
39
+ amount: paymentSession.amount,
40
+ currency_code: paymentSession.currency_code,
41
+ data: paymentSession.data,
42
+ })
43
+ } catch (error: any) {
44
+ res.status(500).json({
45
+ message: error.message || "Failed to retrieve payment session status",
46
+ })
47
+ }
48
+ }
@@ -0,0 +1,161 @@
1
+ import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import {
3
+ Modules,
4
+ PaymentSessionStatus,
5
+ ContainerRegistrationKeys,
6
+ } from "@medusajs/framework/utils"
7
+ import { IPaymentModuleService, Logger } from "@medusajs/framework/types"
8
+ import { capturePaymentWorkflow } from "@medusajs/medusa/core-flows"
9
+
10
+ export async function GET(
11
+ req: MedusaRequest,
12
+ res: MedusaResponse
13
+ ): Promise<void> {
14
+ const logger: Logger = req.scope.resolve(ContainerRegistrationKeys.LOGGER)
15
+ const paymentModule: IPaymentModuleService = req.scope.resolve(
16
+ Modules.PAYMENT
17
+ )
18
+ const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
19
+
20
+ const paymentSessionId = (req.query.paymentSessionId ||
21
+ req.query.payment_session_id) as string
22
+
23
+ if (!paymentSessionId) {
24
+ logger.warn(
25
+ "[Bold Stream] Connection attempt missing paymentSessionId query parameter."
26
+ )
27
+ res.status(400).json({ message: "Missing paymentSessionId parameter" })
28
+ return
29
+ }
30
+
31
+ res.setHeader("Content-Type", "text/event-stream")
32
+ res.setHeader("Cache-Control", "no-cache")
33
+ res.setHeader("Connection", "keep-alive")
34
+
35
+ logger.info(
36
+ `[Bold Stream] SSE connection established for session '${paymentSessionId}'`
37
+ )
38
+
39
+ const intervalId = setInterval(async () => {
40
+ try {
41
+ let session = await paymentModule.retrievePaymentSession(paymentSessionId)
42
+
43
+ // 1. If still pending, query status using the active registered provider instance
44
+ if (session.status === "pending" && session.provider_id) {
45
+ const providerInstance =
46
+ (paymentModule as any).getPaymentProvider?.(session.provider_id) ||
47
+ (paymentModule as any).paymentProviderService_?.retrieveProvider?.(
48
+ session.provider_id
49
+ )
50
+
51
+ if (providerInstance) {
52
+ let isAuthorized = false
53
+
54
+ if (typeof providerInstance.getPaymentStatus === "function") {
55
+ const statusRes = await providerInstance.getPaymentStatus({
56
+ data: session.data,
57
+ })
58
+
59
+ if (
60
+ statusRes?.status === PaymentSessionStatus.AUTHORIZED ||
61
+ statusRes?.status === PaymentSessionStatus.CAPTURED
62
+ ) {
63
+ isAuthorized = true
64
+ }
65
+ } else if (typeof providerInstance.getStatus === "function") {
66
+ const remoteStatus = await providerInstance.getStatus(session.data)
67
+
68
+ if (remoteStatus === "captured" || remoteStatus === "authorized") {
69
+ isAuthorized = true
70
+ }
71
+ }
72
+
73
+ if (isAuthorized) {
74
+ logger.info(
75
+ `[Bold Stream] Confirming payment for session '${session.id}'...`
76
+ )
77
+
78
+ const collectionId = session.payment_collection_id
79
+
80
+ if (collectionId) {
81
+ // Medusa v2 remoteQuery syntax
82
+ await remoteQuery({
83
+ entryPoint: "payment_collection",
84
+ fields: [
85
+ "id",
86
+ "status",
87
+ "amount",
88
+ "payment_sessions.*",
89
+ "payments.*",
90
+ ],
91
+ variables: { id: collectionId },
92
+ })
93
+ }
94
+
95
+ // Step A: Authorize the session in Medusa Payment Module
96
+ const authorizedPayment =
97
+ await paymentModule.authorizePaymentSession(session.id, {})
98
+
99
+ const paymentId =
100
+ (authorizedPayment as any)?.id ||
101
+ (authorizedPayment as any)?.payment?.id
102
+
103
+ // Step B: Execute capture workflow
104
+ if (paymentId) {
105
+ await capturePaymentWorkflow(req.scope).run({
106
+ input: {
107
+ payment_id: paymentId,
108
+ },
109
+ })
110
+ logger.info(
111
+ `[Bold Stream] Successfully captured payment '${paymentId}' with provider '${session.provider_id}'`
112
+ )
113
+ } else {
114
+ logger.warn(
115
+ `[Bold Stream] No payment ID returned from authorizePaymentSession for session '${session.id}'`
116
+ )
117
+ }
118
+
119
+ session =
120
+ await paymentModule.retrievePaymentSession(paymentSessionId)
121
+ }
122
+ } else {
123
+ logger.warn(
124
+ `[Bold Stream] Provider instance for '${session.provider_id}' not found on Payment Module.`
125
+ )
126
+ }
127
+ }
128
+
129
+ // Write event stream payload to client
130
+ res.write(
131
+ `data: ${JSON.stringify({ status: session.status, session })}\n\n`
132
+ )
133
+
134
+ if (
135
+ ["authorized", "captured", "completed", "canceled", "error"].includes(
136
+ session.status
137
+ )
138
+ ) {
139
+ logger.info(
140
+ `[Bold Stream] Stream completed for session '${session.id}' with status '${session.status}'. Closing connection.`
141
+ )
142
+ clearInterval(intervalId)
143
+ res.end()
144
+ }
145
+ } catch (error: any) {
146
+ logger.error(
147
+ `[Bold Stream] Error during SSE polling interval: ${error.message}`
148
+ )
149
+ res.write(`data: ${JSON.stringify({ error: error.message })}\n\n`)
150
+ clearInterval(intervalId)
151
+ res.end()
152
+ }
153
+ }, 3000)
154
+
155
+ req.on("close", () => {
156
+ logger.info(
157
+ `[Bold Stream] Client disconnected SSE stream for session '${paymentSessionId}'`
158
+ )
159
+ clearInterval(intervalId)
160
+ })
161
+ }