Giter Club home page Giter Club logo

twinfield's Introduction

[DEPRECATED] Twinfield Build Status

This library is moved to https://github.com/php-twinfield/twinfield.

A PHP library for Twinfield Integration. Developed by Remco Tolsma and Leon Rowland from Pronamic. Use the Twinfield SOAP Service to have your PHP application communicate directly with your Twinfield account.


Autoloading

The classes follow the PSR2 naming convention.

Usage

General Usage Information

Components will have Factories to simplify the request and send process of Twinfield. Each factory will require just the \Pronamic\Twinfield\Secure\Config() class with the filled in details.

An example of the usage of the Configuration class.

$config = new \Pronamic\Twinfield\Secure\Config();
$config->setCredentials('Username', 'Password', 'Organization', 'Office');
  • or, when using OAuth:
$config = new \Pronamic\Twinfield\Secure\Config();
$config->setOAuthParameters('clientID', 'clientSecret', 'returnURL', 'Organization', 'Office', true);
//the true parameter at the end tells the system to automatically redirect to twinfield to login

Now, to the current modules

In the following example, we will use the Customer component as showcase. Although this will be the method for all components ( including Invoice currently )

Typically it is as follows, if using the Factories

  • Add/Edit: Make Object, Make Factory, Give object in Submit method of related factory.
  • Retrieve: Make Factory, Supply all required params to respective listAll() and get() methods

Add/Edit

Make your Customer object

$customer = new \Pronamic\Twinfield\Customer\Customer();
$customer
	->setID(10666)
	->setName('Leon Rowland')
	->setType('DEB')
	->setWebsite('http://leon.rowland.nl')
	->setEBilling(true)
	->setEBillMail('[email protected]')
	->setVatCode('VL')
	->setDueDays(10)
	->setCocNumber('12341234');

Customers can have addresses associated with them

$customerAddress = new \Pronamic\Twinfield\Customer\CustomerAddress();
$customerAddress
	->setDefault(false)
	->setType('invoice')
	->setField1('Testing field 1')
	->setField2('Testing field 2')
	->setField3('Testing field 3')
	->setPostcode('1212 AB')
	->setCity('TestCity')
	->setCountry('NL')
	->setTelephone('010-12345')
	->setFax('010-1234')
	->setEmail('[email protected]');

Assign that address to the customer

$customer->addAddress($customerAddress);

Now lets submit it!

use \Pronamic\Twinfield\Customer as TwinfieldCustomer;

// Config object prepared and passed to the CustomerFactory
$customerFactory = new TwinfieldCustomer\CustomerFactory($config);

//$customer = new TwinfieldCustomer\Customer();

// Attempt to send the Customer document
if($customerFactory->send($customer)){
	// Use the Mapper to turn the response back into a TwinfieldCustomer\Customer
	$successfulCustomer = TwinfieldCustomer\Mapper\CustomerMapper::map($customerFactory->getResponse());
}

Retrieve/Request

You can get all customers or get a single one currently.

use \Pronamic\Twinfield\Customer as TwinfieldCustomer;

// Config object prepared and passed into the CustomerFactory
$customerFactory = new TwinfieldCustomer\CustomerFactory($config);

$customers = $customerFactory->listAll();

At the moment, listAll will return an array of just name and short name.

$customer = $customerFactory->get('customerCode', 'office[optional]');

The response from get() will be a \Pronamic\Twinfield\Customer\Customer object.

Notes

Advanced documentation coming soon. Detailing usage without the Factory class. Giving you more control with the response and data as well as more in-depth examples and usage recommendations.

Contribute

You can contribute to the development of this project. Try and keep to the way of doing things as the other 2 components have implemented.

A large requirement is to maintain backwards compatibility so if you have any plans for large restructure or alteration please bring up in an issue first.

Component get() listAll() send() Mapper Namespace
Customer Pronamic/Twinfield/Customer
Sales Invoices Pronamic/Twinfield/Invoice
Transactions: Purchase Sale Pronamic/Twinfield/Transaction
Articles Pronamic/Twinfield/Article
Balance Sheets Pronamic/Twinfield/BalanceSheet
Suppliers Pronamic/Twinfield/Supplier
Dimension Groups Pronamic/Twinfield/Dimension/Group
Dimension Types Pronamic/Twinfield/Dimension/Type
Offices Pronamic/Twinfield/Office
Vat types Pronamic/Twinfield/VatCode

Build

  • npm install
  • composer install

Links

Authors

License

Copyright 2009-2013 Pronamic.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

twinfield's People

Contributors

arnoutdemooij avatar emilebons avatar mastercoding avatar mmolhoek avatar muhammedeminakbulut avatar nannehuiges avatar nodiscipline avatar remcotolsma avatar rvanlaarhoven avatar stephangroen avatar tnajanssen avatar tuesdaymultimedia avatar vswarte avatar zogot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twinfield's Issues

Freetext fields in the Transaction is not supported by the api

I get this error message.

<freetext1 msgtype="error" msg="Kostenplaats is niet toegestaan in de koptekst." result="0" /><freetext2 msgtype="error" msg="Uw referentie is niet toegestaan in de koptekst." result="0" /><freetext3 msgtype="error" msg="Extra omschrijving is niet toegestaan in de koptekst." result="0" />

Error on single result from listAll() in OfficeFactory

When using the officeFactory listAll method, an error occurs when only 1 result is returned from Twinfield:

    $officeFactory = new \Pronamic\Twinfield\Office\OfficeFactory($config);
    $officeFactory->listAll();

ErrorException in OfficeFactory.php line 45: Trying to get property of non-object

This happens because the returned value from the Finder is not an array when only a single item is found, but instead the item is returned directly. We can fix this with something like the code below:

    public function listAll($pattern = '*', $field = 0, $firstRow = 1, $maxRows = 100, $options = array())
    {
        $response = $this->searchFinder(self::TYPE_OFFICES, $pattern, $field, $firstRow, $maxRows, $options);
        $offices = [];
        // If a single item is returned, encapsulate in an array to allow further processing, this also
        // allows to always return an array of offices like specified
        $result = $response->data->Items->ArrayOfString;
        if(count($result) == 1) {
            $result = [$result];
        }
        foreach($response->data->Items->ArrayOfString as $officeArray)
        {
            $office = new Office();
            $office->setCode($officeArray->string[0]);
            $office->setCountryCode($officeArray->string[2]);
            $office->setName($officeArray->string[1]);
            $offices[] = $office;
        }
        return $offices;
    }

If you like, I can submit a PR to fix this.

Laravel providers

I'm facing a bunch of projects that seem to have Laravel as their primary framework. Do you guys mind if I publish the providers I wrote for this library? ( In a different repository ).

It essentially just glues this project to Laravel's DI container, allowing for IoC.
Docs found here: https://laravel.com/docs/5.2/container

I obviously don't intend to redistribute any of your code. Just my wrapper around the library to allow for things like Facades, simplifying the usage of the library when used in combination with Laravel.

Implement Suppliers / Refactor Customer

I found myself in the situation where I need to read and insert suppliers. For as far as I can see, there are minor changes to be made to customer (if any at all) in order to allow for this.

I believe it's possible to override the $dimType in CustomerFactory.php L117. However it kinda throws me off having to fetch the suppliers using the CustomerFactory class.

Can we get a more general name? Or refactor most of Customer's mapping to a super class and have a new Supplier class extend it?

TransactionLine not added correctly

Hello,

When I use the transaction addLine function, something is going wrong and I can't figure out what.

I'm using this code:

$transaction = new \Pronamic\Twinfield\Transaction\Transaction();
$transactionLine = new \Pronamic\Twinfield\Transaction\TransactionLine();
$transaction
->setDestiny("temporary")
->setOffice("1234567")
->setCode("MEMO")
->setCurrency("EUR")
->setDate("20140505")
->setPeriod("2014/05");

$transactionLine
->setType("detail")
->setDim1("8000")
->setValue("1855.45")
->setDebitCredit("credit")
->setDescription("Omzet 21% ideal")
->setVatCode("VH");
$transaction->addLine($transactionLine);
print_r($transaction->getLines());

$transactionLine
->setType("detail")
->setDim1("1401")
->setValue("2245.09")
->setDebitCredit("debit")
->setDescription("iDeal betaling")
->setVatCode(null);
$transaction->addLine($transactionLine);
print_r($transaction->getLines());

The first time printing the transaction->getLines, it shows me the lines array with only one item and the item just entered.
The second time printing the transaction->getLines, shows me the lines array with two items. However both items in the array contain the same data, which is the latest added line.

I really don't understand why.. Help appreciated.

login

Hi,
When i use the oauth way of signing in to twinfield i get an error in the login file.
It says that the function print_pre on line 106 in Twinfield\Secure\login.php isnt found.
I cant find anything else on the function either.
Can you help me with this error?

regards

How to add options to the VatCodeFactory (FinderFactory)

When using the VatCodeFactory (or another that uses the Finder), you can see the $options argument. I tried to add the option 'office', because the Finder needs this. Without it, it will use the default office set in Twinfield.

Now.. I thought that this $options array would look like this:

array(
   "office" => "NL12345", // the office code in Twinfield
   "vattype" => "sales"
)

Well no, that didn't work. Now with a lot of frustration and testing I found out that this array works for the finder options:

array(
   "ArrayOfString" => array(
                         array("office", "NL12345"),
                         array("vattype", "sales")
   )
)

I'm not sure if this is the right way of handling this, but it works. Hopefully this comment is helpful for others that are trying to use $options for the Finder.

Enforcement of dueDate in the transactions

Is it really necessary to enforce the due date? the Twinfield API can live without and right now it's hard-coded into the transaction mapper, making it a hassle when importing sales transactions.

Missing debitcredit in TransactionsDocument

in the function addTransaction in TransactionsDocument.php

The raisewarning attribute is not set in the Transaction; Add the following line after the desitiny attribute:

$transactionElement->setAttribute('raisewarning', $transaction->getRaiseWarning());

The period is not added to the Transaction; Add the following to the headerElement:

$periodElement = $this->createElement('period', $transaction->getPeriod());
$headerElement->appendChild($periodElement); 

The debitcredit value is not added to the Line; Add the following in the foreach:

$debitcreditNode = $this->createTextNode($transactionLine->getDebitCredit()); 
$debitcreditElement = $this->createElement('debitcredit');
$debitcreditElement->appendChild($debitcreditNode);
$lineElement->appendChild($debitcreditElement);

make line IDs nullable

Twinfield doesn't require you to set line IDs manually:

<lines>
		<line type="total" id="1">
			<dim1>1010</dim1>
			<debitcredit>debit</debitcredit>
			<value>435.55</value>
		</line>
		<line type="detail" id="2">
			<dim1>1300</dim1>
			<dim2>1000</dim2>
			<debitcredit>credit</debitcredit>
			<value>435.55</value>
			<invoicenumber>11001770</invoicenumber>
			<description>Invoice paid</description>
		</line>
</lines>

These id attributes are optional. If you leave them empty, Twinfield will assign them and send them back in the return XML.

However, when I do not call setId() in my BankTransaction lines, then the client fails, because it always sets the id attribute.

create new invoice ?

@remcotolsma When i want to create my own invoice the code return error : " An item code must be specified.//Item code not found. " then what is the problem with my code:

$config = new Config();
$config->setCredentials('NLG0','password','TWF-SAAS','NLA001498');
$invoice= new Invoice();

$line=new InvoiceLine();
$line->setQuantity(10)
    ->setValueExcl(100)
    ->setUnits(1)
    ->setVatCode('VH')
    ->setUnitsPriceExcl(100)
    ->setItem('1000')
    ;

$invoice
    ->setCustomer($customerFactory->get('1013'))
    ->setBank('BNK')
    ->setDueDate('20150429')
    ->setPeriod('2015/12')
    ->setCurrency('EUR')
    ->setStatus('concept')
    ->setInvoiceDate('20150425')
    ->addLine($line)
    ->setPaymentMethod('cash')
    ->setInvoiceType('FACTUUR');

$invoiceFactory = new InvoiceFactory($config);
var_dump($invoiceFactory->send($invoice));

I mean what is item code , where should set it?

CreditManagement cannot always be mapped to Customer

CustomerMapper assumes a creditmanagement tag is always present on the returned XML from Twinfield when retrieving a customer. This is not necessarily the case. When this is not the case you will get a Fatal error: Call to a member function getElementsByTagName() on null in CustomerMapper.php on line 111.

This can be fixed by checking if $creditManagementElement is null near line 93 (after assigning the variable) and only try to map the element when it's not.

If you like I can submit a PR to fix this.

Is this still maintained? Can't get it to work

I can't get the simple examples to work.

<?php

use Pronamic\Twinfield\Secure\Config;
use Pronamic\Twinfield\Customer as TwinfieldCustomer;


class api {	
	public function finalTest() {

        // Config object prepared and passed into the CustomerFactory
        $customerFactory = new TwinfieldCustomer\CustomerFactory($config);

        $customers = $customerFactory->listAll();
        print_r($customers);
        return false;
    }

Error:
Class 'Pronamic\Twinfield\Customer\CustomerFactory not found

I've tried everything, but it isn't working (PHP 7)

What am I doing wrong?
Thnx

Forgot $

twinfield / src / Pronamic / Twinfield / Invoice / InvoiceLine.php line 201

this should be $this.

Send request always returns (false)

Hi fellow developers,

I've been trying to use this PHP library for the Twinfield Integration.
I started by using the example code in the readme.md to add a test customer to my Twinfield account.

After reading the readme.md and looking into the PHP library, i wrote the following code below.
What i didn't understand is the way the files should be included, and i think this might cause my problem.

I did use error_logging to check if any required files or classes where not found but after including all these files in my script i got no more error's.

Can someone maybe give me push in the right direction ?

Thanks in advance,

Kind Regards,

Lennart

include "Pronamic/Twinfield/SoapClient.php";
include "Pronamic/Twinfield/Secure/Config.php";
include "Pronamic/Twinfield/Secure/Login.php";
include "Pronamic/Twinfield/Secure/Service.php";
include "Pronamic/Twinfield/Request/Catalog/Catalog.php";
include "Pronamic/Twinfield/Request/Catalog/Dimension.php";
include "Pronamic/Twinfield/Customer/Customer.php";
include "Pronamic/Twinfield/Customer/CustomerAddress.php";
include "Pronamic/Twinfield/Customer/CustomerBank.php";
include "Pronamic/Twinfield/Factory/ParentFactory.php";
include "Pronamic/Twinfield/Customer/DOM/CustomersDocument.php";
include "Pronamic/Twinfield/Customer/CustomerFactory.php";
include "Pronamic/Twinfield/Response/Response.php";
include "Pronamic/Twinfield/Customer/Mapper/CustomerMapper.php";

if (class_exists( '\Pronamic\Twinfield\Secure\Config' )){
    $config = new \Pronamic\Twinfield\Secure\Config();
    $config->setCredentials('API000053', 'mypasswordhere', 'TWF-SAAS', 'nlA001651');

    $customer = new \Pronamic\Twinfield\Customer\Customer();
    $customer
        ->setCode(10666)
        ->setName('Lennart Tester')
        ->setType('DEB')
        ->setWebsite('http://webverder.nl')
        ->setEBilling(true)
        ->setEBillMail('[email protected]')
        ->setVatCode('VL')
        ->setDueDays(10);

    $customerAddress = new \Pronamic\Twinfield\Customer\CustomerAddress();
    $customerAddress
        ->setDefault(false)
        ->setType('invoice')
        ->setField1('Testing field 1')
        ->setField2('Testing field 2')
        ->setField3('Testing field 3')
        ->setPostcode('1212 AB')
        ->setCity('TestCity')
        ->setCountry('NL')
        ->setTelephone('010-12345')
        ->setFax('010-1234')
        ->setEmail('[email protected]');

    $customer->addAddress($customerAddress);

    // Config object prepared and passed to the CustomerFactory
    $customerFactory = new \Pronamic\Twinfield\Customer\CustomerFactory($config);

    //$customer = new TwinfieldCustomer\Customer();

    // Attempt to send the Customer document
    if($customerFactory->send($customer)){
        // Use the Mapper to turn the response back into a TwinfieldCustomer\Customer
        $successfulCustomer = \Pronamic\Twinfield\Customer\Mapper\CustomerMapper::map($customerFactory->getResponse());
    } else {
        var_dump($customerFactory->send($customer));
        echo 'DATA NIET JUIST GEIMPORTEERD!! <br /><br />';

        print_r($customer);
    }

    // // Config object prepared and passed into the CustomerFactory
    // $customerFactory = new \Pronamic\Twinfield\Customer\CustomerFactory($config);

    // $customers = $customerFactory->listAll();

} else {
    echo 'CLASS NOT FOUND!';
}

How to expand CustomerFactory to get more info like the collect mandate?

As seen here, I'd like to retrieve the collectmandate set for a customer. As the CustomerFactory doesn't extend the FinderFactory, and the FinderFactory isn't out of the box usable, how would one expand CustomerFactory to get more info, like the financials, bank and collectmandate information?

I'm not too well versed in WSDL, and I'm pulling my hairs out figuring this out.

OAuth v2

Will there be an update for OAuth v2? Twinfield changed their api authentication to OAuth 2.0 (OIDC).

Bad declarations in Customer class

Cannot redeclare Pronamic\Twinfield\Customer\Customer::$office
Cannot redeclare Pronamic\Twinfield\Customer\Customer::getOffice()

This code causes fatal errors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.