Skip to content

Commit

Permalink
Basic changes for the new Stripe version
Browse files Browse the repository at this point in the history
  • Loading branch information
afonic committed Feb 12, 2025
1 parent 04553ee commit b05b26d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Http/Payment/StripePaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Reach\StatamicResrv\Exceptions\RefundFailedException;
use Reach\StatamicResrv\Models\Reservation;
use Stripe\Event;
use Stripe\Exception\SignatureVerificationException;
use Stripe\Exception\UnexpectedValueException;
use Stripe\PaymentIntent;
use Stripe\Refund;
use Stripe\Stripe;
Expand All @@ -25,6 +27,9 @@ public function paymentIntent($payment, Reservation $reservation, $data)
'amount' => $payment->raw(),
'currency' => Str::lower(config('resrv-config.currency_isoCode')),
'metadata' => array_merge(['reservation_id' => $reservation->id], $this->filterCustomerData($data)),
'automatic_payment_methods' => [
'enabled' => true,
],
]);

return $paymentIntent;
Expand All @@ -36,6 +41,7 @@ public function refund($reservation)
try {
$attemptRefund = Refund::create([
'payment_intent' => $reservation->payment_id,
'reverse_transfer' => false,
]);
} catch (\Stripe\Exception\InvalidRequestException $exception) {
throw new RefundFailedException($exception->getMessage());
Expand Down Expand Up @@ -148,11 +154,18 @@ public function verifyPayment($request)

try {
$event = Webhook::constructEvent(
$request->getContent(), $sig_header, config('resrv-config.stripe_webhook_secret')
$request->getContent(),
$sig_header,
config('resrv-config.stripe_webhook_secret'),
null,
false
);
} catch (\Stripe\Exception\SignatureVerificationException $e) {
} catch (SignatureVerificationException $e) {
// Invalid signature
abort(403);
} catch (UnexpectedValueException $e) {
// Invalid payload
abort(403);
}

if ($event->type === 'payment_intent.succeeded') {
Expand Down

0 comments on commit b05b26d

Please sign in to comment.