-
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.
feat: Support partial simulation payloads (#113)
- Loading branch information
1 parent
02596af
commit c9cf681
Showing
28 changed files
with
1,753 additions
and
335 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
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Paddle\SDK\Entities; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class EventNameResolver | ||
{ | ||
public static function resolve(string $eventType): string | ||
{ | ||
$type = explode('.', $eventType); | ||
|
||
return str_replace('_', '', ucwords(implode('_', $type), '_')); | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Paddle\SDK\Notifications\Entities; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class EntityNameResolver | ||
{ | ||
public static function resolve(string $eventType): string | ||
{ | ||
// Map specific event entity types. | ||
$eventEntityTypes = [ | ||
'payment_method.deleted' => 'DeletedPaymentMethod', | ||
]; | ||
|
||
return $eventEntityTypes[$eventType] ?? self::resolveNameFromEventType($eventType); | ||
} | ||
|
||
public static function resolveFqn(string $eventType): string | ||
{ | ||
$fqn = sprintf('\Paddle\SDK\Notifications\Entities\%s', self::resolve($eventType)); | ||
|
||
return class_exists($fqn) ? $fqn : UndefinedEntity::class; | ||
} | ||
|
||
/** | ||
* @return class-string<Entity> | ||
*/ | ||
private static function resolveNameFromEventType(string $eventType): string | ||
{ | ||
$type = explode('.', $eventType); | ||
|
||
return self::snakeToPascalCase($type[0] ?? 'Unknown'); | ||
} | ||
|
||
private static function snakeToPascalCase(string $string): string | ||
{ | ||
return str_replace('_', '', ucwords($string, '_')); | ||
} | ||
} |
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,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Paddle\SDK\Notifications\Entities\Simulation; | ||
|
||
use Paddle\SDK\FiltersUndefined; | ||
use Paddle\SDK\Notifications\Entities\DateTime; | ||
use Paddle\SDK\Notifications\Entities\Shared\CountryCode; | ||
use Paddle\SDK\Notifications\Entities\Shared\CustomData; | ||
use Paddle\SDK\Notifications\Entities\Shared\ImportMeta; | ||
use Paddle\SDK\Notifications\Entities\Shared\Status; | ||
use Paddle\SDK\Notifications\Entities\Simulation\Traits\OptionalProperties; | ||
use Paddle\SDK\Undefined; | ||
|
||
final class Address implements SimulationEntity | ||
{ | ||
use OptionalProperties; | ||
use FiltersUndefined; | ||
|
||
public function __construct( | ||
public readonly string|Undefined $id = new Undefined(), | ||
public readonly string|Undefined|null $description = new Undefined(), | ||
public readonly string|Undefined|null $firstLine = new Undefined(), | ||
public readonly string|Undefined|null $secondLine = new Undefined(), | ||
public readonly string|Undefined|null $city = new Undefined(), | ||
public readonly string|Undefined|null $postalCode = new Undefined(), | ||
public readonly string|Undefined|null $region = new Undefined(), | ||
public readonly CountryCode|Undefined $countryCode = new Undefined(), | ||
public readonly CustomData|Undefined|null $customData = new Undefined(), | ||
public readonly Status|Undefined $status = new Undefined(), | ||
public readonly \DateTimeInterface|Undefined $createdAt = new Undefined(), | ||
public readonly \DateTimeInterface|Undefined $updatedAt = new Undefined(), | ||
public readonly ImportMeta|Undefined|null $importMeta = new Undefined(), | ||
public readonly string|Undefined|null $customerId = new Undefined(), | ||
) { | ||
} | ||
|
||
public static function from(array $data): self | ||
{ | ||
return new self( | ||
id: self::optional($data, 'id'), | ||
description: self::optional($data, 'description'), | ||
firstLine: self::optional($data, 'first_line'), | ||
secondLine: self::optional($data, 'second_line'), | ||
city: self::optional($data, 'city'), | ||
postalCode: self::optional($data, 'postal_code'), | ||
region: self::optional($data, 'region'), | ||
countryCode: self::optional($data, 'country_code', fn ($value) => CountryCode::from($value)), | ||
customData: self::optional($data, 'custom_data', fn ($value) => new CustomData($value)), | ||
status: self::optional($data, 'status', fn ($value) => Status::from($value)), | ||
createdAt: self::optional($data, 'created_at', fn ($value) => DateTime::from($value)), | ||
updatedAt: self::optional($data, 'updated_at', fn ($value) => DateTime::from($value)), | ||
importMeta: self::optional($data, 'import_meta', fn ($value) => ImportMeta::from($value)), | ||
customerId: self::optional($data, 'customer_id'), | ||
); | ||
} | ||
|
||
public function jsonSerialize(): mixed | ||
{ | ||
return $this->filterUndefined([ | ||
'id' => $this->id, | ||
'description' => $this->description, | ||
'first_line' => $this->firstLine, | ||
'second_line' => $this->secondLine, | ||
'city' => $this->city, | ||
'postal_code' => $this->postalCode, | ||
'region' => $this->region, | ||
'country_code' => $this->countryCode, | ||
'custom_data' => $this->customData, | ||
'status' => $this->status, | ||
'created_at' => $this->createdAt, | ||
'updated_at' => $this->updatedAt, | ||
'import_meta' => $this->importMeta, | ||
'customer_id' => $this->customerId, | ||
]); | ||
} | ||
} |
Oops, something went wrong.