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); }
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); }
/** * @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(); }
/** * 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 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> }
function test_UpdateOrderRows_updatePaymentPlanOrderRows_multiple_row_success() { $country = "SE"; // create order $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country)); $order->addOrderRow(WebPayItem::orderRow()->setArticleNumber("1")->setQuantity(1)->setAmountExVat(1000.0)->setVatPercent(25)->setDescription("A Specification")->setName('A Name')->setUnit("st")->setDiscountPercent(0)); $order->addOrderRow(WebPayItem::orderRow()->setArticleNumber("2")->setQuantity(1)->setAmountExVat(2000.0)->setVatPercent(25)->setDescription("B Specification")->setName('B Name')->setUnit("st")->setDiscountPercent(0)); $order->addOrderRow(WebPayItem::orderRow()->setArticleNumber("3")->setQuantity(1)->setAmountExVat(3000.0)->setVatPercent(25)->setDescription("C Specification")->setName('C Name')->setUnit("st")->setDiscountPercent(0)); $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest(); $this->assertEquals(1, $orderResponse->accepted); // update all attributes for a numbered orderRow $updateOrderRowsResponse = WebPayAdmin::updateOrderRows(Svea\SveaConfig::getDefaultConfig())->setOrderId($orderResponse->sveaOrderId)->setCountryCode($country)->updateOrderRow(WebPayItem::numberedOrderRow()->setArticleNumber("10")->setQuantity(1)->setAmountExVat(10.0)->setVatPercent(25)->setDescription("K Specification")->setName('K Name')->setUnit("st")->setDiscountPercent(1)->setRowNumber(1)->setStatus(Svea\NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED))->updateOrderRows(array(WebPayItem::numberedOrderRow()->setArticleNumber("20")->setQuantity(2)->setAmountExVat(20.0)->setVatPercent(25)->setDescription("K2 Specification")->setName('K2 Name')->setUnit("st")->setDiscountPercent(1)->setRowNumber(2)->setStatus(Svea\NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED), WebPayItem::numberedOrderRow()->setArticleNumber("30")->setQuantity(3)->setAmountExVat(30.0)->setVatPercent(25)->setDescription("K3 Specification")->setName('K3 Name')->setUnit("st")->setDiscountPercent(1)->setRowNumber(3)->setStatus(Svea\NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)))->updatePaymentPlanOrderRows()->doRequest(); ////print_r( $updateOrderRowsResponse ); ////print_r("test_UpdateOrderRows_updateInvoiceOrderRows_single_row_success: "); //print_r( $orderResponse->sveaOrderId ); $this->assertEquals(1, $updateOrderRowsResponse->accepted); // todo query result & check amounts, description automatically }
/** 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); }
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); }
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()); } }
/** * 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_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); }
// order currency $myOrder->setClientOrderNumber("order #" . date('c')); // required - use a not previously sent client side order identifier, i.e. "order #20140519-371" // You may also chain fluent methods together: $myOrder->setCustomerReference("customer #123")->setOrderDate("2014-05-28"); // Then specify the items bought as order rows, using the methods in the Svea\OrderRow class, and adding them to the order: $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");
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_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 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); }
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_add_publickey_for_private_customer_full_request() { $config = \Svea\SveaConfig::getTestConfig(); $order = WebPay::createOrder($config)->addCustomerDetails(WebPayItem::companyCustomer()->setCompanyName('mycomp')->setNationalIdNumber('164701161111')->setPublicKey('ac0f2573b58ff523'))->setCountryCode('SE')->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(125.0)->setVatPercent(25)->setQuantity(1))->setOrderDate(date('c'))->useInvoicePayment()->prepareRequest(); $this->assertEquals('ac0f2573b58ff523', $order->request->CreateOrderInformation->CustomerIdentity->PublicKey); }
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 testDeliverOrderSetAsMixedVatAndRelativeDiscount() { $config = Svea\SveaConfig::getDefaultConfig(); $request = WebPay::deliverOrder($config); $request = $request->addOrderRow(WebPayItem::orderRow()->setAmountIncVat(123.9876)->setVatPercent(24)->setQuantity(1))->addOrderRow(WebPayItem::orderRow()->setAmountExVat(99.98999999999999)->setVatPercent(24)->setQuantity(1))->addDiscount(WebPayItem::relativeDiscount()->setDiscountPercent(5))->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(-9.999000000000001, $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); }
require_once $svea_directory . "Includes.php"; // get config object $myConfig = Svea\SveaConfig::getTestConfig(); //replace with class holding your merchantid, secretword, et al, adopted from package Config/SveaConfig.php // Start the order creation process by creating the order builder object by calling WebPay::createOrder(): $myOrder = WebPay::createOrder($myConfig); // You then add information to the order object by using the methods in the Svea\CreateOrderBuilder class. // For a Card order, the following methods are required: $myOrder->setCountryCode("SE"); // customer country, we recommend basing this on the customer billing address $myOrder->setCurrency("SEK"); // order currency $myOrder->setClientOrderNumber("order #" . date('c')); // required - use a not previously sent client side order identifier, i.e. "order #20140519-371" // Add order item in a fluent fashion $myOrder->addOrderRow(WebPayItem::orderRow()->setAmountExVat(100.0)->setVatPercent(25)->setQuantity(1)->setDescription("Månadsavgift via recur")); // 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::KORTCERT), which processes card orders via SveaCardPay. $myRecurOrderRequest = $myOrder->usePaymentMethod(PaymentMethod::SVEACARDPAY); // For recurring card payments, use setSubscriptionId() on the request object, using the subscription id from the initial request response $mySubscriptionId = file_get_contents("subscription.txt"); if ($mySubscriptionId) { $myRecurOrderRequest->setSubscriptionId($mySubscriptionId); } else { echo "<pre>Error: subscription.txt not found, first run cardorder_recur.php to set up the card order subscription. aborting."; die; } // Then set any additional required request attributes as detailed below. (See Svea\PaymentMethodPayment and Svea\HostedPayment classes for details.) $myRecurOrderRequest->setCardPageLanguage("SV")->setReturnUrl("http://localhost/" . getPath() . "/landingpage_recur.php"); // The return url where we receive and process the finished request response // Send the recur payment request to Svea
require_once $svea_directory . "Includes.php"; // get config object $myConfig = Svea\SveaConfig::getTestConfig(); //replace with class holding your merchantid, secretword, et al, adopted from package Config/SveaConfig.php // Start the order creation process by creating the order builder object by calling WebPay::createOrder(): $myOrder = WebPay::createOrder($myConfig); // You then add information to the order object by using the methods in the Svea\CreateOrderBuilder class. // For a Card order, the following methods are required: $myOrder->setCountryCode("SE"); // customer country, we recommend basing this on the customer billing address $myOrder->setCurrency("SEK"); // order currency $myOrder->setClientOrderNumber("order #" . date('c')); // required - use a not previously sent client side order identifier, i.e. "order #20140519-371" // Then specify the items bought as order rows, using the methods in the Svea\OrderRow class, and adding them to the order: $myOrder->addOrderRow(WebPayItem::orderRow()->setAmountExVat(100.0)->setVatPercent(25)->setQuantity(1)->setDescription("A"))->addOrderRow(WebPayItem::orderRow()->setAmountExVat(100.0)->setVatPercent(25)->setQuantity(1)->setDescription("B"))->addOrderRow(WebPayItem::orderRow()->setAmountExVat(100.0)->setVatPercent(25)->setQuantity(1)->setDescription("C")); // The order total amount equals 1*(100*1.25) + 1*(100*1.25) + 1*(100*1.25) = SEK 375.00 (incl. vat 75.00) // 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), which processes card orders via 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_credit.php"); // The return url where we receive and process the finished request response // Get a payment form object which we 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 at SveaCardPay echo "<pre>"; echo "Press submit to send the inital card order request to Svea."; print_r($myCardOrderPaymentForm->completeHtmlFormWithSubmitButton); /** * get the path to this file, for use in specifying the returnurl etc.
/** * 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); }
/** * 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 ." "); }
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; }
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']); }