projectSecret = $projectSecret; } public const RESOLUTION_STATUSES = [ 'PROCESSED' => 'processing', 'FAIL' => 'failed' ]; /** * @return void */ public function webhook() { global $woocommerce; $body = file_get_contents("php://input"); $response = json_decode($body, true); if (!isset($response['data']) || !isset($response['data']['referenceId'])) { return; } if (!Signature::check( json_encode($response['data'], JSON_UNESCAPED_SLASHES), $response['signature'], $this->projectSecret )) { return; } $order = wc_get_order($response['data']['referenceId']); if (!$order) { return; } if ($order->get_status() !== 'pending') { return; } if (isset(self::RESOLUTION_STATUSES[$response['data']['status']['value']])) { $order->update_status(self::RESOLUTION_STATUSES[$response['data']['status']['value']]); } $woocommerce->cart->empty_cart(); update_option('webhook_debug', $_POST); } }