-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: davidgrayston-paddle <[email protected]>
- Loading branch information
1 parent
7bdd4ab
commit d370f6c
Showing
64 changed files
with
3,289 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Paddle\SDK\Entities\Event\EventTypeName; | ||
use Paddle\SDK\Exceptions\ApiError; | ||
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse; | ||
use Paddle\SDK\Notifications\Entities\Address; | ||
use Paddle\SDK\Resources\Shared\Operations\List\Pager; | ||
use Paddle\SDK\Resources\Simulations\Operations\CreateSimulation; | ||
use Paddle\SDK\Resources\Simulations\Operations\ListSimulations; | ||
use Paddle\SDK\Resources\Simulations\Operations\UpdateSimulation; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$environment = Paddle\SDK\Environment::tryFrom(getenv('PADDLE_ENVIRONMENT') ?: '') ?? Paddle\SDK\Environment::SANDBOX; | ||
$apiKey = getenv('PADDLE_API_KEY') ?: null; | ||
$simulationId = getenv('PADDLE_SIMULATION_ID') ?: null; | ||
$notificationSettingId = getenv('PADDLE_NOTIFICATION_SETTING_ID') ?: null; | ||
|
||
if (is_null($apiKey)) { | ||
echo "You must provide the PADDLE_API_KEY in the environment:\n"; | ||
echo "PADDLE_API_KEY=your-key php examples/basic_usage.php\n"; | ||
exit(1); | ||
} | ||
|
||
$paddle = new Paddle\SDK\Client($apiKey, options: new Paddle\SDK\Options($environment)); | ||
|
||
// ┌─── | ||
// │ List Simulations │ | ||
// └──────────────────┘ | ||
try { | ||
$simulations = $paddle->simulations->list(new ListSimulations(new Pager(perPage: 10))); | ||
} catch (ApiError|MalformedResponse $e) { | ||
var_dump($e); | ||
exit; | ||
} | ||
|
||
echo "List Simulations\n"; | ||
|
||
foreach ($simulations as $simulation) { | ||
echo sprintf("- %s:\n", $simulation->name); | ||
echo sprintf(" - ID: %s\n", $simulation->id); | ||
echo sprintf(" - Type: %s\n", $simulation->type->getValue()); | ||
echo sprintf(" - Notification Setting ID: %s\n", $simulation->notificationSettingId); | ||
} | ||
|
||
// ┌─── | ||
// │ Create Simulation │ | ||
// └───────────────────┘ | ||
try { | ||
$simulation = $paddle->simulations->create( | ||
new CreateSimulation( | ||
notificationSettingId: $notificationSettingId, | ||
type: EventTypeName::AddressCreated(), | ||
name: 'Simulate Address Creation', | ||
payload: Address::from([ | ||
'id' => 'add_01hv8gq3318ktkfengj2r75gfx', | ||
'country_code' => 'US', | ||
'status' => 'active', | ||
'created_at' => '2024-04-12T06:42:58.785000Z', | ||
'updated_at' => '2024-04-12T06:42:58.785000Z', | ||
'customer_id' => 'ctm_01hv6y1jedq4p1n0yqn5ba3ky4', | ||
'description' => 'Head Office', | ||
'first_line' => '4050 Jefferson Plaza, 41st Floor', | ||
'second_line' => null, | ||
'city' => 'New York', | ||
'postal_code' => '10021', | ||
'region' => 'NY', | ||
]), | ||
), | ||
); | ||
} catch (ApiError|MalformedResponse $e) { | ||
var_dump($e); | ||
exit; | ||
} | ||
|
||
echo sprintf("Created Simulation: %s\n", $simulation->name); | ||
echo sprintf("- ID: %s\n", $simulation->id); | ||
echo sprintf("- Type: %s\n", $simulation->type->getValue()); | ||
echo sprintf("- Notification Setting ID: %s\n", $simulation->notificationSettingId); | ||
|
||
// ┌─── | ||
// │ Get Simulation │ | ||
// └────────────────┘ | ||
try { | ||
$simulation = $paddle->simulations->get($simulationId); | ||
} catch (ApiError|MalformedResponse $e) { | ||
var_dump($e); | ||
exit; | ||
} | ||
|
||
echo sprintf("Get Simulation: %s\n", $simulation->name); | ||
echo sprintf("- ID: %s\n", $simulation->id); | ||
echo sprintf("- Type: %s\n", $simulation->type->getValue()); | ||
echo sprintf("- Notification Setting ID: %s\n", $simulation->notificationSettingId); | ||
|
||
// ┌─── | ||
// │ Update Simulation │ | ||
// └───────────────────┘ | ||
try { | ||
$simulation = $paddle->simulations->update( | ||
$simulationId, | ||
new UpdateSimulation( | ||
type: EventTypeName::AddressCreated(), | ||
payload: Address::from([ | ||
'id' => 'add_01hv8gq3318ktkfengj2r75gfx', | ||
'country_code' => 'US', | ||
'status' => 'active', | ||
'created_at' => '2024-04-12T06:42:58.785000Z', | ||
'updated_at' => '2024-04-12T06:42:58.785000Z', | ||
'customer_id' => 'ctm_01hv6y1jedq4p1n0yqn5ba3ky4', | ||
'description' => 'Head Office', | ||
'first_line' => '4050 Jefferson Plaza, 41st Floor', | ||
'second_line' => null, | ||
'city' => 'New York', | ||
'postal_code' => '10021', | ||
'region' => 'NY', | ||
]), | ||
), | ||
); | ||
} catch (ApiError|MalformedResponse $e) { | ||
var_dump($e); | ||
exit; | ||
} | ||
|
||
echo sprintf("Updated Simulation: %s\n", $simulation->name); | ||
echo sprintf("- ID: %s\n", $simulation->id); | ||
echo sprintf("- Type: %s\n", $simulation->type->getValue()); | ||
echo sprintf("- Notification Setting ID: %s\n", $simulation->notificationSettingId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* |------ | ||
* | ! Generated code ! | ||
* | Altering this code will result in changes being overwritten | | ||
* |-------------------------------------------------------------|. | ||
*/ | ||
|
||
namespace Paddle\SDK\Entities\Collections; | ||
|
||
use Paddle\SDK\Entities\Simulation; | ||
|
||
class SimulationCollection extends Collection | ||
{ | ||
public static function from(array $itemsData, Paginator|null $paginator = null): self | ||
{ | ||
return new self( | ||
array_map(fn (array $item): Simulation => Simulation::from($item), $itemsData), | ||
$paginator, | ||
); | ||
} | ||
|
||
public function current(): Simulation | ||
{ | ||
return parent::current(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* |------ | ||
* | ! Generated code ! | ||
* | Altering this code will result in changes being overwritten | | ||
* |-------------------------------------------------------------|. | ||
*/ | ||
|
||
namespace Paddle\SDK\Entities\Collections; | ||
|
||
use Paddle\SDK\Entities\SimulationRun; | ||
|
||
class SimulationRunCollection extends Collection | ||
{ | ||
public static function from(array $itemsData, Paginator|null $paginator = null): self | ||
{ | ||
return new self( | ||
array_map(fn (array $item): SimulationRun => SimulationRun::from($item), $itemsData), | ||
$paginator, | ||
); | ||
} | ||
|
||
public function current(): SimulationRun | ||
{ | ||
return parent::current(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* |------ | ||
* | ! Generated code ! | ||
* | Altering this code will result in changes being overwritten | | ||
* |-------------------------------------------------------------|. | ||
*/ | ||
|
||
namespace Paddle\SDK\Entities\Collections; | ||
|
||
use Paddle\SDK\Entities\SimulationRunEvent; | ||
|
||
class SimulationRunEventCollection extends Collection | ||
{ | ||
public static function from(array $itemsData, Paginator|null $paginator = null): self | ||
{ | ||
return new self( | ||
array_map(fn (array $item): SimulationRunEvent => SimulationRunEvent::from($item), $itemsData), | ||
$paginator, | ||
); | ||
} | ||
|
||
public function current(): SimulationRunEvent | ||
{ | ||
return parent::current(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* |------ | ||
* | ! Generated code ! | ||
* | Altering this code will result in changes being overwritten | | ||
* |-------------------------------------------------------------|. | ||
*/ | ||
|
||
namespace Paddle\SDK\Entities\Collections; | ||
|
||
use Paddle\SDK\Entities\SimulationType; | ||
|
||
class SimulationTypeCollection extends Collection | ||
{ | ||
public static function from(array $itemsData, Paginator|null $paginator = null): self | ||
{ | ||
return new self( | ||
array_map(fn (array $item): SimulationType => SimulationType::from($item), $itemsData), | ||
$paginator, | ||
); | ||
} | ||
|
||
public function current(): SimulationType | ||
{ | ||
return parent::current(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.