# CashPay / محفظة كاش — Al-Nasser

Method ID: `9`. 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: `ApiCashPayUrl`.

Active source fallback: `https://www.tamkeen.com.ye:61890/CashPay/`.

This is the active fallback. The older tamkeenye.com:33291/CashPG definition is inside a block comment. RunTestApiCashPayUrl defaults TRUE but is a separate flag; do not infer the base host from the flag name.

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 |
| --- | --- | --- | --- |
| Initiate | POST | `https://www.tamkeen.com.ye:61890/CashPay/api/CashPay/InitPayment` | Active initial payment. |
| Confirm | POST | `https://www.tamkeen.com.ye:61890/CashPay/api/CashPay/ConfirmPayment` | Active separate confirmation. |
| Status | POST | `https://www.tamkeen.com.ye:61890/CashPay/api/Operation/OperationStatus` | Status helper. |
| Change merchant password helper | POST | `https://www.tamkeen.com.ye:61890/CashPay/api/Operation/ChangePass` | Administrative helper; not customer checkout. |


## 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. |
| AccountPaymentSecretKey | Optional JSON override read by the wrapper; otherwise CashPayAccountPaymentSecretKey server constant. |
| CashPayAccountcertificatePassword | Server certificate password constant; actual value omitted. |
| CertificatePath / P12 transport setup | Provider-issued certificate path and certificate type are configured in the certificate transport branch. These are server deployment settings, not customer inputs. |


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: JSON request includes UserName, SpId, MDToken and RequestID. Password security is generated using CreateCashPayPaymentSecuredEncryptKey and the configured secret; inspect header evidence for the provider security headers. Certificate transport is supported. Security headers are encPassword: <CreateCashPayPaymentSecuredEncryptKey output> and unixtimestamp: <request timestamp>, with Accept: application/json and Content-Type: application/json in the secured transport branch. Keep the timestamp/security calculation aligned with the request; do not send the raw merchant password in encPassword.

## Customer and server inputs

| Field | Requirement | Meaning |
| --- | --- | --- |
| payment_account_id | Required | Customer TargetMSISDN; Flutter requires 9 characters. |
| voucher | Required | Customer purchase code; mapped to CustomerCashPayCode. |
| code | Required at confirmation | OTP used to generate TRCode against the saved TransactionRef. |


## Payment flow

1. Require customer wallet/mobile plus purchase voucher; authenticate/provision merchant credentials.
2. Build RequestID and MDToken; POST InitPayment with TargetMSISDN, CustomerCashPayCode and amount. Save TransactionRef/RequestId and set payment_status=2.
3. Flutter asks for the subsequent code. Generate TRCode=md5(TransactionRef + confirmation code) and POST ConfirmPayment.
4. Confirm status 3 on successful adapter result. The extra confirmation request inside the creation dispatcher is behind DoSendTestPaymentConfirmRequest=FALSE; its presence does not mean checkout normally executes it.

## Provider requests

### Initiate

```json
{
  "UserName": "<MERCHANT_USERNAME>",
  "SpId": "<SERVICE_PROVIDER_ID>",
  "MDToken": "<GENERATED_MD5>",
  "RequestID": "<GENERATED_REQUEST_ID>",
  "TargetMSISDN": "<CUSTOMER_MOBILE>",
  "CustomerCashPayCode": "<CUSTOMER_VOUCHER>",
  "Amount": 1000,
  "currencyID": 2,
  "Desc": "فاتورة مشتريات"
}
```

### Confirm — fields in addition to shared merchant fields

```json
{
  "TransactionRef": "<SAVED_TRANSACTION_REF>",
  "TRCode": "<MD5_TRANSACTION_REF_PLUS_OTP>"
}
```

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

### Provider payment response — consumed fields

```json
{
  "ResultCode": "1",
  "ResultMessage": "<PROVIDER_MESSAGE>",
  "TransactionRef": "<TRANSACTION_REFERENCE>",
  "RequestId": "<REQUEST_ID>"
}
```

- A non-null ResultCode other than "1" marks an error. InitPayment additionally requires nonempty TransactionRef.
- Normalized values include RequestTransactionId/TransactionRef where mapped, RequestOrderID, Message, error and raw Response. Preserve spelling/case from wire evidence; RequestId and RequestID are not interchangeable assumptions.

## 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": 9,
  "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.

Confirm: `POST {APP_API_BASE}/orders.php?action=SendConfirmPayment` with form fields:

```json
{
  "order_id": "<ORDER_ID>",
  "code": "<CUSTOMER_OTP>"
}
```

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

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

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.

- Do not treat disabled checkout status/confirmation test branches as the live flow.
- Certificate files and their passphrases must be provisioned separately; this documentation contains no key material.

## Source evidence

- Secret precedence: [functions/FunctionsPaymentCashPayAcount.php:2439](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentCashPayAcount.php:2439>)

- Request fields: [functions/FunctionsPaymentCashPayAcount.php:4018](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentCashPayAcount.php:4018>)

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

- Response parsing: [functions/FunctionsPaymentCashPayAcount.php:6329](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentCashPayAcount.php:6329>)

- Secured transport headers: [functions/FunctionsPaymentCashPayAcount.php:4821](</Users/ayman/Documents/Old Mac Data/Downloads/yemensnackfood/functions/FunctionsPaymentCashPayAcount.php:4821>)

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

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

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

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

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

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

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

- 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>)
