Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to Tahseel are documented here. This project follows [Semant

### Added

- **Xendit driver** (`Tahseel::gateway('xendit')`), the thirteenth international driver and the South-East Asia specialist (Indonesia, the Philippines, Malaysia, Thailand, Vietnam, Singapore), on Payment Sessions in `PAYMENT_LINK` mode rather than the legacy Invoice API: `POST /sessions` with Basic auth (secret key as username, empty password) and the documented `api-version` header, smallest-unit amounts, the hosted `payment_link_url` returned as the checkout url; webhooks authenticated the way Xendit documents them - the dashboard's token echoed verbatim in `x-callback-token`, compared in constant time, no HMAC - and only the documented `payment_session.completed` / `payment_session.expired` events read, with a completed event re-checked against the session's own status so a session that is not `COMPLETED` comes through pending, and the closed status set honoured with anything else refused; refunds through `POST /refunds` keyed by Xendit's `payment_id`, amount required, reason mapped to the documented enum (`REQUESTED_BY_CUSTOMER` unless a documented code is passed), `SUCCEEDED`/`PENDING`/`FAILED` mapped and pending refunds left to their own webhook; config + `XENDIT_*` env vars, and 16 fixture tests. No fetch-on-callback, stated plainly. Fixture-tested only, no live account has run it yet.
- **Square driver** (`Tahseel::gateway('square')`), the twelfth international driver (US, Canada, UK, Ireland, Australia, Japan, France, Spain), on the hosted Checkout product: `POST /v2/online-checkout/payment-links` with a pinned `Square-Version` header, MINOR-unit amounts, the merchant reference carried back as the payment `note`; notifications verified exactly as Square documents them - HMAC-SHA-256 of the notification URL followed by the raw body under the subscription's signature key, base64, in `x-square-hmacsha256-signature`, constant-time, and the docs' own published example vector as a fixture test - then the authenticated `GET /v2/payments/{id}` read decides the status, a body without raw bytes is refused rather than reconstructed, and the documented `APPROVED`/`PENDING`/`COMPLETED`/`CANCELED`/`FAILED` set is honoured with `APPROVED` (authorised, not captured) coming through as pending; refund notifications parsed (`APPROVED` refunded, `PENDING` pending, `REJECTED`/`FAILED` failed); refunds through `POST /v2/refunds` with the required amount, addressed by the Square payment id, idempotency key kept inside Square's 45-character limit; `fetchPaymentStatus()`, config + `SQUARE_*` env vars, and 18 fixture tests. Fixture-tested only, no live account has run it yet.
- **Klarna driver** (`Tahseel::gateway('klarna')`), the eleventh international driver and the BNPL specialist (Sweden and the Nordics, most of Europe, the UK, the US), on the documented hosted payment page product: `POST /payments/v1/sessions` for the purchase session, then `POST /hpp/v1/sessions` for the page the customer pays on, MINOR-unit amounts, and the third step Klarna documents made explicit instead of hidden - `placeOrder($authorizationToken, $request)` creates the order that is actually paid, returns the Klarna `order_id`, and maps the fraud assessment (`REJECTED` fails, `PENDING` stays pending); callbacks carry no HMAC, so the documented one-time token in the `status_update` url is compared in constant time and the session is then re-read through the authenticated API, a post without the token is refused before any API call, and the session's closed status set is honoured with anything else refused rather than guessed; refunds with the required `refunded_amount` and the documented `Klarna-Idempotency-Key` header, addressed by Klarna's own order id; the `{{session_id}}` / `{{authorization_token}}` placeholders are sent literally as Klarna documents them rather than percent-encoded; config + `KLARNA_*` env vars, and 16 fixture tests. No `fetchPaymentStatus()`, and the callback carries no amount, so amounts are compared from `placeOrder()`. Fixture-tested only, no live account has run it yet.
- **PayTabs driver** (`Tahseel::gateway('paytabs')`), the Gulf's own processor (Saudi Arabia, UAE, Egypt, Oman, Jordan, Kuwait, Qatar, Morocco, Iraq), on the hosted payment page product: `POST /payment/request` page creation with the `redirect_url` hop, MAJOR-unit amounts, callbacks verified as documented (hex HMAC-SHA-256 of the whole raw body under the profile's Server Key, in the `Signature` header, constant-time), the browser return post's different documented recipe offered as `verifyReturnSignature()` and never trusted for money, the closed status set honoured - only `A` is paid, `H` (anti-fraud hold) and `P` (pending) come through as pending, `V`/`E`/`D`/`X` fail, and a code outside the set is refused instead of guessed; refunds with the required amount addressed by the original `tran_ref` (a `P` result is a manual refund still pending), `fetchPaymentStatus()` through `POST /payment/query`, the docs' own return-URL signature vector as a fixture test, config + `PAYTABS_*` env vars, and 26 fixture tests. Fixture-tested only, no live account has run it yet.
Expand Down
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A small, honest Laravel package for payment gateways, wherever they are.

New here? Start with the [quickstart](docs/quickstart.md).

Tahseel gives you one clean API for starting a payment, verifying the gateway's callback, and getting a normalised result. Twenty-one drivers so far: **Paymob** (Intention API + Unified Checkout), **Kashier** (v3 payment sessions), **Fawry** (pay-at-outlet reference numbers), **Geidea** (checkout sessions on the hosted page), **MyFatoorah** (invoice payment links + signed webhook v2), **Tap** (hosted charges + `hashstring` webhooks), **HyperPay** (COPYandPAY widget + AES-256-GCM encrypted webhooks), **Checkout.com** (Hosted Payments Page + `Cko-Signature` webhooks), **PayPal** (Orders v2 + `verify-webhook-signature`), **Stripe** (Checkout Sessions + the documented `Stripe-Signature` HMAC), **Paystack** (hosted checkout for Nigeria, Ghana, South Africa and Kenya + two documented webhook schemes) **Moyasar** (Saudi cards, mada, Apple/Samsung Pay and STC Pay over one API + shared-token webhooks) **Razorpay** (hosted Payment Links for India + HMAC-SHA-256 everything), **Mercado Pago** (Checkout Pro hosted pages for Latin America + manifest-signed notifications) and **Mollie** (hosted checkout for Europe - iDEAL, Bancontact, SEPA, Klarna, cards and more + deliberately unsigned webhooks verified by fetch) and **Adyen** (hosted Checkout sessions for global enterprise + HMAC-signed Standard webhooks) **Flutterwave** (hosted checkout across Africa + `verif-hash` webhooks re-checked through the API) and **PayTabs** (hosted payment pages across the Gulf + raw-body `Signature` callbacks) **Klarna** (hosted payment pages for Europe and the US + one-time-token callbacks re-checked through the API, with the documented place-order step) and **Square** (hosted payment links + notifications signed over the notification URL and raw body). Another, **manual**, covers what no wallet publishes an API for: a transfer to your Vodafone Cash number or InstaPay handle, confirmed by a human in a small approval panel. The Gulf drivers, PayPal, Stripe, Paystack, Moyasar, Razorpay, Mercado Pago, Mollie, Adyen, Flutterwave, PayTabs, Klarna and Square are fixture-tested only, no live account has run them yet.
Tahseel gives you one clean API for starting a payment, verifying the gateway's callback, and getting a normalised result. Twenty-two drivers so far: **Paymob** (Intention API + Unified Checkout), **Kashier** (v3 payment sessions), **Fawry** (pay-at-outlet reference numbers), **Geidea** (checkout sessions on the hosted page), **MyFatoorah** (invoice payment links + signed webhook v2), **Tap** (hosted charges + `hashstring` webhooks), **HyperPay** (COPYandPAY widget + AES-256-GCM encrypted webhooks), **Checkout.com** (Hosted Payments Page + `Cko-Signature` webhooks), **PayPal** (Orders v2 + `verify-webhook-signature`), **Stripe** (Checkout Sessions + the documented `Stripe-Signature` HMAC), **Paystack** (hosted checkout for Nigeria, Ghana, South Africa and Kenya + two documented webhook schemes) **Moyasar** (Saudi cards, mada, Apple/Samsung Pay and STC Pay over one API + shared-token webhooks) **Razorpay** (hosted Payment Links for India + HMAC-SHA-256 everything), **Mercado Pago** (Checkout Pro hosted pages for Latin America + manifest-signed notifications) and **Mollie** (hosted checkout for Europe - iDEAL, Bancontact, SEPA, Klarna, cards and more + deliberately unsigned webhooks verified by fetch) and **Adyen** (hosted Checkout sessions for global enterprise + HMAC-signed Standard webhooks) **Flutterwave** (hosted checkout across Africa + `verif-hash` webhooks re-checked through the API) and **PayTabs** (hosted payment pages across the Gulf + raw-body `Signature` callbacks) **Klarna** (hosted payment pages for Europe and the US + one-time-token callbacks re-checked through the API, with the documented place-order step) **Square** (hosted payment links + notifications signed over the notification URL and raw body) and **Xendit** (hosted Payment Sessions across South-East Asia + `x-callback-token` webhooks). Another, **manual**, covers what no wallet publishes an API for: a transfer to your Vodafone Cash number or InstaPay handle, confirmed by a human in a small approval panel. The Gulf drivers, PayPal, Stripe, Paystack, Moyasar, Razorpay, Mercado Pago, Mollie, Adyen, Flutterwave, PayTabs, Klarna, Square and Xendit are fixture-tested only, no live account has run them yet.

> **Status: v0.3.0, EXPERIMENTAL pre-release. Do not take real money through it yet.**
>
Expand Down Expand Up @@ -44,6 +44,7 @@ Tahseel gives you one clean API for starting a payment, verifying the gateway's
| **PayTabs** | `Tahseel::gateway('paytabs')` - hosted payment page (`POST /payment/request`) | hex HMAC-SHA-256 of the whole raw callback body under the profile's Server Key, in a `Signature` header, constant-time; the documented status set is closed, so an unknown code is refused rather than guessed | refund, amount required, addressed by the original `tran_ref`; `P` is a manual refund still pending | server-side `fetchPaymentStatus()` via `POST /payment/query` | Saudi Arabia, UAE, Egypt, Oman, Jordan, Kuwait, Qatar, Morocco, Iraq; MAJOR units; fixture-tested only, no live run yet |
| **Klarna** | `Tahseel::gateway('klarna')` - payment session + hosted page (`POST /payments/v1/sessions`, then `POST /hpp/v1/sessions`) | no HMAC: the documented one-time token in the `status_update` URL is compared in constant time, then the session is re-read through the API, so a forged call can never mark anything paid | refund, amount required, addressed by Klarna's own order id; there is no full-refund default | `placeOrder()` after the customer authorises: an authorization is not money | Europe and the US; BNPL and pay-now; MINOR units; fixture-tested only, no live run yet |
| **Square** | `Tahseel::gateway('square')` - Square-hosted payment link (`POST /v2/online-checkout/payment-links`) | HMAC-SHA-256, base64, of the notification URL followed by the raw body, keyed by the subscription's signature key, in `x-square-hmacsha256-signature`, constant-time; the notification is the signal, the authenticated payment read is the truth | refund, amount required, addressed by the Square payment id; `PENDING` until Square approves it | server-side `fetchPaymentStatus()`; an `APPROVED` payment is authorised, not captured, and comes through pending | US, Canada, UK, Ireland, Australia, Japan, France, Spain; MINOR units; fixture-tested only, no live run yet |
| **Xendit** | `Tahseel::gateway('xendit')` - Payment Session in `PAYMENT_LINK` mode (`POST /sessions`) | no HMAC: the dashboard's callback token comes back verbatim in `x-callback-token`, compared in constant time, and the documented session status set is closed, so an unknown status is refused rather than guessed | refund, amount required, addressed by Xendit's `payment_id`; `PENDING` until the refund webhook settles it | none: the callback token is the documented authentication | Indonesia, the Philippines, Malaysia, Thailand, Vietnam, Singapore; smallest-unit amounts; fixture-tested only, no live run yet |
| **Manual** (Vodafone Cash, InstaPay) | `Tahseel::gateway('manual')` - a reference, a transfer to your wallet, a human decision | none: a human confirms in the panel | not applicable | not applicable | No merchant API to call; the panel stays closed until you name a Gate ability |
| **Wallets, BNPL, Meeza, InstaPay** | through Paymob, Kashier or Geidea methods | - | - | - | None publishes a merchant API of its own; see [Wallets, BNPL, Meeza and InstaPay](#wallets-bnpl-meeza-and-instapay) |

Expand Down Expand Up @@ -295,6 +296,7 @@ $result->succeeded(); // true, false, or false while pending
| PayTabs | full or partial, MAJOR-unit amount required; only on an authorised sale or capture; `P` means a manual refund is pending | not implemented | the original `tran_ref`; the refund's own `tran_ref` comes back |
| Klarna | full or partial, MINOR-unit amount required; synchronous against a captured order | not implemented | Klarna's own order id from `placeOrder()`, not your reference |
| Square | full or partial, MINOR-unit amount required; `PENDING` until Square approves it | not implemented | the Square payment id |
| Xendit | full or partial, smallest-unit amount required; `PENDING` until the refund webhook settles it | not implemented | Xendit's `payment_id`, which the session webhook carries |

The details that bite:

Expand Down Expand Up @@ -840,6 +842,36 @@ Four Square details worth knowing:

Refunds also arrive as `refund.created` / `refund.updated` notifications, which the driver parses: `APPROVED` is refunded, `PENDING` is pending, `REJECTED` and `FAILED` fail. Fixture-tested only, no Square account has run it yet.

## Xendit

Xendit is the thirteenth international driver and the South-East Asia specialist: Indonesia, the Philippines, Malaysia, Thailand, Vietnam and Singapore, on Payment Sessions in `PAYMENT_LINK` mode - the product Xendit's own docs point new integrations at, with the older Invoice API listed under "migrate to Payment Session".

```dotenv
XENDIT_BASE_URL=https://api.xendit.co
XENDIT_SECRET_KEY=... # Dashboard -> Settings -> Developers -> API keys
XENDIT_API_VERSION=2024-11-11 # the documented version header
XENDIT_CALLBACK_TOKEN=... # Dashboard -> Settings -> Developers -> Webhooks
XENDIT_COUNTRY=ID
XENDIT_CURRENCY=IDR
XENDIT_RETURN_URL=https://your-app.test/checkout/done
XENDIT_CANCEL_URL=https://your-app.test/checkout/cancelled
```

```php
$session = Tahseel::gateway('xendit')->createPayment($request);

header('Location: '.$session->checkoutUrl);
```

Four Xendit details worth knowing:

- **Authentication is Basic with the secret key as the username and an empty password.** Xendit documents it that way, colon included, and the driver sends it that way. Every call also carries the `api-version` header, because Xendit versions its API per request rather than per host.
- **Webhooks are authenticated by `x-callback-token`, and nothing else.** There is no HMAC to compute: Xendit echoes the token from your dashboard's webhook settings in that header, and its docs are explicit that comparing it is how you know an event came from them. The driver compares it in constant time, refuses a missing or wrong token, and then reads only the documented events: `payment_session.completed` and `payment_session.expired`. There is no fetch-on-callback here, because Xendit's documented authentication for this flow is the token; the driver compensates by refusing any status outside the documented set rather than guessing.
- **A completed event is checked against the session's own status.** The documented statuses are `COMPLETED`, `ACTIVE`, `EXPIRED` and `CANCELED`: only `COMPLETED` is paid, `ACTIVE` comes through as pending, the other two fail. An event that says completed while the session says otherwise comes through pending, never paid.
- **Refunds are keyed by Xendit's `payment_id`, not by the session or your reference.** The session webhook carries that id when a payment completes, which is where you take it from. The amount is required, and the reason is a fixed enum rather than free text: a documented code you pass through is kept, anything else becomes `REQUESTED_BY_CUSTOMER`. The result is `SUCCEEDED`, `PENDING` or `FAILED`, and a pending refund settles through its own webhook.

Amounts are the currency's smallest unit, the same convention as most drivers here. Fixture-tested only, no Xendit account has run it yet.

## Manual payments: Vodafone Cash and InstaPay

Vodafone Cash and InstaPay publish no merchant API, so the honest way to accept them is the way Egyptian shops already do it: the customer transfers to your wallet or InstaPay handle, quotes a reference, and you confirm the money arrived. Tahseel ships that as a driver named `manual`.
Expand Down Expand Up @@ -934,6 +966,7 @@ Being explicit, so nobody discovers it in production:
- **No capture on Kashier.** Refund and void are wrapped; capture is not.
- **No Fawry card or wallet payments.** Reference numbers only, for the reasons above.
- **No Geidea voids or saved cards.** Refund is wrapped; Geidea documents a void only for pre-authorised, uncaptured payments and publishes no endpoint recipe for it, so it is not guessed.
- **No Xendit payment re-read.** Xendit documents a callback token rather than an HMAC for this flow, and the driver does not fetch the payment afterwards; if you want a second look before fulfilling, call Xendit's own API from your application.
- **No Square capture or voids.** Square's Payments API can complete a delayed capture; Tahseel wraps refunds only, so an `APPROVED` payment stays pending here.
- **No Klarna capture or order reads.** Klarna's Order Management API also captures and reads orders; Tahseel wraps refunds only, and the place-order step is left to `placeOrder()`.
- **Null handling in HMAC is a best guess.** Paymob does not document how it stringifies a `null` field. Tahseel treats `null` as an empty string, the PHP default. If a callback with a null signed field ever fails verification, capture the raw payload and check it against Paymob's HMAC troubleshooter.
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elbanbydev/tahseel",
"description": "Tahseel (تحصيل) - a clean, framework-native Laravel package for payment gateways: Paymob, Kashier, Fawry, Geidea, MyFatoorah, Tap, HyperPay, Checkout.com, PayPal, Stripe, Paystack, Moyasar, Razorpay, Mercado Pago, Mollie, Adyen, Flutterwave, PayTabs, Klarna, Square and manual transfers (Vodafone Cash, InstaPay) behind one gateway contract with signed webhook verification. Experimental.",
"description": "Tahseel (تحصيل) - a clean, framework-native Laravel package for payment gateways: Paymob, Kashier, Fawry, Geidea, MyFatoorah, Tap, HyperPay, Checkout.com, PayPal, Stripe, Paystack, Moyasar, Razorpay, Mercado Pago, Mollie, Adyen, Flutterwave, PayTabs, Klarna, Square, Xendit and manual transfers (Vodafone Cash, InstaPay) behind one gateway contract with signed webhook verification. Experimental.",
"keywords": [
"laravel",
"payments",
Expand Down Expand Up @@ -56,7 +56,11 @@
"sek",
"square",
"squareup",
"usd"
"usd",
"xendit",
"indonesia",
"idr",
"southeast asia"
],
"license": "MIT",
"require": {
Expand Down
Loading
Loading