Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripe webhooks on queue #5

Merged
merged 8 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Actions/AuthorizeStripePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Dystcz\LunarApi\Domain\Orders\Events\OrderPaymentSuccessful;
use Dystcz\LunarApi\Domain\Payments\Contracts\PaymentIntent;
use Illuminate\Support\Facades\Log;
use Lunar\Base\DataTransferObjects\PaymentAuthorize;
use Lunar\Facades\Payments;
use Lunar\Models\Cart;
Expand All @@ -14,8 +13,6 @@ class AuthorizeStripePayment
{
public function __invoke(Order $order, Cart $cart, PaymentIntent $intent): void
{
Log::info('Payment intent succeeded: '.$intent->id);

/** @var PaymentAuthorize $payment */
$payment = Payments::driver('stripe')
->order($order)
Expand Down
24 changes: 5 additions & 19 deletions src/Jobs/Webhooks/HandleChargeFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@

namespace Dystcz\LunarApiStripeAdapter\Jobs\Webhooks;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\WebhookClient\Models\WebhookCall;

class HandleChargeFailed implements ShouldQueue
class HandleChargeFailed extends WebhookHandler
{
use InteractsWithQueue, Queueable, SerializesModels;

public WebhookCall $webhookCall;

public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}

/**
* Handle payment intent processing.
*/
public function handle(): void
{
// do your work here

// you can access the payload of the webhook call with `$this->webhookCall->payload`
// $event = $this->constructStripeEvent();
}
}
24 changes: 5 additions & 19 deletions src/Jobs/Webhooks/HandleChargeableSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@

namespace Dystcz\LunarApiStripeAdapter\Jobs\Webhooks;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\WebhookClient\Models\WebhookCall;

class HandleChargeableSource implements ShouldQueue
class HandleChargeableSource extends WebhookHandler
{
use InteractsWithQueue, Queueable, SerializesModels;

public WebhookCall $webhookCall;

public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}

/**
* Handle payment intent processing.
*/
public function handle(): void
{
// do your work here

// you can access the payload of the webhook call with `$this->webhookCall->payload`
// $event = $this->constructStripeEvent();
}
}
32 changes: 10 additions & 22 deletions src/Jobs/Webhooks/HandleOtherEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@

namespace Dystcz\LunarApiStripeAdapter\Jobs\Webhooks;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\WebhookClient\Models\WebhookCall;
use Stripe\Event;
use Throwable;
use Illuminate\Support\Facades\Config;

class HandleOtherEvent implements ShouldQueue
class HandleOtherEvent extends WebhookHandler
{
use InteractsWithQueue, Queueable, SerializesModels;

public WebhookCall $webhookCall;

public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}

/**
* Handle payment intent processing.
*/
public function handle(): void
{
try {
$event = Event::constructFrom($this->webhookCall->payload);
} catch (Throwable $e) {
$this->fail($e);
}
// $event = $this->constructStripeEvent();
// $paymentIntent = $this->getPaymentIntentFromEvent($event);
// $order = $this->findOrderByIntent($paymentIntent);
//
// $paymentAdapter = $this->register->get(Config::get('lunar-api.stripe.driver', 'stripe'));
}
}
43 changes: 9 additions & 34 deletions src/Jobs/Webhooks/HandlePaymentIntentCancelled.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,21 @@

namespace Dystcz\LunarApiStripeAdapter\Jobs\Webhooks;

use Dystcz\LunarApi\Domain\Orders\Actions\FindOrderByIntent;
use Dystcz\LunarApi\Domain\Orders\Events\OrderPaymentCanceled;
use Dystcz\LunarApi\Domain\Payments\Data\PaymentIntent;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
use Lunar\Stripe\Facades\StripeFacade;
use Spatie\WebhookClient\Models\WebhookCall;
use Stripe\Event;
use Throwable;
use Illuminate\Support\Facades\Config;

class HandlePaymentIntentCancelled implements ShouldQueue
class HandlePaymentIntentCancelled extends WebhookHandler
{
use InteractsWithQueue, Queueable, SerializesModels;

public WebhookCall $webhookCall;

public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}

/**
* Handle failed payment intent.
*/
public function handle(): void
{
try {
$event = Event::constructFrom($this->webhookCall->payload);
$paymentIntent = new PaymentIntent(intent: $event->data->object);
} catch (Throwable $e) {
$this->fail($e);
}

try {
$order = App::make(FindOrderByIntent::class)($paymentIntent);
} catch (Throwable $e) {
$this->fail($e);
}
$event = $this->constructStripeEvent();
$paymentIntent = $this->getPaymentIntentFromEvent($event);
$order = $this->findOrderByIntent($paymentIntent);

$paymentAdapter = StripeFacade::getFacadeRoot();
$paymentAdapter = $this->register->get(Config::get('lunar-api.stripe.driver', 'stripe'));

OrderPaymentCanceled::dispatch($order, $paymentAdapter, $paymentIntent);
}
Expand Down
32 changes: 10 additions & 22 deletions src/Jobs/Webhooks/HandlePaymentIntentCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@

namespace Dystcz\LunarApiStripeAdapter\Jobs\Webhooks;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\WebhookClient\Models\WebhookCall;
use Stripe\Event;
use Throwable;
use Illuminate\Support\Facades\Config;

class HandlePaymentIntentCreated implements ShouldQueue
class HandlePaymentIntentCreated extends WebhookHandler
{
use InteractsWithQueue, Queueable, SerializesModels;

public WebhookCall $webhookCall;

public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}

/**
* Handle payment intent processing.
*/
public function handle(): void
{
try {
$event = Event::constructFrom($this->webhookCall->payload);
} catch (Throwable $e) {
$this->fail($e);
}
// $event = $this->constructStripeEvent();
// $paymentIntent = $this->getPaymentIntentFromEvent($event);
// $order = $this->findOrderByIntent($paymentIntent);
//
// $paymentAdapter = $this->register->get(Config::get('lunar-api.stripe.driver', 'stripe'));
}
}
43 changes: 9 additions & 34 deletions src/Jobs/Webhooks/HandlePaymentIntentFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,21 @@

namespace Dystcz\LunarApiStripeAdapter\Jobs\Webhooks;

use Dystcz\LunarApi\Domain\Orders\Actions\FindOrderByIntent;
use Dystcz\LunarApi\Domain\Orders\Events\OrderPaymentFailed;
use Dystcz\LunarApi\Domain\Payments\Data\PaymentIntent;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
use Lunar\Stripe\Facades\StripeFacade;
use Spatie\WebhookClient\Models\WebhookCall;
use Stripe\Event;
use Throwable;
use Illuminate\Support\Facades\Config;

class HandlePaymentIntentFailed implements ShouldQueue
class HandlePaymentIntentFailed extends WebhookHandler
{
use InteractsWithQueue, Queueable, SerializesModels;

public WebhookCall $webhookCall;

public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}

/**
* Handle failed payment intent.
*/
public function handle(): void
{
try {
$event = Event::constructFrom($this->webhookCall->payload);
$paymentIntent = new PaymentIntent(intent: $event->data->object);
} catch (Throwable $e) {
$this->fail($e);
}

try {
$order = App::make(FindOrderByIntent::class)($paymentIntent);
} catch (Throwable $e) {
$this->fail($e);
}
$event = $this->constructStripeEvent();
$paymentIntent = $this->getPaymentIntentFromEvent($event);
$order = $this->findOrderByIntent($paymentIntent);

$paymentAdapter = StripeFacade::getFacadeRoot();
$paymentAdapter = $this->register->get(Config::get('lunar-api.stripe.driver', 'stripe'));

OrderPaymentFailed::dispatch($order, $paymentAdapter, $paymentIntent);
}
Expand Down
34 changes: 10 additions & 24 deletions src/Jobs/Webhooks/HandlePaymentIntentProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,19 @@

namespace Dystcz\LunarApiStripeAdapter\Jobs\Webhooks;

use Dystcz\LunarApi\Domain\Payments\Data\PaymentIntent;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\WebhookClient\Models\WebhookCall;
use Stripe\Event;
use Throwable;
use Illuminate\Support\Facades\Config;

class HandlePaymentIntentProcessing implements ShouldQueue
class HandlePaymentIntentProcessing extends WebhookHandler
{
use InteractsWithQueue, Queueable, SerializesModels;

public WebhookCall $webhookCall;

public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}

/**
* Handle payment intent processing.
*/
public function handle(): void
{
try {
$event = Event::constructFrom($this->webhookCall->payload);
$paymentIntent = new PaymentIntent(intent: $event->data->object);
} catch (Throwable $e) {
$this->fail($e);
}
// $event = $this->constructStripeEvent();
// $paymentIntent = $this->getPaymentIntentFromEvent($event);
// $order = $this->findOrderByIntent($paymentIntent);
//
// $paymentAdapter = $this->register->get(Config::get('lunar-api.stripe.driver', 'stripe'));
}
}
34 changes: 10 additions & 24 deletions src/Jobs/Webhooks/HandlePaymentIntentRequiresAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,19 @@

namespace Dystcz\LunarApiStripeAdapter\Jobs\Webhooks;

use Dystcz\LunarApi\Domain\Payments\Data\PaymentIntent;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\WebhookClient\Models\WebhookCall;
use Stripe\Event;
use Throwable;
use Illuminate\Support\Facades\Config;

class HandlePaymentIntentRequiresAction implements ShouldQueue
class HandlePaymentIntentRequiresAction extends WebhookHandler
{
use InteractsWithQueue, Queueable, SerializesModels;

public WebhookCall $webhookCall;

public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}

/**
* Handle payment intent processing.
*/
public function handle(): void
{
try {
$event = Event::constructFrom($this->webhookCall->payload);
$paymentIntent = new PaymentIntent(intent: $event->data->object);
} catch (Throwable $e) {
$this->fail($e);
}
// $event = $this->constructStripeEvent();
// $paymentIntent = $this->getPaymentIntentFromEvent($event);
// $order = $this->findOrderByIntent($paymentIntent);
//
// $paymentAdapter = $this->register->get(Config::get('lunar-api.stripe.driver', 'stripe'));
}
}
Loading
Loading