phplaraveltwinfield

twinfield API integration with laravel


Twinfield is an online financial accounting software package for small and medium enterprises, produced and maintained by Twinfield International, based in The Netherlands. It is used by over 15,000 subscribers in 20 countries.

I want to integrate its API. I have install laravel and create some basic API, but its huge. How and where the integration example links? Please help me.


Solution

  • This is not the full code but gives you the login for the twinfield. I am also stuck because many libraries are given for twinfield but not give any sample code for it. There is no document provide for PHP integration. I am very disappointed with twinfield. Even if you have test account and it will disable than it will permanent disable. Here the jsonresponse is custom made so you can call only $e->getMessage() if you have any error related it.

    public function login(\Illuminate\Http\Request $request){
            $user = $request->input('user');
            $password = $request->input('password');
            $org = $request->input('organisation');
    
            $params = array(
                'user' => $user,
                'password' => $password,
                'organisation' => $org 
            );
            // login => Set the param array and send to the logon
            try
            {
                $session = new \SoapClient("https://login.twinfield.com/webservices/session.asmx?wsdl", array('trace' => 1));
                $result = $session->logon($params);
                // echo '<pre>';print_r($result);
                $cluster = $result->cluster;
                $qq = new domDocument();
                $qq->loadXML($session->__getLastResponse());
                $sessionID = $qq->getElementsByTagName('SessionID')->item(0)->textContent;
                //echo $sessionID;
                $newurl = $cluster . '/webservices/processxml.asmx?wsdl';
                try
                {
                    $client = new \SoapClient($newurl);
                    $data = new \SoapHeader('http://www.twinfield.com/', 'Header', array('SessionID'=> $sessionID));
                    $jsonResponse = JsonResponse::success($data);
                }
                catch (SoapFault $e)
                {
                    $jsonResponse = empty($e->getMessage()) ? JsonResponse::error(class_basename($e)) : JsonResponse::error($e->getMessage());
                }
            }
            catch (SoapFault $e)
            {
                $jsonResponse = empty($e->getMessage()) ? JsonResponse::error(class_basename($e)) : JsonResponse::error($e->getMessage());
            }
            return $jsonResponse;
        }
    

    Some code are given in this link too. You will integrate it via https://github.com/php-twinfield/twinfield but you have to work a lot. I am also working on it, if anything you need plz let me know.