@easypayment/medusa-payment-paypal 1.2.3 → 1.2.5

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 (274) hide show
  1. package/.medusa/server/src/admin/index.js +392 -138
  2. package/.medusa/server/src/admin/index.mjs +392 -138
  3. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts +1 -0
  4. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
  5. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js +5 -1
  6. package/.medusa/server/src/api/admin/payment-collections/[id]/payment-sessions/route.js.map +1 -1
  7. package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts +1 -0
  8. package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts.map +1 -1
  9. package/.medusa/server/src/api/admin/paypal/disconnect/route.js +1 -0
  10. package/.medusa/server/src/api/admin/paypal/disconnect/route.js.map +1 -1
  11. package/.medusa/server/src/api/admin/paypal/environment/route.d.ts +2 -0
  12. package/.medusa/server/src/api/admin/paypal/environment/route.d.ts.map +1 -1
  13. package/.medusa/server/src/api/admin/paypal/environment/route.js +2 -0
  14. package/.medusa/server/src/api/admin/paypal/environment/route.js.map +1 -1
  15. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts +9 -0
  16. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts.map +1 -1
  17. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js +9 -4
  18. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js.map +1 -1
  19. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts +7 -1
  20. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts.map +1 -1
  21. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js +9 -2
  22. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js.map +1 -1
  23. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts +1 -0
  24. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts.map +1 -1
  25. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js +1 -0
  26. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js.map +1 -1
  27. package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts +1 -0
  28. package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts.map +1 -1
  29. package/.medusa/server/src/api/admin/paypal/save-credentials/route.js +10 -3
  30. package/.medusa/server/src/api/admin/paypal/save-credentials/route.js.map +1 -1
  31. package/.medusa/server/src/api/admin/paypal/settings/route.d.ts +2 -0
  32. package/.medusa/server/src/api/admin/paypal/settings/route.d.ts.map +1 -1
  33. package/.medusa/server/src/api/admin/paypal/settings/route.js +9 -2
  34. package/.medusa/server/src/api/admin/paypal/settings/route.js.map +1 -1
  35. package/.medusa/server/src/api/admin/paypal/status/route.d.ts +4 -0
  36. package/.medusa/server/src/api/admin/paypal/status/route.d.ts.map +1 -1
  37. package/.medusa/server/src/api/admin/paypal/status/route.js +9 -1
  38. package/.medusa/server/src/api/admin/paypal/status/route.js.map +1 -1
  39. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts +4 -0
  40. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -1
  41. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js +11 -1
  42. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js.map +1 -1
  43. package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts +8 -0
  44. package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -1
  45. package/.medusa/server/src/api/store/paypal/capture-order/route.js +23 -3
  46. package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -1
  47. package/.medusa/server/src/api/store/paypal/config/route.d.ts +5 -0
  48. package/.medusa/server/src/api/store/paypal/config/route.d.ts.map +1 -1
  49. package/.medusa/server/src/api/store/paypal/config/route.js +12 -5
  50. package/.medusa/server/src/api/store/paypal/config/route.js.map +1 -1
  51. package/.medusa/server/src/api/store/paypal/create-order/route.d.ts +8 -0
  52. package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -1
  53. package/.medusa/server/src/api/store/paypal/create-order/route.js +80 -26
  54. package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -1
  55. package/.medusa/server/src/api/store/paypal/onboard-return/route.d.ts.map +1 -1
  56. package/.medusa/server/src/api/store/paypal/onboard-return/route.js +19 -19
  57. package/.medusa/server/src/api/store/paypal/onboard-return/route.js.map +1 -1
  58. package/.medusa/server/src/api/store/paypal/settings/route.d.ts +1 -0
  59. package/.medusa/server/src/api/store/paypal/settings/route.d.ts.map +1 -1
  60. package/.medusa/server/src/api/store/paypal/settings/route.js +4 -1
  61. package/.medusa/server/src/api/store/paypal/settings/route.js.map +1 -1
  62. package/.medusa/server/src/api/store/paypal/webhook/route.d.ts +7 -0
  63. package/.medusa/server/src/api/store/paypal/webhook/route.d.ts.map +1 -1
  64. package/.medusa/server/src/api/store/paypal/webhook/route.js +34 -3
  65. package/.medusa/server/src/api/store/paypal/webhook/route.js.map +1 -1
  66. package/.medusa/server/src/api/store/paypal-complete/route.d.ts +8 -0
  67. package/.medusa/server/src/api/store/paypal-complete/route.d.ts.map +1 -1
  68. package/.medusa/server/src/api/store/paypal-complete/route.js +55 -8
  69. package/.medusa/server/src/api/store/paypal-complete/route.js.map +1 -1
  70. package/.medusa/server/src/api/utils/rate-limit.d.ts +4 -0
  71. package/.medusa/server/src/api/utils/rate-limit.d.ts.map +1 -1
  72. package/.medusa/server/src/api/utils/rate-limit.js +9 -4
  73. package/.medusa/server/src/api/utils/rate-limit.js.map +1 -1
  74. package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts +5 -0
  75. package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -1
  76. package/.medusa/server/src/jobs/paypal-webhook-retry.js +13 -2
  77. package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -1
  78. package/.medusa/server/src/modules/paypal/index.d.ts +1 -0
  79. package/.medusa/server/src/modules/paypal/index.d.ts.map +1 -1
  80. package/.medusa/server/src/modules/paypal/index.js +1 -0
  81. package/.medusa/server/src/modules/paypal/index.js.map +1 -1
  82. package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.js +22 -22
  83. package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.js +11 -11
  84. package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.js +18 -18
  85. package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.js +16 -16
  86. package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.js +20 -20
  87. package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.js +14 -14
  88. package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.js +15 -15
  89. package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.d.ts.map +1 -1
  90. package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.js.map +1 -1
  91. package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.d.ts.map +1 -1
  92. package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.js.map +1 -1
  93. package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.d.ts.map +1 -1
  94. package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.js.map +1 -1
  95. package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.js +6 -6
  96. package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts +5 -0
  97. package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts.map +1 -1
  98. package/.medusa/server/src/modules/paypal/models/paypal_connection.js +5 -0
  99. package/.medusa/server/src/modules/paypal/models/paypal_connection.js.map +1 -1
  100. package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts +4 -0
  101. package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts.map +1 -1
  102. package/.medusa/server/src/modules/paypal/models/paypal_metric.js +4 -0
  103. package/.medusa/server/src/modules/paypal/models/paypal_metric.js.map +1 -1
  104. package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts +5 -0
  105. package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts.map +1 -1
  106. package/.medusa/server/src/modules/paypal/models/paypal_settings.js +5 -0
  107. package/.medusa/server/src/modules/paypal/models/paypal_settings.js.map +1 -1
  108. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts +7 -0
  109. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts.map +1 -1
  110. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js +7 -0
  111. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js.map +1 -1
  112. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts +24 -1
  113. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.d.ts.map +1 -1
  114. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js +296 -0
  115. package/.medusa/server/src/modules/paypal/payment-provider/base-provider.js.map +1 -1
  116. package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts +14 -7
  117. package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -1
  118. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +40 -198
  119. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -1
  120. package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts +6 -1
  121. package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts.map +1 -1
  122. package/.medusa/server/src/modules/paypal/payment-provider/index.js +6 -4
  123. package/.medusa/server/src/modules/paypal/payment-provider/index.js.map +1 -1
  124. package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts +9 -2
  125. package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -1
  126. package/.medusa/server/src/modules/paypal/payment-provider/service.js +29 -181
  127. package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -1
  128. package/.medusa/server/src/modules/paypal/payment-provider/status-utils.d.ts +21 -0
  129. package/.medusa/server/src/modules/paypal/payment-provider/status-utils.d.ts.map +1 -1
  130. package/.medusa/server/src/modules/paypal/payment-provider/status-utils.js +54 -0
  131. package/.medusa/server/src/modules/paypal/payment-provider/status-utils.js.map +1 -1
  132. package/.medusa/server/src/modules/paypal/service.d.ts +72 -2
  133. package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -1
  134. package/.medusa/server/src/modules/paypal/service.js +159 -33
  135. package/.medusa/server/src/modules/paypal/service.js.map +1 -1
  136. package/.medusa/server/src/modules/paypal/types/config.d.ts +2 -0
  137. package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -1
  138. package/.medusa/server/src/modules/paypal/types/config.js +5 -2
  139. package/.medusa/server/src/modules/paypal/types/config.js.map +1 -1
  140. package/.medusa/server/src/modules/paypal/utils/amounts.d.ts +1 -0
  141. package/.medusa/server/src/modules/paypal/utils/amounts.d.ts.map +1 -1
  142. package/.medusa/server/src/modules/paypal/utils/amounts.js +15 -5
  143. package/.medusa/server/src/modules/paypal/utils/amounts.js.map +1 -1
  144. package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts +10 -0
  145. package/.medusa/server/src/modules/paypal/utils/credential-resolver.d.ts.map +1 -1
  146. package/.medusa/server/src/modules/paypal/utils/credential-resolver.js +45 -1
  147. package/.medusa/server/src/modules/paypal/utils/credential-resolver.js.map +1 -1
  148. package/.medusa/server/src/modules/paypal/utils/currencies.d.ts +9 -0
  149. package/.medusa/server/src/modules/paypal/utils/currencies.d.ts.map +1 -1
  150. package/.medusa/server/src/modules/paypal/utils/currencies.js +13 -0
  151. package/.medusa/server/src/modules/paypal/utils/currencies.js.map +1 -1
  152. package/.medusa/server/src/modules/paypal/utils/payment-session.d.ts +12 -0
  153. package/.medusa/server/src/modules/paypal/utils/payment-session.d.ts.map +1 -1
  154. package/.medusa/server/src/modules/paypal/utils/payment-session.js +4 -3
  155. package/.medusa/server/src/modules/paypal/utils/payment-session.js.map +1 -1
  156. package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts +1 -0
  157. package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts.map +1 -1
  158. package/.medusa/server/src/modules/paypal/utils/paypal-auth.js +1 -0
  159. package/.medusa/server/src/modules/paypal/utils/paypal-auth.js.map +1 -1
  160. package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts +11 -0
  161. package/.medusa/server/src/modules/paypal/utils/paypal-fetch.d.ts.map +1 -1
  162. package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js +17 -1
  163. package/.medusa/server/src/modules/paypal/utils/paypal-fetch.js.map +1 -1
  164. package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts +6 -0
  165. package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts.map +1 -1
  166. package/.medusa/server/src/modules/paypal/utils/provider-ids.js +6 -0
  167. package/.medusa/server/src/modules/paypal/utils/provider-ids.js.map +1 -1
  168. package/.medusa/server/src/modules/paypal/utils/secret-crypto.d.ts +2 -0
  169. package/.medusa/server/src/modules/paypal/utils/secret-crypto.d.ts.map +1 -1
  170. package/.medusa/server/src/modules/paypal/utils/secret-crypto.js +6 -1
  171. package/.medusa/server/src/modules/paypal/utils/secret-crypto.js.map +1 -1
  172. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +43 -0
  173. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -1
  174. package/.medusa/server/src/modules/paypal/webhook-processor.js +57 -5
  175. package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -1
  176. package/.medusa/server/src/providers/paypal/index.d.ts +1 -0
  177. package/.medusa/server/src/providers/paypal/index.d.ts.map +1 -1
  178. package/.medusa/server/src/providers/paypal/index.js +1 -0
  179. package/.medusa/server/src/providers/paypal/index.js.map +1 -1
  180. package/.medusa/server/src/providers/paypal_card/index.d.ts +1 -0
  181. package/.medusa/server/src/providers/paypal_card/index.d.ts.map +1 -1
  182. package/.medusa/server/src/providers/paypal_card/index.js +1 -0
  183. package/.medusa/server/src/providers/paypal_card/index.js.map +1 -1
  184. package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts +6 -0
  185. package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts.map +1 -1
  186. package/.medusa/server/src/subscribers/paypal-order-invoice.js +9 -1
  187. package/.medusa/server/src/subscribers/paypal-order-invoice.js.map +1 -1
  188. package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts +1 -0
  189. package/.medusa/server/src/subscribers/paypal-webhook-process.d.ts.map +1 -1
  190. package/.medusa/server/src/subscribers/paypal-webhook-process.js +17 -4
  191. package/.medusa/server/src/subscribers/paypal-webhook-process.js.map +1 -1
  192. package/CHANGELOG.md +65 -0
  193. package/README.md +184 -184
  194. package/package.json +7 -4
  195. package/src/admin/index.ts +1 -1
  196. package/src/admin/routes/settings/paypal/_components/FieldRow.tsx +38 -29
  197. package/src/admin/routes/settings/paypal/_components/SectionCard.tsx +29 -26
  198. package/src/admin/routes/settings/paypal/_components/Tabs.tsx +49 -48
  199. package/src/admin/routes/settings/paypal/_components/Toast.tsx +63 -52
  200. package/src/admin/routes/settings/paypal/_utils/adminFetch.ts +52 -32
  201. package/src/admin/routes/settings/paypal/additional-settings/page.tsx +246 -139
  202. package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +208 -123
  203. package/src/admin/routes/settings/paypal/apple-pay/page.tsx +9 -5
  204. package/src/admin/routes/settings/paypal/connection/page.tsx +974 -908
  205. package/src/admin/routes/settings/paypal/google-pay/page.tsx +9 -5
  206. package/src/admin/routes/settings/paypal/page.tsx +14 -13
  207. package/src/admin/routes/settings/paypal/pay-later-messaging/page.tsx +9 -5
  208. package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +304 -273
  209. package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +48 -39
  210. package/src/api/admin/paypal/disconnect/route.ts +15 -14
  211. package/src/api/admin/paypal/environment/route.ts +34 -32
  212. package/src/api/admin/paypal/onboard-complete/route.ts +61 -50
  213. package/src/api/admin/paypal/onboarding-link/route.ts +91 -76
  214. package/src/api/admin/paypal/onboarding-status/route.ts +21 -20
  215. package/src/api/admin/paypal/save-credentials/route.ts +48 -37
  216. package/src/api/admin/paypal/settings/route.ts +63 -45
  217. package/src/api/admin/paypal/status/route.ts +29 -17
  218. package/src/api/hooks/paypal/onboard-return/route.ts +15 -15
  219. package/src/api/hooks/paypal/webhook/route.ts +17 -17
  220. package/src/api/middlewares.ts +61 -61
  221. package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +69 -54
  222. package/src/api/store/paypal/capture-order/route.ts +416 -370
  223. package/src/api/store/paypal/config/route.ts +121 -115
  224. package/src/api/store/paypal/create-order/route.ts +611 -539
  225. package/src/api/store/paypal/onboard-return/route.ts +116 -113
  226. package/src/api/store/paypal/settings/route.ts +29 -19
  227. package/src/api/store/paypal/webhook/route.ts +380 -314
  228. package/src/api/store/paypal-complete/route.ts +184 -128
  229. package/src/api/utils/rate-limit.ts +143 -129
  230. package/src/index.ts +1 -1
  231. package/src/jobs/paypal-webhook-retry.ts +257 -241
  232. package/src/modules/paypal/index.ts +9 -8
  233. package/src/modules/paypal/migrations/20260115120000_create_paypal_connection.ts +33 -33
  234. package/src/modules/paypal/migrations/20260123090000_create_paypal_settings.ts +22 -22
  235. package/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.ts +29 -29
  236. package/src/modules/paypal/migrations/20260401090000_create_paypal_metric.ts +27 -27
  237. package/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.ts +31 -31
  238. package/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.ts +25 -25
  239. package/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.ts +26 -26
  240. package/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.ts +15 -11
  241. package/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.ts +15 -11
  242. package/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.ts +15 -11
  243. package/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.ts +17 -17
  244. package/src/modules/paypal/migrations/20270202000000_align_nullable_defaults.ts +44 -44
  245. package/src/modules/paypal/migrations/20270301000000_add_webhook_transmission_id_index.ts +15 -15
  246. package/src/modules/paypal/models/paypal_connection.ts +28 -23
  247. package/src/modules/paypal/models/paypal_metric.ts +13 -9
  248. package/src/modules/paypal/models/paypal_settings.ts +13 -8
  249. package/src/modules/paypal/models/paypal_webhook_event.ts +26 -19
  250. package/src/modules/paypal/payment-provider/base-provider.ts +700 -275
  251. package/src/modules/paypal/payment-provider/card-service.ts +693 -855
  252. package/src/modules/paypal/payment-provider/index.ts +14 -15
  253. package/src/modules/paypal/payment-provider/service.ts +673 -836
  254. package/src/modules/paypal/payment-provider/status-utils.ts +116 -59
  255. package/src/modules/paypal/payment-provider/webhook-utils.ts +109 -109
  256. package/src/modules/paypal/service.ts +362 -115
  257. package/src/modules/paypal/types/config.ts +70 -65
  258. package/src/modules/paypal/utils/amounts.ts +123 -107
  259. package/src/modules/paypal/utils/core-workflow.ts +46 -46
  260. package/src/modules/paypal/utils/credential-resolver.ts +315 -271
  261. package/src/modules/paypal/utils/currencies.ts +97 -84
  262. package/src/modules/paypal/utils/partner.ts +8 -8
  263. package/src/modules/paypal/utils/payment-session.ts +144 -138
  264. package/src/modules/paypal/utils/paypal-auth.ts +6 -5
  265. package/src/modules/paypal/utils/paypal-fetch.ts +197 -181
  266. package/src/modules/paypal/utils/provider-ids.ts +21 -15
  267. package/src/modules/paypal/utils/secret-crypto.ts +226 -197
  268. package/src/modules/paypal/utils/webhook-verify.ts +61 -61
  269. package/src/modules/paypal/webhook-processor.ts +641 -573
  270. package/src/providers/paypal/index.ts +9 -8
  271. package/src/providers/paypal_card/index.ts +9 -8
  272. package/src/subscribers/paypal-order-invoice.ts +180 -173
  273. package/src/subscribers/paypal-webhook-process.ts +147 -131
  274. package/tsconfig.json +21 -31
@@ -1,45 +1,63 @@
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
- return res.json(await paypal.getSettings())
8
- } catch (e: unknown) {
9
- console.error("[PayPal] settings GET failed:", e instanceof Error ? e.message : e)
10
- return res.status(500).json({ message: "Failed to load PayPal settings" })
11
- }
12
- }
13
-
14
- const ALLOWED_SETTINGS_KEYS = new Set([
15
- "additional_settings",
16
- "paypal_settings",
17
- "advanced_card_payments",
18
- "pay_later_messaging",
19
- "apple_pay",
20
- "google_pay",
21
- "api_details",
22
- ])
23
-
24
- export async function POST(req: MedusaRequest, res: MedusaResponse) {
25
- const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
26
-
27
- const raw = (req.body && typeof req.body === "object") ? (req.body as Record<string, unknown>) : {}
28
- const patch: Record<string, unknown> = {}
29
- for (const key of Object.keys(raw)) {
30
- if (ALLOWED_SETTINGS_KEYS.has(key)) {
31
- patch[key] = raw[key]
32
- }
33
- }
34
-
35
- if (Object.keys(patch).length === 0) {
36
- return res.status(400).json({ message: "No valid settings fields provided" })
37
- }
38
-
39
- try {
40
- return res.json(await paypal.saveSettings(patch as Record<string, Record<string, unknown>>))
41
- } catch (e: unknown) {
42
- console.error("[PayPal] settings POST failed:", e instanceof Error ? e.message : e)
43
- return res.status(500).json({ message: "Failed to save PayPal settings" })
44
- }
45
- }
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ /** GET /admin/paypal/settings — the full settings singleton. */
5
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
6
+ try {
7
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
8
+ return res.json(await paypal.getSettings())
9
+ } catch (e: unknown) {
10
+ console.error(
11
+ "[PayPal] settings GET failed:",
12
+ e instanceof Error ? e.message : e
13
+ )
14
+ return res.status(500).json({ message: "Failed to load PayPal settings" })
15
+ }
16
+ }
17
+
18
+ /** Top-level settings sections an admin may write; anything else is dropped. */
19
+ const ALLOWED_SETTINGS_KEYS = new Set([
20
+ "additional_settings",
21
+ "paypal_settings",
22
+ "advanced_card_payments",
23
+ "pay_later_messaging",
24
+ "apple_pay",
25
+ "google_pay",
26
+ "api_details",
27
+ ])
28
+
29
+ /** POST /admin/paypal/settings — deep-merge the allowed sections of the body. */
30
+ export async function POST(req: MedusaRequest, res: MedusaResponse) {
31
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
32
+
33
+ const raw =
34
+ req.body && typeof req.body === "object"
35
+ ? (req.body as Record<string, unknown>)
36
+ : {}
37
+ const patch: Record<string, unknown> = {}
38
+ for (const key of Object.keys(raw)) {
39
+ if (ALLOWED_SETTINGS_KEYS.has(key)) {
40
+ patch[key] = raw[key]
41
+ }
42
+ }
43
+
44
+ if (Object.keys(patch).length === 0) {
45
+ return res
46
+ .status(400)
47
+ .json({ message: "No valid settings fields provided" })
48
+ }
49
+
50
+ try {
51
+ return res.json(
52
+ await paypal.saveSettings(
53
+ patch as Record<string, Record<string, unknown>>
54
+ )
55
+ )
56
+ } catch (e: unknown) {
57
+ console.error(
58
+ "[PayPal] settings POST failed:",
59
+ e instanceof Error ? e.message : e
60
+ )
61
+ return res.status(500).json({ message: "Failed to save PayPal settings" })
62
+ }
63
+ }
@@ -1,17 +1,29 @@
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
-
8
- const q = (req.query || {}) as Record<string, any>
9
- const envParam = (q.environment || q.env) as string | undefined
10
- const env = envParam === "live" ? "live" : envParam === "sandbox" ? "sandbox" : undefined
11
-
12
- return res.json(await paypal.getStatus(env))
13
- } catch (e: unknown) {
14
- console.error("[PayPal] status GET failed:", e instanceof Error ? e.message : e)
15
- return res.status(500).json({ message: "Failed to retrieve PayPal status" })
16
- }
17
- }
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
2
+ import type PayPalModuleService from "../../../../modules/paypal/service"
3
+
4
+ /**
5
+ * GET /admin/paypal/status[?environment=sandbox|live] — connection status.
6
+ * Read-only: never triggers the seller-profile backfill.
7
+ */
8
+ export async function GET(req: MedusaRequest, res: MedusaResponse) {
9
+ try {
10
+ const paypal = req.scope.resolve<PayPalModuleService>("paypal_onboarding")
11
+
12
+ const q = (req.query || {}) as Record<string, any>
13
+ const envParam = (q.environment || q.env) as string | undefined
14
+ const env =
15
+ envParam === "live"
16
+ ? "live"
17
+ : envParam === "sandbox"
18
+ ? "sandbox"
19
+ : undefined
20
+
21
+ return res.json(await paypal.getStatus(env))
22
+ } catch (e: unknown) {
23
+ console.error(
24
+ "[PayPal] status GET failed:",
25
+ e instanceof Error ? e.message : e
26
+ )
27
+ return res.status(500).json({ message: "Failed to retrieve PayPal status" })
28
+ }
29
+ }
@@ -1,15 +1,15 @@
1
- /**
2
- * PayPal onboarding `return_url` under the `/hooks` namespace.
3
- *
4
- * PayPal redirects the onboarding popup here as a plain top-level browser
5
- * navigation, which carries no `x-publishable-api-key` header — and Medusa's
6
- * store publishable-key middleware rejects every `/store/*` request without
7
- * that header before the handler runs. Hosting the return bridge under
8
- * `/hooks` (no publishable-key guard) lets the popup complete the credential
9
- * exchange and close itself.
10
- *
11
- * The legacy `/store/paypal/onboard-return` route is kept for deployments
12
- * whose edge injects the key; both paths share this exact handler. Newly
13
- * generated onboarding links point at `/hooks/paypal/onboard-return`.
14
- */
15
- export { GET } from "../../../store/paypal/onboard-return/route"
1
+ /**
2
+ * PayPal onboarding `return_url` under the `/hooks` namespace.
3
+ *
4
+ * PayPal redirects the onboarding popup here as a plain top-level browser
5
+ * navigation, which carries no `x-publishable-api-key` header — and Medusa's
6
+ * store publishable-key middleware rejects every `/store/*` request without
7
+ * that header before the handler runs. Hosting the return bridge under
8
+ * `/hooks` (no publishable-key guard) lets the popup complete the credential
9
+ * exchange and close itself.
10
+ *
11
+ * The legacy `/store/paypal/onboard-return` route is kept for deployments
12
+ * whose edge injects the key; both paths share this exact handler. Newly
13
+ * generated onboarding links point at `/hooks/paypal/onboard-return`.
14
+ */
15
+ export { GET } from "../../../store/paypal/onboard-return/route"
@@ -1,17 +1,17 @@
1
- /**
2
- * PayPal webhook endpoint under the `/hooks` namespace.
3
- *
4
- * Medusa applies its store publishable-key middleware to EVERY `/store/*`
5
- * route, and PayPal's webhook delivery cannot send the
6
- * `x-publishable-api-key` header — so the original
7
- * `/store/paypal/webhook` endpoint is rejected with NOT_ALLOWED before the
8
- * handler runs unless a reverse proxy injects the header. The `/hooks`
9
- * namespace (the same one Medusa core uses for provider webhooks) has no such
10
- * guard, so external callers can reach it directly.
11
- *
12
- * The `/store/paypal/webhook` route is kept for deployments that already
13
- * inject the key at their edge; both paths share this exact handler. New
14
- * webhook registrations (and migrated existing ones) point at
15
- * `/hooks/paypal/webhook`.
16
- */
17
- export { POST } from "../../../store/paypal/webhook/route"
1
+ /**
2
+ * PayPal webhook endpoint under the `/hooks` namespace.
3
+ *
4
+ * Medusa applies its store publishable-key middleware to EVERY `/store/*`
5
+ * route, and PayPal's webhook delivery cannot send the
6
+ * `x-publishable-api-key` header — so the original
7
+ * `/store/paypal/webhook` endpoint is rejected with NOT_ALLOWED before the
8
+ * handler runs unless a reverse proxy injects the header. The `/hooks`
9
+ * namespace (the same one Medusa core uses for provider webhooks) has no such
10
+ * guard, so external callers can reach it directly.
11
+ *
12
+ * The `/store/paypal/webhook` route is kept for deployments that already
13
+ * inject the key at their edge; both paths share this exact handler. New
14
+ * webhook registrations (and migrated existing ones) point at
15
+ * `/hooks/paypal/webhook`.
16
+ */
17
+ export { POST } from "../../../store/paypal/webhook/route"
@@ -1,61 +1,61 @@
1
- import { defineMiddlewares } from "@medusajs/framework/http"
2
- import { createRateLimiter } from "./utils/rate-limit"
3
-
4
- export default defineMiddlewares({
5
- routes: [
6
- {
7
- // Keep the exact bytes PayPal signed (`req.rawBody`) so webhook signature
8
- // verification hashes the original payload, not a re-serialized copy. This
9
- // entry must precede the "/store/paypal/:path*" catch-all below.
10
- // Rate-limited (opt-in, like the store routes): every unauthenticated
11
- // POST here costs a DB dedup read plus an outbound PayPal
12
- // verify-webhook-signature call, and a flood of garbage requests could
13
- // trip the shared circuit breaker for legitimate verifications.
14
- matcher: "/store/paypal/webhook",
15
- method: ["POST"],
16
- bodyParser: { preserveRawBody: true },
17
- middlewares: [
18
- createRateLimiter("webhook", {
19
- maxEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_MAX",
20
- windowEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS",
21
- }),
22
- ],
23
- },
24
- {
25
- // Same raw-body requirement for the /hooks mirror of the webhook route —
26
- // the path external PayPal deliveries actually reach, since Medusa's
27
- // publishable-key middleware blocks unauthenticated POSTs to /store/*.
28
- matcher: "/hooks/paypal/webhook",
29
- method: ["POST"],
30
- bodyParser: { preserveRawBody: true },
31
- middlewares: [
32
- createRateLimiter("webhook-hooks", {
33
- maxEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_MAX",
34
- windowEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS",
35
- }),
36
- ],
37
- },
38
- {
39
- // Rate-limit the order-creating route: unauthenticated by necessity, so
40
- // cap how fast one client can spin up PayPal orders on the merchant
41
- // account. Each createRateLimiter() call builds its own counter at boot.
42
- matcher: "/store/paypal/create-order",
43
- method: ["POST"],
44
- middlewares: [createRateLimiter("create-order")],
45
- },
46
- {
47
- matcher: "/store/paypal/capture-order",
48
- method: ["POST"],
49
- middlewares: [createRateLimiter("capture-order")],
50
- },
51
- {
52
- matcher: "/store/paypal-complete",
53
- method: ["POST"],
54
- middlewares: [createRateLimiter("paypal-complete")],
55
- },
56
- {
57
- matcher: "/store/paypal/:path*",
58
- middlewares: [],
59
- },
60
- ],
61
- })
1
+ import { defineMiddlewares } from "@medusajs/framework/http"
2
+ import { createRateLimiter } from "./utils/rate-limit"
3
+
4
+ export default defineMiddlewares({
5
+ routes: [
6
+ {
7
+ // Keep the exact bytes PayPal signed (`req.rawBody`) so webhook signature
8
+ // verification hashes the original payload, not a re-serialized copy. This
9
+ // entry must precede the "/store/paypal/:path*" catch-all below.
10
+ // Rate-limited (opt-in, like the store routes): every unauthenticated
11
+ // POST here costs a DB dedup read plus an outbound PayPal
12
+ // verify-webhook-signature call, and a flood of garbage requests could
13
+ // trip the shared circuit breaker for legitimate verifications.
14
+ matcher: "/store/paypal/webhook",
15
+ method: ["POST"],
16
+ bodyParser: { preserveRawBody: true },
17
+ middlewares: [
18
+ createRateLimiter("webhook", {
19
+ maxEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_MAX",
20
+ windowEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS",
21
+ }),
22
+ ],
23
+ },
24
+ {
25
+ // Same raw-body requirement for the /hooks mirror of the webhook route —
26
+ // the path external PayPal deliveries actually reach, since Medusa's
27
+ // publishable-key middleware blocks unauthenticated POSTs to /store/*.
28
+ matcher: "/hooks/paypal/webhook",
29
+ method: ["POST"],
30
+ bodyParser: { preserveRawBody: true },
31
+ middlewares: [
32
+ createRateLimiter("webhook-hooks", {
33
+ maxEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_MAX",
34
+ windowEnvVar: "PAYPAL_WEBHOOK_RATE_LIMIT_WINDOW_MS",
35
+ }),
36
+ ],
37
+ },
38
+ {
39
+ // Rate-limit the order-creating route: unauthenticated by necessity, so
40
+ // cap how fast one client can spin up PayPal orders on the merchant
41
+ // account. Each createRateLimiter() call builds its own counter at boot.
42
+ matcher: "/store/paypal/create-order",
43
+ method: ["POST"],
44
+ middlewares: [createRateLimiter("create-order")],
45
+ },
46
+ {
47
+ matcher: "/store/paypal/capture-order",
48
+ method: ["POST"],
49
+ middlewares: [createRateLimiter("capture-order")],
50
+ },
51
+ {
52
+ matcher: "/store/paypal-complete",
53
+ method: ["POST"],
54
+ middlewares: [createRateLimiter("paypal-complete")],
55
+ },
56
+ {
57
+ matcher: "/store/paypal/:path*",
58
+ middlewares: [],
59
+ },
60
+ ],
61
+ })
@@ -1,54 +1,69 @@
1
- import { MedusaResponse, MedusaStoreRequest, refetchEntity } from "@medusajs/framework/http"
2
- import { MedusaError } from "@medusajs/framework/utils"
3
- import { runCoreWorkflow } from "../../../../../modules/paypal/utils/core-workflow"
4
-
5
- type CreatePaymentSessionBody = {
6
- provider_id: string
7
- data?: Record<string, unknown>
8
- }
9
-
10
- const defaultPaymentCollectionFields = [
11
- "id",
12
- "currency_code",
13
- "amount",
14
- "*payment_sessions",
15
- ]
16
-
17
- export async function POST(req: MedusaStoreRequest, res: MedusaResponse) {
18
- const collectionId = req.params.id
19
-
20
- const { provider_id, data } = req.body as CreatePaymentSessionBody
21
-
22
- if (!provider_id || typeof provider_id !== "string") {
23
- throw new MedusaError(
24
- MedusaError.Types.INVALID_DATA,
25
- "provider_id is required to create a payment session"
26
- )
27
- }
28
-
29
- try {
30
- await runCoreWorkflow(req.scope, "create-payment-sessions", {
31
- payment_collection_id: collectionId,
32
- provider_id,
33
- customer_id: req.auth_context?.actor_id,
34
- data,
35
- })
36
- } catch (error) {
37
- const message = error instanceof Error ? error.message : String(error)
38
- throw new MedusaError(
39
- MedusaError.Types.UNEXPECTED_STATE,
40
- `Failed to create payment session for provider '${provider_id}': ${message}`
41
- )
42
- }
43
-
44
- const paymentCollection = await refetchEntity({
45
- entity: "payment_collection",
46
- idOrFilter: collectionId,
47
- scope: req.scope,
48
- fields: req.queryConfig?.fields ?? defaultPaymentCollectionFields,
49
- })
50
-
51
- res.status(200).json({
52
- payment_collection: paymentCollection,
53
- })
54
- }
1
+ import {
2
+ MedusaResponse,
3
+ MedusaStoreRequest,
4
+ refetchEntity,
5
+ } from "@medusajs/framework/http"
6
+ import { MedusaError } from "@medusajs/framework/utils"
7
+ import { runCoreWorkflow } from "../../../../../modules/paypal/utils/core-workflow"
8
+
9
+ type CreatePaymentSessionBody = {
10
+ provider_id: string
11
+ data?: Record<string, unknown>
12
+ }
13
+
14
+ /** Fields returned when the request carries no explicit `fields` query. */
15
+ const defaultPaymentCollectionFields = [
16
+ "id",
17
+ "currency_code",
18
+ "amount",
19
+ "*payment_sessions",
20
+ ]
21
+
22
+ /**
23
+ * POST /store/payment-collections/:id/payment-sessions — create a payment
24
+ * session via the core workflow and return the refreshed collection.
25
+ */
26
+ export async function POST(req: MedusaStoreRequest, res: MedusaResponse) {
27
+ const collectionId = req.params.id
28
+
29
+ const { provider_id, data } = req.body as CreatePaymentSessionBody
30
+
31
+ if (!provider_id || typeof provider_id !== "string") {
32
+ throw new MedusaError(
33
+ MedusaError.Types.INVALID_DATA,
34
+ "provider_id is required to create a payment session"
35
+ )
36
+ }
37
+
38
+ try {
39
+ await runCoreWorkflow(req.scope, "create-payment-sessions", {
40
+ payment_collection_id: collectionId,
41
+ provider_id,
42
+ customer_id: req.auth_context?.actor_id,
43
+ data,
44
+ })
45
+ } catch (error) {
46
+ // A failed core workflow rejects with the step's error, which is not
47
+ // always an `Error` instance (a plain `{ message }` object surfaces as
48
+ // "[object Object]" otherwise).
49
+ const message =
50
+ (error as { message?: unknown } | null)?.message != null
51
+ ? String((error as { message?: unknown }).message)
52
+ : String(error)
53
+ throw new MedusaError(
54
+ MedusaError.Types.UNEXPECTED_STATE,
55
+ `Failed to create payment session for provider '${provider_id}': ${message}`
56
+ )
57
+ }
58
+
59
+ const paymentCollection = await refetchEntity({
60
+ entity: "payment_collection",
61
+ idOrFilter: collectionId,
62
+ scope: req.scope,
63
+ fields: req.queryConfig?.fields ?? defaultPaymentCollectionFields,
64
+ })
65
+
66
+ res.status(200).json({
67
+ payment_collection: paymentCollection,
68
+ })
69
+ }