PHP code example of sandwave-io / f-secure

1. Go to this page and download the library: Download sandwave-io/f-secure library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sandwave-io / f-secure example snippets




MS\Serializer\Naming\IdenticalPropertyNamingStrategy;
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy;
use JMS\Serializer\SerializerBuilder;
use SandwaveIo\FSecure\Client\Client;
use SandwaveIo\FSecure\Client\AuthClient;
use SandwaveIo\FSecure\Client\OrderClient;
use SandwaveIo\FSecure\Client\ProductClient;
use SandwaveIo\FSecure\HttpClient\AuthenticatedClientFactory;
use SandwaveIo\FSecure\HttpClient\BearerTokenMiddleware;
use SandwaveIo\FSecure\HttpClient\ClientFactory;
use SandwaveIo\FSecure\Service\ThrowableConvertor;

$apiEndpoint = 'https://vip.f-secure.com/api/v2/';
$clientId = 'client_id';
$clientSecret = 'client_secret';

// create AuthClient
$auth = new AuthClient(
    $clientId,
    $clientSecret,
    (new ClientFactory($apiEndpoint))->create(),
    (new SerializerBuilder())->build(),
    new ThrowableConvertor()
);

// use AuthClient to create a GuzzleClient binded with middleware for handling the bearer token
$httpClient = (new AuthenticatedClientFactory(
    $apiEndpoint, new BearerTokenMiddleware($auth)
))->create();

// create client by injecting the guzzleclient
$client = new Client(
    $httpClient,
    (new SerializerBuilder())->setPropertyNamingStrategy(
        new SerializedNameAnnotationStrategy(
            new IdenticalPropertyNamingStrategy()
        )
    )->build(),
    new ThrowableConvertor()
);

// use client to create ProductClient
$productClient = new ProductClient($client);
$productCollection = $productClient->get();

// or use client to create OrderClient
$orderClient = new OrderClient($client);
$orderCollection = $orderClient->get();