@paytree/medusa-payment-paytree 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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +195 -0
  3. package/dist/index.d.ts +28 -0
  4. package/dist/index.js +55 -0
  5. package/dist/modules/paytree/index.d.ts +36 -0
  6. package/dist/modules/paytree/index.js +13 -0
  7. package/dist/modules/paytree/migrations/Migration20260617000000.d.ts +5 -0
  8. package/dist/modules/paytree/migrations/Migration20260617000000.js +54 -0
  9. package/dist/modules/paytree/migrations/Migration20260618000000.d.ts +5 -0
  10. package/dist/modules/paytree/migrations/Migration20260618000000.js +19 -0
  11. package/dist/modules/paytree/models/paytree-event-log.d.ts +25 -0
  12. package/dist/modules/paytree/models/paytree-event-log.js +29 -0
  13. package/dist/modules/paytree/models/paytree-setting.d.ts +23 -0
  14. package/dist/modules/paytree/models/paytree-setting.js +27 -0
  15. package/dist/modules/paytree/service.d.ts +60 -0
  16. package/dist/modules/paytree/service.js +47 -0
  17. package/dist/modules/paytree-payment/index.d.ts +8 -0
  18. package/dist/modules/paytree-payment/index.js +16 -0
  19. package/dist/modules/paytree-payment/lib/amount.d.ts +23 -0
  20. package/dist/modules/paytree-payment/lib/amount.js +40 -0
  21. package/dist/modules/paytree-payment/lib/audit.d.ts +26 -0
  22. package/dist/modules/paytree-payment/lib/audit.js +51 -0
  23. package/dist/modules/paytree-payment/lib/client.d.ts +28 -0
  24. package/dist/modules/paytree-payment/lib/client.js +81 -0
  25. package/dist/modules/paytree-payment/lib/constants.d.ts +54 -0
  26. package/dist/modules/paytree-payment/lib/constants.js +55 -0
  27. package/dist/modules/paytree-payment/lib/logger.d.ts +27 -0
  28. package/dist/modules/paytree-payment/lib/logger.js +73 -0
  29. package/dist/modules/paytree-payment/lib/methods.d.ts +69 -0
  30. package/dist/modules/paytree-payment/lib/methods.js +68 -0
  31. package/dist/modules/paytree-payment/lib/redact.d.ts +16 -0
  32. package/dist/modules/paytree-payment/lib/redact.js +60 -0
  33. package/dist/modules/paytree-payment/lib/settings-reader.d.ts +24 -0
  34. package/dist/modules/paytree-payment/lib/settings-reader.js +74 -0
  35. package/dist/modules/paytree-payment/lib/status-map.d.ts +26 -0
  36. package/dist/modules/paytree-payment/lib/status-map.js +66 -0
  37. package/dist/modules/paytree-payment/lib/types.d.ts +144 -0
  38. package/dist/modules/paytree-payment/lib/types.js +2 -0
  39. package/dist/modules/paytree-payment/service.d.ts +36 -0
  40. package/dist/modules/paytree-payment/service.js +369 -0
  41. package/docs/api-reference.md +121 -0
  42. package/docs/architecture.md +97 -0
  43. package/docs/configuration.md +62 -0
  44. package/docs/getting-started.md +111 -0
  45. package/docs/storefront-integration.md +85 -0
  46. package/integration/README.md +46 -0
  47. package/integration/admin/routes/paytree/api.ts +16 -0
  48. package/integration/admin/routes/paytree/method-icons.tsx +106 -0
  49. package/integration/admin/routes/paytree/page.tsx +18 -0
  50. package/integration/admin/routes/paytree/payments/page.tsx +240 -0
  51. package/integration/admin/routes/paytree/settings/page.tsx +214 -0
  52. package/integration/api/admin/paytree/events/route.ts +35 -0
  53. package/integration/api/admin/paytree/settings/route.ts +86 -0
  54. package/integration/api/hooks/paytree/route.ts +195 -0
  55. package/integration/api/store/paytree/methods/route.ts +28 -0
  56. package/package.json +57 -0
  57. package/storefront/README.md +25 -0
  58. package/storefront/components/payment-button.tsx +361 -0
  59. package/storefront/components/payment.tsx +356 -0
  60. package/storefront/components/paytree-method-icon.tsx +106 -0
  61. package/storefront/lib/paytree.ts +23 -0
@@ -0,0 +1,106 @@
1
+ import React from "react"
2
+
3
+ /**
4
+ * SVG icons for each Paytree method shown in the storefront method picker.
5
+ * Generic rails (card, bank transfer, crypto) use line glyphs that inherit the
6
+ * surrounding text color; brand methods use a small colored badge so the set
7
+ * stays consistent and recognizable.
8
+ */
9
+
10
+ type Badge = { bg: string; fg: string; text: string; size?: number }
11
+
12
+ const BADGES: Record<string, Badge> = {
13
+ paypal: { bg: "#003087", fg: "#ffffff", text: "PP" },
14
+ klarna: { bg: "#FFB3C7", fg: "#0A0A0A", text: "K." },
15
+ ideal: { bg: "#CD0067", fg: "#ffffff", text: "iD" },
16
+ bancontact: { bg: "#005498", fg: "#FFD800", text: "BC" },
17
+ trustly: { bg: "#0EE06E", fg: "#0A0A0A", text: "T" },
18
+ kakaopay: { bg: "#FFCD00", fg: "#3C1E1E", text: "pay", size: 7 },
19
+ p24: { bg: "#D3132B", fg: "#ffffff", text: "P24", size: 7 },
20
+ blik: { bg: "#000000", fg: "#E61E2A", text: "blik", size: 6 },
21
+ }
22
+
23
+ const BadgeIcon = ({ bg, fg, text, size = 9 }: Badge) => (
24
+ <svg width="28" height="28" viewBox="0 0 24 24" aria-hidden="true">
25
+ <rect x="1" y="4" width="22" height="16" rx="3" fill={bg} />
26
+ <text
27
+ x="12"
28
+ y="12.5"
29
+ fill={fg}
30
+ fontSize={size}
31
+ fontWeight="700"
32
+ fontFamily="Inter, system-ui, sans-serif"
33
+ textAnchor="middle"
34
+ dominantBaseline="central"
35
+ >
36
+ {text}
37
+ </text>
38
+ </svg>
39
+ )
40
+
41
+ const CardIcon = () => (
42
+ <svg width="28" height="28" viewBox="0 0 24 24" fill="none" aria-hidden="true">
43
+ <rect
44
+ x="2"
45
+ y="5"
46
+ width="20"
47
+ height="14"
48
+ rx="2.5"
49
+ stroke="currentColor"
50
+ strokeWidth="1.6"
51
+ />
52
+ <path d="M2 9.5h20" stroke="currentColor" strokeWidth="1.6" />
53
+ <path
54
+ d="M5.5 15.5h4"
55
+ stroke="currentColor"
56
+ strokeWidth="1.6"
57
+ strokeLinecap="round"
58
+ />
59
+ </svg>
60
+ )
61
+
62
+ const BankIcon = () => (
63
+ <svg width="28" height="28" viewBox="0 0 24 24" fill="none" aria-hidden="true">
64
+ <path
65
+ d="M12 3 3 7.5h18L12 3Z"
66
+ stroke="currentColor"
67
+ strokeWidth="1.5"
68
+ strokeLinejoin="round"
69
+ />
70
+ <path
71
+ d="M5 10v6M9.3 10v6M14.7 10v6M19 10v6M3 19.5h18"
72
+ stroke="currentColor"
73
+ strokeWidth="1.5"
74
+ strokeLinecap="round"
75
+ />
76
+ </svg>
77
+ )
78
+
79
+ const CryptoIcon = () => (
80
+ <svg width="28" height="28" viewBox="0 0 24 24" aria-hidden="true">
81
+ <circle cx="12" cy="12" r="9.2" fill="#F7931A" />
82
+ <text
83
+ x="12"
84
+ y="12.5"
85
+ fill="#ffffff"
86
+ fontSize="11"
87
+ fontWeight="700"
88
+ fontFamily="Inter, system-ui, sans-serif"
89
+ textAnchor="middle"
90
+ dominantBaseline="central"
91
+ >
92
+
93
+ </text>
94
+ </svg>
95
+ )
96
+
97
+ const PaytreeMethodIcon = ({ method }: { method: string }) => {
98
+ if (method === "card") return <CardIcon />
99
+ if (method === "wire") return <BankIcon />
100
+ if (method === "crypto") return <CryptoIcon />
101
+ const badge = BADGES[method]
102
+ if (badge) return <BadgeIcon {...badge} />
103
+ return <CardIcon />
104
+ }
105
+
106
+ export default PaytreeMethodIcon
@@ -0,0 +1,23 @@
1
+ "use server"
2
+
3
+ import { sdk } from "@lib/config"
4
+
5
+ type PaytreeMethod = {
6
+ method: string
7
+ label: string
8
+ }
9
+
10
+ /**
11
+ * Fetch the Paytree methods the admin has enabled, with their (possibly
12
+ * overridden) labels. Returns [] if Paytree isn't configured or the request
13
+ * fails, so the checkout can degrade gracefully.
14
+ */
15
+ export async function listPaytreeMethods(): Promise<PaytreeMethod[]> {
16
+ return sdk.client
17
+ .fetch<{ methods: PaytreeMethod[] }>("/store/paytree/methods", {
18
+ method: "GET",
19
+ next: { tags: ["paytree-methods"], revalidate: 60 },
20
+ })
21
+ .then((res) => res.methods ?? [])
22
+ .catch(() => [])
23
+ }