UNPKG

@unchainedshop/plugins

Version:

Official plugin collection for the Unchained Engine with payment, delivery, and pricing adapters

34 lines (33 loc) 1.21 kB
import { OrderPricingAdapter, PaymentPricingSheet, } from '@unchainedshop/core'; export const OrderPayment = { ...OrderPricingAdapter, key: 'shop.unchained.pricing.order-payment', version: '1.0.0', label: 'Add Payment Fees to Order', orderIndex: 10, isActivatedFor: () => { return true; }, actions: (params) => { const pricingAdapter = OrderPricingAdapter.actions(params); const { order, orderPayment } = params.context; return { ...pricingAdapter, calculate: async () => { if (!orderPayment) return null; const pricing = PaymentPricingSheet({ calculation: orderPayment.calculation, currencyCode: order.currencyCode, }); const tax = pricing.taxSum(); const paymentFees = pricing.gross(); pricingAdapter .resultSheet() .addPayment({ amount: paymentFees, taxAmount: tax, meta: { adapter: OrderPayment.key } }); return pricingAdapter.calculate(); }, }; }, }; export default OrderPayment;