@webbers/pay-payments-medusa 2.2.51 → 2.2.52

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 (39) hide show
  1. package/.medusa/server/package.json +1 -1
  2. package/.medusa/server/src/admin/index.js +171 -11
  3. package/.medusa/server/src/admin/index.mjs +172 -12
  4. package/.medusa/server/src/api/admin/pay/orders/[id]/direct-debit/exchange/route.d.ts +12 -0
  5. package/.medusa/server/src/api/admin/pay/orders/[id]/direct-debit/exchange/route.d.ts.map +1 -0
  6. package/.medusa/server/src/api/admin/pay/orders/[id]/direct-debit/exchange/route.js +42 -0
  7. package/.medusa/server/src/api/admin/pay/orders/[id]/direct-debit/route.d.ts +9 -0
  8. package/.medusa/server/src/api/admin/pay/orders/[id]/direct-debit/route.d.ts.map +1 -0
  9. package/.medusa/server/src/api/admin/pay/orders/[id]/direct-debit/route.js +19 -0
  10. package/.medusa/server/src/api/admin/pay/settings/route.d.ts +12 -0
  11. package/.medusa/server/src/api/admin/pay/settings/route.d.ts.map +1 -0
  12. package/.medusa/server/src/api/admin/pay/settings/route.js +24 -0
  13. package/.medusa/server/src/providers/pay/core/pay-base.d.ts +6 -0
  14. package/.medusa/server/src/providers/pay/core/pay-base.d.ts.map +1 -1
  15. package/.medusa/server/src/providers/pay/core/pay-base.js +24 -1
  16. package/.medusa/server/src/providers/pay/services/pay-direct-debit.d.ts +6 -1
  17. package/.medusa/server/src/providers/pay/services/pay-direct-debit.d.ts.map +1 -1
  18. package/.medusa/server/src/providers/pay/services/pay-direct-debit.js +34 -15
  19. package/.medusa/server/src/providers/pay/types/index.d.ts +6 -5
  20. package/.medusa/server/src/providers/pay/types/index.d.ts.map +1 -1
  21. package/.medusa/server/src/providers/pay/types/index.js +1 -1
  22. package/.medusa/server/src/subscribers/direct-debit-exchange.d.ts.map +1 -1
  23. package/.medusa/server/src/subscribers/direct-debit-exchange.js +95 -24
  24. package/.medusa/server/src/subscribers/payment-failed.d.ts.map +1 -1
  25. package/.medusa/server/src/subscribers/payment-failed.js +23 -4
  26. package/.medusa/server/src/utils/directDebitExchange.d.ts +15 -0
  27. package/.medusa/server/src/utils/directDebitExchange.d.ts.map +1 -1
  28. package/.medusa/server/src/utils/directDebitExchange.js +59 -2
  29. package/.medusa/server/src/utils/directDebitSimulation.d.ts +93 -0
  30. package/.medusa/server/src/utils/directDebitSimulation.d.ts.map +1 -0
  31. package/.medusa/server/src/utils/directDebitSimulation.js +170 -0
  32. package/.medusa/server/src/utils/index.d.ts +1 -0
  33. package/.medusa/server/src/utils/index.d.ts.map +1 -1
  34. package/.medusa/server/src/utils/index.js +2 -1
  35. package/.medusa/server/src/utils/reverseCapturedPayment.d.ts +30 -0
  36. package/.medusa/server/src/utils/reverseCapturedPayment.d.ts.map +1 -0
  37. package/.medusa/server/src/utils/reverseCapturedPayment.js +72 -0
  38. package/README.md +43 -0
  39. package/package.json +1 -1
package/README.md CHANGED
@@ -242,6 +242,49 @@ dropdown.
242
242
 
243
243
  Make sure that the selected payment methods are enabled in your Pay origanization settings as well.
244
244
 
245
+ ### Testing direct debits locally
246
+
247
+ Pay.'s test environment does not process SEPA direct debits. With `testMode` enabled the plugin therefore does not
248
+ create a mandate at Pay. when a direct debit order is placed. It stores a simulated mandate on the payment session
249
+ instead (code `TEST-<payment session id>`, logged as `Pay. direct debit test mode: storing simulated mandate ...`), and
250
+ the collection flow can be driven by posting the exchanges Pay. would normally send to the webhook route yourself.
251
+ Exchanges for a simulated mandate are not re-fetched from Pay., the body is taken as the direct debit state. This only
252
+ happens while `testMode` is on and only for mandates that were created in test mode.
253
+
254
+ ```bash
255
+ # 1. Place an order with SEPA Direct Debit, the payment collection is now "awaiting".
256
+ # Copy the simulated mandate code from the server log.
257
+ MANDATE="TEST-payses_01JXXXXXXXXXXXXXXXXXXXXXXX"
258
+
259
+ # 2. The bank collected the money: the payment is captured and the order is paid.
260
+ curl -X POST http://localhost:9000/hooks/pay/pay-direct-debit_pay \
261
+ -H "Content-Type: application/json" \
262
+ -d "{\"action\":\"incassocollected\",\"mandateId\":\"$MANDATE\"}"
263
+
264
+ # 3. The customer reversed the debit (storno): the payment is refunded in Medusa only, the order
265
+ # shows the outstanding amount again and the admin offers "Copy payment link" / "Mark as paid".
266
+ curl -X POST http://localhost:9000/hooks/pay/pay-direct-debit_pay \
267
+ -H "Content-Type: application/json" \
268
+ -d "{\"action\":\"incassostorno\",\"mandateId\":\"$MANDATE\"}"
269
+ ```
270
+
271
+ Other legacy actions (`incassopending`, `incassosend`) and an explicit `status: {"code": 106}` (failed) or
272
+ `declined: true` work the same way. Add `"reference": "<order display id>"` to the body when the order can not be
273
+ resolved from the mandate code. The webhook route processes exchanges asynchronously (5 seconds by default), so give
274
+ the server a moment before checking the order. The payment link opens the regular Pay. hosted checkout, so the
275
+ outstanding amount can be paid with any test payment method.
276
+
277
+ #### Simulator widget in the admin
278
+
279
+ The same exchanges can be triggered from the order detail page. Switch on **SEPA testing** in Settings > Pay (off by
280
+ default, meant for staging servers) and a "Pay. direct debit simulator" panel appears in the sidebar of orders that hold
281
+ a simulated mandate, with a button per exchange (pending, sent, collected, storno, failed, declined). The exchanges are
282
+ processed synchronously, so the order refreshes right away. The switch is stored in the store's metadata
283
+ (`pay_sepa_testing`), so it applies to every admin user of that server. The panel is backed by
284
+ `GET /admin/pay/orders/:id/direct-debit` and `POST /admin/pay/orders/:id/direct-debit/exchange` (`{"action": "storno"}`),
285
+ which only work while the switch and `testMode` are on; the switch itself is read and written through
286
+ `GET`/`POST /admin/pay/settings` (`{"sepaTesting": true}`).
287
+
245
288
  ## Supported Payment Methods
246
289
 
247
290
  The plugin currently supports the following Pay payment methods:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webbers/pay-payments-medusa",
3
3
  "displayName": "Medusa v2 Pay. Plugin",
4
- "version": "2.2.51",
4
+ "version": "2.2.52",
5
5
  "description": "The Pay.nl payment provider plugin for Medusa v2",
6
6
  "author": "Webbers B.V. <development@webbers.com>",
7
7
  "license": "MIT",