| 12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Commerce\Checkout;
- use App\Commerce\Payments\HitPay\HitPayGateway;
- use App\Commerce\Payments\PaymentException;
- use App\Models\Order;
- use Illuminate\Http\Response;
-
- /**
- * HitPay calls this address when an order's payment page changes. The address names the order.
- *
- * Nothing in the message is trusted: it only tells us to ask HitPay about the order, with the merchant's own key,
- * the same way the shopper's return page does. So a fake message cannot mark an order paid.
- * It is the safety net for shoppers who pay but close the browser before coming back to the store.
- */
- class HitPayWebhookController extends Controller
- {
- public function __invoke(string $publicId, HitPayGateway $hitpay, Checkout $checkout): Response
- {
- $order = Order::query()
- ->where('public_id', $publicId)
- ->where('payment_provider', $hitpay->name())
- ->first();
-
- if ($order !== null && ! $order->isPaid()) {
- try {
- $checkout->markPaid($order, $hitpay->checkPayment($order));
- } catch (PaymentException $e) {
- report($e);
- }
- }
-
- return response('OK');
- }
- }
|