# Chargily Pay Integration

> Integrate Chargily Pay V2 (Algerian payment gateway — EDAHABIA, CIB, and Chargily App) into any store, SaaS, marketplace, or web/mobile app. Use this skill WHEN

- Skill: `bighadj22/chargily-pay-integration` (Agent Skill, multi-file: 38 files)
- Install (CLI): `npx get-skill add bighadj22/chargily-pay-integration`
- Raw SKILL.md: https://api.skillmd.com/api/skills/bighadj22/chargily-pay-integration/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: bighadj22 (https://skillmd.com/u/bighadj22)
- Updated: 2026-12-02
- Page: https://skillmd.com/skills/bighadj22/chargily-pay-integration

---

---
name: chargily-pay-integration
description: >-
  Integrate Chargily Pay V2 (Algerian payment gateway — EDAHABIA, CIB, and
  Chargily App) into any store, SaaS, marketplace, or web/mobile app. Use this
  skill WHENEVER the user wants to accept online payments in Algeria, add a
  checkout or "pay" button, collect money from customers, sell products or
  subscriptions, generate payment links, or wire up Chargily — even if they only
  say "add payments to my store", "accept EDAHABIA/CIB", "Chargily", "Chargily
  Pay", "DZD payments", or "Algerian payment gateway" without naming an endpoint.
  Also use it for handling payment webhooks (confirming a paid order, updating
  order status), verifying webhook signatures, building products/prices/customers
  in Chargily, or debugging a Chargily integration. The skill works for any
  language or framework (PHP/Laravel, Node/Express, Python/Django/Flask, etc.)
  and is written so a developer who has never touched Chargily can ship a working,
  secure integration. Prefer this skill over guessing the API from memory.
---

# Chargily Pay V2 Integration

This skill turns "I want to accept payments" into a working, secure Chargily Pay
integration. It covers the full V2 REST API (checkouts, payment links, products,
prices, customers, balance) and — most importantly — the webhook flow that
actually marks orders as paid.

Chargily Pay is an Algerian payment gateway. It lets a store/SaaS charge
customers via **EDAHABIA**, **CIB**, and the **Chargily App** (QR code), settling
in DZD (USD/EUR wallets also exist for balance).

## Golden rules (read before writing any code)

1. **Money is in the smallest unit, as an integer.** `amount: 2500` means 2500.00
   DZD here (Chargily uses whole DZD as integers — `2500` = 2500 DZD, not cents).
   Never send floats. Always send integers.
2. **The secret key lives ONLY on the server.** Never put it in front-end code,
   mobile apps, git, or a public repo. It authenticates every request as
   `Authorization: Bearer <secret_key>`.
3. **The redirect to `success_url` is NOT proof of payment.** A user can hit that
   URL without paying. **Only a verified `checkout.paid` webhook confirms money
   moved.** Fulfill orders on the webhook, not on the redirect.
4. **Test mode vs live mode is chosen by the base URL + key together.** A test key
   only works against the test base URL; a live key only against the live base URL.
   Build and test entirely in test mode first.
5. **Always verify the webhook signature** before trusting a webhook. Unsigned or
   mismatched requests must be rejected.

## Base URLs

| Mode | Base URL |
|------|----------|
| Test | `https://pay.chargily.net/test/api/v2` |
| Live | `https://pay.chargily.net/api/v2` |

Get keys (`test_sk_...` / `live_sk_...`) from the Developers Corner in the
Chargily Pay Dashboard (`pay.chargily.com/dashboard/developers-corner`).

## The two integration patterns — pick one

Ask the user (or infer from context) which they need, then follow that path.

### Pattern A — Dynamic checkout (most common for stores & SaaS)
Your backend creates a **Checkout** on the fly for each order/cart, redirects the
customer to the returned `checkout_url`, then waits for the `checkout.paid`
webhook to fulfill. Best when the amount, customer, or cart changes per order.
This is the default recommendation.

### Pattern B — Reusable Payment Link
You pre-build **Products → Prices → a Payment Link** once. The link is a fixed
URL you share anywhere (social bio, email, button) and reuse for many customers.
Best for a fixed-price product, a donation page, or a "Buy now" button that never
changes. Still confirmed via webhooks.

Most stores use Pattern A. A "share this link" / "sell one fixed item" request
points to Pattern B.

## End-to-end flow for Pattern A (the happy path)

1. **(Optional) Create or reuse a Customer** to attach buyer info. Skip if you
   only need a one-off charge.
2. **Create a Checkout** — either with an `amount` + `currency`, or with `items`
   (Price IDs + quantities). Include `success_url` (required), `failure_url`, and
   ideally `webhook_endpoint`. Save the returned checkout `id` against your
   internal order.
3. **Redirect the customer** to the `checkout_url` from the response.
4. **Customer pays** on Chargily's hosted page (EDAHABIA / CIB / Chargily App QR).
5. **Chargily POSTs a webhook** to your endpoint with `type: "checkout.paid"`
   (or `checkout.failed`).
6. **Your endpoint verifies the signature, marks the order paid, returns 200.**
7. Customer is redirected to your `success_url` (cosmetic — do not fulfill here).

For exact request/response fields of every endpoint, read
`references/api-reference.md`. For the webhook receiver (signature verification +
handler) in multiple languages, read `references/webhooks.md`. For copy-paste
client code, see `scripts/chargily_client.py` and `scripts/chargily_client.js`.

## Choosing how to build the Checkout body

- Quick one-off charge → send `amount` (integer) + `currency: "dzd"`.
- Reusable catalog / line items / receipts → send `items: [{ price, quantity }]`
  built from Price IDs (create Products and Prices first).
- `payment_method` defaults to `"edahabia"`; can be `"cib"` or `"chargily_app"`.
  With `"chargily_app"` the response also returns a `qr_code_url`. The customer can
  switch method on the checkout page regardless.
- `chargily_pay_fees_allocation`: `"merchant"` (you pay fees), `"customer"` (buyer
  pays), or `"split"`. (`pass_fees_to_customer` is deprecated.)
- `locale`: `"ar"`, `"en"`, or `"fr"` for the checkout page language.

## Implementation checklist (use this to drive the build)

- [ ] Confirm framework/language and Pattern A vs B with the user.
- [ ] Store the secret key in an env var / secret manager — never in code.
- [ ] Build a tiny server-side API client (see `scripts/`) with the Bearer header.
- [ ] Implement the create-checkout (or create-payment-link) call.
- [ ] Redirect the customer to `checkout_url`.
- [ ] Implement the webhook endpoint: read the raw body, verify the `signature`
      header (HMAC-SHA256 of the raw body with the secret key), switch on
      `event.type`, update the order, return 200.
- [ ] Register the webhook URL in the dashboard, or pass `webhook_endpoint` per
      checkout. Test locally with a tunnel (e.g. ngrok) since Chargily can't reach
      `localhost`.
- [ ] Verify in test mode end-to-end before swapping to the live base URL + key.

## Security must-dos (don't ship without these)

- Reject webhooks with a missing `signature` header (HTTP 400) and with a
  mismatched signature (HTTP 403). Compare using a constant-time / timing-safe
  comparison.
- Verify the HMAC against the **raw, unparsed request body bytes** — parsing to
  JSON first and re-serializing will change the bytes and break verification.
- Treat the redirect to `success_url` as untrusted; reconcile real state by
  re-fetching the checkout (`GET /checkouts/{id}`) or trusting only the webhook.
- Keep test and live keys separate; never log secret keys.

## Reference files (read on demand)

- `references/api-reference.md` — every endpoint: method, path, parameters,
  example bodies and responses, list/pagination behavior, object shapes.
- `references/webhooks.md` — webhook payload structure, event types, and complete
  signature-verifying receiver examples (Python/Django, Node/Express, PHP, Go).
- `scripts/chargily_client.py` — minimal, dependency-light Python client.
- `scripts/chargily_client.js` — minimal Node.js (fetch) client.

These are accurate to Chargily Pay V2. When in doubt about a field, open the
reference file rather than guessing.
