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";