PHPackages                             orangecat/module-company-credit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. orangecat/module-company-credit

ActiveMagento2-module[Payment Processing](/categories/payments)

orangecat/module-company-credit
===============================

Company credit payment method and balance management for Magento 2 B2B — credit limits, ledger tracking, and automatic refund handling

0.0.2(2d ago)02↑2900%OSL-3.0PHPPHP &gt;=8.2

Since Jun 5Pushed 2d agoCompare

[ Source](https://github.com/olivertar/m2_companycredit)[ Packagist](https://packagist.org/packages/orangecat/module-company-credit)[ RSS](/packages/orangecat-module-company-credit/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Orangecat\_CompanyCredit
========================

[](#orangecat_companycredit)

B2B company credit payment method and balance management for Magento 2. Assigns configurable credit limits per company, tracks usage via an immutable ledger, and exposes balance information to both store admins and company admins on the frontend.

**Module:** `Orangecat_CompanyCredit`**Version:** 1.0.0 **License:** OSL-3.0 **Author:** Oliverio Gombert

---

Table of Contents
-----------------

[](#table-of-contents)

1. [Overview](#overview)
2. [Theme Compatibility](#theme-compatibility)
3. [Requirements](#requirements)
4. [Installation](#installation)
5. [What Gets Installed](#what-gets-installed)
6. [Credit Balance Semantics](#credit-balance-semantics)
7. [Configuration Reference](#configuration-reference)
8. [Store Admin Guide](#store-admin-guide)
9. [Company Admin Guide (Frontend)](#company-admin-guide-frontend)
10. [Developer Guide](#developer-guide)
11. [REST API](#rest-api)
12. [Frontend Routes Reference](#frontend-routes-reference)
13. [DevOps &amp; Integrator Notes](#devops--integrator-notes)

---

Overview
--------

[](#overview)

`Orangecat_CompanyCredit` extends `Orangecat_Company` with a credit-based payment system. Companies receive a configurable credit line; purchases consume credit, cancellations and credit memos restore it, and every transaction is logged in an auditable ledger.

The module handles:

- Offline checkout payment method (`companycredit`) restricted to company customers
- Per-company credit limit, currency, and exceed-limit toggle
- Immutable transaction ledger with automatic debit/credit on order events
- Admin UI for credit configuration and manual adjustments, embedded in the company edit form
- Frontend credit page for company admins (balance summary + transaction history)
- Full REST API for credit and ledger management

### Position in the Orangecat B2B Dependency Chain

[](#position-in-the-orangecat-b2b-dependency-chain)

```
Orangecat_Core (via composer: orangecat/core)
  └── Orangecat_Company
        └── Orangecat_CompanyCredit     ← this module

```

---

Theme Compatibility
-------------------

[](#theme-compatibility)

ThemeStatusNotes**Luma**SupportedStandard `.phtml` template. Less styles via `_module.less`.**Hyvä**SupportedDedicated `index_hyva.phtml` template with Tailwind CSS. Loaded via `hyva_*` layout handles.**Breeze Evolution**PartialNo dedicated Breeze templates. Falls back to Luma `index.phtml`. Checkout payment JS uses standard RequireJS (Breeze-compatible).For Breeze-specific overrides: create `view/frontend/templates/credit/index_breeze.phtml` and `view/frontend/layout/breeze_company_credit_index.xml` following Breeze conventions.

---

Requirements
------------

[](#requirements)

DependencyVersionPHP8.2+Magento2.4.x`Orangecat_Core`composer: `orangecat/core``Orangecat_Company`must be enabled`Magento_Sales`core`Magento_Payment`core---

Installation
------------

[](#installation)

Run inside the PHP container (`reward shell`):

```
bin/magento module:enable Orangecat_CompanyCredit
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:flush
```

---

What Gets Installed
-------------------

[](#what-gets-installed)

### Database Tables

[](#database-tables)

#### `mycompany_credit`

[](#mycompany_credit)

One record per company (1:1). Stores the credit configuration and running balance.

ColumnTypeNotes`entity_id`int, PKAuto-increment`company_id`int, UNIQUE FK→ `mycompany.entity_id` (CASCADE DELETE)`currency_code`varchar(3)ISO 4217, nullable`credit_limit`decimal(20,4)Default 0.0000`balance`decimal(20,4)Default 0.0000 — outstanding debt`allow_exceed_limit`smallint0 = no, 1 = yes#### `mycompany_credit_ledger`

[](#mycompany_credit_ledger)

Append-only audit log. One row per credit event.

ColumnTypeNotes`entity_id`int, PKAuto-increment`company_id`int, FK→ `mycompany.entity_id` (CASCADE DELETE)`amount`decimal(20,4)Negative = purchase/debit; positive = refund/credit`order_id`varchar(50)Order increment ID, nullable`comment`textNullable`created_at`timestampAuto CURRENT\_TIMESTAMPNo data patches, EAV attributes, or CMS pages are installed by this module.

---

Credit Balance Semantics
------------------------

[](#credit-balance-semantics)

Understanding the sign convention is critical:

ConceptColumnDirectionExample**Balance**`mycompany_credit.balance`Increases on purchase, decreases on refund$1,500 outstanding debt**Credit Limit**`mycompany_credit.credit_limit`Static ceiling$10,000**Available Credit**Computed: `limit − balance`Decreases on purchase$8,500**Ledger: purchase**`mycompany_credit_ledger.amount`Negative number−$1,500**Ledger: refund**`mycompany_credit_ledger.amount`Positive number+$500A company starts with `balance = 0` and `available = credit_limit`. Each purchase increases `balance`. Refunds and cancellations decrease `balance`.

---

Configuration Reference
-----------------------

[](#configuration-reference)

### Store Configuration — My Company &gt; Company Credit

[](#store-configuration--my-company--company-credit)

Path: **Stores → Configuration → My Company → Company Credit**

LabelConfig PathDefaultDescriptionEnable Company Credit`mycompany/company_credit/enabled`YesMaster switch. Disables the frontend menu link and the payment method.Refund Credit on Order Cancel`mycompany/company_credit/refund_on_cancel`YesAutomatically restore credit when a company credit order is cancelled.Refund Credit on Credit Memo`mycompany/company_credit/refund_on_creditmemo`YesAutomatically restore credit when a credit memo is issued.### Payment Methods — Company Credit

[](#payment-methods--company-credit)

Path: **Stores → Configuration → Sales → Payment Methods → Company Credit**

LabelConfig PathDefaultDescriptionEnabled`payment/companycredit/active`YesActivates the payment method entry. Still hidden if `mycompany/company_credit/enabled = No`.Title`payment/companycredit/title`Company CreditLabel shown at checkout.New Order Status`payment/companycredit/order_status`PendingStatus assigned to new orders placed with this method.Payment from Applicable Countries`payment/companycredit/allowspecific`All Allowed CountriesRestrict to specific countries if needed.Sort Order`payment/companycredit/sort_order`—Display order among payment methods.### Per-Company Credit Settings (Admin Company Form)

[](#per-company-credit-settings-admin-company-form)

These are stored in `mycompany_credit`, not `core_config_data`:

FieldDescriptionCurrency CodeCurrency for this company's credit line (must match store currency at checkout).Credit LimitMaximum credit amount the company can carry as outstanding balance.Allow Exceed LimitYes: company can place orders even if `order total > available credit`.---

Store Admin Guide
-----------------

[](#store-admin-guide)

### Accessing Credit Settings

[](#accessing-credit-settings)

1. Go to **Companies** (main menu) → open any company.
2. The **Company Credit** fieldset appears in the company edit form.

### Credit Fieldset

[](#credit-fieldset)

UI ElementPurposeOutstanding BalanceRead-only. Current used credit (`balance`).Available CreditRead-only. Computed: `credit_limit − balance`.Credit LimitEditable. Set the ceiling for this company.Currency CodeEditable. ISO 4217 code (e.g., `USD`, `EUR`).Allow Exceed LimitEditable. Yes/No toggle.Save the company form to persist changes. Credit data is saved via `CompanyRepositoryPlugin` after the main company save.

### Transaction Ledger Grid

[](#transaction-ledger-grid)

Below the credit fieldset, an embedded grid lists all ledger entries for the company:

ColumnDescriptionID`entity_id`AmountPositive = refund/credit; negative = purchase/debit.OrderRelated order increment ID (if applicable).CommentFree-text note.DateUTC timestamp.### Manual Refund / Adjustment

[](#manual-refund--adjustment)

1. Click **Refund** button in the credit fieldset.
2. A modal opens with three fields:
    - **Amount** (required, must be &gt; 0) — credit to restore.
    - **Order ID** (optional) — reference to a specific order.
    - **Comment** (required) — reason for adjustment.
3. Submit. The system creates a positive ledger entry and decreases `balance` accordingly.

To **edit** an existing manual entry (amount &gt; 0, no order ID), click the row action in the ledger grid. The modal reopens pre-populated; saving recalculates the balance delta.

---

Company Admin Guide (Frontend)
------------------------------

[](#company-admin-guide-frontend)

### Where to Find Credit Information

[](#where-to-find-credit-information)

After logging in, go to **My Account → Company Credit** (link in the account navigation sidebar).

Direct URL: `https:///company/credit/index`

### What You See

[](#what-you-see)

**Credit Summary** (three tiles at the top):

TileMeaningOutstanding BalanceHow much your company currently owes.Available CreditHow much you can still spend (`limit − outstanding`).Credit LimitMaximum credit your company has been granted.**Transaction History** table below the tiles:

ColumnMeaningDateWhen the transaction occurred.AmountPositive (green) = credit was restored. Negative (red) = credit was consumed.CommentDescription (order reference or admin note).The list is sorted newest-first. An empty-state message appears if no transactions exist yet.

### Paying with Company Credit at Checkout

[](#paying-with-company-credit-at-checkout)

If your company has available credit (or is allowed to exceed the limit), **Company Credit** appears as a payment option at checkout. Select it and place the order — no card or external payment is required. The amount is deducted from your available credit immediately upon order placement.

If the payment method is not visible, one of the following applies:

- The feature is disabled by the store admin.
- Your company has no credit configuration.
- The order currency does not match your company's credit currency.
- Your available credit is insufficient (and the store does not allow exceeding the limit).

---

Developer Guide
---------------

[](#developer-guide)

### Module Structure

[](#module-structure)

```
CompanyCredit/
├── Api/                         # Service contracts and data interfaces
├── Block/                       # View blocks (frontend credit page, admin fieldset, modal)
├── Controller/
│   ├── Credit/Index.php         # Frontend credit page
│   └── Adminhtml/Ledger/Save.php  # Admin manual refund save
├── Model/
│   ├── Credit.php               # Entity: mycompany_credit
│   ├── Ledger.php               # Entity: mycompany_credit_ledger
│   ├── CreditRepository.php
│   ├── LedgerRepository.php
│   ├── CreditManagement.php     # Service layer
│   └── Payment/CompanyCredit.php  # Payment method
├── Observer/                    # Three event observers (see below)
├── Plugin/                      # Two interceptors (see below)
├── Ui/Component/                # Admin grid data provider + actions column
└── view/
    ├── adminhtml/               # Admin templates, UI component XML, JS
    └── frontend/                # Luma and Hyvä templates, layouts, Less, CSS, JS

```

### Key Classes

[](#key-classes)

#### Service Layer

[](#service-layer)

**`Model/CreditManagement.php`** — implements `Api/CreditManagementInterface.php`. All business operations go through here:

MethodDescription`updateCredit(companyId, currencyCode, creditLimit, allowExceedLimit)`Upsert credit record. Only non-null parameters are updated.`getBalance(companyId)`Return `CreditInterface` with current state.`getLedgerByCompanyId(companyId)`Return ledger entries sorted by `created_at DESC`.`refund(companyId, amount, comment)`Create positive ledger entry, decrease balance. Validates `amount > 0`.`updateLedgerEntry(entryId, amount, comment)`Edit existing entry; recalculates balance delta.#### Payment Method

[](#payment-method)

**`Model/Payment/CompanyCredit.php`** — extends `Magento\Payment\Model\Method\AbstractMethod`. Payment code: `companycredit`.

`isAvailable(?CartInterface $quote)` returns `false` if any of these fail:

1. `mycompany/company_credit/enabled` is off.
2. Customer not logged in or not in a company.
3. No credit record for the company.
4. Currency code mismatch between quote and credit record.
5. `quote->getGrandTotal() > available credit` AND `allow_exceed_limit = 0`.

#### Observers

[](#observers)

ClassEventAction`Observer/OrderPlaceObserver``sales_model_service_quote_submit_success`Creates negative ledger entry; increases `balance`.`Observer/OrderCancelObserver``order_cancel_after`If `refund_on_cancel` enabled: finds original entry by order ID, creates positive entry, decreases `balance`.`Observer/CreditMemoRefundObserver``sales_order_creditmemo_save_after`If `refund_on_creditmemo` enabled: same logic as cancel observer but for credit memo amount.All observers are no-ops when the order's payment method is not `companycredit`.

#### Plugins

[](#plugins)

ClassTargetHookPurpose`Plugin/Api/CompanyRepositoryPlugin``Orangecat\Company\Api\CompanyRepositoryInterface``afterSave()`Reads `company_credit` POST data; upserts `mycompany_credit` record after company save.`Plugin/Ui/Component/Form/Company/DataProviderPlugin``Orangecat\Company\Ui\Component\Form\Company\DataProvider``afterGetData()`Injects `credit_limit`, `currency_code`, `allow_exceed_limit` into company form data from `mycompany_credit`.Both plugins are registered in `etc/adminhtml/di.xml` (admin area only).

### Frontend JS

[](#frontend-js)

FilePurpose`view/frontend/web/js/view/payment/companycredit.js`Registers `companycredit` renderer in Magento checkout JS.`view/frontend/web/js/view/payment/method-renderer/companycredit-method.js`Extends `Magento_Checkout/js/view/payment/default`.`view/frontend/web/template/payment/companycredit.html`Knockout template for the checkout payment step.### Admin JS

[](#admin-js)

FilePurpose`view/adminhtml/web/js/grid/columns/refund-actions.js`Extends `Magento_Ui/js/grid/columns/actions`. Manages modal open/close, pre-populates the refund form for edit mode, clears fields on new entry.### ACL Resources

[](#acl-resources)

Resource IDTitleLocation`Orangecat_CompanyCredit::credit`Company CreditUnder `Orangecat_Company::company_manage`### Adding Custom Logic

[](#adding-custom-logic)

**Before credit is deducted** — listen to `sales_model_service_quote_submit_success` (same event, earlier sort order) or create a plugin on `CreditManagement::updateCredit`.

**To extend the Credit or Ledger data objects** — add a new `preference` or extension attribute via `extension_attributes.xml` targeting `CreditInterface` / `LedgerInterface`.

**To add a column to the ledger grid** — extend `view/adminhtml/ui_component/mycompany_credit_ledger_listing.xml` via a module merge.

---

REST API
--------

[](#rest-api)

All endpoints require the `Orangecat_CompanyCredit::credit` ACL resource (admin token or integration token with that permission).

MethodEndpointDescriptionGET`/V1/mycompany/credit/:companyId`Get credit balance and configuration for a company.PUT`/V1/mycompany/credit/:companyId`Update credit limit, currency, or allow-exceed flag.GET`/V1/mycompany/credit/:companyId/ledger`Get all ledger entries for a company (newest first).POST`/V1/mycompany/credit/:companyId/refund`Create a manual credit refund entry.PUT`/V1/mycompany/credit/ledger/:entryId`Edit an existing ledger entry and recalculate balance.DELETE`/V1/mycompany/credit/ledger/:entityId`Delete a ledger entry by ID.### Examples

[](#examples)

```
# Get credit state for company 5
GET /rest/V1/mycompany/credit/5

# Set credit limit to $50,000 USD, disallow exceed
PUT /rest/V1/mycompany/credit/5
Content-Type: application/json
{
  "creditLimit": 50000,
  "currencyCode": "USD",
  "allowExceedLimit": 0
}

# Manual refund of $1,200
POST /rest/V1/mycompany/credit/5/refund
Content-Type: application/json
{
  "amount": 1200,
  "comment": "Goodwill adjustment — ticket #4412"
}

# Get ledger history
GET /rest/V1/mycompany/credit/5/ledger
```

---

Frontend Routes Reference
-------------------------

[](#frontend-routes-reference)

RouteControllerAccess`GET /company/credit/index``Controller\Credit\Index`Logged-in company customer---

DevOps &amp; Integrator Notes
-----------------------------

[](#devops--integrator-notes)

### Deployment Checklist

[](#deployment-checklist)

```
# After deploying or updating this module:
bin/magento setup:upgrade          # runs db_schema.xml migrations
bin/magento setup:di:compile       # regenerates interceptors and proxies
bin/magento setup:static-content:deploy -f
bin/magento cache:flush
```

### Integration Token Scope

[](#integration-token-scope)

When creating a Magento integration for ERP/external system credit sync, grant:

- `Orangecat_CompanyCredit::credit`
- `Orangecat_Company::company_manage` (parent required)

### Disabling Without Uninstalling

[](#disabling-without-uninstalling)

Set `mycompany/company_credit/enabled = No` in store config. This hides the frontend menu item and makes the payment method unavailable at checkout without removing any data or database schema.

To also hide the payment method from the admin payment method list: set `payment/companycredit/active = No`.

### Data Integrity

[](#data-integrity)

- Both tables use `ON DELETE CASCADE` from `mycompany.entity_id`. Deleting a company removes all its credit and ledger data automatically.
- There is no soft-delete on ledger entries. Manual deletions via the REST API are permanent.
- Currency code is stored per-company. If your store currency changes, update the credit record accordingly or the payment method will be unavailable at checkout (currency mismatch check in `isAvailable`).

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance99

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

2d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/959440?v=4)[Oliverio Gombert](/maintainers/olivertar)[@olivertar](https://github.com/olivertar)

---

Top Contributors

[![olivertar](https://avatars.githubusercontent.com/u/959440?v=4)](https://github.com/olivertar "olivertar (18 commits)")

---

Tags

paymentb2bmagento2companycreditorangecat

### Embed Badge

![Health badge](/badges/orangecat-module-company-credit/health.svg)

```
[![Health](https://phpackages.com/badges/orangecat-module-company-credit/health.svg)](https://phpackages.com/packages/orangecat-module-company-credit)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
