@fayz-ai/plugin-payments 0.9.0 → 0.9.2
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/dist/public/{hooks.d.ts → hooks/index.d.ts} +1 -1
- package/dist/public/hooks/index.d.ts.map +1 -0
- package/dist/public/index.js.map +1 -1
- package/package.json +3 -6
- package/dist/public/hooks.d.ts.map +0 -1
- package/src/data/index.ts +0 -3
- package/src/data/mock.ts +0 -84
- package/src/data/supabase.ts +0 -24
- package/src/index.ts +0 -25
- package/src/public/context.tsx +0 -20
- package/src/public/createPublicPaymentPlugin.ts +0 -59
- package/src/public/hooks.ts +0 -82
- package/src/public/index.ts +0 -10
|
@@ -16,4 +16,4 @@ export declare function usePixCharge(): UsePixChargeResult;
|
|
|
16
16
|
* chargeId change, and terminal states.
|
|
17
17
|
*/
|
|
18
18
|
export declare function useChargeStatus(chargeId: string | null, intervalMs?: number): ChargeStatus | null;
|
|
19
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/public/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAG/E,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAA;IACxB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;IAC/D,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,kBAAkB,CA8BjD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,UAAU,SAAO,GAAG,YAAY,GAAG,IAAI,CA6B/F"}
|
package/dist/public/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/public/context.tsx","../../src/public/createPublicPaymentPlugin.ts","../../src/public/hooks.ts"],"names":[],"mappings":";;;;;AAOA,IAAM,cAAA,GAAiB,cAA0C,IAAI,CAAA;AAE9D,SAAS,sBAAA,CAAuB,EAAE,KAAA,EAAO,QAAA,EAAS,EAAwD;AAC/G,EAAA,uBAAO,GAAA,CAAC,cAAA,CAAe,QAAA,EAAf,EAAwB,OAAe,QAAA,EAAS,CAAA;AAC1D;AAEO,SAAS,iBAAA,GAAyC;AACvD,EAAA,MAAM,GAAA,GAAM,WAAW,cAAc,CAAA;AACrC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,gFAAgF,CAAA;AAAA,EAClG;AACA,EAAA,OAAO,GAAA;AACT;;;ACWO,SAAS,0BAA0B,OAAA,EAAqD;AAM7F,EAAA,MAAM,eAAA,GAAkB,OAAA,EAAS,eAAA,IAAmB,yBAAA,CAA0B,SAAS,IAAI,CAAA;AAE3F,EAAA,MAAM,KAAA,GAA6B,EAAE,QAAA,EAAU,eAAA,EAAgB;AAC/D,EAAA,MAAM,QAAA,GAAwC,CAAC,EAAE,QAAA,EAAS,KACxD,cAAc,sBAAA,EAAwB,EAAE,KAAA,EAAO,QAAA,EAAU,CAAA;AAC3D,EAAA,QAAA,CAAS,WAAA,GAAc,uBAAA;AAEvB,EAAA,MAAM,QAAA,GAA2B;AAAA,IAC/B,EAAA,EAAI,UAAA;AAAA,IACJ,IAAA,EAAM,YAAA;AAAA,IACN,IAAA,EAAM,YAAA;AAAA,IACN,OAAA,EAAS,OAAA;AAAA,IACT,KAAA,EAAO,SAAS,KAAA,IAAS,WAAA;AAAA,IACzB,SAAA,EAAW,CAAC,SAAA,EAAW,cAAc,CAAA;AAAA,IACrC,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QAAA,EAAU,UAAU,CAAC,CAAA;AAEnC,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import { createContext, useContext, type ReactNode } from 'react'\nimport type { PaymentProvider } from '@fayz-ai/core'\n\nexport interface PaymentContextValue {\n provider: PaymentProvider\n}\n\nconst PaymentContext = createContext<PaymentContextValue | null>(null)\n\nexport function PaymentProviderContext({ value, children }: { value: PaymentContextValue; children: ReactNode }) {\n return <PaymentContext.Provider value={value}>{children}</PaymentContext.Provider>\n}\n\nexport function usePaymentContext(): PaymentContextValue {\n const ctx = useContext(PaymentContext)\n if (!ctx) {\n throw new Error('[plugin-payments] usePaymentContext must be used within the payments Provider.')\n }\n return ctx\n}\n","import { createElement, type FC, type ReactNode } from 'react'\nimport type { PluginManifest, PluginScope, PaymentProvider } from '@fayz-ai/core'\nimport { createMockPaymentProvider, type MockPaymentOptions } from '../data/mock'\nimport { PaymentProviderContext, type PaymentContextValue } from './context'\n\n// ---------------------------------------------------------------------------\n// @fayz-ai/plugin-payments/public — website payment surface.\n//\n// Returns a { manifest, Provider, paymentProvider } bundle mirroring the other\n// website plugins. The host injects `paymentProvider` into the booking plugin;\n// the Provider/hooks are for a future standalone checkout page. No routes — a\n// payment is a service, not a screen.\n// ---------------------------------------------------------------------------\n\nexport interface PublicPaymentOptions {\n /** Currency for charges (informational; charges carry their own). */\n currency?: string\n /** Inject a custom provider (real gateway). Overrides the safe resolver. */\n paymentProvider?: PaymentProvider\n /** Tuning for the mock provider (auto-pay/expiry) when no real provider is set. */\n mock?: MockPaymentOptions\n scope?: PluginScope\n}\n\nexport interface PublicPaymentPlugin {\n manifest: PluginManifest\n Provider: FC<{ children: ReactNode }>\n paymentProvider: PaymentProvider\n}\n\nexport function createPublicPaymentPlugin(options?: PublicPaymentOptions): PublicPaymentPlugin {\n // Default is the MOCK provider even when a Supabase client is configured:\n // the Supabase payment path is still a stub (real gateway = MercadoPago edge\n // fn, deferred), so a real provider must be injected explicitly via\n // `paymentProvider`. Don't route through createSafePaymentProvider here or\n // any app with a configured Supabase client would hit the throwing stub.\n const paymentProvider = options?.paymentProvider ?? createMockPaymentProvider(options?.mock)\n\n const value: PaymentContextValue = { provider: paymentProvider }\n const Provider: FC<{ children: ReactNode }> = ({ children }) =>\n createElement(PaymentProviderContext, { value, children })\n Provider.displayName = 'PaymentPluginProvider'\n\n const manifest: PluginManifest = {\n id: 'payments',\n name: 'Pagamentos',\n icon: 'CreditCard',\n version: '0.1.0',\n scope: options?.scope ?? 'universal',\n scaffolds: ['website', 'landing_page'],\n defaultEnabled: true,\n dependencies: [],\n navigation: [],\n routes: [],\n widgets: [],\n }\n\n return { manifest, Provider, paymentProvider }\n}\n","import { useCallback, useEffect, useRef, useState } from 'react'\nimport type { CreateChargeInput, PixCharge, ChargeStatus } from '@fayz-ai/core'\nimport { usePaymentContext } from '
|
|
1
|
+
{"version":3,"sources":["../../src/public/context.tsx","../../src/public/createPublicPaymentPlugin.ts","../../src/public/hooks/index.ts"],"names":[],"mappings":";;;;;AAOA,IAAM,cAAA,GAAiB,cAA0C,IAAI,CAAA;AAE9D,SAAS,sBAAA,CAAuB,EAAE,KAAA,EAAO,QAAA,EAAS,EAAwD;AAC/G,EAAA,uBAAO,GAAA,CAAC,cAAA,CAAe,QAAA,EAAf,EAAwB,OAAe,QAAA,EAAS,CAAA;AAC1D;AAEO,SAAS,iBAAA,GAAyC;AACvD,EAAA,MAAM,GAAA,GAAM,WAAW,cAAc,CAAA;AACrC,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,MAAM,gFAAgF,CAAA;AAAA,EAClG;AACA,EAAA,OAAO,GAAA;AACT;;;ACWO,SAAS,0BAA0B,OAAA,EAAqD;AAM7F,EAAA,MAAM,eAAA,GAAkB,OAAA,EAAS,eAAA,IAAmB,yBAAA,CAA0B,SAAS,IAAI,CAAA;AAE3F,EAAA,MAAM,KAAA,GAA6B,EAAE,QAAA,EAAU,eAAA,EAAgB;AAC/D,EAAA,MAAM,Q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AA,IAAI,MAAM,MAAA,IAAU,CAAA,KAAM,SAAA,IAAa,CAAA,KAAM,UAAU,KAAA,EAAM;AAAA,MAC/D,CAAC,CAAA,CACA,KAAA,CAAM,MAAM;AAAA,MAAyC,CAAC,CAAA;AAAA,IAC3D,CAAA;AACA,IAAA,IAAA,EAAK;AACL,IAAA,KAAA,CAAM,OAAA,GAAU,WAAA,CAAY,IAAA,EAAM,UAAU,CAAA;AAC5C,IAAA,OAAO,MAAM;AAAE,MAAA,MAAA,GAAS,KAAA;AAAO,MAAA,KAAA,EAAM;AAAA,IAAE,CAAA;AAAA,EACzC,CAAA,EAAG,CAAC,QAAA,EAAU,QAAA,EAAU,UAAU,CAAC,CAAA;AAEnC,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import { createContext, useContext, type ReactNode } from 'react'\nimport type { PaymentProvider } from '@fayz-ai/core'\n\nexport interface PaymentContextValue {\n provider: PaymentProvider\n}\n\nconst PaymentContext = createContext<PaymentContextValue | null>(null)\n\nexport function PaymentProviderContext({ value, children }: { value: PaymentContextValue; children: ReactNode }) {\n return <PaymentContext.Provider value={value}>{children}</PaymentContext.Provider>\n}\n\nexport function usePaymentContext(): PaymentContextValue {\n const ctx = useContext(PaymentContext)\n if (!ctx) {\n throw new Error('[plugin-payments] usePaymentContext must be used within the payments Provider.')\n }\n return ctx\n}\n","import { createElement, type FC, type ReactNode } from 'react'\nimport type { PluginManifest, PluginScope, PaymentProvider } from '@fayz-ai/core'\nimport { createMockPaymentProvider, type MockPaymentOptions } from '../data/mock'\nimport { PaymentProviderContext, type PaymentContextValue } from './context'\n\n// ---------------------------------------------------------------------------\n// @fayz-ai/plugin-payments/public — website payment surface.\n//\n// Returns a { manifest, Provider, paymentProvider } bundle mirroring the other\n// website plugins. The host injects `paymentProvider` into the booking plugin;\n// the Provider/hooks are for a future standalone checkout page. No routes — a\n// payment is a service, not a screen.\n// ---------------------------------------------------------------------------\n\nexport interface PublicPaymentOptions {\n /** Currency for charges (informational; charges carry their own). */\n currency?: string\n /** Inject a custom provider (real gateway). Overrides the safe resolver. */\n paymentProvider?: PaymentProvider\n /** Tuning for the mock provider (auto-pay/expiry) when no real provider is set. */\n mock?: MockPaymentOptions\n scope?: PluginScope\n}\n\nexport interface PublicPaymentPlugin {\n manifest: PluginManifest\n Provider: FC<{ children: ReactNode }>\n paymentProvider: PaymentProvider\n}\n\nexport function createPublicPaymentPlugin(options?: PublicPaymentOptions): PublicPaymentPlugin {\n // Default is the MOCK provider even when a Supabase client is configured:\n // the Supabase payment path is still a stub (real gateway = MercadoPago edge\n // fn, deferred), so a real provider must be injected explicitly via\n // `paymentProvider`. Don't route through createSafePaymentProvider here or\n // any app with a configured Supabase client would hit the throwing stub.\n const paymentProvider = options?.paymentProvider ?? createMockPaymentProvider(options?.mock)\n\n const value: PaymentContextValue = { provider: paymentProvider }\n const Provider: FC<{ children: ReactNode }> = ({ children }) =>\n createElement(PaymentProviderContext, { value, children })\n Provider.displayName = 'PaymentPluginProvider'\n\n const manifest: PluginManifest = {\n id: 'payments',\n name: 'Pagamentos',\n icon: 'CreditCard',\n version: '0.1.0',\n scope: options?.scope ?? 'universal',\n scaffolds: ['website', 'landing_page'],\n defaultEnabled: true,\n dependencies: [],\n navigation: [],\n routes: [],\n widgets: [],\n }\n\n return { manifest, Provider, paymentProvider }\n}\n","import { useCallback, useEffect, useRef, useState } from 'react'\nimport type { CreateChargeInput, PixCharge, ChargeStatus } from '@fayz-ai/core'\nimport { usePaymentContext } from '../context'\n\nexport interface UsePixChargeResult {\n charge: PixCharge | null\n creating: boolean\n error: Error | null\n create: (input: CreateChargeInput) => Promise<PixCharge | null>\n reset: () => void\n}\n\n/**\n * Create a Pix charge on demand. For a standalone checkout page; the booking\n * widget uses its own injected provider directly (agenda depends only on core).\n */\nexport function usePixCharge(): UsePixChargeResult {\n const { provider } = usePaymentContext()\n const [charge, setCharge] = useState<PixCharge | null>(null)\n const [creating, setCreating] = useState(false)\n const [error, setError] = useState<Error | null>(null)\n\n const create = useCallback(\n async (input: CreateChargeInput) => {\n setCreating(true)\n setError(null)\n try {\n const c = await provider.createCharge(input)\n setCharge(c)\n return c\n } catch (err) {\n setError(err instanceof Error ? err : new Error(String(err)))\n return null\n } finally {\n setCreating(false)\n }\n },\n [provider],\n )\n\n const reset = useCallback(() => {\n setCharge(null)\n setError(null)\n }, [])\n\n return { charge, creating, error, create, reset }\n}\n\n/**\n * Poll a charge's status until it settles. Cleans the interval on unmount,\n * chargeId change, and terminal states.\n */\nexport function useChargeStatus(chargeId: string | null, intervalMs = 2500): ChargeStatus | null {\n const { provider } = usePaymentContext()\n const [status, setStatus] = useState<ChargeStatus | null>(null)\n const timer = useRef<ReturnType<typeof setInterval> | null>(null)\n\n useEffect(() => {\n let active = true\n setStatus(null)\n if (!chargeId) return\n\n const clear = () => {\n if (timer.current) { clearInterval(timer.current); timer.current = null }\n }\n const tick = () => {\n provider\n .getChargeStatus(chargeId)\n .then((s) => {\n if (!active) return\n setStatus(s)\n if (s === 'paid' || s === 'expired' || s === 'failed') clear()\n })\n .catch(() => { /* keep polling on transient errors */ })\n }\n tick()\n timer.current = setInterval(tick, intervalMs)\n return () => { active = false; clear() }\n }, [provider, chargeId, intervalMs])\n\n return status\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fayz-ai/plugin-payments",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "[experimental] Fayz SDK — payments plugin (Pix charge provider + website surface)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -9,26 +9,23 @@
|
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"source": "./src/index.ts",
|
|
13
12
|
"types": "./dist/index.d.ts",
|
|
14
13
|
"import": "./dist/index.js"
|
|
15
14
|
},
|
|
16
15
|
"./public": {
|
|
17
|
-
"source": "./src/public/index.ts",
|
|
18
16
|
"types": "./dist/public/index.d.ts",
|
|
19
17
|
"import": "./dist/public/index.js"
|
|
20
18
|
}
|
|
21
19
|
},
|
|
22
20
|
"files": [
|
|
23
|
-
"dist"
|
|
24
|
-
"src"
|
|
21
|
+
"dist"
|
|
25
22
|
],
|
|
26
23
|
"peerDependencies": {
|
|
27
24
|
"react": "^18.0.0 || ^19.0.0",
|
|
28
25
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
29
26
|
},
|
|
30
27
|
"dependencies": {
|
|
31
|
-
"@fayz-ai/core": "^0.
|
|
28
|
+
"@fayz-ai/core": "^0.11.0"
|
|
32
29
|
},
|
|
33
30
|
"devDependencies": {
|
|
34
31
|
"@types/react": "^18.3.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/public/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAG/E,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAA;IACxB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;IAC/D,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,kBAAkB,CA8BjD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,UAAU,SAAO,GAAG,YAAY,GAAG,IAAI,CA6B/F"}
|
package/src/data/index.ts
DELETED
package/src/data/mock.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { PaymentProvider, CreateChargeInput, PixCharge, ChargeStatus } from '@fayz-ai/core'
|
|
2
|
-
|
|
3
|
-
/** Mock provider adds a demo-only `markPaid` shortcut on top of the contract. */
|
|
4
|
-
export interface MockPaymentProvider extends PaymentProvider {
|
|
5
|
-
/** Force a charge to 'paid' immediately (demo "Já paguei" button). */
|
|
6
|
-
markPaid(chargeId: string): void
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface MockPaymentOptions {
|
|
10
|
-
/** Auto-confirm a pending charge after this many ms (simulates the gateway webhook). Default 6000. */
|
|
11
|
-
autoPayAfterMs?: number
|
|
12
|
-
/** Charge validity window in ms. Default 5 min. */
|
|
13
|
-
expiresAfterMs?: number
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface ChargeRecord {
|
|
17
|
-
charge: PixCharge
|
|
18
|
-
createdAt: number
|
|
19
|
-
autoPayAt: number
|
|
20
|
-
expiresAt: number
|
|
21
|
-
paid: boolean
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let seq = 0
|
|
25
|
-
|
|
26
|
-
/** Build a realistic-looking (non-functional) Pix BR Code "copia e cola". */
|
|
27
|
-
function buildBrCode(amount: number, chargeId: string): string {
|
|
28
|
-
const amt = amount.toFixed(2)
|
|
29
|
-
// Simplified EMV-ish layout — enough to look/scan like a Pix payload in the POC.
|
|
30
|
-
return (
|
|
31
|
-
`00020126850014br.gov.bcb.pix2563qrcode.fayz.dev/pix/v2/${chargeId}` +
|
|
32
|
-
`520400005303986540${amt.length}${amt}5802BR5913HEMPDENT6009SAO PAULO62070503***6304FZ${(seq % 90 + 10)}`
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function createMockPaymentProvider(options?: MockPaymentOptions): MockPaymentProvider {
|
|
37
|
-
const autoPayAfterMs = options?.autoPayAfterMs ?? 6000
|
|
38
|
-
const expiresAfterMs = options?.expiresAfterMs ?? 5 * 60_000
|
|
39
|
-
const charges = new Map<string, ChargeRecord>()
|
|
40
|
-
|
|
41
|
-
function statusOf(rec: ChargeRecord): ChargeStatus {
|
|
42
|
-
if (rec.paid) return 'paid'
|
|
43
|
-
const now = Date.now()
|
|
44
|
-
if (now >= rec.autoPayAt) return 'paid'
|
|
45
|
-
if (now >= rec.expiresAt) return 'expired'
|
|
46
|
-
return 'pending'
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
async createCharge(input: CreateChargeInput): Promise<PixCharge> {
|
|
51
|
-
const now = Date.now()
|
|
52
|
-
const chargeId = `mockpix-${++seq}-${input.orderId ?? 'na'}`
|
|
53
|
-
const brCode = buildBrCode(input.amount, chargeId)
|
|
54
|
-
const charge: PixCharge = {
|
|
55
|
-
chargeId,
|
|
56
|
-
status: 'pending',
|
|
57
|
-
amount: input.amount,
|
|
58
|
-
currency: input.currency,
|
|
59
|
-
pixQrCode: brCode,
|
|
60
|
-
pixCopyPaste: brCode,
|
|
61
|
-
expiresAt: new Date(now + expiresAfterMs).toISOString(),
|
|
62
|
-
}
|
|
63
|
-
charges.set(chargeId, {
|
|
64
|
-
charge,
|
|
65
|
-
createdAt: now,
|
|
66
|
-
autoPayAt: now + autoPayAfterMs,
|
|
67
|
-
expiresAt: now + expiresAfterMs,
|
|
68
|
-
paid: false,
|
|
69
|
-
})
|
|
70
|
-
return charge
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
async getChargeStatus(chargeId: string): Promise<ChargeStatus> {
|
|
74
|
-
const rec = charges.get(chargeId)
|
|
75
|
-
if (!rec) return 'failed'
|
|
76
|
-
return statusOf(rec)
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
markPaid(chargeId: string): void {
|
|
80
|
-
const rec = charges.get(chargeId)
|
|
81
|
-
if (rec) rec.paid = true
|
|
82
|
-
},
|
|
83
|
-
}
|
|
84
|
-
}
|
package/src/data/supabase.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { PaymentProvider, CreateChargeInput, PixCharge, ChargeStatus } from '@fayz-ai/core'
|
|
2
|
-
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// Supabase/gateway-backed payment provider — STUB (deferred).
|
|
5
|
-
//
|
|
6
|
-
// Later: a real MercadoPago (or other PSP) Pix integration via a Supabase edge
|
|
7
|
-
// function (credentials server-side; actions create_charge | get_status |
|
|
8
|
-
// webhook), mirroring the plugbank-sync edge function. Swapping this in is a
|
|
9
|
-
// pure provider change — the booking widget and hooks are untouched because they
|
|
10
|
-
// depend only on the core PaymentProvider interface.
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
export function createSupabasePaymentProvider(): PaymentProvider {
|
|
14
|
-
const notImplemented = (): never => {
|
|
15
|
-
throw new Error(
|
|
16
|
-
'[plugin-payments] Supabase/MercadoPago provider not implemented yet — deferred. ' +
|
|
17
|
-
'Run on the mock provider (no gateway configured) for now.',
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
createCharge: (_input: CreateChargeInput): Promise<PixCharge> => notImplemented(),
|
|
22
|
-
getChargeStatus: (_chargeId: string): Promise<ChargeStatus> => notImplemented(),
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { createSafeDataProvider } from '@fayz-ai/core'
|
|
2
|
-
import type { PaymentProvider } from '@fayz-ai/core'
|
|
3
|
-
import { createMockPaymentProvider, type MockPaymentOptions } from './data/mock'
|
|
4
|
-
import { createSupabasePaymentProvider } from './data/supabase'
|
|
5
|
-
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
// @fayz-ai/plugin-payments — gateway-agnostic charge provider (Pix today).
|
|
8
|
-
// Bookkeeping (invoices/movements/reconciliation) stays in plugin-financial;
|
|
9
|
-
// this plugin OWNS money-in initiation (create a charge → payable artifacts →
|
|
10
|
-
// status). Mirrors createSafeFinancialProvider.
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
/** Supabase/gateway when configured, else the mock provider. */
|
|
14
|
-
export function createSafePaymentProvider(mockOptions?: MockPaymentOptions): PaymentProvider {
|
|
15
|
-
return createSafeDataProvider(
|
|
16
|
-
() => createSupabasePaymentProvider(),
|
|
17
|
-
() => createMockPaymentProvider(mockOptions),
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { createMockPaymentProvider, createSupabasePaymentProvider } from './data'
|
|
22
|
-
export type { MockPaymentProvider, MockPaymentOptions } from './data'
|
|
23
|
-
export type {
|
|
24
|
-
PaymentProvider, PaymentMethod, ChargeStatus, CreateChargeInput, PixCharge,
|
|
25
|
-
} from '@fayz-ai/core'
|
package/src/public/context.tsx
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext, type ReactNode } from 'react'
|
|
2
|
-
import type { PaymentProvider } from '@fayz-ai/core'
|
|
3
|
-
|
|
4
|
-
export interface PaymentContextValue {
|
|
5
|
-
provider: PaymentProvider
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const PaymentContext = createContext<PaymentContextValue | null>(null)
|
|
9
|
-
|
|
10
|
-
export function PaymentProviderContext({ value, children }: { value: PaymentContextValue; children: ReactNode }) {
|
|
11
|
-
return <PaymentContext.Provider value={value}>{children}</PaymentContext.Provider>
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function usePaymentContext(): PaymentContextValue {
|
|
15
|
-
const ctx = useContext(PaymentContext)
|
|
16
|
-
if (!ctx) {
|
|
17
|
-
throw new Error('[plugin-payments] usePaymentContext must be used within the payments Provider.')
|
|
18
|
-
}
|
|
19
|
-
return ctx
|
|
20
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { createElement, type FC, type ReactNode } from 'react'
|
|
2
|
-
import type { PluginManifest, PluginScope, PaymentProvider } from '@fayz-ai/core'
|
|
3
|
-
import { createMockPaymentProvider, type MockPaymentOptions } from '../data/mock'
|
|
4
|
-
import { PaymentProviderContext, type PaymentContextValue } from './context'
|
|
5
|
-
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
// @fayz-ai/plugin-payments/public — website payment surface.
|
|
8
|
-
//
|
|
9
|
-
// Returns a { manifest, Provider, paymentProvider } bundle mirroring the other
|
|
10
|
-
// website plugins. The host injects `paymentProvider` into the booking plugin;
|
|
11
|
-
// the Provider/hooks are for a future standalone checkout page. No routes — a
|
|
12
|
-
// payment is a service, not a screen.
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
|
|
15
|
-
export interface PublicPaymentOptions {
|
|
16
|
-
/** Currency for charges (informational; charges carry their own). */
|
|
17
|
-
currency?: string
|
|
18
|
-
/** Inject a custom provider (real gateway). Overrides the safe resolver. */
|
|
19
|
-
paymentProvider?: PaymentProvider
|
|
20
|
-
/** Tuning for the mock provider (auto-pay/expiry) when no real provider is set. */
|
|
21
|
-
mock?: MockPaymentOptions
|
|
22
|
-
scope?: PluginScope
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface PublicPaymentPlugin {
|
|
26
|
-
manifest: PluginManifest
|
|
27
|
-
Provider: FC<{ children: ReactNode }>
|
|
28
|
-
paymentProvider: PaymentProvider
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function createPublicPaymentPlugin(options?: PublicPaymentOptions): PublicPaymentPlugin {
|
|
32
|
-
// Default is the MOCK provider even when a Supabase client is configured:
|
|
33
|
-
// the Supabase payment path is still a stub (real gateway = MercadoPago edge
|
|
34
|
-
// fn, deferred), so a real provider must be injected explicitly via
|
|
35
|
-
// `paymentProvider`. Don't route through createSafePaymentProvider here or
|
|
36
|
-
// any app with a configured Supabase client would hit the throwing stub.
|
|
37
|
-
const paymentProvider = options?.paymentProvider ?? createMockPaymentProvider(options?.mock)
|
|
38
|
-
|
|
39
|
-
const value: PaymentContextValue = { provider: paymentProvider }
|
|
40
|
-
const Provider: FC<{ children: ReactNode }> = ({ children }) =>
|
|
41
|
-
createElement(PaymentProviderContext, { value, children })
|
|
42
|
-
Provider.displayName = 'PaymentPluginProvider'
|
|
43
|
-
|
|
44
|
-
const manifest: PluginManifest = {
|
|
45
|
-
id: 'payments',
|
|
46
|
-
name: 'Pagamentos',
|
|
47
|
-
icon: 'CreditCard',
|
|
48
|
-
version: '0.1.0',
|
|
49
|
-
scope: options?.scope ?? 'universal',
|
|
50
|
-
scaffolds: ['website', 'landing_page'],
|
|
51
|
-
defaultEnabled: true,
|
|
52
|
-
dependencies: [],
|
|
53
|
-
navigation: [],
|
|
54
|
-
routes: [],
|
|
55
|
-
widgets: [],
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return { manifest, Provider, paymentProvider }
|
|
59
|
-
}
|
package/src/public/hooks.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
2
|
-
import type { CreateChargeInput, PixCharge, ChargeStatus } from '@fayz-ai/core'
|
|
3
|
-
import { usePaymentContext } from './context'
|
|
4
|
-
|
|
5
|
-
export interface UsePixChargeResult {
|
|
6
|
-
charge: PixCharge | null
|
|
7
|
-
creating: boolean
|
|
8
|
-
error: Error | null
|
|
9
|
-
create: (input: CreateChargeInput) => Promise<PixCharge | null>
|
|
10
|
-
reset: () => void
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Create a Pix charge on demand. For a standalone checkout page; the booking
|
|
15
|
-
* widget uses its own injected provider directly (agenda depends only on core).
|
|
16
|
-
*/
|
|
17
|
-
export function usePixCharge(): UsePixChargeResult {
|
|
18
|
-
const { provider } = usePaymentContext()
|
|
19
|
-
const [charge, setCharge] = useState<PixCharge | null>(null)
|
|
20
|
-
const [creating, setCreating] = useState(false)
|
|
21
|
-
const [error, setError] = useState<Error | null>(null)
|
|
22
|
-
|
|
23
|
-
const create = useCallback(
|
|
24
|
-
async (input: CreateChargeInput) => {
|
|
25
|
-
setCreating(true)
|
|
26
|
-
setError(null)
|
|
27
|
-
try {
|
|
28
|
-
const c = await provider.createCharge(input)
|
|
29
|
-
setCharge(c)
|
|
30
|
-
return c
|
|
31
|
-
} catch (err) {
|
|
32
|
-
setError(err instanceof Error ? err : new Error(String(err)))
|
|
33
|
-
return null
|
|
34
|
-
} finally {
|
|
35
|
-
setCreating(false)
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
[provider],
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
const reset = useCallback(() => {
|
|
42
|
-
setCharge(null)
|
|
43
|
-
setError(null)
|
|
44
|
-
}, [])
|
|
45
|
-
|
|
46
|
-
return { charge, creating, error, create, reset }
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Poll a charge's status until it settles. Cleans the interval on unmount,
|
|
51
|
-
* chargeId change, and terminal states.
|
|
52
|
-
*/
|
|
53
|
-
export function useChargeStatus(chargeId: string | null, intervalMs = 2500): ChargeStatus | null {
|
|
54
|
-
const { provider } = usePaymentContext()
|
|
55
|
-
const [status, setStatus] = useState<ChargeStatus | null>(null)
|
|
56
|
-
const timer = useRef<ReturnType<typeof setInterval> | null>(null)
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
let active = true
|
|
60
|
-
setStatus(null)
|
|
61
|
-
if (!chargeId) return
|
|
62
|
-
|
|
63
|
-
const clear = () => {
|
|
64
|
-
if (timer.current) { clearInterval(timer.current); timer.current = null }
|
|
65
|
-
}
|
|
66
|
-
const tick = () => {
|
|
67
|
-
provider
|
|
68
|
-
.getChargeStatus(chargeId)
|
|
69
|
-
.then((s) => {
|
|
70
|
-
if (!active) return
|
|
71
|
-
setStatus(s)
|
|
72
|
-
if (s === 'paid' || s === 'expired' || s === 'failed') clear()
|
|
73
|
-
})
|
|
74
|
-
.catch(() => { /* keep polling on transient errors */ })
|
|
75
|
-
}
|
|
76
|
-
tick()
|
|
77
|
-
timer.current = setInterval(tick, intervalMs)
|
|
78
|
-
return () => { active = false; clear() }
|
|
79
|
-
}, [provider, chargeId, intervalMs])
|
|
80
|
-
|
|
81
|
-
return status
|
|
82
|
-
}
|
package/src/public/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { createPublicPaymentPlugin } from './createPublicPaymentPlugin'
|
|
2
|
-
export type { PublicPaymentOptions, PublicPaymentPlugin } from './createPublicPaymentPlugin'
|
|
3
|
-
export { PaymentProviderContext, usePaymentContext } from './context'
|
|
4
|
-
export type { PaymentContextValue } from './context'
|
|
5
|
-
export { usePixCharge, useChargeStatus } from './hooks'
|
|
6
|
-
export type { UsePixChargeResult } from './hooks'
|
|
7
|
-
export { createSafePaymentProvider, createMockPaymentProvider } from '../index'
|
|
8
|
-
export type {
|
|
9
|
-
PaymentProvider, ChargeStatus, CreateChargeInput, PixCharge, MockPaymentProvider, MockPaymentOptions,
|
|
10
|
-
} from '../index'
|