Add PayPal webhook handling
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Models\CheckoutSession;
|
||||
use App\Models\Package;
|
||||
use App\Services\Checkout\CheckoutAssignmentService;
|
||||
use App\Services\Checkout\CheckoutSessionService;
|
||||
use App\Services\Coupons\CouponRedemptionService;
|
||||
use App\Services\Coupons\CouponService;
|
||||
use App\Services\PayPal\Exceptions\PayPalException;
|
||||
use App\Services\PayPal\PayPalOrderService;
|
||||
@@ -24,6 +25,7 @@ class PayPalCheckoutController extends Controller
|
||||
private readonly CheckoutSessionService $sessions,
|
||||
private readonly CheckoutAssignmentService $assignment,
|
||||
private readonly CouponService $coupons,
|
||||
private readonly CouponRedemptionService $couponRedemptions,
|
||||
) {}
|
||||
|
||||
public function create(PayPalCheckoutRequest $request): JsonResponse
|
||||
@@ -61,7 +63,7 @@ class PayPalCheckoutController extends Controller
|
||||
$couponCode = Str::upper(trim((string) ($data['coupon_code'] ?? '')));
|
||||
|
||||
if ($couponCode !== '') {
|
||||
$preview = $this->coupons->preview($couponCode, $package, $tenant);
|
||||
$preview = $this->coupons->preview($couponCode, $package, $tenant, CheckoutSession::PROVIDER_PAYPAL);
|
||||
$this->sessions->applyCoupon($session, $preview['coupon'], $preview['pricing']);
|
||||
}
|
||||
|
||||
@@ -154,6 +156,7 @@ class PayPalCheckoutController extends Controller
|
||||
]);
|
||||
|
||||
$this->sessions->markFailed($session, 'paypal_capture_failed');
|
||||
$this->couponRedemptions->recordFailure($session, 'paypal_capture_failed');
|
||||
|
||||
return response()->json([
|
||||
'status' => CheckoutSession::STATUS_FAILED,
|
||||
@@ -191,6 +194,7 @@ class PayPalCheckoutController extends Controller
|
||||
]);
|
||||
|
||||
$this->sessions->markCompleted($session, now());
|
||||
$this->couponRedemptions->recordSuccess($session, $capture);
|
||||
|
||||
return response()->json([
|
||||
'status' => CheckoutSession::STATUS_COMPLETED,
|
||||
@@ -209,6 +213,7 @@ class PayPalCheckoutController extends Controller
|
||||
}
|
||||
|
||||
$this->sessions->markFailed($session, 'paypal_'.$status);
|
||||
$this->couponRedemptions->recordFailure($session, 'paypal_'.$status);
|
||||
|
||||
return response()->json([
|
||||
'status' => CheckoutSession::STATUS_FAILED,
|
||||
|
||||
Reference in New Issue
Block a user