Skip to main content

Payment Pricing

Payment pricing adapters calculate fees for different payment methods — e.g. credit-card processing fees or invoice handling charges.

For the conceptual overview, see Pricing System.

Creating an adapter​

Use the registerPaymentPricing factory. Push fees onto the sheet with addFee(...); the factory continues the chain for you.

import { registerPaymentPricing } from '@unchainedshop/core';

registerPaymentPricing({
adapterId: 'invoice-fee',
isActivatedFor: (context) => context.provider?.type === 'INVOICE',
calculate: async (sheet) => {
sheet.addFee({ amount: 500, isTaxable: true, isNetPrice: true, meta: { type: 'invoice' } });
},
});

calculate(sheet, context) receives a fresh result sheet for this adapter (it contains only the rows you add) and the payment pricing context (provider, order, currencyCode).

Examples​

Credit-card fee​

import { OrderPricingSheet, registerPaymentPricing } from '@unchainedshop/core';

registerPaymentPricing({
adapterId: 'card-fee',
isActivatedFor: (context) =>
context.provider.adapterKey === 'shop.unchained.payment.stripe',
calculate: async (sheet, context) => {
const orderPricing = OrderPricingSheet({
calculation: context.order?.calculation,
currencyCode: context.order?.currencyCode,
});
const orderTotal = orderPricing.total().amount;
const fee = Math.round(orderTotal * 0.029 + 30); // 2.9% + 0.30
sheet.addFee({ amount: fee, isTaxable: false, isNetPrice: true, meta: { rate: 0.029, fixed: 30 } });
},
});

Tiered processing fee​

registerPaymentPricing({
adapterId: 'tiered-fee',
isActivatedFor: (context) =>
context.provider.adapterKey === 'shop.unchained.payment.stripe',
calculate: async (sheet, context) => {
const orderPricing = OrderPricingSheet({
calculation: context.order?.calculation,
currencyCode: context.order?.currencyCode,
});
const orderTotal = orderPricing.total().amount;
const rate = orderTotal >= 50000 ? 0.019 : orderTotal >= 10000 ? 0.025 : 0.029;
sheet.addFee({ amount: Math.round(orderTotal * rate + 30), isTaxable: false, isNetPrice: true, meta: { rate } });
},
});

Low-level adapter (advanced)​

For behavior the factory doesn't expose, build the adapter by spreading PaymentPricingAdapter and registering it via pluginRegistry.register(). See Plugin System.