Skip to content

Commit

Permalink
+PayPalComponent::GetItemTotal
Browse files Browse the repository at this point in the history
  • Loading branch information
hakito committed Jul 16, 2020
1 parent 280d811 commit 7c5b460
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/Controller/Component/PayPalComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ public function AddArticle($name, $quantity, $price, $id = null)
}
}

/**
* @return int|float sum of all item prices (in cents) multilied by quantity
*/
public function GetItemTotal()
{
$itemSum = 0;
foreach($this->items as $item)
$itemSum += $item->CentPrice * $item->getQuantity();
return $itemSum;
}

/**
*
* @param string $remittanceIdentifier id to be used for the callback function
Expand Down
11 changes: 8 additions & 3 deletions tests/TestCase/Controller/Component/PayPalComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\TestSuite\TestCase;


use PayPal\Controller\Component\PayPalComponent;
use PayPal\Model\Table\PayPalPaymentsTable;

/**
* @var PayPalComponent PayPal
* @property PayPalComponent $PayPal
*/
class PayPalComponentTest extends TestCase
{
Expand Down Expand Up @@ -65,6 +63,13 @@ public function testAddArticleWithId()
$this->assertEquals('id', $items['id']->getSku());
}

public function testGetItemTotal()
{
$this->PayPal->AddArticle('foo', 3, 1234);
$this->PayPal->AddArticle('foo', 5, 567);
$this->assertEquals(1234 * 3 + 567 * 5, $this->PayPal->GetItemTotal());
}

public function testPaymentRedirectCreatePaymentFails()
{
$this->PayPal->PayPalPayments = $this->getMockForModel('PayPal.PayPalPayments', ['createPayment']);
Expand Down

0 comments on commit 7c5b460

Please sign in to comment.