Skip to content

Latest commit

 

History

History
118 lines (83 loc) · 4.78 KB

quickstart.md

File metadata and controls

118 lines (83 loc) · 4.78 KB

Quickstart

A short guide from zero to a first payment. Full details live in the README. Arabic version: docs/ar/quickstart.md.

This is an EXPERIMENTAL pre-release. What was run against a real provider is Kashier (hosted checkout and a refund) and Paymob (session creation and the signed redirect HMAC) only. Geidea and Fawry are tested against recorded payloads, and the manual driver is exercised by the test suite. Do not take real money until you have tried it yourself.

1. Install

composer require elbanbydev/paykit
php artisan vendor:publish --tag=paykit-config

The package ships no default keys and no test accounts.

2. Configure

In .env, fill in the gateway you have an account with. Paymob example:

PAYKIT_GATEWAY=paymob
PAYMOB_SECRET_KEY=sk_test_...
PAYMOB_PUBLIC_KEY=pk_test_...
PAYMOB_HMAC_SECRET=...
PAYMOB_INTEGRATION_IDS=5123456
PAYMOB_NOTIFICATION_URL=https://your-app.test/paykit/webhooks/paymob
PAYMOB_REDIRECTION_URL=https://your-app.test/checkout/done

Each gateway has its own section in config/paykit.php with exactly what it needs. Before the first payment, run:

php artisan paykit:check

It prints one line per driver: ok, or missing with the key and its environment variable. It also warns about unsafe setups (plain-HTTP URLs, a volatile idempotency cache store, receipts on a public disk).

3. First payment

use Paykit\Data\Customer;
use Paykit\Data\Money;
use Paykit\Data\PaymentRequest;
use Paykit\Facades\Paykit;

$session = Paykit::createPayment(new PaymentRequest(
    reference: 'ORDER-1042',
    amount: Money::of('250.00', 'EGP'),   // stored as 25000 piastres
    customer: new Customer(
        firstName: 'Ahmed',
        lastName: 'Ali',
        phone: '+201000000000',
    ),
    idempotencyKey: 'order-1042-attempt-1',
));

return redirect()->away($session->checkoutUrl);
  • Money stores integer minor units: EGP 250.00 is 25000 piastres.
  • PaymentSession carries orderId and checkoutUrl. Store the reference and the order id with your order; they come back in the callback.
  • Retrying with the same idempotencyKey returns the same session; the gateway is not called twice.

Want proof your keys really work? php artisan paykit:smoke starts one real payment on the gateway (it only reserves a payment page; no money moves at this step).

4. Callbacks

The package registers POST /paykit/webhooks/{gateway} itself (the path is configurable via paykit.webhooks.path). Point the gateway's notification_url at it.

No callback is read before its signature checks out. A wrong signature is refused, not guessed. Duplicates are filtered: one transaction reaches your code once. And a callback older than one already processed will not move the order backwards.

Listen for the result through events:

use Illuminate\Support\Facades\Event;
use Paykit\Events\PaymentSucceeded;

Event::listen(function (PaymentSucceeded $event) {
    $event->event->reference;        // 'ORDER-1042'
    $event->event->amount->minor;    // 25000
    $event->event->transactionId;    // the gateway's transaction id
});
  • Paykit\Events\PaymentSucceeded - the payment succeeded.
  • Paykit\Events\PaymentFailed - the payment failed or was rejected.

The redirection_url the customer lands on is not signed and anyone can open it: never update an order from it; state changes come only from the verified webhook.

5. Vodafone Cash and InstaPay (the manual driver)

No Egyptian wallet publishes a merchant API, so this driver does the manual part properly:

  1. Paykit::createPayment($request->withMethod('vodafone_cash'), 'manual') returns a reference nobody can guess, the receiving account (wallet number or InstaPay handle) and the amount; show them to the customer.
  2. The customer transfers the exact amount and uploads a receipt photo to the proof route.
  3. Someone on your team reviews in the panel (/paykit/manual/panel) and approves or rejects. Approval raises the same PaymentSucceeded the gateways raise.

This driver needs a migration:

php artisan vendor:publish --tag=paykit-migrations
php artisan migrate

The panel is closed by default: routes register only when panel.ability is set, and every request must pass that Gate ability:

Gate::define('manage-payments', fn ($user) => $user->is_admin);

Nobody can change an amount from a form, and receipts sit on a private disk, never on a public URL.

6. If anything is unclear