se7enxweb / exppaystack
Paystack payment gateway for the Exponential shop: inline Paystack checkout (cards, M-Pesa mobile money) as a kernel payment gateway of the shop/checkout payment workflow, with server-side verification on the callback, a signed webhook, and KES/USD and every other Paystack currency.
Package info
github.com/se7enxweb/exppaystack
Type:ezpublish-legacy-extension
pkg:composer/se7enxweb/exppaystack
Requires
- php: ^7.4 || ^8.0
- ext-curl: *
- ext-json: *
- se7enxweb/exponential-legacy-installer: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
exppaystack lets the Exponential shop take payments through Paystack: cards and
M-Pesa mobile money (and every other channel Paystack offers your account), in KES, USD or any currency Paystack
enables for you. It is a real kernel payment gateway, not a separate shop: the kernel's own basket, account form,
order confirmation, receipt and order administration stay exactly as they are, and Paystack is the payment step
between "Confirm order" and "Order receipt".
- Package:
se7enxweb/exppaystackon Packagist - Source: https://github.com/se7enxweb/exppaystack
- License: GNU General Public License v2.0 or later (LICENSE)
- Requires: Exponential 6.x (any kernel with the shop's
ezpaymentgatewayworkflow event), PHP 7.4 to 8.5 withcurlandjson, a Paystack account
How it works, in one picture
buyer Exponential Paystack
----- ----------- --------
shop/basket -> account -> shop/confirmorder
shop/checkout
trigger "shop / checkout / before"
-> workflow event "Payment Gateway" (exppaystack)
stores a payment object, redirects to
paystack/pay/<order> <-----
"Pay now" ------------------------------------------------------> inline popup: card, M-Pesa ...
payment succeeds
paystack/callback?reference=EXP-<order>-<random> <--------------- (browser goes back)
GET /transaction/verify/<reference> ----> status, amount, currency, metadata
checks: success, order id, amount, <----
currency, reference
approves payment, continues the workflow:
order activated, order email sent,
order status "Paid"
order receipt <---------
paystack/webhook <---------------------- charge.success (signed, HMAC SHA-512)
same verification, nothing done twice
The buyer's browser is never trusted: an order is marked paid only after Paystack's API says that this exact reference was a successful payment of this exact order, amount and currency.
Quick start (ten minutes, test mode)
-
Install.
composer require se7enxweb/exppaystack
or copy this repository to
extension/exppaystack(the folder name must beexppaystack). Then activate it insettings/override/site.ini.append.php:[ExtensionSettings] ActiveExtensions[]=exppaystackand regenerate the autoloads and clear the caches:
php bin/php/ezpgenerateautoloads.php -e php bin/php/ezcache.php --clear-all
-
Keys. In Paystack's dashboard (Settings, API Keys & Webhooks) copy the test public key and the test secret key. Put the public key in
settings/override/paystack.ini.append.php:<?php /* #?ini charset="utf-8"? [PaystackSettings] PublicKey=pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ReferencePrefix=SHOP */ ?>
and the secret key, alone, in a file only the web server user can read:
mkdir -p var/secrets printf '%s' 'sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' > var/secrets/paystack-secret chmod 0600 var/secrets/paystack-secret chown <web server user> var/secrets/paystack-secret
The secret key never goes into an INI file, a template or git.
-
Workflow. In the administration: Setup > Workflows > Standard > New workflow, name it "Shop checkout payment", add the event Event / Payment Gateway, tick Paystack (cards, M-Pesa), OK. Then Setup > Triggers, row
shop/checkout/before, choose the new workflow, Apply changes. -
Webhook. In Paystack's dashboard set the test webhook URL to
https://www.example.com/paystack/webhook(your shop's host). -
Buy something. Put a product in the basket, check out, press Pay now, and pay with one of Paystack's test cards. You land on the order receipt, and the order shows the status Paid in Webshop > Orders.
When it works, swap the test keys for the live keys (same two places) and you are live. The full walkthrough, including a local mock of Paystack's API, is in doc/testing.md.
Documentation
| Guide | What it answers |
|---|---|
| doc/README.md | Index, and the five-minute overview of every moving part |
| doc/installation.md | Requirements, Composer and manual install, activation, checking it is loaded |
| doc/configuration.md | Every setting with its default and examples, keys and secrets, test and live mode, per-siteaccess settings |
| doc/shop-workflow.md | The workflow and trigger (admin and SQL), what happens at each step, several gateways, the receipt link |
| doc/currencies-and-channels.md | Amounts in subunits, KES and USD, multiprice, M-Pesa and the other channels |
| doc/callback-and-webhook.md | The three URLs, the signature check, testing the webhook with curl, request-shield rules, CSP, proxies |
| doc/order-lifecycle.md | Order status mapping, idempotency, failures and retries, double payments, refunds, manual confirmation |
| doc/testing.md | Test-mode walkthrough, Paystack test cards, a local mock of the verify API for staging |
| doc/troubleshooting.md | The logs and what each line means, a symptom, cause and fix table |
| doc/security.md | What is checked where, secrets, multisite, several Paystack accounts, clusters and several nodes |
| doc/customizing.md | Overriding the templates, the CSS hooks (.shop-basket step list), the JavaScript contract, translations |
| doc/faq.md | The questions people ask first |
| doc/upgrading.md | Updating the extension, and moving from a hand-made payment page |
| doc/CHANGELOG.md | What changed in each release |
What is in the box
classes/exppaystackgateway.php the gateway (eZRedirectGateway), registered as "exppaystack"
classes/exppaystackpayment.php amount, currency, references, the verify call and the confirmation
modules/paystack/pay.php paystack/pay/<order id>: the inline checkout page
modules/paystack/callback.php paystack/callback?reference=...: the buyer's return
modules/paystack/webhook.php paystack/webhook: Paystack's signed server-to-server notice
design/standard/templates/paystack/pay.tpl, failed.tpl
design/standard/javascript/exppaystack.js
settings/paystack.ini the settings, with their defaults
settings/site.ini.append.php the three views need no role policy (they check for themselves)
settings/module.ini.append.php registers the paystack module
settings/design.ini.append.php registers the design folder
Support
Questions and bug reports: https://github.com/se7enxweb/exppaystack/issues. Please never paste a secret key, a full webhook body with customer data, or a log with buyers' e-mail addresses into an issue.