mvenghaus/saloon-magento2-connector

Saloon Connector for Magento 2

2.0.2 2024-10-26 11:08 UTC

This package is auto-updated.

Last update: 2024-10-26 11:09:06 UTC


README

Saloon - Magento 2 Connector with token handling, allowing you to easily start building your own requests. It is only working if 2FA is disabled.

Installation

Install the package via composer:

composer require mvenghaus/saloon-magento2-connector

Usage

Basic Structure

$configuration = new Configuration(...);
$connector = new ApiConnector($configuration);

$response = $connector->send(new Your_Request());

Configuration - Structure

class Configuration
{
    public function __construct(
        public string $endpoint, // https://www.your-domain.com/rest/V1/
        public string $username,
        public string $password,
        public int $tokenLifetime = 0, // admin defined token lifetime in seconds 
        public ?string $authenticator = null, // saloon authenticator (serialized)
        public ?Closure $authenticatorUpdateCallback = null, // callback to save authenticator if changed
        public ?Closure $debugCallback = null // callback for debugging
    ) {
    }
}

Configuration - Example

$authenticator = load_from_your_cache();

$configuration = new Configuration(
    'https://www.your-domain.com/rest/V1/',
    'USERNAME',
    'PASSWORD',
    3600,
    $authenticator,
    function (string $authenticator) {
        save_to_your_cache($authenticator);
    },
    function (PendingRequest $pendingRequest, RequestInterface $psrRequest) {
        echo $pendingRequest->getUrl() . PHP_EOL;
    }
);