Skip to content

Commit

Permalink
make finding order more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
repl6669 committed Feb 16, 2024
1 parent 7521ad5 commit 0164476
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Jobs/Webhooks/HandlePaymentIntentCancelled.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function handle(): void
{
$event = $this->constructStripeEvent();
$paymentIntent = $this->getPaymentIntentFromEvent($event);
$order = $this->findOrderByIntent($paymentIntent);
$order = $this->findOrder($paymentIntent);
$paymentAdapter = $this->getPaymentAdapter();

OrderPaymentCanceled::dispatch($order, $paymentAdapter, $paymentIntent);
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/Webhooks/HandlePaymentIntentFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function handle(): void
{
$event = $this->constructStripeEvent();
$paymentIntent = $this->getPaymentIntentFromEvent($event);
$order = $this->findOrderByIntent($paymentIntent);
$order = $this->findOrder($paymentIntent);
$paymentAdapter = $this->getPaymentAdapter();

OrderPaymentFailed::dispatch($order, $paymentAdapter, $paymentIntent);
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/Webhooks/HandlePaymentIntentSucceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function handle(): void
{
$event = $this->constructStripeEvent();
$paymentIntent = $this->getPaymentIntentFromEvent($event);
$order = $this->findOrderByIntent($paymentIntent);
$order = $this->findOrder($paymentIntent);

App::make(AuthorizeStripePayment::class)($order, $order->cart, $paymentIntent);
}
Expand Down
8 changes: 6 additions & 2 deletions src/Jobs/Webhooks/WebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Dystcz\LunarApiStripeAdapter\Jobs\Webhooks;

use Dystcz\LunarApi\Domain\Orders\Actions\FindOrderByCartIntent;
use Dystcz\LunarApi\Domain\Orders\Actions\FindOrderByIntent;
use Dystcz\LunarApi\Domain\Orders\Actions\FindOrderByTransaction;
use Dystcz\LunarApi\Domain\Payments\Contracts\PaymentIntent as PaymentIntentContract;
use Dystcz\LunarApi\Domain\Payments\Data\PaymentIntent;
use Dystcz\LunarApi\Domain\Payments\PaymentAdapters\PaymentAdapter;
Expand Down Expand Up @@ -73,10 +75,12 @@ protected function getPaymentAdapter(): PaymentAdapter
*
* @throws ModelNotFoundException
*/
protected function findOrderByIntent(PaymentIntentContract $paymentIntent): Order
protected function findOrder(PaymentIntentContract $paymentIntent): Order
{
try {
$order = App::make(FindOrderByIntent::class)($paymentIntent);
$order = App::make(FindOrderByIntent::class)($paymentIntent)
?? App::make(FindOrderByTransaction::class)($paymentIntent)
?? App::make(FindOrderByCartIntent::class)($paymentIntent);
} catch (Throwable $e) {
$this->fail($e);
}
Expand Down

0 comments on commit 0164476

Please sign in to comment.