@easypayment/medusa-payment-paypal 0.7.4

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 (268) hide show
  1. package/.medusa/server/src/admin/index.js +1267 -0
  2. package/.medusa/server/src/admin/index.mjs +1268 -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 +18 -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/disconnect/route.d.ts +3 -0
  8. package/.medusa/server/src/api/admin/paypal/disconnect/route.d.ts.map +1 -0
  9. package/.medusa/server/src/api/admin/paypal/disconnect/route.js +9 -0
  10. package/.medusa/server/src/api/admin/paypal/disconnect/route.js.map +1 -0
  11. package/.medusa/server/src/api/admin/paypal/environment/route.d.ts +4 -0
  12. package/.medusa/server/src/api/admin/paypal/environment/route.d.ts.map +1 -0
  13. package/.medusa/server/src/api/admin/paypal/environment/route.js +23 -0
  14. package/.medusa/server/src/api/admin/paypal/environment/route.js.map +1 -0
  15. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts +4 -0
  16. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.d.ts.map +1 -0
  17. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js +31 -0
  18. package/.medusa/server/src/api/admin/paypal/onboard-complete/route.js.map +1 -0
  19. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts +4 -0
  20. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.d.ts.map +1 -0
  21. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js +35 -0
  22. package/.medusa/server/src/api/admin/paypal/onboarding-link/route.js.map +1 -0
  23. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts +3 -0
  24. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.d.ts.map +1 -0
  25. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js +19 -0
  26. package/.medusa/server/src/api/admin/paypal/onboarding-status/route.js.map +1 -0
  27. package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts +3 -0
  28. package/.medusa/server/src/api/admin/paypal/save-credentials/route.d.ts.map +1 -0
  29. package/.medusa/server/src/api/admin/paypal/save-credentials/route.js +17 -0
  30. package/.medusa/server/src/api/admin/paypal/save-credentials/route.js.map +1 -0
  31. package/.medusa/server/src/api/admin/paypal/settings/route.d.ts +4 -0
  32. package/.medusa/server/src/api/admin/paypal/settings/route.d.ts.map +1 -0
  33. package/.medusa/server/src/api/admin/paypal/settings/route.js +14 -0
  34. package/.medusa/server/src/api/admin/paypal/settings/route.js.map +1 -0
  35. package/.medusa/server/src/api/admin/paypal/status/route.d.ts +3 -0
  36. package/.medusa/server/src/api/admin/paypal/status/route.d.ts.map +1 -0
  37. package/.medusa/server/src/api/admin/paypal/status/route.js +11 -0
  38. package/.medusa/server/src/api/admin/paypal/status/route.js.map +1 -0
  39. package/.medusa/server/src/api/middlewares.d.ts +3 -0
  40. package/.medusa/server/src/api/middlewares.d.ts.map +1 -0
  41. package/.medusa/server/src/api/middlewares.js +16 -0
  42. package/.medusa/server/src/api/middlewares.js.map +1 -0
  43. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts +3 -0
  44. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.d.ts.map +1 -0
  45. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js +43 -0
  46. package/.medusa/server/src/api/store/payment-collections/[id]/payment-sessions/route.js.map +1 -0
  47. package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts +3 -0
  48. package/.medusa/server/src/api/store/paypal/capture-order/route.d.ts.map +1 -0
  49. package/.medusa/server/src/api/store/paypal/capture-order/route.js +204 -0
  50. package/.medusa/server/src/api/store/paypal/capture-order/route.js.map +1 -0
  51. package/.medusa/server/src/api/store/paypal/config/route.d.ts +3 -0
  52. package/.medusa/server/src/api/store/paypal/config/route.d.ts.map +1 -0
  53. package/.medusa/server/src/api/store/paypal/config/route.js +77 -0
  54. package/.medusa/server/src/api/store/paypal/config/route.js.map +1 -0
  55. package/.medusa/server/src/api/store/paypal/create-order/route.d.ts +3 -0
  56. package/.medusa/server/src/api/store/paypal/create-order/route.d.ts.map +1 -0
  57. package/.medusa/server/src/api/store/paypal/create-order/route.js +361 -0
  58. package/.medusa/server/src/api/store/paypal/create-order/route.js.map +1 -0
  59. package/.medusa/server/src/api/store/paypal/settings/route.d.ts +3 -0
  60. package/.medusa/server/src/api/store/paypal/settings/route.d.ts.map +1 -0
  61. package/.medusa/server/src/api/store/paypal/settings/route.js +20 -0
  62. package/.medusa/server/src/api/store/paypal/settings/route.js.map +1 -0
  63. package/.medusa/server/src/api/store/paypal/webhook/route.d.ts +3 -0
  64. package/.medusa/server/src/api/store/paypal/webhook/route.d.ts.map +1 -0
  65. package/.medusa/server/src/api/store/paypal/webhook/route.js +250 -0
  66. package/.medusa/server/src/api/store/paypal/webhook/route.js.map +1 -0
  67. package/.medusa/server/src/api/store/paypal-complete/route.d.ts +3 -0
  68. package/.medusa/server/src/api/store/paypal-complete/route.d.ts.map +1 -0
  69. package/.medusa/server/src/api/store/paypal-complete/route.js +76 -0
  70. package/.medusa/server/src/api/store/paypal-complete/route.js.map +1 -0
  71. package/.medusa/server/src/index.d.ts +2 -0
  72. package/.medusa/server/src/index.d.ts.map +1 -0
  73. package/.medusa/server/src/index.js +9 -0
  74. package/.medusa/server/src/index.js.map +1 -0
  75. package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts +7 -0
  76. package/.medusa/server/src/jobs/paypal-webhook-retry.d.ts.map +1 -0
  77. package/.medusa/server/src/jobs/paypal-webhook-retry.js +132 -0
  78. package/.medusa/server/src/jobs/paypal-webhook-retry.js.map +1 -0
  79. package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.d.ts +15 -0
  80. package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.d.ts.map +1 -0
  81. package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js +67 -0
  82. package/.medusa/server/src/modules/paypal/clients/paypal-seller.client.js.map +1 -0
  83. package/.medusa/server/src/modules/paypal/index.d.ts +64 -0
  84. package/.medusa/server/src/modules/paypal/index.d.ts.map +1 -0
  85. package/.medusa/server/src/modules/paypal/index.js +13 -0
  86. package/.medusa/server/src/modules/paypal/index.js.map +1 -0
  87. package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.d.ts +6 -0
  88. package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.d.ts.map +1 -0
  89. package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.js +36 -0
  90. package/.medusa/server/src/modules/paypal/migrations/20260115120000_create_paypal_connection.js.map +1 -0
  91. package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.d.ts +6 -0
  92. package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.d.ts.map +1 -0
  93. package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.js +25 -0
  94. package/.medusa/server/src/modules/paypal/migrations/20260123090000_create_paypal_settings.js.map +1 -0
  95. package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.d.ts +6 -0
  96. package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.d.ts.map +1 -0
  97. package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.js +32 -0
  98. package/.medusa/server/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.js.map +1 -0
  99. package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.d.ts +6 -0
  100. package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.d.ts.map +1 -0
  101. package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.js +30 -0
  102. package/.medusa/server/src/modules/paypal/migrations/20260401090000_create_paypal_metric.js.map +1 -0
  103. package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.d.ts +6 -0
  104. package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.d.ts.map +1 -0
  105. package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.js +34 -0
  106. package/.medusa/server/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.js.map +1 -0
  107. package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.d.ts +6 -0
  108. package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.d.ts.map +1 -0
  109. package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.js +28 -0
  110. package/.medusa/server/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.js.map +1 -0
  111. package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.d.ts +6 -0
  112. package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.d.ts.map +1 -0
  113. package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.js +29 -0
  114. package/.medusa/server/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.js.map +1 -0
  115. package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.d.ts +6 -0
  116. package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.d.ts.map +1 -0
  117. package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.js +14 -0
  118. package/.medusa/server/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.js.map +1 -0
  119. package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.d.ts +6 -0
  120. package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.d.ts.map +1 -0
  121. package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.js +14 -0
  122. package/.medusa/server/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.js.map +1 -0
  123. package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.d.ts +6 -0
  124. package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.d.ts.map +1 -0
  125. package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.js +14 -0
  126. package/.medusa/server/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.js.map +1 -0
  127. package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.d.ts +6 -0
  128. package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.d.ts.map +1 -0
  129. package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.js +20 -0
  130. package/.medusa/server/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.js.map +1 -0
  131. package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts +16 -0
  132. package/.medusa/server/src/modules/paypal/models/paypal_connection.d.ts.map +1 -0
  133. package/.medusa/server/src/modules/paypal/models/paypal_connection.js +19 -0
  134. package/.medusa/server/src/modules/paypal/models/paypal_connection.js.map +1 -0
  135. package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts +7 -0
  136. package/.medusa/server/src/modules/paypal/models/paypal_metric.d.ts.map +1 -0
  137. package/.medusa/server/src/modules/paypal/models/paypal_metric.js +10 -0
  138. package/.medusa/server/src/modules/paypal/models/paypal_metric.js.map +1 -0
  139. package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts +6 -0
  140. package/.medusa/server/src/modules/paypal/models/paypal_settings.d.ts.map +1 -0
  141. package/.medusa/server/src/modules/paypal/models/paypal_settings.js +9 -0
  142. package/.medusa/server/src/modules/paypal/models/paypal_settings.js.map +1 -0
  143. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts +17 -0
  144. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.d.ts.map +1 -0
  145. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js +20 -0
  146. package/.medusa/server/src/modules/paypal/models/paypal_webhook_event.js.map +1 -0
  147. package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts +32 -0
  148. package/.medusa/server/src/modules/paypal/payment-provider/card-service.d.ts.map +1 -0
  149. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js +625 -0
  150. package/.medusa/server/src/modules/paypal/payment-provider/card-service.js.map +1 -0
  151. package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts +6 -0
  152. package/.medusa/server/src/modules/paypal/payment-provider/index.d.ts.map +1 -0
  153. package/.medusa/server/src/modules/paypal/payment-provider/index.js +18 -0
  154. package/.medusa/server/src/modules/paypal/payment-provider/index.js.map +1 -0
  155. package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts +39 -0
  156. package/.medusa/server/src/modules/paypal/payment-provider/service.d.ts.map +1 -0
  157. package/.medusa/server/src/modules/paypal/payment-provider/service.js +869 -0
  158. package/.medusa/server/src/modules/paypal/payment-provider/service.js.map +1 -0
  159. package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.d.ts +3 -0
  160. package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.d.ts.map +1 -0
  161. package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.js +74 -0
  162. package/.medusa/server/src/modules/paypal/payment-provider/webhook-utils.js.map +1 -0
  163. package/.medusa/server/src/modules/paypal/service.d.ts +266 -0
  164. package/.medusa/server/src/modules/paypal/service.d.ts.map +1 -0
  165. package/.medusa/server/src/modules/paypal/service.js +1149 -0
  166. package/.medusa/server/src/modules/paypal/service.js.map +1 -0
  167. package/.medusa/server/src/modules/paypal/types/config.d.ts +12 -0
  168. package/.medusa/server/src/modules/paypal/types/config.d.ts.map +1 -0
  169. package/.medusa/server/src/modules/paypal/types/config.js +24 -0
  170. package/.medusa/server/src/modules/paypal/types/config.js.map +1 -0
  171. package/.medusa/server/src/modules/paypal/utils/amounts.d.ts +3 -0
  172. package/.medusa/server/src/modules/paypal/utils/amounts.d.ts.map +1 -0
  173. package/.medusa/server/src/modules/paypal/utils/amounts.js +40 -0
  174. package/.medusa/server/src/modules/paypal/utils/amounts.js.map +1 -0
  175. package/.medusa/server/src/modules/paypal/utils/currencies.d.ts +19 -0
  176. package/.medusa/server/src/modules/paypal/utils/currencies.d.ts.map +1 -0
  177. package/.medusa/server/src/modules/paypal/utils/currencies.js +69 -0
  178. package/.medusa/server/src/modules/paypal/utils/currencies.js.map +1 -0
  179. package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts +10 -0
  180. package/.medusa/server/src/modules/paypal/utils/paypal-auth.d.ts.map +1 -0
  181. package/.medusa/server/src/modules/paypal/utils/paypal-auth.js +30 -0
  182. package/.medusa/server/src/modules/paypal/utils/paypal-auth.js.map +1 -0
  183. package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts +5 -0
  184. package/.medusa/server/src/modules/paypal/utils/provider-ids.d.ts.map +1 -0
  185. package/.medusa/server/src/modules/paypal/utils/provider-ids.js +16 -0
  186. package/.medusa/server/src/modules/paypal/utils/provider-ids.js.map +1 -0
  187. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts +29 -0
  188. package/.medusa/server/src/modules/paypal/webhook-processor.d.ts.map +1 -0
  189. package/.medusa/server/src/modules/paypal/webhook-processor.js +267 -0
  190. package/.medusa/server/src/modules/paypal/webhook-processor.js.map +1 -0
  191. package/.medusa/server/src/providers/paypal/index.d.ts +5 -0
  192. package/.medusa/server/src/providers/paypal/index.d.ts.map +1 -0
  193. package/.medusa/server/src/providers/paypal/index.js +10 -0
  194. package/.medusa/server/src/providers/paypal/index.js.map +1 -0
  195. package/.medusa/server/src/providers/paypal_card/index.d.ts +5 -0
  196. package/.medusa/server/src/providers/paypal_card/index.d.ts.map +1 -0
  197. package/.medusa/server/src/providers/paypal_card/index.js +10 -0
  198. package/.medusa/server/src/providers/paypal_card/index.js.map +1 -0
  199. package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts +6 -0
  200. package/.medusa/server/src/subscribers/paypal-order-invoice.d.ts.map +1 -0
  201. package/.medusa/server/src/subscribers/paypal-order-invoice.js +124 -0
  202. package/.medusa/server/src/subscribers/paypal-order-invoice.js.map +1 -0
  203. package/LICENSE +21 -0
  204. package/README.md +172 -0
  205. package/package.json +80 -0
  206. package/src/admin/index.ts +7 -0
  207. package/src/admin/routes/settings/paypal/_components/Tabs.tsx +48 -0
  208. package/src/admin/routes/settings/paypal/_components/Toast.tsx +51 -0
  209. package/src/admin/routes/settings/paypal/additional-settings/page.tsx +199 -0
  210. package/src/admin/routes/settings/paypal/advanced-card-payments/page.tsx +183 -0
  211. package/src/admin/routes/settings/paypal/apple-pay/page.tsx +5 -0
  212. package/src/admin/routes/settings/paypal/connection/page.tsx +699 -0
  213. package/src/admin/routes/settings/paypal/google-pay/page.tsx +5 -0
  214. package/src/admin/routes/settings/paypal/page.tsx +13 -0
  215. package/src/admin/routes/settings/paypal/pay-later-messaging/page.tsx +5 -0
  216. package/src/admin/routes/settings/paypal/paypal-settings/page.tsx +351 -0
  217. package/src/api/admin/payment-collections/[id]/payment-sessions/route.ts +24 -0
  218. package/src/api/admin/paypal/disconnect/route.ts +8 -0
  219. package/src/api/admin/paypal/environment/route.ts +25 -0
  220. package/src/api/admin/paypal/onboard-complete/route.ts +34 -0
  221. package/src/api/admin/paypal/onboarding-link/route.ts +45 -0
  222. package/src/api/admin/paypal/onboarding-status/route.ts +17 -0
  223. package/src/api/admin/paypal/save-credentials/route.ts +22 -0
  224. package/src/api/admin/paypal/settings/route.ts +14 -0
  225. package/src/api/admin/paypal/status/route.ts +12 -0
  226. package/src/api/middlewares.ts +14 -0
  227. package/src/api/store/payment-collections/[id]/payment-sessions/route.ts +56 -0
  228. package/src/api/store/paypal/capture-order/route.ts +265 -0
  229. package/src/api/store/paypal/config/route.ts +100 -0
  230. package/src/api/store/paypal/create-order/route.ts +449 -0
  231. package/src/api/store/paypal/settings/route.ts +19 -0
  232. package/src/api/store/paypal/webhook/route.ts +325 -0
  233. package/src/api/store/paypal-complete/route.ts +95 -0
  234. package/src/index.ts +1 -0
  235. package/src/jobs/paypal-webhook-retry.ts +149 -0
  236. package/src/modules/paypal/clients/paypal-seller.client.ts +62 -0
  237. package/src/modules/paypal/index.ts +8 -0
  238. package/src/modules/paypal/migrations/20260115120000_create_paypal_connection.ts +33 -0
  239. package/src/modules/paypal/migrations/20260123090000_create_paypal_settings.ts +22 -0
  240. package/src/modules/paypal/migrations/20260201090000_create_paypal_webhook_event.ts +29 -0
  241. package/src/modules/paypal/migrations/20260401090000_create_paypal_metric.ts +27 -0
  242. package/src/modules/paypal/migrations/20260701090000_add_paypal_webhook_event_processing.ts +31 -0
  243. package/src/modules/paypal/migrations/20261101090000_remove_paypal_reconciliation_status.ts +25 -0
  244. package/src/modules/paypal/migrations/20261201090000_remove_paypal_audit_log.ts +26 -0
  245. package/src/modules/paypal/migrations/20270101090000_set_paypal_environment_default_live.ts +11 -0
  246. package/src/modules/paypal/migrations/20270102090000_add_paypal_seller_email.ts +11 -0
  247. package/src/modules/paypal/migrations/20270103090000_add_paypal_seller_merchant_id.ts +11 -0
  248. package/src/modules/paypal/migrations/20270201000000_add_webhook_dead_letter.ts +17 -0
  249. package/src/modules/paypal/models/paypal_connection.ts +23 -0
  250. package/src/modules/paypal/models/paypal_metric.ts +9 -0
  251. package/src/modules/paypal/models/paypal_settings.ts +8 -0
  252. package/src/modules/paypal/models/paypal_webhook_event.ts +19 -0
  253. package/src/modules/paypal/payment-provider/README.md +22 -0
  254. package/src/modules/paypal/payment-provider/card-service.ts +767 -0
  255. package/src/modules/paypal/payment-provider/index.ts +15 -0
  256. package/src/modules/paypal/payment-provider/service.ts +1039 -0
  257. package/src/modules/paypal/payment-provider/webhook-utils.ts +88 -0
  258. package/src/modules/paypal/service.ts +1416 -0
  259. package/src/modules/paypal/types/config.ts +33 -0
  260. package/src/modules/paypal/utils/amounts.ts +41 -0
  261. package/src/modules/paypal/utils/currencies.ts +84 -0
  262. package/src/modules/paypal/utils/paypal-auth.ts +31 -0
  263. package/src/modules/paypal/utils/provider-ids.ts +15 -0
  264. package/src/modules/paypal/webhook-processor.ts +363 -0
  265. package/src/providers/paypal/index.ts +8 -0
  266. package/src/providers/paypal_card/index.ts +8 -0
  267. package/src/subscribers/paypal-order-invoice.ts +171 -0
  268. package/tsconfig.json +31 -0
@@ -0,0 +1,3 @@
1
+ import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
2
+ export declare function POST(req: MedusaRequest, res: MedusaResponse): Promise<void>;
3
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../../src/api/admin/payment-collections/[id]/payment-sessions/route.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAQxE,wBAAsB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,iBAcjE"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POST = POST;
4
+ const core_flows_1 = require("@medusajs/core-flows");
5
+ async function POST(req, res) {
6
+ const collectionId = req.params.id;
7
+ const { provider_id, data, customer_id } = req.body;
8
+ const { result } = await (0, core_flows_1.createPaymentSessionsWorkflow)(req.scope).run({
9
+ input: {
10
+ payment_collection_id: collectionId,
11
+ provider_id,
12
+ customer_id,
13
+ data,
14
+ },
15
+ });
16
+ res.status(200).json({ payment_session: result });
17
+ }
18
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../../src/api/admin/payment-collections/[id]/payment-sessions/route.ts"],"names":[],"mappings":";;AASA,oBAcC;AAvBD,qDAAoE;AAS7D,KAAK,UAAU,IAAI,CAAC,GAAkB,EAAE,GAAmB;IAChE,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAA;IAClC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,GAAG,CAAC,IAAgC,CAAA;IAE/E,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,0CAA6B,EAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC;QACpE,KAAK,EAAE;YACL,qBAAqB,EAAE,YAAY;YACnC,WAAW;YACX,WAAW;YACX,IAAI;SACL;KACF,CAAC,CAAA;IAEF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC,CAAA;AACnD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
2
+ export declare function POST(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
3
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/disconnect/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAG7E,wBAAsB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAIjE"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POST = POST;
4
+ async function POST(req, res) {
5
+ const paypal = req.scope.resolve("paypal_onboarding");
6
+ await paypal.disconnect();
7
+ return res.json({ ok: true });
8
+ }
9
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/disconnect/route.ts"],"names":[],"mappings":";;AAGA,oBAIC;AAJM,KAAK,UAAU,IAAI,CAAC,GAAkB,EAAE,GAAmB;IAChE,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;IAC1E,MAAM,MAAM,CAAC,UAAU,EAAE,CAAA;IACzB,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;AAC/B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
2
+ export declare function GET(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
3
+ export declare function POST(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
4
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/environment/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAO7E,wBAAsB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAIhE;AAED,wBAAsB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAWjE"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET = GET;
4
+ exports.POST = POST;
5
+ async function GET(req, res) {
6
+ const paypal = req.scope.resolve("paypal_onboarding");
7
+ const status = await paypal.getStatus();
8
+ return res.json({ environment: status.environment });
9
+ }
10
+ async function POST(req, res) {
11
+ try {
12
+ const paypal = req.scope.resolve("paypal_onboarding");
13
+ const body = (req.body || {});
14
+ const env = body.environment === "sandbox" ? "sandbox" : "live";
15
+ await paypal.setEnvironment(env);
16
+ const status = await paypal.getStatus();
17
+ return res.json(status);
18
+ }
19
+ catch (e) {
20
+ return res.status(500).json({ message: e?.message || "Unknown error" });
21
+ }
22
+ }
23
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/environment/route.ts"],"names":[],"mappings":";;AAOA,kBAIC;AAED,oBAWC;AAjBM,KAAK,UAAU,GAAG,CAAC,GAAkB,EAAE,GAAmB;IAC/D,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;IAC1E,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAA;IACvC,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;AACtD,CAAC;AAEM,KAAK,UAAU,IAAI,CAAC,GAAkB,EAAE,GAAmB;IAChE,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;QAC1E,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAS,CAAA;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAA;QAC/D,MAAM,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;QAChC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAA;QACvC,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,IAAI,eAAe,EAAE,CAAC,CAAA;IACzE,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
2
+ export declare function GET(_req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
3
+ export declare function POST(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
4
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/onboard-complete/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAG7E,wBAAsB,GAAG,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAKjE;AAED,wBAAsB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAuBjE"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET = GET;
4
+ exports.POST = POST;
5
+ async function GET(_req, res) {
6
+ return res.status(405).json({
7
+ message: "Method Not Allowed. Use POST with JSON: { authCode, sharedId, env }. This endpoint is called by the PayPal onboarding callback.",
8
+ });
9
+ }
10
+ async function POST(req, res) {
11
+ const paypal = req.scope.resolve("paypal_onboarding");
12
+ const body = req.body;
13
+ if (!body?.authCode || !body?.sharedId) {
14
+ return res.status(400).json({ message: "Missing authCode/sharedId" });
15
+ }
16
+ try {
17
+ await paypal.exchangeAndSaveSellerCredentials({
18
+ authCode: body.authCode,
19
+ sharedId: body.sharedId,
20
+ env: body.env,
21
+ });
22
+ return res.json({ ok: true });
23
+ }
24
+ catch (e) {
25
+ console.error("[PayPal] onboard-complete failed", e);
26
+ return res.status(500).json({
27
+ message: e?.message || "Failed to exchange and save PayPal credentials",
28
+ });
29
+ }
30
+ }
31
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/onboard-complete/route.ts"],"names":[],"mappings":";;AAGA,kBAKC;AAED,oBAuBC;AA9BM,KAAK,UAAU,GAAG,CAAC,IAAmB,EAAE,GAAmB;IAChE,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QAC1B,OAAO,EACL,iIAAiI;KACpI,CAAC,CAAA;AACJ,CAAC;AAEM,KAAK,UAAU,IAAI,CAAC,GAAkB,EAAE,GAAmB;IAChE,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;IAC1E,MAAM,IAAI,GAAG,GAAG,CAAC,IAA0E,CAAA;IAE3F,IAAI,CAAC,IAAI,EAAE,QAAQ,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC;QACvC,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,2BAA2B,EAAE,CAAC,CAAA;IACvE,CAAC;IAED,IAAI,CAAC;QAEH,MAAM,MAAM,CAAC,gCAAgC,CAAC;YAC5C,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAC,CAAA;QAEF,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAC/B,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,CAAC,CAAC,CAAA;QACpD,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YAC1B,OAAO,EAAE,CAAC,EAAE,OAAO,IAAI,gDAAgD;SACxE,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { AuthenticatedMedusaRequest, MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
2
+ export declare function POST(req: AuthenticatedMedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
3
+ export declare function GET(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
4
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/onboarding-link/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACb,cAAc,EACf,MAAM,0BAA0B,CAAA;AAQjC,wBAAsB,IAAI,CAAC,GAAG,EAAE,0BAA0B,EAAE,GAAG,EAAE,cAAc,2BA0B9E;AAED,wBAAsB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAIhE"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POST = POST;
4
+ exports.GET = GET;
5
+ async function POST(req, res) {
6
+ try {
7
+ const paypal = req.scope.resolve("paypal_onboarding");
8
+ const body = (req.body || {});
9
+ const authEmail = typeof req.auth_context?.user_metadata?.email === "string"
10
+ ? String(req.auth_context.user_metadata.email)
11
+ : undefined;
12
+ const email = authEmail ?? body.email ?? "admin@paypal.com";
13
+ const link = await paypal.createOnboardingLink({
14
+ email,
15
+ products: body.products,
16
+ });
17
+ return res.json({
18
+ status: "pending",
19
+ onboarding_url: link.onboarding_url,
20
+ return_url: link.return_url,
21
+ });
22
+ }
23
+ catch (e) {
24
+ console.error("[paypal_onboarding] onboarding-link error:", e?.message || e, e?.stack);
25
+ return res.status(500).json({
26
+ message: e?.message || "Unknown error",
27
+ });
28
+ }
29
+ }
30
+ async function GET(req, res) {
31
+ return res.status(405).json({
32
+ message: "Use POST /admin/paypal/onboarding-link",
33
+ });
34
+ }
35
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/onboarding-link/route.ts"],"names":[],"mappings":";;AAYA,oBA0BC;AAED,kBAIC;AAhCM,KAAK,UAAU,IAAI,CAAC,GAA+B,EAAE,GAAmB;IAC7E,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;QAC1E,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAS,CAAA;QACrC,MAAM,SAAS,GACb,OAAO,GAAG,CAAC,YAAY,EAAE,aAAa,EAAE,KAAK,KAAK,QAAQ;YACxD,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC;YAC9C,CAAC,CAAC,SAAS,CAAA;QACf,MAAM,KAAK,GAAG,SAAS,IAAI,IAAI,CAAC,KAAK,IAAI,kBAAkB,CAAA;QAE3D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC;YAC7C,KAAK;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAA;QAEF,OAAO,GAAG,CAAC,IAAI,CAAC;YACd,MAAM,EAAE,SAAS;YACjB,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,CAAC,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;QACtF,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YAC1B,OAAO,EAAE,CAAC,EAAE,OAAO,IAAI,eAAe;SACvC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,GAAG,CAAC,GAAkB,EAAE,GAAmB;IAC/D,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QAC1B,OAAO,EAAE,wCAAwC;KAClD,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
2
+ export declare function GET(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
3
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/onboarding-status/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAG7E,wBAAsB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAahE"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET = GET;
4
+ async function GET(req, res) {
5
+ try {
6
+ const paypal = req.scope.resolve("paypal_onboarding");
7
+ const status = await paypal.getStatus();
8
+ return res.json(status);
9
+ }
10
+ catch (e) {
11
+ console.error("[paypal_onboarding] onboarding-status error:", e?.message || e, e?.stack);
12
+ return res.json({
13
+ environment: "live",
14
+ status: "disconnected",
15
+ error: e?.message || "Unknown error",
16
+ });
17
+ }
18
+ }
19
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/onboarding-status/route.ts"],"names":[],"mappings":";;AAGA,kBAaC;AAbM,KAAK,UAAU,GAAG,CAAC,GAAkB,EAAE,GAAmB;IAC/D,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;QAC1E,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAA;QACvC,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,8CAA8C,EAAE,CAAC,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;QACxF,OAAO,GAAG,CAAC,IAAI,CAAC;YACd,WAAW,EAAE,MAAM;YACnB,MAAM,EAAE,cAAc;YACtB,KAAK,EAAE,CAAC,EAAE,OAAO,IAAI,eAAe;SACrC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
2
+ export declare function POST(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
3
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/save-credentials/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAG7E,wBAAsB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAkBjE"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POST = POST;
4
+ async function POST(req, res) {
5
+ const paypal = req.scope.resolve("paypal_onboarding");
6
+ const body = req.body;
7
+ if (!body?.clientId || !body?.clientSecret) {
8
+ return res.status(400).json({ message: "Missing clientId/clientSecret" });
9
+ }
10
+ await paypal.saveAndHydrateSellerCredentials({
11
+ clientId: body.clientId,
12
+ clientSecret: body.clientSecret,
13
+ environment: body.environment,
14
+ });
15
+ return res.json({ ok: true });
16
+ }
17
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/save-credentials/route.ts"],"names":[],"mappings":";;AAGA,oBAkBC;AAlBM,KAAK,UAAU,IAAI,CAAC,GAAkB,EAAE,GAAmB;IAChE,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;IAC1E,MAAM,IAAI,GAAG,GAAG,CAAC,IAIhB,CAAA;IAED,IAAI,CAAC,IAAI,EAAE,QAAQ,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC;QAC3C,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,+BAA+B,EAAE,CAAC,CAAA;IAC3E,CAAC;IAED,MAAM,MAAM,CAAC,+BAA+B,CAAC;QAC3C,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,WAAW,EAAE,IAAI,CAAC,WAAW;KAC9B,CAAC,CAAA;IACF,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;AAC/B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
2
+ export declare function GET(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
3
+ export declare function POST(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
4
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/settings/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAG7E,wBAAsB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAGhE;AAED,wBAAsB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAKjE"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET = GET;
4
+ exports.POST = POST;
5
+ async function GET(req, res) {
6
+ const paypal = req.scope.resolve("paypal_onboarding");
7
+ return res.json(await paypal.getSettings());
8
+ }
9
+ async function POST(req, res) {
10
+ const paypal = req.scope.resolve("paypal_onboarding");
11
+ const patch = (req.body && typeof req.body === "object") ? req.body : {};
12
+ return res.json(await paypal.saveSettings(patch));
13
+ }
14
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/settings/route.ts"],"names":[],"mappings":";;AAGA,kBAGC;AAED,oBAKC;AAVM,KAAK,UAAU,GAAG,CAAC,GAAkB,EAAE,GAAmB;IAC/D,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;IAC1E,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;AAC7C,CAAC;AAEM,KAAK,UAAU,IAAI,CAAC,GAAkB,EAAE,GAAmB;IAChE,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;IAE1E,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,IAA4B,CAAC,CAAC,CAAC,EAAE,CAAA;IACjG,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;AACnD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
2
+ export declare function GET(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
3
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/status/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAG7E,wBAAsB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAQhE"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET = GET;
4
+ async function GET(req, res) {
5
+ const paypal = req.scope.resolve("paypal_onboarding");
6
+ const q = (req.query || {});
7
+ const envParam = (q.environment || q.env);
8
+ const env = envParam === "live" ? "live" : envParam === "sandbox" ? "sandbox" : undefined;
9
+ return res.json(await paypal.getStatus(env));
10
+ }
11
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../src/api/admin/paypal/status/route.ts"],"names":[],"mappings":";;AAGA,kBAQC;AARM,KAAK,UAAU,GAAG,CAAC,GAAkB,EAAE,GAAmB;IAC/D,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAsB,mBAAmB,CAAC,CAAA;IAE1E,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAwB,CAAA;IAClD,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,GAAG,CAAuB,CAAA;IAC/D,MAAM,GAAG,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAA;IAEzF,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;AAC9C,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@medusajs/framework/http").MiddlewaresConfig;
2
+ export default _default;
3
+ //# sourceMappingURL=middlewares.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middlewares.d.ts","sourceRoot":"","sources":["../../../../src/api/middlewares.ts"],"names":[],"mappings":";AAEA,wBAWE"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const http_1 = require("@medusajs/framework/http");
4
+ exports.default = (0, http_1.defineMiddlewares)({
5
+ routes: [
6
+ {
7
+ matcher: "/store/paypal-complete",
8
+ middlewares: [],
9
+ },
10
+ {
11
+ matcher: "/store/paypal/:path*",
12
+ middlewares: [],
13
+ },
14
+ ],
15
+ });
16
+ //# sourceMappingURL=middlewares.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../../../../src/api/middlewares.ts"],"names":[],"mappings":";;AAAA,mDAA4D;AAE5D,kBAAe,IAAA,wBAAiB,EAAC;IAC/B,MAAM,EAAE;QACN;YACE,OAAO,EAAE,wBAAwB;YACjC,WAAW,EAAE,EAAE;SAChB;QACD;YACE,OAAO,EAAE,sBAAsB;YAC/B,WAAW,EAAE,EAAE;SAChB;KACF;CACF,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { MedusaResponse, MedusaStoreRequest } from "@medusajs/framework/http";
2
+ export declare function POST(req: MedusaStoreRequest, res: MedusaResponse): Promise<void>;
3
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../../src/api/store/payment-collections/[id]/payment-sessions/route.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAiB,MAAM,0BAA0B,CAAA;AAe5F,wBAAsB,IAAI,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,cAAc,iBAuCtE"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POST = POST;
4
+ const core_flows_1 = require("@medusajs/core-flows");
5
+ const http_1 = require("@medusajs/framework/http");
6
+ const utils_1 = require("@medusajs/framework/utils");
7
+ const defaultPaymentCollectionFields = [
8
+ "id",
9
+ "currency_code",
10
+ "amount",
11
+ "*payment_sessions",
12
+ ];
13
+ async function POST(req, res) {
14
+ const collectionId = req.params.id;
15
+ const { provider_id, data } = req.body;
16
+ if (!provider_id || typeof provider_id !== "string") {
17
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "provider_id is required to create a payment session");
18
+ }
19
+ try {
20
+ await (0, core_flows_1.createPaymentSessionsWorkflow)(req.scope).run({
21
+ input: {
22
+ payment_collection_id: collectionId,
23
+ provider_id,
24
+ customer_id: req.auth_context?.actor_id,
25
+ data,
26
+ },
27
+ });
28
+ }
29
+ catch (error) {
30
+ const message = error instanceof Error ? error.message : String(error);
31
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.UNEXPECTED_STATE, `Failed to create payment session for provider '${provider_id}': ${message}`);
32
+ }
33
+ const paymentCollection = await (0, http_1.refetchEntity)({
34
+ entity: "payment_collection",
35
+ idOrFilter: collectionId,
36
+ scope: req.scope,
37
+ fields: req.queryConfig?.fields ?? defaultPaymentCollectionFields,
38
+ });
39
+ res.status(200).json({
40
+ payment_collection: paymentCollection,
41
+ });
42
+ }
43
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../../src/api/store/payment-collections/[id]/payment-sessions/route.ts"],"names":[],"mappings":";;AAgBA,oBAuCC;AAvDD,qDAAoE;AACpE,mDAA4F;AAC5F,qDAAuD;AAOvD,MAAM,8BAA8B,GAAG;IACrC,IAAI;IACJ,eAAe;IACf,QAAQ;IACR,mBAAmB;CACpB,CAAA;AAEM,KAAK,UAAU,IAAI,CAAC,GAAuB,EAAE,GAAmB;IACrE,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAA;IAElC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAgC,CAAA;IAElE,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpD,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,qDAAqD,CACtD,CAAA;IACH,CAAC;IAED,IAAI,CAAC;QACH,MAAM,IAAA,0CAA6B,EAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC;YACjD,KAAK,EAAE;gBACL,qBAAqB,EAAE,YAAY;gBACnC,WAAW;gBACX,WAAW,EAAE,GAAG,CAAC,YAAY,EAAE,QAAQ;gBACvC,IAAI;aACL;SACF,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACtE,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,gBAAgB,EAClC,kDAAkD,WAAW,MAAM,OAAO,EAAE,CAC7E,CAAA;IACH,CAAC;IAED,MAAM,iBAAiB,GAAG,MAAM,IAAA,oBAAa,EAAC;QAC5C,MAAM,EAAE,oBAAoB;QAC5B,UAAU,EAAE,YAAY;QACxB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,WAAW,EAAE,MAAM,IAAI,8BAA8B;KAClE,CAAC,CAAA;IAEF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QACnB,kBAAkB,EAAE,iBAAiB;KACtC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
2
+ export declare function POST(req: MedusaRequest, res: MedusaResponse): Promise<MedusaResponse>;
3
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../../src/api/store/paypal/capture-order/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAgL7E,wBAAsB,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,2BAwFjE"}
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POST = POST;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ const crypto_1 = require("crypto");
6
+ const paypal_auth_1 = require("../../../../modules/paypal/utils/paypal-auth");
7
+ const provider_ids_1 = require("../../../../modules/paypal/utils/provider-ids");
8
+ const BN_CODE = "MBJTechnolabs_SI_SPB";
9
+ function resolveIdempotencyKey(req, suffix, fallback) {
10
+ const header = req.headers["idempotency-key"] ||
11
+ req.headers["Idempotency-Key"] ||
12
+ req.headers["x-idempotency-key"] ||
13
+ req.headers["X-Idempotency-Key"];
14
+ const key = Array.isArray(header) ? header[0] : header;
15
+ if (key && String(key).trim()) {
16
+ return `${String(key).trim()}-${suffix}`;
17
+ }
18
+ return fallback || `pp-${suffix}-${(0, crypto_1.randomUUID)()}`;
19
+ }
20
+ async function findPayPalSessionForCart(cartId, scope) {
21
+ try {
22
+ const query = scope.resolve("query");
23
+ const { data: carts } = await query.graph({
24
+ entity: "cart",
25
+ fields: [
26
+ "id",
27
+ "payment_collection.payment_sessions.id",
28
+ "payment_collection.payment_sessions.data",
29
+ "payment_collection.payment_sessions.status",
30
+ "payment_collection.payment_sessions.provider_id",
31
+ "payment_collection.payment_sessions.created_at",
32
+ ],
33
+ filters: { id: cartId },
34
+ });
35
+ const cart = carts?.[0];
36
+ const sessions = cart?.payment_collection?.payment_sessions || [];
37
+ const session = sessions
38
+ .filter((s) => (0, provider_ids_1.isPayPalProviderId)(s.provider_id))
39
+ .sort((a, b) => new Date(b.created_at || 0).getTime() - new Date(a.created_at || 0).getTime())[0];
40
+ if (!session)
41
+ return null;
42
+ return {
43
+ session_id: session.id,
44
+ session_data: (session.data || {}),
45
+ session_status: session.status,
46
+ };
47
+ }
48
+ catch (e) {
49
+ console.warn("[PayPal] findPayPalSessionForCart failed:", e?.message);
50
+ return null;
51
+ }
52
+ }
53
+ async function updatePayPalSession(sessionId, status, extraData, scope) {
54
+ try {
55
+ const paymentModule = scope.resolve(utils_1.Modules.PAYMENT);
56
+ const [existing] = await paymentModule.listPaymentSessions({ id: [sessionId] }, { take: 1 });
57
+ const mergedData = { ...(existing?.data || {}), ...extraData };
58
+ await paymentModule.updatePaymentSession({
59
+ id: sessionId,
60
+ data: mergedData,
61
+ status: status,
62
+ amount: existing?.amount,
63
+ currency_code: existing?.currency_code,
64
+ });
65
+ }
66
+ catch (e) {
67
+ console.error("[PayPal] updatePayPalSession failed:", e?.message);
68
+ }
69
+ }
70
+ async function attachPayPalCaptureToSession(cartId, orderId, capture, scope) {
71
+ try {
72
+ const session = await findPayPalSessionForCart(cartId, scope);
73
+ if (!session) {
74
+ console.warn("[PayPal] attachPayPalCaptureToSession: no session found for cart", cartId);
75
+ return;
76
+ }
77
+ const captureId = capture?.purchase_units?.[0]?.payments?.captures?.[0]?.id || capture?.id;
78
+ await updatePayPalSession(session.session_id, "captured", {
79
+ paypal: {
80
+ ...((session.session_data || {}).paypal || {}),
81
+ order_id: orderId,
82
+ capture_id: captureId,
83
+ capture,
84
+ },
85
+ }, scope);
86
+ }
87
+ catch {
88
+ }
89
+ }
90
+ async function attachPayPalAuthorizationToSession(cartId, orderId, authorization, scope) {
91
+ try {
92
+ const session = await findPayPalSessionForCart(cartId, scope);
93
+ if (!session) {
94
+ console.warn("[PayPal] attachPayPalAuthorizationToSession: no session found for cart", cartId);
95
+ return;
96
+ }
97
+ const authorizationId = authorization?.purchase_units?.[0]?.payments?.authorizations?.[0]?.id;
98
+ await updatePayPalSession(session.session_id, "authorized", {
99
+ paypal: {
100
+ ...((session.session_data || {}).paypal || {}),
101
+ order_id: orderId,
102
+ authorization_id: authorizationId,
103
+ authorization,
104
+ },
105
+ }, scope);
106
+ }
107
+ catch {
108
+ }
109
+ }
110
+ async function getExistingCapture(cartId, orderId, scope) {
111
+ try {
112
+ const session = await findPayPalSessionForCart(cartId, scope);
113
+ if (!session)
114
+ return null;
115
+ const paypalData = (session.session_data || {}).paypal || {};
116
+ const existingOrderId = String(paypalData.order_id || "");
117
+ if (existingOrderId && existingOrderId !== orderId)
118
+ return null;
119
+ if (paypalData.capture)
120
+ return paypalData.capture;
121
+ if (paypalData.capture_id)
122
+ return { id: paypalData.capture_id };
123
+ return null;
124
+ }
125
+ catch {
126
+ return null;
127
+ }
128
+ }
129
+ async function POST(req, res) {
130
+ const paypal = req.scope.resolve("paypal_onboarding");
131
+ const { scope } = req;
132
+ let debugId = null;
133
+ try {
134
+ const body = (req.body || {});
135
+ const cartId = body.cart_id;
136
+ const orderId = body.order_id;
137
+ if (!cartId || !orderId) {
138
+ return res.status(400).json({ message: "cart_id and order_id are required" });
139
+ }
140
+ const existingCapture = await getExistingCapture(cartId, orderId, scope);
141
+ if (existingCapture) {
142
+ return res.json({ capture: existingCapture });
143
+ }
144
+ const creds = await paypal.getActiveCredentials();
145
+ const { accessToken, base } = await (0, paypal_auth_1.getPayPalAccessToken)(creds);
146
+ const settings = await paypal.getSettings().catch(() => ({}));
147
+ const data = settings && typeof settings === "object" && "data" in settings
148
+ ? (settings.data ?? {})
149
+ : {};
150
+ const additionalSettings = (data.additional_settings || {});
151
+ const paymentAction = typeof additionalSettings.paymentAction === "string"
152
+ ? additionalSettings.paymentAction
153
+ : "capture";
154
+ const requestId = resolveIdempotencyKey(req, "capture-order", `pp-capture-${orderId}`);
155
+ const endpoint = paymentAction === "authorize"
156
+ ? `${base}/v2/checkout/orders/${orderId}/authorize`
157
+ : `${base}/v2/checkout/orders/${orderId}/capture`;
158
+ const ppResp = await fetch(endpoint, {
159
+ method: "POST",
160
+ headers: {
161
+ Authorization: `Bearer ${accessToken}`,
162
+ "Content-Type": "application/json",
163
+ "PayPal-Request-Id": requestId,
164
+ "PayPal-Partner-Attribution-Id": BN_CODE,
165
+ },
166
+ });
167
+ const ppText = await ppResp.text();
168
+ debugId = ppResp.headers.get("paypal-debug-id");
169
+ if (!ppResp.ok) {
170
+ throw new Error(`PayPal capture error (${ppResp.status}): ${ppText}${debugId ? ` debug_id=${debugId}` : ""}`);
171
+ }
172
+ const payload = JSON.parse(ppText);
173
+ if (paymentAction === "authorize") {
174
+ await attachPayPalAuthorizationToSession(cartId, orderId, payload, req.scope);
175
+ }
176
+ else {
177
+ await attachPayPalCaptureToSession(cartId, orderId, payload, req.scope);
178
+ }
179
+ try {
180
+ await paypal.recordMetric(paymentAction === "authorize" ? "authorize_order_success" : "capture_order_success");
181
+ }
182
+ catch {
183
+ }
184
+ return paymentAction === "authorize"
185
+ ? res.json({ authorization: payload })
186
+ : res.json({ capture: payload });
187
+ }
188
+ catch (e) {
189
+ try {
190
+ const body = (req.body || {});
191
+ await paypal.recordAuditEvent("capture_order_failed", {
192
+ cart_id: body.cart_id,
193
+ order_id: body.order_id,
194
+ debug_id: debugId,
195
+ message: e?.message || String(e),
196
+ });
197
+ await paypal.recordMetric("capture_order_failed");
198
+ }
199
+ catch {
200
+ }
201
+ return res.status(500).json({ message: e?.message || "Failed to capture PayPal order" });
202
+ }
203
+ }
204
+ //# sourceMappingURL=route.js.map