Skip to content

Dollar coupon discounts missing per-currency amounts in API response #62

Description

@evrpress

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

Freemius dashboard — per-currency dollar discount fields (USD 50, EUR 40, GBP 20)

Repro

  1. In Freemius, create or edit a coupon with discount_type = dollar (not percentage).
  2. Set different fixed amounts per currency (e.g. USD 50, EUR 40, GBP 20).
  3. Request GET products/{product_id}/coupons.json?code=COUPON50 (via plugin Coupon::get_by_code() or direct API).
  4. Observe response contains only discount: 50 — no discounts map with eur, 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

  1. Confirm API contract — verify whether coupons.json is expected to return a discounts object (e.g. { "usd": 50, "eur": 40, "gbp": 20 }) or if amounts live in another field/endpoint.
  2. 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).
  3. If plugin-side normalization is possible — map whatever the API returns into the discounts shape in Coupon::get_by_code() before embed/apply logic runs.
  4. Ensure embed path is completeCoupon::to_embed_data() and frontend applyCouponDiscount() already read coupon.discounts[currency] with fallback to coupon.discount; they need populated data from steps 2–3.
  5. Add regression tests — PHP (CouponTest) and/or JS fixtures with multi-currency dollar coupons.

Out of scope

  • Percentage coupons (single discount value 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-data JSON includes the discounts map via Coupon::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) and src/util/discountedPrice.js (applyCouponDiscount) use coupon.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-mapping adds 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.json will 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 (discount fallback 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 discount remain the USD canonical value when discounts is 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.json response for coupon COUPON50 on product 19794.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions