/**
  * 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);
 }
 public function test_paymentPlanPricePerMonth_returns_PaymentPlanPricePerMonth()
 {
     $campaigns = WebPay::getPaymentPlanParams(Svea\SveaConfig::getDefaultConfig())->setCountryCode("SE")->doRequest();
     $this->assertTrue($campaigns->accepted);
     $pricesPerMonth = Svea\Helper::paymentPlanPricePerMonth(2000, $campaigns, true);
     $this->assertInstanceOf("Svea\\WebService\\PaymentPlanPricePerMonth", $pricesPerMonth);
     //        $this->assertEquals(213060, $pricesPerMonth->values[0]['campaignCode']); //don't test to be flexible
     $this->assertEquals(2029, $pricesPerMonth->values[0]['pricePerMonth']);
 }
 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);
 }
Example #4
0
$firstBoughtItem = WebPayItem::orderRow();
$firstBoughtItem->setAmountExVat(10.99);
$firstBoughtItem->setVatPercent(25);
$firstBoughtItem->setQuantity(1);
$firstBoughtItem->setDescription("Billy");
$firstBoughtItem->setArticleNumber("123456789A");
// Add firstBoughtItem to order row
$myOrder->addOrderRow($firstBoughtItem);
// Add secondBoughtItem in a fluent fashion
$myOrder->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(5.0)->setVatPercent(12)->setQuantity(2)->setDescription("Korv med bröd"));
// For card orders the ->addCustomerDetails() method is optional, but recommended, so we'll add what info we have
$myCustomerInformation = WebPayItem::individualCustomer();
// there's also a ::companyCustomer() method, used for non-person entities
// Set customer information, using the methods from the IndividualCustomer class
$myCustomerInformation->setName($customerFirstName, $customerLastName);
$sveaAddress = Svea\Helper::splitStreetAddress($customerAddress);
// Svea requires an address and a house number
$myCustomerInformation->setStreetAddress($sveaAddress[0], $sveaAddress[1]);
$myCustomerInformation->setZipCode($customerZipCode)->setLocality($customerCity);
$myOrder->addCustomerDetails($myCustomerInformation);
// We have now completed specifying the order, and wish to send the payment request to Svea. To do so, we first select a payment method.
// For card orders, we recommend using the ->usePaymentMethod(PaymentMethod::SVEACARDPAY).
$myCardOrderRequest = $myOrder->usePaymentMethod(PaymentMethod::SVEACARDPAY);
// Then set any additional required request attributes as detailed below. (See Svea\PaymentMethodPayment and Svea\HostedPayment classes for details.)
$myCardOrderRequest->setCardPageLanguage("SV")->setReturnUrl("http://localhost/" . getPath() . "/landingpage.php");
// The return url where we receive and process the finished request response
// Get a payment form object which you can use to send the payment request to Svea
$myCardOrderPaymentForm = $myCardOrderRequest->getPaymentForm();
// Then send the form to Svea, and receive the response on the landingpage after the customer has completed the card checkout SveaCardPay
echo "<pre>";
print_r("press submit to send the card payment request to Svea");