app2email API Ọnụahịa

Akwụkwọ

Rịọ ka a kwụọ ụgwọ n'ime mkparịta ụka WhatsApp

Rịọ onye ahịa ka ọ kwụọ ego site na otu oku API: ha na-enweta ozi WhatsApp nwere bọtịnụ Pay, kwụọ site na akaụntụ Stripe ma ọ bụ PayPal gị, ị na-enweta nhalụ payment.paid. Gụnyere ndepụta, ịkwụghachi ego na ịkwụ ụgwọ n'onwe.

Onye ahịa na-ajụ na WhatsApp "Enwere m ike ịkwụ deposit ugbu a?". Sistemu gị na-eme otu oku API, onye ahịa nwetara ozi n'otu chat ahụ nke nwere ihe ịkwụ ụgwọ ahụ bụ maka ya na bọtịnụ Pay. Bọtịnụ ahụ na-emeghe ibe ịkwụ ụgwọ, onye ahịa na-akwụ site na akaụntụ Stripe ma ọ bụ PayPal gị, ego ahụ na-aga kpọmkwem gị.

N'akụkụ gị, oku ahụ na-azaghachi ịkwụ ụgwọ ahụ na adreesị ibe ya. Mgbe onye na-enye ọrụ kwadoro ịkwụ ụgwọ ahụ, nhalụ webhook payment.paid na-abịa, ịkwụ ụgwọ ahụ na-egosi dị ka paid na API na na dashboard.

Note

Ihe a bụ, na ihe ọ bụghị. Arịrịọ ịkwụ ụgwọ bụ akụkụ nke ịkwụ ụgwọ Book-and-Pay nke app2email: ha na-eji akaụntụ Stripe ma ọ bụ PayPal ejikọtara na peeji Book-and-Pay nke dashboard, ha nwere ike ijikọ na booking ma ọ bụ guzo n'onwe ha. Onye ahịa na-akwụ ego n'ibe weebụ, ọ bụghị n'ime WhatsApp n'onwe ya. Order nke Order-and-Pay na tickets nke Tickets-and-Pay na-akwụ ụgwọ site na order flows nke ha, na oku ịkwụghachi ego nke ha (lee "Ụdị ịkwụ ụgwọ ndị ọzọ" n'okpuru).

Ihe ị chọrọ

  • Nọmba WhatsApp ejikọtara na app2email, na atụmatụ akwụghachi ụgwọ (Standard, Professional, Team, Agency ma ọ bụ Agent/Developer), ọrụ ya na-arụ ọrụ (LIVE). Oku API ọ bụla chọrọ ha abụọ (403 plan_not_allowed, 403 service_not_live).
  • Book-and-Pay edozibeela maka nọmba ahụ. Na-enweghị ya, oku ịkwụ ụgwọ na-azaghachi 403 booking_not_enabled.
  • Akaụntụ Stripe ma ọ bụ PayPal nke gị, ejikọtara na peeji Book-and-Pay nke dashboard, Payments (https://www.app2email.com/dashboard/app/book). Stripe na-anara igodo secret ma ọ bụ restricted; PayPal na-anara client id na secret nke REST app. Ebe ahụ ka ị na-ahọrọ ego (otu maka nọmba ọ bụla) na onye na-enye ọrụ abụọ ndị onye ahịa nwere ike iji. Na-enweghị onye na-enye ọrụ, arịrịọ ịkwụ ụgwọ na-azaghachi 409 payments_not_connected.
  • Igodo API site na https://www.app2email.com/dashboard/apikey nwere ikike ndị a:
IkikeIhe ọ bụ maka nduzi a
bookings:manageRịọ ịkwụ ụgwọ (POST /payments/links), kwụghachi ego (POST /payments/{id}/refund), dekọọ ịkwụ ụgwọ e mere n'onwe (POST /bookings/{id}/payment), na ịgụ ịkwụ ụgwọ
messages:readNaanị ịgụ ịkwụ ụgwọ (GET /payments, GET /payments/{id}) na ilele oge awa 24 nke onye ahịa (GET /conversations/{contact})
webhooks:manageTinye webhook nke na-anata payment.paid (POST /webhooks)
messages:sendNaanị ma ị na-ezipu njikọ ịkwụ ụgwọ n'onwe gị na template (nzọụkwụ 3)

Igodo Default (emere tupu igodo nwee ikike) enweghị bookings:manage. Mepụta igodo nwere ikike ahụ, ma ọ bụ Full access (*). GET /v1/YOUR_NUMBER/me na-egosi ikike igodo ị nwere.

Warning

Enweghị sandbox maka ego. Igodo sandbox nwere ike ịgụ ịkwụ ụgwọ (GET /payments), mana ịrịọ ịkwụ ụgwọ na ịkwụghachi ego na-azaghachi 403 sandbox_key, n'ihi na ha na-arụ ọrụ na ego n'ezie n'aka onye na-enye ọrụ gị. Instant sandbox maka nọmba demo 12025550100 enweghị oku ịkwụ ụgwọ ọ bụla (403 not_in_instant_sandbox). Iji nwalee, jikọta PayPal n'ụdị sandbox na peeji Payments, wee rịọ onwe gị ego obere na WhatsApp gị.

Rịọ ịkwụ ụgwọ, nzọụkwụ nzọụkwụ

  1. 1. Lelee ma oghere oge onye ahịa emeghere

    app2email nwere ike izipu njikọ ịkwụ ụgwọ n'WhatsApp maka gị, mana naanị n'ime oge awa 24 nke onye ahịa: n'ime awa 24 site na ozi ikpeazụ ha zipuru nọmba gị (app2email na-akwụsị nkeji 15 tupu oge). Onye ahịa nke ji ajụ "Enwere m ike ịkwụ ugbu a?" nọ n'ime ya.

    GET /v1/YOUR_NUMBER/conversations/61412345678 (ikike messages:read) na-egosi window_state (open ma ọ bụ closed) na window_closes_at.

    cURL
    curl -s https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678 \
      -H "Authorization: Bearer $A2E_KEY"
    Node.js
    const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678", {
      headers: { Authorization: `Bearer ${process.env.A2E_KEY}` },
    });
    const conv = await res.json();
    console.log(conv.window_state, conv.window_closes_at);
    Python
    import os, requests
    
    res = requests.get(
        "https://api.app2email.com/v1/YOUR_NUMBER/conversations/61412345678",
        headers={"Authorization": f"Bearer {os.environ['A2E_KEY']}"},
    )
    conv = res.json()
    print(conv["window_state"], conv.get("window_closes_at"))

    Ihe ị na-enweta azụ (mkpokọta):

    {
      "success": true,
      "request_id": "c9slm",
      "contact": "61412345678",
      "name": "John",
      "window_state": "open",
      "window_open": true,
      "window_closes_at": "2026-10-27T01:05:44Z",
      "last_inbound_at": "2026-10-26T01:20:44Z"
    }

    Ọ bụrụ na oghere ahụ emechiri, ị ka nwere ike ịrịọ ịkwụ ụgwọ n'nzọụkwụ na-esote. app2email anaghị ezipu ya mgbe ahụ; ị na-ezipu url ya n'ime template n'onwe gị (nzọụkwụ 3).

  2. 2. Mee arịrịọ ịkwụ ụgwọ

    POST /v1/YOUR_NUMBER/payments/links (ikike bookings:manage). Body:

    UbiỌ dị mkpa?Ihe ọ pụtara
    contacteeNọmba WhatsApp onye ahịa yana koodu mba, naanị ọnụọgụ, ma ọ bụ user id ya nke azụmahịa
    amounteeEgo n'ego ịkwụ ụgwọ gị, dị ka nọmba: 40 bụ $40.00 ma ọ bụrụ na ego gị bụ USD. Ga-abụ karịa 0
    descriptioneeIhe ịkwụ ụgwọ ahụ bụ maka ya. Onye ahịa hụ ya
    booking_idmbaBooking nke ya: id ya ma ọ bụ ntụaka ya (BK-7Q3M2A)
    namembaAha onye ahịa
    sendmbatrue: zipukwa njikọ n'WhatsApp, dị ka ozi nwere bọtịnụ Pay, mgbe onye ahịa nọ n'ime oge awa 24 ha. Ndabere false

    Enweghị ebe ego: ego ahụ bụ ego a họọrọ na peeji Payments mgbe niile. config.payments.currency na GET /v1/YOUR_NUMBER/settings/booking na-egosi ya, na ịkwụ ụgwọ ọ bụla nwere currency ya.

    Zipu isi Idempotency-Key nke bụ nke arịrịọ a, dịka nọmba invoice gị. Ọ bụrụ na koodu gị na-anwa ọzọ mgbe oge agafeworo, otu igodo na body n'ime awa 24 na-anata azịza mbụ ọzọ, onye ahịa anaghị ajụkwa ọzọ. Njehie adịghị eji igodo ahụ.

    cURL
    curl -s https://api.app2email.com/v1/YOUR_NUMBER/payments/links \
      -H "Authorization: Bearer $A2E_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: deposit-BK-7Q3M2A" \
      -d '{
        "contact": "61412345678",
        "amount": 40,
        "description": "Deposit for your colour",
        "booking_id": "BK-7Q3M2A",
        "send": true
      }'
    Node.js
    async function askForPayment({ phone, amount, description, bookingRef }) {
      const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/payments/links", {
        method: "POST",
        headers: {
          Authorization: `Bearer ${process.env.A2E_KEY}`,
          "Content-Type": "application/json",
          "Idempotency-Key": `deposit-${bookingRef}`,
        },
        body: JSON.stringify({
          contact: phone, // "61412345678"
          amount, // 40
          description, // "Deposit for your colour"
          booking_id: bookingRef, // optional
          send: true,
        }),
      });
      const body = await res.json();
      if (!res.ok) throw new Error(`${body.error.code}: ${body.error.how_to_fix}`);
      return { paymentId: body.payment.id, url: body.url, sent: body.sent };
    }
    Python
    def ask_for_payment(phone, amount, description, booking_ref=None):
        payload = {"contact": phone, "amount": amount, "description": description, "send": True}
        if booking_ref:
            payload["booking_id"] = booking_ref
        res = requests.post(
            "https://api.app2email.com/v1/YOUR_NUMBER/payments/links",
            headers={
                "Authorization": f"Bearer {os.environ['A2E_KEY']}",
                "Idempotency-Key": f"deposit-{booking_ref or phone}",
            },
            json=payload,
        )
        body = res.json()
        if not res.ok:
            raise RuntimeError(f"{body['error']['code']}: {body['error']['how_to_fix']}")
        return body["payment"]["id"], body["url"], body["sent"]

    Ihe ị na-enweta azụ (HTTP 201): ịkwụ ụgwọ ahụ, nwere kind request na status pending, ibe ebe onye ahịa ga-akwụ ụgwọ (url), na ma ọ bụ zipuru n'WhatsApp (sent).

    {
      "success": true,
      "request_id": "p3lk4",
      "payment": {
        "id": 15,
        "kind": "request",
        "status": "pending",
        "provider": "stripe",
        "amount": 40.0,
        "amount_label": "$40.00",
        "full_label": "$40.00",
        "discount_label": "",
        "coupon_code": "",
        "currency": "USD",
        "refunded": 0.0,
        "refunded_label": "",
        "description": "Deposit for your colour",
        "contact": "61412345678",
        "payer_name": "John Smith",
        "appointment_id": 42,
        "booking_reference": "BK-7Q3M2A",
        "package_purchase_id": null,
        "checkout_url": "",
        "link_url": "https://www.app2email.com/book/k3XbQ9rTzP2m",
        "last_error": "",
        "paid": null,
        "refunded_at": null,
        "created": "2026-11-11T01:10:00.000Z"
      },
      "url": "https://www.app2email.com/book/k3XbQ9rTzP2m",
      "sent": true,
      "note": "The customer was sent the pay link on WhatsApp."
    }

    Debe payment.id na invoice ma ọ bụ booking gị: ọ bụ otu ị ga-esi gụọ, tụnyere na kwụghachi ụgwọ a mgbe e mesịrị.

  3. 3. Ọ bụrụ na sent bụ false: zipu url n'onwe gị

    sent bụ false mgbe ị hapụrụ send, ma ọ bụ mgbe oghere onye ahịa emechiri. Arịrịọ ịkwụ ụgwọ ka dị, url ya na-arụ ọrụ. Zipu ya n'ụzọ kwekọrọ:

    • Oghere meghere: ozi ederede nkịtị nwere njikọ (POST /messages, "type": "text", ikike messages:send).
    • Oghere emechiri: template e kwadoro. Template UTILITY dịka Hi {{1}}, here is the payment link for {{2}}: {{3}} na-arụ ọrụ, yana url dị ka uru nke atọ. Otu esi emepụta na izipu template: Zipu ozi order na appointment site na template.
    cURL
    curl -s https://api.app2email.com/v1/YOUR_NUMBER/messages \
      -H "Authorization: Bearer $A2E_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: deposit-BK-7Q3M2A-link" \
      -d '{
        "to": "61412345678",
        "type": "template",
        "template": {
          "name": "payment_request",
          "language": { "code": "en" },
          "components": [
            {
              "type": "body",
              "parameters": [
                { "type": "text", "text": "John" },
                { "type": "text", "text": "the deposit for your colour" },
                { "type": "text", "text": "https://www.app2email.com/book/k3XbQ9rTzP2m" }
              ]
            }
          ]
        }
      }'
    Node.js
    await fetch("https://api.app2email.com/v1/YOUR_NUMBER/messages", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.A2E_KEY}`,
        "Content-Type": "application/json",
        "Idempotency-Key": `payment-${paymentId}-link`,
      },
      body: JSON.stringify({
        to: "61412345678",
        type: "template",
        template: {
          name: "payment_request",
          language: { code: "en" },
          components: [
            {
              type: "body",
              parameters: [
                { type: "text", text: "John" },
                { type: "text", text: "the deposit for your colour" },
                { type: "text", text: url }, // the url from step 2
              ],
            },
          ],
        },
      }),
    });
    Python
    requests.post(
        "https://api.app2email.com/v1/YOUR_NUMBER/messages",
        headers={
            "Authorization": f"Bearer {os.environ['A2E_KEY']}",
            "Idempotency-Key": f"payment-{payment_id}-link",
        },
        json={
            "to": "61412345678",
            "type": "template",
            "template": {
                "name": "payment_request",
                "language": {"code": "en"},
                "components": [
                    {
                        "type": "body",
                        "parameters": [
                            {"type": "text", "text": "John"},
                            {"type": "text", "text": "the deposit for your colour"},
                            {"type": "text", "text": url},  # the url from step 2
                        ],
                    }
                ],
            },
        },
    )

    Ị nwekwara ike ikekọrịta url n'email, SMS ma ọ bụ n'ibe invoice gị n'onwe gị. Ọ bụ otu ịkwụ ụgwọ n'ụzọ abụọ ahụ.

  4. 4. Nata nhalụ payment.paid

    Tinye webhook otu ugboro (POST /v1/YOUR_NUMBER/webhooks yana url https gị, ikike webhooks:manage) wee debe secret ọ na-azaghachi. Webhook ọ bụla nke nọmba ahụ na-anata nhalụ niile, ya mere kwaga payment.paid wee zaghachi 2xx maka ndị ọzọ. Enweghị adreesị ọha ka? GET /v1/YOUR_NUMBER/events?wait=25 na-enweta otu nhalụ ahụ.

    Mgbe Stripe ma ọ bụ PayPal kwadoro ịkwụ ụgwọ ahụ, nke a na-abịa:

    {
      "id": "evt_Pay3k9m2Lw8Rt5Yp1Zs03",
      "type": "payment.paid",
      "created": "2026-11-11T01:00:00.000Z",
      "number": "4976659348270",
      "data": {
        "payment": {
          "id": 15,
          "kind": "request",
          "status": "paid",
          "provider": "stripe",
          "amount": 40.0,
          "amount_label": "$40.00",
          "full_label": "$40.00",
          "discount_label": "",
          "coupon_code": "",
          "currency": "USD",
          "refunded": 0.0,
          "refunded_label": "",
          "description": "Deposit for your colour",
          "contact": "61412345678",
          "payer_name": "John Smith",
          "appointment_id": null,
          "booking_reference": "",
          "package_purchase_id": null,
          "checkout_url": "",
          "link_url": "",
          "last_error": "",
          "paid": "2026-11-11T01:15:00.000Z",
          "refunded_at": null,
          "created": "2026-11-11T01:10:00.000Z"
        },
        "timestamp": "2026-11-11T01:00:00.000Z"
      }
    }

    Jikọta ya na invoice gị site na data.payment.id, wee lelee data.payment.kind: payment.paid na-ezipukwa maka pakej e zụrụ n'ịntanet tupu (package), Order-and-Pay na-ezipu ya n'akụkụ order.paid. paid bụ oge ịkwụ ụgwọ, provider na-ekwu onye na-enye ọrụ nke nara ya.

    Node.js
    app.post("/app2email", express.raw({ type: "application/json" }), async (req, res) => {
      if (!verifyWebhook(req.body, req.get("X-App2email-Signature"), process.env.WEBHOOK_SECRET)) return res.sendStatus(401);
      if (await alreadySeen(req.get("X-App2email-Delivery"))) return res.sendStatus(200); // a retry
      const event = JSON.parse(req.body);
      if (event.type === "payment.paid" && event.data.payment.kind === "request") {
        await markInvoicePaid(event.data.payment.id, event.data.payment.amount, event.data.payment.paid);
      }
      res.sendStatus(200); // within 10 seconds
    });
    Python
    @app.post("/app2email")
    def app2email():
        raw = request.get_data()
        if not verify_webhook(raw, request.headers.get("X-App2email-Signature"), os.environ["WEBHOOK_SECRET"]):
            return "", 401
        if already_seen(request.headers.get("X-App2email-Delivery")):
            return "", 200  # a retry
        event = json.loads(raw)
        if event["type"] == "payment.paid" and event["data"]["payment"]["kind"] == "request":
            p = event["data"]["payment"]
            mark_invoice_paid(p["id"], p["amount"], p["paid"])
        return "", 200  # within 10 seconds

    verifyWebhook na verify_webhook dị n'okpuru nlekọta maka mmepụta.

Nsonaazụ

Ihe onye ahịa hụrụ. Mgbe send: true, ozi site na azụmahịa gị n'ime chat, nwere description gị na bọtịnụ Pay. Bọtịnụ ahụ na-emeghe ibe ịkwụ ụgwọ (link_url, na ibe booking gị), site ebe ahụ onye ahịa na-akwụ na Stripe ma ọ bụ PayPal, na nke ọ bụla n'ime abụọ ahụ ị kwadoro. Ego ahụ na-aga site n'aka onye ahịa gaa na akaụntụ onye na-enye ọrụ gị; app2email anaghị ewere ụgwọ ma enweghị ya ọ bụla. Akwụkwọ ụgwọ ahụ si n'aka onye na-enye ọrụ.

Ihe ị na-ahụ. Ịkwụ ụgwọ na-aga site na ụkpụrụ status ndị a:

statusIhe ọ pụtara
pendingE mere, ma a ka akwụghị ya
paidOnye na-enye ọrụ kwadoro ịkwụ ụgwọ ahụ. payment.paid na-ezipu
partly_refundedA kwụghachiri akụkụ nke ego (refunded na-ekwu ego ole)
refundedA kwụghachiri ya niile
failedỊkwụ ụgwọ agabeghị. last_error na-ekwu ihe kpatara ya
expiredOnye ahịa akwụghị n'oge
cancelledA kagburu ịkwụ ụgwọ ahụ

Naanị paid nwere nhalụ nke ya (payment.paid). Maka steeti ndị ọzọ, gụọ ịkwụ ụgwọ ahụ.

Gụọ otu ịkwụ ụgwọ: GET /v1/YOUR_NUMBER/payments/15 (ikike bookings:manage ma ọ bụ messages:read). Igodo onye na-enye ọrụ ma ọ bụ secret apụtaghị n'azịza.

Depụta ịkwụ ụgwọ, nke ọhụrụ kacha mbụ: GET /v1/YOUR_NUMBER/payments, yana nzacha contact, booking (id booking ma ọ bụ ntụaka BK-), status, kind, limit (1 ruo 200, ndabere 50) na cursor (next_cursor nke azịza gara aga).

cURL
curl -s "https://api.app2email.com/v1/YOUR_NUMBER/payments?kind=request&status=pending&limit=50" \
  -H "Authorization: Bearer $A2E_KEY"
Node.js
let cursor;
do {
  const qs = new URLSearchParams({ kind: "request", status: "pending", limit: "50" });
  if (cursor) qs.set("cursor", cursor);
  const res = await fetch(`https://api.app2email.com/v1/YOUR_NUMBER/payments?${qs}`, {
    headers: { Authorization: `Bearer ${process.env.A2E_KEY}` },
  });
  const page = await res.json();
  for (const p of page.payments) console.log(p.id, p.status, p.amount_label, p.contact);
  cursor = page.next_cursor;
} while (cursor);
Python
params = {"kind": "request", "status": "pending", "limit": 50}
while True:
    page = requests.get(
        "https://api.app2email.com/v1/YOUR_NUMBER/payments",
        headers={"Authorization": f"Bearer {os.environ['A2E_KEY']}"},
        params=params,
    ).json()
    for p in page["payments"]:
        print(p["id"], p["status"], p["amount_label"], p["contact"])
    if not page.get("next_cursor"):
        break
    params["cursor"] = page["next_cursor"]

Ihe ị na-enweta azụ (mkpokọta): payments, count, next_cursor (ewepụrụ ya na peeji ikpeazụ) na currency nọmba ahụ.

{
  "success": true,
  "request_id": "p1ls2",
  "payments": [
    {
      "id": 15,
      "kind": "booking",
      "status": "paid",
      "provider": "stripe",
      "amount": 40.0,
      "amount_label": "$40.00",
      "currency": "USD",
      "refunded": 0.0,
      "description": "Haircut",
      "contact": "61412345678",
      "payer_name": "John Smith",
      "appointment_id": 42,
      "booking_reference": "BK-7Q3M2A",
      "paid": "2026-11-11T01:15:00.000Z",
      "created": "2026-11-11T01:10:00.000Z"
    }
  ],
  "next_cursor": null,
  "count": 1,
  "currency": "USD"
}

kind na-agwa gị ebe ịkwụ ụgwọ si bịa: request (arịrịọ ịkwụ ụgwọ dịka nke n'elu), booking (ịkwụ ụgwọ ntanetị ma ọ bụ deposit nke booking), package (pakej e zụrụ n'ịntanet tupu) ma ọ bụ ticket (order ticket).

Kwụghachi ego nke ịkwụ ụgwọ

POST /v1/YOUR_NUMBER/payments/{id}/refund (ikike bookings:manage) na-eziga ego n'ezie azụ site na onye na-enye ọrụ gị. Enweghị ike ịkagbu ya. Hapụ body (ma ọ bụ amount) maka ịkwụghachi niile fọdụrụ. Zipu amount maka akụkụ, n'ego ịkwụ ụgwọ ahụ.

Zipu mgbe niile Idempotency-Key: ịkwụghachi ego a na-anwa ọzọ mgbe oge agafeworo, yana otu igodo na body, na-anata azịza mbụ, ego ahụ alaghachi otu ugboro.

Ịkwụghachi akụkụ
cURL
curl -s https://api.app2email.com/v1/YOUR_NUMBER/payments/15/refund \
  -H "Authorization: Bearer $A2E_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: refund-15-part-1" \
  -d '{ "amount": 10 }'
Node.js
const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/payments/15/refund", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.A2E_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "refund-15-part-1",
  },
  body: JSON.stringify({ amount: 10 }),
});
const { payment } = await res.json();
console.log(payment.status, payment.refunded_label); // partly_refunded $10.00
Python
res = requests.post(
    "https://api.app2email.com/v1/YOUR_NUMBER/payments/15/refund",
    headers={
        "Authorization": f"Bearer {os.environ['A2E_KEY']}",
        "Idempotency-Key": "refund-15-part-1",
    },
    json={"amount": 10},
)
payment = res.json()["payment"]
print(payment["status"], payment["refunded_label"])  # partly_refunded $10.00
Ịkwụghachi niile
cURL
curl -s -X POST https://api.app2email.com/v1/YOUR_NUMBER/payments/15/refund \
  -H "Authorization: Bearer $A2E_KEY" \
  -H "Idempotency-Key: refund-15-full"
Node.js
const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/payments/15/refund", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.A2E_KEY}`,
    "Idempotency-Key": "refund-15-full",
  },
});
const { payment } = await res.json();
console.log(payment.status); // refunded
Python
res = requests.post(
    "https://api.app2email.com/v1/YOUR_NUMBER/payments/15/refund",
    headers={
        "Authorization": f"Bearer {os.environ['A2E_KEY']}",
        "Idempotency-Key": "refund-15-full",
    },
)
print(res.json()["payment"]["status"])  # refunded

Ihe ị na-enweta azụ (HTTP 200, mkpokọta, mgbe ịkwụghachi $10 nke $40):

{
  "success": true,
  "request_id": "p4rf5",
  "payment": {
    "id": 15,
    "kind": "booking",
    "status": "partly_refunded",
    "provider": "stripe",
    "amount": 40.0,
    "amount_label": "$40.00",
    "currency": "USD",
    "refunded": 10.0,
    "refunded_label": "$10.00",
    "description": "Haircut",
    "contact": "61412345678",
    "appointment_id": 42,
    "booking_reference": "BK-7Q3M2A",
    "paid": "2026-11-11T01:15:00.000Z",
    "created": "2026-11-11T01:10:00.000Z"
  },
  "note": "Refunded through the payment provider. booking.refunded is sent."
}

Ịkwụghachi ego na-ezipukwa nhalụ booking.refunded. Ọ na-ebu ubi booking ahụ yana payment na ihe refund (amount, amount_label, full, by), ya mere ọ dị mkpa nke ukwuu maka ịkwụ ụgwọ ejikọtara na booking. Ịkwụghachi ego niile nke ịkwụ ụgwọ booking na-atọkwa ọnọdụ ịkwụ ụgwọ booking ahụ ka refunded. Maka ịkwụ ụgwọ ọ bụla, azịza dị n'elu na GET /payments/{id} na-egosi steeti ọhụrụ.

{
  "id": "evt_Pay3k9m2Lw8Rt5Yp1Zs02",
  "type": "booking.refunded",
  "created": "2026-11-11T01:00:00.000Z",
  "number": "4976659348270",
  "data": {
    "id": 42,
    "reference": "BK-7Q3M2A",
    "status": "confirmed",
    "contact": "61412345678",
    "start": "2026-11-14T23:00:00.000Z",
    "end": "2026-11-14T23:30:00.000Z",
    "payment_status": "refunded",
    "payment": { "id": 15, "kind": "booking", "status": "refunded", "amount": 40.0, "refunded": 40.0, "refunded_label": "$40.00", "currency": "USD" },
    "refund": { "amount": 40.0, "amount_label": "$40.00", "full": true, "by": "jane@example.com" },
    "timestamp": "2026-11-11T01:00:00.000Z"
  }
}

Ịkwụghachi ego nke enweghị ike ime (ịkwụ ụgwọ ahụ akwụghị, akwughachiri ya, ma ọ bụ ihe fọdụrụ dị nta karịa ihe ị rịọrọ) na-azaghachi 409 refund_not_possible. Ọ bụrụ na Stripe ma ọ bụ PayPal jụrụ, ị na-enweta 502 payment_provider_error yana ozi onye na-enye ọrụ ahụ.

Ịkwụ ụgwọ e mere n'èzí app2email

Mgbe onye ahịa booking kwụrụ n'aka ego, ma ọ bụ site na igwe kaadị, dekọọ ya site na POST /v1/YOUR_NUMBER/bookings/{id}/payment (ikike bookings:manage; id ma ọ bụ ntụaka BK-). Enweghị ego a na-agbakwụnye ma ọ bụ kwụghachi: ndekọ gị n'onwe ya ka ọ bụ.

statusIhe ọ pụtara
paidE mere n'èzí app2email (ego n'aka, terminal)
waivedEnweghị ihe a ga-akwụ
dueKa a na-atụ anya ya (ọnụahịa ọrụ ahụ bụ ego mgbe enweghị ihe e debere)
cURL
curl -s https://api.app2email.com/v1/YOUR_NUMBER/bookings/BK-7Q3M2A/payment \
  -H "Authorization: Bearer $A2E_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "status": "paid" }'
Node.js
const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/bookings/BK-7Q3M2A/payment", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.A2E_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ status: "paid" }),
});
console.log((await res.json()).booking.payment);
Python
res = requests.post(
    "https://api.app2email.com/v1/YOUR_NUMBER/bookings/BK-7Q3M2A/payment",
    headers={"Authorization": f"Bearer {os.environ['A2E_KEY']}"},
    json={"status": "paid"},
)
print(res.json()["booking"]["payment"])

Ihe ị na-enweta azụ:

{
  "success": true,
  "request_id": "p5bs6",
  "booking": {
    "id": 42,
    "reference": "BK-7Q3M2A",
    "status": "confirmed",
    "payment": { "status": "paid", "due": 0.0, "paid": 0.0, "currency": "USD" }
  }
}

Nke a na-arụ ọrụ naanị maka booking. Arịrịọ ịkwụ ụgwọ otu oge na-enweghị booking enweghị ike ịkpọ ya dị ka paid site n'aka site na API: ọ na-aghọ paid mgbe onye na-enye ọrụ kwadoro ya. Nhalụ booking.paid anaghị ezipu maka ịkwụ ụgwọ ị dekọrọ n'aka.

Ụdị ịkwụ ụgwọ ndị ọzọ

Ihe e kwụrụGụọ yaKwụghachi ya
Arịrịọ ịkwụ ụgwọ (kind request)GET /payments/{id}POST /payments/{id}/refund
Ịkwụ ụgwọ ntanetị ma ọ bụ deposit nke booking (kind booking)GET /payments?booking=BK-7Q3M2APOST /payments/{id}/refund (booking.refunded na-ezipu)
Order ticket (kind ticket)GET /tickets/ordersPOST /tickets/orders/{id}/refund (ikike tickets:manage): ọ na-akwụsikwa ticket ndị ahụ
Order nke Order-and-PayGET /shop/orders/{id}POST /shop/orders/{id}/refund (ikike orders:manage; amount ebe ahụ bụ na minor units, dịka cents)

Ịkwụ ụgwọ nke booking n'onwe ya na-arịọkarị site na Book-and-Pay n'onwe ya: akwụkwọ nkwenye booking nwere bọtịnụ "Pay now" mgbe a na-akwụ ọrụ ahụ n'ịntanet, a na-ezipu booking.paid mgbe akwụrụ ya. Lee Nnabata booking n'WhatsApp.

Tip

Site n'aka AI agent. MCP server nke ịkwụ ụgwọ https://api.app2email.com/mcp/payments nwere otu oku dị ka tools: request_payment, list_payments na refund_payment, yana otu igodo na ikike. Lee Kwe ka AI agent na-achịkwa WhatsApp gị site na MCP na MCP.

Nlekọta maka mmepụta

Lelee ibinye akara webhook

Nhalụ ọ bụla nwere isi X-App2email-Signature: t=<unix seconds>,v1=<hex>. Uru v1 bụ HMAC-SHA256 nke "<t>.<raw body>", yana secret webhook (whsec_..., yana prefix) dị ka igodo. Nyochaa v1= ọ bụla (abụọ dị mgbe secret ochie ka na-echekwa mgbe e gbanwere ya), gbakọọ ya n'elu raw body dị ka e nara ya, wee jụ t ochie. X-Hub-Signature-256: sha256=<hex> (HMAC-SHA256 nke raw body, naanị secret ugbu a) dịkwa, maka koodu e dere maka webhook Meta.

Nhalụ payment.paid na-ekwu na onye ahịa akwụla, ya mere emela ihe ọ bụla n'ihe ọ bụla ndị mbinye akara ya adabaghị.

Node.js
import crypto from "node:crypto";

// rawBody: the body exactly as received, eg express.raw({ type: "application/json" })
export function verifyWebhook(rawBody, header, secret, toleranceSeconds = 300) {
  const t = /(?:^|,)\s*t=(\d+)/.exec(header ?? "")?.[1];
  const v1 = [...(header ?? "").matchAll(/(?:^|,)\s*v1=([0-9a-f]+)/g)].map((m) => m[1]);
  if (!t || v1.length === 0 || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false;
  const expected = crypto.createHmac("sha256", secret).update(t + ".").update(rawBody).digest("hex");
  return v1.some((v) => v.length === expected.length && crypto.timingSafeEqual(Buffer.from(v), Buffer.from(expected)));
}
Python
import hashlib, hmac, re, time

def verify_webhook(raw_body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
    t = re.search(r"(?:^|,)\s*t=(\d+)", header or "")
    v1 = re.findall(r"(?:^|,)\s*v1=([0-9a-f]+)", header or "")
    if not t or not v1 or abs(time.time() - int(t.group(1))) > tolerance:
        return False
    expected = hmac.new(secret.encode(), t.group(1).encode() + b"." + raw_body, hashlib.sha256).hexdigest()
    return any(hmac.compare_digest(v, expected) for v in v1)
Gụnye ịkwụ ụgwọ naanị mgbe onye na-enye ọrụ kwadoro ya

Onye ahịa nke mere ibe ahụ, ma ọ bụ laghachi site na checkout, enweghị ike ịbụ na akwụla. Kpọọ invoice ka akwụrụ naanị na payment.paid, ma ọ bụ mgbe GET /payments/{id} gosiri status paid. Nhalụ nwere ike ịbịa n'ụzọ ezighi ezi na mgbe, ya mere ọ bụrụ na ị efuola otu, status ịkwụ ụgwọ ahụ bụ eziokwu.

Hichapụ nhalụ ndị ugboro ugboro

Zaghachi site na koodu 2xx n'ime sekọnd 10. Ọ bụghị ya, nhalụ ahụ na-ezipu ọzọ mgbe sekọnd 10, nkeji 1, nkeji 5, nkeji 30, awa 1, 2, 4, 8 na 16. X-App2email-Delivery (id nhalụ, evt_...) dị otu n'ọnwa nnwale ọ bụla, ya mere chekwaa ya wee hapụ nhalụ ị kpọrọla. Mee ka "kpọọ dị ka akwụrụ" dị nchekwa ịgba ugboro abụọ maka otu data.payment.id. Mee ọrụ dị oke mgbe ị zaghachisịrị.

Ajụla ugboro abụọ, kwụghachikwa ego ugboro abụọ

Zipu isi Idempotency-Key na POST /payments/links na na POST /payments/{id}/refund, site na ntụaka gị (deposit-BK-7Q3M2A, refund-15-full), ọ bụghị site na mbọ. Otu igodo na body n'ime awa 24 na-anata azịza mbụ ọzọ, yana isi Idempotent-Replayed: true. Njehie adịghị eji igodo ahụ.

  • Otu igodo yana body dị iche: 422 idempotency_key_reused. Jiri igodo ọhụrụ maka arịrịọ dị iche.
  • Arịrịọ mbụ ka na-aga: 409 idempotency_request_in_progress. Chere wee nwaa ọzọ yana otu igodo.
  • Arịrịọ mbụ akwụsịghị: 409 idempotency_request_interrupted. Lelee GET /payments?contact=61412345678 tupu ị nwaa yana igodo ọhụrụ.

Igodo ahụ na-echekwa ruo awa 24. Debekwa payment.id na ndekọ gị n'onwe gị, ma ajụla ọzọ mgbe ọ dị n'ebe ahụ.

Nwaa ọzọ naanị njehie kwesịrị ekwesị

Azịza ọ bụla nwere X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset (sekọnd ruo mgbe ọ juputara ọzọ) na X-RateLimit-Policy. Karịa oke ị na-enweta 429 rate_limited yana isi Retry-After na error.retry_after_seconds: chere ogologo oge ahụ, wee zipu arịrịọ otu ahụ ọzọ.

  • 500, oge agwụla, ma ọ bụ 502 payment_provider_error mgbe enweghị ike ịnweta onye na-enye ọrụ: nwaa ọzọ ụfọdụ yana oge na-abawanye, yana otu Idempotency-Key.
  • 409 payments_not_connected, 409 refund_not_possible, 403 booking_not_enabled, 403 plan_not_allowed: anwaghị ọzọ. Ha chọrọ mgbanwe na dashboard ma ọ bụ na arịrịọ gị.
  • Koodu 4xx ọ bụla ọzọ: anwaghị ọzọ na-agbanwegh. Kpebie site na error.code wee soro how_to_fix. error.is_retriable na-agwa gị ma otu arịrịọ ahụ nwere ike ịrụ ọrụ mgbe e mesịrị.
Oghere awa 24

Mgbe send: true, app2email na-ezipu njikọ ịkwụ ụgwọ n'WhatsApp naanị n'ime oge awa 24 nke onye ahịa (app2email na-akwụsị nkeji 15 tupu oge). Ọ bụghị ya, arịrịọ ahụ ka a na-eme ya, sent bụ false: zipu url n'ime template e kwadoro. GET /v1/YOUR_NUMBER/conversations/61412345678 na-egosi window_state na window_closes_at.

Opt-out na Do Not Call

Arịrịọ ịkwụ ụgwọ na-azaghachi onye ahịa na-agwa gị okwu, ya mere ọ na-aga n'ime oge ha, ebe ndepụta Do Not Call anaghị arụ ọrụ (ọ na-arụ ọrụ maka template ahịa). Ọ bụrụ na ị zipu njikọ n'ime template, jiri template UTILITY nke naanị na-arịọ ịkwụ ụgwọ, enweghị ihe nye ego n'ime ya. Ekwula izipu njikọ ịkwụ ụgwọ n'ebe ndị na-achọghị ịzụ ihe.

Chekwaa igodo na ego nke ọma

Debe igodo API na sava gị. Igodo nwere bookings:manage nwere ike ịkwụghachi ego n'ezie, ya mere nye naanị sistemu ndị chọrọ ya. Igodo nwere ike ịgbachi ka ọ bụrụ naanị ụfọdụ adreesị IP (403 ip_not_allowed site n'ebe ndị ọzọ) ma nwee ike ịgwụ. Igodo nwere naanị messages:read nwere ike ịgụ ịkwụ ụgwọ, mana ọ gaghị arịọ ma ọ bụ kwụghachi ego. Ịkwụ ụgwọ anaghị enwe nkọwa kaadị ma ọ bụ igodo onye na-enye ọrụ.

Ọ bụrụ na ọ naghị arụ ọrụ

Njehie ọ bụla bụ JSON nwere error.code, message, how_to_fix na request_id iji kwuo na nkwado. Lee Njehie maka koodu niile.

{
  "success": false,
  "request_id": "p3lk4",
  "error": {
    "code": "payments_not_connected",
    "message": "The business has not connected Stripe or PayPal (or the way of paying is not offered).",
    "how_to_fix": "The account owner connects a provider on the dashboard (Book-and-Pay > Payments) and chooses the methods.",
    "documentation_url": "https://www.app2email.com/docs/api/errors#payments_not_connected",
    "is_retriable": false
  }
}
KooduMgbe ọ na-emeIhe a ga-eme
401 missing_api_keyEnweghị igodo API ezipuruZipu Authorization: Bearer YOUR_API_KEY
403 insufficient_scopeIgodo enweghị ikike (details.required_scope)Jiri igodo nwere bookings:manage (ma ọ bụ messages:read maka ịgụ)
403 sandbox_keyỊrịọ ịkwụ ụgwọ, ịkwụghachi ego ma ọ bụ ịdekọ ịkwụ ụgwọ site na igodo sandboxJiri igodo nkịtị (nke enweghị akara sandbox)
403 plan_not_allowedAtụmatụ nọmba ahụ enweghị APIHọrọ atụmatụ akwụghachi ụgwọ na peeji billing
403 service_not_liveỌrụ akwụsịrị, kagburu ya ma ọ bụ akwụghị ụgwọLelee ọrụ na atụmatụ na dashboard
403 booking_not_enabledBook-and-Pay edozighị maka nọmba a kaDozie Book-and-Pay na dashboard, ma ọ bụ kpọtụrụ support@app2email.com yana request_id
409 payments_not_connectedEnweghị akaụntụ Stripe ma ọ bụ PayPal ejikọtara, ma ọ bụ ụzọ ịkwụ ụgwọ ahụ enyeghịJikọta onye na-enye ọrụ na peeji Book-and-Pay, Payments, wee họrọ usoro ndị ahụ
400 invalid_paymentamount efuru ma ọ bụ abụghị karịa 0, ma ọ bụ booking enweghị ego iji kpọọ dị ka akwụrụDozie ubi a kpọtụrụ n'ozi ahụ
400 invalid_numbercontact abụghị nọmba ekwentị zuru okeKoodu mba mbụ, naanị ọnụọgụ, dịka ọmụmaatụ 61412345678
404 booking_not_foundbooking_id (ma ọ bụ booking nke ụzọ ahụ) abụghị booking nke nọmba aJiri id booking ma ọ bụ ntụaka BK- ya
404 payment_not_foundEnweghị ịkwụ ụgwọ nwere id ahụ na nọmba aGET /payments na-edepụta ịkwụ ụgwọ yana id ha
409 refund_not_possibleAkwụghị ya, akwughachiri ya, ma ọ bụ ihe fọdụrụ dị nta karịa ihe ị rịọrọGET /payments/{id} na-egosi ọnọdụ na ihe e kwụghachiri
502 payment_provider_errorStripe ma ọ bụ PayPal jụrụ arịrịọ ahụ ma ọ bụ enweghị ike ịnweta yaGụọ ozi onye na-enye ọrụ n'njehie ahụ; nwaa ọzọ ma ọ bụ lelee akaụntụ ahụ n'ebe onye na-enye ọrụ ahụ nọ
422 idempotency_key_reusedIdempotency-Key otu, body dị icheJiri igodo ọhụrụ maka arịrịọ dị iche, ma ọ bụ zipu body mbụ ọzọ
409 idempotency_request_in_progressArịrịọ mbụ yana igodo a ka na-agaChere, wee nwaa ọzọ yana otu igodo
400 invalid_cursorA gbanwere cursor nke GET /paymentsZipu next_cursor nke azịza gara aga ka ọ dị otu ahụ
429 rate_limitedOku ndị dị oke maka igodo aChere sekọnd Retry-After, wee nwaa ọzọ

Nduzi how-to ndị ọzọ

Nduzi how-to niile