# Quickstart This guide takes you from onboarding credentials to your first collection in the sandbox. ## 1. Get your credentials During onboarding GoDigital gives you: - **Client ID** and **Client Secret** for OAuth2 - Your **Merchant ID** - Whitelisting of your server's **public IP address** :::note All API calls, including the token endpoint, are rejected from IP addresses that are not whitelisted (`PGW-1009`). ::: ## 2. Request an access token ```bash curl -X POST https://api-sandbox.godigital.tz/api/v1/oauth/token \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET" ``` ```json { "access_token": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ...", "token_type": "Bearer", "expires_in": 3600, "scope": "payments:read payments:write" } ``` Cache the token and refresh it shortly before `expires_in` runs out. ## 3. Build the security headers Every payment request needs these headers. See [Authentication](/authentication) for details. ```js title="headers.js" import crypto from "node:crypto"; export function godigitalHeaders({ token, clientId, body = "" }) { return { "Authorization": `Bearer ${token}`, "Content-Type": "application/json", "X-Client-Id": clientId, "X-Request-Id": crypto.randomUUID(), "X-Idempotency-Key": crypto.randomUUID(), "X-Timestamp": Math.floor(Date.now() / 1000).toString(), "X-Nonce": crypto.randomBytes(16).toString("hex"), "X-Content-SHA256": crypto.createHash("sha256").update(body).digest("base64"), }; } ``` ## 4. Send a C2B push collection ```js title="collect.js" import crypto from "node:crypto"; import { godigitalHeaders } from "./headers.js"; const body = JSON.stringify({ requestId: crypto.randomUUID(), merchantId: process.env.MERCHANT_ID, providerCode: "VODACOM", amount: 10000.0, currency: "TZS", msisdn: "255754123456", reference: "INV-1001", callbackUrl: "https://merchant.example.com/api/payment-result", narration: "Invoice INV-1001", }); const res = await fetch( "https://api-sandbox.godigital.tz/api/v1/payments/collections/push", { method: "POST", headers: godigitalHeaders({ token: process.env.GD_TOKEN, clientId: process.env.CLIENT_ID, body, }), body, // send exactly the string you hashed }, ); console.log(await res.json()); // data.transactionStatus: "ROUTED" ``` :::caution Hash and send the **exact same string**. If you re-serialize the JSON after hashing, the `X-Content-SHA256` value will not match. ::: ## 5. Receive the result The customer approves the prompt on their phone. GoDigital then sends the final result to your `callbackUrl`. Reply with HTTP `200` quickly. See [Callbacks](/callbacks). If no callback arrives, query the status: ```bash curl https://api-sandbox.godigital.tz/api/v1/payments/INV-1001 \ -H "Authorization: Bearer $TOKEN" \ -H "X-Client-Id: $CLIENT_ID" ... ``` ## Next steps - Try every endpoint from the browser: [Sandbox Credentials](/sandbox) - Understand [transaction states](/transaction-states) and [idempotency](/idempotency) - Prepare for production with the [operational notes](/operational-notes)