api_key = preg_replace('/^mw_/', '', trim($api_key)); $this->endpoint = rtrim($base_url, '/') . '/api/v1/send'; } public function send($to, $amount, $currency, $request_id = '', $ip_address = '') { $post = array( 'api_key' => $this->api_key, 'to' => $to, 'amount' => $amount, 'currency' => strtoupper($currency), ); if ($request_id !== '') { $post['request_id'] = $request_id; } if ($ip_address !== '') { $post['ip_address'] = $ip_address; } $ch = curl_init($this->endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $response = curl_exec($ch); $error = curl_error($ch); curl_close($ch); if ($response === false) { return array('status' => 500, 'message' => $error); } $json = json_decode($response, true); return is_array($json) ? $json : array('status' => 500, 'message' => 'Invalid API response'); } }