Skip to content

Commit

Permalink
Stripe updates
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed Oct 3, 2023
1 parent 3304a90 commit 47bf332
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 25 deletions.
2 changes: 1 addition & 1 deletion payment/stripe/config/stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
\Stripe\PaymentIntent::STATUS_REQUIRES_CAPTURE => 'awaiting-payment',
\Stripe\PaymentIntent::STATUS_CANCELED => 'cancelled',
\Stripe\PaymentIntent::STATUS_PROCESSING => 'processing',
\Stripe\PaymentIntent::STATUS_REQUIRES_ACTION => 'failed',
\Stripe\PaymentIntent::STATUS_REQUIRES_ACTION => 'awaiting-payment',
\Stripe\PaymentIntent::STATUS_REQUIRES_CONFIRMATION => 'auth-pending',
\Stripe\PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD => 'failed',
\Stripe\PaymentIntent::STATUS_SUCCEEDED => 'payment-received',
Expand Down
3 changes: 2 additions & 1 deletion payment/stripe/routes/webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Support\Facades\Route;

Route::post(config('lunar.stripe.webhook_path', 'stripe/webhook'), \Lunar\Stripe\Http\Controllers\WebhookController::class)
->middleware([\Lunar\Stripe\Http\Middleware\StripeWebhookMiddleware::class, 'api'])
->withoutMiddleware([\App\Http\Middleware\VerifyCsrfToken::class])
->middleware(\Lunar\Stripe\Http\Middleware\StripeWebhookMiddleware::class)

->name('lunar.stripe.webhook');
4 changes: 2 additions & 2 deletions payment/stripe/src/Actions/StoreCharges.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public function store(Order $order, Collection $charges)
}

if (! empty($paymentDetails['last4'])) {
$cardType = $paymentDetails['last4'];
$lastFour = $paymentDetails['last4'];
}

if (! empty($paymentDetails['checked'])) {
if (! empty($paymentDetails['checks'])) {
$meta = array_merge($meta, (array) $paymentDetails['checks']);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Lunar\Stripe\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Routing\Controllers\Middleware;
use Lunar\Stripe\Concerns\ConstructsWebhookEvent;
use Stripe\Exception\SignatureVerificationException;
use Stripe\Exception\UnexpectedValueException;

class StripeWebhookMiddleware extends Middleware
class StripeWebhookMiddleware
{
public function handle(Request $request, \Closure $next)
public function handle(Request $request, Closure $next = null)
{
$secret = config('services.stripe.webhooks.payment_intent');
$stripeSig = $request->header('Stripe-Signature');
Expand All @@ -26,7 +26,7 @@ public function handle(Request $request, \Closure $next)
}

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

return $next($request);
Expand Down
20 changes: 3 additions & 17 deletions payment/stripe/src/StripePaymentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function __construct()
*/
final public function authorize(): PaymentAuthorize
{
if (! $this->order || ! $this->order = $this->cart->draftOrder) {
$this->order = $this->cart->draftOrder ?: $this->cart->completedOrder;

if (! $this->order) {
try {
$this->order = $this->cart->createOrder();
} catch (DisallowMultipleCartOrdersException $e) {
Expand All @@ -61,14 +63,6 @@ final public function authorize(): PaymentAuthorize
}
}

if ($this->order->placed_at) {
return new PaymentAuthorize(
success: false,
message: 'This order has already been placed',
orderId: $this->order->id,
);
}

$this->paymentIntent = $this->stripe->paymentIntents->retrieve(
$this->data['payment_intent']
);
Expand All @@ -81,14 +75,6 @@ final public function authorize(): PaymentAuthorize
);
}

if ($this->paymentIntent->status == PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD) {
return new PaymentAuthorize(
success: false,
message: 'A payment method is required for this intent.',
orderId: $this->order->id,
);
}

if ($this->paymentIntent->status == PaymentIntent::STATUS_REQUIRES_CAPTURE && $this->policy == 'automatic') {
$this->paymentIntent = $this->stripe->paymentIntents->capture(
$this->data['payment_intent']
Expand Down

0 comments on commit 47bf332

Please sign in to comment.