@unchainedshop/plugins 4.6.1 → 4.7.2
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/README.md +0 -2
- package/lib/delivery/post/adapter.d.ts +2 -0
- package/lib/delivery/{post.js → post/adapter.js} +2 -3
- package/lib/delivery/post/index.d.ts +4 -0
- package/lib/delivery/post/index.js +10 -0
- package/lib/delivery/send-message/adapter.d.ts +2 -0
- package/lib/delivery/{send-message.js → send-message/adapter.js} +2 -3
- package/lib/delivery/send-message/index.d.ts +4 -0
- package/lib/delivery/send-message/index.js +10 -0
- package/lib/delivery/stores/adapter.d.ts +2 -0
- package/lib/delivery/{stores.js → stores/adapter.js} +2 -3
- package/lib/delivery/stores/index.d.ts +4 -0
- package/lib/delivery/stores/index.js +10 -0
- package/lib/enrollments/licensed/adapter.d.ts +6 -0
- package/lib/enrollments/{licensed.js → licensed/adapter.js} +2 -3
- package/lib/enrollments/licensed/index.d.ts +4 -0
- package/lib/enrollments/licensed/index.js +10 -0
- package/lib/events/node-event-emitter.d.ts +3 -1
- package/lib/events/node-event-emitter.js +3 -3
- package/lib/files/gridfs/adapter.d.ts +2 -2
- package/lib/files/gridfs/adapter.js +2 -5
- package/lib/files/gridfs/api.d.ts +7 -0
- package/lib/files/gridfs/api.js +163 -0
- package/lib/files/gridfs/index.d.ts +5 -4
- package/lib/files/gridfs/index.js +30 -3
- package/lib/files/minio/adapter.d.ts +4 -0
- package/lib/files/minio/adapter.js +160 -0
- package/lib/files/minio/api.d.ts +2 -0
- package/lib/files/minio/api.js +41 -0
- package/lib/files/minio/index.d.ts +4 -5
- package/lib/files/minio/index.js +18 -157
- package/lib/files/temp-upload/api.d.ts +6 -0
- package/lib/files/temp-upload/api.js +49 -0
- package/lib/files/temp-upload/index.d.ts +3 -0
- package/lib/files/temp-upload/index.js +15 -0
- package/lib/filters/local-search/adapter.d.ts +2 -0
- package/lib/filters/{local-search.js → local-search/adapter.js} +2 -12
- package/lib/filters/local-search/index.d.ts +4 -0
- package/lib/filters/local-search/index.js +16 -0
- package/lib/filters/strict-equal/adapter.d.ts +2 -0
- package/lib/filters/{strict-equal.js → strict-equal/adapter.js} +2 -3
- package/lib/filters/strict-equal/index.d.ts +4 -0
- package/lib/filters/strict-equal/index.js +10 -0
- package/lib/payment/apple-iap/adapter.d.ts +2 -1
- package/lib/payment/apple-iap/adapter.js +2 -3
- package/lib/payment/apple-iap/api.d.ts +2 -0
- package/lib/payment/apple-iap/{handler-fastify.js → api.js} +47 -30
- package/lib/payment/apple-iap/index.d.ts +6 -4
- package/lib/payment/apple-iap/index.js +28 -3
- package/lib/payment/cryptopay/adapter.d.ts +2 -0
- package/lib/payment/cryptopay/{plugin.js → adapter.js} +2 -4
- package/lib/payment/cryptopay/api.d.ts +2 -0
- package/lib/payment/cryptopay/api.js +23 -0
- package/lib/payment/cryptopay/index.d.ts +5 -4
- package/lib/payment/cryptopay/index.js +31 -3
- package/lib/payment/datatrans-v2/adapter.d.ts +2 -0
- package/lib/payment/datatrans-v2/adapter.js +406 -0
- package/lib/payment/datatrans-v2/api.d.ts +2 -0
- package/lib/payment/datatrans-v2/api.js +108 -0
- package/lib/payment/datatrans-v2/index.d.ts +4 -1
- package/lib/payment/datatrans-v2/index.js +17 -400
- package/lib/payment/invoice/adapter.d.ts +2 -0
- package/lib/payment/{invoice.js → invoice/adapter.js} +2 -3
- package/lib/payment/invoice/index.d.ts +4 -0
- package/lib/payment/invoice/index.js +10 -0
- package/lib/payment/invoice-prepaid/adapter.d.ts +2 -0
- package/lib/payment/{invoice-prepaid.js → invoice-prepaid/adapter.js} +2 -3
- package/lib/payment/invoice-prepaid/index.d.ts +4 -0
- package/lib/payment/invoice-prepaid/index.js +10 -0
- package/lib/payment/payrexx/adapter.d.ts +2 -0
- package/lib/payment/payrexx/adapter.js +161 -0
- package/lib/payment/payrexx/api.d.ts +2 -0
- package/lib/payment/payrexx/api.js +97 -0
- package/lib/payment/payrexx/index.d.ts +4 -1
- package/lib/payment/payrexx/index.js +19 -158
- package/lib/payment/postfinance-checkout/adapter.d.ts +2 -0
- package/lib/payment/postfinance-checkout/adapter.js +189 -0
- package/lib/payment/postfinance-checkout/index.d.ts +5 -0
- package/lib/payment/postfinance-checkout/index.js +25 -186
- package/lib/payment/postfinance-checkout/webhook.d.ts +2 -0
- package/lib/payment/postfinance-checkout/webhook.js +48 -0
- package/lib/payment/saferpay/adapter.js +1 -2
- package/lib/payment/saferpay/index.d.ts +5 -4
- package/lib/payment/saferpay/index.js +29 -3
- package/lib/payment/saferpay/webhook.d.ts +2 -0
- package/lib/payment/saferpay/webhook.js +64 -0
- package/lib/payment/stripe/adapter.d.ts +2 -0
- package/lib/payment/stripe/adapter.js +121 -0
- package/lib/payment/stripe/api.d.ts +6 -0
- package/lib/payment/stripe/api.js +165 -0
- package/lib/payment/stripe/index.d.ts +4 -1
- package/lib/payment/stripe/index.js +22 -116
- package/lib/payment/stripe/stripe.js +2 -5
- package/lib/presets/all.d.ts +1 -70
- package/lib/presets/all.js +41 -27
- package/lib/presets/base.d.ts +1 -25
- package/lib/presets/base.js +56 -25
- package/lib/presets/countries/ch.d.ts +1 -2
- package/lib/presets/countries/ch.js +7 -2
- package/lib/presets/crypto.d.ts +3 -7
- package/lib/presets/crypto.js +18 -7
- package/lib/pricing/{delivery-swiss-tax.d.ts → delivery-swiss-tax/adapter.d.ts} +1 -0
- package/lib/pricing/{delivery-swiss-tax.js → delivery-swiss-tax/adapter.js} +4 -4
- package/lib/pricing/delivery-swiss-tax/index.d.ts +4 -0
- package/lib/pricing/delivery-swiss-tax/index.js +10 -0
- package/lib/pricing/{discount-100-off.d.ts → discount-100-off/adapter.d.ts} +1 -0
- package/lib/pricing/{discount-100-off.js → discount-100-off/adapter.js} +2 -2
- package/lib/pricing/discount-100-off/index.d.ts +4 -0
- package/lib/pricing/discount-100-off/index.js +10 -0
- package/lib/pricing/{discount-half-price-manual.d.ts → discount-half-price-manual/adapter.d.ts} +1 -0
- package/lib/pricing/{discount-half-price-manual.js → discount-half-price-manual/adapter.js} +2 -2
- package/lib/pricing/discount-half-price-manual/index.d.ts +4 -0
- package/lib/pricing/discount-half-price-manual/index.js +10 -0
- package/lib/pricing/{free-delivery.d.ts → free-delivery/adapter.d.ts} +1 -0
- package/lib/pricing/{free-delivery.js → free-delivery/adapter.js} +2 -2
- package/lib/pricing/free-delivery/index.d.ts +4 -0
- package/lib/pricing/free-delivery/index.js +10 -0
- package/lib/pricing/{free-payment.d.ts → free-payment/adapter.d.ts} +1 -0
- package/lib/pricing/{free-payment.js → free-payment/adapter.js} +2 -2
- package/lib/pricing/free-payment/index.d.ts +4 -0
- package/lib/pricing/free-payment/index.js +10 -0
- package/lib/pricing/{order-delivery.d.ts → order-delivery/adapter.d.ts} +1 -0
- package/lib/pricing/{order-delivery.js → order-delivery/adapter.js} +2 -2
- package/lib/pricing/order-delivery/index.d.ts +4 -0
- package/lib/pricing/order-delivery/index.js +10 -0
- package/lib/pricing/{order-discount.d.ts → order-discount/adapter.d.ts} +1 -0
- package/lib/pricing/{order-discount.js → order-discount/adapter.js} +2 -2
- package/lib/pricing/order-discount/index.d.ts +4 -0
- package/lib/pricing/order-discount/index.js +10 -0
- package/lib/pricing/{order-items.d.ts → order-items/adapter.d.ts} +1 -0
- package/lib/pricing/{order-items.js → order-items/adapter.js} +2 -2
- package/lib/pricing/order-items/index.d.ts +4 -0
- package/lib/pricing/order-items/index.js +10 -0
- package/lib/pricing/{order-payment.d.ts → order-payment/adapter.d.ts} +1 -0
- package/lib/pricing/{order-payment.js → order-payment/adapter.js} +2 -2
- package/lib/pricing/order-payment/index.d.ts +4 -0
- package/lib/pricing/order-payment/index.js +10 -0
- package/lib/pricing/{product-catalog-price.d.ts → product-catalog-price/adapter.d.ts} +1 -0
- package/lib/pricing/{product-catalog-price.js → product-catalog-price/adapter.js} +2 -2
- package/lib/pricing/product-catalog-price/index.d.ts +4 -0
- package/lib/pricing/product-catalog-price/index.js +10 -0
- package/lib/pricing/{product-discount.d.ts → product-discount/adapter.d.ts} +1 -0
- package/lib/pricing/{product-discount.js → product-discount/adapter.js} +2 -2
- package/lib/pricing/product-discount/index.d.ts +4 -0
- package/lib/pricing/product-discount/index.js +10 -0
- package/lib/pricing/{product-price-rateconversion.d.ts → product-price-rateconversion/adapter.d.ts} +1 -0
- package/lib/pricing/{product-price-rateconversion.js → product-price-rateconversion/adapter.js} +2 -2
- package/lib/pricing/product-price-rateconversion/index.d.ts +4 -0
- package/lib/pricing/product-price-rateconversion/index.js +10 -0
- package/lib/pricing/{product-swiss-tax.d.ts → product-swiss-tax/adapter.d.ts} +1 -0
- package/lib/pricing/{product-swiss-tax.js → product-swiss-tax/adapter.js} +4 -4
- package/lib/pricing/product-swiss-tax/index.d.ts +4 -0
- package/lib/pricing/product-swiss-tax/index.js +10 -0
- package/lib/quotations/manual/adapter.d.ts +2 -0
- package/lib/quotations/{manual.js → manual/adapter.js} +2 -3
- package/lib/quotations/manual/index.d.ts +4 -0
- package/lib/quotations/manual/index.js +10 -0
- package/lib/warehousing/erc-metadata/api.d.ts +12 -0
- package/lib/warehousing/erc-metadata/api.js +43 -0
- package/lib/warehousing/erc-metadata/index.d.ts +3 -0
- package/lib/warehousing/erc-metadata/index.js +15 -0
- package/lib/warehousing/eth-minter/adapter.d.ts +2 -0
- package/lib/warehousing/{eth-minter.js → eth-minter/adapter.js} +3 -4
- package/lib/warehousing/eth-minter/index.d.ts +4 -0
- package/lib/warehousing/eth-minter/index.js +10 -0
- package/lib/warehousing/store/adapter.d.ts +2 -0
- package/lib/warehousing/{store.js → store/adapter.js} +2 -3
- package/lib/warehousing/store/index.d.ts +4 -0
- package/lib/warehousing/store/index.js +10 -0
- package/lib/worker/budgetsms/adapter.d.ts +22 -0
- package/lib/worker/{budgetsms.js → budgetsms/adapter.js} +3 -3
- package/lib/worker/budgetsms/index.d.ts +4 -0
- package/lib/worker/budgetsms/index.js +10 -0
- package/lib/worker/bulk-export/adapter.d.ts +3 -0
- package/lib/worker/{bulk-export.js → bulk-export/adapter.js} +3 -3
- package/lib/worker/bulk-export/index.d.ts +4 -0
- package/lib/worker/bulk-export/index.js +10 -0
- package/lib/worker/{bulk-import.d.ts → bulk-import/adapter.d.ts} +1 -0
- package/lib/worker/{bulk-import.js → bulk-import/adapter.js} +2 -2
- package/lib/worker/bulk-import/api.d.ts +7 -0
- package/lib/worker/bulk-import/api.js +53 -0
- package/lib/worker/bulk-import/index.d.ts +4 -0
- package/lib/worker/bulk-import/index.js +18 -0
- package/lib/worker/bulkgate/adapter.d.ts +12 -0
- package/lib/worker/{bulkgate.js → bulkgate/adapter.js} +3 -3
- package/lib/worker/bulkgate/index.d.ts +4 -0
- package/lib/worker/bulkgate/index.js +10 -0
- package/lib/worker/email/adapter.d.ts +9 -0
- package/lib/worker/{email.js → email/adapter.js} +27 -13
- package/lib/worker/email/index.d.ts +4 -0
- package/lib/worker/email/index.js +10 -0
- package/lib/worker/enrollment-order-generator/adapter.d.ts +4 -0
- package/lib/worker/{enrollment-order-generator.js → enrollment-order-generator/adapter.js} +2 -2
- package/lib/worker/enrollment-order-generator/index.d.ts +4 -0
- package/lib/worker/enrollment-order-generator/index.js +13 -0
- package/lib/worker/{error-notifications.d.ts → error-notifications/adapter.d.ts} +1 -0
- package/lib/worker/{error-notifications.js → error-notifications/adapter.js} +9 -8
- package/lib/worker/error-notifications/index.d.ts +4 -0
- package/lib/worker/error-notifications/index.js +13 -0
- package/lib/worker/{export-token.d.ts → export-token/adapter.d.ts} +1 -1
- package/lib/worker/{export-token.js → export-token/adapter.js} +2 -3
- package/lib/worker/export-token/index.d.ts +4 -0
- package/lib/worker/export-token/index.js +13 -0
- package/lib/worker/{external.d.ts → external/adapter.d.ts} +1 -0
- package/lib/worker/{external.js → external/adapter.js} +2 -2
- package/lib/worker/external/index.d.ts +4 -0
- package/lib/worker/external/index.js +10 -0
- package/lib/worker/heartbeat/adapter.d.ts +8 -0
- package/lib/worker/{heartbeat.js → heartbeat/adapter.js} +3 -3
- package/lib/worker/heartbeat/index.d.ts +4 -0
- package/lib/worker/heartbeat/index.js +10 -0
- package/lib/worker/{http-request.d.ts → http-request/adapter.d.ts} +1 -1
- package/lib/worker/{http-request.js → http-request/adapter.js} +2 -3
- package/lib/worker/http-request/index.d.ts +4 -0
- package/lib/worker/http-request/index.js +10 -0
- package/lib/worker/{message.d.ts → message/adapter.d.ts} +1 -0
- package/lib/worker/{message.js → message/adapter.js} +2 -2
- package/lib/worker/message/index.d.ts +4 -0
- package/lib/worker/message/index.js +10 -0
- package/lib/worker/push-notification/adapter.d.ts +9 -0
- package/lib/worker/{push-notification.js → push-notification/adapter.js} +3 -3
- package/lib/worker/push-notification/index.d.ts +4 -0
- package/lib/worker/push-notification/index.js +10 -0
- package/lib/worker/twilio/adapter.d.ts +8 -0
- package/lib/worker/{twilio.js → twilio/adapter.js} +3 -3
- package/lib/worker/twilio/index.d.ts +4 -0
- package/lib/worker/twilio/index.js +10 -0
- package/lib/worker/update-coinbase-rates/adapter.d.ts +4 -0
- package/lib/worker/{update-coinbase-rates.js → update-coinbase-rates/adapter.js} +8 -6
- package/lib/worker/update-coinbase-rates/index.d.ts +4 -0
- package/lib/worker/update-coinbase-rates/index.js +13 -0
- package/lib/worker/update-ecb-rates/adapter.d.ts +4 -0
- package/lib/worker/{update-ecb-rates.js → update-ecb-rates/adapter.js} +11 -9
- package/lib/worker/update-ecb-rates/index.d.ts +4 -0
- package/lib/worker/update-ecb-rates/index.js +13 -0
- package/lib/worker/{update-token-ownership.d.ts → update-token-ownership/adapter.d.ts} +2 -0
- package/lib/worker/{update-token-ownership.js → update-token-ownership/adapter.js} +8 -7
- package/lib/worker/update-token-ownership/index.d.ts +4 -0
- package/lib/worker/update-token-ownership/index.js +13 -0
- package/lib/worker/{zombie-killer.js → zombie-killer/adapter.js} +1 -2
- package/lib/worker/zombie-killer/index.d.ts +4 -0
- package/lib/worker/zombie-killer/index.js +10 -0
- package/package.json +15 -10
- package/lib/delivery/post.d.ts +0 -1
- package/lib/delivery/send-message.d.ts +0 -1
- package/lib/delivery/stores.d.ts +0 -1
- package/lib/enrollments/licensed.d.ts +0 -4
- package/lib/files/gridfs/handler-express.d.ts +0 -9
- package/lib/files/gridfs/handler-express.js +0 -110
- package/lib/files/gridfs/handler-fastify.d.ts +0 -3
- package/lib/files/gridfs/handler-fastify.js +0 -138
- package/lib/files/minio/handler-express.d.ts +0 -2
- package/lib/files/minio/handler-express.js +0 -36
- package/lib/files/minio/handler-fastify.d.ts +0 -3
- package/lib/files/minio/handler-fastify.js +0 -40
- package/lib/filters/local-search.d.ts +0 -3
- package/lib/filters/strict-equal.d.ts +0 -1
- package/lib/payment/apple-iap/handler-express.d.ts +0 -2
- package/lib/payment/apple-iap/handler-express.js +0 -103
- package/lib/payment/apple-iap/handler-fastify.d.ts +0 -3
- package/lib/payment/braintree.d.ts +0 -1
- package/lib/payment/braintree.js +0 -138
- package/lib/payment/cryptopay/handler-express.d.ts +0 -2
- package/lib/payment/cryptopay/handler-express.js +0 -19
- package/lib/payment/cryptopay/handler-fastify.d.ts +0 -3
- package/lib/payment/cryptopay/handler-fastify.js +0 -17
- package/lib/payment/cryptopay/plugin.d.ts +0 -3
- package/lib/payment/datatrans-v2/handler-express.d.ts +0 -1
- package/lib/payment/datatrans-v2/handler-express.js +0 -71
- package/lib/payment/datatrans-v2/handler-fastify.d.ts +0 -2
- package/lib/payment/datatrans-v2/handler-fastify.js +0 -71
- package/lib/payment/invoice-prepaid.d.ts +0 -1
- package/lib/payment/invoice.d.ts +0 -1
- package/lib/payment/paypal-checkout.d.ts +0 -1
- package/lib/payment/paypal-checkout.js +0 -87
- package/lib/payment/payrexx/handler-express.d.ts +0 -1
- package/lib/payment/payrexx/handler-express.js +0 -85
- package/lib/payment/payrexx/handler-fastify.d.ts +0 -2
- package/lib/payment/payrexx/handler-fastify.js +0 -91
- package/lib/payment/postfinance-checkout/handler-express.d.ts +0 -1
- package/lib/payment/postfinance-checkout/handler-express.js +0 -37
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts +0 -2
- package/lib/payment/postfinance-checkout/handler-fastify.js +0 -40
- package/lib/payment/saferpay/handler-express.d.ts +0 -1
- package/lib/payment/saferpay/handler-express.js +0 -59
- package/lib/payment/saferpay/handler-fastify.d.ts +0 -2
- package/lib/payment/saferpay/handler-fastify.js +0 -62
- package/lib/payment/stripe/handler-express.d.ts +0 -5
- package/lib/payment/stripe/handler-express.js +0 -121
- package/lib/payment/stripe/handler-fastify.d.ts +0 -6
- package/lib/payment/stripe/handler-fastify.js +0 -131
- package/lib/presets/all-express.d.ts +0 -6
- package/lib/presets/all-express.js +0 -26
- package/lib/presets/all-fastify.d.ts +0 -6
- package/lib/presets/all-fastify.js +0 -49
- package/lib/presets/base-express.d.ts +0 -2
- package/lib/presets/base-express.js +0 -5
- package/lib/presets/base-fastify.d.ts +0 -3
- package/lib/presets/base-fastify.js +0 -16
- package/lib/presets/crypto-express.d.ts +0 -3
- package/lib/presets/crypto-express.js +0 -8
- package/lib/presets/crypto-fastify.d.ts +0 -3
- package/lib/presets/crypto-fastify.js +0 -11
- package/lib/pricing/discount-half-price.d.ts +0 -2
- package/lib/pricing/discount-half-price.js +0 -33
- package/lib/pricing/order-items-discount.d.ts +0 -2
- package/lib/pricing/order-items-discount.js +0 -50
- package/lib/pricing/order-round.d.ts +0 -10
- package/lib/pricing/order-round.js +0 -135
- package/lib/pricing/product-catalog-price-options.d.ts +0 -2
- package/lib/pricing/product-catalog-price-options.js +0 -51
- package/lib/pricing/product-round.d.ts +0 -10
- package/lib/pricing/product-round.js +0 -44
- package/lib/quotations/manual.d.ts +0 -1
- package/lib/warehousing/eth-minter.d.ts +0 -1
- package/lib/warehousing/store.d.ts +0 -1
- package/lib/worker/budgetsms.d.ts +0 -9
- package/lib/worker/bulk-export.d.ts +0 -2
- package/lib/worker/bulkgate.d.ts +0 -1
- package/lib/worker/email.d.ts +0 -1
- package/lib/worker/enrollment-order-generator.d.ts +0 -1
- package/lib/worker/heartbeat.d.ts +0 -1
- package/lib/worker/push-notification.d.ts +0 -1
- package/lib/worker/twilio.d.ts +0 -1
- package/lib/worker/update-coinbase-rates.d.ts +0 -1
- package/lib/worker/update-ecb-rates.d.ts +0 -1
- /package/lib/worker/{zombie-killer.d.ts → zombie-killer/adapter.d.ts} +0 -0
|
@@ -1,192 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { CompletionModes, IntegrationModes } from "./types.js";
|
|
6
|
-
import { LineItemType, TokenizationMode, TransactionCompletionBehavior, TransactionState, CreationEntityState, } from "./api-types.js";
|
|
7
|
-
const { PFCHECKOUT_SPACE_ID, PFCHECKOUT_USER_ID, PFCHECKOUT_SECRET, PFCHECKOUT_SUCCESS_URL, PFCHECKOUT_FAILED_URL, } = process.env;
|
|
8
|
-
const logger = createLogger('unchained:postfinance-checkout');
|
|
9
|
-
const newError = ({ code, message }) => {
|
|
10
|
-
const error = new Error(message);
|
|
11
|
-
error.name = `POSTFINANCE_${code}`;
|
|
12
|
-
return error;
|
|
13
|
-
};
|
|
14
|
-
const PostfinanceCheckout = {
|
|
15
|
-
...PaymentAdapter,
|
|
1
|
+
import { PostfinanceCheckout } from "./adapter.js";
|
|
2
|
+
import { postfinanceCheckoutWebhookHandler } from "./webhook.js";
|
|
3
|
+
const { PFCHECKOUT_WEBHOOK_PATH = '/payment/postfinance-checkout' } = process.env;
|
|
4
|
+
export const PostfinanceCheckoutPlugin = {
|
|
16
5
|
key: 'shop.unchained.payment.postfinance-checkout',
|
|
17
|
-
label: 'Postfinance Checkout',
|
|
6
|
+
label: 'Postfinance Checkout Payment Plugin',
|
|
18
7
|
version: '1.0.0',
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
},
|
|
39
|
-
isActive() {
|
|
40
|
-
if (adapter.configurationError() === null)
|
|
41
|
-
return true;
|
|
42
|
-
return false;
|
|
43
|
-
},
|
|
44
|
-
isPayLaterAllowed() {
|
|
45
|
-
return false;
|
|
46
|
-
},
|
|
47
|
-
async validate(credentials) {
|
|
48
|
-
if (!credentials.meta)
|
|
49
|
-
return false;
|
|
50
|
-
const { linkedSpaceId } = credentials.meta;
|
|
51
|
-
const tokenData = await getToken(linkedSpaceId, credentials.token);
|
|
52
|
-
return tokenData.state === CreationEntityState.ACTIVE;
|
|
53
|
-
},
|
|
54
|
-
sign: async (transactionContext = {}) => {
|
|
55
|
-
const { orderPayment, order } = context;
|
|
56
|
-
if (!order)
|
|
57
|
-
throw new Error('No order in context, can only sign with order context');
|
|
58
|
-
if (!orderPayment)
|
|
59
|
-
throw new Error('No order payment in context, can only sign with order payment context');
|
|
60
|
-
const { integrationMode = IntegrationModes.PaymentPage } = transactionContext;
|
|
61
|
-
const completionMode = adapter.getCompletionMode();
|
|
62
|
-
const pricing = OrderPricingSheet({
|
|
63
|
-
calculation: order.calculation,
|
|
64
|
-
currencyCode: order.currencyCode,
|
|
65
|
-
});
|
|
66
|
-
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
67
|
-
const transaction = {
|
|
68
|
-
currency: order.currencyCode,
|
|
69
|
-
metaData: {
|
|
70
|
-
orderPaymentId: orderPayment._id,
|
|
71
|
-
},
|
|
72
|
-
successUrl: `${transactionContext?.successUrl || PFCHECKOUT_SUCCESS_URL}?order_id=${orderPayment.orderId}`,
|
|
73
|
-
failedUrl: `${transactionContext?.failedUrl || PFCHECKOUT_FAILED_URL}?order_id=${orderPayment.orderId}`,
|
|
74
|
-
customerId: order?.userId || context?.userId,
|
|
75
|
-
tokenizationMode: TokenizationMode.ALLOW_ONE_CLICK_PAYMENT,
|
|
76
|
-
};
|
|
77
|
-
if (completionMode === CompletionModes.Immediate) {
|
|
78
|
-
transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_IMMEDIATELY;
|
|
79
|
-
}
|
|
80
|
-
else if (completionMode === CompletionModes.Deferred) {
|
|
81
|
-
transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_DEFERRED;
|
|
82
|
-
}
|
|
83
|
-
if (totalAmount) {
|
|
84
|
-
const lineItemSum = {
|
|
85
|
-
name: `Bestellung ${orderPayment.orderId}`,
|
|
86
|
-
type: LineItemType.FEE,
|
|
87
|
-
quantity: 1,
|
|
88
|
-
uniqueId: orderPayment.orderId,
|
|
89
|
-
amountIncludingTax: totalAmount / 100,
|
|
90
|
-
};
|
|
91
|
-
transaction.lineItems = [lineItemSum];
|
|
92
|
-
}
|
|
93
|
-
const transactionId = await createTransaction(transaction);
|
|
94
|
-
if (!transactionId)
|
|
95
|
-
throw new Error('Could not create transaction');
|
|
96
|
-
let location = null;
|
|
97
|
-
if (integrationMode === IntegrationModes.PaymentPage) {
|
|
98
|
-
location = await getPaymentPageUrl(transactionId);
|
|
99
|
-
}
|
|
100
|
-
else if (integrationMode === IntegrationModes.Lightbox) {
|
|
101
|
-
location = await getLightboxJavascriptUrl(transactionId);
|
|
102
|
-
}
|
|
103
|
-
else if (integrationMode === IntegrationModes.iFrame) {
|
|
104
|
-
location = await getIframeJavascriptUrl(transactionId);
|
|
105
|
-
}
|
|
106
|
-
const res = {
|
|
107
|
-
transactionId,
|
|
108
|
-
location,
|
|
109
|
-
};
|
|
110
|
-
return JSON.stringify(res);
|
|
111
|
-
},
|
|
112
|
-
charge: async ({ transactionId, paymentCredentials, }) => {
|
|
113
|
-
if (paymentCredentials && !transactionId) {
|
|
114
|
-
throw new Error('Not implemented yet');
|
|
115
|
-
}
|
|
116
|
-
if (!transactionId)
|
|
117
|
-
return false;
|
|
118
|
-
const transaction = await getTransaction(transactionId);
|
|
119
|
-
if (!transaction) {
|
|
120
|
-
logger.error(`Transaction #${transactionId}: Transaction not found`);
|
|
121
|
-
throw newError({
|
|
122
|
-
code: `TRANSACTION_NOT_FOUND`,
|
|
123
|
-
message: 'Payment declined',
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
const { order, orderPayment } = context;
|
|
127
|
-
if (!orderPayment)
|
|
128
|
-
throw new Error('No order payment in context, cannot charge payment');
|
|
129
|
-
if (!order)
|
|
130
|
-
throw new Error('No order in context, can only sign with order context');
|
|
131
|
-
const isPaid = await orderIsPaid(order, transaction);
|
|
132
|
-
if (!isPaid) {
|
|
133
|
-
logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
|
|
134
|
-
throw newError({
|
|
135
|
-
code: `STATE_${transaction.state?.toUpperCase()}`,
|
|
136
|
-
message: 'Invalid state / Amount incorrect',
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
if (transaction.metaData?.orderPaymentId !== orderPayment._id) {
|
|
140
|
-
logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
|
|
141
|
-
throw newError({
|
|
142
|
-
code: `TRANSACTION_ALREADY_USED`,
|
|
143
|
-
message: 'Transaction already used in previous checkout',
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
const { id, ...tokenMeta } = transaction.token || {};
|
|
147
|
-
return {
|
|
148
|
-
transaction,
|
|
149
|
-
transactionId,
|
|
150
|
-
credentials: id && {
|
|
151
|
-
...tokenMeta,
|
|
152
|
-
token: id.toString(),
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
cancel: async () => {
|
|
157
|
-
const { orderPayment, order } = context;
|
|
158
|
-
if (!order)
|
|
159
|
-
throw new Error('No order in context, can only cancel with order context');
|
|
160
|
-
if (!orderPayment?.transactionId) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
const { transactionId } = orderPayment;
|
|
164
|
-
const transaction = await getTransaction(transactionId);
|
|
165
|
-
const refund = transaction.state === TransactionState.FULFILL;
|
|
166
|
-
const pricing = OrderPricingSheet({
|
|
167
|
-
calculation: order.calculation,
|
|
168
|
-
currencyCode: order.currencyCode,
|
|
169
|
-
});
|
|
170
|
-
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
171
|
-
return ((refund && refundTransaction(transactionId, order._id, totalAmount / 100)) ||
|
|
172
|
-
voidTransaction(transactionId));
|
|
173
|
-
},
|
|
174
|
-
confirm: async () => {
|
|
175
|
-
const { orderPayment } = context;
|
|
176
|
-
if (!orderPayment?.transactionId) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
const { transactionId } = orderPayment;
|
|
180
|
-
const transaction = await getTransaction(transactionId);
|
|
181
|
-
if (transaction.state === TransactionState.AUTHORIZED) {
|
|
182
|
-
return confirmDeferredTransaction(transactionId);
|
|
183
|
-
}
|
|
184
|
-
return false;
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
return adapter;
|
|
8
|
+
adapters: [PostfinanceCheckout],
|
|
9
|
+
routes: [
|
|
10
|
+
{
|
|
11
|
+
path: PFCHECKOUT_WEBHOOK_PATH,
|
|
12
|
+
method: 'POST',
|
|
13
|
+
handler: postfinanceCheckoutWebhookHandler,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
onRegister: () => {
|
|
17
|
+
const { PFCHECKOUT_SPACE_ID, PFCHECKOUT_USER_ID, PFCHECKOUT_SECRET, PFCHECKOUT_SUCCESS_URL, PFCHECKOUT_FAILED_URL, } = process.env;
|
|
18
|
+
if (!PFCHECKOUT_SPACE_ID ||
|
|
19
|
+
!PFCHECKOUT_USER_ID ||
|
|
20
|
+
!PFCHECKOUT_SECRET ||
|
|
21
|
+
!PFCHECKOUT_SUCCESS_URL ||
|
|
22
|
+
!PFCHECKOUT_FAILED_URL) {
|
|
23
|
+
throw new Error('Postfinance Checkout environment variables not fully configured');
|
|
24
|
+
}
|
|
188
25
|
},
|
|
189
26
|
};
|
|
190
|
-
|
|
27
|
+
export default PostfinanceCheckoutPlugin;
|
|
28
|
+
export { PostfinanceCheckout } from "./adapter.js";
|
|
191
29
|
export * from "./types.js";
|
|
192
30
|
export * from "./api-types.js";
|
|
31
|
+
export * from "./utils.js";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
+
import { getTransaction, getTransactionCompletion } from "./api.js";
|
|
3
|
+
const logger = createLogger('unchained:postfinance-checkout');
|
|
4
|
+
export async function postfinanceCheckoutWebhookHandler(request, context) {
|
|
5
|
+
try {
|
|
6
|
+
const { services, modules } = context;
|
|
7
|
+
const data = (await request.json());
|
|
8
|
+
if (data.listenerEntityTechnicalName === 'TransactionCompletion') {
|
|
9
|
+
const transactionCompletion = await getTransactionCompletion(data.entityId);
|
|
10
|
+
const transaction = await getTransaction(transactionCompletion ? transactionCompletion.linkedTransaction : data.entityId);
|
|
11
|
+
const { orderPaymentId } = transaction.metaData;
|
|
12
|
+
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
13
|
+
orderPaymentId,
|
|
14
|
+
});
|
|
15
|
+
if (!orderPayment) {
|
|
16
|
+
throw new Error('Order Payment not found');
|
|
17
|
+
}
|
|
18
|
+
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
19
|
+
paymentContext: {
|
|
20
|
+
transactionId: transactionCompletion.linkedTransaction,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
if (!order) {
|
|
24
|
+
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
25
|
+
}
|
|
26
|
+
logger.info(`Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData?.orderPaymentId} as paid`);
|
|
27
|
+
return new Response(JSON.stringify({ orderNumber: order.orderNumber }), {
|
|
28
|
+
status: 200,
|
|
29
|
+
headers: { 'Content-Type': 'application/json' },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
logger.error(`Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`);
|
|
34
|
+
return new Response(null, { status: 404 });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
logger.error('Postfinance Checkout webhook error:', error);
|
|
39
|
+
return new Response(JSON.stringify({
|
|
40
|
+
name: error.name,
|
|
41
|
+
code: error.code,
|
|
42
|
+
message: error.message,
|
|
43
|
+
}), {
|
|
44
|
+
status: 500,
|
|
45
|
+
headers: { 'Content-Type': 'application/json' },
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
2
|
import { SaferpayClient } from "./api/index.js";
|
|
3
3
|
import { buildSignature } from "./buildSignature.js";
|
|
4
|
-
import { OrderPricingSheet, PaymentAdapter,
|
|
4
|
+
import { OrderPricingSheet, PaymentAdapter, PaymentError, } from '@unchainedshop/core';
|
|
5
5
|
const newSaferpayError = ({ code, message }) => {
|
|
6
6
|
const error = new Error(message || code);
|
|
7
7
|
error.name = `SAFERPAY_${code}`;
|
|
@@ -187,4 +187,3 @@ export const WordlineSaferpay = {
|
|
|
187
187
|
return adapter;
|
|
188
188
|
},
|
|
189
189
|
};
|
|
190
|
-
PaymentDirector.registerAdapter(WordlineSaferpay);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
import type { IPlugin } from '@unchainedshop/core';
|
|
2
|
+
export declare const SaferpayPlugin: IPlugin;
|
|
3
|
+
export default SaferpayPlugin;
|
|
4
|
+
export { WordlineSaferpay } from './adapter.ts';
|
|
5
|
+
export { type SaferpayTransactionsModule } from './module.ts';
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { WordlineSaferpay } from "./adapter.js";
|
|
2
|
+
import saferpayModules from "./module.js";
|
|
3
|
+
import { saferpayWebhookHandler } from "./webhook.js";
|
|
4
|
+
const { SAFERPAY_WEBHOOK_PATH = '/payment/saferpay/webhook' } = process.env;
|
|
5
|
+
export const SaferpayPlugin = {
|
|
6
|
+
key: 'shop.unchained.payment.saferpay',
|
|
7
|
+
label: 'Wordline Saferpay Payment Plugin',
|
|
8
|
+
version: '1.0.0',
|
|
9
|
+
adapters: [WordlineSaferpay],
|
|
10
|
+
module: ({ db }) => ({
|
|
11
|
+
saferpayTransactions: saferpayModules.saferpayTransactions.configure({ db }),
|
|
12
|
+
}),
|
|
13
|
+
routes: [
|
|
14
|
+
{
|
|
15
|
+
path: SAFERPAY_WEBHOOK_PATH,
|
|
16
|
+
method: 'GET',
|
|
17
|
+
handler: saferpayWebhookHandler,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
onRegister: () => {
|
|
21
|
+
const { SAFERPAY_CUSTOMER_ID, SAFERPAY_TERMINAL_ID, SAFERPAY_API_USER, SAFERPAY_API_PASSWORD } = process.env;
|
|
22
|
+
if (!SAFERPAY_CUSTOMER_ID || !SAFERPAY_TERMINAL_ID || !SAFERPAY_API_USER || !SAFERPAY_API_PASSWORD) {
|
|
23
|
+
throw new Error('Saferpay environment variables not fully configured');
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export default SaferpayPlugin;
|
|
28
|
+
export { WordlineSaferpay } from "./adapter.js";
|
|
29
|
+
export {} from "./module.js";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
+
import { timingSafeStringEqual } from '@unchainedshop/utils';
|
|
3
|
+
import { buildSignature } from "./buildSignature.js";
|
|
4
|
+
const logger = createLogger('unchained:saferpay');
|
|
5
|
+
export async function saferpayWebhookHandler(request, context) {
|
|
6
|
+
try {
|
|
7
|
+
const { modules, services } = context;
|
|
8
|
+
const url = new URL(request.url);
|
|
9
|
+
const orderPaymentId = url.searchParams.get('orderPaymentId');
|
|
10
|
+
const signature = url.searchParams.get('signature');
|
|
11
|
+
const transactionId = url.searchParams.get('transactionId');
|
|
12
|
+
const isValidRequest = typeof orderPaymentId === 'string' &&
|
|
13
|
+
typeof signature === 'string' &&
|
|
14
|
+
typeof transactionId === 'string' &&
|
|
15
|
+
orderPaymentId &&
|
|
16
|
+
transactionId &&
|
|
17
|
+
signature;
|
|
18
|
+
if (!isValidRequest) {
|
|
19
|
+
logger.warn('Missing required query parameters');
|
|
20
|
+
return new Response(null, { status: 404 });
|
|
21
|
+
}
|
|
22
|
+
logger.info(`Checkout with orderPaymentId: ${orderPaymentId}`);
|
|
23
|
+
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
24
|
+
orderPaymentId,
|
|
25
|
+
});
|
|
26
|
+
if (!orderPayment) {
|
|
27
|
+
throw new Error(`Order payment not found with orderPaymentId: ${orderPaymentId}`);
|
|
28
|
+
}
|
|
29
|
+
const correctSignature = await buildSignature(transactionId, orderPaymentId);
|
|
30
|
+
if (!(await timingSafeStringEqual(correctSignature, signature))) {
|
|
31
|
+
throw new Error('Invalid signature');
|
|
32
|
+
}
|
|
33
|
+
const order = await services.orders.checkoutOrder(orderPayment.orderId, {
|
|
34
|
+
paymentContext: {
|
|
35
|
+
transactionId,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
if (!order) {
|
|
39
|
+
throw new Error(`Order with id ${orderPayment.orderId} not found`);
|
|
40
|
+
}
|
|
41
|
+
logger.info('Checkout successful', {
|
|
42
|
+
orderPaymentId,
|
|
43
|
+
orderId: order._id,
|
|
44
|
+
});
|
|
45
|
+
return new Response(JSON.stringify({
|
|
46
|
+
message: 'checkout successful',
|
|
47
|
+
orderPaymentId,
|
|
48
|
+
orderId: order._id,
|
|
49
|
+
}), {
|
|
50
|
+
status: 200,
|
|
51
|
+
headers: { 'Content-Type': 'application/json' },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
logger.error('Saferpay webhook error:', error);
|
|
56
|
+
return new Response(JSON.stringify({
|
|
57
|
+
message: error.message,
|
|
58
|
+
name: error.name,
|
|
59
|
+
}), {
|
|
60
|
+
status: 500,
|
|
61
|
+
headers: { 'Content-Type': 'application/json' },
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
+
import { stripe, createOrderPaymentIntent, createRegistrationIntent } from "./stripe.js";
|
|
3
|
+
import { OrderPricingSheet, PaymentAdapter, PaymentError, } from '@unchainedshop/core';
|
|
4
|
+
const logger = createLogger('unchained:stripe');
|
|
5
|
+
export const Stripe = {
|
|
6
|
+
...PaymentAdapter,
|
|
7
|
+
key: 'shop.unchained.payment.stripe',
|
|
8
|
+
label: 'Stripe',
|
|
9
|
+
version: '2.0.0',
|
|
10
|
+
typeSupported(type) {
|
|
11
|
+
return type === 'GENERIC';
|
|
12
|
+
},
|
|
13
|
+
actions: (config, context) => {
|
|
14
|
+
const { modules } = context;
|
|
15
|
+
const descriptorPrefix = config.find(({ key }) => key === 'descriptorPrefix')?.value || '';
|
|
16
|
+
const assertUserData = async (forcedUserId) => {
|
|
17
|
+
const userId = forcedUserId || context?.userId;
|
|
18
|
+
const user = await modules.users.findUserById(userId);
|
|
19
|
+
if (!user)
|
|
20
|
+
throw new Error('User not found');
|
|
21
|
+
const email = modules.users.primaryEmail(user)?.address;
|
|
22
|
+
const name = user.profile?.displayName || user.username || email;
|
|
23
|
+
return {
|
|
24
|
+
email,
|
|
25
|
+
name,
|
|
26
|
+
userId,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const adapterActions = {
|
|
30
|
+
...PaymentAdapter.actions(config, context),
|
|
31
|
+
configurationError() {
|
|
32
|
+
if (!stripe)
|
|
33
|
+
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
34
|
+
return null;
|
|
35
|
+
},
|
|
36
|
+
isActive: () => {
|
|
37
|
+
if (adapterActions.configurationError() === null)
|
|
38
|
+
return true;
|
|
39
|
+
return false;
|
|
40
|
+
},
|
|
41
|
+
isPayLaterAllowed() {
|
|
42
|
+
return false;
|
|
43
|
+
},
|
|
44
|
+
validate: async ({ token }) => {
|
|
45
|
+
const paymentMethod = await stripe.paymentMethods.retrieve(token);
|
|
46
|
+
return !!paymentMethod;
|
|
47
|
+
},
|
|
48
|
+
register: async ({ setupIntentId }) => {
|
|
49
|
+
if (!setupIntentId) {
|
|
50
|
+
throw new Error('You have to provide a setupIntentId');
|
|
51
|
+
}
|
|
52
|
+
const setupIntent = await stripe.setupIntents.retrieve(setupIntentId);
|
|
53
|
+
if (setupIntent.status === 'succeeded') {
|
|
54
|
+
return {
|
|
55
|
+
token: setupIntent.payment_method,
|
|
56
|
+
customer: setupIntent.customer,
|
|
57
|
+
payment_method_types: setupIntent.payment_method_types,
|
|
58
|
+
usage: setupIntent.usage,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
logger.warn('Registration declined', setupIntentId);
|
|
62
|
+
return null;
|
|
63
|
+
},
|
|
64
|
+
sign: async (transactionContext = {}) => {
|
|
65
|
+
const { orderPayment, order, paymentProvider } = context;
|
|
66
|
+
const { userId, name, email } = await assertUserData(order?.userId);
|
|
67
|
+
if (orderPayment) {
|
|
68
|
+
if (!order)
|
|
69
|
+
throw new Error('order not found in context');
|
|
70
|
+
const pricing = OrderPricingSheet({
|
|
71
|
+
calculation: order?.calculation,
|
|
72
|
+
currencyCode: order?.currencyCode,
|
|
73
|
+
});
|
|
74
|
+
const paymentIntent = await createOrderPaymentIntent({ userId, name, email, order, orderPayment, pricing, descriptorPrefix }, transactionContext);
|
|
75
|
+
return paymentIntent.client_secret;
|
|
76
|
+
}
|
|
77
|
+
const paymentIntent = await createRegistrationIntent({ userId, name, email, paymentProviderId: paymentProvider._id, descriptorPrefix }, transactionContext);
|
|
78
|
+
return paymentIntent.client_secret;
|
|
79
|
+
},
|
|
80
|
+
charge: async ({ paymentIntentId, paymentCredentials }) => {
|
|
81
|
+
if (!paymentIntentId && !paymentCredentials) {
|
|
82
|
+
throw new Error('You have to provide paymentIntentId or paymentCredentials');
|
|
83
|
+
}
|
|
84
|
+
const { order, orderPayment } = context;
|
|
85
|
+
if (!order)
|
|
86
|
+
throw new Error('order not found in context');
|
|
87
|
+
if (!orderPayment)
|
|
88
|
+
throw new Error('orderPayment not found in context');
|
|
89
|
+
const { userId, name, email } = await assertUserData(order?.userId);
|
|
90
|
+
const pricing = OrderPricingSheet({
|
|
91
|
+
calculation: order.calculation,
|
|
92
|
+
currencyCode: order.currencyCode,
|
|
93
|
+
});
|
|
94
|
+
const paymentIntentObject = paymentIntentId
|
|
95
|
+
? await stripe.paymentIntents.retrieve(paymentIntentId)
|
|
96
|
+
: await createOrderPaymentIntent({ userId, name, email, orderPayment, order, pricing, descriptorPrefix }, {
|
|
97
|
+
customer: paymentCredentials.meta?.customer,
|
|
98
|
+
confirm: true,
|
|
99
|
+
payment_method: paymentCredentials.token,
|
|
100
|
+
payment_method_types: paymentCredentials.meta?.payment_method_types,
|
|
101
|
+
});
|
|
102
|
+
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
103
|
+
if (paymentIntentObject.currency !== currencyCode.toLowerCase() ||
|
|
104
|
+
paymentIntentObject.amount !== Math.round(amount)) {
|
|
105
|
+
throw new Error('The price has changed since the intent has been created');
|
|
106
|
+
}
|
|
107
|
+
if (paymentIntentObject.metadata?.orderPaymentId !== orderPayment?._id) {
|
|
108
|
+
throw new Error('The order payment is different from the initiating intent');
|
|
109
|
+
}
|
|
110
|
+
if (paymentIntentObject.status === 'succeeded') {
|
|
111
|
+
return paymentIntentObject;
|
|
112
|
+
}
|
|
113
|
+
logger.info('Charge postponed because paymentIntent has wrong status', {
|
|
114
|
+
orderPaymentId: paymentIntentObject.id,
|
|
115
|
+
});
|
|
116
|
+
return false;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
return adapterActions;
|
|
120
|
+
},
|
|
121
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
+
export declare const WebhookEventTypes: {
|
|
3
|
+
PAYMENT_INTENT_SUCCEEDED: string;
|
|
4
|
+
SETUP_INTENT_SUCCEEDED: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function stripeWebhookHandler(request: Request, context: UnchainedCore): Promise<Response>;
|