π SarfSDK Integration Guide
This guide explains how to integrate SarfSDK into your Laravel (or any web) project.
1. Introduction
SarfSDK is part of the Sarf application, a digital platform that helps users track budgets, monitor daily expenses, and maintain financial records.
By integrating this SDK, your system can send invoices directly to Sarf users, eliminating manual entry and enabling real-time expense tracking.
2. How to Include
<script src="https://sarf.sa/project/sdk/sarf-sdk.js"></script>
<script>
SarfSDK({
key: "YOUR_PUBLIC_KEY",
container: "sarf-sdk",
userid: "9665XXXXXXXX",
invoiceTotal: "total",
customer_mobile: "customer_mobile",
description: "description",
attachments: "attachments",
language: "en" // or "ar"
});
</script>
3. Configuration Options
| Option | Type | Required | Description |
|---|---|---|---|
key | String | β Yes | Your Sarf public API key. |
container | String | β Yes | Element ID where SDK will render. |
userid | String | β Yes | Userβs mobile number (9665XXXXXXXX). |
invoiceTotal | String | β No | Input ID for invoice total. |
customer_mobile | String | β No | Input ID for customerβs mobile number. |
description | String | β No | Input ID for invoice description. |
attachments | String | β No | File input ID for invoice attachments. |
isModal | Boolean | β No | Whether to use modal form (default: true). |
register_div | String | β No | Element ID where register button appears. |
invoice_btn_type | "button" / "submit" | β No | Button type for invoice submission. |
registration_btn_type | "button" / "submit" | β No | Button type for registration. |
language | "en" or "ar" | β No | Interface language (default: "ar"). |
4. Workflow
- SDK initializes and validates your public key.
- Calls
/api/check-userto verify the userid. - If user exists β shows Send Invoice button.
- If not β shows Register with Sarf button.
- If customer_mobile + invoiceTotal are present β invoice auto-generated.
- Otherwise β modal form appears for manual input.
5. Examples
Example 1: Show Only Buttons
<div id="sarf-sdk"></div>
<script>
SarfSDK({
key: "MY_PUBLIC_KEY",
container: "sarf-sdk",
userid: "966500123456",
language: "en"
});
</script>
Example 2: Auto-send Invoice
<input type="text" id="customer_mobile" value="966500987654" />
<input type="text" id="total" value="150.75" />
<input type="text" id="description" value="Order #1234" />
<input type="file" id="attachments" multiple />
<div id="sarf-sdk"></div>
<script>
SarfSDK({
key: "MY_PUBLIC_KEY",
container: "sarf-sdk",
userid: "966500123456",
invoiceTotal: "total",
customer_mobile: "customer_mobile",
description: "description",
attachments: "attachments",
language: "en"
});
</script>
6. API Endpoints Used
/api/validate-keyβ Validate key/api/check-userβ Check user registration/api/user/listβ Search customers/api/generate_simple_invoiceβ Generate invoice
7. Error Handling
- Empty fields β Invoice not generated.
- Invalid files β Attachments rejected.
- Invalid/expired key β Auth error.
- Network issues β Console + alert message.