0

I am implementing a payment gateway for transferring airtime as well as mobile money from an api written in php. There is an http post endpoint for the airtime and an https endpoint for the mobile money transfer. When i execute the http endpoint for the airtime I get response from the api server. However, i receive no response when i make an api call to the https endpoint for the mobile money. When i use postman to hit the https endpoint, it gives me the correct response but does not work on my live environment. Below is the curl function I am using

`

function call_api($MERCHANT_KEY,$MERCHANT_TOKEN,$SERVICE_NAME,$MERCHANT_REFERRENCE,$SERVICE_DETAILS,$API_URL) {
   try{
        $request = curl_init($API_URL);
        $request_params = array(
        "merchantKey"  =>  $MERCHANT_KEY,
        "merchantToken" => $MERCHANT_TOKEN,
        "serviename"  =>  $SERVICE_NAME,
        "merchantreference" => $MERCHANT_REFERRENCE,
        "serviceDetails" => $SERVICE_DETAILS
        );
        curl_setopt($request, CURLOPT_POST, true);
        curl_setopt($request,CURLOPT_POSTFIELDS, json_encode($request_params));
        curl_setopt($request, CURLOPT_HTTPHEADER, array(
            "Content-type: application/json"
            )
        );
        curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
        $feedback = curl_exec($request);

        curl_close($request);
        return $feedback;
    }
    catch(Exception $ex){
        echo "API IS NOT WORKING";
    }


//END OF API CALL
}

`

Below is my code implementation for the airtime endpoint

`

$SERVICE_NAME='airtime';
                    $AMOUNT=2.00;
                    //CALL THE API
                    $MERCHANT_KEY = '1C60809F-4F6B-4404-BB46-738F5A365B5F';
                    $MERCHANT_TOKEN = '777402A0-1166-4307-9C88-7C65475321B2';
                    $MERCHANT_REFERRENCE = date("YmdHis");
                    $TRANSACTION_ID=date("YmdHis");
                    $SERVICE_DETAILS="{'amount': '".$AMOUNT."','network': '".$NETWORK."','mobileNumber': '".$MSISDN."','transId':'".$TRANSACTION_ID."'}"; 
                    $API_URL = 'http://196.216.228.23/ApiHubtest/api/myghpayextension/paymentRequest';
                    $feedback=call_api($MERCHANT_KEY, $MERCHANT_TOKEN,$SERVICE_NAME,$MERCHANT_REFERRENCE,$SERVICE_DETAILS,$API_URL);

                    //DECODE THE RESPONSE AND SAVE IN A TABLE
                    $obj = json_decode($feedback);
                    $STATUS=$obj->{'Status'};
                    if($STATUS==1){
                        //SAVE API CALL DETAILS
                        $apisave="INSERT INTO payment_details SET code='$CODE', status='$STATUS', transactionid='API_FAILED'";
                        $conn->query($dbconnection,$apisave);
                        $RESPONSE="API_FAILED";
                    }elseif($STATUS==0){
                        $MESSAGE=$obj->{'Message'};
                        //$TRANSACTION_ID=$obj->{'transactionid'};

                        //SAVE API CALL DETAILS
                        $apisave="INSERT INTO payment_details SET code='$CODE', status='$STATUS', transactionid='$TRANSACTION_ID'";
                        $conn->query($dbconnection,$apisave);

                        //UPDATE THE STAFF RECORDS
                        $updsub="SELECT * FROM promo_subs WHERE MSISDN='$MSISDN'";
                        $updsubrun=$conn->query($dbconnection,$updsub);
                        if($conn->sqlnum($updsubrun)==0){
                            $inssub="INSERT INTO promo_subs(msisdn,creditrating,lastplayed) VALUES ('$MSISDN',1,'$dateTime')";
                            $conn->query($dbconnection,$inssub);

                        }else{
                            $updsub="UPDATE promo_subs SET creditrating=(creditrating + 1), lastplayed='$dateTime' WHERE msisdn='$MSISDN'";
                            $conn->query($dbconnection,$updsub);
                        }

                        $RESPONSE="OK";

                    }

And this is the code implementation for the mobile money transfer <pre>

$SERVICE_NAME='creditwallet'; $AMOUNT=1.00; //CALL THE API $MERCHANT_KEY = 'BBA81A2F-E9E3-46FB-9E89-6B8A0EABF26E'; $MERCHANT_TOKEN = '59E00F9D-F98F-4348-B221-E7DFA79A445F'; $MERCHANT_REFERRENCE = date("YmdHis"); $TRANSACTION_ID=date("YmdHis"); $SERVICE_DETAILS="{'amount': '".$AMOUNT."','network': '".$NETWORK."','mobileNumber': '".$MSISDN."','transId':'".$TRANSACTION_ID."','ReferecnceID':'".$TRANSACTION_ID."','remarks':'CREDIT Wallet'}"; $API_URL = "https://196.216.228.129/apihub/api/myghpayextension/paymentRequest"; echo $feedback=call_api($MERCHANT_KEY, $MERCHANT_TOKEN,$SERVICE_NAME,$MERCHANT_REFERRENCE,$SERVICE_DETAILS,$API_URL); //DECODE THE RESPONSE AND SAVE IN A TABLE $obj = json_decode($feedback); $STATUS=$obj->{'Status'}; if($STATUS==0){ //SAVE API CALL DETAILS $apisave="INSERT INTO payment_details SET code='$CODE', status='$STATUS', transactionid='API_FAILED'"; $conn->query($dbconnection,$apisave); $RESPONSE="API_FAILED"; }elseif($STATUS==1){ $MESSAGE=$obj->{'Message'}; //$TRANSACTION_ID=$obj->{'transactionid'}; //SAVE API CALL DETAILS $apisave="INSERT INTO payment_details SET code='$CODE', status='$STATUS', transactionid='$TRANSACTION_ID'"; $conn->query($dbconnection,$apisave); //UPDATE THE STAFF RECORDS $updsub="SELECT * FROM promo_subs WHERE MSISDN='$MSISDN'"; $updsubrun=$conn->query($dbconnection,$updsub); if($conn->sqlnum($updsubrun)==0){ $inssub="INSERT INTO promo_subs(msisdn,creditrating,lastplayed) VALUES ('$MSISDN',1,'$dateTime')"; $conn->query($dbconnection,$inssub); }else{ $updsub="UPDATE promo_subs SET creditrating=(creditrating + 1), lastplayed='$dateTime' WHERE msisdn='$MSISDN'"; $conn->query($dbconnection,$updsub); } $RESPONSE="OK";
N. Felix
  • 69
  • 1
  • 10

1 Answers1

0

Have you tried adding

CURLOPT_SSL_VERIFYPEER set to false

and

CURLOPT_SSL_VERIFYHOST set to false

?

If it works, just note that there are some caveats to run it in production, pointed here: https://stackoverflow.com/a/26641565

  • Error: 51 Errormessage: SSL: no alternative certificate subject name matches target host name '196.216.228.129' . This is the error message I am getting from my curl. Any assistance please? – N. Felix Feb 24 '19 at 02:44
  • don't start with that, start with replacing ```curl_exec($ch)``` with ```if(false===curl_exec($ch)){throw new \RuntimeException("curl_exec() failed: ".curl_errno($ch).": ".curl_error($ch);}``` and replace ```curl_setopt($ch,...);``` with ```if(true!==curl_setopt($ch,...)){throw new \RuntimeException("curl_setopt() failed!";}``` and see where you get exceptions. – hanshenrik Feb 24 '19 at 13:02
  • I'm afraid that the server doesn't contain a certificate with alternative host name for an IP based call. At least, that's how I see it from your comment. What if you try to set `CURLOPT_SSL_VERIFYHOST` to `false` as well? – emanuelpoletto Feb 24 '19 at 13:23