@unchainedshop/plugins 3.1.15 → 4.0.0-rc.11
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/delivery/pick-mup.js +0 -2
- package/lib/delivery/pick-mup.js.map +1 -1
- package/lib/files/gridfs/adapter.d.ts.map +1 -1
- package/lib/files/gridfs/adapter.js +2 -2
- package/lib/files/gridfs/adapter.js.map +1 -1
- package/lib/files/gridfs/handler-express.d.ts.map +1 -1
- package/lib/files/gridfs/handler-express.js +6 -1
- 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 +5 -1
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/gridfs/module.d.ts +2 -2
- package/lib/files/gridfs/module.d.ts.map +1 -1
- package/lib/filters/local-search.d.ts.map +1 -1
- package/lib/filters/local-search.js +9 -2
- package/lib/filters/local-search.js.map +1 -1
- package/lib/filters/strict-equal.js +18 -0
- package/lib/filters/strict-equal.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +6 -13
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/fix-periods.d.ts.map +1 -1
- package/lib/payment/apple-iap/fix-periods.js +3 -5
- package/lib/payment/apple-iap/fix-periods.js.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +4 -4
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +4 -4
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/apple-iap/module.d.ts +2 -2
- package/lib/payment/apple-iap/module.d.ts.map +1 -1
- package/lib/payment/braintree.js +3 -4
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -2
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.js.map +1 -1
- package/lib/payment/cryptopay/handle-webhook.js +1 -1
- 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 -57
- 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 +4 -56
- package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/module.d.ts +26 -26
- package/lib/payment/cryptopay/module.d.ts.map +1 -1
- package/lib/payment/cryptopay/module.js +26 -24
- 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 +33 -79
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/api/types.d.ts +41 -41
- package/lib/payment/datatrans-v2/api/types.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/getPaths.d.ts +2 -2
- package/lib/payment/datatrans-v2/getPaths.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/index.js +16 -14
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +3 -3
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -1
- package/lib/payment/paypal-checkout.js +6 -8
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/api/index.d.ts +2 -2
- package/lib/payment/payrexx/api/index.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
- package/lib/payment/payrexx/index.js +4 -4
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/payrexx.js +2 -2
- package/lib/payment/payrexx/payrexx.js.map +1 -1
- 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 +5 -5
- 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 +6 -6
- 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 +27 -30
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/types.d.ts +4 -4
- package/lib/payment/postfinance-checkout/types.d.ts.map +1 -1
- 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 +5 -6
- 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 +4 -6
- package/lib/payment/saferpay/adapter.js.map +1 -1
- package/lib/payment/saferpay/api/models/Transaction.d.ts +2 -2
- package/lib/payment/saferpay/api/models/Transaction.d.ts.map +1 -1
- package/lib/payment/saferpay/module.d.ts +2 -2
- package/lib/payment/saferpay/module.d.ts.map +1 -1
- package/lib/payment/stripe/index.js +5 -5
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/stripe.js +3 -3
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/presets/all.d.ts +15 -13
- 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 +2 -2
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/order-delivery.js +1 -1
- package/lib/pricing/order-delivery.js.map +1 -1
- package/lib/pricing/order-discount.js +3 -3
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-items-discount.js +1 -1
- package/lib/pricing/order-items-discount.js.map +1 -1
- package/lib/pricing/order-items.js +1 -1
- package/lib/pricing/order-items.js.map +1 -1
- package/lib/pricing/order-payment.js +1 -1
- package/lib/pricing/order-payment.js.map +1 -1
- package/lib/pricing/order-round.d.ts +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +8 -8
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts +0 -1
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +6 -18
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +2 -2
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-round.d.ts +1 -1
- package/lib/pricing/product-round.d.ts.map +1 -1
- package/lib/pricing/product-round.js +2 -2
- package/lib/pricing/product-round.js.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +1 -1
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +2 -2
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/warehousing/eth-minter.js +2 -2
- 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.js +1 -1
- 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/enrollment-order-generator.js +1 -1
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/error-notifications.d.ts +4 -4
- package/lib/worker/error-notifications.d.ts.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/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 +56 -0
- package/lib/worker/twilio.js.map +1 -0
- package/lib/worker/update-coinbase-rates.js +1 -1
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/package.json +32 -53
- package/src/delivery/pick-mup.ts +0 -2
- package/src/files/gridfs/adapter.ts +6 -2
- package/src/files/gridfs/handler-express.ts +9 -1
- package/src/files/gridfs/handler-fastify.ts +8 -1
- package/src/files/gridfs/module.ts +2 -2
- package/src/filters/local-search.ts +11 -2
- package/src/filters/strict-equal.ts +21 -0
- package/src/payment/apple-iap/adapter.ts +7 -14
- package/src/payment/apple-iap/fix-periods.ts +4 -7
- package/src/payment/apple-iap/handler-express.ts +4 -4
- package/src/payment/apple-iap/handler-fastify.ts +4 -4
- package/src/payment/apple-iap/module.ts +2 -2
- package/src/payment/braintree.ts +3 -4
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -2
- package/src/payment/cryptopay/denote-amount.test.ts +28 -0
- package/src/payment/cryptopay/denote-amount.ts +29 -0
- package/src/payment/cryptopay/derive-btc-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-btc-address.ts +48 -0
- package/src/payment/cryptopay/derive-eth-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-eth-address.ts +38 -0
- package/src/payment/cryptopay/handle-webhook.ts +103 -0
- package/src/payment/cryptopay/handler-express.ts +4 -70
- package/src/payment/cryptopay/handler-fastify.ts +6 -71
- package/src/payment/cryptopay/module.ts +44 -40
- package/src/payment/cryptopay/plugin.ts +50 -87
- package/src/payment/cryptopay/readme.md +23 -1
- package/src/payment/datatrans-v2/api/types.ts +41 -41
- package/src/payment/datatrans-v2/getPaths.ts +2 -2
- package/src/payment/datatrans-v2/index.ts +17 -15
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +4 -4
- package/src/payment/paypal-checkout.ts +6 -11
- package/src/payment/payrexx/api/index.ts +2 -2
- package/src/payment/payrexx/api/makeFetcher.ts +1 -1
- package/src/payment/payrexx/index.ts +4 -4
- package/src/payment/payrexx/payrexx.ts +2 -2
- package/src/payment/postfinance-checkout/api-client.ts +106 -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 +5 -7
- package/src/payment/postfinance-checkout/handler-fastify.ts +6 -8
- package/src/payment/postfinance-checkout/index.ts +43 -35
- package/src/payment/postfinance-checkout/types.ts +6 -6
- package/src/payment/postfinance-checkout/utils.ts +7 -12
- package/src/payment/saferpay/adapter.ts +4 -6
- package/src/payment/saferpay/api/models/Transaction.ts +2 -2
- package/src/payment/saferpay/module.ts +2 -2
- package/src/payment/stripe/index.ts +5 -5
- package/src/payment/stripe/stripe.ts +3 -3
- package/src/presets/all.ts +3 -1
- package/src/pricing/delivery-swiss-tax.ts +6 -2
- package/src/pricing/order-delivery.ts +1 -1
- package/src/pricing/order-discount.ts +3 -3
- package/src/pricing/order-items-discount.ts +1 -1
- package/src/pricing/order-items.ts +1 -1
- package/src/pricing/order-payment.ts +1 -1
- package/src/pricing/order-round.ts +9 -9
- package/src/pricing/product-catalog-price.ts +6 -25
- package/src/pricing/product-price-rateconversion.ts +2 -2
- package/src/pricing/product-round.ts +3 -3
- package/src/pricing/product-swiss-tax.test.ts +6 -6
- package/src/pricing/product-swiss-tax.ts +2 -2
- package/src/warehousing/eth-minter.ts +2 -2
- package/src/worker/budgetsms.ts +268 -0
- package/src/worker/bulk-import.ts +1 -1
- package/src/worker/bulkgate.ts +138 -0
- package/src/worker/enrollment-order-generator.ts +3 -3
- package/src/worker/error-notifications.ts +4 -4
- package/src/worker/heartbeat.ts +4 -11
- package/src/worker/message.ts +1 -1
- package/src/worker/push-notification.ts +2 -2
- package/src/worker/twilio.ts +71 -0
- package/src/worker/update-coinbase-rates.ts +3 -6
- package/src/worker/update-ecb-rates.ts +3 -3
- package/lib/accounts/google-oauth.d.ts +0 -4
- package/lib/accounts/google-oauth.d.ts.map +0 -1
- package/lib/accounts/google-oauth.js +0 -145
- package/lib/accounts/google-oauth.js.map +0 -1
- package/lib/accounts/linkedin-oauth.d.ts +0 -4
- package/lib/accounts/linkedin-oauth.d.ts.map +0 -1
- package/lib/accounts/linkedin-oauth.js +0 -82
- package/lib/accounts/linkedin-oauth.js.map +0 -1
- package/lib/files/gridfs/gridfs-adapter.d.ts +0 -3
- package/lib/files/gridfs/gridfs-adapter.d.ts.map +0 -1
- package/lib/files/gridfs/gridfs-adapter.js +0 -97
- package/lib/files/gridfs/gridfs-adapter.js.map +0 -1
- package/lib/files/gridfs/gridfs-webhook.d.ts +0 -11
- package/lib/files/gridfs/gridfs-webhook.d.ts.map +0 -1
- package/lib/files/gridfs/gridfs-webhook.js +0 -84
- package/lib/files/gridfs/gridfs-webhook.js.map +0 -1
- package/lib/files/minio/minio-adapter.d.ts +0 -6
- package/lib/files/minio/minio-adapter.d.ts.map +0 -1
- package/lib/files/minio/minio-adapter.js +0 -181
- package/lib/files/minio/minio-adapter.js.map +0 -1
- package/lib/files/minio/minio-webhook.d.ts +0 -2
- package/lib/files/minio/minio-webhook.d.ts.map +0 -1
- package/lib/files/minio/minio-webhook.js +0 -33
- package/lib/files/minio/minio-webhook.js.map +0 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +0 -9
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +0 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +0 -17
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +0 -1
- package/lib/payment/cryptopay/middleware.d.ts +0 -2
- package/lib/payment/cryptopay/middleware.d.ts.map +0 -1
- package/lib/payment/cryptopay/middleware.js +0 -75
- package/lib/payment/cryptopay/middleware.js.map +0 -1
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +0 -25
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +0 -1
- package/lib/payment/cryptopay/module/configureCryptopayModule.js +0 -75
- package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +0 -1
- package/lib/payment/datatrans-v2/middleware.d.ts +0 -2
- package/lib/payment/datatrans-v2/middleware.d.ts.map +0 -1
- package/lib/payment/datatrans-v2/middleware.js +0 -68
- package/lib/payment/datatrans-v2/middleware.js.map +0 -1
- package/lib/payment/payrexx/middleware.d.ts +0 -2
- package/lib/payment/payrexx/middleware.d.ts.map +0 -1
- package/lib/payment/payrexx/middleware.js +0 -86
- package/lib/payment/payrexx/middleware.js.map +0 -1
- package/lib/payment/postfinance-checkout/middleware.d.ts +0 -2
- package/lib/payment/postfinance-checkout/middleware.d.ts.map +0 -1
- package/lib/payment/postfinance-checkout/middleware.js +0 -38
- package/lib/payment/postfinance-checkout/middleware.js.map +0 -1
- package/lib/payment/saferpay/middleware.d.ts +0 -2
- package/lib/payment/saferpay/middleware.d.ts.map +0 -1
- package/lib/payment/saferpay/middleware.js +0 -57
- package/lib/payment/saferpay/middleware.js.map +0 -1
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +0 -10
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +0 -1
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +0 -24
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +0 -1
- package/lib/payment/stripe/middleware.d.ts +0 -6
- package/lib/payment/stripe/middleware.d.ts.map +0 -1
- package/lib/payment/stripe/middleware.js +0 -114
- package/lib/payment/stripe/middleware.js.map +0 -1
- package/lib/plugins-index.d.ts +0 -48
- package/lib/plugins-index.d.ts.map +0 -1
- package/lib/plugins-index.js +0 -107
- package/lib/plugins-index.js.map +0 -1
- package/lib/worker/BaseWorker.d.ts +0 -30
- package/lib/worker/BaseWorker.d.ts.map +0 -1
- package/lib/worker/BaseWorker.js +0 -79
- package/lib/worker/BaseWorker.js.map +0 -1
- package/lib/worker/EventListenerWorker.d.ts +0 -6
- package/lib/worker/EventListenerWorker.d.ts.map +0 -1
- package/lib/worker/EventListenerWorker.js +0 -46
- package/lib/worker/EventListenerWorker.js.map +0 -1
- package/lib/worker/FailedRescheduler.d.ts +0 -15
- package/lib/worker/FailedRescheduler.d.ts.map +0 -1
- package/lib/worker/FailedRescheduler.js +0 -45
- package/lib/worker/FailedRescheduler.js.map +0 -1
- package/lib/worker/IntervalWorker.d.ts +0 -10
- package/lib/worker/IntervalWorker.d.ts.map +0 -1
- package/lib/worker/IntervalWorker.js +0 -37
- package/lib/worker/IntervalWorker.js.map +0 -1
- package/src/worker/BaseWorker.ts +0 -116
- package/src/worker/EventListenerWorker.ts +0 -61
- package/src/worker/FailedRescheduler.ts +0 -80
- package/src/worker/IntervalWorker.ts +0 -54
- package/src/worker/sms.ts +0 -87
|
@@ -5,9 +5,8 @@ export type CryptopayTransaction = {
|
|
|
5
5
|
blockHeight: number;
|
|
6
6
|
mostRecentBlockHeight: number;
|
|
7
7
|
amount: mongodb.Decimal128;
|
|
8
|
-
|
|
8
|
+
currencyCode: string;
|
|
9
9
|
decimals: number;
|
|
10
|
-
contract: string;
|
|
11
10
|
orderPaymentId?: string;
|
|
12
11
|
} & TimestampFields;
|
|
13
12
|
export declare const CryptopayTransactionsCollection: (db: mongodb.Db) => mongodb.Collection<CryptopayTransaction>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptopayTransactions.d.ts","sourceRoot":"","sources":["../../../../src/payment/cryptopay/db/CryptopayTransactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC;IAC3B,
|
|
1
|
+
{"version":3,"file":"CryptopayTransactions.d.ts","sourceRoot":"","sources":["../../../../src/payment/cryptopay/db/CryptopayTransactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,eAAe,CAAC;AAEpB,eAAO,MAAM,+BAA+B,GAAI,IAAI,OAAO,CAAC,EAAE,6CAE7D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptopayTransactions.js","sourceRoot":"","sources":["../../../../src/payment/cryptopay/db/CryptopayTransactions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CryptopayTransactions.js","sourceRoot":"","sources":["../../../../src/payment/cryptopay/db/CryptopayTransactions.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,EAAc,EAAE,EAAE;IAChE,OAAO,EAAE,CAAC,UAAU,CAAuB,wBAAwB,CAAC,CAAC;AACvE,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createLogger } from '@unchainedshop/logger';
|
|
2
2
|
import { OrderStatus } from '@unchainedshop/core-orders';
|
|
3
3
|
const { CRYPTOPAY_SECRET, CRYPTOPAY_MAX_RATE_AGE = '360' } = process.env;
|
|
4
|
-
const logger = createLogger('unchained:core-payment:cryptopay');
|
|
4
|
+
const logger = createLogger('unchained:core-payment:cryptopay:handler');
|
|
5
5
|
export default async function handleWebhook({ secret, wallet, price, ping, }, context) {
|
|
6
6
|
const { modules, services } = context;
|
|
7
7
|
if (secret !== CRYPTOPAY_SECRET) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle-webhook.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/handle-webhook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAIzD,MAAM,EAAE,gBAAgB,EAAE,sBAAsB,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEzE,MAAM,MAAM,GAAG,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"handle-webhook.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/handle-webhook.ts"],"names":[],"mappings":"A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MAAM,OAAO,CAAC,SAAS,CAAC,qBAAqB,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-express.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-express.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler-express.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-express.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,gBAAgB,GAAU,QAAG,EAAE,QAAG,kBAgBvC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,69 +1,16 @@
|
|
|
1
1
|
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
const logger = createLogger('unchained:core-payment:cryptopay');
|
|
2
|
+
import handleWebhook from './handle-webhook.js';
|
|
3
|
+
const logger = createLogger('unchained:core-payment:cryptopay:handler');
|
|
5
4
|
const cryptopayHandler = async (req, res) => {
|
|
6
|
-
const resolvedContext = req.unchainedContext;
|
|
7
|
-
const { modules, services } = resolvedContext;
|
|
8
5
|
if (req.method === 'POST') {
|
|
9
6
|
try {
|
|
10
|
-
|
|
11
|
-
if (secret !== CRYPTOPAY_SECRET) {
|
|
12
|
-
logger.warn(`Cryptopay Plugin: Invalid Cryptopay Secret provided`);
|
|
13
|
-
throw new Error('Secret invalid');
|
|
14
|
-
}
|
|
15
|
-
if (wallet) {
|
|
16
|
-
const { address, blockHeight, amount, contract, decimals, currency } = wallet;
|
|
17
|
-
const { orderPaymentId } = await modules.cryptopay.updateWalletAddress({
|
|
18
|
-
addressId: address,
|
|
19
|
-
blockHeight,
|
|
20
|
-
amount,
|
|
21
|
-
contract,
|
|
22
|
-
decimals,
|
|
23
|
-
currency,
|
|
24
|
-
});
|
|
25
|
-
const orderPayment = orderPaymentId &&
|
|
26
|
-
(await modules.orders.payments.findOrderPayment({
|
|
27
|
-
orderPaymentId,
|
|
28
|
-
}));
|
|
29
|
-
if (orderPayment) {
|
|
30
|
-
// Try to process order to next status
|
|
31
|
-
// TODO: Not sure if it's correct to use processOrder here if status is PENDING!
|
|
32
|
-
const order = await modules.orders.findOrder({ orderId: orderPayment.orderId });
|
|
33
|
-
if (order.status === null) {
|
|
34
|
-
await services.orders.checkoutOrder(order._id, {});
|
|
35
|
-
}
|
|
36
|
-
else if (order.status === OrderStatus.PENDING) {
|
|
37
|
-
await services.orders.processOrder(order, {});
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
throw new Error('Already processed');
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (price) {
|
|
45
|
-
const { baseCurrency, token, rate, timestamp } = price;
|
|
46
|
-
const timestampDate = new Date(timestamp);
|
|
47
|
-
const expiresAt = new Date(new Date().getTime() + parseInt(CRYPTOPAY_MAX_RATE_AGE, 10) * 1000);
|
|
48
|
-
const rateData = {
|
|
49
|
-
baseCurrency,
|
|
50
|
-
quoteCurrency: token,
|
|
51
|
-
rate,
|
|
52
|
-
expiresAt,
|
|
53
|
-
timestamp: timestampDate,
|
|
54
|
-
};
|
|
55
|
-
logger.info(`update rate ${JSON.stringify(price)}, ${JSON.stringify(rateData)}`);
|
|
56
|
-
await resolvedContext.modules.products.prices.rates.updateRates([rateData]);
|
|
57
|
-
}
|
|
58
|
-
if (ping) {
|
|
59
|
-
const { blockHeight, currency } = ping;
|
|
60
|
-
await modules.cryptopay.updateMostRecentBlock(currency, blockHeight);
|
|
61
|
-
}
|
|
7
|
+
await handleWebhook(req.body, req.unchainedContext);
|
|
62
8
|
res.writeHead(200);
|
|
63
9
|
res.end(JSON.stringify({ success: true }));
|
|
64
10
|
return;
|
|
65
11
|
}
|
|
66
12
|
catch (e) {
|
|
13
|
+
logger.error(e);
|
|
67
14
|
res.writeHead(500);
|
|
68
15
|
res.end(JSON.stringify({ success: false, error: e.message }));
|
|
69
16
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-express.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-express.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"handler-express.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-express.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAEhD,MAAM,MAAM,GAAG,YAAY,CAAC,0CAA0C,CAAC,CAAC;AAExE,MAAM,gBAAgB,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IAC1C,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,MAAM,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;YACpD,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACnB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC3C,OAAO;QACT,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAChB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACnB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC9D,OAAO;QACT,CAAC;IACH,CAAC;IACD,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACnB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-fastify.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-fastify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler-fastify.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-fastify.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAI7D,QAAA,MAAM,gBAAgB,EAAE,kBAevB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,66 +1,14 @@
|
|
|
1
1
|
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
const logger = createLogger('unchained:core-payment:cryptopay');
|
|
2
|
+
import handleWebhook from './handle-webhook.js';
|
|
3
|
+
const logger = createLogger('unchained:core-payment:cryptopay:handler');
|
|
5
4
|
const cryptopayHandler = async (req, reply) => {
|
|
6
|
-
const { modules, services } = req.unchainedContext;
|
|
7
5
|
try {
|
|
8
|
-
|
|
9
|
-
if (secret !== CRYPTOPAY_SECRET) {
|
|
10
|
-
logger.warn(`Cryptopay Plugin: Invalid Cryptopay Secret provided`);
|
|
11
|
-
throw new Error('Secret invalid');
|
|
12
|
-
}
|
|
13
|
-
if (wallet) {
|
|
14
|
-
const { address, blockHeight, amount, contract, decimals, currency } = wallet;
|
|
15
|
-
const { orderPaymentId } = await modules.cryptopay.updateWalletAddress({
|
|
16
|
-
addressId: address,
|
|
17
|
-
blockHeight,
|
|
18
|
-
amount,
|
|
19
|
-
contract,
|
|
20
|
-
decimals,
|
|
21
|
-
currency,
|
|
22
|
-
});
|
|
23
|
-
const orderPayment = orderPaymentId &&
|
|
24
|
-
(await modules.orders.payments.findOrderPayment({
|
|
25
|
-
orderPaymentId,
|
|
26
|
-
}));
|
|
27
|
-
if (orderPayment) {
|
|
28
|
-
// Try to process order to next status
|
|
29
|
-
// TODO: Not sure if it's correct to use processOrder here if status is PENDING!
|
|
30
|
-
const order = await modules.orders.findOrder({ orderId: orderPayment.orderId });
|
|
31
|
-
if (order.status === null) {
|
|
32
|
-
await services.orders.checkoutOrder(order._id, {});
|
|
33
|
-
}
|
|
34
|
-
else if (order.status === OrderStatus.PENDING) {
|
|
35
|
-
await services.orders.processOrder(order, {});
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
throw new Error('Already processed');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (price) {
|
|
43
|
-
const { baseCurrency, token, rate, timestamp } = price;
|
|
44
|
-
const timestampDate = new Date(timestamp);
|
|
45
|
-
const expiresAt = new Date(new Date().getTime() + parseInt(CRYPTOPAY_MAX_RATE_AGE, 10) * 1000);
|
|
46
|
-
const rateData = {
|
|
47
|
-
baseCurrency,
|
|
48
|
-
quoteCurrency: token,
|
|
49
|
-
rate,
|
|
50
|
-
expiresAt,
|
|
51
|
-
timestamp: timestampDate,
|
|
52
|
-
};
|
|
53
|
-
logger.info(`update rate ${JSON.stringify(price)}, ${JSON.stringify(rateData)}`);
|
|
54
|
-
await modules.products.prices.rates.updateRates([rateData]);
|
|
55
|
-
}
|
|
56
|
-
if (ping) {
|
|
57
|
-
const { blockHeight, currency } = ping;
|
|
58
|
-
await modules.cryptopay.updateMostRecentBlock(currency, blockHeight);
|
|
59
|
-
}
|
|
6
|
+
await handleWebhook(req.body, req.unchainedContext);
|
|
60
7
|
reply.status(200);
|
|
61
8
|
return reply.send({ success: true });
|
|
62
9
|
}
|
|
63
10
|
catch (e) {
|
|
11
|
+
logger.error(e);
|
|
64
12
|
reply.status(500);
|
|
65
13
|
return reply.send({ success: false, error: e.message });
|
|
66
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-fastify.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-fastify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler-fastify.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/handler-fastify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAGhD,MAAM,MAAM,GAAG,YAAY,CAAC,0CAA0C,CAAC,CAAC;AAExE,MAAM,gBAAgB,GAAuB,KAAK,EAChD,GAEC,EACD,KAAK,EACL,EAAE;IACF,IAAI,CAAC;QACH,MAAM,aAAa,CAAC,GAAG,CAAC,IAAW,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC3D,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -2,23 +2,23 @@ import { CryptopayTransaction } from './db/CryptopayTransactions.js';
|
|
|
2
2
|
declare const configureCryptopayModule: ({ db }: {
|
|
3
3
|
db: any;
|
|
4
4
|
}) => {
|
|
5
|
-
getWalletAddress: (
|
|
6
|
-
updateMostRecentBlock: (
|
|
7
|
-
updateWalletAddress: ({
|
|
8
|
-
|
|
5
|
+
getWalletAddress: (address: string, contract?: string) => Promise<CryptopayTransaction>;
|
|
6
|
+
updateMostRecentBlock: (currencyCode: string, blockHeight: number) => Promise<void>;
|
|
7
|
+
updateWalletAddress: ({ address, blockHeight, amount, contract, currencyCode, decimals, }: {
|
|
8
|
+
address: string;
|
|
9
9
|
blockHeight: number;
|
|
10
|
-
amount: string;
|
|
11
|
-
contract
|
|
12
|
-
|
|
10
|
+
amount: string | number;
|
|
11
|
+
contract?: string;
|
|
12
|
+
currencyCode: string;
|
|
13
13
|
decimals: number;
|
|
14
14
|
}) => Promise<CryptopayTransaction>;
|
|
15
|
-
mapOrderPaymentToWalletAddress: ({
|
|
16
|
-
|
|
17
|
-
contract
|
|
18
|
-
|
|
15
|
+
mapOrderPaymentToWalletAddress: ({ address, contract, currencyCode, orderPaymentId, }: {
|
|
16
|
+
address: string;
|
|
17
|
+
contract?: string;
|
|
18
|
+
currencyCode: string;
|
|
19
19
|
orderPaymentId: string;
|
|
20
20
|
}) => Promise<CryptopayTransaction>;
|
|
21
|
-
getNextDerivationNumber: (
|
|
21
|
+
getNextDerivationNumber: (currencyCode: string) => Promise<number>;
|
|
22
22
|
getWalletAddressesByOrderPaymentId: (orderPaymentId: string) => Promise<CryptopayTransaction[]>;
|
|
23
23
|
};
|
|
24
24
|
declare const _default: {
|
|
@@ -26,29 +26,29 @@ declare const _default: {
|
|
|
26
26
|
configure: ({ db }: {
|
|
27
27
|
db: any;
|
|
28
28
|
}) => {
|
|
29
|
-
getWalletAddress: (
|
|
30
|
-
updateMostRecentBlock: (
|
|
31
|
-
updateWalletAddress: ({
|
|
32
|
-
|
|
29
|
+
getWalletAddress: (address: string, contract?: string) => Promise<CryptopayTransaction>;
|
|
30
|
+
updateMostRecentBlock: (currencyCode: string, blockHeight: number) => Promise<void>;
|
|
31
|
+
updateWalletAddress: ({ address, blockHeight, amount, contract, currencyCode, decimals, }: {
|
|
32
|
+
address: string;
|
|
33
33
|
blockHeight: number;
|
|
34
|
-
amount: string;
|
|
35
|
-
contract
|
|
36
|
-
|
|
34
|
+
amount: string | number;
|
|
35
|
+
contract?: string;
|
|
36
|
+
currencyCode: string;
|
|
37
37
|
decimals: number;
|
|
38
38
|
}) => Promise<CryptopayTransaction>;
|
|
39
|
-
mapOrderPaymentToWalletAddress: ({
|
|
40
|
-
|
|
41
|
-
contract
|
|
42
|
-
|
|
39
|
+
mapOrderPaymentToWalletAddress: ({ address, contract, currencyCode, orderPaymentId, }: {
|
|
40
|
+
address: string;
|
|
41
|
+
contract?: string;
|
|
42
|
+
currencyCode: string;
|
|
43
43
|
orderPaymentId: string;
|
|
44
44
|
}) => Promise<CryptopayTransaction>;
|
|
45
|
-
getNextDerivationNumber: (
|
|
45
|
+
getNextDerivationNumber: (currencyCode: string) => Promise<number>;
|
|
46
46
|
getWalletAddressesByOrderPaymentId: (orderPaymentId: string) => Promise<CryptopayTransaction[]>;
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
50
|
export default _default;
|
|
51
|
-
export
|
|
51
|
+
export interface CryptopayModule {
|
|
52
52
|
cryptopay: ReturnType<typeof configureCryptopayModule>;
|
|
53
|
-
}
|
|
53
|
+
}
|
|
54
54
|
//# sourceMappingURL=module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAmC,MAAM,+BAA+B,CAAC;AAEtG,QAAA,MAAM,wBAAwB,GAAI;;CAAM;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAmC,MAAM,+BAA+B,CAAC;AAEtG,QAAA,MAAM,wBAAwB,GAAI;;CAAM;gCAGG,MAAM,aAAa,MAAM,KAAG,OAAO,CAAC,oBAAoB,CAAC;0CAK/C,MAAM,eAAe,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;+FA0E3F;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;QACxB,QAAQ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|
|
2
2
|
import { CryptopayTransactionsCollection } from './db/CryptopayTransactions.js';
|
|
3
3
|
const configureCryptopayModule = ({ db }) => {
|
|
4
4
|
const CryptoTransactions = CryptopayTransactionsCollection(db);
|
|
5
|
-
const getWalletAddress = async (
|
|
6
|
-
|
|
5
|
+
const getWalletAddress = async (address, contract) => {
|
|
6
|
+
const addressId = [address, contract].filter(Boolean).join(':');
|
|
7
|
+
return CryptoTransactions.findOne({ _id: addressId });
|
|
7
8
|
};
|
|
8
|
-
const updateMostRecentBlock = async (
|
|
9
|
+
const updateMostRecentBlock = async (currencyCode, blockHeight) => {
|
|
9
10
|
await CryptoTransactions.updateMany({
|
|
10
|
-
|
|
11
|
+
currencyCode,
|
|
11
12
|
}, {
|
|
12
13
|
$set: {
|
|
13
14
|
mostRecentBlockHeight: blockHeight,
|
|
14
15
|
},
|
|
15
16
|
});
|
|
16
17
|
};
|
|
17
|
-
const mapOrderPaymentToWalletAddress = async ({
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const mapOrderPaymentToWalletAddress = async ({ address, contract, currencyCode, orderPaymentId, }) => {
|
|
19
|
+
const addressId = [address, contract].filter(Boolean).join(':');
|
|
20
|
+
return CryptoTransactions.findOneAndUpdate({
|
|
21
|
+
_id: addressId,
|
|
20
22
|
}, {
|
|
21
23
|
$setOnInsert: {
|
|
22
|
-
_id: addressId
|
|
23
|
-
|
|
24
|
-
currency,
|
|
25
|
-
decimals: null,
|
|
24
|
+
_id: addressId,
|
|
25
|
+
currencyCode,
|
|
26
26
|
mostRecentBlockHeight: 0,
|
|
27
27
|
blockHeight: 0,
|
|
28
28
|
amount: mongodb.Decimal128.fromString('0'),
|
|
@@ -32,36 +32,38 @@ const configureCryptopayModule = ({ db }) => {
|
|
|
32
32
|
orderPaymentId,
|
|
33
33
|
updated: new Date(),
|
|
34
34
|
},
|
|
35
|
-
}, { upsert: true });
|
|
36
|
-
return CryptoTransactions.findOne({ _id: addressId.toLowerCase() });
|
|
35
|
+
}, { upsert: true, returnDocument: 'after' });
|
|
37
36
|
};
|
|
38
|
-
const getNextDerivationNumber = async (
|
|
39
|
-
return (await CryptoTransactions.countDocuments({
|
|
37
|
+
const getNextDerivationNumber = async (currencyCode) => {
|
|
38
|
+
return (await CryptoTransactions.countDocuments({ currencyCode })) + 1;
|
|
40
39
|
};
|
|
41
40
|
const getWalletAddressesByOrderPaymentId = async (orderPaymentId) => {
|
|
42
41
|
return CryptoTransactions.find({
|
|
43
42
|
orderPaymentId,
|
|
43
|
+
}, {
|
|
44
|
+
sort: {
|
|
45
|
+
created: 1, // Sort by creation date, most recent first
|
|
46
|
+
},
|
|
44
47
|
}).toArray();
|
|
45
48
|
};
|
|
46
|
-
const updateWalletAddress = async ({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const updateWalletAddress = async ({ address, blockHeight, amount, contract, currencyCode, decimals, }) => {
|
|
50
|
+
const addressId = [address, contract].filter(Boolean).join(':');
|
|
51
|
+
return CryptoTransactions.findOneAndUpdate({
|
|
52
|
+
_id: addressId,
|
|
49
53
|
}, {
|
|
50
54
|
$setOnInsert: {
|
|
51
|
-
_id: addressId
|
|
52
|
-
currency,
|
|
53
|
-
contract,
|
|
55
|
+
_id: addressId,
|
|
54
56
|
created: new Date(),
|
|
55
57
|
},
|
|
56
58
|
$set: {
|
|
59
|
+
currencyCode,
|
|
57
60
|
decimals,
|
|
58
61
|
blockHeight,
|
|
59
62
|
mostRecentBlockHeight: blockHeight,
|
|
60
|
-
amount: mongodb.Decimal128.fromString(amount),
|
|
63
|
+
amount: mongodb.Decimal128.fromString(typeof amount === 'number' ? `${amount}` : amount),
|
|
61
64
|
updated: new Date(),
|
|
62
65
|
},
|
|
63
|
-
}, { upsert: true });
|
|
64
|
-
return CryptoTransactions.findOne({ _id: addressId.toLowerCase() });
|
|
66
|
+
}, { upsert: true, returnDocument: 'after' });
|
|
65
67
|
};
|
|
66
68
|
return {
|
|
67
69
|
getWalletAddress,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAwB,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAEtG,MAAM,wBAAwB,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE;IAC1C,MAAM,kBAAkB,GAAG,+BAA+B,CAAC,EAAE,CAAC,CAAC;IAE/D,MAAM,gBAAgB,GAAG,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAwB,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAEtG,MAAM,wBAAwB,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE;IAC1C,MAAM,kBAAkB,GAAG,+BAA+B,CAAC,EAAE,CAAC,CAAC;IAE/D,MAAM,gBAAgB,GAAG,KAAK,EAAE,OAAe,EAAE,QAAiB,EAAiC,EAAE;QACnG,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChE,OAAO,kBAAkB,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;IACxD,CAAC,CAAC;IAEF,MAAM,qBAAqB,GAAG,KAAK,EAAE,YAAoB,EAAE,WAAmB,EAAiB,EAAE;QAC/F,MAAM,kBAAkB,CAAC,UAAU,CACjC;YACE,YAAY;SACb,EACD;YACE,IAAI,EAAE;gBACJ,qBAAqB,EAAE,WAAW;aACnC;SACF,CACF,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,8BAA8B,GAAG,KAAK,EAAE,EAC5C,OAAO,EACP,QAAQ,EAC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AO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChE,OAAO,kBAAkB,CAAC,gBAAgB,CACxC;YACE,GAAG,EAAE,SAAS;SACf,EACD;YACE,YAAY,EAAE;gBACZ,GAAG,EAAE,SAAS;gBACd,OAAO,EAAE,IAAI,IAAI,EAAE;aACpB;YACD,IAAI,EAAE;gBACJ,YAAY;gBACZ,QAAQ;gBACR,WAAW;gBACX,qBAAqB,EAAE,WAAW;gBAClC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;gBACxF,OAAO,EAAE,IAAI,IAAI,EAAE;aACpB;SACF,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,CAC1C,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,gBAAgB;QAChB,qBAAqB;QACrB,mBAAmB;QACnB,8BAA8B;QAC9B,uBAAuB;QACvB,kCAAkC;KACnC,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe;IACb,SAAS,EAAE;QACT,SAAS,EAAE,wBAAwB;KACpC;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAKhB,MAAM,qBAAqB,CAAC;AAwB7B,QAAA,MAAM,SAAS,EAAE,eAsOhB,CAAC;AAIF,eAAe,SAAS,CAAC"}
|
|
@@ -1,45 +1,10 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import { BIP32Factory } from 'bip32';
|
|
3
|
-
import bs58check from 'bs58check';
|
|
4
|
-
import * as ecc from 'tiny-secp256k1';
|
|
5
|
-
import { networks, payments } from 'bitcoinjs-lib';
|
|
6
|
-
import { createLogger } from '@unchainedshop/logger';
|
|
7
1
|
import { PaymentAdapter, PaymentDirector, PaymentError, OrderPricingSheet, } from '@unchainedshop/core';
|
|
2
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
+
import deriveBtcAddress from './derive-btc-address.js';
|
|
4
|
+
import deriveEthAddress from './derive-eth-address.js';
|
|
5
|
+
import denoteAmount from './denote-amount.js';
|
|
8
6
|
const logger = createLogger('unchained:core-payment:cryptopay');
|
|
9
7
|
const { CRYPTOPAY_SECRET, CRYPTOPAY_BTC_XPUB, CRYPTOPAY_ETH_XPUB } = process.env;
|
|
10
|
-
const resolvePath = (prefix) => {
|
|
11
|
-
if (prefix === 'x')
|
|
12
|
-
return `m/44'/0'`;
|
|
13
|
-
if (prefix === 'y')
|
|
14
|
-
return `m/49'/0'`;
|
|
15
|
-
if (prefix === 'z')
|
|
16
|
-
return `m/84'/0'`;
|
|
17
|
-
if (prefix === 't')
|
|
18
|
-
return `m/44'/1'`;
|
|
19
|
-
if (prefix === 'u')
|
|
20
|
-
return `m/49'/1'`;
|
|
21
|
-
if (prefix === 'v')
|
|
22
|
-
return `m/84'/1'`;
|
|
23
|
-
return `m`;
|
|
24
|
-
};
|
|
25
|
-
const resolveNetwork = (prefix) => {
|
|
26
|
-
if (['x', 'y', 'z'].includes(prefix))
|
|
27
|
-
return networks.bitcoin;
|
|
28
|
-
return networks.testnet;
|
|
29
|
-
};
|
|
30
|
-
function convertExtendedPublicKey(z) {
|
|
31
|
-
const derivationPath = resolvePath(z.slice(0, 1));
|
|
32
|
-
const network = resolveNetwork(z.slice(0, 1));
|
|
33
|
-
// https://github.com/satoshilabs/slips/blob/master/slip-0132.md
|
|
34
|
-
let data = bs58check.decode(z);
|
|
35
|
-
data = data.slice(4);
|
|
36
|
-
data = Buffer.concat([Buffer.from('0488b21e', 'hex'), data]);
|
|
37
|
-
return {
|
|
38
|
-
xpub: bs58check.encode(data),
|
|
39
|
-
network,
|
|
40
|
-
derivationPath,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
8
|
var CryptopayCurrencies;
|
|
44
9
|
(function (CryptopayCurrencies) {
|
|
45
10
|
CryptopayCurrencies["BTC"] = "BTC";
|
|
@@ -59,7 +24,7 @@ const Cryptopay = {
|
|
|
59
24
|
const originCurrencyObj = await modules.currencies.findCurrency({ isoCode: currencyCode });
|
|
60
25
|
const updatedAddresses = await Promise.all(existingAddresses.map(async (addressData) => {
|
|
61
26
|
const targetCurrencyObj = await modules.currencies.findCurrency({
|
|
62
|
-
isoCode: addressData.
|
|
27
|
+
isoCode: addressData.currencyCode,
|
|
63
28
|
});
|
|
64
29
|
if (!targetCurrencyObj?.isActive)
|
|
65
30
|
return null;
|
|
@@ -73,18 +38,18 @@ const Cryptopay = {
|
|
|
73
38
|
return updatedAddresses.filter(Boolean);
|
|
74
39
|
};
|
|
75
40
|
const updateTransactionsWithOrderPaymentId = async (orderPaymentId, cryptoAddresses) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
41
|
+
for (const cryptoAddress of cryptoAddresses) {
|
|
42
|
+
const { address, currencyCode } = cryptoAddress;
|
|
43
|
+
await modules.cryptopay.mapOrderPaymentToWalletAddress({
|
|
44
|
+
address,
|
|
45
|
+
currencyCode,
|
|
46
|
+
orderPaymentId,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
82
49
|
};
|
|
83
50
|
const adapterActions = {
|
|
84
51
|
...PaymentAdapter.actions(config, context),
|
|
85
|
-
// eslint-disable-next-line
|
|
86
52
|
configurationError() {
|
|
87
|
-
// eslint-disable-line
|
|
88
53
|
if (!CRYPTOPAY_SECRET) {
|
|
89
54
|
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
90
55
|
}
|
|
@@ -101,7 +66,7 @@ const Cryptopay = {
|
|
|
101
66
|
return true;
|
|
102
67
|
// if (
|
|
103
68
|
// !Object.values(CryptopayCurrencies).includes(
|
|
104
|
-
// context.order.
|
|
69
|
+
// context.order.currencyCode as CryptopayCurrencies,
|
|
105
70
|
// )
|
|
106
71
|
// )
|
|
107
72
|
// return false;
|
|
@@ -112,42 +77,35 @@ const Cryptopay = {
|
|
|
112
77
|
},
|
|
113
78
|
sign: async () => {
|
|
114
79
|
const { orderPayment, order } = context;
|
|
80
|
+
if (!orderPayment)
|
|
81
|
+
throw new Error('Payment Credential Registration is not yet supported for Cryptopay');
|
|
115
82
|
const existingAddresses = await modules.cryptopay.getWalletAddressesByOrderPaymentId(orderPayment._id);
|
|
116
83
|
if (existingAddresses.length) {
|
|
117
84
|
// Do not derive addresses a second time for order payment, return existing addresses
|
|
118
|
-
const existingAddressesWithNewExpiration = await setConversionRates(order.
|
|
85
|
+
const existingAddressesWithNewExpiration = await setConversionRates(order.currencyCode, existingAddresses.map(({ _id, currencyCode }) => ({
|
|
119
86
|
address: _id,
|
|
120
|
-
|
|
87
|
+
currencyCode,
|
|
121
88
|
})));
|
|
122
89
|
return JSON.stringify(existingAddressesWithNewExpiration);
|
|
123
90
|
}
|
|
124
91
|
const cryptoAddresses = [];
|
|
125
92
|
if (CRYPTOPAY_BTC_XPUB) {
|
|
126
|
-
const { xpub, network } = convertExtendedPublicKey(CRYPTOPAY_BTC_XPUB);
|
|
127
|
-
const bip32 = BIP32Factory(ecc);
|
|
128
|
-
const hardenedMaster = bip32.fromBase58(xpub, network);
|
|
129
93
|
const btcDerivationNumber = await modules.cryptopay.getNextDerivationNumber(CryptopayCurrencies.BTC);
|
|
130
|
-
const
|
|
94
|
+
const address = deriveBtcAddress(CRYPTOPAY_BTC_XPUB, btcDerivationNumber);
|
|
131
95
|
cryptoAddresses.push({
|
|
132
|
-
|
|
133
|
-
address
|
|
134
|
-
pubkey: child.publicKey,
|
|
135
|
-
network,
|
|
136
|
-
}).address,
|
|
96
|
+
currencyCode: CryptopayCurrencies.BTC,
|
|
97
|
+
address,
|
|
137
98
|
});
|
|
138
99
|
}
|
|
139
100
|
if (CRYPTOPAY_ETH_XPUB) {
|
|
140
|
-
// we neuter for security reasons, it's still quite complicated for most ethereum clients to show an appropriate
|
|
141
|
-
// xpub, that's why
|
|
142
|
-
const hdWallet = ethers.HDNodeWallet.fromExtendedKey(CRYPTOPAY_ETH_XPUB);
|
|
143
|
-
const hardenedMaster = 'neuter' in hdWallet ? hdWallet.neuter() : hdWallet;
|
|
144
101
|
const ethDerivationNumber = await modules.cryptopay.getNextDerivationNumber(CryptopayCurrencies.ETH);
|
|
102
|
+
const address = deriveEthAddress(CRYPTOPAY_ETH_XPUB, ethDerivationNumber);
|
|
145
103
|
cryptoAddresses.push({
|
|
146
|
-
|
|
147
|
-
address
|
|
104
|
+
currencyCode: CryptopayCurrencies.ETH,
|
|
105
|
+
address,
|
|
148
106
|
});
|
|
149
107
|
}
|
|
150
|
-
const cryptoAddressesWithExpiration = await setConversionRates(order.
|
|
108
|
+
const cryptoAddressesWithExpiration = await setConversionRates(order.currencyCode, cryptoAddresses);
|
|
151
109
|
await updateTransactionsWithOrderPaymentId(orderPayment._id, cryptoAddresses);
|
|
152
110
|
return JSON.stringify(cryptoAddressesWithExpiration);
|
|
153
111
|
},
|
|
@@ -157,17 +115,16 @@ const Cryptopay = {
|
|
|
157
115
|
const walletForOrderPayment = foundWalletsWithBalances.find((wallet) => BigInt(wallet.amount.toString()) > 0n);
|
|
158
116
|
const pricing = OrderPricingSheet({
|
|
159
117
|
calculation: order.calculation,
|
|
160
|
-
|
|
118
|
+
currencyCode: order.currencyCode,
|
|
161
119
|
});
|
|
162
120
|
const totalAmount = BigInt(pricing?.total({ useNetPrice: false }).amount);
|
|
163
|
-
if (walletForOrderPayment.
|
|
121
|
+
if (walletForOrderPayment.currencyCode !== order.currencyCode) {
|
|
164
122
|
const baseCurrency = await modules.currencies.findCurrency({
|
|
165
|
-
isoCode: walletForOrderPayment.
|
|
123
|
+
isoCode: walletForOrderPayment.currencyCode,
|
|
166
124
|
});
|
|
167
|
-
const quoteCurrency = await modules.currencies.findCurrency({ isoCode: order.
|
|
125
|
+
const quoteCurrency = await modules.currencies.findCurrency({ isoCode: order.currencyCode });
|
|
168
126
|
const { /* min, */ max } = await modules.products.prices.rates.getRateRange(baseCurrency, quoteCurrency, order.confirmed || new Date());
|
|
169
|
-
const convertedAmount =
|
|
170
|
-
10n ** (BigInt(walletForOrderPayment.decimals) - 9n);
|
|
127
|
+
const convertedAmount = denoteAmount(walletForOrderPayment.amount.toString(), walletForOrderPayment.decimals);
|
|
171
128
|
// Add a Promille 🍻
|
|
172
129
|
// const minAmount = parseFloat(convertedAmount.toString()) * min * 0.999;
|
|
173
130
|
const maxAmount = parseFloat(convertedAmount.toString()) * max * 1.001;
|
|
@@ -180,9 +137,7 @@ const Cryptopay = {
|
|
|
180
137
|
logger.info(`Cryptopay Plugin: Wallet ${walletForOrderPayment._id} balance too low (yet): ${maxAmount} < ${totalAmount}`);
|
|
181
138
|
}
|
|
182
139
|
if (walletForOrderPayment) {
|
|
183
|
-
|
|
184
|
-
const convertedAmount = BigInt(walletForOrderPayment.amount.toString()) /
|
|
185
|
-
10n ** (BigInt(walletForOrderPayment.decimals) - 9n); // All crypto native prices denoted with 8 decimals
|
|
140
|
+
const convertedAmount = denoteAmount(walletForOrderPayment.amount.toString(), walletForOrderPayment.decimals);
|
|
186
141
|
if (convertedAmount && convertedAmount >= totalAmount) {
|
|
187
142
|
return {
|
|
188
143
|
transactionId: walletForOrderPayment._id,
|
|
@@ -190,9 +145,8 @@ const Cryptopay = {
|
|
|
190
145
|
}
|
|
191
146
|
logger.info(`Cryptopay Plugin: Wallet ${walletForOrderPayment._id} balance too low (yet): ${convertedAmount} < ${totalAmount}`);
|
|
192
147
|
}
|
|
193
|
-
logger.info(`Cryptopay Plugin: No confirmed payments found for currency ${order.
|
|
194
|
-
/*
|
|
195
|
-
TODO:
|
|
148
|
+
logger.info(`Cryptopay Plugin: No confirmed payments found for currency ${order.currencyCode} and addresses ${JSON.stringify(foundWalletsWithBalances)}`);
|
|
149
|
+
/* TODO: Crypto Handling
|
|
196
150
|
|
|
197
151
|
1. Check that generated crypto addresses are unique and no order payments share the same crypto address, only repeat when derivations completely exhausted.
|
|
198
152
|
2. When derivation path get's close to "exhaustedness" (95%), send a special e-mail alert to tell the user should generate a new xpub.
|