public function testCreateOrderWithFeesAsAmountExAndDeliverWithAmountIncvat() { $config = Svea\SveaConfig::getDefaultConfig(); $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting(); $order = WebPay::createOrder($config)->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(1239.876)->setVatPercent(24)->setQuantity(1))->addFee(WebPayItem::shippingFee()->setAmountIncVat(123.9876)->setVatPercent(24))->addFee(WebPayItem::invoiceFee()->setAmountIncVat(123.9876)->setVatPercent(24))->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))->setCountryCode("SE")->setOrderDate("2012-12-12")->usePaymentPlanPayment($campaigncode)->doRequest(); $request = WebPay::deliverOrder($config); $request = $request->addOrderRow(WebPayItem::orderRow()->setAmountExVat(999.9)->setVatPercent(24)->setQuantity(1))->addFee(WebPayItem::shippingFee()->setAmountExVat(99.98999999999999)->setVatPercent(24))->addFee(WebPayItem::invoiceFee()->setAmountExVat(99.98999999999999)->setVatPercent(24))->setOrderId($order->sveaOrderId)->setInvoiceDistributionType(DistributionType::POST)->setCountryCode("SE")->deliverPaymentPlanOrder()->doRequest(); $this->assertEquals(1, $request->accepted); }
private static function create_only_incvat_order_and_fee_rows_order() { $order = WebPay::createOrder(Svea\SveaConfig::getDefaultConfig())->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))->setCountryCode("SE")->setCustomerReference("33")->setOrderDate("2012-12-12")->setCurrency("SEK")->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(72.0)->setVatPercent(20)->setQuantity(1)->setName("incvatRow"))->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(33.0)->setVatPercent(10)->setQuantity(1)->setName("incvatRow2"))->addFee(WebPayItem::invoiceFee()->setAmountIncVat(8.800000000000001)->setVatPercent(10)->setName("incvatInvoiceFee"))->addFee(WebPayItem::shippingFee()->setAmountIncVat(17.6)->setVatPercent(10)->setName("incvatShippingFee")); return $order; }
/** * Regression test for float to int conversion error, where we lost accuracy * on straight cast of 25f (eg. 24.9999999964) to 24i * See also test in InvoicePaymentIntegrationTest, Jira issue WEB-193 */ public function test_regressiontest_for_float_to_int_conversion_errorS() { $config = Svea\SveaConfig::getDefaultConfig(); $order = WebPay::createOrder($config); $order->addOrderRow(WebPayItem::orderRow()->setAmountExVat(100.0)->setVatPercent(25)->setQuantity(1))->addFee(WebPayItem::shippingFee()->setAmountExVat(0.0)->setVatPercent(0))->addFee(WebPayItem::invoiceFee()->setAmountExVat(23.2)->setVatPercent(25)); $formatter = new WebServiceRowFormatter($order); $resultRows = $formatter->formatRows(); $testedRow = $resultRows[0]; $this->assertEquals(100, $testedRow->PricePerUnit); $this->assertEquals(25, $testedRow->VatPercent); $testedRow = $resultRows[1]; $this->assertEquals(0, $testedRow->PricePerUnit); $this->assertEquals(0, $testedRow->VatPercent); $testedRow = $resultRows[2]; $this->assertEquals(23.2, $testedRow->PricePerUnit); $this->assertEquals(25, $testedRow->VatPercent); }
public function test_fixedDiscount_amount_with_calculated_vat_rate_incvat_creates_discount_rows_using_incvat_and_vatpercent() { $order = WebPay::createOrder(Svea\SveaConfig::getDefaultConfig())->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))->setCountryCode("SE")->setCustomerReference("33")->setOrderDate("2012-12-12")->setCurrency("SEK")->addOrderRow(WebPayItem::orderRow()->setAmountExVat(60.0)->setVatPercent(20)->setQuantity(1)->setName("exvatRow"))->addOrderRow(WebPayItem::orderRow()->setAmountExVat(30.0)->setVatPercent(10)->setQuantity(1)->setName("exvatRow2"))->addFee(WebPayItem::invoiceFee()->setAmountExVat(8.0)->setVatPercent(10)->setName("exvatInvoiceFee"))->addFee(WebPayItem::shippingFee()->setAmountExVat(16.0)->setVatPercent(10)->setName("exvatShippingFee"))->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10.0)->setDiscountId("TenCrownsOff")->setName("fixedDiscount: 10 off incvat")); $request = $order->useInvoicePayment()->prepareRequest(); // all order rows $this->assertEquals(60.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit); $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent); $this->assertEquals(30.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit); $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent); // all invoice fee rows $this->assertEquals(8.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit); $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent); // all shipping fee rows $this->assertEquals(16.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit); $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent); // all discount rows // expected: fixedDiscount: 10 off incvat, order row amount are 66% at 20% vat, 33% at 10% vat // 1.2*0.66x + 1.1*0.33x = 10 => x = 8.6580 => 5.7143 @20% and 2.8571 @10% = $this->assertEquals(-5.7142857142857, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit); $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent); $this->assertEquals(-2.8571428571429, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit); $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent); }
public function test_incvat_only_order_with_fixedDiscount_amount_specified_as_incvat_and_calculated_vat_rate_order_sent_with_PriceIncludingVat_true() { $order = $this->order; $order->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(720.0)->setVatPercent(20)->setQuantity(1))->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(330.0)->setVatPercent(10)->setQuantity(1))->addFee(WebPayItem::invoiceFee()->setAmountIncVat(88.0)->setVatPercent(10))->addFee(WebPayItem::shippingFee()->setAmountIncVat(172.0)->setVatPercent(10)); $order->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10.0)->setDiscountId("TenCrownsOff")->setName("fixedDiscount: 10 off incvat")); $request = $order->useInvoicePayment()->prepareRequest(); // all order rows $this->assertEquals(720.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit); $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent); $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat); $this->assertEquals(330.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit); $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent); $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat); // all invoice fee rows $this->assertEquals(88.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit); $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent); $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat); // all shipping fee rows $this->assertEquals(172.0, Svea\Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit, 2)); $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent); $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat); // all discount rows // expected: fixedDiscount: 10 off incvat, order row amount are 66% at 20% vat, 33% at 10% vat // 1.2*0.66x + 1.1*0.33x = 10 => x = 8.6580 => 5.7143 @20% and 2.8571 @10% = 10kr $this->assertEquals(-6.86, Svea\Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2)); $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent); $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat); $this->assertEquals(-3.14, Svea\Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2)); $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent); $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat); }
public function testDeliverOrderSetWithMixedOrderRowAndFeeAndVatPercentSet() { $config = Svea\SveaConfig::getDefaultConfig(); $request = WebPay::deliverOrder($config); $request = $request->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(123.9876)->setVatPercent(24)->setQuantity(1))->addFee(WebPayItem::invoiceFee()->setAmountExVat(99.98999999999999)->setVatPercent(24))->addFee(WebPayItem::shippingFee()->setAmountIncVat(123.9876)->setVatPercent(24))->setOrderId("id")->setInvoiceDistributionType(DistributionType::POST)->setCreditInvoice("id")->setCountryCode("SE")->deliverInvoiceOrder()->prepareRequest(); $this->assertEquals(99.98999999999999, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit); $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent); $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat); $this->assertEquals(99.98999999999999, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit); $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent); $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat); $this->assertEquals(99.98999999999999, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit); $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent); $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PriceIncludingVat); }
/** * Builds request for DeliverInvoice as Credit for Invoice. Calls from * Magento Refund * * @param type $payment * @param type $auth * @param type $sveaOrderId * @return type */ public function getRefundRequest($payment, $auth, $sveaOrderId) { $conf = new SveaMageConfigProvider($auth); $sveaObject = WebPay::deliverOrder($conf); $order = $payment->getOrder(); $creditMemo = $payment->getCreditmemo(); $storeId = $order->getStoreId(); $countryCode = $order->getBillingAddress()->getCountryId(); $taxCalculationModel = Mage::getSingleton('tax/calculation'); $taxConfig = Mage::getSingleton('tax/config'); $store = Mage::app()->getStore($storeId); foreach ($creditMemo->getAllItems() as $item) { $orderItem = $item->getOrderItem(); if ($orderItem->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { continue; } // Default to the item price $name = $item->getName(); $price = $orderItem->getPrice(); $priceInclTax = $orderItem->getPriceInclTax(); $taxPercent = $orderItem->getTaxPercent(); if (!(int) $taxPercent) { $taxPercent = false; } $qty = $item->getQty(); $parentItem = $orderItem->getParentItem(); if ($parentItem) { switch ($parentItem->getProductType()) { case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE: $price = $parentItem->getPrice(); $priceInclTax = $parentItem->getPriceInclTax(); $taxPercent = $parentItem->getTaxPercent(); $qty = $parentItem->getQtyRefunded(); break; case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE: $taxPercent = $priceInclTax = $price = 0; $name = '- ' . $name; break; } } if ($taxPercent === false) { // If it's a bundle item we have to calculate the tax from // the including/excluding tax values $taxPercent = round(100 * ($priceInclTax / $price - 1)); } $orderRow = WebPayItem::orderRow()->setArticleNumber($item->getSku())->setQuantity((int) $qty)->setName($name)->setUnit(Mage::helper('svea_webpay')->__('unit'))->setVatPercent((int) $taxPercent)->setAmountIncVat((double) $priceInclTax); $sveaObject->addOrderRow($orderRow); } $request = $taxCalculationModel->getRateRequest($order->getShippingAddress(), $order->getBillingAddress(), null, $store); // Shipping if ($creditMemo->getShippingAmount() > 0) { $shippingFee = WebPayItem::shippingFee()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setName($order->getShippingDescription()); // We require shipping tax to be set $shippingTaxClass = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $storeId); $rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass)); $shippingFee->setVatPercent((int) $rate); if ($taxConfig->shippingPriceIncludesTax($storeId)) { $shippingFee->setAmountIncVat($creditMemo->getShippingInclTax()); } else { $shippingFee->setAmountExVat($creditMemo->getShippingAmount()); } $sveaObject->addFee($shippingFee); } // Discount $discount = abs($creditMemo->getDiscountAmount()); if ($discount > 0) { $discountRow = WebPayItem::fixedDiscount()->setAmountIncVat($discount)->setName(Mage::helper('svea_webpay')->__('discount'))->setUnit(Mage::helper('svea_webpay')->__('unit')); $sveaObject->addDiscount($discountRow); } // Gift cards if (abs($creditMemo->getGiftCardsAmount()) > 0) { $giftCardRow = WebPayItem::fixedDiscount()->setAmountIncVat(abs($creditMemo->getGiftCardsAmount()))->setUnit(Mage::helper('svea_webpay')->__('unit')); $sveaObject->addDiscount($giftCardRow); } // Invoice fee $paymentFee = $creditMemo->getSveaPaymentFeeAmount(); $paymentFeeInclTax = $creditMemo->getSveaPaymentFeeInclTax(); $refunded = $creditMemo->getOrder()->getSveaPaymentFeeRefunded(); if ($paymentFee > 0 && $refunded == 0) { $invoiceFee = WebPayItem::invoiceFee()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setName(Mage::helper('svea_webpay')->__('invoice_fee'))->setAmountExVat($paymentFee)->setAmountIncVat($paymentFeeInclTax); $sveaObject = $sveaObject->addFee($invoiceFee); $creditMemo->getOrder()->setSveaPaymentFeeRefunded($paymentFeeInclTax); } $adjustmentFee = $creditMemo->getAdjustmentPositive(); if ($adjustmentFee > 0) { $invoiceAdjustment = WebPayItem::invoiceFee()->setVatPercent(0)->setAmountIncVat($adjustmentFee); $sveaObject->addFee($invoiceAdjustment); } $response = $sveaObject->setCountryCode($countryCode)->setOrderId($sveaOrderId)->setInvoiceDistributionType(Mage::getStoreConfig("payment/svea_invoice/deliver_method")); $order->setData('svea_refund_request', $response); return $order->getData('svea_refund_request'); }
public function test_BuildCardPayment_With_InvoiceFee_ExVat_IncVat() { $config = SveaConfig::getDefaultConfig(); $form = \WebPay::createOrder($config)->addOrderRow(\WebPayItem::orderRow()->setArticleNumber("1")->setQuantity(1)->setAmountExVat(240.0)->setAmountIncVat(300.0)->setDescription("CD"))->addFee(\WebPayItem::invoiceFee()->setAmountExVat(80)->setAmountIncVat(100)->setName("test_BuildCardPayment_With_InvoiceFee title")->setDescription("test_BuildCardPayment_With_InvoiceFee description")->setUnit("kr"))->setClientOrderNumber("33")->setCurrency("SEK")->setCountryCode("SE")->usePayPageCardOnly()->setReturnUrl("http://myurl.se")->getPaymentForm(); $xmlMessage = new \SimpleXMLElement($form->xmlMessage); $this->assertEquals("8000", $xmlMessage->vat); $this->assertEquals("40000", $xmlMessage->amount); }
public function test_FixedDiscount_specified_using_amountExVat_is_calculated_from_order_item_rows_only_php_original_version() { $order = \WebPay::createOrder(Svea\SveaConfig::getDefaultConfig())->addOrderRow(\WebPayItem::orderRow()->setName("product with price 100 @25% = 125")->setAmountExVat(100.0)->setVatPercent(25)->setQuantity(2.0))->addOrderRow(\WebPayItem::orderRow()->setName("product with price 100 @6% = 106")->setAmountExVat(100.0)->setVatPercent(6)->setQuantity(1.0))->addFee(\WebPayItem::shippingFee()->setName("shipping with price 50 @6% = 53")->setAmountExVat(50.0)->setVatPercent(6))->addFee(\WebPayItem::invoiceFee()->setAmountExVat(23.2)->setVatPercent(25))->addDiscount(\WebPayItem::fixedDiscount()->setDiscountId("f100e")->setName("couponName")->setDescription("couponDesc")->setAmountExVat(100.0)->setUnit("st")); $formatter = new HostedRowFormatter(); $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder // 100*200/300 = 66.67 ex. 25% vat => discount 83.34 (incl. 16.67 vat @25%) // 100*100/300 = 33.33 ex. 6% vat => discount 35.33 (incl 2.00 vat @6%) // => total discount is 118.67 (incl 18.67 vat @18.67%) // validate HostedOrderRowBuilder row contents $newRow = $newRows[4]; $this->assertEquals("f100e", $newRow->sku); $this->assertEquals("couponName", $newRow->name); $this->assertEquals("couponDesc", $newRow->description); $this->assertEquals(-11867, $newRow->amount); $this->assertEquals(-1867, $newRow->vat); $this->assertEquals(1, $newRow->quantity); $this->assertEquals("st", $newRow->unit); $paymentForm = $order->setCountryCode("SE")->setOrderDate("2015-02-23")->setClientOrderNumber("unique")->setCurrency("SEK")->usePaymentMethod(PaymentMethod::KORTCERT)->setReturnUrl("http://myurl.com")->getPaymentForm(); $paymentXml = $paymentForm->xmlMessage; // // 250.00 (50.00) // // 106.00 (6.00) // // 53.00 (3.00) // // 29.00 (5.80) // // -118.67 (-18.67) // // => 319.33 (46.13) $this->assertRegexp('/<amount>31933<\\/amount>/', $paymentXml); $this->assertRegexp('/<vat>4613<\\/vat>/', $paymentXml); }
public function testFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent() { $config = Svea\SveaConfig::getDefaultConfig(); $campaign = $this->getGetPaymentPlanParamsForTesting(); $request = WebPay::createOrder($config)->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(123.9876)->setVatPercent(24)->setQuantity(1))->addFee(WebPayItem::shippingFee()->setAmountIncVat(100.0)->setVatPercent(24))->addFee(WebPayItem::invoiceFee()->setAmountIncVat(100.0)->setVatPercent(24))->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))->setCountryCode("SE")->setOrderDate("2012-12-12")->usePaymentPlanPayment($campaign)->prepareRequest(); $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit); $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent); $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit); $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent); $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit); $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent); }
/** * Add values and rows to Svea CreateOrder object * * Configurable products: * Calculate prices using the parent price, to take price variations into concern * * Simple products: * Just use their prices as is * * Bundle products: * The main parent product has the price, but the associated products * need to be transferred on separate 0 amount lines so the invoice is * verbose enough * * Grouped products: * These are treated the same way as simple products * * @param type $order * @param type $additionalInfo * @return type Svea CreateOrder object */ public function getSveaPaymentObject($order, $additionalInfo = null) { //Get Request and billing addres $svea = $order->getData('svea_payment_request'); $billingAddress = $order->getBillingAddress(); $storeId = $order->getStoreId(); $store = Mage::app()->getStore($storeId); $taxCalculationModel = Mage::getSingleton('tax/calculation'); $taxConfig = Mage::getSingleton('tax/config'); // Build the rows for request foreach ($order->getAllItems() as $item) { if ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { continue; } // Default to the item price $name = $item->getName(); $price = $item->getPrice(); $priceInclTax = $item->getPriceInclTax(); $taxPercent = $item->getTaxPercent(); if (!(int) $taxPercent) { $taxPercent = false; } $parentItem = $item->getParentItem(); if ($parentItem) { switch ($parentItem->getProductType()) { case Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE: $priceInclTax = $parentItem->getPriceInclTax(); $taxPercent = $parentItem->getTaxPercent(); break; case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE: $taxPercent = $priceInclTax = $price = 0; $name = '- ' . $name; break; } } if ($taxPercent === false) { if ((double) $price === 0.0) { if ((double) $priceInclTax === 0.0) { $taxPercent = 0; } else { throw new Mage_Exception("Price is 0 but priceIncTax is not"); } } else { // If it's a bundle item we have to calculate the tax from // the including/excluding tax values $taxPercent = round(100 * ($priceInclTax / $price - 1)); } } $qty = get_class($item) == 'Mage_Sales_Model_Quote_Item' ? $item->getQty() : $item->getQtyOrdered(); $orderRow = WebPayItem::orderRow()->setArticleNumber($item->getSku())->setQuantity((int) $qty)->setName($name)->setUnit(Mage::helper('svea_webpay')->__('unit'))->setVatPercent((int) $taxPercent)->setAmountIncVat((double) $priceInclTax); $svea->addOrderRow($orderRow); } $request = $taxCalculationModel->getRateRequest($order->getShippingAddress(), $order->getBillingAddress(), null, $store); // Shipping if ($order->getShippingAmount() > 0) { $shippingFee = WebPayItem::shippingFee()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setName($order->getShippingDescription()); // We require shipping tax to be set $shippingTaxClass = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $storeId); $rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass)); $shippingFee->setVatPercent((int) $rate); $shippingFee->setAmountIncVat($order->getShippingInclTax()); $svea->addFee($shippingFee); } // Discount $discount = abs($order->getDiscountAmount()); if ($discount > 0) { $discountRow = WebPayItem::fixedDiscount()->setName(Mage::helper('svea_webpay')->__('discount'))->setUnit(Mage::helper('svea_webpay')->__('unit'))->setAmountIncVat($discount); $svea->addDiscount($discountRow); } // Gift cards if (abs($order->getGiftCardsAmount()) > 0) { $giftCardRow = WebPayItem::fixedDiscount()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setAmountIncVat(abs($order->getGiftCardsAmount())); $svea->addDiscount($giftCardRow); } // Invoice fee $paymentFeeInclTax = $order->getSveaPaymentFeeInclTax(); if ($paymentFeeInclTax > 0) { $paymentFeeTaxClass = $this->getConfigData('handling_fee_tax_class'); $rate = $taxCalculationModel->getRate($request->setProductClassId($paymentFeeTaxClass)); $invoiceFeeRow = WebPayItem::invoiceFee()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setName(Mage::helper('svea_webpay')->__('invoice_fee'))->setVatPercent((int) $rate); $invoiceFeeRow->setAmountIncVat((double) $paymentFeeInclTax); $svea->addFee($invoiceFeeRow); } $svea->setCountryCode($billingAddress->getCountryId())->setClientOrderNumber($order->getIncrementId())->setOrderDate(date("Y-m-d"))->setCurrency($order->getOrderCurrencyCode()); return $svea; }
public function testResponseFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent() { $config = Svea\SveaConfig::getDefaultConfig(); $request = WebPay::createOrder($config)->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(123.9876)->setVatPercent(24)->setQuantity(1))->addFee(WebPayItem::shippingFee()->setAmountIncVat(100.0)->setVatPercent(24))->addFee(WebPayItem::invoiceFee()->setAmountIncVat(100.0)->setVatPercent(24))->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))->setCountryCode("SE")->setOrderDate("2012-12-12")->useInvoicePayment()->doRequest(); $this->assertEquals(1, $request->accepted); }
public function test_queryOrder_queryInvoiceOrder_single_order_row_with_invoice_fee_and_shipping_fee() { // create order using order row specified with ->setName() and ->setDescription $specifiedOrderRow = WebPayItem::orderRow()->setAmountExVat(100.0)->setVatPercent(25)->setQuantity(1)->setName("orderrow 1")->setDescription("description 1"); $invoiceFeeOrderRow = WebPayItem::invoiceFee()->setAmountExVat(20.0)->setVatPercent(25)->setName("invoicefee 1")->setDescription("invoicefee description 1"); $shippingFeeOrderRow = WebPayItem::shippingFee()->setAmountExVat(40.0)->setVatPercent(25)->setName("shippingfee 1")->setDescription("shippingfee description 1"); $order = TestUtil::createOrderWithoutOrderRows()->addOrderRow($specifiedOrderRow)->addOrderRow($invoiceFeeOrderRow)->addOrderRow($shippingFeeOrderRow); $createOrderResponse = $order->useInvoicePayment()->doRequest(); //print_r( $createOrderResponse ); $this->assertInstanceOf("Svea\\WebService\\CreateOrderResponse", $createOrderResponse); $this->assertTrue($createOrderResponse->accepted); $createdOrderId = $createOrderResponse->sveaOrderId; // query orderrows $queryOrderBuilder = WebPayAdmin::queryOrder(Svea\SveaConfig::getDefaultConfig())->setOrderId($createdOrderId)->setCountryCode("SE"); $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest(); //print_r( $queryResponse); $this->assertEquals(1, $queryResponse->accepted); $this->assertEquals(1, $queryResponse->numberedOrderRows[0]->rowNumber); $this->assertEquals(1.0, $queryResponse->numberedOrderRows[0]->quantity); $this->assertEquals(100.0, $queryResponse->numberedOrderRows[0]->amountExVat); $this->assertEquals(25, $queryResponse->numberedOrderRows[0]->vatPercent); $this->assertEquals(null, $queryResponse->numberedOrderRows[0]->name); $this->assertEquals("orderrow 1: description 1", $queryResponse->numberedOrderRows[0]->description); $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber); $this->assertEquals(1.0, $queryResponse->numberedOrderRows[1]->quantity); $this->assertEquals(20.0, $queryResponse->numberedOrderRows[1]->amountExVat); $this->assertEquals(25, $queryResponse->numberedOrderRows[1]->vatPercent); $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->name); $this->assertEquals("invoicefee 1: invoicefee description 1", $queryResponse->numberedOrderRows[1]->description); $this->assertEquals(3, $queryResponse->numberedOrderRows[2]->rowNumber); $this->assertEquals(1.0, $queryResponse->numberedOrderRows[2]->quantity); $this->assertEquals(40.0, $queryResponse->numberedOrderRows[2]->amountExVat); $this->assertEquals(25, $queryResponse->numberedOrderRows[2]->vatPercent); $this->assertEquals(null, $queryResponse->numberedOrderRows[2]->name); $this->assertEquals("shippingfee 1: shippingfee description 1", $queryResponse->numberedOrderRows[2]->description); }
public function testOrderRowsInOrderAsAddedOnHosted() { $config = SveaConfig::getDefaultConfig(); $request = \WebPay::createOrder($config); $form = $request->addOrderRow(\WebPayItem::orderRow()->setDescription("1")->setQuantity(1)->setAmountIncVat(10.0)->setVatPercent(25))->addFee(\WebPayItem::invoiceFee()->setDescription("2")->setVatPercent(25)->setAmountIncVat(30))->addOrderRow(\WebPayItem::orderRow()->setDescription("3")->setQuantity(1)->setAmountIncVat(20.0)->setVatPercent(25))->addDiscount(\WebPayItem::fixedDiscount()->setDescription("4")->setAmountIncVat(10))->setCountryCode("SE")->setClientOrderNumber("33")->setOrderDate("2012-12-12")->setCurrency("SEK")->usePaymentMethod(\PaymentMethod::SVEACARDPAY)->setReturnUrl("http://myurl.se")->getPaymentForm(); $xmlMessage = new \SimpleXMLElement($form->xmlMessage); $this->assertEquals('1', $xmlMessage->orderrows->row[0]->description); $this->assertEquals('2', $xmlMessage->orderrows->row[1]->description); $this->assertEquals('3', $xmlMessage->orderrows->row[2]->description); $this->assertEquals('4', $xmlMessage->orderrows->row[3]->description); }
public static function invoiceFee() { return WebPayItem::invoiceFee(); }