public function testPaymentMethodInvoiceNLCallbackUrl()
 {
     $config = SveaConfig::getDefaultConfig();
     $form = \WebPay::createOrder($config)->addOrderRow(\TestUtil::createOrderRow())->addCustomerDetails(\WebPayItem::individualCustomer()->setInitials("SB")->setBirthDate(1923, 12, 12)->setName("Sneider", "Boasman")->setEmail("*****@*****.**")->setPhoneNumber(999999)->setIpAddress("123.123.123")->setStreetAddress("Gatan", 23)->setCoAddress("c/o Eriksson")->setZipCode(9999)->setLocality("Stan"))->setCountryCode("NL")->setClientOrderNumber("33")->setOrderDate("2012-12-12")->setCurrency("SEK")->usePaymentMethod(\PaymentMethod::INVOICE)->setReturnUrl("http://myurl.se")->setCallbackUrl("http://myurl.se")->getPaymentForm();
     $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
     $this->assertEquals("http://myurl.se", $xmlMessage->callbackurl);
 }
 /**
  * @expectedException Svea\ValidationException
  * @expectedExceptionMessage -missing value : InvoiceDistributionType is required for deliverInvoiceOrder. Use function setInvoiceDistributionType().
  */
 public function testFailOnMissingInvoiceDetailsOnInvoiceDeliver()
 {
     $config = Svea\SveaConfig::getDefaultConfig();
     $builder = WebPay::deliverOrder($config);
     $object = $builder->addOrderRow(TestUtil::createOrderRow())->addFee(WebPayItem::shippingFee()->setShippingId('33')->setName('shipping')->setDescription("Specification")->setAmountExVat(50)->setUnit("st")->setVatPercent(25)->setDiscountPercent(0))->setOrderId('id')->deliverInvoiceOrder();
     $object->prepareRequest();
 }
 public function testPaymentPlanRequestReturnsAcceptedResult()
 {
     $config = Svea\SveaConfig::getDefaultConfig();
     $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
     $request = WebPay::createOrder($config)->addOrderRow(WebPayItem::orderRow()->setArticleNumber("1")->setQuantity(2)->setAmountExVat(1000.0)->setDescription("Specification")->setName('Prod')->setUnit("st")->setVatPercent(25)->setDiscountPercent(0))->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222)->setInitials("SB")->setBirthDate(1923, 12, 12)->setName("Tess", "Testson")->setEmail("*****@*****.**")->setPhoneNumber(999999)->setIpAddress("123.123.123")->setStreetAddress("Gatan", 23)->setCoAddress("c/o Eriksson")->setZipCode(9999)->setLocality("Stan"))->setCountryCode("SE")->setCustomerReference("33")->setClientOrderNumber("nr26")->setOrderDate("2012-12-12")->setCurrency("SEK")->usePaymentPlanPayment($campaigncode)->doRequest();
     $this->assertEquals(1, $request->accepted);
 }
 /**
  * @expectedException Svea\ValidationException
  * @expectedExceptionMessage -missing value : Description is required.
  */
 public function test_creditOrderRows_creditPyamentplanOrderRows_noDesciription()
 {
     $config = Svea\SveaConfig::getDefaultConfig();
     $orderRows[] = WebPayItem::orderRow()->setAmountIncVat(10.0)->setVatPercent(25)->setQuantity(1);
     $orderRows[] = WebPayItem::orderRow()->setAmountIncVat(10.0)->setVatPercent(25)->setQuantity(1);
     $credit = WebPayAdmin::creditOrderRows($config)->setContractNumber(123123)->setCountryCode('SE')->addCreditOrderRows($orderRows)->creditPaymentplanOrderRows()->prepareRequest();
 }
 public function test_deliver_multiple_invoice_orderRows_returns_accepted_with_invoiceId()
 {
     // create order
     $country = "SE";
     $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))->addOrderRow(WebPayItem::orderRow()->setDescription("second row")->setQuantity(1)->setAmountExVat(16.0)->setVatPercent(25))->addOrderRow(WebPayItem::orderRow()->setDescription("third row")->setQuantity(1)->setAmountExVat(24.0)->setVatPercent(25));
     $orderResponse = $order->useInvoicePayment()->doRequest();
     ////print_r( $orderResponse );
     $this->assertEquals(1, $orderResponse->accepted);
     $myOrderId = $orderResponse->sveaOrderId;
     // deliver first row in order
     $deliverOrderRowsRequest = WebPayAdmin::deliverOrderRows(Svea\SveaConfig::getDefaultConfig());
     $deliverOrderRowsRequest->setCountryCode($country);
     $deliverOrderRowsRequest->setOrderId($myOrderId);
     $deliverOrderRowsRequest->setInvoiceDistributionType(DistributionType::POST);
     $deliverOrderRowsRequest->setRowsToDeliver(array(1, 2));
     $deliverOrderRowsResponse = $deliverOrderRowsRequest->deliverInvoiceOrderRows()->doRequest();
     ////print_r( $deliverOrderRowsResponse );
     $this->assertInstanceOf('Svea\\AdminService\\DeliverPartialResponse', $deliverOrderRowsResponse);
     $this->assertEquals(true, $deliverOrderRowsResponse->accepted);
     // truth
     $this->assertEquals(1, $deliverOrderRowsResponse->accepted);
     // equals literal 1
     $this->assertEquals(0, $deliverOrderRowsResponse->resultcode);
     $this->assertEquals(270.0, $deliverOrderRowsResponse->amount);
     $this->assertEquals("Invoice", $deliverOrderRowsResponse->orderType);
     $this->assertNotNull($deliverOrderRowsResponse->invoiceId);
 }
Beispiel #6
0
 /**
  * This method is a sad reality in order for the total amount to work in
  * all the different magento versions we support. Calculations differ
  * between systems and we can't at this point send only the grand total
  * value (that would fix things).
  *
  * @param $request
  * @param $order
  * @return mixed
  */
 protected function _equalizeRows($request, $order)
 {
     // Find out what the amount is, and if it differs from the Magento
     // grand total, add it as an equalisation row
     $paymentForm = $request->getPaymentForm();
     $message = @simplexml_load_string($paymentForm->xmlMessage);
     $amount = (int) $message->amount;
     $grandTotal = (int) ($order->getGrandTotal() * 100);
     if ($amount !== $grandTotal) {
         // The difference can be negative or positive
         $diff = $grandTotal - $amount;
         $diff /= 100;
         $svea = $request->order;
         if ($diff < 0) {
             // Negative, use a discount row
             $row = WebPayItem::fixedDiscount()->setUnit(Mage::helper('svea_webpay')->__('unit'))->setAmountIncVat(abs($diff));
             $svea->addDiscount($row);
         } else {
             // Positive, use a normal order row
             $rate = $this->_getOrderMainTaxRate($order);
             $row = WebPayItem::orderRow()->setArticleNumber('eq')->setQuantity(1)->setName('Magento Equalisation')->setUnit(Mage::helper('svea_webpay')->__('unit'))->setVatPercent($rate)->setAmountIncVat($diff);
             $svea->addOrderRow($row);
         }
     }
     return $request;
 }
 public function test_createOrder_usePayPage_redirects_to_paypage()
 {
     $config = Svea\SveaConfig::getDefaultConfig();
     $rowFactory = new TestUtil();
     $form = WebPay::createOrder($config)->addOrderRow(TestUtil::createOrderRow())->run($rowFactory->buildShippingFee())->addDiscount(WebPayItem::relativeDiscount()->setDiscountId("1")->setDiscountPercent(50)->setUnit("st")->setName('Relative')->setDescription("RelativeDiscount"))->setCountryCode("SE")->setClientOrderNumber("foobar" . date('c'))->setOrderDate("2012-12-12")->setCurrency("SEK")->usePayPage()->setReturnUrl("http://myurl.se")->getPaymentForm();
     $url = "https://test.sveaekonomi.se/webpay/payment";
     /** CURL  **/
     $fields = array('merchantid' => urlencode($form->merchantid), 'message' => urlencode($form->xmlMessageBase64), 'mac' => urlencode($form->mac));
     $fieldsString = "";
     foreach ($fields as $key => $value) {
         $fieldsString .= $key . '=' . $value . '&';
     }
     rtrim($fieldsString, '&');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, count($fields));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     // follow redirects
     curl_setopt($ch, CURLOPT_HEADER, true);
     // include headers in transfer history
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // return transfer history
     $cr = curl_exec($ch);
     $info = curl_getinfo($ch);
     curl_close($ch);
     //print_r( $cr);
     $this->assertEquals(200, $info['http_code']);
     $this->assertEquals(2, $info['redirect_count']);
     $expected_infourl = "https://test.sveaekonomi.se/webpay/public/static/paypage.html";
     $start_of_actual_infourl = substr($info['url'], 0, strlen($expected_infourl));
     $this->assertEquals($expected_infourl, $start_of_actual_infourl);
 }
 public function testOrderWithSEConfigFromFunction()
 {
     $request = \WebPay::createOrder(SveaConfig::getTestConfig())->addOrderRow(\TestUtil::createOrderRow())->addCustomerDetails(\WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))->setCountryCode("SE")->setCustomerReference("33")->setOrderDate("2012-12-12")->setCurrency("SEK")->useInvoicePayment()->prepareRequest();
     $this->assertEquals("sverigetest", $request->request->Auth->Username);
     $this->assertEquals("sverigetest", $request->request->Auth->Password);
     $this->assertEquals(79021, $request->request->Auth->ClientNumber);
 }
 public function testBuildDirectBankPaymentCallBackUrl()
 {
     $config = SveaConfig::getDefaultConfig();
     $rowFactory = new \TestUtil();
     $form = \WebPay::createOrder($config)->addOrderRow(\TestUtil::createOrderRow())->addCustomerDetails(\WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))->setCountryCode("SE")->setClientOrderNumber("33")->setOrderDate("2012-12-12")->setCurrency("SEK")->usePayPageDirectBankOnly()->setReturnUrl("http://myurl.se")->setCallbackUrl("http://myurl.se")->getPaymentForm();
     $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
     $this->assertEquals("http://myurl.se", $xmlMessage->callbackurl);
 }
 public function testBuildPayPagePaymentCallBackUrl()
 {
     $config = SveaConfig::getDefaultConfig();
     $rowFactory = new \TestUtil();
     $form = \WebPay::createOrder($config)->addOrderRow(\WebPayItem::orderRow()->setQuantity(2)->setAmountExVat(100.0)->setName('Prod')->setVatPercent(0))->setCountryCode("SE")->setClientOrderNumber("33")->setCurrency("SEK")->usePayPage()->setReturnUrl("myurl")->setCallbackUrl("http://myurl.se")->getPaymentForm();
     $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
     $this->assertEquals("http://myurl.se", $xmlMessage->callbackurl);
 }
 function test_CancelOrderBuilder_PaymentPlan_success()
 {
     $country = "SE";
     $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))->addOrderRow(WebPayItem::orderRow()->setQuantity(1)->setAmountExVat(1000.0)->setVatPercent(25));
     $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
     $this->assertEquals(1, $orderResponse->accepted);
     $cancelResponse = WebPayAdmin::cancelOrder(Svea\SveaConfig::getDefaultConfig())->setOrderId($orderResponse->sveaOrderId)->setCountryCode($country)->cancelPaymentPlanOrder()->doRequest();
     $this->assertEquals(1, $cancelResponse->accepted);
 }
 public function test_add_new_notes_invoice()
 {
     $config = Svea\SveaConfig::getDefaultConfig();
     $orderResponse = WebPay::createOrder($config)->addOrderRow(WebPayItem::orderRow()->setAmountExVat(145.0)->setVatPercent(24)->setQuantity(1))->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))->setCountryCode("SE")->setOrderDate("2012-12-12")->useInvoicePayment()->doRequest();
     $this->assertEquals(1, $orderResponse->accepted);
     $response = WebPayAdmin::updateOrder($config)->setCountryCode('SE')->setOrderId($orderResponse->sveaOrderId)->setNotes($this->notes)->updateInvoiceOrder()->doRequest();
     $this->assertEquals(1, $response->accepted);
     // query order and assert row totals
     $query2 = WebPayAdmin::queryOrder($config)->setOrderId($orderResponse->sveaOrderId)->setCountryCode('SE')->queryInvoiceOrder()->doRequest();
     $this->assertEquals(1, $query2->accepted);
     $this->assertEquals($this->notes, $query2->notes);
     //print_r($orderResponse->sveaOrderId);
 }
 public function test_bv_order_sent_incvat_two_decimals_with_both_discounts_with_amount_only()
 {
     //    print_r("\n\n-----test_bv_order_sent_incvat_two_decimals_with_both_discounts_with_amount_only()\n");
     $order = WebPay::createOrder(Svea\SveaConfig::getDefaultConfig())->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))->setCountryCode("SE")->setCustomerReference("1337")->setOrderDate("2015-05-20")->setCurrency("SEK")->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(1.0)->setVatPercent(6)->setQuantity(800)->setName("3.00i@6%*800"))->setClientOrderNumber(date('c'));
     $order->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(240)->setDiscountId("fixedDiscount")->setName("-240i*1"));
     $order->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(20)->setDiscountId("fixedDiscount2")->setName("-20i*1"));
     $request = $order->usePaymentMethod(PaymentMethod::KORTCERT)->setReturnUrl("https://test.sveaekonomi.se/webpay-admin/admin/merchantresponsetest.xhtml");
     $request = $request->getPaymentForm();
     //    print_r( $request->xmlMessage );
     // 240i@6% => 240 (13,58491) => 24000 (1358)
     $expectedDiscountRow = "  <row>\n" . "   <sku>fixedDiscount</sku>\n" . "   <name>-240i*1</name>\n" . "   <description></description>\n" . "   <amount>-24000</amount>\n" . "   <vat>-1358</vat>\n";
     "   <quantity>1</quantity>\n" . "  </row>\n";
     $this->assertEquals(1, substr_count($request->xmlMessage, $expectedDiscountRow));
     // 20i@6% => 2000 (1,132076) => 2000 (113)
     $expectedDiscountRow2 = "  <row>\n" . "   <sku>fixedDiscount2</sku>\n" . "   <name>-20i*1</name>\n" . "   <description></description>\n" . "   <amount>-2000</amount>\n" . "   <vat>-113</vat>\n";
     "   <quantity>1</quantity>\n" . "  </row>\n";
     $this->assertEquals(1, substr_count($request->xmlMessage, $expectedDiscountRow2));
     // lagt ordern med den dumpade xml:en från utskriften i tools/payment, ger detta response:
     //<response>
     //  <transaction id="600123">
     //    <paymentmethod>KORTCERT</paymentmethod>
     //    <merchantid>1130</merchantid>
     //    <customerrefno>2015-05-22T13:00:54 02:00</customerrefno>
     //    <amount>54000</amount>
     //    <currency>SEK</currency>
     //    <cardtype>VISA</cardtype>
     //    <maskedcardno>444433xxxxxx1100</maskedcardno>
     //    <expirymonth>02</expirymonth>
     //    <expiryyear>17</expiryyear>
     //    <authcode>594378</authcode>
     //    <customer>
     //      <firstname/>
     //      <lastname/>
     //      <initials/>
     //      <email/>
     //      <ssn>194605092222</ssn>
     //      <address/>
     //      <address2/>
     //      <city/>
     //      <country>SE</country>
     //      <zip/>
     //      <phone/>
     //      <vatnumber/>
     //      <housenumber/>
     //      <companyname/>
     //      <fullname/>
     //    </customer>
     //  </transaction>
     //  <statuscode>0</statuscode>
     //</response>
 }
 /** helper function, returns invoice for delivered order with one row, sent with PriceIncludingVat flag set to false */
 public function get_orderInfo_sent_ex_vat($amount, $vat, $quantity, $is_paymentplan = NULL)
 {
     $config = Svea\SveaConfig::getDefaultConfig();
     if ($is_paymentplan) {
         $campaignCode = TestUtil::getGetPaymentPlanParamsForTesting();
     }
     $orderResponse = WebPay::createOrder($config)->addOrderRow(WebPayItem::orderRow()->setAmountExVat($amount)->setVatPercent($vat)->setQuantity($quantity))->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))->setCountryCode("SE")->setOrderDate("2012-12-12");
     if ($is_paymentplan) {
         $orderResponse = $orderResponse->usePaymentPlanPayment($campaignCode)->doRequest();
     }
     $this->assertEquals(1, $orderResponse->accepted);
     if ($is_paymentplan) {
         $deliver = WebPay::deliverOrder($config)->setOrderId($orderResponse->sveaOrderId)->setCountryCode('SE')->deliverPaymentPlanOrder()->doRequest();
     }
     $this->assertEquals(1, $deliver->accepted);
     return new orderToCreditAmount($orderResponse->sveaOrderId, NULL, $deliver->contractNumber);
 }
 public function test_cancel_multiple_paymentplan_orderRows_()
 {
     // create order
     $country = "SE";
     $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
     $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))->addOrderRow(WebPayItem::orderRow()->setDescription("second row")->setQuantity(1)->setAmountExVat(1600.0)->setVatPercent(25))->addOrderRow(WebPayItem::orderRow()->setDescription("third row")->setQuantity(1)->setAmountExVat(2400.0)->setVatPercent(25));
     $orderResponse = $order->usePaymentPlanPayment($campaigncode)->doRequest();
     ////print_r( $orderResponse );
     $this->assertEquals(1, $orderResponse->accepted);
     $myOrderId = $orderResponse->sveaOrderId;
     // cancel first row in order
     $cancelOrderRowsRequest = WebPayAdmin::cancelOrderRows(Svea\SveaConfig::getDefaultConfig());
     $cancelOrderRowsRequest->setCountryCode($country);
     $cancelOrderRowsRequest->setOrderId($myOrderId);
     $cancelOrderRowsRequest->setRowsToCancel(array(1, 2));
     $cancelOrderRowsResponse = $cancelOrderRowsRequest->cancelPaymentPlanOrderRows()->doRequest();
     ////print_r( $cancelOrderRowsResponse );
     $this->assertInstanceOf('Svea\\AdminService\\CancelOrderRowsResponse', $cancelOrderRowsResponse);
     $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 function test_AddOrderRows_addInvoiceOrderRows_specified_with_price_specified_using_inc_vat_and_ex_vat()
 {
     $country = "SE";
     $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
     $order->addOrderRow(WebPayItem::orderRow()->setArticleNumber("1")->setQuantity(1)->setAmountExVat(100.0)->setVatPercent(25)->setDescription("Specification")->setName('Product')->setUnit("st")->setDiscountPercent(0));
     $orderResponse = $order->useInvoicePayment()->doRequest();
     $this->assertEquals(1, $orderResponse->accepted);
     $addOrderRowsBuilder = new \Svea\AddOrderRowsBuilder(Svea\SveaConfig::getDefaultConfig());
     $addOrderRowsResponse = $addOrderRowsBuilder->setOrderId($orderResponse->sveaOrderId)->setCountryCode($country)->addOrderRow(WebPayItem::orderRow()->setArticleNumber("1")->setQuantity(1)->setAmountIncVat(1.0 * 1.25)->setVatPercent(25)->setDescription("Specification")->setName('Product')->setUnit("st")->setDiscountPercent(0))->addOrderRow(WebPayItem::orderRow()->setArticleNumber("1")->setQuantity(1)->setAmountExVat(4.0)->setAmountIncVat(4.0 * 1.25)->setDescription("Specification")->setName('Product')->setUnit("st")->setDiscountPercent(0))->addInvoiceOrderRows()->doRequest();
     $this->assertEquals(1, $addOrderRowsResponse->accepted);
 }
 /**
  * test_manual_queryOrder_queryDirectBank_order_step_1
  *
  */
 function test_manual_queryOrder_queryDirectBank_order_step_1()
 {
     // Stop here and mark this test as incomplete.
     $this->markTestIncomplete('skeleton for test_manual_queryOrder_queryDirectBank_order_step_1, step 1');
     // 1. remove (put in a comment) the above code to enable the test
     // 2. run the test, and get the paymenturl from the output
     // 3. go to the paymenturl and complete the transaction manually, making note of the response transactionid
     // 4. enter the transactionid into test_manual_queryOrder_queryCard_order_step_12() below and run the test
     $orderLanguage = "sv";
     $returnUrl = "http://foo.bar.com";
     $ipAddress = "127.0.0.1";
     // create order
     $order = \TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
     // create order w/three rows (2xA, 1xB)
     $country = "SE";
     $a_quantity = 2;
     $a_amountExVat = 1000.0;
     $a_vatPercent = 25;
     $b_quantity = 1;
     $b_amountExVat = 100.0;
     $b_vatPercent = 12;
     $b_articleNumber = "Red 5";
     $b_unit = "pcs.";
     $b_name = "B Name";
     $b_description = "B Description";
     $b_discount = 0;
     $order->addOrderRow(WebPayItem::orderRow()->setQuantity($a_quantity)->setAmountExVat($a_amountExVat)->setVatPercent($a_vatPercent))->addOrderRow(WebPayItem::orderRow()->setQuantity($b_quantity)->setAmountExVat($b_amountExVat)->setVatPercent($b_vatPercent)->setArticleNumber($b_articleNumber)->setUnit($b_unit)->setName($b_name)->setDescription($b_description)->setDiscountPercent($b_discount));
     // set payment method
     // call getPaymentURL
     $response = $order->usePayPageDirectBankOnly()->setPayPageLanguage($orderLanguage)->setReturnUrl($returnUrl)->getPaymentUrl();
     // check that request was accepted
     $this->assertEquals(1, $response->accepted);
     // print the url to use to confirm the transaction
     //print_r( " test_manual_queryOrder_queryDirectBank_order_step_1(): " . $response->testurl ." ");
 }
 /**
  * test_manual_CancelOrderBuilderRows_Card_single_row_success_step_1
  *
  */
 function test_manual_CancelOrderBuilderRows_Card_multiple_rows_success_step_1()
 {
     // Stop here and mark this test as incomplete.
     $this->markTestIncomplete('skeleton for test_manual_CancelOrderBuilderRows_Card_single_row_success_step_1, step 1');
     // 1. remove (put in a comment) the above code to enable the test
     // 2. run the test, and get the paymenturl from the output
     // 3. go to the paymenturl and complete the transaction manually, making note of the response transactionid
     // 4. enter the transactionid into test_manual_queryOrder_queryCard_order_step_2() below and run the test
     $orderLanguage = "sv";
     $returnUrl = "http://foo.bar.com";
     $ipAddress = "127.0.0.1";
     // create order w/three rows
     $order = \TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
     // 2x100 @25 = 25000 (5000)
     // 1x100 @25 = 12500 (2500)
     // 1x100 @12 = 11200 (1200)
     // amount = 48700, vat = 8700
     $country = "SE";
     $order->addOrderRow(WebPayItem::orderRow()->setQuantity(2)->setAmountExVat(100.0)->setVatPercent(25))->addOrderRow(WebPayItem::orderRow()->setQuantity(1)->setAmountExVat(100.0)->setVatPercent(25))->addOrderRow(WebPayItem::orderRow()->setQuantity(1)->setAmountExVat(100.0)->setVatPercent(12));
     $response = $order->usePayPageCardOnly()->setPayPageLanguage($orderLanguage)->setReturnUrl($returnUrl)->getPaymentUrl();
     // check that request was accepted
     $this->assertEquals(1, $response->accepted);
     // print the url to use to confirm the transaction
     //print_r( "\n test_manual_CancelOrderBuilderRows_Card_single_row_success_step_1(): " . $response->testurl ."\n ");
 }
 public function test_deliverOrder_deliverCardOrder_allows_orderRow_with_zero_amount()
 {
     $dummyorderid = 123456;
     $deliverOrderBuilder = WebPay::deliverOrder(Svea\SveaConfig::getDefaultConfig())->setOrderId($dummyorderid)->setCountryCode("SE")->setInvoiceDistributionType(DistributionType::POST)->addOrderRow(WebPayItem::orderRow()->setAmountExVat(0.0)->setVatPercent(0)->setQuantity(0));
     try {
         $request = $deliverOrderBuilder->deliverCardOrder()->prepareRequest();
     } catch (Exception $e) {
         // fail on validation error
         $this->fail("Unexpected validation exception: " . $e->getMessage());
     }
 }
 public function test_add_row_multiple_times_as_incvat_mixed_with_exvat()
 {
     $orderrowArray[] = WebPayItem::orderRow()->setAmountExVat(99.98999999999999)->setVatPercent(24)->setQuantity(1);
     $orderrowArray[] = WebPayItem::orderRow()->setAmountExVat(99.98999999999999)->setVatPercent(24)->setQuantity(1);
     $orderrowArray[] = WebPayItem::orderRow()->setAmountIncVat(123.9876)->setVatPercent(24)->setQuantity(1);
     $config = Svea\SveaConfig::getDefaultConfig();
     $request = WebPayAdmin::addOrderRows($config)->setOrderId('sveaOrderId')->setCountryCode('SE')->addOrderRow(WebPayItem::orderRow()->setAmountExVat(99.98999999999999)->setVatPercent(24)->setQuantity(1))->addOrderRow(WebPayItem::orderRow()->setAmountExVat(99.98999999999999)->setAmountIncVat(123.9876)->setQuantity(1))->addOrderRow(WebPayItem::orderRow()->setVatPercent(24)->setAmountIncVat(123.9876)->setQuantity(1))->addInvoiceOrderRows()->prepareRequest();
     $this->assertEquals(99.98999999999999, $request->OrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
     $this->assertFalse($request->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
     $this->assertEquals(99.98999999999999, $request->OrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
     $this->assertFalse($request->OrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
     $this->assertEquals(99.98999999999999, $request->OrderRows->enc_value->enc_value[2]->enc_value->PricePerUnit->enc_value);
     $this->assertFalse($request->OrderRows->enc_value->enc_value[2]->enc_value->PriceIncludingVat->enc_value);
 }
 public function test_getRequestTotals_reference_1321_00_ex_behaviour()
 {
     $config = Svea\SveaConfig::getDefaultConfig();
     $order = WebPay::createOrder($config)->addOrderRow(WebPayItem::orderRow()->setAmountExVat(1321.0)->setVatPercent(6)->setQuantity(1))->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))->setCountryCode("SE")->setOrderDate("2016-04-14");
     $preview_total = $order->useInvoicePayment()->getRequestTotals();
     $this->assertEquals(1400.26, $preview_total['total_incvat']);
     $this->assertEquals(1321.0, $preview_total['total_exvat']);
     $this->assertEquals(79.26000000000001, $preview_total['total_vat']);
 }
 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_createOrder_Paymentplan_SE_Accepted()
 {
     $order = WebPay::createOrder(Svea\SveaConfig::getDefaultConfig())->addOrderRow(WebPayItem::orderRow()->setQuantity(1)->setAmountExVat(1000.0)->setVatPercent(25))->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))->setCountryCode("SE")->setCurrency("SEK")->setOrderDate(date('c'));
     $response = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
     $this->assertEquals(1, $response->accepted);
 }
 public function test_deliverOrder_deliverPaymentPlanOrder_with_orderrows_misleadingly_delivers_order_in_full()
 {
     // create order
     $config = Svea\SveaConfig::getDefaultConfig();
     $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
     $order = WebPay::createOrder($config)->addOrderRow(WebPayItem::orderRow()->setArticleNumber("1")->setQuantity(2)->setAmountExVat(1000.0)->setDescription("Specification")->setName('Prod')->setUnit("st")->setVatPercent(25)->setDiscountPercent(0))->addOrderRow(WebPayItem::orderRow()->setArticleNumber("2")->setQuantity(2)->setAmountExVat(1000.0)->setDescription("Specification")->setName('Prod')->setUnit("st")->setVatPercent(25)->setDiscountPercent(0))->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222)->setInitials("SB")->setBirthDate(1923, 12, 12)->setName("Tess", "Testson")->setEmail("*****@*****.**")->setPhoneNumber(999999)->setIpAddress("123.123.123")->setStreetAddress("Gatan", 23)->setCoAddress("c/o Eriksson")->setZipCode(9999)->setLocality("Stan"))->setCountryCode("SE")->setCustomerReference("33")->setClientOrderNumber("nr26")->setOrderDate("2012-12-12")->setCurrency("SEK")->usePaymentPlanPayment($campaigncode)->doRequest();
     //print_r($order);
     $this->assertEquals(1, $order->accepted);
     $this->assertEquals(5000, $order->amount);
     // deliver order
     $orderId = $order->sveaOrderId;
     $orderBuilder = WebPay::deliverOrder($config);
     $deliverResponse = $orderBuilder->addOrderRow(WebPayItem::orderRow()->setArticleNumber("1")->setQuantity(2)->setAmountExVat(1000.0)->setDescription("Specification")->setName('Prod')->setUnit("st")->setVatPercent(25)->setDiscountPercent(0))->setOrderId($orderId)->setInvoiceDistributionType("Post")->setCountryCode("SE")->deliverPaymentPlanOrder()->doRequest();
     //print_r($deliverResponse);
     $this->assertEquals(1, $deliverResponse->accepted);
     $this->assertEquals(5000, $deliverResponse->amount);
 }
 public function test_incvat_order_with_fixedDiscount_as_incvat_and_vatpercent_has_priceIncludingVat_true()
 {
     $order = FixedDiscountRowsTest::create_only_incvat_order_and_fee_rows_order();
     $order->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(11.0)->setVatPercent(10)->setDiscountId("fixedDiscount")->setName("fixedDiscount: 11i@10%"));
     $request = $order->useInvoicePayment()->prepareRequest();
     // all order rows
     $this->assertEquals(72.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(33.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(8.800000000000001, $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(17.6, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
     $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: 11incvat @10% = -11.00
     $this->assertEquals(-11.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
     $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
     $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
     $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
     // See file IntegrationTest/WebService/Payment/FixedDiscountRowsIntegrationTest for service response tests.
 }
 public function testCreateOrderWithDiscountAsAmountExAndDeliverWithAmountIncvat()
 {
     $config = Svea\SveaConfig::getDefaultConfig();
     $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
     $order = WebPay::createOrder($config)->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(1239.876)->setVatPercent(24)->setQuantity(1))->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(8)->setVatPercent(24))->addDiscount(WebPayItem::relativeDiscount()->setDiscountPercent(10))->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))->addDiscount(WebPayItem::fixedDiscount()->setAmountExVat(8)->setVatPercent(24))->addDiscount(WebPayItem::relativeDiscount()->setDiscountPercent(10))->setOrderId($order->sveaOrderId)->setInvoiceDistributionType(DistributionType::POST)->setCountryCode("SE")->deliverPaymentPlanOrder()->doRequest();
     $this->assertEquals(1, $request->accepted);
 }
Beispiel #29
0
 /**
  * Add Customer details to Svea CreateOrder object
  *
  * @param type $order
  * @param type $additionalInfo
  * @return type Svea CreateOrder object
  */
 public function getSveaPaymentObject($order, $additionalInfo = null)
 {
     $svea = parent::getSveaPaymentObject($order, $additionalInfo);
     //Add more customer info
     $countryCode = $order->getBillingAddress()->getCountryId();
     $company = $additionalInfo['svea_customerType'];
     $address = $order->getBillingAddress()->getStreetFull();
     $addressArray = \Svea\Helper::splitStreetAddress($address);
     if ($company == "1") {
         $item = WebPayItem::companyCustomer();
         $item = $item->setEmail($order->getBillingAddress()->getEmail())->setCompanyName($order->getBillingAddress()->getCompany())->setStreetAddress($addressArray[1], $addressArray[2])->setZipCode($order->getBillingAddress()->getPostcode())->setLocality($order->getBillingAddress()->getCity())->setIpAddress(Mage::helper('core/http')->getRemoteAddr(false))->setPhoneNumber($order->getBillingAddress()->getTelephone());
         if ($countryCode == "DE" || $countryCode == "NL") {
             $item = $item->setVatNumber($additionalInfo['svea_vatNo']);
         } else {
             $item = $item->setNationalIdNumber($additionalInfo['svea_ssn']);
             $item = $item->setAddressSelector($additionalInfo['svea_addressSelector']);
         }
     } else {
         $item = WebPayItem::individualCustomer();
         // Not all countries has svea_ssn input
         if (array_key_exists('svea_ssn', $additionalInfo)) {
             $item = $item->setNationalIdNumber($additionalInfo['svea_ssn']);
         }
         $item = $item->setEmail($order->getBillingAddress()->getEmail())->setName($order->getBillingAddress()->getFirstname(), $order->getBillingAddress()->getLastname())->setStreetAddress($addressArray[1], $addressArray[2])->setZipCode($order->getBillingAddress()->getPostcode())->setLocality($order->getBillingAddress()->getCity())->setIpAddress(Mage::helper('core/http')->getRemoteAddr(false))->setPhoneNumber($order->getBillingAddress()->getTelephone());
         if ($countryCode == "DE" || $countryCode == "NL") {
             $validBirthday = true;
             foreach (array('svea_birthYear', 'svea_birthMonth', 'svea_birthDay') as $key) {
                 if (!array_key_exists($key, $additionalInfo) || trim($additionalInfo[$key]) === "") {
                     $validBirthday = false;
                 }
             }
             if ($validBirthday) {
                 $item = $item->setBirthDate($additionalInfo['svea_birthYear'], $additionalInfo['svea_birthMonth'], $additionalInfo['svea_birthDay']);
             }
         }
         if ($countryCode == "NL") {
             if (array_key_exists('svea_initials', $additionalInfo)) {
                 $item = $item->setInitials($additionalInfo['svea_initials']);
             }
         }
     }
     // Set public key on the object if publicKey is set in additionalInfo
     if (array_key_exists('svea_publicKey', $additionalInfo)) {
         $publicKey = $additionalInfo['svea_publicKey'];
         if ($publicKey !== '') {
             $item = $item->setPublicKey($publicKey);
             // $item = $item->setAddressSelector('');
         }
     }
     $svea = $svea->addCustomerDetails($item);
     return $svea;
 }
 public function test_incvat_order_with_fixedDiscount_as_incvat_and_vatpercent_has_priceIncludingVat_true()
 {
     $order = FixedDiscountRowsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
     $order->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(11.0)->setVatPercent(10)->setDiscountId("fixedDiscount")->setName("fixedDiscount: 11i@10%"));
     $request = $order->useInvoicePayment()->prepareRequest();
     // all order rows
     $this->assertEquals(72.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(33.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(8.800000000000001, $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(17.6, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
     $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: 11incvat @10% = -11.00
     $this->assertEquals(-11.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
     $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
     $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
     $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
     // check that service accepts order
     $response = $order->useInvoicePayment()->doRequest();
     $this->assertEquals(true, $response->accepted);
     // r() is round($val, 2, PHP_ROUND_HALF_EVEN), i.e. bankers rounding
     // r(72*1) + r(33*1) + r(17.60*1) + r(8.80*1) + r(-5.72*1.20*1) + r(-2.85*1.10*1) => 72.00+33.00+17.60+8.80-11.00 => 120.40
     $this->assertEquals("120.40", $response->amount);
 }