requirePayment({
...,
hooks: {
onPaymentRequired: async ({ req, requirements }) => {
// Log the quote or bump the price for premium users
metrics.increment("402.emitted", { path: req.path });
},
onVerify: async ({ req, verification, requirements }) => {
// Enforce a business rule beyond the payment itself
if (isBlockedAccount(verification.from)) {
throw new PaymentRejection("account_blocked");
}
},
onSettle: async ({ verification, settlement }) => {
await db.record({
tx: settlement.txHash,
from: verification.from,
amount: settlement.amount,
});
},
},
});