diff --git a/src/Listeners/HandleStripeWebhook.php b/src/Listeners/HandleStripeWebhook.php index 2876924..4885630 100644 --- a/src/Listeners/HandleStripeWebhook.php +++ b/src/Listeners/HandleStripeWebhook.php @@ -6,7 +6,6 @@ use Cone\Bazar\Models\Transaction; use Cone\Bazar\Stripe\Events\StripeWebhookInvoked; use Cone\Bazar\Support\Facades\Gateway; -use Illuminate\Support\Facades\Date; use Stripe\Event; use Throwable; @@ -55,13 +54,15 @@ public function handlePayment(Event $event, Order $order): void */ public function handleRefund(Event $event, Order $order): void { - foreach ($event->data['refunds']['data'] as $refund) { + foreach ($event->data['object']['refunds']['data'] as $refund) { if (is_null($order->transactions->firstWhere('key', $refund['id']))) { - Gateway::driver('stripe')->refund( + $transaction = Gateway::driver('stripe')->refund( $order, $refund['amount'] / 100, - ['key' => $refund['id'], 'completed_at' => Date::now()] + ['key' => $refund['id']] ); + + $transaction->markAsCompleted(); } } } diff --git a/src/StripeDriver.php b/src/StripeDriver.php index 0a3245b..728f7fa 100644 --- a/src/StripeDriver.php +++ b/src/StripeDriver.php @@ -10,7 +10,6 @@ use Cone\Bazar\Models\Transaction; use Cone\Bazar\Stripe\Events\StripeWebhookInvoked; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\URL; use Stripe\Checkout\Session; use Stripe\StripeClient; @@ -97,7 +96,7 @@ public function checkout(Request $request, Order $order): Order { $this->session = $this->createSession($order); - return $order; + return parent::checkout($request, $order); } /** @@ -123,7 +122,7 @@ public function resolveOrderForCapture(Request $request): Order $request->input('session_id') ); - return Order::proxy()->newQuery()->where('uuid', $this->session->client_reference_id)->firstOrFail(); + return Order::proxy()->newQuery()->where('bazar_orders.uuid', $this->session->client_reference_id)->firstOrFail(); } /** @@ -131,7 +130,7 @@ public function resolveOrderForCapture(Request $request): Order */ public function capture(Request $request, Order $order): Order { - if (! $order->transactions()->where('key', $this->session->payment_intent)->exists()) { + if (! $order->transactions()->where('bazar_transactions.key', $this->session->payment_intent)->exists()) { $this->pay($order, null, ['key' => $this->session->payment_intent]); }