From f90ed0dff663f121c7b77033ac0a88f62e34e8f5 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Thu, 17 Oct 2024 12:29:43 +0100 Subject: [PATCH] docs: Add simulation example --- examples/catalog_management.php | 2 +- examples/simulations.php | 130 ++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 examples/simulations.php diff --git a/examples/catalog_management.php b/examples/catalog_management.php index f2fcb01..c36c0f1 100644 --- a/examples/catalog_management.php +++ b/examples/catalog_management.php @@ -24,7 +24,7 @@ require __DIR__ . '/../vendor/autoload.php'; -$environment = Paddle\SDK\Environment::tryFrom(getenv('PAD') ?: '') ?? Paddle\SDK\Environment::SANDBOX; +$environment = Paddle\SDK\Environment::tryFrom(getenv('PADDLE_ENVIRONMENT') ?: '') ?? Paddle\SDK\Environment::SANDBOX; $apiKey = getenv('PADDLE_API_KEY') ?: null; if (is_null($apiKey)) { diff --git a/examples/simulations.php b/examples/simulations.php new file mode 100644 index 0000000..0e4c3ba --- /dev/null +++ b/examples/simulations.php @@ -0,0 +1,130 @@ +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);