| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace Longyi\Pay\Airwallex\Http\Controllers;
- use Longyi\Pay\Airwallex\Payment\Airwallex;
- use Webkul\Checkout\Facades\Cart;
- use Webkul\Sales\Models\Order;
- use Webkul\Sales\Repositories\OrderRepository;
- use Webkul\Sales\Transformers\OrderResource;
- use Longyi\Pay\AwxKlarna\Payment\AwxKlarna;
- class AirwallexController extends Controller
- {
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct(
- protected OrderRepository $orderRepository,
- protected Airwallex $airwallex,
- ) {}
- public function hook()
- {
- $param = @file_get_contents('php://input');
- $header = $this->getAllHeaders();
- $data = [
- 'timestamp' => $header['x-timestamp'],
- 'signature' => $header['x-signature'],
- 'content' => $param
- ];
- $result = $this->airwallex->checkSignature($data, 'secret');
- if (!$result) {
- @header("HTTP/1.0 400 Bad Request");
- exit;
- }
- $notifyData = json_decode($param, true);
- $orderNo = $notifyData['data']['object']['merchant_order_id'] ?: 0;
- if (empty($orderNo)) {
- @header("HTTP/1.0 400 Bad Request");
- exit;
- }
- $prefix = $this->airwallex->getPrefix();
- if (strpos($orderNo, $prefix) === false) {
- @header("HTTP/1.0 200 ok");
- exit;
- }
- $type = $notifyData['name'];
- $orderId = str_replace($prefix, '', $orderNo);
- $transactionId = $notifyData['data']['object']['id'] ?: '';
- $eventType = "payments_webhook_" . strtolower(str_replace(".", "_", $type));
- $this->airwallex->$eventType($orderId, $transactionId);
- }
- }
|