/** * split mean vat given by shop (i.e. when using a coupon in OpenCart) into two fixedDiscountRows */ public function test_splitMeanToTwoTaxRatesToFormatFixedDiscountRows_OneRateInOrder() { $config = Svea\SveaConfig::getDefaultConfig(); $order = WebPay::createOrder($config); $order->addOrderRow(WebPayItem::orderRow()->setAmountExVat(100.0)->setVatPercent(25)->setQuantity(2)); $discountExVatFromShop = 100; $meanVatRateFromShop = 25.0; $titleFromShop = "Coupon (1112)"; $descriptionFromShop = "Value 100"; $taxRates = Svea\Helper::getTaxRatesInOrder($order); $discountRows = Svea\Helper::splitMeanToTwoTaxRates($discountExVatFromShop, $meanVatRateFromShop, $titleFromShop, $descriptionFromShop, $taxRates); foreach ($discountRows as $row) { $order = $order->addDiscount($row); } $formatter = new Svea\WebService\WebServiceRowFormatter($order); $newRows = $formatter->formatRows(); $newRow = $newRows[1]; $this->assertEquals("Coupon (1112): Value 100", $newRow->Description); $this->assertEquals(-100, $newRow->PricePerUnit); $this->assertEquals(25, $newRow->VatPercent); }
/** * wraps Svea\WebServiceRowFormatter->formatRowNameAndDescription to create a request description from order builder row name & description fields * * @param OrderRow|ShippingFee|et al. $webPayItemRow an instance of the order row classes from WebPayItem * @return string the combined description string that should be written to Description */ protected function formatRowNameAndDescription($webPayItemRow) { $wsrf = new \Svea\WebService\WebServiceRowFormatter(null, null); return $wsrf->formatRowNameAndDescription($webPayItemRow); }