Skip to content

Commit 47bf332

Browse files
committed
Stripe updates
1 parent 3304a90 commit 47bf332

File tree

5 files changed

+12
-25
lines changed

5 files changed

+12
-25
lines changed

payment/stripe/config/stripe.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
\Stripe\PaymentIntent::STATUS_REQUIRES_CAPTURE => 'awaiting-payment',
4141
\Stripe\PaymentIntent::STATUS_CANCELED => 'cancelled',
4242
\Stripe\PaymentIntent::STATUS_PROCESSING => 'processing',
43-
\Stripe\PaymentIntent::STATUS_REQUIRES_ACTION => 'failed',
43+
\Stripe\PaymentIntent::STATUS_REQUIRES_ACTION => 'awaiting-payment',
4444
\Stripe\PaymentIntent::STATUS_REQUIRES_CONFIRMATION => 'auth-pending',
4545
\Stripe\PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD => 'failed',
4646
\Stripe\PaymentIntent::STATUS_SUCCEEDED => 'payment-received',

payment/stripe/routes/webhooks.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Illuminate\Support\Facades\Route;
44

55
Route::post(config('lunar.stripe.webhook_path', 'stripe/webhook'), \Lunar\Stripe\Http\Controllers\WebhookController::class)
6+
->middleware([\Lunar\Stripe\Http\Middleware\StripeWebhookMiddleware::class, 'api'])
67
->withoutMiddleware([\App\Http\Middleware\VerifyCsrfToken::class])
7-
->middleware(\Lunar\Stripe\Http\Middleware\StripeWebhookMiddleware::class)
8+
89
->name('lunar.stripe.webhook');

payment/stripe/src/Actions/StoreCharges.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public function store(Order $order, Collection $charges)
5151
}
5252

5353
if (! empty($paymentDetails['last4'])) {
54-
$cardType = $paymentDetails['last4'];
54+
$lastFour = $paymentDetails['last4'];
5555
}
5656

57-
if (! empty($paymentDetails['checked'])) {
57+
if (! empty($paymentDetails['checks'])) {
5858
$meta = array_merge($meta, (array) $paymentDetails['checks']);
5959
}
6060

payment/stripe/src/Http/Middleware/StripeWebhookMiddleware.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace Lunar\Stripe\Http\Middleware;
44

5+
use Closure;
56
use Illuminate\Http\Request;
6-
use Illuminate\Routing\Controllers\Middleware;
77
use Lunar\Stripe\Concerns\ConstructsWebhookEvent;
88
use Stripe\Exception\SignatureVerificationException;
99
use Stripe\Exception\UnexpectedValueException;
1010

11-
class StripeWebhookMiddleware extends Middleware
11+
class StripeWebhookMiddleware
1212
{
13-
public function handle(Request $request, \Closure $next)
13+
public function handle(Request $request, Closure $next = null)
1414
{
1515
$secret = config('services.stripe.webhooks.payment_intent');
1616
$stripeSig = $request->header('Stripe-Signature');
@@ -26,7 +26,7 @@ public function handle(Request $request, \Closure $next)
2626
}
2727

2828
if (! in_array($event->type, ['payment_intent.succeeded', 'payment_intent.payment_failed', 'payment_intent.payment_failed'])) {
29-
return response(status: 200);
29+
abort(200);
3030
}
3131

3232
return $next($request);

payment/stripe/src/StripePaymentType.php

+3-17
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public function __construct()
5050
*/
5151
final public function authorize(): PaymentAuthorize
5252
{
53-
if (! $this->order || ! $this->order = $this->cart->draftOrder) {
53+
$this->order = $this->cart->draftOrder ?: $this->cart->completedOrder;
54+
55+
if (! $this->order) {
5456
try {
5557
$this->order = $this->cart->createOrder();
5658
} catch (DisallowMultipleCartOrdersException $e) {
@@ -61,14 +63,6 @@ final public function authorize(): PaymentAuthorize
6163
}
6264
}
6365

64-
if ($this->order->placed_at) {
65-
return new PaymentAuthorize(
66-
success: false,
67-
message: 'This order has already been placed',
68-
orderId: $this->order->id,
69-
);
70-
}
71-
7266
$this->paymentIntent = $this->stripe->paymentIntents->retrieve(
7367
$this->data['payment_intent']
7468
);
@@ -81,14 +75,6 @@ final public function authorize(): PaymentAuthorize
8175
);
8276
}
8377

84-
if ($this->paymentIntent->status == PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD) {
85-
return new PaymentAuthorize(
86-
success: false,
87-
message: 'A payment method is required for this intent.',
88-
orderId: $this->order->id,
89-
);
90-
}
91-
9278
if ($this->paymentIntent->status == PaymentIntent::STATUS_REQUIRES_CAPTURE && $this->policy == 'automatic') {
9379
$this->paymentIntent = $this->stripe->paymentIntents->capture(
9480
$this->data['payment_intent']

0 commit comments

Comments
 (0)