@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,139 +1,246 @@
1
- import React, { useCallback, useEffect, useRef, useState } from "react"
2
- import PayPalTabs from "../_components/Tabs"
3
- import SectionCard from "../_components/SectionCard"
4
- import FieldRow from "../_components/FieldRow"
5
- import Toast, { ToastState } from "../_components/Toast"
6
- import { adminFetch } from "../_utils/adminFetch"
7
-
8
- type PaymentAction = "capture" | "authorize"
9
- type LandingPage = "no_preference" | "login" | "billing"
10
-
11
- type AdditionalSettingsForm = {
12
- paymentAction: PaymentAction
13
- brandName: string
14
- landingPage: LandingPage
15
- requireInstantPayment: boolean
16
- sendItemDetails: boolean
17
- invoicePrefix: string
18
- creditCardStatementName: string
19
- }
20
-
21
- const DEFAULT_FORM: AdditionalSettingsForm = {
22
- paymentAction: "capture",
23
- brandName: "PayPal",
24
- landingPage: "no_preference",
25
- requireInstantPayment: false,
26
- sendItemDetails: true,
27
- invoicePrefix: "PP-",
28
- creditCardStatementName: "PayPal",
29
- }
30
-
31
- function mergeWithDefaults(saved?: Partial<AdditionalSettingsForm> | null) {
32
- if (!saved) return { ...DEFAULT_FORM }
33
- const entries = Object.entries(saved).filter(([, value]) => value !== undefined)
34
- return { ...DEFAULT_FORM, ...(Object.fromEntries(entries) as Partial<AdditionalSettingsForm>) }
35
- }
36
-
37
- export default function AdditionalSettingsTab() {
38
- const [form, setForm] = useState<AdditionalSettingsForm>(() => ({ ...DEFAULT_FORM }))
39
- const [loading, setLoading] = useState(false)
40
- const [saving, setSaving] = useState(false)
41
- const [toast, setToast] = useState<ToastState>(null)
42
- const didInit = useRef(false)
43
-
44
- const dismissToast = useCallback(() => setToast(null), [])
45
-
46
- useEffect(() => {
47
- if (didInit.current) return
48
- didInit.current = true
49
- ;(async () => {
50
- try {
51
- setLoading(true)
52
- const json = await adminFetch<any>("/admin/paypal/settings")
53
- const payload = json?.data ?? json
54
- const saved = payload?.additional_settings
55
- if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved))
56
- } catch {
57
- } finally {
58
- setLoading(false)
59
- }
60
- })()
61
- }, [])
62
-
63
- async function onSave() {
64
- try {
65
- setSaving(true)
66
- setToast(null)
67
- const json = await adminFetch<any>("/admin/paypal/settings", { method: "POST", body: { additional_settings: form as unknown as Record<string, unknown> } })
68
- const payload = json?.data ?? json
69
- const saved = payload?.additional_settings
70
- if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved))
71
- setToast({ kind: "success", message: "Settings saved" })
72
- } catch (e: unknown) {
73
- setToast({ kind: "error", message: e instanceof Error ? e.message : "Failed to save settings" })
74
- } finally {
75
- setSaving(false)
76
- }
77
- }
78
-
79
- return (
80
- <div className="p-6">
81
- <div className="flex flex-col gap-6">
82
- <div className="flex items-start justify-between gap-4">
83
- <div><h1 className="text-xl font-semibold text-ui-fg-base">PayPal Gateway By Easy Payment</h1></div>
84
- </div>
85
- <PayPalTabs />
86
- <Toast toast={toast} onClose={dismissToast} />
87
- <SectionCard
88
- title="Additional Settings"
89
- description="These settings control checkout behavior and PayPal experience."
90
- right={(
91
- <div className="flex items-center gap-3">
92
- <button type="button" onClick={onSave} disabled={saving || loading} className="transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5">
93
- {saving ? "Saving..." : "Save settings"}
94
- </button>
95
- {loading ? <span className="text-sm text-ui-fg-subtle">Loading…</span> : null}
96
- </div>
97
- )}
98
- >
99
- <div className="divide-y divide-ui-border-base">
100
- <FieldRow label="Payment action" htmlFor="as-payment-action">
101
- <select id="as-payment-action" value={form.paymentAction} onChange={(e) => setForm((p) => ({ ...p, paymentAction: e.target.value as PaymentAction }))} className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive">
102
- <option value="capture">Capture</option>
103
- <option value="authorize">Authorize</option>
104
- </select>
105
- </FieldRow>
106
- <FieldRow label="Brand Name" htmlFor="as-brand-name">
107
- <input id="as-brand-name" value={form.brandName} onChange={(e) => setForm((p) => ({ ...p, brandName: e.target.value }))} className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive" placeholder="PayPal" />
108
- </FieldRow>
109
- <FieldRow label="Landing Page" htmlFor="as-landing-page">
110
- <select id="as-landing-page" value={form.landingPage} onChange={(e) => setForm((p) => ({ ...p, landingPage: e.target.value as LandingPage }))} className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive">
111
- <option value="no_preference">No Preference</option>
112
- <option value="login">Login</option>
113
- <option value="billing">Billing</option>
114
- </select>
115
- </FieldRow>
116
- <FieldRow label="Instant Payments">
117
- <label className="inline-flex items-center gap-2">
118
- <input type="checkbox" checked={form.requireInstantPayment} onChange={(e) => setForm((p) => ({ ...p, requireInstantPayment: e.target.checked }))} className="h-4 w-4 rounded border-ui-border-base" />
119
- <span className="text-sm text-ui-fg-base">Require Instant Payment</span>
120
- </label>
121
- </FieldRow>
122
- <FieldRow label="Send Item Details" hint="Include all line item details in the payment request to PayPal so that they can be seen from the PayPal transaction details page.">
123
- <label className="inline-flex items-center gap-2">
124
- <input type="checkbox" checked={form.sendItemDetails} onChange={(e) => setForm((p) => ({ ...p, sendItemDetails: e.target.checked }))} className="h-4 w-4 rounded border-ui-border-base" />
125
- <span className="text-sm text-ui-fg-base">Send line item details to PayPal</span>
126
- </label>
127
- </FieldRow>
128
- <FieldRow label="Invoice prefix" htmlFor="as-invoice-prefix">
129
- <input id="as-invoice-prefix" value={form.invoicePrefix} onChange={(e) => setForm((p) => ({ ...p, invoicePrefix: e.target.value }))} className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive" placeholder="PP-" />
130
- </FieldRow>
131
- <FieldRow label="Credit Card Statement Name" htmlFor="as-cc-statement">
132
- <input id="as-cc-statement" value={form.creditCardStatementName} onChange={(e) => setForm((p) => ({ ...p, creditCardStatementName: e.target.value }))} className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive" placeholder="PayPal" />
133
- </FieldRow>
134
- </div>
135
- </SectionCard>
136
- </div>
137
- </div>
138
- )
139
- }
1
+ import React, { useCallback, useEffect, useRef, useState } from "react"
2
+ import PayPalTabs from "../_components/Tabs"
3
+ import SectionCard from "../_components/SectionCard"
4
+ import FieldRow from "../_components/FieldRow"
5
+ import Toast, { ToastState } from "../_components/Toast"
6
+ import { adminFetch } from "../_utils/adminFetch"
7
+
8
+ type PaymentAction = "capture" | "authorize"
9
+ type LandingPage = "no_preference" | "login" | "billing"
10
+
11
+ type AdditionalSettingsForm = {
12
+ paymentAction: PaymentAction
13
+ brandName: string
14
+ landingPage: LandingPage
15
+ requireInstantPayment: boolean
16
+ sendItemDetails: boolean
17
+ invoicePrefix: string
18
+ creditCardStatementName: string
19
+ }
20
+
21
+ const DEFAULT_FORM: AdditionalSettingsForm = {
22
+ paymentAction: "capture",
23
+ brandName: "PayPal",
24
+ landingPage: "no_preference",
25
+ requireInstantPayment: false,
26
+ sendItemDetails: true,
27
+ invoicePrefix: "PP-",
28
+ creditCardStatementName: "PayPal",
29
+ }
30
+
31
+ /** Overlay saved values on the defaults, ignoring `undefined` entries. */
32
+ function mergeWithDefaults(saved?: Partial<AdditionalSettingsForm> | null) {
33
+ if (!saved) return { ...DEFAULT_FORM }
34
+ const entries = Object.entries(saved).filter(
35
+ ([, value]) => value !== undefined
36
+ )
37
+ return {
38
+ ...DEFAULT_FORM,
39
+ ...(Object.fromEntries(entries) as Partial<AdditionalSettingsForm>),
40
+ }
41
+ }
42
+
43
+ /** Settings → PayPal → Additional Settings (checkout behaviour + invoice options). */
44
+ export default function AdditionalSettingsTab() {
45
+ const [form, setForm] = useState<AdditionalSettingsForm>(() => ({
46
+ ...DEFAULT_FORM,
47
+ }))
48
+ const [loading, setLoading] = useState(false)
49
+ const [saving, setSaving] = useState(false)
50
+ const [toast, setToast] = useState<ToastState>(null)
51
+ const didInit = useRef(false)
52
+
53
+ const dismissToast = useCallback(() => setToast(null), [])
54
+
55
+ useEffect(() => {
56
+ if (didInit.current) return
57
+ didInit.current = true
58
+ ;(async () => {
59
+ try {
60
+ setLoading(true)
61
+ const json = await adminFetch<any>("/admin/paypal/settings")
62
+ const payload = json?.data ?? json
63
+ const saved = payload?.additional_settings
64
+ if (saved && typeof saved === "object")
65
+ setForm(mergeWithDefaults(saved))
66
+ } catch {
67
+ // Keep the defaults if settings can't be loaded; saving still works.
68
+ } finally {
69
+ setLoading(false)
70
+ }
71
+ })()
72
+ }, [])
73
+
74
+ async function onSave() {
75
+ try {
76
+ setSaving(true)
77
+ setToast(null)
78
+ const json = await adminFetch<any>("/admin/paypal/settings", {
79
+ method: "POST",
80
+ body: {
81
+ additional_settings: form as unknown as Record<string, unknown>,
82
+ },
83
+ })
84
+ const payload = json?.data ?? json
85
+ const saved = payload?.additional_settings
86
+ if (saved && typeof saved === "object") setForm(mergeWithDefaults(saved))
87
+ setToast({ kind: "success", message: "Settings saved" })
88
+ } catch (e: unknown) {
89
+ setToast({
90
+ kind: "error",
91
+ message: e instanceof Error ? e.message : "Failed to save settings",
92
+ })
93
+ } finally {
94
+ setSaving(false)
95
+ }
96
+ }
97
+
98
+ return (
99
+ <div className="p-6">
100
+ <div className="flex flex-col gap-6">
101
+ <div className="flex items-start justify-between gap-4">
102
+ <div>
103
+ <h1 className="text-xl font-semibold text-ui-fg-base">
104
+ PayPal Gateway By Easy Payment
105
+ </h1>
106
+ </div>
107
+ </div>
108
+ <PayPalTabs />
109
+ <Toast toast={toast} onClose={dismissToast} />
110
+ <SectionCard
111
+ title="Additional Settings"
112
+ description="These settings control checkout behavior and PayPal experience."
113
+ right={
114
+ <div className="flex items-center gap-3">
115
+ <button
116
+ type="button"
117
+ onClick={onSave}
118
+ disabled={saving || loading}
119
+ className="transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none shadow-buttons-neutral text-ui-fg-base bg-ui-button-neutral after:transition-fg after:absolute after:inset-0 after:content-[''] after:button-neutral-gradient hover:bg-ui-button-neutral-hover hover:after:button-neutral-hover-gradient active:bg-ui-button-neutral-pressed active:after:button-neutral-pressed-gradient focus-visible:shadow-buttons-neutral-focus disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden txt-compact-small-plus px-3 py-1.5"
120
+ >
121
+ {saving ? "Saving..." : "Save settings"}
122
+ </button>
123
+ {loading ? (
124
+ <span className="text-sm text-ui-fg-subtle">Loading…</span>
125
+ ) : null}
126
+ </div>
127
+ }
128
+ >
129
+ <div className="divide-y divide-ui-border-base">
130
+ <FieldRow label="Payment action" htmlFor="as-payment-action">
131
+ <select
132
+ id="as-payment-action"
133
+ value={form.paymentAction}
134
+ onChange={(e) =>
135
+ setForm((p) => ({
136
+ ...p,
137
+ paymentAction: e.target.value as PaymentAction,
138
+ }))
139
+ }
140
+ className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive"
141
+ >
142
+ <option value="capture">Capture</option>
143
+ <option value="authorize">Authorize</option>
144
+ </select>
145
+ </FieldRow>
146
+ <FieldRow label="Brand Name" htmlFor="as-brand-name">
147
+ <input
148
+ id="as-brand-name"
149
+ value={form.brandName}
150
+ onChange={(e) =>
151
+ setForm((p) => ({ ...p, brandName: e.target.value }))
152
+ }
153
+ className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive"
154
+ placeholder="PayPal"
155
+ />
156
+ </FieldRow>
157
+ <FieldRow label="Landing Page" htmlFor="as-landing-page">
158
+ <select
159
+ id="as-landing-page"
160
+ value={form.landingPage}
161
+ onChange={(e) =>
162
+ setForm((p) => ({
163
+ ...p,
164
+ landingPage: e.target.value as LandingPage,
165
+ }))
166
+ }
167
+ className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive"
168
+ >
169
+ <option value="no_preference">No Preference</option>
170
+ <option value="login">Login</option>
171
+ <option value="billing">Billing</option>
172
+ </select>
173
+ </FieldRow>
174
+ <FieldRow label="Instant Payments">
175
+ <label className="inline-flex items-center gap-2">
176
+ <input
177
+ type="checkbox"
178
+ checked={form.requireInstantPayment}
179
+ onChange={(e) =>
180
+ setForm((p) => ({
181
+ ...p,
182
+ requireInstantPayment: e.target.checked,
183
+ }))
184
+ }
185
+ className="h-4 w-4 rounded border-ui-border-base"
186
+ />
187
+ <span className="text-sm text-ui-fg-base">
188
+ Require Instant Payment
189
+ </span>
190
+ </label>
191
+ </FieldRow>
192
+ <FieldRow
193
+ label="Send Item Details"
194
+ hint="Include all line item details in the payment request to PayPal so that they can be seen from the PayPal transaction details page."
195
+ >
196
+ <label className="inline-flex items-center gap-2">
197
+ <input
198
+ type="checkbox"
199
+ checked={form.sendItemDetails}
200
+ onChange={(e) =>
201
+ setForm((p) => ({
202
+ ...p,
203
+ sendItemDetails: e.target.checked,
204
+ }))
205
+ }
206
+ className="h-4 w-4 rounded border-ui-border-base"
207
+ />
208
+ <span className="text-sm text-ui-fg-base">
209
+ Send line item details to PayPal
210
+ </span>
211
+ </label>
212
+ </FieldRow>
213
+ <FieldRow label="Invoice prefix" htmlFor="as-invoice-prefix">
214
+ <input
215
+ id="as-invoice-prefix"
216
+ value={form.invoicePrefix}
217
+ onChange={(e) =>
218
+ setForm((p) => ({ ...p, invoicePrefix: e.target.value }))
219
+ }
220
+ className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive"
221
+ placeholder="PP-"
222
+ />
223
+ </FieldRow>
224
+ <FieldRow
225
+ label="Credit Card Statement Name"
226
+ htmlFor="as-cc-statement"
227
+ >
228
+ <input
229
+ id="as-cc-statement"
230
+ value={form.creditCardStatementName}
231
+ onChange={(e) =>
232
+ setForm((p) => ({
233
+ ...p,
234
+ creditCardStatementName: e.target.value,
235
+ }))
236
+ }
237
+ className="w-full rounded-md border border-ui-border-base bg-ui-bg-base px-3 py-2 text-sm text-ui-fg-base outline-none focus:ring-2 focus:ring-ui-border-interactive"
238
+ placeholder="PayPal"
239
+ />
240
+ </FieldRow>
241
+ </div>
242
+ </SectionCard>
243
+ </div>
244
+ </div>
245
+ )
246
+ }