Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Feb 19, 2024
1 parent 139cc39 commit 3c77480
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/Listeners/HandleStripeWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/StripeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,7 +96,7 @@ public function checkout(Request $request, Order $order): Order
{
$this->session = $this->createSession($order);

return $order;
return parent::checkout($request, $order);
}

/**
Expand All @@ -123,15 +122,15 @@ 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();
}

/**
* {@inheritdoc}
*/
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]);
}

Expand Down

0 comments on commit 3c77480

Please sign in to comment.