Am having issues with the below php code snippet, am new to PHP

Viewed 28
<?php

    if (isset($_POST['variable'])) {
        function generateRandomString($length = 10) {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
        }
    
    
        require('vendor/Autoload.php');
        $msisdn     = 999144026;
        $tamount    = 500;
        $ccode      = "MW";
        $currency   = "MWK";
        $auth       = "[enter image description here][1]";
        $transID    = generateRandomString();
        //$msg        = "";
    
    
            $headers = array(
                'Content-Type' => 'application/json',
                'X-Country' => $ccode,
                'X-Currency' => $currency,
                'Authorization'  =>  $auth,
            );
            $client = new GuzzleHttpClient();
            // Define array of request body.
            $request_body = array(
                  'reference' :  'Testing transaction',
                  "subscriber": {
                    "country": $ccode,
                    "currency": $currency,
                    "msisdn": $msisdn
                  },
                  "transaction": {
                    "amount": $tamount,
                    "country": $ccode,
                    "currency": $currency,
                    "id": $transID
                  }
        
            );
            try {
                $response = $client>request('POST','https://openapiuat.airtel.africa/merchant/v1/payments/', array(
                    'headers' => $headers,
                    'json' => $request_body,
                   )
                );
                echo = print_r($response->getBody()->getContents());
             }
             catch (GuzzleHttpExceptionBadResponseException $e) {
                // handle exception or api errors.
                echo = print_r($e->getMessage());
             }
    }
    ?>
0 Answers
Related