0

I am using event customer_register_success for sending customer detail to a third party website. I am facing problem in implementation of CURL in event observer. Do you have any example of using CURL in a magento 2 observer?

  • Can you specify which error you are facing? – Dhiren Vasoya Apr 20 '18 at 12:24
1

I dont think its a good practice but you can follow below code in you observer for your requirement.

$ch = curl_init();

//pass your arguments in array
$request = array(
    'USER' => $user,
    'PWD' => $pwd,
    'SIGNATURE' => $signature,
    'METHOD' => 'RefundTransaction',
    'VERSION' => urlencode($version)
);
$api = "Your Api Url here";
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request));

//here curl request will be sent

$curlResponse = curl_exec($ch);

You can get your response in $curlResponse

Thankx

  • 1
    +1 for "not good practise" ;) the better way imho would be to implement a cronjob that sends this data every 5 minutes or so – simonthesorcerer Apr 20 '18 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.