@easypayment/medusa-paypal 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 (272) hide show
  1. package/.medusa/server/src/admin/index.js +2127 -0
  2. package/.medusa/server/src/admin/index.mjs +2128 -0
  3. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts +3 -0
  4. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -0
  5. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js +25 -0
  6. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js.map +1 -0
  7. package/.medusa/server/src/api/admin/paypal/audit-logs/route.d.ts +3 -0
  8. package/.medusa/server/src/api/admin/paypal/audit-logs/route.d.ts.map +1 -0
  9. package/.medusa/server/src/api/admin/paypal/audit-logs/route.js +12 -0
  10. package/.medusa/server/src/api/admin/paypal/audit-logs/route.js.map +1 -0
  11. package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts +3 -0
  12. package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts.map +1 -0
  13. package/.medusa/server/src/api/admin/paypal/disconnect/route.js +9 -0
  14. package/.medusa/server/src/api/admin/paypal/disconnect/route.js.map +1 -0
  15. package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.d.ts +3 -0
  16. package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.d.ts.map +1 -0
  17. package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.js +17 -0
  18. package/.medusa/server/src/api/admin/paypal/disputes/[id]/route.js.map +1 -0
  19. package/.medusa/server/src/api/admin/paypal/disputes/route.d.ts +3 -0
  20. package/.medusa/server/src/api/admin/paypal/disputes/route.d.ts.map +1 -0
  21. package/.medusa/server/src/api/admin/paypal/disputes/route.js +27 -0
  22. package/.medusa/server/src/api/admin/paypal/disputes/route.js.map +1 -0
  23. package/.medusa/server/src/api/admin/paypal/disputes/summary/route.d.ts +3 -0
  24. package/.medusa/server/src/api/admin/paypal/disputes/summary/route.d.ts.map +1 -0
  25. package/.medusa/server/src/api/admin/paypal/disputes/summary/route.js +17 -0
  26. package/.medusa/server/src/api/admin/paypal/disputes/summary/route.js.map +1 -0
  27. package/.medusa/server/src/api/admin/paypal/environment/route.d.ts +4 -0
  28. package/.medusa/server/src/api/admin/paypal/environment/route.d.ts.map +1 -0
  29. package/.medusa/server/src/api/admin/paypal/environment/route.js +23 -0
  30. package/.medusa/server/src/api/admin/paypal/environment/route.js.map +1 -0
  31. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts +8 -0
  32. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts.map +1 -0
  33. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js +41 -0
  34. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js.map +1 -0
  35. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts +4 -0
  36. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts.map +1 -0
  37. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js +35 -0
  38. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js.map +1 -0
  39. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts +3 -0
  40. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts.map +1 -0
  41. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js +20 -0
  42. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js.map +1 -0
  43. package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.d.ts +3 -0
  44. package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.d.ts.map +1 -0
  45. package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.js +8 -0
  46. package/.medusa/server/src/api/admin/paypal/reconciliation-status/route.js.map +1 -0
  47. package/.medusa/server/src/api/admin/paypal/rotate-credentials/route.d.ts +3 -0
  48. package/.medusa/server/src/api/admin/paypal/rotate-credentials/route.d.ts.map +1 -0
  49. package/.medusa/server/src/api/admin/paypal/rotate-credentials/route.js +9 -0
  50. package/.medusa/server/src/api/admin/paypal/rotate-credentials/route.js.map +1 -0
  51. package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts +3 -0
  52. package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts.map +1 -0
  53. package/.medusa/server/src/api/admin/paypal/save-credentials/route.js +13 -0
  54. package/.medusa/server/src/api/admin/paypal/save-credentials/route.js.map +1 -0
  55. package/.medusa/server/src/api/admin/paypal/settings/route.d.ts +4 -0
  56. package/.medusa/server/src/api/admin/paypal/settings/route.d.ts.map +1 -0
  57. package/.medusa/server/src/api/admin/paypal/settings/route.js +14 -0
  58. package/.medusa/server/src/api/admin/paypal/settings/route.js.map +1 -0
  59. package/.medusa/server/src/api/admin/paypal/status/route.d.ts +3 -0
  60. package/.medusa/server/src/api/admin/paypal/status/route.d.ts.map +1 -0
  61. package/.medusa/server/src/api/admin/paypal/status/route.js +11 -0
  62. package/.medusa/server/src/api/admin/paypal/status/route.js.map +1 -0
  63. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts +3 -0
  64. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -0
  65. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js +43 -0
  66. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js.map +1 -0
  67. package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts +3 -0
  68. package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -0
  69. package/.medusa/server/src/api/store/paypal/capture-order/route.js +215 -0
  70. package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -0
  71. package/.medusa/server/src/api/store/paypal/config/route.d.ts +3 -0
  72. package/.medusa/server/src/api/store/paypal/config/route.d.ts.map +1 -0
  73. package/.medusa/server/src/api/store/paypal/config/route.js +45 -0
  74. package/.medusa/server/src/api/store/paypal/config/route.js.map +1 -0
  75. package/.medusa/server/src/api/store/paypal/create-order/route.d.ts +3 -0
  76. package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -0
  77. package/.medusa/server/src/api/store/paypal/create-order/route.js +305 -0
  78. package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -0
  79. package/.medusa/server/src/api/store/paypal/disputes/route.d.ts +3 -0
  80. package/.medusa/server/src/api/store/paypal/disputes/route.d.ts.map +1 -0
  81. package/.medusa/server/src/api/store/paypal/disputes/route.js +46 -0
  82. package/.medusa/server/src/api/store/paypal/disputes/route.js.map +1 -0
  83. package/.medusa/server/src/api/store/paypal/settings/route.d.ts +3 -0
  84. package/.medusa/server/src/api/store/paypal/settings/route.d.ts.map +1 -0
  85. package/.medusa/server/src/api/store/paypal/settings/route.js +14 -0
  86. package/.medusa/server/src/api/store/paypal/settings/route.js.map +1 -0
  87. package/.medusa/server/src/api/store/paypal/webhook/route.d.ts +3 -0
  88. package/.medusa/server/src/api/store/paypal/webhook/route.d.ts.map +1 -0
  89. package/.medusa/server/src/api/store/paypal/webhook/route.js +203 -0
  90. package/.medusa/server/src/api/store/paypal/webhook/route.js.map +1 -0
  91. package/.medusa/server/src/jobs/paypal-reconcile.d.ts +7 -0
  92. package/.medusa/server/src/jobs/paypal-reconcile.d.ts.map +1 -0
  93. package/.medusa/server/src/jobs/paypal-reconcile.js +131 -0
  94. package/.medusa/server/src/jobs/paypal-reconcile.js.map +1 -0
  95. package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts +7 -0
  96. package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -0
  97. package/.medusa/server/src/jobs/paypal-webhook-retry.js +78 -0
  98. package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -0
  99. package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.d.ts +14 -0
  100. package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.d.ts.map +1 -0
  101. package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js +65 -0
  102. package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js.map +1 -0
  103. package/.medusa/server/src/modules/paypal/index.d.ts +92 -0
  104. package/.medusa/server/src/modules/paypal/index.d.ts.map +1 -0
  105. package/.medusa/server/src/modules/paypal/index.js +13 -0
  106. package/.medusa/server/src/modules/paypal/index.js.map +1 -0
  107. package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.d.ts +6 -0
  108. package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.d.ts.map +1 -0
  109. package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.js +36 -0
  110. package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.js.map +1 -0
  111. package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.d.ts +6 -0
  112. package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.d.ts.map +1 -0
  113. package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.js +25 -0
  114. package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.js.map +1 -0
  115. package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.d.ts +6 -0
  116. package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.d.ts.map +1 -0
  117. package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.js +32 -0
  118. package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.js.map +1 -0
  119. package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.d.ts +6 -0
  120. package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.d.ts.map +1 -0
  121. package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.js +29 -0
  122. package/.medusa/server/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.js.map +1 -0
  123. package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.d.ts +6 -0
  124. package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.d.ts.map +1 -0
  125. package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.js +30 -0
  126. package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.js.map +1 -0
  127. package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.d.ts +6 -0
  128. package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.d.ts.map +1 -0
  129. package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.js +43 -0
  130. package/.medusa/server/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.js.map +1 -0
  131. package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.d.ts +6 -0
  132. package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.d.ts.map +1 -0
  133. package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.js +34 -0
  134. package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.js.map +1 -0
  135. package/.medusa/server/src/modules/paypal/models/paypal_audit_log.d.ts +7 -0
  136. package/.medusa/server/src/modules/paypal/models/paypal_audit_log.d.ts.map +1 -0
  137. package/.medusa/server/src/modules/paypal/models/paypal_audit_log.js +10 -0
  138. package/.medusa/server/src/modules/paypal/models/paypal_audit_log.js.map +1 -0
  139. package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts +14 -0
  140. package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts.map +1 -0
  141. package/.medusa/server/src/modules/paypal/models/paypal_connection.js +17 -0
  142. package/.medusa/server/src/modules/paypal/models/paypal_connection.js.map +1 -0
  143. package/.medusa/server/src/modules/paypal/models/paypal_dispute.d.ts +16 -0
  144. package/.medusa/server/src/modules/paypal/models/paypal_dispute.d.ts.map +1 -0
  145. package/.medusa/server/src/modules/paypal/models/paypal_dispute.js +19 -0
  146. package/.medusa/server/src/modules/paypal/models/paypal_dispute.js.map +1 -0
  147. package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts +7 -0
  148. package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts.map +1 -0
  149. package/.medusa/server/src/modules/paypal/models/paypal_metric.js +10 -0
  150. package/.medusa/server/src/modules/paypal/models/paypal_metric.js.map +1 -0
  151. package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts +6 -0
  152. package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts.map +1 -0
  153. package/.medusa/server/src/modules/paypal/models/paypal_settings.js +9 -0
  154. package/.medusa/server/src/modules/paypal/models/paypal_settings.js.map +1 -0
  155. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts +17 -0
  156. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts.map +1 -0
  157. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js +20 -0
  158. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js.map +1 -0
  159. package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts +35 -0
  160. package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -0
  161. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +569 -0
  162. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -0
  163. package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts +10 -0
  164. package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts.map +1 -0
  165. package/.medusa/server/src/modules/paypal/payment-provider/index.js +22 -0
  166. package/.medusa/server/src/modules/paypal/payment-provider/index.js.map +1 -0
  167. package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts +44 -0
  168. package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -0
  169. package/.medusa/server/src/modules/paypal/payment-provider/service.js +825 -0
  170. package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -0
  171. package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.d.ts +3 -0
  172. package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.d.ts.map +1 -0
  173. package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.js +74 -0
  174. package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.js.map +1 -0
  175. package/.medusa/server/src/modules/paypal/service.d.ts +362 -0
  176. package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -0
  177. package/.medusa/server/src/modules/paypal/service.js +1180 -0
  178. package/.medusa/server/src/modules/paypal/service.js.map +1 -0
  179. package/.medusa/server/src/modules/paypal/types/config.d.ts +14 -0
  180. package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -0
  181. package/.medusa/server/src/modules/paypal/types/config.js +33 -0
  182. package/.medusa/server/src/modules/paypal/types/config.js.map +1 -0
  183. package/.medusa/server/src/modules/paypal/utils/amounts.d.ts +3 -0
  184. package/.medusa/server/src/modules/paypal/utils/amounts.d.ts.map +1 -0
  185. package/.medusa/server/src/modules/paypal/utils/amounts.js +40 -0
  186. package/.medusa/server/src/modules/paypal/utils/amounts.js.map +1 -0
  187. package/.medusa/server/src/modules/paypal/utils/crypto.d.ts +4 -0
  188. package/.medusa/server/src/modules/paypal/utils/crypto.d.ts.map +1 -0
  189. package/.medusa/server/src/modules/paypal/utils/crypto.js +47 -0
  190. package/.medusa/server/src/modules/paypal/utils/crypto.js.map +1 -0
  191. package/.medusa/server/src/modules/paypal/utils/currencies.d.ts +19 -0
  192. package/.medusa/server/src/modules/paypal/utils/currencies.d.ts.map +1 -0
  193. package/.medusa/server/src/modules/paypal/utils/currencies.js +69 -0
  194. package/.medusa/server/src/modules/paypal/utils/currencies.js.map +1 -0
  195. package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts +9 -0
  196. package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts.map +1 -0
  197. package/.medusa/server/src/modules/paypal/utils/provider-ids.js +50 -0
  198. package/.medusa/server/src/modules/paypal/utils/provider-ids.js.map +1 -0
  199. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +38 -0
  200. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -0
  201. package/.medusa/server/src/modules/paypal/webhook-processor.js +265 -0
  202. package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -0
  203. package/LICENSE +21 -0
  204. package/README.md +67 -0
  205. package/package.json +61 -0
  206. package/postcss.config.cjs +3 -0
  207. package/src/admin/index.ts +7 -0
  208. package/src/admin/routes/settings/paypal/_components/Tabs.tsx +55 -0
  209. package/src/admin/routes/settings/paypal/_components/Toast.tsx +51 -0
  210. package/src/admin/routes/settings/paypal/additional-settings/page.tsx +346 -0
  211. package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +381 -0
  212. package/src/admin/routes/settings/paypal/apple-pay/page.tsx +5 -0
  213. package/src/admin/routes/settings/paypal/audit-logs/page.tsx +131 -0
  214. package/src/admin/routes/settings/paypal/connection/page.tsx +750 -0
  215. package/src/admin/routes/settings/paypal/disputes/page.tsx +259 -0
  216. package/src/admin/routes/settings/paypal/google-pay/page.tsx +5 -0
  217. package/src/admin/routes/settings/paypal/page.tsx +16 -0
  218. package/src/admin/routes/settings/paypal/pay-later-messaging/page.tsx +5 -0
  219. package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +557 -0
  220. package/src/admin/routes/settings/paypal/reconciliation-status/page.tsx +165 -0
  221. package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +32 -0
  222. package/src/api/admin/paypal/audit-logs/route.ts +13 -0
  223. package/src/api/admin/paypal/disconnect/route.ts +8 -0
  224. package/src/api/admin/paypal/disputes/[id]/route.ts +19 -0
  225. package/src/api/admin/paypal/disputes/route.ts +30 -0
  226. package/src/api/admin/paypal/disputes/summary/route.ts +18 -0
  227. package/src/api/admin/paypal/environment/route.ts +25 -0
  228. package/src/api/admin/paypal/onboard-complete/route.ts +44 -0
  229. package/src/api/admin/paypal/onboarding-link/route.ts +45 -0
  230. package/src/api/admin/paypal/onboarding-status/route.ts +18 -0
  231. package/src/api/admin/paypal/reconciliation-status/route.ts +7 -0
  232. package/src/api/admin/paypal/rotate-credentials/route.ts +8 -0
  233. package/src/api/admin/paypal/save-credentials/route.ts +14 -0
  234. package/src/api/admin/paypal/settings/route.ts +14 -0
  235. package/src/api/admin/paypal/status/route.ts +12 -0
  236. package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +51 -0
  237. package/src/api/store/paypal/capture-order/route.ts +270 -0
  238. package/src/api/store/paypal/config/route.ts +59 -0
  239. package/src/api/store/paypal/create-order/route.ts +374 -0
  240. package/src/api/store/paypal/disputes/route.ts +67 -0
  241. package/src/api/store/paypal/settings/route.ts +12 -0
  242. package/src/api/store/paypal/webhook/route.ts +247 -0
  243. package/src/jobs/paypal-reconcile.ts +135 -0
  244. package/src/jobs/paypal-webhook-retry.ts +86 -0
  245. package/src/modules/paypal/clients/paypal-seller.client.ts +59 -0
  246. package/src/modules/paypal/index.ts +8 -0
  247. package/src/modules/paypal/migrations/20260115120000_create_paypal_connection.ts +33 -0
  248. package/src/modules/paypal/migrations/20260123090000_create_paypal_settings.ts +22 -0
  249. package/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.ts +29 -0
  250. package/src/modules/paypal/migrations/20260301090000_create_paypal_audit_log.ts +26 -0
  251. package/src/modules/paypal/migrations/20260401090000_create_paypal_metric.ts +27 -0
  252. package/src/modules/paypal/migrations/20260501090000_create_paypal_dispute.ts +40 -0
  253. package/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.ts +31 -0
  254. package/src/modules/paypal/models/paypal_audit_log.ts +9 -0
  255. package/src/modules/paypal/models/paypal_connection.ts +21 -0
  256. package/src/modules/paypal/models/paypal_dispute.ts +18 -0
  257. package/src/modules/paypal/models/paypal_metric.ts +9 -0
  258. package/src/modules/paypal/models/paypal_settings.ts +8 -0
  259. package/src/modules/paypal/models/paypal_webhook_event.ts +19 -0
  260. package/src/modules/paypal/payment-provider/README.md +22 -0
  261. package/src/modules/paypal/payment-provider/card-service.ts +710 -0
  262. package/src/modules/paypal/payment-provider/index.ts +19 -0
  263. package/src/modules/paypal/payment-provider/service.ts +1035 -0
  264. package/src/modules/paypal/payment-provider/webhook-utils.ts +88 -0
  265. package/src/modules/paypal/service.ts +1422 -0
  266. package/src/modules/paypal/types/config.ts +47 -0
  267. package/src/modules/paypal/utils/amounts.ts +41 -0
  268. package/src/modules/paypal/utils/crypto.ts +51 -0
  269. package/src/modules/paypal/utils/currencies.ts +84 -0
  270. package/src/modules/paypal/utils/provider-ids.ts +53 -0
  271. package/src/modules/paypal/webhook-processor.ts +313 -0
  272. package/tsconfig.json +31 -0
@@ -0,0 +1,165 @@
1
+ import React, { useCallback, useEffect, useState } from "react"
2
+ import PayPalTabs from "../_components/Tabs"
3
+
4
+ type ReconciliationStatus = {
5
+ runs?: number
6
+ last_run_at?: string | null
7
+ last_run_status?: string | null
8
+ last_success_at?: string | null
9
+ last_failure_at?: string | null
10
+ sessions_checked?: number
11
+ sessions_updated?: number
12
+ drift_count?: number
13
+ last_drift_at?: string | null
14
+ last_drift_order_id?: string | null
15
+ last_error?: string | null
16
+ }
17
+
18
+ function formatDate(value?: string | null) {
19
+ if (!value) {
20
+ return "—"
21
+ }
22
+ const parsed = new Date(value)
23
+ if (Number.isNaN(parsed.getTime())) {
24
+ return value
25
+ }
26
+ return parsed.toLocaleString()
27
+ }
28
+
29
+ export default function PayPalReconciliationStatusPage() {
30
+ const [status, setStatus] = useState<ReconciliationStatus>({})
31
+ const [loading, setLoading] = useState(false)
32
+ const [error, setError] = useState<string | null>(null)
33
+
34
+ const fetchStatus = useCallback(async () => {
35
+ try {
36
+ setLoading(true)
37
+ setError(null)
38
+ const response = await fetch("/admin/paypal/reconciliation-status", {
39
+ credentials: "include",
40
+ headers: {
41
+ Accept: "application/json",
42
+ },
43
+ })
44
+
45
+ if (!response.ok) {
46
+ const message = await response.text().catch(() => "")
47
+ throw new Error(message || "Failed to load reconciliation status.")
48
+ }
49
+
50
+ const data = await response.json().catch(() => ({}))
51
+ setStatus((data?.status as ReconciliationStatus) || {})
52
+ } catch (fetchError: any) {
53
+ setError(fetchError?.message || "Failed to load reconciliation status.")
54
+ setStatus({})
55
+ } finally {
56
+ setLoading(false)
57
+ }
58
+ }, [])
59
+
60
+ useEffect(() => {
61
+ fetchStatus()
62
+ }, [fetchStatus])
63
+
64
+ return (
65
+ <div className="p-6">
66
+ <div className="flex flex-col gap-6">
67
+ <div>
68
+ <h1 className="text-xl font-semibold text-ui-fg-base">
69
+ PayPal Reconciliation Status
70
+ </h1>
71
+ <p className="mt-1 text-sm text-ui-fg-subtle">
72
+ Monitor reconciliation health and drift detection for PayPal payment sessions.
73
+ </p>
74
+ </div>
75
+
76
+ <PayPalTabs />
77
+
78
+ <div className="rounded-xl border border-ui-border-base bg-ui-bg-base shadow-sm">
79
+ <div className="border-b border-ui-border-base p-4">
80
+ <div className="flex items-center justify-between gap-4">
81
+ <div className="text-base font-semibold text-ui-fg-base">
82
+ Latest reconciliation run
83
+ </div>
84
+ <button
85
+ type="button"
86
+ onClick={fetchStatus}
87
+ className="rounded-md border border-ui-border-base px-3 py-2 text-sm text-ui-fg-base"
88
+ disabled={loading}
89
+ >
90
+ {loading ? "Refreshing..." : "Refresh"}
91
+ </button>
92
+ </div>
93
+ </div>
94
+ <div className="p-4">
95
+ {error ? (
96
+ <div className="rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-600">
97
+ {error}
98
+ </div>
99
+ ) : null}
100
+
101
+ {!error && Object.keys(status).length === 0 ? (
102
+ <div className="text-sm text-ui-fg-subtle">
103
+ {loading ? "Loading reconciliation status..." : "No reconciliation data yet."}
104
+ </div>
105
+ ) : null}
106
+
107
+ {Object.keys(status).length > 0 ? (
108
+ <div className="grid gap-4 text-sm text-ui-fg-base md:grid-cols-2">
109
+ <div className="rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3">
110
+ <div className="text-ui-fg-subtle">Last run</div>
111
+ <div className="mt-1 font-medium">{formatDate(status.last_run_at)}</div>
112
+ </div>
113
+ <div className="rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3">
114
+ <div className="text-ui-fg-subtle">Last run status</div>
115
+ <div className="mt-1 font-medium capitalize">
116
+ {status.last_run_status || "—"}
117
+ </div>
118
+ </div>
119
+ <div className="rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3">
120
+ <div className="text-ui-fg-subtle">Last success</div>
121
+ <div className="mt-1 font-medium">{formatDate(status.last_success_at)}</div>
122
+ </div>
123
+ <div className="rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3">
124
+ <div className="text-ui-fg-subtle">Last failure</div>
125
+ <div className="mt-1 font-medium">{formatDate(status.last_failure_at)}</div>
126
+ </div>
127
+ <div className="rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3">
128
+ <div className="text-ui-fg-subtle">Sessions checked</div>
129
+ <div className="mt-1 font-medium">{status.sessions_checked ?? 0}</div>
130
+ </div>
131
+ <div className="rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3">
132
+ <div className="text-ui-fg-subtle">Sessions updated</div>
133
+ <div className="mt-1 font-medium">{status.sessions_updated ?? 0}</div>
134
+ </div>
135
+ <div className="rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3">
136
+ <div className="text-ui-fg-subtle">Drift detections</div>
137
+ <div className="mt-1 font-medium">{status.drift_count ?? 0}</div>
138
+ </div>
139
+ <div className="rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3">
140
+ <div className="text-ui-fg-subtle">Last drift order</div>
141
+ <div className="mt-1 font-medium">
142
+ {status.last_drift_order_id || "—"}
143
+ </div>
144
+ <div className="mt-1 text-xs text-ui-fg-subtle">
145
+ {formatDate(status.last_drift_at)}
146
+ </div>
147
+ </div>
148
+ <div className="rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3 md:col-span-2">
149
+ <div className="text-ui-fg-subtle">Last error</div>
150
+ <div className="mt-1 font-medium">
151
+ {status.last_error || "No errors recorded."}
152
+ </div>
153
+ </div>
154
+ <div className="rounded-lg border border-ui-border-base bg-ui-bg-subtle p-3 md:col-span-2">
155
+ <div className="text-ui-fg-subtle">Total runs</div>
156
+ <div className="mt-1 font-medium">{status.runs ?? 0}</div>
157
+ </div>
158
+ </div>
159
+ ) : null}
160
+ </div>
161
+ </div>
162
+ </div>
163
+ </div>
164
+ )
165
+ }
@@ -0,0 +1,32 @@
1
+ import { createPaymentSessionsWorkflow } from "@medusajs/core-flows"
2
+ import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
3
+ import { normalizePayPalProviderId } from "../../../../../modules/paypal/utils/provider-ids"
4
+
5
+ type CreatePaymentSessionBody = {
6
+ provider_id: string
7
+ data?: Record<string, unknown>
8
+ customer_id?: string
9
+ }
10
+
11
+ export async function POST(req: MedusaRequest, res: MedusaResponse) {
12
+ const collectionId = req.params.id
13
+ const { provider_id, data, customer_id } = req.body as CreatePaymentSessionBody
14
+ const normalizedProviderId = normalizePayPalProviderId(provider_id)
15
+
16
+ if (!normalizedProviderId) {
17
+ return res.status(400).json({
18
+ message: `Provider ${provider_id} is not a valid PayPal provider`,
19
+ })
20
+ }
21
+
22
+ const { result } = await createPaymentSessionsWorkflow(req.scope).run({
23
+ input: {
24
+ payment_collection_id: collectionId,
25
+ provider_id: normalizedProviderId,
26
+ customer_id,
27
+ data,
28
+ },
29
+ })
30
+
31
+ res.status(200).json({ payment_session: result })
32
+ }
@@ -0,0 +1,13 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
5
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
6
+ const q = (req.query || {}) as Record<string, any>
7
+ const limitRaw = Number(q.limit || 50)
8
+ const limit = Number.isFinite(limitRaw) ? Math.min(Math.max(limitRaw, 1), 200) : 50
9
+
10
+ const logs = await paypal.getAuditLogs(limit)
11
+
12
+ return res.json({ logs })
13
+ }
@@ -0,0 +1,8 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ export async function POST(req: MedusaRequest, res: MedusaResponse) {
5
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
6
+ await paypal.disconnect()
7
+ return res.json({ ok: true })
8
+ }
@@ -0,0 +1,19 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../../modules/paypal/service"
3
+
4
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
5
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
6
+ const disputeId = String(req.params?.id || "").trim()
7
+
8
+ if (!disputeId) {
9
+ return res.status(400).json({ message: "dispute id is required" })
10
+ }
11
+
12
+ const matches = await paypal.listPayPalDisputes({ dispute_id: disputeId })
13
+ const dispute = matches?.[0]
14
+ if (!dispute) {
15
+ return res.status(404).json({ message: "Dispute not found" })
16
+ }
17
+
18
+ return res.json({ dispute })
19
+ }
@@ -0,0 +1,30 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
5
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
6
+
7
+ const query = (req.query || {}) as Record<string, string | string[] | undefined>
8
+ const filters: Record<string, string> = {}
9
+
10
+ const addFilter = (key: string) => {
11
+ const value = query[key]
12
+ if (Array.isArray(value)) {
13
+ if (value[0]) {
14
+ filters[key] = value[0]
15
+ }
16
+ return
17
+ }
18
+ if (typeof value === "string" && value.trim()) {
19
+ filters[key] = value.trim()
20
+ }
21
+ }
22
+
23
+ addFilter("status")
24
+ addFilter("order_id")
25
+ addFilter("cart_id")
26
+ addFilter("dispute_id")
27
+
28
+ const disputes = await paypal.listPayPalDisputes(filters)
29
+ return res.json({ disputes })
30
+ }
@@ -0,0 +1,18 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../../modules/paypal/service"
3
+
4
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
5
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
6
+ const disputes = await paypal.listPayPalDisputes({})
7
+ const counts: Record<string, number> = {}
8
+
9
+ for (const dispute of disputes || []) {
10
+ const status = dispute.status || "unknown"
11
+ counts[status] = (counts[status] || 0) + 1
12
+ }
13
+
14
+ return res.json({
15
+ total: disputes?.length ?? 0,
16
+ statuses: counts,
17
+ })
18
+ }
@@ -0,0 +1,25 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ type Body = {
5
+ environment?: "sandbox" | "live"
6
+ }
7
+
8
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
9
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
10
+ const status = await paypal.getStatus()
11
+ return res.json({ environment: status.environment })
12
+ }
13
+
14
+ export async function POST(req: MedusaRequest, res: MedusaResponse) {
15
+ try {
16
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
17
+ const body = (req.body || {}) as Body
18
+ const env = body.environment === "live" ? "live" : "sandbox"
19
+ await paypal.setEnvironment(env)
20
+ const status = await paypal.getStatus()
21
+ return res.json(status)
22
+ } catch (e: any) {
23
+ return res.status(500).json({ message: e?.message || "Unknown error" })
24
+ }
25
+ }
@@ -0,0 +1,44 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ /**
5
+ * Helpful response for browser address-bar tests.
6
+ * The onboarding callback must call this endpoint via POST.
7
+ */
8
+ export async function GET(_req: MedusaRequest, res: MedusaResponse) {
9
+ return res.status(405).json({
10
+ message:
11
+ "Method Not Allowed. Use POST with JSON: { authCode, sharedId, env }. This endpoint is called by the PayPal onboarding callback.",
12
+ })
13
+ }
14
+
15
+ export async function POST(req: MedusaRequest, res: MedusaResponse) {
16
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
17
+ const body = req.body as { authCode?: string; sharedId?: string; env?: "sandbox" | "live" }
18
+
19
+ if (!body?.authCode || !body?.sharedId) {
20
+ return res.status(400).json({ message: "Missing authCode/sharedId" })
21
+ }
22
+
23
+ try {
24
+ // Useful for debugging "No response" / hanging requests
25
+ console.log("[PayPal] /admin/paypal/onboard-complete", {
26
+ env: body.env,
27
+ hasAuthCode: !!body.authCode,
28
+ hasSharedId: !!body.sharedId,
29
+ })
30
+
31
+ await paypal.exchangeAndSaveSellerCredentials({
32
+ authCode: body.authCode,
33
+ sharedId: body.sharedId,
34
+ env: body.env,
35
+ })
36
+
37
+ return res.json({ ok: true })
38
+ } catch (e: any) {
39
+ console.error("[PayPal] onboard-complete failed", e)
40
+ return res.status(500).json({
41
+ message: e?.message || "Failed to exchange and save PayPal credentials",
42
+ })
43
+ }
44
+ }
@@ -0,0 +1,45 @@
1
+ import type {
2
+ AuthenticatedMedusaRequest,
3
+ MedusaRequest,
4
+ MedusaResponse,
5
+ } from "@medusajs/framework/http"
6
+ import type PayPalModuleService from "../../../../modules/paypal/service"
7
+
8
+ type Body = {
9
+ email?: string
10
+ products?: string[]
11
+ }
12
+
13
+ export async function POST(req: AuthenticatedMedusaRequest, res: MedusaResponse) {
14
+ try {
15
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
16
+ const body = (req.body || {}) as Body
17
+ const authEmail =
18
+ typeof req.auth_context?.user_metadata?.email === "string"
19
+ ? String(req.auth_context.user_metadata.email)
20
+ : undefined
21
+ const email = authEmail ?? body.email ?? "admin@paypal.com"
22
+
23
+ const link = await paypal.createOnboardingLink({
24
+ email,
25
+ products: body.products,
26
+ })
27
+
28
+ return res.json({
29
+ status: "pending",
30
+ onboarding_url: link.onboarding_url,
31
+ return_url: link.return_url,
32
+ })
33
+ } catch (e: any) {
34
+ console.error("[paypal_onboarding] onboarding-link error:", e?.message || e, e?.stack)
35
+ return res.status(500).json({
36
+ message: e?.message || "Unknown error",
37
+ })
38
+ }
39
+ }
40
+
41
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
42
+ return res.status(405).json({
43
+ message: "Use POST /admin/paypal/onboarding-link",
44
+ })
45
+ }
@@ -0,0 +1,18 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
5
+ try {
6
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
7
+ const status = await paypal.getStatus()
8
+ return res.json(status)
9
+ } catch (e: any) {
10
+ // ✅ Avoid breaking Admin UI with Medusa's generic "unknown_error"
11
+ console.error("[paypal_onboarding] onboarding-status error:", e?.message || e, e?.stack)
12
+ return res.json({
13
+ environment: "sandbox",
14
+ status: "disconnected",
15
+ error: e?.message || "Unknown error",
16
+ })
17
+ }
18
+ }
@@ -0,0 +1,7 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
5
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
6
+ return res.json(await paypal.getReconciliationStatus())
7
+ }
@@ -0,0 +1,8 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ export async function POST(req: MedusaRequest, res: MedusaResponse) {
5
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
6
+ const result = await paypal.rotateCredentialEncryptionKey()
7
+ return res.json(result)
8
+ }
@@ -0,0 +1,14 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ export async function POST(req: MedusaRequest, res: MedusaResponse) {
5
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
6
+ const body = req.body as { clientId?: string; clientSecret?: string }
7
+
8
+ if (!body?.clientId || !body?.clientSecret) {
9
+ return res.status(400).json({ message: "Missing clientId/clientSecret" })
10
+ }
11
+
12
+ await paypal.saveSellerCredentials({ clientId: body.clientId, clientSecret: body.clientSecret })
13
+ return res.json({ ok: true })
14
+ }
@@ -0,0 +1,14 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
5
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
6
+ return res.json(await paypal.getSettings())
7
+ }
8
+
9
+ export async function POST(req: MedusaRequest, res: MedusaResponse) {
10
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
11
+
12
+ const patch = (req.body && typeof req.body === "object") ? (req.body as Record<string, any>) : {}
13
+ return res.json(await paypal.saveSettings(patch))
14
+ }
@@ -0,0 +1,12 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
5
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
6
+
7
+ const q = (req.query || {}) as Record<string, any>
8
+ const envParam = (q.environment || q.env) as string | undefined
9
+ const env = envParam === "live" ? "live" : envParam === "sandbox" ? "sandbox" : undefined
10
+
11
+ return res.json(await paypal.getStatus(env))
12
+ }
@@ -0,0 +1,51 @@
1
+ import { createPaymentSessionsWorkflow } from "@medusajs/core-flows"
2
+ import { MedusaResponse, MedusaStoreRequest, refetchEntity } from "@medusajs/framework/http"
3
+ import { normalizePayPalProviderId } from "../../../../../modules/paypal/utils/provider-ids"
4
+
5
+ type CreatePaymentSessionBody = {
6
+ provider_id: string
7
+ data?: Record<string, unknown>
8
+ }
9
+
10
+ export async function POST(req: MedusaStoreRequest, res: MedusaResponse) {
11
+ const collectionId = req.params.id
12
+ const { provider_id, data } = req.body as CreatePaymentSessionBody
13
+ const normalizedProviderId = normalizePayPalProviderId(provider_id)
14
+ const providerId = normalizedProviderId ?? provider_id
15
+ const sessionData = normalizedProviderId
16
+ ? { ...(data || {}), provider_id: providerId }
17
+ : data
18
+
19
+ try {
20
+ await createPaymentSessionsWorkflow(req.scope).run({
21
+ input: {
22
+ payment_collection_id: collectionId,
23
+ provider_id: providerId,
24
+ customer_id: req.auth_context?.actor_id,
25
+ data: sessionData,
26
+ },
27
+ })
28
+ } catch (error: any) {
29
+ console.error(
30
+ "[paypal] payment session creation failed",
31
+ error?.message || error,
32
+ error?.stack
33
+ )
34
+ return res.status(400).json({
35
+ code: "paypal_payment_session_error",
36
+ type: "paypal_payment_session_error",
37
+ message: error?.message || "Unable to create PayPal payment session",
38
+ })
39
+ }
40
+
41
+ const paymentCollection = await refetchEntity({
42
+ entity: "payment_collection",
43
+ idOrFilter: collectionId,
44
+ scope: req.scope,
45
+ fields: req.queryConfig.fields,
46
+ })
47
+
48
+ res.status(200).json({
49
+ payment_collection: paymentCollection,
50
+ })
51
+ }