=== The Uni Deals ===
Contributors: theunideals
Tags: woocommerce, coupons, discounts, students, student discount
Requires at least: 5.8
Tested up to: 7.1.3
Requires PHP: 7.4
Stable tag: 1.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Adds The Uni Deals student verification widget to your store and applies verified student discount codes to the cart automatically.

== Description ==

The Uni Deals verifies that a shopper really is a student, then hands your
store a discount code that the shopper never has to copy or paste. This
plugin puts the verification widget on your cart and checkout pages and
turns a verified code into a real WooCommerce coupon on the cart.

**How it works for the shopper**

1. The widget appears on the cart and checkout pages once you have saved
   your partner key, or wherever you place the `[unideals_widget]`
   shortcode.
2. The shopper clicks the widget and verifies their student status with
   The Uni Deals in a popup.
3. The widget hands the code back to the page, and this plugin sends it to
   your own site to be checked.
4. Your site asks The Uni Deals, server to server, whether that code was
   genuinely issued and what discount it carries. The shopper's browser
   never talks to that endpoint, so a code cannot be forged from the
   browser.
5. If the code checks out, the plugin creates a single use WooCommerce
   coupon that matches the confirmed discount and applies it to the cart.
   The totals update in place.

The plugin works on both the block based cart and checkout that ship with
current WooCommerce and the older shortcode based templates.

**Make it yours**

The widget wears your store's design, not ours. From **WooCommerce > The
Uni Deals** you choose a button or a full banner, pick one of four button
styles (your theme's primary or secondary button, a minimal outline, or
The Uni Deals orange), set the label, alignment and width, and color the
banner yourself. A live preview on the settings screen updates as you
type. If none of that is enough, a custom HTML slot replaces the whole
widget with your own markup and a custom CSS box styles any of it. Every
appearance option can also be set per shortcode:

`[unideals_widget layout="banner" align="center" full_width="yes"]`

or wrap your own markup and mark the clickable element:

`[unideals_widget]<button data-tud-trigger>Students click here</button>[/unideals_widget]`

**What it never does**

It never guesses a discount. If the confirmed discount cannot be turned
into a coupon with confidence, no coupon is created. The shopper is told
plainly what happened and asked to paste the code into the coupon field,
where the widget has already put it.

**What it stores**

The only thing this plugin saves is your settings, which is your partner
key and your display preferences, plus the ordinary WooCommerce coupons
it creates. It stores nothing about students.

**External services**

This plugin relies on The Uni Deals, which is a third party service.

* The widget script is loaded in the shopper's browser from
  `https://theunideals.com/sdk/v1.js` on any page where the widget is
  shown. It renders the verification button and runs the verification
  popup.
* Your server sends the discount code and your public partner key to
  `https://api.theunideals.com` to confirm that the code was genuinely
  issued and to read the discount it carries. This request happens only
  when a shopper submits a code.
* When an order that used a student code is paid, marked processing, or
  marked completed, your server sends the order ID, the code, its subtotal
  and its currency to `https://api.theunideals.com` so commission is
  calculated from the real order value. This is on by default and can be
  turned off from **WooCommerce > The Uni Deals**. Nothing about the
  customer is sent. If you have set a partner secret, the request is signed
  with an `X-TUD-Signature` header so only your store can report your
  orders; without one, orders are still recorded but do not count toward
  commission.
* When you refund an order that used a student code, in full or in part,
  your server sends the order ID, the refund ID, the refunded item amount
  (without shipping or tax), its currency and its date to
  `https://api.theunideals.com`, so no commission is charged on what you
  gave back. It uses the same setting as order reporting and is always
  signed with your partner secret; without a secret, refunds are not
  reported. Nothing about the customer is sent, not even the refund reason.

Terms of service: https://theunideals.com/terms
Privacy policy: https://theunideals.com/privacy

You need a partner key to use this plugin. Email hello@theunideals.com to
get one for your store.

== Installation ==

1. Upload the plugin through **Plugins > Add New > Upload Plugin**, or
   install it from the WordPress plugin directory.
2. Activate it. WooCommerce must be installed and active.
3. Go to **WooCommerce > The Uni Deals**.
4. Paste your partner key.
5. Leave **Auto-inject widget** on to show the widget on the cart and
   checkout pages, or turn it off and place `[unideals_widget]` yourself.
6. Save. That is the whole setup.

== Frequently Asked Questions ==

= Do I need a partner key? =

Yes. The widget will not render without one, and the plugin will not
confirm any codes. Email hello@theunideals.com to get a key for your
store.

= Does it work with the new block cart and checkout? =

Yes. The widget is injected above the WooCommerce cart and checkout
blocks, and it also hooks the classic shortcode templates, so either
setup works.

= Can a shopper fake a code? =

No. Confirmation happens server to server between your site and The Uni
Deals. Nothing the shopper's browser sends is trusted on its own.

= What happens if The Uni Deals is unreachable? =

Nothing is applied and no coupon is created. The shopper sees an honest
message asking them to paste the code into the coupon field manually. The
widget has already filled that field as a fallback.

= What coupons does it create? =

One coupon per confirmed code, named exactly after the code, limited to
one use overall and one use per customer, expiring after two days, with
the discount type and amount that The Uni Deals confirmed.

With your partner key and partner secret saved, each verified student who
taps Get my code in The Uni Deals app or website gets their own coupon
created in your store at that moment: a code starting TUD-, good for one
use, expiring after two hours. Orders that use it are reported by code as
before.

= How does a student get their own code? =

Save your partner key and partner secret on the settings page. Saving
links your store with The Uni Deals; the settings page then says
"Per-student codes: Linked". From then on The Uni Deals asks your store,
through a signed request to /wp-json/tud/v1/mint, to create each
student's coupon. Without the secret, or before you save, students get
your shared code as before. If you generate a new partner secret in your
portal, paste it here and save again.

= My host or a security plugin has a firewall. What do I allow? =

POST requests to /wp-json/tud/v1/mint on your store (or
?rest_route=/tud/v1/mint if your site does not use pretty permalinks),
sent with the user agent TheUniDeals-Mint. Every one is signed with your
partner secret and refused by the plugin otherwise. In Wordfence, add the
URL to Allowlisted URLs; in Cloudflare, add a WAF custom rule that skips
security for that URI path; in Sucuri or your host's firewall, allowlist
the path. Page caches do not need a change: the request is a POST and
asks not to be cached, but if yours caches the REST API, exclude
/wp-json/tud/.

= Does it collect any student data? =

No. Verification happens inside The Uni Deals. Your store only ever sees
a discount code and the discount it carries.

= Where do I put the widget if I do not want it on the cart? =

Turn off auto-inject and place the `[unideals_widget]` shortcode on any
page or template you like.

= Can I change how the widget looks? =

Yes. The settings screen has a live preview and controls for layout
(button or banner), button style, label, alignment, width, banner colors
and the powered-by line. For full control, the custom HTML slot replaces
the widget with your own markup (mark the clickable element with
`data-tud-trigger`) and the custom CSS box styles anything. The same
options work as shortcode attributes.

== Screenshots ==

1. The verification widget on the WooCommerce cart page, above the cart.
2. The cart after a verified code, with the coupon applied and the
   discount in the totals.

== Changelog ==

= 1.3.0 =
* Each verified student gets their own single-use code, created in your
  store when they tap Get my code, the way Shopify and Wix stores do. A
  signed route, /wp-json/tud/v1/mint, creates it: one use, one use per
  customer, expiring after two hours (one hour for The Uni Deals testers).
* Saving the settings links your store with your partner key and secret;
  the settings page shows whether it is linked. Deactivating the plugin
  unlinks it. The link is only made once The Uni Deals has reached your
  store, and a store updated from an older version links by itself.

= 1.2.0 =
* Reports refunds on orders that used a student code, full or partial, so
  no commission is charged on what you refund. Signed with your partner
  secret, sent once per refund, and retried in the background if The Uni
  Deals cannot be reached. The outcome is a private note on the order.
* Declares compatibility with WooCommerce High-Performance Order Storage.
* Deleting the plugin also removes its refund report data.

= 1.1.0 =
* Reports orders that used a student code so commission is based on real
  order value. Optional, on by default.

= 1.0.0 =
* First release.
* Widget embed on the block cart and checkout, the classic cart and
  checkout, and anywhere via the `[unideals_widget]` shortcode.
* Server side code confirmation against The Uni Deals before any coupon
  is created.
* Single use coupon creation and automatic application to the cart.
* Settings screen under WooCommerce with a live preview: layout, button
  styles, alignment, banner colors, custom HTML and custom CSS.

== Upgrade Notice ==

= 1.3.0 =
Students get their own single-use code instead of a shared one. After
updating, open WooCommerce > The Uni Deals and save once with your partner
secret set.

= 1.2.0 =
Refunds on student code orders are now reported so you are not charged
commission on them. Set your partner secret to use it.

= 1.0.0 =
First release.
