vendure-plugin-nowpayments
Version:
A cryptocurrency payment gateway plugin for Vendure that integrates with NOWPayments.io, enabling your store to accept payments in Bitcoin, Ethereum, and 100+ other cryptocurrencies.
57 lines (56 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "nowPaymentsPaymentHandler", {
enumerable: true,
get: function() {
return nowPaymentsPaymentHandler;
}
});
const _core = require("@vendure/core");
const nowPaymentsPaymentHandler = new _core.PaymentMethodHandler({
code: 'nowpayments',
description: [
{
languageCode: _core.LanguageCode.en,
value: 'NOWPayments Cryptocurrency Payment Gateway'
}
],
args: {},
createPayment: async (ctx, order, amount, args, metadata)=>{
// Payment is already settled in NOWPayments by the time the webhook in nowpayments.controller.ts
// adds the payment to the order via addPaymentToOrder
if (ctx.apiType !== 'admin') {
throw Error(`CreatePayment is not allowed for apiType '${ctx.apiType}'`);
}
// If metadata contains paymentId, this is coming from addPaymentToOrder (webhook flow)
if (metadata == null ? void 0 : metadata.paymentId) {
var _metadata_paymentId;
// Convert amount from decimal to minor units if needed
// The amount received is already in minor units from the controller
const amountReceived = metadata.actuallyPaid ? Math.round(parseFloat(metadata.actuallyPaid) * 100) : amount;
return {
amount: amountReceived,
state: 'Settled',
transactionId: (_metadata_paymentId = metadata.paymentId) == null ? void 0 : _metadata_paymentId.toString(),
metadata
};
}
// Fallback: if no paymentId in metadata, this might be a direct payment creation
// This should not happen in normal flow, but keeping for backwards compatibility
return {
amount: amount,
state: 'Authorized',
metadata: metadata || {}
};
},
settlePayment: async (ctx, order, payment, args)=>{
// For NOWPayments, we don't settle immediately
// The payment is settled via IPN callback
return {
success: true
};
}
});
//# sourceMappingURL=nowpayments-payment.handler.js.map