picqer / twinfield-php-client
Twinfield Soap 服务使用的 PHP 客户端库。
Requires
- php: >=5.6
Requires (Dev)
README
一个用于 Twinfield 集成的 PHP 库。由来自 Remco Tolsma 和 Leon Rowland 的 Pronamic 开发。
使用 Twinfield SOAP 服务,让您的 PHP 应用程序直接与您的 Twinfield 账户通信。
为什么要创建这个分支?
此包 提供了正确的 semver 版本分支,以确保在项目中使用 composer 时的安全使用。
使用方法
使用 composer 安装此包
composer require picqer/twinfield-php-client
一般使用
组件有工厂来简化 Twinfield 的请求和发送过程。每个工厂只需要 \Pronamic\Twinfield\Secure\Config() 类以及填写好的详细信息。
配置类使用示例。
$config = new \Pronamic\Twinfield\Secure\Config(); $config->setCredentials('Username', 'Password', 'Organization', 'Office');
- 或者,当使用 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
当前模块
在以下示例中,我们将使用客户组件作为展示。尽管这将适用于所有组件(包括当前的发票)
通常如下,如果使用工厂
- 添加/编辑:创建对象,创建工厂,在相关工厂的提交方法中提供对象。
- 检索:创建工厂,向相应的 listAll() 和 get() 方法提供所有必需的参数
添加/编辑
创建您的客户对象
$customer = new \Pronamic\Twinfield\Customer\Customer(); $customer ->setID(10666) ->setName('Leon Rowland') ->setType('DEB') ->setWebsite('http://leon.rowland.nl') ->setEBilling(true) ->setEBillMail('leon@rowland.nl') ->setVatCode('VL') ->setDueDays(10) ->setCocNumber('12341234');
客户可以与他们关联地址
$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('test@email.com');
将地址分配给客户
$customer->addAddress($customerAddress);
现在让我们提交它!
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()); }
检索/请求
您可以获取所有客户或获取一个单个的。
use \Pronamic\Twinfield\Customer as TwinfieldCustomer; // Config object prepared and passed into the CustomerFactory $customerFactory = new TwinfieldCustomer\CustomerFactory($config); $customers = $customerFactory->listAll();
目前,listAll 将返回仅包含名称和简称的数组。
$customer = $customerFactory->get('customerCode', 'office[optional]');
get() 的响应将是 \Pronamic\Twinfield\Customer\Customer 对象。
贡献
您可以为此项目的开发做出贡献。尽量按照其他两个组件实现的方式行事。
一个重要要求是维护向后兼容性,因此如果您有任何大重构或修改的计划,请首先提出问题。
链接
作者
许可证
版权所有 2009-2017 Pronamic。
本程序是自由软件;您可以在自由软件基金会发布的 GNU 通用公共许可证条款下重新分发和/或修改它;许可证的第二版或(根据您的选择)任何后续版本。
本程序是在希望它有用的希望下分发的,但没有任何保证;甚至没有关于适销性或特定用途的隐含保证。有关详细信息,请参阅 GNU 通用公共许可证。
您应该已收到此程序的 GNU 通用公共许可证副本;如果没有,请写信给自由软件基金会,Inc.,59 Temple Place,Suite 330,波士顿,MA 02111-1307 USA