---
tags: [vompay, service]
module: VomPay
---

# [Service]InvoiceServices

## Connections
[[_VomPay]] · [[[Model]Models]] · [[[Action]Actions]] · [[[Repo]Repositories]] · [[[Enum]Enums]] · [[[Job]Jobs]] · [[[Cross]CrossModuleDependencies]]

## Source
`Modules/VomPay/Services/Invoices/`

---

## VomPayInvoiceService

Orchestrates payment link creation and retrieval.

**Dependencies:** `VomPayInvoiceRepository` · `PreparingCurrentSubscriptionDataService` · `GeneratingPaymentLinkAction` · `VomPaySupplierRepository` · `RetrievingTenantBySubdomainService`  
**Traits:** `TenantConnectionOnRuntime`

| Method | Purpose |
|---|---|
| createPaymentLink($subdomain, $paiableType, $paiableId, $amount, $customerId) | Validates package support → calls `GeneratingPaymentLinkAction` → creates `VomPayInvoice` DB row |
| getMyPhatoorahLink($subdomain, $paiableType, $paiableId) | Returns payment URL, or error URL if: supplier inactive (code 3), invoice already paid (code 2), general error (code 1) |
| createVomPayInvoiceInDB() | Persists `VomPayInvoice` with MyFatoorah response data |

Error URLs read from `config('vompay.*')`.

---

## Webhook Status Handlers (`WebHookStatusServices/`)

Dispatched by `VomPayInvoiceStatusService` via `VomPayWebHookEventsEnum::HANDLE_SUCCESS_STATUS_SERVICES`.

---

### VomPayInvoiceStatusService

Main webhook router for `TransactionsStatusChanged` events.

**Dependencies:** `VomPayInvoiceRepository` · `RetrievingTenantBySubdomainService` · `VomPaySettingRepository`  
**Traits:** `TenantConnectionOnRuntime`

**Flow:**
```
execute($request)
  → extractData()  — parses CustomerReference: "{type}_{subdomain}_{id}"
  → connectToDB($subdomain)
  → if SUCCESS and not already paid:
      handleSuccessStatus() → routes to handler via VomPayWebHookEventsEnum
  → updateInvoiceByWebHookData() — status, payment_method, payment_id
  → logs non-SUCCESS statuses
```

`isInvoicePayedBefore()` — prevents double-processing on duplicate webhooks.

---

### VomPayStatusHandlerForInvoiceService

Handles successful payment on a Sales Invoice.

**Dependencies:** `CreatingJournalEntryAfterPayingService` · `CreatingCustomerReceiptAfterPayingService` · `InvoicesRepository`

```
execute($requestData, $settings, $paiableId, $packageId)
  → if apply_on_customer_receipt disabled → return early
  → getAmountData()  — calculates fees (15% VAT on commission) + actual price
  → CreatingJournalEntryAfterPayingService (SALES_RECEIPTS type)
  → CreatingCustomerReceiptAfterPayingService
  → Invoice.paid_amount updated
```

Commission from `VomPayPackagesEnum::METHODS` by package + payment method.

---

### VomPayStatusHandlerForDebitNoteService

Handles successful payment on a Debit Note (same flow as invoice but no VAT on fees).

**Dependencies:** `CreatingJournalEntryAfterPayingService` · `CreatingCustomerReceiptAfterPayingService`

Uses `VomPayPackagesEnum::COMMISSIONS_BY_METHODS_NAMES` keyed by payment method name.

---

### VomPayStatusHandlerForProformaService

⚠️ Not yet implemented. All logic is TODO comments.  
Intended to optionally auto-convert Proforma → Invoice on payment, then create JE + receipt.

---

### VomPayBalanceTransferredService

No-op handler for `BalanceTransferred` webhook events. Always returns `false`.  
Exists to suppress errors from unexpected MyFatoorah webhook calls.
