πŸ“˜ SarfSDK Integration Guide

This guide explains how to integrate SarfSDK into your Laravel (or any web) project.

⬇ Download Documentation

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
keyStringβœ… YesYour Sarf public API key.
containerStringβœ… YesElement ID where SDK will render.
useridStringβœ… YesUser’s mobile number (9665XXXXXXXX).
invoiceTotalString❌ NoInput ID for invoice total.
customer_mobileString❌ NoInput ID for customer’s mobile number.
descriptionString❌ NoInput ID for invoice description.
attachmentsString❌ NoFile input ID for invoice attachments.
isModalBoolean❌ NoWhether to use modal form (default: true).
register_divString❌ NoElement ID where register button appears.
invoice_btn_type"button" / "submit"❌ NoButton type for invoice submission.
registration_btn_type"button" / "submit"❌ NoButton type for registration.
language"en" or "ar"❌ NoInterface language (default: "ar").

4. Workflow

  1. SDK initializes and validates your public key.
  2. Calls /api/check-user to verify the userid.
  3. If user exists β†’ shows Send Invoice button.
  4. If not β†’ shows Register with Sarf button.
  5. If customer_mobile + invoiceTotal are present β†’ invoice auto-generated.
  6. 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.