@unchainedshop/plugins 4.0.0-rc.2 → 4.0.0-rc.21
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.
- package/lib/accounts/google-oauth.d.ts +4 -0
- package/lib/accounts/google-oauth.d.ts.map +1 -0
- package/lib/accounts/google-oauth.js +145 -0
- package/lib/accounts/google-oauth.js.map +1 -0
- package/lib/accounts/linkedin-oauth.d.ts +4 -0
- package/lib/accounts/linkedin-oauth.d.ts.map +1 -0
- package/lib/accounts/linkedin-oauth.js +82 -0
- package/lib/accounts/linkedin-oauth.js.map +1 -0
- package/lib/delivery/send-message.js.map +1 -1
- package/lib/enrollments/licensed.js +15 -2
- package/lib/enrollments/licensed.js.map +1 -1
- package/lib/files/gridfs/adapter.d.ts.map +1 -1
- package/lib/files/gridfs/adapter.js +19 -11
- package/lib/files/gridfs/adapter.js.map +1 -1
- package/lib/files/gridfs/gridfs-adapter.d.ts +3 -0
- package/lib/files/gridfs/gridfs-adapter.d.ts.map +1 -0
- package/lib/files/gridfs/gridfs-adapter.js +97 -0
- package/lib/files/gridfs/gridfs-adapter.js.map +1 -0
- package/lib/files/gridfs/gridfs-webhook.d.ts +11 -0
- package/lib/files/gridfs/gridfs-webhook.d.ts.map +1 -0
- package/lib/files/gridfs/gridfs-webhook.js +84 -0
- package/lib/files/gridfs/gridfs-webhook.js.map +1 -0
- package/lib/files/gridfs/handler-express.d.ts.map +1 -1
- package/lib/files/gridfs/handler-express.js +27 -24
- package/lib/files/gridfs/handler-express.js.map +1 -1
- package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
- package/lib/files/gridfs/handler-fastify.js +57 -14
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/gridfs/module.d.ts +4 -4
- package/lib/files/gridfs/module.d.ts.map +1 -1
- package/lib/files/gridfs/module.js +2 -2
- package/lib/files/gridfs/module.js.map +1 -1
- package/lib/files/minio/handler-express.d.ts.map +1 -1
- package/lib/files/minio/handler-express.js +4 -7
- package/lib/files/minio/handler-express.js.map +1 -1
- package/lib/files/minio/handler-fastify.js +2 -2
- package/lib/files/minio/handler-fastify.js.map +1 -1
- package/lib/files/minio/index.d.ts +1 -1
- package/lib/files/minio/index.d.ts.map +1 -1
- package/lib/files/minio/index.js +7 -7
- package/lib/files/minio/index.js.map +1 -1
- package/lib/files/minio/minio-adapter.d.ts +6 -0
- package/lib/files/minio/minio-adapter.d.ts.map +1 -0
- package/lib/files/minio/minio-adapter.js +181 -0
- package/lib/files/minio/minio-adapter.js.map +1 -0
- package/lib/files/minio/minio-webhook.d.ts +2 -0
- package/lib/files/minio/minio-webhook.d.ts.map +1 -0
- package/lib/files/minio/minio-webhook.js +33 -0
- package/lib/files/minio/minio-webhook.js.map +1 -0
- package/lib/filters/local-search.js +1 -1
- package/lib/filters/local-search.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +12 -10
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +1 -1
- package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts.map +1 -1
- package/lib/payment/apple-iap/handler-express.d.ts.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +14 -10
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.d.ts.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +15 -8
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +9 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +1 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +17 -0
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +1 -0
- package/lib/payment/apple-iap/module.d.ts +4 -4
- package/lib/payment/apple-iap/module.d.ts.map +1 -1
- package/lib/payment/apple-iap/module.js +4 -2
- package/lib/payment/apple-iap/module.js.map +1 -1
- package/lib/payment/braintree.js +3 -1
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
- package/lib/payment/cryptopay/derive-btc-address.d.ts.map +1 -1
- package/lib/payment/cryptopay/derive-btc-address.js +2 -3
- package/lib/payment/cryptopay/derive-btc-address.js.map +1 -1
- package/lib/payment/cryptopay/derive-eth-address.d.ts.map +1 -1
- package/lib/payment/cryptopay/derive-eth-address.js +5 -3
- package/lib/payment/cryptopay/derive-eth-address.js.map +1 -1
- package/lib/payment/cryptopay/handle-webhook.js +2 -2
- package/lib/payment/cryptopay/handle-webhook.js.map +1 -1
- package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +4 -7
- package/lib/payment/cryptopay/handler-express.js.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.js +1 -1
- package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/middleware.d.ts +2 -0
- package/lib/payment/cryptopay/middleware.d.ts.map +1 -0
- package/lib/payment/cryptopay/middleware.js +75 -0
- package/lib/payment/cryptopay/middleware.js.map +1 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +25 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +1 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.js +75 -0
- package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +1 -0
- package/lib/payment/cryptopay/module.d.ts +2 -2
- package/lib/payment/cryptopay/module.d.ts.map +1 -1
- package/lib/payment/cryptopay/module.js +4 -4
- package/lib/payment/cryptopay/module.js.map +1 -1
- package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
- package/lib/payment/cryptopay/plugin.js +18 -4
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/handler-express.js +13 -11
- package/lib/payment/datatrans-v2/handler-express.js.map +1 -1
- package/lib/payment/datatrans-v2/handler-fastify.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/handler-fastify.js +11 -5
- package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -1
- package/lib/payment/datatrans-v2/index.js +63 -37
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/middleware.d.ts +2 -0
- package/lib/payment/datatrans-v2/middleware.d.ts.map +1 -0
- package/lib/payment/datatrans-v2/middleware.js +68 -0
- package/lib/payment/datatrans-v2/middleware.js.map +1 -0
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts +1 -1
- package/lib/payment/datatrans-v2/parseRegistrationData.d.ts.map +1 -1
- package/lib/payment/paypal-checkout.js +8 -8
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/api/index.d.ts +1 -1
- package/lib/payment/payrexx/api/index.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
- package/lib/payment/payrexx/handler-express.d.ts.map +1 -1
- package/lib/payment/payrexx/handler-express.js +15 -15
- package/lib/payment/payrexx/handler-express.js.map +1 -1
- package/lib/payment/payrexx/handler-fastify.js +23 -15
- package/lib/payment/payrexx/handler-fastify.js.map +1 -1
- package/lib/payment/payrexx/index.js +21 -15
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/middleware.d.ts +2 -0
- package/lib/payment/payrexx/middleware.d.ts.map +1 -0
- package/lib/payment/payrexx/middleware.js +86 -0
- package/lib/payment/payrexx/middleware.js.map +1 -0
- package/lib/payment/postfinance-checkout/api-client.d.ts +16 -0
- package/lib/payment/postfinance-checkout/api-client.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/api-client.js +75 -0
- package/lib/payment/postfinance-checkout/api-client.js.map +1 -0
- package/lib/payment/postfinance-checkout/api-types.d.ts +98 -0
- package/lib/payment/postfinance-checkout/api-types.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/api-types.js +51 -0
- package/lib/payment/postfinance-checkout/api-types.js.map +1 -0
- package/lib/payment/postfinance-checkout/api.d.ts +5 -5
- package/lib/payment/postfinance-checkout/api.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/api.js +38 -62
- package/lib/payment/postfinance-checkout/api.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.js +10 -11
- package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.js +10 -8
- package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.d.ts +2 -1
- package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +44 -32
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/middleware.d.ts +2 -0
- package/lib/payment/postfinance-checkout/middleware.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/middleware.js +38 -0
- package/lib/payment/postfinance-checkout/middleware.js.map +1 -0
- package/lib/payment/postfinance-checkout/utils.d.ts +3 -3
- package/lib/payment/postfinance-checkout/utils.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/utils.js +3 -4
- package/lib/payment/postfinance-checkout/utils.js.map +1 -1
- package/lib/payment/saferpay/adapter.d.ts.map +1 -1
- package/lib/payment/saferpay/adapter.js +9 -0
- package/lib/payment/saferpay/adapter.js.map +1 -1
- package/lib/payment/saferpay/handler-express.d.ts.map +1 -1
- package/lib/payment/saferpay/handler-express.js +10 -8
- package/lib/payment/saferpay/handler-express.js.map +1 -1
- package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -1
- package/lib/payment/saferpay/handler-fastify.js +11 -5
- package/lib/payment/saferpay/handler-fastify.js.map +1 -1
- package/lib/payment/saferpay/middleware.d.ts +2 -0
- package/lib/payment/saferpay/middleware.d.ts.map +1 -0
- package/lib/payment/saferpay/middleware.js +57 -0
- package/lib/payment/saferpay/middleware.js.map +1 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +10 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +1 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +24 -0
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +1 -0
- package/lib/payment/saferpay/module.d.ts +2 -2
- package/lib/payment/stripe/handler-express.js +25 -17
- package/lib/payment/stripe/handler-express.js.map +1 -1
- package/lib/payment/stripe/handler-fastify.d.ts.map +1 -1
- package/lib/payment/stripe/handler-fastify.js +33 -12
- package/lib/payment/stripe/handler-fastify.js.map +1 -1
- package/lib/payment/stripe/index.js +19 -13
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/middleware.d.ts +6 -0
- package/lib/payment/stripe/middleware.d.ts.map +1 -0
- package/lib/payment/stripe/middleware.js +114 -0
- package/lib/payment/stripe/middleware.js.map +1 -0
- package/lib/payment/stripe/stripe.d.ts +2 -2
- package/lib/payment/stripe/stripe.d.ts.map +1 -1
- package/lib/payment/stripe/stripe.js +14 -11
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/plugins-index.d.ts +48 -0
- package/lib/plugins-index.d.ts.map +1 -0
- package/lib/plugins-index.js +107 -0
- package/lib/plugins-index.js.map +1 -0
- package/lib/presets/all.d.ts +9 -7
- package/lib/presets/all.d.ts.map +1 -1
- package/lib/presets/all.js +3 -1
- package/lib/presets/all.js.map +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +13 -20
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/order-discount.d.ts.map +1 -1
- package/lib/pricing/order-discount.js +5 -3
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +4 -3
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +26 -2
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +3 -3
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +1 -5
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +26 -22
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/pricing/tax/ch.d.ts +7 -2
- package/lib/pricing/tax/ch.d.ts.map +1 -1
- package/lib/pricing/tax/ch.js +16 -1
- package/lib/pricing/tax/ch.js.map +1 -1
- package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts +7 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.d.ts.map +1 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.js +13 -0
- package/lib/pricing/utils/isDeliveryAddressInCountry.js.map +1 -0
- package/lib/warehousing/eth-minter.js +23 -11
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/budgetsms.d.ts +10 -0
- package/lib/worker/budgetsms.d.ts.map +1 -0
- package/lib/worker/budgetsms.js +217 -0
- package/lib/worker/budgetsms.js.map +1 -0
- package/lib/worker/bulk-import.d.ts +1 -1
- package/lib/worker/bulk-import.d.ts.map +1 -1
- package/lib/worker/bulk-import.js +11 -33
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/bulkgate.d.ts +2 -0
- package/lib/worker/bulkgate.d.ts.map +1 -0
- package/lib/worker/bulkgate.js +104 -0
- package/lib/worker/bulkgate.js.map +1 -0
- package/lib/worker/email.d.ts.map +1 -1
- package/lib/worker/email.js +25 -7
- package/lib/worker/email.js.map +1 -1
- package/lib/worker/enrollment-order-generator.d.ts.map +1 -1
- package/lib/worker/enrollment-order-generator.js +7 -49
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/error-notifications.js +1 -1
- package/lib/worker/error-notifications.js.map +1 -1
- package/lib/worker/export-token.d.ts.map +1 -1
- package/lib/worker/export-token.js +0 -1
- package/lib/worker/export-token.js.map +1 -1
- package/lib/worker/heartbeat.js +2 -8
- package/lib/worker/heartbeat.js.map +1 -1
- package/lib/worker/message.d.ts +1 -1
- package/lib/worker/message.d.ts.map +1 -1
- package/lib/worker/message.js +4 -2
- package/lib/worker/message.js.map +1 -1
- package/lib/worker/sms.js +16 -16
- package/lib/worker/sms.js.map +1 -1
- package/lib/worker/twilio.d.ts +2 -0
- package/lib/worker/twilio.d.ts.map +1 -0
- package/lib/worker/twilio.js +60 -0
- package/lib/worker/twilio.js.map +1 -0
- package/package.json +29 -45
- package/src/delivery/send-message.ts +1 -1
- package/src/enrollments/licensed.ts +15 -2
- package/src/files/gridfs/adapter.ts +24 -10
- package/src/files/gridfs/handler-express.ts +32 -24
- package/src/files/gridfs/handler-fastify.ts +63 -15
- package/src/files/gridfs/module.ts +7 -2
- package/src/files/minio/handler-express.ts +4 -7
- package/src/files/minio/handler-fastify.ts +2 -2
- package/src/files/minio/index.ts +16 -16
- package/src/filters/local-search.ts +1 -1
- package/src/payment/apple-iap/adapter.ts +12 -14
- package/src/payment/apple-iap/db/AppleTransactionsCollection.ts +1 -1
- package/src/payment/apple-iap/handler-express.ts +17 -11
- package/src/payment/apple-iap/handler-fastify.ts +19 -9
- package/src/payment/apple-iap/module.ts +9 -4
- package/src/payment/braintree.ts +4 -1
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -1
- package/src/payment/cryptopay/derive-btc-address.ts +1 -3
- package/src/payment/cryptopay/derive-eth-address.ts +5 -3
- package/src/payment/cryptopay/handle-webhook.ts +6 -6
- package/src/payment/cryptopay/handler-express.ts +4 -7
- package/src/payment/cryptopay/handler-fastify.ts +2 -2
- package/src/payment/cryptopay/module.ts +8 -5
- package/src/payment/cryptopay/plugin.ts +21 -4
- package/src/payment/datatrans-v2/handler-express.ts +17 -12
- package/src/payment/datatrans-v2/handler-fastify.ts +15 -6
- package/src/payment/datatrans-v2/index.ts +82 -50
- package/src/payment/paypal-checkout.ts +8 -11
- package/src/payment/payrexx/api/index.ts +1 -1
- package/src/payment/payrexx/api/makeFetcher.ts +2 -2
- package/src/payment/payrexx/handler-express.ts +24 -32
- package/src/payment/payrexx/handler-fastify.ts +33 -33
- package/src/payment/payrexx/index.ts +26 -16
- package/src/payment/postfinance-checkout/api-client.ts +111 -0
- package/src/payment/postfinance-checkout/api-types.ts +111 -0
- package/src/payment/postfinance-checkout/api.ts +58 -85
- package/src/payment/postfinance-checkout/handler-express.ts +11 -13
- package/src/payment/postfinance-checkout/handler-fastify.ts +11 -10
- package/src/payment/postfinance-checkout/index.ts +60 -38
- package/src/payment/postfinance-checkout/utils.ts +5 -10
- package/src/payment/saferpay/adapter.ts +14 -2
- package/src/payment/saferpay/handler-express.ts +14 -13
- package/src/payment/saferpay/handler-fastify.ts +14 -9
- package/src/payment/stripe/handler-express.ts +33 -33
- package/src/payment/stripe/handler-fastify.ts +40 -27
- package/src/payment/stripe/index.ts +17 -13
- package/src/payment/stripe/stripe.ts +17 -12
- package/src/presets/all.ts +3 -1
- package/src/pricing/delivery-swiss-tax.ts +16 -31
- package/src/pricing/order-discount.ts +6 -4
- package/src/pricing/order-round.ts +5 -4
- package/src/pricing/product-catalog-price.ts +25 -2
- package/src/pricing/product-price-rateconversion.ts +3 -3
- package/src/pricing/product-swiss-tax.ts +39 -40
- package/src/pricing/tax/ch.ts +33 -7
- package/src/pricing/utils/isDeliveryAddressInCountry.test.ts +106 -0
- package/src/pricing/utils/isDeliveryAddressInCountry.ts +26 -0
- package/src/warehousing/eth-minter.ts +30 -11
- package/src/worker/budgetsms.ts +268 -0
- package/src/worker/bulk-import.ts +12 -53
- package/src/worker/bulkgate.ts +138 -0
- package/src/worker/email.ts +30 -8
- package/src/worker/enrollment-order-generator.ts +14 -72
- package/src/worker/error-notifications.ts +2 -2
- package/src/worker/export-token.ts +0 -1
- package/src/worker/heartbeat.ts +2 -9
- package/src/worker/message.ts +5 -3
- package/src/worker/{sms.ts → twilio.ts} +15 -26
- package/lib/payment/cryptopay/de.d.ts +0 -2
- package/lib/payment/cryptopay/de.d.ts.map +0 -1
- package/lib/payment/cryptopay/de.js +0 -10
- package/lib/payment/cryptopay/de.js.map +0 -1
- package/lib/payment/cryptopay/derive-btc-address.test copy.d.ts +0 -2
- package/lib/payment/cryptopay/derive-btc-address.test copy.d.ts.map +0 -1
- package/lib/payment/cryptopay/derive-btc-address.test copy.js +0 -10
- package/lib/payment/cryptopay/derive-btc-address.test copy.js.map +0 -1
- package/src/pricing/product-swiss-tax.test.ts +0 -139
|
@@ -3,7 +3,7 @@ import { createLogger } from '@unchainedshop/logger';
|
|
|
3
3
|
import { WebhookData } from './types.js';
|
|
4
4
|
import { getTransaction, getTransactionCompletion } from './api.js';
|
|
5
5
|
|
|
6
|
-
const logger = createLogger('unchained:
|
|
6
|
+
const logger = createLogger('unchained:postfinance-checkout:handler');
|
|
7
7
|
|
|
8
8
|
export const postfinanceCheckoutHandler = async (req, res) => {
|
|
9
9
|
const context = req.unchainedContext as Context;
|
|
@@ -13,7 +13,7 @@ export const postfinanceCheckoutHandler = async (req, res) => {
|
|
|
13
13
|
try {
|
|
14
14
|
const transactionCompletion = await getTransactionCompletion(data.entityId as unknown as string);
|
|
15
15
|
const transaction = await getTransaction(
|
|
16
|
-
transactionCompletion
|
|
16
|
+
transactionCompletion ? (transactionCompletion as any).linkedTransaction : data.entityId,
|
|
17
17
|
);
|
|
18
18
|
const { orderPaymentId } = transaction.metaData as { orderPaymentId: string };
|
|
19
19
|
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
@@ -26,21 +26,19 @@ export const postfinanceCheckoutHandler = async (req, res) => {
|
|
|
26
26
|
transactionId: transactionCompletion.linkedTransaction,
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
|
+
|
|
30
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
31
|
+
|
|
29
32
|
logger.info(
|
|
30
|
-
`
|
|
33
|
+
`Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData?.orderPaymentId} as paid`,
|
|
31
34
|
);
|
|
32
|
-
res.
|
|
33
|
-
res.end(`Order marked as paid: ${order.orderNumber}`);
|
|
35
|
+
res.status(200).send(`Order marked as paid: ${order.orderNumber}`);
|
|
34
36
|
} catch (e) {
|
|
35
|
-
logger.error(
|
|
36
|
-
res.
|
|
37
|
-
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
37
|
+
logger.error(e);
|
|
38
|
+
res.status(500).send({ name: e.name, code: e.code, message: e.message });
|
|
38
39
|
}
|
|
39
40
|
} else {
|
|
40
|
-
logger.error(
|
|
41
|
-
|
|
42
|
-
);
|
|
43
|
-
res.writeHead(404);
|
|
44
|
-
res.end();
|
|
41
|
+
logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
|
|
42
|
+
res.status(404).end();
|
|
45
43
|
}
|
|
46
44
|
};
|
|
@@ -4,7 +4,7 @@ import { WebhookData } from './types.js';
|
|
|
4
4
|
import { getTransaction, getTransactionCompletion } from './api.js';
|
|
5
5
|
import { FastifyRequest, RouteHandlerMethod } from 'fastify';
|
|
6
6
|
|
|
7
|
-
const logger = createLogger('unchained:
|
|
7
|
+
const logger = createLogger('unchained:postfinance-checkout:handler');
|
|
8
8
|
|
|
9
9
|
export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
|
|
10
10
|
req: FastifyRequest & {
|
|
@@ -19,7 +19,7 @@ export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
|
|
|
19
19
|
try {
|
|
20
20
|
const transactionCompletion = await getTransactionCompletion(data.entityId as unknown as string);
|
|
21
21
|
const transaction = await getTransaction(
|
|
22
|
-
transactionCompletion
|
|
22
|
+
transactionCompletion ? (transactionCompletion as any).linkedTransaction : data.entityId,
|
|
23
23
|
);
|
|
24
24
|
const { orderPaymentId } = transaction.metaData as { orderPaymentId: string };
|
|
25
25
|
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
@@ -29,23 +29,24 @@ export const postfinanceCheckoutHandler: RouteHandlerMethod = async (
|
|
|
29
29
|
|
|
30
30
|
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
31
31
|
paymentContext: {
|
|
32
|
-
transactionId:
|
|
32
|
+
transactionId: transaction.id,
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
|
+
|
|
36
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
37
|
+
|
|
35
38
|
logger.info(
|
|
36
|
-
`
|
|
39
|
+
`Transaction ${transaction.id} marked order payment ID ${transaction.metaData?.orderPaymentId} as paid`,
|
|
37
40
|
);
|
|
38
41
|
reply.status(200);
|
|
39
|
-
return reply.send(
|
|
42
|
+
return reply.send({ success: true, orderNumber: order.orderNumber });
|
|
40
43
|
} catch (e) {
|
|
41
|
-
logger.error(
|
|
44
|
+
logger.error(e);
|
|
42
45
|
reply.status(500);
|
|
43
|
-
return reply.send({ name: e.name, code: e.code, message: e.message });
|
|
46
|
+
return reply.send({ success: false, name: e.name, code: e.code, message: e.message });
|
|
44
47
|
}
|
|
45
48
|
} else {
|
|
46
|
-
logger.error(
|
|
47
|
-
`PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`,
|
|
48
|
-
);
|
|
49
|
+
logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
|
|
49
50
|
reply.status(404);
|
|
50
51
|
return reply.send();
|
|
51
52
|
}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
PaymentDirector,
|
|
9
9
|
PaymentError,
|
|
10
10
|
} from '@unchainedshop/core';
|
|
11
|
-
import * as pf from 'postfinancecheckout';
|
|
12
11
|
|
|
13
12
|
import {
|
|
14
13
|
confirmDeferredTransaction,
|
|
@@ -23,8 +22,15 @@ import {
|
|
|
23
22
|
} from './api.js';
|
|
24
23
|
import { orderIsPaid } from './utils.js';
|
|
25
24
|
import { CompletionModes, IntegrationModes, SignResponse } from './types.js';
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
import {
|
|
26
|
+
TransactionCreate,
|
|
27
|
+
LineItem,
|
|
28
|
+
LineItemType,
|
|
29
|
+
TokenizationMode,
|
|
30
|
+
TransactionCompletionBehavior,
|
|
31
|
+
TransactionState,
|
|
32
|
+
CreationEntityState,
|
|
33
|
+
} from './api-types.js';
|
|
28
34
|
|
|
29
35
|
const {
|
|
30
36
|
PFCHECKOUT_SPACE_ID,
|
|
@@ -34,7 +40,7 @@ const {
|
|
|
34
40
|
PFCHECKOUT_FAILED_URL,
|
|
35
41
|
} = process.env;
|
|
36
42
|
|
|
37
|
-
const logger = createLogger('unchained:
|
|
43
|
+
const logger = createLogger('unchained:postfinance-checkout');
|
|
38
44
|
|
|
39
45
|
const newError = ({ code, message }: { code: string; message: string }) => {
|
|
40
46
|
const error = new Error(message);
|
|
@@ -92,12 +98,16 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
92
98
|
if (!credentials.meta) return false;
|
|
93
99
|
const { linkedSpaceId } = credentials.meta;
|
|
94
100
|
const tokenData = await getToken(linkedSpaceId, credentials.token);
|
|
95
|
-
return tokenData.state ===
|
|
101
|
+
return tokenData.state === CreationEntityState.ACTIVE;
|
|
96
102
|
},
|
|
97
103
|
|
|
98
104
|
sign: async (transactionContext: any = {}) => {
|
|
99
105
|
const { orderPayment, order } = context;
|
|
100
106
|
|
|
107
|
+
if (!order) throw new Error('No order in context, can only sign with order context');
|
|
108
|
+
if (!orderPayment)
|
|
109
|
+
throw new Error('No order payment in context, can only sign with order payment context');
|
|
110
|
+
|
|
101
111
|
const { integrationMode = IntegrationModes.PaymentPage }: { integrationMode: IntegrationModes } =
|
|
102
112
|
transactionContext;
|
|
103
113
|
const completionMode = adapter.getCompletionMode();
|
|
@@ -107,39 +117,43 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
107
117
|
});
|
|
108
118
|
|
|
109
119
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
110
|
-
const transaction =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
120
|
+
const transaction: TransactionCreate = {
|
|
121
|
+
currency: order.currencyCode,
|
|
122
|
+
metaData: {
|
|
123
|
+
orderPaymentId: orderPayment._id,
|
|
124
|
+
},
|
|
125
|
+
successUrl: `${transactionContext?.successUrl || PFCHECKOUT_SUCCESS_URL}?order_id=${
|
|
126
|
+
orderPayment.orderId
|
|
127
|
+
}`,
|
|
128
|
+
failedUrl: `${transactionContext?.failedUrl || PFCHECKOUT_FAILED_URL}?order_id=${
|
|
129
|
+
orderPayment.orderId
|
|
130
|
+
}`,
|
|
131
|
+
customerId: order?.userId || context?.userId,
|
|
132
|
+
tokenizationMode: TokenizationMode.ALLOW_ONE_CLICK_PAYMENT,
|
|
115
133
|
};
|
|
116
|
-
|
|
117
|
-
orderPayment.orderId
|
|
118
|
-
}`;
|
|
119
|
-
transaction.failedUrl = `${transactionContext?.failedUrl || PFCHECKOUT_FAILED_URL}?order_id=${
|
|
120
|
-
orderPayment.orderId
|
|
121
|
-
}`;
|
|
122
|
-
transaction.customerId = userId;
|
|
123
|
-
transaction.tokenizationMode =
|
|
124
|
-
PostFinanceCheckout.model.TokenizationMode.ALLOW_ONE_CLICK_PAYMENT;
|
|
134
|
+
|
|
125
135
|
if (completionMode === CompletionModes.Immediate) {
|
|
126
|
-
transaction.completionBehavior =
|
|
127
|
-
PostFinanceCheckout.model.TransactionCompletionBehavior.COMPLETE_IMMEDIATELY;
|
|
136
|
+
transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_IMMEDIATELY;
|
|
128
137
|
} else if (completionMode === CompletionModes.Deferred) {
|
|
129
|
-
transaction.completionBehavior =
|
|
130
|
-
PostFinanceCheckout.model.TransactionCompletionBehavior.COMPLETE_DEFERRED;
|
|
138
|
+
transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_DEFERRED;
|
|
131
139
|
}
|
|
140
|
+
|
|
132
141
|
if (totalAmount) {
|
|
133
|
-
const lineItemSum =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
const lineItemSum: LineItem = {
|
|
143
|
+
name: `Bestellung ${orderPayment.orderId}`,
|
|
144
|
+
type: LineItemType.FEE,
|
|
145
|
+
quantity: 1,
|
|
146
|
+
uniqueId: orderPayment.orderId,
|
|
147
|
+
amountIncludingTax: totalAmount / 100,
|
|
148
|
+
};
|
|
139
149
|
transaction.lineItems = [lineItemSum];
|
|
140
150
|
}
|
|
151
|
+
|
|
141
152
|
const transactionId = await createTransaction(transaction);
|
|
142
|
-
|
|
153
|
+
|
|
154
|
+
if (!transactionId) throw new Error('Could not create transaction');
|
|
155
|
+
|
|
156
|
+
let location: string | null = null;
|
|
143
157
|
if (integrationMode === IntegrationModes.PaymentPage) {
|
|
144
158
|
location = await getPaymentPageUrl(transactionId);
|
|
145
159
|
} else if (integrationMode === IntegrationModes.Lightbox) {
|
|
@@ -178,7 +192,11 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
178
192
|
});
|
|
179
193
|
}
|
|
180
194
|
|
|
181
|
-
const
|
|
195
|
+
const { order, orderPayment } = context;
|
|
196
|
+
if (!orderPayment) throw new Error('No order payment in context, cannot charge payment');
|
|
197
|
+
if (!order) throw new Error('No order in context, can only sign with order context');
|
|
198
|
+
|
|
199
|
+
const isPaid = await orderIsPaid(order, transaction);
|
|
182
200
|
if (!isPaid) {
|
|
183
201
|
logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
|
|
184
202
|
throw newError({
|
|
@@ -187,7 +205,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
187
205
|
});
|
|
188
206
|
}
|
|
189
207
|
|
|
190
|
-
if (transaction.metaData
|
|
208
|
+
if (transaction.metaData?.orderPaymentId !== orderPayment._id) {
|
|
191
209
|
logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
|
|
192
210
|
throw newError({
|
|
193
211
|
code: `TRANSACTION_ALREADY_USED`,
|
|
@@ -209,12 +227,13 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
209
227
|
|
|
210
228
|
cancel: async () => {
|
|
211
229
|
const { orderPayment, order } = context;
|
|
212
|
-
|
|
213
|
-
if (!transactionId) {
|
|
230
|
+
if (!order) throw new Error('No order in context, can only cancel with order context');
|
|
231
|
+
if (!orderPayment?.transactionId) {
|
|
214
232
|
return false;
|
|
215
233
|
}
|
|
234
|
+
const { transactionId } = orderPayment;
|
|
216
235
|
const transaction = await getTransaction(transactionId);
|
|
217
|
-
const refund = transaction.state ===
|
|
236
|
+
const refund = transaction.state === TransactionState.FULFILL;
|
|
218
237
|
const pricing = OrderPricingSheet({
|
|
219
238
|
calculation: order.calculation,
|
|
220
239
|
currencyCode: order.currencyCode,
|
|
@@ -230,12 +249,12 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
230
249
|
|
|
231
250
|
confirm: async () => {
|
|
232
251
|
const { orderPayment } = context;
|
|
233
|
-
|
|
234
|
-
if (!transactionId) {
|
|
252
|
+
if (!orderPayment?.transactionId) {
|
|
235
253
|
return false;
|
|
236
254
|
}
|
|
255
|
+
const { transactionId } = orderPayment;
|
|
237
256
|
const transaction = await getTransaction(transactionId);
|
|
238
|
-
if (transaction.state ===
|
|
257
|
+
if (transaction.state === TransactionState.AUTHORIZED) {
|
|
239
258
|
return confirmDeferredTransaction(transactionId);
|
|
240
259
|
}
|
|
241
260
|
return false;
|
|
@@ -247,3 +266,6 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
247
266
|
};
|
|
248
267
|
|
|
249
268
|
PaymentDirector.registerAdapter(PostfinanceCheckout);
|
|
269
|
+
|
|
270
|
+
export * from './types.js';
|
|
271
|
+
export * from './api-types.js';
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { OrderPricingSheet } from '@unchainedshop/core';
|
|
2
2
|
import { Order } from '@unchainedshop/core-orders';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const { PostFinanceCheckout } = pf;
|
|
3
|
+
import { Transaction, TransactionState } from './api-types.js';
|
|
6
4
|
|
|
7
5
|
export const transactionIsPaid = async (
|
|
8
|
-
transaction:
|
|
6
|
+
transaction: Transaction,
|
|
9
7
|
expectedCurrency: string,
|
|
10
8
|
expectedAmount: number,
|
|
11
9
|
): Promise<boolean> => {
|
|
12
|
-
if (transaction.state ===
|
|
10
|
+
if (transaction.state === TransactionState.FULFILL) {
|
|
13
11
|
return (
|
|
14
12
|
transaction.completedAmount !== undefined &&
|
|
15
13
|
transaction.completedAmount.toFixed(2) === expectedAmount.toFixed(2) &&
|
|
16
14
|
transaction.currency === expectedCurrency
|
|
17
15
|
);
|
|
18
16
|
}
|
|
19
|
-
if (transaction.state ===
|
|
17
|
+
if (transaction.state === TransactionState.AUTHORIZED) {
|
|
20
18
|
return (
|
|
21
19
|
transaction.authorizationAmount !== undefined &&
|
|
22
20
|
transaction.authorizationAmount.toFixed(2) === expectedAmount.toFixed(2) &&
|
|
@@ -26,10 +24,7 @@ export const transactionIsPaid = async (
|
|
|
26
24
|
return false;
|
|
27
25
|
};
|
|
28
26
|
|
|
29
|
-
export const orderIsPaid = async (
|
|
30
|
-
order: Order,
|
|
31
|
-
transaction: pf.PostFinanceCheckout.model.Transaction,
|
|
32
|
-
): Promise<boolean> => {
|
|
27
|
+
export const orderIsPaid = async (order: Order, transaction: Transaction): Promise<boolean> => {
|
|
33
28
|
const pricing = OrderPricingSheet({
|
|
34
29
|
calculation: order.calculation,
|
|
35
30
|
currencyCode: order.currencyCode,
|
|
@@ -133,8 +133,8 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
133
133
|
saferpayTransactionId,
|
|
134
134
|
);
|
|
135
135
|
|
|
136
|
-
paymentPageInitInput.Notification
|
|
137
|
-
paymentPageInitInput.Notification
|
|
136
|
+
paymentPageInitInput.Notification!.SuccessNotifyUrl = addTransactionId(
|
|
137
|
+
paymentPageInitInput.Notification!.SuccessNotifyUrl,
|
|
138
138
|
saferpayTransactionId,
|
|
139
139
|
);
|
|
140
140
|
|
|
@@ -166,6 +166,10 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
166
166
|
mongodb.ObjectId.createFromHexString(transactionId),
|
|
167
167
|
);
|
|
168
168
|
|
|
169
|
+
if (!saferpayTransaction?.token) {
|
|
170
|
+
throw new Error('No initialized transaction Token');
|
|
171
|
+
}
|
|
172
|
+
|
|
169
173
|
const api = createSaferPayClient();
|
|
170
174
|
const paymentPageAssert = await api.paymentPageAssert(orderPayment, {
|
|
171
175
|
Token: saferpayTransaction.token,
|
|
@@ -205,6 +209,10 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
205
209
|
mongodb.ObjectId.createFromHexString(transactionId),
|
|
206
210
|
);
|
|
207
211
|
|
|
212
|
+
if (!saferpayTransaction?.token) {
|
|
213
|
+
throw new Error('No initialized transaction Token');
|
|
214
|
+
}
|
|
215
|
+
|
|
208
216
|
const api = createSaferPayClient();
|
|
209
217
|
const paymentPageAssert = await api.paymentPageAssert(orderPayment, {
|
|
210
218
|
Token: saferpayTransaction.token,
|
|
@@ -236,6 +244,10 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
236
244
|
mongodb.ObjectId.createFromHexString(transactionId),
|
|
237
245
|
);
|
|
238
246
|
|
|
247
|
+
if (!saferpayTransaction?.token) {
|
|
248
|
+
throw new Error('No initialized transaction Token');
|
|
249
|
+
}
|
|
250
|
+
|
|
239
251
|
const api = createSaferPayClient();
|
|
240
252
|
const paymentPageAssert = await api.paymentPageAssert(orderPayment, {
|
|
241
253
|
Token: saferpayTransaction.token,
|
|
@@ -3,7 +3,7 @@ import { createLogger } from '@unchainedshop/logger';
|
|
|
3
3
|
import { buildSignature } from './buildSignature.js';
|
|
4
4
|
import { SaferpayTransactionsModule } from './module.js';
|
|
5
5
|
|
|
6
|
-
const logger = createLogger('unchained:
|
|
6
|
+
const logger = createLogger('unchained:saferpay:handler');
|
|
7
7
|
|
|
8
8
|
export const saferpayHandler = async (request, response) => {
|
|
9
9
|
const resolvedContext = request.unchainedContext as Context & {
|
|
@@ -22,8 +22,7 @@ export const saferpayHandler = async (request, response) => {
|
|
|
22
22
|
|
|
23
23
|
if ((request.method !== 'GET' && request.method !== 'HEAD') || !isValidRequest) {
|
|
24
24
|
logger.warn(`unhandled http method ${request.method} or orderPaymentId missing in query`);
|
|
25
|
-
response.
|
|
26
|
-
response.end();
|
|
25
|
+
response.status(404).end();
|
|
27
26
|
return;
|
|
28
27
|
}
|
|
29
28
|
|
|
@@ -47,24 +46,26 @@ export const saferpayHandler = async (request, response) => {
|
|
|
47
46
|
transactionId,
|
|
48
47
|
},
|
|
49
48
|
});
|
|
49
|
+
|
|
50
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
51
|
+
|
|
50
52
|
logger.info(`checkout successful`, {
|
|
51
53
|
orderPaymentId,
|
|
52
54
|
orderId: order._id,
|
|
53
55
|
});
|
|
54
|
-
response.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
orderId: order._id,
|
|
60
|
-
}),
|
|
61
|
-
);
|
|
56
|
+
response.status(200).send({
|
|
57
|
+
message: 'checkout successful',
|
|
58
|
+
orderPaymentId,
|
|
59
|
+
orderId: order._id,
|
|
60
|
+
});
|
|
62
61
|
} catch (error) {
|
|
63
62
|
logger.error(error, {
|
|
64
63
|
orderPaymentId,
|
|
65
64
|
transactionId,
|
|
66
65
|
});
|
|
67
|
-
response.
|
|
68
|
-
|
|
66
|
+
response.status(500).send({
|
|
67
|
+
message: error.message,
|
|
68
|
+
name: error.name,
|
|
69
|
+
});
|
|
69
70
|
}
|
|
70
71
|
};
|
|
@@ -4,7 +4,7 @@ import { buildSignature } from './buildSignature.js';
|
|
|
4
4
|
import { SaferpayTransactionsModule } from './module.js';
|
|
5
5
|
import { FastifyRequest, RouteHandlerMethod } from 'fastify';
|
|
6
6
|
|
|
7
|
-
const logger = createLogger('unchained:
|
|
7
|
+
const logger = createLogger('unchained:saferpay:handler');
|
|
8
8
|
|
|
9
9
|
export const saferpayHandler: RouteHandlerMethod = async (
|
|
10
10
|
request: FastifyRequest & {
|
|
@@ -52,24 +52,29 @@ export const saferpayHandler: RouteHandlerMethod = async (
|
|
|
52
52
|
transactionId,
|
|
53
53
|
},
|
|
54
54
|
});
|
|
55
|
+
|
|
56
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
57
|
+
|
|
55
58
|
logger.info(`checkout successful`, {
|
|
56
59
|
orderPaymentId,
|
|
57
60
|
orderId: order._id,
|
|
58
61
|
});
|
|
59
62
|
reply.status(200);
|
|
60
|
-
return reply.send(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}),
|
|
66
|
-
);
|
|
63
|
+
return reply.send({
|
|
64
|
+
success: true,
|
|
65
|
+
orderPaymentId,
|
|
66
|
+
orderId: order._id,
|
|
67
|
+
});
|
|
67
68
|
} catch (error) {
|
|
68
69
|
logger.error(error, {
|
|
69
70
|
orderPaymentId,
|
|
70
71
|
transactionId,
|
|
71
72
|
});
|
|
72
73
|
reply.status(500);
|
|
73
|
-
return reply.send(
|
|
74
|
+
return reply.send({
|
|
75
|
+
success: false,
|
|
76
|
+
message: error.message,
|
|
77
|
+
name: error.name,
|
|
78
|
+
});
|
|
74
79
|
}
|
|
75
80
|
};
|
|
@@ -2,7 +2,7 @@ import { Context } from '@unchainedshop/api';
|
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
3
|
import stripeClient from './stripe.js';
|
|
4
4
|
|
|
5
|
-
const logger = createLogger('unchained:
|
|
5
|
+
const logger = createLogger('unchained:stripe:handler');
|
|
6
6
|
|
|
7
7
|
export const WebhookEventTypes = {
|
|
8
8
|
PAYMENT_INTENT_SUCCEEDED: 'payment_intent.succeeded',
|
|
@@ -18,11 +18,19 @@ export const stripeHandler = async (request, response) => {
|
|
|
18
18
|
try {
|
|
19
19
|
const stripe = stripeClient();
|
|
20
20
|
const sig = request.headers['stripe-signature'];
|
|
21
|
+
if (!sig) {
|
|
22
|
+
throw new Error('stripe-signature header was not provided for webhook');
|
|
23
|
+
}
|
|
24
|
+
if (!process.env.STRIPE_ENDPOINT_SECRET) {
|
|
25
|
+
throw new Error('env STRIPE_ENDPOINT_SECRET is required for webhook handling');
|
|
26
|
+
}
|
|
21
27
|
event = stripe.webhooks.constructEvent(request.body, sig, process.env.STRIPE_ENDPOINT_SECRET);
|
|
22
28
|
} catch (err) {
|
|
23
29
|
logger.error(`Error constructing event: ${err.message}`);
|
|
24
|
-
response.
|
|
25
|
-
|
|
30
|
+
response.status(400).send({
|
|
31
|
+
message: err.message,
|
|
32
|
+
name: err.name,
|
|
33
|
+
});
|
|
26
34
|
return;
|
|
27
35
|
}
|
|
28
36
|
|
|
@@ -30,13 +38,10 @@ export const stripeHandler = async (request, response) => {
|
|
|
30
38
|
logger.info(`unhandled event type`, {
|
|
31
39
|
type: event.type,
|
|
32
40
|
});
|
|
33
|
-
response.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
message: `Unhandled event type: ${event.type}. Supported types: ${Object.values(WebhookEventTypes).join(', ')}`,
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
41
|
+
response.status(200).send({
|
|
42
|
+
ignored: true,
|
|
43
|
+
message: `Unhandled event type: ${event.type}. Supported types: ${Object.values(WebhookEventTypes).join(', ')}`,
|
|
44
|
+
});
|
|
40
45
|
return;
|
|
41
46
|
}
|
|
42
47
|
|
|
@@ -47,13 +52,10 @@ export const stripeHandler = async (request, response) => {
|
|
|
47
52
|
type: event.type,
|
|
48
53
|
environment: environmentInMetadata,
|
|
49
54
|
});
|
|
50
|
-
response.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
message: `Unhandled event environment: ${environmentInMetadata}. Supported environment: ${environmentInEnv}`,
|
|
55
|
-
}),
|
|
56
|
-
);
|
|
55
|
+
response.status(200).send({
|
|
56
|
+
ignored: true,
|
|
57
|
+
message: `Unhandled event environment: ${environmentInMetadata}. Supported environment: ${environmentInEnv}`,
|
|
58
|
+
});
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -84,18 +86,17 @@ export const stripeHandler = async (request, response) => {
|
|
|
84
86
|
},
|
|
85
87
|
});
|
|
86
88
|
|
|
89
|
+
if (!order) throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
90
|
+
|
|
87
91
|
logger.info(`checkout successful`, {
|
|
88
92
|
orderPaymentId,
|
|
89
93
|
orderId: order._id,
|
|
90
94
|
type: event.type,
|
|
91
95
|
});
|
|
92
|
-
response.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
orderId: order._id,
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
96
|
+
response.status(200).send({
|
|
97
|
+
message: 'checkout successful',
|
|
98
|
+
orderId: order._id,
|
|
99
|
+
});
|
|
99
100
|
} else if (event.type === WebhookEventTypes.SETUP_INTENT_SUCCEEDED) {
|
|
100
101
|
const setupIntent = event.data.object;
|
|
101
102
|
const { paymentProviderId, userId } = setupIntent.metadata || {};
|
|
@@ -118,19 +119,18 @@ export const stripeHandler = async (request, response) => {
|
|
|
118
119
|
paymentCredentialsId: paymentCredentials?._id,
|
|
119
120
|
type: event.type,
|
|
120
121
|
});
|
|
121
|
-
response.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
paymentCredentialsId: paymentCredentials?._id,
|
|
126
|
-
}),
|
|
127
|
-
);
|
|
122
|
+
response.status(200).send({
|
|
123
|
+
message: 'payment credentials registration successful',
|
|
124
|
+
paymentCredentialsId: paymentCredentials?._id,
|
|
125
|
+
});
|
|
128
126
|
}
|
|
129
127
|
} catch (error) {
|
|
130
128
|
logger.error(error, {
|
|
131
129
|
type: event.type,
|
|
132
130
|
});
|
|
133
|
-
response.
|
|
134
|
-
|
|
131
|
+
response.status(500).send({
|
|
132
|
+
message: error.message,
|
|
133
|
+
name: error.name,
|
|
134
|
+
});
|
|
135
135
|
}
|
|
136
136
|
};
|