curl API return 401 error in Magento 2












0















I m trying to implement worldpay on a PHP site using XML direct method but whenever I try to connect I get error saying you are not authorized to view the file.. Can you tell me were you testing the payment gateway on live site.
Code:



$adminUrl="https://secure.worldpay.com/sso/public/auth/login.html?serviceIdentifier=merchantadmin";
$data = array("username" => $merchant_user, "password" => $merchant_password);
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$token = curl_exec($ch);

$token = json_decode($token);
// var_dump($token);
// echo json_encode($token);

$url = 'https://secure.worldpay.com/jsp/merchant/xml/paymentService.jsp';
$authorization = "Authorization: Bearer $token";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', $token));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xml );
$result = curl_exec($ch);
// // curl_close($ch);
echo json_encode($result);


How to solve it?
Anyone can help me to solve this
i was used this payment-gateway .










share|improve this question

























  • make sure you are using this api token url /rest/V1/integration/admin/token

    – magefms
    23 hours ago













  • I used my payment gateway administration Interface url

    – divya sekar
    23 hours ago











  • try this one $adminUrl = "127.0.0.1/your_Magento_dir/rest/V1/integration/admin/token"

    – magefms
    23 hours ago













  • assuming you are running on localhost 127.0.0.1

    – magefms
    23 hours ago











  • modify your $adminUrl value like that one

    – magefms
    23 hours ago
















0















I m trying to implement worldpay on a PHP site using XML direct method but whenever I try to connect I get error saying you are not authorized to view the file.. Can you tell me were you testing the payment gateway on live site.
Code:



$adminUrl="https://secure.worldpay.com/sso/public/auth/login.html?serviceIdentifier=merchantadmin";
$data = array("username" => $merchant_user, "password" => $merchant_password);
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$token = curl_exec($ch);

$token = json_decode($token);
// var_dump($token);
// echo json_encode($token);

$url = 'https://secure.worldpay.com/jsp/merchant/xml/paymentService.jsp';
$authorization = "Authorization: Bearer $token";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', $token));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xml );
$result = curl_exec($ch);
// // curl_close($ch);
echo json_encode($result);


How to solve it?
Anyone can help me to solve this
i was used this payment-gateway .










share|improve this question

























  • make sure you are using this api token url /rest/V1/integration/admin/token

    – magefms
    23 hours ago













  • I used my payment gateway administration Interface url

    – divya sekar
    23 hours ago











  • try this one $adminUrl = "127.0.0.1/your_Magento_dir/rest/V1/integration/admin/token"

    – magefms
    23 hours ago













  • assuming you are running on localhost 127.0.0.1

    – magefms
    23 hours ago











  • modify your $adminUrl value like that one

    – magefms
    23 hours ago














0












0








0








I m trying to implement worldpay on a PHP site using XML direct method but whenever I try to connect I get error saying you are not authorized to view the file.. Can you tell me were you testing the payment gateway on live site.
Code:



$adminUrl="https://secure.worldpay.com/sso/public/auth/login.html?serviceIdentifier=merchantadmin";
$data = array("username" => $merchant_user, "password" => $merchant_password);
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$token = curl_exec($ch);

$token = json_decode($token);
// var_dump($token);
// echo json_encode($token);

$url = 'https://secure.worldpay.com/jsp/merchant/xml/paymentService.jsp';
$authorization = "Authorization: Bearer $token";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', $token));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xml );
$result = curl_exec($ch);
// // curl_close($ch);
echo json_encode($result);


How to solve it?
Anyone can help me to solve this
i was used this payment-gateway .










share|improve this question
















I m trying to implement worldpay on a PHP site using XML direct method but whenever I try to connect I get error saying you are not authorized to view the file.. Can you tell me were you testing the payment gateway on live site.
Code:



$adminUrl="https://secure.worldpay.com/sso/public/auth/login.html?serviceIdentifier=merchantadmin";
$data = array("username" => $merchant_user, "password" => $merchant_password);
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$token = curl_exec($ch);

$token = json_decode($token);
// var_dump($token);
// echo json_encode($token);

$url = 'https://secure.worldpay.com/jsp/merchant/xml/paymentService.jsp';
$authorization = "Authorization: Bearer $token";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', $token));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xml );
$result = curl_exec($ch);
// // curl_close($ch);
echo json_encode($result);


How to solve it?
Anyone can help me to solve this
i was used this payment-gateway .







magento2 payment-gateway curl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 mins ago







divya sekar

















asked yesterday









divya sekardivya sekar

13012




13012













  • make sure you are using this api token url /rest/V1/integration/admin/token

    – magefms
    23 hours ago













  • I used my payment gateway administration Interface url

    – divya sekar
    23 hours ago











  • try this one $adminUrl = "127.0.0.1/your_Magento_dir/rest/V1/integration/admin/token"

    – magefms
    23 hours ago













  • assuming you are running on localhost 127.0.0.1

    – magefms
    23 hours ago











  • modify your $adminUrl value like that one

    – magefms
    23 hours ago



















  • make sure you are using this api token url /rest/V1/integration/admin/token

    – magefms
    23 hours ago













  • I used my payment gateway administration Interface url

    – divya sekar
    23 hours ago











  • try this one $adminUrl = "127.0.0.1/your_Magento_dir/rest/V1/integration/admin/token"

    – magefms
    23 hours ago













  • assuming you are running on localhost 127.0.0.1

    – magefms
    23 hours ago











  • modify your $adminUrl value like that one

    – magefms
    23 hours ago

















make sure you are using this api token url /rest/V1/integration/admin/token

– magefms
23 hours ago







make sure you are using this api token url /rest/V1/integration/admin/token

– magefms
23 hours ago















I used my payment gateway administration Interface url

– divya sekar
23 hours ago





I used my payment gateway administration Interface url

– divya sekar
23 hours ago













try this one $adminUrl = "127.0.0.1/your_Magento_dir/rest/V1/integration/admin/token"

– magefms
23 hours ago







try this one $adminUrl = "127.0.0.1/your_Magento_dir/rest/V1/integration/admin/token"

– magefms
23 hours ago















assuming you are running on localhost 127.0.0.1

– magefms
23 hours ago





assuming you are running on localhost 127.0.0.1

– magefms
23 hours ago













modify your $adminUrl value like that one

– magefms
23 hours ago





modify your $adminUrl value like that one

– magefms
23 hours ago










2 Answers
2






active

oldest

votes


















1
















  1. This is the Data




dataFormat = array('temp_order_id'=>$qouteId, 'MobileNumber'=>$mobileNo, 'OTP'=>$otp, 'Amount'=>$amount); $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




  1. Here I'm calling Helper function




$response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




  1. Here is the Helper function




public function getcurlDataArray($dataFormat,$username,$password,$service_url){

$ch = curl_init($service_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataFormat));
curl_setopt($ch, CURLOPT_USERPWD, $username. ":" .$password);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
$token = curl_exec($ch);
if (curl_error($ch)) {
$error_msg = curl_error($ch);
$Errorhead = 'CurlError for Url:'.$service_url.' DataFormat:'.json_encode($dataFormat);
$this->logError($Errorhead,$error_msg);
}
$response = json_decode($token,true);
return $response;
}





share|improve this answer

































    0














    dataFormat = array('temp_order_id'=>$qouteId, 'MobileNumber'=>$mobileNo, 'OTP'=>$otp, 'Amount'=>$amount); $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




    1. Here I'm calling Helper function




    $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




    1. Here is the Helper function




    public function getcurlDataArray($dataFormat,$username,$password,$service_url){

    $ch = curl_init($service_url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataFormat));
    curl_setopt($ch, CURLOPT_USERPWD, $username. ":" .$password);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
    $token = curl_exec($ch);
    if (curl_error($ch)) {
    $error_msg = curl_error($ch);
    $Errorhead = 'CurlError for Url:'.$service_url.' DataFormat:'.json_encode($dataFormat);
    $this->logError($Errorhead,$error_msg);
    }
    $response = json_decode($token,true);
    return $response;





    share|improve this answer


























    • @divya sekar, Please check this code might be it will be helpful for u

      – Umarfarooq Galibwale
      18 hours ago











    • i will tried and update u @Umar

      – divya sekar
      18 hours ago











    • no i was getting a null value @umar

      – divya sekar
      2 hours ago











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f261724%2fcurl-api-return-401-error-in-magento-2%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1
















    1. This is the Data




    dataFormat = array('temp_order_id'=>$qouteId, 'MobileNumber'=>$mobileNo, 'OTP'=>$otp, 'Amount'=>$amount); $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




    1. Here I'm calling Helper function




    $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




    1. Here is the Helper function




    public function getcurlDataArray($dataFormat,$username,$password,$service_url){

    $ch = curl_init($service_url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataFormat));
    curl_setopt($ch, CURLOPT_USERPWD, $username. ":" .$password);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
    $token = curl_exec($ch);
    if (curl_error($ch)) {
    $error_msg = curl_error($ch);
    $Errorhead = 'CurlError for Url:'.$service_url.' DataFormat:'.json_encode($dataFormat);
    $this->logError($Errorhead,$error_msg);
    }
    $response = json_decode($token,true);
    return $response;
    }





    share|improve this answer






























      1
















      1. This is the Data




      dataFormat = array('temp_order_id'=>$qouteId, 'MobileNumber'=>$mobileNo, 'OTP'=>$otp, 'Amount'=>$amount); $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




      1. Here I'm calling Helper function




      $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




      1. Here is the Helper function




      public function getcurlDataArray($dataFormat,$username,$password,$service_url){

      $ch = curl_init($service_url);
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataFormat));
      curl_setopt($ch, CURLOPT_USERPWD, $username. ":" .$password);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
      $token = curl_exec($ch);
      if (curl_error($ch)) {
      $error_msg = curl_error($ch);
      $Errorhead = 'CurlError for Url:'.$service_url.' DataFormat:'.json_encode($dataFormat);
      $this->logError($Errorhead,$error_msg);
      }
      $response = json_decode($token,true);
      return $response;
      }





      share|improve this answer




























        1












        1








        1









        1. This is the Data




        dataFormat = array('temp_order_id'=>$qouteId, 'MobileNumber'=>$mobileNo, 'OTP'=>$otp, 'Amount'=>$amount); $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




        1. Here I'm calling Helper function




        $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




        1. Here is the Helper function




        public function getcurlDataArray($dataFormat,$username,$password,$service_url){

        $ch = curl_init($service_url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataFormat));
        curl_setopt($ch, CURLOPT_USERPWD, $username. ":" .$password);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
        $token = curl_exec($ch);
        if (curl_error($ch)) {
        $error_msg = curl_error($ch);
        $Errorhead = 'CurlError for Url:'.$service_url.' DataFormat:'.json_encode($dataFormat);
        $this->logError($Errorhead,$error_msg);
        }
        $response = json_decode($token,true);
        return $response;
        }





        share|improve this answer

















        1. This is the Data




        dataFormat = array('temp_order_id'=>$qouteId, 'MobileNumber'=>$mobileNo, 'OTP'=>$otp, 'Amount'=>$amount); $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




        1. Here I'm calling Helper function




        $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




        1. Here is the Helper function




        public function getcurlDataArray($dataFormat,$username,$password,$service_url){

        $ch = curl_init($service_url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataFormat));
        curl_setopt($ch, CURLOPT_USERPWD, $username. ":" .$password);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
        $token = curl_exec($ch);
        if (curl_error($ch)) {
        $error_msg = curl_error($ch);
        $Errorhead = 'CurlError for Url:'.$service_url.' DataFormat:'.json_encode($dataFormat);
        $this->logError($Errorhead,$error_msg);
        }
        $response = json_decode($token,true);
        return $response;
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 17 hours ago









        magefms

        896220




        896220










        answered 18 hours ago









        Umarfarooq GalibwaleUmarfarooq Galibwale

        715




        715

























            0














            dataFormat = array('temp_order_id'=>$qouteId, 'MobileNumber'=>$mobileNo, 'OTP'=>$otp, 'Amount'=>$amount); $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




            1. Here I'm calling Helper function




            $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




            1. Here is the Helper function




            public function getcurlDataArray($dataFormat,$username,$password,$service_url){

            $ch = curl_init($service_url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataFormat));
            curl_setopt($ch, CURLOPT_USERPWD, $username. ":" .$password);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
            $token = curl_exec($ch);
            if (curl_error($ch)) {
            $error_msg = curl_error($ch);
            $Errorhead = 'CurlError for Url:'.$service_url.' DataFormat:'.json_encode($dataFormat);
            $this->logError($Errorhead,$error_msg);
            }
            $response = json_decode($token,true);
            return $response;





            share|improve this answer


























            • @divya sekar, Please check this code might be it will be helpful for u

              – Umarfarooq Galibwale
              18 hours ago











            • i will tried and update u @Umar

              – divya sekar
              18 hours ago











            • no i was getting a null value @umar

              – divya sekar
              2 hours ago
















            0














            dataFormat = array('temp_order_id'=>$qouteId, 'MobileNumber'=>$mobileNo, 'OTP'=>$otp, 'Amount'=>$amount); $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




            1. Here I'm calling Helper function




            $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




            1. Here is the Helper function




            public function getcurlDataArray($dataFormat,$username,$password,$service_url){

            $ch = curl_init($service_url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataFormat));
            curl_setopt($ch, CURLOPT_USERPWD, $username. ":" .$password);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
            $token = curl_exec($ch);
            if (curl_error($ch)) {
            $error_msg = curl_error($ch);
            $Errorhead = 'CurlError for Url:'.$service_url.' DataFormat:'.json_encode($dataFormat);
            $this->logError($Errorhead,$error_msg);
            }
            $response = json_decode($token,true);
            return $response;





            share|improve this answer


























            • @divya sekar, Please check this code might be it will be helpful for u

              – Umarfarooq Galibwale
              18 hours ago











            • i will tried and update u @Umar

              – divya sekar
              18 hours ago











            • no i was getting a null value @umar

              – divya sekar
              2 hours ago














            0












            0








            0







            dataFormat = array('temp_order_id'=>$qouteId, 'MobileNumber'=>$mobileNo, 'OTP'=>$otp, 'Amount'=>$amount); $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




            1. Here I'm calling Helper function




            $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




            1. Here is the Helper function




            public function getcurlDataArray($dataFormat,$username,$password,$service_url){

            $ch = curl_init($service_url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataFormat));
            curl_setopt($ch, CURLOPT_USERPWD, $username. ":" .$password);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
            $token = curl_exec($ch);
            if (curl_error($ch)) {
            $error_msg = curl_error($ch);
            $Errorhead = 'CurlError for Url:'.$service_url.' DataFormat:'.json_encode($dataFormat);
            $this->logError($Errorhead,$error_msg);
            }
            $response = json_decode($token,true);
            return $response;





            share|improve this answer















            dataFormat = array('temp_order_id'=>$qouteId, 'MobileNumber'=>$mobileNo, 'OTP'=>$otp, 'Amount'=>$amount); $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




            1. Here I'm calling Helper function




            $response = $helper->getcurlDataArray($dataFormat,"username" => $merchant_user,"password" => $merchant_password, $adminUrl);




            1. Here is the Helper function




            public function getcurlDataArray($dataFormat,$username,$password,$service_url){

            $ch = curl_init($service_url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dataFormat));
            curl_setopt($ch, CURLOPT_USERPWD, $username. ":" .$password);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
            $token = curl_exec($ch);
            if (curl_error($ch)) {
            $error_msg = curl_error($ch);
            $Errorhead = 'CurlError for Url:'.$service_url.' DataFormat:'.json_encode($dataFormat);
            $this->logError($Errorhead,$error_msg);
            }
            $response = json_decode($token,true);
            return $response;






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 18 hours ago









            magefms

            896220




            896220










            answered 18 hours ago









            Umarfarooq GalibwaleUmarfarooq Galibwale

            715




            715













            • @divya sekar, Please check this code might be it will be helpful for u

              – Umarfarooq Galibwale
              18 hours ago











            • i will tried and update u @Umar

              – divya sekar
              18 hours ago











            • no i was getting a null value @umar

              – divya sekar
              2 hours ago



















            • @divya sekar, Please check this code might be it will be helpful for u

              – Umarfarooq Galibwale
              18 hours ago











            • i will tried and update u @Umar

              – divya sekar
              18 hours ago











            • no i was getting a null value @umar

              – divya sekar
              2 hours ago

















            @divya sekar, Please check this code might be it will be helpful for u

            – Umarfarooq Galibwale
            18 hours ago





            @divya sekar, Please check this code might be it will be helpful for u

            – Umarfarooq Galibwale
            18 hours ago













            i will tried and update u @Umar

            – divya sekar
            18 hours ago





            i will tried and update u @Umar

            – divya sekar
            18 hours ago













            no i was getting a null value @umar

            – divya sekar
            2 hours ago





            no i was getting a null value @umar

            – divya sekar
            2 hours ago


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f261724%2fcurl-api-return-401-error-in-magento-2%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What other Star Trek series did the main TNG cast show up in?

            Berlina muro

            Berlina aerponto