Repository navigation
Open
Description
Summary
Fixed-amount (dollar) coupons can be configured with different discount values per currency in the Freemius dashboard, but products/{product_id}/coupons.json only returns a single discount field (USD). Per-currency amounts are absent, so non-USD pricing uses the wrong discount.
Goal: Dollar-type coupons expose all configured currency discount amounts to the WordPress plugin (and embedded frontend scope) so discounted prices are correct for every supported currency.
Problem
When a coupon uses discount_type: dollar and has per-currency amounts configured (e.g. USD 50, EUR 40, GBP 20), the coupons API response only includes the USD value:
[
'code' => 'COUPON50',
'discount' => 50,
'discount_type' => 'dollar',
// no `discounts` key — EUR/GBP amounts missing
]Screenshots
Repro
- In Freemius, create or edit a coupon with
discount_type= dollar (not percentage). - Set different fixed amounts per currency (e.g. USD 50, EUR 40, GBP 20).
- Request
GET products/{product_id}/coupons.json?code=COUPON50(via pluginCoupon::get_by_code()or direct API). - Observe response contains only
discount: 50— nodiscountsmap witheur,gbp, etc.
Example response
Product 19794, coupon COUPON50:
[
'coupons' => [
[
'entity_id' => 19794,
'code' => 'COUPON50',
'discount' => 50,
'discount_type' => 'dollar',
'has_renewals_discount' => 1,
'id' => 86595,
// …other fields; no per-currency discounts
],
],
]Proposed approach
- Confirm API contract — verify whether
coupons.jsonis expected to return adiscountsobject (e.g.{ "usd": 50, "eur": 40, "gbp": 20 }) or if amounts live in another field/endpoint. - If API-side gap — coordinate with Freemius platform so multi-currency dollar discounts are included in the coupons payload (percentage coupons may not need this).
- If plugin-side normalization is possible — map whatever the API returns into the
discountsshape inCoupon::get_by_code()before embed/apply logic runs. - Ensure embed path is complete —
Coupon::to_embed_data()and frontendapplyCouponDiscount()already readcoupon.discounts[currency]with fallback tocoupon.discount; they need populated data from steps 2–3. - Add regression tests — PHP (
CouponTest) and/or JS fixtures with multi-currency dollar coupons.
Out of scope
- Percentage coupons (single
discountvalue is correct). - Checkout modal coupon application (separate from scope embed path unless the same API gap affects it).
Acceptance criteria
-
Coupon::get_by_code()returns per-currency discount amounts for dollar-type coupons when configured in Freemius (e.g.discounts: { usd: 50, eur: 40, gbp: 20 }). - Embedded
.freemius-coupon-dataJSON includes thediscountsmap viaCoupon::to_embed_data(). -
Coupon::apply_discount()/applyCouponDiscount()produce correct prices for EUR and GBP (not USD fallback). - Tests cover multi-currency dollar coupon payload.
Considerations
- Plugin already expects
discounts:includes/class-freemius-coupon.php(apply_discount,to_embed_data) andsrc/util/discountedPrice.js(applyCouponDiscount) usecoupon.discounts[currency] ?? coupon.discount. The gap appears to be missing data from the API, not missing consumer logic. - Related in-flight work: branch
feature/discounted-price-mappingadds coupon-aware discounted price mapping and tests; likely the right place to land a fix once the API shape is confirmed. - API vs plugin ownership: if
coupons.jsonwill never expose multi-currency amounts, we need an alternate data source or a platform change — document the decision in the fix PR. - Backward compatibility: sites with only USD dollar coupons should behave unchanged (
discountfallback still works).
Open questions
- Does the Freemius API store per-currency dollar amounts under a different key today (e.g. nested pricing object), or is this a platform API omission?
- Should
discountremain the USD canonical value whendiscountsis present, or be deprecated in favor of the map?
Context
- Branch: feat: add discounted price mapping field #61 (related — coupon discount plumbing and mapping work in progress)
- Reported while debugging
Coupon::get_by_code()/products/{id}/coupons.jsonresponse for couponCOUPON50on product19794.
Metadata
Metadata
Assignees
Labels
No labels

Activity