=== smartEngin buy ===
Contributors: businesskiai
Tags: ecommerce, digital downloads, stripe, paypal, invoices
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.6.6
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Sell digital products from your own site: cart, Stripe and PayPal, invoices, coupons, customer accounts. No marketplace, no fee per sale.

== Description ==

smartEngin buy turns your own WordPress site into a shop for digital products — documents, e-books, templates, any file you sell. There is no marketplace in between: your site takes the payment, writes the invoice and serves the download.

**No commission per sale. No foreign branding. No customer data at a third party.** Everything runs in your own database; the only outside parties are the payment providers you switch on.

**What you can sell**

* Files — PDF, ZIP, images, audio, video, office documents: everything WordPress itself accepts as an upload. Delivered through short-lived signed links, never a public URL.
* One-time purchases and subscriptions, monthly or yearly.
* Several items in one order, with a cart and a single payment.

**Selling and getting paid**

* Offer cards on any page — the block "smartEngin Offer cards" or `[sels_cards product="your-product-slug"]`. Buyers never leave the page.
* Stripe and PayPal, including subscriptions and Stripe's redirect methods (Klarna, Amazon Pay, Bancontact, eps …).
* A test mode that runs a complete purchase — order, invoice, customer account, download — without a payment provider, so you can try everything before going live.
* Coupons and discount codes, shared for a campaign or unique per customer.
* `[sels_preis]` writes the current price into your running text, so a price change leaves no stale number on a landing page.

**Invoices and bookkeeping**

* Invoices with gap-free, frozen numbers, plus credit notes. They are printable HTML pages that any browser saves as PDF — no PDF library involved, so nothing breaks when a server lacks one.
* A small-business tax mode for the German § 19 UStG rule, with the required sentence on the invoice.
* Refund a payment in Stripe or PayPal and the matching credit note is written here automatically.
* A payment check that lists only the orders where something does not add up. An empty screen means everything went through cleanly.

**Your customers**

* A customer account with magic-link sign-in: purchases, invoices and downloads in one place, no password.
* Automatic renewal and expiry reminders for subscriptions.

**Setting it up with an AI assistant**

Stripe keys, webhooks, tax settings, invoice numbers — that is where most people get stuck. Under "Help & docs" one click copies a briefing about *your* installation into ChatGPT or Claude, which then tells you what is still missing. No account, no setup, nothing leaves your site. If your assistant can read online by itself, an optional read-only connection lets it check your settings directly: off until you switch it on, never exposing a secret, never able to change anything, and it closes itself when its short-lived code expires.

**Extensions**

* *smartEngin Courses* adds trainings, courses and videos with a member area, sold through this plugin. https://smartengin.de/smartengin-courses/
* *smartEngin Licence & buy* is the same core plus licence keys, activation limits and an update server for software you sell. It replaces this plugin; your data stays. https://smartengin.de/smartengin-licence-buy/

== Installation ==

**1. Install and activate.** Plugins → Add New → Upload, or copy the `smartengin-buy` folder to `/wp-content/plugins/`. A menu "smartEngin buy" appears.

**2. Settings.** Sender name and address for the invoices, your tax mode (standard or the German § 19 small-business rule) and the prefix for your invoice numbers. Set the prefix before the first sale — numbers are frozen once issued.

**3. Add a product.** Products → Add: a name, at least one purchase option (one-time, monthly or yearly) and the file the buyer receives.

**4. Put the offer cards on a page.** The block "smartEngin Offer cards", or `[sels_cards product="your-product-slug"]`. That is the whole shop front.

**5. Try it in test mode first.** Test mode is on until you switch it off. Buy your own product and you get the order, the invoice, the mail and the download — without a payment provider and without money moving.

**6. Then switch on real payments.** Enter your Stripe or PayPal credentials — **and set up the webhook the settings screen shows you.** That is not optional: subscriptions, refunds and payments that send the buyer to another site (Klarna, Amazon Pay …) are confirmed by the webhook, not by the browser. Without it a paid order can stay open. Test and live mode need separate webhooks at both providers.

Not sure whether everything is done? The Dashboard shows a checklist of what is still missing, and "Help & docs" explains every screen.

== Frequently Asked Questions ==

= What does it cost? =

Nothing, with no time limit, and no commission on your sales. Only your payment provider charges its usual fee.

= Do I need an account with an external service? =

Only to take real money. Stripe and PayPal are optional and switched off until you enter your credentials. The test mode runs a complete purchase without either.

= What kinds of file can I sell? =

Everything WordPress itself accepts as an upload: PDF, ZIP, images, audio, video, office documents and so on. Executable software (EXE, MSI, DMG, APK) is not among them — WordPress blocks those uploads and this plugin does not widen the list.

= Do I really have to set up a webhook? =

Yes, as soon as you take real money. Subscription renewals, refunds and every payment method that sends the buyer to another site are reported by the provider directly to your site, not by the buyer's browser — without the webhook a paid order can stay open. The settings screen shows the exact address; test and live mode need one each.

= What happens when I refund a customer? =

Refund the payment in Stripe or PayPal; their webhook then writes the matching credit note here and updates the order. Provider events are never retroactive, so a refund made before the webhook existed produces none.

= Are the invoices PDF files? =

They are printable HTML pages, which every browser saves as PDF.

= Where is my customer data stored? =

In its own database tables on your site. Nothing is sent anywhere except to the payment provider you switched on, and only what that payment needs.

= Does it work with subscriptions? =

Yes. Monthly and yearly subscriptions run through Stripe or PayPal, and the plugin keeps access, invoices and reminders in step with them.

= Can I sell online courses with it? =

Yes, with the free add-on *smartEngin Courses*: trainings, courses, videos and a member area, sold through this plugin's checkout.

= Can it license my own software? =

Not this plugin. That is what *smartEngin Licence & buy* is for — the same core plus licence keys, activation limits and an update server.

= What happens when I switch to smartEngin Licence & buy, or back? =

The two are the same core and share their data tables, so they must never run side by side — loading both would break the site with duplicate class names. This plugin therefore never touches the other one: if smartEngin Licence & buy is active, activating this plugin is refused with a message asking you to deactivate that one first. You stay in control of which plugin runs, and nothing is deleted in either direction — products, orders, invoices, coupons and customer accounts are picked up unchanged.

= My site runs behind Cloudflare or another proxy/CDN — anything to watch out for? =

The plugin identifies visitors by the address the web server reports, on purpose: forwarded headers can be faked, and the abuse brakes and the security log must not be foolable. Most hosts restore the real visitor address automatically. If yours does not, every visitor appears to come from the proxy — the security log becomes useless and the purchase-attempt brake can catch genuine buyers. Ask your host to enable real-IP restoration (mod_remoteip, real_ip or their Cloudflare integration).

== External services ==

This plugin connects to external services only when YOU switch them on and only to take a payment. Nothing is transmitted while they are switched off.

**Stripe**

Used to take card payments and subscriptions when you enter your Stripe keys under Settings → Payment providers.

* What is sent, and when: at the moment a customer starts a payment, your server sends the amount, the currency, your order number and the customer's e-mail address to Stripe's API at `https://api.stripe.com`. Card details are entered in Stripe's own form and go directly to Stripe — the plugin never sees or stores them.
* The checkout page loads Stripe's JavaScript library from `https://js.stripe.com` — in the visitor's browser, and only once that visitor has actually started a card payment, never on page load. Stripe then reports the result of the payment back to your site.
* Domains contacted: `api.stripe.com` (from your server), `js.stripe.com` (from the visitor's browser). No other Stripe address is used.
* Service provided by Stripe, Inc. — [terms of service](https://stripe.com/legal/ssa), [privacy policy](https://stripe.com/privacy).

**PayPal**

Used to take PayPal payments and subscriptions when you enter your PayPal credentials under Settings → Payment providers.

* What is sent, and when: at the moment a customer starts a payment, your server sends the amount, the currency and your order number to PayPal's API at `https://api-m.paypal.com` — or at `https://api-m.sandbox.paypal.com` while you are testing with sandbox credentials. The customer signs in with PayPal directly; the plugin never sees those credentials.
* The checkout page loads PayPal's JavaScript SDK from `https://www.paypal.com` — in the visitor's browser, and only once that visitor has actually started a PayPal payment, never on page load. PayPal then reports the result of the payment back to your site.
* Domains contacted: `api-m.paypal.com` (or `api-m.sandbox.paypal.com` in sandbox mode) from your server, and `www.paypal.com` from the visitor's browser. No other PayPal address is used.
* Service provided by PayPal, Inc. — [user agreement](https://www.paypal.com/legalhub/useragreement-full), [privacy statement](https://www.paypal.com/myaccount/privacy/privacyhub).

No other external service is contacted. The plugin does not phone home, does not collect statistics and does not load fonts, scripts or images from anywhere else.

== Privacy ==

The plugin stores what a purchase needs: name, e-mail address, billing address when your invoice settings require one, the ordered items and the invoice. This data lives in tables on your own site and is never sent anywhere but to the payment provider handling that payment.

Invoices are kept because tax law requires it; they are not deleted automatically. Secret keys (Stripe, PayPal) are never exported, never shown again after saving and never included in any support or setup output.

Beyond the purchase itself, the plugin keeps two short technical logs on your own site — for you as the site owner, and for nobody else:

* A security log of sign-in attempts, both to the WordPress backend and to the passwordless customer account. It records what was typed in (username or e-mail address), the visitor's IP address, the result and the time — that is what makes a repeated attack visible on the Security screen. Passwords are never stored, and no payment data ever reaches it. These rows are deleted automatically after a retention period you set yourself: 90 days by default, seven at the least.
* An access log for the optional read-only connection an AI assistant can use to help you set the shop up (smartEngin buy → REST API). That connection is switched off until you enable it and generate a short-lived code, and it switches itself back off when that code expires; while it is on, the last 30 accesses are kept with address, route and result. It is capped at 30 entries and is removed whenever the plugin is uninstalled, together with the connection settings and the code.

Neither log is sent anywhere. "Remove all data" on uninstall clears both, along with everything else the plugin stored.

== Screenshots ==

1. Offer cards on a page: the visitor picks a purchase option and buys without leaving the page.
2. Checkout with the payment methods you switched on — card via Stripe, PayPal, or the built-in test mode.
3. The dashboard: revenue over time, the latest orders and a checklist of what is still missing.
4. Creating a product and giving it purchase options — one-time price, monthly or yearly subscription.
5. The invoice list: every paid order is invoiced automatically — re-open any invoice or send the customer a fresh link.
6. An invoice with a gap-free number, ready to send or download.
7. Coupons and discount codes — shared for a campaign, or unique per customer.
8. The customer account: purchases, invoices and downloads, opened with a magic link instead of a password.

== Changelog ==

= 1.6.6 =
* First release in the WordPress Plugin Directory. This is a mature code base that was distributed from smartengin.de before joining the directory, so the version number does not start at 1.0 — the full history of every earlier version is in changelog.txt inside the plugin folder.
* The most recent work: redirect payment methods (Klarna, Amazon Pay, Bancontact, eps) now work for one-off purchases; the read-only AI connection closes itself when its code expires; and a round of security hardening in which every printed value is escaped at the point of output.
