/**
  * @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();
 }
Esempio n. 2
0
 /**
  * For Svea, Deliver order
  *
  * @param Varien_Object $payment
  * @param float $amount
  * @return type
  */
 public function capture(Varien_Object $payment, $amount)
 {
     //Alternative: $sveaOrderId = $payment->getTransactionId(), comes with -capture
     $sveaOrderId = $this->getInfoInstance()->getAdditionalInformation('svea_order_id');
     if (empty($sveaOrderId)) {
         if (!$this->getConfigData('autodeliver')) {
             $errorTranslated = Mage::helper('svea_webpay')->responseCodes("", 'no_orderid');
             Mage::throwException($errorTranslated);
         }
         $sveaOrderId = $this->getInfoInstance()->getAdditionalInformation('svea_order_id');
     }
     $order = $payment->getOrder();
     $countryCode = $order->getBillingAddress()->getCountryId();
     $paymentMethodConfig = $this->getSveaStoreConfClass($order->getStoreId());
     $conf = new SveaMageConfigProvider($paymentMethodConfig);
     $sveaObject = WebPay::deliverOrder($conf);
     $response = $sveaObject->setCountryCode($countryCode)->setOrderId($sveaOrderId)->deliverPaymentPlanOrder()->doRequest();
     if ($response->accepted == 1) {
         $successMessage = Mage::helper('svea_webpay')->__('delivered');
         $orderStatus = $this->getConfigData('paid_order_status') ?: $order->getStatus();
         if (!empty($orderStatus)) {
             $order->addStatusToHistory($orderStatus, $successMessage, false);
         }
         $rawDetails = $this->_sveaResponseToArray($response);
         $payment->setTransactionId($response->contractNumber)->setIsTransactionClosed(false)->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $rawDetails);
     } else {
         $errorMessage = $response->errormessage;
         $statusCode = $response->resultcode;
         $errorTranslated = Mage::helper('svea_webpay')->responseCodes($statusCode, $errorMessage);
         $order->addStatusToHistory($order->getStatus(), $errorTranslated, false);
         Mage::throwException($errorTranslated);
     }
 }
 /** 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);
 }
 function test_manual_setup_CreditInvoiceOrderRows_testdata()
 {
     // Stop here and mark this test as incomplete.
     $this->markTestIncomplete('test_manual_setup_CreditOrderRows_testdata -- run this first to setup order for CreditOrderRows tests to work with. 
         1. Run once, then make sure to log as ug 79021 and approve the invoice in the admin interface. 
         2. Set $this->invoiceIdToTest to the approved invoice id in setUp() above.
         3. Then uncomment and run CreditOrderRows tests below.');
     // create order
     $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($this->country));
     $order->addOrderRow(WebPayItem::orderRow()->setArticleNumber("1")->setQuantity(1)->setAmountExVat(100.0)->setVatPercent(25)->setDescription("A Specification")->setName('A Name')->setUnit("st")->setDiscountPercent(0));
     $order->addOrderRow(WebPayItem::orderRow()->setArticleNumber("2")->setQuantity(1)->setAmountExVat(100.0)->setVatPercent(12)->setDescription("B Specification")->setName('B Name')->setUnit("st")->setDiscountPercent(0));
     $order->addOrderRow(WebPayItem::orderRow()->setArticleNumber("3")->setQuantity(1)->setAmountExVat(1.0)->setVatPercent(25)->setDescription("C Specification")->setName('C Name')->setUnit("st")->setDiscountPercent(0));
     $order->addOrderRow(WebPayItem::orderRow()->setArticleNumber("4")->setQuantity(1)->setAmountExVat(100.0)->setVatPercent(0)->setDescription("D Specification")->setName('D Name')->setUnit("st")->setDiscountPercent(0));
     $order->addOrderRow(WebPayItem::orderRow()->setArticleNumber("5")->setQuantity(1)->setAmountExVat(100.0)->setVatPercent(0)->setDescription("E Specification")->setName('E Name')->setUnit("st")->setDiscountPercent(0));
     $orderResponse = $order->useInvoicePayment()->doRequest();
     $this->assertEquals(1, $orderResponse->accepted);
     // deliver order
     $deliver = WebPay::deliverOrder(Svea\SveaConfig::getDefaultConfig());
     $deliver->setCountryCode($this->country)->setOrderId($orderResponse->sveaOrderId)->setInvoiceDistributionType(DistributionType::POST);
     $deliverResponse = $deliver->deliverInvoiceOrder()->doRequest();
     $this->assertEquals(1, $deliverResponse->accepted);
     //print_r("\ntest_manual_setup_CreditOrderRows_testdata finished, now approve the following invoice: ". $deliverResponse->invoiceId . "\n");
 }
 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_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 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 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);
 }
Esempio n. 9
0
 /**
  * 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');
 }
 /**
  * @expectedException Exception
  * @expectedExceptionMessage
  * -missing parameter: This method requires an ConfigurationProvider object as parameter. Create a class that implements class ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class SveaConfig e.g. SveaConfig::getDefaultConfig(). You can replace the default config values to return your own config values in the method.
  */
 public function testFailOnMissingCofigurationProviderDeliverOrder()
 {
     $object = \WebPay::deliverOrder();
 }
 public function test_manual_deliverOrder_deliverCardOrder_use_ConfirmTransaction_and_is_accepted()
 {
     // Stop here and mark this test as incomplete.
     $this->markTestIncomplete('skeleton for manual test, needs a pre-existing card transactionId with status AUTHORIZED');
     // 1. remove (put in a comment) the above code to enable the test
     // 2. run the test, and check status of transaction in backoffice logs
     $orderId = 585714;
     // pre-existing card transactionId with status AUTHORIZED
     $DeliverOrderBuilder = WebPay::deliverOrder(Svea\SveaConfig::getDefaultConfig())->setCountryCode("SE")->setOrderId($orderId);
     $response = $DeliverOrderBuilder->deliverCardOrder()->doRequest();
     ////print_r( $response );
     $this->assertEquals(1, $response->accepted);
     $this->assertInstanceOf("Svea\\HostedService\\ConfirmTransactionResponse", $response);
 }
Esempio n. 12
0
 */
error_reporting(E_ALL);
ini_set('display_errors', 'On');
// Include Svea PHP integration package.
$svea_directory = "../../src/";
require $svea_directory . "Includes.php";
// get configuration object holding the Svea service login credentials
$myConfig = Svea\SveaConfig::getTestConfig();
// We assume that you've previously run the firstorder.php file and successfully made a createOrder request to Svea using the invoice payment method.
// The svea order id returned in the request response was then written to the file sveaorderid.txt in the firstorder/ folder
$mySveaOrderId = file_get_contents("../firstorder/sveaorderid.txt");
if (!$mySveaOrderId) {
    print_r("../firstorder/sveaorderid.txt not found, run firstorder.php first. aborting.");
    die;
}
// Begin the order creation process by creating an order builder object using the WebPay::createOrder() method:
$myOrder = WebPay::deliverOrder($myConfig);
// We then add information to the order object by using the various methods in the Svea\DeliverOrderBuilder class.
// We begin by adding any additional information required by the payment method, which for an invoice order means:
$myOrder->setCountryCode("SE");
$myOrder->setOrderId($mySveaOrderId);
$myOrder->setInvoiceDistributionType(\DistributionType::POST);
// We have now completed specifying the order, and wish to send the payment request to Svea. To do so, we first select the invoice payment method:
$myDeliverOrderRequest = $myOrder->deliverInvoiceOrder();
// Then send the request to Svea using the doRequest method, and immediately receive the service response object
$myResponse = $myDeliverOrderRequest->doRequest();
// If the response attribute accepted is true, the order delivery succeeded.
echo "<pre>Your request response (the invoiceId attribute contains the id of the newly created invoice at Svea):\n\n";
print_r($myResponse);
echo "</pre><font color='blue'><pre>\n\n\nAn example of a successful request response. The 'accepted' attribute is true (1), and resultcode/errormessage is not set.\n\nSvea\\AdminService\\DeliverOrdersResponse Object\n(\n    [accepted] => 1\n    [resultcode] => 0\n    [errormessage] => \n    [amount] => 876.24\n    [orderType] => Invoice\n    [invoiceId] => 1028004\n    [contractNumber] => \n)";
echo "</pre><font color='red'><pre>\n\n\nAn example of a rejected request response -- 'accepted' is false (0) and resultcode/errormessage indicates that the order has already been delivered (i.e. the order has status closed).   \n\nSvea\\AdminService\\DeliverOrdersResponse Object\n(\n    [accepted] => 0\n    [resultcode] => 20000\n    [errormessage] => Order is closed.\n    [amount] => \n    [orderType] => \n    [invoiceId] => \n    [contractNumber] => \n)";