The LemonWay API (called Directkit) has two implementations: DirectkitJson2 and DirectkitXml. There are different ways to call the service depends on the implementation you chose.
The best way to access to directkitJson2 is to use the curl_init
function to send POST request to the DirectkitJson2 service.
It is the simplest and the most network-efficient way.
If you don't like the json format, you can also send SOAP (XML) requests to DirectkitXml, you can do it in 3 different ways:
- SoapClient: the casual method in PHP to consume any Web Service. It is the simplest way to access to SOAP request.
- SoapClient SDK: same with the first method, but all the structure of requests / responses are generated overhead with
wsdl2phpgenerator
- LemonWay SDK: call the web service as a normal http request
curl_init
. The SDK will help you to parse the SOAP response.
This example demonstrates the second method.
In order to use SoapClient
, you have to activate the following extensions in php.ini
extension=php_soap.dll
(Windows) orsoap.so
(Linux)extension=php_openssl.dll
(Windows) oropenssl.so
(Linux)
We will use wsdl2phpgenerator client
to generate the LemonWay Stubs:
php wsdl2phpgenerator-2.5.5.phar -i https://ws.lemonway.fr/mb/YOUR_COMPANY/dev/directkitxml/service.asmx?wsdl -o .\directkitxml -n Directkit
this command will generate the PHP classes corespond to all requests / response of the Lemonway Directkit API
The stubs are created in the directkitxml
folder with the namespace Directkit
. Feel free to change them as your needs but NEVER modify the generated stubs.
You have to generate these Stubs for each update of the LemonWay API.
require_once __DIR__.'/directkitxml/Service_mb_xml.php';
$client = new Directkit\Service_mb_xml(array("trace"=>true), DIRECTKIT_WS."?wsdl");
$param = new Directkit\GetWalletTransHistory(null, null, null, null, null, null, null, null, null);
$param->wlLogin = LOGIN;
$param->wlPass = PASSWORD;
$param->language = "fr";
$param->version = VERSION;
$param->walletIp = getUserIP();
$param->walletUa = UA;
$param->wallet = "8888";
$response = $client->GetWalletTransHistory($param);
//print the response
echo "<pre>".json_encode($response, JSON_PRETTY_PRINT)."</pre>";
//you can access to $response->GetWalletTransHistoryResult->TRANS->HPAY
See also: LemonWay API documentation / method GetWalletTransHistory
(Please refer to the SoapClient manual for more information)
The SoapClient relies upon the WebService description (WSDL) to validate every SOAP requests and parse the SOAP responses. Your PHP Server will download and cache the WSDL in the first call.
You must to keep your WSDL cache in sync with the WebService.
If you got
Fatal error: Uncaught SoapFault exception...
In most case, it means that your cached WSDL is outdated, please refresh the cache using one of the following methods. Don't forget to re-generate the SDK stub as above.
In php.ini
you can configure the cache folder and the expire time (ttl) of the WSDL cache or disable it completly.
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
You can force refresh the cache by deleting every wsdl-*
files in the folder wsdl_cache_dir
. No need to restart your PHP Server
Please refer to the SoapClient configuration for more information
- Disable cache usage:
ini_set("soap.wsdl_cache_enabled", 0);
- Redefine the expire time to 10 seconds so the cache will refreshed sooner / more frequently:
ini_set("soap.wsdl_cache_ttl", 10);