Skip to main content

Overview

Moyasar integration in Flexprice syncs invoices to Moyasar and generates a payment link (Moyasar invoice URL) for each synced invoice.

Synchronization Flow

The sync process is one-way (Flexprice → Moyasar) and works as follows:

How it Works

1

Trigger

An invoice sync is triggered (automatically).
2

Creation

Flexprice creates an invoice object in Moyasar using the secret_key.
3

Link Generation

Moyasar returns a url (the payment page).
4

Metadata Update

Flexprice saves the Moyasar invoice ID and payment URL in the invoice metadata.

Invoice Data Model

Flexprice Invoice Structure

{
  "id": "inv_123",
  "amount": "100.00",
  "currency": "SAR",
  "metadata": {
    "moyasar_invoice_id": "inv_moy_xyz",
    "moyasar_invoice_url": "https://moyasar.com/i/inv_moy_xyz"
  }
}

Moyasar Invoice Structure

{
  "id": "inv_moy_xyz",
  "status": "initiated",
  "amount": 10000,
  "currency": "SAR",
  "description": "Invoice for Premium Plan",
  "url": "https://moyasar.com/i/inv_moy_xyz",
  "metadata": {
    "flexprice_invoice_id": "inv_123"
  }
}

Sync Configuration

The following fields are mapped during sync:
FieldFlexprice → MoyasarNotes
amountConverted to smallest unit (e.g., Halalah)
currencyPassed as-is (e.g., SAR)
descriptionSummary of line items
metadataIncludes flexprice_invoice_id for tracking

Payment Flow & Webhooks

Payment Journey

1

User pays

User clicks the moyasar_invoice_url.
2

Processing

Payment is processed on Moyasar’s hosted page.
3

Webhook

Moyasar sends a payment_paid webhook.
4

Reconciliation

Flexprice receives the webhook, finds the invoice via the metadata/mapping, and updates the invoice status to PAID.

Error Handling

ErrorCause
Moyasar connection not configuredNo active Moyasar connection found for the tenant/env.
Currency not supportedInvoice currency (e.g., INR) not supported by your Moyasar account.
Invalid amountAmount must be positive.

Testing

1

Create invoice

Create a Flexprice invoice.
2

Trigger sync (Automatically)

Trigger the sync to Moyasar.
3

Check metadata

Check invoice metadata for moyasar_invoice_url.
4

Test payment

Open the URL and pay using a Test Card.

Test Cards (Moyasar Sandbox)

NumberExpiryCVCResult
4111 1111 1111 1111Future123Success
4000 0000 0000 0002Future123Failure