netflex/commerce

Netflex Commerce library
1,173
Install
composer require netflex/commerce
Latest Version:v7.0.1
PHP:^8.4
License:MIT
Last Updated:Jun 3, 2026
Links: GitHub  ·  Packagist
Maintainer: thomas-alrek

Netflex Commerce

[READ ONLY] Subtree split of the Netflex Commerce component (see netflex/framework)

The Netflex Commerce library is for working with the commerce endpoints in the Netflex API.

Installation

composer require netflex/commerce

Getting started TL;DR

// Creating new order and checking out
$order = Order::create()
  ->addToSession()
  ->addCart([
    'entry_id' => 10001,
    'entry_name' => 'Ticket',
    'variant_cost' => 100,
    'no_of_entries' => 1,
    'tax_percent' => 1.12
  ])
  ->checkout([
    'firstname' => 'Ola',
    'surname' => 'Nordmann'
  ])
  ->save([
    'status' => 'p',
    'currency' => 'NOK',
    'customer_mail' => 'ola@nordmann.no',
    'customer_phone' => '99123456'
  ])
  ->addData('paymentId', '123456789', 'Payment ID')
  ->addLog('Customer sent to payment');

// Adding payment and completing order
$order = Order::retrieveBySecret('a72b...12f4')
  ->addLog('Customer returned from payment')
  ->addPayment([
    'payment_method' => 'stripe',
    'amount' => 100,
    'status' => 'OK',
    'capture_status' => 'OK',
    'transaction_id' => '123456789',
    'card_type_name' => 'visa',
  ])
  ->register()
  ->lock()
  ->removeFromSession();

Getting started properly

Always start with an Order object. Order is the main class of this library, meant to hold all other objects.

// Empty object. Does NOT create an order in the API.
$order = new Order();

// Creating and getting a new empty order in the API.
$order = Order::create();

// Retrieves an existing order from the API based on an order id. Throws an exception if not found.
$order = Order::retrieve(10001);

// Retrieves an existing order from the API based on a register id. Throws an exception if not found.
$order = Order::retrieveByRegisterId(10001);

// Retrieves an existing order from the API based on an order secret. Throws an exception if not found.
$order = Order::retrieveBySecret('a1234567896e8bf63bbd43e851811234');

// Retrieves an existing order from the API based on an order secret stored in $_SESSION.
// If session or order does not exist, it creates an empty object.
// It does NOT create a new empty order in the API.
// On the next save() or refresh(), it stores the order secret in session.
$order = Order::retrieveBySession();

// Retrieves an existing order from the API based on an order secret stored in $_SESSION.
// If session or order does not exist, it creates a new empty order in the API
// and stores the order secret in session.
$order = Order::retrieveBySessionOrCreate();

// Manually adding the order secret to session.
$order->addToSession();

Adding things to the order

On all add-methods below, the data is immediately sent to the API. To update the order object with added items and calculated totals, you need to call the refresh() method.

$order->addCart([
  'entry_id' => 10001,
  'entry_name' => 'Ticket',
  'variant_cost' => 100,
  'no_of_entries' => 1,
  'tax_percent' => 1.12,
  'properties' => [
    'someCustomKey' => 'someCustomValue'
  ]
]);

$order->addLog('This is a log item');

$order->addLogInfo('Log some info');
$order->addLogWarning('Log a warning');
$order->addLogSuccess('Log a success');
$order->addLogDanger('Log danger');

$order->addData('key', 'value', 'Label');

$order->addDiscount([
  'scope' => 'item', // cart|item|shipping
  'scope_key' => '10001', // cart item id
  'label' => '20 % discount on your ticket',
  'discount' => 0.20,
  'type' => 'percent', // percent|fixed|amount
]);

$order->addPayment([
  'payment_method' => 'stripe',
  'amount' => 100,
  'status' => 'OK',
  'capture_status' => 'OK',
  'transaction_id' => '123456789',
  'card_type_name' => 'visa',
  'data' => [
    'someCustomKey' => 'someCustomValue'
  ]
]);

// Updating the order object with added items and calculated totals
$order->refresh();

It is also possible to pass in and Item object in most of the add methods.

$cartItem = new CartItem();

$cartItem->entry_id = 10001;
$cartItem->entry_name = 'Ticket';
$cartItem->variant_cost = 100;
$cartItem->no_of_entries = 1;
$cartItem->tax_percent = 1.12;

$order->addCart($cartItem);

Updating the order

Updating the properties on the main order object. Option A:

$order->status = 'p';
$order->currency = 'NOK';
$order->customer_mail = 'ola@nordmann.no';
$order->customer_phone = '99123456';
$order->save();

Option B:

$order->save([
  'status' => 'p',
  'currency' => 'NOK',
  'customer_mail' => 'ola@nordmann.no',
  'customer_phone' => '99123456'
]);

Updating a cart item. Option A:

// Updating the number of entries on cart items with a specific entry_id
foreach ($order->cart->items as $item) {
  if ($item->entry_id == 10001) {
    $item->no_of_entries = 5;
    $item->save();
  }
}

Option B:

foreach ($order->cart->items as $item) {
  if ($item->entry_id == 10001) {
    $item->save(['no_of_entries' => 5]);
  }
}

Checking out and completing the order

$order->checkout([
  'firstname' => 'Ola',
  'surname' => 'Nordmann'
]);

$order->register();

$order->saveStatus('n');

$order->checkoutEnd();

// This does the same as saveStatus('n') and checkoutEnd();
// Saves the status to 'n' and add a checkout_end date.
$order->lock();

$order->removeFromSession();

Search query builder

This package use the Netflex QueryBuilder library, so you can easily search for and return a collection of orders.

$orders = Order::where('data.someCustomKey', 'someCustomValue')->get();

Contributing

Thank you for considering contributing to the Netflex Commerce library! Please read the contribution guide.

Code of Conduct

In order to ensure that the community is welcoming to all, please review and abide by the Code of Conduct.

License

The Netflex Commerce library is open-sourced software licensed under the MIT license.

Copyright © 2020 Apility AS

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

641,106,524 9,700
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

502,645,077 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

418,291,778 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

394,964,158 4,660

Version History

Version Released PHP Laravel License
v7.0.1 ^8.4 ^13.0 MIT
v7.0.0 ^8.4 ^13.0 MIT
v6.7.3 ^8.2 ^12.0 MIT
v6.7.2 ^8.2 ^12.0 MIT
v6.7.1 ^8.2 ^12.0 MIT
Pre-releases (3)
Version Released Laravel License
v2.0.0-RC3 ^7.0 MIT
v2.0.0-RC2 ^7.0 MIT
v2.0.0-RC1 ^6.12 MIT