Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Feb 5, 2024
1 parent faad25f commit 992af8f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/StripeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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 @@ -170,7 +171,19 @@ public function handleManualTransaction(Transaction $transaction): void
*/
public function handleManualPayment(Transaction $transaction): void
{
// create payment link
$payment = $this->client->paymentIntents->create([
'amount' => $transaction->amount * 100,
'currency' => strtolower($transaction->order->currency),
'automatic_payment_methods' => ['enabled' => true],
'metadata' => [
'order' => $transaction->order->uuid,
],
]);

$transaction
->setAttribute('key', $payment->id)
->setAttribute('completed_at', Date::now())
->save();
}

/**
Expand All @@ -188,6 +201,14 @@ public function handleManualRefund(Transaction $transaction): void
));
}

// create refund
$refund = $this->client->refunds->create([
'payment_intent' => $payment->key,
'amount' => $transaction->amount,
'metadata' => [
'order' => $transaction->order->uuid,
],
]);

$transaction->setAttribute('key', $refund->id)->save();
}
}

0 comments on commit 992af8f

Please sign in to comment.