Discussions

Ask a Question
Back to All

PHP Example of /v3/auth/payment_requests/address

Long time trying to make a working solution. Now I have it and want to share, maybe help someone.

$client = new \GuzzleHttp\Client();

        $post_data = array(
            "currency"     => "usdt",
            "blockchain"   => "trx",
            "callback_url" => YOUR_CALLBACK_URL,
        );

        $nonce = strval(date_timestamp_get(date_create()) * 1000);
        $body  = json_encode($post_data);

        $signatureString = '/v3/auth/payment_requests/address' . $nonce . $body;
        $public_key = YOUR_PUBLIC_KEY;
        $secret_key = YOUR_SECRET_KEY;
        $signature = hash_hmac("sha384", $signatureString, $secret_key);

        $headers = array(
            'Content-Type' => 'application/json',
            'kun-nonce' => $nonce,
            'kun-apikey' => $public_key,
            'kun-signature' => $signature,
        );

        $response = $client->request('POST', 'https://api.kuna.io/v3/auth/payment_requests/address', [
            'body' => $body,
            'headers' => $headers,
        ]);

        echo '<pre>' . print_r( json_decode($response->getBody()->getContents(), true), true ) . '</pre>';
        die();