=== Passkaar Loyalty for WooCommerce ===
Contributors: passkaar
Tags: loyalty, rewards, apple wallet, google wallet, woocommerce
Requires at least: 7.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 0.4.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Your customers earn on your Passkaar loyalty card when they buy in your store, add it to their phone and spend it at checkout.

== Description ==

Passkaar runs loyalty cards that live in Apple Wallet and Google Wallet: stamps, points, prepaid,
coupons, memberships and VIP cards. This plugin joins your WooCommerce store to your Passkaar
account, so one card earns in your shop and online.

You paste the API key from the Passkaar portal, test it, and choose which of your cards the store
uses. When an order is paid, the customer's card earns: a points or VIP card from the order total, a
stamps card one stamp. A cash-on-delivery order earns when you mark it completed. A refund takes back
its share, and a full refund all of it. Each result is written on the order as a note. The work runs
in the background through WooCommerce's scheduled actions, so checkout never waits on Passkaar, and a
failed call is tried again for about three days.

The card is found by the customer's store account once it is linked to their card, otherwise by the
billing phone, then the billing email. An order whose customer has no card earns nothing.

A signed-in customer sees "Add to Apple Wallet / Google Wallet" on My Account and on the thank-you
page. Tapping it makes their card, or finds the one they have, and opens the page where they add it
to their phone. A customer who got the card at your shop links it to their account with the card ID
printed on it and the phone number or email they joined with.

Once a card is linked to their account, the customer can spend it at checkout, in the block checkout
or the classic one: a prepaid card pays from its balance, a cash-back points card at its rate, and a
stamps card's reward for the amount you set. The value is held on the card for 15 minutes and comes
off the order as a one-time coupon for that customer; it is spent when the order is paid, and let go
if the coupon is removed or the order fails or is cancelled. While a loyalty card pays part of an
order, the rest is paid at checkout: cash on delivery, bank transfer and cheque are not offered. A
store whose only ways to pay are those offers no card at checkout; its customers still earn.

You need a Passkaar account with API access switched on, and an API key made in the Passkaar
portal under Settings > Integrations.

The guide to connecting your store, and the documentation for developers, are at
https://docs.passkaar.com/connect-your-store/

== External services ==

This plugin connects your store to Passkaar (https://passkaar.com), the loyalty card service it
exists for. It sends nothing until you save an API key.

* **When you test the connection** (WooCommerce > Settings > Integration > Passkaar Loyalty), the
  store's server calls `https://api.passkaar.com/integrations/v1/programs` with your API key and
  receives the names of your loyalty cards. Nothing about your customers or orders is sent.
* **When an order is paid**, the store's server calls
  `https://api.passkaar.com/integrations/v1/awards` with the order's number, its total, tax and
  delivery in whole rupees, the time it was paid, the card you chose, and one way to find the
  customer's card: your store's id for a signed-in customer (`wp-user-` and their user id), or else
  the order's billing phone, or else its billing email, tried in that order until one is found.
  It receives what the card earned.
* **When an order is refunded**, the store's server calls
  `https://api.passkaar.com/integrations/v1/awards/{order number}/reverse` with the refund's number
  and, for a partial refund, its amount in whole rupees. It receives what was taken back.
* **When a signed-in customer taps "Add to Apple Wallet / Google Wallet"**, the store's server calls
  `https://api.passkaar.com/integrations/v1/programs/{card}` to read the card's join form, then
  `https://api.passkaar.com/integrations/v1/enrolments` with the customer's first name, the phone
  number and email the form asks for (from their account, or a phone they type), the card you
  chose, and your store's id for them (`wp-user-` and their user id). It receives the card's ids and
  the link the customer is sent to, on Passkaar's site, to add the card to their phone. Nothing is
  sent for a customer who does not tap.
* **When a signed-in customer links a card**, the store's server calls
  `https://api.passkaar.com/integrations/v1/cards/link` with the card ID and the phone number or email
  they typed, and your store's id for them. It receives the card's ids, then calls
  `https://api.passkaar.com/integrations/v1/cards/{card}` to check the card is the one your store uses.
* **When a customer with a linked card taps "Use my loyalty card"** in the cart or at checkout, the
  store's server calls `https://api.passkaar.com/integrations/v1/cards/{card}` for the card's balance
  and `https://api.passkaar.com/integrations/v1/redemption-holds` with your store's id for them, the
  card you chose and what to hold. When that order is paid it calls
  `https://api.passkaar.com/integrations/v1/redemption-holds/{hold}/confirm` with the time it was
  paid, or `https://api.passkaar.com/integrations/v1/redemptions` with the same if the hold had ended;
  when the coupon is removed or the order fails or is cancelled, it calls
  `https://api.passkaar.com/integrations/v1/redemption-holds/{hold}/release`.
* **When you save the settings with a card chosen**, the store's server calls
  `https://api.passkaar.com/integrations/v1/programs/{card}` for the card's rules and join form.

Your API key is kept on your server and is never sent to a visitor's browser. The plugin loads no
script, style or code from Passkaar or anywhere else: the block checkout's button is a script inside
the plugin, served from your site.

Passkaar's terms: https://passkaar.com/terms
Passkaar's privacy policy: https://passkaar.com/privacy

== Installation ==

1. Install and activate WooCommerce, then this plugin.
2. In the Passkaar portal, open Settings > Integrations, add a connection for your store and make
   an API key. Copy it: it is shown once.
3. In WordPress, open WooCommerce > Settings > Integration > Passkaar Loyalty, paste the key and
   save.
4. Press "Test the connection", then choose your loyalty card and save.

The full guide: https://docs.passkaar.com/connect-your-store/

You can keep the key out of the database by adding it to `wp-config.php` instead:
`define( 'PASSKAAR_LOYALTY_API_KEY', 'psk_live_…' );`

== Frequently Asked Questions ==

= What happens to my key when I uninstall the plugin? =

The plugin deletes it from your site. The key stays valid in Passkaar until you revoke it in the
portal.

= Does it work with the block checkout and High-Performance Order Storage? =

Yes. The plugin declares both.

= Why are cash on delivery and bank transfer not offered with a loyalty card? =

The value is held on the card for 15 minutes and spent when the order is paid. An order paid on
delivery, by bank transfer or by cheque is paid days later, after the hold has ended and the value
could have been spent again, so the plugin does not let a loyalty card pay part of one. A store
with no other way to pay (no card or online payment) does not offer the card at checkout at all,
and the settings page says so; orders paid any way still earn. A developer can change which payment
methods count with the `passkaar_loyalty_pay_later_gateways` filter.

= What is a reward worth at checkout? =

For a stamps card, what you set under "A reward online (Rs)". Leave it empty and rewards are kept
for your shop. A points card whose points buy items from a list is spent at your shop only.

= Does it work if my store sells in another currency? =

Passkaar cards count Pakistani rupees. An order in another currency earns nothing and is noted on the
order, and customers are not offered their card at checkout. The settings page says so.

= What happens when I deactivate or delete the plugin? =

Deactivating stops everything until you activate it again: coupons of ours not yet used are deleted,
and orders, refunds and loyalty spends left waiting are sent when you switch it back on. Deleting
the plugin also removes its settings, the key and each customer's linked card from your site; what it
wrote on orders stays on them.

== Screenshots ==

1. A signed-in customer's account page: their card is linked, and one tap adds it to Apple Wallet or Google Wallet.
2. At checkout the card pays part of the order, as a discount the customer can remove to keep their card for later.
3. The settings: the key from the Passkaar portal, a connection test, and the card the store earns on.
4. Each paid order says on its notes what the customer's card earned.

== Changelog ==

= 0.4.4 =
* The notice that Passkaar has refused the store's key shows only on the plugins list, WooCommerce's
  settings and its orders, can be closed, and goes by itself once the key works. The notice that
  WooCommerce is missing shows only on the plugins list.

= 0.4.3 =
* The plugin header names Passkaar once, as the author, as WordPress.org asks.

= 0.4.2 =
* Passkaar being briefly unavailable no longer hides the card from customers for ten minutes or
  tells the owner the key was refused: the tap asks the customer to try again, and orders are sent
  again. Only a refused key is kept and shown on WooCommerce's screens.
* While the key is refused, a customer's tap says to try again, never to link a card already linked.
* A tap whose lock could not be taken at all waits for the next tap instead of going ahead.

= 0.4.1 =
* A store whose only ways to pay are paid later (cash on delivery, bank transfer, cheque) no longer
  offers the card at checkout, where using it left no way to pay; the settings page says spending
  needs a way to pay online. Orders still earn.
* The Loyalty card list offers only the cards an order can earn on.
* A card whose join form asks no phone number or email is not offered to sign up from the store: the
  customer is asked to see the shop, and the settings page tells the owner what to add.

= 0.4.0 =
* A customer's tap waits at most a few seconds for Passkaar; if Passkaar is slow, the customer is
  asked to try again and the checkout goes on without the card. A hold whose answer was lost is asked
  for again on the next tap, never made twice, and a second tap gets the first tap's coupon.
* A store not selling in rupees offers no card at checkout, and the settings page says why.
* While Passkaar refuses the store's key, WooCommerce's screens and the settings page say so and what
  to do, and customers are not offered the card for ten minutes at a time.
* WooCommerce's coupon messages for the loyalty card speak of "your loyalty card", never a coupon
  code: added, removed, ended after 15 minutes, or the order changed.
* Only the store's own ways to pay later are named at checkout.
* A customer whose card is already in their wallet is told so instead of being sent to add it again,
  and one who links a card the store does not use is told which card to link.
* Cancelling a paid order notes that the card keeps what it earned until the order is refunded.
* Deactivating deletes unused loyalty coupons and stops the plugin's jobs; activating again queues
  what was left waiting. Deleting the plugin also deletes unused loyalty coupons.


= 0.3.3 =
* A cash-on-delivery order tells Passkaar it was paid on delivery when it is completed. The shop's
  owner chooses in Passkaar whether such orders earn.

= 0.3.2 =
* Bank transfer and cheque, like cash on delivery, are not offered while a loyalty card pays part of
  an order, in either checkout, so a card's value cannot come off an order that is paid after its
  hold ends. The `passkaar_loyalty_pay_later_gateways` filter changes the list.

= 0.3.1 =
* After "Use my loyalty card" on the classic cart or checkout, the customer stays on that page.
* The buttons take the theme's button style, and the block checkout names the card "Your loyalty
  card" beside the discount.

= 0.3.0 =
* "Add to Apple Wallet / Google Wallet" and "Link your card" on My Account and the thank-you page.
* Spending the card at checkout, in the block checkout and the classic one, as a one-time coupon held
  for 15 minutes and spent when the order is paid.

= 0.2.0 =
* A paid order earns on the customer's card, a refund takes its share back, and both are noted on
  the order. Retries run through WooCommerce's scheduled actions.

= 0.1.0 =
* The connection: the API key, a connection test, and choosing your loyalty card.
