Payments
Payments
Payment providers usually expect minor units.
ts
import { amount } from '@crapthings/money-safe';
export function createProviderPayment(orderId: string, total: string) {
const charge = amount(total, 'CNY');
const serialized = charge.toJSON();
return {
amount: charge.toMinor(),
currency: charge.toMoney().currency,
metadata: {
orderId,
amountMinor: serialized.amountMinor,
minorUnit: serialized.minorUnit
}
};
}Keep the serialized amount in metadata or audit logs when you need to reconcile later.