ucs / billing
UCS 计费组件
1.0.1
2017-05-30 05:53 UTC
Requires
- php: >=5.3.2
- doctrine/collections: 1.2.*
Requires (Dev)
- leaphub/phpcs-symfony2-standard: ^2.0
- phpunit/phpunit: ^5.5
- squizlabs/php_codesniffer: ^2.5
This package is not auto-updated.
Last update: 2019-09-06 13:57:59 UTC
README
UCS 计费组件为您的Web应用提供了表示高级订单和发票功能的抽象层。它允许建模财务数据流和任何类型的订单创建。
安装
该组件可以通过以下命令通过composer获取:
composer require ucs/billing
基本用法
实现自己的 OrderManager
尽管计费组件自带预构建的 OrderManager,但由于实现方式的差异,它已被抽象化。OrderManager 为处理特定数据管理器(如 Doctrine 和 Propel)提供了抽象层。如果您打算直接使用该组件,您需要创建自己的实现
<?php
namespace \Demo\Billing;
use UCS\Component\Billing\Order\OrderManager as BasOrderManager;
/**
* Implementation of the OrderManager
*/
class OrderManager extends BaseOrderManager
{
/**
* {@inheritdoc}
*/
public function deleteOrder(OrderInterface $order)
{
// Implement order deletion here
}
/**
* {@inheritdoc}
*/
public function findOrderBy(array $criteria)
{
// Implement the order retrival
}
/**
* {@inheritdoc}
*/
public function findOrders()
{
// Find all orders here
}
}
使用组件
该组件基于“订单”的概念,可以包含“订单项”(s)和“定价器”(s),关联到特定的“计费信息”和给定的“订单状态”。订单表示可以计费并呈现在发票中的所有数据。订单随后由“订单管理器”操作。
<?php
$order = new \UCS\Component\Billing\Order\Order();
// add order items
$item = new \UCS\Component\Billing\Order\OrderItem();
$item->setUnitPrice(10.00)
->setQuantity(1)
->setReference('my_ref') // must be unique
->setTotalPrice(10);
// add the items to the order
$order->addItem($item);
// create your own implementation of the OrderManager
$orderManager = new \Demo\Billing\OrderManager();
// computes the total order, including tax rates and promotions
$orderManager->calculateOrderTotal($order);
定价器的作用
“定价器”是一个可以与订单和订单项相关联的概念。定价器处理账单中包含的附加价格修饰符
- 增值税
- 总增值税
- 运费
- 促销/折扣代码
- ...
这是一个通用模型,可以表示所有可能改变订单或订单项总价格的可能值。
向订单或订单项添加定价器相当简单
<?php
$order = new \UCS\Component\Billing\Order\Order();
// add order items
$item = new \UCS\Component\Billing\Order\OrderItem();
$item->setUnitPrice(10.00)
->setQuantity(1)
->setReference('my_ref'); // must be unique;
$itemVat = new \UCS\Component\Billing\Pricer\Pricer();
$itemVat->setSubject($item)
->setLabel('VAT on product')
->setDescription('VAT on product description')
->setAmount(20.0*$item->getTotalPrice()) // Credit
->setNeutral(false);
// register the price to the item
$item->addPricer($itemVat);
// add the item to the order
$order->addItem($item);
$orderManager = new \UCS\Component\Billing\Order\OrderManager();
// computes the total order, including tax rates and promotions
$orderManager->calculateOrderTotal($order);
测试
运行测试套件
您可以使用以下命令运行单元测试:
$ cd path/to/UCS/Component/Billing/
$ composer install
$ ./bin/phpunit -c .
可以通过复制 phpunit.xml.dist 文件并添加自己的选项来对运行 phpunit 测试套件进行额外的自定义。