-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from MyParcelCOM/feature/authorization-disrupti…
…on-event ♻️ ✨ Refactored publish library + Introduced AuthorizationDisruption message
- Loading branch information
Showing
16 changed files
with
330 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelCom\Payments\Providers\Publish; | ||
|
||
use Override; | ||
|
||
class AuthorizationDisruption extends Message | ||
{ | ||
private readonly string $paymentProviderCode; | ||
|
||
public function __construct( | ||
private readonly string $shopId, | ||
?string $paymentProviderCode = null, | ||
?string $topicArn = null, | ||
) { | ||
$this->paymentProviderCode = $paymentProviderCode ?? env('PAYMENT_PROVIDER_CODE'); | ||
|
||
parent::__construct($topicArn); | ||
} | ||
|
||
#[Override] | ||
public function payload(): array | ||
{ | ||
return [ | ||
'shop_id' => $this->shopId, | ||
'payment_provider_code' => $this->paymentProviderCode, | ||
]; | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelCom\Payments\Providers\Publish; | ||
|
||
use Illuminate\Support\Str; | ||
|
||
abstract class Message | ||
{ | ||
private readonly string $topicArn; | ||
|
||
public function __construct(?string $topicArn = null) | ||
{ | ||
$this->topicArn = $topicArn ?? config('publish.sns.topic_arn'); | ||
} | ||
|
||
public function getTopicArn(): string | ||
{ | ||
return $this->topicArn; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return strtolower(Str::snake(class_basename($this))); | ||
} | ||
|
||
abstract public function payload(): array; | ||
} |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelCom\Payments\Providers\Publish; | ||
|
||
use Override; | ||
|
||
class PaymentFailed extends Message | ||
{ | ||
public function __construct( | ||
private readonly string $myparcelcomPaymentId, | ||
private readonly FailureCode $failureCode, | ||
private readonly ?string $failureMessage = null, | ||
?string $topicArn = null, | ||
) { | ||
parent::__construct($topicArn); | ||
} | ||
|
||
#[Override] | ||
public function payload(): array | ||
{ | ||
return [ | ||
'myparcelcom_payment_id' => $this->myparcelcomPaymentId, | ||
'failure_code' => $this->failureCode->value, | ||
'failure_message' => $this->failureMessage, | ||
]; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelCom\Payments\Providers\Publish; | ||
|
||
use DateTimeInterface; | ||
use Override; | ||
|
||
class PaymentSuccessful extends Message | ||
{ | ||
public function __construct( | ||
private readonly string $myparcelcomPaymentId, | ||
private readonly DateTimeInterface $paidAt, | ||
?string $topicArn = null, | ||
) { | ||
parent::__construct($topicArn); | ||
} | ||
|
||
#[Override] | ||
public function payload(): array | ||
{ | ||
return [ | ||
'myparcelcom_payment_id' => $this->myparcelcomPaymentId, | ||
'paid_at' => $this->paidAt->format(DateTimeInterface::ATOM), | ||
]; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelCom\Payments\Providers\Publish; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class PublishJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function __construct(private readonly Message $message) | ||
{ | ||
} | ||
|
||
public function handle(Publisher $publisher): void | ||
{ | ||
$publisher | ||
->publish($this->message) | ||
->wait(); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelCom\Payments\Providers\Publish; | ||
|
||
use Aws\Sns\SnsClient; | ||
use GuzzleHttp\Promise\PromiseInterface; | ||
use GuzzleHttp\Utils; | ||
use Illuminate\Support\Env; | ||
|
||
class Publisher | ||
{ | ||
public function __construct( | ||
private readonly SnsClient $snsClient, | ||
private readonly LocalClient $localClient, | ||
) { | ||
} | ||
|
||
public function publish(Message $message): PromiseInterface | ||
{ | ||
$payload = [ | ||
'type' => $message->getType(), | ||
'data' => $message->payload(), | ||
]; | ||
|
||
if (Env::get('APP_ENV') === 'local') { | ||
return $this->localClient->publish($payload); | ||
} | ||
|
||
return $this->snsClient->publishAsync([ | ||
'Message' => Utils::jsonEncode($payload), | ||
'TopicArn' => $message->getTopicArn(), | ||
]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelCom\Payments\Providers\Support; | ||
|
||
use ReflectionClass; | ||
use ReflectionException; | ||
|
||
trait GetPrivatePropertyValue | ||
{ | ||
/** | ||
* @throws ReflectionException | ||
*/ | ||
private function getPrivatePropertyValue(object $object, string $property): mixed | ||
{ | ||
$classReflection = new ReflectionClass($object); | ||
$propertyReflection = $classReflection->getProperty($property); | ||
/** @noinspection PhpExpressionResultUnusedInspection */ | ||
$propertyReflection->setAccessible(true); | ||
|
||
return $propertyReflection->getValue($object); | ||
} | ||
} |
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.