=== DPay for WooCommerce ===
Contributors: dpay, downlabs
Tags: woocommerce, payment gateway, pakistan, bank transfer, easypaisa, jazzcash
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.2.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Accept Easypaisa, JazzCash, NayaPay and bank-transfer payments in Pakistan, verified automatically, straight into your own account.

== Description ==

DPay is a bank-transfer payment gateway for Pakistan. Your customer pays from the app they already use — Easypaisa, JazzCash, SadaPay, NayaPay or any bank — into your own NayaPay or Meezan Bank account. DPay reads your bank's own alert, checks it six ways, and marks the WooCommerce order paid. No card, no merchant account, no percentage fee, no screenshots.

**What the plugin does**

* Adds "Bank transfer / Easypaisa / JazzCash" as a payment method, with the DPay logo, in both the classic and the block checkout.
* Opens DPay's hosted checkout for the order total — in a popup over the checkout on desktop, as its own page on phones (paisa rounded up to whole rupees, since no Pakistani transfer carries paisa).
* Optional advance payment: the customer pays Rs 250 (or a percentage, or the delivery charge) now and the rest in cash on delivery. Once the advance is verified the order becomes a cash-on-delivery order for the balance, so courier plugins collect the right amount.
* Marks the order paid the moment DPay verifies the transfer — by webhook, when the customer returns, and by a five-minute sync as a safety net — so it works even where webhooks cannot reach.
* Puts the DPay reference, bank and status on the order, with a "Check with DPay now" button.
* Registers its webhook with DPay automatically when you save your API key.
* Supports High-Performance Order Storage (HPOS).

**What you need**

* A DPay account (free plan available) with a receiving account and a connected inbox: https://dpay.com.pk
* Your shop currency set to PKR.

== External services ==

This plugin connects to the DPay API (https://api.dpay.com.pk) to create the hosted checkout for an order, to read a payment's status, and to register the shop's webhook. It sends the order total, the order number, the customer's name and email, and the shop's URL; DPay sends back the checkout address and, later, whether the transfer was verified. Nothing is sent until you save an API key. Terms: https://dpay.com.pk/terms · Privacy: https://dpay.com.pk/privacy

== Installation ==

1. Upload the `dpay-for-woocommerce` folder to `/wp-content/plugins/`, or upload the zip under Plugins → Add New → Upload Plugin.
2. Activate the plugin.
3. WooCommerce → Settings → Payments → DPay → paste your API key from https://dpay.com.pk/dashboard/developers and save. The plugin connects and registers its webhook by itself.
4. On the DPay Developers page, press "Send test event" next to your site's webhook to prove the connection.
5. Check the connection and signed test event, then test the full checkout with a controlled small real transfer. Normal test checkouts can verify real payments; no-money simulation is restricted to specially enabled DPay demo environments.

== Frequently Asked Questions ==

= Does money pass through the plugin or through DPay? =

No. The customer transfers directly into your own bank or wallet account. DPay only verifies that it arrived.

= Can I refund from WooCommerce? =

Refunds are ordinary transfers you make from your own bank, because DPay never holds the money. Record the refund in WooCommerce as usual; DPay's dashboard keeps the verified record.

= Can customers pay an advance and the rest on delivery? =

Yes. Under Advance payment in the settings, offer it as a choice or require it, and set a fixed amount, a percentage or the delivery charge. When DPay verifies the advance, the order goes to Processing as a cash-on-delivery order: a line "Advance paid (DPay)" takes the advance off the total, so the total is exactly what the rider collects.

= What if the customer closes the page before paying? =

The order stays pending with its DPay reference. They can pay it from My account → Orders; a transfer that lands late can still be honoured in the DPay dashboard.

== Changelog ==

= 1.2.1 =
* Clarify that normal test checkouts may verify real transfers; no payment behaviour changed.

= 1.2.0 =
* Advance payment: offer customers the full amount or an advance (fixed, percentage or the delivery charge) with the rest in cash on delivery, or require the advance. A verified advance turns the order into a cash-on-delivery order for the balance, with an "Advance paid (DPay)" line, so courier plugins collect exactly what is left.
* Switching between the full amount and an advance on an order's pay page closes the earlier DPay checkout, so the customer cannot pay both.

= 1.1.2 =
* Order-note wording for adjusted amounts.

= 1.1.1 =
* The paid-amount meta and the order note record the amount DPay actually received, which can differ slightly from the order total when the verification layer for wallet payments is enabled in DPay Settings; a second note states both figures.

= 1.1.0 =
* Checkout popup: on desktop the DPay payment page opens in a window over the checkout instead of leaving the shop, in both the classic and the block checkout. Phones still go to the payment page, where switching to a banking app is easier. Switch it off under the gateway settings if you prefer the redirect.
* The order-received page offers a way to another payment method while a transfer is still unconfirmed.

= 1.0.1 =
* Settings save can no longer take the page down: connection errors become a message, and the two API calls it makes fit inside a shared host's 30-second limit.

= 1.0.0 =
* First release.
