Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #20 from Estigy/dev-master
Browse files Browse the repository at this point in the history
Update BasketItem and Basket fields to new wirecard specs
  • Loading branch information
CHH authored Dec 5, 2016
2 parents d019a00 + bde651f commit d1dc070
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/Model/Common/Basket.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Basket extends Model
*/
function setAmount($amount)
{
return $this->addParam('basketAmount', $amount);
return $this->addParam('amount', $amount);
}

/**
Expand All @@ -26,7 +26,7 @@ function setAmount($amount)
*/
function getAmount()
{
return $this->getParam('basketAmount');
return $this->getParam('amount');
}

/**
Expand All @@ -37,7 +37,7 @@ function getAmount()
*/
function setCurrency($currency)
{
return $this->addParam('basketCurrency', $currency);
return $this->addParam('currency', $currency);
}

/**
Expand All @@ -47,7 +47,7 @@ function setCurrency($currency)
*/
function getCurrency()
{
return $this->getParam('basketCurrency');
return $this->getParam('currency');
}

/**
Expand Down
77 changes: 67 additions & 10 deletions src/Model/Common/BasketItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ function getArticleNumber()
return $this->getParam('articleNumber');
}

/**
* Set the item's name
*
* @param string $name
* @return BasketItem
*/
function setName($name)
{
return $this->addParam('name', $name);
}

/**
* @return string
*/
function getName()
{
return $this->getParam('name');
}

/**
* Set the item description, typically a product name
*
Expand Down Expand Up @@ -64,40 +83,78 @@ function getQuantity()
}

/**
* Set item tax amount as string, formatted as float, e.g. "12.50"
* Set item tax amount as string, formatted as float, e.g. "2.50"
*
* @param string $amount
* @return BasketItem
*/
function setUnitTaxAmount($amount)
{
return $this->addParam('unitTaxAmount', $amount);
}

/**
* @return string
*/
function getUnitTaxAmount()
{
return $this->getParam('unitTaxAmount');
}

/**
* Set item tax rate as string, formatted as float, e.g. "25"
*
* @param string $rate
* @return BasketItem
*/
function setUnitTaxRate($rate)
{
return $this->addParam('unitTaxRate', $rate);
}

/**
* @return string
*/
function getUnitTaxRate()
{
return $this->getParam('unitTaxRate');
}

/**
* Set item gross amount as string, formatted as float, e.g. "12.50"
*
* @param string $amount
* @return BasketItem
*/
function setTax($amount)
function setUnitGrossAmount($amount)
{
return $this->addParam('tax', $amount);
return $this->addParam('unitGrossAmount', $amount);
}

/**
* @return string
*/
function getTax()
function getUnitGrossAmount()
{
return $this->getParam('tax');
return $this->getParam('unitGrossAmount');
}

/**
* Set item cost as string, formatted as float, e.g. "12.50"
* Set item net amount as string, formatted as float, e.g. "10.00"
*
* @param string $amount
* @return BasketItem
*/
function setUnitPrice($amount)
function setUnitNetAmount($amount)
{
return $this->addParam('unitPrice', $amount);
return $this->addParam('unitNetAmount', $amount);
}

/**
* @return string
*/
function getUnitPrice()
function getUnitNetAmount()
{
return $this->getParam('unitPrice');
return $this->getParam('unitNetAmount');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,21 @@ public function testBasket()
$basket->setCurrency('EUR');
$basket->addItem((new BasketItem)
->setArticleNumber('A001')
->setDescription('Product A1')
->setName('Product A1')
->setQuantity(1)
->setUnitPrice('10.00')
->setTax('2.00')
->setUnitGrossAmount('11.00')
->setUnitNetAmount('10.00')
->setUnitTaxAmount('1.00')
->setUnitTaxRate('10')
);
$basket->addItem((new BasketItem)
->setArticleNumber('SHIPPING')
->setDescription('Shipping')
->setName('Shipping')
->setQuantity(1)
->setUnitPrice('5.00')
->setTax('1.00')
->setUnitGrossAmount('5.00')
->setUnitNetAmount('5.00')
->setUnitTaxAmount('0')
->setUnitTaxRate('0')
);

$shippingInformation = (new ShippingInformation)
Expand Down
58 changes: 37 additions & 21 deletions tests/unit/Common/BasketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,66 @@ class BasketTest extends \PHPUnit_Framework_Testcase
function test()
{
$basket = new Basket;
$basket->setAmount(58);
$basket->setAmount(110);
$basket->setCurrency('EUR');
$basket->addItem((new BasketItem)
->setArticleNumber('A001')
->setDescription('Product A1')
->setName('Product A1')
->setDescription('Desc for Product A1')
->setQuantity(1)
->setUnitPrice(10)
->setTax(1)
->setUnitGrossAmount(55)
->setUnitNetAmount(50)
->setUnitTaxAmount(5)
->setUnitTaxRate(10)
);
$basket->addItem((new BasketItem)
->setArticleNumber('A002')
->setDescription('Product A2')
->setName('Product A2')
->setDescription('Desc for Product A2')
->setQuantity(2)
->setUnitPrice(20)
->setTax(2)
->setUnitGrossAmount(25)
->setUnitNetAmount(20)
->setUnitTaxAmount(5)
->setUnitTaxRate(25)
);
$basket->addItem((new BasketItem)
->setArticleNumber('S001')
->setDescription('Shipping')
->setName('Shipping')
->setQuantity(1)
->setUnitPrice(5)
->setTax(0)
->setUnitGrossAmount(5)
->setUnitNetAmount(5)
->setUnitTaxAmount(0)
->setUnitTaxRate(0)
);

$this->assertEquals(
[
'basketAmount' => 58,
'basketCurrency' => 'EUR',
'amount' => 110,
'currency' => 'EUR',
'basketItems' => 3,
'basketItem1ArticleNumber' => 'A001',
'basketItem1Description' => 'Product A1',
'basketItem1Name' => 'Product A1',
'basketItem1Description' => 'Desc for Product A1',
'basketItem1Quantity' => 1,
'basketItem1UnitPrice' => 10,
'basketItem1Tax' => 1,
'basketItem1UnitGrossAmount' => 55,
'basketItem1UnitNetAmount' => 50,
'basketItem1UnitTaxAmount' => 5,
'basketItem1UnitTaxRate' => 10,
'basketItem2ArticleNumber' => 'A002',
'basketItem2Description' => 'Product A2',
'basketItem2Name' => 'Product A2',
'basketItem2Description' => 'Desc for Product A2',
'basketItem2Quantity' => 2,
'basketItem2UnitPrice' => 20,
'basketItem2Tax' => 2,
'basketItem2UnitGrossAmount' => 25,
'basketItem2UnitNetAmount' => 20,
'basketItem2UnitTaxAmount' => 5,
'basketItem2UnitTaxRate' => 25,
'basketItem3ArticleNumber' => 'S001',
'basketItem3Description' => 'Shipping',
'basketItem3Name' => 'Shipping',
'basketItem3Quantity' => 1,
'basketItem3UnitPrice' => 5,
'basketItem3Tax' => 0,
'basketItem3UnitGrossAmount' => 5,
'basketItem3UnitNetAmount' => 5,
'basketItem3UnitTaxAmount' => 0,
'basketItem3UnitTaxRate' => 0,
],
$basket->toArray()
);
Expand Down

0 comments on commit d1dc070

Please sign in to comment.