PHP code example of guilty / poweroffice

1. Go to this page and download the library: Download guilty/poweroffice 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/ */

    

guilty / poweroffice example snippets





use Guilty\Poweroffice\Services\PowerofficeService;
use Guilty\Poweroffice\Sessions\ValueStoreSession;
use GuzzleHttp\Client;
use Spatie\Valuestore\Valuestore;


$client = new Client();
$store = Valuestore::make(config("poweroffice.store_path"));
$session = new ValueStoreSession($store);
$service = new PowerOfficeService(
    $client,
    $session,
    "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // Application Key
    "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // Client Key 
    true // Test Mode
);



return [
    'application_key' => env("POWEROFFICE_APPLICATION_KEY"),
    'client_key' => env("POWEROFFICE_CLIENT_KEY"),
    'test_mode' => env("POWEROFFICE_TEST_MODE"),
    'store_path' => storage_path("poweroffice.json"), // Used with the ValueStoreSession
];



namespace Guilty\Poweroffice\Interfaces;

interface SessionInterface
{
    public function setAccessToken($accessToken);
    public function getAccessToken();
    public function setRefreshToken($refreshToken);
    public function getRefreshToken();
    public function canRefresh();
    public function disconnect();
    public function setExpireDate(\DateTime $expireDate);
    /** @return \DateTimeImmutable */
    public function getExpireDate();
    public function hasExpired();
    public function isValid();
    public function setFromResponse($response);
}



use Guilty\Poweroffice\Sessions\AbstractSession;

// Or whatever else you want to store your session
class ExcelSpreadsheetSession extends AbstractSession
{
    public function setAccessToken($accessToken) { /* TODO: Implement */ }
    public function getAccessToken() { /* TODO: Implement */ }
    public function setRefreshToken($refreshToken) { /* TODO: Implement */ }
    public function getRefreshToken() { /* TODO: Implement */ }
    public function disconnect() { /* TODO: Implement */ }
    public function setExpireDate(\DateTime $expireDate) { /* TODO: Implement */ }
    public function getExpireDate() { /* TODO: Implement */ } 
}


 
uilty\Poweroffice\Services\PowerofficeService;
use GuzzleHttp\Client;
use Guilty\Poweroffice\Sessions\ArraySession;

$service = new PowerOfficeService(
    new Client(),
    new ArraySession(), 
    "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // Application Key
    "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // Client Key 
    true // Test Mode
);

$customer = $service->performRequest("post", "/Customer", [
    "json" => [
        "firstName" => "John",
        "lastName" => "Smith",
        "emailAddress" => "[email protected]",
        "invoiceEmailAddress" => "[email protected]",
        "isArchived" => false,
        "isPerson" => true,
        "invoiceDeliveryType" => 1, // PDF By Email
        "since" => (new DateTimeImmutable())->format("Y-m-d"),
        "mailAddress" => $address = [
            "address1" => "123 Fakestreet",
            "city" => "Lazytown",
            "zipCode" => "1234",
            "countryCode" => "NO", // ISO Country Code (norway)
            "isPrimary" => true,
        ],
        "streetAddresses" => [$address], // Must be an array
    ]
]);

// All responses will 


 
uilty\Poweroffice\Services\PowerofficeService;
use GuzzleHttp\Client;
use Guilty\Poweroffice\Sessions\ArraySession;

$service = new PowerOfficeService(
    new Client(),
    new ArraySession(),
    "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", // Application Key
    "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", // Client Key 
    true // Test Mode
);

$customer = $service->createCustomer([
    "json" => [
        "firstName" => "John",
        "lastName" => "Smith",
        "emailAddress" => "[email protected]",
        "invoiceEmailAddress" => "[email protected]",
        "isArchived" => false,
        "isPerson" => true,
        "invoiceDeliveryType" => 1, // PDF By Email
        "since" => (new DateTimeImmutable())->format("Y-m-d"),
        "mailAddress" => $address = [
            "address1" => "123 Fakestreet",
            "city" => "Lazytown",
            "zipCode" => "1234",
            "countryCode" => "NO", // ISO Country Code (norway)
            "isPrimary" => true,
        ],
        "streetAddresses" => [$address], // Must be an array
    ]
]);

// All responses will 

php artisan vendor:publish --provider="Guilty\Poweroffice\PowerofficeServiceProvider" --tag="config"