PHPackages                             morningtrain/economic - 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. [API Development](/categories/api)
4. /
5. morningtrain/economic

ActiveLibrary[API Development](/categories/api)

morningtrain/economic
=====================

PHP SDK for e-conomic

v1.2.0(9mo ago)213.7k↑75%[2 PRs](https://github.com/Morning-Train/economic/pulls)2MITPHPPHP ^8.1CI passing

Since Dec 7Pushed 9mo ago3 watchersCompare

[ Source](https://github.com/Morning-Train/economic)[ Packagist](https://packagist.org/packages/morningtrain/economic)[ Docs](https://github.com/morning-train/economic)[ GitHub Sponsors](https://github.com/Morning-Train)[ RSS](/packages/morningtrain-economic/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (60)Used By (2)

PHP SDK for E-conomic
=====================

[](#php-sdk-for-e-conomic)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bf3b45eaf8ac9381263bc72ca49b670c0772a30805280d9e42f3adbc572536c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f726e696e67747261696e2f65636f6e6f6d69632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/morningtrain/economic)[![Tests](https://camo.githubusercontent.com/27328d5a6bedd49cbbe175960f5c9314392b8745d8cebd847aaf2d8dc25693cf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f726e696e672d747261696e2f652d636f6e6f6d69632f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/morning-train/economic/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/a778af996cc5aa6d9ff7b2c6418df0e15229a05ab81e22ab66e989641b6c5086/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f726e696e67747261696e2f65636f6e6f6d69632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/morningtrain/economic)

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

[](#installation)

You can install the package via composer:

```
composer require morningtrain/economic
```

Basic Concepts
--------------

[](#basic-concepts)

This SDK is built to make it simple to handle and use the e-conomic REST API. You can read the e-conomic REST API documentation here:

### Driver

[](#driver)

The SDK uses a driver to handle the communication with the e-conomic REST API. We have not implemented a driver in this package, since we want to make it possible to use the SDK with different frameworks.

You are free to use some of our implementations, or make your own driver:

FrameworkGit RepoComposer PackageLaravel[Morning-Train/laravel-economic](https://github.com/Morning-Train/laravel-economic)[morningtrain/laravel-economic](https://packagist.org/packages/morningtrain/laravel-economic)WordPress[Morning-Train/wp-economic](https://github.com/Morning-Train/wp-economic)[morningtrain/wp-economic](https://packagist.org/packages/morningtrain/wp-economic)If you make your own driver, you must implement the `Morningtrain\Economic\Interfaces\EconomicDriver` interface, and initialize the API like this:

```
use Morningtrain\Economic\EconomicApi;

EconomicApiService::setDriver(new YourDriver($appSecretToken, $agreementGrantToken));
```

### Loggers

[](#loggers)

We have implemented a PSR logger interface, so you can log all the requests and responses from the e-conomic REST API.

You can register a PSR logger by calling the `registerLogger` method on the `Morningtrain\Economic\Services\EconomicLoggerService` class.

### Resources

[](#resources)

Every resource in the e-conomic REST API is represented by a class in this SDK. The resources are located in the `src/Resources` folder.

Some resources are divided into sub resources based on the REST API.

Every resource class is implementing function corresponding to the endpoints in the API.

Some resources are just a DTO (Data Transfer Object) that is not represented with endpoints in the REST API. These resources are used to make it easy to work with objects represented in other Resources.

### Collections

[](#collections)

Collections are used to fetch multiple resources from the e-conomic REST API. We make use of Laravels lazy collections to make it easy to work with the collection. This means, that you can use all the methods from the Laravel collection class on the collections returned from the SDK. The lazy collection will automatically get the resources you need and handle pagination for you. The API is only called when you need the resources, so the collection will not contain data before you need it.

### Filtering

[](#filtering)

When fetching resources from the e-conomic REST API, you can filter the resources you want to get, if the endpoint allows it. See  for more information about which filters every resource support. The SDK has a simple way to filter resources, using af query builder like syntax.

A simple example could be:

```
use Morningtrain\Economic\Resources\Customer;

$customer = Customer::where('email', 'ms@morningtrain.dk')
                ->orWhere('name', 'Morningtrain')
                ->first();
```

### Sorting

[](#sorting)

Is not yet implemented.

Usage
-----

[](#usage)

Every resource in the e-conomic REST API is represented by a class in this SDK. And every class is implementing function corresponding to the endpoints in the API.

### Get multiple resources

[](#get-multiple-resources)

When fetching multiple resources from the e-conomic REST API, you will get a collection of the resources. The collection is an implementation of the Laravel lazy collection, so you can use all the methods from the Laravel collection class on the collection.

To get multiple resources from the e-conomic REST API, you can use the `all` method on the resource class.

```
use Morningtrain\Economic\Resources\Customer;

$customers = Customer::all();
```

#### Filtering

[](#filtering-1)

You can filter the resources you want to get, if the endpoint allows it. See  for more information about which filters every resource support. This will return af collection of resources matching the filter.

```
use Morningtrain\Economic\Resources\Customer;

$customers = Customer::where('email', 'ms@morningtrain.dk');
```

### Get a single resource

[](#get-a-single-resource)

When fetching a single resource from the e-conomic REST API, you will get an instance of the resource class you are asking for.

To get a single resource from the e-conomic REST API, you can use the `find` method on the resource class. The find method is using the primary key to find the resource. The primary key is different from resource to resource, so you need to look in the e-conomic REST API documentation to find the primary key for the resource you want to get. The type of primary key is mixed, so you can use a string or an integer to find the resource.

```
use Morningtrain\Economic\Resources\Customer;
use Morningtrain\Economic\Resources\Product;

$customer = Customer::find(1); // Where 1 is the customer number

$product = Product::find('proudct-1'); // Where 'product-1' is the product number
```

### Creating a resource

[](#creating-a-resource)

Some resources can be created in E-conomic. When created succesfully you will get the resource you just created. We have implemented a `create` method on the resource class, so you can create a resource like this:

The parameters you need to provide when creating a resource is different from resource to resource, so you need to look in the implementation of the resource class to see which parameters you need to provide. Some parameter is required and some is optional. You can see which parameters are required and optional in the implementation of the resource class. To just use some of the optional parameters, you can use named parameters in PHP.

```
use Morningtrain\Economic\Resources\Product;

$product = Product::create(
    'Product 1', // product name
    1, // product group number
    'p-1', // product number
    barCode: '1234567890',
    costPrice: 100.0,
    recommendedPrice: 150.0,
    salesPrice: 199.95,
    description: 'test',
    unit: 1 // unit number
);
```

Some resources can be created in an alternative way with the `new` method. This will create a new instance of the resource class with the required properties. Some of these resources can then use the `save` method to create the resource in E-conomic.

```
use Morningtrain\Economic\Resources\Invoice\DraftInvoice;

$draftInvoice = DraftInvoice::new(
    'DKK',
    1,
    new DateTime('2024-02-13T12:20:18+00:00'),
    14,
    1,
    Recipient::new(
        'John Doe',
        new VatZone(1),
    ),
    [
        ProductLine::new(
            description: 'T-shirt - Size L',
            product: new Product([
                'productNumber' => 1,
            ]),
            quantity: 1,
            unitNetPrice: 500
        )
    ]
    notes: Note::new(
        heading: 'Heading',
        textLine1: 'Text line 1',
        textLine2: 'Text line 2'
    )
);

$draftInvoice->save();
```

### Updating a resource

[](#updating-a-resource)

Some resources can be updated after creation. This can be done as follows:

```
use Morningtrain\Economic\Resources\Customer;

$customer = new Customer::find(1); // Where 1 is the customer number

$customer->name = 'New name';

$customer->save();
```

This will update the customer name in E-conomic. You can also simply provide all the new values when instantiating the customer.

```
use Morningtrain\Economic\Resources\Customer;

$customer = new Customer([
    'customerNumber' => 1,
    'name' => 'New Name',
]);

$customer->save();
```

### Deleting a resource

[](#deleting-a-resource)

Some resources can be deleted in E-conomic. This can be done using the `delete` method on the resource class.

```
use Morningtrain\Economic\Resources\Customer;

$customer = new Customer::find(1); // Where 1 is the customer number

$customer->delete();
```

This will delete the customer in E-conomic.

You can also delete a resource by calling the static method `deleteByPrimaryKey`.

```
use Morningtrain\Economic\Resources\Customer;

Customer::deleteByPrimaryKey(1); // Where 1 is the customer number
```

Examples
--------

[](#examples)

### Get all customers

[](#get-all-customers)

```
use Morningtrain\Economic\Resources\Customer;

$customers = Customer::all();

foreach ($customers as $customer) {
    echo $customer->name;
}
```

### Get a single customer

[](#get-a-single-customer)

```
use Morningtrain\Economic\Resources\Customer;

$customer = Customer::find(1); // Where 1 is the customer number

if(!empty($customer)) {
    echo $customer->name;
}
```

### Get a customer by email

[](#get-a-customer-by-email)

```
use Morningtrain\Economic\Resources\Customer;

$customer = Customer::where('email', 'ms@morningtrain.dk');

if(!empty($customer)) {
    echo $customer->name;
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Martin Schadegg Brønniche](https://github.com/mschadegg)
- [Simon Jønsson](https://github.com/Morning-Train)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

---

Developed by

[![Morningtrain logo](https://camo.githubusercontent.com/e5c33559f0458f056816ab1a75dc9fe3bbd5a141e5d8630d85ec32fa45c01526/68747470733a2f2f6d6f726e696e67747261696e2e646b2f77702d636f6e74656e742f7468656d65732f6d74742d776f726470726573732d7468656d652f6173736574732f696d672f6c6f676f2d6f6e6c792d746578742e737667)](https://morningtrain.dk)

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance58

Moderate activity, may be stable

Popularity27

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 54.8% 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 ~22 days

Recently: every ~89 days

Total

28

Last Release

271d ago

Major Versions

v0.7.3 → v1.0.02024-08-29

v0.9.0 → v1.1.02025-05-19

PHP version history (2 changes)v0.1.0PHP ^8.1

v1.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/278725?v=4)[morningtrain](/maintainers/morningtrain)[@morningtrain](https://github.com/morningtrain)

---

Top Contributors

[![mschadegg](https://avatars.githubusercontent.com/u/11231039?v=4)](https://github.com/mschadegg "mschadegg (102 commits)")[![SimonJnsson](https://avatars.githubusercontent.com/u/11147193?v=4)](https://github.com/SimonJnsson "SimonJnsson (68 commits)")[![larasmorningtrain](https://avatars.githubusercontent.com/u/86046759?v=4)](https://github.com/larasmorningtrain "larasmorningtrain (9 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")[![matbaek](https://avatars.githubusercontent.com/u/2310644?v=4)](https://github.com/matbaek "matbaek (1 commits)")[![VKattou](https://avatars.githubusercontent.com/u/11645860?v=4)](https://github.com/VKattou "VKattou (1 commits)")

---

Tags

e-conomiceconomicphpphp-sdksdkvismae-conomicmorningtrain

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/morningtrain-economic/health.svg)

```
[![Health](https://phpackages.com/badges/morningtrain-economic/health.svg)](https://phpackages.com/packages/morningtrain-economic)
```

###  Alternatives

[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[esign/laravel-conversions-api

A laravel wrapper package around the Facebook Conversions API

69145.4k](/packages/esign-laravel-conversions-api)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[lasserafn/laravel-economic

Economic REST wrapper for Laravel

1118.5k](/packages/lasserafn-laravel-economic)

PHPackages © 2026

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