@unchainedshop/plugins 3.1.11 → 4.0.0-rc.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/lib/delivery/pick-mup.js +0 -2
- package/lib/delivery/pick-mup.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/payment/apple-iap/adapter.js +5 -12
- 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 +3 -3
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +3 -3
- 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/de.d.ts +2 -0
- package/lib/payment/cryptopay/de.d.ts.map +1 -0
- package/lib/payment/cryptopay/de.js +10 -0
- package/lib/payment/cryptopay/de.js.map +1 -0
- package/lib/payment/cryptopay/denote-amount.d.ts +25 -0
- package/lib/payment/cryptopay/denote-amount.d.ts.map +1 -0
- package/lib/payment/cryptopay/denote-amount.js +31 -0
- package/lib/payment/cryptopay/denote-amount.js.map +1 -0
- package/lib/payment/cryptopay/derive-btc-address.d.ts +3 -0
- package/lib/payment/cryptopay/derive-btc-address.d.ts.map +1 -0
- package/lib/payment/cryptopay/derive-btc-address.js +39 -0
- package/lib/payment/cryptopay/derive-btc-address.js.map +1 -0
- package/lib/payment/cryptopay/derive-btc-address.test copy.d.ts +2 -0
- package/lib/payment/cryptopay/derive-btc-address.test copy.d.ts.map +1 -0
- package/lib/payment/cryptopay/derive-btc-address.test copy.js +10 -0
- package/lib/payment/cryptopay/derive-btc-address.test copy.js.map +1 -0
- package/lib/payment/cryptopay/derive-eth-address.d.ts +3 -0
- package/lib/payment/cryptopay/derive-eth-address.d.ts.map +1 -0
- package/lib/payment/cryptopay/derive-eth-address.js +32 -0
- package/lib/payment/cryptopay/derive-eth-address.js.map +1 -0
- package/lib/payment/cryptopay/handle-webhook.d.ts +26 -0
- package/lib/payment/cryptopay/handle-webhook.d.ts.map +1 -0
- package/lib/payment/cryptopay/handle-webhook.js +61 -0
- package/lib/payment/cryptopay/handle-webhook.js.map +1 -0
- package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +3 -56
- 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 +3 -55
- 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 +1 -1
- 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/index.js +3 -5
- 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.js +2 -2
- 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 +12 -12
- package/lib/presets/all.d.ts.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/bulk-import.js +1 -1
- package/lib/worker/bulk-import.js.map +1 -1
- 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/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/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 +37 -53
- package/src/delivery/pick-mup.ts +0 -2
- package/src/files/gridfs/module.ts +2 -2
- package/src/filters/local-search.ts +11 -2
- package/src/payment/apple-iap/adapter.ts +6 -13
- package/src/payment/apple-iap/fix-periods.ts +4 -7
- package/src/payment/apple-iap/handler-express.ts +3 -3
- package/src/payment/apple-iap/handler-fastify.ts +3 -3
- 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 +3 -69
- package/src/payment/cryptopay/handler-fastify.ts +5 -70
- 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 +1 -1
- 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/index.ts +3 -5
- package/src/payment/postfinance-checkout/types.ts +6 -6
- package/src/payment/postfinance-checkout/utils.ts +2 -2
- 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/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/bulk-import.ts +1 -1
- package/src/worker/enrollment-order-generator.ts +3 -3
- package/src/worker/error-notifications.ts +4 -4
- package/src/worker/heartbeat.ts +2 -2
- package/src/worker/message.ts +1 -1
- package/src/worker/push-notification.ts +2 -2
- package/src/worker/sms.ts +19 -17
- package/src/worker/update-coinbase-rates.ts +3 -6
- package/src/worker/update-ecb-rates.ts +3 -3
- 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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { HDKey } from '@scure/bip32';
|
|
2
|
+
import { keccak_256 } from '@noble/hashes/sha3';
|
|
3
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
4
|
+
function getChecksumAddress(address) {
|
|
5
|
+
const chars = address.split('');
|
|
6
|
+
const expanded = new Uint8Array(40);
|
|
7
|
+
for (let i = 0; i < 40; i++) {
|
|
8
|
+
expanded[i] = chars[i].charCodeAt(0);
|
|
9
|
+
}
|
|
10
|
+
const hashed = keccak_256(expanded);
|
|
11
|
+
for (let i = 0; i < 40; i += 2) {
|
|
12
|
+
if (hashed[i >> 1] >> 4 >= 8) {
|
|
13
|
+
chars[i] = chars[i].toUpperCase();
|
|
14
|
+
}
|
|
15
|
+
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
|
16
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return '0x' + chars.join('');
|
|
20
|
+
}
|
|
21
|
+
export default (xpub, index) => {
|
|
22
|
+
const hardenedMaster = HDKey.fromExtendedKey(xpub);
|
|
23
|
+
hardenedMaster.wipePrivateData(); // Neuter
|
|
24
|
+
const child = hardenedMaster.deriveChild(0).deriveChild(index);
|
|
25
|
+
// ETH Address (secp256k1 + keccak_256 + checksum)
|
|
26
|
+
const childSigningKey = secp256k1.ProjectivePoint.fromHex(child.publicKey).toRawBytes(false);
|
|
27
|
+
const address = Buffer.from(keccak_256(childSigningKey.slice(1)))
|
|
28
|
+
.toString('hex')
|
|
29
|
+
.substring(24);
|
|
30
|
+
return getChecksumAddress(address);
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=derive-eth-address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive-eth-address.js","sourceRoot":"","sources":["../../../src/payment/cryptopay/derive-eth-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,SAAS,kBAAkB,CAAC,OAAO;IACjC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChC,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,QAAQ,CA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,CAAC;SAC9D,QAAQ,CAAC,KAAK,CAAC;SACf,SAAS,CAAC,EAAE,CAAC,CAAC;IAEjB,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Context } from '@unchainedshop/api';
|
|
2
|
+
import { CryptopayModule } from './module.js';
|
|
3
|
+
export default function handleWebhook({ secret, wallet, price, ping, }: {
|
|
4
|
+
secret: string;
|
|
5
|
+
wallet?: {
|
|
6
|
+
address: string;
|
|
7
|
+
blockHeight: number;
|
|
8
|
+
amount: string;
|
|
9
|
+
contract?: string;
|
|
10
|
+
decimals?: number;
|
|
11
|
+
currencyCode: string;
|
|
12
|
+
};
|
|
13
|
+
price?: {
|
|
14
|
+
baseCurrency: string;
|
|
15
|
+
token: string;
|
|
16
|
+
rate: number;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
};
|
|
19
|
+
ping?: {
|
|
20
|
+
blockHeight: number;
|
|
21
|
+
currencyCode: string;
|
|
22
|
+
};
|
|
23
|
+
}, context: Context & {
|
|
24
|
+
modules: CryptopayModule;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
//# sourceMappingURL=handle-webhook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-webhook.d.ts","sourceRoot":"","sources":["../../../src/payment/cryptopay/handle-webhook.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAO9C,wBAA8B,aAAa,CACzC,EACE,MAAM,EACN,MAAM,EACN,KAAK,EACL,IAAI,GACL,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,KAAK,CAAC,EAAE;QACN,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,IAAI,CAAC,EAAE;QACL,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH,EACD,OAAO,EAAE,OAAO,GAAG;IACjB,OAAO,EAAE,eAAe,CAAC;CAC1B,iBA+DF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
+
import { OrderStatus } from '@unchainedshop/core-orders';
|
|
3
|
+
const { CRYPTOPAY_SECRET, CRYPTOPAY_MAX_RATE_AGE = '360' } = process.env;
|
|
4
|
+
const logger = createLogger('unchained:core-payment:cryptopay');
|
|
5
|
+
export default async function handleWebhook({ secret, wallet, price, ping, }, context) {
|
|
6
|
+
const { modules, services } = context;
|
|
7
|
+
if (secret !== CRYPTOPAY_SECRET) {
|
|
8
|
+
logger.warn(`webhook called with invalid secret`);
|
|
9
|
+
throw new Error('Secret invalid');
|
|
10
|
+
}
|
|
11
|
+
if (wallet) {
|
|
12
|
+
const { address, blockHeight, amount, contract, decimals, currencyCode } = wallet;
|
|
13
|
+
logger.debug('webhook received wallet data', wallet);
|
|
14
|
+
const { orderPaymentId } = await modules.cryptopay.updateWalletAddress({
|
|
15
|
+
address,
|
|
16
|
+
blockHeight,
|
|
17
|
+
amount,
|
|
18
|
+
contract,
|
|
19
|
+
decimals,
|
|
20
|
+
currencyCode,
|
|
21
|
+
});
|
|
22
|
+
const orderPayment = orderPaymentId &&
|
|
23
|
+
(await modules.orders.payments.findOrderPayment({
|
|
24
|
+
orderPaymentId,
|
|
25
|
+
}));
|
|
26
|
+
if (orderPayment) {
|
|
27
|
+
// Try to process order to next status
|
|
28
|
+
// TODO: Not sure if it's correct to use processOrder here if status is PENDING!
|
|
29
|
+
const order = await modules.orders.findOrder({ orderId: orderPayment.orderId });
|
|
30
|
+
if (order.status === null) {
|
|
31
|
+
await services.orders.checkoutOrder(order._id, {});
|
|
32
|
+
}
|
|
33
|
+
else if (order.status === OrderStatus.PENDING) {
|
|
34
|
+
await services.orders.processOrder(order, {});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new Error('Already processed');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (price) {
|
|
42
|
+
logger.debug('webhook received price data', 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
|
+
await modules.products.prices.rates.updateRates([rateData]);
|
|
54
|
+
}
|
|
55
|
+
if (ping) {
|
|
56
|
+
logger.debug('webhook received ping data', ping);
|
|
57
|
+
const { blockHeight, currencyCode } = ping;
|
|
58
|
+
await modules.cryptopay.updateMostRecentBlock(currencyCode, blockHeight);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=handle-webhook.js.map
|
|
@@ -0,0 +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,gBAA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|
|
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 { CRYPTOPAY_SECRET, CRYPTOPAY_MAX_RATE_AGE = '360' } = process.env;
|
|
2
|
+
import handleWebhook from './handle-webhook.js';
|
|
4
3
|
const logger = createLogger('unchained:core-payment:cryptopay');
|
|
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,kCAAkC,CAAC,CAAC;AAEhE,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":"AAIA,OAAO,EAAkB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7D,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 { CRYPTOPAY_SECRET, CRYPTOPAY_MAX_RATE_AGE = '360' } = process.env;
|
|
2
|
+
import handleWebhook from './handle-webhook.js';
|
|
4
3
|
const logger = createLogger('unchained:core-payment:cryptopay');
|
|
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;AAEhD,MAAM,MAAM,GAAG,YAAY,CAAC,kCAAkC,CAAC,CAAC;AAGhE,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,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,MAAM,CAAC;KAClB,KAAG,OAAO,CAAC,oBAAoB,CAAC;2FA/D9B;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;KACxB,KAAG,OAAO,CAAC,oBAAoB,CAAC;4CAyBoB,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC;yDAK3D,MAAM,KACrB,OAAO,CAAC,oBAAoB,EAAE,CAAC;CA2DnC,CAAC;;;;;;wCAtHyC,MAAM,aAAa,MAAM,KAAG,OAAO,CAAC,oBAAoB,CAAC;kDAK/C,MAAM,eAAe,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;uGA0E3F;gBACD,OAAO,EAAE,MAAM,CAAC;gBAChB,WAAW,EAAE,MAAM,CAAC;gBACpB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;gBACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAClB,YAAY,EAAE,MAAM,CAAC;gBACrB,QAAQ,EAAE,MAAM,CAAC;aAClB,KAAG,OAAO,CAAC,oBAAoB,CAAC;mGA/D9B;gBACD,OAAO,EAAE,MAAM,CAAC;gBAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAClB,YAAY,EAAE,MAAM,CAAC;gBACrB,cAAc,EAAE,MAAM,CAAC;aACxB,KAAG,OAAO,CAAC,oBAAoB,CAAC;oDAyBoB,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC;iEAK3D,MAAM,KACrB,OAAO,CAAC,oBAAoB,EAAE,CAAC;;;;AA6DpC,wBAIE;AAEF,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC;CACxD"}
|
|
@@ -2,27 +2,27 @@ import { mongodb } from '@unchainedshop/mongodb';
|
|
|
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,OAA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AAE,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"}
|