UNPKG

@unchainedshop/plugins

Version:

Because of a Typescript issue with upstream "postfinancecheckout", the Postfinance plugin has been disabled from transpilation, import the source ts files from src and enable node_module tsc or copy over the src/payment/postfinance-checkout to your projec

80 lines 2.81 kB
import { mongodb } from '@unchainedshop/mongodb'; import { CryptopayTransactionsCollection } from './db/CryptopayTransactions.js'; const configureCryptopayModule = ({ db }) => { const CryptoTransactions = CryptopayTransactionsCollection(db); const getWalletAddress = async (addressId) => { return CryptoTransactions.findOne({ _id: addressId.toLowerCase() }); }; const updateMostRecentBlock = async (currency, blockHeight) => { await CryptoTransactions.updateMany({ currency, }, { $set: { mostRecentBlockHeight: blockHeight, }, }); }; const mapOrderPaymentToWalletAddress = async ({ addressId, contract, currency, orderPaymentId, }) => { await CryptoTransactions.updateOne({ _id: addressId.toLowerCase(), }, { $setOnInsert: { _id: addressId.toLowerCase(), contract, currency, decimals: null, mostRecentBlockHeight: 0, blockHeight: 0, amount: mongodb.Decimal128.fromString('0'), created: new Date(), }, $set: { orderPaymentId, updated: new Date(), }, }, { upsert: true }); return CryptoTransactions.findOne({ _id: addressId.toLowerCase() }); }; const getNextDerivationNumber = async (currency) => { return (await CryptoTransactions.countDocuments({ currency })) + 1; }; const getWalletAddressesByOrderPaymentId = async (orderPaymentId) => { return CryptoTransactions.find({ orderPaymentId, }).toArray(); }; const updateWalletAddress = async ({ addressId, blockHeight, amount, contract, currency, decimals, }) => { await CryptoTransactions.updateOne({ _id: addressId.toLowerCase(), }, { $setOnInsert: { _id: addressId.toLowerCase(), currency, contract, created: new Date(), }, $set: { decimals, blockHeight, mostRecentBlockHeight: blockHeight, amount: mongodb.Decimal128.fromString(amount), updated: new Date(), }, }, { upsert: true }); return CryptoTransactions.findOne({ _id: addressId.toLowerCase() }); }; return { getWalletAddress, updateMostRecentBlock, updateWalletAddress, mapOrderPaymentToWalletAddress, getNextDerivationNumber, getWalletAddressesByOrderPaymentId, }; }; export default { cryptopay: { configure: configureCryptopayModule, }, }; //# sourceMappingURL=module.js.map