@vicacha-devs/medusa-payment-bold 0.0.0-stage → 0.0.1
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.
- package/.medusa/server/src/admin/index.cjs +1732 -0
- package/.medusa/server/src/admin/index.js +1732 -0
- package/.medusa/server/src/api/admin/bold/banks/route.js +15 -0
- package/.medusa/server/src/api/admin/bold/payment-button/route.js +44 -0
- package/.medusa/server/src/api/admin/bold/payment-link/route.js +61 -0
- package/.medusa/server/src/api/admin/bold/payment-link-methods/route.js +16 -0
- package/.medusa/server/src/api/admin/bold/payment-methods/route.js +17 -0
- package/.medusa/server/src/api/admin/bold/payment-qr/route.js +53 -0
- package/.medusa/server/src/api/admin/bold/payment-status/route.js +37 -0
- package/.medusa/server/src/api/admin/bold/payment-stream/route.js +103 -0
- package/.medusa/server/src/api/admin/bold/pos-push/route.js +46 -0
- package/.medusa/server/src/api/admin/bold/refund/route.js +37 -0
- package/.medusa/server/src/api/admin/bold/terminals/route.js +16 -0
- package/.medusa/server/src/api/admin/plugin/route.js +10 -0
- package/.medusa/server/src/api/hooks/payment/bold/route.js +104 -0
- package/.medusa/server/src/api/store/plugin/route.js +4 -0
- package/.medusa/server/src/hooks/index.js +10 -0
- package/.medusa/server/src/hooks/use-bold-checkout-handler.js +135 -0
- package/.medusa/server/src/hooks/use-bold-payment-methods.js +20 -0
- package/.medusa/server/src/hooks/use-bold-payment-status-stream.js +19 -0
- package/.medusa/server/src/hooks/use-bold-refund.js +19 -0
- package/.medusa/server/src/hooks/use-bold-terminals.js +13 -0
- package/.medusa/server/src/hooks/use-create-bold-button.js +19 -0
- package/.medusa/server/src/hooks/use-create-bold-link.js +19 -0
- package/.medusa/server/src/hooks/use-create-bold-qr.js +19 -0
- package/.medusa/server/src/hooks/use-create-bold-terminal.js +19 -0
- package/.medusa/server/src/index.js +21 -0
- package/.medusa/server/src/lib/error-utils.js +25 -0
- package/.medusa/server/src/lib/get-active-providers.js +34 -0
- package/.medusa/server/src/lib/get-provider-options.js +20 -0
- package/.medusa/server/src/lib/index.js +4 -0
- package/.medusa/server/src/lib/session-helpers.js +11 -0
- package/.medusa/server/src/providers/bold-button/index.js +157 -0
- package/.medusa/server/src/providers/bold-link/index.js +249 -0
- package/.medusa/server/src/providers/bold-online/index.js +169 -0
- package/.medusa/server/src/providers/bold-terminal/index.js +170 -0
- package/.medusa/server/src/rbac.js +58 -0
- package/.medusa/server/src/sdk/client.js +112 -0
- package/.medusa/server/src/sdk/query-keys.js +13 -0
- package/.medusa/server/src/services/bold-client.js +304 -0
- package/.medusa/server/src/services/integrity.js +54 -0
- package/.medusa/server/src/types/constants.js +55 -0
- package/.medusa/server/src/types/enums.js +15 -0
- package/.medusa/server/src/types/errors.js +80 -0
- package/.medusa/server/src/types/index.js +3 -0
- package/.medusa/server/src/workflows/create-bold-payment-link.js +7 -0
- package/.medusa/server/src/workflows/create-bold-refund.js +7 -0
- package/.medusa/server/src/workflows/get-bold-payment-methods.js +7 -0
- package/.medusa/server/src/workflows/get-integration-api-payment-methods.js +7 -0
- package/.medusa/server/src/workflows/get-payment-link-methods.js +7 -0
- package/.medusa/server/src/workflows/get-terminals.js +7 -0
- package/.medusa/server/src/workflows/index.js +7 -0
- package/.medusa/server/src/workflows/steps/create-bold-link.js +43 -0
- package/.medusa/server/src/workflows/steps/get-bold-payment-methods.js +12 -0
- package/.medusa/server/src/workflows/steps/get-payment-link-methods.js +12 -0
- package/.medusa/server/src/workflows/steps/get-terminals.js +13 -0
- package/.medusa/server/src/workflows/steps/refund-bold-payment.js +15 -0
- package/README.md +106 -2
- package/package.json +115 -3
- package/src/__tests__/bold-contract.spec.ts +40 -0
- package/src/__tests__/bold-qa-emulator.ts +582 -0
- package/src/__tests__/bold-use-cases.spec.ts +773 -0
- package/src/__tests__/medusa-payment-shim.mjs +334 -0
- package/src/__tests__/register-ts-resolver.mjs +101 -0
- package/src/admin/README.md +71 -0
- package/src/admin/components/bold-terminal-status.tsx +166 -0
- package/src/admin/components/icons/bold-fav.tsx +45 -0
- package/src/admin/components/icons/copy.tsx +23 -0
- package/src/admin/components/icons/index.ts +3 -0
- package/src/admin/components/icons/qr-code.tsx +33 -0
- package/src/admin/components/icons/smart-phone.tsx +23 -0
- package/src/admin/components/index.ts +4 -0
- package/src/admin/components/logos/bold.tsx +45 -0
- package/src/admin/components/method-item.tsx +19 -0
- package/src/admin/components/provider-card.tsx +21 -0
- package/src/admin/components/section.tsx +23 -0
- package/src/admin/i18n/README.md +58 -0
- package/src/admin/i18n/index.ts +11 -0
- package/src/admin/i18n/json/ar.json +99 -0
- package/src/admin/i18n/json/en.json +99 -0
- package/src/admin/i18n/json/es.json +99 -0
- package/src/admin/i18n/json/tr.json +99 -0
- package/src/admin/routes/settings/bold/components/bold-methods-sidebar.tsx +96 -0
- package/src/admin/routes/settings/bold/components/bold-providers-section.tsx +67 -0
- package/src/admin/routes/settings/bold/components/index.ts +2 -0
- package/src/admin/routes/settings/bold/page.tsx +109 -0
- package/src/admin/tsconfig.json +24 -0
- package/src/admin/vite-env.d.ts +1 -0
- package/src/admin/widgets/bold-audit-timeline.tsx +155 -0
- package/src/admin/widgets/bold-payment-actions/bold-payment-actions.tsx +114 -0
- package/src/admin/widgets/bold-payment-actions/components/bold-payment-tabs.tsx +127 -0
- package/src/admin/widgets/bold-payment-actions/components/bold-remote-payment-panel.tsx +104 -0
- package/src/admin/widgets/bold-payment-actions/components/bold-terminal-section.tsx +71 -0
- package/src/admin/widgets/bold-payment-actions/hooks/bold-order-balance.ts +126 -0
- package/src/admin/widgets/bold-payment-actions/hooks/use-bold-widget-state.tsx +181 -0
- package/src/admin/widgets/bold-refund-actions.tsx +151 -0
- package/src/admin/widgets/index.ts +12 -0
- package/src/api/README.md +37 -0
- package/src/api/admin/bold/banks/route.ts +23 -0
- package/src/api/admin/bold/payment-button/route.ts +57 -0
- package/src/api/admin/bold/payment-link/route.ts +68 -0
- package/src/api/admin/bold/payment-link-methods/route.ts +24 -0
- package/src/api/admin/bold/payment-methods/route.ts +27 -0
- package/src/api/admin/bold/payment-qr/route.ts +68 -0
- package/src/api/admin/bold/payment-status/route.ts +48 -0
- package/src/api/admin/bold/payment-stream/route.ts +157 -0
- package/src/api/admin/bold/pos-push/route.ts +59 -0
- package/src/api/admin/bold/refund/route.ts +51 -0
- package/src/api/admin/bold/terminals/route.ts +26 -0
- package/src/api/admin/plugin/route.ts +14 -0
- package/src/api/hooks/payment/bold/route.ts +156 -0
- package/src/api/store/plugin/route.ts +5 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/use-bold-checkout-handler.ts +172 -0
- package/src/hooks/use-bold-payment-methods.ts +36 -0
- package/src/hooks/use-bold-payment-status-stream.ts +55 -0
- package/src/hooks/use-bold-refund.ts +33 -0
- package/src/hooks/use-bold-terminals.ts +22 -0
- package/src/hooks/use-create-bold-button.ts +34 -0
- package/src/hooks/use-create-bold-link.ts +33 -0
- package/src/hooks/use-create-bold-qr.ts +33 -0
- package/src/hooks/use-create-bold-terminal.ts +37 -0
- package/src/index.ts +31 -0
- package/src/lib/error-utils.ts +29 -0
- package/src/lib/get-active-providers.ts +52 -0
- package/src/lib/get-provider-options.ts +54 -0
- package/src/lib/index.ts +3 -0
- package/src/lib/session-helpers.ts +16 -0
- package/src/providers/README.md +30 -0
- package/src/providers/bold-button/index.ts +244 -0
- package/src/providers/bold-link/index.ts +350 -0
- package/src/providers/bold-online/index.ts +254 -0
- package/src/providers/bold-terminal/index.ts +258 -0
- package/src/rbac.ts +72 -0
- package/src/sdk/client.ts +157 -0
- package/src/sdk/query-keys.ts +13 -0
- package/src/services/bold-client.ts +470 -0
- package/src/services/integrity.ts +74 -0
- package/src/types/constants.ts +63 -0
- package/src/types/enums.ts +13 -0
- package/src/types/errors.ts +88 -0
- package/src/types/index.ts +517 -0
- package/src/workflows/create-bold-payment-link.ts +16 -0
- package/src/workflows/create-bold-refund.ts +16 -0
- package/src/workflows/get-bold-payment-methods.ts +13 -0
- package/src/workflows/get-integration-api-payment-methods.ts +13 -0
- package/src/workflows/get-payment-link-methods.ts +13 -0
- package/src/workflows/get-terminals.ts +10 -0
- package/src/workflows/index.ts +6 -0
- package/src/workflows/steps/create-bold-link.ts +74 -0
- package/src/workflows/steps/get-bold-payment-methods.ts +21 -0
- package/src/workflows/steps/get-payment-link-methods.ts +19 -0
- package/src/workflows/steps/get-terminals.ts +20 -0
- package/src/workflows/steps/refund-bold-payment.ts +28 -0
- package/tsconfig.json +41 -0
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import { Logger } from "@medusajs/medusa"
|
|
2
|
+
import {
|
|
3
|
+
BOLD_ENVIRONMENT,
|
|
4
|
+
BOLD_PAYMENT_METHOD_QR_FORMAT,
|
|
5
|
+
BOLD_PAYMENT_METHOD_TYPE,
|
|
6
|
+
} from "./constants"
|
|
7
|
+
import { BoldApiClient } from "@payment-bold/sdk/client"
|
|
8
|
+
|
|
9
|
+
// export { BOLD_PLUGIN_PROVIDERS } from "./constants"
|
|
10
|
+
export { EBoldPaymentProvider } from "./enums"
|
|
11
|
+
|
|
12
|
+
// ==========================================
|
|
13
|
+
// 1. Core Plugin Configuration & Utils
|
|
14
|
+
// ==========================================
|
|
15
|
+
|
|
16
|
+
export type TBoldEnvironment = (typeof BOLD_ENVIRONMENT)[number]
|
|
17
|
+
export type TBoldPaymentMethodQrFormat =
|
|
18
|
+
(typeof BOLD_PAYMENT_METHOD_QR_FORMAT)[number]
|
|
19
|
+
|
|
20
|
+
export interface BoldBaseOptions {
|
|
21
|
+
// Payment Button Keys (used for Payment Links & Checkout Webhooks)
|
|
22
|
+
buttonApiKey: string
|
|
23
|
+
buttonSecretKey?: string
|
|
24
|
+
|
|
25
|
+
// API Integrations Keys (used for Terminals / Data-phone)
|
|
26
|
+
integrationApiKey?: string
|
|
27
|
+
integrationSecretKey?: string
|
|
28
|
+
|
|
29
|
+
defaultCurrency?: string
|
|
30
|
+
linkExpirationMinutes?: number
|
|
31
|
+
|
|
32
|
+
// Optional base URL overrides (for local QA emulator / sandbox environments)
|
|
33
|
+
integrationsUrl?: string
|
|
34
|
+
onlineUrl?: string
|
|
35
|
+
paymentsUrl?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type InjectedDependencies = {
|
|
39
|
+
logger: Logger
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface MappedPaymentError {
|
|
43
|
+
code: string
|
|
44
|
+
userMessage: string
|
|
45
|
+
adminReason: string
|
|
46
|
+
retryable: boolean
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ==========================================
|
|
50
|
+
// 2. Bold API Schemas (snake_case)
|
|
51
|
+
// ==========================================
|
|
52
|
+
|
|
53
|
+
export interface BoldApiError {
|
|
54
|
+
code?: string
|
|
55
|
+
message?: string
|
|
56
|
+
field?: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type BoldPersonType = "NATURAL_PERSON" | "LEGAL_PERSON"
|
|
60
|
+
|
|
61
|
+
export type BoldDocumentType =
|
|
62
|
+
| "CEDULA"
|
|
63
|
+
| "CEDULA_EXTRANJERIA"
|
|
64
|
+
| "PASAPORTE"
|
|
65
|
+
| "NIT"
|
|
66
|
+
| "TI"
|
|
67
|
+
| "PEP"
|
|
68
|
+
|
|
69
|
+
export interface BankItem {
|
|
70
|
+
bank_code: string
|
|
71
|
+
bank_name: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface BoldBillingAddress {
|
|
75
|
+
street1: string
|
|
76
|
+
street2?: string
|
|
77
|
+
city: string
|
|
78
|
+
zip_code?: string
|
|
79
|
+
province?: string
|
|
80
|
+
country: string
|
|
81
|
+
phone?: string
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface BoldPayer {
|
|
85
|
+
person_type?: BoldPersonType
|
|
86
|
+
name?: string
|
|
87
|
+
phone?: string
|
|
88
|
+
email?: string
|
|
89
|
+
document_type?: BoldDocumentType
|
|
90
|
+
document_number?: string
|
|
91
|
+
billing_address?: BoldBillingAddress
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface BoldDeviceFingerprint {
|
|
95
|
+
ip?: string
|
|
96
|
+
device_type?: "DESKTOP" | "MOBILE" | "TABLET"
|
|
97
|
+
os?: string
|
|
98
|
+
model?: string
|
|
99
|
+
browser?: string
|
|
100
|
+
java_enabled?: boolean
|
|
101
|
+
language?: string
|
|
102
|
+
color_depth?: number
|
|
103
|
+
screen_height?: number
|
|
104
|
+
screen_width?: number
|
|
105
|
+
time_zone_offset?: number
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface BoldMetadata {
|
|
109
|
+
key: string
|
|
110
|
+
value: string
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface BoldPaymentMethodQR {
|
|
114
|
+
name: "QR"
|
|
115
|
+
qr_format?: TBoldPaymentMethodQrFormat
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface BoldPaymentMethodCard {
|
|
119
|
+
name: "CREDIT_CARD"
|
|
120
|
+
card_number: string
|
|
121
|
+
cardholder_name: string
|
|
122
|
+
expiration_month: string
|
|
123
|
+
expiration_year: string
|
|
124
|
+
installments?: number
|
|
125
|
+
cvc: string
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface BoldPaymentMethodPSE extends BankItem {
|
|
129
|
+
name: "PSE"
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface BoldPaymentMethodBotonBancolombia {
|
|
133
|
+
name: "BOTON_BANCOLOMBIA" | "NEQUI"
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export type BoldPaymentMethod =
|
|
137
|
+
| BoldPaymentMethodQR
|
|
138
|
+
| BoldPaymentMethodCard
|
|
139
|
+
| BoldPaymentMethodPSE
|
|
140
|
+
| BoldPaymentMethodBotonBancolombia
|
|
141
|
+
|
|
142
|
+
// Raw payload sent to Bold POST /v1/payment-intent
|
|
143
|
+
export interface BoldPaymentIntentApiRequest {
|
|
144
|
+
reference_id: string
|
|
145
|
+
metadata?: BoldMetadata
|
|
146
|
+
payer?: BoldPayer
|
|
147
|
+
payment_method: BoldPaymentMethod
|
|
148
|
+
device_fingerprint?: BoldDeviceFingerprint
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Raw response from Bold POST /v1/payment-intent
|
|
152
|
+
export interface BoldPaymentAttemptResponse {
|
|
153
|
+
id: string
|
|
154
|
+
status: string
|
|
155
|
+
payment_url?: string
|
|
156
|
+
reference_id: string
|
|
157
|
+
payment_method?: {
|
|
158
|
+
name: string
|
|
159
|
+
[key: string]: any
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Raw payload sent to Bold POST /v1/refunds
|
|
164
|
+
export interface BoldRefundApiRequest {
|
|
165
|
+
transaction_id: string
|
|
166
|
+
amount: number
|
|
167
|
+
reason?: string
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Raw response from Bold POST /v1/refunds
|
|
171
|
+
export interface BoldRefundApiResponse {
|
|
172
|
+
refund_id: string
|
|
173
|
+
transaction_id: string
|
|
174
|
+
amount: number
|
|
175
|
+
status: string
|
|
176
|
+
created_at: string
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export type BoldLinkPaymentStatus =
|
|
180
|
+
| "NO_TRANSACTION_FOUND"
|
|
181
|
+
| "APPROVED"
|
|
182
|
+
| "REJECTED"
|
|
183
|
+
| "PROCESSING"
|
|
184
|
+
| "FAILED"
|
|
185
|
+
| "CANCELLED"
|
|
186
|
+
|
|
187
|
+
export interface BoldLinkPaymentStatusResponse {
|
|
188
|
+
link_id: string
|
|
189
|
+
reference_id: string
|
|
190
|
+
total: number
|
|
191
|
+
subtotal: number
|
|
192
|
+
description: string
|
|
193
|
+
payment_status: BoldLinkPaymentStatus
|
|
194
|
+
transaction_id?: string
|
|
195
|
+
payment_method?: string
|
|
196
|
+
payer_email?: string
|
|
197
|
+
transaction_date?: string
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface BoldTerminalItem {
|
|
201
|
+
terminal_serial: string
|
|
202
|
+
terminal_model: string
|
|
203
|
+
status?: string
|
|
204
|
+
name?: string
|
|
205
|
+
[key: string]: any
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface BoldTerminalsResponse {
|
|
209
|
+
payload: {
|
|
210
|
+
available_terminals: BoldTerminalItem[]
|
|
211
|
+
}
|
|
212
|
+
errors?: any[]
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface BoldWebhookPayload {
|
|
216
|
+
event:
|
|
217
|
+
| "sale.successful"
|
|
218
|
+
| "sale.failed"
|
|
219
|
+
| "sale.rejected"
|
|
220
|
+
| "refund.successful"
|
|
221
|
+
data: {
|
|
222
|
+
id: string
|
|
223
|
+
reference: string
|
|
224
|
+
amount: number
|
|
225
|
+
currency: string
|
|
226
|
+
status: string
|
|
227
|
+
payment_method?: string
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ==========================================
|
|
232
|
+
// 3. Plugin Internal Payloads (camelCase)
|
|
233
|
+
// ==========================================
|
|
234
|
+
|
|
235
|
+
export type PaymentMethodType = (typeof BOLD_PAYMENT_METHOD_TYPE)[number]
|
|
236
|
+
|
|
237
|
+
export interface BoldTerminalPayload {
|
|
238
|
+
paymentCollectionId?: string
|
|
239
|
+
terminalModel: string
|
|
240
|
+
terminalSerial: string
|
|
241
|
+
amount: number
|
|
242
|
+
currency: string
|
|
243
|
+
reference: string
|
|
244
|
+
vatAmount?: number
|
|
245
|
+
userEmail: string
|
|
246
|
+
description?: string
|
|
247
|
+
payer?: {
|
|
248
|
+
email: string
|
|
249
|
+
phoneNumber: string
|
|
250
|
+
document: {
|
|
251
|
+
documentType: string
|
|
252
|
+
documentNumber: string
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface BoldPaymentMethodsResponse {
|
|
258
|
+
payload: {
|
|
259
|
+
payment_methods: Array<BoldPaymentMethod>
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface BoldIntegrationAPIPaymentMethod {
|
|
264
|
+
name: string
|
|
265
|
+
enabled: boolean
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export interface BoldIntegrationApiPaymentMethodsPayload {
|
|
269
|
+
payment_methods: Array<BoldIntegrationAPIPaymentMethod>
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface BoldIntegrationApiPaymentMethodsResponse extends BoldIntegrationApiPaymentMethodsPayload {
|
|
273
|
+
errors: any[]
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface BoldPaymentMethodLimits {
|
|
277
|
+
min: number
|
|
278
|
+
max: number
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export type BoldPaymentLinkPaymentMethodKey =
|
|
282
|
+
| "CREDIT_CARD"
|
|
283
|
+
| "PSE"
|
|
284
|
+
| "BOTON_BANCOLOMBIA"
|
|
285
|
+
| "NEQUI"
|
|
286
|
+
| (string & {}) // Fallback for future online channels
|
|
287
|
+
|
|
288
|
+
export interface BoldPaymentLinkPaymentMethodsMap {
|
|
289
|
+
[key: string]: BoldPaymentMethodLimits
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export type BoldPaymentLinkPaymentMethodLimits = Record<
|
|
293
|
+
BoldPaymentLinkPaymentMethodKey,
|
|
294
|
+
BoldPaymentMethodLimits
|
|
295
|
+
>
|
|
296
|
+
|
|
297
|
+
export interface BoldPaymentLinkPaymentLimitsPayload {
|
|
298
|
+
payment_methods: BoldPaymentLinkPaymentMethodLimits
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export interface BoldPaymentLinkPaymentLimitsResponse {
|
|
302
|
+
payload: BoldPaymentLinkPaymentLimitsPayload
|
|
303
|
+
errors: any[]
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export interface BoldPaymentIntentPayload {
|
|
307
|
+
reference: string
|
|
308
|
+
amount: number
|
|
309
|
+
currency?: string
|
|
310
|
+
methodType: PaymentMethodType
|
|
311
|
+
description?: string
|
|
312
|
+
callbackUrl?: string
|
|
313
|
+
|
|
314
|
+
// Nested Payer details (Optional)
|
|
315
|
+
payer?: {
|
|
316
|
+
personType?: BoldPersonType
|
|
317
|
+
name?: string
|
|
318
|
+
phone?: string
|
|
319
|
+
email?: string
|
|
320
|
+
documentType?: BoldDocumentType
|
|
321
|
+
documentNumber?: string
|
|
322
|
+
billingAddress?: BoldBillingAddress
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Anti-fraud
|
|
326
|
+
deviceFingerprint?: BoldDeviceFingerprint
|
|
327
|
+
metadata?: BoldMetadata
|
|
328
|
+
|
|
329
|
+
// Method-specific input fields
|
|
330
|
+
cardNumber?: string
|
|
331
|
+
cardholderName?: string
|
|
332
|
+
expirationMonth?: string
|
|
333
|
+
expirationYear?: string
|
|
334
|
+
cvc?: string
|
|
335
|
+
installments?: number
|
|
336
|
+
bankCode?: string
|
|
337
|
+
bankName?: string
|
|
338
|
+
qrFormat?: string
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface CreatePaymentLinkPayload {
|
|
342
|
+
amount: number
|
|
343
|
+
currency?: string
|
|
344
|
+
reference: string
|
|
345
|
+
description?: string
|
|
346
|
+
expirationMinutes?: number
|
|
347
|
+
email?: string
|
|
348
|
+
callbackUrl?: string
|
|
349
|
+
vatAmount?: number
|
|
350
|
+
consumptionTaxAmount?: number
|
|
351
|
+
imageUrl?: string
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export interface CreateRefundPayload {
|
|
355
|
+
transactionId: string
|
|
356
|
+
amount: number
|
|
357
|
+
reason?: string
|
|
358
|
+
}
|
|
359
|
+
export interface BoldPaymentLinkPayload {
|
|
360
|
+
payment_link: string
|
|
361
|
+
url: string
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export interface BoldCreatePaymentLinkResponse {
|
|
365
|
+
payload: BoldPaymentLinkPayload
|
|
366
|
+
errors: Array<BoldApiError>
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// ==========================================
|
|
370
|
+
// 4. Plugin Admin SDK
|
|
371
|
+
// ==========================================
|
|
372
|
+
|
|
373
|
+
export interface BoldLinkPayload {
|
|
374
|
+
amount: number
|
|
375
|
+
currency: string
|
|
376
|
+
reference: string
|
|
377
|
+
description: string
|
|
378
|
+
email: string
|
|
379
|
+
vatAmount?: number
|
|
380
|
+
consumptionTaxAmount?: number
|
|
381
|
+
callbackUrl?: string
|
|
382
|
+
expirationMinutes?: number
|
|
383
|
+
imageUrl?: string
|
|
384
|
+
paymentCollectionId?: string
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export interface BoldPaymentSession {
|
|
388
|
+
id: string
|
|
389
|
+
currency_code?: string
|
|
390
|
+
provider_id?: string
|
|
391
|
+
status?: string
|
|
392
|
+
amount?: number
|
|
393
|
+
payment_collection_id?: string
|
|
394
|
+
payment_collection?: {
|
|
395
|
+
id: string
|
|
396
|
+
}
|
|
397
|
+
data?: {
|
|
398
|
+
url?: string
|
|
399
|
+
payment_url?: string
|
|
400
|
+
status?: string
|
|
401
|
+
session_id?: string
|
|
402
|
+
payment_link_id?: string
|
|
403
|
+
[key: string]: any
|
|
404
|
+
}
|
|
405
|
+
[key: string]: any
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export interface BoldLinkResponse {
|
|
409
|
+
paymentSession: BoldPaymentSession
|
|
410
|
+
[key: string]: any
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export interface BoldButtonPayload {
|
|
414
|
+
amount: number
|
|
415
|
+
currency: string
|
|
416
|
+
reference: string
|
|
417
|
+
description: string
|
|
418
|
+
email?: string
|
|
419
|
+
taxAmount?: number
|
|
420
|
+
paymentCollectionId?: string
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export interface BoldButtonResponse {
|
|
424
|
+
paymentSession?: {
|
|
425
|
+
id: string
|
|
426
|
+
data?: {
|
|
427
|
+
order_id?: string
|
|
428
|
+
hash?: string
|
|
429
|
+
checkout_url?: string
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export interface BoldQrPayload {
|
|
435
|
+
amount: number
|
|
436
|
+
currency_code: string
|
|
437
|
+
paymentCollectionId?: string
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export interface BoldQrResponse {
|
|
441
|
+
qr_payload: string
|
|
442
|
+
paymentSession: BoldPaymentSession
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export interface BoldTerminalResponse {
|
|
446
|
+
paymentSession: BoldPaymentSession
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export type BoldPaymentStreamStatus = "pending" | "captured" | "error"
|
|
450
|
+
|
|
451
|
+
export interface BoldStatusStreamCallbacks {
|
|
452
|
+
onStatusChange?: (status: BoldPaymentStreamStatus, rawData: any) => void
|
|
453
|
+
onSuccess?: (rawData: any) => void
|
|
454
|
+
onError?: (error?: any) => void
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export interface BoldRefundPayload {
|
|
458
|
+
payment_id: string
|
|
459
|
+
amount: number
|
|
460
|
+
note?: string
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export interface BoldRefundResponse {
|
|
464
|
+
refund: any
|
|
465
|
+
message?: string
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// ==========================================
|
|
469
|
+
// 5. Plugin Hooks
|
|
470
|
+
// ==========================================
|
|
471
|
+
|
|
472
|
+
export interface BoldMutationHookOptions {
|
|
473
|
+
/**
|
|
474
|
+
* The API client instance to use (e.g. boldAdminSdk or boldStoreSdk)
|
|
475
|
+
* @default boldAdminSdk
|
|
476
|
+
*/
|
|
477
|
+
client?: BoldApiClient // TODO: remove circular import
|
|
478
|
+
/**
|
|
479
|
+
* Custom query key array to invalidate upon mutation success
|
|
480
|
+
* @default boldQueryKeys.orders()
|
|
481
|
+
*/
|
|
482
|
+
queryKey?: readonly unknown[]
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export interface ClientInfo {
|
|
486
|
+
first_name?: string
|
|
487
|
+
last_name?: string
|
|
488
|
+
phone?: string
|
|
489
|
+
email?: string
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export interface BoldCheckoutDetails {
|
|
493
|
+
boldMode: "link" | "button" | "qr" | "terminal"
|
|
494
|
+
amount: number
|
|
495
|
+
vatAmount?: number
|
|
496
|
+
consumptionTaxAmount?: number
|
|
497
|
+
callbackUrl?: string
|
|
498
|
+
expirationMinutes?: number
|
|
499
|
+
imageUrl?: string
|
|
500
|
+
terminalId?: string
|
|
501
|
+
terminalModel?: string
|
|
502
|
+
terminalSerial?: string
|
|
503
|
+
paymentCollectionId?: string
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export interface BoldCheckoutData {
|
|
507
|
+
details: BoldCheckoutDetails
|
|
508
|
+
paymentMode?: "installments" | "full"
|
|
509
|
+
client: ClientInfo
|
|
510
|
+
currencyCode: string
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export type BoldCheckoutResult =
|
|
514
|
+
| { type: "link"; url?: string; sessionId?: string }
|
|
515
|
+
| { type: "button"; hash?: string; sessionId?: string }
|
|
516
|
+
| { type: "qr"; qrPayload: string; sessionId: string }
|
|
517
|
+
| { type: "terminal"; sessionId: string }
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWorkflow,
|
|
3
|
+
WorkflowResponse,
|
|
4
|
+
} from "@medusajs/framework/workflows-sdk"
|
|
5
|
+
import {
|
|
6
|
+
createBoldLinkStep,
|
|
7
|
+
CreateBoldLinkStepInput,
|
|
8
|
+
} from "./steps/create-bold-link"
|
|
9
|
+
|
|
10
|
+
export const createBoldPaymentLinkWorkflow = createWorkflow(
|
|
11
|
+
"create-bold-payment-link",
|
|
12
|
+
(input: CreateBoldLinkStepInput) => {
|
|
13
|
+
const result = createBoldLinkStep(input)
|
|
14
|
+
return new WorkflowResponse(result)
|
|
15
|
+
}
|
|
16
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWorkflow,
|
|
3
|
+
WorkflowResponse,
|
|
4
|
+
} from "@medusajs/framework/workflows-sdk"
|
|
5
|
+
import {
|
|
6
|
+
refundBoldPaymentStep,
|
|
7
|
+
RefundBoldPaymentStepInput,
|
|
8
|
+
} from "./steps/refund-bold-payment"
|
|
9
|
+
|
|
10
|
+
export const refundBoldPaymentWorkflow = createWorkflow(
|
|
11
|
+
"refund-bold-payment",
|
|
12
|
+
(input: RefundBoldPaymentStepInput) => {
|
|
13
|
+
const result = refundBoldPaymentStep(input)
|
|
14
|
+
return new WorkflowResponse(result)
|
|
15
|
+
}
|
|
16
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWorkflow,
|
|
3
|
+
WorkflowResponse,
|
|
4
|
+
} from "@medusajs/framework/workflows-sdk"
|
|
5
|
+
import { getBoldPaymentMethodsStep } from "./steps/get-bold-payment-methods"
|
|
6
|
+
|
|
7
|
+
export const getBoldPaymentMethodsWorkflow = createWorkflow(
|
|
8
|
+
"get-bold-payment-methods",
|
|
9
|
+
function () {
|
|
10
|
+
const result = getBoldPaymentMethodsStep()
|
|
11
|
+
return new WorkflowResponse(result)
|
|
12
|
+
}
|
|
13
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWorkflow,
|
|
3
|
+
WorkflowResponse,
|
|
4
|
+
} from "@medusajs/framework/workflows-sdk"
|
|
5
|
+
import { getBoldPaymentMethodsStep } from "./steps/get-bold-payment-methods"
|
|
6
|
+
|
|
7
|
+
export const getIntegrationApiPaymentMethodsWorkflow = createWorkflow(
|
|
8
|
+
"get-integration-api-payment-methods",
|
|
9
|
+
() => {
|
|
10
|
+
const { paymentMethods } = getBoldPaymentMethodsStep()
|
|
11
|
+
return new WorkflowResponse(paymentMethods)
|
|
12
|
+
}
|
|
13
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWorkflow,
|
|
3
|
+
WorkflowResponse,
|
|
4
|
+
} from "@medusajs/framework/workflows-sdk"
|
|
5
|
+
import { getPaymentLinkMethodsStep } from "./steps/get-payment-link-methods"
|
|
6
|
+
|
|
7
|
+
export const getPaymentLinkMethodsWorkflow = createWorkflow(
|
|
8
|
+
"get-payment-link-methods",
|
|
9
|
+
() => {
|
|
10
|
+
const { paymentMethods } = getPaymentLinkMethodsStep()
|
|
11
|
+
return new WorkflowResponse(paymentMethods)
|
|
12
|
+
}
|
|
13
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWorkflow,
|
|
3
|
+
WorkflowResponse,
|
|
4
|
+
} from "@medusajs/framework/workflows-sdk"
|
|
5
|
+
import { getTerminalsStep } from "./steps/get-terminals"
|
|
6
|
+
|
|
7
|
+
export const getTerminalsWorkflow = createWorkflow("get-terminals", () => {
|
|
8
|
+
const terminals = getTerminalsStep()
|
|
9
|
+
return new WorkflowResponse(terminals)
|
|
10
|
+
})
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createBoldPaymentLinkWorkflow } from "./create-bold-payment-link"
|
|
2
|
+
export { refundBoldPaymentWorkflow } from "./create-bold-refund"
|
|
3
|
+
export { getBoldPaymentMethodsWorkflow } from "./get-bold-payment-methods"
|
|
4
|
+
export { getIntegrationApiPaymentMethodsWorkflow } from "./get-integration-api-payment-methods"
|
|
5
|
+
export { getPaymentLinkMethodsWorkflow } from "./get-payment-link-methods"
|
|
6
|
+
export { getTerminalsWorkflow } from "./get-terminals"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
2
|
+
import { Modules } from "@medusajs/framework/utils"
|
|
3
|
+
import { IPaymentModuleService } from "@medusajs/framework/types"
|
|
4
|
+
import { createPaymentSessionsWorkflow } from "@medusajs/medusa/core-flows"
|
|
5
|
+
import { EMedusaFormatBoldPaymentProvider } from "@payment-bold/types/enums"
|
|
6
|
+
|
|
7
|
+
export interface CreateBoldLinkStepInput {
|
|
8
|
+
paymentCollectionId?: string
|
|
9
|
+
paymentSessionId?: string
|
|
10
|
+
amount: number
|
|
11
|
+
currency: string
|
|
12
|
+
email: string
|
|
13
|
+
reference: string
|
|
14
|
+
description: string
|
|
15
|
+
vatAmount: number
|
|
16
|
+
consumptionTaxAmount?: number
|
|
17
|
+
callbackUrl: string
|
|
18
|
+
imageUrl?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const createBoldLinkStep = createStep(
|
|
22
|
+
"create-bold-link",
|
|
23
|
+
async (input: CreateBoldLinkStepInput, { container }) => {
|
|
24
|
+
const paymentModule: IPaymentModuleService = container.resolve(
|
|
25
|
+
Modules.PAYMENT
|
|
26
|
+
)
|
|
27
|
+
let collectionId = input.paymentCollectionId
|
|
28
|
+
let createdCollection = false
|
|
29
|
+
|
|
30
|
+
// 1. Ensure PaymentCollection exists
|
|
31
|
+
if (!collectionId) {
|
|
32
|
+
const collection = await paymentModule.createPaymentCollections({
|
|
33
|
+
currency_code: input.currency.toLowerCase(),
|
|
34
|
+
amount: input.amount,
|
|
35
|
+
})
|
|
36
|
+
collectionId = collection.id
|
|
37
|
+
createdCollection = true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 2. Create Payment Session using Medusa v2 Core Workflow
|
|
41
|
+
const { result: paymentSession } = await createPaymentSessionsWorkflow(
|
|
42
|
+
container
|
|
43
|
+
).run({
|
|
44
|
+
input: {
|
|
45
|
+
payment_collection_id: collectionId,
|
|
46
|
+
provider_id: EMedusaFormatBoldPaymentProvider.LINK,
|
|
47
|
+
data: {
|
|
48
|
+
reference: input.reference,
|
|
49
|
+
description: input.description,
|
|
50
|
+
email: input.email,
|
|
51
|
+
callbackUrl: input.callbackUrl,
|
|
52
|
+
vatAmount: input.vatAmount,
|
|
53
|
+
consumptionTaxAmount: input.consumptionTaxAmount,
|
|
54
|
+
imageUrl: input.imageUrl,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
return new StepResponse(
|
|
60
|
+
{ paymentSession, paymentCollectionId: collectionId },
|
|
61
|
+
{ collectionId: createdCollection ? collectionId : undefined }
|
|
62
|
+
)
|
|
63
|
+
},
|
|
64
|
+
async (compensationData, { container }) => {
|
|
65
|
+
if (compensationData?.collectionId) {
|
|
66
|
+
const paymentModule: IPaymentModuleService = container.resolve(
|
|
67
|
+
Modules.PAYMENT
|
|
68
|
+
)
|
|
69
|
+
await paymentModule.deletePaymentCollections([
|
|
70
|
+
compensationData.collectionId,
|
|
71
|
+
])
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Logger } from "@medusajs/medusa"
|
|
2
|
+
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|
3
|
+
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
|
4
|
+
import { BoldIntegrationAPIPaymentMethod } from "@payment-bold/types"
|
|
5
|
+
import { getProviderOptionsFromContainer } from "@payment-bold/lib/get-provider-options"
|
|
6
|
+
import { BoldHttpClient } from "@payment-bold/services/bold-client"
|
|
7
|
+
|
|
8
|
+
export const getBoldPaymentMethodsStep = createStep(
|
|
9
|
+
"get-bold-payment-methods",
|
|
10
|
+
async (_, { container }) => {
|
|
11
|
+
const logger = container.resolve<Logger>(ContainerRegistrationKeys.LOGGER)
|
|
12
|
+
|
|
13
|
+
const boldProviderOptions = getProviderOptionsFromContainer(container)
|
|
14
|
+
|
|
15
|
+
const client = new BoldHttpClient(boldProviderOptions, logger)
|
|
16
|
+
const paymentMethods: Array<BoldIntegrationAPIPaymentMethod> =
|
|
17
|
+
await client.getAvailableIntegrationApiPaymentMethods()
|
|
18
|
+
|
|
19
|
+
return new StepResponse({ paymentMethods })
|
|
20
|
+
}
|
|
21
|
+
)
|