$account, 'timestamp' => $timestamp, 'action' => $action, 'payload' => $encoded, 'signature' => hash_hmac('sha256', "$timestamp.$action.$account.$encoded", get_option('refref_secret', ''))]; } public static function request(string $path, array $body): array { if (!RefRef_Config::connection()) { throw new RuntimeException(esc_html__('The store is not connected.', 'refref')); } $options = ['timeout' => 10, 'redirection' => 0, 'headers' => ['Content-Type' => 'application/json'], 'body' => wp_json_encode($body)]; if (wp_get_environment_type() === 'local' && defined('REFREF_LOCAL_CA')) { $options['sslcertificates'] = REFREF_LOCAL_CA; } $response = wp_remote_post(RefRef_Config::core_url() . $path, $options); if (is_wp_error($response)) { throw new RuntimeException(esc_html__('RefRef could not be reached.', 'refref')); } $status = wp_remote_retrieve_response_code($response); if ($status < 200 || $status >= 300) { throw new RuntimeException(esc_html__('RefRef refused the request.', 'refref')); } $data = json_decode(wp_remote_retrieve_body($response), true); if (!is_array($data)) { throw new RuntimeException(esc_html__('RefRef returned an invalid response.', 'refref')); } return $data; } public static function shopper(string $action, array $payload, array $pagination = []): array { $proof = self::proof($action, $payload); $paths = ['capture' => 'proxy/capture', 'offer' => 'proxy/offer', 'share' => 'viewer/share', 'account' => 'viewer/account']; return self::request('/integrations/v1/woocommerce/' . $paths[$action] . ($pagination ? '?' . http_build_query($pagination) : ''), $proof); } }