Use SoapClient in cakephp

Hello everyone, how to use this php code in cakephp 3 by passing the variables?

<?php

 ini_set("soap.wsdl_cache_enabled", 0); 
 $url="https://www.paiementpro.net/webservice/OnlineServicePayment_v2.php?wsdl"; 
 $client = new SoapClient($url,array('cache_wsdl' => WSDL_CACHE_NONE)); 
 $array=array( 'merchantId'=>'PP-F105', 
 'countryCurrencyCode'=>'952', 
 'amount'=>1000, 
 'customerId'=>1, 
 'channel'=>'CARD', 
 'customerEmail'=>'t@t.ci', 
 'customerFirstName'=>'Thierry', 
 'customerLastname'=>'Narcisse', 
 'customerPhoneNumber'=>'22507517917', 
 'referenceNumber'=>'878AABCDEFZ'.time(), 
 'notificationURL'=>'http://test.ci/notification/', 
 'returnURL'=>'http://test.ci/return/', 
 'description'=>'achat en ligne', 
 'returnContext'=>'test=2&ok=1&oui=2',
  );
 try{ 
 $response=$client->initTransact($array); 
if($response->Code==0){

//var_dump($response->Sessionid);die();

header("Location:https://www.paiementpro.net/webservice/onlinepayment/processing_v2.php?sessionid=".$response->Sessionid);

}

  }
   catch(Exception $e)
  { 
  echo $e->getMessage();
   }
?>

Hi Yves,

It should work. I have implemented the SoapClient recently in a project. Have you tried to execute this code?

The main difference or thing I would suggest is to add the right import:

use SoapClient;

Saludos,

When I run this single code in a php file it works fine, but in a controller under cakephp I get no response.

should I create a controller action template file containing the code?
Should I enter the code in a controller or single action in a template file? I am new to cakephp and I use version 3.8
Thank you for helping me.

That would depend on your project. In my case, since I invoke this kind of code from scheduled shells, I make the calls inside my model.

But I should clarify that you should never put this kind of code in a template file. This is not code suitable for a view.

Saludos,

can you give me some guidelines to adapt the code of the file to my project in cakephp. In fact, this project consists of subscribing to offers and then making payments via the code in the file.
I beg you to guide me. thank you

As far as I know, you could begin by:

  1. Defining where to put the code. Wich model or controller should be responsible for this behavior
  2. Then, add the dependency to that class:

use SoapClient;

  1. Create a method that does the job
  2. Put your code in that method

Saludos,

Thank you. I followed all of your instructions and it works but I see that there is no redirect to the payout site. And I see that it is at the level of
header("Location:https://www.paiementpro.net/webservice/onlinepayment/processing_v2.php?sessionid=".$response->Sessionid);

the redirection is not done. How can I adapt this redirect code to cakephp?
Thank you for you precious help

You’re asking how to redirect to a different URL in Cake3?

thank you I will come back to you