Step 1: Validate a Coupon
Before showing the discounted price to a customer, verify that the coupon code exists, is active, and applies to the product being purchased. Endpoint:GET /coupons/{code}/validate
The coupon code as stored in Nova.Pay (normalized, uppercased).
The discount magnitude. Interpretation depends on
type:- When
typeis"percentage", this is the percentage to deduct (e.g.20.0= 20% off). - When
typeis"price", this is the fixed amount to deduct in the currency’s major unit (e.g.15.0= R$ 15.00 off).
Discount strategy. One of:
If the coupon code is invalid, expired, or does not apply to the specified product, the API returns
422 Unprocessable Entity with a descriptive error message. Always handle this case in your UI so customers can correct the code.Step 2: Fetch Payment Plans with the Coupon
Once you have a valid coupon, pass it as thecoupon query parameter when fetching payment plans. Nova.Pay recalculates plan amounts server-side and returns prices that already reflect the discount — you can display these directly to the customer without any client-side arithmetic.
Endpoint: GET /payment_plans
/payment_plans call, but amount and instalment_amount values are already discounted.
Step 3: Apply the Coupon at Payment Time
Include thecoupon field in your POST /payments request body. Nova.Pay validates the coupon again server-side and applies the discount to the charge.
Endpoint: POST /payments
Full End-to-End Example
Here is a completePOST /payments request body that combines a coupon with a credit card payment:
If the coupon code passed in
POST /payments is invalid or does not apply to the selected products, Nova.Pay returns 422 Unprocessable Entity with an error message identifying the problem. Make sure your checkout UI surfaces this error clearly so customers can enter a different code or proceed without a coupon.