-
Notifications
You must be signed in to change notification settings - Fork 20
/
createEntity.php
53 lines (39 loc) · 1.11 KB
/
createEntity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* This source file is proprietary and part of Rebilly.
*
* (c) Rebilly SRL
* Rebilly Ltd.
* Rebilly Inc.
*
* @see https://www.rebilly.com
*/
declare(strict_types=1);
use Rebilly\Sdk\Client;
use Rebilly\Sdk\Model\Product;
use Rebilly\Sdk\Service;
require_once __DIR__ . '/../vendor/autoload.php';
$client = new Client([
'baseUrl' => Client::SANDBOX_HOST,
'organizationId' => '{organizationId}',
'apiKey' => '{secretKey}',
]);
$service = new Service(client: $client);
// Create entity using setters
$product1 = Product::from()
->setName('Test setters product')
->setDescription('Test setters description');
$service->products()->create($product1);
printEntity($product1);
// Create entity using from array method
$product2 = Product::from([
'name' => 'Test fromArray product',
'description' => 'Test fromArray description',
]);
$service->products()->create($product2);
printEntity($product2);
function printEntity(mixed $entity): void
{
echo json_encode($entity, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . PHP_EOL;
echo str_repeat('=', 80) . PHP_EOL . PHP_EOL;
}