I wrote a script integrating ID broker with WooCommerce.
After a successful purchase in the store, the broker ID authentication process should begin and the Broker ID link should be downloaded and displayed on the thank you for your purchase
page.add_action('woocommerce_before_thankyou', '');
function after_purchase_completed($order_id) {
$order = wc_get_order($order_id);
$process_id = 'AUT_' . $order->get_order_number() . '_' . uniqid();
$data = array(
'identification_channel_id' => '651d17427587d47324c683e3',
'state' => $process_id,
);
$username = 'API Client';
$password = 'API Key';
$auth_token = base64_encode($username . ':' . $password);
$response = wp_remote_post('http://i.broker.id/api/v1.0/oauth2/authorize', array(
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'Basic ' . $auth_token
),
'body' => json_encode($data)
));
if (!is_wp_error($response)) {
$response_code = wp_remote_retrieve_response_code($response);
$response_body = wp_remote_retrieve_body($response);
$error_message = '';
if ($response_code !== 200) {
$error_message = ' Error code: ' . $response_code . '. Error message: ' . $response_body;
}
$result = json_decode($response_body, true);
if (isset($result['link'])) {
echo '<p>URL: <a href="' . $result['link'] . '">' . $result['link'] . '</a></p>';
} else {
echo '<p>Sorry, the Broker ID authorization link could not be retrieved. Contact us for help.' . $error_message . '</p>';
}
} else {
echo '<p>Sorry, there was a problem retrieving your Broker ID authorization link. Contact us for help.' . $error_message . '</p>';
}
}
of course, I provide the correct data in place of Api Client and Api Key. I get an error:
Sorry, the Broker ID authorization link could not be retrieved. Contact us for help. Error code: 401. Error message: {„timestamp”:”2024-05-05T15:00:53.172684169+02:00[Europe/Warsaw]”,”exceptionId”:”bad.credentials”,”traceId”:”66378305d5ef962325c0e06ec7ca4c97″,”errorCode”:”66378305d5ef962325c0e06ec7ca4c97″,”message”:”Bad Authorization”}
I use Broker ID documentation:
https://i.broker.id/documentation/documentation/resources/swagger-ui/index.html#/
Can someone tell me where I’m making a mistake?