=== Interac e-Transfer / Email Money Transfer (EMT) Gateway for WooCommerce ===
Author: CaphLabs
Tags: woocommerce, payment, canada, interac, e-transfer
Requires at least: 5.8
Tested up to: 7.0
Requires PHP: 7.4
WC requires at least: 6.0
WC tested up to: 8.6
Stable tag: 2.1.1
License: GPL2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Accept Interac e-Transfer payments in WooCommerce with clear instructions, optional discounts, and static or dynamic secret answers.

== Description ==

A clean, reliable EMT gateway for Canadian WooCommerce stores.

Customers place an order, then send an Interac e-Transfer. Your store shows clear payment instructions on:
- The Thank You page
- Order emails
- My Account → Order details

You can use a static password/answer, or generate dynamic answers per order. You can also offer a discount to encourage EMT.

= Core Features =
- Works with WooCommerce Classic Checkout and Block Checkout
- Static or dynamic secret answer
- Highly customizable instructions (with placeholders)
- Shows instructions in Thank You, emails, and My Account
- Optional EMT discount (percentage) + optional savings message
- Admin/debug friendly; HPOS-ready; translatable

= Pro Upgrade (Automation & Convenience) =
If you want the “stop waking me at 3am” features, upgrade to Pro. Pro adds tools that help you match incoming deposit emails to the correct order automatically (IMAP inbox watching) and avoid “same total” collisions (Auto-Match Cents).

You can upgrade from the plugin settings screen.

== Installation ==

1. Upload to `/wp-content/plugins/advanced-emt-payment-gateway/` or install via WP Admin → Plugins → Add New.
2. Activate the plugin.
3. Go to WooCommerce → Settings → Payments.
4. Enable “Email Money Transfer (EMT)” and configure the settings.

== Configuration (Recommended Setup) ==

Go to:
WooCommerce → Settings → Payments → Email Money Transfer (EMT) → Manage

= 1) Basic EMT Settings =
These are the settings most stores need:

- Enable/Disable: turn EMT on.
- Title: what customers see at checkout (example: “Interac e-Transfer”).
- Description: short checkout text to reduce confusion (example: “Pay by EMT. Instructions shown after checkout.”).
- Secret Answer Mode:
  - Static: you enter one answer and customers use it.
  - Dynamic: the plugin generates an answer per order (less reuse, less confusion).
- Instructions:
  Write your “send the EMT to X email + use password Y” instructions here.

= 2) Instruction Placeholders (Copy/Paste Safe) =
You can use placeholders inside your instructions:

- [order]    → Order number
- [answer]   → The secret answer/password for that order
- [amount]   → Exact total the customer must send
- [discount] → Your discount percent

Example instruction template:
Send [amount] to payments@yourdomain.com.
Security answer: [answer]
Include order #[order] in the message.

= 3) EMT Discount (Optional) =
If you want to encourage EMT use:
- Discount Percent: enter a number like 3 (for 3%).
- Discount Message: optional. Use [discount] where you want the percent to appear.
  If blank, the plugin uses a default “Save X% …” message.
  
  

== Pro Feature: Auto-Match Cents (Unique Totals) ==



The biggest problem with “auto matching” is when multiple unpaid orders have the same total.
Auto-Match Cents solves this by applying a tiny extra discount (cents) so each EMT order total becomes unique.

How it works:
- At checkout, Pro can add a small “cents” discount line (for example, -$0.07).
- The customer sends the exact total shown.
- When your deposit email arrives, the plugin can match the amount to the exact unpaid order.

Settings:
- Enable Auto-Match Cents
- Auto-Match Min Cents (default 1 = $0.01)
- Auto-Match Max Cents (default 25 = $0.25)
- Auto-Match Window (Hours) (default 72)
  When picking cents, the plugin avoids totals already used by unpaid EMT orders created in this window.
- Auto-Match Line Label
  The label shown at checkout for the tiny cents discount (example: “EMT Auto-Match Discount”).

Recommended values (most stores):
- Min: 1
- Max: 25
- Window: 72 hours

Notes:
- This is still a DISCOUNT line (not a fee). It reduces the order total slightly.
- Keep the range small (1–25¢) so customers don’t feel “baited” or confused.



== Pro Feature: Auto-Confirm Orders via Inbox (IMAP) ==

SEE SCREENSHOT 7 ON HOW TO FIND THE 7 DAY FREE TRIAL (For a limited time)



Pro can check a mailbox (via IMAP) for Interac deposit emails and automatically mark matching EMT orders as paid.

IMPORTANT:
- This requires the PHP IMAP extension on your server.
- Credentials are stored in WordPress options. Use a dedicated mailbox if possible.

= Best-Practice Setup (Do This Once) =
1) Create a dedicated mailbox used only for EMT deposit notifications.
   (Example: etransfer@yourdomain.com)
2) Ensure deposit notifications for that mailbox go ONLY to that mailbox.
3) Turn on Auto-Match Cents (recommended) so totals are unique.
4) Configure IMAP settings and click “Test IMAP Connection”.

= IMAP Settings (Field-by-Field, Dummy-Proof) =

1) IMAP Username
Usually your full email address (example: you@domain.com).
Some hosts use only the mailbox name—check your provider’s “Mail client setup” page.

2) IMAP Password / App Password
Use your mailbox password for this email account.
If your email provider uses Two-Factor Authentication (2FA) and offers App Passwords (common with Gmail, Yahoo, Microsoft 365), you may need to use an App Password instead of your normal password.
Most “website email” accounts (cPanel/Plesk hosting email) do not have App Passwords—use the mailbox password you set in your hosting panel.

3) IMAP Host
This must be your provider’s IMAP server.
Examples: imap.gmail.com, imap.mail.yahoo.com, outlook.office365.com, or mail.yourdomain.com
App Passwords do not fix a wrong host—make sure Host/Port/Encryption are correct first.

4) IMAP Encryption
Most providers use SSL.

5) IMAP Port
Most providers use 993 for IMAP over SSL.

6) Mailbox / Folder
Default: INBOX
You can use a subfolder like INBOX/EMT if your mailbox supports it.

7) Skip Certificate Validation (advanced)
*NOTE*- Only enable this if your mail server uses a self-signed/invalid certificate and the connection test fails.
Leaving it off is more secure.

8) Inbox Check Interval (Minutes)
How often to check the mailbox (default 5).
Note: if your site relies on WP-Cron and has low traffic, the checks can be delayed. For best reliability, use server cron or WooCommerce Action Scheduler.
sites with regular visitors will not have to worry. 

9) Subject Keywords (comma separated)
Only process emails whose subject contains at least one keyword (case-insensitive).
Defaults include: Interac, e-Transfer, eTransfer, Autodeposit, Auto Deposit, Deposit

10) Trusted Sender Addresses (comma separated)
Only emails from these senders can auto-confirm orders.
Default: notify@payments.interac.ca
Examples:
notify@payments.interac.ca, payments.interac.ca

11) From Contains (optional)
An extra filter to reduce false positives (example: interac, notify, etransfer, yourbank)

12) Mark Processed Emails as Seen
If enabled, processed emails are marked read/seen.

13) Order Completion Method
Controls how the order is marked paid. (Payment Complete is recommended.)

14) Matching Window (Hours)
Only match unpaid EMT orders created within this window.

= IMAP Connection Test =
Click “Test IMAP Connection”.
You should see Connected OK (green) or an error message (red).

== Troubleshooting (Common Problems) ==

= “IMAP extension missing” =
Your server doesn’t have PHP IMAP enabled. Ask your host to enable the PHP IMAP extension.

= “Authentication failed” =
- Wrong username/password, or you need an App Password.
- Username is your email address.
- If you have 2FA enabled, create an App Password and use it.
- Some providers block IMAP until you enable IMAP access in the mailbox settings.

= “Could not connect / Host not found” =
- Wrong IMAP host.
- Wrong encryption or port.
Start with SSL + 993 and the provider’s documented host.

= “Certificate / SSL error” =
- Try enabling “Skip Certificate Validation” ONLY if your host uses a self-signed/invalid cert.

= Auto-Match isn’t finding matches =
- Make sure deposit notifications land in the mailbox/folder you configured.
- Confirm Trusted Senders includes the real sender address.
- Confirm Subject Keywords match your deposit email subjects.
- Enable Auto-Match Cents to prevent same-total collisions.
- Auto-Match is not going to match %100 of the orders, and that is mostly for security. if enough matches are not found it will be left for manual confirm.

== Frequently Asked Questions ==

= Does it work with WooCommerce Blocks? =
Yes, native support.

= Where do customers see EMT instructions? =
On the Thank You page, in emails, and in My Account for the order.

= Can I offer a discount for using EMT? =
Yes. Set the percent and an optional savings message in settings.

= What placeholders can I use? =
[order] (order number), [answer] (secret answer), [amount] (total to send), [discount] (percent).

= Does Pro store my mailbox credentials? =
Yes. IMAP credentials are stored in WordPress options. Use a dedicated mailbox for EMT deposits if possible, gmail recommended.

== Screenshots ==
1. Admin settings with EMT options
2. Custom instruction placeholders
3. Blocks checkout with branded gateway
4. Thank You page showing EMT info
5. My Account order details with instructions
6. Pro: Auto-Match Cents settings
7. Pro: IMAP Auto-Confirm settings + Test Connection

== Changelog ==

= 2.1.0 =
- Added activation-safe Free/Pro conflict handling so activating one version disables the other without fatal collisions.
- Added early bootstrap guards to prevent same-request redeclare failures during WordPress plugin activation sandbox.
- Guarded shared helper declaration (`advanced_emt_get_default_instructions`) to avoid duplicate declaration fatals.
- Fixed Checkout Block editor integration by using valid React element registration (`content` and `edit`) in EMT Blocks.
- Hardened Blocks payment-method data retrieval to safely handle early editor loads when gateways are not initialized.

= 2.0.5 =
- Fixed Checkout Block editor preview crash caused by invalid EMT payment-method registration config.
- Fixed EMT gateway not appearing in Checkout Blocks when content/edit types failed Woo Blocks validation.
- Hardened Blocks payment data loading for editor contexts where WooCommerce gateways are not fully initialized.
- Added safe string truncation fallback when mbstring is unavailable.

= 2.0.4 =
- Fixed WooCommerce Blocks dependency warnings by declaring proper script dependencies.
- Fixed EMT discount recalculation on both Classic and Blocks checkout when payment method changes.
- Improved Blocks payment-method sync and cart refresh so discount/fees update reliably.
- Added secure AJAX nonce handling for payment-method session updates.
- Fixed duplicate EMT description behavior in Blocks UI.
- Improved logo and discount notice rendering consistency in Blocks checkout.
- Fixed static answer mode handling so settings are respected when random answers are disabled.
- Improved admin save behavior for static answer settings to avoid false empty-state failures.
- Removed masking/toggle code that could trigger admin-side fatal errors.
- Removed debug/polling noise and cleaned temporary troubleshooting output.

= 2.0.3 =

Fix: Prevent EMT payment instructions from appearing twice on the Order Received page by removing duplicate output hook.
-Output EMT instructions above the Order Details table on the thank-you page.
-Add unique wrapper classes (.aemt-instructions, .aemt-instructions--thankyou, .aemt-instructions__body) to make styling easier.
-Remove inline styles from thank-you page instructions so themes/custom CSS can control appearance.

= 2.0.2 =
free version was missing a exit :) im so far from perfect but im trying.
enjoy and thank you for the support 
FREE 7 DAY TRIAL OF PRO IN ACCOUNT SEE SCREENSHOTS

= 2.0.1 =
Pro: Adds optional IMAP inbox auto-confirmation.
Adds optional auto-match cents + [amount] placeholder.

= 1.1.3 =
* New (Pro): Optional IMAP inbox watcher to auto-confirm EMT orders by matching deposit emails to the order's expected total.
* New (Pro): Inbox watcher settings (host/port/encryption/folder/filters) and safe de-duplication.

= 1.1.2 =
* New: [amount] placeholder for instructions (shows the exact total to send).
* New (Pro): Optional auto-match cents discount (1–25¢ by default) to make EMT totals unique for automatic inbox matching.

= 1.1.1 =
* Fix: Prevent gateway title HTML from appearing in order notes/admin.
* Tweak: Keep checkout title UI (logo + savings) visible during AJAX refresh.
* New: Dashboard review banner (≥5 EMT orders or 14 days; 30-day snooze).

= 1.0.2 =
* Added support for WooCommerce Blocks
* JSON-safe restore default button
* Polished admin UI
* Verified HPOS support

= 1.0.0 =
* Initial release

== Upgrade Notice ==



= 2.0.2 =
free version was missing a exit :) im so far from perfect but im trying.
enjoy and thank you for the support 
FREE 7 DAY TRIAL OF PRO IN ACCOUNT SEE SCREENSHOTS 
