function it_should_spread_the_bursary_when_the_plan_spans_multiple_years($baseCalculator, PaymentPlan $planBeforeBursary, PaymentPlan $finalPlan) { $baseCalculator->getPlan(Def::withName('Foo'), Money::GBP(250), Argument::any())->willReturn($planBeforeBursary); $planBeforeBursary->getPlannedPayments()->willReturn([PlannedPayment::immediate(Money::GBP(50)), PlannedPayment::withDueDate(Money::GBP(50), DueDate::fromString('2014-01-01')), PlannedPayment::withDueDate(Money::GBP(50), DueDate::fromString('2014-06-01')), PlannedPayment::withDueDate(Money::GBP(50), DueDate::fromString('2015-01-01')), PlannedPayment::withDueDate(Money::GBP(50), DueDate::fromString('2015-06-01'))]); $planBeforeBursary->getShortDescription()->willReturn('foo'); $planBeforeBursary->getLongDescription()->willReturn('foofoo'); $finalPlan = new PaymentPlan([PlannedPayment::immediate(Money::GBP(50)), PlannedPayment::withDueDate(Money::GBP(50), DueDate::fromString('2014-01-01')), PlannedPayment::withDueDate(Money::GBP(40), DueDate::fromString('2014-06-01')), PlannedPayment::withDueDate(Money::GBP(50), DueDate::fromString('2015-01-01')), PlannedPayment::withDueDate(Money::GBP(40), DueDate::fromString('2015-06-01'))], 'foo', 'foofoo'); $this->getPlan(Def::withName('Foo'), Money::GBP(230), Params::fromArray(['bursary_total_deduction' => 20]))->shouldBeLike($finalPlan); }
function it_should_use_a_registered_modifier_when_it_is_part_of_the_plan_definition($basePlan, PlanModifierInterface $modifier, PaymentPlan $planProvidedByModifier, PaymentPlan $unmodifiedPlan) { $definition = PlanDefinition::withNameAndAttributesAsArray('Foo', ['modifiers' => ['mymodifier']]); $this->registerModifier('mymodifier', $modifier); $modifier->setBaseCalculator($basePlan)->shouldBeCalled(); $modifier->getPlan($definition, Money::GBP(100), PlanParameters::none())->shouldBeCalled()->willReturn($planProvidedByModifier); $basePlan->getPlan(PlanDefinition::withName('Foo'), Money::GBP(100), PlanParameters::none())->willReturn($unmodifiedPlan); $this->getPlan($definition, Money::GBP(100), PlanParameters::none())->shouldReturn($planProvidedByModifier); $this->getPlan(PlanDefinition::withName('Foo'), Money::GBP(100), PlanParameters::none())->shouldReturn($unmodifiedPlan); }
/** * @return float */ public function calculateTotal() { /** @var Money $total */ $total = Money::GBP(0); foreach ($this->products as $product) { $unitPrice = $product->getUnitPrice() ?: Money::GBP(0); $total = $total->add($unitPrice); } return round($total->getAmount() / 100, 2); }
/** * @param PlanDefinition $definition * @param Money $amountToPay * @param PlanParameters $parameters * @internal param string $planCode * @return \Ice\PaymentPlan\PaymentPlan */ public function getPlan(PlanDefinition $definition, Money $amountToPay, PlanParameters $parameters) { if ($parameters->hasParameter('bursary_total_deduction') && ($bursaryTotalDeduction = intval($parameters->get('bursary_total_deduction'))) > 0) { $absoluteBursaryTotal = Money::GBP($bursaryTotalDeduction); $amountBeforeBursary = $amountToPay->add($absoluteBursaryTotal); $planWithoutBursary = $this->childCalculator->getPlan($definition, $amountBeforeBursary, $parameters); return $this->subtractBursaryFromPlan($planWithoutBursary, $absoluteBursaryTotal); } return $this->childCalculator->getPlan($definition, $amountToPay, $parameters); }
protected function productsProvider() { $products = new Products(); $productA = new Product('Avocado', 'Best Avocado in town!', '32.23kb', Money::GBP(180)); $productB = new Product('Apricot', 'Best Avocado in town!', '32.23kb', Money::GBP(150)); $productC = new Product('Avocado x4', 'Great Avocado x4 deal', '32.23kb', Money::GBP(280)); $products->add($productA); $products->add($productB); $products->add($productC); return $products; }
function testIntegration() { $definition = PlanDefinition::withNameAndAttributesAsArray('PercentOnDate', ['short_description' => '20/40/40 split', 'long_description' => '20% immediately, 40% on 2014/01/01, 40% on 2014/03/01, except that bursaries are always taken from the final instalment', 'payments' => ['immediate' => 0.2, '2014-01-01' => 0.4, '2014-03-01' => 0.4], 'modifiers' => ['bursary_off_final_payment']]); $params = PlanParameters::fromArray(['bursary_total_deduction' => 10]); $this->assertTrue($this->factory->isAvailable($definition, Money::GBP(90), $params)); $plan = $this->factory->getPlan($definition, Money::GBP(90), $params); /** * The net booking cost is 90, which includes a 10 deduction for a bursary. Without the bursary, we'd expect * the 100 to be split as 20/40/40. With the bursary_off_final_payment modifier, this becomes 20/40/30 */ $this->assertEquals(new PaymentPlan([PlannedPayment::immediate(Money::GBP(20)), PlannedPayment::withDueDate(Money::GBP(40), DueDate::fromString('2014-01-01')), PlannedPayment::withDueDate(Money::GBP(30), DueDate::fromString('2014-03-01'))], '20/40/40 split', '20% immediately, 40% on 2014/01/01, 40% on 2014/03/01, except that bursaries are always taken from the final instalment'), $plan); }
public function testScrapeProducts() { $productListUrl = new Url('http://sainsbury.com/products'); $productsDetailurls = [new Url('http://sainsbury.com/products/avocado'), new Url('http://sainsbury.com/products/apricot'), new Url('http://sainsbury.com/products/avocado-x4')]; $productListScraper = $this->prophesize('Sainsburys\\Scraper\\ProductListScraper'); $productDetailScraper = $this->prophesize('Sainsburys\\Scraper\\ProductDetailScraper'); $productListScraper->extractProductLinks($productListUrl)->shouldBeCalled()->willReturn($productsDetailurls); $productDetailScraper->extractDetail($productsDetailurls[0])->shouldBeCalled()->willReturn(new Product('Avocado', 'Best Avocado in town!', '32.23kb', Money::GBP(180))); $productDetailScraper->extractDetail($productsDetailurls[1])->shouldBeCalled()->willReturn(new Product('Apricot', 'Best Avocado in town!', '32.23kb', Money::GBP(150))); $productDetailScraper->extractDetail($productsDetailurls[2])->shouldBeCalled()->willReturn(new Product('Avocado x4', 'Great Avocado x4 deal', '32.23kb', Money::GBP(280))); $productsInfoScraper = new ProductsInfoScraper($productListScraper->reveal(), $productDetailScraper->reveal()); $products = $productsInfoScraper->extract($productListUrl); $this->assertInstanceOf('Sainsburys\\Model\\Products', $products); }
public function testConstructorWithMoney() { $price = new Price([Money::EUR(5), Money::USD(10), Money::GBP(10), 'TRY' => 120], [CurrencyPair::createFromIso('USD/CHF 1.5'), CurrencyPair::createFromIso('USD/AWG 1.0')]); $this->assertInstanceOf('Leaphly\\Price\\Price', $price); $this->assertEquals(15, $price->getAmount('CHF')); }
public function testFunction() { $calculator = $this->getContainer()->get('ice.payment_plan.calculator'); $plan = $calculator->getPlan(PlanDefinition::withNameAndAttributesAsArray('PercentOnDate', ['short_description' => 'Test', 'long_description' => 'My test plan', 'payments' => ['immediate' => 0.4, '2016-01-01' => 0.6], 'modifiers' => ['bursary_off_final_payment']]), Money::GBP(1000), PlanParameters::none()); $this->assertInstanceOf('Ice\\PaymentPlan\\PaymentPlan', $plan); }
function it_should_return_a_plan_based_on_definition_attributes() { $expected = new PaymentPlan([PlannedPayment::immediate(Money::GBP(10)), PlannedPayment::withDueDate(Money::GBP(70), DueDate::fromString('2014-01-01')), PlannedPayment::withDueDate(Money::GBP(20), DueDate::fromString('2015-01-01'))], 'Foo', 'FooFoo'); $this->getPlan(PlanDefinition::withNameAndAttributesAsArray('PercentOnDate', ['short_description' => 'Foo', 'long_description' => 'FooFoo', 'payments' => ['immediate' => 0.1, '2014-01-01' => 0.7, '2015-01-01' => 0.2]]), Money::GBP(100), PlanParameters::none())->shouldBeLike($expected); }
function it_should_use_a_calculator_to_return_a_plan(PaymentPlan $fooPlan, $delegatedFooCalculator) { $delegatedFooCalculator->getPlan(PlanDefinition::withName('Foo'), Money::GBP(100), PlanParameters::none())->willReturn($fooPlan); $this->getPlan(PlanDefinition::withName('Foo'), Money::GBP(100), PlanParameters::none())->shouldReturn($fooPlan); }