# Jaib / جيب

Method ID: `14`. Payment type: `4`. Source reviewed: 2026-10-24. This is an archived-code contract, not a live-provider certification. Examples are illustrative partial schemas; placeholder values are not credentials or captured transactions.

## URLs

Base selector: `ApiJaibWalletUrl`.

Active source fallback: `https://www.w-jaib.com:4075/`.

Active fallback labelled live; api2.e-jaib.com:5088 is a commented test alternative.

Most legacy base constants are wrapped in `if (!defined(...))`; an earlier bootstrap definition can override the fallback. Hard-coded full-URL exceptions are called out above. Merchant JSON is not automatically a base-URL override.

| Operation | HTTP method | Full URL | Use |
| --- | --- | --- | --- |
| Login | POST | `https://www.w-jaib.com:4075/api/v1/TokenAuth/LoginPay` | Merchant login. |
| Purchase | POST | `https://www.w-jaib.com:4075/api/v1/BuyOnline/ExeBuy` | Direct purchase with voucher. |
| Progress | POST | `https://www.w-jaib.com:4075/api/v1/BuyOnline/CheckProgress` | Status helper. |
| Refund | POST | `https://www.w-jaib.com:4075/api/v1/BuyOnline/RefoundBuy` | Spelling is RefoundBuy in the archive. |


## Configuration fields

| Field / source setting | Meaning |
| --- | --- |
| AccountUserId | Merchant/agent/client identifier where used; stored in ElectronicPaymentAccountApiInfo. |
| AccountUserName | Merchant login/account name; not the customer phone unless the provider contract specifically uses it. |
| AccountUserPassword | Merchant password/short code; keep server-side. |
| pinApi | Payment API PIN read from authentication metadata or ElectronicPaymentAccountApiInfo; passed in purchase requests. |
| JaibWalletAccountPaymentSecretKey / JaibWalletAccountcertificatePassword | Server cryptographic/certificate helper defaults, where the selected transport path uses them. |


Configuration location: merchant row `platform_payment_ways.ElectronicPaymentAccountApiInfo`, plus named server constants/transport files where stated. Common listing fields (`type`, titles, descriptions, icon, account_number, order_view, status, active) are documented in [00-common-contract.md](00-common-contract.md).

Authentication/transport: Login sends userName, password and agentCode. It returns result.accessToken and result.expire; authenticated purchase calls additionally carry pinApi.

## Customer and server inputs

| Field | Requirement | Meaning |
| --- | --- | --- |
| payment_account_id | Required | Customer mobile. |
| voucher | Required | Customer purchase code; sent as code in ExeBuy. |


## Payment flow

1. Require customer mobile and purchase voucher, then login the merchant.
2. Execute ExeBuy using saved merchant token/pinApi, requestID, code, amount, currencyID and mobile.
3. Require a successful response with nonempty result.requestID and result.referenceID. Successful direct execution sets payment_status=3.
4. CheckProgress/RefoundBuy are helper operations. A separate SendPaymentConfirm branch in the adapter has no active URL assignment; it is not the normal direct-purchase flow.

## Provider requests

### Login

```json
{
  "userName": "<MERCHANT_USERNAME>",
  "password": "<MERCHANT_PASSWORD>",
  "agentCode": "<MERCHANT_AGENT_CODE>"
}
```

### Purchase

```json
{
  "pinApi": "<MERCHANT_API_PIN>",
  "requestID": "<ORDER_REFERENCE>",
  "code": "<CUSTOMER_PURCHASE_VOUCHER>",
  "amount": 1000,
  "currencyID": 1,
  "mobile": "<CUSTOMER_MOBILE>",
  "notes": "فاتورة مشتريات"
}
```

The examples show fields used by the archived adapter. Additional transport headers, derived identifiers and conditional helper-operation fields must be read with the source evidence below. Secrets and calculated security values are supplied/generated server-side.

## Provider responses and success rules

### Login — consumed fields

```json
{
  "success": true,
  "result": {
    "accessToken": "<ACCESS_TOKEN>",
    "expire": 3600
  },
  "error": null
}
```

### Purchase/status/refund — consumed fields

```json
{
  "success": true,
  "result": {
    "requestID": "<REQUEST_ID>",
    "referenceID": "<PROVIDER_REFERENCE>",
    "msg": "<PROVIDER_MESSAGE>"
  },
  "error": null
}
```

### Provider failure — consumed fields

```json
{
  "success": false,
  "result": null,
  "error": {
    "code": "<PROVIDER_ERROR_CODE>",
    "message": "<PROVIDER_ERROR_MESSAGE>"
  }
}
```

- success must be true and result nonempty. Login requires result.accessToken. Purchase/status/refund require both requestID and referenceID.
- The wrapper normalizes requestID and referenceID into request/transaction identifiers and retains provider error.code/error.message.

## Adapter result returned to the application layer

```json
{
  "error": false,
  "TimeOut": false,
  "Message": "<NORMALIZED_MESSAGE>",
  "Response": {
    "<provider-fields>": "<RAW_PROVIDER_RESPONSE>"
  }
}
```

This is a representative partial adapter result, not the public Flutter response. Keys are conditional and provider-specific. `error=true` or `TimeOut=true` prevents treating an initiation/confirmation as successful; transport errors can return before all keys exist. RequestType, saved references, token/cache metadata and provider-specific values may also be present. Raw merchant credentials/request logs must not be included in a customer-facing response.

## Application API requests and responses

The archived Flutter default for `APP_API_BASE` is **`https://platformdgtl.com/yemensnackfood/connect/v1/`**, set in Remote Config defaults. Fetched Remote Config can override it; this is a source default, not a verified live deployment. Trim the trailing slash when combining it with the paths below. Source: [lib/src/controllers/splash_controller.dart:234](</Users/ayman/Documents/Old Mac Data/flutter_projects/platform/yemen_snack_food/lib/src/controllers/splash_controller.dart:234>).

`APP_API_BASE` is supplied by Firebase Remote Config key `api_url` in the archived Flutter app. The resolved deployment value is not present in the reviewed source; use that runtime value rather than inventing a host. These paths belong to Yemen Snack Food, not Sharqiah v1 driver APIs.

Create: `POST {APP_API_BASE}/orders.php?action=add_order`, using multipart form data. The JSON below is a readable representation of those form fields; `items` is JSON-encoded text. The server calculates the amount.

```json
{
  "address_id": "<OWNED_ADDRESS_ID>",
  "delivery_time": "<DELIVERY_OPTION>",
  "items": "[{\"id\":1,\"quantity\":1}]",
  "payment_id": 14,
  "payment_account_id": "<CUSTOMER_WALLET_OR_MOBILE>",
  "voucher": "<CUSTOMER_PURCHASE_CODE>"
}
```

Change method/details: `POST {APP_API_BASE}/orders.php?action=add_payment_info`, with `order_id`, `payment_id` and the relevant customer fields above. Changes are limited to early eligible orders and unconfirmed payment state; confirmation independently rejects ineligible/already-confirmed orders.

A generic code-confirm endpoint exists, but the normal direct checkout for this method completes payment without an additional OTP call.

Illustrative **partial** create response (business success, not proof of settlement):

```json
{
  "status": 0,
  "message": "<APPLICATION_MESSAGE>",
  "result": {
    "order_id": 123,
    "order_payment_id": 14,
    "order_payment_type": 4,
    "order_payment_status": 3
  }
}
```

Expected confirmed order state: `order_payment_status=3`. The confirm endpoint may return a message without an order object; Flutter reloads the order.

Business failure shape, illustrative and partial:

```json
{
  "status": 1,
  "message": "<VALIDATION_OR_PROVIDER_ERROR_MESSAGE>"
}
```

See [the common contract](00-common-contract.md) for auth, status meanings, shared fields and response-layer differences.


## Persistence, cancellation and implementation limits

Payment initiation uses `platform_orders_temporary_storage` and electronic-payment temporary metadata. Later operations load saved transaction references from electronic-payment metadata. The archive also uses filesystem caches; these are implementation details, not proof of atomicity or idempotency.

- Checkout already requires the purchase voucher; this is not a generic phone-then-OTP-only method.
- The presence of RefoundBuy does not prove automatic cancellation refunds.

## Source evidence

- pinApi precedence: [functions/FunctionsPaymentJaibWalletAcount.php:2867](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentJaibWalletAcount.php:2867>)

- Endpoints: [functions/FunctionsPaymentJaibWalletAcount.php:4813](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentJaibWalletAcount.php:4813>)

- Purchase fields: [functions/FunctionsPaymentJaibWalletAcount.php:5546](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentJaibWalletAcount.php:5546>)

- Response success checks: [functions/FunctionsPaymentJaibWalletAcount.php:8974](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentJaibWalletAcount.php:8974>)

- URL assignment: [functions/FunctionsPaymentJaibWalletAcount.php:4715](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentJaibWalletAcount.php:4715>)

- URL assignment: [functions/FunctionsPaymentJaibWalletAcount.php:4820](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentJaibWalletAcount.php:4820>)

- URL assignment: [functions/FunctionsPaymentJaibWalletAcount.php:4828](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentJaibWalletAcount.php:4828>)

- URL assignment: [functions/FunctionsPaymentJaibWalletAcount.php:4837](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentJaibWalletAcount.php:4837>)

- URL assignment: [functions/FunctionsPaymentJaibWalletAcount.php:4845](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentJaibWalletAcount.php:4845>)

- URL assignment: [functions/FunctionsPaymentJaibWalletAcount.php:4853](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentJaibWalletAcount.php:4853>)

- Checkout dispatch: [connect/v1/OrderManagementPaymentWaysElectronic/AddOrder-PaymentSendInset.php:5455](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/connect/v1/OrderManagementPaymentWaysElectronic/AddOrder-PaymentSendInset.php:5455>)

- Customer validation/configuration gate: [connect/v1/contains-orders/add_order.php:926](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/connect/v1/contains-orders/add_order.php:926>)

- Flutter field selection: [lib/src/view/components/form_fields/payment_form_fields.dart:65](</Users/ayman/Documents/Old Mac Data/flutter_projects/platform/yemen_snack_food/lib/src/view/components/form_fields/payment_form_fields.dart:65>)
