Buy SMS

API reference

Buy SMS from your site

Your server calls Taysend with the same Bearer key you use to send. The key identifies the wallet. The person at the shop never signs in to Taysend. Keep the key on the server. The browser only opens the checkout URL.

GET /v1/billing
curl https://api.taysend.com/v1/billing \
  -H "Authorization: Bearer $TAYSEND_KEY"

The response includes sms_left and the published packages (id, amount, sms).

Start a payment

POST /v1/billing/checkout with a package_id, the page on your site to return to, and the email of the person paying. That email is only for the payment page. The API key still names the wallet.

POST /v1/billing/checkout
curl -X POST https://api.taysend.com/v1/billing/checkout \
  -H "Authorization: Bearer $TAYSEND_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "package_id": "ghs-20",
    "email": "[email protected]",
    "success_url": "https://yourshop.com/sms/thanks"
  }'

Redirect the browser to checkout_url. After payment, GET /v1/billing/checkout/:id with the same key. status succeeded means the SMS are on the wallet. sms on that response is how many were added.

The button

Your page asks your server for the balance. Your server asks Taysend. The button posts the chosen package to your server, which returns the checkout URL.

your shop server
app.get("/sms-wallet", async (_req, res) => {
  const wallet = await fetch("https://api.taysend.com/v1/billing", {
    headers: { Authorization: "Bearer " + process.env.TAYSEND_KEY },
  }).then((r) => r.json());
  res.json({ sms_left: wallet.sms_left, packages: wallet.packages });
});

app.post("/sms-wallet/buy", async (req, res) => {
  const checkout = await fetch("https://api.taysend.com/v1/billing/checkout", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.TAYSEND_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      package_id: req.body.package_id,
      email: req.body.email,
      success_url: "https://yourshop.com/sms/thanks",
    }),
  }).then((r) => r.json());
  res.json({ checkout_url: checkout.checkout_url });
});