Code examples
There's no published SDK package yet — every example below is a plain HTTP call you can copy into your own codebase.
JavaScript / TypeScript
login.ts
const API_BASE = 'https://api.boyasa.com/api';
async function login(identifier: string, password: string) {
const res = await fetch(`${API_BASE}/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ identifier, password, rememberMe: true }),
});
if (!res.ok) throw new Error((await res.json()).message);
return res.json(); // { sessionId, phone }
}
async function verifyOtp(sessionId: string, phone: string, code: string) {
const res = await fetch(`${API_BASE}/auth/login/verify-otp`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sessionId, phone, code }),
});
if (!res.ok) throw new Error((await res.json()).message);
return res.json(); // { accessToken, refreshToken, user }
}
async function createPackageOrder(accessToken: string, order: Record<string, unknown>) {
const res = await fetch(`${API_BASE}/packages/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify(order),
});
if (!res.ok) throw new Error((await res.json()).message);
return res.json();
}PHP
This mirrors the request pattern used internally by the WooCommerce plugin.
boyasa-client.php
<?php
class BoyasaClient {
private string $api_url;
private string $access_token;
public function __construct(string $api_url, string $access_token) {
$this->api_url = rtrim($api_url, '/');
$this->access_token = $access_token;
}
private function request(string $endpoint, string $method = 'GET', array $data = []) {
$args = [
'method' => $method,
'headers' => [
'Authorization' => 'Bearer ' . $this->access_token,
'Content-Type' => 'application/json',
],
'timeout' => 30,
];
if (!empty($data) && in_array($method, ['POST', 'PUT', 'PATCH'])) {
$args['body'] = wp_json_encode($data);
}
$response = wp_remote_request($this->api_url . $endpoint, $args);
if (is_wp_error($response)) {
return ['success' => false, 'error' => $response->get_error_message()];
}
return json_decode(wp_remote_retrieve_body($response), true);
}
public function create_package_order(array $order) {
return $this->request('/packages/create', 'POST', $order);
}
public function get_order(string $order_id) {
return $this->request('/packages/' . $order_id, 'GET');
}
}