diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..473f5db2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +# EditorConfig: https://EditorConfig.org +# Notepad++ Plugin: https://github.com/editorconfig/editorconfig-notepad-plus-plus +# Visual Studio Code Plugin: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig + +root = true + +[*.{json,md,php}] +charset = utf-8 +indent_style = tab +indent_size = 4 +trim_trailing_whitespace = true diff --git a/example/accountcredit/create__accountCredit.php b/example/accountcredit/create__accountCredit.php deleted file mode 100644 index a76a6285..00000000 --- a/example/accountcredit/create__accountCredit.php +++ /dev/null @@ -1,45 +0,0 @@ -setNationalIdNumber("194605092222") - ->setBirthDate(1986, 03, 31) - ->setName("Janko", "Stevanovic") - ->setStreetAddress("Neka tamo", 1) - ->setCoAddress("c/o BB, Batajnica") - ->setLocality("Okrug Beograda") - ->setEmail('batajarules@svea.com') - ->setZipCode("99999"); - -$orderObject = WebPay::createOrder(ConfigurationService::getDefaultConfig()) - ->addOrderRow(WebPayItem::orderRow() - ->setQuantity(1) - ->setAmountIncVat(1000) - ->setVatPercent(25.00) - ->setArticleNumber('Cowboy Hat') - ->setDescription('Some desc for Cowboy Hat') - ) - ->addOrderRow(WebPayItem::orderRow() - ->setQuantity(3) - ->setAmountIncVat(500.33) - ->setVatPercent(25) - ->setArticleNumber('Cowboy lasso') - ->setDescription('Some desc for Cowboy Lasso twine') - ) - ->addCustomerDetails($customer) - ->setCountryCode("SE") - ->setCurrency("SEK") - ->setOrderDate(date('c')) - ->useAccountCredit("111111") - ->doRequest(); - - -var_dump($orderObject); diff --git a/example/cardorder_recur/cancel_recur.php b/example/cardorder_recur/cancel_recur.php deleted file mode 100644 index 3608a625..00000000 --- a/example/cardorder_recur/cancel_recur.php +++ /dev/null @@ -1,35 +0,0 @@ -setCountryCode("SE"); - - $subscriptionId = file_get_contents("subscription.txt"); - if ($subscriptionId) { - $request->setSubscriptionId($subscriptionId); - } else { - echo "
Error: subscription.txt not found, first run cardorder_recur.php to set up the card order subscription. aborting.";
- die;
- }
-
- $response = $request->cancelRecurSubscription()->doRequest();
-
- if ($response->accepted == 1) {
- echo "SubscriptionId " . $subscriptionId . " was cancelled.";
- }
- else
- {
- echo "Statuscode: " . $response->resultcode . " Error message: " . $response->errormessage;
- }
-}
-catch(Exception $exception)
-{
- echo $exception->getMessage();
-}
\ No newline at end of file
diff --git a/example/checkout/admin/add-order-row.php b/example/checkout/admin/add-order-row.php
deleted file mode 100644
index efa3a014..00000000
--- a/example/checkout/admin/add-order-row.php
+++ /dev/null
@@ -1,35 +0,0 @@
-setCheckoutOrderId($sveaCheckoutOrderId)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setArticleNumber('prod-01')
- ->setName('someProd1')
- ->setVatPercent(0)// required - 0, 6, 12, 25.
- ->setAmountIncVat(50.00)
- ->setQuantity(1)
- ->setUnit('pc')
- )
- ->addCheckoutOrderRows()
- ->doRequest();
-
- var_dump($response);
-} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
-}
diff --git a/example/checkout/admin/cancel-order-amount.php b/example/checkout/admin/cancel-order-amount.php
deleted file mode 100644
index b0d949ff..00000000
--- a/example/checkout/admin/cancel-order-amount.php
+++ /dev/null
@@ -1,25 +0,0 @@
-setCheckoutOrderId($sveaCheckoutOrderId)
- ->setAmountIncVat(5.00)
- ->cancelCheckoutOrderAmount()
- ->doRequest();
- var_dump($response);
-} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
-}
diff --git a/example/checkout/admin/cancel-order-row.php b/example/checkout/admin/cancel-order-row.php
deleted file mode 100644
index f816b804..00000000
--- a/example/checkout/admin/cancel-order-row.php
+++ /dev/null
@@ -1,27 +0,0 @@
-setCheckoutOrderId($sveaCheckoutOrderId)
- ->setRowToCancel(1)
- ->cancelCheckoutOrderRows()
- ->doRequest();
-
- var_dump($response);
-} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
-}
diff --git a/example/checkout/admin/credit-amount.php b/example/checkout/admin/credit-amount.php
deleted file mode 100644
index 0e70deb4..00000000
--- a/example/checkout/admin/credit-amount.php
+++ /dev/null
@@ -1,27 +0,0 @@
-setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId(1)
- ->setAmountIncVat(20.00)
- ->creditCheckoutAmount()
- ->doRequest();
-
- var_dump($response);
-} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
-}
diff --git a/example/checkout/admin/credit-new-order-row.php b/example/checkout/admin/credit-new-order-row.php
deleted file mode 100644
index 31ba0a90..00000000
--- a/example/checkout/admin/credit-new-order-row.php
+++ /dev/null
@@ -1,48 +0,0 @@
-setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId(1);
-
-
- /**
- * Create a new OrderRow for the credited amount and add it to the builder object using addCreditOrderRow():
- */
- $myCreditRow = WebPayItem::orderRow()
- ->setAmountIncVat(300.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("Credited order with new Order row");
-
- /**
- * If client wants to credit order with new order row, he can use code snippet above for that.
- */
- $creditOrderRowsBuilder->addCreditOrderRow($myCreditRow);
-
-
- /**
- * For crediting OrderRowIds look at credit-order-rows.php example
- */
- $response = $creditOrderRowsBuilder->creditCheckoutOrderWithNewOrderRow()->doRequest();
-
- var_dump($response);
-} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
-}
diff --git a/example/checkout/admin/credit-order-rows.php b/example/checkout/admin/credit-order-rows.php
deleted file mode 100644
index 8e910aee..00000000
--- a/example/checkout/admin/credit-order-rows.php
+++ /dev/null
@@ -1,37 +0,0 @@
-setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId(1);
-
- /**
- * $creditOrderRowsBuilder->setRowsToCredit(array(1, 2)) // If you want to credited more then one order Row
- * $creditOrderRowsBuilder->setRowToCredit(3)// Credit just one order Row
- *
- * For crediting NewOrderRow look at credit-new-order-row.php example
- */
- $creditOrderRowsBuilder->setRowsToCredit(array(3));
-
- $response = $creditOrderRowsBuilder->creditCheckoutOrderRows()->doRequest();
-
- var_dump($response);
-} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
-}
diff --git a/example/checkout/admin/deliver-order-rows.php b/example/checkout/admin/deliver-order-rows.php
deleted file mode 100644
index 3021f184..00000000
--- a/example/checkout/admin/deliver-order-rows.php
+++ /dev/null
@@ -1,26 +0,0 @@
-setCheckoutOrderId($sveaCheckoutOrderId) // Required field
- ->setRowsToDeliver(array(1, 2)) // Required field
- ->deliverCheckoutOrderRows()
- ->doRequest();
-
- var_dump($response);
-} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
-}
diff --git a/example/checkout/admin/deliver-order.php b/example/checkout/admin/deliver-order.php
deleted file mode 100644
index 4687155e..00000000
--- a/example/checkout/admin/deliver-order.php
+++ /dev/null
@@ -1,25 +0,0 @@
-setCheckoutOrderId($sveaCheckoutOrderId) // Required field
- ->deliverCheckoutOrder()
- ->doRequest();
-
- var_dump($response);
-} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
-}
diff --git a/example/checkout/admin/query-order.php b/example/checkout/admin/query-order.php
deleted file mode 100644
index 164b580a..00000000
--- a/example/checkout/admin/query-order.php
+++ /dev/null
@@ -1,24 +0,0 @@
-setCheckoutOrderId($sveaCheckoutOrderId)
- ->queryCheckoutOrder()
- ->doRequest();
-
- print_r($response);
-} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
-}
diff --git a/example/checkout/admin/update-order-row.php b/example/checkout/admin/update-order-row.php
deleted file mode 100644
index 74858484..00000000
--- a/example/checkout/admin/update-order-row.php
+++ /dev/null
@@ -1,37 +0,0 @@
-setCheckoutOrderId($sveaCheckoutOrderId)
- ->updateOrderRow(
- WebPayItem::numberedOrderRow()
- ->setRowId(4)
- ->setName('someProd')
- ->setVatPercent(6)
- ->setDiscountPercent(50)
- ->setAmountIncVat(123.9876)
- ->setQuantity(4)
- ->setUnit('pc')
- )
- ->updateCheckoutOrderRows()
- ->doRequest();
-
- var_dump($response);
-} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
-}
diff --git a/example/checkout/getAvailablePartPaymentCampaigns.php b/example/checkout/getAvailablePartPaymentCampaigns.php
deleted file mode 100644
index 80e994ec..00000000
--- a/example/checkout/getAvailablePartPaymentCampaigns.php
+++ /dev/null
@@ -1,33 +0,0 @@
-setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::IS_COMPANY)
- ->setValue(false)
- ->setIsReadonly(true);
-
- $request->setCountryCode('SE')
- ->addPresetValue($presetValueIsCompany);
-
- $response = $request->getAvailablePartPaymentCampaigns();
- echo "" . print_r($response, true) . "
";
-} catch (\Exception $e) {
- echo "" . print_r($e->getMessage(), true) . "
";
-}
\ No newline at end of file
diff --git a/example/config_getaddresses/MyConfig.php b/example/config_getaddresses/MyConfig.php
deleted file mode 100644
index 4ee7b8c8..00000000
--- a/example/config_getaddresses/MyConfig.php
+++ /dev/null
@@ -1,244 +0,0 @@
-
- array(
- // invoice payment method credentials for SE, i.e. client number, username and password
- // replace with your own, or leave blank
- WebPay\Config\ConfigurationProvider::INVOICE_TYPE =>
- array(
- "username" => "sverigetest", // swap this for your actual SE invoice prod account credentials
- "password" => "sverigetest", // swap this for your actual SE invoice prod account credentials
- "clientNumber" => 79021 // swap this for your actual SE invoice prod account credentials
- ),
-
- // payment plan payment method credentials for SE
- // replace with your own, or leave blank
- WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE =>
- array(
- "username" => "sverigetest", // swap this for your actual SE payment plan prod account credentials
- "password" => "sverigetest", // swap this for your actual SE payment plan prod account credentials
- "clientNumber" => 59999 // swap this for your actual SE payment plan prod account credentials
- ),
-
- // card and direct bank payment method credentials, i.e. merchant id and secret word
- // replace with your own, or leave blank
- WebPay\Config\ConfigurationProvider::HOSTED_TYPE =>
- array(
- "merchantId" => 1130,
- "secret" => "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3"
- )
- )
- );
-
- // We don't accept payment plan payments in Norway, nor do we accept card payments from there
- $prodConfig["NO"] =
- array("auth" =>
- array(
- WebPay\Config\ConfigurationProvider::INVOICE_TYPE =>
- array(
- "username" => "norgetest2", // swap this for your actual SE invoice account credentials
- "password" => "norgetest2", // swap this for your actual SE invoice account credentials
- "clientNumber" => 33308 // swap this for your actual SE invoice account credentials
- ),
- WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- WebPay\Config\ConfigurationProvider::HOSTED_TYPE => array("merchantId" => "", "secret" => "")
- )
- );
-
- // We have no invoice or payment plan accounts for Denmark, but our card payment account is configured to accept orders there
- $prodConfig["DK"] =
- array("auth" =>
- array(
- WebPay\Config\ConfigurationProvider::INVOICE_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- array(
- // swap these for your actual merchant id and secret word
- "merchantId" => 1130,
- "secret" => "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3"
- )
- )
- );
-
- // We have no invoice or payment plan accounts for Finland, neither do we accept card payments from there
- $prodConfig["FI"] =
- array("auth" =>
- array(
- WebPay\Config\ConfigurationProvider::INVOICE_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- WebPay\Config\ConfigurationProvider::HOSTED_TYPE => array("merchantId" => "", "secret" => "")
- )
- );
- // We have no invoice or payment plan accounts for Germany, neither do we accept card payments from there
- $prodConfig["DE"] =
- array("auth" =>
- array(
- WebPay\Config\ConfigurationProvider::INVOICE_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- WebPay\Config\ConfigurationProvider::HOSTED_TYPE => array("merchantId" => "", "secret" => "")
- )
- );
- // We have no invoice or payment plan accounts for Netherlands, neither do we accept card payments from Denmark
- $prodConfig["NL"] =
- array("auth" =>
- array(
- WebPay\Config\ConfigurationProvider::INVOICE_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- WebPay\Config\ConfigurationProvider::HOSTED_TYPE => array("merchantId" => "", "secret" => "")
- )
- );
-
- // don't modify this
- $url = array(
- ConfigurationProvider::HOSTED_TYPE => self::SWP_PROD_URL,
- ConfigurationProvider::INVOICE_TYPE => self::SWP_PROD_WS_URL,
- ConfigurationProvider::PAYMENTPLAN_TYPE => self::SWP_PROD_WS_URL,
- ConfigurationProvider::HOSTED_ADMIN_TYPE => self::SWP_PROD_HOSTED_ADMIN_URL,
- ConfigurationProvider::ADMIN_TYPE => self::SWP_PROD_ADMIN_URL
- );
-
- return new SveaConfigurationProvider(array("url" => $url, "credentials" => $prodConfig));
- }
-
- /**
- * @return \Svea\WebPay\Config\SveaConfigurationProvider
- */
- public static function getDefaultConfig()
- {
- return self::getTestConfig();
- }
-
- /**
- * Replace the provided Svea test account credentials with your own to use
- * the package with your own account.
- *
- * @return \Svea\WebPay\Config\SveaConfigurationProvider
- */
- public static function getTestConfig()
- {
- $testConfig = array();
-
-
- // test credentials for Sweden
- $testConfig["SE"] =
- array("auth" =>
- array(
- ConfigurationProvider::INVOICE_TYPE =>
- array(
- "username" => "sverigetest", // swap this for your actual SE invoice test account credentials
- "password" => "sverigetest", // swap this for your actual SE invoice test account credentials
- "clientNumber" => 79021 // swap this for your actual SE invoice test account credentials
- ),
-
- ConfigurationProvider::PAYMENTPLAN_TYPE =>
- array(
- "username" => "sverigetest", // swap this for your actual SE payment plan test account credentials
- "password" => "sverigetest", // swap this for your actual SE payment plan test account credentials
- "clientNumber" => 59999 // swap this for your actual SE payment plan test account credentials
- ),
-
- ConfigurationProvider::HOSTED_TYPE =>
- array(
- // swap these for your actual merchant id and secret word
- "merchantId" => 1130,
- "secret" => "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3"
- )
- )
- );
-
- // We don't accept payment plan payments in Norway, nor do we accept card payments from there
- $testConfig["NO"] =
- array("auth" =>
- array(
- ConfigurationProvider::INVOICE_TYPE =>
- array(
- "username" => "norgetest2", // swap this for your actual SE invoice account credentials
- "password" => "norgetest2", // swap this for your actual SE invoice account credentials
- "clientNumber" => 33308 // swap this for your actual SE invoice account credentials
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- ConfigurationProvider::HOSTED_TYPE => array("merchantId" => "", "secret" => "")
- )
- );
-
- // We have no invoice or payment plan accounts for Denmark, but our card payment account is configured to accept orders there
- $testConfig["DK"] =
- array("auth" =>
- array(
- ConfigurationProvider::INVOICE_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- array(
- // swap these for your actual merchant id and secret word
- "merchantId" => 1130,
- "secret" => "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3"
- )
- )
- );
-
- // We have no invoice or payment plan accounts for Finland, neither do we accept card payments from there
- $testConfig["FI"] =
- array("auth" =>
- array(
- ConfigurationProvider::INVOICE_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- ConfigurationProvider::HOSTED_TYPE => array("merchantId" => "", "secret" => "")
- )
- );
-
- // We have no invoice or payment plan accounts for Germany, neither do we accept card payments from there
- $testConfig["DE"] =
- array("auth" =>
- array(
- ConfigurationProvider::INVOICE_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- ConfigurationProvider::HOSTED_TYPE => array("merchantId" => "", "secret" => "")
- )
- );
-
- // We have no invoice or payment plan accounts for Netherlands, neither do we accept card payments from Denmark
- $testConfig["NL"] =
- array("auth" =>
- array(
- ConfigurationProvider::INVOICE_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array("username" => "", "password" => "", "clientNumber" => ""),
- ConfigurationProvider::HOSTED_TYPE => array("merchantId" => "", "secret" => "")
- )
- );
-
- // don't modify this
- $url = array(
- ConfigurationProvider::HOSTED_TYPE => self::SWP_TEST_URL,
- ConfigurationProvider::INVOICE_TYPE => self::SWP_TEST_WS_URL,
- ConfigurationProvider::PAYMENTPLAN_TYPE => self::SWP_TEST_WS_URL,
- ConfigurationProvider::HOSTED_ADMIN_TYPE => self::SWP_TEST_HOSTED_ADMIN_URL,
- ConfigurationProvider::ADMIN_TYPE => self::SWP_TEST_ADMIN_URL
- );
-
- return new SveaConfigurationProvider(array("url" => $url, "credentials" => $testConfig));
- }
-}
diff --git a/example/creditorderrows_card/creditorderrows.php b/example/creditorderrows_card/creditorderrows.php
deleted file mode 100644
index 2861cf7d..00000000
--- a/example/creditorderrows_card/creditorderrows.php
+++ /dev/null
@@ -1,202 +0,0 @@
-Error: transactionid.txt not found, first run cardorder_credit.php to set up the card order. aborting.";
- die;
-}
-$firstCreditOrderRowsBuilder
- ->setOrderId($myTransactionId)
- ->setCountryCode("SE");
-
-// Assume that we know that the original order total amount was 1*(100*1.25) + 2*(5.00*1.12) = 125+11.2 = SEK 136.2 (incl. VAT 26.2)
-// Create a new OrderRow for the credited amount and add it to the builder object using addCreditOrderRow():
-$myCreditRow = WebPayItem::orderRow()
- ->setAmountExVat(300)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("Credited order #" . $myTransactionId);
-// Add the new order row to credit to the builder object.
-$firstCreditOrderRowsBuilder->addCreditOrderRow($myCreditRow);
-
-// Then we can send the credit request to Svea:
-
-$myCreditRequest = $firstCreditOrderRowsBuilder->creditCardOrderRows();
-$myCreditResponse = $myCreditRequest->doRequest();
-
-
-// The response is an instance of LowerTransactionResponse
-echo "";
-print_r("the creditCardOrderRows() response:");
-print_r($myCreditResponse);
-
-echo "\n\n\n
-An example of a non-successful credit request response, where the card order had not yet been processed (i.e. Svea transactionstatus doesn't equal SUCCESS).
-
-the creditCardOrderRows() response:Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse Object
-(
- [customerrefno] => order #2014-08-26T13:49:48 02:00
- [accepted] => 0
- [resultcode] => 105 (ILLEGAL_TRANSACTIONSTATUS)
- [errormessage] => Invalid transaction status.
-)
-
-An example of a non-successful credit request response, where the card order has already been credited for the full amount.
-
-the creditCardOrderRows() response:Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse Object
-(
- [customerrefno] => order #2014-08-26T14:28:33 02:00
- [accepted] => 0
- [resultcode] => 119 (ILLEGAL_CREDITED_AMOUNT)
- [errormessage] => Invalid credited amount.
-)";
-
-echo "\n
\n\n
-An example of a non-successful credit request response, where the card order has been first confirmed and then processed to status SUCCESS in bank.
-
-the creditCardOrderRows() response:Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse Object
-(
- [customerrefno] => order #2014-08-26T14:28:33 02:00
- [accepted] => 1
- [resultcode] => 0
- [errormessage] =>
-)
-
-The following is the result of a Svea\WebPay\WebPayAdmin::queryOrder for the above order, as you can see the entire authorized/captured amount has been credited:
-
-
-
-Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse Object
-(
- [transactionId] => 589747
- [clientOrderNumber] => order #2014-11-20T15:26:33 01:00
- [merchantId] => 1130
- [status] => SUCCESS
- [amount] => 37500
- [currency] => SEK
- [vat] => 7500
- [capturedamount] => 37500
- [authorizedamount] => 37500
- [created] => 2014-11-20 15:26:35.09
- [creditstatus] => CREDSUCCESS
- [creditedamount] => 37500
- [merchantresponsecode] => 0
- [paymentMethod] => KORTCERT
- [numberedOrderRows] => Array
- (
- [0] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
- (
- [creditInvoiceId] =>
- [invoiceId] =>
- [rowNumber] => 1
- [status] =>
- [articleNumber] =>
- [quantity] => 1
- [unit] =>
- [amountExVat] => 100
- [vatPercent] => 25
- [amountIncVat] =>
- [name] =>
- [description] => A
- [discountPercent] =>
- [vatDiscount] => 0
- )
-
- [1] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
- (
- [creditInvoiceId] =>
- [invoiceId] =>
- [rowNumber] => 2
- [status] =>
- [articleNumber] =>
- [quantity] => 1
- [unit] =>
- [amountExVat] => 100
- [vatPercent] => 25
- [amountIncVat] =>
- [name] =>
- [description] => B
- [discountPercent] =>
- [vatDiscount] => 0
- )
-
- [2] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
- (
- [creditInvoiceId] =>
- [invoiceId] =>
- [rowNumber] => 3
- [status] =>
- [articleNumber] =>
- [quantity] => 1
- [unit] =>
- [amountExVat] => 100
- [vatPercent] => 25
- [amountIncVat] =>
- [name] =>
- [description] => C
- [discountPercent] =>
- [vatDiscount] => 0
- )
-
- )
-
- [callbackurl] =>
- [capturedate] => 2014-11-20 15:36:12.607
- [subscriptionId] =>
- [subscriptiontype] =>
- [cardType] =>
- [maskedCardNumber] =>
- [eci] =>
- [mdstatus] =>
- [expiryYear] =>
- [expiryMonth] =>
- [chname] =>
- [authCode] =>
- [accepted] => 1
- [resultcode] => 0
- [errormessage] =>
-)
-
";
-
-/**
- * get the path to this file, for use in specifying the returnurl etc.
- */
-function getPath()
-{
- $myURL = $_SERVER['SCRIPT_NAME'];
- $myPath = explode('/', $myURL);
- unset($myPath[count($myPath) - 1]);
- $myPath = implode('/', $myPath);
-
- return $myPath;
-}
-
-?>
diff --git a/example/swishorder/swishorder.php b/example/swishorder/swishorder.php
deleted file mode 100644
index 93bd352c..00000000
--- a/example/swishorder/swishorder.php
+++ /dev/null
@@ -1,93 +0,0 @@
-setCurrency("SEK"); // 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") // optional - This should contain a customer reference, as in "customer #123".
- ->setOrderDate("2019-11-29") // optional - or use an ISO8601 date as produced by i.e. date('c')
- ->setPayerAlias("46707937643") // required for Swish payments, ignored otherwise;
- ->setCountryCode("SE"); // countryCode "SE" is required for Swish payments
-
-
- // Then specify the items bought as order rows, using the methods in the Svea\WebPay\BuildOrder\RowBuilders\OrderRow class, and adding them to the order:
- $firstBoughtItem = WebPayItem::orderRow();
- $firstBoughtItem->setAmountExVat(1.00);
- $firstBoughtItem->setVatPercent(25);
- $firstBoughtItem->setQuantity(1);
- $firstBoughtItem->setDescription("Yellow duck");
- $firstBoughtItem->setArticleNumber("yel-duck-01");
-
- // Add firstBoughtItem to order row
- $myOrder->addOrderRow($firstBoughtItem);
-
- // Add secondBoughtItem in a fluent fashion
- $myOrder->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(2.50)
- ->setVatPercent(12)
- ->setQuantity(1)
- ->setDescription("Blue duck")
- );
-
- // Add Swish as the payment method for the order
- $mySwishOrderRequest = $myOrder->usePaymentMethod(PaymentMethod::SWISH);
-
-
- // Then set any additional required request attributes as detailed below. (See Svea\PaymentMethodPayment and Svea\HostedPayment classes for details.)
- $mySwishOrderRequest
- ->setReturnUrl("http://localhost/" . getPath() . "/landingpage.php"); // The return url where we receive and process the finished request response
-
- // Get a payment form object which you can use to send the payment request to Svea
- $mySwishOrderRequest = $mySwishOrderRequest->getPaymentForm();
-
- // Then send the form to Svea, and receive the response on the landingpage after the customer has completed the card checkout SveaCardPay
- echo "";
- print_r("press submit to send the swish payment request to Svea");
- print_r($mySwishOrderRequest->completeHtmlFormWithSubmitButton);
-}
-catch (Exception $exception)
-{
- echo $exception->getMessage();
-}
-/**
- * get the path to this file, for use in specifying the returnurl etc.
- */
-function getPath()
-{
- $myURL = $_SERVER['SCRIPT_NAME'];
- $myPath = explode('/', $myURL);
- unset($myPath[count($myPath) - 1]);
- $myPath = implode('/', $myPath);
-
- return $myPath;
-}
-
-
diff --git a/example/accountcredit/cancel__accountCredit.php b/examples/accountcredit/cancel__accountCredit.php
similarity index 74%
rename from example/accountcredit/cancel__accountCredit.php
rename to examples/accountcredit/cancel__accountCredit.php
index 89dc33a9..0b5d9eeb 100644
--- a/example/accountcredit/cancel__accountCredit.php
+++ b/examples/accountcredit/cancel__accountCredit.php
@@ -11,9 +11,9 @@
$svea_order_id = 1045661;
$svea_cancel_request = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($svea_order_id)
- ->setCountryCode('SE')
- ->cancelAccountCreditOrder()
- ->doRequest();
+ ->setOrderId($svea_order_id)
+ ->setCountryCode('SE')
+ ->cancelAccountCreditOrder()
+ ->doRequest();
var_dump($svea_cancel_request);
\ No newline at end of file
diff --git a/examples/accountcredit/create__accountCredit.php b/examples/accountcredit/create__accountCredit.php
new file mode 100644
index 00000000..65e0d70e
--- /dev/null
+++ b/examples/accountcredit/create__accountCredit.php
@@ -0,0 +1,45 @@
+setNationalIdNumber("194605092222")
+ ->setBirthDate(1986, 03, 31)
+ ->setName("Janko", "Stevanovic")
+ ->setStreetAddress("Neka tamo", 1)
+ ->setCoAddress("c/o BB, Batajnica")
+ ->setLocality("Okrug Beograda")
+ ->setEmail('batajarules@svea.com')
+ ->setZipCode("99999");
+
+$orderObject = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(1)
+ ->setAmountIncVat(1000)
+ ->setVatPercent(25.00)
+ ->setArticleNumber('Cowboy Hat')
+ ->setDescription('Some desc for Cowboy Hat')
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(3)
+ ->setAmountIncVat(500.33)
+ ->setVatPercent(25)
+ ->setArticleNumber('Cowboy lasso')
+ ->setDescription('Some desc for Cowboy Lasso twine')
+ )
+ ->addCustomerDetails($customer)
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate(date('c'))
+ ->useAccountCredit("111111")
+ ->doRequest();
+
+
+var_dump($orderObject);
diff --git a/example/accountcredit/credit_amount__accountCredit.php b/examples/accountcredit/credit_amount__accountCredit.php
similarity index 65%
rename from example/accountcredit/credit_amount__accountCredit.php
rename to examples/accountcredit/credit_amount__accountCredit.php
index 8fe407c9..bf3180f3 100644
--- a/example/accountcredit/credit_amount__accountCredit.php
+++ b/examples/accountcredit/credit_amount__accountCredit.php
@@ -12,11 +12,11 @@
$referenceNumber = 1000760;
$credit = WebPayAdmin::creditAmount(ConfigurationService::getDefaultConfig())
- ->setOrderId($referenceNumber)
- ->setCountryCode('SE')
- ->setDescription('try and credit desc')
- ->setAmountIncVat(150.00)
- ->creditAccountCredit()
- ->doRequest();
+ ->setOrderId($referenceNumber)
+ ->setCountryCode('SE')
+ ->setDescription('try and credit desc')
+ ->setAmountIncVat(150.00)
+ ->creditAccountCredit()
+ ->doRequest();
var_dump($credit);
diff --git a/example/accountcredit/credit_order_rows__accountCredit.php b/examples/accountcredit/credit_order_rows__accountCredit.php
similarity index 75%
rename from example/accountcredit/credit_order_rows__accountCredit.php
rename to examples/accountcredit/credit_order_rows__accountCredit.php
index ca56723e..0306d5fe 100644
--- a/example/accountcredit/credit_order_rows__accountCredit.php
+++ b/examples/accountcredit/credit_order_rows__accountCredit.php
@@ -15,10 +15,10 @@
$orderRowIndex = 2;
$credit = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId($orderId)
- ->setCountryCode('SE')
- ->setRowToCredit(2)
- ->creditAccountCreditOrderRows()
- ->doRequest();
+ ->setOrderId($orderId)
+ ->setCountryCode('SE')
+ ->setRowToCredit(2)
+ ->creditAccountCreditOrderRows()
+ ->doRequest();
var_dump($credit);
\ No newline at end of file
diff --git a/example/accountcredit/deliver__accountCredit.php b/examples/accountcredit/deliver__accountCredit.php
similarity index 66%
rename from example/accountcredit/deliver__accountCredit.php
rename to examples/accountcredit/deliver__accountCredit.php
index 6e1810f5..a4697893 100644
--- a/example/accountcredit/deliver__accountCredit.php
+++ b/examples/accountcredit/deliver__accountCredit.php
@@ -12,11 +12,11 @@
$svea_order_id = 1045662;
$svea_delivery_request = \Svea\WebPay\WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($svea_order_id)
- ->setOrderDate(date('c'))
- ->setCountryCode('SE')
- ->setInvoiceDistributionType(DistributionType::POST)
- ->deliverAccountCreditOrder()
- ->doRequest();
+ ->setOrderId($svea_order_id)
+ ->setOrderDate(date('c'))
+ ->setCountryCode('SE')
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->deliverAccountCreditOrder()
+ ->doRequest();
var_dump($svea_delivery_request);
\ No newline at end of file
diff --git a/example/accountcredit/deliver_partial_account_credit.php b/examples/accountcredit/deliver_partial_account_credit.php
similarity index 63%
rename from example/accountcredit/deliver_partial_account_credit.php
rename to examples/accountcredit/deliver_partial_account_credit.php
index 126eb260..de08add8 100644
--- a/example/accountcredit/deliver_partial_account_credit.php
+++ b/examples/accountcredit/deliver_partial_account_credit.php
@@ -12,11 +12,11 @@
$svea_order_id = 1048734;
$response = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId($svea_order_id)
- ->setRowsToDeliver(array(8, 9))
- ->setCountryCode('SE')
- ->setInvoiceDistributionType(DistributionType::POST)
- ->deliverAccountCreditOrderRows()
- ->doRequest();
+ ->setOrderId($svea_order_id)
+ ->setRowsToDeliver([8, 9])
+ ->setCountryCode('SE')
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->deliverAccountCreditOrderRows()
+ ->doRequest();
var_dump($response);
\ No newline at end of file
diff --git a/example/accountcredit/query__accountCredit.php b/examples/accountcredit/query__accountCredit.php
similarity index 73%
rename from example/accountcredit/query__accountCredit.php
rename to examples/accountcredit/query__accountCredit.php
index 97d0d8da..a1a1abf9 100644
--- a/example/accountcredit/query__accountCredit.php
+++ b/examples/accountcredit/query__accountCredit.php
@@ -11,9 +11,9 @@
$svea_order_id = 1048731;
$svea_query = WebPayAdmin::queryOrder(ConfigurationService::getTestConfig())
- ->setOrderId($svea_order_id)
- ->setCountryCode('SE')
- ->queryAccountCreditOrder()
- ->doRequest();
+ ->setOrderId($svea_order_id)
+ ->setCountryCode('SE')
+ ->queryAccountCreditOrder()
+ ->doRequest();
var_dump($svea_query);
\ No newline at end of file
diff --git a/example/accountcredit/return_campaings_for_accountCredit.php b/examples/accountcredit/return_campaings_for_accountCredit.php
similarity index 94%
rename from example/accountcredit/return_campaings_for_accountCredit.php
rename to examples/accountcredit/return_campaings_for_accountCredit.php
index db57a5a7..671ec2bd 100644
--- a/example/accountcredit/return_campaings_for_accountCredit.php
+++ b/examples/accountcredit/return_campaings_for_accountCredit.php
@@ -12,6 +12,6 @@
$ppCampaign = WebPay::getAccountCreditParams(ConfigurationService::getDefaultConfig());
$campaigns = $ppCampaign->setCountryCode('SE')
- ->doRequest();
+ ->doRequest();
var_dump($campaigns);
\ No newline at end of file
diff --git a/example/cardorder/cardorder.php b/examples/cardorder/cardorder.php
similarity index 80%
rename from example/cardorder/cardorder.php
rename to examples/cardorder/cardorder.php
index e217b3ec..ff96a198 100644
--- a/example/cardorder/cardorder.php
+++ b/examples/cardorder/cardorder.php
@@ -38,12 +38,12 @@
// You then add information to the order object by using the methods in the Svea\WebPay\BuildOrder\CreateOrderBuilder class.
// For a Card order, the following methods are required:
-$myOrder->setCurrency("SEK"); // order currency
+$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"
// You may also chain fluent methods together:
$myOrder
- ->setCustomerReference("customer #123") // optional - This should contain a customer reference, as in "customer #123".
- ->setOrderDate("2014-05-28") // optional - or use an ISO8601 date as produced by i.e. date('c')
+ ->setCustomerReference("customer #123") // optional - This should contain a customer reference, as in "customer #123".
+ ->setOrderDate("2014-05-28") // optional - or use an ISO8601 date as produced by i.e. date('c')
;
// Then specify the items bought as order rows, using the methods in the Svea\WebPay\BuildOrder\RowBuilders\OrderRow class, and adding them to the order:
@@ -59,11 +59,11 @@
// Add secondBoughtItem in a fluent fashion
$myOrder->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat( 5.00 )
- ->setVatPercent( 12 )
- ->setQuantity( 2 )
- ->setDescription( "Korv med bröd" )
+ WebPayItem::orderRow()
+ ->setAmountIncVat( 5.00 )
+ ->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
@@ -84,8 +84,8 @@
// Then set any additional required request attributes as detailed below. (See Svea\PaymentMethodPayment and Svea\HostedPayment classes for details.)
$myCardOrderRequest
- ->setCardPageLanguage("SV") // ISO639 language code, i.e. "SV", "EN" etc. Defaults to English.
- ->setReturnUrl("http://localhost/".getPath()."/landingpage.php"); // The return url where we receive and process the finished request response
+ ->setCardPageLanguage("SV") // ISO639 language code, i.e. "SV", "EN" etc. Defaults to English.
+ ->setReturnUrl("http://localhost/".getPath()."/landingpage.php"); // The return url where we receive and process the finished request response
// Get a payment form object which you can use to send the payment request to Svea
$myCardOrderPaymentForm = $myCardOrderRequest->getPaymentForm();
@@ -99,12 +99,10 @@
* get the path to this file, for use in specifying the returnurl etc.
*/
function getPath() {
- $myURL = $_SERVER['SCRIPT_NAME'];
- $myPath = explode('/', $myURL);
- unset( $myPath[count($myPath)-1]);
- $myPath = implode( '/', $myPath);
+ $myURL = $_SERVER['SCRIPT_NAME'];
+ $myPath = explode('/', $myURL);
+ unset( $myPath[count($myPath)-1]);
+ $myPath = implode( '/', $myPath);
- return $myPath;
+ return $myPath;
}
-
-?>
diff --git a/example/cardorder/landingpage.php b/examples/cardorder/landingpage.php
similarity index 60%
rename from example/cardorder/landingpage.php
rename to examples/cardorder/landingpage.php
index 27354cb7..326a3f2c 100644
--- a/example/cardorder/landingpage.php
+++ b/examples/cardorder/landingpage.php
@@ -2,7 +2,7 @@
/**
* example file, how to handle a card order request response
- *
+ *
* @author Kristian Grossman-madsen for Svea Svea\WebPay\WebPay
*/
@@ -24,11 +24,11 @@
// decode the raw response by passing it through the Svea\WebPay\Response\SveaResponse class
try
{
- $myResponse = new SveaResponse($rawResponse, $countryCode = NULL, $myConfig);
+ $myResponse = new SveaResponse($rawResponse, $countryCode = NULL, $myConfig);
}
catch (Exception $e)
{
- echo $e->getMessage();
+ echo $e->getMessage();
}
// The decoded response is available through the ->getResponse() method.
@@ -43,35 +43,34 @@
Svea\HostedPaymentResponse Object
(
- [transactionId] => 582827
- [clientOrderNumber] => order #20140519-374
- [paymentMethod] => KORTCERT
- [merchantId] => 1130
- [amount] => 23.74
- [currency] => SEK
- [accepted] => 1
- [resultcode] =>
- [cardType] => VISA
- [maskedCardNumber] => 444433xxxxxx1100
- [expiryMonth] => 02
- [expiryYear] => 15
- [authCode] => 941033
+ [transactionId] => 582827
+ [clientOrderNumber] => order #20140519-374
+ [paymentMethod] => KORTCERT
+ [merchantId] => 1130
+ [amount] => 23.74
+ [currency] => SEK
+ [accepted] => 1
+ [resultcode] =>
+ [cardType] => VISA
+ [maskedCardNumber] => 444433xxxxxx1100
+ [expiryMonth] => 02
+ [expiryYear] => 15
+ [authCode] => 941033
)";
echo "\n\n\n
-An example of a rejected request response -- 'accepted' is false (0) and resultcode/errormessage indicates that the clientOrderNumber above has been reused, which is prohibited.
+An example of a rejected request response -- 'accepted' is false (0) and resultcode/errormessage indicates that the clientOrderNumber above has been reused, which is prohibited.
Svea\HostedPaymentResponse Object
(
- [transactionId] => 582828
- [clientOrderNumber] => order #20140519-374.err
- [paymentMethod] => KORTCERT
- [merchantId] => 1130
- [amount] => 23.74
- [currency] => SEK
- [accepted] => 0
- [resultcode] => 127 (CUSTOMERREFNO_ALREADY_USED)
- [errormessage] => Customer reference number already used in another transaction.
+ [transactionId] => 582828
+ [clientOrderNumber] => order #20140519-374.err
+ [paymentMethod] => KORTCERT
+ [merchantId] => 1130
+ [amount] => 23.74
+ [currency] => SEK
+ [accepted] => 0
+ [resultcode] => 127 (CUSTOMERREFNO_ALREADY_USED)
+ [errormessage] => Customer reference number already used in another transaction.
)";
-?>
diff --git a/example/cardorder_recur/.gitignore b/examples/cardorder_recur/.gitignore
similarity index 100%
rename from example/cardorder_recur/.gitignore
rename to examples/cardorder_recur/.gitignore
diff --git a/examples/cardorder_recur/cancel_recur.php b/examples/cardorder_recur/cancel_recur.php
new file mode 100644
index 00000000..90ddcf58
--- /dev/null
+++ b/examples/cardorder_recur/cancel_recur.php
@@ -0,0 +1,35 @@
+setCountryCode("SE");
+
+ $subscriptionId = file_get_contents("subscription.txt");
+ if ($subscriptionId) {
+ $request->setSubscriptionId($subscriptionId);
+ } else {
+ echo "Error: subscription.txt not found, first run cardorder_recur.php to set up the card order subscription. aborting.";
+ die;
+ }
+
+ $response = $request->cancelRecurSubscription()->doRequest();
+
+ if ($response->accepted == 1) {
+ echo "SubscriptionId " . $subscriptionId . " was cancelled.";
+ }
+ else
+ {
+ echo "Statuscode: " . $response->resultcode . " Error message: " . $response->errormessage;
+ }
+}
+catch(Exception $exception)
+{
+ echo $exception->getMessage();
+}
\ No newline at end of file
diff --git a/example/cardorder_recur/cardorder_recur.php b/examples/cardorder_recur/cardorder_recur.php
similarity index 73%
rename from example/cardorder_recur/cardorder_recur.php
rename to examples/cardorder_recur/cardorder_recur.php
index b7d324db..f8cfdc2a 100644
--- a/example/cardorder_recur/cardorder_recur.php
+++ b/examples/cardorder_recur/cardorder_recur.php
@@ -23,17 +23,17 @@
// You then add information to the order object by using the methods in the Svea\WebPay\BuildOrder\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->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.00 )
- ->setVatPercent( 25 )
- ->setQuantity( 1 )
- ->setDescription( "Månadsavgift" )
+ WebPayItem::orderRow()
+ ->setAmountExVat( 100.00 )
+ ->setVatPercent( 25 )
+ ->setQuantity( 1 )
+ ->setDescription( "Månadsavgift" )
);
// 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.
@@ -45,8 +45,8 @@
// Then set any additional required request attributes as detailed below. (See Svea\PaymentMethodPayment and Svea\HostedPayment classes for details.)
$myCardOrderRequest
- ->setCardPageLanguage("SV") // ISO639 language code, i.e. "SV", "EN" etc. Defaults to English.
- ->setReturnUrl("http://localhost/".getPath()."/landingpage_recur.php"); // The return url where we receive and process the finished request response
+ ->setCardPageLanguage("SV") // ISO639 language code, i.e. "SV", "EN" etc. Defaults to English.
+ ->setReturnUrl("http://localhost/".getPath()."/landingpage_recur.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();
@@ -60,12 +60,10 @@
* get the path to this file, for use in specifying the returnurl etc.
*/
function getPath() {
- $myURL = $_SERVER['SCRIPT_NAME'];
- $myPath = explode('/', $myURL);
- unset( $myPath[count($myPath)-1]);
- $myPath = implode( '/', $myPath);
+ $myURL = $_SERVER['SCRIPT_NAME'];
+ $myPath = explode('/', $myURL);
+ unset( $myPath[count($myPath)-1]);
+ $myPath = implode( '/', $myPath);
- return $myPath;
+ return $myPath;
}
-
-?>
diff --git a/example/cardorder_recur/landingpage_recur.php b/examples/cardorder_recur/landingpage_recur.php
similarity index 86%
rename from example/cardorder_recur/landingpage_recur.php
rename to examples/cardorder_recur/landingpage_recur.php
index c7ef6016..8dcad973 100644
--- a/example/cardorder_recur/landingpage_recur.php
+++ b/examples/cardorder_recur/landingpage_recur.php
@@ -26,9 +26,9 @@
// abort if request failed
if ($myResponse->getResponse()->accepted == 0) {
- echo "Request failed. aborting";
- print_r($myResponse->getResponse());
- die;
+ echo "Request failed. aborting";
+ print_r($myResponse->getResponse());
+ die;
}
// The decoded response is available through the ->getResponse() method.
@@ -50,11 +50,11 @@
*/
function getPath()
{
- $myURL = $_SERVER['SCRIPT_NAME'];
- $myPath = explode('/', $myURL);
- unset($myPath[count($myPath) - 1]);
- $myPath = implode('/', $myPath);
+ $myURL = $_SERVER['SCRIPT_NAME'];
+ $myPath = explode('/', $myURL);
+ unset($myPath[count($myPath) - 1]);
+ $myPath = implode('/', $myPath);
- return $myPath;
+ return $myPath;
}
diff --git a/example/cardorder_recur/recurorder.php b/examples/cardorder_recur/recurorder.php
similarity index 71%
rename from example/cardorder_recur/recurorder.php
rename to examples/cardorder_recur/recurorder.php
index 21ead1b9..95094095 100644
--- a/example/cardorder_recur/recurorder.php
+++ b/examples/cardorder_recur/recurorder.php
@@ -24,17 +24,17 @@
// 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->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.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("Monthly recurring fee")
+ WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("Monthly recurring fee")
);
// 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.
@@ -45,12 +45,12 @@
if ($mySubscriptionId)
{
- $myRecurOrderRequest->setSubscriptionId($mySubscriptionId);
+ $myRecurOrderRequest->setSubscriptionId($mySubscriptionId);
}
else // or, abort if subscription.txt is missing
{
- echo "Error: subscription.txt not found, first run cardorder_recur.php to set up the card order subscription. aborting.";
- die;
+ echo "Error: subscription.txt not found, first run cardorder_recur.php to set up the card order subscription. aborting.";
+ die;
}
// Send the recur payment request to Svea
@@ -65,11 +65,11 @@
*/
function getPath()
{
- $myURL = $_SERVER['SCRIPT_NAME'];
- $myPath = explode('/', $myURL);
- unset($myPath[count($myPath) - 1]);
- $myPath = implode('/', $myPath);
+ $myURL = $_SERVER['SCRIPT_NAME'];
+ $myPath = explode('/', $myURL);
+ unset($myPath[count($myPath) - 1]);
+ $myPath = implode('/', $myPath);
- return $myPath;
+ return $myPath;
}
diff --git a/examples/checkout/admin/add-order-row.php b/examples/checkout/admin/add-order-row.php
new file mode 100644
index 00000000..7ac4ed16
--- /dev/null
+++ b/examples/checkout/admin/add-order-row.php
@@ -0,0 +1,35 @@
+setCheckoutOrderId($sveaCheckoutOrderId)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setArticleNumber('prod-01')
+ ->setName('someProd1')
+ ->setVatPercent(0)// required - 0, 6, 12, 25.
+ ->setAmountIncVat(50.00)
+ ->setQuantity(1)
+ ->setUnit('pc')
+ )
+ ->addCheckoutOrderRows()
+ ->doRequest();
+
+ var_dump($response);
+} catch (\Exception $ex) {
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
+}
diff --git a/examples/checkout/admin/cancel-order-amount.php b/examples/checkout/admin/cancel-order-amount.php
new file mode 100644
index 00000000..d6c842ea
--- /dev/null
+++ b/examples/checkout/admin/cancel-order-amount.php
@@ -0,0 +1,25 @@
+setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setAmountIncVat(5.00)
+ ->cancelCheckoutOrderAmount()
+ ->doRequest();
+ var_dump($response);
+} catch (\Exception $ex) {
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
+}
diff --git a/examples/checkout/admin/cancel-order-row.php b/examples/checkout/admin/cancel-order-row.php
new file mode 100644
index 00000000..dbd80978
--- /dev/null
+++ b/examples/checkout/admin/cancel-order-row.php
@@ -0,0 +1,27 @@
+setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setRowToCancel(1)
+ ->cancelCheckoutOrderRows()
+ ->doRequest();
+
+ var_dump($response);
+} catch (\Exception $ex) {
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
+}
diff --git a/example/checkout/admin/cancel-order.php b/examples/checkout/admin/cancel-order.php
similarity index 50%
rename from example/checkout/admin/cancel-order.php
rename to examples/checkout/admin/cancel-order.php
index 1e354064..33a8cf50 100644
--- a/example/checkout/admin/cancel-order.php
+++ b/examples/checkout/admin/cancel-order.php
@@ -13,12 +13,12 @@
// Cancel order
try {
- $response = WebPayAdmin::cancelOrder($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->cancelCheckoutOrder()
- ->doRequest();
- var_dump($response);
+ $response = WebPayAdmin::cancelOrder($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->cancelCheckoutOrder()
+ ->doRequest();
+ var_dump($response);
} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
}
diff --git a/examples/checkout/admin/credit-amount.php b/examples/checkout/admin/credit-amount.php
new file mode 100644
index 00000000..5b23d06e
--- /dev/null
+++ b/examples/checkout/admin/credit-amount.php
@@ -0,0 +1,27 @@
+setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId(1)
+ ->setAmountIncVat(20.00)
+ ->creditCheckoutAmount()
+ ->doRequest();
+
+ var_dump($response);
+} catch (\Exception $ex) {
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
+}
diff --git a/examples/checkout/admin/credit-new-order-row.php b/examples/checkout/admin/credit-new-order-row.php
new file mode 100644
index 00000000..129157fd
--- /dev/null
+++ b/examples/checkout/admin/credit-new-order-row.php
@@ -0,0 +1,48 @@
+setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId(1);
+
+
+ /**
+ * Create a new OrderRow for the credited amount and add it to the builder object using addCreditOrderRow():
+ */
+ $myCreditRow = WebPayItem::orderRow()
+ ->setAmountIncVat(300.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("Credited order with new Order row");
+
+ /**
+ * If client wants to credit order with new order row, he can use code snippet above for that.
+ */
+ $creditOrderRowsBuilder->addCreditOrderRow($myCreditRow);
+
+
+ /**
+ * For crediting OrderRowIds look at credit-order-rows.php example
+ */
+ $response = $creditOrderRowsBuilder->creditCheckoutOrderWithNewOrderRow()->doRequest();
+
+ var_dump($response);
+} catch (\Exception $ex) {
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
+}
diff --git a/examples/checkout/admin/credit-order-rows.php b/examples/checkout/admin/credit-order-rows.php
new file mode 100644
index 00000000..b5e813fe
--- /dev/null
+++ b/examples/checkout/admin/credit-order-rows.php
@@ -0,0 +1,37 @@
+setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId(1);
+
+ /**
+ * $creditOrderRowsBuilder->setRowsToCredit(array(1, 2)) // If you want to credited more then one order Row
+ * $creditOrderRowsBuilder->setRowToCredit(3)// Credit just one order Row
+ *
+ * For crediting NewOrderRow look at credit-new-order-row.php example
+ */
+ $creditOrderRowsBuilder->setRowsToCredit([3]);
+
+ $response = $creditOrderRowsBuilder->creditCheckoutOrderRows()->doRequest();
+
+ var_dump($response);
+} catch (\Exception $ex) {
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
+}
diff --git a/examples/checkout/admin/deliver-order-rows.php b/examples/checkout/admin/deliver-order-rows.php
new file mode 100644
index 00000000..b0fa28dd
--- /dev/null
+++ b/examples/checkout/admin/deliver-order-rows.php
@@ -0,0 +1,26 @@
+setCheckoutOrderId($sveaCheckoutOrderId) // Required field
+ ->setRowsToDeliver([1, 2]) // Required field
+ ->deliverCheckoutOrderRows()
+ ->doRequest();
+
+ var_dump($response);
+} catch (\Exception $ex) {
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
+}
diff --git a/examples/checkout/admin/deliver-order.php b/examples/checkout/admin/deliver-order.php
new file mode 100644
index 00000000..0032d90f
--- /dev/null
+++ b/examples/checkout/admin/deliver-order.php
@@ -0,0 +1,25 @@
+setCheckoutOrderId($sveaCheckoutOrderId) // Required field
+ ->deliverCheckoutOrder()
+ ->doRequest();
+
+ var_dump($response);
+} catch (\Exception $ex) {
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
+}
diff --git a/example/checkout/admin/get-task-info.php b/examples/checkout/admin/get-task-info.php
similarity index 54%
rename from example/checkout/admin/get-task-info.php
rename to examples/checkout/admin/get-task-info.php
index 77960a68..c8946edf 100644
--- a/example/checkout/admin/get-task-info.php
+++ b/examples/checkout/admin/get-task-info.php
@@ -12,13 +12,13 @@
$taskUrl = 'http://paymentadminapi.svea.com/api/v1/queue/1';
try {
- $response = WebPayAdmin::queryTaskInfo($testConfig)
- ->setTaskUrl($taskUrl)
- ->getTaskInfo()
- ->doRequest();
+ $response = WebPayAdmin::queryTaskInfo($testConfig)
+ ->setTaskUrl($taskUrl)
+ ->getTaskInfo()
+ ->doRequest();
- print_r($response);
+ print_r($response);
} catch (\Exception $ex) {
- var_dump('Error message -> ' . $ex->getMessage());
- var_dump('Error code -> ' . $ex->getCode());
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
}
diff --git a/examples/checkout/admin/query-order.php b/examples/checkout/admin/query-order.php
new file mode 100644
index 00000000..7aad5d19
--- /dev/null
+++ b/examples/checkout/admin/query-order.php
@@ -0,0 +1,24 @@
+setCheckoutOrderId($sveaCheckoutOrderId)
+ ->queryCheckoutOrder()
+ ->doRequest();
+
+ print_r($response);
+} catch (\Exception $ex) {
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
+}
diff --git a/examples/checkout/admin/update-order-row.php b/examples/checkout/admin/update-order-row.php
new file mode 100644
index 00000000..544c39e9
--- /dev/null
+++ b/examples/checkout/admin/update-order-row.php
@@ -0,0 +1,37 @@
+setCheckoutOrderId($sveaCheckoutOrderId)
+ ->updateOrderRow(
+ WebPayItem::numberedOrderRow()
+ ->setRowId(4)
+ ->setName('someProd')
+ ->setVatPercent(6)
+ ->setDiscountPercent(50)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(4)
+ ->setUnit('pc')
+ )
+ ->updateCheckoutOrderRows()
+ ->doRequest();
+
+ var_dump($response);
+} catch (\Exception $ex) {
+ var_dump('Error message -> ' . $ex->getMessage());
+ var_dump('Error code -> ' . $ex->getCode());
+}
diff --git a/example/checkout/createCheckoutOrder.php b/examples/checkout/createCheckoutOrder.php
similarity index 50%
rename from example/checkout/createCheckoutOrder.php
rename to examples/checkout/createCheckoutOrder.php
index d9f094bd..3a34ecd4 100644
--- a/example/checkout/createCheckoutOrder.php
+++ b/examples/checkout/createCheckoutOrder.php
@@ -24,26 +24,26 @@
$orderBuilder->setCountryCode('SE')// customer country, we recommend basing this on the customer billing address
->setCurrency('SEK')
- ->setClientOrderNumber(rand(270000, 670000))
- ->setCheckoutUri('http://localhost:51925/')
- ->setConfirmationUri('http://localhost:51925/checkout/confirm')
- ->setPushUri('https://svea.com/push.aspx?sid=123&svea_order=123')
- ->setTermsUri('http://localhost:51898/terms')
+ ->setClientOrderNumber(rand(270000, 670000))
+ ->setCheckoutUri('http://localhost:51925/')
+ ->setConfirmationUri('http://localhost:51925/checkout/confirm')
+ ->setPushUri('https://svea.com/push.aspx?sid=123&svea_order=123')
+ ->setTermsUri('http://localhost:51898/terms')
//->setValidationCallbackUri('http://localhost:51898/validation-callback')
//->setPartnerKey("77FB33EC-505D-4CCF-AA21-D9DF50DC8344")
//->setMerchantData("merchantData")
//->setRequireElectronicIdAuthentication(true)
- ->setLocale($locale);
+ ->setLocale($locale);
$presetPhoneNumber = WebPayItem::presetValue()
- ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::PHONE_NUMBER)
- ->setValue('+381212121')
- ->setIsReadonly(true);
+ ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::PHONE_NUMBER)
+ ->setValue('+381212121')
+ ->setIsReadonly(true);
$presetPostalCode = WebPayItem::presetValue()
- ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::POSTAL_CODE)
- ->setValue('11000')
- ->setIsReadonly(false);
+ ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::POSTAL_CODE)
+ ->setValue('11000')
+ ->setIsReadonly(false);
$orderBuilder->addPresetValue($presetPhoneNumber);
@@ -54,36 +54,36 @@
// create and add items to order
$firstBoughtItem = WebPayItem::orderRow()
- ->setAmountIncVat(100.00)// - required
- ->setVatPercent(25)// - required
- ->setQuantity(1)
- ->setArticleNumber('123')
-// ->setAmountExVat(12.32) // - this action is not allowed for checkout
- ->setTemporaryReference('230')
- ->setName('Fork');
+ ->setAmountIncVat(100.00)// - required
+ ->setVatPercent(25)// - required
+ ->setQuantity(1)
+ ->setArticleNumber('123')
+// ->setAmountExVat(12.32) // - this action is not allowed for checkout
+ ->setTemporaryReference('230')
+ ->setName('Fork');
$secondBoughtItem = WebPayItem::orderRow()
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- ->setDescription('Korv med bröd')
- ->setArticleNumber('321')
- ->setTemporaryReference('231')
- ->setName('Fork');
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ ->setDescription('Korv med bröd')
+ ->setArticleNumber('321')
+ ->setTemporaryReference('231')
+ ->setName('Fork');
$discountItem = WebPayItem::fixedDiscount()
- ->setName('Promo coupon')
- ->setVatPercent(25)
- ->setTemporaryReference('123')
-// ->setAmountExVat(12.32) // - this action is not allowed for checkout
- ->setAmountIncVat(20.00);
+ ->setName('Promo coupon')
+ ->setVatPercent(25)
+ ->setTemporaryReference('123')
+// ->setAmountExVat(12.32) // - this action is not allowed for checkout
+ ->setAmountIncVat(20.00);
$shippingItem = WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(25)
- ->setTemporaryReference('123')
-// ->setAmountExVat(25.32) // - this action is not allowed for checkout
- ->setName('incvatShippingFee');
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(25)
+ ->setTemporaryReference('123')
+// ->setAmountExVat(25.32) // - this action is not allowed for checkout
+ ->setName('incvatShippingFee');
$orderBuilder->addOrderRow($firstBoughtItem);
$orderBuilder->addOrderRow($secondBoughtItem);
@@ -91,8 +91,8 @@
$orderBuilder->addFee($shippingItem);
try {
- $response = $orderBuilder->createOrder();
- echo "" . print_r($response, true) . "
";
+ $response = $orderBuilder->createOrder();
+ echo "" . print_r($response, true) . "
";
} catch (\Exception $e) {
- echo "" . print_r($e->getMessage(), true) . "
";
+ echo "" . print_r($e->getMessage(), true) . "
";
}
diff --git a/examples/checkout/getAvailablePartPaymentCampaigns.php b/examples/checkout/getAvailablePartPaymentCampaigns.php
new file mode 100644
index 00000000..53b8c181
--- /dev/null
+++ b/examples/checkout/getAvailablePartPaymentCampaigns.php
@@ -0,0 +1,33 @@
+setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::IS_COMPANY)
+ ->setValue(false)
+ ->setIsReadonly(true);
+
+ $request->setCountryCode('SE')
+ ->addPresetValue($presetValueIsCompany);
+
+ $response = $request->getAvailablePartPaymentCampaigns();
+ echo "" . print_r($response, true) . "
";
+} catch (\Exception $e) {
+ echo "" . print_r($e->getMessage(), true) . "
";
+}
\ No newline at end of file
diff --git a/example/checkout/getCheckoutOrder.php b/examples/checkout/getCheckoutOrder.php
similarity index 70%
rename from example/checkout/getCheckoutOrder.php
rename to examples/checkout/getCheckoutOrder.php
index c1028265..98cd9f54 100644
--- a/example/checkout/getCheckoutOrder.php
+++ b/examples/checkout/getCheckoutOrder.php
@@ -19,11 +19,11 @@
$orderBuilder = WebPay::checkout($myConfig);
$orderBuilder->setCheckoutOrderId(51721)
- ->setCountryCode('SE'); // optional line of code
+ ->setCountryCode('SE'); // optional line of code
try {
- $response = $orderBuilder->getOrder();
- echo "" . print_r($response, true) ."
";
+ $response = $orderBuilder->getOrder();
+ echo "" . print_r($response, true) ."
";
} catch (\Exception $e) {
- echo "" . print_r($e->getMessage(), true) . "
";
+ echo "" . print_r($e->getMessage(), true) . "
";
}
diff --git a/example/checkout/updateCheckoutOrder.php b/examples/checkout/updateCheckoutOrder.php
similarity index 53%
rename from example/checkout/updateCheckoutOrder.php
rename to examples/checkout/updateCheckoutOrder.php
index bb294caf..6019a481 100644
--- a/example/checkout/updateCheckoutOrder.php
+++ b/examples/checkout/updateCheckoutOrder.php
@@ -20,35 +20,35 @@
$orderBuilder = WebPay::checkout($myConfig);
$orderBuilder->setCheckoutOrderId(7479)
- //->setMerchantData("merchantData")
- ->setCountryCode('SE');
+ //->setMerchantData("merchantData")
+ ->setCountryCode('SE');
// create and add items to order
$firstBoughtItem = WebPayItem::orderRow()
- ->setAmountIncVat(10.99)
- ->setVatPercent(25)
-// ->setAmountExVat(12.32) // - this action is not allowed for checkout
- ->setQuantity(1)
- ->setDescription("Billy")
- ->setArticleNumber("123456789A")
- ->setName('Fork');
+ ->setAmountIncVat(10.99)
+ ->setVatPercent(25)
+// ->setAmountExVat(12.32) // - this action is not allowed for checkout
+ ->setQuantity(1)
+ ->setDescription("Billy")
+ ->setArticleNumber("123456789A")
+ ->setName('Fork');
$secondBoughtItem = WebPayItem::orderRow()
- ->setAmountIncVat(5.00)
- ->setVatPercent(12)
-// ->setAmountExVat(12.32) // - this action is not allowed for checkout
- ->setQuantity(2)
- ->setDescription("Korv med bröd")
- ->setArticleNumber("123456789B")
- ->setName('Fork');
+ ->setAmountIncVat(5.00)
+ ->setVatPercent(12)
+// ->setAmountExVat(12.32) // - this action is not allowed for checkout
+ ->setQuantity(2)
+ ->setDescription("Korv med bröd")
+ ->setArticleNumber("123456789B")
+ ->setName('Fork');
$orderBuilder->addOrderRow($firstBoughtItem);
$orderBuilder->addOrderRow($secondBoughtItem);
try {
- $response = $orderBuilder->updateOrder();
- print_r($response);
+ $response = $orderBuilder->updateOrder();
+ print_r($response);
} catch (\Exception $e) {
- print_r($e->getMessage());
+ print_r($e->getMessage());
}
diff --git a/examples/config_getaddresses/MyConfig.php b/examples/config_getaddresses/MyConfig.php
new file mode 100644
index 00000000..8d9647f8
--- /dev/null
+++ b/examples/config_getaddresses/MyConfig.php
@@ -0,0 +1,244 @@
+
+ [
+ // invoice payment method credentials for SE, i.e. client number, username and password
+ // replace with your own, or leave blank
+ WebPay\Config\ConfigurationProvider::INVOICE_TYPE =>
+ [
+ "username" => "sverigetest", // swap this for your actual SE invoice prod account credentials
+ "password" => "sverigetest", // swap this for your actual SE invoice prod account credentials
+ "clientNumber" => 79021 // swap this for your actual SE invoice prod account credentials
+ ],
+
+ // payment plan payment method credentials for SE
+ // replace with your own, or leave blank
+ WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE =>
+ [
+ "username" => "sverigetest", // swap this for your actual SE payment plan prod account credentials
+ "password" => "sverigetest", // swap this for your actual SE payment plan prod account credentials
+ "clientNumber" => 59999 // swap this for your actual SE payment plan prod account credentials
+ ],
+
+ // card and direct bank payment method credentials, i.e. merchant id and secret word
+ // replace with your own, or leave blank
+ WebPay\Config\ConfigurationProvider::HOSTED_TYPE =>
+ [
+ "merchantId" => 1130,
+ "secret" => "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3"
+ ]
+ ]
+ ];
+
+ // We don't accept payment plan payments in Norway, nor do we accept card payments from there
+ $prodConfig["NO"] =
+ ["auth" =>
+ [
+ WebPay\Config\ConfigurationProvider::INVOICE_TYPE =>
+ [
+ "username" => "norgetest2", // swap this for your actual SE invoice account credentials
+ "password" => "norgetest2", // swap this for your actual SE invoice account credentials
+ "clientNumber" => 33308 // swap this for your actual SE invoice account credentials
+ ],
+ WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ WebPay\Config\ConfigurationProvider::HOSTED_TYPE => ["merchantId" => "", "secret" => ""]
+ ]
+ ];
+
+ // We have no invoice or payment plan accounts for Denmark, but our card payment account is configured to accept orders there
+ $prodConfig["DK"] =
+ ["auth" =>
+ [
+ WebPay\Config\ConfigurationProvider::INVOICE_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ [
+ // swap these for your actual merchant id and secret word
+ "merchantId" => 1130,
+ "secret" => "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3"
+ ]
+ ]
+ ];
+
+ // We have no invoice or payment plan accounts for Finland, neither do we accept card payments from there
+ $prodConfig["FI"] =
+ ["auth" =>
+ [
+ WebPay\Config\ConfigurationProvider::INVOICE_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ WebPay\Config\ConfigurationProvider::HOSTED_TYPE => ["merchantId" => "", "secret" => ""]
+ ]
+ ];
+ // We have no invoice or payment plan accounts for Germany, neither do we accept card payments from there
+ $prodConfig["DE"] =
+ ["auth" =>
+ [
+ WebPay\Config\ConfigurationProvider::INVOICE_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ WebPay\Config\ConfigurationProvider::HOSTED_TYPE => ["merchantId" => "", "secret" => ""]
+ ]
+ ];
+ // We have no invoice or payment plan accounts for Netherlands, neither do we accept card payments from Denmark
+ $prodConfig["NL"] =
+ ["auth" =>
+ [
+ WebPay\Config\ConfigurationProvider::INVOICE_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ WebPay\Config\ConfigurationProvider::PAYMENTPLAN_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ WebPay\Config\ConfigurationProvider::HOSTED_TYPE => ["merchantId" => "", "secret" => ""]
+ ]
+ ];
+
+ // don't modify this
+ $url = [
+ ConfigurationProvider::HOSTED_TYPE => self::SWP_PROD_URL,
+ ConfigurationProvider::INVOICE_TYPE => self::SWP_PROD_WS_URL,
+ ConfigurationProvider::PAYMENTPLAN_TYPE => self::SWP_PROD_WS_URL,
+ ConfigurationProvider::HOSTED_ADMIN_TYPE => self::SWP_PROD_HOSTED_ADMIN_URL,
+ ConfigurationProvider::ADMIN_TYPE => self::SWP_PROD_ADMIN_URL
+ ];
+
+ return new SveaConfigurationProvider(["url" => $url, "credentials" => $prodConfig]);
+ }
+
+ /**
+ * @return \Svea\WebPay\Config\SveaConfigurationProvider
+ */
+ public static function getDefaultConfig()
+ {
+ return self::getTestConfig();
+ }
+
+ /**
+ * Replace the provided Svea test account credentials with your own to use
+ * the package with your own account.
+ *
+ * @return \Svea\WebPay\Config\SveaConfigurationProvider
+ */
+ public static function getTestConfig()
+ {
+ $testConfig = [];
+
+
+ // test credentials for Sweden
+ $testConfig["SE"] =
+ ["auth" =>
+ [
+ ConfigurationProvider::INVOICE_TYPE =>
+ [
+ "username" => "sverigetest", // swap this for your actual SE invoice test account credentials
+ "password" => "sverigetest", // swap this for your actual SE invoice test account credentials
+ "clientNumber" => 79021 // swap this for your actual SE invoice test account credentials
+ ],
+
+ ConfigurationProvider::PAYMENTPLAN_TYPE =>
+ [
+ "username" => "sverigetest", // swap this for your actual SE payment plan test account credentials
+ "password" => "sverigetest", // swap this for your actual SE payment plan test account credentials
+ "clientNumber" => 59999 // swap this for your actual SE payment plan test account credentials
+ ],
+
+ ConfigurationProvider::HOSTED_TYPE =>
+ [
+ // swap these for your actual merchant id and secret word
+ "merchantId" => 1130,
+ "secret" => "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3"
+ ]
+ ]
+ ];
+
+ // We don't accept payment plan payments in Norway, nor do we accept card payments from there
+ $testConfig["NO"] =
+ ["auth" =>
+ [
+ ConfigurationProvider::INVOICE_TYPE =>
+ [
+ "username" => "norgetest2", // swap this for your actual SE invoice account credentials
+ "password" => "norgetest2", // swap this for your actual SE invoice account credentials
+ "clientNumber" => 33308 // swap this for your actual SE invoice account credentials
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ ConfigurationProvider::HOSTED_TYPE => ["merchantId" => "", "secret" => ""]
+ ]
+ ];
+
+ // We have no invoice or payment plan accounts for Denmark, but our card payment account is configured to accept orders there
+ $testConfig["DK"] =
+ ["auth" =>
+ [
+ ConfigurationProvider::INVOICE_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ [
+ // swap these for your actual merchant id and secret word
+ "merchantId" => 1130,
+ "secret" => "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3"
+ ]
+ ]
+ ];
+
+ // We have no invoice or payment plan accounts for Finland, neither do we accept card payments from there
+ $testConfig["FI"] =
+ ["auth" =>
+ [
+ ConfigurationProvider::INVOICE_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ ConfigurationProvider::HOSTED_TYPE => ["merchantId" => "", "secret" => ""]
+ ]
+ ];
+
+ // We have no invoice or payment plan accounts for Germany, neither do we accept card payments from there
+ $testConfig["DE"] =
+ ["auth" =>
+ [
+ ConfigurationProvider::INVOICE_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ ConfigurationProvider::HOSTED_TYPE => ["merchantId" => "", "secret" => ""]
+ ]
+ ];
+
+ // We have no invoice or payment plan accounts for Netherlands, neither do we accept card payments from Denmark
+ $testConfig["NL"] =
+ ["auth" =>
+ [
+ ConfigurationProvider::INVOICE_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => ["username" => "", "password" => "", "clientNumber" => ""],
+ ConfigurationProvider::HOSTED_TYPE => ["merchantId" => "", "secret" => ""]
+ ]
+ ];
+
+ // don't modify this
+ $url = [
+ ConfigurationProvider::HOSTED_TYPE => self::SWP_TEST_URL,
+ ConfigurationProvider::INVOICE_TYPE => self::SWP_TEST_WS_URL,
+ ConfigurationProvider::PAYMENTPLAN_TYPE => self::SWP_TEST_WS_URL,
+ ConfigurationProvider::HOSTED_ADMIN_TYPE => self::SWP_TEST_HOSTED_ADMIN_URL,
+ ConfigurationProvider::ADMIN_TYPE => self::SWP_TEST_ADMIN_URL
+ ];
+
+ return new SveaConfigurationProvider(["url" => $url, "credentials" => $testConfig]);
+ }
+}
diff --git a/example/config_getaddresses/config_getaddresses.php b/examples/config_getaddresses/config_getaddresses.php
similarity index 93%
rename from example/config_getaddresses/config_getaddresses.php
rename to examples/config_getaddresses/config_getaddresses.php
index 20866075..9fb3ff52 100644
--- a/example/config_getaddresses/config_getaddresses.php
+++ b/examples/config_getaddresses/config_getaddresses.php
@@ -22,9 +22,9 @@
// Get a config object populated with the correct credentials, for test or production, respectively
if ($testmode_enabled) {
- $myConfig = Svea\MyConfig::getTestConfig();
+ $myConfig = Svea\MyConfig::getTestConfig();
} else {
- $myConfig = Svea\MyConfig::getProdConfig();
+ $myConfig = Svea\MyConfig::getProdConfig();
}
// Make a getAddresses lookup using my account test credentials:
@@ -67,7 +67,5 @@
print_r($companyResponse);
//foreach( $companyResponse->customerIdentity as $address ) {
-// print_r( $address ); print_r( "\n" );
+// print_r( $address ); print_r( "\n" );
//}
-
-?>
diff --git a/example/creditorderrows_card/.gitignore b/examples/creditorderrows_card/.gitignore
similarity index 100%
rename from example/creditorderrows_card/.gitignore
rename to examples/creditorderrows_card/.gitignore
diff --git a/example/creditorderrows_card/cardorder_credit.php b/examples/creditorderrows_card/cardorder_credit.php
similarity index 66%
rename from example/creditorderrows_card/cardorder_credit.php
rename to examples/creditorderrows_card/cardorder_credit.php
index 5517890a..921e3f73 100644
--- a/example/creditorderrows_card/cardorder_credit.php
+++ b/examples/creditorderrows_card/cardorder_credit.php
@@ -23,33 +23,33 @@
// You then add information to the order object by using the methods in the Svea\WebPay\BuildOrder\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->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\WebPay\BuildOrder\RowBuilders\OrderRow class, and adding them to the order:
$myOrder
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("A")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("B")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("C")
- );
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("A")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("B")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->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)
@@ -59,8 +59,8 @@
// Then set any additional required request attributes as detailed below. (See Svea\PaymentMethodPayment and Svea\HostedPayment classes for details.)
$myCardOrderRequest
- ->setCardPageLanguage("SV")// ISO639 language code, i.e. "SV", "EN" etc. Defaults to English.
- ->setReturnUrl("http://localhost/" . getPath() . "/landingpage_credit.php"); // The return url where we receive and process the finished request response
+ ->setCardPageLanguage("SV")// ISO639 language code, i.e. "SV", "EN" etc. Defaults to English.
+ ->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();
@@ -75,12 +75,10 @@
*/
function getPath()
{
- $myURL = $_SERVER['SCRIPT_NAME'];
- $myPath = explode('/', $myURL);
- unset($myPath[count($myPath) - 1]);
- $myPath = implode('/', $myPath);
+ $myURL = $_SERVER['SCRIPT_NAME'];
+ $myPath = explode('/', $myURL);
+ unset($myPath[count($myPath) - 1]);
+ $myPath = implode('/', $myPath);
- return $myPath;
+ return $myPath;
}
-
-?>
diff --git a/examples/creditorderrows_card/creditorderrows.php b/examples/creditorderrows_card/creditorderrows.php
new file mode 100644
index 00000000..25604965
--- /dev/null
+++ b/examples/creditorderrows_card/creditorderrows.php
@@ -0,0 +1,200 @@
+Error: transactionid.txt not found, first run cardorder_credit.php to set up the card order. aborting.";
+ die;
+}
+$firstCreditOrderRowsBuilder
+ ->setOrderId($myTransactionId)
+ ->setCountryCode("SE");
+
+// Assume that we know that the original order total amount was 1*(100*1.25) + 2*(5.00*1.12) = 125+11.2 = SEK 136.2 (incl. VAT 26.2)
+// Create a new OrderRow for the credited amount and add it to the builder object using addCreditOrderRow():
+$myCreditRow = WebPayItem::orderRow()
+ ->setAmountExVat(300)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("Credited order #" . $myTransactionId);
+// Add the new order row to credit to the builder object.
+$firstCreditOrderRowsBuilder->addCreditOrderRow($myCreditRow);
+
+// Then we can send the credit request to Svea:
+
+$myCreditRequest = $firstCreditOrderRowsBuilder->creditCardOrderRows();
+$myCreditResponse = $myCreditRequest->doRequest();
+
+
+// The response is an instance of LowerTransactionResponse
+echo "";
+print_r("the creditCardOrderRows() response:");
+print_r($myCreditResponse);
+
+echo "\n\n\n
+An example of a non-successful credit request response, where the card order had not yet been processed (i.e. Svea transactionstatus doesn't equal SUCCESS).
+
+the creditCardOrderRows() response:Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse Object
+(
+ [customerrefno] => order #2014-08-26T13:49:48 02:00
+ [accepted] => 0
+ [resultcode] => 105 (ILLEGAL_TRANSACTIONSTATUS)
+ [errormessage] => Invalid transaction status.
+)
+
+An example of a non-successful credit request response, where the card order has already been credited for the full amount.
+
+the creditCardOrderRows() response:Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse Object
+(
+ [customerrefno] => order #2014-08-26T14:28:33 02:00
+ [accepted] => 0
+ [resultcode] => 119 (ILLEGAL_CREDITED_AMOUNT)
+ [errormessage] => Invalid credited amount.
+)";
+
+echo "\n
\n\n
+An example of a non-successful credit request response, where the card order has been first confirmed and then processed to status SUCCESS in bank.
+
+the creditCardOrderRows() response:Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse Object
+(
+ [customerrefno] => order #2014-08-26T14:28:33 02:00
+ [accepted] => 1
+ [resultcode] => 0
+ [errormessage] =>
+)
+
+The following is the result of a Svea\WebPay\WebPayAdmin::queryOrder for the above order, as you can see the entire authorized/captured amount has been credited:
+
+
+
+Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse Object
+(
+ [transactionId] => 589747
+ [clientOrderNumber] => order #2014-11-20T15:26:33 01:00
+ [merchantId] => 1130
+ [status] => SUCCESS
+ [amount] => 37500
+ [currency] => SEK
+ [vat] => 7500
+ [capturedamount] => 37500
+ [authorizedamount] => 37500
+ [created] => 2014-11-20 15:26:35.09
+ [creditstatus] => CREDSUCCESS
+ [creditedamount] => 37500
+ [merchantresponsecode] => 0
+ [paymentMethod] => KORTCERT
+ [numberedOrderRows] => Array
+ (
+ [0] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
+ (
+ [creditInvoiceId] =>
+ [invoiceId] =>
+ [rowNumber] => 1
+ [status] =>
+ [articleNumber] =>
+ [quantity] => 1
+ [unit] =>
+ [amountExVat] => 100
+ [vatPercent] => 25
+ [amountIncVat] =>
+ [name] =>
+ [description] => A
+ [discountPercent] =>
+ [vatDiscount] => 0
+ )
+
+ [1] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
+ (
+ [creditInvoiceId] =>
+ [invoiceId] =>
+ [rowNumber] => 2
+ [status] =>
+ [articleNumber] =>
+ [quantity] => 1
+ [unit] =>
+ [amountExVat] => 100
+ [vatPercent] => 25
+ [amountIncVat] =>
+ [name] =>
+ [description] => B
+ [discountPercent] =>
+ [vatDiscount] => 0
+ )
+
+ [2] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
+ (
+ [creditInvoiceId] =>
+ [invoiceId] =>
+ [rowNumber] => 3
+ [status] =>
+ [articleNumber] =>
+ [quantity] => 1
+ [unit] =>
+ [amountExVat] => 100
+ [vatPercent] => 25
+ [amountIncVat] =>
+ [name] =>
+ [description] => C
+ [discountPercent] =>
+ [vatDiscount] => 0
+ )
+
+ )
+
+ [callbackurl] =>
+ [capturedate] => 2014-11-20 15:36:12.607
+ [subscriptionId] =>
+ [subscriptiontype] =>
+ [cardType] =>
+ [maskedCardNumber] =>
+ [eci] =>
+ [mdstatus] =>
+ [expiryYear] =>
+ [expiryMonth] =>
+ [chname] =>
+ [authCode] =>
+ [accepted] => 1
+ [resultcode] => 0
+ [errormessage] =>
+)
+
";
+
+/**
+ * get the path to this file, for use in specifying the returnurl etc.
+ */
+function getPath()
+{
+ $myURL = $_SERVER['SCRIPT_NAME'];
+ $myPath = explode('/', $myURL);
+ unset($myPath[count($myPath) - 1]);
+ $myPath = implode('/', $myPath);
+
+ return $myPath;
+}
diff --git a/example/creditorderrows_card/creditorderrows_with_rows.php b/examples/creditorderrows_card/creditorderrows_with_rows.php
similarity index 50%
rename from example/creditorderrows_card/creditorderrows_with_rows.php
rename to examples/creditorderrows_card/creditorderrows_with_rows.php
index c95dd01d..f395c953 100644
--- a/example/creditorderrows_card/creditorderrows_with_rows.php
+++ b/examples/creditorderrows_card/creditorderrows_with_rows.php
@@ -1,7 +1,7 @@
Error: transactionid.txt not found, first run cardorder_credit.php to set up the card order. aborting.";
- die;
+ echo "Error: transactionid.txt not found, first run cardorder_credit.php to set up the card order. aborting.";
+ die;
}
$firstCreditOrderRowsBuilder
- ->setOrderId( $myTransactionId )
- ->setCountryCode( "SE" )
+ ->setOrderId( $myTransactionId )
+ ->setCountryCode( "SE" )
;
$secondCreditOrderRowsBuilder = WebPayAdmin::creditOrderRows( $myConfig );
$secondCreditOrderRowsBuilder
- ->setOrderId( $myTransactionId )
- ->setCountryCode( "SE" )
+ ->setOrderId( $myTransactionId )
+ ->setCountryCode( "SE" )
;
// To credit specific order rows, you pass the order rows numbers you wish to credit using setRowsToCredit().
-// For card orders, you also need to pass in the numbered order rows themselves using addNumberedOrderRows().
+// For card orders, you also need to pass in the numbered order rows themselves using addNumberedOrderRows().
// You can use the Svea\WebPay\WebPayAdmin::queryCardOrder() entrypoint method to get a copy of the original order rows sent to Svea.
// Note that these order rows does not update following a successful credit order rows request, even though the
-// QueryTransactionResponse field creditedamount returned by a queryOrder request will reflect the current credit status.
+// QueryTransactionResponse field creditedamount returned by a queryOrder request will reflect the current credit status.
//
$queryOrderBuilder = WebPayAdmin::queryOrder( $myConfig )
- ->setOrderId( $myTransactionId )
- ->setCountryCode( "SE" )
+ ->setOrderId( $myTransactionId )
+ ->setCountryCode( "SE" )
;
// query orderrows to pass in creditOrderRows->setNumberedOrderRows()
-$queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+$queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
if( ! $queryResponse->accepted ) {
- echo "Error: queryOrder failed. aborting.";
- die;
+ echo "Error: queryOrder failed. aborting.";
+ die;
}
// The query response holds an array of NumberedOrderRow containing the order rows as sent in the createOrder request
@@ -71,16 +71,16 @@
// Add the indexes to credit and the order row data to the builder object.
$secondCreditOrderRowsBuilder
- ->addNumberedOrderRows( $myOriginalOrderRows )
- ->setRowsToCredit( $myRowIndexesToCredit )
+ ->addNumberedOrderRows( $myOriginalOrderRows )
+ ->setRowsToCredit( $myRowIndexesToCredit )
;
// Send the credit request to Svea:
-$myCreditRequest = $secondCreditOrderRowsBuilder->creditCardOrderRows();
+$myCreditRequest = $secondCreditOrderRowsBuilder->creditCardOrderRows();
$myCreditResponse = $myCreditRequest->doRequest();
-// The response is an instance of LowerTransactionResponse
+// The response is an instance of LowerTransactionResponse
echo "";
print_r( "the creditCardOrderRows() response:");
print_r( $myCreditResponse );
@@ -90,20 +90,20 @@
the creditCardOrderRows() response:Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse Object
(
- [customerrefno] => order #2014-08-26T13:49:48 02:00
- [accepted] => 0
- [resultcode] => 105 (ILLEGAL_TRANSACTIONSTATUS)
- [errormessage] => Invalid transaction status.
+ [customerrefno] => order #2014-08-26T13:49:48 02:00
+ [accepted] => 0
+ [resultcode] => 105 (ILLEGAL_TRANSACTIONSTATUS)
+ [errormessage] => Invalid transaction status.
)
An example of a non-successful credit request response, where the card order has already been credited for the full amount.
the creditCardOrderRows() response:Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse Object
(
- [customerrefno] => order #2014-08-26T14:28:33 02:00
- [accepted] => 0
- [resultcode] => 119 (ILLEGAL_CREDITED_AMOUNT)
- [errormessage] => Invalid credited amount.
+ [customerrefno] => order #2014-08-26T14:28:33 02:00
+ [accepted] => 0
+ [resultcode] => 119 (ILLEGAL_CREDITED_AMOUNT)
+ [errormessage] => Invalid credited amount.
)";
echo "\n
\n\n
@@ -111,10 +111,10 @@
the creditCardOrderRows() response:Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse Object
(
- [customerrefno] => order #2014-08-26T14:28:33 02:00
- [accepted] => 1
- [resultcode] => 0
- [errormessage] =>
+ [customerrefno] => order #2014-08-26T14:28:33 02:00
+ [accepted] => 1
+ [resultcode] => 0
+ [errormessage] =>
)
The following is the result of a Svea\WebPay\WebPayAdmin::queryOrder for the above order, as you can see the entire authorized/captured amount has been credited:
@@ -123,93 +123,93 @@
Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse Object
(
- [transactionId] => 589756
- [clientOrderNumber] => order #2014-11-20T16:00:34 01:00
- [merchantId] => 1130
- [status] => SUCCESS
- [amount] => 37500
- [currency] => SEK
- [vat] => 7500
- [capturedamount] => 37500
- [authorizedamount] => 37500
- [created] => 2014-11-20 16:00:35.737
- [creditstatus] => CREDSUCCESS
- [creditedamount] => 37500
- [merchantresponsecode] => 0
- [paymentMethod] => KORTCERT
- [numberedOrderRows] => Array
- (
- [0] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
- (
- [creditInvoiceId] =>
- [invoiceId] =>
- [rowNumber] => 1
- [status] =>
- [articleNumber] =>
- [quantity] => 1
- [unit] =>
- [amountExVat] => 100
- [vatPercent] => 25
- [amountIncVat] =>
- [name] =>
- [description] => A
- [discountPercent] =>
- [vatDiscount] => 0
- )
-
- [1] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
- (
- [creditInvoiceId] =>
- [invoiceId] =>
- [rowNumber] => 2
- [status] =>
- [articleNumber] =>
- [quantity] => 1
- [unit] =>
- [amountExVat] => 100
- [vatPercent] => 25
- [amountIncVat] =>
- [name] =>
- [description] => B
- [discountPercent] =>
- [vatDiscount] => 0
- )
-
- [2] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
- (
- [creditInvoiceId] =>
- [invoiceId] =>
- [rowNumber] => 3
- [status] =>
- [articleNumber] =>
- [quantity] => 1
- [unit] =>
- [amountExVat] => 100
- [vatPercent] => 25
- [amountIncVat] =>
- [name] =>
- [description] => C
- [discountPercent] =>
- [vatDiscount] => 0
- )
-
- )
-
- [callbackurl] =>
- [capturedate] => 2014-11-20 16:02:20.26
- [subscriptionId] =>
- [subscriptiontype] =>
- [cardType] =>
- [maskedCardNumber] =>
- [eci] =>
- [mdstatus] =>
- [expiryYear] =>
- [expiryMonth] =>
- [chname] =>
- [authCode] =>
- [accepted] => 1
- [resultcode] => 0
- [errormessage] =>
+ [transactionId] => 589756
+ [clientOrderNumber] => order #2014-11-20T16:00:34 01:00
+ [merchantId] => 1130
+ [status] => SUCCESS
+ [amount] => 37500
+ [currency] => SEK
+ [vat] => 7500
+ [capturedamount] => 37500
+ [authorizedamount] => 37500
+ [created] => 2014-11-20 16:00:35.737
+ [creditstatus] => CREDSUCCESS
+ [creditedamount] => 37500
+ [merchantresponsecode] => 0
+ [paymentMethod] => KORTCERT
+ [numberedOrderRows] => Array
+ (
+ [0] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
+ (
+ [creditInvoiceId] =>
+ [invoiceId] =>
+ [rowNumber] => 1
+ [status] =>
+ [articleNumber] =>
+ [quantity] => 1
+ [unit] =>
+ [amountExVat] => 100
+ [vatPercent] => 25
+ [amountIncVat] =>
+ [name] =>
+ [description] => A
+ [discountPercent] =>
+ [vatDiscount] => 0
+ )
+
+ [1] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
+ (
+ [creditInvoiceId] =>
+ [invoiceId] =>
+ [rowNumber] => 2
+ [status] =>
+ [articleNumber] =>
+ [quantity] => 1
+ [unit] =>
+ [amountExVat] => 100
+ [vatPercent] => 25
+ [amountIncVat] =>
+ [name] =>
+ [description] => B
+ [discountPercent] =>
+ [vatDiscount] => 0
+ )
+
+ [2] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
+ (
+ [creditInvoiceId] =>
+ [invoiceId] =>
+ [rowNumber] => 3
+ [status] =>
+ [articleNumber] =>
+ [quantity] => 1
+ [unit] =>
+ [amountExVat] => 100
+ [vatPercent] => 25
+ [amountIncVat] =>
+ [name] =>
+ [description] => C
+ [discountPercent] =>
+ [vatDiscount] => 0
+ )
+
+ )
+
+ [callbackurl] =>
+ [capturedate] => 2014-11-20 16:02:20.26
+ [subscriptionId] =>
+ [subscriptiontype] =>
+ [cardType] =>
+ [maskedCardNumber] =>
+ [eci] =>
+ [mdstatus] =>
+ [expiryYear] =>
+ [expiryMonth] =>
+ [chname] =>
+ [authCode] =>
+ [accepted] => 1
+ [resultcode] => 0
+ [errormessage] =>
)
";
@@ -217,11 +217,10 @@
* get the path to this file, for use in specifying the returnurl etc.
*/
function getPath() {
- $myURL = $_SERVER['SCRIPT_NAME'];
- $myPath = explode('/', $myURL);
- unset( $myPath[count($myPath)-1]);
- $myPath = implode( '/', $myPath);
+ $myURL = $_SERVER['SCRIPT_NAME'];
+ $myPath = explode('/', $myURL);
+ unset( $myPath[count($myPath)-1]);
+ $myPath = implode( '/', $myPath);
- return $myPath;
+ return $myPath;
}
-?>
diff --git a/example/creditorderrows_card/landingpage_credit.php b/examples/creditorderrows_card/landingpage_credit.php
similarity index 74%
rename from example/creditorderrows_card/landingpage_credit.php
rename to examples/creditorderrows_card/landingpage_credit.php
index beb464c6..9b9f14e8 100644
--- a/example/creditorderrows_card/landingpage_credit.php
+++ b/examples/creditorderrows_card/landingpage_credit.php
@@ -1,7 +1,7 @@
getResponse()->accepted == 0 ) {
- echo "Request failed. aborting";
- print_r( $myResponse->getResponse() );
- die;
+ echo "Request failed. aborting";
+ print_r( $myResponse->getResponse() );
+ die;
}
// The decoded response is available through the ->getResponse() method.
@@ -50,31 +50,30 @@
Svea\WebPay\HostedService\HostedResponse\HostedPaymentResponse Object
(
- [transactionId] => 589739
- [clientOrderNumber] => order #2014-11-20T14:48:28 01:00
- [paymentMethod] => KORTCERT
- [merchantId] => 1130
- [amount] => 375
- [currency] => SEK
- [accepted] => 1
- [resultcode] =>
- [errormessage] =>
- [cardType] => VISA
- [maskedCardNumber] => 444433xxxxxx1100
- [expiryMonth] => 01
- [expiryYear] => 15
- [authCode] => 204374
+ [transactionId] => 589739
+ [clientOrderNumber] => order #2014-11-20T14:48:28 01:00
+ [paymentMethod] => KORTCERT
+ [merchantId] => 1130
+ [amount] => 375
+ [currency] => SEK
+ [accepted] => 1
+ [resultcode] =>
+ [errormessage] =>
+ [cardType] => VISA
+ [maskedCardNumber] => 444433xxxxxx1100
+ [expiryMonth] => 01
+ [expiryYear] => 15
+ [authCode] => 204374
)";
/**
* get the path to this file, for use in specifying the returnurl etc.
*/
function getPath() {
- $myURL = $_SERVER['SCRIPT_NAME'];
- $myPath = explode('/', $myURL);
- unset( $myPath[count($myPath)-1]);
- $myPath = implode( '/', $myPath);
+ $myURL = $_SERVER['SCRIPT_NAME'];
+ $myPath = explode('/', $myURL);
+ unset( $myPath[count($myPath)-1]);
+ $myPath = implode( '/', $myPath);
- return $myPath;
+ return $myPath;
}
-?>
diff --git a/example/firstdeliver/firstdeliver.php b/examples/firstdeliver/firstdeliver.php
similarity index 80%
rename from example/firstdeliver/firstdeliver.php
rename to examples/firstdeliver/firstdeliver.php
index 74fc2edf..ffe0f13f 100644
--- a/example/firstdeliver/firstdeliver.php
+++ b/examples/firstdeliver/firstdeliver.php
@@ -16,12 +16,12 @@
$myConfig = \Svea\WebPay\Config\ConfigurationService::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
+// 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();
+ 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 Svea\WebPay\WebPay::createOrder() method:
@@ -51,27 +51,27 @@
Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse Object
(
- [accepted] => 1
- [resultcode] => 0
- [errormessage] =>
- [amount] => 876.24
- [orderType] => Invoice
- [invoiceId] => 1028004
- [contractNumber] =>
+ [accepted] => 1
+ [resultcode] => 0
+ [errormessage] =>
+ [amount] => 876.24
+ [orderType] => Invoice
+ [invoiceId] => 1028004
+ [contractNumber] =>
)";
echo "\n
-An 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).
+An 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).
Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse Object
(
- [accepted] => 0
- [resultcode] => 20000
- [errormessage] => Order is closed.
- [amount] =>
- [orderType] =>
- [invoiceId] =>
- [contractNumber] =>
+ [accepted] => 0
+ [resultcode] => 20000
+ [errormessage] => Order is closed.
+ [amount] =>
+ [orderType] =>
+ [invoiceId] =>
+ [contractNumber] =>
)";
diff --git a/example/firstorder/.gitignore b/examples/firstorder/.gitignore
similarity index 100%
rename from example/firstorder/.gitignore
rename to examples/firstorder/.gitignore
diff --git a/example/firstorder/firstorder.php b/examples/firstorder/firstorder.php
similarity index 73%
rename from example/firstorder/firstorder.php
rename to examples/firstorder/firstorder.php
index ea9f3879..fe3b3cb8 100644
--- a/example/firstorder/firstorder.php
+++ b/examples/firstorder/firstorder.php
@@ -17,7 +17,7 @@
// get configuration object holding the Svea service login credentials
$myConfig = ConfigurationService::getTestConfig();
-// We assume that you've collected the following information about the order in your shop:
+// We assume that you've collected the following information about the order in your shop:
// The shop cart contains one item "Billy" which cost 700,99 kr excluding vat (25%).
// When selecting to pay using the invoice payment method, the customer has also provided their social security number, which is required for invoice orders.
@@ -37,14 +37,14 @@
$boughtItem->setVatPercent(0);
$boughtItem->setQuantity(1);
-// Add the order rows to the order:
+// Add the order rows to the order:
$myOrder->addOrderRow($boughtItem);
// Next, we create a customer identity object, for invoice orders Svea will look up the customer address et al based on the social security number
$customerInformation = WebPayItem::individualCustomer();
$customerInformation->setNationalIdNumber("194605092222");
-// Add the customer to the order:
+// Add the customer to the order:
$myOrder->addCustomerDetails($customerInformation);
// 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:
@@ -55,9 +55,9 @@
// Check the response attribute 'accepted' for true to see if the request succeeded, if not, see the attributes resultcode and/or errormessage
if ($myResponse->accepted == true) {
- // save the sveaOrderId to a file, for use in firstdeliver.php
- $myFirstOrderId = $myResponse->sveaOrderId;
- file_put_contents("sveaorderid.txt", $myFirstOrderId);
+ // save the sveaOrderId to a file, for use in firstdeliver.php
+ $myFirstOrderId = $myResponse->sveaOrderId;
+ file_put_contents("sveaorderid.txt", $myFirstOrderId);
};
echo "Your request response (the customerIdentity contains the verified invoice address, which should match the order shipping address used):\n\n";
@@ -72,29 +72,29 @@
Svea\WebPay\WebService\WebServiceResponse\CreateOrderResponse Object
(
- [sveaOrderId] => 362168
- [sveaWillBuyOrder] => 1
- [amount] => 876.24
- [expirationDate] => 2014-08-16T00:00:00+02:00
- [accepted] => 1
- [errormessage] =>
- [resultcode] => 0
- [orderType] => Invoice
- [customerIdentity] => Svea\WebPay\WebService\WebServiceResponse\CustomerIdentity\CreateOrderIdentity Object
- (
- [email] =>
- [ipAddress] =>
- [countryCode] => SE
- [houseNumber] =>
- [customerType] => Individual
- [nationalIdNumber] => 194605092222
- [phoneNumber] =>
- [fullName] => Persson, Tess T
- [street] => Testgatan 1
- [coAddress] => c/o Eriksson, Erik
- [zipCode] => 99999
- [locality] => Stan
- )
+ [sveaOrderId] => 362168
+ [sveaWillBuyOrder] => 1
+ [amount] => 876.24
+ [expirationDate] => 2014-08-16T00:00:00+02:00
+ [accepted] => 1
+ [errormessage] =>
+ [resultcode] => 0
+ [orderType] => Invoice
+ [customerIdentity] => Svea\WebPay\WebService\WebServiceResponse\CustomerIdentity\CreateOrderIdentity Object
+ (
+ [email] =>
+ [ipAddress] =>
+ [countryCode] => SE
+ [houseNumber] =>
+ [customerType] => Individual
+ [nationalIdNumber] => 194605092222
+ [phoneNumber] =>
+ [fullName] => Persson, Tess T
+ [street] => Testgatan 1
+ [coAddress] => c/o Eriksson, Erik
+ [zipCode] => 99999
+ [locality] => Stan
+ )
)";
diff --git a/example/invoiceorder/invoiceorder.php b/examples/invoiceorder/invoiceorder.php
similarity index 69%
rename from example/invoiceorder/invoiceorder.php
rename to examples/invoiceorder/invoiceorder.php
index 6d5679fd..3558eaa5 100644
--- a/example/invoiceorder/invoiceorder.php
+++ b/examples/invoiceorder/invoiceorder.php
@@ -38,13 +38,13 @@
// You then add information to the order object by using the methods in the Svea\WebPay\BuildOrder\CreateOrderBuilder class.
// For an Invoice 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->setCountryCode("SE"); // customer country, we recommend basing this on the customer billing address
+//$myOrder->setCurrency("SEK"); // order currency
// You may also chain fluent methods together:
$myOrder
-// ->setClientOrderNumber("order #20140519-375") // optional - use a not previously sent client side order identifier, i.e. "order #20140519-371"
-// ->setCustomerReference("customer #123") // optional - This should contain a customer reference, as in "customer #123".
- ->setOrderDate("2014-05-28") // required - or use an ISO8601 date as produced by i.e. date('c')
+// ->setClientOrderNumber("order #20140519-375") // optional - use a not previously sent client side order identifier, i.e. "order #20140519-371"
+// ->setCustomerReference("customer #123") // optional - This should contain a customer reference, as in "customer #123".
+ ->setOrderDate("2014-05-28") // required - or use an ISO8601 date as produced by i.e. date('c')
;
// Then specify the items bought as order rows, using the methods in the Svea\WebPay\BuildOrder\RowBuilders\OrderRow class, and adding them to the order:
$firstBoughtItem = WebPayItem::orderRow();
@@ -57,13 +57,13 @@
// Add firstBoughtItem to order row
$myOrder->addOrderRow($firstBoughtItem);
-// Add secondBoughtItem in a fluent fashion
+// Add secondBoughtItem in a fluent fashion
$myOrder->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(5.00)
- ->setVatPercent(12)
- ->setQuantity(2)
- ->setDescription("Korv med bröd")
+ WebPayItem::orderRow()
+ ->setAmountIncVat(5.00)
+ ->setVatPercent(12)
+ ->setQuantity(2)
+ ->setDescription("Korv med bröd")
);
// Next, we create a customer identity object, note that for invoice orders Svea overrides any given address w/verified credit report address in the response.
@@ -91,36 +91,36 @@
print_r($myResponse);
echo "
-An example of a successful request response. The 'accepted' attribute is true (1), and resultcode/errormessage is not set.
+An example of a successful request response. The 'accepted' attribute is true (1), and resultcode/errormessage is not set.
(Note that the customerIdentity received in the response indicates the Svea invoice address, which should normally match the order shipping address.):
Svea\WebPay\WebService\WebServiceResponse\CreateOrderResponse Object
(
- [sveaOrderId] => 503312
- [sveaWillBuyOrder] => 1
- [amount] => 23.73
- [expirationDate] => 2015-03-10T00:00:00+01:00
- [clientOrderNumber] =>
- [orderType] => Invoice
- [customerIdentity] => Svea\WebPay\WebService\WebServiceResponse\CustomerIdentity\CreateOrderIdentity Object
- (
- [email] =>
- [ipAddress] =>
- [countryCode] => SE
- [houseNumber] =>
- [customerType] => Individual
- [nationalIdNumber] => 194605092222
- [phoneNumber] =>
- [fullName] => Persson, Tess T
- [street] => Testgatan 1
- [coAddress] => c/o Eriksson, Erik
- [zipCode] => 99999
- [locality] => Stan
- )
-
- [accepted] => 1
- [errormessage] =>
- [resultcode] => 0
+ [sveaOrderId] => 503312
+ [sveaWillBuyOrder] => 1
+ [amount] => 23.73
+ [expirationDate] => 2015-03-10T00:00:00+01:00
+ [clientOrderNumber] =>
+ [orderType] => Invoice
+ [customerIdentity] => Svea\WebPay\WebService\WebServiceResponse\CustomerIdentity\CreateOrderIdentity Object
+ (
+ [email] =>
+ [ipAddress] =>
+ [countryCode] => SE
+ [houseNumber] =>
+ [customerType] => Individual
+ [nationalIdNumber] => 194605092222
+ [phoneNumber] =>
+ [fullName] => Persson, Tess T
+ [street] => Testgatan 1
+ [coAddress] => c/o Eriksson, Erik
+ [zipCode] => 99999
+ [locality] => Stan
+ )
+
+ [accepted] => 1
+ [errormessage] =>
+ [resultcode] => 0
)
";
diff --git a/example/paymentplan/getting_campaigns.php b/examples/paymentplan/getting_campaigns.php
similarity index 95%
rename from example/paymentplan/getting_campaigns.php
rename to examples/paymentplan/getting_campaigns.php
index 03573e0e..4e8aeadb 100644
--- a/example/paymentplan/getting_campaigns.php
+++ b/examples/paymentplan/getting_campaigns.php
@@ -15,6 +15,6 @@
$ppCampaign->enableLogging(true);
$campaigns = $ppCampaign->setCountryCode('SE')
- ->doRequest();
+ ->doRequest();
echo "" . print_r($campaigns, true) . "
";
diff --git a/example/swishorder/landingpage.php b/examples/swishorder/landingpage.php
similarity index 63%
rename from example/swishorder/landingpage.php
rename to examples/swishorder/landingpage.php
index dad209d9..147f552e 100644
--- a/example/swishorder/landingpage.php
+++ b/examples/swishorder/landingpage.php
@@ -2,7 +2,7 @@
/**
* example file, how to handle a swish order request response
- *
+ *
* @author Fredrik Sundell / fre-sund
*/
@@ -24,11 +24,11 @@
// decode the raw response by passing it through the Svea\WebPay\Response\SveaResponse class
try
{
- $myResponse = new SveaResponse($rawResponse, $countryCode = NULL, $myConfig);
+ $myResponse = new SveaResponse($rawResponse, $countryCode = NULL, $myConfig);
}
catch (Exception $e)
{
- echo $e->getMessage();
+ echo $e->getMessage();
}
// The decoded response is available through the ->getResponse() method.
@@ -43,33 +43,32 @@
Svea\WebPay\HostedService\HostedResponse\HostedPaymentResponse Object
(
- [transactionId] => 722742
- [clientOrderNumber] => order #2019-11-29T14:28:35 01:00
- [paymentMethod] => SWISH
- [merchantId] => 1130
- [amount] => 3.75
- [currency] => SEK
- [accepted] => 1
- [resultcode] =>
- [errormessage] =>
+ [transactionId] => 722742
+ [clientOrderNumber] => order #2019-11-29T14:28:35 01:00
+ [paymentMethod] => SWISH
+ [merchantId] => 1130
+ [amount] => 3.75
+ [currency] => SEK
+ [accepted] => 1
+ [resultcode] =>
+ [errormessage] =>
)
)";
echo "\n\n\n
-An example of a rejected request response -- 'accepted' is false (0) and resultcode/errormessage indicates that the clientOrderNumber above has been reused, which is prohibited.
+An example of a rejected request response -- 'accepted' is false (0) and resultcode/errormessage indicates that the clientOrderNumber above has been reused, which is prohibited.
Svea\HostedPaymentResponse Object
(
- [transactionId] => 582828
- [clientOrderNumber] => order #2019-11-29T14:28:35 01:00
- [paymentMethod] => SWISH
- [merchantId] => 1130
- [amount] => 3.75
- [currency] => SEK
- [accepted] => 0
- [resultcode] => 127 (CUSTOMERREFNO_ALREADY_USED)
- [errormessage] => Customer reference number already used in another transaction.
+ [transactionId] => 582828
+ [clientOrderNumber] => order #2019-11-29T14:28:35 01:00
+ [paymentMethod] => SWISH
+ [merchantId] => 1130
+ [amount] => 3.75
+ [currency] => SEK
+ [accepted] => 0
+ [resultcode] => 127 (CUSTOMERREFNO_ALREADY_USED)
+ [errormessage] => Customer reference number already used in another transaction.
)";
-?>
diff --git a/examples/swishorder/swishorder.php b/examples/swishorder/swishorder.php
new file mode 100644
index 00000000..f2b827c8
--- /dev/null
+++ b/examples/swishorder/swishorder.php
@@ -0,0 +1,93 @@
+setCurrency("SEK"); // 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") // optional - This should contain a customer reference, as in "customer #123".
+ ->setOrderDate("2019-11-29") // optional - or use an ISO8601 date as produced by i.e. date('c')
+ ->setPayerAlias("46707937643") // required for Swish payments, ignored otherwise;
+ ->setCountryCode("SE"); // countryCode "SE" is required for Swish payments
+
+
+ // Then specify the items bought as order rows, using the methods in the Svea\WebPay\BuildOrder\RowBuilders\OrderRow class, and adding them to the order:
+ $firstBoughtItem = WebPayItem::orderRow();
+ $firstBoughtItem->setAmountExVat(1.00);
+ $firstBoughtItem->setVatPercent(25);
+ $firstBoughtItem->setQuantity(1);
+ $firstBoughtItem->setDescription("Yellow duck");
+ $firstBoughtItem->setArticleNumber("yel-duck-01");
+
+ // Add firstBoughtItem to order row
+ $myOrder->addOrderRow($firstBoughtItem);
+
+ // Add secondBoughtItem in a fluent fashion
+ $myOrder->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(2.50)
+ ->setVatPercent(12)
+ ->setQuantity(1)
+ ->setDescription("Blue duck")
+ );
+
+ // Add Swish as the payment method for the order
+ $mySwishOrderRequest = $myOrder->usePaymentMethod(PaymentMethod::SWISH);
+
+
+ // Then set any additional required request attributes as detailed below. (See Svea\PaymentMethodPayment and Svea\HostedPayment classes for details.)
+ $mySwishOrderRequest
+ ->setReturnUrl("http://localhost/" . getPath() . "/landingpage.php"); // The return url where we receive and process the finished request response
+
+ // Get a payment form object which you can use to send the payment request to Svea
+ $mySwishOrderRequest = $mySwishOrderRequest->getPaymentForm();
+
+ // Then send the form to Svea, and receive the response on the landingpage after the customer has completed the card checkout SveaCardPay
+ echo "";
+ print_r("press submit to send the swish payment request to Svea");
+ print_r($mySwishOrderRequest->completeHtmlFormWithSubmitButton);
+}
+catch (Exception $exception)
+{
+ echo $exception->getMessage();
+}
+/**
+ * get the path to this file, for use in specifying the returnurl etc.
+ */
+function getPath()
+{
+ $myURL = $_SERVER['SCRIPT_NAME'];
+ $myPath = explode('/', $myURL);
+ unset($myPath[count($myPath) - 1]);
+ $myPath = implode('/', $myPath);
+
+ return $myPath;
+}
+
+
diff --git a/src/AdminService/AddOrderRowsRequest.php b/src/AdminService/AddOrderRowsRequest.php
index 5474875f..4da9cde2 100644
--- a/src/AdminService/AddOrderRowsRequest.php
+++ b/src/AdminService/AddOrderRowsRequest.php
@@ -17,107 +17,107 @@
*/
class AddOrderRowsRequest extends AdminServiceRequest
{
- /**
- * @var AddOrderRowsBuilder $orderBuilder
- */
- public $orderBuilder;
-
- private $amount;
-
- /**
- * @param AddOrderRowsBuilder $addOrderRowsBuilder
- */
- public function __construct($addOrderRowsBuilder)
- {
- $this->action = "AddOrderRows";
- $this->orderBuilder = $addOrderRowsBuilder;
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @param bool $resendOrderWithFlippedPriceIncludingVat
- * @return AdminSoap\AddOrderRowsRequest
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
- {
- $this->validateRequest();
-
- $this->priceIncludingVat = $this->determineVatFlag($this->orderBuilder->orderRows, $resendOrderWithFlippedPriceIncludingVat);
- $orderRows = $this->getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($this->orderBuilder->orderRows, $this->priceIncludingVat);
-
- $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\AddOrderRowsRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- new SoapVar($orderRows, SOAP_ENC_OBJECT),
- AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
- $this->orderBuilder->orderId
- );
-
- return $soapRequest;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateOrderId($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
- $errors = $this->validateRowsToAdd($errors);
- $errors = $this->validateRowsHasPriceAndVatInformation($errors);
-
- return $errors;
- }
-
- private function validateOrderId($errors)
- {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required.");
- }
-
- return $errors;
- }
-
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required.");
- }
-
- return $errors;
- }
-
- private function validateRowsToAdd($errors)
- {
- if (isset($this->orderBuilder->orderRows) == FALSE) {
- $errors[] = array('missing value' => "orderRows is required.");
- }
-
- return $errors;
- }
-
- private function validateRowsHasPriceAndVatInformation($errors)
- {
- if (isset($this->orderBuilder->orderRows)) {
- foreach ($this->orderBuilder->orderRows as $orderRow) {
- if (!isset($orderRow->vatPercent) && (!isset($orderRow->amountIncVat) && !isset($orderRow->amountExVat))) {
- $errors[] = array('missing order row vat information' => "cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent.");
- }
- }
- }
-
- return $errors;
- }
+ /**
+ * @var AddOrderRowsBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+ private $amount;
+
+ /**
+ * @param AddOrderRowsBuilder $addOrderRowsBuilder
+ */
+ public function __construct($addOrderRowsBuilder)
+ {
+ $this->action = "AddOrderRows";
+ $this->orderBuilder = $addOrderRowsBuilder;
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @param bool $resendOrderWithFlippedPriceIncludingVat
+ * @return AdminSoap\AddOrderRowsRequest
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
+ {
+ $this->validateRequest();
+
+ $this->priceIncludingVat = $this->determineVatFlag($this->orderBuilder->orderRows, $resendOrderWithFlippedPriceIncludingVat);
+ $orderRows = $this->getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($this->orderBuilder->orderRows, $this->priceIncludingVat);
+
+ $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\AddOrderRowsRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ new SoapVar($orderRows, SOAP_ENC_OBJECT),
+ AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
+ $this->orderBuilder->orderId
+ );
+
+ return $soapRequest;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateOrderId($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+ $errors = $this->validateRowsToAdd($errors);
+ $errors = $this->validateRowsHasPriceAndVatInformation($errors);
+
+ return $errors;
+ }
+
+ private function validateOrderId($errors)
+ {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateRowsToAdd($errors)
+ {
+ if (isset($this->orderBuilder->orderRows) == FALSE) {
+ $errors[] = ['missing value' => "orderRows is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateRowsHasPriceAndVatInformation($errors)
+ {
+ if (isset($this->orderBuilder->orderRows)) {
+ foreach ($this->orderBuilder->orderRows as $orderRow) {
+ if (!isset($orderRow->vatPercent) && (!isset($orderRow->amountIncVat) && !isset($orderRow->amountExVat))) {
+ $errors[] = ['missing order row vat information' => "cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent."];
+ }
+ }
+ }
+
+ return $errors;
+ }
}
diff --git a/src/AdminService/AdminServiceRequest.php b/src/AdminService/AdminServiceRequest.php
index f0c3507f..f546626e 100644
--- a/src/AdminService/AdminServiceRequest.php
+++ b/src/AdminService/AdminServiceRequest.php
@@ -18,239 +18,239 @@
*/
abstract class AdminServiceRequest
{
- /**
- * @var string $action the AdminService soap action called by this class
- */
- protected $action;
+ /**
+ * @var string $action the AdminService soap action called by this class
+ */
+ protected $action;
- /**
- * @var string $countryCode
- */
- protected $countryCode;
+ /**
+ * @var string $countryCode
+ */
+ protected $countryCode;
- /**
- * @var boolean $priceIncludingVat
- */
- protected $priceIncludingVat;
+ /**
+ * @var boolean $priceIncludingVat
+ */
+ protected $priceIncludingVat;
- protected $resendOrderVat = NULL;
+ protected $resendOrderVat = NULL;
- public $logging = false;
+ public $logging = false;
- /**
- * the integration package Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE and ::PAYMENTPLAN_TYPE constants are all caps, whereas the admin service
- * enumeration used in the calls are CamelCase. This function converts the package constants so that they work with the admin service.
- * @param $orderTypeAsConst
- * @return string
- */
- public static function CamelCaseOrderType($orderTypeAsConst)
- {
- switch ($orderTypeAsConst) {
- case ConfigurationProvider::INVOICE_TYPE:
- return "Invoice";
- break;
- case ConfigurationProvider::PAYMENTPLAN_TYPE:
- return "PaymentPlan";
- break;
- case ConfigurationProvider::ACCOUNTCREDIT_TYPE:
- return "AccountCredit";
- break;
- default:
- return $orderTypeAsConst;
- }
- }
+ /**
+ * the integration package Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE and ::PAYMENTPLAN_TYPE constants are all caps, whereas the admin service
+ * enumeration used in the calls are CamelCase. This function converts the package constants so that they work with the admin service.
+ * @param $orderTypeAsConst
+ * @return string
+ */
+ public static function CamelCaseOrderType($orderTypeAsConst)
+ {
+ switch ($orderTypeAsConst) {
+ case ConfigurationProvider::INVOICE_TYPE:
+ return "Invoice";
+ break;
+ case ConfigurationProvider::PAYMENTPLAN_TYPE:
+ return "PaymentPlan";
+ break;
+ case ConfigurationProvider::ACCOUNTCREDIT_TYPE:
+ return "AccountCredit";
+ break;
+ default:
+ return $orderTypeAsConst;
+ }
+ }
- /**
- * Set up the soap client and perform the soap call, with the soap action and prepared request from the relevant subclass.
- * Returns the appropriate request response class, as determined by Svea\WebPay\Response\SveaResponse matching on request action.
- * @param bool $resendOrderWithFlippedPriceIncludingVat
- * @return mixed
- */
- public function doRequest($resendOrderWithFlippedPriceIncludingVat = false)
- {
- $requestObject = $this->prepareRequest($resendOrderWithFlippedPriceIncludingVat);
+ /**
+ * Set up the soap client and perform the soap call, with the soap action and prepared request from the relevant subclass.
+ * Returns the appropriate request response class, as determined by Svea\WebPay\Response\SveaResponse matching on request action.
+ * @param bool $resendOrderWithFlippedPriceIncludingVat
+ * @return mixed
+ */
+ public function doRequest($resendOrderWithFlippedPriceIncludingVat = false)
+ {
+ $requestObject = $this->prepareRequest($resendOrderWithFlippedPriceIncludingVat);
- $soapClient = new SoapClient($this->orderBuilder->conf, ConfigurationProvider::ADMIN_TYPE);
- if($this->orderBuilder->logging == true)
- {
- $timestampStart = time();
- $microtimeStart = microtime(true);
- }
- $soapResponse = $soapClient->doSoapCall($this->action, $requestObject);
- if($this->orderBuilder->logging == true)
- {
- $logs = array(
- "logs" => array(
- "request" => array(
- "timestamp" => $timestampStart,
- "headers" => $soapClient->getClient()->__getLastRequestHeaders(),
- "body" => htmlentities($soapClient->getClient()->__getLastRequest())
- ),
- "response" => array(
- "timestamp" => time(),
- "headers" => $soapClient->getClient()->__getLastResponseHeaders(),
- "body" => htmlentities($soapClient->getClient()->__getLastResponse()),
- "dataAmount" => strlen($soapClient->getClient()->__getLastResponseHeaders()) + strlen($soapClient->getClient()->__getLastResponse()),
- "duration" => round(microtime(true) - $microtimeStart, 3)
- )
- ));
- }
- $sveaResponse = new SveaResponse($soapResponse, null, null, $this->action, isset($logs['logs']) ? $logs['logs'] : NULL);
- $response = $sveaResponse->getResponse();
+ $soapClient = new SoapClient($this->orderBuilder->conf, ConfigurationProvider::ADMIN_TYPE);
+ if($this->orderBuilder->logging == true)
+ {
+ $timestampStart = time();
+ $microtimeStart = microtime(true);
+ }
+ $soapResponse = $soapClient->doSoapCall($this->action, $requestObject);
+ if($this->orderBuilder->logging == true)
+ {
+ $logs = [
+ "logs" => [
+ "request" => [
+ "timestamp" => $timestampStart,
+ "headers" => $soapClient->getClient()->__getLastRequestHeaders(),
+ "body" => htmlentities($soapClient->getClient()->__getLastRequest())
+ ],
+ "response" => [
+ "timestamp" => time(),
+ "headers" => $soapClient->getClient()->__getLastResponseHeaders(),
+ "body" => htmlentities($soapClient->getClient()->__getLastResponse()),
+ "dataAmount" => strlen($soapClient->getClient()->__getLastResponseHeaders()) + strlen($soapClient->getClient()->__getLastResponse()),
+ "duration" => round(microtime(true) - $microtimeStart, 3)
+ ]
+ ]];
+ }
+ $sveaResponse = new SveaResponse($soapResponse, null, null, $this->action, isset($logs['logs']) ? $logs['logs'] : NULL);
+ $response = $sveaResponse->getResponse();
- // iff error 50036, flip priceIncludingVat and resend enforcing flipped value
- if ($response->resultcode == "50036") {
- if (property_exists($requestObject, 'OrderRows')) {
- $priceIncludingVat = $requestObject->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value;
- } elseif (property_exists($requestObject, 'UpdatedOrderRows')) {
- $priceIncludingVat = $requestObject->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value;
- } else {
- $priceIncludingVat = $this->priceIncludingVat;
- }
- $this->priceIncludingVat = !$priceIncludingVat;
+ // iff error 50036, flip priceIncludingVat and resend enforcing flipped value
+ if ($response->resultcode == "50036") {
+ if (property_exists($requestObject, 'OrderRows')) {
+ $priceIncludingVat = $requestObject->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value;
+ } elseif (property_exists($requestObject, 'UpdatedOrderRows')) {
+ $priceIncludingVat = $requestObject->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value;
+ } else {
+ $priceIncludingVat = $this->priceIncludingVat;
+ }
+ $this->priceIncludingVat = !$priceIncludingVat;
- return $this->doRequest(true);
- } else {
- return $sveaResponse->getResponse();
- }
- }
+ return $this->doRequest(true);
+ } else {
+ return $sveaResponse->getResponse();
+ }
+ }
- abstract function prepareRequest(); // prepare the soap request data
+ abstract function prepareRequest(); // prepare the soap request data
- /**
- * Validates the orderBuilder object to make sure that all required settings
- * are present. If not, throws an exception. Actual validation is delegated
- * to subclass validate() implementations.
- *
- * @throws ValidationException
- */
- public function validateRequest()
- {
- // validate sub-class requirements by calling sub-class validate() method
- $errors = $this->validate();
+ /**
+ * Validates the orderBuilder object to make sure that all required settings
+ * are present. If not, throws an exception. Actual validation is delegated
+ * to subclass validate() implementations.
+ *
+ * @throws ValidationException
+ */
+ public function validateRequest()
+ {
+ // validate sub-class requirements by calling sub-class validate() method
+ $errors = $this->validate();
- if (count($errors) > 0) {
- $exceptionString = "";
- foreach ($errors as $error) {
- foreach ($error as $key => $value) {
- $exceptionString .= "-" . $key . " : " . $value . "\n";
- }
- }
+ if (count($errors) > 0) {
+ $exceptionString = "";
+ foreach ($errors as $error) {
+ foreach ($error as $key => $value) {
+ $exceptionString .= "-" . $key . " : " . $value . "\n";
+ }
+ }
- throw new ValidationException($exceptionString);
- }
- } // validate is defined by subclasses, should validate all elements required for call is present
+ throw new ValidationException($exceptionString);
+ }
+ } // validate is defined by subclasses, should validate all elements required for call is present
- abstract function validate();
+ abstract function validate();
- /**
- * @param $orderRows
- * @param bool $flipPriceIncludingVat
- * @return true iff all order rows are specified using amountIncVat, and the $flipPriceIncludingVat flag is omitted or false
- */
- protected function determineVatFlag($orderRows, $flipPriceIncludingVat = false)
- {
+ /**
+ * @param $orderRows
+ * @param bool $flipPriceIncludingVat
+ * @return true iff all order rows are specified using amountIncVat, and the $flipPriceIncludingVat flag is omitted or false
+ */
+ protected function determineVatFlag($orderRows, $flipPriceIncludingVat = false)
+ {
- $exVat = 0;
- $incVat = 0;
- foreach ($orderRows as $row) {
- if (isset($row->amountExVat) && isset($row->amountIncVat)) {
- $incVat++;
- } elseif (isset($row->amountExVat) && isset ($row->vatPercent)) {
- $exVat++;
- } else {
- $incVat++;
- }
- }
- //if at least one of the rows are set as exVat, set priceIncludingVat flag to false
- $priceIncludingVat = ($exVat >= 1) ? FALSE : TRUE;
+ $exVat = 0;
+ $incVat = 0;
+ foreach ($orderRows as $row) {
+ if (isset($row->amountExVat) && isset($row->amountIncVat)) {
+ $incVat++;
+ } elseif (isset($row->amountExVat) && isset ($row->vatPercent)) {
+ $exVat++;
+ } else {
+ $incVat++;
+ }
+ }
+ //if at least one of the rows are set as exVat, set priceIncludingVat flag to false
+ $priceIncludingVat = ($exVat >= 1) ? FALSE : TRUE;
- return $flipPriceIncludingVat ? !$priceIncludingVat : $priceIncludingVat;
- }
+ return $flipPriceIncludingVat ? !$priceIncludingVat : $priceIncludingVat;
+ }
- protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat)
- {
- $amount = 0;
- $orderRows = array();
- foreach ($builderOrderRows as $orderRow) {
- if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
- $amount = $priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent) : $orderRow->amountExVat;
- } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
- $amount = $priceIncludingVat ? $orderRow->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($orderRow->amountIncVat, $orderRow->vatPercent);
- } else {
- $amount = $priceIncludingVat ? $orderRow->amountIncVat : $orderRow->amountExVat;
- $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
- }
+ protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat)
+ {
+ $amount = 0;
+ $orderRows = [];
+ foreach ($builderOrderRows as $orderRow) {
+ if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
+ $amount = $priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent) : $orderRow->amountExVat;
+ } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
+ $amount = $priceIncludingVat ? $orderRow->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($orderRow->amountIncVat, $orderRow->vatPercent);
+ } else {
+ $amount = $priceIncludingVat ? $orderRow->amountIncVat : $orderRow->amountExVat;
+ $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
+ }
- $orderRows[] = new SoapVar(
- new OrderRow(
- $orderRow->articleNumber,
- $this->formatRowNameAndDescription($orderRow),
- !isset($orderRow->discountPercent) ? 0 : $orderRow->discountPercent,
- $orderRow->quantity,
- $amount,
- $orderRow->unit,
- $orderRow->vatPercent,
- $priceIncludingVat // attribute is set in correct (alphabetical) position via OrderRow constructor, see AdminSoap/OrderRow
- ), SOAP_ENC_OBJECT, null, null, 'OrderRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice"
- );
- }
+ $orderRows[] = new SoapVar(
+ new OrderRow(
+ $orderRow->articleNumber,
+ $this->formatRowNameAndDescription($orderRow),
+ !isset($orderRow->discountPercent) ? 0 : $orderRow->discountPercent,
+ $orderRow->quantity,
+ $amount,
+ $orderRow->unit,
+ $orderRow->vatPercent,
+ $priceIncludingVat // attribute is set in correct (alphabetical) position via OrderRow constructor, see AdminSoap/OrderRow
+ ), SOAP_ENC_OBJECT, null, null, 'OrderRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice"
+ );
+ }
- return $orderRows;
- }
+ return $orderRows;
+ }
- /**
- * wraps Svea\WebServiceRowFormatter->formatRowNameAndDescription to create a request description from order builder row name & description fields
- *
- * @param OrderRow|ShippingFee|et al . $webPayItemRow an instance of the order row classes from Svea\WebPay\WebPayItem
- * @return string the combined description string that should be written to Description
- */
- protected function formatRowNameAndDescription($webPayItemRow)
- {
- $wsrf = new WebServiceRowFormatter(null, null);
+ /**
+ * wraps Svea\WebServiceRowFormatter->formatRowNameAndDescription to create a request description from order builder row name & description fields
+ *
+ * @param OrderRow|ShippingFee|et al . $webPayItemRow an instance of the order row classes from Svea\WebPay\WebPayItem
+ * @return string the combined description string that should be written to Description
+ */
+ protected function formatRowNameAndDescription($webPayItemRow)
+ {
+ $wsrf = new WebServiceRowFormatter(null, null);
- return $wsrf->formatRowNameAndDescription($webPayItemRow);
- }
+ return $wsrf->formatRowNameAndDescription($webPayItemRow);
+ }
- protected function getAdminSoapNumberedOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat)
- {
- $amount = 0;
- $numberedOrderRows = array();
- foreach ($builderOrderRows as $orderRow) {
- if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
- $amount = $priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent) : $orderRow->amountExVat;
- } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
- $amount = $priceIncludingVat ? $orderRow->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($orderRow->amountIncVat, $orderRow->vatPercent);
- } else {
- $amount = $priceIncludingVat ? $orderRow->amountIncVat : $orderRow->amountExVat;
- $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
- }
+ protected function getAdminSoapNumberedOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat)
+ {
+ $amount = 0;
+ $numberedOrderRows = [];
+ foreach ($builderOrderRows as $orderRow) {
+ if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
+ $amount = $priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent) : $orderRow->amountExVat;
+ } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
+ $amount = $priceIncludingVat ? $orderRow->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($orderRow->amountIncVat, $orderRow->vatPercent);
+ } else {
+ $amount = $priceIncludingVat ? $orderRow->amountIncVat : $orderRow->amountExVat;
+ $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
+ }
- $numberedOrderRows[] = new SoapVar(
- new NumberedOrderRow(
- $orderRow->articleNumber,
- $this->formatRowNameAndDescription($orderRow),
- !isset($orderRow->discountPercent) ? 0 : $orderRow->discountPercent,
- $orderRow->quantity,
- $amount,
- $orderRow->unit,
- $orderRow->vatPercent,
- $orderRow->creditInvoiceId,
- $orderRow->invoiceId,
- $orderRow->rowNumber,
- $priceIncludingVat // attribute is set in correct (alphabetical) position via OrderRow constructor, see AdminSoap/OrderRow
- ),
- SOAP_ENC_OBJECT, null, null, 'NumberedOrderRow', "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service"
- );
- }
+ $numberedOrderRows[] = new SoapVar(
+ new NumberedOrderRow(
+ $orderRow->articleNumber,
+ $this->formatRowNameAndDescription($orderRow),
+ !isset($orderRow->discountPercent) ? 0 : $orderRow->discountPercent,
+ $orderRow->quantity,
+ $amount,
+ $orderRow->unit,
+ $orderRow->vatPercent,
+ $orderRow->creditInvoiceId,
+ $orderRow->invoiceId,
+ $orderRow->rowNumber,
+ $priceIncludingVat // attribute is set in correct (alphabetical) position via OrderRow constructor, see AdminSoap/OrderRow
+ ),
+ SOAP_ENC_OBJECT, null, null, 'NumberedOrderRow', "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service"
+ );
+ }
- return $numberedOrderRows;
- }
+ return $numberedOrderRows;
+ }
- public function enableLogging($logging)
- {
- $this->logging = $logging;
+ public function enableLogging($logging)
+ {
+ $this->logging = $logging;
- return $this;
- }
+ return $this;
+ }
}
diff --git a/src/AdminService/AdminServiceResponse/AddOrderRowsResponse.php b/src/AdminService/AdminServiceResponse/AddOrderRowsResponse.php
index 4121c70d..7677f3ea 100644
--- a/src/AdminService/AdminServiceResponse/AddOrderRowsResponse.php
+++ b/src/AdminService/AdminServiceResponse/AddOrderRowsResponse.php
@@ -9,27 +9,27 @@
*/
class AddOrderRowsResponse extends AdminServiceResponse
{
- /**
- * AddOrderRowsResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
+ /**
+ * AddOrderRowsResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
- /**
- * Parses response and sets attributes.
- * @param $message
- * @param $logs
- */
- protected function formatObject($message, $logs)
- {
- parent::formatObject($message, $logs);
+ /**
+ * Parses response and sets attributes.
+ * @param $message
+ * @param $logs
+ */
+ protected function formatObject($message, $logs)
+ {
+ parent::formatObject($message, $logs);
- if ($this->accepted == 1) {
- // nothing to do for cancelOrderRequest response
- }
- }
+ if ($this->accepted == 1) {
+ // nothing to do for cancelOrderRequest response
+ }
+ }
}
diff --git a/src/AdminService/AdminServiceResponse/AdminServiceResponse.php b/src/AdminService/AdminServiceResponse/AdminServiceResponse.php
index 48c11094..ef44a4d2 100644
--- a/src/AdminService/AdminServiceResponse/AdminServiceResponse.php
+++ b/src/AdminService/AdminServiceResponse/AdminServiceResponse.php
@@ -9,41 +9,41 @@
*/
class AdminServiceResponse
{
- /**
- * @var int $accepted true iff request was accepted by the service
- */
- public $accepted;
+ /**
+ * @var int $accepted true iff request was accepted by the service
+ */
+ public $accepted;
- /**
- * @var int $resultcode response specific result code
- */
- public $resultcode;
+ /**
+ * @var int $resultcode response specific result code
+ */
+ public $resultcode;
- /**
- * @var string errormessage may be set iff accepted above is false
- */
- public $errormessage;
+ /**
+ * @var string errormessage may be set iff accepted above is false
+ */
+ public $errormessage;
- /**
- * @var $logs
- */
- public $logs;
+ /**
+ * @var $logs
+ */
+ public $logs;
- /**
- * Parses response and sets basic attributes.
- * @param $message
- * @param $logs
- */
- protected function formatObject($message, $logs)
- {
- // was request accepted?
- $this->accepted = $message->ResultCode == 0 ? 1 : 0; // ResultCode of 0 means all went well.
- $this->errormessage = isset($message->ErrorMessage) ? $message->ErrorMessage : "";
- $this->resultcode = $message->ResultCode;
+ /**
+ * Parses response and sets basic attributes.
+ * @param $message
+ * @param $logs
+ */
+ protected function formatObject($message, $logs)
+ {
+ // was request accepted?
+ $this->accepted = $message->ResultCode == 0 ? 1 : 0; // ResultCode of 0 means all went well.
+ $this->errormessage = isset($message->ErrorMessage) ? $message->ErrorMessage : "";
+ $this->resultcode = $message->ResultCode;
- if(isset($logs))
- {
- $this->logs = $logs;
- }
- }
+ if(isset($logs))
+ {
+ $this->logs = $logs;
+ }
+ }
}
diff --git a/src/AdminService/AdminServiceResponse/CancelAccountCreditAmount.php b/src/AdminService/AdminServiceResponse/CancelAccountCreditAmount.php
index 1734231b..9648a4fe 100644
--- a/src/AdminService/AdminServiceResponse/CancelAccountCreditAmount.php
+++ b/src/AdminService/AdminServiceResponse/CancelAccountCreditAmount.php
@@ -9,13 +9,13 @@
*/
class CancelAccountCreditAmount extends AdminServiceResponse
{
- /**
- * CreditPaymentPlanResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
+ /**
+ * CreditPaymentPlanResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/AdminServiceResponse/CancelAccountCreditRows.php b/src/AdminService/AdminServiceResponse/CancelAccountCreditRows.php
index d93bc87c..b49c5824 100644
--- a/src/AdminService/AdminServiceResponse/CancelAccountCreditRows.php
+++ b/src/AdminService/AdminServiceResponse/CancelAccountCreditRows.php
@@ -9,13 +9,13 @@
*/
class CancelAccountCreditRows extends AdminServiceResponse
{
- /**
- * CreditPaymentPlanResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
+ /**
+ * CreditPaymentPlanResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/AdminServiceResponse/CancelOrderResponse.php b/src/AdminService/AdminServiceResponse/CancelOrderResponse.php
index 5879b659..fe6873e9 100644
--- a/src/AdminService/AdminServiceResponse/CancelOrderResponse.php
+++ b/src/AdminService/AdminServiceResponse/CancelOrderResponse.php
@@ -9,27 +9,27 @@
*/
class CancelOrderResponse extends AdminServiceResponse
{
- /**
- * CancelOrderResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
+ /**
+ * CancelOrderResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
- /**
- * Parses response and sets attributes.
- * @param $message
- * @param $logs
- */
- protected function formatObject($message, $logs)
- {
- parent::formatObject($message, $logs);
+ /**
+ * Parses response and sets attributes.
+ * @param $message
+ * @param $logs
+ */
+ protected function formatObject($message, $logs)
+ {
+ parent::formatObject($message, $logs);
- if ($this->accepted == 1) {
- // nothing to do for cancelOrderRequest response
- }
- }
+ if ($this->accepted == 1) {
+ // nothing to do for cancelOrderRequest response
+ }
+ }
}
diff --git a/src/AdminService/AdminServiceResponse/CancelOrderRowsResponse.php b/src/AdminService/AdminServiceResponse/CancelOrderRowsResponse.php
index 31991a58..52c501d6 100644
--- a/src/AdminService/AdminServiceResponse/CancelOrderRowsResponse.php
+++ b/src/AdminService/AdminServiceResponse/CancelOrderRowsResponse.php
@@ -9,27 +9,27 @@
*/
class CancelOrderRowsResponse extends AdminServiceResponse
{
- /**
- * CancelOrderRowsResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
+ /**
+ * CancelOrderRowsResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
- /**
- * Parses response and sets attributes.
- * @param $message
- * @param $logs
- */
- protected function formatObject($message, $logs)
- {
- parent::formatObject($message, $logs);
+ /**
+ * Parses response and sets attributes.
+ * @param $message
+ * @param $logs
+ */
+ protected function formatObject($message, $logs)
+ {
+ parent::formatObject($message, $logs);
- if ($this->accepted == 1) {
- // nothing to do for cancelOrderRequest response
- }
- }
+ if ($this->accepted == 1) {
+ // nothing to do for cancelOrderRequest response
+ }
+ }
}
diff --git a/src/AdminService/AdminServiceResponse/CreditInvoiceRowsResponse.php b/src/AdminService/AdminServiceResponse/CreditInvoiceRowsResponse.php
index e887bc06..7afa3af6 100644
--- a/src/AdminService/AdminServiceResponse/CreditInvoiceRowsResponse.php
+++ b/src/AdminService/AdminServiceResponse/CreditInvoiceRowsResponse.php
@@ -9,76 +9,76 @@
*/
class CreditInvoiceRowsResponse extends AdminServiceResponse
{
- /**
- * @var float $amount (set iff accepted) the amount credited with this request (a negative amount)
- */
- public $amount;
+ /**
+ * @var float $amount (set iff accepted) the amount credited with this request (a negative amount)
+ */
+ public $amount;
- /**
- * @var string $orderType (set iff accepted) one of [Invoice|PaymentPlan]
- */
- public $orderType;
+ /**
+ * @var string $orderType (set iff accepted) one of [Invoice|PaymentPlan]
+ */
+ public $orderType;
- /**
- * @var string $creditInvoiceId (set iff accepted, orderType Invoice) the $creditInvoiceId for the credit invoice issued with this request
- */
- public $creditInvoiceId;
+ /**
+ * @var string $creditInvoiceId (set iff accepted, orderType Invoice) the $creditInvoiceId for the credit invoice issued with this request
+ */
+ public $creditInvoiceId;
- /**
- * @var string $clientId (set iff accepted)
- */
- public $clientId;
+ /**
+ * @var string $clientId (set iff accepted)
+ */
+ public $clientId;
- /**
- * @var string $orderId (set iff accepted)
- */
- public $orderId;
+ /**
+ * @var string $orderId (set iff accepted)
+ */
+ public $orderId;
- /**
- * CreditInvoiceRowsResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
+ /**
+ * CreditInvoiceRowsResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
- /**
- * Parses response and sets attributes.
- * @param $message
- * @param $logs
- */
- protected function formatObject($message, $logs)
- {
- parent::formatObject($message, $logs);
+ /**
+ * Parses response and sets attributes.
+ * @param $message
+ * @param $logs
+ */
+ protected function formatObject($message, $logs)
+ {
+ parent::formatObject($message, $logs);
- if ($this->accepted == 1) {
- $this->amount = (-1) * $message->OrdersDelivered->DeliverOrderResult->DeliveredAmount;
- $this->orderType = $message->OrdersDelivered->DeliverOrderResult->OrderType;
- $this->creditInvoiceId = $message->OrdersDelivered->DeliverOrderResult->DeliveryReferenceNumber;
- $this->clientId = $message->OrdersDelivered->DeliverOrderResult->ClientId;
- $this->orderId = $message->OrdersDelivered->DeliverOrderResult->SveaOrderId;
- }
- }
+ if ($this->accepted == 1) {
+ $this->amount = (-1) * $message->OrdersDelivered->DeliverOrderResult->DeliveredAmount;
+ $this->orderType = $message->OrdersDelivered->DeliverOrderResult->OrderType;
+ $this->creditInvoiceId = $message->OrdersDelivered->DeliverOrderResult->DeliveryReferenceNumber;
+ $this->clientId = $message->OrdersDelivered->DeliverOrderResult->ClientId;
+ $this->orderId = $message->OrdersDelivered->DeliverOrderResult->SveaOrderId;
+ }
+ }
}
// raw response message example:
//
//stdClass Object
//(
-// [ErrorMessage] =>
-// [ResultCode] => 0
-// [OrdersDelivered] => stdClass Object
-// (
-// [DeliverOrderResult] => stdClass Object
-// (
-// [ClientId] => 79021
-// [DeliveredAmount] => 125.00
-// [DeliveryReferenceNumber] => 1027080
-// [OrderType] => Invoice
-// [SveaOrderId] => 352701
-// )
+// [ErrorMessage] =>
+// [ResultCode] => 0
+// [OrdersDelivered] => stdClass Object
+// (
+// [DeliverOrderResult] => stdClass Object
+// (
+// [ClientId] => 79021
+// [DeliveredAmount] => 125.00
+// [DeliveryReferenceNumber] => 1027080
+// [OrderType] => Invoice
+// [SveaOrderId] => 352701
+// )
//
-// )
+// )
//)
\ No newline at end of file
diff --git a/src/AdminService/AdminServiceResponse/CreditPaymentPlanResponse.php b/src/AdminService/AdminServiceResponse/CreditPaymentPlanResponse.php
index 1720d892..d1ee2915 100644
--- a/src/AdminService/AdminServiceResponse/CreditPaymentPlanResponse.php
+++ b/src/AdminService/AdminServiceResponse/CreditPaymentPlanResponse.php
@@ -9,21 +9,21 @@
*/
class CreditPaymentPlanResponse extends AdminServiceResponse
{
- /**
- * CreditPaymentPlanResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
+ /**
+ * CreditPaymentPlanResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
}
// raw response message example:
//
//stdClass Object
//(
-// [ErrorMessage] =>
-// [ResultCode] => 0
+// [ErrorMessage] =>
+// [ResultCode] => 0
//)
\ No newline at end of file
diff --git a/src/AdminService/AdminServiceResponse/DeliverOrdersResponse.php b/src/AdminService/AdminServiceResponse/DeliverOrdersResponse.php
index d86572b1..3d44e193 100644
--- a/src/AdminService/AdminServiceResponse/DeliverOrdersResponse.php
+++ b/src/AdminService/AdminServiceResponse/DeliverOrdersResponse.php
@@ -11,76 +11,76 @@
*/
class DeliverOrdersResponse extends AdminServiceResponse
{
- /**
- * @var string $clientId
- */
- public $clientId;
-
- /**
- * @var float $amount (set iff accepted) the amount delivered with this request
- */
- public $amount;
-
- /**
- * @var string $invoiceId (set iff accepted, orderType Invoice) the invoice id for the delivered order
- */
- public $invoiceId;
-
- /**
- * @var string $contractNumber (set iff accepted, orderType PaymentPlan) the contract number for the delivered order
- */
- public $contractNumber;
-
- /**
- * @var string $orderType
- */
- public $orderType;
-
- /**
- * @var string $orderId
- */
- public $orderId;
-
- /**
- * @var int $deliveryReferenceNumber - this is accountCredit specific, and its returned on order delivery
- */
- public $deliveryReferenceNumber;
-
- /**
- * DeliverOrdersResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
-
- protected function formatObject($message, $logs)
- {
- parent::formatObject($message, $logs);
-
- if ($this->accepted == 1) {
-
- $this->clientId = $message->OrdersDelivered->DeliverOrderResult->ClientId;
- $this->amount = $message->OrdersDelivered->DeliverOrderResult->DeliveredAmount;
-
- if ($message->OrdersDelivered->DeliverOrderResult->OrderType == ConfigurationProvider::INVOICE_TYPE) {
- $this->invoiceId = $message->OrdersDelivered->DeliverOrderResult->DeliveryReferenceNumber;
- }
-
- if ($message->OrdersDelivered->DeliverOrderResult->OrderType == ConfigurationProvider::PAYMENTPLAN_TYPE) {
- $this->contractNumber = $message->OrdersDelivered->DeliverOrderResult->DeliveryReferenceNumber;
- }
-
- // - specific for accountCredit
- if(property_exists($message->OrdersDelivered->DeliverOrderResult, "DeliveryReferenceNumber"))
- {
- $this->deliveryReferenceNumber = $message->OrdersDelivered->DeliverOrderResult->DeliveryReferenceNumber;
- }
-
- $this->orderType = $message->OrdersDelivered->DeliverOrderResult->OrderType;
- $this->orderId = $message->OrdersDelivered->DeliverOrderResult->SveaOrderId;
- }
- }
+ /**
+ * @var string $clientId
+ */
+ public $clientId;
+
+ /**
+ * @var float $amount (set iff accepted) the amount delivered with this request
+ */
+ public $amount;
+
+ /**
+ * @var string $invoiceId (set iff accepted, orderType Invoice) the invoice id for the delivered order
+ */
+ public $invoiceId;
+
+ /**
+ * @var string $contractNumber (set iff accepted, orderType PaymentPlan) the contract number for the delivered order
+ */
+ public $contractNumber;
+
+ /**
+ * @var string $orderType
+ */
+ public $orderType;
+
+ /**
+ * @var string $orderId
+ */
+ public $orderId;
+
+ /**
+ * @var int $deliveryReferenceNumber - this is accountCredit specific, and its returned on order delivery
+ */
+ public $deliveryReferenceNumber;
+
+ /**
+ * DeliverOrdersResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
+
+ protected function formatObject($message, $logs)
+ {
+ parent::formatObject($message, $logs);
+
+ if ($this->accepted == 1) {
+
+ $this->clientId = $message->OrdersDelivered->DeliverOrderResult->ClientId;
+ $this->amount = $message->OrdersDelivered->DeliverOrderResult->DeliveredAmount;
+
+ if ($message->OrdersDelivered->DeliverOrderResult->OrderType == ConfigurationProvider::INVOICE_TYPE) {
+ $this->invoiceId = $message->OrdersDelivered->DeliverOrderResult->DeliveryReferenceNumber;
+ }
+
+ if ($message->OrdersDelivered->DeliverOrderResult->OrderType == ConfigurationProvider::PAYMENTPLAN_TYPE) {
+ $this->contractNumber = $message->OrdersDelivered->DeliverOrderResult->DeliveryReferenceNumber;
+ }
+
+ // - specific for accountCredit
+ if(property_exists($message->OrdersDelivered->DeliverOrderResult, "DeliveryReferenceNumber"))
+ {
+ $this->deliveryReferenceNumber = $message->OrdersDelivered->DeliverOrderResult->DeliveryReferenceNumber;
+ }
+
+ $this->orderType = $message->OrdersDelivered->DeliverOrderResult->OrderType;
+ $this->orderId = $message->OrdersDelivered->DeliverOrderResult->SveaOrderId;
+ }
+ }
}
diff --git a/src/AdminService/AdminServiceResponse/DeliverPartialResponse.php b/src/AdminService/AdminServiceResponse/DeliverPartialResponse.php
index b54af47b..3f2b516d 100644
--- a/src/AdminService/AdminServiceResponse/DeliverPartialResponse.php
+++ b/src/AdminService/AdminServiceResponse/DeliverPartialResponse.php
@@ -10,5 +10,5 @@
*/
class DeliverPartialResponse extends DeliverOrdersResponse
{
-
+
}
diff --git a/src/AdminService/AdminServiceResponse/GetAccountCreditsResponse.php b/src/AdminService/AdminServiceResponse/GetAccountCreditsResponse.php
index bfef8bf4..2e25c356 100644
--- a/src/AdminService/AdminServiceResponse/GetAccountCreditsResponse.php
+++ b/src/AdminService/AdminServiceResponse/GetAccountCreditsResponse.php
@@ -14,216 +14,216 @@
*/
class GetAccountCreditsResponse
{
- /**
- * @var int $accepted true iff request was accepted by the service
- */
- public $accepted;
-
- /**
- * @var int $resultcode response specific result code
- */
- public $resultcode;
-
- /**
- * @var string errormessage may be set iff accepted above is false
- */
- public $errormessage;
-
- /**
- * @var array
- */
- public $accountCredits;
-
- /**
- * GetOrdersResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
-
- protected function formatObject($message, $logs)
- {
- $this->errormessage = isset($message->ErrorMessage) ? $message->ErrorMessage : "";
- $this->resultcode = $message->ResultCode;
-
- // if successful, set deliverOrderResult, using the same attributes as for DeliverOrderEU?
- if (property_exists($message, "AccountCredits")) {
-
- // @todo -this is for searching AccountCredit orders and for formatting response, it will be implemented in the future
- foreach($message->AccountCredits as $accountCredit)
- {
- // @todo - create AccountCredits class
-
- // @todo - create AccountCreditItem class
-
- // @todo - new class AccountCreditRows
- // @todo - new property NumberedOrderRow that contain list of OrderRows
- }
-
- // populate GetOrdersResponse select attributes from the raw GetOrders response
- $order = $message->Orders->Order;
-
- $this->changedDate = $order->ChangedDate;
- $this->clientId = $order->ClientId;
- $this->clientOrderId = $order->ClientOrderId;
- $this->createdDate = $order->CreatedDate;
-
- if(isset($order->CreditReportStatus->Accepted)) {
- $this->creditReportStatusAccepted = ($order->CreditReportStatus->Accepted === "true") ? true : false;
- $this->creditReportStatusCreationDate = $order->CreditReportStatus->CreationDate;
- }
-
- $this->currency = $order->Currency;
-
- //individual customer?
- if ($order->Customer->CustomerType === "Individual") {
-
- $this->customer = new IndividualCustomer;
-
- $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber);
- $this->customer->setInitials($order->Customer->IndividualIdentity->Initials);
- if (isset($order->Customer->IndividualIdentity->BirthDate) && $order->Customer->IndividualIdentity->BirthDate) { // setBirthDate is picky about the argument format
- $this->customer->setBirthDate($order->Customer->IndividualIdentity->BirthDate);
- }
- $this->customer->setName($order->Customer->IndividualIdentity->FirstName, $order->Customer->IndividualIdentity->LastName); // sets firstName, lastName if present
- $this->customer->setName($order->Customer->FullName); // sets compounded fullName if present
- $this->customer->setEmail($order->Customer->Email);
- $this->customer->setPhoneNumber($order->Customer->PhoneNumber);
- $this->customer->setStreetAddress($order->Customer->Street); // sets compounded streetAddress if present, as well as street
- $this->customer->setStreetAddress($order->Customer->Street, $order->Customer->HouseNumber); // sets Individual street, houseNumber if present
- $this->customer->setCoAddress($order->Customer->CoAddress);
- $this->customer->setZipCode($order->Customer->ZipCode);
- $this->customer->setLocality($order->Customer->Locality);
- }
-
- if ($order->Customer->CustomerType === "Company") {
-
- $this->customer = new CompanyCustomer;
-
- $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber);
- $this->customer->setVatNumber($order->Customer->CompanyIdentity->CompanyVatNumber);
- $this->customer->setCompanyName($order->Customer->FullName);
- $this->customer->setEmail($order->Customer->Email);
- $this->customer->setPhoneNumber($order->Customer->PhoneNumber);
- $this->customer->setStreetAddress($order->Customer->Street); // sets compounded streetAddress if present, as well as street
- $this->customer->setStreetAddress($order->Customer->Street, $order->Customer->HouseNumber);
- $this->customer->setCoAddress($order->Customer->CoAddress);
- $this->customer->setZipCode($order->Customer->ZipCode);
- $this->customer->setLocality($order->Customer->Locality);
- }
-
- $this->customerId = $order->CustomerId;
- $this->customerReference = $order->CustomerReference;
- //$this->deliveryAddress = $order->DeliveryAddress; // not supported
- $this->isPossibleToAdminister = ($order->IsPossibleToAdminister === "true") ? true : false;
- $this->isPossibleToCancel = ($order->IsPossibleToCancel === 'true') ? true : false;
- $this->notes = $order->Notes;
- $this->orderDeliveryStatus = $order->OrderDeliveryStatus;
-
- // a single order row is returned as type stdClass
- if (is_a($order->OrderRows->NumberedOrderRow, "stdClass")) {
- $row = $order->OrderRows->NumberedOrderRow;
- $newrow = new NumberedOrderRow(); // webpay orderrow
- $newrow
- //->setName()
-// ->setAmountExVat( $row->PricePerUnit )
- ->setDescription($row->Description)
- ->setQuantity($row->NumberOfUnits)
- ->setArticleNumber($row->ArticleNumber)
- ->setUnit($row->Unit)
- ->setVatPercent((int)$row->VatPercent)
- ->setDiscountPercent($row->DiscountPercent);
- if ($row->PriceIncludingVat === 'true') {
- $newrow->setAmountIncVat($row->PricePerUnit);
- } else {
- $newrow->setAmountExVat($row->PricePerUnit);
- }
-
-
- $newrow->creditInvoiceId = $row->CreditInvoiceId;
- $newrow->invoiceId = $row->InvoiceId;
- $newrow->rowNumber = $row->RowNumber;
- $newrow->status = $row->Status;
-
- $this->numberedOrderRows[] = $newrow;
- } // multiple order rows are returned as an array
- elseif (is_array($order->OrderRows->NumberedOrderRow)) {
- // for each numbered orderrow, add it to the numberedOrderRow array
- foreach ($order->OrderRows->NumberedOrderRow as $row) {
- //GetOrders NumberedOrderRow:
- // [ArticleNumber]
- // [Description]
- // [DiscountPercent]
- // [NumberOfUnits]
- // [PricePerUnit]
- // [Unit]
- // [VatPercent]
- // [CreditInvoiceId]
- // [InvoiceId]
- // [RowNumber]
- // [Status]
-
- $newrow = new NumberedOrderRow(); // webpay orderrow
- //Svea\WebPay\WebPayItem OrderRow:
- // $articleNumber *
- // $quantity *
- // $unit *
- // $amountExVat * depends on bool priceincludingvat
- // $amountIncVat * depends on bool priceincludingvat
- // $vatPercent *
- // $name not used
- // $description *
- // $discountPercent *
- // $vatDiscount not used
-
- $newrow
- //->setName()
-// ->setAmountExVat( $row->PricePerUnit )
- ->setDescription($row->Description)
- ->setQuantity($row->NumberOfUnits)
- ->setArticleNumber($row->ArticleNumber)
- ->setUnit($row->Unit)
- ->setVatPercent((int)$row->VatPercent)
- ->setDiscountPercent($row->DiscountPercent);
- if ($row->PriceIncludingVat === 'true') {
- $newrow->setAmountIncVat($row->PricePerUnit);
- } else {
- $newrow->setAmountExVat($row->PricePerUnit);
- }
-
- $newrow->creditInvoiceId = $row->CreditInvoiceId;
- $newrow->invoiceId = $row->InvoiceId;
- $newrow->rowNumber = $row->RowNumber;
- $newrow->status = $row->Status;
-
- $this->numberedOrderRows[] = $newrow;
- }
- }
-
- $this->orderStatus = $order->OrderStatus;
- $this->orderType = $order->OrderType;
-
- if (is_a($order->PaymentPlanDetails, "stdClass") && property_exists($order->PaymentPlanDetails, "ContractLengthMonths")) {
- $this->paymentPlanDetailsContractLengthMonths = $order->PaymentPlanDetails->ContractLengthMonths;
- }
- if (is_a($order->PaymentPlanDetails, "stdClass") && property_exists($order->PaymentPlanDetails, "ContractNumber")) {
- $this->paymentPlanDetailsContractNumber = $order->PaymentPlanDetails->ContractNumber;
- }
-
- $this->pendingReasons = $order->PendingReasons;
- if (is_a($order->PendingReasons, "stdClass") && property_exists($order->PendingReasons, "PendingType")) {
- $this->pendingReasonsPendingType = $order->PendingReasons->PendingType;
- }
- if (is_a($order->PendingReasons, "stdClass") && property_exists($order->PendingReasons, "CreatedDate")) {
- $this->PendingReasonsCreatedDate = $order->PendingReasons->CreatedDate;
- }
-
- $this->orderId = $order->SveaOrderId;
- $this->sveaWillBuy = ($order->SveaWillBuy === 'true') ? true : false;
-
- }
- }
+ /**
+ * @var int $accepted true iff request was accepted by the service
+ */
+ public $accepted;
+
+ /**
+ * @var int $resultcode response specific result code
+ */
+ public $resultcode;
+
+ /**
+ * @var string errormessage may be set iff accepted above is false
+ */
+ public $errormessage;
+
+ /**
+ * @var array
+ */
+ public $accountCredits;
+
+ /**
+ * GetOrdersResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
+
+ protected function formatObject($message, $logs)
+ {
+ $this->errormessage = isset($message->ErrorMessage) ? $message->ErrorMessage : "";
+ $this->resultcode = $message->ResultCode;
+
+ // if successful, set deliverOrderResult, using the same attributes as for DeliverOrderEU?
+ if (property_exists($message, "AccountCredits")) {
+
+ // @todo -this is for searching AccountCredit orders and for formatting response, it will be implemented in the future
+ foreach($message->AccountCredits as $accountCredit)
+ {
+ // @todo - create AccountCredits class
+
+ // @todo - create AccountCreditItem class
+
+ // @todo - new class AccountCreditRows
+ // @todo - new property NumberedOrderRow that contain list of OrderRows
+ }
+
+ // populate GetOrdersResponse select attributes from the raw GetOrders response
+ $order = $message->Orders->Order;
+
+ $this->changedDate = $order->ChangedDate;
+ $this->clientId = $order->ClientId;
+ $this->clientOrderId = $order->ClientOrderId;
+ $this->createdDate = $order->CreatedDate;
+
+ if(isset($order->CreditReportStatus->Accepted)) {
+ $this->creditReportStatusAccepted = ($order->CreditReportStatus->Accepted === "true") ? true : false;
+ $this->creditReportStatusCreationDate = $order->CreditReportStatus->CreationDate;
+ }
+
+ $this->currency = $order->Currency;
+
+ //individual customer?
+ if ($order->Customer->CustomerType === "Individual") {
+
+ $this->customer = new IndividualCustomer;
+
+ $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber);
+ $this->customer->setInitials($order->Customer->IndividualIdentity->Initials);
+ if (isset($order->Customer->IndividualIdentity->BirthDate) && $order->Customer->IndividualIdentity->BirthDate) { // setBirthDate is picky about the argument format
+ $this->customer->setBirthDate($order->Customer->IndividualIdentity->BirthDate);
+ }
+ $this->customer->setName($order->Customer->IndividualIdentity->FirstName, $order->Customer->IndividualIdentity->LastName); // sets firstName, lastName if present
+ $this->customer->setName($order->Customer->FullName); // sets compounded fullName if present
+ $this->customer->setEmail($order->Customer->Email);
+ $this->customer->setPhoneNumber($order->Customer->PhoneNumber);
+ $this->customer->setStreetAddress($order->Customer->Street); // sets compounded streetAddress if present, as well as street
+ $this->customer->setStreetAddress($order->Customer->Street, $order->Customer->HouseNumber); // sets Individual street, houseNumber if present
+ $this->customer->setCoAddress($order->Customer->CoAddress);
+ $this->customer->setZipCode($order->Customer->ZipCode);
+ $this->customer->setLocality($order->Customer->Locality);
+ }
+
+ if ($order->Customer->CustomerType === "Company") {
+
+ $this->customer = new CompanyCustomer;
+
+ $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber);
+ $this->customer->setVatNumber($order->Customer->CompanyIdentity->CompanyVatNumber);
+ $this->customer->setCompanyName($order->Customer->FullName);
+ $this->customer->setEmail($order->Customer->Email);
+ $this->customer->setPhoneNumber($order->Customer->PhoneNumber);
+ $this->customer->setStreetAddress($order->Customer->Street); // sets compounded streetAddress if present, as well as street
+ $this->customer->setStreetAddress($order->Customer->Street, $order->Customer->HouseNumber);
+ $this->customer->setCoAddress($order->Customer->CoAddress);
+ $this->customer->setZipCode($order->Customer->ZipCode);
+ $this->customer->setLocality($order->Customer->Locality);
+ }
+
+ $this->customerId = $order->CustomerId;
+ $this->customerReference = $order->CustomerReference;
+ //$this->deliveryAddress = $order->DeliveryAddress; // not supported
+ $this->isPossibleToAdminister = ($order->IsPossibleToAdminister === "true") ? true : false;
+ $this->isPossibleToCancel = ($order->IsPossibleToCancel === 'true') ? true : false;
+ $this->notes = $order->Notes;
+ $this->orderDeliveryStatus = $order->OrderDeliveryStatus;
+
+ // a single order row is returned as type stdClass
+ if (is_a($order->OrderRows->NumberedOrderRow, "stdClass")) {
+ $row = $order->OrderRows->NumberedOrderRow;
+ $newrow = new NumberedOrderRow(); // webpay orderrow
+ $newrow
+ //->setName()
+// ->setAmountExVat( $row->PricePerUnit )
+ ->setDescription($row->Description)
+ ->setQuantity($row->NumberOfUnits)
+ ->setArticleNumber($row->ArticleNumber)
+ ->setUnit($row->Unit)
+ ->setVatPercent((int)$row->VatPercent)
+ ->setDiscountPercent($row->DiscountPercent);
+ if ($row->PriceIncludingVat === 'true') {
+ $newrow->setAmountIncVat($row->PricePerUnit);
+ } else {
+ $newrow->setAmountExVat($row->PricePerUnit);
+ }
+
+
+ $newrow->creditInvoiceId = $row->CreditInvoiceId;
+ $newrow->invoiceId = $row->InvoiceId;
+ $newrow->rowNumber = $row->RowNumber;
+ $newrow->status = $row->Status;
+
+ $this->numberedOrderRows[] = $newrow;
+ } // multiple order rows are returned as an array
+ elseif (is_array($order->OrderRows->NumberedOrderRow)) {
+ // for each numbered orderrow, add it to the numberedOrderRow array
+ foreach ($order->OrderRows->NumberedOrderRow as $row) {
+ //GetOrders NumberedOrderRow:
+ // [ArticleNumber]
+ // [Description]
+ // [DiscountPercent]
+ // [NumberOfUnits]
+ // [PricePerUnit]
+ // [Unit]
+ // [VatPercent]
+ // [CreditInvoiceId]
+ // [InvoiceId]
+ // [RowNumber]
+ // [Status]
+
+ $newrow = new NumberedOrderRow(); // webpay orderrow
+ //Svea\WebPay\WebPayItem OrderRow:
+ // $articleNumber *
+ // $quantity *
+ // $unit *
+ // $amountExVat * depends on bool priceincludingvat
+ // $amountIncVat * depends on bool priceincludingvat
+ // $vatPercent *
+ // $name not used
+ // $description *
+ // $discountPercent *
+ // $vatDiscount not used
+
+ $newrow
+ //->setName()
+// ->setAmountExVat( $row->PricePerUnit )
+ ->setDescription($row->Description)
+ ->setQuantity($row->NumberOfUnits)
+ ->setArticleNumber($row->ArticleNumber)
+ ->setUnit($row->Unit)
+ ->setVatPercent((int)$row->VatPercent)
+ ->setDiscountPercent($row->DiscountPercent);
+ if ($row->PriceIncludingVat === 'true') {
+ $newrow->setAmountIncVat($row->PricePerUnit);
+ } else {
+ $newrow->setAmountExVat($row->PricePerUnit);
+ }
+
+ $newrow->creditInvoiceId = $row->CreditInvoiceId;
+ $newrow->invoiceId = $row->InvoiceId;
+ $newrow->rowNumber = $row->RowNumber;
+ $newrow->status = $row->Status;
+
+ $this->numberedOrderRows[] = $newrow;
+ }
+ }
+
+ $this->orderStatus = $order->OrderStatus;
+ $this->orderType = $order->OrderType;
+
+ if (is_a($order->PaymentPlanDetails, "stdClass") && property_exists($order->PaymentPlanDetails, "ContractLengthMonths")) {
+ $this->paymentPlanDetailsContractLengthMonths = $order->PaymentPlanDetails->ContractLengthMonths;
+ }
+ if (is_a($order->PaymentPlanDetails, "stdClass") && property_exists($order->PaymentPlanDetails, "ContractNumber")) {
+ $this->paymentPlanDetailsContractNumber = $order->PaymentPlanDetails->ContractNumber;
+ }
+
+ $this->pendingReasons = $order->PendingReasons;
+ if (is_a($order->PendingReasons, "stdClass") && property_exists($order->PendingReasons, "PendingType")) {
+ $this->pendingReasonsPendingType = $order->PendingReasons->PendingType;
+ }
+ if (is_a($order->PendingReasons, "stdClass") && property_exists($order->PendingReasons, "CreatedDate")) {
+ $this->PendingReasonsCreatedDate = $order->PendingReasons->CreatedDate;
+ }
+
+ $this->orderId = $order->SveaOrderId;
+ $this->sveaWillBuy = ($order->SveaWillBuy === 'true') ? true : false;
+
+ }
+ }
}
diff --git a/src/AdminService/AdminServiceResponse/GetOrdersResponse.php b/src/AdminService/AdminServiceResponse/GetOrdersResponse.php
index a7538b7d..8c733adf 100644
--- a/src/AdminService/AdminServiceResponse/GetOrdersResponse.php
+++ b/src/AdminService/AdminServiceResponse/GetOrdersResponse.php
@@ -14,519 +14,519 @@
*/
class GetOrdersResponse extends AdminServiceResponse
{
- // phpdoc attributes below takes its info from admin service api Order structure
- /**
- * @var string $changedDate -- Date when order status was changed, e.g when order was delivered.
- */
- public $changedDate;
-
- /**
- * @var string $clientId -- Id that identifies a client in sveawebpay system
- */
- public $clientId;
-
- /**
- * @var string $clientOrderId -- I.e. clientOrderNumber. Order number from client's ordersystem
- */
- public $clientOrderId;
-
- /**
- * @var string $createdDate -- Date when order was first created.
- */
- public $createdDate;
-
- /**
- * @var boolean $creditReportStatusAccepted -- Tells if credit decision is accepted or not
- */
- public $creditReportStatusAccepted;
-
- /**
- * @var string $creditReportStatusCreationDate -- Date of order credit decision.
- */
- public $creditReportStatusCreationDate;
-
- /**
- * @var string $currency -- Country currency
- */
- public $currency;
-
- /**
- * @var CompanyCustomer|IndividualCustomer $customer -- customer identity as associated with
- * the order by Svea, also Shipping address.
- */
- public $customer;
-
- /**
- * @var string $customerId -- Customer id that is created by SveaWebPay system.
- */
- public $customerId;
-
- /**
- * @var string $customerReference -- Customer Reference. (Gets printed on the invoice.)
- */
- public $customerReference;
-
- /**
- * @var boolean $isPossibleToAdminister
- */
- public $isPossibleToAdminister;
-
- /**
- * @var boolean $isPossibleToCancel -- Tells if order can be cancelled or not
- */
- public $isPossibleToCancel;
-
- /**
- * @var string $notes -- Text on order created by client
- */
- public $notes;
-
- /**
- * @var string $orderDeliveryStatus -- one of {Created,PartiallyDelivered,Delivered,Cancelled}
- */
- public $orderDeliveryStatus;
-
- /**
- * @var OrderRow[] $numberedOrderRows array of OrderRow objects,
- * note that invoice and payment plan order rows name attribute will be null
- */
- public $numberedOrderRows;
-
- /**
- * @var string $orderStatus -- one of {Created,Pending,Active,Denied,Error}
- */
- public $orderStatus;
-
- /**
- * @var string $orderType -- one of {Invoice,PaymentPlan}
- */
- public $orderType;
-
- /**
- * @var string $paymentPlanDetailsContractLengthMonths
- */
- public $paymentPlanDetailsContractLengthMonths;
-
- /**
- * @var string $paymentPlanDetailsContractContractNumber -- Contract number of a specific contract.
- */
- public $paymentPlanDetailsContractNumber;
-
- /**
- * @var string $pendingReasonsPendingType -- one of {SMSOnHighAmount,UseOfDeliveryAddress}
- */
- public $pendingReasonsPendingType;
-
- /**
- * @var string $pendingReasonsCreatedDate
- */
- public $pendingReasonsCreatedDate;
-
- /**
- * @var string $orderId -- Unique Id for the created order. Used for any further order webservice requests.
- */
- public $orderId;
-
- /**
- * @var boolean $sveaWillBuy -- Describes whether SveaWebPay will buy the order or just administrate it
- */
- public $sveaWillBuy;
-
- /**
- * GetOrdersResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
-
- protected function formatObject($message, $logs)
- {
-
- // was request accepted?
- parent::formatObject($message, $logs);
-
- // if successful, set deliverOrderResult, using the same attributes as for DeliverOrderEU?
- if ($this->accepted == 1) {
-
- // populate GetOrdersResponse select attributes from the raw GetOrders response
- $order = $message->Orders->Order;
-
- $this->changedDate = $order->ChangedDate;
- $this->clientId = $order->ClientId;
- $this->clientOrderId = $order->ClientOrderId;
- $this->createdDate = $order->CreatedDate;
-
- if(isset($order->CreditReportStatus->Accepted)) {
- $this->creditReportStatusAccepted = ($order->CreditReportStatus->Accepted === "true") ? true : false;
- $this->creditReportStatusCreationDate = $order->CreditReportStatus->CreationDate;
- }
-
- $this->currency = $order->Currency;
-
- //individual customer?
- if ($order->Customer->CustomerType === "Individual") {
-
- //stdClass Object
- //(
- // [ChangedDate] =>
- // [ClientId] => 79021
- // [ClientOrderId] => 449
- // [CreatedDate] => 2014-05-19T16:04:54.787
- // [CreditReportStatus] => stdClass Object
- // (
- // [Accepted] => true
- // [CreationDate] => 2014-05-19T16:04:54.893
- // )
- //
- // [Currency] => SEK
- // [Customer] => stdClass Object
- // (
- // [CoAddress] => c/o Eriksson, Erik
- // [CompanyIdentity] =>
- // [CountryCode] => SE
- // [CustomerType] => Individual
- // [Email] =>
- // [FullName] => Persson, Tess T
- // [HouseNumber] =>
- // [IndividualIdentity] => stdClass Object
- // (
- // [BirthDate] =>
- // [FirstName] =>
- // [Initials] =>
- // [LastName] =>
- // )
- //
- // [Locality] => Stan
- // [NationalIdNumber] => 194605092222
- // [PhoneNumber] =>
- // [PublicKey] =>
- // [Street] => Testgatan 1
- // [ZipCode] => 99999
- // )
- //
- // [CustomerId] => 1000117
- // [CustomerReference] =>
- // [DeliveryAddress] =>
- // [IsPossibleToAdminister] => false
- // [IsPossibleToCancel] => true
- // [Notes] =>
- // [OrderDeliveryStatus] => Created
- // [OrderRows] => stdClass Object
- // (
- // [NumberedOrderRow] => Array
- // (
- // [0] => stdClass Object
- // (
- // [ArticleNumber] =>
- // [Description] => Dyr produkt 25%
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 2.00
- // [PriceIncludingVat] => false
- // [PricePerUnit] => 2000.00
- // [Unit] =>
- // [VatPercent] => 25.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 1
- // [Status] => NotDelivered
- // )
- //
- // [1] => stdClass Object
- // (
- // [ArticleNumber] =>
- // [Description] => Testprodukt 1kr 25%
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 1.00
- // [PriceIncludingVat] => false
- // [PricePerUnit] => 1.00
- // [Unit] =>
- // [VatPercent] => 25.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 2
- // [Status] => NotDelivered
- // )
- //
- // [2] => stdClass Object
- // (
- // [ArticleNumber] =>
- // [Description] => Fastpris (Fast fraktpris)
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 1.00
- // [PriceIncludingVat] => false
- // [PricePerUnit] => 4.00
- // [Unit] =>
- // [VatPercent] => 25.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 3
- // [Status] => NotDelivered
- // )
- //
- // [3] => stdClass Object
- // (
- // [ArticleNumber] =>
- // [Description] => Svea Fakturaavgift:: 20.00kr (SE)
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 1.00
- // [PriceIncludingVat] => false
- // [PricePerUnit] => 20.00
- // [Unit] =>
- // [VatPercent] => 0.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 4
- // [Status] => NotDelivered
- // )
- //
- // )
- //
- // )
- //
- // [OrderStatus] => Active
- // [OrderType] => Invoice
- // [PaymentPlanDetails] =>
- // [PendingReasons] =>
- // [SveaOrderId] => 348629
- // [SveaWillBuy] => true
- //)
-
- $this->customer = new IndividualCustomer;
-
- $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber);
- $this->customer->setInitials($order->Customer->IndividualIdentity->Initials);
- if (isset($order->Customer->IndividualIdentity->BirthDate) && $order->Customer->IndividualIdentity->BirthDate) { // setBirthDate is picky about the argument format
- $this->customer->setBirthDate($order->Customer->IndividualIdentity->BirthDate);
- }
- $this->customer->setName($order->Customer->IndividualIdentity->FirstName, $order->Customer->IndividualIdentity->LastName); // sets firstName, lastName if present
- $this->customer->setName($order->Customer->FullName); // sets compounded fullName if present
- $this->customer->setEmail($order->Customer->Email);
- $this->customer->setPhoneNumber($order->Customer->PhoneNumber);
- $this->customer->setStreetAddress($order->Customer->Street); // sets compounded streetAddress if present, as well as street
- $this->customer->setStreetAddress($order->Customer->Street, $order->Customer->HouseNumber); // sets Individual street, houseNumber if present
- $this->customer->setCoAddress($order->Customer->CoAddress);
- $this->customer->setZipCode($order->Customer->ZipCode);
- $this->customer->setLocality($order->Customer->Locality);
- }
-
- if ($order->Customer->CustomerType === "Company") {
-
- //stdClass Object
- //(
- // [ChangedDate] =>
- // [ClientId] => 79021
- // [ClientOrderId] =>
- // [CreatedDate] => 2014-12-29T16:41:58.897
- // [CreditReportStatus] => stdClass Object
- // (
- // [Accepted] => true
- // [CreationDate] => 2014-12-29T16:41:58.96
- // )
- //
- // [Currency] => SEK
- // [Customer] => stdClass Object
- // (
- // [CoAddress] => c/o Eriksson, Erik
- // [CompanyIdentity] => stdClass Object
- // (
- // [CompanyIdentification] =>
- // [CompanyVatNumber] =>
- // )
- //
- // [CountryCode] => SE
- // [CustomerType] => Company
- // [Email] =>
- // [FullName] => Persson, Tess T
- // [HouseNumber] =>
- // [IndividualIdentity] =>
- // [Locality] => Stan
- // [NationalIdNumber] => 164608142222
- // [PhoneNumber] =>
- // [PublicKey] =>
- // [Street] => Testgatan 1
- // [ZipCode] => 99999
- // )
- //
- // [CustomerId] => 1000119
- // [CustomerReference] =>
- // [DeliveryAddress] =>
- // [IsPossibleToAdminister] => false
- // [IsPossibleToCancel] => true
- // [Notes] =>
- // [OrderDeliveryStatus] => Created
- // [OrderRows] => stdClass Object
- // (
- // [NumberedOrderRow] => Array
- // (
- // [0] => stdClass Object
- // (
- // [ArticleNumber] => 1
- // [Description] => Product: Specification
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 2.00
- // [PriceIncludingVat] => false
- // [PricePerUnit] => 100.00
- // [Unit] => st
- // [VatPercent] => 25.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 1
- // [Status] => NotDelivered
- // )
- //
- // [1] => stdClass Object
- // (
- // [ArticleNumber] => 1
- // [Description] => Product: Specification
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 2.00
- // [PriceIncludingVat] => false
- // [PricePerUnit] => 1000.00
- // [Unit] => st
- // [VatPercent] => 25.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 2
- // [Status] => NotDelivered
- // )
- //
- // )
- //
- // )
- //
- // [OrderStatus] => Active
- // [OrderType] => Invoice
- // [PaymentPlanDetails] =>
- // [PendingReasons] =>
- // [SveaOrderId] => 499329
- // [SveaWillBuy] => true
- //)
- $this->customer = new CompanyCustomer;
-
- $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber);
- $this->customer->setVatNumber($order->Customer->CompanyIdentity->CompanyVatNumber);
- $this->customer->setCompanyName($order->Customer->FullName);
- $this->customer->setEmail($order->Customer->Email);
- $this->customer->setPhoneNumber($order->Customer->PhoneNumber);
- $this->customer->setStreetAddress($order->Customer->Street); // sets compounded streetAddress if present, as well as street
- $this->customer->setStreetAddress($order->Customer->Street, $order->Customer->HouseNumber);
- $this->customer->setCoAddress($order->Customer->CoAddress);
- $this->customer->setZipCode($order->Customer->ZipCode);
- $this->customer->setLocality($order->Customer->Locality);
- }
-
- $this->customerId = $order->CustomerId;
- $this->customerReference = $order->CustomerReference;
- //$this->deliveryAddress = $order->DeliveryAddress; // not supported
- $this->isPossibleToAdminister = ($order->IsPossibleToAdminister === "true") ? true : false;
- $this->isPossibleToCancel = ($order->IsPossibleToCancel === 'true') ? true : false;
- $this->notes = $order->Notes;
- $this->orderDeliveryStatus = $order->OrderDeliveryStatus;
-
- // a single order row is returned as type stdClass
- if (is_a($order->OrderRows->NumberedOrderRow, "stdClass")) {
- $row = $order->OrderRows->NumberedOrderRow;
- $newrow = new NumberedOrderRow(); // webpay orderrow
- $newrow
- //->setName()
-// ->setAmountExVat( $row->PricePerUnit )
- ->setDescription($row->Description)
- ->setQuantity($row->NumberOfUnits)
- ->setArticleNumber($row->ArticleNumber)
- ->setUnit($row->Unit)
- ->setVatPercent((int)$row->VatPercent)
- ->setDiscountPercent($row->DiscountPercent);
- if ($row->PriceIncludingVat === 'true') {
- $newrow->setAmountIncVat($row->PricePerUnit);
- } else {
- $newrow->setAmountExVat($row->PricePerUnit);
- }
-
-
- $newrow->creditInvoiceId = $row->CreditInvoiceId;
- $newrow->invoiceId = $row->InvoiceId;
- $newrow->rowNumber = $row->RowNumber;
- $newrow->status = $row->Status;
-
- $this->numberedOrderRows[] = $newrow;
- } // multiple order rows are returned as an array
- elseif (is_array($order->OrderRows->NumberedOrderRow)) {
- // for each numbered orderrow, add it to the numberedOrderRow array
- foreach ($order->OrderRows->NumberedOrderRow as $row) {
- //GetOrders NumberedOrderRow:
- // [ArticleNumber]
- // [Description]
- // [DiscountPercent]
- // [NumberOfUnits]
- // [PricePerUnit]
- // [Unit]
- // [VatPercent]
- // [CreditInvoiceId]
- // [InvoiceId]
- // [RowNumber]
- // [Status]
-
- $newrow = new NumberedOrderRow(); // webpay orderrow
- //Svea\WebPay\WebPayItem OrderRow:
- // $articleNumber *
- // $quantity *
- // $unit *
- // $amountExVat * depends on bool priceincludingvat
- // $amountIncVat * depends on bool priceincludingvat
- // $vatPercent *
- // $name not used
- // $description *
- // $discountPercent *
- // $vatDiscount not used
-
- $newrow
- //->setName()
-// ->setAmountExVat( $row->PricePerUnit )
- ->setDescription($row->Description)
- ->setQuantity($row->NumberOfUnits)
- ->setArticleNumber($row->ArticleNumber)
- ->setUnit($row->Unit)
- ->setVatPercent((int)$row->VatPercent)
- ->setDiscountPercent($row->DiscountPercent);
- if ($row->PriceIncludingVat === 'true') {
- $newrow->setAmountIncVat($row->PricePerUnit);
- } else {
- $newrow->setAmountExVat($row->PricePerUnit);
- }
-
- $newrow->creditInvoiceId = $row->CreditInvoiceId;
- $newrow->invoiceId = $row->InvoiceId;
- $newrow->rowNumber = $row->RowNumber;
- $newrow->status = $row->Status;
-
- $this->numberedOrderRows[] = $newrow;
- }
- }
-
- $this->orderStatus = $order->OrderStatus;
- $this->orderType = $order->OrderType;
-
- if (is_a($order->PaymentPlanDetails, "stdClass") && property_exists($order->PaymentPlanDetails, "ContractLengthMonths")) {
- $this->paymentPlanDetailsContractLengthMonths = $order->PaymentPlanDetails->ContractLengthMonths;
- }
- if (is_a($order->PaymentPlanDetails, "stdClass") && property_exists($order->PaymentPlanDetails, "ContractNumber")) {
- $this->paymentPlanDetailsContractNumber = $order->PaymentPlanDetails->ContractNumber;
- }
-
- $this->pendingReasons = $order->PendingReasons;
- if (is_a($order->PendingReasons, "stdClass") && property_exists($order->PendingReasons, "PendingType")) {
- $this->pendingReasonsPendingType = $order->PendingReasons->PendingType;
- }
- if (is_a($order->PendingReasons, "stdClass") && property_exists($order->PendingReasons, "CreatedDate")) {
- $this->PendingReasonsCreatedDate = $order->PendingReasons->CreatedDate;
- }
-
- $this->orderId = $order->SveaOrderId;
- $this->sveaWillBuy = ($order->SveaWillBuy === 'true') ? true : false;
-
- }
- }
+ // phpdoc attributes below takes its info from admin service api Order structure
+ /**
+ * @var string $changedDate -- Date when order status was changed, e.g when order was delivered.
+ */
+ public $changedDate;
+
+ /**
+ * @var string $clientId -- Id that identifies a client in sveawebpay system
+ */
+ public $clientId;
+
+ /**
+ * @var string $clientOrderId -- I.e. clientOrderNumber. Order number from client's ordersystem
+ */
+ public $clientOrderId;
+
+ /**
+ * @var string $createdDate -- Date when order was first created.
+ */
+ public $createdDate;
+
+ /**
+ * @var boolean $creditReportStatusAccepted -- Tells if credit decision is accepted or not
+ */
+ public $creditReportStatusAccepted;
+
+ /**
+ * @var string $creditReportStatusCreationDate -- Date of order credit decision.
+ */
+ public $creditReportStatusCreationDate;
+
+ /**
+ * @var string $currency -- Country currency
+ */
+ public $currency;
+
+ /**
+ * @var CompanyCustomer|IndividualCustomer $customer -- customer identity as associated with
+ * the order by Svea, also Shipping address.
+ */
+ public $customer;
+
+ /**
+ * @var string $customerId -- Customer id that is created by SveaWebPay system.
+ */
+ public $customerId;
+
+ /**
+ * @var string $customerReference -- Customer Reference. (Gets printed on the invoice.)
+ */
+ public $customerReference;
+
+ /**
+ * @var boolean $isPossibleToAdminister
+ */
+ public $isPossibleToAdminister;
+
+ /**
+ * @var boolean $isPossibleToCancel -- Tells if order can be cancelled or not
+ */
+ public $isPossibleToCancel;
+
+ /**
+ * @var string $notes -- Text on order created by client
+ */
+ public $notes;
+
+ /**
+ * @var string $orderDeliveryStatus -- one of {Created,PartiallyDelivered,Delivered,Cancelled}
+ */
+ public $orderDeliveryStatus;
+
+ /**
+ * @var OrderRow[] $numberedOrderRows array of OrderRow objects,
+ * note that invoice and payment plan order rows name attribute will be null
+ */
+ public $numberedOrderRows;
+
+ /**
+ * @var string $orderStatus -- one of {Created,Pending,Active,Denied,Error}
+ */
+ public $orderStatus;
+
+ /**
+ * @var string $orderType -- one of {Invoice,PaymentPlan}
+ */
+ public $orderType;
+
+ /**
+ * @var string $paymentPlanDetailsContractLengthMonths
+ */
+ public $paymentPlanDetailsContractLengthMonths;
+
+ /**
+ * @var string $paymentPlanDetailsContractContractNumber -- Contract number of a specific contract.
+ */
+ public $paymentPlanDetailsContractNumber;
+
+ /**
+ * @var string $pendingReasonsPendingType -- one of {SMSOnHighAmount,UseOfDeliveryAddress}
+ */
+ public $pendingReasonsPendingType;
+
+ /**
+ * @var string $pendingReasonsCreatedDate
+ */
+ public $pendingReasonsCreatedDate;
+
+ /**
+ * @var string $orderId -- Unique Id for the created order. Used for any further order webservice requests.
+ */
+ public $orderId;
+
+ /**
+ * @var boolean $sveaWillBuy -- Describes whether SveaWebPay will buy the order or just administrate it
+ */
+ public $sveaWillBuy;
+
+ /**
+ * GetOrdersResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
+
+ protected function formatObject($message, $logs)
+ {
+
+ // was request accepted?
+ parent::formatObject($message, $logs);
+
+ // if successful, set deliverOrderResult, using the same attributes as for DeliverOrderEU?
+ if ($this->accepted == 1) {
+
+ // populate GetOrdersResponse select attributes from the raw GetOrders response
+ $order = $message->Orders->Order;
+
+ $this->changedDate = $order->ChangedDate;
+ $this->clientId = $order->ClientId;
+ $this->clientOrderId = $order->ClientOrderId;
+ $this->createdDate = $order->CreatedDate;
+
+ if(isset($order->CreditReportStatus->Accepted)) {
+ $this->creditReportStatusAccepted = ($order->CreditReportStatus->Accepted === "true") ? true : false;
+ $this->creditReportStatusCreationDate = $order->CreditReportStatus->CreationDate;
+ }
+
+ $this->currency = $order->Currency;
+
+ //individual customer?
+ if ($order->Customer->CustomerType === "Individual") {
+
+ //stdClass Object
+ //(
+ // [ChangedDate] =>
+ // [ClientId] => 79021
+ // [ClientOrderId] => 449
+ // [CreatedDate] => 2014-05-19T16:04:54.787
+ // [CreditReportStatus] => stdClass Object
+ // (
+ // [Accepted] => true
+ // [CreationDate] => 2014-05-19T16:04:54.893
+ // )
+ //
+ // [Currency] => SEK
+ // [Customer] => stdClass Object
+ // (
+ // [CoAddress] => c/o Eriksson, Erik
+ // [CompanyIdentity] =>
+ // [CountryCode] => SE
+ // [CustomerType] => Individual
+ // [Email] =>
+ // [FullName] => Persson, Tess T
+ // [HouseNumber] =>
+ // [IndividualIdentity] => stdClass Object
+ // (
+ // [BirthDate] =>
+ // [FirstName] =>
+ // [Initials] =>
+ // [LastName] =>
+ // )
+ //
+ // [Locality] => Stan
+ // [NationalIdNumber] => 194605092222
+ // [PhoneNumber] =>
+ // [PublicKey] =>
+ // [Street] => Testgatan 1
+ // [ZipCode] => 99999
+ // )
+ //
+ // [CustomerId] => 1000117
+ // [CustomerReference] =>
+ // [DeliveryAddress] =>
+ // [IsPossibleToAdminister] => false
+ // [IsPossibleToCancel] => true
+ // [Notes] =>
+ // [OrderDeliveryStatus] => Created
+ // [OrderRows] => stdClass Object
+ // (
+ // [NumberedOrderRow] => Array
+ // (
+ // [0] => stdClass Object
+ // (
+ // [ArticleNumber] =>
+ // [Description] => Dyr produkt 25%
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 2.00
+ // [PriceIncludingVat] => false
+ // [PricePerUnit] => 2000.00
+ // [Unit] =>
+ // [VatPercent] => 25.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 1
+ // [Status] => NotDelivered
+ // )
+ //
+ // [1] => stdClass Object
+ // (
+ // [ArticleNumber] =>
+ // [Description] => Testprodukt 1kr 25%
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 1.00
+ // [PriceIncludingVat] => false
+ // [PricePerUnit] => 1.00
+ // [Unit] =>
+ // [VatPercent] => 25.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 2
+ // [Status] => NotDelivered
+ // )
+ //
+ // [2] => stdClass Object
+ // (
+ // [ArticleNumber] =>
+ // [Description] => Fastpris (Fast fraktpris)
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 1.00
+ // [PriceIncludingVat] => false
+ // [PricePerUnit] => 4.00
+ // [Unit] =>
+ // [VatPercent] => 25.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 3
+ // [Status] => NotDelivered
+ // )
+ //
+ // [3] => stdClass Object
+ // (
+ // [ArticleNumber] =>
+ // [Description] => Svea Fakturaavgift:: 20.00kr (SE)
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 1.00
+ // [PriceIncludingVat] => false
+ // [PricePerUnit] => 20.00
+ // [Unit] =>
+ // [VatPercent] => 0.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 4
+ // [Status] => NotDelivered
+ // )
+ //
+ // )
+ //
+ // )
+ //
+ // [OrderStatus] => Active
+ // [OrderType] => Invoice
+ // [PaymentPlanDetails] =>
+ // [PendingReasons] =>
+ // [SveaOrderId] => 348629
+ // [SveaWillBuy] => true
+ //)
+
+ $this->customer = new IndividualCustomer;
+
+ $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber);
+ $this->customer->setInitials($order->Customer->IndividualIdentity->Initials);
+ if (isset($order->Customer->IndividualIdentity->BirthDate) && $order->Customer->IndividualIdentity->BirthDate) { // setBirthDate is picky about the argument format
+ $this->customer->setBirthDate($order->Customer->IndividualIdentity->BirthDate);
+ }
+ $this->customer->setName($order->Customer->IndividualIdentity->FirstName, $order->Customer->IndividualIdentity->LastName); // sets firstName, lastName if present
+ $this->customer->setName($order->Customer->FullName); // sets compounded fullName if present
+ $this->customer->setEmail($order->Customer->Email);
+ $this->customer->setPhoneNumber($order->Customer->PhoneNumber);
+ $this->customer->setStreetAddress($order->Customer->Street); // sets compounded streetAddress if present, as well as street
+ $this->customer->setStreetAddress($order->Customer->Street, $order->Customer->HouseNumber); // sets Individual street, houseNumber if present
+ $this->customer->setCoAddress($order->Customer->CoAddress);
+ $this->customer->setZipCode($order->Customer->ZipCode);
+ $this->customer->setLocality($order->Customer->Locality);
+ }
+
+ if ($order->Customer->CustomerType === "Company") {
+
+ //stdClass Object
+ //(
+ // [ChangedDate] =>
+ // [ClientId] => 79021
+ // [ClientOrderId] =>
+ // [CreatedDate] => 2014-12-29T16:41:58.897
+ // [CreditReportStatus] => stdClass Object
+ // (
+ // [Accepted] => true
+ // [CreationDate] => 2014-12-29T16:41:58.96
+ // )
+ //
+ // [Currency] => SEK
+ // [Customer] => stdClass Object
+ // (
+ // [CoAddress] => c/o Eriksson, Erik
+ // [CompanyIdentity] => stdClass Object
+ // (
+ // [CompanyIdentification] =>
+ // [CompanyVatNumber] =>
+ // )
+ //
+ // [CountryCode] => SE
+ // [CustomerType] => Company
+ // [Email] =>
+ // [FullName] => Persson, Tess T
+ // [HouseNumber] =>
+ // [IndividualIdentity] =>
+ // [Locality] => Stan
+ // [NationalIdNumber] => 164608142222
+ // [PhoneNumber] =>
+ // [PublicKey] =>
+ // [Street] => Testgatan 1
+ // [ZipCode] => 99999
+ // )
+ //
+ // [CustomerId] => 1000119
+ // [CustomerReference] =>
+ // [DeliveryAddress] =>
+ // [IsPossibleToAdminister] => false
+ // [IsPossibleToCancel] => true
+ // [Notes] =>
+ // [OrderDeliveryStatus] => Created
+ // [OrderRows] => stdClass Object
+ // (
+ // [NumberedOrderRow] => Array
+ // (
+ // [0] => stdClass Object
+ // (
+ // [ArticleNumber] => 1
+ // [Description] => Product: Specification
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 2.00
+ // [PriceIncludingVat] => false
+ // [PricePerUnit] => 100.00
+ // [Unit] => st
+ // [VatPercent] => 25.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 1
+ // [Status] => NotDelivered
+ // )
+ //
+ // [1] => stdClass Object
+ // (
+ // [ArticleNumber] => 1
+ // [Description] => Product: Specification
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 2.00
+ // [PriceIncludingVat] => false
+ // [PricePerUnit] => 1000.00
+ // [Unit] => st
+ // [VatPercent] => 25.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 2
+ // [Status] => NotDelivered
+ // )
+ //
+ // )
+ //
+ // )
+ //
+ // [OrderStatus] => Active
+ // [OrderType] => Invoice
+ // [PaymentPlanDetails] =>
+ // [PendingReasons] =>
+ // [SveaOrderId] => 499329
+ // [SveaWillBuy] => true
+ //)
+ $this->customer = new CompanyCustomer;
+
+ $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber);
+ $this->customer->setVatNumber($order->Customer->CompanyIdentity->CompanyVatNumber);
+ $this->customer->setCompanyName($order->Customer->FullName);
+ $this->customer->setEmail($order->Customer->Email);
+ $this->customer->setPhoneNumber($order->Customer->PhoneNumber);
+ $this->customer->setStreetAddress($order->Customer->Street); // sets compounded streetAddress if present, as well as street
+ $this->customer->setStreetAddress($order->Customer->Street, $order->Customer->HouseNumber);
+ $this->customer->setCoAddress($order->Customer->CoAddress);
+ $this->customer->setZipCode($order->Customer->ZipCode);
+ $this->customer->setLocality($order->Customer->Locality);
+ }
+
+ $this->customerId = $order->CustomerId;
+ $this->customerReference = $order->CustomerReference;
+ //$this->deliveryAddress = $order->DeliveryAddress; // not supported
+ $this->isPossibleToAdminister = ($order->IsPossibleToAdminister === "true") ? true : false;
+ $this->isPossibleToCancel = ($order->IsPossibleToCancel === 'true') ? true : false;
+ $this->notes = $order->Notes;
+ $this->orderDeliveryStatus = $order->OrderDeliveryStatus;
+
+ // a single order row is returned as type stdClass
+ if (is_a($order->OrderRows->NumberedOrderRow, "stdClass")) {
+ $row = $order->OrderRows->NumberedOrderRow;
+ $newrow = new NumberedOrderRow(); // webpay orderrow
+ $newrow
+ //->setName()
+// ->setAmountExVat( $row->PricePerUnit )
+ ->setDescription($row->Description)
+ ->setQuantity($row->NumberOfUnits)
+ ->setArticleNumber($row->ArticleNumber)
+ ->setUnit($row->Unit)
+ ->setVatPercent((int)$row->VatPercent)
+ ->setDiscountPercent($row->DiscountPercent);
+ if ($row->PriceIncludingVat === 'true') {
+ $newrow->setAmountIncVat($row->PricePerUnit);
+ } else {
+ $newrow->setAmountExVat($row->PricePerUnit);
+ }
+
+
+ $newrow->creditInvoiceId = $row->CreditInvoiceId;
+ $newrow->invoiceId = $row->InvoiceId;
+ $newrow->rowNumber = $row->RowNumber;
+ $newrow->status = $row->Status;
+
+ $this->numberedOrderRows[] = $newrow;
+ } // multiple order rows are returned as an array
+ elseif (is_array($order->OrderRows->NumberedOrderRow)) {
+ // for each numbered orderrow, add it to the numberedOrderRow array
+ foreach ($order->OrderRows->NumberedOrderRow as $row) {
+ //GetOrders NumberedOrderRow:
+ // [ArticleNumber]
+ // [Description]
+ // [DiscountPercent]
+ // [NumberOfUnits]
+ // [PricePerUnit]
+ // [Unit]
+ // [VatPercent]
+ // [CreditInvoiceId]
+ // [InvoiceId]
+ // [RowNumber]
+ // [Status]
+
+ $newrow = new NumberedOrderRow(); // webpay orderrow
+ //Svea\WebPay\WebPayItem OrderRow:
+ // $articleNumber *
+ // $quantity *
+ // $unit *
+ // $amountExVat * depends on bool priceincludingvat
+ // $amountIncVat * depends on bool priceincludingvat
+ // $vatPercent *
+ // $name not used
+ // $description *
+ // $discountPercent *
+ // $vatDiscount not used
+
+ $newrow
+ //->setName()
+// ->setAmountExVat( $row->PricePerUnit )
+ ->setDescription($row->Description)
+ ->setQuantity($row->NumberOfUnits)
+ ->setArticleNumber($row->ArticleNumber)
+ ->setUnit($row->Unit)
+ ->setVatPercent((int)$row->VatPercent)
+ ->setDiscountPercent($row->DiscountPercent);
+ if ($row->PriceIncludingVat === 'true') {
+ $newrow->setAmountIncVat($row->PricePerUnit);
+ } else {
+ $newrow->setAmountExVat($row->PricePerUnit);
+ }
+
+ $newrow->creditInvoiceId = $row->CreditInvoiceId;
+ $newrow->invoiceId = $row->InvoiceId;
+ $newrow->rowNumber = $row->RowNumber;
+ $newrow->status = $row->Status;
+
+ $this->numberedOrderRows[] = $newrow;
+ }
+ }
+
+ $this->orderStatus = $order->OrderStatus;
+ $this->orderType = $order->OrderType;
+
+ if (is_a($order->PaymentPlanDetails, "stdClass") && property_exists($order->PaymentPlanDetails, "ContractLengthMonths")) {
+ $this->paymentPlanDetailsContractLengthMonths = $order->PaymentPlanDetails->ContractLengthMonths;
+ }
+ if (is_a($order->PaymentPlanDetails, "stdClass") && property_exists($order->PaymentPlanDetails, "ContractNumber")) {
+ $this->paymentPlanDetailsContractNumber = $order->PaymentPlanDetails->ContractNumber;
+ }
+
+ $this->pendingReasons = $order->PendingReasons;
+ if (is_a($order->PendingReasons, "stdClass") && property_exists($order->PendingReasons, "PendingType")) {
+ $this->pendingReasonsPendingType = $order->PendingReasons->PendingType;
+ }
+ if (is_a($order->PendingReasons, "stdClass") && property_exists($order->PendingReasons, "CreatedDate")) {
+ $this->PendingReasonsCreatedDate = $order->PendingReasons->CreatedDate;
+ }
+
+ $this->orderId = $order->SveaOrderId;
+ $this->sveaWillBuy = ($order->SveaWillBuy === 'true') ? true : false;
+
+ }
+ }
}
diff --git a/src/AdminService/AdminServiceResponse/UpdateOrderResponse.php b/src/AdminService/AdminServiceResponse/UpdateOrderResponse.php
index 06c53b1e..7a0b6dd0 100644
--- a/src/AdminService/AdminServiceResponse/UpdateOrderResponse.php
+++ b/src/AdminService/AdminServiceResponse/UpdateOrderResponse.php
@@ -7,27 +7,27 @@
*/
class UpdateOrderResponse extends AdminServiceResponse
{
- /**
- * UpdateOrderResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
+ /**
+ * UpdateOrderResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
- /**
- * Parses response and sets attributes.
- * @param $message
- * @param $logs
- */
- protected function formatObject($message, $logs)
- {
- parent::formatObject($message, $logs);
+ /**
+ * Parses response and sets attributes.
+ * @param $message
+ * @param $logs
+ */
+ protected function formatObject($message, $logs)
+ {
+ parent::formatObject($message, $logs);
- if ($this->accepted == 1) {
- // nothing to do for updateOrderRequest response
- }
- }
+ if ($this->accepted == 1) {
+ // nothing to do for updateOrderRequest response
+ }
+ }
}
diff --git a/src/AdminService/AdminServiceResponse/UpdateOrderRowsResponse.php b/src/AdminService/AdminServiceResponse/UpdateOrderRowsResponse.php
index accf4a49..c52d5b2d 100644
--- a/src/AdminService/AdminServiceResponse/UpdateOrderRowsResponse.php
+++ b/src/AdminService/AdminServiceResponse/UpdateOrderRowsResponse.php
@@ -9,27 +9,27 @@
*/
class UpdateOrderRowsResponse extends AdminServiceResponse
{
- /**
- * UpdateOrderRowsResponse constructor.
- * @param $message
- * @param $logs
- */
- function __construct($message, $logs)
- {
- $this->formatObject($message, $logs);
- }
+ /**
+ * UpdateOrderRowsResponse constructor.
+ * @param $message
+ * @param $logs
+ */
+ function __construct($message, $logs)
+ {
+ $this->formatObject($message, $logs);
+ }
- /**
- * Parses response and sets attributes.
- * @param $message
- * @param $logs
- */
- protected function formatObject($message, $logs)
- {
- parent::formatObject($message, $logs);
+ /**
+ * Parses response and sets attributes.
+ * @param $message
+ * @param $logs
+ */
+ protected function formatObject($message, $logs)
+ {
+ parent::formatObject($message, $logs);
- if ($this->accepted == 1) {
- // nothing to do for updateOrderRequest response
- }
- }
+ if ($this->accepted == 1) {
+ // nothing to do for updateOrderRequest response
+ }
+ }
}
diff --git a/src/AdminService/AdminSoap/AccountCredit/AccountCreditInformation.php b/src/AdminService/AdminSoap/AccountCredit/AccountCreditInformation.php
index 9ca28b14..152d4cda 100644
--- a/src/AdminService/AdminSoap/AccountCredit/AccountCreditInformation.php
+++ b/src/AdminService/AdminSoap/AccountCredit/AccountCreditInformation.php
@@ -4,57 +4,57 @@
class AccountCreditInformation
{
- public $clientAccountCreditId;
- public $clientId;
-
- /**
- * AccountCreditInformation constructor.
- * @param $clientAccountCreditId
- * @param $clientId
- */
- public function __construct($clientAccountCreditId = null, $clientId = null)
- {
- $this->clientAccountCreditId = $clientAccountCreditId;
- $this->clientId = $clientId;
- }
-
- /**
- * @return mixed
- */
- public function getClientId()
- {
- return $this->clientId;
- }
-
- /**
- * @param mixed $clientId
- * @return $this
- */
- public function setClientId($clientId)
- {
- $this->clientId = $clientId;
-
- return $this;
- }
-
- /**
- * @return mixed
- */
- public function getClientAccountCreditId()
- {
- return $this->clientAccountCreditId;
- }
-
- /**
- * @param mixed $clientAccountCreditId
- * @return $this
- */
- public function setClientAccountCreditId($clientAccountCreditId)
- {
- $this->clientAccountCreditId = $clientAccountCreditId;
-
- return $this;
- }
+ public $clientAccountCreditId;
+ public $clientId;
+
+ /**
+ * AccountCreditInformation constructor.
+ * @param $clientAccountCreditId
+ * @param $clientId
+ */
+ public function __construct($clientAccountCreditId = null, $clientId = null)
+ {
+ $this->clientAccountCreditId = $clientAccountCreditId;
+ $this->clientId = $clientId;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getClientId()
+ {
+ return $this->clientId;
+ }
+
+ /**
+ * @param mixed $clientId
+ * @return $this
+ */
+ public function setClientId($clientId)
+ {
+ $this->clientId = $clientId;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getClientAccountCreditId()
+ {
+ return $this->clientAccountCreditId;
+ }
+
+ /**
+ * @param mixed $clientAccountCreditId
+ * @return $this
+ */
+ public function setClientAccountCreditId($clientAccountCreditId)
+ {
+ $this->clientAccountCreditId = $clientAccountCreditId;
+
+ return $this;
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/AdminSoap/AddOrderRowsRequest.php b/src/AdminService/AdminSoap/AddOrderRowsRequest.php
index 3b533b50..ade3f803 100644
--- a/src/AdminService/AdminSoap/AddOrderRowsRequest.php
+++ b/src/AdminService/AdminSoap/AddOrderRowsRequest.php
@@ -9,33 +9,33 @@
*/
class AddOrderRowsRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $ClientId;
- public $OrderRows;
- public $OrderType;
- public $SveaOrderId;
+ public $Authentication; // note that the order of the attributes matter!
+ public $ClientId;
+ public $OrderRows;
+ public $OrderType;
+ public $SveaOrderId;
- /**
- * AdminService AddOrderRowsRequest
- * @param Authentication $authentication
- * @param string $clientId
- * @param OrderRow $orderRows
- * @param string $orderType
- * @param string $sveaOrderId
- */
- function __construct($authentication, $clientId, $orderRows, $orderType, $sveaOrderId)
- {
+ /**
+ * AdminService AddOrderRowsRequest
+ * @param Authentication $authentication
+ * @param string $clientId
+ * @param OrderRow $orderRows
+ * @param string $orderType
+ * @param string $sveaOrderId
+ */
+ function __construct($authentication, $clientId, $orderRows, $orderType, $sveaOrderId)
+ {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrderRows = new SoapVar($orderRows, SOAP_ENC_OBJECT,
- "-", "--", "OrderRows", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrderType = new SoapVar($orderType, XSD_STRING,
- "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
- "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrderRows = new SoapVar($orderRows, SOAP_ENC_OBJECT,
+ "-", "--", "OrderRows", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrderType = new SoapVar($orderType, XSD_STRING,
+ "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
+ "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/AdminSoap/Authentication.php b/src/AdminService/AdminSoap/Authentication.php
index 9459b2f6..b8aa9dc1 100644
--- a/src/AdminService/AdminSoap/Authentication.php
+++ b/src/AdminService/AdminSoap/Authentication.php
@@ -4,17 +4,17 @@
class Authentication
{
- public $Password;
- public $Username;
+ public $Password;
+ public $Username;
- /**
- * AdminService request Authentication
- * @param string $username
- * @param string $password
- */
- function __construct($username, $password)
- {
- $this->Password = new \SoapVar( $password, XSD_STRING,"-","--","Password","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->Username = new \SoapVar( $username, XSD_STRING,"-","--","Username","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService request Authentication
+ * @param string $username
+ * @param string $password
+ */
+ function __construct($username, $password)
+ {
+ $this->Password = new \SoapVar( $password, XSD_STRING,"-","--","Password","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->Username = new \SoapVar( $username, XSD_STRING,"-","--","Username","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/CancelAccountCreditAmountRequest.php b/src/AdminService/AdminSoap/CancelAccountCreditAmountRequest.php
index 17b5815c..63826c1b 100644
--- a/src/AdminService/AdminSoap/CancelAccountCreditAmountRequest.php
+++ b/src/AdminService/AdminSoap/CancelAccountCreditAmountRequest.php
@@ -6,35 +6,35 @@
class CancelAccountCreditAmountRequest
{
- public $Authentication;
- public $AmountIncVat; // note that the order of the attributes matter!
- public $ClientAccountCreditId; // order id
- public $ClientId;
- public $Description;
+ public $Authentication;
+ public $AmountIncVat; // note that the order of the attributes matter!
+ public $ClientAccountCreditId; // order id
+ public $ClientId;
+ public $Description;
- /**
- * AdminService CreditInvoiceRowsRequest
- *
- * @param Authentication $authentication
- * @param AmountIncVat $amountInclVat
- * @param string $description
- * @param string $clientId
- * @param string $orderId
- */
- function __construct($authentication, $amountIncVat, $description, $clientId, $orderId)
- {
- $regular = 'http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service';
- $request = 'http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Requests';
+ /**
+ * AdminService CreditInvoiceRowsRequest
+ *
+ * @param Authentication $authentication
+ * @param AmountIncVat $amountInclVat
+ * @param string $description
+ * @param string $clientId
+ * @param string $orderId
+ */
+ function __construct($authentication, $amountIncVat, $description, $clientId, $orderId)
+ {
+ $regular = 'http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service';
+ $request = 'http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Requests';
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", $regular);
- $this->AmountIncVat = new SoapVar($amountIncVat, XSD_DECIMAL,
- "-", "--", "AmountInclVat", $request);
- $this->ClientAccountCreditId = new SoapVar($orderId, XSD_LONG,
- "-", "--", "ClientAccountCreditId", $request);
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", $request);
- $this->Description = new SoapVar($description, XSD_STRING,
- "-", "--", "Description", $request);
- }
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", $regular);
+ $this->AmountIncVat = new SoapVar($amountIncVat, XSD_DECIMAL,
+ "-", "--", "AmountInclVat", $request);
+ $this->ClientAccountCreditId = new SoapVar($orderId, XSD_LONG,
+ "-", "--", "ClientAccountCreditId", $request);
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", $request);
+ $this->Description = new SoapVar($description, XSD_STRING,
+ "-", "--", "Description", $request);
+ }
}
diff --git a/src/AdminService/AdminSoap/CancelAccountCreditRowsRequest.php b/src/AdminService/AdminSoap/CancelAccountCreditRowsRequest.php
index 61912d8c..8aa6a410 100644
--- a/src/AdminService/AdminSoap/CancelAccountCreditRowsRequest.php
+++ b/src/AdminService/AdminSoap/CancelAccountCreditRowsRequest.php
@@ -6,35 +6,35 @@
class CancelAccountCreditRowsRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $CancellationRows;
- public $ClientAccountCreditId;
- public $ClientId;
+ public $Authentication; // note that the order of the attributes matter!
+ public $CancellationRows;
+ public $ClientAccountCreditId;
+ public $ClientId;
- /**
- * AdminService CreditInvoiceRowsRequest
- *
- * @param Authentication $authentication
- * @param CancellationRows $newCancellationRows
- * @param string $clientId
- * @param ClientAccountCreditId $contractNumber
- */
- function __construct($authentication, $newCancellationRows, $clientId, $orderId)
- {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- if (count($newCancellationRows) > 0) {
- $this->CancellationRows = new SoapVar($newCancellationRows, SOAP_ENC_OBJECT,
- "-", "--", "NewCancellationRows", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Requests");
- } else {
- unset($this->NewCancellationRows);
- }
+ /**
+ * AdminService CreditInvoiceRowsRequest
+ *
+ * @param Authentication $authentication
+ * @param CancellationRows $newCancellationRows
+ * @param string $clientId
+ * @param ClientAccountCreditId $contractNumber
+ */
+ function __construct($authentication, $newCancellationRows, $clientId, $orderId)
+ {
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ if (count($newCancellationRows) > 0) {
+ $this->CancellationRows = new SoapVar($newCancellationRows, SOAP_ENC_OBJECT,
+ "-", "--", "NewCancellationRows", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Requests");
+ } else {
+ unset($this->NewCancellationRows);
+ }
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Requests");
- $this->ClientAccountCreditId = new SoapVar($orderId, XSD_LONG,
- "-", "--", "ClientAccountCreditId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Requests");
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Requests");
+ $this->ClientAccountCreditId = new SoapVar($orderId, XSD_LONG,
+ "-", "--", "ClientAccountCreditId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Requests");
- }
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/AdminSoap/CancelOrderRequest.php b/src/AdminService/AdminSoap/CancelOrderRequest.php
index 98fba875..6dcad382 100644
--- a/src/AdminService/AdminSoap/CancelOrderRequest.php
+++ b/src/AdminService/AdminSoap/CancelOrderRequest.php
@@ -6,28 +6,28 @@
class CancelOrderRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $ClientId;
- public $OrderType;
- public $SveaOrderId;
+ public $Authentication; // note that the order of the attributes matter!
+ public $ClientId;
+ public $OrderType;
+ public $SveaOrderId;
- /**
- * AdminService CloseOrderRequest
- * @param Authentication $authentication
- * @param long $sveaOrderId
- * @param string $orderType -- one of [Invoice|PaymentPlan]
- * @param long $clientId
- */
- function __construct($authentication, $sveaOrderId, $orderType, $clientId)
- {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrderType = new SoapVar($orderType, XSD_STRING,
- "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
- "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService CloseOrderRequest
+ * @param Authentication $authentication
+ * @param long $sveaOrderId
+ * @param string $orderType -- one of [Invoice|PaymentPlan]
+ * @param long $clientId
+ */
+ function __construct($authentication, $sveaOrderId, $orderType, $clientId)
+ {
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrderType = new SoapVar($orderType, XSD_STRING,
+ "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
+ "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/CancelOrderRowsRequest.php b/src/AdminService/AdminSoap/CancelOrderRowsRequest.php
index 2e024146..8bcce44a 100644
--- a/src/AdminService/AdminSoap/CancelOrderRowsRequest.php
+++ b/src/AdminService/AdminSoap/CancelOrderRowsRequest.php
@@ -6,33 +6,33 @@
class CancelOrderRowsRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $ClientId;
- public $OrderRowNumbers;
- public $OrderType;
- public $SveaOrderId;
+ public $Authentication; // note that the order of the attributes matter!
+ public $ClientId;
+ public $OrderRowNumbers;
+ public $OrderType;
+ public $SveaOrderId;
- /**
- * AdminService CancelOrderRowsRequest
- * @param Authentication $authentication
- * @param $clientId
- * @param $orderRowNumbers
- * @param $orderType
- * @param $sveaOrderId
- */
- function __construct($authentication, $clientId, $orderRowNumbers, $orderType, $sveaOrderId)
- {
+ /**
+ * AdminService CancelOrderRowsRequest
+ * @param Authentication $authentication
+ * @param $clientId
+ * @param $orderRowNumbers
+ * @param $orderType
+ * @param $sveaOrderId
+ */
+ function __construct($authentication, $clientId, $orderRowNumbers, $orderType, $sveaOrderId)
+ {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrderRowNumbers = new SoapVar($orderRowNumbers, SOAP_ENC_OBJECT,
- "-", "--", "OrderRowNumbers", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrderType = new SoapVar($orderType, XSD_STRING,
- "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
- "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrderRowNumbers = new SoapVar($orderRowNumbers, SOAP_ENC_OBJECT,
+ "-", "--", "OrderRowNumbers", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrderType = new SoapVar($orderType, XSD_STRING,
+ "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
+ "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/AdminSoap/CancelPaymentPlanAmountRequest.php b/src/AdminService/AdminSoap/CancelPaymentPlanAmountRequest.php
index c8533fed..bb16208e 100644
--- a/src/AdminService/AdminSoap/CancelPaymentPlanAmountRequest.php
+++ b/src/AdminService/AdminSoap/CancelPaymentPlanAmountRequest.php
@@ -6,32 +6,32 @@
class CancelPaymentPlanAmountRequest
{
- public $Authentication;
- public $AmountInclVat; // note that the order of the attributes matter!
- public $ClientId;
- public $ContractNumber;
- public $Description;
+ public $Authentication;
+ public $AmountInclVat; // note that the order of the attributes matter!
+ public $ClientId;
+ public $ContractNumber;
+ public $Description;
- /**
- * AdminService CreditInvoiceRowsRequest
- *
- * @param Authentication $authentication
- * @param AmountIncVat $amountInclVat
- * @param string $description
- * @param string $clientId
- * @param ContractNumber $contractNumber
- */
- function __construct($authentication, $amountInclVat, $description, $clientId, $contractNumber)
- {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->AmountInclVat = new SoapVar($amountInclVat, XSD_DECIMAL,
- "-", "--", "AmountInclVat", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->ContractNumber = new SoapVar($contractNumber, XSD_LONG,
- "-", "--", "ContractNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->Description = new SoapVar($description, XSD_STRING,
- "-", "--", "Description", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService CreditInvoiceRowsRequest
+ *
+ * @param Authentication $authentication
+ * @param AmountIncVat $amountInclVat
+ * @param string $description
+ * @param string $clientId
+ * @param ContractNumber $contractNumber
+ */
+ function __construct($authentication, $amountInclVat, $description, $clientId, $contractNumber)
+ {
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->AmountInclVat = new SoapVar($amountInclVat, XSD_DECIMAL,
+ "-", "--", "AmountInclVat", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->ContractNumber = new SoapVar($contractNumber, XSD_LONG,
+ "-", "--", "ContractNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->Description = new SoapVar($description, XSD_STRING,
+ "-", "--", "Description", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/CancelPaymentPlanRowsRequest.php b/src/AdminService/AdminSoap/CancelPaymentPlanRowsRequest.php
index eacd6067..36772a1c 100644
--- a/src/AdminService/AdminSoap/CancelPaymentPlanRowsRequest.php
+++ b/src/AdminService/AdminSoap/CancelPaymentPlanRowsRequest.php
@@ -6,35 +6,35 @@
class CancelPaymentPlanRowsRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $CancellationRows;
- public $ClientId;
- public $ContractNumber;
+ public $Authentication; // note that the order of the attributes matter!
+ public $CancellationRows;
+ public $ClientId;
+ public $ContractNumber;
- /**
- * AdminService CreditInvoiceRowsRequest
- *
- * @param Authentication $authentication
- * @param CancellationRows $newCancellationRows
- * @param string $clientId
- * @param ContractNumber $contractNumber
- */
- function __construct($authentication, $newCancellationRows, $clientId, $contractNumber)
- {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- if (count($newCancellationRows) > 0) {
- $this->CancellationRows = new SoapVar($newCancellationRows, SOAP_ENC_OBJECT,
- "-", "--", "NewCancellationRows", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- } else {
- unset($this->NewCancellationRows);
- }
+ /**
+ * AdminService CreditInvoiceRowsRequest
+ *
+ * @param Authentication $authentication
+ * @param CancellationRows $newCancellationRows
+ * @param string $clientId
+ * @param ContractNumber $contractNumber
+ */
+ function __construct($authentication, $newCancellationRows, $clientId, $contractNumber)
+ {
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ if (count($newCancellationRows) > 0) {
+ $this->CancellationRows = new SoapVar($newCancellationRows, SOAP_ENC_OBJECT,
+ "-", "--", "NewCancellationRows", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ } else {
+ unset($this->NewCancellationRows);
+ }
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->ContractNumber = new SoapVar($contractNumber, XSD_LONG,
- "-", "--", "ContractNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->ContractNumber = new SoapVar($contractNumber, XSD_LONG,
+ "-", "--", "ContractNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ }
}
diff --git a/src/AdminService/AdminSoap/CancellationAccountCreditRow.php b/src/AdminService/AdminSoap/CancellationAccountCreditRow.php
index ad11a3d4..6021aee9 100644
--- a/src/AdminService/AdminSoap/CancellationAccountCreditRow.php
+++ b/src/AdminService/AdminSoap/CancellationAccountCreditRow.php
@@ -6,32 +6,32 @@
class CancellationAccountCreditRow
{
- public $AmountInclVat;
- public $Description;
- public $RowNumber;
- public $VatPercent;
+ public $AmountInclVat;
+ public $Description;
+ public $RowNumber;
+ public $VatPercent;
- /**
- * CancellationRow constructor.
- * @param $amount
- * @param $description
- * @param $vatPercent
- * @param null $rowNumber
- */
- function __construct($amount, $description, $vatPercent, $rowNumber = null)
- {
- $this->AmountInclVat = new SoapVar($amount, XSD_DECIMAL,
- "-", "--", "AmountInclVat", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ /**
+ * CancellationRow constructor.
+ * @param $amount
+ * @param $description
+ * @param $vatPercent
+ * @param null $rowNumber
+ */
+ function __construct($amount, $description, $vatPercent, $rowNumber = null)
+ {
+ $this->AmountInclVat = new SoapVar($amount, XSD_DECIMAL,
+ "-", "--", "AmountInclVat", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->Description = new SoapVar($description, XSD_STRING,
- "-", "--", "Description", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->Description = new SoapVar($description, XSD_STRING,
+ "-", "--", "Description", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- if ($rowNumber) {
- $this->RowNumber = new SoapVar($rowNumber, XSD_DECIMAL,
- "-", "--", "RowNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ if ($rowNumber) {
+ $this->RowNumber = new SoapVar($rowNumber, XSD_DECIMAL,
+ "-", "--", "RowNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
- $this->VatPercent = new SoapVar($vatPercent, XSD_DECIMAL,
- "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ $this->VatPercent = new SoapVar($vatPercent, XSD_DECIMAL,
+ "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/AdminSoap/CancellationRow.php b/src/AdminService/AdminSoap/CancellationRow.php
index 4b81c0c1..3ac2fd91 100644
--- a/src/AdminService/AdminSoap/CancellationRow.php
+++ b/src/AdminService/AdminSoap/CancellationRow.php
@@ -6,33 +6,33 @@
class CancellationRow
{
- public $AmountInclVat;
- public $Description;
- public $RowNumber;
- public $VatPercent;
-
- /**
- * CancellationRow constructor.
- * @param $amount
- * @param $description
- * @param $vatPercent
- * @param null $rowNumber
- */
- function __construct($amount, $description, $vatPercent, $rowNumber = null)
- {
-
- $this->AmountInclVat = new SoapVar($amount, XSD_DECIMAL,
- "-", "--", "AmountInclVat", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->Description = new SoapVar($description, XSD_STRING,
- "-", "--", "Description", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
-
- if ($rowNumber) {
- $this->RowNumber = new SoapVar($rowNumber, XSD_DECIMAL,
- "-", "--", "RowNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- }
-
- $this->VatPercent = new SoapVar($vatPercent, XSD_DECIMAL,
- "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
-
- }
+ public $AmountInclVat;
+ public $Description;
+ public $RowNumber;
+ public $VatPercent;
+
+ /**
+ * CancellationRow constructor.
+ * @param $amount
+ * @param $description
+ * @param $vatPercent
+ * @param null $rowNumber
+ */
+ function __construct($amount, $description, $vatPercent, $rowNumber = null)
+ {
+
+ $this->AmountInclVat = new SoapVar($amount, XSD_DECIMAL,
+ "-", "--", "AmountInclVat", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->Description = new SoapVar($description, XSD_STRING,
+ "-", "--", "Description", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+
+ if ($rowNumber) {
+ $this->RowNumber = new SoapVar($rowNumber, XSD_DECIMAL,
+ "-", "--", "RowNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ }
+
+ $this->VatPercent = new SoapVar($vatPercent, XSD_DECIMAL,
+ "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/AdminSoap/CreditInvoiceRowsRequest.php b/src/AdminService/AdminSoap/CreditInvoiceRowsRequest.php
index a444da1c..2c63e851 100644
--- a/src/AdminService/AdminSoap/CreditInvoiceRowsRequest.php
+++ b/src/AdminService/AdminSoap/CreditInvoiceRowsRequest.php
@@ -6,45 +6,45 @@
class CreditInvoiceRowsRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $ClientId;
- public $InvoiceDistributionType;
- public $InvoiceId;
- public $NewCreditInvoiceRows;
- public $RowNumbers;
+ public $Authentication; // note that the order of the attributes matter!
+ public $ClientId;
+ public $InvoiceDistributionType;
+ public $InvoiceId;
+ public $NewCreditInvoiceRows;
+ public $RowNumbers;
- /**
- * Admin Service for CreditInvoiceRowsRequest
- *
- * @param Authentication $authentication
- * @param string $clientId
- * @param string $invoiceDistributionType
- * @param string $invoiceId
- * @param OrderRow[] $newCreditInvoiceRows
- * @param string[] $orderRowNumbers
- */
- function __construct($authentication, $clientId, $invoiceDistributionType, $invoiceId, $newCreditInvoiceRows, $orderRowNumbers)
- {
- $this->Authentication = new \SoapVar( $authentication, SOAP_ENC_OBJECT,
- "-","--","Authentication","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- $this->ClientId = new \SoapVar( $clientId, XSD_LONG,
- "-","--","ClientId","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->InvoiceDistributionType = new \SoapVar( $invoiceDistributionType, XSD_STRING,
- "-","--","InvoiceDistributionType","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->InvoiceId = new \SoapVar( $invoiceId, XSD_LONG,
- "-","--","InvoiceId","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ /**
+ * Admin Service for CreditInvoiceRowsRequest
+ *
+ * @param Authentication $authentication
+ * @param string $clientId
+ * @param string $invoiceDistributionType
+ * @param string $invoiceId
+ * @param OrderRow[] $newCreditInvoiceRows
+ * @param string[] $orderRowNumbers
+ */
+ function __construct($authentication, $clientId, $invoiceDistributionType, $invoiceId, $newCreditInvoiceRows, $orderRowNumbers)
+ {
+ $this->Authentication = new \SoapVar( $authentication, SOAP_ENC_OBJECT,
+ "-","--","Authentication","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ $this->ClientId = new \SoapVar( $clientId, XSD_LONG,
+ "-","--","ClientId","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->InvoiceDistributionType = new \SoapVar( $invoiceDistributionType, XSD_STRING,
+ "-","--","InvoiceDistributionType","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->InvoiceId = new \SoapVar( $invoiceId, XSD_LONG,
+ "-","--","InvoiceId","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- if( count($newCreditInvoiceRows) > 0) {
- $this->NewCreditInvoiceRows = new \SoapVar( $newCreditInvoiceRows, SOAP_ENC_OBJECT,
- "-","--","NewCreditInvoiceRows","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
- else
- {
- unset( $this->NewCreditInvoiceRows );
- }
+ if( count($newCreditInvoiceRows) > 0) {
+ $this->NewCreditInvoiceRows = new \SoapVar( $newCreditInvoiceRows, SOAP_ENC_OBJECT,
+ "-","--","NewCreditInvoiceRows","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
+ else
+ {
+ unset( $this->NewCreditInvoiceRows );
+ }
- $this->RowNumbers = new \SoapVar( $orderRowNumbers, SOAP_ENC_OBJECT,
- "-","--","RowNumbers","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ $this->RowNumbers = new \SoapVar( $orderRowNumbers, SOAP_ENC_OBJECT,
+ "-","--","RowNumbers","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/DeliverOrderInformation.php b/src/AdminService/AdminSoap/DeliverOrderInformation.php
index 5ea1293a..f68cb993 100644
--- a/src/AdminService/AdminSoap/DeliverOrderInformation.php
+++ b/src/AdminService/AdminSoap/DeliverOrderInformation.php
@@ -6,23 +6,23 @@
class DeliverOrderInformation
{
- public $ClientId;
- public $OrderType;
- public $SveaOrderId;
+ public $ClientId;
+ public $OrderType;
+ public $SveaOrderId;
- /**
- * AdminService DeliverOrderInformation
- * @param long $clientId
- * @param string $orderType -- one of [Invoice|PaymentPlan]
- * @param long $sveaOrderId
- */
- function __construct($clientId, $orderType, $sveaOrderId)
- {
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrderType = new SoapVar($orderType, XSD_STRING,
- "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
- "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService DeliverOrderInformation
+ * @param long $clientId
+ * @param string $orderType -- one of [Invoice|PaymentPlan]
+ * @param long $sveaOrderId
+ */
+ function __construct($clientId, $orderType, $sveaOrderId)
+ {
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrderType = new SoapVar($orderType, XSD_STRING,
+ "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
+ "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/AdminSoap/DeliverOrdersRequest.php b/src/AdminService/AdminSoap/DeliverOrdersRequest.php
index 44b4e70c..79039481 100644
--- a/src/AdminService/AdminSoap/DeliverOrdersRequest.php
+++ b/src/AdminService/AdminSoap/DeliverOrdersRequest.php
@@ -6,24 +6,24 @@
class DeliverOrdersRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $InvoiceDistributionType;
- public $OrdersToDeliver;
+ public $Authentication; // note that the order of the attributes matter!
+ public $InvoiceDistributionType;
+ public $OrdersToDeliver;
- /**
- * AdminService DeliverOrdersRequest
- * @param Authentication $authentication
- * @param string $invoiceDistributionType -- one of [Post|Email]
- * @param OrdersToDeliver $ordersToDeliver
- */
- function __construct($authentication, $invoiceDistributionType, $ordersToDeliver)
- {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- $this->InvoiceDistributionType = new SoapVar($invoiceDistributionType, XSD_STRING,
- "-", "--", "InvoiceDistributionType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrdersToDeliver = new SoapVar($ordersToDeliver, SOAP_ENC_OBJECT,
- "-", "--", "OrdersToDeliver", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService DeliverOrdersRequest
+ * @param Authentication $authentication
+ * @param string $invoiceDistributionType -- one of [Post|Email]
+ * @param OrdersToDeliver $ordersToDeliver
+ */
+ function __construct($authentication, $invoiceDistributionType, $ordersToDeliver)
+ {
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ $this->InvoiceDistributionType = new SoapVar($invoiceDistributionType, XSD_STRING,
+ "-", "--", "InvoiceDistributionType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrdersToDeliver = new SoapVar($ordersToDeliver, SOAP_ENC_OBJECT,
+ "-", "--", "OrdersToDeliver", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/DeliverPartialRequest.php b/src/AdminService/AdminSoap/DeliverPartialRequest.php
index da5e84ab..99afb723 100644
--- a/src/AdminService/AdminSoap/DeliverPartialRequest.php
+++ b/src/AdminService/AdminSoap/DeliverPartialRequest.php
@@ -6,29 +6,29 @@
class DeliverPartialRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $InvoiceDistributionType;
- public $OrderToDeliver;
- public $RowNumbers;
+ public $Authentication; // note that the order of the attributes matter!
+ public $InvoiceDistributionType;
+ public $OrderToDeliver;
+ public $RowNumbers;
- /**
- * AdminService DeliverPartialRequest
- *
- * @param Authentication $authentication
- * @param string $invoiceDistributionType
- * @param OrderToDeliver $orderToDeliver
- * @param string[] $orderRowNumbers
- */
- function __construct($authentication, $invoiceDistributionType, $orderToDeliver, $orderRowNumbers)
- {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- $this->InvoiceDistributionType = new SoapVar($invoiceDistributionType, XSD_STRING,
- "-", "--", "InvoiceDistributionType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrderToDeliver = new SoapVar($orderToDeliver, SOAP_ENC_OBJECT,
- "-", "--", "OrdersToDeliver", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->RowNumbers = new SoapVar($orderRowNumbers, SOAP_ENC_OBJECT,
- "-", "--", "RowNumbers", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService DeliverPartialRequest
+ *
+ * @param Authentication $authentication
+ * @param string $invoiceDistributionType
+ * @param OrderToDeliver $orderToDeliver
+ * @param string[] $orderRowNumbers
+ */
+ function __construct($authentication, $invoiceDistributionType, $orderToDeliver, $orderRowNumbers)
+ {
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ $this->InvoiceDistributionType = new SoapVar($invoiceDistributionType, XSD_STRING,
+ "-", "--", "InvoiceDistributionType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrderToDeliver = new SoapVar($orderToDeliver, SOAP_ENC_OBJECT,
+ "-", "--", "OrdersToDeliver", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->RowNumbers = new SoapVar($orderRowNumbers, SOAP_ENC_OBJECT,
+ "-", "--", "RowNumbers", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/AdminSoap/GetOrderInformation.php b/src/AdminService/AdminSoap/GetOrderInformation.php
index 2f49dd77..14b8d86b 100644
--- a/src/AdminService/AdminSoap/GetOrderInformation.php
+++ b/src/AdminService/AdminSoap/GetOrderInformation.php
@@ -6,20 +6,20 @@
class GetOrderInformation
{
- public $ClientId;
- public $SveaOrderId;
+ public $ClientId;
+ public $SveaOrderId;
- /**
- * AdminService GetOrderInformation
- * @param long $clientId
- * @param long $sveaOrderId
- */
- function __construct($clientId, $sveaOrderId)
- {
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // OrderType -- optional, not sent by package
- $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
- "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService GetOrderInformation
+ * @param long $clientId
+ * @param long $sveaOrderId
+ */
+ function __construct($clientId, $sveaOrderId)
+ {
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // OrderType -- optional, not sent by package
+ $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
+ "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/GetOrdersRequest.php b/src/AdminService/AdminSoap/GetOrdersRequest.php
index fb30bda1..cca16a0c 100644
--- a/src/AdminService/AdminSoap/GetOrdersRequest.php
+++ b/src/AdminService/AdminSoap/GetOrdersRequest.php
@@ -6,20 +6,20 @@
class GetOrdersRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $OrdersToRetrieve;
+ public $Authentication; // note that the order of the attributes matter!
+ public $OrdersToRetrieve;
- /**
- * AdminService GetOrdersRequest
- * @param Authentication $authentication
- * @param OrdersToRetrieve $ordersToRetrieve
- */
- function __construct($authentication, $ordersToRetrieve)
- {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- $this->OrdersToRetrieve = new SoapVar($ordersToRetrieve, SOAP_ENC_OBJECT,
- "-", "--", "OrdersToRetrieve", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService GetOrdersRequest
+ * @param Authentication $authentication
+ * @param OrdersToRetrieve $ordersToRetrieve
+ */
+ function __construct($authentication, $ordersToRetrieve)
+ {
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ $this->OrdersToRetrieve = new SoapVar($ordersToRetrieve, SOAP_ENC_OBJECT,
+ "-", "--", "OrdersToRetrieve", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/NumberedOrderRow.php b/src/AdminService/AdminSoap/NumberedOrderRow.php
index fd5210dd..5101d8bf 100644
--- a/src/AdminService/AdminSoap/NumberedOrderRow.php
+++ b/src/AdminService/AdminSoap/NumberedOrderRow.php
@@ -6,73 +6,73 @@
class NumberedOrderRow
{
- //Webservice
- public $ArticleNumber;
- public $Description;
- public $DiscountPercent;
- public $CreditInvoiceId;
- public $NumberOfUnits;
- public $PriceIncludingVat;
- public $PricePerUnit;
- public $Unit;
- public $VatPercent;
+ //Webservice
+ public $ArticleNumber;
+ public $Description;
+ public $DiscountPercent;
+ public $CreditInvoiceId;
+ public $NumberOfUnits;
+ public $PriceIncludingVat;
+ public $PricePerUnit;
+ public $Unit;
+ public $VatPercent;
- //Admin.service
- public $InvoiceId;
- public $Status;
- public $RowNumber;
+ //Admin.service
+ public $InvoiceId;
+ public $Status;
+ public $RowNumber;
- /**
- * NumberedOrderRow constructor.
- * @param $articleNumber
- * @param $description
- * @param $discountPercent
- * @param $quantity
- * @param $amountExVat
- * @param $unit
- * @param $vatPercent
- * @param $creditInvoiceId
- * @param $invoiceId
- * @param $rowNumber
- * @param $priceIncludingVat
- */
- function __construct($articleNumber, $description, $discountPercent, $quantity, $amountExVat, $unit, $vatPercent,
- $creditInvoiceId, $invoiceId, $rowNumber, $priceIncludingVat)
- {
- //Webservice
- $this->ArticleNumber = new SoapVar($articleNumber, XSD_STRING,
- "-", "--", "ArticleNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->Description = new SoapVar($description, XSD_STRING,
- "-", "--", "Description", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->DiscountPercent = new SoapVar($discountPercent, XSD_DECIMAL,
- "-", "--", "DiscountPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->NumberOfUnits = new SoapVar($quantity, XSD_DECIMAL,
- "-", "--", "NumberOfUnits", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->PriceIncludingVat = new SoapVar($priceIncludingVat, XSD_BOOLEAN,
- "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->PricePerUnit = new SoapVar($amountExVat, XSD_DECIMAL,
- "-", "--", "PricePerUnit", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->Unit = new SoapVar($unit, XSD_STRING,
- "-", "--", "Unit", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->VatPercent = new SoapVar($vatPercent, XSD_DECIMAL,
- "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ /**
+ * NumberedOrderRow constructor.
+ * @param $articleNumber
+ * @param $description
+ * @param $discountPercent
+ * @param $quantity
+ * @param $amountExVat
+ * @param $unit
+ * @param $vatPercent
+ * @param $creditInvoiceId
+ * @param $invoiceId
+ * @param $rowNumber
+ * @param $priceIncludingVat
+ */
+ function __construct($articleNumber, $description, $discountPercent, $quantity, $amountExVat, $unit, $vatPercent,
+ $creditInvoiceId, $invoiceId, $rowNumber, $priceIncludingVat)
+ {
+ //Webservice
+ $this->ArticleNumber = new SoapVar($articleNumber, XSD_STRING,
+ "-", "--", "ArticleNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->Description = new SoapVar($description, XSD_STRING,
+ "-", "--", "Description", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->DiscountPercent = new SoapVar($discountPercent, XSD_DECIMAL,
+ "-", "--", "DiscountPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->NumberOfUnits = new SoapVar($quantity, XSD_DECIMAL,
+ "-", "--", "NumberOfUnits", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->PriceIncludingVat = new SoapVar($priceIncludingVat, XSD_BOOLEAN,
+ "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->PricePerUnit = new SoapVar($amountExVat, XSD_DECIMAL,
+ "-", "--", "PricePerUnit", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->Unit = new SoapVar($unit, XSD_STRING,
+ "-", "--", "Unit", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->VatPercent = new SoapVar($vatPercent, XSD_DECIMAL,
+ "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- //admin.service
- if (!isset($creditInvoiceId)) {
- unset($this->CreditInvoiceId); // nullable attributes should not be included in soap xml if not set, so unset them
- } else {
- $this->CreditInvoiceId = new SoapVar($creditInvoiceId, XSD_LONG,
- "-", "--", "CreditInvoiceId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
- if (!isset($invoiceId)) {
- unset($this->InvoiceId);
- } else {
- $this->InvoiceId = new SoapVar($invoiceId, XSD_LONG,
- "-", "--", "InvoiceId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
- $this->RowNumber = new SoapVar($rowNumber, XSD_LONG,
- "-", "--", "RowNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ //admin.service
+ if (!isset($creditInvoiceId)) {
+ unset($this->CreditInvoiceId); // nullable attributes should not be included in soap xml if not set, so unset them
+ } else {
+ $this->CreditInvoiceId = new SoapVar($creditInvoiceId, XSD_LONG,
+ "-", "--", "CreditInvoiceId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
+ if (!isset($invoiceId)) {
+ unset($this->InvoiceId);
+ } else {
+ $this->InvoiceId = new SoapVar($invoiceId, XSD_LONG,
+ "-", "--", "InvoiceId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
+ $this->RowNumber = new SoapVar($rowNumber, XSD_LONG,
+ "-", "--", "RowNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
- // Status -- optional, not sent by package
+ }
+ // Status -- optional, not sent by package
}
diff --git a/src/AdminService/AdminSoap/OrderRow.php b/src/AdminService/AdminSoap/OrderRow.php
index b528f51f..622a20cb 100644
--- a/src/AdminService/AdminSoap/OrderRow.php
+++ b/src/AdminService/AdminSoap/OrderRow.php
@@ -6,44 +6,44 @@
class OrderRow
{
- public $ArticleNumber;
- public $Description;
- public $DiscountPercent;
- public $NumberOfUnits;
- public $PriceIncludingVat;
- public $PricePerUnit;
- public $Unit;
- public $VatPercent;
+ public $ArticleNumber;
+ public $Description;
+ public $DiscountPercent;
+ public $NumberOfUnits;
+ public $PriceIncludingVat;
+ public $PricePerUnit;
+ public $Unit;
+ public $VatPercent;
- /**
- * OrderRow constructor.
- * @param $articleNumber
- * @param $description
- * @param $discountPercent
- * @param $quantity
- * @param $amount
- * @param $unit
- * @param $vatPercent
- * @param $priceIncludingVat
- */
- function __construct($articleNumber, $description, $discountPercent, $quantity, $amount, $unit, $vatPercent, $priceIncludingVat)
- {
- $this->ArticleNumber = new SoapVar($articleNumber, XSD_STRING,
- "-", "--", "ArticleNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->Description = new SoapVar($description, XSD_STRING,
- "-", "--", "Description", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->DiscountPercent = new SoapVar($discountPercent, XSD_DECIMAL,
- "-", "--", "DiscountPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->NumberOfUnits = new SoapVar($quantity, XSD_DECIMAL,
- "-", "--", "NumberOfUnits", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->PriceIncludingVat = new SoapVar($priceIncludingVat, XSD_BOOLEAN,
- "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->PricePerUnit = new SoapVar($amount, XSD_DECIMAL,
- "-", "--", "PricePerUnit", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->Unit = new SoapVar($unit, XSD_STRING,
- "-", "--", "Unit", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- $this->VatPercent = new SoapVar($vatPercent, XSD_DECIMAL,
- "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ /**
+ * OrderRow constructor.
+ * @param $articleNumber
+ * @param $description
+ * @param $discountPercent
+ * @param $quantity
+ * @param $amount
+ * @param $unit
+ * @param $vatPercent
+ * @param $priceIncludingVat
+ */
+ function __construct($articleNumber, $description, $discountPercent, $quantity, $amount, $unit, $vatPercent, $priceIncludingVat)
+ {
+ $this->ArticleNumber = new SoapVar($articleNumber, XSD_STRING,
+ "-", "--", "ArticleNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->Description = new SoapVar($description, XSD_STRING,
+ "-", "--", "Description", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->DiscountPercent = new SoapVar($discountPercent, XSD_DECIMAL,
+ "-", "--", "DiscountPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->NumberOfUnits = new SoapVar($quantity, XSD_DECIMAL,
+ "-", "--", "NumberOfUnits", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->PriceIncludingVat = new SoapVar($priceIncludingVat, XSD_BOOLEAN,
+ "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->PricePerUnit = new SoapVar($amount, XSD_DECIMAL,
+ "-", "--", "PricePerUnit", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->Unit = new SoapVar($unit, XSD_STRING,
+ "-", "--", "Unit", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
+ $this->VatPercent = new SoapVar($vatPercent, XSD_DECIMAL,
+ "-", "--", "VatPercent", "http://schemas.datacontract.org/2004/07/DataObjects.Webservice");
- }
+ }
}
diff --git a/src/AdminService/AdminSoap/OrderToDeliver.php b/src/AdminService/AdminSoap/OrderToDeliver.php
index 3c694598..59fcd917 100644
--- a/src/AdminService/AdminSoap/OrderToDeliver.php
+++ b/src/AdminService/AdminSoap/OrderToDeliver.php
@@ -6,23 +6,23 @@
class OrderToDeliver
{
- public $ClientId;
- public $OrderType;
- public $SveaOrderId;
+ public $ClientId;
+ public $OrderType;
+ public $SveaOrderId;
- /**
- * AdminService OrderToDeliver
- * @param long $clientId
- * @param string $orderType -- one of [Invoice|PaymentPlan]
- * @param long $sveaOrderId
- */
- function __construct($clientId, $orderType, $sveaOrderId)
- {
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrderType = new SoapVar($orderType, XSD_STRING,
- "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
- "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService OrderToDeliver
+ * @param long $clientId
+ * @param string $orderType -- one of [Invoice|PaymentPlan]
+ * @param long $sveaOrderId
+ */
+ function __construct($clientId, $orderType, $sveaOrderId)
+ {
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrderType = new SoapVar($orderType, XSD_STRING,
+ "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
+ "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/OrdersToDeliver.php b/src/AdminService/AdminSoap/OrdersToDeliver.php
index 96e2fb2b..7ca877c0 100644
--- a/src/AdminService/AdminSoap/OrdersToDeliver.php
+++ b/src/AdminService/AdminSoap/OrdersToDeliver.php
@@ -6,15 +6,15 @@
class OrdersToDeliver
{
- public $DeliverOrderInformation;
+ public $DeliverOrderInformation;
- /**
- * AdminService OrdersToDeliver
- * @param DeliverOrderInformation $deliverOrderInformation
- */
- function __construct($deliverOrderInformation)
- {
- $this->DeliverOrderInformation = new SoapVar($deliverOrderInformation, SOAP_ENC_OBJECT,
- "-", "--", "DeliverOrderInformation", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService OrdersToDeliver
+ * @param DeliverOrderInformation $deliverOrderInformation
+ */
+ function __construct($deliverOrderInformation)
+ {
+ $this->DeliverOrderInformation = new SoapVar($deliverOrderInformation, SOAP_ENC_OBJECT,
+ "-", "--", "DeliverOrderInformation", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/OrdersToRetrieve.php b/src/AdminService/AdminSoap/OrdersToRetrieve.php
index 80cc726a..3486426c 100644
--- a/src/AdminService/AdminSoap/OrdersToRetrieve.php
+++ b/src/AdminService/AdminSoap/OrdersToRetrieve.php
@@ -6,15 +6,15 @@
class OrdersToRetrieve
{
- public $GetOrderInformation;
+ public $GetOrderInformation;
- /**
- * AdminService OrdersToRetrieve
- * @param GetOrderInformation $getOrderInformation
- */
- function __construct($getOrderInformation)
- {
- $this->GetOrderInformation = new SoapVar($getOrderInformation, SOAP_ENC_OBJECT,
- "-", "--", "GetOrderInformation", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService OrdersToRetrieve
+ * @param GetOrderInformation $getOrderInformation
+ */
+ function __construct($getOrderInformation)
+ {
+ $this->GetOrderInformation = new SoapVar($getOrderInformation, SOAP_ENC_OBJECT,
+ "-", "--", "GetOrderInformation", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/SearchOrdersRequest.php b/src/AdminService/AdminSoap/SearchOrdersRequest.php
index 4ae88dcf..a2aaa230 100644
--- a/src/AdminService/AdminSoap/SearchOrdersRequest.php
+++ b/src/AdminService/AdminSoap/SearchOrdersRequest.php
@@ -6,39 +6,39 @@
class SearchOrdersRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $AccountCreditsToRetrieve;
-
- /**
- * AdminService GetOrdersRequest
- * @param Authentication $authentication
- * @param OrdersToRetrieve $ordersToRetrieve
- */
- function __construct($authentication, $accountsToRetrieve)
- {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
-
- $list = array();
- foreach($accountsToRetrieve as $accountInfo)
- {
- $clientAccountCreditId = new SoapVar($accountInfo->clientAccountCreditId, XSD_LONG,
- "-", "--", "ClientAccountCreditId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Account");
-
- $clientId = new SoapVar($accountInfo->clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Account");
-
- $obj = new \stdClass();
- $obj->ClientAccountCreditId = $clientAccountCreditId;
- $obj->ClientId = $clientId;
-
-
- $list [] = new SoapVar($obj, SOAP_ENC_OBJECT,
- "-", "--", "GetAccountCreditInformation", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Account");
- }
-
- $this->AccountCreditsToRetrieve = new SoapVar($list, SOAP_ENC_OBJECT,
- "-", "--", "AccountCreditsToRetrieve", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ public $Authentication; // note that the order of the attributes matter!
+ public $AccountCreditsToRetrieve;
+
+ /**
+ * AdminService GetOrdersRequest
+ * @param Authentication $authentication
+ * @param OrdersToRetrieve $ordersToRetrieve
+ */
+ function __construct($authentication, $accountsToRetrieve)
+ {
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+
+ $list = [];
+ foreach($accountsToRetrieve as $accountInfo)
+ {
+ $clientAccountCreditId = new SoapVar($accountInfo->clientAccountCreditId, XSD_LONG,
+ "-", "--", "ClientAccountCreditId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Account");
+
+ $clientId = new SoapVar($accountInfo->clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Account");
+
+ $obj = new \stdClass();
+ $obj->ClientAccountCreditId = $clientAccountCreditId;
+ $obj->ClientId = $clientId;
+
+
+ $list [] = new SoapVar($obj, SOAP_ENC_OBJECT,
+ "-", "--", "GetAccountCreditInformation", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service.Account");
+ }
+
+ $this->AccountCreditsToRetrieve = new SoapVar($list, SOAP_ENC_OBJECT,
+ "-", "--", "AccountCreditsToRetrieve", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/SoapClient.php b/src/AdminService/AdminSoap/SoapClient.php
index ded6be90..07908992 100644
--- a/src/AdminService/AdminSoap/SoapClient.php
+++ b/src/AdminService/AdminSoap/SoapClient.php
@@ -7,90 +7,90 @@
class SoapClient
{
- private $client;
+ private $client;
- /**
- * Constructor, sets up soap server and SoapClient
- * @param ConfigurationProvider $config
- * @param string $orderType
- */
- public function __construct($config, $orderType)
- {
- $this->client = $this->setSoapClient($config, $orderType);
- }
+ /**
+ * Constructor, sets up soap server and SoapClient
+ * @param ConfigurationProvider $config
+ * @param string $orderType
+ */
+ public function __construct($config, $orderType)
+ {
+ $this->client = $this->setSoapClient($config, $orderType);
+ }
- /**
- * When used from PHP, the SveaWebPay Administration Service requires some configuration.
- * getSoapClient() takes the config and returns a SoapClient with a working set
- * of options, bypassing the server wsdl.
- *
- * @param ConfigurationProvider $config
- * @param string $orderType
- * @return \SoapClient
- */
- public function setSoapClient($config, $orderType)
- {
- $libraryProperties = Helper::getSveaLibraryProperties();
- $libraryName = $libraryProperties['library_name'];
- $libraryVersion = $libraryProperties['library_version'];
+ /**
+ * When used from PHP, the SveaWebPay Administration Service requires some configuration.
+ * getSoapClient() takes the config and returns a SoapClient with a working set
+ * of options, bypassing the server wsdl.
+ *
+ * @param ConfigurationProvider $config
+ * @param string $orderType
+ * @return \SoapClient
+ */
+ public function setSoapClient($config, $orderType)
+ {
+ $libraryProperties = Helper::getSveaLibraryProperties();
+ $libraryName = $libraryProperties['library_name'];
+ $libraryVersion = $libraryProperties['library_version'];
- $integrationProperties = Helper::getSveaIntegrationProperties($config);
- $integrationPlatform = $integrationProperties['integration_platform'];
- $integrationCompany = $integrationProperties['integration_company'];
- $integrationVersion = $integrationProperties['integration_version'];
+ $integrationProperties = Helper::getSveaIntegrationProperties($config);
+ $integrationPlatform = $integrationProperties['integration_platform'];
+ $integrationCompany = $integrationProperties['integration_company'];
+ $integrationVersion = $integrationProperties['integration_version'];
- $endpoint = $config->getEndPoint($orderType);
+ $endpoint = $config->getEndPoint($orderType);
- $client = new \SoapClient(
- null,
- array(
- 'location' => $endpoint,
- 'uri' => "http://tempuri.org/",
- 'use' => SOAP_LITERAL,
- 'exceptions' => 1,
- 'connection_timeout' => 60,
- 'trace' => 1,
- 'soap_version' => SOAP_1_1,
- 'stream_context' => stream_context_create(array('http' => array(
- 'header' => 'X-Svea-Library-Name: ' . $libraryName . "\n" .
- 'X-Svea-Library-Version: ' . $libraryVersion . "\n" .
- 'X-Svea-Integration-Platform: ' . $integrationPlatform . "\n" .
- 'X-Svea-Integration-Company: ' . $integrationCompany . "\n" .
- 'X-Svea-Integration-Version: ' . $integrationVersion
- )))
- )
- );
+ $client = new \SoapClient(
+ null,
+ [
+ 'location' => $endpoint,
+ 'uri' => "http://tempuri.org/",
+ 'use' => SOAP_LITERAL,
+ 'exceptions' => 1,
+ 'connection_timeout' => 60,
+ 'trace' => 1,
+ 'soap_version' => SOAP_1_1,
+ 'stream_context' => stream_context_create(['http' => [
+ 'header' => 'X-Svea-Library-Name: ' . $libraryName . "\n" .
+ 'X-Svea-Library-Version: ' . $libraryVersion . "\n" .
+ 'X-Svea-Integration-Platform: ' . $integrationPlatform . "\n" .
+ 'X-Svea-Integration-Company: ' . $integrationCompany . "\n" .
+ 'X-Svea-Integration-Version: ' . $integrationVersion
+ ]])
+ ]
+ );
- return $client;
- }
+ return $client;
+ }
- /**
- * doSoapCall takes the $action name of the soap function you wish to call,
- * and the $request data.
- *
- * Use the provided AdminSoap classes to build the request content, as these
- * perform the \SoapVar conversion. Note that doSoapCall performs the final
- * wrapping of the request contents, so you do not need a "request" SoapVar.
- *
- * @param string $action
- * @param \SoapVar $request
- * @return \StdClass $response
- */
- public function doSoapCall($action, $request)
- {
- // wrap the request
- $wrappedRequest = new \SoapVar($request, SOAP_ENC_OBJECT, "-", "--", "request", "http://tempuri.org/");
+ /**
+ * doSoapCall takes the $action name of the soap function you wish to call,
+ * and the $request data.
+ *
+ * Use the provided AdminSoap classes to build the request content, as these
+ * perform the \SoapVar conversion. Note that doSoapCall performs the final
+ * wrapping of the request contents, so you do not need a "request" SoapVar.
+ *
+ * @param string $action
+ * @param \SoapVar $request
+ * @return \StdClass $response
+ */
+ public function doSoapCall($action, $request)
+ {
+ // wrap the request
+ $wrappedRequest = new \SoapVar($request, SOAP_ENC_OBJECT, "-", "--", "request", "http://tempuri.org/");
- // do soapcall
- $response = $this->client->__soapCall($action, array($wrappedRequest),
- array("soapaction" => 'http://tempuri.org/IAdminService/' . $action)
- );
+ // do soapcall
+ $response = $this->client->__soapCall($action, [$wrappedRequest],
+ ["soapaction" => 'http://tempuri.org/IAdminService/' . $action]
+ );
- return $response;
- }
+ return $response;
+ }
- public function getClient()
- {
- return $this->client;
- }
+ public function getClient()
+ {
+ return $this->client;
+ }
}
diff --git a/src/AdminService/AdminSoap/UpdateOrderRequest.php b/src/AdminService/AdminSoap/UpdateOrderRequest.php
index a4490489..18a34bfa 100644
--- a/src/AdminService/AdminSoap/UpdateOrderRequest.php
+++ b/src/AdminService/AdminSoap/UpdateOrderRequest.php
@@ -6,35 +6,35 @@
class UpdateOrderRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $ClientId;
- public $ClientOrderNumber;
- public $Notes;
- public $OrderType;
- public $SveaOrderId;
+ public $Authentication; // note that the order of the attributes matter!
+ public $ClientId;
+ public $ClientOrderNumber;
+ public $Notes;
+ public $OrderType;
+ public $SveaOrderId;
- /**
- * @param Authentication $authentication
- * @param string $clientId
- * @param string $orderType
- * @param string $sveaOrderId
- * @param $clientOrderNumber
- * @param $notes
- */
- function __construct($authentication, $clientId, $orderType, $sveaOrderId, $clientOrderNumber, $notes)
- {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrderType = new SoapVar($orderType, XSD_STRING,
- "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
- "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->ClientOrderNumber = new SoapVar($clientOrderNumber, XSD_STRING,
- "-", "--", "ClientOrderNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->Notes = new SoapVar($notes, XSD_STRING,
- "-", "--", "Notes", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * @param Authentication $authentication
+ * @param string $clientId
+ * @param string $orderType
+ * @param string $sveaOrderId
+ * @param $clientOrderNumber
+ * @param $notes
+ */
+ function __construct($authentication, $clientId, $orderType, $sveaOrderId, $clientOrderNumber, $notes)
+ {
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrderType = new SoapVar($orderType, XSD_STRING,
+ "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
+ "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->ClientOrderNumber = new SoapVar($clientOrderNumber, XSD_STRING,
+ "-", "--", "ClientOrderNumber", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->Notes = new SoapVar($notes, XSD_STRING,
+ "-", "--", "Notes", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/AdminSoap/UpdateOrderRowsRequest.php b/src/AdminService/AdminSoap/UpdateOrderRowsRequest.php
index b086108b..9163f76c 100644
--- a/src/AdminService/AdminSoap/UpdateOrderRowsRequest.php
+++ b/src/AdminService/AdminSoap/UpdateOrderRowsRequest.php
@@ -6,32 +6,32 @@
class UpdateOrderRowsRequest
{
- public $Authentication; // note that the order of the attributes matter!
- public $ClientId;
- public $OrderType;
- public $SveaOrderId;
- public $UpdatedOrderRows;
+ public $Authentication; // note that the order of the attributes matter!
+ public $ClientId;
+ public $OrderType;
+ public $SveaOrderId;
+ public $UpdatedOrderRows;
- /**
- * AdminService AddOrderRowsRequest
- * @param Authentication $authentication
- * @param string $clientId
- * @param string $orderType
- * @param string $sveaOrderId
- * @param NumberedOrderRow[] $updatedOrderRows ;
- */
- function __construct($authentication, $clientId, $orderType, $sveaOrderId, $updatedOrderRows)
- {
- $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
- "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- // Settings -- optional, not sent by package
- $this->ClientId = new SoapVar($clientId, XSD_LONG,
- "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->OrderType = new SoapVar($orderType, XSD_STRING,
- "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
- "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- $this->UpdatedOrderRows = new SoapVar($updatedOrderRows, SOAP_ENC_OBJECT,
- "-", "--", "UpdatedOrderRows", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
- }
+ /**
+ * AdminService AddOrderRowsRequest
+ * @param Authentication $authentication
+ * @param string $clientId
+ * @param string $orderType
+ * @param string $sveaOrderId
+ * @param NumberedOrderRow[] $updatedOrderRows ;
+ */
+ function __construct($authentication, $clientId, $orderType, $sveaOrderId, $updatedOrderRows)
+ {
+ $this->Authentication = new SoapVar($authentication, SOAP_ENC_OBJECT,
+ "-", "--", "Authentication", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ // Settings -- optional, not sent by package
+ $this->ClientId = new SoapVar($clientId, XSD_LONG,
+ "-", "--", "ClientId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->OrderType = new SoapVar($orderType, XSD_STRING,
+ "-", "--", "OrderType", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->SveaOrderId = new SoapVar($sveaOrderId, XSD_LONG,
+ "-", "--", "SveaOrderId", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ $this->UpdatedOrderRows = new SoapVar($updatedOrderRows, SOAP_ENC_OBJECT,
+ "-", "--", "UpdatedOrderRows", "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service");
+ }
}
diff --git a/src/AdminService/CancelOrderRequest.php b/src/AdminService/CancelOrderRequest.php
index b615c966..78ad219f 100644
--- a/src/AdminService/CancelOrderRequest.php
+++ b/src/AdminService/CancelOrderRequest.php
@@ -8,71 +8,71 @@
/**
* Admin Service CancelOrderRequest class
- *
+ *
* @author Kristian Grossman-Madsen
*/
class CancelOrderRequest extends AdminServiceRequest {
-
- /**
- * @var cancelOrderBuilder $orderBuilder
- */
- public $orderBuilder;
- /**
- * @param $cancelOrderBuilder
- */
- public function __construct($cancelOrderBuilder) {
- $this->action = "CancelOrder";
- $this->orderBuilder = $cancelOrderBuilder;
- }
+ /**
+ * @var cancelOrderBuilder $orderBuilder
+ */
+ public $orderBuilder;
- /**
- * populate and return soap request contents
- * @return \Svea\WebPay\AdminService\AdminSoap\CancelOrderRequest
- */
- public function prepareRequest() {
-
- $this->validateRequest();
-
- $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\CancelOrderRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername( ($this->orderBuilder->orderType), $this->orderBuilder->countryCode ),
- $this->orderBuilder->conf->getPassword( ($this->orderBuilder->orderType), $this->orderBuilder->countryCode )
- ),
- $this->orderBuilder->orderId,
- AdminServiceRequest::CamelCaseOrderType( $this->orderBuilder->orderType ),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- );
-
- return $soapRequest;
- }
-
- public function validate() {
- $errors = array();
- $errors = $this->validateOrderId($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
- return $errors;
- }
-
- private function validateOrderId($errors) {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required.");
- }
- return $errors;
- }
-
- private function validateOrderType($errors) {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
- return $errors;
- }
+ /**
+ * @param $cancelOrderBuilder
+ */
+ public function __construct($cancelOrderBuilder) {
+ $this->action = "CancelOrder";
+ $this->orderBuilder = $cancelOrderBuilder;
+ }
- private function validateCountryCode($errors) {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required.");
- }
- return $errors;
- }
-}
+ /**
+ * populate and return soap request contents
+ * @return \Svea\WebPay\AdminService\AdminSoap\CancelOrderRequest
+ */
+ public function prepareRequest() {
+
+ $this->validateRequest();
+
+ $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\CancelOrderRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername( ($this->orderBuilder->orderType), $this->orderBuilder->countryCode ),
+ $this->orderBuilder->conf->getPassword( ($this->orderBuilder->orderType), $this->orderBuilder->countryCode )
+ ),
+ $this->orderBuilder->orderId,
+ AdminServiceRequest::CamelCaseOrderType( $this->orderBuilder->orderType ),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ );
+
+ return $soapRequest;
+ }
+
+ public function validate() {
+ $errors = [];
+ $errors = $this->validateOrderId($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+ return $errors;
+ }
+
+ private function validateOrderId($errors) {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required."];
+ }
+ return $errors;
+ }
+
+ private function validateOrderType($errors) {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+ return $errors;
+ }
+
+ private function validateCountryCode($errors) {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required."];
+ }
+ return $errors;
+ }
+}
diff --git a/src/AdminService/CancelOrderRowsRequest.php b/src/AdminService/CancelOrderRowsRequest.php
index b44faaef..fec530d4 100644
--- a/src/AdminService/CancelOrderRowsRequest.php
+++ b/src/AdminService/CancelOrderRowsRequest.php
@@ -13,114 +13,114 @@
*/
class CancelOrderRowsRequest extends AdminServiceRequest
{
- /**
- * @var \Svea\WebPay\AdminService\AdminSoap\CancelOrderRowsRequest $orderBuilder
- */
- public $orderBuilder;
-
- /**
- * @param \Svea\WebPay\AdminService\AdminSoap\CancelOrderRowsRequest $cancelOrderRowsBuilder
- */
- public function __construct($cancelOrderRowsBuilder)
- {
- $this->action = "CancelOrderRows";
- $this->orderBuilder = $cancelOrderRowsBuilder;
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @return \Svea\WebPay\AdminService\AdminSoap\CancelOrderRowsRequest
- */
- public function prepareRequest()
- {
- $this->validateRequest();
-
- $orderRowNumbers = array();
- foreach ($this->orderBuilder->rowsToCancel as $rowToCancel) {
- $orderRowNumbers[] = new SoapVar($rowToCancel, XSD_LONG, null, null, 'long', "http://schemas.microsoft.com/2003/10/Serialization/Arrays");
- }
-
- $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\CancelOrderRowsRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderBuilder->conf->getClientNumber($this->orderBuilder->orderType, $this->orderBuilder->countryCode),
- new SoapVar($orderRowNumbers, SOAP_ENC_OBJECT),
- AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
- $this->orderBuilder->orderId
- );
-
- // Example request to cancel rows 1 & 2 in order 349092
- //
- //
- //
- //
- //
- //
- //
- // sverigetest
- // sverigetest
- //
- // 79021
- //
- // 1
- // 2
- //
- // Invoice
- // 349092
- //
- //
- //
- //
-
- return $soapRequest;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateOrderId($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
- $errors = $this->validateRowsToCancel($errors);
-
- return $errors;
- }
-
- private function validateOrderId($errors)
- {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required.");
- }
-
- return $errors;
- }
-
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required.");
- }
-
- return $errors;
- }
-
- private function validateRowsToCancel($errors)
- {
- if (isset($this->orderBuilder->rowsToCancel) == FALSE) {
- $errors[] = array('missing value' => "rowsToCancel is required.");
- }
-
- return $errors;
- }
+ /**
+ * @var \Svea\WebPay\AdminService\AdminSoap\CancelOrderRowsRequest $orderBuilder
+ */
+ public $orderBuilder;
+
+ /**
+ * @param \Svea\WebPay\AdminService\AdminSoap\CancelOrderRowsRequest $cancelOrderRowsBuilder
+ */
+ public function __construct($cancelOrderRowsBuilder)
+ {
+ $this->action = "CancelOrderRows";
+ $this->orderBuilder = $cancelOrderRowsBuilder;
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @return \Svea\WebPay\AdminService\AdminSoap\CancelOrderRowsRequest
+ */
+ public function prepareRequest()
+ {
+ $this->validateRequest();
+
+ $orderRowNumbers = [];
+ foreach ($this->orderBuilder->rowsToCancel as $rowToCancel) {
+ $orderRowNumbers[] = new SoapVar($rowToCancel, XSD_LONG, null, null, 'long', "http://schemas.microsoft.com/2003/10/Serialization/Arrays");
+ }
+
+ $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\CancelOrderRowsRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderBuilder->conf->getClientNumber($this->orderBuilder->orderType, $this->orderBuilder->countryCode),
+ new SoapVar($orderRowNumbers, SOAP_ENC_OBJECT),
+ AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
+ $this->orderBuilder->orderId
+ );
+
+ // Example request to cancel rows 1 & 2 in order 349092
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // sverigetest
+ // sverigetest
+ //
+ // 79021
+ //
+ // 1
+ // 2
+ //
+ // Invoice
+ // 349092
+ //
+ //
+ //
+ //
+
+ return $soapRequest;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateOrderId($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+ $errors = $this->validateRowsToCancel($errors);
+
+ return $errors;
+ }
+
+ private function validateOrderId($errors)
+ {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateRowsToCancel($errors)
+ {
+ if (isset($this->orderBuilder->rowsToCancel) == FALSE) {
+ $errors[] = ['missing value' => "rowsToCancel is required."];
+ }
+
+ return $errors;
+ }
}
diff --git a/src/AdminService/CreditAccountCreditRowsRequest.php b/src/AdminService/CreditAccountCreditRowsRequest.php
index 85c25ac4..e1ffa917 100644
--- a/src/AdminService/CreditAccountCreditRowsRequest.php
+++ b/src/AdminService/CreditAccountCreditRowsRequest.php
@@ -14,159 +14,159 @@
class CreditAccountCreditRowsRequest extends AdminServiceRequest
{
- /**
- * @var CreditOrderRowsBuilder $orderBuilder
- */
- public $orderBuilder;
-
- /**
- * @var \SoapVar[] $orderRows initially empty, specifies any additional credit order rows to credit
- */
- public $orderRows;
-
- /**
- * @param CreditOrderRowsBuilder $creditOrderRowsBuilder
- */
- public function __construct($creditOrderRowsBuilder)
- {
- $this->action = "CancelAccountCreditRows";
- $this->orderRows = array();
- $this->orderBuilder = $creditOrderRowsBuilder;
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @param bool $resendOrderWithFlippedPriceIncludingVat
- * @return CreditOrderRowsRequest
- * @throws ValidationException
- */
- public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
- {
- $this->validateRequest();
- $this->orderRows = $this->getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($this->orderBuilder->creditOrderRows);
- $soapRequest = new CancelAccountCreditRowsRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderRows,
- $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->orderId
- );
-
- return $soapRequest;
- }
-
- protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat = NULL)
- {
- $amount = 0;
- $orderRows = array();
- //if orderrownumber is set, create an orderrow with dummy values. Will be ignored in Svea\WebPay\WebPay WS
- if (count($this->orderBuilder->rowsToCredit) > 0) {
- foreach ($this->orderBuilder->rowsToCredit as $rownumber) {
- $orderRows[] = new \SoapVar(
- new CancellationAccountCreditRow(
- 0.00,
- "Numbered row",
- 0,
- $rownumber
- ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service"
- );
- }
- }
- //add orderrows if there are any
- foreach ($builderOrderRows as $orderRow) {
- if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
- $amount = WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent);
- } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
- $amount = $orderRow->amountIncVat;
- } else {
- $amount = $orderRow->amountIncVat;
- $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
- }
- $orderRows[] = new \SoapVar(
- new CancellationAccountCreditRow(
- $amount,
- $this->formatRowNameAndDescription($orderRow),
- $orderRow->vatPercent
- ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service"
- );
- }
-
- return $orderRows;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateOrderId($errors);
- $errors = $this->validateHasRows($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
- $errors = $this->validateDescription($errors);
- $errors = $this->validateCreditOrderRowsHasPriceAndVatInformation($errors);
-
- return $errors;
- }
-
- public function validateOrderId($errors)
- {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required, use setOrderId().");
- }
-
- return $errors;
- }
-
- private function validateHasRows($errors)
- {
- if ((count($this->orderBuilder->rowsToCredit) == 0) &&
- (count($this->orderBuilder->creditOrderRows) == 0)
- ) {
- $errors[] = array('missing value' => "no rows to credit, use setRow(s)ToCredit() or addCreditOrderRow(s)().");
- }
-
- return $errors;
- }
-
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required, use setCountryCode().");
- }
-
- return $errors;
- }
-
- public function validateDescription($errors)
- {
- foreach ($this->orderBuilder->creditOrderRows as $orderRow) {
- if (!isset($orderRow->description)) {
- $errors[] = array('missing value' => "Description is required.");
- }
- }
-
- return $errors;
- }
-
- private function validateCreditOrderRowsHasPriceAndVatInformation($errors)
- {
- foreach ($this->orderBuilder->creditOrderRows as $orderRow) {
- if (!isset($orderRow->vatPercent) && (!isset($orderRow->amountIncVat) && !isset($orderRow->amountExVat))) {
- $errors[] = array('missing order row vat information' => "cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent.");
- }
- }
-
- return $errors;
- }
+ /**
+ * @var CreditOrderRowsBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+ /**
+ * @var \SoapVar[] $orderRows initially empty, specifies any additional credit order rows to credit
+ */
+ public $orderRows;
+
+ /**
+ * @param CreditOrderRowsBuilder $creditOrderRowsBuilder
+ */
+ public function __construct($creditOrderRowsBuilder)
+ {
+ $this->action = "CancelAccountCreditRows";
+ $this->orderRows = [];
+ $this->orderBuilder = $creditOrderRowsBuilder;
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @param bool $resendOrderWithFlippedPriceIncludingVat
+ * @return CreditOrderRowsRequest
+ * @throws ValidationException
+ */
+ public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
+ {
+ $this->validateRequest();
+ $this->orderRows = $this->getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($this->orderBuilder->creditOrderRows);
+ $soapRequest = new CancelAccountCreditRowsRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderRows,
+ $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->orderId
+ );
+
+ return $soapRequest;
+ }
+
+ protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat = NULL)
+ {
+ $amount = 0;
+ $orderRows = [];
+ //if orderrownumber is set, create an orderrow with dummy values. Will be ignored in Svea\WebPay\WebPay WS
+ if (count($this->orderBuilder->rowsToCredit) > 0) {
+ foreach ($this->orderBuilder->rowsToCredit as $rownumber) {
+ $orderRows[] = new \SoapVar(
+ new CancellationAccountCreditRow(
+ 0.00,
+ "Numbered row",
+ 0,
+ $rownumber
+ ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service"
+ );
+ }
+ }
+ //add orderrows if there are any
+ foreach ($builderOrderRows as $orderRow) {
+ if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
+ $amount = WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent);
+ } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
+ $amount = $orderRow->amountIncVat;
+ } else {
+ $amount = $orderRow->amountIncVat;
+ $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
+ }
+ $orderRows[] = new \SoapVar(
+ new CancellationAccountCreditRow(
+ $amount,
+ $this->formatRowNameAndDescription($orderRow),
+ $orderRow->vatPercent
+ ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service"
+ );
+ }
+
+ return $orderRows;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateOrderId($errors);
+ $errors = $this->validateHasRows($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+ $errors = $this->validateDescription($errors);
+ $errors = $this->validateCreditOrderRowsHasPriceAndVatInformation($errors);
+
+ return $errors;
+ }
+
+ public function validateOrderId($errors)
+ {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required, use setOrderId()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateHasRows($errors)
+ {
+ if ((count($this->orderBuilder->rowsToCredit) == 0) &&
+ (count($this->orderBuilder->creditOrderRows) == 0)
+ ) {
+ $errors[] = ['missing value' => "no rows to credit, use setRow(s)ToCredit() or addCreditOrderRow(s)()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required, use setCountryCode()."];
+ }
+
+ return $errors;
+ }
+
+ public function validateDescription($errors)
+ {
+ foreach ($this->orderBuilder->creditOrderRows as $orderRow) {
+ if (!isset($orderRow->description)) {
+ $errors[] = ['missing value' => "Description is required."];
+ }
+ }
+
+ return $errors;
+ }
+
+ private function validateCreditOrderRowsHasPriceAndVatInformation($errors)
+ {
+ foreach ($this->orderBuilder->creditOrderRows as $orderRow) {
+ if (!isset($orderRow->vatPercent) && (!isset($orderRow->amountIncVat) && !isset($orderRow->amountExVat))) {
+ $errors[] = ['missing order row vat information' => "cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent."];
+ }
+ }
+
+ return $errors;
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/CreditAmountAccountCreditRequest.php b/src/AdminService/CreditAmountAccountCreditRequest.php
index 26410671..c104ef76 100644
--- a/src/AdminService/CreditAmountAccountCreditRequest.php
+++ b/src/AdminService/CreditAmountAccountCreditRequest.php
@@ -19,108 +19,108 @@
*/
class CreditAmountAccountCreditRequest extends AdminServiceRequest
{
- /**
- * @var CreditOrderRowsBuilder $orderBuilder
- */
- public $orderBuilder;
-
-
- /**
- * @param CreditAmountBuilder $creditAmountBuilder
- */
- public function __construct($creditAmountBuilder)
- {
- $this->action = "CancelAccountCreditAmount";
- $this->orderBuilder = $creditAmountBuilder;
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @param bool $resendOrderWithFlippedPriceIncludingVat
- * @return CreditOrderRowsRequest
- * @throws ValidationException
- */
- public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
- {
- $this->validateRequest();
- $soapRequest = new CancelAccountCreditAmountRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderBuilder->amountIncVat,
- $this->orderBuilder->description,
- $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->orderId
-
- );
-
- return $soapRequest;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateOrderId($errors);
- $errors = $this->validateCountryCode($errors);
- $errors = $this->validateAmount($errors);
-
- return $errors;
- }
-
- public function validateOrderId($errors)
- {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required, use setOrderId().");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required, use setCountryCode().");
- }
-
- return $errors;
- }
-
- private function validateAmount($errors)
- {
- if (!isset($this->orderBuilder->amountIncVat) || $this->orderBuilder->amountIncVat <= 0) {
- $errors[] = array('incorrect value' => "amountIncVat is too small.");
- } elseif (isset($this->orderBuilder->amountIncVat) &&
- !(is_float($this->orderBuilder->amountIncVat) || is_int($this->orderBuilder->amountIncVat))) {
- $errors[] = array('incorrect datatype' => "amountIncVat is not of type float or int.");
- }
-
- return $errors;
- }
-
- protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat = NULL)
- {
- $amount = 0;
- $orderRows = array();
- foreach ($builderOrderRows as $orderRow) {
- if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
- $amount = WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent);
- } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
- $amount = $orderRow->amountIncVat;
- } else {
- $amount = $orderRow->amountIncVat;
- $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
- }
- $orderRows[] = new SoapVar(
- new CancellationRow(
- $amount,
- $this->formatRowNameAndDescription($orderRow),
- $orderRow->rowNumber,
- $orderRow->vatPercent
- ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice"
- );
- }
-
- return $orderRows;
- }
+ /**
+ * @var CreditOrderRowsBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+
+ /**
+ * @param CreditAmountBuilder $creditAmountBuilder
+ */
+ public function __construct($creditAmountBuilder)
+ {
+ $this->action = "CancelAccountCreditAmount";
+ $this->orderBuilder = $creditAmountBuilder;
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @param bool $resendOrderWithFlippedPriceIncludingVat
+ * @return CreditOrderRowsRequest
+ * @throws ValidationException
+ */
+ public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
+ {
+ $this->validateRequest();
+ $soapRequest = new CancelAccountCreditAmountRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderBuilder->amountIncVat,
+ $this->orderBuilder->description,
+ $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->orderId
+
+ );
+
+ return $soapRequest;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateOrderId($errors);
+ $errors = $this->validateCountryCode($errors);
+ $errors = $this->validateAmount($errors);
+
+ return $errors;
+ }
+
+ public function validateOrderId($errors)
+ {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required, use setOrderId()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required, use setCountryCode()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateAmount($errors)
+ {
+ if (!isset($this->orderBuilder->amountIncVat) || $this->orderBuilder->amountIncVat <= 0) {
+ $errors[] = ['incorrect value' => "amountIncVat is too small."];
+ } elseif (isset($this->orderBuilder->amountIncVat) &&
+ !(is_float($this->orderBuilder->amountIncVat) || is_int($this->orderBuilder->amountIncVat))) {
+ $errors[] = ['incorrect datatype' => "amountIncVat is not of type float or int."];
+ }
+
+ return $errors;
+ }
+
+ protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat = NULL)
+ {
+ $amount = 0;
+ $orderRows = [];
+ foreach ($builderOrderRows as $orderRow) {
+ if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
+ $amount = WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent);
+ } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
+ $amount = $orderRow->amountIncVat;
+ } else {
+ $amount = $orderRow->amountIncVat;
+ $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
+ }
+ $orderRows[] = new SoapVar(
+ new CancellationRow(
+ $amount,
+ $this->formatRowNameAndDescription($orderRow),
+ $orderRow->rowNumber,
+ $orderRow->vatPercent
+ ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice"
+ );
+ }
+
+ return $orderRows;
+ }
}
diff --git a/src/AdminService/CreditAmountRequest.php b/src/AdminService/CreditAmountRequest.php
index c101db73..c2290bdc 100644
--- a/src/AdminService/CreditAmountRequest.php
+++ b/src/AdminService/CreditAmountRequest.php
@@ -19,117 +19,117 @@
class CreditAmountRequest extends AdminServiceRequest
{
- /**
- * @var CreditOrderRowsBuilder $orderBuilder
- */
- public $orderBuilder;
-
- /**
- * @param CreditAmountBuilder $creditAmountBuilder
- */
- public function __construct($creditAmountBuilder)
- {
- $this->action = "CancelPaymentPlanAmount";
- $this->orderBuilder = $creditAmountBuilder;
-
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @param bool $resendOrderWithFlippedPriceIncludingVat
- * @return CreditOrderRowsRequest
- * @throws ValidationException
- */
- public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
- {
- $this->validateRequest();
- $soapRequest = new CancelPaymentPlanAmountRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderBuilder->amountIncVat,
- $this->orderBuilder->description,
- $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->contractNumber
-
- );
-
- return $soapRequest;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateContractNumber($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
- $errors = $this->validateAmount($errors);
-
- return $errors;
- }
-
- public function validateContractNumber($errors)
- {
- if (isset($this->orderBuilder->contractNumber) == FALSE) {
- $errors[] = array('missing value' => "contractNumber is required, use setContractNumber().");
- }
-
- return $errors;
- }
-
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required, use setCountryCode().");
- }
-
- return $errors;
- }
-
- private function validateAmount($errors)
- {
- if (!isset($this->orderBuilder->amountIncVat) || $this->orderBuilder->amountIncVat <= 0) {
- $errors[] = array('incorrect value' => "amountIncVat is too small.");
- } elseif (isset($this->orderBuilder->amountIncVat) && !(is_float($this->orderBuilder->amountIncVat) || is_int($this->orderBuilder->amountIncVat))) {
- $errors[] = array('incorrect datatype' => "amountIncVat is not of type float or float.");
- }
-
- return $errors;
- }
-
- protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat = NULL)
- {
- $amount = 0;
- $orderRows = array();
- foreach ($builderOrderRows as $orderRow) {
- if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
- $amount = WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent);
- } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
- $amount = $orderRow->amountIncVat;
- } else {
- $amount = $orderRow->amountIncVat;
- $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
- }
- $orderRows[] = new SoapVar(
- new CancellationRow(
- $amount,
- $this->formatRowNameAndDescription($orderRow),
- $orderRow->rowNumber,
- $orderRow->vatPercent
- ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice"
- );
- }
-
- return $orderRows;
- }
+ /**
+ * @var CreditOrderRowsBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+ /**
+ * @param CreditAmountBuilder $creditAmountBuilder
+ */
+ public function __construct($creditAmountBuilder)
+ {
+ $this->action = "CancelPaymentPlanAmount";
+ $this->orderBuilder = $creditAmountBuilder;
+
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @param bool $resendOrderWithFlippedPriceIncludingVat
+ * @return CreditOrderRowsRequest
+ * @throws ValidationException
+ */
+ public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
+ {
+ $this->validateRequest();
+ $soapRequest = new CancelPaymentPlanAmountRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderBuilder->amountIncVat,
+ $this->orderBuilder->description,
+ $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->contractNumber
+
+ );
+
+ return $soapRequest;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateContractNumber($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+ $errors = $this->validateAmount($errors);
+
+ return $errors;
+ }
+
+ public function validateContractNumber($errors)
+ {
+ if (isset($this->orderBuilder->contractNumber) == FALSE) {
+ $errors[] = ['missing value' => "contractNumber is required, use setContractNumber()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required, use setCountryCode()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateAmount($errors)
+ {
+ if (!isset($this->orderBuilder->amountIncVat) || $this->orderBuilder->amountIncVat <= 0) {
+ $errors[] = ['incorrect value' => "amountIncVat is too small."];
+ } elseif (isset($this->orderBuilder->amountIncVat) && !(is_float($this->orderBuilder->amountIncVat) || is_int($this->orderBuilder->amountIncVat))) {
+ $errors[] = ['incorrect datatype' => "amountIncVat is not of type float or float."];
+ }
+
+ return $errors;
+ }
+
+ protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat = NULL)
+ {
+ $amount = 0;
+ $orderRows = [];
+ foreach ($builderOrderRows as $orderRow) {
+ if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
+ $amount = WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent);
+ } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
+ $amount = $orderRow->amountIncVat;
+ } else {
+ $amount = $orderRow->amountIncVat;
+ $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
+ }
+ $orderRows[] = new SoapVar(
+ new CancellationRow(
+ $amount,
+ $this->formatRowNameAndDescription($orderRow),
+ $orderRow->rowNumber,
+ $orderRow->vatPercent
+ ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice"
+ );
+ }
+
+ return $orderRows;
+ }
}
diff --git a/src/AdminService/CreditInvoiceRowsRequest.php b/src/AdminService/CreditInvoiceRowsRequest.php
index 50bd822f..c8313c70 100644
--- a/src/AdminService/CreditInvoiceRowsRequest.php
+++ b/src/AdminService/CreditInvoiceRowsRequest.php
@@ -14,133 +14,133 @@
*/
class CreditInvoiceRowsRequest extends AdminServiceRequest
{
- /**
- * @var CreditOrderRowsBuilder $orderBuilder
- */
- public $orderBuilder;
-
- /**
- * @var \SoapVar[] $rowNumbers initally empty, contains the indexes of all order rows that will be credited
- */
- public $rowNumbers;
-
- /**
- * @var \SoapVar[] $orderRows initially empty, specifies any additional credit order rows to credit
- */
- public $orderRows;
-
- /**
- * @param CreditOrderRowsBuilder $creditOrderRowsBuilder
- */
- public function __construct($creditOrderRowsBuilder)
- {
- $this->action = "CreditInvoiceRows";
- $this->orderBuilder = $creditOrderRowsBuilder;
- $this->rowNumbers = array();
- $this->orderRows = array();
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @param bool $resendOrderWithFlippedPriceIncludingVat
- * @return CreditOrderRowsRequest
- * @throws ValidationException
- */
- public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
- {
- $this->validateRequest();
- $this->priceIncludingVat = $this->determineVatFlag($this->orderBuilder->creditOrderRows, $resendOrderWithFlippedPriceIncludingVat);
- $this->orderRows =
- $this->getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($this->orderBuilder->creditOrderRows, $this->priceIncludingVat);
-
- foreach ($this->orderBuilder->rowsToCredit as $rowToCredit) {
- $this->rowNumbers[] = new \SoapVar($rowToCredit, XSD_LONG, null, null, 'long', "http://schemas.microsoft.com/2003/10/Serialization/Arrays");
- }
-
- $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\CreditInvoiceRowsRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->distributionType,
- $this->orderBuilder->invoiceId,
- $this->orderRows,
- $this->rowNumbers
- );
-
- return $soapRequest;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateInvoiceId($errors);
- $errors = $this->validateInvoiceDistributionType($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
- $errors = $this->validateHasRows($errors);
- $errors = $this->validateCreditOrderRowsHasPriceAndVatInformation($errors);
-
- return $errors;
- }
-
- private function validateInvoiceId($errors)
- {
- if (isset($this->orderBuilder->invoiceId) == FALSE) {
- $errors[] = array('missing value' => "invoiceId is required, use setInvoiceId().");
- }
-
- return $errors;
- }
-
- private function validateInvoiceDistributionType($errors)
- {
- if (isset($this->orderBuilder->distributionType) == FALSE) {
- $errors[] = array('missing value' => "distributionType is required, use setInvoiceDistributionType().");
- }
-
- return $errors;
- }
-
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required, use setCountryCode().");
- }
-
- return $errors;
- }
-
- private function validateHasRows($errors)
- {
- if ((count($this->orderBuilder->rowsToCredit) == 0) &&
- (count($this->orderBuilder->creditOrderRows) == 0)
- ) {
- $errors[] = array('missing value' => "no rows to credit, use setRow(s)ToCredit() or addCreditOrderRow(s)().");
- }
-
- return $errors;
- }
-
- private function validateCreditOrderRowsHasPriceAndVatInformation($errors)
- {
- foreach ($this->orderBuilder->creditOrderRows as $orderRow) {
- if (!isset($orderRow->vatPercent) && (!isset($orderRow->amountIncVat) && !isset($orderRow->amountExVat))) {
- $errors[] = array('missing order row vat information' => "cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent.");
- }
- }
-
- return $errors;
- }
+ /**
+ * @var CreditOrderRowsBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+ /**
+ * @var \SoapVar[] $rowNumbers initally empty, contains the indexes of all order rows that will be credited
+ */
+ public $rowNumbers;
+
+ /**
+ * @var \SoapVar[] $orderRows initially empty, specifies any additional credit order rows to credit
+ */
+ public $orderRows;
+
+ /**
+ * @param CreditOrderRowsBuilder $creditOrderRowsBuilder
+ */
+ public function __construct($creditOrderRowsBuilder)
+ {
+ $this->action = "CreditInvoiceRows";
+ $this->orderBuilder = $creditOrderRowsBuilder;
+ $this->rowNumbers = [];
+ $this->orderRows = [];
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @param bool $resendOrderWithFlippedPriceIncludingVat
+ * @return CreditOrderRowsRequest
+ * @throws ValidationException
+ */
+ public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
+ {
+ $this->validateRequest();
+ $this->priceIncludingVat = $this->determineVatFlag($this->orderBuilder->creditOrderRows, $resendOrderWithFlippedPriceIncludingVat);
+ $this->orderRows =
+ $this->getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($this->orderBuilder->creditOrderRows, $this->priceIncludingVat);
+
+ foreach ($this->orderBuilder->rowsToCredit as $rowToCredit) {
+ $this->rowNumbers[] = new \SoapVar($rowToCredit, XSD_LONG, null, null, 'long', "http://schemas.microsoft.com/2003/10/Serialization/Arrays");
+ }
+
+ $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\CreditInvoiceRowsRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->distributionType,
+ $this->orderBuilder->invoiceId,
+ $this->orderRows,
+ $this->rowNumbers
+ );
+
+ return $soapRequest;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateInvoiceId($errors);
+ $errors = $this->validateInvoiceDistributionType($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+ $errors = $this->validateHasRows($errors);
+ $errors = $this->validateCreditOrderRowsHasPriceAndVatInformation($errors);
+
+ return $errors;
+ }
+
+ private function validateInvoiceId($errors)
+ {
+ if (isset($this->orderBuilder->invoiceId) == FALSE) {
+ $errors[] = ['missing value' => "invoiceId is required, use setInvoiceId()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateInvoiceDistributionType($errors)
+ {
+ if (isset($this->orderBuilder->distributionType) == FALSE) {
+ $errors[] = ['missing value' => "distributionType is required, use setInvoiceDistributionType()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required, use setCountryCode()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateHasRows($errors)
+ {
+ if ((count($this->orderBuilder->rowsToCredit) == 0) &&
+ (count($this->orderBuilder->creditOrderRows) == 0)
+ ) {
+ $errors[] = ['missing value' => "no rows to credit, use setRow(s)ToCredit() or addCreditOrderRow(s)()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCreditOrderRowsHasPriceAndVatInformation($errors)
+ {
+ foreach ($this->orderBuilder->creditOrderRows as $orderRow) {
+ if (!isset($orderRow->vatPercent) && (!isset($orderRow->amountIncVat) && !isset($orderRow->amountExVat))) {
+ $errors[] = ['missing order row vat information' => "cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent."];
+ }
+ }
+
+ return $errors;
+ }
}
diff --git a/src/AdminService/CreditPaymentPlanRowsRequest.php b/src/AdminService/CreditPaymentPlanRowsRequest.php
index 47a1009b..2f252f15 100644
--- a/src/AdminService/CreditPaymentPlanRowsRequest.php
+++ b/src/AdminService/CreditPaymentPlanRowsRequest.php
@@ -17,159 +17,159 @@
*/
class CreditPaymentPlanRowsRequest extends AdminServiceRequest
{
- /**
- * @var CreditOrderRowsBuilder $orderBuilder
- */
- public $orderBuilder;
-
- /**
- * @var \SoapVar[] $orderRows initially empty, specifies any additional credit order rows to credit
- */
- public $orderRows;
-
- /**
- * @param CreditOrderRowsBuilder $creditOrderRowsBuilder
- */
- public function __construct($creditOrderRowsBuilder)
- {
- $this->action = "CancelPaymentPlanRows";
- $this->orderRows = array();
- $this->orderBuilder = $creditOrderRowsBuilder;
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @param bool $resendOrderWithFlippedPriceIncludingVat
- * @return CreditOrderRowsRequest
- * @throws ValidationException
- */
- public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
- {
- $this->validateRequest();
- $this->orderRows = $this->getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($this->orderBuilder->creditOrderRows);
- $soapRequest = new CancelPaymentPlanRowsRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderRows,
- $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->contractNumber
- );
-
- return $soapRequest;
- }
-
- protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat = NULL)
- {
- $amount = 0;
- $orderRows = array();
- //if orderrownumber is set, create an orderrow with dummy values. Will be ignored in Svea\WebPay\WebPay WS
- if (count($this->orderBuilder->rowsToCredit) > 0) {
- foreach ($this->orderBuilder->rowsToCredit as $rownumber) {
- $orderRows[] = new \SoapVar(
- new CancellationRow(
- 0.00,
- "Numbered row",
- 0,
- $rownumber
- ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice"
- );
- }
- }
- //add orderrows if there are any
- foreach ($builderOrderRows as $orderRow) {
- if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
- $amount = WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent);
- } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
- $amount = $orderRow->amountIncVat;
- } else {
- $amount = $orderRow->amountIncVat;
- $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
- }
- $orderRows[] = new \SoapVar(
- new CancellationRow(
- $amount,
- $this->formatRowNameAndDescription($orderRow),
- $orderRow->vatPercent
- ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice"
- );
- }
-
- return $orderRows;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateContractNumber($errors);
- $errors = $this->validateHasRows($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
- $errors = $this->validateDescription($errors);
- $errors = $this->validateCreditOrderRowsHasPriceAndVatInformation($errors);
-
- return $errors;
- }
-
- public function validateContractNumber($errors)
- {
- if (isset($this->orderBuilder->contractNumber) == FALSE) {
- $errors[] = array('missing value' => "contractNumber is required, use setContractNumber().");
- }
-
- return $errors;
- }
-
- private function validateHasRows($errors)
- {
- if ((count($this->orderBuilder->rowsToCredit) == 0) &&
- (count($this->orderBuilder->creditOrderRows) == 0)
- ) {
- $errors[] = array('missing value' => "no rows to credit, use setRow(s)ToCredit() or addCreditOrderRow(s)().");
- }
-
- return $errors;
- }
-
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required, use setCountryCode().");
- }
-
- return $errors;
- }
-
- public function validateDescription($errors)
- {
- foreach ($this->orderBuilder->creditOrderRows as $orderRow) {
- if (!isset($orderRow->description)) {
- $errors[] = array('missing value' => "Description is required.");
- }
- }
-
- return $errors;
- }
-
- private function validateCreditOrderRowsHasPriceAndVatInformation($errors)
- {
- foreach ($this->orderBuilder->creditOrderRows as $orderRow) {
- if (!isset($orderRow->vatPercent) && (!isset($orderRow->amountIncVat) && !isset($orderRow->amountExVat))) {
- $errors[] = array('missing order row vat information' => "cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent.");
- }
- }
-
- return $errors;
- }
+ /**
+ * @var CreditOrderRowsBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+ /**
+ * @var \SoapVar[] $orderRows initially empty, specifies any additional credit order rows to credit
+ */
+ public $orderRows;
+
+ /**
+ * @param CreditOrderRowsBuilder $creditOrderRowsBuilder
+ */
+ public function __construct($creditOrderRowsBuilder)
+ {
+ $this->action = "CancelPaymentPlanRows";
+ $this->orderRows = [];
+ $this->orderBuilder = $creditOrderRowsBuilder;
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @param bool $resendOrderWithFlippedPriceIncludingVat
+ * @return CreditOrderRowsRequest
+ * @throws ValidationException
+ */
+ public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
+ {
+ $this->validateRequest();
+ $this->orderRows = $this->getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($this->orderBuilder->creditOrderRows);
+ $soapRequest = new CancelPaymentPlanRowsRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderRows,
+ $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->contractNumber
+ );
+
+ return $soapRequest;
+ }
+
+ protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builderOrderRows, $priceIncludingVat = NULL)
+ {
+ $amount = 0;
+ $orderRows = [];
+ //if orderrownumber is set, create an orderrow with dummy values. Will be ignored in Svea\WebPay\WebPay WS
+ if (count($this->orderBuilder->rowsToCredit) > 0) {
+ foreach ($this->orderBuilder->rowsToCredit as $rownumber) {
+ $orderRows[] = new \SoapVar(
+ new CancellationRow(
+ 0.00,
+ "Numbered row",
+ 0,
+ $rownumber
+ ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice"
+ );
+ }
+ }
+ //add orderrows if there are any
+ foreach ($builderOrderRows as $orderRow) {
+ if (isset($orderRow->vatPercent) && isset($orderRow->amountExVat)) {
+ $amount = WebServiceRowFormatter::convertExVatToIncVat($orderRow->amountExVat, $orderRow->vatPercent);
+ } elseif (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) {
+ $amount = $orderRow->amountIncVat;
+ } else {
+ $amount = $orderRow->amountIncVat;
+ $orderRow->vatPercent = WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat);
+ }
+ $orderRows[] = new \SoapVar(
+ new CancellationRow(
+ $amount,
+ $this->formatRowNameAndDescription($orderRow),
+ $orderRow->vatPercent
+ ), SOAP_ENC_OBJECT, null, null, 'CancellationRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice"
+ );
+ }
+
+ return $orderRows;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateContractNumber($errors);
+ $errors = $this->validateHasRows($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+ $errors = $this->validateDescription($errors);
+ $errors = $this->validateCreditOrderRowsHasPriceAndVatInformation($errors);
+
+ return $errors;
+ }
+
+ public function validateContractNumber($errors)
+ {
+ if (isset($this->orderBuilder->contractNumber) == FALSE) {
+ $errors[] = ['missing value' => "contractNumber is required, use setContractNumber()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateHasRows($errors)
+ {
+ if ((count($this->orderBuilder->rowsToCredit) == 0) &&
+ (count($this->orderBuilder->creditOrderRows) == 0)
+ ) {
+ $errors[] = ['missing value' => "no rows to credit, use setRow(s)ToCredit() or addCreditOrderRow(s)()."];
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required, use setCountryCode()."];
+ }
+
+ return $errors;
+ }
+
+ public function validateDescription($errors)
+ {
+ foreach ($this->orderBuilder->creditOrderRows as $orderRow) {
+ if (!isset($orderRow->description)) {
+ $errors[] = ['missing value' => "Description is required."];
+ }
+ }
+
+ return $errors;
+ }
+
+ private function validateCreditOrderRowsHasPriceAndVatInformation($errors)
+ {
+ foreach ($this->orderBuilder->creditOrderRows as $orderRow) {
+ if (!isset($orderRow->vatPercent) && (!isset($orderRow->amountIncVat) && !isset($orderRow->amountExVat))) {
+ $errors[] = ['missing order row vat information' => "cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent."];
+ }
+ }
+
+ return $errors;
+ }
}
diff --git a/src/AdminService/DeliverOrderRowsRequest.php b/src/AdminService/DeliverOrderRowsRequest.php
index 9c1d5b0f..75fe1da4 100644
--- a/src/AdminService/DeliverOrderRowsRequest.php
+++ b/src/AdminService/DeliverOrderRowsRequest.php
@@ -17,95 +17,95 @@
*/
class DeliverOrderRowsRequest extends AdminServiceRequest
{
- /**
- * @var DeliverOrderRowsBuilder $orderBuilder
- */
- public $orderBuilder;
-
- /**
- * @param DeliverOrderRowsBuilder $deliverOrderRowsBuilder
- */
- public function __construct($deliverOrderRowsBuilder)
- {
- $this->action = "DeliverPartial";
- $this->orderBuilder = $deliverOrderRowsBuilder;
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @return DeliverOrderRowsRequest
- * @throws ValidationException
- */
- public function prepareRequest()
- {
- $this->validateRequest();
-
- foreach ($this->orderBuilder->rowsToDeliver as $rowToDeliver) {
- $this->rowNumbers[] = new SoapVar($rowToDeliver, XSD_LONG, null, null, 'long', "http://schemas.microsoft.com/2003/10/Serialization/Arrays");
- }
-
- $soapRequest = new DeliverPartialRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderBuilder->distributionType,
-
- new OrderToDeliver(
- $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
- $this->orderBuilder->orderId
- ),
- $this->rowNumbers
- );
-
- return $soapRequest;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateOrderId($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
- $errors = $this->validateRowsToDeliver($errors);
-
- return $errors;
- }
-
- private function validateOrderId($errors)
- {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required.");
- }
-
- return $errors;
- }
-
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required.");
- }
-
- return $errors;
- }
-
- private function validateRowsToDeliver($errors)
- {
- if (isset($this->orderBuilder->rowsToDeliver) == FALSE) {
- $errors[] = array('missing value' => "rowsToDeliver is required.");
- }
-
- return $errors;
- }
-}
+ /**
+ * @var DeliverOrderRowsBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+ /**
+ * @param DeliverOrderRowsBuilder $deliverOrderRowsBuilder
+ */
+ public function __construct($deliverOrderRowsBuilder)
+ {
+ $this->action = "DeliverPartial";
+ $this->orderBuilder = $deliverOrderRowsBuilder;
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @return DeliverOrderRowsRequest
+ * @throws ValidationException
+ */
+ public function prepareRequest()
+ {
+ $this->validateRequest();
+
+ foreach ($this->orderBuilder->rowsToDeliver as $rowToDeliver) {
+ $this->rowNumbers[] = new SoapVar($rowToDeliver, XSD_LONG, null, null, 'long', "http://schemas.microsoft.com/2003/10/Serialization/Arrays");
+ }
+
+ $soapRequest = new DeliverPartialRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderBuilder->distributionType,
+
+ new OrderToDeliver(
+ $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
+ $this->orderBuilder->orderId
+ ),
+ $this->rowNumbers
+ );
+
+ return $soapRequest;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateOrderId($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+ $errors = $this->validateRowsToDeliver($errors);
+
+ return $errors;
+ }
+
+ private function validateOrderId($errors)
+ {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateRowsToDeliver($errors)
+ {
+ if (isset($this->orderBuilder->rowsToDeliver) == FALSE) {
+ $errors[] = ['missing value' => "rowsToDeliver is required."];
+ }
+
+ return $errors;
+ }
+}
diff --git a/src/AdminService/DeliverOrdersRequest.php b/src/AdminService/DeliverOrdersRequest.php
index 2993e214..8004f191 100644
--- a/src/AdminService/DeliverOrdersRequest.php
+++ b/src/AdminService/DeliverOrdersRequest.php
@@ -17,100 +17,100 @@
*/
class DeliverOrdersRequest extends AdminServiceRequest
{
- /**
- * @var DeliverOrderBuilder $orderBuilder
- */
- public $orderBuilder;
-
- /**
- * @param deliverOrderBuilder $deliverOrderBuilder
- */
- public function __construct($deliverOrderBuilder)
- {
- $this->action = "DeliverOrders";
- $this->orderBuilder = $deliverOrderBuilder;
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @return \Svea\WebPay\AdminService\AdminSoap\DeliverOrdersRequest
- */
- public function prepareRequest()
- {
- $this->validateRequest();
-
- $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\DeliverOrdersRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername($this->orderBuilder->orderType, $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword($this->orderBuilder->orderType, $this->orderBuilder->countryCode)
- ),
- $this->orderBuilder->distributionType,
- new OrdersToDeliver(
- new DeliverOrderInformation(
- $this->orderBuilder->conf->getClientNumber($this->orderBuilder->orderType, $this->orderBuilder->countryCode),
- AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
- $this->orderBuilder->orderId
- )
- )
- );
-
- return $soapRequest;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateDistributionType($errors);
- $errors = $this->validateOrderId($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
-
- return $errors;
- }
-
- private function validateDistributionType($errors)
- {
- if (isset($this->orderBuilder->distributionType) == FALSE) {
- $errors[] = array('missing value' => "distributionType is required.");
- }
- else
- {
- if(isset($this->orderBuilder->orderType) == TRUE && $this->orderBuilder->orderType == ConfigurationProvider::INVOICE_TYPE)
- {
- if(isset($this->orderBuilder->distributionType) == TRUE && $this->orderBuilder->distributionType == DistributionType::EINVOICEB2B && $this->orderBuilder->countryCode != "NO")
- {
- $errors[] = array('incorrect value' => "distributionType EInvoiceB2B is only allowed for Norway.");
- }
- }
- }
-
- return $errors;
- }
-
- private function validateOrderId($errors)
- {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required.");
- }
-
- return $errors;
- }
-
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required.");
- }
-
- return $errors;
- }
-}
+ /**
+ * @var DeliverOrderBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+ /**
+ * @param deliverOrderBuilder $deliverOrderBuilder
+ */
+ public function __construct($deliverOrderBuilder)
+ {
+ $this->action = "DeliverOrders";
+ $this->orderBuilder = $deliverOrderBuilder;
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @return \Svea\WebPay\AdminService\AdminSoap\DeliverOrdersRequest
+ */
+ public function prepareRequest()
+ {
+ $this->validateRequest();
+
+ $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\DeliverOrdersRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername($this->orderBuilder->orderType, $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword($this->orderBuilder->orderType, $this->orderBuilder->countryCode)
+ ),
+ $this->orderBuilder->distributionType,
+ new OrdersToDeliver(
+ new DeliverOrderInformation(
+ $this->orderBuilder->conf->getClientNumber($this->orderBuilder->orderType, $this->orderBuilder->countryCode),
+ AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
+ $this->orderBuilder->orderId
+ )
+ )
+ );
+
+ return $soapRequest;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateDistributionType($errors);
+ $errors = $this->validateOrderId($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+
+ return $errors;
+ }
+
+ private function validateDistributionType($errors)
+ {
+ if (isset($this->orderBuilder->distributionType) == FALSE) {
+ $errors[] = ['missing value' => "distributionType is required."];
+ }
+ else
+ {
+ if(isset($this->orderBuilder->orderType) == TRUE && $this->orderBuilder->orderType == ConfigurationProvider::INVOICE_TYPE)
+ {
+ if(isset($this->orderBuilder->distributionType) == TRUE && $this->orderBuilder->distributionType == DistributionType::EINVOICEB2B && $this->orderBuilder->countryCode != "NO")
+ {
+ $errors[] = ['incorrect value' => "distributionType EInvoiceB2B is only allowed for Norway."];
+ }
+ }
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderId($errors)
+ {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required."];
+ }
+
+ return $errors;
+ }
+}
diff --git a/src/AdminService/GetOrdersRequest.php b/src/AdminService/GetOrdersRequest.php
index 7375b5e5..ad8e5e0e 100644
--- a/src/AdminService/GetOrdersRequest.php
+++ b/src/AdminService/GetOrdersRequest.php
@@ -14,78 +14,78 @@
*/
class GetOrdersRequest extends AdminServiceRequest
{
- /**
- * @var QueryOrderBuilder $orderBuilder
- */
- public $orderBuilder;
- /**
- * @param QueryOrderBuilder $builder
- */
- public function __construct($builder)
- {
- $this->action = "GetOrders";
- $this->orderBuilder = $builder;
- }
+ /**
+ * @var QueryOrderBuilder $orderBuilder
+ */
+ public $orderBuilder;
+ /**
+ * @param QueryOrderBuilder $builder
+ */
+ public function __construct($builder)
+ {
+ $this->action = "GetOrders";
+ $this->orderBuilder = $builder;
+ }
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @return \Svea\WebPay\AdminService\AdminSoap\GetOrdersRequest
- */
- public function prepareRequest()
- {
- $this->validateRequest();
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @return \Svea\WebPay\AdminService\AdminSoap\GetOrdersRequest
+ */
+ public function prepareRequest()
+ {
+ $this->validateRequest();
- $soapRequest = array();
- $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\GetOrdersRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- new OrdersToRetrieve(
- new GetOrderInformation(
- $this->orderBuilder->conf->getClientNumber( ($this->orderBuilder->orderType), $this->orderBuilder->countryCode ),
- $this->orderBuilder->orderId
- )
- )
- );
+ $soapRequest = [];
+ $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\GetOrdersRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ new OrdersToRetrieve(
+ new GetOrderInformation(
+ $this->orderBuilder->conf->getClientNumber( ($this->orderBuilder->orderType), $this->orderBuilder->countryCode ),
+ $this->orderBuilder->orderId
+ )
+ )
+ );
- return $soapRequest;
- }
+ return $soapRequest;
+ }
- public function validate()
- {
- $errors = array();
- $errors = $this->validateOrderId($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateOrderId($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
- return $errors;
- }
+ return $errors;
+ }
- private function validateOrderId($errors)
- {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required.");
- }
+ private function validateOrderId($errors)
+ {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required."];
+ }
- return $errors;
- }
+ return $errors;
+ }
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
- return $errors;
- }
+ return $errors;
+ }
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required.");
- }
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required."];
+ }
- return $errors;
- }
-}
+ return $errors;
+ }
+}
diff --git a/src/AdminService/SearchOrdersRequest.php b/src/AdminService/SearchOrdersRequest.php
index a3d8b3ac..6f813e95 100644
--- a/src/AdminService/SearchOrdersRequest.php
+++ b/src/AdminService/SearchOrdersRequest.php
@@ -7,53 +7,53 @@
class SearchOrdersRequest extends AdminServiceRequest
{
- /**
- * @var QueryOrderBuilder $orderBuilder
- */
- public $orderBuilder;
-
- /**
- * @param QueryOrderBuilder $builder
- */
- public function __construct($builder)
- {
- $this->action = "GetAccountCredits";
- $this->orderBuilder = $builder;
- }
-
-
- function prepareRequest()
- {
- $this->validateRequest();
-
- $soapRequest = array();
- $soapRequest = new SearchOrdersSoapRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderBuilder->getClientAccountCreditInformation()
- );
-
- return $soapRequest;
- }
-
- public function validate()
- {
- $errors = array();
- // $errors = $this->validateOrderId($errors);
- // $errors = $this->validateOrderType($errors);
- // $errors = $this->validateCountryCode($errors);
-
- return $errors;
- }
-
- private function validateOrderId($errors)
- {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required.");
- }
-
- return $errors;
- }
+ /**
+ * @var QueryOrderBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+ /**
+ * @param QueryOrderBuilder $builder
+ */
+ public function __construct($builder)
+ {
+ $this->action = "GetAccountCredits";
+ $this->orderBuilder = $builder;
+ }
+
+
+ function prepareRequest()
+ {
+ $this->validateRequest();
+
+ $soapRequest = [];
+ $soapRequest = new SearchOrdersSoapRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderBuilder->getClientAccountCreditInformation()
+ );
+
+ return $soapRequest;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ // $errors = $this->validateOrderId($errors);
+ // $errors = $this->validateOrderType($errors);
+ // $errors = $this->validateCountryCode($errors);
+
+ return $errors;
+ }
+
+ private function validateOrderId($errors)
+ {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required."];
+ }
+
+ return $errors;
+ }
}
\ No newline at end of file
diff --git a/src/AdminService/UpdateOrderRequest.php b/src/AdminService/UpdateOrderRequest.php
index 411691ec..74309cda 100644
--- a/src/AdminService/UpdateOrderRequest.php
+++ b/src/AdminService/UpdateOrderRequest.php
@@ -13,88 +13,88 @@
*/
class UpdateOrderRequest extends AdminServiceRequest
{
- /**
- * @var UpdateOrderRowsBuilder $orderBuilder
- */
- public $orderBuilder;
-
- /**
- * @param UpdateOrderBuilder $updateOrderBuilder
- */
- public function __construct($updateOrderBuilder)
- {
- $this->action = "UpdateOrder";
- $this->orderBuilder = $updateOrderBuilder;
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @return \Svea\WebPay\AdminService\AdminSoap\UpdateOrderRequest
- * @throws ValidationException
- */
- public function prepareRequest()
- {
- $this->validateRequest();
- $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\UpdateOrderRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
- $this->orderBuilder->orderId,
- $this->orderBuilder->clientOrderNumber,
- $this->orderBuilder->notes
-
- );
-
- return $soapRequest;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateOrderId($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
- $errors = $this->validateStringLength($errors);
-
- return $errors;
- }
-
- private function validateOrderId($errors)
- {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required.");
- }
-
- return $errors;
- }
-
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required.");
- }
-
- return $errors;
- }
-
- private function validateStringLength($errors)
- {
- if (strlen($this->orderBuilder->notes) > 200) {
- $errors[] = array('String length' => "The field Notes must be a string with a maximum length of 200.");
- }
-
- return $errors;
- }
+ /**
+ * @var UpdateOrderRowsBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+ /**
+ * @param UpdateOrderBuilder $updateOrderBuilder
+ */
+ public function __construct($updateOrderBuilder)
+ {
+ $this->action = "UpdateOrder";
+ $this->orderBuilder = $updateOrderBuilder;
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @return \Svea\WebPay\AdminService\AdminSoap\UpdateOrderRequest
+ * @throws ValidationException
+ */
+ public function prepareRequest()
+ {
+ $this->validateRequest();
+ $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\UpdateOrderRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
+ $this->orderBuilder->orderId,
+ $this->orderBuilder->clientOrderNumber,
+ $this->orderBuilder->notes
+
+ );
+
+ return $soapRequest;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateOrderId($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+ $errors = $this->validateStringLength($errors);
+
+ return $errors;
+ }
+
+ private function validateOrderId($errors)
+ {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateStringLength($errors)
+ {
+ if (strlen($this->orderBuilder->notes) > 200) {
+ $errors[] = ['String length' => "The field Notes must be a string with a maximum length of 200."];
+ }
+
+ return $errors;
+ }
}
diff --git a/src/AdminService/UpdateOrderRowsRequest.php b/src/AdminService/UpdateOrderRowsRequest.php
index f9f65491..f5ab7ba6 100644
--- a/src/AdminService/UpdateOrderRowsRequest.php
+++ b/src/AdminService/UpdateOrderRowsRequest.php
@@ -15,117 +15,117 @@
*/
class UpdateOrderRowsRequest extends AdminServiceRequest
{
- /**
- * @var UpdateOrderRowsBuilder $orderBuilder
- */
- public $orderBuilder;
-
- private $amount;
-
- /**
- * @param UpdateOrderRowsBuilder $updateOrderRowsBuilder
- */
- public function __construct($updateOrderRowsBuilder)
- {
- $this->action = "UpdateOrderRows";
- $this->orderBuilder = $updateOrderRowsBuilder;
- }
-
- /**
- * populate and return soap request contents using AdminSoap helper classes to get the correct data format
- * @param bool $resendOrderWithFlippedPriceIncludingVat
- * @return AdminSoap\UpdateOrderRowsRequest
- * @throws ValidationException
- */
- public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
- {
- $this->validateRequest();
- $this->priceIncludingVat = $this->determineVatFlag($this->orderBuilder->numberedOrderRows, $resendOrderWithFlippedPriceIncludingVat);
- $updatedOrderRows =
- $this->getAdminSoapNumberedOrderRowsFromBuilderOrderRowsUsingVatFlag($this->orderBuilder->numberedOrderRows, $this->priceIncludingVat);
-
- $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\UpdateOrderRowsRequest(
- new Authentication(
- $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
- ),
- $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
- AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
- $this->orderBuilder->orderId,
- new SoapVar($updatedOrderRows, SOAP_ENC_OBJECT)
- );
-
- return $soapRequest;
- }
-
- public function validate()
- {
- $errors = array();
- $errors = $this->validateOrderId($errors);
- $errors = $this->validateRowNumber($errors);
- $errors = $this->validateOrderType($errors);
- $errors = $this->validateCountryCode($errors);
- $errors = $this->validateNumberedOrderRowsExist($errors);
- $errors = $this->validateNumberedOrderRowsHasPriceAndVatInformation($errors);
-
- return $errors;
- }
-
- private function validateOrderId($errors)
- {
- if (isset($this->orderBuilder->orderId) == FALSE) {
- $errors[] = array('missing value' => "orderId is required.");
- }
-
- return $errors;
- }
-
- private function validateRowNumber($errors)
- {
- foreach ($this->orderBuilder->numberedOrderRows as $orderRow) {
- if (isset($orderRow->rowNumber) == FALSE) {
- $errors[] = array('missing value' => "rowNumber is required.");
- }
- }
-
- return $errors;
- }
-
- private function validateOrderType($errors)
- {
- if (isset($this->orderBuilder->orderType) == FALSE) {
- $errors[] = array('missing value' => "orderType is required.");
- }
-
- return $errors;
- }
-
- private function validateCountryCode($errors)
- {
- if (isset($this->orderBuilder->countryCode) == FALSE) {
- $errors[] = array('missing value' => "countryCode is required.");
- }
-
- return $errors;
- }
-
- private function validateNumberedOrderRowsExist($errors)
- {
- if (isset($this->orderBuilder->numberedOrderRows) == FALSE) {
- $errors[] = array('missing value' => "numberedOrderRows is required.");
- }
-
- return $errors;
- }
-
- private function validateNumberedOrderRowsHasPriceAndVatInformation($errors)
- {
- foreach ($this->orderBuilder->numberedOrderRows as $orderRow) {
- if (!isset($orderRow->vatPercent) && (!isset($orderRow->amountIncVat) && !isset($orderRow->amountExVat))) {
- $errors[] = array('missing order row vat information' => "cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent.");
- }
- }
-
- return $errors;
- }
+ /**
+ * @var UpdateOrderRowsBuilder $orderBuilder
+ */
+ public $orderBuilder;
+
+ private $amount;
+
+ /**
+ * @param UpdateOrderRowsBuilder $updateOrderRowsBuilder
+ */
+ public function __construct($updateOrderRowsBuilder)
+ {
+ $this->action = "UpdateOrderRows";
+ $this->orderBuilder = $updateOrderRowsBuilder;
+ }
+
+ /**
+ * populate and return soap request contents using AdminSoap helper classes to get the correct data format
+ * @param bool $resendOrderWithFlippedPriceIncludingVat
+ * @return AdminSoap\UpdateOrderRowsRequest
+ * @throws ValidationException
+ */
+ public function prepareRequest($resendOrderWithFlippedPriceIncludingVat = false)
+ {
+ $this->validateRequest();
+ $this->priceIncludingVat = $this->determineVatFlag($this->orderBuilder->numberedOrderRows, $resendOrderWithFlippedPriceIncludingVat);
+ $updatedOrderRows =
+ $this->getAdminSoapNumberedOrderRowsFromBuilderOrderRowsUsingVatFlag($this->orderBuilder->numberedOrderRows, $this->priceIncludingVat);
+
+ $soapRequest = new \Svea\WebPay\AdminService\AdminSoap\UpdateOrderRowsRequest(
+ new Authentication(
+ $this->orderBuilder->conf->getUsername(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword(($this->orderBuilder->orderType), $this->orderBuilder->countryCode)
+ ),
+ $this->orderBuilder->conf->getClientNumber(($this->orderBuilder->orderType), $this->orderBuilder->countryCode),
+ AdminServiceRequest::CamelCaseOrderType($this->orderBuilder->orderType),
+ $this->orderBuilder->orderId,
+ new SoapVar($updatedOrderRows, SOAP_ENC_OBJECT)
+ );
+
+ return $soapRequest;
+ }
+
+ public function validate()
+ {
+ $errors = [];
+ $errors = $this->validateOrderId($errors);
+ $errors = $this->validateRowNumber($errors);
+ $errors = $this->validateOrderType($errors);
+ $errors = $this->validateCountryCode($errors);
+ $errors = $this->validateNumberedOrderRowsExist($errors);
+ $errors = $this->validateNumberedOrderRowsHasPriceAndVatInformation($errors);
+
+ return $errors;
+ }
+
+ private function validateOrderId($errors)
+ {
+ if (isset($this->orderBuilder->orderId) == FALSE) {
+ $errors[] = ['missing value' => "orderId is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateRowNumber($errors)
+ {
+ foreach ($this->orderBuilder->numberedOrderRows as $orderRow) {
+ if (isset($orderRow->rowNumber) == FALSE) {
+ $errors[] = ['missing value' => "rowNumber is required."];
+ }
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderType($errors)
+ {
+ if (isset($this->orderBuilder->orderType) == FALSE) {
+ $errors[] = ['missing value' => "orderType is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateCountryCode($errors)
+ {
+ if (isset($this->orderBuilder->countryCode) == FALSE) {
+ $errors[] = ['missing value' => "countryCode is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateNumberedOrderRowsExist($errors)
+ {
+ if (isset($this->orderBuilder->numberedOrderRows) == FALSE) {
+ $errors[] = ['missing value' => "numberedOrderRows is required."];
+ }
+
+ return $errors;
+ }
+
+ private function validateNumberedOrderRowsHasPriceAndVatInformation($errors)
+ {
+ foreach ($this->orderBuilder->numberedOrderRows as $orderRow) {
+ if (!isset($orderRow->vatPercent) && (!isset($orderRow->amountIncVat) && !isset($orderRow->amountExVat))) {
+ $errors[] = ['missing order row vat information' => "cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent."];
+ }
+ }
+
+ return $errors;
+ }
}
diff --git a/src/BuildOrder/AccountCreditQueryBuilder.php b/src/BuildOrder/AccountCreditQueryBuilder.php
index 447bf9eb..0dee9e16 100644
--- a/src/BuildOrder/AccountCreditQueryBuilder.php
+++ b/src/BuildOrder/AccountCreditQueryBuilder.php
@@ -29,44 +29,44 @@
*/
class AccountCreditQueryBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
- /**
- * @var AccountCreditInformation []
- * */
- public $clientAccountCreditInformation = array();
+ /**
+ * @var AccountCreditInformation []
+ * */
+ public $clientAccountCreditInformation = [];
- public function __construct($config) {
- $this->conf = $config;
- }
+ public function __construct($config) {
+ $this->conf = $config;
+ }
- /**
- * Add ClientAccountInformation, this is only for AccountCredit
- *
- * @var AccountCreditInformation @info
- * @return $this
- */
- public function addClientAccountCreditInformation($info)
- {
- $this->clientAccountCreditInformation [] = $info;
+ /**
+ * Add ClientAccountInformation, this is only for AccountCredit
+ *
+ * @var AccountCreditInformation @info
+ * @return $this
+ */
+ public function addClientAccountCreditInformation($info)
+ {
+ $this->clientAccountCreditInformation [] = $info;
- return $this;
- }
+ return $this;
+ }
- /**
- * Retrieve list of clientAccountCreditInformation
- */
- public function getClientAccountCreditInformation()
- {
- return $this->clientAccountCreditInformation;
- }
+ /**
+ * Retrieve list of clientAccountCreditInformation
+ */
+ public function getClientAccountCreditInformation()
+ {
+ return $this->clientAccountCreditInformation;
+ }
- public function queryAccountCreditOrder()
- {
- $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
- return new SearchOrdersRequest($this);
- }
+ public function queryAccountCreditOrder()
+ {
+ $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+ return new SearchOrdersRequest($this);
+ }
}
diff --git a/src/BuildOrder/AddOrderRowsBuilder.php b/src/BuildOrder/AddOrderRowsBuilder.php
index aafc134d..f7394062 100644
--- a/src/BuildOrder/AddOrderRowsBuilder.php
+++ b/src/BuildOrder/AddOrderRowsBuilder.php
@@ -33,114 +33,114 @@
*/
class AddOrderRowsBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
-
- /**
- * @var OrderRow[] $orderRows
- */
- public $orderRows;
-
- /**
- * string $orderId Svea order id to query, as returned in the createOrder request response,
- * either a transactionId or a SveaOrderId
- */
- public $orderId;
-
- /**
- * @var string $countryCode
- */
- public $countryCode;
-
- /**
- * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE
- */
- public $orderType;
-
-
- /**
- * AddOrderRowsBuilder constructor.
- * @param $config
- */
- public function __construct($config)
- {
- parent::__construct($config);
- $this->orderRows = array();
- }
-
- /**
- * Required. Use SveaOrderId recieved with createOrder response.
- * @param string $orderIdAsString
- * @return $this
- */
- public function setOrderId($orderIdAsString) {
- $this->orderId = $orderIdAsString;
- return $this;
- }
-
- /**
- * Required. Use same countryCode as in createOrder request.
- * @param $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
- return $this;
- }
-
- /**
- * Required.
- * @param OrderRow $row
- * @return $this
- */
- public function addOrderRow($row)
- {
- $this->orderRows[] = $row;
- return $this;
- }
-
- /**
- * Convenience method to add several rows at once.
- * @param \Svea\WebPay\BuildOrder\RowBuilders\OrderRow[] $rows
- * @return $this
- */
- public function addOrderRows($rows)
- {
- $this->orderRows = array_merge($this->orderRows, $rows);
- return $this;
- }
-
- /**
- * Use addInvoiceOrderRows() to add rows to an Invoice order using AdminServiceRequest AddOrderRows request
- * @return AddOrderRowsRequest
- */
- public function addInvoiceOrderRows()
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
- return new AddOrderRowsRequest($this);
- }
-
- /**
- * Use addPaymentPlanOrderRows() to add rows to a PaymentPlan order using AdminServiceRequest AddOrderRows request
- * @return AddOrderRowsRequest
- */
- public function addPaymentPlanOrderRows()
- {
- $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
- return new AddOrderRowsRequest($this);
- }
-
- /**
- * Use addCheckoutOrderRows() to add rows to a Checkout order
- * @return AddOrderRowService
- * @throws ValidationException
- * @throws \Exception
- */
- public function addCheckoutOrderRows()
- {
- return new AddOrderRowService($this);
- }
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
+
+ /**
+ * @var OrderRow[] $orderRows
+ */
+ public $orderRows;
+
+ /**
+ * string $orderId Svea order id to query, as returned in the createOrder request response,
+ * either a transactionId or a SveaOrderId
+ */
+ public $orderId;
+
+ /**
+ * @var string $countryCode
+ */
+ public $countryCode;
+
+ /**
+ * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE
+ */
+ public $orderType;
+
+
+ /**
+ * AddOrderRowsBuilder constructor.
+ * @param $config
+ */
+ public function __construct($config)
+ {
+ parent::__construct($config);
+ $this->orderRows = [];
+ }
+
+ /**
+ * Required. Use SveaOrderId recieved with createOrder response.
+ * @param string $orderIdAsString
+ * @return $this
+ */
+ public function setOrderId($orderIdAsString) {
+ $this->orderId = $orderIdAsString;
+ return $this;
+ }
+
+ /**
+ * Required. Use same countryCode as in createOrder request.
+ * @param $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+ return $this;
+ }
+
+ /**
+ * Required.
+ * @param OrderRow $row
+ * @return $this
+ */
+ public function addOrderRow($row)
+ {
+ $this->orderRows[] = $row;
+ return $this;
+ }
+
+ /**
+ * Convenience method to add several rows at once.
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\OrderRow[] $rows
+ * @return $this
+ */
+ public function addOrderRows($rows)
+ {
+ $this->orderRows = array_merge($this->orderRows, $rows);
+ return $this;
+ }
+
+ /**
+ * Use addInvoiceOrderRows() to add rows to an Invoice order using AdminServiceRequest AddOrderRows request
+ * @return AddOrderRowsRequest
+ */
+ public function addInvoiceOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+ return new AddOrderRowsRequest($this);
+ }
+
+ /**
+ * Use addPaymentPlanOrderRows() to add rows to a PaymentPlan order using AdminServiceRequest AddOrderRows request
+ * @return AddOrderRowsRequest
+ */
+ public function addPaymentPlanOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+ return new AddOrderRowsRequest($this);
+ }
+
+ /**
+ * Use addCheckoutOrderRows() to add rows to a Checkout order
+ * @return AddOrderRowService
+ * @throws ValidationException
+ * @throws \Exception
+ */
+ public function addCheckoutOrderRows()
+ {
+ return new AddOrderRowService($this);
+ }
}
diff --git a/src/BuildOrder/CancelOrderBuilder.php b/src/BuildOrder/CancelOrderBuilder.php
index 6ac785e7..1e85cc2f 100644
--- a/src/BuildOrder/CancelOrderBuilder.php
+++ b/src/BuildOrder/CancelOrderBuilder.php
@@ -24,118 +24,118 @@
* @author Kristian Grossman-Madsen for Svea Svea\WebPay\WebPay
*/
class CancelOrderBuilder extends CheckoutAdminOrderBuilder
-{
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
-
- /**
- * @var string $orderId Svea order id to cancel, as returned in the createOrder request response,
- * either a transactionId or a SveaOrderId
- */
- public $orderId;
-
- /**
- * @var string $countryCode
- */
- public $countryCode;
-
- /**
- * @var ConfigurationProvider::INVOICE_TYPE, ::ACCCOUNTCREDIT_TYPE or ::PAYMENTPLAN_TYPE
- */
- public $orderType;
-
- /**
- * Optional -- alias for setOrderId().
- * @param string $transactionIdAsString
- * @return $this
- */
- public function setTransactionId($transactionIdAsString) {
- return $this->setOrderId($transactionIdAsString);
- }
-
- /**
- * Required. Use same country code as in createOrder request.
- *
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
-
- return $this;
- }
-
-
-
- /**
- * Use cancelInvoiceOrder() to close an Invoice order.
- *
- * Use the method corresponding to the original createOrder payment method.
- *
- * @return CloseOrder
- */
- public function cancelInvoiceOrder()
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
-
- return new CloseOrder($this);
- }
-
- /**
- * Use cancelPaymentPlanOrder() to close a PaymentPlan order.
- *
- * Use the method corresponding to the original createOrder payment method.
- *
- * @return CloseOrder
- */
- public function cancelPaymentPlanOrder()
- {
- $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
-
- return new CloseOrder($this);
- }
-
- /**
- * Use cancelAccountCreditOrder() to close a AccountCredit order.
- *
- * Use the method corresponding to the original createOrder payment method.
- *
- * @return CloseOrder
- */
- public function cancelAccountCreditOrder()
- {
- $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
-
- return new CloseOrder($this);
- }
-
- /**
- * Use cancelCardOrder() to close a Card order.
- *
- * Use the method corresponding to the original createOrder payment method.
- *
- * @return AnnulTransaction
- */
- public function cancelCardOrder()
- {
- $this->orderType = ConfigurationProvider::HOSTED_ADMIN_TYPE;
- $annulTransaction = new AnnulTransaction($this->conf);
- $annulTransaction->transactionId = $this->orderId;
- $annulTransaction->countryCode = $this->countryCode;
-
- return $annulTransaction;
- }
-
- public function cancelCheckoutOrder()
- {
- return new CancelOrderService($this);
- }
-
- public function cancelCheckoutOrderAmount()
- {
- return new CancelOrderService($this, true);
- }
+{
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
+
+ /**
+ * @var string $orderId Svea order id to cancel, as returned in the createOrder request response,
+ * either a transactionId or a SveaOrderId
+ */
+ public $orderId;
+
+ /**
+ * @var string $countryCode
+ */
+ public $countryCode;
+
+ /**
+ * @var ConfigurationProvider::INVOICE_TYPE, ::ACCCOUNTCREDIT_TYPE or ::PAYMENTPLAN_TYPE
+ */
+ public $orderType;
+
+ /**
+ * Optional -- alias for setOrderId().
+ * @param string $transactionIdAsString
+ * @return $this
+ */
+ public function setTransactionId($transactionIdAsString) {
+ return $this->setOrderId($transactionIdAsString);
+ }
+
+ /**
+ * Required. Use same country code as in createOrder request.
+ *
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+
+ return $this;
+ }
+
+
+
+ /**
+ * Use cancelInvoiceOrder() to close an Invoice order.
+ *
+ * Use the method corresponding to the original createOrder payment method.
+ *
+ * @return CloseOrder
+ */
+ public function cancelInvoiceOrder()
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ return new CloseOrder($this);
+ }
+
+ /**
+ * Use cancelPaymentPlanOrder() to close a PaymentPlan order.
+ *
+ * Use the method corresponding to the original createOrder payment method.
+ *
+ * @return CloseOrder
+ */
+ public function cancelPaymentPlanOrder()
+ {
+ $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+
+ return new CloseOrder($this);
+ }
+
+ /**
+ * Use cancelAccountCreditOrder() to close a AccountCredit order.
+ *
+ * Use the method corresponding to the original createOrder payment method.
+ *
+ * @return CloseOrder
+ */
+ public function cancelAccountCreditOrder()
+ {
+ $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+
+ return new CloseOrder($this);
+ }
+
+ /**
+ * Use cancelCardOrder() to close a Card order.
+ *
+ * Use the method corresponding to the original createOrder payment method.
+ *
+ * @return AnnulTransaction
+ */
+ public function cancelCardOrder()
+ {
+ $this->orderType = ConfigurationProvider::HOSTED_ADMIN_TYPE;
+ $annulTransaction = new AnnulTransaction($this->conf);
+ $annulTransaction->transactionId = $this->orderId;
+ $annulTransaction->countryCode = $this->countryCode;
+
+ return $annulTransaction;
+ }
+
+ public function cancelCheckoutOrder()
+ {
+ return new CancelOrderService($this);
+ }
+
+ public function cancelCheckoutOrderAmount()
+ {
+ return new CancelOrderService($this, true);
+ }
}
diff --git a/src/BuildOrder/CancelOrderRowsBuilder.php b/src/BuildOrder/CancelOrderRowsBuilder.php
index 5273f6a8..20663dea 100644
--- a/src/BuildOrder/CancelOrderRowsBuilder.php
+++ b/src/BuildOrder/CancelOrderRowsBuilder.php
@@ -49,216 +49,216 @@
class CancelOrderRowsBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
-
- /**
- * @var int[] $rowsToCancel
- */
- public $rowsToCancel;
-
- /**
- * @var NumberedOrderRow[] $numberedOrderRows
- */
- public $numberedOrderRows;
-
- /**
- * @var string $orderId Svea order id to query, as returned in the createOrder request response,
- * either a transactionId or a SveaOrderId
- */
- public $orderId;
-
- /**
- * @var string $countryCode
- */
- public $countryCode;
-
- /**
- * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_TYPE
- */
- public $orderType;
-
- /**
- * CancelOrderRowsBuilder constructor.
- * @param $config
- */
- public function __construct($config)
- {
- parent::__construct($config);
- $this->rowsToCancel = array();
- $this->numberedOrderRows = array();
- }
-
- /**
- * Optional for card orders -- use the order id (transaction id) received with the createOrder response.
- *
- * This is an alias for setOrderId().
- *
- * @param string $orderIdAsString
- * @return $this
- */
- public function setTransactionId($orderIdAsString)
- {
- return $this->setOrderId($orderIdAsString);
- }
-
- /**
- * Required. Use same countryCode as in createOrder request.
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
-
- return $this;
- }
-
- /**
- * Required - add a row number to cancel
- * @param int $rowNumber
- * @return $this
- */
- public function setRowToCancel($rowNumber)
- {
- $this->rowsToCancel[] = $rowNumber;
-
- return $this;
- }
-
- /**
- * Optional - convenience method to provide several row numbers at once.
- * @param int[] $rowNumbers
- * @return $this
- */
- public function setRowsToCancel($rowNumbers)
- {
- $this->rowsToCancel = array_merge($this->rowsToCancel, $rowNumbers);
-
- return $this;
- }
-
- /**
- * Required - add information on a single numbered order row
- *
- * When cancelling card order rows, you must pass in information about the row
- * along with the request. The rows are then matched with the order rows specified
- * using setRow(s)ToCredit().
- *
- * Note: the card order does not update the state of any cancelled order rows, only
- * the total order amount to be charged.
- *
- * @param NumberedOrderRow $rowNumber - instance of NumberedOrderRow
- * @return $this
- */
- public function addNumberedOrderRow($rowNumber)
- {
- $this->numberedOrderRows[] = $rowNumber;
-
- return $this;
- }
-
- /**
- * Use cancelCheckoutOrderRows() to cancel a Checkout Order
- * @return CancelOrderRowService
- * @throws ValidationException
- * @throws \Exception
- */
- public function cancelCheckoutOrderRows()
- {
- return new CancelOrderRowService($this);
- }
-
- /**
- * Optional - Convenience method to provide several numbered order rows at once.
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow[] $numberedOrderRows array of NumberedOrderRow
- * @return $this
- */
- public function addNumberedOrderRows($numberedOrderRows)
- {
- $this->numberedOrderRows = array_merge($this->numberedOrderRows, $numberedOrderRows);
-
- return $this;
- }
-
- /**
- * Use cancelCardOrderRows() to lower the amount of a Card order by the specified order row amounts using HostedRequests LowerTransaction request
- *
- * @return LowerTransaction
- * @throws ValidationException if addNumberedOrderRows() has not been used.
- */
- public function cancelCardOrderRows()
- {
- $this->orderType = ConfigurationProvider::HOSTED_ADMIN_TYPE;
-
- $this->validateCancelCardOrderRows();
- $sumOfRowAmounts = $this->calculateSumOfRowAmounts($this->rowsToCancel, $this->numberedOrderRows);
-
- $lowerTransaction = new LowerTransaction($this->conf);
- $lowerTransaction->countryCode = $this->countryCode;
- $lowerTransaction->transactionId = $this->orderId;
- $lowerTransaction->amountToLower = $sumOfRowAmounts * 100; // *100, as setAmountToLower wants minor currency
- return $lowerTransaction;
- }
-
- private function validateCancelCardOrderRows()
- {
- if (count($this->numberedOrderRows) == 0) {
- $exceptionString = "numberedOrderRows is required for cancelCardOrderRows(). Use method addNumberedOrderRows().";
- throw new ValidationException($exceptionString);
- }
- if (count($this->rowsToCancel) == 0) {
- $exceptionString = "rowsToCancel is required for cancelCardOrderRows(). Use method setRowToCancel() or setRowsToCancel.";
- throw new ValidationException($exceptionString);
- }
- }
-
- private function calculateSumOfRowAmounts($rowIndexes, $numberedRows)
- {
- $sum = 0.0;
- $unique_indexes = array_unique($rowIndexes);
- foreach ($numberedRows as $numberedRow) {
- if (in_array($numberedRow->rowNumber, $unique_indexes)) {
- $sum += ($numberedRow->quantity * ($numberedRow->amountExVat * (1 + ($numberedRow->vatPercent / 100))));
- }
- }
-
- return $sum;
- }
-
- /**
- * Use cancelInvoiceOrderRows() to cancel an Invoice order using AdminServiceRequest CancelOrderRows request
- * @return CancelOrderRowsRequest
- */
- public function cancelInvoiceOrderRows()
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
-
- return new CancelOrderRowsRequest($this);
- }
-
- /**
- * Use cancelPaymentPlanOrderRows() to cancel a PaymentPlan order using AdminServiceRequest CancelOrderRows request
- * @return CancelOrderRowsRequest
- */
- public function cancelPaymentPlanOrderRows()
- {
- $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
-
- return new CancelOrderRowsRequest($this);
- }
-
- /**
- * Use cancelAccountCreditOrderRows() to cancel a AccountCredit order using AdminServiceRequest CancelOrderRows request
- * @return CancelOrderRowsRequest
- */
- public function cancelAccountCreditOrderRows()
- {
- $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
-
- return new CancelOrderRowsRequest($this);
- }
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
+
+ /**
+ * @var int[] $rowsToCancel
+ */
+ public $rowsToCancel;
+
+ /**
+ * @var NumberedOrderRow[] $numberedOrderRows
+ */
+ public $numberedOrderRows;
+
+ /**
+ * @var string $orderId Svea order id to query, as returned in the createOrder request response,
+ * either a transactionId or a SveaOrderId
+ */
+ public $orderId;
+
+ /**
+ * @var string $countryCode
+ */
+ public $countryCode;
+
+ /**
+ * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_TYPE
+ */
+ public $orderType;
+
+ /**
+ * CancelOrderRowsBuilder constructor.
+ * @param $config
+ */
+ public function __construct($config)
+ {
+ parent::__construct($config);
+ $this->rowsToCancel = [];
+ $this->numberedOrderRows = [];
+ }
+
+ /**
+ * Optional for card orders -- use the order id (transaction id) received with the createOrder response.
+ *
+ * This is an alias for setOrderId().
+ *
+ * @param string $orderIdAsString
+ * @return $this
+ */
+ public function setTransactionId($orderIdAsString)
+ {
+ return $this->setOrderId($orderIdAsString);
+ }
+
+ /**
+ * Required. Use same countryCode as in createOrder request.
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required - add a row number to cancel
+ * @param int $rowNumber
+ * @return $this
+ */
+ public function setRowToCancel($rowNumber)
+ {
+ $this->rowsToCancel[] = $rowNumber;
+
+ return $this;
+ }
+
+ /**
+ * Optional - convenience method to provide several row numbers at once.
+ * @param int[] $rowNumbers
+ * @return $this
+ */
+ public function setRowsToCancel($rowNumbers)
+ {
+ $this->rowsToCancel = array_merge($this->rowsToCancel, $rowNumbers);
+
+ return $this;
+ }
+
+ /**
+ * Required - add information on a single numbered order row
+ *
+ * When cancelling card order rows, you must pass in information about the row
+ * along with the request. The rows are then matched with the order rows specified
+ * using setRow(s)ToCredit().
+ *
+ * Note: the card order does not update the state of any cancelled order rows, only
+ * the total order amount to be charged.
+ *
+ * @param NumberedOrderRow $rowNumber - instance of NumberedOrderRow
+ * @return $this
+ */
+ public function addNumberedOrderRow($rowNumber)
+ {
+ $this->numberedOrderRows[] = $rowNumber;
+
+ return $this;
+ }
+
+ /**
+ * Use cancelCheckoutOrderRows() to cancel a Checkout Order
+ * @return CancelOrderRowService
+ * @throws ValidationException
+ * @throws \Exception
+ */
+ public function cancelCheckoutOrderRows()
+ {
+ return new CancelOrderRowService($this);
+ }
+
+ /**
+ * Optional - Convenience method to provide several numbered order rows at once.
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow[] $numberedOrderRows array of NumberedOrderRow
+ * @return $this
+ */
+ public function addNumberedOrderRows($numberedOrderRows)
+ {
+ $this->numberedOrderRows = array_merge($this->numberedOrderRows, $numberedOrderRows);
+
+ return $this;
+ }
+
+ /**
+ * Use cancelCardOrderRows() to lower the amount of a Card order by the specified order row amounts using HostedRequests LowerTransaction request
+ *
+ * @return LowerTransaction
+ * @throws ValidationException if addNumberedOrderRows() has not been used.
+ */
+ public function cancelCardOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::HOSTED_ADMIN_TYPE;
+
+ $this->validateCancelCardOrderRows();
+ $sumOfRowAmounts = $this->calculateSumOfRowAmounts($this->rowsToCancel, $this->numberedOrderRows);
+
+ $lowerTransaction = new LowerTransaction($this->conf);
+ $lowerTransaction->countryCode = $this->countryCode;
+ $lowerTransaction->transactionId = $this->orderId;
+ $lowerTransaction->amountToLower = $sumOfRowAmounts * 100; // *100, as setAmountToLower wants minor currency
+ return $lowerTransaction;
+ }
+
+ private function validateCancelCardOrderRows()
+ {
+ if (count($this->numberedOrderRows) == 0) {
+ $exceptionString = "numberedOrderRows is required for cancelCardOrderRows(). Use method addNumberedOrderRows().";
+ throw new ValidationException($exceptionString);
+ }
+ if (count($this->rowsToCancel) == 0) {
+ $exceptionString = "rowsToCancel is required for cancelCardOrderRows(). Use method setRowToCancel() or setRowsToCancel.";
+ throw new ValidationException($exceptionString);
+ }
+ }
+
+ private function calculateSumOfRowAmounts($rowIndexes, $numberedRows)
+ {
+ $sum = 0.0;
+ $unique_indexes = array_unique($rowIndexes);
+ foreach ($numberedRows as $numberedRow) {
+ if (in_array($numberedRow->rowNumber, $unique_indexes)) {
+ $sum += ($numberedRow->quantity * ($numberedRow->amountExVat * (1 + ($numberedRow->vatPercent / 100))));
+ }
+ }
+
+ return $sum;
+ }
+
+ /**
+ * Use cancelInvoiceOrderRows() to cancel an Invoice order using AdminServiceRequest CancelOrderRows request
+ * @return CancelOrderRowsRequest
+ */
+ public function cancelInvoiceOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ return new CancelOrderRowsRequest($this);
+ }
+
+ /**
+ * Use cancelPaymentPlanOrderRows() to cancel a PaymentPlan order using AdminServiceRequest CancelOrderRows request
+ * @return CancelOrderRowsRequest
+ */
+ public function cancelPaymentPlanOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+
+ return new CancelOrderRowsRequest($this);
+ }
+
+ /**
+ * Use cancelAccountCreditOrderRows() to cancel a AccountCredit order using AdminServiceRequest CancelOrderRows request
+ * @return CancelOrderRowsRequest
+ */
+ public function cancelAccountCreditOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+
+ return new CancelOrderRowsRequest($this);
+ }
}
diff --git a/src/BuildOrder/CancelRecurSubscriptionBuilder.php b/src/BuildOrder/CancelRecurSubscriptionBuilder.php
index 0545cd07..d92e18eb 100644
--- a/src/BuildOrder/CancelRecurSubscriptionBuilder.php
+++ b/src/BuildOrder/CancelRecurSubscriptionBuilder.php
@@ -8,29 +8,29 @@
class CancelRecurSubscriptionBuilder extends OrderBuilder
{
- /**
- * @var string $subscriptionId
- */
- public $subscriptionId;
+ /**
+ * @var string $subscriptionId
+ */
+ public $subscriptionId;
- /**
- * Set subscriptionId
- *
- * @param string $subscriptionId
- * @return $this
- */
- public function setSubscriptionId($subscriptionId)
- {
- $this->subscriptionId = $subscriptionId;
+ /**
+ * Set subscriptionId
+ *
+ * @param string $subscriptionId
+ * @return $this
+ */
+ public function setSubscriptionId($subscriptionId)
+ {
+ $this->subscriptionId = $subscriptionId;
- return $this;
- }
+ return $this;
+ }
- public function cancelRecurSubscription()
- {
- $cancelRecurSubscription = new CancelRecurSubscription($this->conf);
- $cancelRecurSubscription->subscriptionId = $this->subscriptionId;
- $cancelRecurSubscription->countryCode = $this->countryCode;
- return $cancelRecurSubscription;
- }
+ public function cancelRecurSubscription()
+ {
+ $cancelRecurSubscription = new CancelRecurSubscription($this->conf);
+ $cancelRecurSubscription->subscriptionId = $this->subscriptionId;
+ $cancelRecurSubscription->countryCode = $this->countryCode;
+ return $cancelRecurSubscription;
+ }
}
diff --git a/src/BuildOrder/CheckoutAdminOrderBuilder.php b/src/BuildOrder/CheckoutAdminOrderBuilder.php
index 19c8e85a..d6045ac5 100644
--- a/src/BuildOrder/CheckoutAdminOrderBuilder.php
+++ b/src/BuildOrder/CheckoutAdminOrderBuilder.php
@@ -17,73 +17,73 @@
*/
class CheckoutAdminOrderBuilder extends OrderBuilder
{
- /**
- * @var string $orderId
- */
- public $orderId;
+ /**
+ * @var string $orderId
+ */
+ public $orderId;
- /**
- * @var integer $deliveryId
- */
- public $deliveryId;
+ /**
+ * @var integer $deliveryId
+ */
+ public $deliveryId;
- public $amountIncVat;
+ public $amountIncVat;
- /**
- * @return string
- */
- public function getCountryCode()
- {
- return $this->countryCode;
- }
+ /**
+ * @return string
+ */
+ public function getCountryCode()
+ {
+ return $this->countryCode;
+ }
- /**
- * Optional -- alias for setOrderId().
- * @param string $transactionIdAsString
- * @return $this
- */
- public function setTransactionId($transactionIdAsString)
- {
- return $this->setOrderId($transactionIdAsString);
- }
+ /**
+ * Optional -- alias for setOrderId().
+ * @param string $transactionIdAsString
+ * @return $this
+ */
+ public function setTransactionId($transactionIdAsString)
+ {
+ return $this->setOrderId($transactionIdAsString);
+ }
- /**
- * Optional -- alias for setOrderId().
- * @param string $checkoutOrderId
- * @return $this
- */
- public function setCheckoutOrderId($checkoutOrderId)
- {
- return $this->setOrderId($checkoutOrderId);
- }
+ /**
+ * Optional -- alias for setOrderId().
+ * @param string $checkoutOrderId
+ * @return $this
+ */
+ public function setCheckoutOrderId($checkoutOrderId)
+ {
+ return $this->setOrderId($checkoutOrderId);
+ }
- /**
- * @param mixed $orderId
- * @return $this
- */
- public function setOrderId($orderId)
- {
- $this->orderId = $orderId;
- return $this;
- }
+ /**
+ * @param mixed $orderId
+ * @return $this
+ */
+ public function setOrderId($orderId)
+ {
+ $this->orderId = $orderId;
+ return $this;
+ }
- /**
- * @param mixed $deliveryId
- * @return $this
- */
- public function setDeliveryId($deliveryId)
- {
- $this->deliveryId = $deliveryId;
- return $this;
- }
+ /**
+ * @param mixed $deliveryId
+ * @return $this
+ */
+ public function setDeliveryId($deliveryId)
+ {
+ $this->deliveryId = $deliveryId;
+ return $this;
+ }
- /**
- * @param mixed $amountIncVat
- * @return $this
- */
- public function setAmountIncVat($amountIncVat)
- {
- $this->amountIncVat = $amountIncVat;
- return $this;
- }
+ /**
+ * @param mixed $amountIncVat
+ * @return $this
+ */
+ public function setAmountIncVat($amountIncVat)
+ {
+ $this->amountIncVat = $amountIncVat;
+ return $this;
+ }
}
diff --git a/src/BuildOrder/CloseOrderBuilder.php b/src/BuildOrder/CloseOrderBuilder.php
index 5ee458d4..b0da12ff 100644
--- a/src/BuildOrder/CloseOrderBuilder.php
+++ b/src/BuildOrder/CloseOrderBuilder.php
@@ -11,77 +11,77 @@
*/
class CloseOrderBuilder extends OrderBuilder
{
- /**
- * @var ConfigurationService
- */
- public $conf;
+ /**
+ * @var ConfigurationService
+ */
+ public $conf;
- /**
- * @var ConfigurationProvider::INVOICE_TYPE|ConfigurationProvider::PAYMENTPLAN_TYPE
- */
- public $orderType;
+ /**
+ * @var ConfigurationProvider::INVOICE_TYPE|ConfigurationProvider::PAYMENTPLAN_TYPE
+ */
+ public $orderType;
- /**
- * @var string $orderId
- */
- public $orderId;
+ /**
+ * @var string $orderId
+ */
+ public $orderId;
- /**
- * @var string $countryCode
- */
- public $countryCode;
+ /**
+ * @var string $countryCode
+ */
+ public $countryCode;
- /**
- * CloseOrderBuilder constructor.
- * @param $config
- */
- public function __construct($config)
- {
- $this->conf = $config;
- }
+ /**
+ * CloseOrderBuilder constructor.
+ * @param $config
+ */
+ public function __construct($config)
+ {
+ $this->conf = $config;
+ }
- /**
- * Required. Use SveaOrderId recieved with createOrder response.
- * @param string $orderIdAsString
- * @return $this
- */
- public function setOrderId($orderIdAsString)
- {
- $this->orderId = $orderIdAsString;
+ /**
+ * Required. Use SveaOrderId recieved with createOrder response.
+ * @param string $orderIdAsString
+ * @return $this
+ */
+ public function setOrderId($orderIdAsString)
+ {
+ $this->orderId = $orderIdAsString;
- return $this;
- }
+ return $this;
+ }
- /**
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
+ /**
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
- return $this;
- }
+ return $this;
+ }
- /**
- * Use closeInvoiceOrder() to close an Invoice order.
- * @return CloseOrder
- */
- public function closeInvoiceOrder()
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+ /**
+ * Use closeInvoiceOrder() to close an Invoice order.
+ * @return CloseOrder
+ */
+ public function closeInvoiceOrder()
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
- return new CloseOrder($this);
- }
+ return new CloseOrder($this);
+ }
- /**
- * Use closePaymentPlanOrder() to close a PaymentPlan order.
- * @return CloseOrder
- */
- public function closePaymentPlanOrder()
- {
- $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+ /**
+ * Use closePaymentPlanOrder() to close a PaymentPlan order.
+ * @return CloseOrder
+ */
+ public function closePaymentPlanOrder()
+ {
+ $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
- return new CloseOrder($this);
- }
+ return new CloseOrder($this);
+ }
}
diff --git a/src/BuildOrder/CreateOrderBuilder.php b/src/BuildOrder/CreateOrderBuilder.php
index 0272bbfa..2f3483c8 100644
--- a/src/BuildOrder/CreateOrderBuilder.php
+++ b/src/BuildOrder/CreateOrderBuilder.php
@@ -27,131 +27,131 @@
class CreateOrderBuilder extends OrderBuilder
{
- /**
- * Use useInvoicePayment to initiate an invoice payment.
- *
- * Set additional attributes using InvoicePayment methods.
- *
- * @return InvoicePayment
- */
- public function useInvoicePayment()
- {
- return new InvoicePayment($this);
- }
-
- /**
- * Use usePaymentPlanPayment to initate a payment plan payment.
- *
- * You can use Svea\WebPay\WebPay::getPaymentPlanParams() to get available campaign codes (payment plans).
- *
- * Set additional attributes using PaymentPlanPayment methods.
- *
- * @see \WebPay::getPaymentPlanParams() Svea\WebPay\WebPay::getPaymentPlanParams()
- *
- * @param string $campaignCodeAsString
- * @param int $sendAutomaticGiroPaymentFormAsBool (optional boolean)
- * @return PaymentPlanPayment
- */
- public function usePaymentPlanPayment($campaignCodeAsString, $sendAutomaticGiroPaymentFormAsBool = 0)
- {
- $this->campaignCode = $campaignCodeAsString;
- $this->sendAutomaticGiroPaymentForm = $sendAutomaticGiroPaymentFormAsBool;
-
- return new PaymentPlanPayment($this);
- }
-
- /**
- * Use useAccountCredit to initate a Account Credit payment.
- *
- * You can use Svea\WebPay\WebPay::getAccountCreditParams() to get available campaign codes (payment plans).
- *
- *
- * @see \WebPay::getAccountCreditParams() Svea\WebPay\WebPay::getAccountCreditParams()
- *
- * @param string $campaignCode
- * @return AccountCredit
- */
- public function useAccountCredit($campaignCode)
- {
- $this->campaignCode = $campaignCode;
-
- return new AccountCredit($this);
- }
-
- /**
- * Use usePaymentMethod to initate a payment bypassing the PayPage completely, going straight to the payment method
- * specified. This is the preferred way to perform a payment, as it cuts down on the number of payment steps in the
- * end user checkout flow.
- *
- * You can use Svea\WebPay\WebPay::getPaymentMethods() to get available payment methods. See also the
- * Svea\WebPay\Constant\PaymentMethod class constants.
- *
- * Set additional attributes using PaymentMethodPayment methods.
- *
- * @see \WebPay::getPaymentMethods() Svea\WebPay\WebPay::getPaymentMethods()
- * @see \PaymentMethod Svea\WebPay\Constant\PaymentMethod
- *
- * @param string $paymentMethodAsConst i.e. Svea\WebPay\Constant\PaymentMethod::SEB_SE et al
- * @return PaymentMethodPayment
- */
- public function usePaymentMethod($paymentMethodAsConst)
- {
- return new PaymentMethodPayment($this, $paymentMethodAsConst);
- }
-
- /**
- * Use usePayPageCardOnly to initate a card payment via PayPage, showing only the available card payment methods.
- *
- * Set additional attributes using CardPayment methods.
- * @return CardPayment
- */
- public function usePayPageCardOnly()
- {
- return new CardPayment($this);
- }
-
- /**
- * Use usePayPageDirectBankOnly to initate a direct bank payment via PayPage, showing only the available direct
- * bank payment methods.
- *
- * Set additional attributes using DirectPayment methods.
- * @return DirectPayment
- */
- public function usePayPageDirectBankOnly()
- {
- return new DirectPayment($this);
- }
-
- /**
- * Use usePayPage to initate a payment via PayPage, showing all available payment methods to the user.
- *
- * Set additional attributes using PayPagePayment methods.
- * @return PayPagePayment
- */
- public function usePayPage()
- {
- $paypagepayment = new PayPagePayment($this);
-
- return $paypagepayment;
- }
-
- /**
- * @param \Svea\WebPay\Config\ConfigurationProvider $config
- */
- public function __construct($config)
- {
- parent::__construct($config);
- }
-
- /**
- * @internal for testfunctions
- * @param type $func
- * @return $this
- */
- public function run($func)
- {
- call_user_func($func, $this);
-
- return $this;
- }
+ /**
+ * Use useInvoicePayment to initiate an invoice payment.
+ *
+ * Set additional attributes using InvoicePayment methods.
+ *
+ * @return InvoicePayment
+ */
+ public function useInvoicePayment()
+ {
+ return new InvoicePayment($this);
+ }
+
+ /**
+ * Use usePaymentPlanPayment to initate a payment plan payment.
+ *
+ * You can use Svea\WebPay\WebPay::getPaymentPlanParams() to get available campaign codes (payment plans).
+ *
+ * Set additional attributes using PaymentPlanPayment methods.
+ *
+ * @see \WebPay::getPaymentPlanParams() Svea\WebPay\WebPay::getPaymentPlanParams()
+ *
+ * @param string $campaignCodeAsString
+ * @param int $sendAutomaticGiroPaymentFormAsBool (optional boolean)
+ * @return PaymentPlanPayment
+ */
+ public function usePaymentPlanPayment($campaignCodeAsString, $sendAutomaticGiroPaymentFormAsBool = 0)
+ {
+ $this->campaignCode = $campaignCodeAsString;
+ $this->sendAutomaticGiroPaymentForm = $sendAutomaticGiroPaymentFormAsBool;
+
+ return new PaymentPlanPayment($this);
+ }
+
+ /**
+ * Use useAccountCredit to initate a Account Credit payment.
+ *
+ * You can use Svea\WebPay\WebPay::getAccountCreditParams() to get available campaign codes (payment plans).
+ *
+ *
+ * @see \WebPay::getAccountCreditParams() Svea\WebPay\WebPay::getAccountCreditParams()
+ *
+ * @param string $campaignCode
+ * @return AccountCredit
+ */
+ public function useAccountCredit($campaignCode)
+ {
+ $this->campaignCode = $campaignCode;
+
+ return new AccountCredit($this);
+ }
+
+ /**
+ * Use usePaymentMethod to initate a payment bypassing the PayPage completely, going straight to the payment method
+ * specified. This is the preferred way to perform a payment, as it cuts down on the number of payment steps in the
+ * end user checkout flow.
+ *
+ * You can use Svea\WebPay\WebPay::getPaymentMethods() to get available payment methods. See also the
+ * Svea\WebPay\Constant\PaymentMethod class constants.
+ *
+ * Set additional attributes using PaymentMethodPayment methods.
+ *
+ * @see \WebPay::getPaymentMethods() Svea\WebPay\WebPay::getPaymentMethods()
+ * @see \PaymentMethod Svea\WebPay\Constant\PaymentMethod
+ *
+ * @param string $paymentMethodAsConst i.e. Svea\WebPay\Constant\PaymentMethod::SEB_SE et al
+ * @return PaymentMethodPayment
+ */
+ public function usePaymentMethod($paymentMethodAsConst)
+ {
+ return new PaymentMethodPayment($this, $paymentMethodAsConst);
+ }
+
+ /**
+ * Use usePayPageCardOnly to initate a card payment via PayPage, showing only the available card payment methods.
+ *
+ * Set additional attributes using CardPayment methods.
+ * @return CardPayment
+ */
+ public function usePayPageCardOnly()
+ {
+ return new CardPayment($this);
+ }
+
+ /**
+ * Use usePayPageDirectBankOnly to initate a direct bank payment via PayPage, showing only the available direct
+ * bank payment methods.
+ *
+ * Set additional attributes using DirectPayment methods.
+ * @return DirectPayment
+ */
+ public function usePayPageDirectBankOnly()
+ {
+ return new DirectPayment($this);
+ }
+
+ /**
+ * Use usePayPage to initate a payment via PayPage, showing all available payment methods to the user.
+ *
+ * Set additional attributes using PayPagePayment methods.
+ * @return PayPagePayment
+ */
+ public function usePayPage()
+ {
+ $paypagepayment = new PayPagePayment($this);
+
+ return $paypagepayment;
+ }
+
+ /**
+ * @param \Svea\WebPay\Config\ConfigurationProvider $config
+ */
+ public function __construct($config)
+ {
+ parent::__construct($config);
+ }
+
+ /**
+ * @internal for testfunctions
+ * @param type $func
+ * @return $this
+ */
+ public function run($func)
+ {
+ call_user_func($func, $this);
+
+ return $this;
+ }
}
diff --git a/src/BuildOrder/CreditAmountBuilder.php b/src/BuildOrder/CreditAmountBuilder.php
index 0bcc36f5..3ff58dc1 100644
--- a/src/BuildOrder/CreditAmountBuilder.php
+++ b/src/BuildOrder/CreditAmountBuilder.php
@@ -14,132 +14,132 @@
*/
class CreditAmountBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
-
- /**
- * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, PAYMENTPLAN_TYPE,
- * ::HOSTED_ADMIN_TYPE
- */
- public $orderType;
-
- /**
- * @var float $amountIncVat
- */
- public $amountIncVat;
-
- /**
- * @var string @contractNumber contract number as returned in the deliverOrder request response. PaymentPlan
- * orders only.
- */
- public $contractNumber;
-
- /**
- * @var string $countryCode
- */
- public $countryCode;
-
- /**
- * @var string $description
- */
- public $description;
-
- public function __construct($config) {
- $this->conf = $config;
- }
-
- /**
- * Required
- * @param float $amountAsFloat
- * @return $this
- */
- public function setAmountIncVat($amountAsFloat)
- {
- $this->amountIncVat = $amountAsFloat;
-
- return $this;
- }
-
- /**
- * Required -- use same countryCode as in createOrder request
- *
- * Use setCountryCode() to specify the country code matching the original
- * createOrder request.
- *
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
-
- return $this;
- }
-
- /**
- * PaymentPlan only
- * Required for creditPaymentPlanOrder() -- use contract number recieved with deliverOrder response.
- *
- *
- * @param string $contractNumberAsString
- * @return $this
- */
- public function setContractNumber($contractNumberAsString)
- {
- $this->contractNumber = $contractNumberAsString;
-
- return $this;
- }
-
- /**
- * Required
- *
- * @param string $descriptionAsString
- * @return $this
- */
- public function setDescription($descriptionAsString)
- {
- $this->description = $descriptionAsString;
-
- return $this;
- }
-
- /**
- * Use creditPaymentPlanAmount() to cancel amount to a delivered Payment plan using AdminServiceRequest
- * CreditAmount request
- * @return CreditAmountRequest
- */
- public function creditPaymentPlanAmount()
- {
- $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
-
- // CreditPaymentPlan amount is really a CancelPaymentPlanAmount in API but wrapped in lib
- return new CreditAmountRequest($this);
- }
-
- /**
- * Use creditAccountCreditAmount() to cancel amount to a delivered AccountCredit using AdminServiceRequest
- * CreditAmount request
- *
- * @return CreditAmountAccountCreditRequest
- */
- public function creditAccountCredit()
- {
- $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
-
- return new CreditAmountAccountCreditRequest($this);
- }
-
- /**
- * Use creditCheckoutAmount() to cancel amount to a Checkout order
- * @return CreditOrderAmountService
- * @throws ValidationException
- * @throws \Exception
- */
- public function creditCheckoutAmount()
- {
- return new CreditOrderAmountService($this);
- }
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
+
+ /**
+ * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, PAYMENTPLAN_TYPE,
+ * ::HOSTED_ADMIN_TYPE
+ */
+ public $orderType;
+
+ /**
+ * @var float $amountIncVat
+ */
+ public $amountIncVat;
+
+ /**
+ * @var string @contractNumber contract number as returned in the deliverOrder request response. PaymentPlan
+ * orders only.
+ */
+ public $contractNumber;
+
+ /**
+ * @var string $countryCode
+ */
+ public $countryCode;
+
+ /**
+ * @var string $description
+ */
+ public $description;
+
+ public function __construct($config) {
+ $this->conf = $config;
+ }
+
+ /**
+ * Required
+ * @param float $amountAsFloat
+ * @return $this
+ */
+ public function setAmountIncVat($amountAsFloat)
+ {
+ $this->amountIncVat = $amountAsFloat;
+
+ return $this;
+ }
+
+ /**
+ * Required -- use same countryCode as in createOrder request
+ *
+ * Use setCountryCode() to specify the country code matching the original
+ * createOrder request.
+ *
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+
+ return $this;
+ }
+
+ /**
+ * PaymentPlan only
+ * Required for creditPaymentPlanOrder() -- use contract number recieved with deliverOrder response.
+ *
+ *
+ * @param string $contractNumberAsString
+ * @return $this
+ */
+ public function setContractNumber($contractNumberAsString)
+ {
+ $this->contractNumber = $contractNumberAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required
+ *
+ * @param string $descriptionAsString
+ * @return $this
+ */
+ public function setDescription($descriptionAsString)
+ {
+ $this->description = $descriptionAsString;
+
+ return $this;
+ }
+
+ /**
+ * Use creditPaymentPlanAmount() to cancel amount to a delivered Payment plan using AdminServiceRequest
+ * CreditAmount request
+ * @return CreditAmountRequest
+ */
+ public function creditPaymentPlanAmount()
+ {
+ $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+
+ // CreditPaymentPlan amount is really a CancelPaymentPlanAmount in API but wrapped in lib
+ return new CreditAmountRequest($this);
+ }
+
+ /**
+ * Use creditAccountCreditAmount() to cancel amount to a delivered AccountCredit using AdminServiceRequest
+ * CreditAmount request
+ *
+ * @return CreditAmountAccountCreditRequest
+ */
+ public function creditAccountCredit()
+ {
+ $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+
+ return new CreditAmountAccountCreditRequest($this);
+ }
+
+ /**
+ * Use creditCheckoutAmount() to cancel amount to a Checkout order
+ * @return CreditOrderAmountService
+ * @throws ValidationException
+ * @throws \Exception
+ */
+ public function creditCheckoutAmount()
+ {
+ return new CreditOrderAmountService($this);
+ }
}
diff --git a/src/BuildOrder/CreditOrderRowsBuilder.php b/src/BuildOrder/CreditOrderRowsBuilder.php
index 2c0c3b36..30748f38 100644
--- a/src/BuildOrder/CreditOrderRowsBuilder.php
+++ b/src/BuildOrder/CreditOrderRowsBuilder.php
@@ -54,417 +54,417 @@
*/
class CreditOrderRowsBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
-
- /**
- * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, PAYMENTPLAN_TYPE, ::HOSTED_ADMIN_TYPE
- */
- public $orderType;
-
- /**
- * @var OrderRow[] $creditOrderRows any additional new order rows to credit
- */
- public $creditOrderRows;
-
- /**
- * @var int[] $rowsToCredit array of original order row indexes to credit
- */
- public $rowsToCredit;
-
- /**
- * @var NumberedOrderRow[] $numberedOrderRows numbered order rows passed in for hosted service orders
- */
- public $numberedOrderRows;
-
- /**
- * @var string @invoiceId invoice id as returned in the deliverOrder request response. Invoice orders only.
- */
- public $invoiceId;
-
- /**
- * @var string @contractNumber contract number as returned in the deliverOrder request response.
- * PaymentPlan orders only.
- */
- public $contractNumber;
-
- /**
- * @var string $orderId card/direct bank order transaction id as returned in the createOrder request response,
- */
- public $orderId;
-
- /**
- * @var string $countryCode
- */
- public $countryCode;
-
- /**
- * @var string "Post" or "Email"
- */
- public $distributionType;
-
- /**
- * CreditOrderRowsBuilder constructor.
- * @param $config
- */
- public function __construct($config)
- {
- $this->conf = $config;
- $this->creditOrderRows = array();
- $this->rowsToCredit = array();
- $this->numberedOrderRows = array();
- }
-
- /**
- * Required -- use same countryCode as in createOrder request
- *
- * Use setCountryCode() to specify the country code matching the original
- * createOrder request.
- *
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
- return $this;
- }
-
- /**
- * Invoice only
- * Required for creditInvoiceOrder() -- use invoice id recieved with deliverOrder response.
- *
- * @param string $invoiceIdAsString
- * @return $this
- */
- public function setInvoiceId($invoiceIdAsString)
- {
- $this->invoiceId = $invoiceIdAsString;
- return $this;
- }
-
- /**
- * @param mixed $amountIncVat
- * @return $this
- */
- public function setAmountIncVat($amountIncVat)
- {
- $this->amountIncVat = $amountIncVat;
- return $this;
- }
-
- /**
- * PaymentPlan only
- * Required for creditPaymentPlanOrder() -- use contract number recieved with deliverOrder response.
- *
- * @param string $contractNumberAsString
- * @return $this
- */
- public function setContractNumber($contractNumberAsString)
- {
- $this->contractNumber = $contractNumberAsString;
- return $this;
- }
-
- /**
- * Required for creditCardOrder() -- use the order id (transaction id) received with the createOrder response.
- *
- * @param string $orderIdAsString
- * @return $this
- */
- public function setOrderId($orderIdAsString)
- {
- $this->orderId = $orderIdAsString;
- return $this;
- }
-
- /**
- * Optional for creditCardOrder() -- use the order id (transaction id) received with the createOrder response.
- *
- * This is an alias for setOrderId().
- *
- * @param string $orderIdAsString
- * @return $this
- */
- public function setTransactionId($orderIdAsString)
- {
- return $this->setOrderId($orderIdAsString);
- }
-
- /**
- * Required for creditInvoiceOrder() -- must match the invoice distribution type for the order
- *
- * @param string $distributionTypeAsConst -
- * i.e. Svea\WebPay\Constant\DistributionType::POST|Svea\WebPay\Constant\DistributionType::EMAIL
- * @return $this
- */
- public function setInvoiceDistributionType($distributionTypeAsConst)
- {
- $this->distributionType = $distributionTypeAsConst;
- return $this;
- }
-
- /**
- * Required -- a row number to credit
- *
- * Use setRowToCredit() or setRowsToCredit() to specify order rows to credit.
- * The given row numbers must correspond with the the serverside row number.
- *
- * @param string $rowNumber
- * @return $this
- */
- public function setRowToCredit($rowNumber)
- {
- $this->rowsToCredit[] = $rowNumber;
- return $this;
- }
-
- /**
- * Optional -- convenience method to provide several row numbers at once.
- *
- * @param int[] $rowNumbers
- * @return $this
- */
- public function setRowsToCredit($rowNumbers)
- {
- $this->rowsToCredit = array_merge($this->rowsToCredit, $rowNumbers);
- return $this;
- }
-
- /**
- * Optional -- add an order row to credit that was not present in the original order.
- *
- * These rows will be credited in addition to the rows specified using setRow(s)ToCredit
- *
- * @param OrderRow $row
- * @return $this
- */
- public function addCreditOrderRow($row)
- {
- $this->creditOrderRows[] = $row;
- return $this;
- }
-
- /**
- * Optional -- convenience method to add serveral new rows at once.
- *
- * @param OrderRow[] $rows
- * @return $this
- */
- public function addCreditOrderRows($rows)
- {
- $this->creditOrderRows = array_merge($this->creditOrderRows, $rows);
- return $this;
- }
-
- /**
- * CreditCardOrderRows, CreditDirectBankOrderRows: Required - add information on a single numbered order row
- *
- * When crediting card or direct bank order rows, you must pass in information about the row
- * along with the request. The rows are then matched with the order rows specified
- * using setRow(s)ToCredit().
- *
- * Use the Svea\WebPay\WebPayAdmin::queryOrder() entrypoint to get information about the order,
- * the queryOrder response numberedOrderRows attribute contains the order rows and
- * their numbers.
- *
- * When used with card or direct bank orders the following limitations apply:
- * You need to supply the NumberedOrderRows on which to operate. These may be
- * fetched using the queryOrder method, but if the order has been edited after
- * creation they may not be accurate.
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow $numberedOrderRow instance of NumberedOrderRow
- * @return $this
- */
- public function addNumberedOrderRow($numberedOrderRow)
- {
- $this->numberedOrderRows[] = $numberedOrderRow;
- return $this;
- }
-
- /**
- * CreditCardOrderRows, CreditDirectBankOrderRows: Optional - convenience method to provide several numbered order rows at once.
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow[] $numberedOrderRows array of NumberedOrderRow
- * @return $this
- */
- public function addNumberedOrderRows($numberedOrderRows)
- {
- $this->numberedOrderRows = array_merge($this->numberedOrderRows, $numberedOrderRows);
- return $this;
- }
-
- /**
- * Use creditInvoiceOrderRows() to credit rows to an Invoice order using AdminServiceRequest CreditOrderRows request
- * @return CreditInvoiceRowsRequest
- */
- public function creditInvoiceOrderRows()
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
-
- // validation is done in CreditInvoiceRowsRequest
-
- return new CreditInvoiceRowsRequest($this);
- }
-
- /**
- * Use CreditPaymentPlanOrderRows() to cancel rows to a delivered Payment plan using AdminServiceRequest CreditOrderRows request
- * @return CreditPaymentPlanRowsRequest
- */
- public function creditPaymentPlanOrderRows()
- {
- $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
-
- //Credit Paymentplan request is really cancelPaymentPlanRows but wrapped as creditPaymentPlanRows
- return new CreditPaymentPlanRowsRequest($this);
- }
-
- /**
- * Use creditAccountCreditOrderRows() to cancel rows to a delivered Account Credit using AdminServiceRequest CreditOrderRows request
- * @return CreditAccountCreditRowsRequest
- */
- public function creditAccountCreditOrderRows()
- {
- $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
-
- return new CreditAccountCreditRowsRequest($this);
- }
-
- /**
- * Use creditCardOrderRows() to credit a Card order by the specified order row amounts using HostedRequests CreditTransaction request
- *
- * @return CreditTransaction
- * @throws ValidationException if addNumberedOrderRows() has not been used.
- */
- public function creditCardOrderRows()
- {
- $this->orderType = ConfigurationProvider::HOSTED_ADMIN_TYPE;
-
- // we need to validate card on this level before translating attributes to those relevant to hosted admin functions
- $this->validateCreditCardOrderRows();
-
- $sumOfRowAmounts = $this->calculateSumOfRowAmounts($this->rowsToCredit, $this->numberedOrderRows, $this->creditOrderRows);
-
- $creditTransaction = new CreditTransaction($this->conf);
- $creditTransaction->transactionId = $this->orderId;
- $creditTransaction->creditAmount = Helper::bround($sumOfRowAmounts, 2) * 100; // *100, as setAmountToLower wants minor currency
- $creditTransaction->countryCode = $this->countryCode;
- return $creditTransaction;
- }
-
- /**
- * Use creditCheckoutOrderRows() to credit a Checkout order rows
- * @return CreditOrderRowsService
- * @throws ValidationException
- * @throws \Exception
- */
- public function creditCheckoutOrderRows()
- {
- return new CreditOrderRowsService($this);
- }
-
- /**
- * Use creditCheckoutOrderWithNewOrderRow() to credit a Checkout order with new credit Row
- * @return CreditOrderRowsService
- * @throws ValidationException
- * @throws \Exception
- */
- public function creditCheckoutOrderWithNewOrderRow()
- {
- return new CreditOrderRowsService($this, true);
- }
-
- /**
- * Use creditDirectBankOrderRows() to credit a Direct Bank order by the specified order row amounts using HostedRequests CreditTransaction request
- *
- * @return CreditTransaction
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException if addNumberedOrderRows() has not been used.
- */
- public function creditDirectBankOrderRows()
- {
- return $this->creditCardOrderRows();
- }
-
- /**
- * @internal
- */
- private function validateCreditCardOrderRows()
- {
- if (!isset($this->orderId)) {
- $exceptionString = "orderId is required for creditCardOrderRows(). Use method setOrderId().";
- throw new ValidationException($exceptionString);
- }
-
- if (!isset($this->countryCode)) {
- $exceptionString = "countryCode is required for creditCardOrderRows(). Use method setCountryCode().";
- throw new ValidationException($exceptionString);
- }
-
- if ((count($this->rowsToCredit) == 0) && (count($this->creditOrderRows) == 0)) {
- $exceptionString = "at least one of rowsToCredit or creditOrderRows must be set. Use setRowToCredit() or addCreditOrderRow().";
- throw new ValidationException($exceptionString);
- }
-
- if ((count($this->rowsToCredit) > 0) && ((count($this->rowsToCredit) != count($this->numberedOrderRows)))) {
- $exceptionString = "every entry in rowsToCredit must have a corresponding numberedOrderRows. Use setRowsToCredit() and addNumberedOrderRow().";
- throw new ValidationException($exceptionString);
- }
-
- // validate that indexes matches entries
- $numberedOrderRowNumbers = array_map(function ($nrow) {
- return $nrow->rowNumber;
- }, $this->numberedOrderRows);
-
- foreach ($this->rowsToCredit as $index) {
- if (!in_array($index, $numberedOrderRowNumbers)) {
- $exceptionString = "every entry in rowsToCredit must match a numberedOrderRows. Use setRowsToCredit() and addNumberedOrderRow().";
- throw new ValidationException($exceptionString);
- }
- }
-
- foreach ($this->creditOrderRows as $orderRow) {
- if ($orderRow->amountExVat && !isset($orderRow->vatPercent) && !isset($orderRow->amountIncVat)) {
- $exceptionString = "Order with amountExVat must have vatPercent";
- throw new ValidationException($exceptionString);
- }
-
- if (!isset($orderRow->amountExVat) && !isset($orderRow->amountIncVat)) {
- $exceptionString = "amountExVat or amountIncVat must be set";
- throw new ValidationException($exceptionString);
- }
- }
- }
-
- /**
- * @param $rowIndexes
- * @param $numberedRows
- * @param $creditOrderRows
- * @return float
- */
- private function calculateSumOfRowAmounts($rowIndexes, $numberedRows, $creditOrderRows)
- {
- $sum = 0.0;
- $unique_indexes = array_unique($rowIndexes);
- foreach ($numberedRows as $numberedRow) {
- if (in_array($numberedRow->rowNumber, $unique_indexes)) {
- if ($numberedRow->amountIncVat) {
- $sum += $numberedRow->quantity * $numberedRow->amountIncVat;
- } else {
- $sum += ($numberedRow->quantity * ($numberedRow->amountExVat * (1 + ($numberedRow->vatPercent / 100))));
- }
- }
- }
- if (count($creditOrderRows) > 0) {
- foreach ($creditOrderRows as $creditOrderRow) {
- if ($creditOrderRow->amountIncVat) {
- $sum += $creditOrderRow->quantity * $creditOrderRow->amountIncVat;
- } else {
- $sum += ($creditOrderRow->quantity * ($creditOrderRow->amountExVat * (1 + ($creditOrderRow->vatPercent / 100))));
- }
- }
- }
- return $sum;
- }
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
+
+ /**
+ * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, PAYMENTPLAN_TYPE, ::HOSTED_ADMIN_TYPE
+ */
+ public $orderType;
+
+ /**
+ * @var OrderRow[] $creditOrderRows any additional new order rows to credit
+ */
+ public $creditOrderRows;
+
+ /**
+ * @var int[] $rowsToCredit array of original order row indexes to credit
+ */
+ public $rowsToCredit;
+
+ /**
+ * @var NumberedOrderRow[] $numberedOrderRows numbered order rows passed in for hosted service orders
+ */
+ public $numberedOrderRows;
+
+ /**
+ * @var string @invoiceId invoice id as returned in the deliverOrder request response. Invoice orders only.
+ */
+ public $invoiceId;
+
+ /**
+ * @var string @contractNumber contract number as returned in the deliverOrder request response.
+ * PaymentPlan orders only.
+ */
+ public $contractNumber;
+
+ /**
+ * @var string $orderId card/direct bank order transaction id as returned in the createOrder request response,
+ */
+ public $orderId;
+
+ /**
+ * @var string $countryCode
+ */
+ public $countryCode;
+
+ /**
+ * @var string "Post" or "Email"
+ */
+ public $distributionType;
+
+ /**
+ * CreditOrderRowsBuilder constructor.
+ * @param $config
+ */
+ public function __construct($config)
+ {
+ $this->conf = $config;
+ $this->creditOrderRows = [];
+ $this->rowsToCredit = [];
+ $this->numberedOrderRows = [];
+ }
+
+ /**
+ * Required -- use same countryCode as in createOrder request
+ *
+ * Use setCountryCode() to specify the country code matching the original
+ * createOrder request.
+ *
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+ return $this;
+ }
+
+ /**
+ * Invoice only
+ * Required for creditInvoiceOrder() -- use invoice id recieved with deliverOrder response.
+ *
+ * @param string $invoiceIdAsString
+ * @return $this
+ */
+ public function setInvoiceId($invoiceIdAsString)
+ {
+ $this->invoiceId = $invoiceIdAsString;
+ return $this;
+ }
+
+ /**
+ * @param mixed $amountIncVat
+ * @return $this
+ */
+ public function setAmountIncVat($amountIncVat)
+ {
+ $this->amountIncVat = $amountIncVat;
+ return $this;
+ }
+
+ /**
+ * PaymentPlan only
+ * Required for creditPaymentPlanOrder() -- use contract number recieved with deliverOrder response.
+ *
+ * @param string $contractNumberAsString
+ * @return $this
+ */
+ public function setContractNumber($contractNumberAsString)
+ {
+ $this->contractNumber = $contractNumberAsString;
+ return $this;
+ }
+
+ /**
+ * Required for creditCardOrder() -- use the order id (transaction id) received with the createOrder response.
+ *
+ * @param string $orderIdAsString
+ * @return $this
+ */
+ public function setOrderId($orderIdAsString)
+ {
+ $this->orderId = $orderIdAsString;
+ return $this;
+ }
+
+ /**
+ * Optional for creditCardOrder() -- use the order id (transaction id) received with the createOrder response.
+ *
+ * This is an alias for setOrderId().
+ *
+ * @param string $orderIdAsString
+ * @return $this
+ */
+ public function setTransactionId($orderIdAsString)
+ {
+ return $this->setOrderId($orderIdAsString);
+ }
+
+ /**
+ * Required for creditInvoiceOrder() -- must match the invoice distribution type for the order
+ *
+ * @param string $distributionTypeAsConst -
+ * i.e. Svea\WebPay\Constant\DistributionType::POST|Svea\WebPay\Constant\DistributionType::EMAIL
+ * @return $this
+ */
+ public function setInvoiceDistributionType($distributionTypeAsConst)
+ {
+ $this->distributionType = $distributionTypeAsConst;
+ return $this;
+ }
+
+ /**
+ * Required -- a row number to credit
+ *
+ * Use setRowToCredit() or setRowsToCredit() to specify order rows to credit.
+ * The given row numbers must correspond with the the serverside row number.
+ *
+ * @param string $rowNumber
+ * @return $this
+ */
+ public function setRowToCredit($rowNumber)
+ {
+ $this->rowsToCredit[] = $rowNumber;
+ return $this;
+ }
+
+ /**
+ * Optional -- convenience method to provide several row numbers at once.
+ *
+ * @param int[] $rowNumbers
+ * @return $this
+ */
+ public function setRowsToCredit($rowNumbers)
+ {
+ $this->rowsToCredit = array_merge($this->rowsToCredit, $rowNumbers);
+ return $this;
+ }
+
+ /**
+ * Optional -- add an order row to credit that was not present in the original order.
+ *
+ * These rows will be credited in addition to the rows specified using setRow(s)ToCredit
+ *
+ * @param OrderRow $row
+ * @return $this
+ */
+ public function addCreditOrderRow($row)
+ {
+ $this->creditOrderRows[] = $row;
+ return $this;
+ }
+
+ /**
+ * Optional -- convenience method to add serveral new rows at once.
+ *
+ * @param OrderRow[] $rows
+ * @return $this
+ */
+ public function addCreditOrderRows($rows)
+ {
+ $this->creditOrderRows = array_merge($this->creditOrderRows, $rows);
+ return $this;
+ }
+
+ /**
+ * CreditCardOrderRows, CreditDirectBankOrderRows: Required - add information on a single numbered order row
+ *
+ * When crediting card or direct bank order rows, you must pass in information about the row
+ * along with the request. The rows are then matched with the order rows specified
+ * using setRow(s)ToCredit().
+ *
+ * Use the Svea\WebPay\WebPayAdmin::queryOrder() entrypoint to get information about the order,
+ * the queryOrder response numberedOrderRows attribute contains the order rows and
+ * their numbers.
+ *
+ * When used with card or direct bank orders the following limitations apply:
+ * You need to supply the NumberedOrderRows on which to operate. These may be
+ * fetched using the queryOrder method, but if the order has been edited after
+ * creation they may not be accurate.
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow $numberedOrderRow instance of NumberedOrderRow
+ * @return $this
+ */
+ public function addNumberedOrderRow($numberedOrderRow)
+ {
+ $this->numberedOrderRows[] = $numberedOrderRow;
+ return $this;
+ }
+
+ /**
+ * CreditCardOrderRows, CreditDirectBankOrderRows: Optional - convenience method to provide several numbered order rows at once.
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow[] $numberedOrderRows array of NumberedOrderRow
+ * @return $this
+ */
+ public function addNumberedOrderRows($numberedOrderRows)
+ {
+ $this->numberedOrderRows = array_merge($this->numberedOrderRows, $numberedOrderRows);
+ return $this;
+ }
+
+ /**
+ * Use creditInvoiceOrderRows() to credit rows to an Invoice order using AdminServiceRequest CreditOrderRows request
+ * @return CreditInvoiceRowsRequest
+ */
+ public function creditInvoiceOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ // validation is done in CreditInvoiceRowsRequest
+
+ return new CreditInvoiceRowsRequest($this);
+ }
+
+ /**
+ * Use CreditPaymentPlanOrderRows() to cancel rows to a delivered Payment plan using AdminServiceRequest CreditOrderRows request
+ * @return CreditPaymentPlanRowsRequest
+ */
+ public function creditPaymentPlanOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+
+ //Credit Paymentplan request is really cancelPaymentPlanRows but wrapped as creditPaymentPlanRows
+ return new CreditPaymentPlanRowsRequest($this);
+ }
+
+ /**
+ * Use creditAccountCreditOrderRows() to cancel rows to a delivered Account Credit using AdminServiceRequest CreditOrderRows request
+ * @return CreditAccountCreditRowsRequest
+ */
+ public function creditAccountCreditOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+
+ return new CreditAccountCreditRowsRequest($this);
+ }
+
+ /**
+ * Use creditCardOrderRows() to credit a Card order by the specified order row amounts using HostedRequests CreditTransaction request
+ *
+ * @return CreditTransaction
+ * @throws ValidationException if addNumberedOrderRows() has not been used.
+ */
+ public function creditCardOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::HOSTED_ADMIN_TYPE;
+
+ // we need to validate card on this level before translating attributes to those relevant to hosted admin functions
+ $this->validateCreditCardOrderRows();
+
+ $sumOfRowAmounts = $this->calculateSumOfRowAmounts($this->rowsToCredit, $this->numberedOrderRows, $this->creditOrderRows);
+
+ $creditTransaction = new CreditTransaction($this->conf);
+ $creditTransaction->transactionId = $this->orderId;
+ $creditTransaction->creditAmount = Helper::bround($sumOfRowAmounts, 2) * 100; // *100, as setAmountToLower wants minor currency
+ $creditTransaction->countryCode = $this->countryCode;
+ return $creditTransaction;
+ }
+
+ /**
+ * Use creditCheckoutOrderRows() to credit a Checkout order rows
+ * @return CreditOrderRowsService
+ * @throws ValidationException
+ * @throws \Exception
+ */
+ public function creditCheckoutOrderRows()
+ {
+ return new CreditOrderRowsService($this);
+ }
+
+ /**
+ * Use creditCheckoutOrderWithNewOrderRow() to credit a Checkout order with new credit Row
+ * @return CreditOrderRowsService
+ * @throws ValidationException
+ * @throws \Exception
+ */
+ public function creditCheckoutOrderWithNewOrderRow()
+ {
+ return new CreditOrderRowsService($this, true);
+ }
+
+ /**
+ * Use creditDirectBankOrderRows() to credit a Direct Bank order by the specified order row amounts using HostedRequests CreditTransaction request
+ *
+ * @return CreditTransaction
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException if addNumberedOrderRows() has not been used.
+ */
+ public function creditDirectBankOrderRows()
+ {
+ return $this->creditCardOrderRows();
+ }
+
+ /**
+ * @internal
+ */
+ private function validateCreditCardOrderRows()
+ {
+ if (!isset($this->orderId)) {
+ $exceptionString = "orderId is required for creditCardOrderRows(). Use method setOrderId().";
+ throw new ValidationException($exceptionString);
+ }
+
+ if (!isset($this->countryCode)) {
+ $exceptionString = "countryCode is required for creditCardOrderRows(). Use method setCountryCode().";
+ throw new ValidationException($exceptionString);
+ }
+
+ if ((count($this->rowsToCredit) == 0) && (count($this->creditOrderRows) == 0)) {
+ $exceptionString = "at least one of rowsToCredit or creditOrderRows must be set. Use setRowToCredit() or addCreditOrderRow().";
+ throw new ValidationException($exceptionString);
+ }
+
+ if ((count($this->rowsToCredit) > 0) && ((count($this->rowsToCredit) != count($this->numberedOrderRows)))) {
+ $exceptionString = "every entry in rowsToCredit must have a corresponding numberedOrderRows. Use setRowsToCredit() and addNumberedOrderRow().";
+ throw new ValidationException($exceptionString);
+ }
+
+ // validate that indexes matches entries
+ $numberedOrderRowNumbers = array_map(function ($nrow) {
+ return $nrow->rowNumber;
+ }, $this->numberedOrderRows);
+
+ foreach ($this->rowsToCredit as $index) {
+ if (!in_array($index, $numberedOrderRowNumbers)) {
+ $exceptionString = "every entry in rowsToCredit must match a numberedOrderRows. Use setRowsToCredit() and addNumberedOrderRow().";
+ throw new ValidationException($exceptionString);
+ }
+ }
+
+ foreach ($this->creditOrderRows as $orderRow) {
+ if ($orderRow->amountExVat && !isset($orderRow->vatPercent) && !isset($orderRow->amountIncVat)) {
+ $exceptionString = "Order with amountExVat must have vatPercent";
+ throw new ValidationException($exceptionString);
+ }
+
+ if (!isset($orderRow->amountExVat) && !isset($orderRow->amountIncVat)) {
+ $exceptionString = "amountExVat or amountIncVat must be set";
+ throw new ValidationException($exceptionString);
+ }
+ }
+ }
+
+ /**
+ * @param $rowIndexes
+ * @param $numberedRows
+ * @param $creditOrderRows
+ * @return float
+ */
+ private function calculateSumOfRowAmounts($rowIndexes, $numberedRows, $creditOrderRows)
+ {
+ $sum = 0.0;
+ $unique_indexes = array_unique($rowIndexes);
+ foreach ($numberedRows as $numberedRow) {
+ if (in_array($numberedRow->rowNumber, $unique_indexes)) {
+ if ($numberedRow->amountIncVat) {
+ $sum += $numberedRow->quantity * $numberedRow->amountIncVat;
+ } else {
+ $sum += ($numberedRow->quantity * ($numberedRow->amountExVat * (1 + ($numberedRow->vatPercent / 100))));
+ }
+ }
+ }
+ if (count($creditOrderRows) > 0) {
+ foreach ($creditOrderRows as $creditOrderRow) {
+ if ($creditOrderRow->amountIncVat) {
+ $sum += $creditOrderRow->quantity * $creditOrderRow->amountIncVat;
+ } else {
+ $sum += ($creditOrderRow->quantity * ($creditOrderRow->amountExVat * (1 + ($creditOrderRow->vatPercent / 100))));
+ }
+ }
+ }
+ return $sum;
+ }
}
diff --git a/src/BuildOrder/DeliverOrderBuilder.php b/src/BuildOrder/DeliverOrderBuilder.php
index 4458e282..ac96816e 100644
--- a/src/BuildOrder/DeliverOrderBuilder.php
+++ b/src/BuildOrder/DeliverOrderBuilder.php
@@ -49,212 +49,212 @@
*/
class DeliverOrderBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var string $orderId order id/transaction id as returned in the createOrder request response,
- */
- public $orderId;
-
- /**
- * @var string $distributionType -- one of Svea\WebPay\Constant\DistributionType::POST, ::EMAIL
- */
- public $distributionType;
-
- /**
- * @var string $captureDate -- confirmation date on format "YYYY-MM-DD"
- */
- public $captureDate;
-
- /**
- * If Invoice is to be credit Invoice
- * @var $invoiceIdToCredit - Invoice Id
- */
- public $invoiceIdToCredit;
-
- /**
- * @var int $numberOfCreditDays
- */
- public $numberOfCreditDays;
-
- /**
- * @var string
- * \Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE or ::HOSTED_TYPE
- */
- public $orderType;
-
- /**
- * @param \Svea\WebPay\Config\ConfigurationProvider $config
- */
- public function __construct($config)
- {
- parent::__construct($config);
- }
-
- /**
- * @deprecated 2.0.0 -- use Svea\WebPay\WebPayAdmin::updateOrderRows in order to modify an existing order.
- *
- * 2.x: Optional. Use setOrderRows to add invoice order rows to deliver.
- * Rows matching the original create order request order rows will be
- * invoiced by Svea. If not all order rows match, an invoice order will be
- * partially delivered/invoiced, see the Svea Web Service EU API
- * documentation for details.
- * @param \Svea\WebPay\BuildOrder\RowBuilders\OrderRow $itemOrderRowObject
- * @return $this
- */
- public function addOrderRow($itemOrderRowObject)
- {
- return parent::addOrderRow($itemOrderRowObject);
- }
-
- /**
- * Required for invoice or part payment orders -- use the order id (transaction id) recieved with the createOrder
- * response.
- * @param string $orderIdAsString
- * @return $this
- */
- public function setOrderId($orderIdAsString)
- {
- $this->orderId = $orderIdAsString;
-
- return $this;
- }
-
- /**
- * Optional -- alias for setOrderId().
- * @param string $transactionIdAsString
- * @return $this
- */
- public function setTransactionId($transactionIdAsString)
- {
- return $this->setOrderId($transactionIdAsString);
- }
-
- /**
- * Optional for card orders -- confirmation date on format "YYYY-MM-DD"
- *
- * If no date is given the current date is used per default.
- *
- * @param $captureDateAsString
- * @return $this
- */
- public function setCaptureDate($captureDateAsString)
- {
- $this->captureDate = $captureDateAsString;
-
- return $this;
- }
-
- /**
- * Invoice only, required.
- * @param string $distributionTypeAsConst - Svea\WebPay\Constant\DistributionType i.e.
- * Svea\WebPay\Constant\DistributionType::POST|Svea\WebPay\Constant\DistributionType::EMAIL
- * @return $this
- */
- public function setInvoiceDistributionType($distributionTypeAsConst)
- {
- $this->distributionType = $distributionTypeAsConst;
-
- return $this;
- }
-
- /**
- * Invoice only, optional
- * Use if this should be a credit invoice
- * @param $invoiceId
- * @return $this
- */
- public function setCreditInvoice($invoiceId)
- {
- $this->invoiceIdToCredit = $invoiceId;
-
- return $this;
- }
-
- /**
- * Invoice only, optional
- * @param int $numberOfDaysAsInt
- * @return $this
- */
- public function setNumberOfCreditDays($numberOfDaysAsInt)
- {
- $this->numberOfCreditDays = $numberOfDaysAsInt;
-
- return $this;
- }
-
- /**
- * To ensure backwards compatibility, deliverInvoiceOrder() checks if the
- * order has any order rows defined, and if so performs a DeliverOrderEU
- * request to Svea, passing on the order rows.
- *
- * If no order rows are defined, deliverInvoiceOrder() performs a
- * DeliverOrders request using the Admin Web Service API at Svea.
- *
- * @return DeliverInvoice|DeliverOrdersRequest
- */
- public function deliverInvoiceOrder()
- {
- if (count($this->orderRows) > 0) {
- return new DeliverInvoice($this);
- } else {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
-
- return new DeliverOrdersRequest($this);
- }
- }
-
- /**
- * deliverPaymentPlanOrder prepares the PaymentPlan order for delivery.
- * @return DeliverPaymentPlan
- */
- public function deliverPaymentPlanOrder()
- {
- $this->distributionType = DistributionType::POST;
-
- return new DeliverPaymentPlan($this);
- }
-
- /**
- * deliverAccountCreditOrder prepares the AccountPlan order for delivery.
- * @return DeliverAccountCredit
- */
- public function deliverAccountCreditOrder()
- {
- if (count($this->orderRows) > 0) {
- return new DeliverAccountCredit($this);
- } else {
- $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
-
- return new DeliverOrdersRequest($this);
- }
-
- }
-
- /**
- * deliverCardOrder() sets the status of a card order to CONFIRMED.
- *
- * A default capturedate equal to the current date will be supplied. This
- * may be overridden using the ConfirmTransaction setCaptureDate() method
- * on the returned ConfirmTransaction object.
- *
- * @return ConfirmTransaction
- */
- public function deliverCardOrder()
- {
- $this->orderType = ConfigurationProvider::HOSTED_TYPE;
-
- // validation is done in ConfirmTransaction
-
- // if no captureDate set, use today's date as default.
- if (!isset($this->captureDate)) {
- $defaultCaptureDate = explode("T", date('c')); // [0] contains date part
- $this->captureDate = $defaultCaptureDate[0];
- }
-
- $confirmTransaction = new ConfirmTransaction($this->conf);
- $confirmTransaction->transactionId = $this->orderId;
- $confirmTransaction->captureDate = $this->captureDate;
- $confirmTransaction->countryCode = $this->countryCode;
-
- return $confirmTransaction;
- }
+ /**
+ * @var string $orderId order id/transaction id as returned in the createOrder request response,
+ */
+ public $orderId;
+
+ /**
+ * @var string $distributionType -- one of Svea\WebPay\Constant\DistributionType::POST, ::EMAIL
+ */
+ public $distributionType;
+
+ /**
+ * @var string $captureDate -- confirmation date on format "YYYY-MM-DD"
+ */
+ public $captureDate;
+
+ /**
+ * If Invoice is to be credit Invoice
+ * @var $invoiceIdToCredit - Invoice Id
+ */
+ public $invoiceIdToCredit;
+
+ /**
+ * @var int $numberOfCreditDays
+ */
+ public $numberOfCreditDays;
+
+ /**
+ * @var string
+ * \Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE or ::HOSTED_TYPE
+ */
+ public $orderType;
+
+ /**
+ * @param \Svea\WebPay\Config\ConfigurationProvider $config
+ */
+ public function __construct($config)
+ {
+ parent::__construct($config);
+ }
+
+ /**
+ * @deprecated 2.0.0 -- use Svea\WebPay\WebPayAdmin::updateOrderRows in order to modify an existing order.
+ *
+ * 2.x: Optional. Use setOrderRows to add invoice order rows to deliver.
+ * Rows matching the original create order request order rows will be
+ * invoiced by Svea. If not all order rows match, an invoice order will be
+ * partially delivered/invoiced, see the Svea Web Service EU API
+ * documentation for details.
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\OrderRow $itemOrderRowObject
+ * @return $this
+ */
+ public function addOrderRow($itemOrderRowObject)
+ {
+ return parent::addOrderRow($itemOrderRowObject);
+ }
+
+ /**
+ * Required for invoice or part payment orders -- use the order id (transaction id) recieved with the createOrder
+ * response.
+ * @param string $orderIdAsString
+ * @return $this
+ */
+ public function setOrderId($orderIdAsString)
+ {
+ $this->orderId = $orderIdAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional -- alias for setOrderId().
+ * @param string $transactionIdAsString
+ * @return $this
+ */
+ public function setTransactionId($transactionIdAsString)
+ {
+ return $this->setOrderId($transactionIdAsString);
+ }
+
+ /**
+ * Optional for card orders -- confirmation date on format "YYYY-MM-DD"
+ *
+ * If no date is given the current date is used per default.
+ *
+ * @param $captureDateAsString
+ * @return $this
+ */
+ public function setCaptureDate($captureDateAsString)
+ {
+ $this->captureDate = $captureDateAsString;
+
+ return $this;
+ }
+
+ /**
+ * Invoice only, required.
+ * @param string $distributionTypeAsConst - Svea\WebPay\Constant\DistributionType i.e.
+ * Svea\WebPay\Constant\DistributionType::POST|Svea\WebPay\Constant\DistributionType::EMAIL
+ * @return $this
+ */
+ public function setInvoiceDistributionType($distributionTypeAsConst)
+ {
+ $this->distributionType = $distributionTypeAsConst;
+
+ return $this;
+ }
+
+ /**
+ * Invoice only, optional
+ * Use if this should be a credit invoice
+ * @param $invoiceId
+ * @return $this
+ */
+ public function setCreditInvoice($invoiceId)
+ {
+ $this->invoiceIdToCredit = $invoiceId;
+
+ return $this;
+ }
+
+ /**
+ * Invoice only, optional
+ * @param int $numberOfDaysAsInt
+ * @return $this
+ */
+ public function setNumberOfCreditDays($numberOfDaysAsInt)
+ {
+ $this->numberOfCreditDays = $numberOfDaysAsInt;
+
+ return $this;
+ }
+
+ /**
+ * To ensure backwards compatibility, deliverInvoiceOrder() checks if the
+ * order has any order rows defined, and if so performs a DeliverOrderEU
+ * request to Svea, passing on the order rows.
+ *
+ * If no order rows are defined, deliverInvoiceOrder() performs a
+ * DeliverOrders request using the Admin Web Service API at Svea.
+ *
+ * @return DeliverInvoice|DeliverOrdersRequest
+ */
+ public function deliverInvoiceOrder()
+ {
+ if (count($this->orderRows) > 0) {
+ return new DeliverInvoice($this);
+ } else {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ return new DeliverOrdersRequest($this);
+ }
+ }
+
+ /**
+ * deliverPaymentPlanOrder prepares the PaymentPlan order for delivery.
+ * @return DeliverPaymentPlan
+ */
+ public function deliverPaymentPlanOrder()
+ {
+ $this->distributionType = DistributionType::POST;
+
+ return new DeliverPaymentPlan($this);
+ }
+
+ /**
+ * deliverAccountCreditOrder prepares the AccountPlan order for delivery.
+ * @return DeliverAccountCredit
+ */
+ public function deliverAccountCreditOrder()
+ {
+ if (count($this->orderRows) > 0) {
+ return new DeliverAccountCredit($this);
+ } else {
+ $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+
+ return new DeliverOrdersRequest($this);
+ }
+
+ }
+
+ /**
+ * deliverCardOrder() sets the status of a card order to CONFIRMED.
+ *
+ * A default capturedate equal to the current date will be supplied. This
+ * may be overridden using the ConfirmTransaction setCaptureDate() method
+ * on the returned ConfirmTransaction object.
+ *
+ * @return ConfirmTransaction
+ */
+ public function deliverCardOrder()
+ {
+ $this->orderType = ConfigurationProvider::HOSTED_TYPE;
+
+ // validation is done in ConfirmTransaction
+
+ // if no captureDate set, use today's date as default.
+ if (!isset($this->captureDate)) {
+ $defaultCaptureDate = explode("T", date('c')); // [0] contains date part
+ $this->captureDate = $defaultCaptureDate[0];
+ }
+
+ $confirmTransaction = new ConfirmTransaction($this->conf);
+ $confirmTransaction->transactionId = $this->orderId;
+ $confirmTransaction->captureDate = $this->captureDate;
+ $confirmTransaction->countryCode = $this->countryCode;
+
+ return $confirmTransaction;
+ }
}
diff --git a/src/BuildOrder/DeliverOrderRowsBuilder.php b/src/BuildOrder/DeliverOrderRowsBuilder.php
index 8a81e45c..655efec5 100644
--- a/src/BuildOrder/DeliverOrderRowsBuilder.php
+++ b/src/BuildOrder/DeliverOrderRowsBuilder.php
@@ -48,298 +48,298 @@
*/
class DeliverOrderRowsBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
-
- /**
- * @var string $orderId order id/transaction id as returned in the createOrder request response,
- */
- public $orderId;
-
- /**
- * @var string $countryCode
- */
- public $countryCode;
-
- /**
- * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::HOSTED_ADMIN_TYPE
- */
- public $orderType;
-
- /**
- * @var string $distributionType -- one of Svea\WebPay\Constant\DistributionType::POST, ::EMAIL
- */
- public $distributionType;
-
- /**
- * @var int[] $rowsToDeliver array of original order row indexes to deliver
- */
- public $rowsToDeliver;
-
- public $numberedOrderRows;
-
- /**
- * DeliverOrderRowsBuilder constructor.
- * @param $config
- */
- public function __construct($config)
- {
- parent::__construct($config);
- $this->rowsToDeliver = array();
- $this->numberedOrderRows = array();
- }
-
- /**
- * Required -- use same countryCode as in createOrder request
- *
- * Use setCountryCode() to specify the country code matching the original
- * createOrder request.
- *
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
-
- return $this;
- }
-
- /**
- * Optional for deliverCardOrder() -- use the order id (transaction id) received with the createOrder response.
- *
- * This is an alias for setOrderId().
- *
- * @param string $orderIdAsString
- * @return $this
- */
- public function setTransactionId($orderIdAsString)
- {
- return $this->setOrderId($orderIdAsString);
- }
-
- /**
- * Required -- must match the invoice distribution type for the order
- *
- * @param DistributionType $distributionTypeAsConst - i.e.
- * Svea\WebPay\Constant\DistributionType::POST|Svea\WebPay\Constant\DistributionType::EMAIL
- * @return $this
- */
- public function setInvoiceDistributionType($distributionTypeAsConst)
- {
- $this->distributionType = $distributionTypeAsConst;
-
- return $this;
- }
-
- /**
- * Required -- a row number to deliver
- *
- * Use setRowToDeliver() or setRowsToDeliver() to specify order rows to deliver.
- * The given row numbers must correspond with the serverside row numbers.
- *
- * For card orders, the rows must match order rows specified using addNumberedOrderRow() or addNumberedOrderRows().
- *
- * For invoice orders, the serverside order rows is updated after a deliverOrderRows request.
- * Note that for Card and orders the serverside order rows will not be updated.
- *
- * @param string $rowNumber
- * @return $this
- */
- public function setRowToDeliver($rowNumber)
- {
- $this->rowsToDeliver[] = $rowNumber;
-
- return $this;
- }
-
- /**
- * Optional -- convenience method to provide several row numbers at once.
- *
- * @param int[] $rowNumbers
- * @return $this
- */
- public function setRowsToDeliver($rowNumbers)
- {
- $this->rowsToDeliver = array_merge($this->rowsToDeliver, $rowNumbers);
-
- return $this;
- }
-
- /**
- * Required for card orders -- add information on a single numbered order row
- *
- * For card orders, it is required to use addNumberedOrderRow() or addNumberedOrderRows()
- * to pass in a copy of the serverside order row data. All order rows must be supplied.
- *
- * You can use the Svea\WebPay\WebPayAdmin::queryOrder() entrypoint to get information about the order,
- * the QueryOrderResponse->numberedOrderRows attribute contains the order rows, but
- * note that if the order has been modified after creation these may not be accurate.
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow $numberedOrderRows instance of NumberedOrderRow
- * @return $this
- */
- public function addNumberedOrderRow($numberedOrderRow)
- {
- $this->numberedOrderRows[] = $numberedOrderRow;
-
- return $this;
- }
-
- /**
- * Optional for card orders -- convenience method to provide several numbered order rows at once.
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow[] $numberedOrderRows array of NumberedOrderRow
- * @return $this
- */
- public function addNumberedOrderRows($numberedOrderRows)
- {
- $this->numberedOrderRows = array_merge($this->numberedOrderRows, $numberedOrderRows);
-
- return $this;
- }
-
- /**
- * Use deliverInvoiceOrderRows() to deliver rows to an Invoice order using AdminServiceRequest DeliverOrderRows
- * request
- * @return DeliverOrderRowsRequest
- */
- public function deliverInvoiceOrderRows()
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
-
- $this->validateDeliverInvoiceOrderRows();
-
- return new DeliverOrderRowsRequest($this);
- }
-
- /**
- * Use deliverAccountCreditOrderRows() to deliver rows to an AccountCredit order using AdminServiceRequest DeliverOrderRows
- * request
- * @return DeliverOrderRowsRequest
- */
- public function deliverAccountCreditOrderRows()
- {
- $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
-
- $this->validateDeliverInvoiceOrderRows();
-
- return new DeliverOrderRowsRequest($this);
- }
-
- /**
- * Use deliverCardOrderRows() to deliver rows to an Card order using HostedService requests.
- *
- * Then use deliverInvoiceOrderRows() or deliver CardOrderRows to get a request object,
- * which ever matches the payment method used in the original order. deliverCardOrderRows
- * Calculates the correct amount to deliver from supplied order rows and when followed by a
- * a ->doRequest() call performs a LowerTransaction followed by a ConfirmTransaction. Note
- * that the card transaction must have status AUTHORIZED at Svea in order to be delivered.
- *
- * @return ConfirmTransactionResponse
- */
- public function deliverCardOrderRows()
- {
- $this->orderType = ConfigurationProvider::HOSTED_TYPE;
-
- $this->validateDeliverCardOrderRows();
-
- $total_amount = 0;
- foreach ($this->numberedOrderRows as $row) {
- $total_amount += ($row->amountExVat * (1 + $row->vatPercent / 100));
- }
-
- $total_delivered = 0;
- foreach ($this->rowsToDeliver as $row_index) {
- $row = $this->numberedOrderRows[$row_index - 1];
- $total_delivered += ($row->amountExVat * (1 + $row->vatPercent / 100));
- }
-
- $amountToLower = $total_amount - $total_delivered;
- $amountToLower *= 100; // minor currency
-
- $lowerTransactionRequest = new LowerTransaction($this->conf);
- $lowerTransactionRequest->countryCode = $this->countryCode;
- $lowerTransactionRequest->transactionId = $this->orderId;
- $lowerTransactionRequest->amountToLower = $amountToLower;
- $lowerTransactionRequest->alsoDoConfirm = true;
-
- return $lowerTransactionRequest;
- }
-
- /**
- * Use deliverCheckoutOrderRows() to deliver rows to an Checkout Order.
- * @return DeliverOrderService
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @throws \Exception
- */
- public function deliverCheckoutOrderRows()
- {
- return new DeliverOrderService($this, true);
- }
-
- /**
- * Use deliverCheckoutOrder() to deliver whole Checkout Order.
- * @return DeliverOrderService
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @throws \Exception
- */
- public function deliverCheckoutOrder()
- {
- return new DeliverOrderService($this);
- }
-
- /**
- * @internal
- */
- private function validateDeliverInvoiceOrderRows()
- {
- if (!isset($this->orderId)) {
- $exceptionString = "orderId is required for deliverInvoiceOrderRows(). Use method setOrderId().";
- throw new ValidationException($exceptionString);
- }
-
- if (!isset($this->countryCode)) {
- $exceptionString = "countryCode is required for deliverInvoiceOrderRows(). Use method setCountryCode().";
- throw new ValidationException($exceptionString);
- }
-
- if (!isset($this->distributionType)) {
- $exceptionString = "distributionType is required for deliverInvoiceOrderRows(). Use method setInvoiceDistributionType().";
- throw new ValidationException($exceptionString);
- }
-
- if ((count($this->rowsToDeliver) == 0)) {
- $exceptionString = "rowsToDeliver is required for deliverInvoiceOrderRows(). Use methods setRowToDeliver() or setRowsToDeliver().";
- throw new ValidationException($exceptionString);
- }
- }
-
- /**
- * @internal
- */
- private function validateDeliverCardOrderRows()
- {
- if (!isset($this->orderId)) {
- $exceptionString = "orderId is required for deliverInvoiceOrderRows(). Use method setOrderId().";
- throw new ValidationException($exceptionString);
- }
-
- if (!isset($this->countryCode)) {
- $exceptionString = "countryCode is required for deliverInvoiceOrderRows(). Use method setCountryCode().";
- throw new ValidationException($exceptionString);
- }
-
- if ((count($this->rowsToDeliver) == 0)) {
- $exceptionString = "rowsToDeliver is required for deliverCardOrderRows(). Use methods setRowToDeliver() or setRowsToDeliver().";
- throw new ValidationException($exceptionString);
- }
-
- if ((count($this->numberedOrderRows) == 0)) {
- $exceptionString = "numberedOrderRows is required for deliverCardOrderRows(). Use setNumberedOrderRow() or setNumberedOrderRows().";
- throw new ValidationException($exceptionString);
- }
- }
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
+
+ /**
+ * @var string $orderId order id/transaction id as returned in the createOrder request response,
+ */
+ public $orderId;
+
+ /**
+ * @var string $countryCode
+ */
+ public $countryCode;
+
+ /**
+ * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::HOSTED_ADMIN_TYPE
+ */
+ public $orderType;
+
+ /**
+ * @var string $distributionType -- one of Svea\WebPay\Constant\DistributionType::POST, ::EMAIL
+ */
+ public $distributionType;
+
+ /**
+ * @var int[] $rowsToDeliver array of original order row indexes to deliver
+ */
+ public $rowsToDeliver;
+
+ public $numberedOrderRows;
+
+ /**
+ * DeliverOrderRowsBuilder constructor.
+ * @param $config
+ */
+ public function __construct($config)
+ {
+ parent::__construct($config);
+ $this->rowsToDeliver = [];
+ $this->numberedOrderRows = [];
+ }
+
+ /**
+ * Required -- use same countryCode as in createOrder request
+ *
+ * Use setCountryCode() to specify the country code matching the original
+ * createOrder request.
+ *
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional for deliverCardOrder() -- use the order id (transaction id) received with the createOrder response.
+ *
+ * This is an alias for setOrderId().
+ *
+ * @param string $orderIdAsString
+ * @return $this
+ */
+ public function setTransactionId($orderIdAsString)
+ {
+ return $this->setOrderId($orderIdAsString);
+ }
+
+ /**
+ * Required -- must match the invoice distribution type for the order
+ *
+ * @param DistributionType $distributionTypeAsConst - i.e.
+ * Svea\WebPay\Constant\DistributionType::POST|Svea\WebPay\Constant\DistributionType::EMAIL
+ * @return $this
+ */
+ public function setInvoiceDistributionType($distributionTypeAsConst)
+ {
+ $this->distributionType = $distributionTypeAsConst;
+
+ return $this;
+ }
+
+ /**
+ * Required -- a row number to deliver
+ *
+ * Use setRowToDeliver() or setRowsToDeliver() to specify order rows to deliver.
+ * The given row numbers must correspond with the serverside row numbers.
+ *
+ * For card orders, the rows must match order rows specified using addNumberedOrderRow() or addNumberedOrderRows().
+ *
+ * For invoice orders, the serverside order rows is updated after a deliverOrderRows request.
+ * Note that for Card and orders the serverside order rows will not be updated.
+ *
+ * @param string $rowNumber
+ * @return $this
+ */
+ public function setRowToDeliver($rowNumber)
+ {
+ $this->rowsToDeliver[] = $rowNumber;
+
+ return $this;
+ }
+
+ /**
+ * Optional -- convenience method to provide several row numbers at once.
+ *
+ * @param int[] $rowNumbers
+ * @return $this
+ */
+ public function setRowsToDeliver($rowNumbers)
+ {
+ $this->rowsToDeliver = array_merge($this->rowsToDeliver, $rowNumbers);
+
+ return $this;
+ }
+
+ /**
+ * Required for card orders -- add information on a single numbered order row
+ *
+ * For card orders, it is required to use addNumberedOrderRow() or addNumberedOrderRows()
+ * to pass in a copy of the serverside order row data. All order rows must be supplied.
+ *
+ * You can use the Svea\WebPay\WebPayAdmin::queryOrder() entrypoint to get information about the order,
+ * the QueryOrderResponse->numberedOrderRows attribute contains the order rows, but
+ * note that if the order has been modified after creation these may not be accurate.
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow $numberedOrderRows instance of NumberedOrderRow
+ * @return $this
+ */
+ public function addNumberedOrderRow($numberedOrderRow)
+ {
+ $this->numberedOrderRows[] = $numberedOrderRow;
+
+ return $this;
+ }
+
+ /**
+ * Optional for card orders -- convenience method to provide several numbered order rows at once.
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow[] $numberedOrderRows array of NumberedOrderRow
+ * @return $this
+ */
+ public function addNumberedOrderRows($numberedOrderRows)
+ {
+ $this->numberedOrderRows = array_merge($this->numberedOrderRows, $numberedOrderRows);
+
+ return $this;
+ }
+
+ /**
+ * Use deliverInvoiceOrderRows() to deliver rows to an Invoice order using AdminServiceRequest DeliverOrderRows
+ * request
+ * @return DeliverOrderRowsRequest
+ */
+ public function deliverInvoiceOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ $this->validateDeliverInvoiceOrderRows();
+
+ return new DeliverOrderRowsRequest($this);
+ }
+
+ /**
+ * Use deliverAccountCreditOrderRows() to deliver rows to an AccountCredit order using AdminServiceRequest DeliverOrderRows
+ * request
+ * @return DeliverOrderRowsRequest
+ */
+ public function deliverAccountCreditOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+
+ $this->validateDeliverInvoiceOrderRows();
+
+ return new DeliverOrderRowsRequest($this);
+ }
+
+ /**
+ * Use deliverCardOrderRows() to deliver rows to an Card order using HostedService requests.
+ *
+ * Then use deliverInvoiceOrderRows() or deliver CardOrderRows to get a request object,
+ * which ever matches the payment method used in the original order. deliverCardOrderRows
+ * Calculates the correct amount to deliver from supplied order rows and when followed by a
+ * a ->doRequest() call performs a LowerTransaction followed by a ConfirmTransaction. Note
+ * that the card transaction must have status AUTHORIZED at Svea in order to be delivered.
+ *
+ * @return ConfirmTransactionResponse
+ */
+ public function deliverCardOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::HOSTED_TYPE;
+
+ $this->validateDeliverCardOrderRows();
+
+ $total_amount = 0;
+ foreach ($this->numberedOrderRows as $row) {
+ $total_amount += ($row->amountExVat * (1 + $row->vatPercent / 100));
+ }
+
+ $total_delivered = 0;
+ foreach ($this->rowsToDeliver as $row_index) {
+ $row = $this->numberedOrderRows[$row_index - 1];
+ $total_delivered += ($row->amountExVat * (1 + $row->vatPercent / 100));
+ }
+
+ $amountToLower = $total_amount - $total_delivered;
+ $amountToLower *= 100; // minor currency
+
+ $lowerTransactionRequest = new LowerTransaction($this->conf);
+ $lowerTransactionRequest->countryCode = $this->countryCode;
+ $lowerTransactionRequest->transactionId = $this->orderId;
+ $lowerTransactionRequest->amountToLower = $amountToLower;
+ $lowerTransactionRequest->alsoDoConfirm = true;
+
+ return $lowerTransactionRequest;
+ }
+
+ /**
+ * Use deliverCheckoutOrderRows() to deliver rows to an Checkout Order.
+ * @return DeliverOrderService
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @throws \Exception
+ */
+ public function deliverCheckoutOrderRows()
+ {
+ return new DeliverOrderService($this, true);
+ }
+
+ /**
+ * Use deliverCheckoutOrder() to deliver whole Checkout Order.
+ * @return DeliverOrderService
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @throws \Exception
+ */
+ public function deliverCheckoutOrder()
+ {
+ return new DeliverOrderService($this);
+ }
+
+ /**
+ * @internal
+ */
+ private function validateDeliverInvoiceOrderRows()
+ {
+ if (!isset($this->orderId)) {
+ $exceptionString = "orderId is required for deliverInvoiceOrderRows(). Use method setOrderId().";
+ throw new ValidationException($exceptionString);
+ }
+
+ if (!isset($this->countryCode)) {
+ $exceptionString = "countryCode is required for deliverInvoiceOrderRows(). Use method setCountryCode().";
+ throw new ValidationException($exceptionString);
+ }
+
+ if (!isset($this->distributionType)) {
+ $exceptionString = "distributionType is required for deliverInvoiceOrderRows(). Use method setInvoiceDistributionType().";
+ throw new ValidationException($exceptionString);
+ }
+
+ if ((count($this->rowsToDeliver) == 0)) {
+ $exceptionString = "rowsToDeliver is required for deliverInvoiceOrderRows(). Use methods setRowToDeliver() or setRowsToDeliver().";
+ throw new ValidationException($exceptionString);
+ }
+ }
+
+ /**
+ * @internal
+ */
+ private function validateDeliverCardOrderRows()
+ {
+ if (!isset($this->orderId)) {
+ $exceptionString = "orderId is required for deliverInvoiceOrderRows(). Use method setOrderId().";
+ throw new ValidationException($exceptionString);
+ }
+
+ if (!isset($this->countryCode)) {
+ $exceptionString = "countryCode is required for deliverInvoiceOrderRows(). Use method setCountryCode().";
+ throw new ValidationException($exceptionString);
+ }
+
+ if ((count($this->rowsToDeliver) == 0)) {
+ $exceptionString = "rowsToDeliver is required for deliverCardOrderRows(). Use methods setRowToDeliver() or setRowsToDeliver().";
+ throw new ValidationException($exceptionString);
+ }
+
+ if ((count($this->numberedOrderRows) == 0)) {
+ $exceptionString = "numberedOrderRows is required for deliverCardOrderRows(). Use setNumberedOrderRow() or setNumberedOrderRows().";
+ throw new ValidationException($exceptionString);
+ }
+ }
}
diff --git a/src/BuildOrder/OrderBuilder.php b/src/BuildOrder/OrderBuilder.php
index d6d6997d..7d86cdc3 100644
--- a/src/BuildOrder/OrderBuilder.php
+++ b/src/BuildOrder/OrderBuilder.php
@@ -12,335 +12,335 @@
*/
class OrderBuilder
{
- /**
- * @var boolean true indicates test mode, false indicates production mode
- */
- public $testmode = false;
-
- /**
- * @var boolean
- */
- public $logging = false;
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
-
- /**
- * @var \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer|\Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer
- */
- public $customerIdentity;
-
- /**
- * @var \Svea\WebPay\BuildOrder\RowBuilders\OrderRow [] array of OrderRow
- */
- public $orderRows = array();
-
- /**
- * @var \Svea\WebPay\BuildOrder\RowBuilders\ShippingFee [] array of ShippingFee
- */
- public $shippingFeeRows = array();
-
- /**
- * @var \Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee [] array of InvoiceFee
- */
- public $invoiceFeeRows = array();
-
- /**
- * @var \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount [] array of FixedDiscount
- */
- public $fixedDiscountRows = array();
-
- /**
- * @var \Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount [] array of RelativeDiscount
- */
- public $relativeDiscountRows = array();
-
- /**
- * @var array $rows of all rows in the order they are set
- */
- public $rows = array();
-
- /**
- * @var string Country code as described by ISO 3166-1: "SE", "NO", "DK", "FI","DE", "NL"
- */
- public $countryCode;
-
- /**
- * @var string Currency in ISO 4217 three-letter format, ex. "SEK", "EUR"
- */
- public $currency;
-
- /**
- * @var string ISO 8601 date, as produced by php date('c'): "2004-02-12T15:19:21+00:00", also accepts dates like "2004-02-12"
- */
- public $orderDate;
-
- /**
- * @var string your customer Reference number
- */
- public $customerReference;
-
- /**
- * @var string order number given by client side, should uniquely identify order at client
- */
- public $clientOrderNumber;
-
- /*
- * @var \Svea\WebPay\BuildOrder\RowBuilders\OrderDeliveryAddress
- */
- public $orderDeliveryAddress;
-
- /*
- * @var string Used to send Peppol invoices
- */
- public $peppolId;
-
- /*
- * @var string Mobile number to payer, only used with Swish else ignored
- */
- public $payerAlias;
-
- /**
- * @param ConfigurationProvider $config
- */
- public function __construct($config)
- {
- $this->conf = $config;
- }
-
- /*
- * Optional
- * @param \Svea\WebPay\BuildOrder\RowBuilders\OrderDeliveryAddress
- * @return $this
- */
- public function setOrderDeliveryAddress($orderDeliveryAddressObject)
- {
- $this->orderDeliveryAddress = $orderDeliveryAddressObject;
-
- return $this;
- }
-
- /**
- * Required for invoice and payment plan orders - add customer information to the order
- * Optional for card and direct bank orders
- *
- * See the customer objects for information on required customer information fields for
- * invoice and payment plan orders.
- *
- * @see \Svea\IndividualCustomer \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer
- * @see \Svea\CompanyCustomer \Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer|\Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer $itemCustomerObject
- * @return $this
- */
- public function addCustomerDetails($itemCustomerObject)
- {
- $this->customerIdentity = $itemCustomerObject;
-
- return $this;
- }
-
- /**
- * Required - you need to add at least one order row to the order
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\OrderRow $itemOrderRowObject
- * @return $this
- */
- public function addOrderRow($itemOrderRowObject)
- {
- if (is_array($itemOrderRowObject)) {
- foreach ($itemOrderRowObject as $row) {
- array_push($this->orderRows, $row);
- array_push($this->rows, $row);
- }
- } else {
- array_push($this->orderRows, $itemOrderRowObject);
- array_push($this->rows, $itemOrderRowObject);
- }
-
- return $this;
- }
-
- /**
- * Optional - adds a shipping fee or invoice fee to the order
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee|\Svea\WebPay\BuildOrder\RowBuilders\ShippingFee $itemFeeObject
- * @return $this
- */
- public function addFee($itemFeeObject)
- {
- if (is_array($itemFeeObject)) {
- foreach ($itemFeeObject as $row) {
- array_push($this->rows, $row);
- if (get_class($row) == 'Svea\WebPay\BuildOrder\RowBuilders\ShippingFee') {
- array_push($this->shippingFeeRows, $row);
- }
- if (get_class($row) == 'Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee') {
- array_push($this->invoiceFeeRows, $row);
- }
- }
- } else {
- array_push($this->rows, $itemFeeObject);
- if (get_class($itemFeeObject) == 'Svea\WebPay\BuildOrder\RowBuilders\ShippingFee') {
- array_push($this->shippingFeeRows, $itemFeeObject);
- }
- if (get_class($itemFeeObject) == 'Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee') {
- array_push($this->invoiceFeeRows, $itemFeeObject);
- }
- }
-
- return $this;
- }
-
- /**
- * Optional - adds a fixed amount discount or an order total percent discount to the order
- *
- * See the discount objects for information on how the discount is calculated et al.
- *
- * @see \Svea\FixedDiscount \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount
- * @see \Svea\RelativeDiscount \Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount|\Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount $itemDiscountObject
- *
- * @return $this
- */
- public function addDiscount($itemDiscountObject)
- {
- if (is_array($itemDiscountObject)) {
- foreach ($itemDiscountObject as $row) {
- array_push($this->rows, $row);
- if (get_class($row) == 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount') {
- array_push($this->fixedDiscountRows, $row);
- }
- if (get_class($row) == 'Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount') {
- array_push($this->relativeDiscountRows, $row);
- }
- }
- } else {
- array_push($this->rows, $itemDiscountObject);
- if (get_class($itemDiscountObject) == 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount') {
- array_push($this->fixedDiscountRows, $itemDiscountObject);
- }
- if (get_class($itemDiscountObject) == 'Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount') {
- array_push($this->relativeDiscountRows, $itemDiscountObject);
- }
- }
-
- return $this;
- }
-
- /**
- * Required - set order country code, we recommend basing this on the customer billing address
- *
- * For orders using the invoice or payment plan payment methods, you need to supply a country code that corresponds
- * to the account credentials used for the address lookup. (Note that this means that these methods don't support
- * orders from foreign countries, this is a consequence of the fact that the invoice and payment plan payment
- * methods don't support foreign orders.)
- *
- * @param string $countryCodeAsString Country code as described by ISO 3166-1, one of "SE", "NO", "DK", "FI", "DE", "NL"
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
-
- return $this;
- }
-
- /**
- * Required for card payment, direct bank & PayPage payments. Ignored for invoice and payment plan.
- *
- * Ignored for invoice and payment plan orders, which use the selected client id currency, as determined by Svea\WebPay\Config\ConfigurationProvider and setCountryCode.
- *
- * @param string $currencyAsString in ISO 4217 three-letter format, ex. "SEK", "EUR"
- * @return $this
- */
- public function setCurrency($currencyAsString)
- {
- $currency = strtoupper(trim($currencyAsString));
- $this->currency = $currency;
-
- return $this;
- }
-
- /**
- * Optional - set a client side customer reference, i.e. customer number etc.
- * Max length 30 characters.
- *
- * @param string $customerReferenceAsString needs to be unique to the order for card and direct bank orders
- * @return $this
- */
- public function setCustomerReference($customerReferenceAsString)
- {
- $this->customerReference = $customerReferenceAsString;
-
- return $this;
- }
-
- /**
- * Required for Card, Direct Bank and Svea\WebPay\Constant\PaymentMethod and PayPage orders - set a client side order identifier, i.e. the webshop order number etc.
- * Max length 30 characters.
- *
- * Note that for Card and Direct Bank orders, you may not reuse a previously sent client order number, or you'll get error 127 from the service.
- *
- * @param string $clientOrderNumberAsString
- * @return $this
- */
- public function setClientOrderNumber($clientOrderNumberAsString)
- {
- $this->clientOrderNumber = $clientOrderNumberAsString;
-
- return $this;
- }
-
- /**
- * Required for Invoice and Payment plan orders -- set the order date
- *
- * @param string $orderDateAsString ISO 8601 date, as produced by php date('c'): "2004-02-12T15:19:21+00:00", also accepts dates like "2004-02-12"
- * @return $this
- */
- public function setOrderDate($orderDateAsString)
- {
- $this->orderDate = $orderDateAsString;
-
- return $this;
- }
-
- /**
- * Enables/disables logging for raw HTTP requests / responses
- *
- * @param boolean $status, if true then raw requests / responses will be logged on the order. Disabled by default.
- * @return $this
- */
- public function enableLogging($status)
- {
- $this->logging = $status;
-
- return $this;
- }
-
- /**
- * Optional, used to send Peppol invoices
- * @param string $peppolId
- * @return $this
- */
- public function setPeppolId($peppolId)
- {
- $this->peppolId = $peppolId;
-
- return $this;
- }
-
- /**
- * Required if using Swish, ignored if not
- * @param string $payerAlias
- * @return $this
- */
- public function setPayerAlias($payerAlias)
- {
- $this->payerAlias = $payerAlias;
-
- return $this;
- }
+ /**
+ * @var boolean true indicates test mode, false indicates production mode
+ */
+ public $testmode = false;
+
+ /**
+ * @var boolean
+ */
+ public $logging = false;
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
+
+ /**
+ * @var \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer|\Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer
+ */
+ public $customerIdentity;
+
+ /**
+ * @var \Svea\WebPay\BuildOrder\RowBuilders\OrderRow [] array of OrderRow
+ */
+ public $orderRows = [];
+
+ /**
+ * @var \Svea\WebPay\BuildOrder\RowBuilders\ShippingFee [] array of ShippingFee
+ */
+ public $shippingFeeRows = [];
+
+ /**
+ * @var \Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee [] array of InvoiceFee
+ */
+ public $invoiceFeeRows = [];
+
+ /**
+ * @var \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount [] array of FixedDiscount
+ */
+ public $fixedDiscountRows = [];
+
+ /**
+ * @var \Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount [] array of RelativeDiscount
+ */
+ public $relativeDiscountRows = [];
+
+ /**
+ * @var array $rows of all rows in the order they are set
+ */
+ public $rows = [];
+
+ /**
+ * @var string Country code as described by ISO 3166-1: "SE", "NO", "DK", "FI","DE", "NL"
+ */
+ public $countryCode;
+
+ /**
+ * @var string Currency in ISO 4217 three-letter format, ex. "SEK", "EUR"
+ */
+ public $currency;
+
+ /**
+ * @var string ISO 8601 date, as produced by php date('c'): "2004-02-12T15:19:21+00:00", also accepts dates like "2004-02-12"
+ */
+ public $orderDate;
+
+ /**
+ * @var string your customer Reference number
+ */
+ public $customerReference;
+
+ /**
+ * @var string order number given by client side, should uniquely identify order at client
+ */
+ public $clientOrderNumber;
+
+ /*
+ * @var \Svea\WebPay\BuildOrder\RowBuilders\OrderDeliveryAddress
+ */
+ public $orderDeliveryAddress;
+
+ /*
+ * @var string Used to send Peppol invoices
+ */
+ public $peppolId;
+
+ /*
+ * @var string Mobile number to payer, only used with Swish else ignored
+ */
+ public $payerAlias;
+
+ /**
+ * @param ConfigurationProvider $config
+ */
+ public function __construct($config)
+ {
+ $this->conf = $config;
+ }
+
+ /*
+ * Optional
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\OrderDeliveryAddress
+ * @return $this
+ */
+ public function setOrderDeliveryAddress($orderDeliveryAddressObject)
+ {
+ $this->orderDeliveryAddress = $orderDeliveryAddressObject;
+
+ return $this;
+ }
+
+ /**
+ * Required for invoice and payment plan orders - add customer information to the order
+ * Optional for card and direct bank orders
+ *
+ * See the customer objects for information on required customer information fields for
+ * invoice and payment plan orders.
+ *
+ * @see \Svea\IndividualCustomer \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer
+ * @see \Svea\CompanyCustomer \Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer|\Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer $itemCustomerObject
+ * @return $this
+ */
+ public function addCustomerDetails($itemCustomerObject)
+ {
+ $this->customerIdentity = $itemCustomerObject;
+
+ return $this;
+ }
+
+ /**
+ * Required - you need to add at least one order row to the order
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\OrderRow $itemOrderRowObject
+ * @return $this
+ */
+ public function addOrderRow($itemOrderRowObject)
+ {
+ if (is_array($itemOrderRowObject)) {
+ foreach ($itemOrderRowObject as $row) {
+ array_push($this->orderRows, $row);
+ array_push($this->rows, $row);
+ }
+ } else {
+ array_push($this->orderRows, $itemOrderRowObject);
+ array_push($this->rows, $itemOrderRowObject);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Optional - adds a shipping fee or invoice fee to the order
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee|\Svea\WebPay\BuildOrder\RowBuilders\ShippingFee $itemFeeObject
+ * @return $this
+ */
+ public function addFee($itemFeeObject)
+ {
+ if (is_array($itemFeeObject)) {
+ foreach ($itemFeeObject as $row) {
+ array_push($this->rows, $row);
+ if (get_class($row) == 'Svea\WebPay\BuildOrder\RowBuilders\ShippingFee') {
+ array_push($this->shippingFeeRows, $row);
+ }
+ if (get_class($row) == 'Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee') {
+ array_push($this->invoiceFeeRows, $row);
+ }
+ }
+ } else {
+ array_push($this->rows, $itemFeeObject);
+ if (get_class($itemFeeObject) == 'Svea\WebPay\BuildOrder\RowBuilders\ShippingFee') {
+ array_push($this->shippingFeeRows, $itemFeeObject);
+ }
+ if (get_class($itemFeeObject) == 'Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee') {
+ array_push($this->invoiceFeeRows, $itemFeeObject);
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * Optional - adds a fixed amount discount or an order total percent discount to the order
+ *
+ * See the discount objects for information on how the discount is calculated et al.
+ *
+ * @see \Svea\FixedDiscount \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount
+ * @see \Svea\RelativeDiscount \Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount|\Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount $itemDiscountObject
+ *
+ * @return $this
+ */
+ public function addDiscount($itemDiscountObject)
+ {
+ if (is_array($itemDiscountObject)) {
+ foreach ($itemDiscountObject as $row) {
+ array_push($this->rows, $row);
+ if (get_class($row) == 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount') {
+ array_push($this->fixedDiscountRows, $row);
+ }
+ if (get_class($row) == 'Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount') {
+ array_push($this->relativeDiscountRows, $row);
+ }
+ }
+ } else {
+ array_push($this->rows, $itemDiscountObject);
+ if (get_class($itemDiscountObject) == 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount') {
+ array_push($this->fixedDiscountRows, $itemDiscountObject);
+ }
+ if (get_class($itemDiscountObject) == 'Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount') {
+ array_push($this->relativeDiscountRows, $itemDiscountObject);
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * Required - set order country code, we recommend basing this on the customer billing address
+ *
+ * For orders using the invoice or payment plan payment methods, you need to supply a country code that corresponds
+ * to the account credentials used for the address lookup. (Note that this means that these methods don't support
+ * orders from foreign countries, this is a consequence of the fact that the invoice and payment plan payment
+ * methods don't support foreign orders.)
+ *
+ * @param string $countryCodeAsString Country code as described by ISO 3166-1, one of "SE", "NO", "DK", "FI", "DE", "NL"
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required for card payment, direct bank & PayPage payments. Ignored for invoice and payment plan.
+ *
+ * Ignored for invoice and payment plan orders, which use the selected client id currency, as determined by Svea\WebPay\Config\ConfigurationProvider and setCountryCode.
+ *
+ * @param string $currencyAsString in ISO 4217 three-letter format, ex. "SEK", "EUR"
+ * @return $this
+ */
+ public function setCurrency($currencyAsString)
+ {
+ $currency = strtoupper(trim($currencyAsString));
+ $this->currency = $currency;
+
+ return $this;
+ }
+
+ /**
+ * Optional - set a client side customer reference, i.e. customer number etc.
+ * Max length 30 characters.
+ *
+ * @param string $customerReferenceAsString needs to be unique to the order for card and direct bank orders
+ * @return $this
+ */
+ public function setCustomerReference($customerReferenceAsString)
+ {
+ $this->customerReference = $customerReferenceAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required for Card, Direct Bank and Svea\WebPay\Constant\PaymentMethod and PayPage orders - set a client side order identifier, i.e. the webshop order number etc.
+ * Max length 30 characters.
+ *
+ * Note that for Card and Direct Bank orders, you may not reuse a previously sent client order number, or you'll get error 127 from the service.
+ *
+ * @param string $clientOrderNumberAsString
+ * @return $this
+ */
+ public function setClientOrderNumber($clientOrderNumberAsString)
+ {
+ $this->clientOrderNumber = $clientOrderNumberAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required for Invoice and Payment plan orders -- set the order date
+ *
+ * @param string $orderDateAsString ISO 8601 date, as produced by php date('c'): "2004-02-12T15:19:21+00:00", also accepts dates like "2004-02-12"
+ * @return $this
+ */
+ public function setOrderDate($orderDateAsString)
+ {
+ $this->orderDate = $orderDateAsString;
+
+ return $this;
+ }
+
+ /**
+ * Enables/disables logging for raw HTTP requests / responses
+ *
+ * @param boolean $status, if true then raw requests / responses will be logged on the order. Disabled by default.
+ * @return $this
+ */
+ public function enableLogging($status)
+ {
+ $this->logging = $status;
+
+ return $this;
+ }
+
+ /**
+ * Optional, used to send Peppol invoices
+ * @param string $peppolId
+ * @return $this
+ */
+ public function setPeppolId($peppolId)
+ {
+ $this->peppolId = $peppolId;
+
+ return $this;
+ }
+
+ /**
+ * Required if using Swish, ignored if not
+ * @param string $payerAlias
+ * @return $this
+ */
+ public function setPayerAlias($payerAlias)
+ {
+ $this->payerAlias = $payerAlias;
+
+ return $this;
+ }
}
diff --git a/src/BuildOrder/PaymentAdminOrderBuilder.php b/src/BuildOrder/PaymentAdminOrderBuilder.php
index de43d9ca..a6cba2bd 100644
--- a/src/BuildOrder/PaymentAdminOrderBuilder.php
+++ b/src/BuildOrder/PaymentAdminOrderBuilder.php
@@ -2,8 +2,8 @@
namespace Svea\WebPay\BuildOrder;
-use Svea\WebPay\Config\SveaConfigurationProvider;
-use Svea\WebPay\BuildOrder\Validator\ValidationException;
+use Svea\WebPay\Config\SveaConfigurationProvider;
+use Svea\WebPay\BuildOrder\Validator\ValidationException;
/**
* Class PaymentAdminOrderBuilder
@@ -11,84 +11,84 @@
*/
class PaymentAdminOrderBuilder
{
- /**
- * @var string $orderId
- */
- public $orderId;
+ /**
+ * @var string $orderId
+ */
+ public $orderId;
- /**
- * @var SveaConfigurationProvider
- */
- public $conf;
+ /**
+ * @var SveaConfigurationProvider
+ */
+ public $conf;
- /**
- * @var string $countryCode
- */
- public $countryCode;
+ /**
+ * @var string $countryCode
+ */
+ public $countryCode;
- /**
- * PaymentAdminOrderBuilder constructor.
- * @param $configProvider
- */
- public function __construct($configProvider)
- {
- $this->conf = $configProvider;
- }
+ /**
+ * PaymentAdminOrderBuilder constructor.
+ * @param $configProvider
+ */
+ public function __construct($configProvider)
+ {
+ $this->conf = $configProvider;
+ }
-
- /**
- * @param $clientNumber
- */
- private function setClientNumberConfigurationValue($clientNumber)
- {
- $this->conf->setClientNumber($clientNumber);
- }
- /**
- * @return mixed
- */
- public function getOrderId()
- {
- return $this->orderId;
- }
+ /**
+ * @param $clientNumber
+ */
+ private function setClientNumberConfigurationValue($clientNumber)
+ {
+ $this->conf->setClientNumber($clientNumber);
+ }
- /**
- * @param mixed $orderId
- * @return $this
- */
- public function setOrderId($orderId)
- {
- $this->orderId = $orderId;
- return $this;
- }
+ /**
+ * @return mixed
+ */
+ public function getOrderId()
+ {
+ return $this->orderId;
+ }
- /**
- * @return string
- */
- public function getCountryCode()
- {
- return $this->countryCode;
- }
+ /**
+ * @param mixed $orderId
+ * @return $this
+ */
+ public function setOrderId($orderId)
+ {
+ $this->orderId = $orderId;
+ return $this;
+ }
- /**
- * @param $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
- return $this;
- }
+ /**
+ * @return string
+ */
+ public function getCountryCode()
+ {
+ return $this->countryCode;
+ }
+
+ /**
+ * @param $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+ return $this;
+ }
+
+ /**
+ * Optional -- alias for setOrderId().
+ * @param string $transactionIdAsString
+ * @return $this
+ */
+ public function setTransactionId($transactionIdAsString)
+ {
+ return $this->setOrderId($transactionIdAsString);
+ }
- /**
- * Optional -- alias for setOrderId().
- * @param string $transactionIdAsString
- * @return $this
- */
- public function setTransactionId($transactionIdAsString)
- {
- return $this->setOrderId($transactionIdAsString);
- }
-
}
diff --git a/src/BuildOrder/QueryOrderBuilder.php b/src/BuildOrder/QueryOrderBuilder.php
index a4d748ff..1115d4d1 100644
--- a/src/BuildOrder/QueryOrderBuilder.php
+++ b/src/BuildOrder/QueryOrderBuilder.php
@@ -29,130 +29,130 @@
*/
class QueryOrderBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
-
- /**
- * @var string $orderId
- */
- public $orderId;
-
- /**
- * @var string $countryCode
- */
- public $countryCode;
-
- /**
- * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_TYPE
- */
- public $orderType;
-
- public function __construct($config) {
- $this->conf = $config;
- }
-
- /**
- * Required for invoice or part payment orders -- use the order id (transaction id) recieved with the createOrder response.
- * @param string $orderIdAsString
- * @return $this
- */
- public function setOrderId($orderIdAsString) {
- $this->orderId = $orderIdAsString;
- return $this;
- }
- /**
- * Optional -- alias for setOrderId().
- * @param string $transactionIdAsString
- * @return $this
- */
- public function setTransactionId($transactionIdAsString) {
- return $this->setOrderId($transactionIdAsString);
- }
-
- /**
- * Required. Use same countryCode as in createOrder request.
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
- return $this;
- }
-
- /**
- * Use queryInvoiceOrder() to query an Invoice order.
- * @return GetOrdersRequest
- */
- public function queryInvoiceOrder()
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
- return new GetOrdersRequest($this);
- }
-
- /**
- * Use queryPaymentPlanOrder() to query an PaymentPlan order.
- * @return GetOrdersRequest
- */
- public function queryPaymentPlanOrder()
- {
- $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
- return new GetOrdersRequest($this);
- }
-
- public function queryAccountCreditOrder()
- {
- $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
- return new GetOrdersRequest($this);
- }
-
-
- /**
- * Use queryCardOrder() to query a Card order.
- * @return QueryTransaction
- */
- public function queryCardOrder()
- {
- $this->orderType = ConfigurationProvider::HOSTED_ADMIN_TYPE;
- if(isset($this->clientOrderNumber))
- {
- $queryTransaction = new QueryTransactionByCustomerRefNo($this->conf);
- $queryTransaction->customerRefNo = $this->clientOrderNumber;
- }
- else
- {
- $queryTransaction = new QueryTransaction($this->conf);
- $queryTransaction->transactionId = $this->orderId;
- }
- $queryTransaction->countryCode = $this->countryCode;
- return $queryTransaction;
- }
-
- /**
- * Use queryDirectBankOrder() to query a Direct Bank order.
- * @return QueryTransaction
- */
- public function queryDirectBankOrder()
- {
- $this->orderType = ConfigurationProvider::HOSTED_ADMIN_TYPE;
- if(isset($this->clientOrderNumber))
- {
- $queryTransaction = new QueryTransactionByCustomerRefNo($this->conf);
- $queryTransaction->customerRefNo = $this->clientOrderNumber;
- }
- else
- {
- $queryTransaction = new QueryTransaction($this->conf);
- $queryTransaction->transactionId = $this->orderId;
- }
- $queryTransaction->countryCode = $this->countryCode;
- return $queryTransaction;
- }
-
- public function queryCheckoutOrder()
- {
- return new GetOrderService($this);
- }
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
+
+ /**
+ * @var string $orderId
+ */
+ public $orderId;
+
+ /**
+ * @var string $countryCode
+ */
+ public $countryCode;
+
+ /**
+ * @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_TYPE
+ */
+ public $orderType;
+
+ public function __construct($config) {
+ $this->conf = $config;
+ }
+
+ /**
+ * Required for invoice or part payment orders -- use the order id (transaction id) recieved with the createOrder response.
+ * @param string $orderIdAsString
+ * @return $this
+ */
+ public function setOrderId($orderIdAsString) {
+ $this->orderId = $orderIdAsString;
+ return $this;
+ }
+ /**
+ * Optional -- alias for setOrderId().
+ * @param string $transactionIdAsString
+ * @return $this
+ */
+ public function setTransactionId($transactionIdAsString) {
+ return $this->setOrderId($transactionIdAsString);
+ }
+
+ /**
+ * Required. Use same countryCode as in createOrder request.
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+ return $this;
+ }
+
+ /**
+ * Use queryInvoiceOrder() to query an Invoice order.
+ * @return GetOrdersRequest
+ */
+ public function queryInvoiceOrder()
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+ return new GetOrdersRequest($this);
+ }
+
+ /**
+ * Use queryPaymentPlanOrder() to query an PaymentPlan order.
+ * @return GetOrdersRequest
+ */
+ public function queryPaymentPlanOrder()
+ {
+ $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+ return new GetOrdersRequest($this);
+ }
+
+ public function queryAccountCreditOrder()
+ {
+ $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+ return new GetOrdersRequest($this);
+ }
+
+
+ /**
+ * Use queryCardOrder() to query a Card order.
+ * @return QueryTransaction
+ */
+ public function queryCardOrder()
+ {
+ $this->orderType = ConfigurationProvider::HOSTED_ADMIN_TYPE;
+ if(isset($this->clientOrderNumber))
+ {
+ $queryTransaction = new QueryTransactionByCustomerRefNo($this->conf);
+ $queryTransaction->customerRefNo = $this->clientOrderNumber;
+ }
+ else
+ {
+ $queryTransaction = new QueryTransaction($this->conf);
+ $queryTransaction->transactionId = $this->orderId;
+ }
+ $queryTransaction->countryCode = $this->countryCode;
+ return $queryTransaction;
+ }
+
+ /**
+ * Use queryDirectBankOrder() to query a Direct Bank order.
+ * @return QueryTransaction
+ */
+ public function queryDirectBankOrder()
+ {
+ $this->orderType = ConfigurationProvider::HOSTED_ADMIN_TYPE;
+ if(isset($this->clientOrderNumber))
+ {
+ $queryTransaction = new QueryTransactionByCustomerRefNo($this->conf);
+ $queryTransaction->customerRefNo = $this->clientOrderNumber;
+ }
+ else
+ {
+ $queryTransaction = new QueryTransaction($this->conf);
+ $queryTransaction->transactionId = $this->orderId;
+ }
+ $queryTransaction->countryCode = $this->countryCode;
+ return $queryTransaction;
+ }
+
+ public function queryCheckoutOrder()
+ {
+ return new GetOrderService($this);
+ }
}
diff --git a/src/BuildOrder/QueryTaskInfoBuilder.php b/src/BuildOrder/QueryTaskInfoBuilder.php
index fbeefc53..8cd63976 100644
--- a/src/BuildOrder/QueryTaskInfoBuilder.php
+++ b/src/BuildOrder/QueryTaskInfoBuilder.php
@@ -7,29 +7,29 @@
class QueryTaskInfoBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var string $taskUrl
- */
- public $taskUrl;
+ /**
+ * @var string $taskUrl
+ */
+ public $taskUrl;
- /**
- * Set Url that should be called with Svea Authorization
- *
- * @param string $url
- * @return $this
- */
- public function setTaskUrl($url)
- {
- $this->taskUrl = $url;
+ /**
+ * Set Url that should be called with Svea Authorization
+ *
+ * @param string $url
+ * @return $this
+ */
+ public function setTaskUrl($url)
+ {
+ $this->taskUrl = $url;
- return $this;
- }
+ return $this;
+ }
- /**
- * @return AdminImplementationService
- */
- public function getTaskInfo()
- {
- return new GetTaskInfoService($this);
- }
+ /**
+ * @return AdminImplementationService
+ */
+ public function getTaskInfo()
+ {
+ return new GetTaskInfoService($this);
+ }
}
diff --git a/src/BuildOrder/RowBuilders/CompanyCustomer.php b/src/BuildOrder/RowBuilders/CompanyCustomer.php
index e6e02e1e..9bee87f1 100644
--- a/src/BuildOrder/RowBuilders/CompanyCustomer.php
+++ b/src/BuildOrder/RowBuilders/CompanyCustomer.php
@@ -8,241 +8,241 @@
*/
class CompanyCustomer
{
- /**
- * @var string $orgNumber
- */
- public $orgNumber;
-
- /**
- * @var string $companyVatNumber
- */
- public $companyVatNumber;
-
- /**
- * @var string $email
- */
- public $email;
-
- /**
- * @var int $phonenumber
- */
- public $phonenumber;
-
- /**
- * @var string $ipAddress
- */
- public $ipAddress;
-
- /**
- * @var string $firstname
- */
- public $firstname;
-
- /**
- * @var string $lastname
- */
- public $lastname;
-
- /**
- * @var string $street
- */
- public $street;
-
- /**
- * @var int $housenumber
- */
- public $housenumber;
-
- /**
- * @var string $coAddress
- */
- public $coAddress;
-
- /**
- * @var string $zipCode
- */
- public $zipCode;
-
- /**
- * @var string $locality
- */
- public $locality;
-
- /**
- * @var string $companyName
- */
- public $companyName;
-
- /**
- * @var string $addressSelector
- */
- public $addressSelector;
-
- /**
- * $var string $publicKey
- */
- public $publicKey;
-
- // set in GetOrdersResponse
- public $streetAddress; // compounds street + housenumber,fullName, may be set by CreateOrder for i.e. orders where identify customer via ssn
-
- /**
- * Example: 4608142222
- * Required for company customers in SE, NO, DK, FI
- * For SE: Organisationsnummer
- * For NO: Organisasjonsnummer
- * For DK: CVR
- * For FI: Yritystunnus
- * @param string $companyIdNumberAsString
- * @return $this
- */
- public function setNationalIdNumber($companyIdNumberAsString)
- {
- $this->orgNumber = $companyIdNumberAsString;
-
- return $this;
- }
-
- /**
- * Example: NL123456789A12
- * @param string $vatNumberAsString
- * Required for NL and DE
- * @return $this
- */
- public function setVatNumber($vatNumberAsString)
- {
- $this->companyVatNumber = $vatNumberAsString;
-
- return $this;
- }
-
- /**
- * Optional but desirable
- * @param type $emailAsString
- * @return $this
- */
- public function setEmail($emailAsString)
- {
- $this->email = $emailAsString;
-
- return $this;
- }
-
- /**
- * Optional
- * @param int $phoneNumberAsInt
- * @return $this
- */
- public function setPhoneNumber($phoneNumberAsInt)
- {
- $this->phonenumber = $phoneNumberAsInt;
-
- return $this;
- }
-
- /**
- * Optinal but desirable
- * @param type $ipAddressAsString
- * @return $this
- */
- public function setIpAddress($ipAddressAsString)
- {
- $this->ipAddress = $ipAddressAsString;
-
- return $this;
- }
-
- /**
- * Required to set street and houseNumber in NL and DE
- * @param string $streetAsString , or $streetAddressAsString iff sole argument
- * @param int $houseNumberAsInt , or omitted if setting streetAddress
- * @return $this
- */
- public function setStreetAddress($streetAsString, $houseNumberAsInt = null)
- { // = null is poor man's overloading
- // only one name given, assume streetName;
- if ($houseNumberAsInt == null) {
- $streetAddressAsString = $streetAsString;
- $this->streetAddress = $streetAddressAsString;
- $this->street = $streetAsString; // preserve old behaviour if only street given (assume contains compounded street + housenumber)
- } else {
- $this->street = $streetAsString;
- $this->housenumber = $houseNumberAsInt;
- }
-
- return $this;
- }
-
- /**
- * Optional in NL and DE
- * @param type $coAddressAsString
- * @return $this
- */
- public function setCoAddress($coAddressAsString)
- {
- $this->coAddress = $coAddressAsString;
-
- return $this;
- }
-
- /**
- * Requuired in NL and DE
- * @param type $zipCodeAsString
- * @return $this
- */
- public function setZipCode($zipCodeAsString)
- {
- $this->zipCode = $zipCodeAsString;
-
- return $this;
- }
-
- /**
- * Required in NL and DE
- * @param type $cityAsString
- * @return $this
- */
- public function setLocality($cityAsString)
- {
- $this->locality = $cityAsString;
-
- return $this;
- }
-
- /**
- * Required for Eu countries like NL and DE
- * @param string $nameAsString
- * @return $this
- */
- public function setCompanyName($nameAsString)
- {
- $this->companyName = $nameAsString;
-
- return $this;
- }
-
- /**
- * Optional. If not set, the invoice/partpayment orders will use the first registered address as invoice address.
- * Recieve string param from getAddresses
- * @param type $addressSelectorAsString
- * @return $this
- */
- public function setAddressSelector($addressSelectorAsString)
- {
- $this->addressSelector = $addressSelectorAsString;
-
- return $this;
- }
-
- /**
- * Optional. Identifier for selecting a specific pre-approved address.
- * @param type $publicKeyAsString
- * @return $this
- */
- public function setPublicKey($publicKeyAsString)
- {
- $this->publicKey = $publicKeyAsString;
-
- return $this;
- }
+ /**
+ * @var string $orgNumber
+ */
+ public $orgNumber;
+
+ /**
+ * @var string $companyVatNumber
+ */
+ public $companyVatNumber;
+
+ /**
+ * @var string $email
+ */
+ public $email;
+
+ /**
+ * @var int $phonenumber
+ */
+ public $phonenumber;
+
+ /**
+ * @var string $ipAddress
+ */
+ public $ipAddress;
+
+ /**
+ * @var string $firstname
+ */
+ public $firstname;
+
+ /**
+ * @var string $lastname
+ */
+ public $lastname;
+
+ /**
+ * @var string $street
+ */
+ public $street;
+
+ /**
+ * @var int $housenumber
+ */
+ public $housenumber;
+
+ /**
+ * @var string $coAddress
+ */
+ public $coAddress;
+
+ /**
+ * @var string $zipCode
+ */
+ public $zipCode;
+
+ /**
+ * @var string $locality
+ */
+ public $locality;
+
+ /**
+ * @var string $companyName
+ */
+ public $companyName;
+
+ /**
+ * @var string $addressSelector
+ */
+ public $addressSelector;
+
+ /**
+ * $var string $publicKey
+ */
+ public $publicKey;
+
+ // set in GetOrdersResponse
+ public $streetAddress; // compounds street + housenumber,fullName, may be set by CreateOrder for i.e. orders where identify customer via ssn
+
+ /**
+ * Example: 4608142222
+ * Required for company customers in SE, NO, DK, FI
+ * For SE: Organisationsnummer
+ * For NO: Organisasjonsnummer
+ * For DK: CVR
+ * For FI: Yritystunnus
+ * @param string $companyIdNumberAsString
+ * @return $this
+ */
+ public function setNationalIdNumber($companyIdNumberAsString)
+ {
+ $this->orgNumber = $companyIdNumberAsString;
+
+ return $this;
+ }
+
+ /**
+ * Example: NL123456789A12
+ * @param string $vatNumberAsString
+ * Required for NL and DE
+ * @return $this
+ */
+ public function setVatNumber($vatNumberAsString)
+ {
+ $this->companyVatNumber = $vatNumberAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional but desirable
+ * @param type $emailAsString
+ * @return $this
+ */
+ public function setEmail($emailAsString)
+ {
+ $this->email = $emailAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional
+ * @param int $phoneNumberAsInt
+ * @return $this
+ */
+ public function setPhoneNumber($phoneNumberAsInt)
+ {
+ $this->phonenumber = $phoneNumberAsInt;
+
+ return $this;
+ }
+
+ /**
+ * Optinal but desirable
+ * @param type $ipAddressAsString
+ * @return $this
+ */
+ public function setIpAddress($ipAddressAsString)
+ {
+ $this->ipAddress = $ipAddressAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required to set street and houseNumber in NL and DE
+ * @param string $streetAsString , or $streetAddressAsString iff sole argument
+ * @param int $houseNumberAsInt , or omitted if setting streetAddress
+ * @return $this
+ */
+ public function setStreetAddress($streetAsString, $houseNumberAsInt = null)
+ { // = null is poor man's overloading
+ // only one name given, assume streetName;
+ if ($houseNumberAsInt == null) {
+ $streetAddressAsString = $streetAsString;
+ $this->streetAddress = $streetAddressAsString;
+ $this->street = $streetAsString; // preserve old behaviour if only street given (assume contains compounded street + housenumber)
+ } else {
+ $this->street = $streetAsString;
+ $this->housenumber = $houseNumberAsInt;
+ }
+
+ return $this;
+ }
+
+ /**
+ * Optional in NL and DE
+ * @param type $coAddressAsString
+ * @return $this
+ */
+ public function setCoAddress($coAddressAsString)
+ {
+ $this->coAddress = $coAddressAsString;
+
+ return $this;
+ }
+
+ /**
+ * Requuired in NL and DE
+ * @param type $zipCodeAsString
+ * @return $this
+ */
+ public function setZipCode($zipCodeAsString)
+ {
+ $this->zipCode = $zipCodeAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required in NL and DE
+ * @param type $cityAsString
+ * @return $this
+ */
+ public function setLocality($cityAsString)
+ {
+ $this->locality = $cityAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required for Eu countries like NL and DE
+ * @param string $nameAsString
+ * @return $this
+ */
+ public function setCompanyName($nameAsString)
+ {
+ $this->companyName = $nameAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional. If not set, the invoice/partpayment orders will use the first registered address as invoice address.
+ * Recieve string param from getAddresses
+ * @param type $addressSelectorAsString
+ * @return $this
+ */
+ public function setAddressSelector($addressSelectorAsString)
+ {
+ $this->addressSelector = $addressSelectorAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional. Identifier for selecting a specific pre-approved address.
+ * @param type $publicKeyAsString
+ * @return $this
+ */
+ public function setPublicKey($publicKeyAsString)
+ {
+ $this->publicKey = $publicKeyAsString;
+
+ return $this;
+ }
}
diff --git a/src/BuildOrder/RowBuilders/FixedDiscount.php b/src/BuildOrder/RowBuilders/FixedDiscount.php
index 2a476dfe..feedc504 100644
--- a/src/BuildOrder/RowBuilders/FixedDiscount.php
+++ b/src/BuildOrder/RowBuilders/FixedDiscount.php
@@ -9,195 +9,195 @@
*/
class FixedDiscount
{
- /**
- * @var string
- */
- public $discountId;
-
- /**
- * @var string
- */
- public $unit;
-
- /**
- * @var string $name
- */
- public $name;
-
- /**
- * @var string $description
- */
- public $description;
-
- /**
- * @var float $amountIncVat
- */
- public $amountIncVat;
-
- /**
- * @var float $amountExVat
- */
- public $amountExVat;
-
- /**
- * @var int $vatPercent
- */
- public $vatPercent;
-
- /**
- * @var string $temporaryReference - Option parameter.
- */
- public $temporaryReference;
-
- /**
- * Optional
- *
- * @param string $IdAsString
- *
- * @return $this
- */
- public function setDiscountId($IdAsString)
- {
- $this->discountId = $IdAsString;
-
- return $this;
- }
-
- /**
- * Optional
- *
- * @param string $unitDescriptionAsString
- *
- * @return $this
- */
- public function setUnit($unitDescriptionAsString)
- {
- $this->unit = $unitDescriptionAsString;
-
- return $this;
- }
-
- /**
- * Optional
- *
- * @param string $nameAsString
- *
- * @return $this
- */
- public function setName($nameAsString)
- {
- $this->name = $nameAsString;
-
- return $this;
- }
-
- /**
- * Optional
- *
- * @param string $descriptionAsString
- *
- * @return $this
- */
- public function setDescription($descriptionAsString)
- {
- $this->description = $descriptionAsString;
-
- return $this;
- }
-
- /**
- * Required to use at least one of the functions setAmountExVat() or setAmountIncVat(), and optionally also
- * setVatPercent().
- *
- * If only AmountIncVat is given, for Invoice and Payment plan payment methods we calculate the discount split
- * across the tax (vat) rates present in the order. The discount will be split based upon the order total for each
- * tax rate, the totals being calculated including taxes.
- *
- * This means that the discount will show up split across multiple rows on the invoice, one for each tax rate
- * present in the order.
- *
- * For Card and Direct bank payments we only subtract the appropriate amount from the request, but we still honour
- * the specified percentage, if given using two the functions below.
- *
- * Otherwise, it is required to use precisely two of the functions setAmountExVat(), setAmountIncVat() and
- * setVatPercent(). If two of these three attributes are specified, we respect the amount indicated and include the
- * discount with the specified tax rate.
- *
- * See WebServiceRowFormaterTest,
- * test_FixedDiscount_specified_using_amountIncVat_in_order_with_multiple_vat_rates() for an example.
- *
- * @param float $amountIncVatAsFloat
- *
- * @return $this
- */
- public function setAmountIncVat($amountIncVatAsFloat)
- {
- $this->amount = $amountIncVatAsFloat;
- $this->amountIncVat = $amountIncVatAsFloat;
-
- return $this;
- }
-
- /**
- * Required to use at least one of the functions setAmountExVat() or setAmountIncVat(), and optionally also
- * setVatPercent().
- *
- * If only AmountExVat is given, for Invoice and Payment plan payment methods we calculate the discount split
- * across the tax (vat) rates present in the order. The discount will be split based upon the total amount for each
- * tax rate, the totals being calculated before taxes.
- *
- * This means that the discount will show up split across multiple rows on the invoice, one for each tax rate
- * present in the order.
- *
- * For Card and Direct bank payments we only subtract the appropriate amount from the request, but we still honour
- * the specified percentage, if given using two the functions below.
- *
- * Otherwise, it is required to use precisely two of the functions setAmountExVat(), setAmountIncVat() and
- * setVatPercent(). If two of these three attributes are specified, we respect the amount indicated and include the
- * discount with the specified tax rate.
- *
- * See WebServiceRowFormaterTest, test_FixedDiscount_specified_using_amountExVat_in_order_with_multiple_vat_rates()
- * for an example.
- *
- * This action is not allowed for Checkout payment
- *
- * @param float $amountExVatAsFloat
- *
- * @return $this
- */
- public function setAmountExVat($amountExVatAsFloat)
- {
- $this->amountExVat = $amountExVatAsFloat;
-
- return $this;
- }
-
- /**
- * Optional. If vatPercent is specified along with either one of setAmountExVat() or setAmountIncVat(),
- * we respect the specified rate and amount and enter the discount using the specified tax rate.
- *
- * @param int $vatPercentAsInt
- *
- * @return $this
- */
- public function setVatPercent($vatPercentAsInt)
- {
- $this->vatPercent = $vatPercentAsInt;
-
- return $this;
- }
-
- /**
- * Optional - Can be used when creating or updating an order.
- * The returned rows will have their corresponding temporary reference as they were given in the in-data.
- * It will not be stored and will not be returned in GetOrder.
- * Checkout orders only. Will not be applicable for other order types.
- * @param $temporaryReference
- * @return $this
- */
- public function setTemporaryReference($temporaryReference)
- {
- $this->temporaryReference = $temporaryReference;
- return $this;
- }
+ /**
+ * @var string
+ */
+ public $discountId;
+
+ /**
+ * @var string
+ */
+ public $unit;
+
+ /**
+ * @var string $name
+ */
+ public $name;
+
+ /**
+ * @var string $description
+ */
+ public $description;
+
+ /**
+ * @var float $amountIncVat
+ */
+ public $amountIncVat;
+
+ /**
+ * @var float $amountExVat
+ */
+ public $amountExVat;
+
+ /**
+ * @var int $vatPercent
+ */
+ public $vatPercent;
+
+ /**
+ * @var string $temporaryReference - Option parameter.
+ */
+ public $temporaryReference;
+
+ /**
+ * Optional
+ *
+ * @param string $IdAsString
+ *
+ * @return $this
+ */
+ public function setDiscountId($IdAsString)
+ {
+ $this->discountId = $IdAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional
+ *
+ * @param string $unitDescriptionAsString
+ *
+ * @return $this
+ */
+ public function setUnit($unitDescriptionAsString)
+ {
+ $this->unit = $unitDescriptionAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional
+ *
+ * @param string $nameAsString
+ *
+ * @return $this
+ */
+ public function setName($nameAsString)
+ {
+ $this->name = $nameAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional
+ *
+ * @param string $descriptionAsString
+ *
+ * @return $this
+ */
+ public function setDescription($descriptionAsString)
+ {
+ $this->description = $descriptionAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required to use at least one of the functions setAmountExVat() or setAmountIncVat(), and optionally also
+ * setVatPercent().
+ *
+ * If only AmountIncVat is given, for Invoice and Payment plan payment methods we calculate the discount split
+ * across the tax (vat) rates present in the order. The discount will be split based upon the order total for each
+ * tax rate, the totals being calculated including taxes.
+ *
+ * This means that the discount will show up split across multiple rows on the invoice, one for each tax rate
+ * present in the order.
+ *
+ * For Card and Direct bank payments we only subtract the appropriate amount from the request, but we still honour
+ * the specified percentage, if given using two the functions below.
+ *
+ * Otherwise, it is required to use precisely two of the functions setAmountExVat(), setAmountIncVat() and
+ * setVatPercent(). If two of these three attributes are specified, we respect the amount indicated and include the
+ * discount with the specified tax rate.
+ *
+ * See WebServiceRowFormaterTest,
+ * test_FixedDiscount_specified_using_amountIncVat_in_order_with_multiple_vat_rates() for an example.
+ *
+ * @param float $amountIncVatAsFloat
+ *
+ * @return $this
+ */
+ public function setAmountIncVat($amountIncVatAsFloat)
+ {
+ $this->amount = $amountIncVatAsFloat;
+ $this->amountIncVat = $amountIncVatAsFloat;
+
+ return $this;
+ }
+
+ /**
+ * Required to use at least one of the functions setAmountExVat() or setAmountIncVat(), and optionally also
+ * setVatPercent().
+ *
+ * If only AmountExVat is given, for Invoice and Payment plan payment methods we calculate the discount split
+ * across the tax (vat) rates present in the order. The discount will be split based upon the total amount for each
+ * tax rate, the totals being calculated before taxes.
+ *
+ * This means that the discount will show up split across multiple rows on the invoice, one for each tax rate
+ * present in the order.
+ *
+ * For Card and Direct bank payments we only subtract the appropriate amount from the request, but we still honour
+ * the specified percentage, if given using two the functions below.
+ *
+ * Otherwise, it is required to use precisely two of the functions setAmountExVat(), setAmountIncVat() and
+ * setVatPercent(). If two of these three attributes are specified, we respect the amount indicated and include the
+ * discount with the specified tax rate.
+ *
+ * See WebServiceRowFormaterTest, test_FixedDiscount_specified_using_amountExVat_in_order_with_multiple_vat_rates()
+ * for an example.
+ *
+ * This action is not allowed for Checkout payment
+ *
+ * @param float $amountExVatAsFloat
+ *
+ * @return $this
+ */
+ public function setAmountExVat($amountExVatAsFloat)
+ {
+ $this->amountExVat = $amountExVatAsFloat;
+
+ return $this;
+ }
+
+ /**
+ * Optional. If vatPercent is specified along with either one of setAmountExVat() or setAmountIncVat(),
+ * we respect the specified rate and amount and enter the discount using the specified tax rate.
+ *
+ * @param int $vatPercentAsInt
+ *
+ * @return $this
+ */
+ public function setVatPercent($vatPercentAsInt)
+ {
+ $this->vatPercent = $vatPercentAsInt;
+
+ return $this;
+ }
+
+ /**
+ * Optional - Can be used when creating or updating an order.
+ * The returned rows will have their corresponding temporary reference as they were given in the in-data.
+ * It will not be stored and will not be returned in GetOrder.
+ * Checkout orders only. Will not be applicable for other order types.
+ * @param $temporaryReference
+ * @return $this
+ */
+ public function setTemporaryReference($temporaryReference)
+ {
+ $this->temporaryReference = $temporaryReference;
+ return $this;
+ }
}
diff --git a/src/BuildOrder/RowBuilders/IndividualCustomer.php b/src/BuildOrder/RowBuilders/IndividualCustomer.php
index 2f5770f9..e77dc2f7 100644
--- a/src/BuildOrder/RowBuilders/IndividualCustomer.php
+++ b/src/BuildOrder/RowBuilders/IndividualCustomer.php
@@ -8,283 +8,283 @@
*/
class IndividualCustomer
{
- /**
- * @var string $ssn
- */
- public $ssn;
-
- /**
- * @var string $initials
- */
- public $initials;
-
- /**
- * @var string $birthDate numeric string on the format yyyymmdd
- */
- public $birthDate;
-
- /**
- * @var string $email
- */
- public $email;
-
- /**
- * @var int $phonenumber
- */
- public $phonenumber;
-
- /**
- * @var string $ipAddress
- */
- public $ipAddress;
-
- /**
- * @var string $firstname
- */
- public $firstname;
-
- /**
- * @var string $lastname
- */
- public $lastname;
-
- /**
- * @var string $street
- */
- public $street;
-
- /**
- * @var int $housenumber
- */
- public $housenumber;
-
- /**
- * @var string $coAddress
- */
- public $coAddress;
-
- /**
- * @var string $zipCode
- */
- public $zipCode;
-
- /**
- * @var string $locality
- */
- public $locality;
-
- /**
- * $var string $publicKey
- */
- public $publicKey;
-
- // set in GetOrdersResponse
- public $fullName; // compounded fullName, may be set by CreateOrder for i.e. orders where identify customer via ssn
- public $streetAddress; // compounds street + housenumber,fullName, may be set by CreateOrder for i.e. orders where identify customer via ssn
-
- /**
- * Required for private customers in SE, NO, DK, FI
- *
- * @param string for SE, DK: $yyyymmddxxxx, for FI: $ddmmyyxxxx, NO: $ddmmyyxxxxx
- *
- * @return $this
- */
- public function setNationalIdNumber($nationalIdNumber)
- {
- $this->ssn = $nationalIdNumber;
-
- return $this;
- }
-
- /**
- * Required for private customers in NL
- *
- * @param string $initialsAsString
- *
- * @return $this
- */
- public function setInitials($initialsAsString)
- {
- $this->initials = $initialsAsString;
-
- return $this;
- }
-
- /**
- * Required for private customers in NL and DE
- *
- * @param string $yyyy or $yyyymmdd
- * @param string $mm
- * @param string $dd
- *
- * @return $this
- * @throws \InvalidArgumentException in case of bad birthdate string format
- */
- public function setBirthDate($yyyy, $mm = null, $dd = null)
- {
- if ($mm == null && $dd == null) { // poor man's overloading
- $yyyymmdd = $yyyy;
- if (strlen($yyyymmdd) != 8) {
- throw new \InvalidArgumentException('setBirthDate expects arguments on format $yyyy, $mm, $dd or $yyyymmdd');
- } else {
- $yyyy = substr($yyyymmdd, 0, 4);
- $mm = substr($yyyymmdd, 4, 2);
- $dd = substr($yyyymmdd, 6, 2);
- }
- }
- if ($mm < 10) {
- $mm = "0" . intval($mm);
- }
- if ($dd < 10) {
- $dd = "0" . intval($dd);
- }
-
- $this->birthDate = $yyyy . $mm . $dd;
-
- return $this;
- }
-
- /**
- * Optional but desirable
- *
- * @param string $emailAsString
- *
- * @return $this
- */
- public function setEmail($emailAsString)
- {
- $this->email = $emailAsString;
-
- return $this;
- }
-
- /**
- * Optional
- *
- * @param int $phoneNumberAsInt
- *
- * @return $this
- */
- public function setPhoneNumber($phoneNumberAsInt)
- {
- $this->phonenumber = $phoneNumberAsInt;
-
- return $this;
- }
-
- /**
- * Optional but desirable
- *
- * @param string $ipAddressAsString
- *
- * @return $this
- */
- public function setIpAddress($ipAddressAsString)
- {
- $this->ipAddress = $ipAddressAsString;
-
- return $this;
- }
-
- /**
- * Required to set firstName and lastName for private Customers in NL and DE
- *
- * @param string $firstnameAsString , or $fullNameAsString iff sole argument
- * @param string $lastnameAsString , or omitted if setting fullName
- *
- * @return $this
- */
- public function setName($firstnameAsString, $lastnameAsString = null)
- { // = null is poor man's overloading
- // only one name given, assume fullName;
- if ($lastnameAsString == null) {
- $fullNameAsString = $firstnameAsString;
- $this->name = $fullNameAsString;
- } // two names given, assume firstName and lastName
- else {
- $this->firstname = $firstnameAsString;
- $this->lastname = $lastnameAsString;
- }
-
- return $this;
- }
-
- /**
- * Required to set street and houseNumber in NL and DE
- *
- * @param string $streetAsString , or $streetAddressAsString iff sole argument
- * @param int $houseNumberAsInt , or omitted if setting streetAddress
- *
- * @return $this
- */
- public function setStreetAddress($streetAsString, $houseNumberAsInt = null)
- { // = null is poor man's overloading
- // only one name given, assume streetName;
- if ($houseNumberAsInt == null) {
- $streetAddressAsString = $streetAsString;
- $this->streetAddress = $streetAddressAsString;
- $this->street = $streetAsString; // preserve old behaviour if only street given (assume contains compounded street + housenumber)
- } else {
- $this->street = $streetAsString;
- $this->housenumber = $houseNumberAsInt;
- }
-
- return $this;
- }
-
- /**
- * Optional in NL and DE
- *
- * @param string $coAddressAsString
- *
- * @return $this
- */
- public function setCoAddress($coAddressAsString)
- {
- $this->coAddress = $coAddressAsString;
-
- return $this;
- }
-
- /**
- * Requuired in NL and DE
- *
- * @param string $zipCodeAsString
- *
- * @return $this
- */
- public function setZipCode($zipCodeAsString)
- {
- $this->zipCode = $zipCodeAsString;
-
- return $this;
- }
-
- /**
- * Required in NL and DE
- *
- * @param string $cityAsString
- *
- * @return $this
- */
- public function setLocality($cityAsString)
- {
- $this->locality = $cityAsString;
-
- return $this;
- }
-
- /**
- * Optional. Identifier for selecting a specific pre-approved address.
- *
- * @param type $publicKeyAsString
- *
- * @return $this
- */
- public function setPublicKey($publicKeyAsString)
- {
- $this->publicKey = $publicKeyAsString;
-
- return $this;
- }
+ /**
+ * @var string $ssn
+ */
+ public $ssn;
+
+ /**
+ * @var string $initials
+ */
+ public $initials;
+
+ /**
+ * @var string $birthDate numeric string on the format yyyymmdd
+ */
+ public $birthDate;
+
+ /**
+ * @var string $email
+ */
+ public $email;
+
+ /**
+ * @var int $phonenumber
+ */
+ public $phonenumber;
+
+ /**
+ * @var string $ipAddress
+ */
+ public $ipAddress;
+
+ /**
+ * @var string $firstname
+ */
+ public $firstname;
+
+ /**
+ * @var string $lastname
+ */
+ public $lastname;
+
+ /**
+ * @var string $street
+ */
+ public $street;
+
+ /**
+ * @var int $housenumber
+ */
+ public $housenumber;
+
+ /**
+ * @var string $coAddress
+ */
+ public $coAddress;
+
+ /**
+ * @var string $zipCode
+ */
+ public $zipCode;
+
+ /**
+ * @var string $locality
+ */
+ public $locality;
+
+ /**
+ * $var string $publicKey
+ */
+ public $publicKey;
+
+ // set in GetOrdersResponse
+ public $fullName; // compounded fullName, may be set by CreateOrder for i.e. orders where identify customer via ssn
+ public $streetAddress; // compounds street + housenumber,fullName, may be set by CreateOrder for i.e. orders where identify customer via ssn
+
+ /**
+ * Required for private customers in SE, NO, DK, FI
+ *
+ * @param string for SE, DK: $yyyymmddxxxx, for FI: $ddmmyyxxxx, NO: $ddmmyyxxxxx
+ *
+ * @return $this
+ */
+ public function setNationalIdNumber($nationalIdNumber)
+ {
+ $this->ssn = $nationalIdNumber;
+
+ return $this;
+ }
+
+ /**
+ * Required for private customers in NL
+ *
+ * @param string $initialsAsString
+ *
+ * @return $this
+ */
+ public function setInitials($initialsAsString)
+ {
+ $this->initials = $initialsAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required for private customers in NL and DE
+ *
+ * @param string $yyyy or $yyyymmdd
+ * @param string $mm
+ * @param string $dd
+ *
+ * @return $this
+ * @throws \InvalidArgumentException in case of bad birthdate string format
+ */
+ public function setBirthDate($yyyy, $mm = null, $dd = null)
+ {
+ if ($mm == null && $dd == null) { // poor man's overloading
+ $yyyymmdd = $yyyy;
+ if (strlen($yyyymmdd) != 8) {
+ throw new \InvalidArgumentException('setBirthDate expects arguments on format $yyyy, $mm, $dd or $yyyymmdd');
+ } else {
+ $yyyy = substr($yyyymmdd, 0, 4);
+ $mm = substr($yyyymmdd, 4, 2);
+ $dd = substr($yyyymmdd, 6, 2);
+ }
+ }
+ if ($mm < 10) {
+ $mm = "0" . intval($mm);
+ }
+ if ($dd < 10) {
+ $dd = "0" . intval($dd);
+ }
+
+ $this->birthDate = $yyyy . $mm . $dd;
+
+ return $this;
+ }
+
+ /**
+ * Optional but desirable
+ *
+ * @param string $emailAsString
+ *
+ * @return $this
+ */
+ public function setEmail($emailAsString)
+ {
+ $this->email = $emailAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional
+ *
+ * @param int $phoneNumberAsInt
+ *
+ * @return $this
+ */
+ public function setPhoneNumber($phoneNumberAsInt)
+ {
+ $this->phonenumber = $phoneNumberAsInt;
+
+ return $this;
+ }
+
+ /**
+ * Optional but desirable
+ *
+ * @param string $ipAddressAsString
+ *
+ * @return $this
+ */
+ public function setIpAddress($ipAddressAsString)
+ {
+ $this->ipAddress = $ipAddressAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required to set firstName and lastName for private Customers in NL and DE
+ *
+ * @param string $firstnameAsString , or $fullNameAsString iff sole argument
+ * @param string $lastnameAsString , or omitted if setting fullName
+ *
+ * @return $this
+ */
+ public function setName($firstnameAsString, $lastnameAsString = null)
+ { // = null is poor man's overloading
+ // only one name given, assume fullName;
+ if ($lastnameAsString == null) {
+ $fullNameAsString = $firstnameAsString;
+ $this->name = $fullNameAsString;
+ } // two names given, assume firstName and lastName
+ else {
+ $this->firstname = $firstnameAsString;
+ $this->lastname = $lastnameAsString;
+ }
+
+ return $this;
+ }
+
+ /**
+ * Required to set street and houseNumber in NL and DE
+ *
+ * @param string $streetAsString , or $streetAddressAsString iff sole argument
+ * @param int $houseNumberAsInt , or omitted if setting streetAddress
+ *
+ * @return $this
+ */
+ public function setStreetAddress($streetAsString, $houseNumberAsInt = null)
+ { // = null is poor man's overloading
+ // only one name given, assume streetName;
+ if ($houseNumberAsInt == null) {
+ $streetAddressAsString = $streetAsString;
+ $this->streetAddress = $streetAddressAsString;
+ $this->street = $streetAsString; // preserve old behaviour if only street given (assume contains compounded street + housenumber)
+ } else {
+ $this->street = $streetAsString;
+ $this->housenumber = $houseNumberAsInt;
+ }
+
+ return $this;
+ }
+
+ /**
+ * Optional in NL and DE
+ *
+ * @param string $coAddressAsString
+ *
+ * @return $this
+ */
+ public function setCoAddress($coAddressAsString)
+ {
+ $this->coAddress = $coAddressAsString;
+
+ return $this;
+ }
+
+ /**
+ * Requuired in NL and DE
+ *
+ * @param string $zipCodeAsString
+ *
+ * @return $this
+ */
+ public function setZipCode($zipCodeAsString)
+ {
+ $this->zipCode = $zipCodeAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required in NL and DE
+ *
+ * @param string $cityAsString
+ *
+ * @return $this
+ */
+ public function setLocality($cityAsString)
+ {
+ $this->locality = $cityAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional. Identifier for selecting a specific pre-approved address.
+ *
+ * @param type $publicKeyAsString
+ *
+ * @return $this
+ */
+ public function setPublicKey($publicKeyAsString)
+ {
+ $this->publicKey = $publicKeyAsString;
+
+ return $this;
+ }
}
diff --git a/src/BuildOrder/RowBuilders/InvoiceFee.php b/src/BuildOrder/RowBuilders/InvoiceFee.php
index c6959132..52d43d04 100644
--- a/src/BuildOrder/RowBuilders/InvoiceFee.php
+++ b/src/BuildOrder/RowBuilders/InvoiceFee.php
@@ -9,178 +9,178 @@
*/
class InvoiceFee
{
- /**
- * @var float $quantity quantity is always 1
- */
- public $quantity;
-
- /**
- * @var string $description
- */
- public $description;
-
- /**
- * @var float $amountExVat
- */
- public $amountExVat;
-
- /**
- * @var float $amountIncVat
- */
- public $amountIncVat;
-
- /**
- * @var int $vatPercent
- */
- public $vatPercent;
-
- /**
- * @var string $unit
- */
- public $unit;
-
- /**
- * @var int $vatDiscount -- defaults to zero (0)
- */
- public $discountPercent;
-
- /**
- * @var string $temporaryReference - Option parameter.
- */
- public $temporaryReference;
-
- /**
- * InvoiceFee constructor.
- */
- function __construct()
- {
- $this->quantity = 1; // set to 1, as this attribute is used by WebServiceRowFormatter() and all shipping rows are for one (1) unit
- }
-
- /**
- * Optional - short item name
- *
- * Note that this will be merged with the item description when the request is sent to Svea
- *
- * @param string $nameAsString
- * @return $this
- */
- public function setName($nameAsString)
- {
- $this->name = $nameAsString;
-
- return $this;
- }
-
- /**
- * Optional - long item description
- *
- * Note that this will be merged with the item name when the request is sent to Svea
- *
- * @param string $descriptionAsString
- * @return $this
- */
- public function setDescription($descriptionAsString)
- {
- $this->description = $descriptionAsString;
-
- return $this;
- }
-
- /**
- * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
- * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
- *
- * Order row item price excluding taxes, expressed as a float value.
- *
- * This action is not allowed for Checkout payment
- *
- * @param float $amountAsFloat
- * @return $this
- */
- public function setAmountExVat($amountAsFloat)
- {
- $this->amountExVat = $amountAsFloat;
-
- return $this;
- }
-
- /**
- * Optional - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
- * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
- *
- * Order row item price including tax, expressed as a float value.
- *
- * If you specify AmountIncVat, note that this may introduce a cumulative rounding error when ordering large
- * quantities of an item, as the package bases the total order sum on a calculated price ex. vat.
- *
- * Also, Svea uses bankers rounding (half-to-even) when calculating the order total, so at times a rounding error of at most
- * one cent/öre may show up if the implementation/shop does not use the same rounding method.
- *
- * See HostedPaymentTest for examples, including sums and calculations.
- *
- * @param float $amountAsFloat
- * @return $this
- */
- public function setAmountIncVat($amountAsFloat)
- {
- $this->amountIncVat = $amountAsFloat;
-
- return $this;
- }
-
- /**
- * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
- * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
- *
- * Order row item price vat rate in percent, expressed as an integer.
- *
- * @param int $vatPercentAsInt
- * @return $this
- */
- public function setVatPercent($vatPercentAsInt)
- {
- $this->vatPercent = $vatPercentAsInt;
-
- return $this;
- }
-
- /**
- * Optional - the name of the unit used for the shipping fee.
- * @param string $unitDescriptionAsString
- * @return $this
- */
- public function setUnit($unitDescriptionAsString)
- {
- $this->unit = $unitDescriptionAsString;
-
- return $this;
- }
-
- /**
- * Optional - discount in percent, applies to this order row only
- *
- * @param int $discountPercentAsInt
- * @return $this
- */
- public function setDiscountPercent($discountPercentAsInt)
- {
- $this->discountPercent = $discountPercentAsInt;
-
- return $this;
- }
-
- /**
- * Optional - Can be used when creating or updating an order.
- * The returned rows will have their corresponding temporary reference as they were given in the in-data.
- * It will not be stored and will not be returned in GetOrder.
- * Checkout orders only. Will not be applicable for other order types.
- * @param $temporaryReference
- * @return $this
- */
- public function setTemporaryReference($temporaryReference)
- {
- $this->temporaryReference = $temporaryReference;
- return $this;
- }
+ /**
+ * @var float $quantity quantity is always 1
+ */
+ public $quantity;
+
+ /**
+ * @var string $description
+ */
+ public $description;
+
+ /**
+ * @var float $amountExVat
+ */
+ public $amountExVat;
+
+ /**
+ * @var float $amountIncVat
+ */
+ public $amountIncVat;
+
+ /**
+ * @var int $vatPercent
+ */
+ public $vatPercent;
+
+ /**
+ * @var string $unit
+ */
+ public $unit;
+
+ /**
+ * @var int $vatDiscount -- defaults to zero (0)
+ */
+ public $discountPercent;
+
+ /**
+ * @var string $temporaryReference - Option parameter.
+ */
+ public $temporaryReference;
+
+ /**
+ * InvoiceFee constructor.
+ */
+ function __construct()
+ {
+ $this->quantity = 1; // set to 1, as this attribute is used by WebServiceRowFormatter() and all shipping rows are for one (1) unit
+ }
+
+ /**
+ * Optional - short item name
+ *
+ * Note that this will be merged with the item description when the request is sent to Svea
+ *
+ * @param string $nameAsString
+ * @return $this
+ */
+ public function setName($nameAsString)
+ {
+ $this->name = $nameAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional - long item description
+ *
+ * Note that this will be merged with the item name when the request is sent to Svea
+ *
+ * @param string $descriptionAsString
+ * @return $this
+ */
+ public function setDescription($descriptionAsString)
+ {
+ $this->description = $descriptionAsString;
+
+ return $this;
+ }
+
+ /**
+ * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
+ * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
+ *
+ * Order row item price excluding taxes, expressed as a float value.
+ *
+ * This action is not allowed for Checkout payment
+ *
+ * @param float $amountAsFloat
+ * @return $this
+ */
+ public function setAmountExVat($amountAsFloat)
+ {
+ $this->amountExVat = $amountAsFloat;
+
+ return $this;
+ }
+
+ /**
+ * Optional - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
+ * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
+ *
+ * Order row item price including tax, expressed as a float value.
+ *
+ * If you specify AmountIncVat, note that this may introduce a cumulative rounding error when ordering large
+ * quantities of an item, as the package bases the total order sum on a calculated price ex. vat.
+ *
+ * Also, Svea uses bankers rounding (half-to-even) when calculating the order total, so at times a rounding error of at most
+ * one cent/öre may show up if the implementation/shop does not use the same rounding method.
+ *
+ * See HostedPaymentTest for examples, including sums and calculations.
+ *
+ * @param float $amountAsFloat
+ * @return $this
+ */
+ public function setAmountIncVat($amountAsFloat)
+ {
+ $this->amountIncVat = $amountAsFloat;
+
+ return $this;
+ }
+
+ /**
+ * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
+ * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
+ *
+ * Order row item price vat rate in percent, expressed as an integer.
+ *
+ * @param int $vatPercentAsInt
+ * @return $this
+ */
+ public function setVatPercent($vatPercentAsInt)
+ {
+ $this->vatPercent = $vatPercentAsInt;
+
+ return $this;
+ }
+
+ /**
+ * Optional - the name of the unit used for the shipping fee.
+ * @param string $unitDescriptionAsString
+ * @return $this
+ */
+ public function setUnit($unitDescriptionAsString)
+ {
+ $this->unit = $unitDescriptionAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional - discount in percent, applies to this order row only
+ *
+ * @param int $discountPercentAsInt
+ * @return $this
+ */
+ public function setDiscountPercent($discountPercentAsInt)
+ {
+ $this->discountPercent = $discountPercentAsInt;
+
+ return $this;
+ }
+
+ /**
+ * Optional - Can be used when creating or updating an order.
+ * The returned rows will have their corresponding temporary reference as they were given in the in-data.
+ * It will not be stored and will not be returned in GetOrder.
+ * Checkout orders only. Will not be applicable for other order types.
+ * @param $temporaryReference
+ * @return $this
+ */
+ public function setTemporaryReference($temporaryReference)
+ {
+ $this->temporaryReference = $temporaryReference;
+ return $this;
+ }
}
diff --git a/src/BuildOrder/RowBuilders/Item.php b/src/BuildOrder/RowBuilders/Item.php
index 6371792a..6d9584b2 100644
--- a/src/BuildOrder/RowBuilders/Item.php
+++ b/src/BuildOrder/RowBuilders/Item.php
@@ -13,38 +13,38 @@
*/
class Item
{
- public static function orderRow()
- {
- return WebPayItem::orderRow();
- }
-
- public static function shippingFee()
- {
- return WebPayItem::shippingFee();
- }
-
- public static function invoiceFee()
- {
- return WebPayItem::invoiceFee();
- }
-
- public static function fixedDiscount()
- {
- return WebPayItem::fixedDiscount();
- }
-
- public static function relativeDiscount()
- {
- return WebPayItem::relativeDiscount();
- }
-
- public static function individualCustomer()
- {
- return WebPayItem::individualCustomer();
- }
-
- public static function companyCustomer()
- {
- return WebPayItem::companyCustomer();
- }
+ public static function orderRow()
+ {
+ return WebPayItem::orderRow();
+ }
+
+ public static function shippingFee()
+ {
+ return WebPayItem::shippingFee();
+ }
+
+ public static function invoiceFee()
+ {
+ return WebPayItem::invoiceFee();
+ }
+
+ public static function fixedDiscount()
+ {
+ return WebPayItem::fixedDiscount();
+ }
+
+ public static function relativeDiscount()
+ {
+ return WebPayItem::relativeDiscount();
+ }
+
+ public static function individualCustomer()
+ {
+ return WebPayItem::individualCustomer();
+ }
+
+ public static function companyCustomer()
+ {
+ return WebPayItem::companyCustomer();
+ }
}
diff --git a/src/BuildOrder/RowBuilders/NumberedOrderRow.php b/src/BuildOrder/RowBuilders/NumberedOrderRow.php
index 28f7f4d0..a03024d1 100644
--- a/src/BuildOrder/RowBuilders/NumberedOrderRow.php
+++ b/src/BuildOrder/RowBuilders/NumberedOrderRow.php
@@ -9,105 +9,105 @@
* directly via the service requests GetOrders, or QueryTransaction, responses.
*
* $myNumberedOrderRow =
- * Svea\WebPay\WebPayItem::numberedOrderRow()
+ * Svea\WebPay\WebPayItem::numberedOrderRow()
*
- * //inherited from OrderRow
- * ->setAmountExVat(100.00) // recommended to specify price using AmountExVat & VatPercent
- * ->setVatPercent(25) // recommended to specify price using AmountExVat & VatPercent
- * ->setAmountIncVat(125.00) // optional, need to use two out of three of the price specification methods
- * ->setQuantity(2) // required
- * ->setUnit("st") // optional
- * ->setName('Prod') // optional
- * ->setDescription("Specification") // optional
- * ->setArticleNumber("1") // optional
- * ->setDiscountPercent(0) // optional
+ * //inherited from OrderRow
+ * ->setAmountExVat(100.00) // recommended to specify price using AmountExVat & VatPercent
+ * ->setVatPercent(25) // recommended to specify price using AmountExVat & VatPercent
+ * ->setAmountIncVat(125.00) // optional, need to use two out of three of the price specification methods
+ * ->setQuantity(2) // required
+ * ->setUnit("st") // optional
+ * ->setName('Prod') // optional
+ * ->setDescription("Specification") // optional
+ * ->setArticleNumber("1") // optional
+ * ->setDiscountPercent(0) // optional
*
- * //numberedOrderRow
- * ->setCreditInvoiceId($creditInvoiceIdAsNumeric) //optional
- * ->setInvoiceId($invoiceIdAsNumeric) //optional
- * ->setRowNumber($rowNumberAsNumeric) //optional
- * ->setStatus(NumberedOrderRow::ORDERROWSTATUS_DELIVERED) //optional, one of _DELIVERED, _NOTDELIVERED, _CANCELLED
+ * //numberedOrderRow
+ * ->setCreditInvoiceId($creditInvoiceIdAsNumeric) //optional
+ * ->setInvoiceId($invoiceIdAsNumeric) //optional
+ * ->setRowNumber($rowNumberAsNumeric) //optional
+ * ->setStatus(NumberedOrderRow::ORDERROWSTATUS_DELIVERED) //optional, one of _DELIVERED, _NOTDELIVERED, _CANCELLED
*
*/
class NumberedOrderRow extends OrderRow
{
- const ORDERROWSTATUS_NOTDELIVERED = 'NotDelivered';
- const ORDERROWSTATUS_DELIVERED = 'Delivered';
- const ORDERROWSTATUS_CANCELLED = 'Cancelled';
+ const ORDERROWSTATUS_NOTDELIVERED = 'NotDelivered';
+ const ORDERROWSTATUS_DELIVERED = 'Delivered';
+ const ORDERROWSTATUS_CANCELLED = 'Cancelled';
- /**
- * @var string $creditInvoiceId reference to invoice to credit
- */
- public $creditInvoiceId;
+ /**
+ * @var string $creditInvoiceId reference to invoice to credit
+ */
+ public $creditInvoiceId;
- /**
- * @var string $invoiceId if order has been delivered, reference to resulting invoice
- */
- public $invoiceId;
+ /**
+ * @var string $invoiceId if order has been delivered, reference to resulting invoice
+ */
+ public $invoiceId;
- /**
- * @var integer $rowNumber the order row number, starting with 1 for the first order row
- */
- public $rowNumber;
+ /**
+ * @var integer $rowNumber the order row number, starting with 1 for the first order row
+ */
+ public $rowNumber;
- /**
- * @var string $status one of: NotDelivered | Delivered | Cancelled
- */
- public $status;
+ /**
+ * @var string $status one of: NotDelivered | Delivered | Cancelled
+ */
+ public $status;
- /**
- * Optional.
- * @param string $creditInvoiceIdAsNumeric
- * @return $this
- */
- public function setCreditInvoiceId($creditInvoiceIdAsNumeric)
- {
- $this->creditInvoiceId = $creditInvoiceIdAsNumeric;
- return $this;
- }
+ /**
+ * Optional.
+ * @param string $creditInvoiceIdAsNumeric
+ * @return $this
+ */
+ public function setCreditInvoiceId($creditInvoiceIdAsNumeric)
+ {
+ $this->creditInvoiceId = $creditInvoiceIdAsNumeric;
+ return $this;
+ }
- /**
- * Optional.
- * @param string $invoiceIdAsNumeric
- * @return $this
- */
- public function setInvoiceId($invoiceIdAsNumeric)
- {
- $this->invoiceId = $invoiceIdAsNumeric;
- return $this;
- }
+ /**
+ * Optional.
+ * @param string $invoiceIdAsNumeric
+ * @return $this
+ */
+ public function setInvoiceId($invoiceIdAsNumeric)
+ {
+ $this->invoiceId = $invoiceIdAsNumeric;
+ return $this;
+ }
- /**
- * Optional.
- * @param string $rowNumberAsNumeric
- * @return $this
- */
- public function setRowNumber($rowNumberAsNumeric)
- {
- $this->rowNumber = $rowNumberAsNumeric;
- return $this;
- }
+ /**
+ * Optional.
+ * @param string $rowNumberAsNumeric
+ * @return $this
+ */
+ public function setRowNumber($rowNumberAsNumeric)
+ {
+ $this->rowNumber = $rowNumberAsNumeric;
+ return $this;
+ }
- /**
- * Deprecated. Status is returned by Svea sytem and should not be populated in UpdateOrderRowsRequest
- * @param string $status
- * @return $this
- */
- public function setStatus($status)
- {
- $this->status = $status;
- return $this;
- }
+ /**
+ * Deprecated. Status is returned by Svea sytem and should not be populated in UpdateOrderRowsRequest
+ * @param string $status
+ * @return $this
+ */
+ public function setStatus($status)
+ {
+ $this->status = $status;
+ return $this;
+ }
- /**
- * This is alias for setRowNUmber
- * Optional.
- * @param int $rowId
- * @return $this
- */
- public function setRowId($rowId)
- {
- $this->rowNumber = $rowId;
- return $this;
- }
+ /**
+ * This is alias for setRowNUmber
+ * Optional.
+ * @param int $rowId
+ * @return $this
+ */
+ public function setRowId($rowId)
+ {
+ $this->rowNumber = $rowId;
+ return $this;
+ }
}
diff --git a/src/BuildOrder/RowBuilders/OrderDeliveryAddress.php b/src/BuildOrder/RowBuilders/OrderDeliveryAddress.php
index 9c701c18..07df1dcc 100644
--- a/src/BuildOrder/RowBuilders/OrderDeliveryAddress.php
+++ b/src/BuildOrder/RowBuilders/OrderDeliveryAddress.php
@@ -13,114 +13,114 @@
class OrderDeliveryAddress
{
- public $fullName;
- public $firstName;
- public $lastName;
- public $streetAddress;
- public $coAddress;
- public $zipCode;
- public $houseNumber;
- public $locality;
- public $countryCode;
- /**
- * @return mixed
- */
- /**
- * @param mixed $fullName
- * @return $this
- */
- public function setFullName($fullName)
- {
- $this->fullName = $fullName;
-
- return $this;
- }
-
- /**
- * @param mixed $firstName
- * @return $this
- */
- public function setFirstName($firstName)
- {
- $this->firstName = $firstName;
-
- return $this;
- }
-
- /**
- * @param mixed $lastName
- * @return $this
- */
- public function setLastName($lastName)
- {
- $this->lastName = $lastName;
-
- return $this;
- }
-
- /**
- * @param mixed $streetAddress
- * @return $this
- */
- public function setStreetAddress($streetAddress)
- {
- $this->streetAddress = $streetAddress;
-
- return $this;
- }
-
- /**
- * @param mixed $coAddress
- * @return $this
- */
- public function setCoAddress($coAddress)
- {
- $this->coAddress = $coAddress;
-
- return $this;
- }
-
- /**
- * @param mixed $zipCode
- * @return mixed
- */
- public function setZipCode($zipCode)
- {
- $this->zipCode = $zipCode;
-
- return $this;
- }
-
- /**
- * @param mixed $houseNumber
- * @return $this
- */
- public function setHouseNumber($houseNumber)
- {
- $this->houseNumber = $houseNumber;
-
- return $this;
- }
-
- /**
- * @param mixed $locality
- * @return $this
- */
- public function setLocality($locality)
- {
- $this->locality = $locality;
-
- return $this;
- }
-
- /**
- * @param mixed $countryCode
- * @return $this
- */
- public function setCountryCode($countryCode)
- {
- $this->countryCode = $countryCode;
-
- return $this;
- }
+ public $fullName;
+ public $firstName;
+ public $lastName;
+ public $streetAddress;
+ public $coAddress;
+ public $zipCode;
+ public $houseNumber;
+ public $locality;
+ public $countryCode;
+ /**
+ * @return mixed
+ */
+ /**
+ * @param mixed $fullName
+ * @return $this
+ */
+ public function setFullName($fullName)
+ {
+ $this->fullName = $fullName;
+
+ return $this;
+ }
+
+ /**
+ * @param mixed $firstName
+ * @return $this
+ */
+ public function setFirstName($firstName)
+ {
+ $this->firstName = $firstName;
+
+ return $this;
+ }
+
+ /**
+ * @param mixed $lastName
+ * @return $this
+ */
+ public function setLastName($lastName)
+ {
+ $this->lastName = $lastName;
+
+ return $this;
+ }
+
+ /**
+ * @param mixed $streetAddress
+ * @return $this
+ */
+ public function setStreetAddress($streetAddress)
+ {
+ $this->streetAddress = $streetAddress;
+
+ return $this;
+ }
+
+ /**
+ * @param mixed $coAddress
+ * @return $this
+ */
+ public function setCoAddress($coAddress)
+ {
+ $this->coAddress = $coAddress;
+
+ return $this;
+ }
+
+ /**
+ * @param mixed $zipCode
+ * @return mixed
+ */
+ public function setZipCode($zipCode)
+ {
+ $this->zipCode = $zipCode;
+
+ return $this;
+ }
+
+ /**
+ * @param mixed $houseNumber
+ * @return $this
+ */
+ public function setHouseNumber($houseNumber)
+ {
+ $this->houseNumber = $houseNumber;
+
+ return $this;
+ }
+
+ /**
+ * @param mixed $locality
+ * @return $this
+ */
+ public function setLocality($locality)
+ {
+ $this->locality = $locality;
+
+ return $this;
+ }
+
+ /**
+ * @param mixed $countryCode
+ * @return $this
+ */
+ public function setCountryCode($countryCode)
+ {
+ $this->countryCode = $countryCode;
+
+ return $this;
+ }
}
\ No newline at end of file
diff --git a/src/BuildOrder/RowBuilders/OrderRow.php b/src/BuildOrder/RowBuilders/OrderRow.php
index 165d174c..e94724e4 100644
--- a/src/BuildOrder/RowBuilders/OrderRow.php
+++ b/src/BuildOrder/RowBuilders/OrderRow.php
@@ -9,229 +9,229 @@
*/
class OrderRow
{
- /**
- * @var string $articlenumber Optional.
- */
- public $articleNumber;
-
- /**
- * @var float $quantity
- */
- public $quantity;
-
- /**
- * @var string $unit
- */
- public $unit;
-
- /**
- * @var string $temporaryReference - Option parameter.
- */
- public $temporaryReference;
-
- /**
- * @var float $amountExVat
- */
- public $amountExVat;
-
- /**
- * @var int $vatPercent
- */
- public $vatPercent;
-
- /**
- * @var float $amountIncVat
- */
- public $amountIncVat;
-
- /**
- * @var string $name
- */
- public $name;
-
- /**
- * @var string $description
- */
- public $description;
-
- /**
- * @var int $discountPercent
- */
- public $discountPercent;
-
- /**
- * @var int $vatDiscount -- defaults to zero (0)
- */
- public $vatDiscount = 0;
-
- /**
- * @var string $merchantData
- */
- public $merchantData;
-
- /**
- * Optional
- * @param string $articleNumberAsString
- * @return $this
- */
- public function setArticleNumber($articleNumberAsString)
- {
- $this->articleNumber = $articleNumberAsString;
- return $this;
- }
-
- /**
- * Required -- item quantity, i.e. how many were ordered of this item
- *
- * The integration package supports fractions input at any precision, but
- * when sending the request to Svea numbers are rounded to two decimal places.
- *
- * @param $quantityAsNumeric
- * @return $this
- */
- public function setQuantity($quantityAsNumeric)
- {
- $this->quantity = $quantityAsNumeric;
- return $this;
- }
-
- /**
- * Optional - the name of the unit used for the order quantity, i.e. "pieces", "pcs.", "st.", "mb" et al.
- *
- * @param string $unitAsString
- * @return $this
- */
- public function setUnit($unitAsString)
- {
- $this->unit = $unitAsString;
- return $this;
- }
-
- /**
- * Optional - Can be used when creating or updating an order.
- * The returned rows will have their corresponding temporary reference as they were given in the in-data.
- * It will not be stored and will not be returned in GetOrder.
- * Checkout orders only. Will not be applicable for other order types.
- * @param $temporaryReference
- * @return $this
- */
- public function setTemporaryReference($temporaryReference)
- {
- $this->temporaryReference = $temporaryReference;
- return $this;
- }
-
- /**
- * Optional - Can be used when creating or updating an order.
- * The returned rows will have their corresponding merchant data as they were given in the in-data.
- * It will be stored by Svea and will be returned in GetOrder.
- * Checkout orders only. Will not be applicable for other order types.
- * @param $merchantData
- * @return $this
- */
- public function setMerchantData($merchantData)
- {
- $this->merchantData = $merchantData;
- return $this;
- }
-
- /**
- * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
- * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
- *
- * Order row item price excluding taxes, expressed as a float value.
- *
- * This action is not allowed for Checkout payment
- *
- * @param float $amountAsFloat
- * @return $this
- */
- public function setAmountExVat($amountAsFloat)
- {
- $this->amountExVat = $amountAsFloat;
- return $this;
- }
-
- /**
- * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
- * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
- *
- * Order row item price vat rate in percent, expressed as an integer.
- *
- * @param int $vatPercentAsInt
- * @return $this
- */
- public function setVatPercent($vatPercentAsInt)
- {
- $this->vatPercent = $vatPercentAsInt;
- return $this;
- }
-
- /**
- * Optional - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
- * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
- *
- * Order row item price including tax, expressed as a float value.
- *
- * We recommend specifying AmountExVat and VatPercentage. If not, make sure not retain as much precision as possible, i.e. use no
- * premature rounding (87.4875 is a "better" PriceIncVat than 87.49) as the package processes the price before sending the request to Svea.
- *
- * If you specify AmountIncVat, note that this may introduce a cumulative rounding error when ordering large
- * quantities of an item, as the package bases the total order sum on a calculated price ex. vat.
- *
- * Also, Svea uses bankers rounding (half-to-even) when calculating the order total, so at times a rounding error of at most
- * one cent/öre may show up if the implementation/shop does not use the same rounding method.
- *
- * See HostedPaymentTest for examples, including sums and calculations.
- *
- * @param float $amountAsFloat
- * @return $this
- */
- public function setAmountIncVat($amountAsFloat)
- {
- $this->amountIncVat = $amountAsFloat;
- return $this;
- }
-
- /**
- * Optional - short item name
- *
- * Note that this will be merged with the item description when the request is sent to Svea
- *
- * @param string $nameAsString
- * @return $this
- */
- public function setName($nameAsString)
- {
- $this->name = $nameAsString;
- return $this;
- }
-
- /**
- * Optional - long item description
- *
- * Note that this will be merged with the item name when the request is sent to Svea
- *
- * Note: this is not used for Checkout order
- *
- * @param string $descriptionAsString
- * @return $this
- */
- public function setDescription($descriptionAsString)
- {
- $this->description = $descriptionAsString;
- return $this;
- }
-
- /**
- * Optional - discount in percent, applies to this order row only
- *
- * @param int $discountPercentAsInteger
- * @return $this
- */
- public function setDiscountPercent($discountPercentAsInteger)
- {
- $this->discountPercent = $discountPercentAsInteger;
- return $this;
- }
+ /**
+ * @var string $articlenumber Optional.
+ */
+ public $articleNumber;
+
+ /**
+ * @var float $quantity
+ */
+ public $quantity;
+
+ /**
+ * @var string $unit
+ */
+ public $unit;
+
+ /**
+ * @var string $temporaryReference - Option parameter.
+ */
+ public $temporaryReference;
+
+ /**
+ * @var float $amountExVat
+ */
+ public $amountExVat;
+
+ /**
+ * @var int $vatPercent
+ */
+ public $vatPercent;
+
+ /**
+ * @var float $amountIncVat
+ */
+ public $amountIncVat;
+
+ /**
+ * @var string $name
+ */
+ public $name;
+
+ /**
+ * @var string $description
+ */
+ public $description;
+
+ /**
+ * @var int $discountPercent
+ */
+ public $discountPercent;
+
+ /**
+ * @var int $vatDiscount -- defaults to zero (0)
+ */
+ public $vatDiscount = 0;
+
+ /**
+ * @var string $merchantData
+ */
+ public $merchantData;
+
+ /**
+ * Optional
+ * @param string $articleNumberAsString
+ * @return $this
+ */
+ public function setArticleNumber($articleNumberAsString)
+ {
+ $this->articleNumber = $articleNumberAsString;
+ return $this;
+ }
+
+ /**
+ * Required -- item quantity, i.e. how many were ordered of this item
+ *
+ * The integration package supports fractions input at any precision, but
+ * when sending the request to Svea numbers are rounded to two decimal places.
+ *
+ * @param $quantityAsNumeric
+ * @return $this
+ */
+ public function setQuantity($quantityAsNumeric)
+ {
+ $this->quantity = $quantityAsNumeric;
+ return $this;
+ }
+
+ /**
+ * Optional - the name of the unit used for the order quantity, i.e. "pieces", "pcs.", "st.", "mb" et al.
+ *
+ * @param string $unitAsString
+ * @return $this
+ */
+ public function setUnit($unitAsString)
+ {
+ $this->unit = $unitAsString;
+ return $this;
+ }
+
+ /**
+ * Optional - Can be used when creating or updating an order.
+ * The returned rows will have their corresponding temporary reference as they were given in the in-data.
+ * It will not be stored and will not be returned in GetOrder.
+ * Checkout orders only. Will not be applicable for other order types.
+ * @param $temporaryReference
+ * @return $this
+ */
+ public function setTemporaryReference($temporaryReference)
+ {
+ $this->temporaryReference = $temporaryReference;
+ return $this;
+ }
+
+ /**
+ * Optional - Can be used when creating or updating an order.
+ * The returned rows will have their corresponding merchant data as they were given in the in-data.
+ * It will be stored by Svea and will be returned in GetOrder.
+ * Checkout orders only. Will not be applicable for other order types.
+ * @param $merchantData
+ * @return $this
+ */
+ public function setMerchantData($merchantData)
+ {
+ $this->merchantData = $merchantData;
+ return $this;
+ }
+
+ /**
+ * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
+ * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
+ *
+ * Order row item price excluding taxes, expressed as a float value.
+ *
+ * This action is not allowed for Checkout payment
+ *
+ * @param float $amountAsFloat
+ * @return $this
+ */
+ public function setAmountExVat($amountAsFloat)
+ {
+ $this->amountExVat = $amountAsFloat;
+ return $this;
+ }
+
+ /**
+ * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
+ * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
+ *
+ * Order row item price vat rate in percent, expressed as an integer.
+ *
+ * @param int $vatPercentAsInt
+ * @return $this
+ */
+ public function setVatPercent($vatPercentAsInt)
+ {
+ $this->vatPercent = $vatPercentAsInt;
+ return $this;
+ }
+
+ /**
+ * Optional - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
+ * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
+ *
+ * Order row item price including tax, expressed as a float value.
+ *
+ * We recommend specifying AmountExVat and VatPercentage. If not, make sure not retain as much precision as possible, i.e. use no
+ * premature rounding (87.4875 is a "better" PriceIncVat than 87.49) as the package processes the price before sending the request to Svea.
+ *
+ * If you specify AmountIncVat, note that this may introduce a cumulative rounding error when ordering large
+ * quantities of an item, as the package bases the total order sum on a calculated price ex. vat.
+ *
+ * Also, Svea uses bankers rounding (half-to-even) when calculating the order total, so at times a rounding error of at most
+ * one cent/öre may show up if the implementation/shop does not use the same rounding method.
+ *
+ * See HostedPaymentTest for examples, including sums and calculations.
+ *
+ * @param float $amountAsFloat
+ * @return $this
+ */
+ public function setAmountIncVat($amountAsFloat)
+ {
+ $this->amountIncVat = $amountAsFloat;
+ return $this;
+ }
+
+ /**
+ * Optional - short item name
+ *
+ * Note that this will be merged with the item description when the request is sent to Svea
+ *
+ * @param string $nameAsString
+ * @return $this
+ */
+ public function setName($nameAsString)
+ {
+ $this->name = $nameAsString;
+ return $this;
+ }
+
+ /**
+ * Optional - long item description
+ *
+ * Note that this will be merged with the item name when the request is sent to Svea
+ *
+ * Note: this is not used for Checkout order
+ *
+ * @param string $descriptionAsString
+ * @return $this
+ */
+ public function setDescription($descriptionAsString)
+ {
+ $this->description = $descriptionAsString;
+ return $this;
+ }
+
+ /**
+ * Optional - discount in percent, applies to this order row only
+ *
+ * @param int $discountPercentAsInteger
+ * @return $this
+ */
+ public function setDiscountPercent($discountPercentAsInteger)
+ {
+ $this->discountPercent = $discountPercentAsInteger;
+ return $this;
+ }
}
diff --git a/src/BuildOrder/RowBuilders/RelativeDiscount.php b/src/BuildOrder/RowBuilders/RelativeDiscount.php
index 9551a5bd..a1ba3a65 100644
--- a/src/BuildOrder/RowBuilders/RelativeDiscount.php
+++ b/src/BuildOrder/RowBuilders/RelativeDiscount.php
@@ -7,86 +7,86 @@
*/
class RelativeDiscount
{
- /**
- * @var string
- */
- public $discountId;
+ /**
+ * @var string
+ */
+ public $discountId;
- /**
- * @var float
- */
- public $discountPercent;
+ /**
+ * @var float
+ */
+ public $discountPercent;
- /**
- * @var string
- */
- public $unit;
+ /**
+ * @var string
+ */
+ public $unit;
- /**
- * @var string $name
- */
- public $name;
+ /**
+ * @var string $name
+ */
+ public $name;
- /**
- * @var string $description
- */
- public $description;
+ /**
+ * @var string $description
+ */
+ public $description;
- /**
- * Optional
- * @param string $idAsString
- * @return $this
- */
- public function setDiscountId($idAsString)
- {
- $this->discountId = $idAsString;
- return $this;
- }
+ /**
+ * Optional
+ * @param string $idAsString
+ * @return $this
+ */
+ public function setDiscountId($idAsString)
+ {
+ $this->discountId = $idAsString;
+ return $this;
+ }
- /**
- * Required
- * The percentage of the discount, either a float or a real number
- *
- * @param number $discountPercentOnTotalAmountAsNumber
- * @return $this
- */
- public function setDiscountPercent($discountPercentOnTotalAmountAsNumber)
- {
- $this->discountPercent = $discountPercentOnTotalAmountAsNumber;
- return $this;
- }
+ /**
+ * Required
+ * The percentage of the discount, either a float or a real number
+ *
+ * @param number $discountPercentOnTotalAmountAsNumber
+ * @return $this
+ */
+ public function setDiscountPercent($discountPercentOnTotalAmountAsNumber)
+ {
+ $this->discountPercent = $discountPercentOnTotalAmountAsNumber;
+ return $this;
+ }
- /**
- * Optional
- * @param string $unitDescriptionAsString
- * @return $this
- */
- public function setUnit($unitDescriptionAsString)
- {
- $this->unit = $unitDescriptionAsString;
- return $this;
- }
+ /**
+ * Optional
+ * @param string $unitDescriptionAsString
+ * @return $this
+ */
+ public function setUnit($unitDescriptionAsString)
+ {
+ $this->unit = $unitDescriptionAsString;
+ return $this;
+ }
- /**
- * Optional
- * @param string $nameAsString
- * @return $this
- */
- public function setName($nameAsString)
- {
- $this->name = $nameAsString;
- return $this;
- }
+ /**
+ * Optional
+ * @param string $nameAsString
+ * @return $this
+ */
+ public function setName($nameAsString)
+ {
+ $this->name = $nameAsString;
+ return $this;
+ }
- /**
- * Optional
- * @param string $descriptionAsString
- * @return $this
- */
- public function setDescription($descriptionAsString)
- {
- $this->description = $descriptionAsString;
- return $this;
- }
+ /**
+ * Optional
+ * @param string $descriptionAsString
+ * @return $this
+ */
+ public function setDescription($descriptionAsString)
+ {
+ $this->description = $descriptionAsString;
+ return $this;
+ }
}
diff --git a/src/BuildOrder/RowBuilders/ShippingFee.php b/src/BuildOrder/RowBuilders/ShippingFee.php
index ff427907..70e4efeb 100644
--- a/src/BuildOrder/RowBuilders/ShippingFee.php
+++ b/src/BuildOrder/RowBuilders/ShippingFee.php
@@ -9,195 +9,195 @@
*/
class ShippingFee
{
- /**
- * @var float $quantity quantity is always 1
- */
- public $quantity;
-
- /**
- * @var string $shippingId
- */
- public $shippingId;
-
- /**
- * @var string $name
- */
- public $name;
-
- /**
- * @var string $description
- */
- public $description;
-
-
- /**
- * @var float $amountExVat
- */
- public $amountExVat;
-
-
- /**
- * @var float $amountIncVat
- */
- public $amountIncVat;
-
- /**
- * @var int $vatPercent
- */
- public $vatPercent;
-
- /**
- * @var string $unit
- */
- public $unit;
-
- /**
- * @var int $vatDiscount -- defaults to zero (0)
- */
- public $discountPercent;
-
- /**
- * @var string $temporaryReference - Option parameter.
- */
- public $temporaryReference;
-
- /**
- * ShippingFee constructor.
- */
- function __construct()
- {
- // set to 1, as this attribute is used by WebServiceRowFormatter() and all shipping rows are for one (1) unit
- $this->quantity = 1;
- }
-
- /**
- * Optional
- * @param string $idAsString
- * @return $this
- */
- public function setShippingId($idAsString)
- {
- $this->shippingId = $idAsString;
- return $this;
- }
-
- /**
- * Optional - short item name
- *
- * Note that this will be merged with the item description when the request is sent to Svea
- *
- * @param string $nameAsString
- * @return $this
- */
- public function setName($nameAsString)
- {
- $this->name = $nameAsString;
- return $this;
- }
-
- /**
- * Optional - long item description
- *
- * Note that this will be merged with the item name when the request is sent to Svea
- *
- * @param string $descriptionAsString
- * @return $this
- */
- public function setDescription($descriptionAsString)
- {
- $this->description = $descriptionAsString;
- return $this;
- }
-
- /**
- * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
- * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
- *
- * Order row item price excluding taxes, expressed as a float value.
- *
- * This action is not allowed for Checkout payment
- *
- * @param float $amountAsFloat
- * @return $this
- */
- public function setAmountExVat($amountAsFloat)
- {
- $this->amountExVat = $amountAsFloat;
- return $this;
- }
-
- /**
- * Optional - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
- * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
- *
- * Order row item price including tax, expressed as a float value.
- *
- * If you specify AmountIncVat, note that this may introduce a cumulative rounding error when ordering large
- * quantities of an item, as the package bases the total order sum on a calculated price ex. vat.
- *
- * Also, Svea uses bankers rounding (half-to-even) when calculating the order total, so at times a rounding error of at most
- * one cent/öre may show up if the implementation/shop does not use the same rounding method.
- *
- * See HostedPaymentTest for examples, including sums and calculations.
- *
- * @param float $amountAsFloat
- * @return $this
- */
- public function setAmountIncVat($amountAsFloat)
- {
- $this->amountIncVat = $amountAsFloat;
- return $this;
- }
-
- /**
- * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
- * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
- *
- * Order row item price vat rate in percent, expressed as an integer.
- *
- * @param int $vatPercentAsInt
- * @return $this
- */
- public function setVatPercent($vatPercentAsInt)
- {
- $this->vatPercent = $vatPercentAsInt;
- return $this;
- }
-
- /**
- * Optional - the name of the unit used for the shipping fee.
- * @param string $unitDescriptionAsString
- * @return $this
- */
- public function setUnit($unitDescriptionAsString)
- {
- $this->unit = $unitDescriptionAsString;
- return $this;
- }
-
- /**
- * Optional - discount in percent, applies to this order row only
- *
- * @param int $discountPercentAsInt
- * @return $this
- */
- public function setDiscountPercent($discountPercentAsInt)
- {
- $this->discountPercent = $discountPercentAsInt;
- return $this;
- }
-
- /**
- * Optional - Can be used when creating or updating an order.
- * The returned rows will have their corresponding temporary reference as they were given in the in-data.
- * It will not be stored and will not be returned in GetOrder.
- * Checkout orders only. Will not be applicable for other order types.
- * @param $temporaryReference
- * @return $this
- */
- public function setTemporaryReference($temporaryReference)
- {
- $this->temporaryReference = $temporaryReference;
- return $this;
- }
+ /**
+ * @var float $quantity quantity is always 1
+ */
+ public $quantity;
+
+ /**
+ * @var string $shippingId
+ */
+ public $shippingId;
+
+ /**
+ * @var string $name
+ */
+ public $name;
+
+ /**
+ * @var string $description
+ */
+ public $description;
+
+
+ /**
+ * @var float $amountExVat
+ */
+ public $amountExVat;
+
+
+ /**
+ * @var float $amountIncVat
+ */
+ public $amountIncVat;
+
+ /**
+ * @var int $vatPercent
+ */
+ public $vatPercent;
+
+ /**
+ * @var string $unit
+ */
+ public $unit;
+
+ /**
+ * @var int $vatDiscount -- defaults to zero (0)
+ */
+ public $discountPercent;
+
+ /**
+ * @var string $temporaryReference - Option parameter.
+ */
+ public $temporaryReference;
+
+ /**
+ * ShippingFee constructor.
+ */
+ function __construct()
+ {
+ // set to 1, as this attribute is used by WebServiceRowFormatter() and all shipping rows are for one (1) unit
+ $this->quantity = 1;
+ }
+
+ /**
+ * Optional
+ * @param string $idAsString
+ * @return $this
+ */
+ public function setShippingId($idAsString)
+ {
+ $this->shippingId = $idAsString;
+ return $this;
+ }
+
+ /**
+ * Optional - short item name
+ *
+ * Note that this will be merged with the item description when the request is sent to Svea
+ *
+ * @param string $nameAsString
+ * @return $this
+ */
+ public function setName($nameAsString)
+ {
+ $this->name = $nameAsString;
+ return $this;
+ }
+
+ /**
+ * Optional - long item description
+ *
+ * Note that this will be merged with the item name when the request is sent to Svea
+ *
+ * @param string $descriptionAsString
+ * @return $this
+ */
+ public function setDescription($descriptionAsString)
+ {
+ $this->description = $descriptionAsString;
+ return $this;
+ }
+
+ /**
+ * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
+ * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
+ *
+ * Order row item price excluding taxes, expressed as a float value.
+ *
+ * This action is not allowed for Checkout payment
+ *
+ * @param float $amountAsFloat
+ * @return $this
+ */
+ public function setAmountExVat($amountAsFloat)
+ {
+ $this->amountExVat = $amountAsFloat;
+ return $this;
+ }
+
+ /**
+ * Optional - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
+ * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
+ *
+ * Order row item price including tax, expressed as a float value.
+ *
+ * If you specify AmountIncVat, note that this may introduce a cumulative rounding error when ordering large
+ * quantities of an item, as the package bases the total order sum on a calculated price ex. vat.
+ *
+ * Also, Svea uses bankers rounding (half-to-even) when calculating the order total, so at times a rounding error of at most
+ * one cent/öre may show up if the implementation/shop does not use the same rounding method.
+ *
+ * See HostedPaymentTest for examples, including sums and calculations.
+ *
+ * @param float $amountAsFloat
+ * @return $this
+ */
+ public function setAmountIncVat($amountAsFloat)
+ {
+ $this->amountIncVat = $amountAsFloat;
+ return $this;
+ }
+
+ /**
+ * Recommended - precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow.
+ * Use functions setAmountExVat(), setAmountIncVat() or setVatPercent(). The recommended is to use setAmountExVat() and setVatPercent().
+ *
+ * Order row item price vat rate in percent, expressed as an integer.
+ *
+ * @param int $vatPercentAsInt
+ * @return $this
+ */
+ public function setVatPercent($vatPercentAsInt)
+ {
+ $this->vatPercent = $vatPercentAsInt;
+ return $this;
+ }
+
+ /**
+ * Optional - the name of the unit used for the shipping fee.
+ * @param string $unitDescriptionAsString
+ * @return $this
+ */
+ public function setUnit($unitDescriptionAsString)
+ {
+ $this->unit = $unitDescriptionAsString;
+ return $this;
+ }
+
+ /**
+ * Optional - discount in percent, applies to this order row only
+ *
+ * @param int $discountPercentAsInt
+ * @return $this
+ */
+ public function setDiscountPercent($discountPercentAsInt)
+ {
+ $this->discountPercent = $discountPercentAsInt;
+ return $this;
+ }
+
+ /**
+ * Optional - Can be used when creating or updating an order.
+ * The returned rows will have their corresponding temporary reference as they were given in the in-data.
+ * It will not be stored and will not be returned in GetOrder.
+ * Checkout orders only. Will not be applicable for other order types.
+ * @param $temporaryReference
+ * @return $this
+ */
+ public function setTemporaryReference($temporaryReference)
+ {
+ $this->temporaryReference = $temporaryReference;
+ return $this;
+ }
}
diff --git a/src/BuildOrder/UpdateOrderBuilder.php b/src/BuildOrder/UpdateOrderBuilder.php
index 14e7ef9a..8410079b 100644
--- a/src/BuildOrder/UpdateOrderBuilder.php
+++ b/src/BuildOrder/UpdateOrderBuilder.php
@@ -11,105 +11,105 @@
*/
class UpdateOrderBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
-
- /**
- * string $orderId Svea order id to query, as returned in the createOrder request response, either a transactionId or a SveaOrderId
- */
- public $orderId;
-
- /**
- * @var string $countryCode
- */
- public $countryCode;
-
- /**
- * @var string $orderType -- one of ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE
- */
- public $orderType;
-
- /**
- * @var string $clientOrderNumber
- */
- public $clientOrderNumber = null;
-
- /**
- * @var string $notes
- */
- public $notes = null;
-
- public function __construct($config) {
- $this->conf = $config;
- }
-
- /**
- * Required. Use SveaOrderId recieved with createOrder response.
- * @param string $orderIdAsString
- * @return $this
- */
- public function setOrderId($orderIdAsString) {
- $this->orderId = $orderIdAsString;
- return $this;
- }
-
- /**
- * Required. Use same countryCode as in createOrder request.
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
-
- return $this;
- }
-
- /**
- * Optional. Update clientOrderNumber on order.
- * @param string $clientOrderNumberAsString
- * @return $this
- */
- public function setClientOrderNumber($clientOrderNumberAsString)
- {
- $this->clientOrderNumber = $clientOrderNumberAsString;
-
- return $this;
- }
-
- /**
- * Optional. Update notes on order.
- * @param string $notesAsString (200)
- * @return $this
- */
- public function setNotes($notesAsString)
- {
- $this->notes = $notesAsString;
-
- return $this;
- }
-
- /**
- * Use updateInvoiceOrder() to update an Invoice order using AdminServiceRequest UpdateOrder request
- * @return UpdateOrderRequest
- */
- public function updateInvoiceOrder()
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
-
- return new UpdateOrderRequest($this);
- }
-
- /**
- * Use updatePaymentPlanOrder() to update a PaymentPlan order using AdminServiceRequest UpdateOrder request
- * @return UpdateOrderRequest
- */
- public function updatePaymentPlanOrder()
- {
- $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
-
- return new UpdateOrderRequest($this);
- }
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
+
+ /**
+ * string $orderId Svea order id to query, as returned in the createOrder request response, either a transactionId or a SveaOrderId
+ */
+ public $orderId;
+
+ /**
+ * @var string $countryCode
+ */
+ public $countryCode;
+
+ /**
+ * @var string $orderType -- one of ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE
+ */
+ public $orderType;
+
+ /**
+ * @var string $clientOrderNumber
+ */
+ public $clientOrderNumber = null;
+
+ /**
+ * @var string $notes
+ */
+ public $notes = null;
+
+ public function __construct($config) {
+ $this->conf = $config;
+ }
+
+ /**
+ * Required. Use SveaOrderId recieved with createOrder response.
+ * @param string $orderIdAsString
+ * @return $this
+ */
+ public function setOrderId($orderIdAsString) {
+ $this->orderId = $orderIdAsString;
+ return $this;
+ }
+
+ /**
+ * Required. Use same countryCode as in createOrder request.
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional. Update clientOrderNumber on order.
+ * @param string $clientOrderNumberAsString
+ * @return $this
+ */
+ public function setClientOrderNumber($clientOrderNumberAsString)
+ {
+ $this->clientOrderNumber = $clientOrderNumberAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional. Update notes on order.
+ * @param string $notesAsString (200)
+ * @return $this
+ */
+ public function setNotes($notesAsString)
+ {
+ $this->notes = $notesAsString;
+
+ return $this;
+ }
+
+ /**
+ * Use updateInvoiceOrder() to update an Invoice order using AdminServiceRequest UpdateOrder request
+ * @return UpdateOrderRequest
+ */
+ public function updateInvoiceOrder()
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ return new UpdateOrderRequest($this);
+ }
+
+ /**
+ * Use updatePaymentPlanOrder() to update a PaymentPlan order using AdminServiceRequest UpdateOrder request
+ * @return UpdateOrderRequest
+ */
+ public function updatePaymentPlanOrder()
+ {
+ $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+
+ return new UpdateOrderRequest($this);
+ }
}
diff --git a/src/BuildOrder/UpdateOrderRowsBuilder.php b/src/BuildOrder/UpdateOrderRowsBuilder.php
index a52de604..9e9abcdc 100644
--- a/src/BuildOrder/UpdateOrderRowsBuilder.php
+++ b/src/BuildOrder/UpdateOrderRowsBuilder.php
@@ -35,109 +35,109 @@
*/
class UpdateOrderRowsBuilder extends CheckoutAdminOrderBuilder
{
- /**
- * @var ConfigurationProvider $conf
- */
- public $conf;
-
- /**
- * @var NumberedOrderRow[] $numberedOrderRows the updated order rows
- */
- public $numberedOrderRows;
-
- /**
- * string $orderId Svea order id to query, as returned in the createOrder request response,
- * either a transactionId or a SveaOrderId
- */
- public $orderId;
-
- /** @var string $countryCode */
- public $countryCode;
-
- /** @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE */
- public $orderType;
-
-
- /**
- * UpdateOrderRowsBuilder constructor.
- * @param $config
- */
- public function __construct($config)
- {
- $this->conf = $config;
- $this->numberedOrderRows = array();
- }
-
- /**
- * Required. Use SveaOrderId recieved with createOrder response.
- * @param string $orderIdAsString
- * @return $this
- */
- public function setOrderId($orderIdAsString) {
- $this->orderId = $orderIdAsString;
- return $this;
- }
-
- /**
- * Required. Use same countryCode as in createOrder request.
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
-
- return $this;
- }
-
- /**
- * Required.
- * @param NumberedOrderRow $row
- * @return $this
- */
- public function updateOrderRow($row)
- {
- $this->numberedOrderRows[] = $row;
-
- return $this;
- }
-
- /**
- * Convenience method to add several rows at once.
- * @param NumberedOrderRow[] $rows
- * @return $this
- */
- public function updateOrderRows($rows)
- {
- $this->numberedOrderRows = array_merge($this->numberedOrderRows, $rows);
-
- return $this;
- }
-
- /**
- * Use updateInvoiceOrderRows() to update an Invoice order using AdminServiceRequest UpdateOrderRows request
- * @return UpdateOrderRowsRequest
- */
- public function updateInvoiceOrderRows()
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
-
- return new UpdateOrderRowsRequest($this);
- }
-
- /**
- * Use updatePaymentPlanOrderRows() to update a PaymentPlan order using AdminServiceRequest UpdateOrderRows request
- * @return UpdateOrderRowsRequest
- */
- public function updatePaymentPlanOrderRows()
- {
- $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
-
- return new UpdateOrderRowsRequest($this);
- }
-
- public function updateCheckoutOrderRows()
- {
- return new UpdateOrderRowsService($this);
- }
+ /**
+ * @var ConfigurationProvider $conf
+ */
+ public $conf;
+
+ /**
+ * @var NumberedOrderRow[] $numberedOrderRows the updated order rows
+ */
+ public $numberedOrderRows;
+
+ /**
+ * string $orderId Svea order id to query, as returned in the createOrder request response,
+ * either a transactionId or a SveaOrderId
+ */
+ public $orderId;
+
+ /** @var string $countryCode */
+ public $countryCode;
+
+ /** @var string $orderType -- one of Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE */
+ public $orderType;
+
+
+ /**
+ * UpdateOrderRowsBuilder constructor.
+ * @param $config
+ */
+ public function __construct($config)
+ {
+ $this->conf = $config;
+ $this->numberedOrderRows = [];
+ }
+
+ /**
+ * Required. Use SveaOrderId recieved with createOrder response.
+ * @param string $orderIdAsString
+ * @return $this
+ */
+ public function setOrderId($orderIdAsString) {
+ $this->orderId = $orderIdAsString;
+ return $this;
+ }
+
+ /**
+ * Required. Use same countryCode as in createOrder request.
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+
+ return $this;
+ }
+
+ /**
+ * Required.
+ * @param NumberedOrderRow $row
+ * @return $this
+ */
+ public function updateOrderRow($row)
+ {
+ $this->numberedOrderRows[] = $row;
+
+ return $this;
+ }
+
+ /**
+ * Convenience method to add several rows at once.
+ * @param NumberedOrderRow[] $rows
+ * @return $this
+ */
+ public function updateOrderRows($rows)
+ {
+ $this->numberedOrderRows = array_merge($this->numberedOrderRows, $rows);
+
+ return $this;
+ }
+
+ /**
+ * Use updateInvoiceOrderRows() to update an Invoice order using AdminServiceRequest UpdateOrderRows request
+ * @return UpdateOrderRowsRequest
+ */
+ public function updateInvoiceOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ return new UpdateOrderRowsRequest($this);
+ }
+
+ /**
+ * Use updatePaymentPlanOrderRows() to update a PaymentPlan order using AdminServiceRequest UpdateOrderRows request
+ * @return UpdateOrderRowsRequest
+ */
+ public function updatePaymentPlanOrderRows()
+ {
+ $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+
+ return new UpdateOrderRowsRequest($this);
+ }
+
+ public function updateCheckoutOrderRows()
+ {
+ return new UpdateOrderRowsService($this);
+ }
}
diff --git a/src/BuildOrder/Validator/HostedOrderValidator.php b/src/BuildOrder/Validator/HostedOrderValidator.php
index e34d962c..733eb8a5 100644
--- a/src/BuildOrder/Validator/HostedOrderValidator.php
+++ b/src/BuildOrder/Validator/HostedOrderValidator.php
@@ -8,140 +8,140 @@
*/
class HostedOrderValidator extends OrderValidator
{
- public $errors = array();
+ public $errors = [];
- protected $isCompany = false;
+ protected $isCompany = false;
- /**
- * @param type $order
- * @return array $errors
- */
- public function validate($order)
- {
- if (isset($order->order->orgNumber) || isset($order->order->companyVatNumber) || isset($order->order->companyName)) {
- $this->isCompany = TRUE;
- }
+ /**
+ * @param type $order
+ * @return array $errors
+ */
+ public function validate($order)
+ {
+ if (isset($order->order->orgNumber) || isset($order->order->companyVatNumber) || isset($order->order->companyName)) {
+ $this->isCompany = TRUE;
+ }
- $this->errors = $this->validateClientOrderNumber($order->order, $this->errors);
- $this->errors = $this->validateCurrency($order, $this->errors);
- $this->errors = $this->validateCountryCode($order, $this->errors); //should be optional for hosted payment because not used
- $this->errors = $this->validateRequiredFieldsForOrder($order->order, $this->errors);
- $this->errors = $this->validateOrderRows($order, $this->errors);
- $this->errors = $this->validatePayerAlias($order, $this->errors); // validate for swish
+ $this->errors = $this->validateClientOrderNumber($order->order, $this->errors);
+ $this->errors = $this->validateCurrency($order, $this->errors);
+ $this->errors = $this->validateCountryCode($order, $this->errors); //should be optional for hosted payment because not used
+ $this->errors = $this->validateRequiredFieldsForOrder($order->order, $this->errors);
+ $this->errors = $this->validateOrderRows($order, $this->errors);
+ $this->errors = $this->validatePayerAlias($order, $this->errors); // validate for swish
- return $this->errors;
- }
+ return $this->errors;
+ }
- /**
- * @param type $order
- * @param array $errors
- * @return array
- */
- private function validatePayerAlias($order, $errors)
- {
- if (isset($order->order->payerAlias) && $order->paymentMethod == "SWISH")
- {
- if(ctype_digit($order->order->payerAlias) == false)
- {
- $errors['incorrect type'] = 'payerAlias must be numeric and can not contain any non-numeric characters';
- }
- if(strlen($order->order->payerAlias) != 11)
- {
- $errors['incorrect length'] = 'payerAlias must be 11 digits';
- }
- if($order->order->countryCode != "SE")
- {
- $errors['incorrect value'] = 'countryCode must be set to "SE" if payment method is SWISH';
- }
- }
- elseif(isset($order->order->payerAlias) == false && isset($order->paymentMethod) && $order->paymentMethod == "SWISH")
- {
- $errors['missing value'] = 'payerAlias must be set if using payment method SWISH. Use function setPayerAlias()';
- }
- return $errors;
- }
+ /**
+ * @param type $order
+ * @param array $errors
+ * @return array
+ */
+ private function validatePayerAlias($order, $errors)
+ {
+ if (isset($order->order->payerAlias) && $order->paymentMethod == "SWISH")
+ {
+ if(ctype_digit($order->order->payerAlias) == false)
+ {
+ $errors['incorrect type'] = 'payerAlias must be numeric and can not contain any non-numeric characters';
+ }
+ if(strlen($order->order->payerAlias) != 11)
+ {
+ $errors['incorrect length'] = 'payerAlias must be 11 digits';
+ }
+ if($order->order->countryCode != "SE")
+ {
+ $errors['incorrect value'] = 'countryCode must be set to "SE" if payment method is SWISH';
+ }
+ }
+ elseif(isset($order->order->payerAlias) == false && isset($order->paymentMethod) && $order->paymentMethod == "SWISH")
+ {
+ $errors['missing value'] = 'payerAlias must be set if using payment method SWISH. Use function setPayerAlias()';
+ }
+ return $errors;
+ }
- /**
- * @param type $order
- * @param array $errors
- * @return array
- */
- private function validateClientOrderNumber($order, $errors)
- {
- if (isset($order->clientOrderNumber) == false || "" == $order->clientOrderNumber) {
- $errors['missing value'] = "ClientOrderNumber is required. Use function setClientOrderNumber().";
- }
- /*if(isset($order->clientOrderNumber) && $order->paymentMethod == "SWISH")
- {
- $errors['incorrect value'] = "ClientOrderNumber cannot be longer than 35 characters for Swish payments";
- }*/
- return $errors;
- }
+ /**
+ * @param type $order
+ * @param array $errors
+ * @return array
+ */
+ private function validateClientOrderNumber($order, $errors)
+ {
+ if (isset($order->clientOrderNumber) == false || "" == $order->clientOrderNumber) {
+ $errors['missing value'] = "ClientOrderNumber is required. Use function setClientOrderNumber().";
+ }
+ /*if(isset($order->clientOrderNumber) && $order->paymentMethod == "SWISH")
+ {
+ $errors['incorrect value'] = "ClientOrderNumber cannot be longer than 35 characters for Swish payments";
+ }*/
+ return $errors;
+ }
- /**
- * @param type $order
- * @param type $errors
- * @return type
- */
- private function validateCurrency($order, $errors)
- {
- if (isset($order->order->currency) == false) {
- $errors['missing value'] = "Currency is required. Use function setCurrency().";
- }
- if (isset($order->order->currency) && isset($order->paymentMethod))
- {
- if($order->paymentMethod == "SVEACARDPAY" || $order->paymentMethod == "SVEACARDPAY_PF")
- {
- if(Helper::isCardPayCurrency($order->order->currency) == false)
- {
- $errors['unsupported currency'] = "Currency is not supported with this payment method.";
- }
- }
- }
- return $errors;
- }
+ /**
+ * @param type $order
+ * @param type $errors
+ * @return type
+ */
+ private function validateCurrency($order, $errors)
+ {
+ if (isset($order->order->currency) == false) {
+ $errors['missing value'] = "Currency is required. Use function setCurrency().";
+ }
+ if (isset($order->order->currency) && isset($order->paymentMethod))
+ {
+ if($order->paymentMethod == "SVEACARDPAY" || $order->paymentMethod == "SVEACARDPAY_PF")
+ {
+ if(Helper::isCardPayCurrency($order->order->currency) == false)
+ {
+ $errors['unsupported currency'] = "Currency is not supported with this payment method.";
+ }
+ }
+ }
+ return $errors;
+ }
- /**
- * @param type $order
- * @param type $errors
- * @return type
- */
- private function validateCountryCode($order, $errors)
- {
- if (isset($order->order->countryCode) == false && isset($order->paymentMethod) && $order->paymentMethod == "SVEACARDPAY_PF") {
- $errors['missing value'] = "CountryCode is required for SVEACARDPAY_PF. Use function setCountryCode().";
- }
+ /**
+ * @param type $order
+ * @param type $errors
+ * @return type
+ */
+ private function validateCountryCode($order, $errors)
+ {
+ if (isset($order->order->countryCode) == false && isset($order->paymentMethod) && $order->paymentMethod == "SVEACARDPAY_PF") {
+ $errors['missing value'] = "CountryCode is required for SVEACARDPAY_PF. Use function setCountryCode().";
+ }
- return $errors;
- }
+ return $errors;
+ }
- public function validateEuroCustomer($order, $errors)
- {
- if (isset($order->customerIdentity->initials) == false && $this->isCompany == FALSE && $order->countryCode == "NL") {
- $errors['missing value'] = "Initials is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setInitials().";
- }
- if (isset($order->customerIdentity->birthDate) == false && $this->isCompany == FALSE) {
- $errors['missing value'] = "BirthDate is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setBirthDate().";
- }
- if (isset($order->customerIdentity->firstname) == false || isset($order->customerIdentity->lastname) == false && $this->isCompany == FALSE) {
- $errors['missing value'] = "Name is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setName().";
- }
- if (isset($order->customerIdentity->companyVatNumber) == false && $this->isCompany == true) {
- $errors['missing value'] = "VatNumber is required for INVOICE and PAYMENTPLAN payments for company customers when countrycode is NL. Use function setVatNumber().";
- }
- if (isset($order->customerIdentity->companyName) == false && $this->isCompany == true) {
- $errors['missing value'] = "CompanyName is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setCompanyName().";
- }
- if (isset($order->customerIdentity->street) == false || isset($order->customerIdentity->housenumber) == false) {
- $errors['missing value'] = "StreetAddress is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setStreetAddress().";
- }
- if (isset($order->customerIdentity->locality) == false) {
- $errors['missing value'] = "Locality is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setLocality().";
- }
- if (isset($order->customerIdentity->zipCode) == false) {
- $errors['missing value'] = "ZipCode is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setZipCode().";
- }
+ public function validateEuroCustomer($order, $errors)
+ {
+ if (isset($order->customerIdentity->initials) == false && $this->isCompany == FALSE && $order->countryCode == "NL") {
+ $errors['missing value'] = "Initials is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setInitials().";
+ }
+ if (isset($order->customerIdentity->birthDate) == false && $this->isCompany == FALSE) {
+ $errors['missing value'] = "BirthDate is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setBirthDate().";
+ }
+ if (isset($order->customerIdentity->firstname) == false || isset($order->customerIdentity->lastname) == false && $this->isCompany == FALSE) {
+ $errors['missing value'] = "Name is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setName().";
+ }
+ if (isset($order->customerIdentity->companyVatNumber) == false && $this->isCompany == true) {
+ $errors['missing value'] = "VatNumber is required for INVOICE and PAYMENTPLAN payments for company customers when countrycode is NL. Use function setVatNumber().";
+ }
+ if (isset($order->customerIdentity->companyName) == false && $this->isCompany == true) {
+ $errors['missing value'] = "CompanyName is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setCompanyName().";
+ }
+ if (isset($order->customerIdentity->street) == false || isset($order->customerIdentity->housenumber) == false) {
+ $errors['missing value'] = "StreetAddress is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setStreetAddress().";
+ }
+ if (isset($order->customerIdentity->locality) == false) {
+ $errors['missing value'] = "Locality is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setLocality().";
+ }
+ if (isset($order->customerIdentity->zipCode) == false) {
+ $errors['missing value'] = "ZipCode is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setZipCode().";
+ }
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/BuildOrder/Validator/IdentityValidator.php b/src/BuildOrder/Validator/IdentityValidator.php
index 7bededa4..5575a168 100644
--- a/src/BuildOrder/Validator/IdentityValidator.php
+++ b/src/BuildOrder/Validator/IdentityValidator.php
@@ -5,165 +5,165 @@
use Svea\WebPay\BuildOrder\CreateOrderBuilder;
class IdentityValidator
-{
- private $isCompany;
-
- /**
- * IdentityValidator constructor.
- * @param bool $isCompany
- */
- function __construct($isCompany = false)
- {
- $this->isCompany = $isCompany;
- }
-
- /**
- * Not in use
- * @param type $order
- * @param string $errors
- * @return string
- */
- public function validateThatCustomerIdentityExists($order, $errors)
- {
- if (isset($order->customerIdentity->ssn) == false
- && isset($order->customerIdentity->orgNumber) == false
- && isset($order->customerIdentity->companyVatNumber) == false
- && isset($order->customerIdentity->initials) == false
- && isset($order->customerIdentity->email) == false
- && isset($order->customerIdentity->phonenumber) == false
- && isset($order->customerIdentity->ipAddress) == false
- && isset($order->customerIdentity->firstname) == false
- && isset($order->customerIdentity->lastname) == false
- && isset($order->customerIdentity->street) == false
- && isset($order->customerIdentity->housenumber) == false
- && isset($order->customerIdentity->zipcode) == false
- && isset($order->customerIdentity->coAddress) == false
- && isset($order->customerIdentity->locality) == false
- && isset($order->customerIdentity->companyName) == false
- ) {
- $errors['missing values'] = "Customer values are required for Invoice and PaymentPlan orders.";
- }
-
- return $errors;
- }
-
- /**
- * Validates that either NationalIdNumber (individual customers) or companyVatNumber (company customers) is set to
- * a non-empty string.
- * (NationalIdNumber or companyVatNumber required for SE, NO, DK, FI orders)
- * @param CreateOrderBuilder $order
- * @param array of string $errors -- validator errors array
- * @return array of string $errors -- updated validator errors array
- */
- public function validateNordicIdentity($order, $errors)
- {
- if ($this->isCompany == FALSE) {
- if (!isset($order->customerIdentity->ssn) || empty($order->customerIdentity->ssn)) {
- $errors['missing value'] = "NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().";
- }
- } else // is company customer
- {
- if (!isset($order->customerIdentity->orgNumber) || empty($order->customerIdentity->orgNumber)) {
- $errors['missing value'] = "OrgNumber is required for company customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().";
- }
- }
-
- return $errors;
- }
-
- /**
- * CustomerIdentity values Required for NL
- * @param type $order
- * @param type $errors
- * @return type
- */
- public function validateNLidentity($order, $errors)
- {
- if ($this->isCompany == FALSE && isset($order->customerIdentity->initials) == false) {
- $errors['missing value'] = "Initials is required for individual customers when countrycode is NL. Use function setInitials().";
- }
-
- if ($this->isCompany == FALSE && isset($order->customerIdentity->birthDate) == false) {
- $errors['missing value'] = "BirthDate is required for individual customers when countrycode is NL. Use function setBirthDate().";
- }
-
- if ($this->isCompany == FALSE && (isset($order->customerIdentity->firstname) == false || isset($order->customerIdentity->lastname) == false)) {
- $errors['missing value'] = "Name is required for individual customers when countrycode is NL. Use function setName().";
- }
-
- if ($this->isCompany == true && isset($order->customerIdentity->companyVatNumber) == false) {
- $errors['missing value'] = "VatNumber is required for company customers when countrycode is NL. Use function setVatNumber().";
- }
- if ($this->isCompany == true && isset($order->customerIdentity->companyName) == false) {
- $errors['missing value'] = "CompanyName is required for company customers when countrycode is NL. Use function setCompanyName().";
-
- }
-
- if (isset($order->customerIdentity->street) == false || isset($order->customerIdentity->housenumber) == false) {
- $errors['missing value'] = "StreetAddress is required for all customers when countrycode is NL. Use function setStreetAddress().";
- }
-
- if (isset($order->customerIdentity->locality) == false) {
- $errors['missing value'] = "Locality is required for all customers when countrycode is NL. Use function setLocality().";
- }
-
- if (isset($order->customerIdentity->zipCode) == false) {
- $errors['missing value'] = "ZipCode is required for all customers when countrycode is NL. Use function setZipCode().";
- }
-
- return $errors;
- }
-
- /**
- * CustomerIdentity values Required for DE
- * @param type $order
- * @param type $errors
- * @return type
- */
- public function validateDEidentity($order, $errors)
- {
- if ($this->isCompany == FALSE && isset($order->customerIdentity->birthDate) == false) {
- $errors['missing value'] = "BirthDate is required for individual customers when countrycode is DE. Use function setBirthDate().";
- }
-
- if ($this->isCompany == FALSE && (isset($order->customerIdentity->firstname) == false || isset($order->customerIdentity->lastname) == false)) {
- $errors['missing value'] = "Name is required for individual customers when countrycode is DE. Use function setName().";
- }
-
- if ($this->isCompany == true && isset($order->customerIdentity->companyVatNumber) == false) {
- $errors['missing value'] = "VatNumber is required for company customers when countrycode is DE. Use function setVatNumber().";
- }
-
- if ($this->isCompany == true && isset($order->customerIdentity->companyName) == false) {
- $errors['missing value'] = "CompanyName is required for individual customers when countrycode is DE. Use function setCompanyName().";
- }
-
- if (isset($order->customerIdentity->street) == false || isset($order->customerIdentity->housenumber) == false) {
- $errors['missing value'] = "StreetAddress is required for all customers when countrycode is DE. Use function setStreetAddress().";
- }
-
- if (isset($order->customerIdentity->locality) == false) {
- $errors['missing value'] = "Locality is required for all customers when countrycode is DE. Use function setLocality().";
- }
-
- if (isset($order->customerIdentity->zipCode) == false) {
- $errors['missing value'] = "ZipCode is required for all customers when countrycode is DE. Use function setZipCode().";
- }
-
- return $errors;
- }
-
- /**
- * @param type $order
- * @param type $errors
- * @return type $errors
- */
- public function validateDoubleIdentity($order, $errors)
- {
- if ((isset($order->customerIdentity->orgNumber) || isset($order->customerIdentity->companyVatNumber)) && isset($order->customerIdentity->ssn)) {
- $errors['duplicated value'] = "Customer is either an individual or a company. You can not use function setNationalIdNumber() in combination with setNationalIdNumber() or setCompanyVatNumber().";
- }
-
- return $errors;
- }
+{
+ private $isCompany;
+
+ /**
+ * IdentityValidator constructor.
+ * @param bool $isCompany
+ */
+ function __construct($isCompany = false)
+ {
+ $this->isCompany = $isCompany;
+ }
+
+ /**
+ * Not in use
+ * @param type $order
+ * @param string $errors
+ * @return string
+ */
+ public function validateThatCustomerIdentityExists($order, $errors)
+ {
+ if (isset($order->customerIdentity->ssn) == false
+ && isset($order->customerIdentity->orgNumber) == false
+ && isset($order->customerIdentity->companyVatNumber) == false
+ && isset($order->customerIdentity->initials) == false
+ && isset($order->customerIdentity->email) == false
+ && isset($order->customerIdentity->phonenumber) == false
+ && isset($order->customerIdentity->ipAddress) == false
+ && isset($order->customerIdentity->firstname) == false
+ && isset($order->customerIdentity->lastname) == false
+ && isset($order->customerIdentity->street) == false
+ && isset($order->customerIdentity->housenumber) == false
+ && isset($order->customerIdentity->zipcode) == false
+ && isset($order->customerIdentity->coAddress) == false
+ && isset($order->customerIdentity->locality) == false
+ && isset($order->customerIdentity->companyName) == false
+ ) {
+ $errors['missing values'] = "Customer values are required for Invoice and PaymentPlan orders.";
+ }
+
+ return $errors;
+ }
+
+ /**
+ * Validates that either NationalIdNumber (individual customers) or companyVatNumber (company customers) is set to
+ * a non-empty string.
+ * (NationalIdNumber or companyVatNumber required for SE, NO, DK, FI orders)
+ * @param CreateOrderBuilder $order
+ * @param array of string $errors -- validator errors array
+ * @return array of string $errors -- updated validator errors array
+ */
+ public function validateNordicIdentity($order, $errors)
+ {
+ if ($this->isCompany == FALSE) {
+ if (!isset($order->customerIdentity->ssn) || empty($order->customerIdentity->ssn)) {
+ $errors['missing value'] = "NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().";
+ }
+ } else // is company customer
+ {
+ if (!isset($order->customerIdentity->orgNumber) || empty($order->customerIdentity->orgNumber)) {
+ $errors['missing value'] = "OrgNumber is required for company customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().";
+ }
+ }
+
+ return $errors;
+ }
+
+ /**
+ * CustomerIdentity values Required for NL
+ * @param type $order
+ * @param type $errors
+ * @return type
+ */
+ public function validateNLidentity($order, $errors)
+ {
+ if ($this->isCompany == FALSE && isset($order->customerIdentity->initials) == false) {
+ $errors['missing value'] = "Initials is required for individual customers when countrycode is NL. Use function setInitials().";
+ }
+
+ if ($this->isCompany == FALSE && isset($order->customerIdentity->birthDate) == false) {
+ $errors['missing value'] = "BirthDate is required for individual customers when countrycode is NL. Use function setBirthDate().";
+ }
+
+ if ($this->isCompany == FALSE && (isset($order->customerIdentity->firstname) == false || isset($order->customerIdentity->lastname) == false)) {
+ $errors['missing value'] = "Name is required for individual customers when countrycode is NL. Use function setName().";
+ }
+
+ if ($this->isCompany == true && isset($order->customerIdentity->companyVatNumber) == false) {
+ $errors['missing value'] = "VatNumber is required for company customers when countrycode is NL. Use function setVatNumber().";
+ }
+ if ($this->isCompany == true && isset($order->customerIdentity->companyName) == false) {
+ $errors['missing value'] = "CompanyName is required for company customers when countrycode is NL. Use function setCompanyName().";
+
+ }
+
+ if (isset($order->customerIdentity->street) == false || isset($order->customerIdentity->housenumber) == false) {
+ $errors['missing value'] = "StreetAddress is required for all customers when countrycode is NL. Use function setStreetAddress().";
+ }
+
+ if (isset($order->customerIdentity->locality) == false) {
+ $errors['missing value'] = "Locality is required for all customers when countrycode is NL. Use function setLocality().";
+ }
+
+ if (isset($order->customerIdentity->zipCode) == false) {
+ $errors['missing value'] = "ZipCode is required for all customers when countrycode is NL. Use function setZipCode().";
+ }
+
+ return $errors;
+ }
+
+ /**
+ * CustomerIdentity values Required for DE
+ * @param type $order
+ * @param type $errors
+ * @return type
+ */
+ public function validateDEidentity($order, $errors)
+ {
+ if ($this->isCompany == FALSE && isset($order->customerIdentity->birthDate) == false) {
+ $errors['missing value'] = "BirthDate is required for individual customers when countrycode is DE. Use function setBirthDate().";
+ }
+
+ if ($this->isCompany == FALSE && (isset($order->customerIdentity->firstname) == false || isset($order->customerIdentity->lastname) == false)) {
+ $errors['missing value'] = "Name is required for individual customers when countrycode is DE. Use function setName().";
+ }
+
+ if ($this->isCompany == true && isset($order->customerIdentity->companyVatNumber) == false) {
+ $errors['missing value'] = "VatNumber is required for company customers when countrycode is DE. Use function setVatNumber().";
+ }
+
+ if ($this->isCompany == true && isset($order->customerIdentity->companyName) == false) {
+ $errors['missing value'] = "CompanyName is required for individual customers when countrycode is DE. Use function setCompanyName().";
+ }
+
+ if (isset($order->customerIdentity->street) == false || isset($order->customerIdentity->housenumber) == false) {
+ $errors['missing value'] = "StreetAddress is required for all customers when countrycode is DE. Use function setStreetAddress().";
+ }
+
+ if (isset($order->customerIdentity->locality) == false) {
+ $errors['missing value'] = "Locality is required for all customers when countrycode is DE. Use function setLocality().";
+ }
+
+ if (isset($order->customerIdentity->zipCode) == false) {
+ $errors['missing value'] = "ZipCode is required for all customers when countrycode is DE. Use function setZipCode().";
+ }
+
+ return $errors;
+ }
+
+ /**
+ * @param type $order
+ * @param type $errors
+ * @return type $errors
+ */
+ public function validateDoubleIdentity($order, $errors)
+ {
+ if ((isset($order->customerIdentity->orgNumber) || isset($order->customerIdentity->companyVatNumber)) && isset($order->customerIdentity->ssn)) {
+ $errors['duplicated value'] = "Customer is either an individual or a company. You can not use function setNationalIdNumber() in combination with setNationalIdNumber() or setCompanyVatNumber().";
+ }
+
+ return $errors;
+ }
}
diff --git a/src/BuildOrder/Validator/OrderValidator.php b/src/BuildOrder/Validator/OrderValidator.php
index 11768487..d62ce368 100644
--- a/src/BuildOrder/Validator/OrderValidator.php
+++ b/src/BuildOrder/Validator/OrderValidator.php
@@ -13,226 +13,226 @@
*/
abstract class OrderValidator
{
- public abstract function validate($order);
-
- /**
- * @param type $order
- * @param type $errors
- * @return type $errors
- */
- public function validatePeppolId($order, $errors)
- {
- if (isset($order->peppolId)) {
-
- if($this->isCompany == false)
- {
- $errors['incorrect value'] = "CustomerType must be a company when using PeppolId.";
- }
-
- if(is_numeric(substr($order->peppolId,0,4)) == false )
- {
- $errors['incorrect value'] = "First 4 characters of PeppolId must be numeric.";
- }
-
- if(ctype_alnum(substr($order->peppolId,6)) == false)
- {
- $errors['incorrect value'] = "All characters after the fifth character in PeppolId must be alphanumeric.";
- }
-
- if(substr($order->peppolId,4,1) != ":")
- {
- $errors['incorrect value'] = "The fifth character of PeppolId must be \":\".";
- }
-
- if(strlen($order->peppolId) > 55)
- {
- $errors['incorrect value'] = "PeppolId is too long, must be 55 characters or fewer.";
- }
-
- if(strlen($order->peppolId) < 6)
- {
- $errors['incorrect value'] = "PeppolId is too short, must be 6 characters or longer.";
- }
- }
-
- return $errors;
- }
-
- /*
- * @param type $order
- * @param type $errors
- * @return type $errors
- */
- protected function validateRequiredFieldsForOrder($order, $errors)
- {
- if (isset($order->orderRows) == false || count($order->orderRows) == 0) {
- $errors['missing values'] = 'OrderRows are required. Use function addOrderRow(Svea\WebPay\WebPayItem::orderRow) to get orderrow setters. ';
- }
-
- return $errors;
- }
-
- /**
- * @param $order
- * @param $errors
- * @return array $errors
- */
- protected function validateOrderRows($order, $errors)
- {
- if (isset($order->orderRows)) {
- foreach ($order->orderRows as $row) {
- if (isset($row->quantity) == false) {
- $errors['missing value'] = "Quantity is required in object Svea\WebPay\BuildOrder\RowBuilders\Item. Use function Svea\WebPay\BuildOrder\RowBuilders\Item::setQuantity().";
- }
-
- // Precisely two of the following attributes must be set in order to calculate total amount and vat
- if ((isset($row->amountExVat) == false && isset($row->vatPercent) == false && isset($row->amountIncVat) == false) ||
- (isset($row->amountExVat) == true && isset($row->vatPercent) == true && isset($row->amountIncVat) == true)
- ) {
- $errors['missing values'] = "Precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow. Use functions setAmountExVat(), setAmountIncVat() or setVatPercent().";
- } elseif (isset($row->amountExVat) && (isset($row->vatPercent) == false && isset($row->amountIncVat) == false)) {
- $errors['missing values'] = "At least one of these values must be set in combination with AmountExVat, in object Svea\WebPay\BuildOrder\RowBuilders\Item:: AmountIncVat or VatPercent for Orderrow. Use functions setAmountIncVat() or setVatPercent().";
- } elseif (isset($row->amountIncVat) && (isset($row->amountExVat) == false) && isset($row->vatPercent) == false) {
- $errors['missing values'] = "At least one of the values must be set in combination with AmountIncVat, in object Svea\WebPay\BuildOrder\RowBuilders\Item:: AmountExVat or VatPercent for Orderrow. Use functions setAmountExVat() or setVatPercent().";
- } elseif (isset($row->vatPercent) && (isset($row->amountExVat) == false && isset($row->amountIncVat) == false)) {
- $errors['missing values'] = "At least one of the values must be set in combination with VatPercent, in object Svea\WebPay\BuildOrder\RowBuilders\Item:: AmountIncVat or AmountExVat for Orderrow. Use functions setAmountExVat() or setAmountIncVat().";
- }
-
- // force correct order type of present attributes, see class OrderRow
- if (isset($row->vatDiscount) && !(is_int($row->vatDiscount) || is_float($row->vatDiscount)))
- $errors['incorrect datatype'] = "vatDiscount is not of type int or float.";
-
- if (isset($row->articleNumber) && !is_string($row->articleNumber))
- $errors['incorrect datatype'] = 'articleNumber is not of type string.';
-
- if (isset($row->quantity) && !(is_numeric($row->quantity)))
- $errors['incorrect datatype'] = "quantity is not numeric.";
-
- if (isset($row->unit) && !is_string($row->unit))
- $errors['incorrect datatype'] = 'unit is not of type string.';
-
- if (isset($row->amountExVat) && !(is_int($row->amountExVat) || is_float($row->amountExVat)))
- $errors['incorrect datatype'] = 'amountExVat is not of type float or int.';
-
- if (isset($row->amountIncVat) && !(is_int($row->amountIncVat) || is_float($row->amountIncVat)))
- $errors['incorrect datatype'] = 'amountIncVat is not of type float or int.';
-
- if (isset($row->name) && !is_string($row->name))
- $errors['incorrect datatype'] = 'name is not of type string.';
-
- if (isset($row->description) && !is_string($row->description))
- $errors['incorrect datatype'] = 'description is not of type string.';
-
- if (isset($row->vatPercent) && !(is_int($row->vatPercent) || is_float($row->vatPercent)))
- $errors['incorrect datatype'] = "vatPercent is not of type int.";
-
- if (isset($row->discountPercent) && !(is_int($row->discountPercent) || is_float($row->discountPercent)))
- $errors['incorrect datatype'] = "discountPercent is not of type int.";
- }
- }
-
- return $errors;
- }
-
- /**
- * @param $order
- * @param $errors
- * @return mixed
- *
- * Validate all rows - products and shipping and discount or voucher rows
- * Because that we use rows instead of orderRows
- *
- */
- protected function validateCheckoutOrderRows($order, $errors)
- {
- /**
- * * @var \Svea\WebPay\BuildOrder\RowBuilders\OrderRow [] $rows
- */
- $orderRows = $order->rows;
-
- if (count($orderRows) === 0) {
- $orderRows = $order->orderRows;
- }
-
- foreach ($orderRows as $row) {
- if (empty($row->name)) {
- $errors['missing values'] = "Name must be set in the Svea\\WebPay\\WebPayItem object. Use functions setName().";
- }
- }
-
- return $errors;
- }
-
-
- /**
- * @param CheckoutOrderBuilder $order
- * @param array $errors
- * @return array
- */
- protected function validateOrderId(CheckoutOrderBuilder $order, $errors)
+ public abstract function validate($order);
+
+ /**
+ * @param type $order
+ * @param type $errors
+ * @return type $errors
+ */
+ public function validatePeppolId($order, $errors)
+ {
+ if (isset($order->peppolId)) {
+
+ if($this->isCompany == false)
+ {
+ $errors['incorrect value'] = "CustomerType must be a company when using PeppolId.";
+ }
+
+ if(is_numeric(substr($order->peppolId,0,4)) == false )
+ {
+ $errors['incorrect value'] = "First 4 characters of PeppolId must be numeric.";
+ }
+
+ if(ctype_alnum(substr($order->peppolId,6)) == false)
+ {
+ $errors['incorrect value'] = "All characters after the fifth character in PeppolId must be alphanumeric.";
+ }
+
+ if(substr($order->peppolId,4,1) != ":")
+ {
+ $errors['incorrect value'] = "The fifth character of PeppolId must be \":\".";
+ }
+
+ if(strlen($order->peppolId) > 55)
+ {
+ $errors['incorrect value'] = "PeppolId is too long, must be 55 characters or fewer.";
+ }
+
+ if(strlen($order->peppolId) < 6)
+ {
+ $errors['incorrect value'] = "PeppolId is too short, must be 6 characters or longer.";
+ }
+ }
+
+ return $errors;
+ }
+
+ /*
+ * @param type $order
+ * @param type $errors
+ * @return type $errors
+ */
+ protected function validateRequiredFieldsForOrder($order, $errors)
+ {
+ if (isset($order->orderRows) == false || count($order->orderRows) == 0) {
+ $errors['missing values'] = 'OrderRows are required. Use function addOrderRow(Svea\WebPay\WebPayItem::orderRow) to get orderrow setters. ';
+ }
+
+ return $errors;
+ }
+
+ /**
+ * @param $order
+ * @param $errors
+ * @return array $errors
+ */
+ protected function validateOrderRows($order, $errors)
+ {
+ if (isset($order->orderRows)) {
+ foreach ($order->orderRows as $row) {
+ if (isset($row->quantity) == false) {
+ $errors['missing value'] = "Quantity is required in object Svea\WebPay\BuildOrder\RowBuilders\Item. Use function Svea\WebPay\BuildOrder\RowBuilders\Item::setQuantity().";
+ }
+
+ // Precisely two of the following attributes must be set in order to calculate total amount and vat
+ if ((isset($row->amountExVat) == false && isset($row->vatPercent) == false && isset($row->amountIncVat) == false) ||
+ (isset($row->amountExVat) == true && isset($row->vatPercent) == true && isset($row->amountIncVat) == true)
+ ) {
+ $errors['missing values'] = "Precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow. Use functions setAmountExVat(), setAmountIncVat() or setVatPercent().";
+ } elseif (isset($row->amountExVat) && (isset($row->vatPercent) == false && isset($row->amountIncVat) == false)) {
+ $errors['missing values'] = "At least one of these values must be set in combination with AmountExVat, in object Svea\WebPay\BuildOrder\RowBuilders\Item:: AmountIncVat or VatPercent for Orderrow. Use functions setAmountIncVat() or setVatPercent().";
+ } elseif (isset($row->amountIncVat) && (isset($row->amountExVat) == false) && isset($row->vatPercent) == false) {
+ $errors['missing values'] = "At least one of the values must be set in combination with AmountIncVat, in object Svea\WebPay\BuildOrder\RowBuilders\Item:: AmountExVat or VatPercent for Orderrow. Use functions setAmountExVat() or setVatPercent().";
+ } elseif (isset($row->vatPercent) && (isset($row->amountExVat) == false && isset($row->amountIncVat) == false)) {
+ $errors['missing values'] = "At least one of the values must be set in combination with VatPercent, in object Svea\WebPay\BuildOrder\RowBuilders\Item:: AmountIncVat or AmountExVat for Orderrow. Use functions setAmountExVat() or setAmountIncVat().";
+ }
+
+ // force correct order type of present attributes, see class OrderRow
+ if (isset($row->vatDiscount) && !(is_int($row->vatDiscount) || is_float($row->vatDiscount)))
+ $errors['incorrect datatype'] = "vatDiscount is not of type int or float.";
+
+ if (isset($row->articleNumber) && !is_string($row->articleNumber))
+ $errors['incorrect datatype'] = 'articleNumber is not of type string.';
+
+ if (isset($row->quantity) && !(is_numeric($row->quantity)))
+ $errors['incorrect datatype'] = "quantity is not numeric.";
+
+ if (isset($row->unit) && !is_string($row->unit))
+ $errors['incorrect datatype'] = 'unit is not of type string.';
+
+ if (isset($row->amountExVat) && !(is_int($row->amountExVat) || is_float($row->amountExVat)))
+ $errors['incorrect datatype'] = 'amountExVat is not of type float or int.';
+
+ if (isset($row->amountIncVat) && !(is_int($row->amountIncVat) || is_float($row->amountIncVat)))
+ $errors['incorrect datatype'] = 'amountIncVat is not of type float or int.';
+
+ if (isset($row->name) && !is_string($row->name))
+ $errors['incorrect datatype'] = 'name is not of type string.';
+
+ if (isset($row->description) && !is_string($row->description))
+ $errors['incorrect datatype'] = 'description is not of type string.';
+
+ if (isset($row->vatPercent) && !(is_int($row->vatPercent) || is_float($row->vatPercent)))
+ $errors['incorrect datatype'] = "vatPercent is not of type int.";
+
+ if (isset($row->discountPercent) && !(is_int($row->discountPercent) || is_float($row->discountPercent)))
+ $errors['incorrect datatype'] = "discountPercent is not of type int.";
+ }
+ }
+
+ return $errors;
+ }
+
+ /**
+ * @param $order
+ * @param $errors
+ * @return mixed
+ *
+ * Validate all rows - products and shipping and discount or voucher rows
+ * Because that we use rows instead of orderRows
+ *
+ */
+ protected function validateCheckoutOrderRows($order, $errors)
+ {
+ /**
+ * * @var \Svea\WebPay\BuildOrder\RowBuilders\OrderRow [] $rows
+ */
+ $orderRows = $order->rows;
+
+ if (count($orderRows) === 0) {
+ $orderRows = $order->orderRows;
+ }
+
+ foreach ($orderRows as $row) {
+ if (empty($row->name)) {
+ $errors['missing values'] = "Name must be set in the Svea\\WebPay\\WebPayItem object. Use functions setName().";
+ }
+ }
+
+ return $errors;
+ }
+
+
+ /**
+ * @param CheckoutOrderBuilder $order
+ * @param array $errors
+ * @return array
+ */
+ protected function validateOrderId(CheckoutOrderBuilder $order, $errors)
{
- if (!is_numeric($order->getId()) || !is_int($order->getId())) {
- $errors['incorrect OrderId'] = "orderId can't be empty and must be int";
- }
+ if (!is_numeric($order->getId()) || !is_int($order->getId())) {
+ $errors['incorrect OrderId'] = "orderId can't be empty and must be int";
+ }
- return $errors;
+ return $errors;
}
- /**
- * @param CheckoutOrderBuilder $request
- * @param array $errors
- * @return array
- */
- protected function validatePresetIsCompanyIsBoolean($request, $errors)
- {
- if (count($request->getPresetValues()) > 0) {
- foreach ($request->getPresetValues() as $presetValue) {
- if(strtolower($presetValue->getTypeName()) == 'iscompany')
- {
- if(!is_bool($presetValue->getValue()))
- {
- $errors['incorrect type'] = "isCompany must be of type boolean";
- }
- }
- }
- }
- return $errors;
- }
-
- /**
- * @param CheckoutOrderBuilder $request
- * @param array $errors
- * @return array
- */
- protected function validatePresetIsCompanyIsSet($request, $errors)
- {
- if(count($request->getPresetValues()) == 0)
- {
- $errors['missing value'] = "isCompany presetValue is not set";
- }
- else
- {
- foreach ($request->getPresetValues() as $presetValue) {
- if (strtolower($presetValue->getTypeName()) == 'iscompany') {
- if ($presetValue->getValue() === null) {
- $errors['missing value'] = "isCompany value is null";
- }
- }
- }
- }
- return $errors;
- }
-
- /**
- * @param CheckoutOrderBuilder $order
- * @param array $errors
- * @return mixed
- */
- public function restrictExVatValue(CheckoutOrderBuilder $order, $errors)
- {
- $exVatValidator = new ExVatRestrictionValidator();
- $errors = $exVatValidator->validate($order, $errors);
-
- return $errors;
- }
+ /**
+ * @param CheckoutOrderBuilder $request
+ * @param array $errors
+ * @return array
+ */
+ protected function validatePresetIsCompanyIsBoolean($request, $errors)
+ {
+ if (count($request->getPresetValues()) > 0) {
+ foreach ($request->getPresetValues() as $presetValue) {
+ if(strtolower($presetValue->getTypeName()) == 'iscompany')
+ {
+ if(!is_bool($presetValue->getValue()))
+ {
+ $errors['incorrect type'] = "isCompany must be of type boolean";
+ }
+ }
+ }
+ }
+ return $errors;
+ }
+
+ /**
+ * @param CheckoutOrderBuilder $request
+ * @param array $errors
+ * @return array
+ */
+ protected function validatePresetIsCompanyIsSet($request, $errors)
+ {
+ if(count($request->getPresetValues()) == 0)
+ {
+ $errors['missing value'] = "isCompany presetValue is not set";
+ }
+ else
+ {
+ foreach ($request->getPresetValues() as $presetValue) {
+ if (strtolower($presetValue->getTypeName()) == 'iscompany') {
+ if ($presetValue->getValue() === null) {
+ $errors['missing value'] = "isCompany value is null";
+ }
+ }
+ }
+ }
+ return $errors;
+ }
+
+ /**
+ * @param CheckoutOrderBuilder $order
+ * @param array $errors
+ * @return mixed
+ */
+ public function restrictExVatValue(CheckoutOrderBuilder $order, $errors)
+ {
+ $exVatValidator = new ExVatRestrictionValidator();
+ $errors = $exVatValidator->validate($order, $errors);
+
+ return $errors;
+ }
}
diff --git a/src/BuildOrder/Validator/ValidationException.php b/src/BuildOrder/Validator/ValidationException.php
index a8cd4a59..9d4e5ed0 100644
--- a/src/BuildOrder/Validator/ValidationException.php
+++ b/src/BuildOrder/Validator/ValidationException.php
@@ -9,5 +9,5 @@
*/
class ValidationException extends Exception
{
- // \Exception referes to class Exception outside our \Svea\ namespace
+ // \Exception referes to class Exception outside our \Svea\ namespace
}
diff --git a/src/BuildOrder/Validator/WebServiceOrderValidator.php b/src/BuildOrder/Validator/WebServiceOrderValidator.php
index b94b8e08..4fe8b7b3 100644
--- a/src/BuildOrder/Validator/WebServiceOrderValidator.php
+++ b/src/BuildOrder/Validator/WebServiceOrderValidator.php
@@ -9,76 +9,76 @@
*/
class WebServiceOrderValidator extends OrderValidator
{
- public $errors = array();
+ public $errors = [];
- protected $isCompany;
+ protected $isCompany;
- /**
- * WebServiceOrderValidator constructor.
- */
- function __construct()
- {
- $this->isCompany = FALSE;
- }
+ /**
+ * WebServiceOrderValidator constructor.
+ */
+ function __construct()
+ {
+ $this->isCompany = FALSE;
+ }
- /**
- * validate($order) ensures that attributes in $order are of the right type
- * and format before creating the xmlMessage or soap calls
- *
- * @param instance of CreateOrderBuilder $order
- * @return array
- */
- public function validate($order)
- {
- if (isset($order->orgNumber) || isset($order->companyVatNumber) || isset($order->companyName)) {
- $this->isCompany = TRUE;
- }
+ /**
+ * validate($order) ensures that attributes in $order are of the right type
+ * and format before creating the xmlMessage or soap calls
+ *
+ * @param instance of CreateOrderBuilder $order
+ * @return array
+ */
+ public function validate($order)
+ {
+ if (isset($order->orgNumber) || isset($order->companyVatNumber) || isset($order->companyName)) {
+ $this->isCompany = TRUE;
+ }
- if (!isset($order->customerIdentity)) {
- $this->errors['missing customerIdentity'] = "customerIdentity is required. Use function addCustomerDetails().";
- }
+ if (!isset($order->customerIdentity)) {
+ $this->errors['missing customerIdentity'] = "customerIdentity is required. Use function addCustomerDetails().";
+ }
- if (isset($order->customerIdentity->orgNumber) ||
- isset($order->customerIdentity->companyVatNumber) ||
- isset($order->customerIdentity->companyName)
- ) {
+ if (isset($order->customerIdentity->orgNumber) ||
+ isset($order->customerIdentity->companyVatNumber) ||
+ isset($order->customerIdentity->companyName)
+ ) {
- $this->isCompany = TRUE;
- }
+ $this->isCompany = TRUE;
+ }
- $identityValidator = new IdentityValidator($this->isCompany);
+ $identityValidator = new IdentityValidator($this->isCompany);
- if ($order->orderType == ConfigurationProvider::PAYMENTPLAN_TYPE && $this->isCompany == TRUE) {
- $this->errors["Wrong customer type"] = "PaymentPlanPayment not allowed for Company customer.";
- }
+ if ($order->orderType == ConfigurationProvider::PAYMENTPLAN_TYPE && $this->isCompany == TRUE) {
+ $this->errors["Wrong customer type"] = "PaymentPlanPayment not allowed for Company customer.";
+ }
- if (isset($order->countryCode)) {
- if ($order->countryCode == "SE"
- || $order->countryCode == "NO"
- || $order->countryCode == "DK"
- || $order->countryCode == "FI"
- ) {
- $this->errors = $identityValidator->validateNordicIdentity($order, $this->errors);
- } elseif ($order->countryCode == "NL") {
- $this->errors = $identityValidator->validateNLidentity($order, $this->errors);
- } elseif ($order->countryCode == "DE") {
- $this->errors = $identityValidator->validateDEidentity($order, $this->errors);
- } else {
- $this->errors['not valid'] = "Given countrycode does not exist in our system.";
- }
- } else {
- $this->errors['missing value'] = "CountryCode is required. Use function setCountryCode().";
- }
+ if (isset($order->countryCode)) {
+ if ($order->countryCode == "SE"
+ || $order->countryCode == "NO"
+ || $order->countryCode == "DK"
+ || $order->countryCode == "FI"
+ ) {
+ $this->errors = $identityValidator->validateNordicIdentity($order, $this->errors);
+ } elseif ($order->countryCode == "NL") {
+ $this->errors = $identityValidator->validateNLidentity($order, $this->errors);
+ } elseif ($order->countryCode == "DE") {
+ $this->errors = $identityValidator->validateDEidentity($order, $this->errors);
+ } else {
+ $this->errors['not valid'] = "Given countrycode does not exist in our system.";
+ }
+ } else {
+ $this->errors['missing value'] = "CountryCode is required. Use function setCountryCode().";
+ }
- $this->errors = $identityValidator->validateDoubleIdentity($order, $this->errors);
- $this->errors = $this->validatePeppolId($order, $this->errors);
- $this->errors = $this->validateRequiredFieldsForOrder($order, $this->errors);
- $this->errors = $this->validateOrderRows($order, $this->errors);
+ $this->errors = $identityValidator->validateDoubleIdentity($order, $this->errors);
+ $this->errors = $this->validatePeppolId($order, $this->errors);
+ $this->errors = $this->validateRequiredFieldsForOrder($order, $this->errors);
+ $this->errors = $this->validateOrderRows($order, $this->errors);
- if (isset($order->orderDate) == false) {
- $this->errors["missing value"] = "OrderDate is Required. Use function setOrderDate().";
- }
+ if (isset($order->orderDate) == false) {
+ $this->errors["missing value"] = "OrderDate is Required. Use function setOrderDate().";
+ }
- return $this->errors;
- }
+ return $this->errors;
+ }
}
diff --git a/src/Checkout/CheckoutOrderEntry.php b/src/Checkout/CheckoutOrderEntry.php
index 3047d7fe..9cee2989 100644
--- a/src/Checkout/CheckoutOrderEntry.php
+++ b/src/Checkout/CheckoutOrderEntry.php
@@ -12,305 +12,305 @@
*/
class CheckoutOrderEntry
{
- /**
- * @var CheckoutOrderBuilder
- */
- private $checkoutOrderBuilder;
-
- /**
- * CheckoutOrderEntry constructor.
- * @param $checkoutOrderBuilder
- */
- public function __construct($checkoutOrderBuilder)
- {
- $this->checkoutOrderBuilder = $checkoutOrderBuilder;
- }
-
- /**
- * Calls logic that initialize creating a Checkout Order
- * and returns response from server
- *
- * @return array
- */
- public function createOrder()
- {
- $createService = $this->checkoutOrderBuilder->createOrder();
-
- return $createService;
- }
-
- /**
- * Calls logic that initialize getting a Checkout Order
- * and returns response from server
- *
- * @return array
- */
- public function getOrder()
- {
- $getOrderService = $this->checkoutOrderBuilder->getOrder();
-
- return $getOrderService;
- }
-
- /**
- * Calls logic that initialize updating a Checkout Order
- * and returns response from server
- *
- * @return array
- */
- public function updateOrder()
- {
- $updateOrderService = $this->checkoutOrderBuilder->updateOrder();
-
- return $updateOrderService;
- }
-
- /**
- * Returns all campaigns that is available on the merchant
- *
- * @return array
- */
- public function getAvailablePartPaymentCampaigns()
- {
- $getAvailablePartPaymentCampaigns = $this->checkoutOrderBuilder->getAvailablePartPaymentCampaigns();
-
- return $getAvailablePartPaymentCampaigns;
- }
-
- /**
- * @param string $checkoutUri
- * @return $this
- */
- public function setCheckoutUri($checkoutUri)
- {
- $this->checkoutOrderBuilder->setCheckoutUri($checkoutUri);
-
- return $this;
- }
-
- /**
- * @param string $confirmationUri
- * @return $this
- */
- public function setConfirmationUri($confirmationUri)
- {
- $this->checkoutOrderBuilder->setConfirmationUri($confirmationUri);
-
- return $this;
- }
-
- /**
- * @param string $pushUri
- * @return $this
- */
- public function setPushUri($pushUri)
- {
- $this->checkoutOrderBuilder->setPushUri($pushUri);
-
- return $this;
- }
-
- /**
- * @param string $termsUri
- * @return $this
- */
- public function setTermsUri($termsUri)
- {
- $this->checkoutOrderBuilder->setTermsUri($termsUri);
-
- return $this;
- }
-
- /**
- * @param string $locale
- * @return $this
- */
- public function setLocale($locale)
- {
- $this->checkoutOrderBuilder->setLocale($locale);
-
- return $this;
- }
-
- /**
- * @param string $validationCallbackUri
- * @return $this
- */
- public function setValidationCallbackUri($validationCallbackUri)
- {
- $this->checkoutOrderBuilder->setValidationCallbackUri($validationCallbackUri);
-
- return $this;
- }
-
- /**
- * Required for get and update methods
- * @param $id
- * @return $this
- */
- public function setCheckoutOrderId($id)
- {
- $this->checkoutOrderBuilder->setId($id);
-
- return $this;
- }
-
- /**
- * @param string $clientOrderNumber
- * @return $this
- */
- public function setClientOrderNumber($clientOrderNumber)
- {
- $this->checkoutOrderBuilder->setClientOrderNumber($clientOrderNumber);
-
- return $this;
- }
-
- /**
- * Add Preset Value to the list of Preset Values
- *
- * @param PresetValue $presetValues
- * @return $this
- */
- public function addPresetValue($presetValues)
- {
- $this->checkoutOrderBuilder->addPresetValue($presetValues);
-
- return $this;
- }
-
- /**
- * Sets a partnerKey that's provided by Svea
- *
- * @param string $partnerKey
- * @return $this
- */
- public function setPartnerKey($partnerKey)
- {
- $this->checkoutOrderBuilder->setPartnerKey($partnerKey);
-
- return $this;
- }
-
- /**
- * Required - set order country code, we recommend basing this on the customer billing address
- *
- * For orders using the invoice or payment plan payment methods, you need to supply a country code that corresponds
- * to the account credentials used for the address lookup. (Note that this means that these methods don't support
- * orders from foreign countries, this is a consequence of the fact that the invoice and payment plan payment
- * methods don't support foreign orders.)
- *
- * @param string $countryCode
- * @return $this
- */
- public function setCountryCode($countryCode)
- {
- $this->checkoutOrderBuilder->setCountryCode($countryCode);
-
- return $this;
- }
-
- /**
- * Required - you need to add at least one order row to the order
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\OrderRow $orderRowItem
- * @return $this
- */
- public function addOrderRow($orderRowItem)
- {
- $this->checkoutOrderBuilder->addOrderRow($orderRowItem);
-
- return $this;
- }
-
- /**
- * Optional - adds a shipping fee or invoice fee to the order
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee|\Svea\WebPay\BuildOrder\RowBuilders\ShippingFee $itemFeeObject
- * @return $this
- */
- public function addFee($itemFeeObject)
- {
- $this->checkoutOrderBuilder->addFee($itemFeeObject);
-
- return $this;
- }
-
- /**
- * Optional - adds a fixed amount discount or an order total percent discount to the order
- *
- * See the discount objects for information on how the discount is calculated et al.
- *
- * @see \Svea\FixedDiscount \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount
- * @see \Svea\RelativeDiscount \Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount
- *
- * @param \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount|\Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount $itemDiscountObject
- * @return $this
- */
- public function addDiscount($itemDiscountObject)
- {
- $this->checkoutOrderBuilder->addDiscount($itemDiscountObject);
-
- return $this;
- }
-
- /**
- * Required for card payment, direct bank & PayPage payments. Ignored for invoice and payment plan.
- *
- * Ignored for invoice and payment plan orders, which use the selected client id currency, as determined by Svea\WebPay\Config\ConfigurationProvider and setCountryCode.
- *
- * @param string $currencyString in ISO 4217 three-letter format, ex. "SEK", "EUR"
- * @return $this
- */
- public function setCurrency($currencyString)
- {
- $this->checkoutOrderBuilder->setCurrency($currencyString);
-
- return $this;
- }
-
- /**
- * @return CheckoutOrderBuilder
- */
- public function getCheckoutOrderBuilder()
- {
- return $this->checkoutOrderBuilder;
- }
-
- /**
- * Add IdentityFlag to the list of IdentityFlag
- *
- * @param string $identityFlag
- * @return $this
- */
- public function addIdentityFlag($identityFlag)
- {
- $this->checkoutOrderBuilder->addIdentityFlag($identityFlag);
-
- return $this;
- }
-
- /**
- * Set merchantData on order
- *
- * @param string $merchantData
- * @return $this
- */
- public function setMerchantData($merchantData)
- {
- $this->checkoutOrderBuilder->setMerchantData($merchantData);
- return $this;
- }
-
- /**
- * Enable/disable electronic id authentication when end-customer finalizes order, default = false
- *
- * @param bool $enabled
- * @return $this
- */
- public function setRequireElectronicIdAuthentication($enabled)
- {
- $this->checkoutOrderBuilder->setRequireElectronicIdAuthentication($enabled);
- return $this;
- }
+ /**
+ * @var CheckoutOrderBuilder
+ */
+ private $checkoutOrderBuilder;
+
+ /**
+ * CheckoutOrderEntry constructor.
+ * @param $checkoutOrderBuilder
+ */
+ public function __construct($checkoutOrderBuilder)
+ {
+ $this->checkoutOrderBuilder = $checkoutOrderBuilder;
+ }
+
+ /**
+ * Calls logic that initialize creating a Checkout Order
+ * and returns response from server
+ *
+ * @return array
+ */
+ public function createOrder()
+ {
+ $createService = $this->checkoutOrderBuilder->createOrder();
+
+ return $createService;
+ }
+
+ /**
+ * Calls logic that initialize getting a Checkout Order
+ * and returns response from server
+ *
+ * @return array
+ */
+ public function getOrder()
+ {
+ $getOrderService = $this->checkoutOrderBuilder->getOrder();
+
+ return $getOrderService;
+ }
+
+ /**
+ * Calls logic that initialize updating a Checkout Order
+ * and returns response from server
+ *
+ * @return array
+ */
+ public function updateOrder()
+ {
+ $updateOrderService = $this->checkoutOrderBuilder->updateOrder();
+
+ return $updateOrderService;
+ }
+
+ /**
+ * Returns all campaigns that is available on the merchant
+ *
+ * @return array
+ */
+ public function getAvailablePartPaymentCampaigns()
+ {
+ $getAvailablePartPaymentCampaigns = $this->checkoutOrderBuilder->getAvailablePartPaymentCampaigns();
+
+ return $getAvailablePartPaymentCampaigns;
+ }
+
+ /**
+ * @param string $checkoutUri
+ * @return $this
+ */
+ public function setCheckoutUri($checkoutUri)
+ {
+ $this->checkoutOrderBuilder->setCheckoutUri($checkoutUri);
+
+ return $this;
+ }
+
+ /**
+ * @param string $confirmationUri
+ * @return $this
+ */
+ public function setConfirmationUri($confirmationUri)
+ {
+ $this->checkoutOrderBuilder->setConfirmationUri($confirmationUri);
+
+ return $this;
+ }
+
+ /**
+ * @param string $pushUri
+ * @return $this
+ */
+ public function setPushUri($pushUri)
+ {
+ $this->checkoutOrderBuilder->setPushUri($pushUri);
+
+ return $this;
+ }
+
+ /**
+ * @param string $termsUri
+ * @return $this
+ */
+ public function setTermsUri($termsUri)
+ {
+ $this->checkoutOrderBuilder->setTermsUri($termsUri);
+
+ return $this;
+ }
+
+ /**
+ * @param string $locale
+ * @return $this
+ */
+ public function setLocale($locale)
+ {
+ $this->checkoutOrderBuilder->setLocale($locale);
+
+ return $this;
+ }
+
+ /**
+ * @param string $validationCallbackUri
+ * @return $this
+ */
+ public function setValidationCallbackUri($validationCallbackUri)
+ {
+ $this->checkoutOrderBuilder->setValidationCallbackUri($validationCallbackUri);
+
+ return $this;
+ }
+
+ /**
+ * Required for get and update methods
+ * @param $id
+ * @return $this
+ */
+ public function setCheckoutOrderId($id)
+ {
+ $this->checkoutOrderBuilder->setId($id);
+
+ return $this;
+ }
+
+ /**
+ * @param string $clientOrderNumber
+ * @return $this
+ */
+ public function setClientOrderNumber($clientOrderNumber)
+ {
+ $this->checkoutOrderBuilder->setClientOrderNumber($clientOrderNumber);
+
+ return $this;
+ }
+
+ /**
+ * Add Preset Value to the list of Preset Values
+ *
+ * @param PresetValue $presetValues
+ * @return $this
+ */
+ public function addPresetValue($presetValues)
+ {
+ $this->checkoutOrderBuilder->addPresetValue($presetValues);
+
+ return $this;
+ }
+
+ /**
+ * Sets a partnerKey that's provided by Svea
+ *
+ * @param string $partnerKey
+ * @return $this
+ */
+ public function setPartnerKey($partnerKey)
+ {
+ $this->checkoutOrderBuilder->setPartnerKey($partnerKey);
+
+ return $this;
+ }
+
+ /**
+ * Required - set order country code, we recommend basing this on the customer billing address
+ *
+ * For orders using the invoice or payment plan payment methods, you need to supply a country code that corresponds
+ * to the account credentials used for the address lookup. (Note that this means that these methods don't support
+ * orders from foreign countries, this is a consequence of the fact that the invoice and payment plan payment
+ * methods don't support foreign orders.)
+ *
+ * @param string $countryCode
+ * @return $this
+ */
+ public function setCountryCode($countryCode)
+ {
+ $this->checkoutOrderBuilder->setCountryCode($countryCode);
+
+ return $this;
+ }
+
+ /**
+ * Required - you need to add at least one order row to the order
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\OrderRow $orderRowItem
+ * @return $this
+ */
+ public function addOrderRow($orderRowItem)
+ {
+ $this->checkoutOrderBuilder->addOrderRow($orderRowItem);
+
+ return $this;
+ }
+
+ /**
+ * Optional - adds a shipping fee or invoice fee to the order
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee|\Svea\WebPay\BuildOrder\RowBuilders\ShippingFee $itemFeeObject
+ * @return $this
+ */
+ public function addFee($itemFeeObject)
+ {
+ $this->checkoutOrderBuilder->addFee($itemFeeObject);
+
+ return $this;
+ }
+
+ /**
+ * Optional - adds a fixed amount discount or an order total percent discount to the order
+ *
+ * See the discount objects for information on how the discount is calculated et al.
+ *
+ * @see \Svea\FixedDiscount \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount
+ * @see \Svea\RelativeDiscount \Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount
+ *
+ * @param \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount|\Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount $itemDiscountObject
+ * @return $this
+ */
+ public function addDiscount($itemDiscountObject)
+ {
+ $this->checkoutOrderBuilder->addDiscount($itemDiscountObject);
+
+ return $this;
+ }
+
+ /**
+ * Required for card payment, direct bank & PayPage payments. Ignored for invoice and payment plan.
+ *
+ * Ignored for invoice and payment plan orders, which use the selected client id currency, as determined by Svea\WebPay\Config\ConfigurationProvider and setCountryCode.
+ *
+ * @param string $currencyString in ISO 4217 three-letter format, ex. "SEK", "EUR"
+ * @return $this
+ */
+ public function setCurrency($currencyString)
+ {
+ $this->checkoutOrderBuilder->setCurrency($currencyString);
+
+ return $this;
+ }
+
+ /**
+ * @return CheckoutOrderBuilder
+ */
+ public function getCheckoutOrderBuilder()
+ {
+ return $this->checkoutOrderBuilder;
+ }
+
+ /**
+ * Add IdentityFlag to the list of IdentityFlag
+ *
+ * @param string $identityFlag
+ * @return $this
+ */
+ public function addIdentityFlag($identityFlag)
+ {
+ $this->checkoutOrderBuilder->addIdentityFlag($identityFlag);
+
+ return $this;
+ }
+
+ /**
+ * Set merchantData on order
+ *
+ * @param string $merchantData
+ * @return $this
+ */
+ public function setMerchantData($merchantData)
+ {
+ $this->checkoutOrderBuilder->setMerchantData($merchantData);
+ return $this;
+ }
+
+ /**
+ * Enable/disable electronic id authentication when end-customer finalizes order, default = false
+ *
+ * @param bool $enabled
+ * @return $this
+ */
+ public function setRequireElectronicIdAuthentication($enabled)
+ {
+ $this->checkoutOrderBuilder->setRequireElectronicIdAuthentication($enabled);
+ return $this;
+ }
}
diff --git a/src/Checkout/Helper/CheckoutOrderBuilder.php b/src/Checkout/Helper/CheckoutOrderBuilder.php
index 8e63acbd..18c2efe4 100644
--- a/src/Checkout/Helper/CheckoutOrderBuilder.php
+++ b/src/Checkout/Helper/CheckoutOrderBuilder.php
@@ -20,355 +20,355 @@
*/
class CheckoutOrderBuilder extends OrderBuilder
{
- /**
- * @var float $id
- */
- protected $id;
-
- /**
- * @var MerchantSettings $merchantSettings
- */
- protected $merchantSettings;
-
- /**
- * @var string $locale
- */
- protected $locale;
-
- /**
- * @var PresetValue []
- */
- protected $presetValues = array();
-
- /**
- * @var string $partnerKey
- */
- protected $partnerKey;
-
- /**
- * @var IdentityFlags []
- */
- protected $identityFlags = array();
-
- /**
- * @var string $merchantData
- */
- protected $merchantData;
-
- /**
- * @var bool $requireElectronicIdAuthentication
- */
- protected $requireElectronicIdAuthentication;
-
- /**
- * CheckoutOrderBuilder constructor.
- * @param \Svea\WebPay\Config\ConfigurationProvider $config
- */
- public function __construct($config)
- {
- parent::__construct($config);
-
- $this->merchantSettings = new MerchantSettings();
- }
-
- /**
- * Calls logic that initialize creating a Checkout Order
- * and returns response from server
- *
- * @return array
- */
- public function createOrder()
- {
- $createService = new CreateOrderService($this);
-
- return $createService->doRequest();
- }
-
- /**
- * Calls logic that initialize getting a Checkout Order
- * and returns response from server
- *
- * @return array
- */
- public function getOrder()
- {
- $getOrderService = new GetOrderService($this);
-
- return $getOrderService->doRequest();
- }
-
- /**
- * Calls logic that initialize updating a Checkout Order
- * and returns response from server
- *
- * @return array
- */
- public function updateOrder()
- {
- $updateOrderService = new UpdateOrderService($this);
-
- return $updateOrderService->doRequest();
- }
-
- /**
- * Returns all campaigns that is available on the merchant
- *
- * @return array
- */
- public function getAvailablePartPaymentCampaigns()
- {
- $getAvailablePartPaymentCampaigns = new GetAvailablePartPaymentCampaignsService($this);
-
- return $getAvailablePartPaymentCampaigns->doRequest();
- }
-
- /**
- * Set Merchant Settings for an Checkout Order
- *
- * @param $merchantSettings
- * @return $this
- */
- public function setMerchantSettings($merchantSettings)
- {
- $this->merchantSettings = $merchantSettings;
-
- return $this;
- }
-
- /**
- * @return MerchantSettings
- */
- public function getMerchantSettings()
- {
- return $this->merchantSettings;
- }
-
- /**
- * @param string $checkoutUri
- * @return $this
- */
- public function setCheckoutUri($checkoutUri)
- {
- $this->merchantSettings->setCheckoutUri($checkoutUri);
-
- return $this;
- }
-
- /**
- * @param string $confirmationUri
- * @return $this
- */
- public function setConfirmationUri($confirmationUri)
- {
- $this->merchantSettings->setConfirmationUri($confirmationUri);
-
- return $this;
- }
-
- /**
- * @param string $pushUri
- * @return $this
- */
- public function setPushUri($pushUri)
- {
- $this->merchantSettings->setPushUri($pushUri);
-
- return $this;
- }
-
- /**
- * @param string $termsUri
- * @return $this
- */
- public function setTermsUri($termsUri)
- {
- $this->merchantSettings->setTermsUri($termsUri);
-
- return $this;
- }
-
- /**
- * @param string $validationCallbackUri
- * @return $this
- */
- public function setValidationCallbackUri($validationCallbackUri)
- {
- $this->merchantSettings->setValidationCallbackUri($validationCallbackUri);
- return $this;
- }
-
- /**
- * @return string
- */
- public function getLocale()
- {
- return $this->locale;
- }
-
- /**
- * @param string $locale
- * @return $this
- */
- public function setLocale($locale)
- {
- $this->locale = $locale;
-
- return $this;
- }
-
- /**
- * @return float
- */
- public function getId()
- {
- return $this->id;
- }
-
- /**
- * @param $id
- * @return $this
- */
- public function setId($id)
- {
- $this->id = $id;
-
- return $this;
- }
-
- /**
- * Return country code
- * If country code is not defined, default value "SE" will be returned
- *
- * @return string
- */
- public function getCountryCode()
- {
- $countryCode = $this->countryCode != null ? $this->countryCode : "SE";
-
- return $countryCode;
- }
-
- /**
- * @return string
- */
- public function getCurrency()
- {
- return $this->currency;
- }
-
- /**
- * @param string $clientOrderNumber
- * @return CheckoutOrderBuilder
- */
- public function setClientOrderNumber($clientOrderNumber)
- {
- $this->clientOrderNumber = $clientOrderNumber;
-
- return $this;
- }
-
- /**
- * @return string
- */
- public function getClientOrderNumber()
- {
- return $this->clientOrderNumber;
- }
-
- /**
- * Return a list of Preset Values
- *
- * @return PresetValue []
- */
- public function getPresetValues()
- {
- return $this->presetValues;
- }
-
- /**
- * Add Preset Value to the list of Preset Values
- *
- * @param PresetValue $presetValues
- * @return $this
- */
- public function addPresetValue($presetValues)
- {
- $this->presetValues [] = $presetValues;
-
- return $this;
- }
-
- /**
- * Sets a partnerKey which is provided by Svea.
- * Optional to use
- * @param string $partnerKey
- * @return $this
- */
- public function setPartnerKey($partnerKey)
- {
- $this->partnerKey = $partnerKey;
-
- return $this;
- }
-
- /**
- * Returns a partnerKey
- * @return string
- */
- public function getPartnerKey()
- {
- return $this->partnerKey;
- }
-
- /**
- * Return a list of IdentityFlags
- *
- * @return IdentityFlags []
- */
- public function getIdentityFlags()
- {
- return $this->identityFlags;
- }
-
- /**
- * Add IdentityFlag to the list of IdentityFlags
- *
- * @param string $identityFlag
- * @return $this
- */
- public function addIdentityFlag($identityFlag)
- {
- $this->identityFlags [] = $identityFlag;
-
- return $this;
- }
-
- public function setMerchantData($merchantData)
- {
- $this->merchantData = $merchantData;
- return $this;
- }
-
- public function getMerchantData()
- {
- return $this->merchantData;
- }
-
- /**
- * Enable electronic id authentication for end-user if set to true
- *
- * @param bool $enabled
- * @return $this
- */
- public function setRequireElectronicIdAuthentication($enabled)
- {
- $this->requireElectronicIdAuthentication = $enabled;
- return $this;
- }
-
- public function getRequireElectronicIdAuthentication()
- {
- return $this->requireElectronicIdAuthentication;
- }
+ /**
+ * @var float $id
+ */
+ protected $id;
+
+ /**
+ * @var MerchantSettings $merchantSettings
+ */
+ protected $merchantSettings;
+
+ /**
+ * @var string $locale
+ */
+ protected $locale;
+
+ /**
+ * @var PresetValue []
+ */
+ protected $presetValues = [];
+
+ /**
+ * @var string $partnerKey
+ */
+ protected $partnerKey;
+
+ /**
+ * @var IdentityFlags []
+ */
+ protected $identityFlags = [];
+
+ /**
+ * @var string $merchantData
+ */
+ protected $merchantData;
+
+ /**
+ * @var bool $requireElectronicIdAuthentication
+ */
+ protected $requireElectronicIdAuthentication;
+
+ /**
+ * CheckoutOrderBuilder constructor.
+ * @param \Svea\WebPay\Config\ConfigurationProvider $config
+ */
+ public function __construct($config)
+ {
+ parent::__construct($config);
+
+ $this->merchantSettings = new MerchantSettings();
+ }
+
+ /**
+ * Calls logic that initialize creating a Checkout Order
+ * and returns response from server
+ *
+ * @return array
+ */
+ public function createOrder()
+ {
+ $createService = new CreateOrderService($this);
+
+ return $createService->doRequest();
+ }
+
+ /**
+ * Calls logic that initialize getting a Checkout Order
+ * and returns response from server
+ *
+ * @return array
+ */
+ public function getOrder()
+ {
+ $getOrderService = new GetOrderService($this);
+
+ return $getOrderService->doRequest();
+ }
+
+ /**
+ * Calls logic that initialize updating a Checkout Order
+ * and returns response from server
+ *
+ * @return array
+ */
+ public function updateOrder()
+ {
+ $updateOrderService = new UpdateOrderService($this);
+
+ return $updateOrderService->doRequest();
+ }
+
+ /**
+ * Returns all campaigns that is available on the merchant
+ *
+ * @return array
+ */
+ public function getAvailablePartPaymentCampaigns()
+ {
+ $getAvailablePartPaymentCampaigns = new GetAvailablePartPaymentCampaignsService($this);
+
+ return $getAvailablePartPaymentCampaigns->doRequest();
+ }
+
+ /**
+ * Set Merchant Settings for an Checkout Order
+ *
+ * @param $merchantSettings
+ * @return $this
+ */
+ public function setMerchantSettings($merchantSettings)
+ {
+ $this->merchantSettings = $merchantSettings;
+
+ return $this;
+ }
+
+ /**
+ * @return MerchantSettings
+ */
+ public function getMerchantSettings()
+ {
+ return $this->merchantSettings;
+ }
+
+ /**
+ * @param string $checkoutUri
+ * @return $this
+ */
+ public function setCheckoutUri($checkoutUri)
+ {
+ $this->merchantSettings->setCheckoutUri($checkoutUri);
+
+ return $this;
+ }
+
+ /**
+ * @param string $confirmationUri
+ * @return $this
+ */
+ public function setConfirmationUri($confirmationUri)
+ {
+ $this->merchantSettings->setConfirmationUri($confirmationUri);
+
+ return $this;
+ }
+
+ /**
+ * @param string $pushUri
+ * @return $this
+ */
+ public function setPushUri($pushUri)
+ {
+ $this->merchantSettings->setPushUri($pushUri);
+
+ return $this;
+ }
+
+ /**
+ * @param string $termsUri
+ * @return $this
+ */
+ public function setTermsUri($termsUri)
+ {
+ $this->merchantSettings->setTermsUri($termsUri);
+
+ return $this;
+ }
+
+ /**
+ * @param string $validationCallbackUri
+ * @return $this
+ */
+ public function setValidationCallbackUri($validationCallbackUri)
+ {
+ $this->merchantSettings->setValidationCallbackUri($validationCallbackUri);
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getLocale()
+ {
+ return $this->locale;
+ }
+
+ /**
+ * @param string $locale
+ * @return $this
+ */
+ public function setLocale($locale)
+ {
+ $this->locale = $locale;
+
+ return $this;
+ }
+
+ /**
+ * @return float
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * @param $id
+ * @return $this
+ */
+ public function setId($id)
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+
+ /**
+ * Return country code
+ * If country code is not defined, default value "SE" will be returned
+ *
+ * @return string
+ */
+ public function getCountryCode()
+ {
+ $countryCode = $this->countryCode != null ? $this->countryCode : "SE";
+
+ return $countryCode;
+ }
+
+ /**
+ * @return string
+ */
+ public function getCurrency()
+ {
+ return $this->currency;
+ }
+
+ /**
+ * @param string $clientOrderNumber
+ * @return CheckoutOrderBuilder
+ */
+ public function setClientOrderNumber($clientOrderNumber)
+ {
+ $this->clientOrderNumber = $clientOrderNumber;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getClientOrderNumber()
+ {
+ return $this->clientOrderNumber;
+ }
+
+ /**
+ * Return a list of Preset Values
+ *
+ * @return PresetValue []
+ */
+ public function getPresetValues()
+ {
+ return $this->presetValues;
+ }
+
+ /**
+ * Add Preset Value to the list of Preset Values
+ *
+ * @param PresetValue $presetValues
+ * @return $this
+ */
+ public function addPresetValue($presetValues)
+ {
+ $this->presetValues [] = $presetValues;
+
+ return $this;
+ }
+
+ /**
+ * Sets a partnerKey which is provided by Svea.
+ * Optional to use
+ * @param string $partnerKey
+ * @return $this
+ */
+ public function setPartnerKey($partnerKey)
+ {
+ $this->partnerKey = $partnerKey;
+
+ return $this;
+ }
+
+ /**
+ * Returns a partnerKey
+ * @return string
+ */
+ public function getPartnerKey()
+ {
+ return $this->partnerKey;
+ }
+
+ /**
+ * Return a list of IdentityFlags
+ *
+ * @return IdentityFlags []
+ */
+ public function getIdentityFlags()
+ {
+ return $this->identityFlags;
+ }
+
+ /**
+ * Add IdentityFlag to the list of IdentityFlags
+ *
+ * @param string $identityFlag
+ * @return $this
+ */
+ public function addIdentityFlag($identityFlag)
+ {
+ $this->identityFlags [] = $identityFlag;
+
+ return $this;
+ }
+
+ public function setMerchantData($merchantData)
+ {
+ $this->merchantData = $merchantData;
+ return $this;
+ }
+
+ public function getMerchantData()
+ {
+ return $this->merchantData;
+ }
+
+ /**
+ * Enable electronic id authentication for end-user if set to true
+ *
+ * @param bool $enabled
+ * @return $this
+ */
+ public function setRequireElectronicIdAuthentication($enabled)
+ {
+ $this->requireElectronicIdAuthentication = $enabled;
+ return $this;
+ }
+
+ public function getRequireElectronicIdAuthentication()
+ {
+ return $this->requireElectronicIdAuthentication;
+ }
}
diff --git a/src/Checkout/Helper/CheckoutRowFormatter.php b/src/Checkout/Helper/CheckoutRowFormatter.php
index a6f2f47a..8c34419d 100644
--- a/src/Checkout/Helper/CheckoutRowFormatter.php
+++ b/src/Checkout/Helper/CheckoutRowFormatter.php
@@ -15,113 +15,113 @@
*/
class CheckoutRowFormatter extends WebServiceRowFormatter
{
- /**
- * Go through list of passed Order Rows and
- * call appropriate format methods.
- *
- * @return array
- */
- public function formatRows()
- {
- $this->newRows = array();
-
- $this->calculateTotals();
-
- if ($this->resendOrderVat === null) {
- $this->determineVatFlag();
- } else {
- $this->priceIncludingVat = $this->resendOrderVat ? false : true;
- }
-
- foreach ($this->order->rows as $row) {
- switch (get_class($row)) {
- case 'Svea\WebPay\BuildOrder\RowBuilders\OrderRow':
- $this->formatOrderRows($row);
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\ShippingFee':
- $this->formatShippingFeeRows($row);
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee':
- $this->formatInvoiceFeeRows($row);
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount':
- $this->formatFixedDiscountRows($row);
- break;
- default:
- $this->handleOtherOrderRow($row);
- break;
- }
- }
-
- foreach ($this->newRows as $row) {
- $this->formatValues($row);
- }
-
- return $this->newRows;
- }
-
- /**
- * Format OrderRow
- * @param $row
- */
- protected function formatOrderRows($row)
- {
- $tempRow = new SveaOrderRow(); // new empty object
-
- if (isset($row->name)) {
- $tempRow->Name = $row->name;
- }
-
- if (isset($row->articleNumber)) {
- $tempRow->ArticleNumber = $row->articleNumber;
- }
-
- if (isset($row->quantity)) {
- $tempRow->NumberOfUnits = $row->quantity;
- }
-
- if (isset($row->amountIncVat)) {
- $tempRow->PricePerUnit = $row->amountIncVat;
- }
-
- if (isset($row->discountPercent)) {
- $tempRow->DiscountPercent = $row->discountPercent;
- }
-
- if (isset($row->vatPercent)) {
- $tempRow->VatPercent = $row->vatPercent;
- }
-
- if (isset($row->unit)) {
- $tempRow->Unit = $row->unit;
- }
-
- if (isset($row->temporaryReference)) {
- $tempRow->TemporaryReference = $row->temporaryReference;
- }
-
- $this->newRows[] = $tempRow;
- }
-
- private function formatValues($row)
- {
- if (isset($row->PricePerUnit)) {
- $row->PricePerUnit = Helper::bround($row->PricePerUnit, 2) * 100;
- }
-
- // @todo - check if this should be from 1-100 or like minor currency
- if (isset($row->DiscountPercent)) {
- $row->DiscountPercent = Helper::bround($row->DiscountPercent, 2) * 100;
- }
-
- if (isset($row->VatPercent)) {
- $row->VatPercent = Helper::bround($row->VatPercent, 2) * 100;
- }
- }
-
- private function handleOtherOrderRow($row)
- {
- $type = get_class($row);
- throw new \Exception("This functionality currently does not support this Order type ($type)");
- }
+ /**
+ * Go through list of passed Order Rows and
+ * call appropriate format methods.
+ *
+ * @return array
+ */
+ public function formatRows()
+ {
+ $this->newRows = [];
+
+ $this->calculateTotals();
+
+ if ($this->resendOrderVat === null) {
+ $this->determineVatFlag();
+ } else {
+ $this->priceIncludingVat = $this->resendOrderVat ? false : true;
+ }
+
+ foreach ($this->order->rows as $row) {
+ switch (get_class($row)) {
+ case 'Svea\WebPay\BuildOrder\RowBuilders\OrderRow':
+ $this->formatOrderRows($row);
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\ShippingFee':
+ $this->formatShippingFeeRows($row);
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee':
+ $this->formatInvoiceFeeRows($row);
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount':
+ $this->formatFixedDiscountRows($row);
+ break;
+ default:
+ $this->handleOtherOrderRow($row);
+ break;
+ }
+ }
+
+ foreach ($this->newRows as $row) {
+ $this->formatValues($row);
+ }
+
+ return $this->newRows;
+ }
+
+ /**
+ * Format OrderRow
+ * @param $row
+ */
+ protected function formatOrderRows($row)
+ {
+ $tempRow = new SveaOrderRow(); // new empty object
+
+ if (isset($row->name)) {
+ $tempRow->Name = $row->name;
+ }
+
+ if (isset($row->articleNumber)) {
+ $tempRow->ArticleNumber = $row->articleNumber;
+ }
+
+ if (isset($row->quantity)) {
+ $tempRow->NumberOfUnits = $row->quantity;
+ }
+
+ if (isset($row->amountIncVat)) {
+ $tempRow->PricePerUnit = $row->amountIncVat;
+ }
+
+ if (isset($row->discountPercent)) {
+ $tempRow->DiscountPercent = $row->discountPercent;
+ }
+
+ if (isset($row->vatPercent)) {
+ $tempRow->VatPercent = $row->vatPercent;
+ }
+
+ if (isset($row->unit)) {
+ $tempRow->Unit = $row->unit;
+ }
+
+ if (isset($row->temporaryReference)) {
+ $tempRow->TemporaryReference = $row->temporaryReference;
+ }
+
+ $this->newRows[] = $tempRow;
+ }
+
+ private function formatValues($row)
+ {
+ if (isset($row->PricePerUnit)) {
+ $row->PricePerUnit = Helper::bround($row->PricePerUnit, 2) * 100;
+ }
+
+ // @todo - check if this should be from 1-100 or like minor currency
+ if (isset($row->DiscountPercent)) {
+ $row->DiscountPercent = Helper::bround($row->DiscountPercent, 2) * 100;
+ }
+
+ if (isset($row->VatPercent)) {
+ $row->VatPercent = Helper::bround($row->VatPercent, 2) * 100;
+ }
+ }
+
+ private function handleOtherOrderRow($row)
+ {
+ $type = get_class($row);
+ throw new \Exception("This functionality currently does not support this Order type ($type)");
+ }
}
diff --git a/src/Checkout/Model/CheckoutOrderRow.php b/src/Checkout/Model/CheckoutOrderRow.php
index 10d351f5..e4b4111a 100644
--- a/src/Checkout/Model/CheckoutOrderRow.php
+++ b/src/Checkout/Model/CheckoutOrderRow.php
@@ -12,223 +12,223 @@
*/
class CheckoutOrderRow
{
- /**
- * @var string $articleNumber
- */
- private $articleNumber;
-
- /**
- * @var string $name
- */
- private $name;
-
- /**
- * @var integer $quantity
- */
- private $quantity;
-
- /**
- * @var integer $unitPrice
- */
- private $unitPrice;
-
- /**
- * @var integer $discountPercent
- */
- private $discountPercent;
-
- /**
- * @var integer $vatPercent
- */
- private $vatPercent;
-
- /**
- * @var string $unit
- */
- private $unit;
-
- /**
- * @var $temporaryReference
- */
- private $temporaryReference;
-
- /**
- * @var $merchantData
- */
- private $merchantData;
-
- /**
- * @return string
- */
- public function getMerchantData()
- {
- return $this->merchantData;
- }
-
- public function setMerchantData($merchantData)
- {
- $this->merchantData = $merchantData;
- return $this;
- }
-
- /**
- * @return string
- */
- public function getArticleNumber()
- {
- return $this->articleNumber;
- }
-
- /**
- * @param string $articleNumber
- * @return CheckoutOrderRow
- */
- public function setArticleNumber($articleNumber)
- {
- $this->articleNumber = $articleNumber;
- return $this;
- }
-
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
-
- /**
- * @param string $name
- * @return CheckoutOrderRow
- */
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
-
- /**
- * @return integer
- */
- public function getQuantity()
- {
- return $this->quantity;
- }
-
- /**
- * @param integer $quantity
- * @return CheckoutOrderRow
- */
- public function setQuantity($quantity)
- {
- $this->quantity = $quantity * 100;
- return $this;
- }
-
- /**
- * @return integer
- */
- public function getUnitPrice()
- {
- return $this->unitPrice;
- }
-
- /**
- * @param integer $unitPrice
- * @return CheckoutOrderRow
- */
- public function setUnitPrice($unitPrice)
- {
- $this->unitPrice = $unitPrice;
- return $this;
- }
-
- /**
- * @return integer
- */
- public function getDiscountPercent()
- {
- return $this->discountPercent;
- }
-
- /**
- * @param integer $discountPercent
- * @return CheckoutOrderRow
- */
- public function setDiscountPercent($discountPercent)
- {
- $this->discountPercent = $discountPercent;
- return $this;
- }
-
- /**
- * @return integer
- */
- public function getVatPercent()
- {
- return $this->vatPercent;
- }
-
- /**
- * @param integer $vatPercent
- * @return CheckoutOrderRow
- */
- public function setVatPercent($vatPercent)
- {
- $this->vatPercent = $vatPercent;
- return $this;
- }
-
- /**
- * @return string
- */
- public function getUnit()
- {
- return $this->unit;
- }
-
- /**
- * @param string $unit
- * @return CheckoutOrderRow
- */
- public function setUnit($unit)
- {
- $this->unit = $unit;
- return $this;
- }
-
- /**
- * @return string
- */
- public function getTemporaryReference()
- {
- return $this->temporaryReference;
- }
-
- /**
- * @param string $temporaryReference
- */
- public function setTemporaryReference($temporaryReference)
- {
- $this->temporaryReference = $temporaryReference;
- }
-
- /**
- * Return formatted array
- * Convert this object to array, only filled fields
- * @return array
- */
- public function toArray()
- {
- $result = array();
- $properties = get_object_vars($this);
-
- foreach ($properties as $property => $value) {
- if (isset($this->$property)) {
- $result[$property] = $value;
- }
- }
-
- return $result;
- }
+ /**
+ * @var string $articleNumber
+ */
+ private $articleNumber;
+
+ /**
+ * @var string $name
+ */
+ private $name;
+
+ /**
+ * @var integer $quantity
+ */
+ private $quantity;
+
+ /**
+ * @var integer $unitPrice
+ */
+ private $unitPrice;
+
+ /**
+ * @var integer $discountPercent
+ */
+ private $discountPercent;
+
+ /**
+ * @var integer $vatPercent
+ */
+ private $vatPercent;
+
+ /**
+ * @var string $unit
+ */
+ private $unit;
+
+ /**
+ * @var $temporaryReference
+ */
+ private $temporaryReference;
+
+ /**
+ * @var $merchantData
+ */
+ private $merchantData;
+
+ /**
+ * @return string
+ */
+ public function getMerchantData()
+ {
+ return $this->merchantData;
+ }
+
+ public function setMerchantData($merchantData)
+ {
+ $this->merchantData = $merchantData;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getArticleNumber()
+ {
+ return $this->articleNumber;
+ }
+
+ /**
+ * @param string $articleNumber
+ * @return CheckoutOrderRow
+ */
+ public function setArticleNumber($articleNumber)
+ {
+ $this->articleNumber = $articleNumber;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * @param string $name
+ * @return CheckoutOrderRow
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ return $this;
+ }
+
+ /**
+ * @return integer
+ */
+ public function getQuantity()
+ {
+ return $this->quantity;
+ }
+
+ /**
+ * @param integer $quantity
+ * @return CheckoutOrderRow
+ */
+ public function setQuantity($quantity)
+ {
+ $this->quantity = $quantity * 100;
+ return $this;
+ }
+
+ /**
+ * @return integer
+ */
+ public function getUnitPrice()
+ {
+ return $this->unitPrice;
+ }
+
+ /**
+ * @param integer $unitPrice
+ * @return CheckoutOrderRow
+ */
+ public function setUnitPrice($unitPrice)
+ {
+ $this->unitPrice = $unitPrice;
+ return $this;
+ }
+
+ /**
+ * @return integer
+ */
+ public function getDiscountPercent()
+ {
+ return $this->discountPercent;
+ }
+
+ /**
+ * @param integer $discountPercent
+ * @return CheckoutOrderRow
+ */
+ public function setDiscountPercent($discountPercent)
+ {
+ $this->discountPercent = $discountPercent;
+ return $this;
+ }
+
+ /**
+ * @return integer
+ */
+ public function getVatPercent()
+ {
+ return $this->vatPercent;
+ }
+
+ /**
+ * @param integer $vatPercent
+ * @return CheckoutOrderRow
+ */
+ public function setVatPercent($vatPercent)
+ {
+ $this->vatPercent = $vatPercent;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getUnit()
+ {
+ return $this->unit;
+ }
+
+ /**
+ * @param string $unit
+ * @return CheckoutOrderRow
+ */
+ public function setUnit($unit)
+ {
+ $this->unit = $unit;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getTemporaryReference()
+ {
+ return $this->temporaryReference;
+ }
+
+ /**
+ * @param string $temporaryReference
+ */
+ public function setTemporaryReference($temporaryReference)
+ {
+ $this->temporaryReference = $temporaryReference;
+ }
+
+ /**
+ * Return formatted array
+ * Convert this object to array, only filled fields
+ * @return array
+ */
+ public function toArray()
+ {
+ $result = [];
+ $properties = get_object_vars($this);
+
+ foreach ($properties as $property => $value) {
+ if (isset($this->$property)) {
+ $result[$property] = $value;
+ }
+ }
+
+ return $result;
+ }
}
diff --git a/src/Checkout/Model/IdentityFlags.php b/src/Checkout/Model/IdentityFlags.php
index 7b37191c..19630ca8 100644
--- a/src/Checkout/Model/IdentityFlags.php
+++ b/src/Checkout/Model/IdentityFlags.php
@@ -8,7 +8,7 @@
*/
abstract class IdentityFlags
{
- const HIDENOTYOU = "HideNotYou";
- const HIDECHANGEADDRESS = "HideChangeAddress";
- const HIDEANONYMOUS = "HideAnonymous";
+ const HIDENOTYOU = "HideNotYou";
+ const HIDECHANGEADDRESS = "HideChangeAddress";
+ const HIDEANONYMOUS = "HideAnonymous";
}
diff --git a/src/Checkout/Model/MerchantSettings.php b/src/Checkout/Model/MerchantSettings.php
index 8104c202..1399262a 100644
--- a/src/Checkout/Model/MerchantSettings.php
+++ b/src/Checkout/Model/MerchantSettings.php
@@ -5,151 +5,151 @@
/**
* This class hold information about urls that
* are necessary for creating an checkout order
- *
+ *
* Class MerchantSettings
* @package Svea\Svea\WebPay\WebPay\Checkout\Model
*/
class MerchantSettings
{
- /**
- * @var string $termsUri
- */
- private $termsUri;
-
- /**
- * @var string $checkoutUri
- */
- private $checkoutUri;
-
- /**
- * @var string $confirmationUri
- */
- private $confirmationUri;
-
- /**
- * @var string $pushUri
- */
- private $pushUri;
-
- /**
- * @var string $validationCallbackUri
- */
- private $validationCallbackUri;
-
- /**
- * MerchantSettings constructor.
- */
- public function __construct()
- {
- return $this;
- }
-
- /**
- * @return string
- */
- public function getTermsUri()
- {
- return $this->termsUri;
- }
-
- /**
- * @param string $termsUri
- * @return MerchantSettings
- */
- public function setTermsUri($termsUri)
- {
- $this->termsUri = $termsUri;
-
- return $this;
- }
-
- /**
- * @return string
- */
- public function getCheckoutUri()
- {
- return $this->checkoutUri;
- }
-
- /**
- * @param string $checkoutUri
- * @return MerchantSettings
- */
- public function setCheckoutUri($checkoutUri)
- {
- $this->checkoutUri = $checkoutUri;
-
- return $this;
- }
-
- /**
- * @return string
- */
- public function getConfirmationUri()
- {
- return $this->confirmationUri;
- }
-
- /**
- * @param string $confirmationUri
- * @return MerchantSettings
- */
- public function setConfirmationUri($confirmationUri)
- {
- $this->confirmationUri = $confirmationUri;
-
- return $this;
- }
-
- /**
- * @return string
- */
- public function getPushUri()
- {
- return $this->pushUri;
- }
-
- /**
- * @param string $pushUri
- * @return MerchantSettings
- */
- public function setPushUri($pushUri)
- {
- $this->pushUri = $pushUri;
-
- return $this;
- }
-
- /**
- * @return string
- */
- public function getValidationCallbackUri()
- {
- return $this->validationCallbackUri;
- }
-
- /**
- * @param string $validationCallbackUri
- * @return MerchantSettings
- */
- public function setValidationCallbackUri($validationCallbackUri)
- {
- $this->validationCallbackUri = $validationCallbackUri;
- return $this;
- }
-
- /**
- * Return structured merchant urls
- * @return array
- */
- public function getMerchantSettings()
- {
- return array(
- 'termsUri' => $this->getTermsUri(),
- 'checkoutUri' => $this->getCheckoutUri(),
- 'confirmationUri' => $this->getConfirmationUri(),
- 'checkoutValidationCallBackUri' => $this->getValidationCallbackUri(),
- 'pushUri' => $this->getPushUri()
- );
- }
+ /**
+ * @var string $termsUri
+ */
+ private $termsUri;
+
+ /**
+ * @var string $checkoutUri
+ */
+ private $checkoutUri;
+
+ /**
+ * @var string $confirmationUri
+ */
+ private $confirmationUri;
+
+ /**
+ * @var string $pushUri
+ */
+ private $pushUri;
+
+ /**
+ * @var string $validationCallbackUri
+ */
+ private $validationCallbackUri;
+
+ /**
+ * MerchantSettings constructor.
+ */
+ public function __construct()
+ {
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getTermsUri()
+ {
+ return $this->termsUri;
+ }
+
+ /**
+ * @param string $termsUri
+ * @return MerchantSettings
+ */
+ public function setTermsUri($termsUri)
+ {
+ $this->termsUri = $termsUri;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getCheckoutUri()
+ {
+ return $this->checkoutUri;
+ }
+
+ /**
+ * @param string $checkoutUri
+ * @return MerchantSettings
+ */
+ public function setCheckoutUri($checkoutUri)
+ {
+ $this->checkoutUri = $checkoutUri;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getConfirmationUri()
+ {
+ return $this->confirmationUri;
+ }
+
+ /**
+ * @param string $confirmationUri
+ * @return MerchantSettings
+ */
+ public function setConfirmationUri($confirmationUri)
+ {
+ $this->confirmationUri = $confirmationUri;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPushUri()
+ {
+ return $this->pushUri;
+ }
+
+ /**
+ * @param string $pushUri
+ * @return MerchantSettings
+ */
+ public function setPushUri($pushUri)
+ {
+ $this->pushUri = $pushUri;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getValidationCallbackUri()
+ {
+ return $this->validationCallbackUri;
+ }
+
+ /**
+ * @param string $validationCallbackUri
+ * @return MerchantSettings
+ */
+ public function setValidationCallbackUri($validationCallbackUri)
+ {
+ $this->validationCallbackUri = $validationCallbackUri;
+ return $this;
+ }
+
+ /**
+ * Return structured merchant urls
+ * @return array
+ */
+ public function getMerchantSettings()
+ {
+ return [
+ 'termsUri' => $this->getTermsUri(),
+ 'checkoutUri' => $this->getCheckoutUri(),
+ 'confirmationUri' => $this->getConfirmationUri(),
+ 'checkoutValidationCallBackUri' => $this->getValidationCallbackUri(),
+ 'pushUri' => $this->getPushUri()
+ ];
+ }
}
diff --git a/src/Checkout/Model/PresetValue.php b/src/Checkout/Model/PresetValue.php
index 63b847cd..784a10c2 100644
--- a/src/Checkout/Model/PresetValue.php
+++ b/src/Checkout/Model/PresetValue.php
@@ -11,124 +11,124 @@
*/
class PresetValue
{
- const NATIONAL_ID = 'nationalId';
- const EMAIL_ADDRESS = 'emailAddress';
- const PHONE_NUMBER = 'phoneNumber';
- const POSTAL_CODE = 'postalCode';
- const IS_COMPANY = 'isCompany';
-
- /**
- * @var string
- */
- protected $typeName;
-
- /**
- * @var mixed
- */
- protected $value;
-
- /**
- * @var bool
- */
- protected $isReadonly;
-
- /**
- * @return string
- */
- public function getTypeName()
- {
- return $this->typeName;
- }
-
- /**
- * @param string $typeName
- * @return PresetValue
- * @throws ValidationException
- */
- public function setTypeName($typeName)
- {
- $this->validateInput($typeName);
-
- $this->typeName = $typeName;
-
- return $this;
- }
-
- /**
- * @param $typeName
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- private function validateInput($typeName)
- {
- $constantListValue = $this->getConstantListValues();
-
- if (!in_array($typeName, $constantListValue)) {
- throw new ValidationException('This Typename "' . $typeName . '" is not supported. Supported types are: ' .
- join(', ', $constantListValue) . '.');
- }
- }
-
- /**
- * Return values of all defined constants in this class
- *
- * @return array
- */
- private function getConstantListValues()
- {
- $rc = new \ReflectionClass($this);
- $constantList = array_values($rc->getConstants());
-
- return $constantList;
- }
-
- /**
- * @return mixed
- */
- public function getValue()
- {
- return $this->value;
- }
-
- /**
- * @param mixed $value
- * @return PresetValue
- */
- public function setValue($value)
- {
- $this->value = $value;
-
- return $this;
- }
-
- /**
- * @return boolean
- */
- public function isIsReadonly()
- {
- return $this->isReadonly;
- }
-
- /**
- * @param boolean $isReadonly
- * @return PresetValue
- */
- public function setIsReadonly($isReadonly)
- {
- $this->isReadonly = $isReadonly;
-
- return $this;
- }
-
-
- /**
- * @return array
- */
- public function returnPresetArray()
- {
- return array(
- 'typeName' => $this->typeName,
- 'value' => $this->value,
- 'isReadonly' => $this->isReadonly,
- );
- }
+ const NATIONAL_ID = 'nationalId';
+ const EMAIL_ADDRESS = 'emailAddress';
+ const PHONE_NUMBER = 'phoneNumber';
+ const POSTAL_CODE = 'postalCode';
+ const IS_COMPANY = 'isCompany';
+
+ /**
+ * @var string
+ */
+ protected $typeName;
+
+ /**
+ * @var mixed
+ */
+ protected $value;
+
+ /**
+ * @var bool
+ */
+ protected $isReadonly;
+
+ /**
+ * @return string
+ */
+ public function getTypeName()
+ {
+ return $this->typeName;
+ }
+
+ /**
+ * @param string $typeName
+ * @return PresetValue
+ * @throws ValidationException
+ */
+ public function setTypeName($typeName)
+ {
+ $this->validateInput($typeName);
+
+ $this->typeName = $typeName;
+
+ return $this;
+ }
+
+ /**
+ * @param $typeName
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ private function validateInput($typeName)
+ {
+ $constantListValue = $this->getConstantListValues();
+
+ if (!in_array($typeName, $constantListValue)) {
+ throw new ValidationException('This Typename "' . $typeName . '" is not supported. Supported types are: ' .
+ join(', ', $constantListValue) . '.');
+ }
+ }
+
+ /**
+ * Return values of all defined constants in this class
+ *
+ * @return array
+ */
+ private function getConstantListValues()
+ {
+ $rc = new \ReflectionClass($this);
+ $constantList = array_values($rc->getConstants());
+
+ return $constantList;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ /**
+ * @param mixed $value
+ * @return PresetValue
+ */
+ public function setValue($value)
+ {
+ $this->value = $value;
+
+ return $this;
+ }
+
+ /**
+ * @return boolean
+ */
+ public function isIsReadonly()
+ {
+ return $this->isReadonly;
+ }
+
+ /**
+ * @param boolean $isReadonly
+ * @return PresetValue
+ */
+ public function setIsReadonly($isReadonly)
+ {
+ $this->isReadonly = $isReadonly;
+
+ return $this;
+ }
+
+
+ /**
+ * @return array
+ */
+ public function returnPresetArray()
+ {
+ return [
+ 'typeName' => $this->typeName,
+ 'value' => $this->value,
+ 'isReadonly' => $this->isReadonly,
+ ];
+ }
}
diff --git a/src/Checkout/Response/CheckoutAdminResponseHelper.php b/src/Checkout/Response/CheckoutAdminResponseHelper.php
index 90cbf62b..a4863899 100644
--- a/src/Checkout/Response/CheckoutAdminResponseHelper.php
+++ b/src/Checkout/Response/CheckoutAdminResponseHelper.php
@@ -4,118 +4,118 @@
class CheckoutAdminResponseHelper
{
- const MINOR_CURRENCY = 100;
-
- public static function processResponse($response)
- {
- if (isset($response['OrderAmount']) && !empty($response['OrderAmount'])) {
- $response['OrderAmount'] = $response['OrderAmount'] / self::MINOR_CURRENCY;
- }
-
- if (isset($response['CancelledAmount']) && !empty($response['CancelledAmount'])) {
- $response['CancelledAmount'] = $response['CancelledAmount'] / self::MINOR_CURRENCY;
- }
-
- $orderRows = $response['OrderRows'];
- $deliveries = $response['Deliveries'];
-
- if (isset($deliveries)) {
- $response['Deliveries'] = self::convertDeliveries($deliveries);
- }
-
- if (isset($orderRows)) {
- $response['OrderRows'] = self::convertOrderRows($orderRows);
- }
-
- return $response;
- }
-
- private static function convertDeliveries($deliveries)
- {
- $newDeliveries = array();
- foreach ($deliveries as $delivery) {
- if (isset($delivery['DeliveryAmount']) && !empty($delivery['DeliveryAmount'])) {
- $delivery['DeliveryAmount'] = $delivery['DeliveryAmount'] / self::MINOR_CURRENCY;
- }
-
- if (isset($delivery['CreditedAmount']) && !empty($delivery['CreditedAmount'])) {
- $delivery['CreditedAmount'] = $delivery['CreditedAmount'] / self::MINOR_CURRENCY;
- }
-
- $credits = $delivery['Credits'];
- if (isset($credits)) {
- $delivery['Credits'] = self::convertCredits($credits);
- }
-
- $deliveryOrderRows = $delivery['OrderRows'];
- $newDeliveryOrderRows = array();
-
- if (is_array($deliveryOrderRows)) {
- foreach ($deliveryOrderRows as $deliveryOrderRow) {
- $newDeliveryOrderRows[] = self::convertMinorCurrencyValues($deliveryOrderRow);
- }
- }
-
- $delivery['OrderRows'] = $newDeliveryOrderRows;
- $newDeliveries[] = $delivery;
- }
-
- return $newDeliveries;
- }
-
- private static function convertCredits($credits)
- {
- $newCredits = array();
-
- foreach ($credits as $credit) {
- if (isset($credit['Amount']) && !empty($credit['Amount'])) {
- $credit['Amount'] = $credit['Amount'] / self::MINOR_CURRENCY;
- }
-
- $creditOrderRows = $credit['OrderRows'];
- $newCreditOrderRows = array();
-
- if (is_array($creditOrderRows)) {
- foreach ($creditOrderRows as $creditOrderRow) {
- $newCreditOrderRows[] = self::convertMinorCurrencyValues($creditOrderRow);
- }
- }
-
- $credit['OrderRows'] = $newCreditOrderRows;
- $newCredits[] = $credit;
- }
-
- return $newCredits;
- }
-
- private static function convertOrderRows($orderRows)
- {
- $newOrderRows = array();
- foreach ($orderRows as $row) {
- $newOrderRows[] = self::convertMinorCurrencyValues($row);
- }
-
- return $newOrderRows;
- }
-
- private static function convertMinorCurrencyValues($orderRowData)
- {
- if (isset($orderRowData['Quantity']) && !empty($orderRowData['Quantity'])) {
- $orderRowData['Quantity'] = $orderRowData['Quantity'] / self::MINOR_CURRENCY;
- }
-
- if (isset($orderRowData['UnitPrice']) && !empty($orderRowData['UnitPrice'])) {
- $orderRowData['UnitPrice'] = $orderRowData['UnitPrice'] / self::MINOR_CURRENCY;
- }
-
- if (isset($orderRowData['VatPercent']) && !empty($orderRowData['VatPercent'])) {
- $orderRowData['VatPercent'] = $orderRowData['VatPercent'] / self::MINOR_CURRENCY;
- }
-
- if (isset($orderRowData['DiscountPercent']) && !empty($orderRowData['DiscountPercent'])) {
- $orderRowData['DiscountPercent'] = $orderRowData['DiscountPercent'] / self::MINOR_CURRENCY;
- }
-
- return $orderRowData;
- }
+ const MINOR_CURRENCY = 100;
+
+ public static function processResponse($response)
+ {
+ if (isset($response['OrderAmount']) && !empty($response['OrderAmount'])) {
+ $response['OrderAmount'] = $response['OrderAmount'] / self::MINOR_CURRENCY;
+ }
+
+ if (isset($response['CancelledAmount']) && !empty($response['CancelledAmount'])) {
+ $response['CancelledAmount'] = $response['CancelledAmount'] / self::MINOR_CURRENCY;
+ }
+
+ $orderRows = $response['OrderRows'];
+ $deliveries = $response['Deliveries'];
+
+ if (isset($deliveries)) {
+ $response['Deliveries'] = self::convertDeliveries($deliveries);
+ }
+
+ if (isset($orderRows)) {
+ $response['OrderRows'] = self::convertOrderRows($orderRows);
+ }
+
+ return $response;
+ }
+
+ private static function convertDeliveries($deliveries)
+ {
+ $newDeliveries = [];
+ foreach ($deliveries as $delivery) {
+ if (isset($delivery['DeliveryAmount']) && !empty($delivery['DeliveryAmount'])) {
+ $delivery['DeliveryAmount'] = $delivery['DeliveryAmount'] / self::MINOR_CURRENCY;
+ }
+
+ if (isset($delivery['CreditedAmount']) && !empty($delivery['CreditedAmount'])) {
+ $delivery['CreditedAmount'] = $delivery['CreditedAmount'] / self::MINOR_CURRENCY;
+ }
+
+ $credits = $delivery['Credits'];
+ if (isset($credits)) {
+ $delivery['Credits'] = self::convertCredits($credits);
+ }
+
+ $deliveryOrderRows = $delivery['OrderRows'];
+ $newDeliveryOrderRows = [];
+
+ if (is_array($deliveryOrderRows)) {
+ foreach ($deliveryOrderRows as $deliveryOrderRow) {
+ $newDeliveryOrderRows[] = self::convertMinorCurrencyValues($deliveryOrderRow);
+ }
+ }
+
+ $delivery['OrderRows'] = $newDeliveryOrderRows;
+ $newDeliveries[] = $delivery;
+ }
+
+ return $newDeliveries;
+ }
+
+ private static function convertCredits($credits)
+ {
+ $newCredits = [];
+
+ foreach ($credits as $credit) {
+ if (isset($credit['Amount']) && !empty($credit['Amount'])) {
+ $credit['Amount'] = $credit['Amount'] / self::MINOR_CURRENCY;
+ }
+
+ $creditOrderRows = $credit['OrderRows'];
+ $newCreditOrderRows = [];
+
+ if (is_array($creditOrderRows)) {
+ foreach ($creditOrderRows as $creditOrderRow) {
+ $newCreditOrderRows[] = self::convertMinorCurrencyValues($creditOrderRow);
+ }
+ }
+
+ $credit['OrderRows'] = $newCreditOrderRows;
+ $newCredits[] = $credit;
+ }
+
+ return $newCredits;
+ }
+
+ private static function convertOrderRows($orderRows)
+ {
+ $newOrderRows = [];
+ foreach ($orderRows as $row) {
+ $newOrderRows[] = self::convertMinorCurrencyValues($row);
+ }
+
+ return $newOrderRows;
+ }
+
+ private static function convertMinorCurrencyValues($orderRowData)
+ {
+ if (isset($orderRowData['Quantity']) && !empty($orderRowData['Quantity'])) {
+ $orderRowData['Quantity'] = $orderRowData['Quantity'] / self::MINOR_CURRENCY;
+ }
+
+ if (isset($orderRowData['UnitPrice']) && !empty($orderRowData['UnitPrice'])) {
+ $orderRowData['UnitPrice'] = $orderRowData['UnitPrice'] / self::MINOR_CURRENCY;
+ }
+
+ if (isset($orderRowData['VatPercent']) && !empty($orderRowData['VatPercent'])) {
+ $orderRowData['VatPercent'] = $orderRowData['VatPercent'] / self::MINOR_CURRENCY;
+ }
+
+ if (isset($orderRowData['DiscountPercent']) && !empty($orderRowData['DiscountPercent'])) {
+ $orderRowData['DiscountPercent'] = $orderRowData['DiscountPercent'] / self::MINOR_CURRENCY;
+ }
+
+ return $orderRowData;
+ }
}
\ No newline at end of file
diff --git a/src/Checkout/Response/CheckoutResponseHelper.php b/src/Checkout/Response/CheckoutResponseHelper.php
index 115b8413..64645c4e 100644
--- a/src/Checkout/Response/CheckoutResponseHelper.php
+++ b/src/Checkout/Response/CheckoutResponseHelper.php
@@ -6,23 +6,23 @@
class CheckoutResponseHelper
{
- public static function processData($data)
- {
- $response = $data;
+ public static function processData($data)
+ {
+ $response = $data;
- if (isset($response['Cart']['Items']) && is_array($response['Cart']['Items'])) {
- $newItems = array();
- $cartItems = $response['Cart']['Items'];
+ if (isset($response['Cart']['Items']) && is_array($response['Cart']['Items'])) {
+ $newItems = [];
+ $cartItems = $response['Cart']['Items'];
- foreach ($cartItems as $item) {
- $orderRow = new OrderRow();
- $orderRow->map($item);
- $newItems[] = $orderRow->getRefactoredData();
- }
+ foreach ($cartItems as $item) {
+ $orderRow = new OrderRow();
+ $orderRow->map($item);
+ $newItems[] = $orderRow->getRefactoredData();
+ }
- $response['Cart']['Items'] = $newItems;
- }
+ $response['Cart']['Items'] = $newItems;
+ }
- return $response;
- }
+ return $response;
+ }
}
diff --git a/src/Checkout/Response/Model/OrderRow.php b/src/Checkout/Response/Model/OrderRow.php
index bdf1149b..e1fa049d 100644
--- a/src/Checkout/Response/Model/OrderRow.php
+++ b/src/Checkout/Response/Model/OrderRow.php
@@ -4,79 +4,79 @@
class OrderRow
{
- const MINOR_CURRENCY = 100;
+ const MINOR_CURRENCY = 100;
- /**
- * @var int $rowId
- */
- private $rowId;
+ /**
+ * @var int $rowId
+ */
+ private $rowId;
- /**
- * @var int $articleNumber
- */
- private $articleNumber;
+ /**
+ * @var int $articleNumber
+ */
+ private $articleNumber;
- /**
- * @var string $name
- */
- private $name;
+ /**
+ * @var string $name
+ */
+ private $name;
- /**
- * @var int $quantity
- */
- private $quantity;
+ /**
+ * @var int $quantity
+ */
+ private $quantity;
- /**
- * @var int $unitPrice
- */
- private $unitPrice;
+ /**
+ * @var int $unitPrice
+ */
+ private $unitPrice;
- /**
- * @var int $discountPercent
- */
- private $discountPercent;
+ /**
+ * @var int $discountPercent
+ */
+ private $discountPercent;
- /**
- * @var int $vatPercent
- */
- private $vatPercent;
+ /**
+ * @var int $vatPercent
+ */
+ private $vatPercent;
- /**
- * @var string $unit
- */
- private $unit;
+ /**
+ * @var string $unit
+ */
+ private $unit;
- /**
- * @var int $temporaryReference
- */
- private $temporaryReference;
+ /**
+ * @var int $temporaryReference
+ */
+ private $temporaryReference;
- public function map($data)
- {
- $this->articleNumber = $data['ArticleNumber'];
- $this->name = $data['Name'];
- $this->quantity = $data['Quantity'];
- $this->unitPrice = $data['UnitPrice'];
- $this->discountPercent = $data['DiscountPercent'];
- $this->vatPercent = $data['VatPercent'];
- $this->temporaryReference = $data['TemporaryReference'];
- $this->unit = $data['Unit'];
- $this->rowId = $data['RowNumber'];
- }
+ public function map($data)
+ {
+ $this->articleNumber = $data['ArticleNumber'];
+ $this->name = $data['Name'];
+ $this->quantity = $data['Quantity'];
+ $this->unitPrice = $data['UnitPrice'];
+ $this->discountPercent = $data['DiscountPercent'];
+ $this->vatPercent = $data['VatPercent'];
+ $this->temporaryReference = $data['TemporaryReference'];
+ $this->unit = $data['Unit'];
+ $this->rowId = $data['RowNumber'];
+ }
- public function getRefactoredData()
- {
- return array(
- 'ArticleNumber' => $this->articleNumber,
- 'Name' => $this->name,
- 'Quantity' => $this->quantity / $this::MINOR_CURRENCY,
- 'UnitPrice' => $this->unitPrice / $this::MINOR_CURRENCY,
- 'VatPercent' => $this->vatPercent / $this::MINOR_CURRENCY,
- 'DiscountPercent' => $this->discountPercent,
- 'Unit' => $this->unit,
- 'TemporaryReference' => $this->temporaryReference,
- 'RowId' => $this->rowId
- );
- }
+ public function getRefactoredData()
+ {
+ return [
+ 'ArticleNumber' => $this->articleNumber,
+ 'Name' => $this->name,
+ 'Quantity' => $this->quantity / $this::MINOR_CURRENCY,
+ 'UnitPrice' => $this->unitPrice / $this::MINOR_CURRENCY,
+ 'VatPercent' => $this->vatPercent / $this::MINOR_CURRENCY,
+ 'DiscountPercent' => $this->discountPercent,
+ 'Unit' => $this->unit,
+ 'TemporaryReference' => $this->temporaryReference,
+ 'RowId' => $this->rowId
+ ];
+ }
}
\ No newline at end of file
diff --git a/src/Checkout/Service/Admin/AddOrderRowService.php b/src/Checkout/Service/Admin/AddOrderRowService.php
index 05430146..ea24ae09 100644
--- a/src/Checkout/Service/Admin/AddOrderRowService.php
+++ b/src/Checkout/Service/Admin/AddOrderRowService.php
@@ -8,73 +8,73 @@
class AddOrderRowService extends AdminImplementationService
{
- /**
- * @var AddOrderRowsBuilder $adminBuilder
- */
- public $adminBuilder;
+ /**
+ * @var AddOrderRowsBuilder $adminBuilder
+ */
+ public $adminBuilder;
- /**
- * Validate order data
- */
- public function validate()
- {
- $validator = new AddOrderRowValidator();
- $errors = $validator->validate($this->adminBuilder);
+ /**
+ * Validate order data
+ */
+ public function validate()
+ {
+ $validator = new AddOrderRowValidator();
+ $errors = $validator->validate($this->adminBuilder);
- $this->processErrors($errors);
- }
+ $this->processErrors($errors);
+ }
- /**
- * Format given date so that will match data structure required for Admin API
- * @return mixed
- */
- public function prepareRequest()
- {
- $this->validate();
+ /**
+ * Format given date so that will match data structure required for Admin API
+ * @return mixed
+ */
+ public function prepareRequest()
+ {
+ $this->validate();
- $requestData = array(
- 'orderId' => $this->adminBuilder->orderId,
- 'orderRow' => $this->formatOrderRowValues()
- );
+ $requestData = [
+ 'orderId' => $this->adminBuilder->orderId,
+ 'orderRow' => $this->formatOrderRowValues()
+ ];
- return $requestData;
- }
+ return $requestData;
+ }
- /**
- * Send call Connection Library
- */
- public function doRequest()
- {
- $preparedData = $this->prepareRequest();
- $response = $this->checkoutAdminConnection->addOrderRow($preparedData);
+ /**
+ * Send call Connection Library
+ */
+ public function doRequest()
+ {
+ $preparedData = $this->prepareRequest();
+ $response = $this->checkoutAdminConnection->addOrderRow($preparedData);
- return $response;
- }
+ return $response;
+ }
- private function formatOrderRowValues()
- {
- $requestOrderRow = array();
+ private function formatOrderRowValues()
+ {
+ $requestOrderRow = [];
- $rowData = $this->adminBuilder->orderRows[0];
- foreach ($rowData as $orderRowKey => $orderRowValue) {
- switch ($orderRowKey) {
- case 'amountIncVat':
- $requestOrderRow['unitPrice'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
- break;
- case 'vatPercent':
- $requestOrderRow['vatPercent'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
- break;
- case 'discountPercent':
- $requestOrderRow['discountPercent'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
- break;
- case 'quantity':
- $requestOrderRow['quantity'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
- break;
- default:
- $requestOrderRow[$orderRowKey] = $orderRowValue;
- }
- }
+ $rowData = $this->adminBuilder->orderRows[0];
+ foreach ($rowData as $orderRowKey => $orderRowValue) {
+ switch ($orderRowKey) {
+ case 'amountIncVat':
+ $requestOrderRow['unitPrice'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
+ break;
+ case 'vatPercent':
+ $requestOrderRow['vatPercent'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
+ break;
+ case 'discountPercent':
+ $requestOrderRow['discountPercent'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
+ break;
+ case 'quantity':
+ $requestOrderRow['quantity'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
+ break;
+ default:
+ $requestOrderRow[$orderRowKey] = $orderRowValue;
+ }
+ }
- return $requestOrderRow;
- }
+ return $requestOrderRow;
+ }
}
diff --git a/src/Checkout/Service/Admin/AdminImplementationService.php b/src/Checkout/Service/Admin/AdminImplementationService.php
index 9526cc5a..982ae474 100644
--- a/src/Checkout/Service/Admin/AdminImplementationService.php
+++ b/src/Checkout/Service/Admin/AdminImplementationService.php
@@ -13,68 +13,68 @@
*/
abstract class AdminImplementationService
{
- /**
- * @var CheckoutAdminConnection $checkoutAdminConnection
- */
- protected $checkoutAdminConnection;
+ /**
+ * @var CheckoutAdminConnection $checkoutAdminConnection
+ */
+ protected $checkoutAdminConnection;
- /**
- * @var CheckoutAdminOrderBuilder $adminBuilder
- */
- protected $adminBuilder;
+ /**
+ * @var CheckoutAdminOrderBuilder $adminBuilder
+ */
+ protected $adminBuilder;
- /**
- * CheckoutService constructor.
- *
- * @param CheckoutAdminOrderBuilder $adminBuilder
- */
- public function __construct(CheckoutAdminOrderBuilder $adminBuilder)
- {
- $this->adminBuilder = $adminBuilder;
- $this->checkoutAdminConnection = new CheckoutAdminConnection($adminBuilder->conf, $adminBuilder->countryCode);
- }
+ /**
+ * CheckoutService constructor.
+ *
+ * @param CheckoutAdminOrderBuilder $adminBuilder
+ */
+ public function __construct(CheckoutAdminOrderBuilder $adminBuilder)
+ {
+ $this->adminBuilder = $adminBuilder;
+ $this->checkoutAdminConnection = new CheckoutAdminConnection($adminBuilder->conf, $adminBuilder->countryCode);
+ }
- /**
- * Validate order data
- */
- abstract public function validate();
+ /**
+ * Validate order data
+ */
+ abstract public function validate();
- /**
- * Format given date so that will match data structure required for Admin API
- * @return mixed
- */
- abstract public function prepareRequest();
+ /**
+ * Format given date so that will match data structure required for Admin API
+ * @return mixed
+ */
+ abstract public function prepareRequest();
- /**
- * Send call Connection Library
- */
- abstract public function doRequest();
+ /**
+ * Send call Connection Library
+ */
+ abstract public function doRequest();
- /**
- * @param array $errors
- * @throws ValidationException
- */
- protected function processErrors(array $errors)
- {
- if (count($errors) > 0) {
- $message = '';
- foreach ($errors as $key => $val) {
- $message = "Error - $key : $val";
- break;
- }
+ /**
+ * @param array $errors
+ * @throws ValidationException
+ */
+ protected function processErrors(array $errors)
+ {
+ if (count($errors) > 0) {
+ $message = '';
+ foreach ($errors as $key => $val) {
+ $message = "Error - $key : $val";
+ break;
+ }
- throw new ValidationException($message);
- }
- }
+ throw new ValidationException($message);
+ }
+ }
- /**
- * @return mixed
- */
- protected function formatOrderInformationWithOrderRows()
- {
- $formatter = new CheckoutRowFormatter($this);
- $formattedOrderRows = $formatter->formatRows();
+ /**
+ * @return mixed
+ */
+ protected function formatOrderInformationWithOrderRows()
+ {
+ $formatter = new CheckoutRowFormatter($this);
+ $formattedOrderRows = $formatter->formatRows();
- return $formattedOrderRows;
- }
+ return $formattedOrderRows;
+ }
}
diff --git a/src/Checkout/Service/Admin/CancelOrderRowService.php b/src/Checkout/Service/Admin/CancelOrderRowService.php
index dc3c4ec9..321d9077 100644
--- a/src/Checkout/Service/Admin/CancelOrderRowService.php
+++ b/src/Checkout/Service/Admin/CancelOrderRowService.php
@@ -6,67 +6,67 @@
class CancelOrderRowService extends AdminImplementationService
{
- /**
- * @var CancelOrderRowsBuilder $adminBuilder
- */
- public $adminBuilder;
+ /**
+ * @var CancelOrderRowsBuilder $adminBuilder
+ */
+ public $adminBuilder;
- /**
- * Validate order data
- */
- public function validate()
- {
- $errors = array();
+ /**
+ * Validate order data
+ */
+ public function validate()
+ {
+ $errors = [];
- $orderId = $this->adminBuilder->orderId;
- if (empty($orderId) || !is_int($orderId)) {
- $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
- }
+ $orderId = $this->adminBuilder->orderId;
+ if (empty($orderId) || !is_int($orderId)) {
+ $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
+ }
- $orderRowIds = $this->adminBuilder->rowsToCancel;
- if (!is_array($orderRowIds)) {
- $errors['incorrect Order Row Ids'] = "Order Row Ids must be not empty array";
- }
+ $orderRowIds = $this->adminBuilder->rowsToCancel;
+ if (!is_array($orderRowIds)) {
+ $errors['incorrect Order Row Ids'] = "Order Row Ids must be not empty array";
+ }
- if (count($orderRowIds) > 1) {
- $errors['incorrect Order Row Id'] = "You can Cancel just one Order Row";
- }
+ if (count($orderRowIds) > 1) {
+ $errors['incorrect Order Row Id'] = "You can Cancel just one Order Row";
+ }
- if (is_array($orderRowIds) && count($orderRowIds) > 0) {
- $orderRowId = $orderRowIds[0];
- if (empty($orderRowId) || !is_int($orderRowId)) {
- $errors['incorrect Order Row Id'] = "Order Row Id can't be empty and must be Integer";
- }
- }
+ if (is_array($orderRowIds) && count($orderRowIds) > 0) {
+ $orderRowId = $orderRowIds[0];
+ if (empty($orderRowId) || !is_int($orderRowId)) {
+ $errors['incorrect Order Row Id'] = "Order Row Id can't be empty and must be Integer";
+ }
+ }
- $this->processErrors($errors);
- }
+ $this->processErrors($errors);
+ }
- /**
- * Format given date so that will match data structure required for Admin API
- * @return mixed
- */
- public function prepareRequest()
- {
- $this->validate();
+ /**
+ * Format given date so that will match data structure required for Admin API
+ * @return mixed
+ */
+ public function prepareRequest()
+ {
+ $this->validate();
- $orderRowId = $this->adminBuilder->rowsToCancel[0];
- $requestData = array(
- 'orderId' => $this->adminBuilder->orderId,
- 'orderRowId' => $orderRowId
- );
+ $orderRowId = $this->adminBuilder->rowsToCancel[0];
+ $requestData = [
+ 'orderId' => $this->adminBuilder->orderId,
+ 'orderRowId' => $orderRowId
+ ];
- return $requestData;
- }
+ return $requestData;
+ }
- /**
- * Send call Connection Library
- */
- public function doRequest()
- {
- $preparedData = $this->prepareRequest();
- $response = $this->checkoutAdminConnection->cancelOrderRow($preparedData);
+ /**
+ * Send call Connection Library
+ */
+ public function doRequest()
+ {
+ $preparedData = $this->prepareRequest();
+ $response = $this->checkoutAdminConnection->cancelOrderRow($preparedData);
- return $response;
- }
+ return $response;
+ }
}
diff --git a/src/Checkout/Service/Admin/CancelOrderService.php b/src/Checkout/Service/Admin/CancelOrderService.php
index 015c05bb..ab8829d5 100644
--- a/src/Checkout/Service/Admin/CancelOrderService.php
+++ b/src/Checkout/Service/Admin/CancelOrderService.php
@@ -8,82 +8,82 @@
class CancelOrderService extends AdminImplementationService
{
- /**
- * @var CancelOrderBuilder $adminBuilder
- */
- public $adminBuilder;
+ /**
+ * @var CancelOrderBuilder $adminBuilder
+ */
+ public $adminBuilder;
- /**
- * @var bool $isCancelAmount
- */
- protected $isCancelAmount;
+ /**
+ * @var bool $isCancelAmount
+ */
+ protected $isCancelAmount;
- /**
- * CancelOrderService constructor.
- * @param CheckoutAdminOrderBuilder $adminBuilder
- * @param bool $isCancelAmount
- */
- public function __construct(CheckoutAdminOrderBuilder $adminBuilder, $isCancelAmount = false)
- {
- parent::__construct($adminBuilder);
- $this->isCancelAmount = $isCancelAmount;
- }
+ /**
+ * CancelOrderService constructor.
+ * @param CheckoutAdminOrderBuilder $adminBuilder
+ * @param bool $isCancelAmount
+ */
+ public function __construct(CheckoutAdminOrderBuilder $adminBuilder, $isCancelAmount = false)
+ {
+ parent::__construct($adminBuilder);
+ $this->isCancelAmount = $isCancelAmount;
+ }
- /**
- * Validate order data
- */
- public function validate()
- {
- $errors = array();
+ /**
+ * Validate order data
+ */
+ public function validate()
+ {
+ $errors = [];
- $orderId = $this->adminBuilder->orderId;
- if (empty($orderId) || !is_int($orderId)) {
- $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
- }
+ $orderId = $this->adminBuilder->orderId;
+ if (empty($orderId) || !is_int($orderId)) {
+ $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
+ }
- if ($this->isCancelAmount === true) {
- $amount = $this->adminBuilder->amountIncVat;
- if (empty($amount) || (!is_float($amount) && !is_int($amount))) {
- $errors['incorrect Amount for cancel order'] = "Amount can't be empty and must be Integer";
- }
- }
+ if ($this->isCancelAmount === true) {
+ $amount = $this->adminBuilder->amountIncVat;
+ if (empty($amount) || (!is_float($amount) && !is_int($amount))) {
+ $errors['incorrect Amount for cancel order'] = "Amount can't be empty and must be Integer";
+ }
+ }
- $this->processErrors($errors);
- }
+ $this->processErrors($errors);
+ }
- /**
- * Format given date so that will match data structure required for Admin API
- * @return mixed
- */
- public function prepareRequest()
- {
- $this->validate();
+ /**
+ * Format given date so that will match data structure required for Admin API
+ * @return mixed
+ */
+ public function prepareRequest()
+ {
+ $this->validate();
- $requestData = array(
- 'orderId' => $this->adminBuilder->orderId
- );
+ $requestData = [
+ 'orderId' => $this->adminBuilder->orderId
+ ];
- if ($this->isCancelAmount === true) {
- $amount = $this->adminBuilder->amountIncVat;
- $minorCurrencyAmount = Helper::bround($amount, 2) * 100;
- $requestData['cancelledAmount'] = intval((string)$minorCurrencyAmount);;
- }
+ if ($this->isCancelAmount === true) {
+ $amount = $this->adminBuilder->amountIncVat;
+ $minorCurrencyAmount = Helper::bround($amount, 2) * 100;
+ $requestData['cancelledAmount'] = intval((string)$minorCurrencyAmount);;
+ }
- return $requestData;
- }
+ return $requestData;
+ }
- /**
- * Send call Connection Library
- */
- public function doRequest()
- {
- $preparedData = $this->prepareRequest();
- if ($this->isCancelAmount === true) {
- $response = $this->checkoutAdminConnection->cancelOrderAmount($preparedData);
- } else {
- $response = $this->checkoutAdminConnection->cancelOrder($preparedData);
- }
+ /**
+ * Send call Connection Library
+ */
+ public function doRequest()
+ {
+ $preparedData = $this->prepareRequest();
+ if ($this->isCancelAmount === true) {
+ $response = $this->checkoutAdminConnection->cancelOrderAmount($preparedData);
+ } else {
+ $response = $this->checkoutAdminConnection->cancelOrder($preparedData);
+ }
- return $response;
- }
+ return $response;
+ }
}
diff --git a/src/Checkout/Service/Admin/CreditOrderAmountService.php b/src/Checkout/Service/Admin/CreditOrderAmountService.php
index 44714b8b..4be68bde 100644
--- a/src/Checkout/Service/Admin/CreditOrderAmountService.php
+++ b/src/Checkout/Service/Admin/CreditOrderAmountService.php
@@ -7,67 +7,67 @@
class CreditOrderAmountService extends AdminImplementationService
{
- /**
- * @var CreditAmountBuilder $adminBuilder
- */
- public $adminBuilder;
- /**
- * Validate order data
- */
- public function validate()
- {
- $errors = array();
+ /**
+ * @var CreditAmountBuilder $adminBuilder
+ */
+ public $adminBuilder;
+ /**
+ * Validate order data
+ */
+ public function validate()
+ {
+ $errors = [];
- $orderId = $this->adminBuilder->orderId;
- if (empty($orderId) || !is_int($orderId)) {
- $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
- }
+ $orderId = $this->adminBuilder->orderId;
+ if (empty($orderId) || !is_int($orderId)) {
+ $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
+ }
- $deliveryId = $this->adminBuilder->deliveryId;
- if (is_int($deliveryId) || (is_float($deliveryId) && $deliveryId > 2147483647))
- {
+ $deliveryId = $this->adminBuilder->deliveryId;
+ if (is_int($deliveryId) || (is_float($deliveryId) && $deliveryId > 2147483647))
+ {
- }
- else
- {
- $errors['incorrect Delivery Id'] = "Delivery Id can't be empty and must be Integer";
- }
+ }
+ else
+ {
+ $errors['incorrect Delivery Id'] = "Delivery Id can't be empty and must be Integer";
+ }
- $creditAmount = $this->adminBuilder->amountIncVat;
- if (empty($creditAmount) || !is_numeric($creditAmount)) {
- $errors['incorrect Credit Amount'] = "Credit amount can't be empty and must be number";
- }
+ $creditAmount = $this->adminBuilder->amountIncVat;
+ if (empty($creditAmount) || !is_numeric($creditAmount)) {
+ $errors['incorrect Credit Amount'] = "Credit amount can't be empty and must be number";
+ }
- $this->processErrors($errors);
- }
+ $this->processErrors($errors);
+ }
- /**
- * Format given date so that will match data structure required for Admin API
- * @return mixed
- */
- public function prepareRequest()
- {
- $this->validate();
+ /**
+ * Format given date so that will match data structure required for Admin API
+ * @return mixed
+ */
+ public function prepareRequest()
+ {
+ $this->validate();
- $requestData = array(
- 'orderId' => $this->adminBuilder->orderId,
- 'deliveryId' => $this->adminBuilder->deliveryId
- );
- $amount = $this->adminBuilder->amountIncVat;
- $minorCreditAmount = Helper::bround($amount, 2) * 100;
- $requestData['creditedAmount'] = intval((string)$minorCreditAmount);
+ $requestData = [
+ 'orderId' => $this->adminBuilder->orderId,
+ 'deliveryId' => $this->adminBuilder->deliveryId
+ ];
+ $amount = $this->adminBuilder->amountIncVat;
+ $minorCreditAmount = Helper::bround($amount, 2) * 100;
+ $requestData['creditedAmount'] = intval((string)$minorCreditAmount);
- return $requestData;
- }
+ return $requestData;
+ }
- /**
- * Send call Connection Library
- */
- public function doRequest()
- {
- $preparedData = $this->prepareRequest();
- $response = $this->checkoutAdminConnection->creditOrderAmount($preparedData);
+ /**
+ * Send call Connection Library
+ */
+ public function doRequest()
+ {
+ $preparedData = $this->prepareRequest();
+ $response = $this->checkoutAdminConnection->creditOrderAmount($preparedData);
- return $response;
- }
+ return $response;
+ }
}
diff --git a/src/Checkout/Service/Admin/CreditOrderRowsService.php b/src/Checkout/Service/Admin/CreditOrderRowsService.php
index 5a111ce1..e81fc0a0 100644
--- a/src/Checkout/Service/Admin/CreditOrderRowsService.php
+++ b/src/Checkout/Service/Admin/CreditOrderRowsService.php
@@ -9,125 +9,125 @@
class CreditOrderRowsService extends AdminImplementationService
{
- /**
- * @var CreditOrderRowsBuilder $adminBuilder
- */
- public $adminBuilder;
-
- /**
- * @var bool $isNewCreditRow
- */
- protected $isNewCreditRow;
-
- public function __construct(CheckoutAdminOrderBuilder $adminBuilder, $isNewCreditRow = false)
- {
- parent::__construct($adminBuilder);
- $this->isNewCreditRow = $isNewCreditRow;
- }
-
- /**
- * Validate order data
- */
- public function validate()
- {
- $errors = array();
-
- $orderId = $this->adminBuilder->orderId;
- if (empty($orderId) || !is_int($orderId)) {
- $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
- }
-
- $deliveryId = $this->adminBuilder->deliveryId;
- if (is_int($deliveryId) || (is_float($deliveryId) && $deliveryId > 2147483647))
- {
-
- }
- else
- {
- $errors['incorrect Delivery Id'] = "Delivery Id can't be empty and must be Integer";
- }
-
- if ($this->isNewCreditRow === true) {
- $creditOrderRows = $this->adminBuilder->creditOrderRows;
-
- if (count($creditOrderRows) > 1) {
- $errors['incorrect New Credit Row'] = "Only one Credit row can be set!";
- }
-
- $newCreditRow = $creditOrderRows[0];
- if (!($newCreditRow instanceof OrderRow)) {
- $errors['incorrect New Credit Row'] = "New Credit Row can't be empty and must be array";
- } else {
- foreach ($creditOrderRows as $orderRow) {
- if (!isset($orderRow->vatPercent)) {
- $errors['missing order row vat information'] = "cannot calculate orderRow vatPercent, need to set vatPercent.";
- }
-
- if (!is_float($orderRow->amountIncVat) && $orderRow->amountIncVat !== 0) {
- $errors['missing order row amount information'] = "cannot calculate orderRow amount, need to set value for amountIncVat.";
- }
- }
- }
- } else {
- $orderRowIds = $this->adminBuilder->rowsToCredit;
- if (is_array($orderRowIds) && count($orderRowIds) > 0) {
- foreach ($orderRowIds as $orderRowId) {
- if (empty($orderRowId) || !is_int($orderRowId)) {
- $errors['incorrect Order Row Id'] = "Order Row Id can't be empty and must be Integer";
- }
- }
- } else {
- $errors['missing order rows'] = "must be at least one Order row set.";
- }
- }
-
- $this->processErrors($errors);
- }
-
- /**
- * Format given date so that will match data structure required for Admin API
- * @return mixed
- */
- public function prepareRequest()
- {
- $this->validate();
-
- $requestData = array(
- 'orderId' => $this->adminBuilder->orderId,
- 'deliveryId' => $this->adminBuilder->deliveryId
- );
-
- if (!empty($this->adminBuilder->rowsToCredit)) {
- $requestData['orderRowIds'] = $this->adminBuilder->rowsToCredit;
- } elseif (count($this->adminBuilder->creditOrderRows) > 0) {
- /**
- * @var OrderRow $orderRow
- */
- $orderRow = $this->adminBuilder->creditOrderRows[0];
-
- $requestData['newCreditRow'] = array(
- 'name' => $orderRow->name,
- 'quantity' => intval((string)Helper::bround($orderRow->quantity, 2) * 100),
- 'unitPrice' => intval((string)Helper::bround($orderRow->amountIncVat, 2) * 100),
- 'vatPercent' => intval((string)Helper::bround($orderRow->vatPercent, 2) * 100)
- );
- }
-
- return $requestData;
- }
-
- /**
- * Send call Connection Library
- */
- public function doRequest()
- {
- $preparedData = $this->prepareRequest();
- if ($this->isNewCreditRow === true) {
- $response = $this->checkoutAdminConnection->creditNewOrderRow($preparedData);
- } else {
- $response = $this->checkoutAdminConnection->creditOrderRows($preparedData);
- }
-
- return $response;
- }
+ /**
+ * @var CreditOrderRowsBuilder $adminBuilder
+ */
+ public $adminBuilder;
+
+ /**
+ * @var bool $isNewCreditRow
+ */
+ protected $isNewCreditRow;
+
+ public function __construct(CheckoutAdminOrderBuilder $adminBuilder, $isNewCreditRow = false)
+ {
+ parent::__construct($adminBuilder);
+ $this->isNewCreditRow = $isNewCreditRow;
+ }
+
+ /**
+ * Validate order data
+ */
+ public function validate()
+ {
+ $errors = [];
+
+ $orderId = $this->adminBuilder->orderId;
+ if (empty($orderId) || !is_int($orderId)) {
+ $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
+ }
+
+ $deliveryId = $this->adminBuilder->deliveryId;
+ if (is_int($deliveryId) || (is_float($deliveryId) && $deliveryId > 2147483647))
+ {
+
+ }
+ else
+ {
+ $errors['incorrect Delivery Id'] = "Delivery Id can't be empty and must be Integer";
+ }
+
+ if ($this->isNewCreditRow === true) {
+ $creditOrderRows = $this->adminBuilder->creditOrderRows;
+
+ if (count($creditOrderRows) > 1) {
+ $errors['incorrect New Credit Row'] = "Only one Credit row can be set!";
+ }
+
+ $newCreditRow = $creditOrderRows[0];
+ if (!($newCreditRow instanceof OrderRow)) {
+ $errors['incorrect New Credit Row'] = "New Credit Row can't be empty and must be array";
+ } else {
+ foreach ($creditOrderRows as $orderRow) {
+ if (!isset($orderRow->vatPercent)) {
+ $errors['missing order row vat information'] = "cannot calculate orderRow vatPercent, need to set vatPercent.";
+ }
+
+ if (!is_float($orderRow->amountIncVat) && $orderRow->amountIncVat !== 0) {
+ $errors['missing order row amount information'] = "cannot calculate orderRow amount, need to set value for amountIncVat.";
+ }
+ }
+ }
+ } else {
+ $orderRowIds = $this->adminBuilder->rowsToCredit;
+ if (is_array($orderRowIds) && count($orderRowIds) > 0) {
+ foreach ($orderRowIds as $orderRowId) {
+ if (empty($orderRowId) || !is_int($orderRowId)) {
+ $errors['incorrect Order Row Id'] = "Order Row Id can't be empty and must be Integer";
+ }
+ }
+ } else {
+ $errors['missing order rows'] = "must be at least one Order row set.";
+ }
+ }
+
+ $this->processErrors($errors);
+ }
+
+ /**
+ * Format given date so that will match data structure required for Admin API
+ * @return mixed
+ */
+ public function prepareRequest()
+ {
+ $this->validate();
+
+ $requestData = [
+ 'orderId' => $this->adminBuilder->orderId,
+ 'deliveryId' => $this->adminBuilder->deliveryId
+ ];
+
+ if (!empty($this->adminBuilder->rowsToCredit)) {
+ $requestData['orderRowIds'] = $this->adminBuilder->rowsToCredit;
+ } elseif (count($this->adminBuilder->creditOrderRows) > 0) {
+ /**
+ * @var OrderRow $orderRow
+ */
+ $orderRow = $this->adminBuilder->creditOrderRows[0];
+
+ $requestData['newCreditRow'] = [
+ 'name' => $orderRow->name,
+ 'quantity' => intval((string)Helper::bround($orderRow->quantity, 2) * 100),
+ 'unitPrice' => intval((string)Helper::bround($orderRow->amountIncVat, 2) * 100),
+ 'vatPercent' => intval((string)Helper::bround($orderRow->vatPercent, 2) * 100)
+ ];
+ }
+
+ return $requestData;
+ }
+
+ /**
+ * Send call Connection Library
+ */
+ public function doRequest()
+ {
+ $preparedData = $this->prepareRequest();
+ if ($this->isNewCreditRow === true) {
+ $response = $this->checkoutAdminConnection->creditNewOrderRow($preparedData);
+ } else {
+ $response = $this->checkoutAdminConnection->creditOrderRows($preparedData);
+ }
+
+ return $response;
+ }
}
diff --git a/src/Checkout/Service/Admin/DeliverOrderService.php b/src/Checkout/Service/Admin/DeliverOrderService.php
index 02c90f5a..505bf3e0 100644
--- a/src/Checkout/Service/Admin/DeliverOrderService.php
+++ b/src/Checkout/Service/Admin/DeliverOrderService.php
@@ -7,83 +7,83 @@
class DeliverOrderService extends AdminImplementationService
{
- /**
- * @var DeliverOrderRowsBuilder $adminBuilder
- */
- public $adminBuilder;
+ /**
+ * @var DeliverOrderRowsBuilder $adminBuilder
+ */
+ public $adminBuilder;
- /**
- * @var bool $isDeliverOrderRows
- */
- protected $isDeliverOrderRows;
+ /**
+ * @var bool $isDeliverOrderRows
+ */
+ protected $isDeliverOrderRows;
- /**
- * DeliverOrderService constructor.
- * @param CheckoutAdminOrderBuilder $adminBuilder
- * @param bool $isDeliverOrderRows
- */
- public function __construct(CheckoutAdminOrderBuilder $adminBuilder, $isDeliverOrderRows = false)
- {
- parent::__construct($adminBuilder);
- $this->isDeliverOrderRows = $isDeliverOrderRows;
- }
+ /**
+ * DeliverOrderService constructor.
+ * @param CheckoutAdminOrderBuilder $adminBuilder
+ * @param bool $isDeliverOrderRows
+ */
+ public function __construct(CheckoutAdminOrderBuilder $adminBuilder, $isDeliverOrderRows = false)
+ {
+ parent::__construct($adminBuilder);
+ $this->isDeliverOrderRows = $isDeliverOrderRows;
+ }
- /**
- * Validate order data
- */
- public function validate()
- {
- $errors = array();
+ /**
+ * Validate order data
+ */
+ public function validate()
+ {
+ $errors = [];
- $orderId = $this->adminBuilder->orderId;
- if (empty($orderId) || !is_int($orderId)) {
- $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
- }
+ $orderId = $this->adminBuilder->orderId;
+ if (empty($orderId) || !is_int($orderId)) {
+ $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
+ }
- if ($this->isDeliverOrderRows === true) {
- $orderRowIds = $this->adminBuilder->rowsToDeliver;
- if (!is_array($orderRowIds) || count($orderRowIds) === 0) {
- $errors['incorrect Order Row Ids'] = "Order Row Ids must be array of integers!";
- }
- foreach ($orderRowIds as $orderRowId) {
- if (empty($orderRowId) || !is_int($orderRowId)) {
- $errors['incorrect Order Row Id'] = "Order Row Id can't be empty and must be Integer";
- }
- }
- }
+ if ($this->isDeliverOrderRows === true) {
+ $orderRowIds = $this->adminBuilder->rowsToDeliver;
+ if (!is_array($orderRowIds) || count($orderRowIds) === 0) {
+ $errors['incorrect Order Row Ids'] = "Order Row Ids must be array of integers!";
+ }
+ foreach ($orderRowIds as $orderRowId) {
+ if (empty($orderRowId) || !is_int($orderRowId)) {
+ $errors['incorrect Order Row Id'] = "Order Row Id can't be empty and must be Integer";
+ }
+ }
+ }
- $this->processErrors($errors);
- }
+ $this->processErrors($errors);
+ }
- /**
- * Format given date so that will match data structure required for Admin API
- * @return mixed|void
- */
- public function prepareRequest()
- {
- $this->validate();
+ /**
+ * Format given date so that will match data structure required for Admin API
+ * @return mixed|void
+ */
+ public function prepareRequest()
+ {
+ $this->validate();
- $requestData = array(
- 'orderId' => $this->adminBuilder->orderId
- );
+ $requestData = [
+ 'orderId' => $this->adminBuilder->orderId
+ ];
- $orderRowIds = array();
- if ($this->isDeliverOrderRows === true) {
- $orderRowIds = $this->adminBuilder->rowsToDeliver;
- }
- $requestData['orderRowIds'] = $orderRowIds;
+ $orderRowIds = [];
+ if ($this->isDeliverOrderRows === true) {
+ $orderRowIds = $this->adminBuilder->rowsToDeliver;
+ }
+ $requestData['orderRowIds'] = $orderRowIds;
- return $requestData;
- }
+ return $requestData;
+ }
- /**
- * Send call Connection Library
- */
- public function doRequest()
- {
- $preparedData = $this->prepareRequest();
- $response = $this->checkoutAdminConnection->deliverOrder($preparedData);
+ /**
+ * Send call Connection Library
+ */
+ public function doRequest()
+ {
+ $preparedData = $this->prepareRequest();
+ $response = $this->checkoutAdminConnection->deliverOrder($preparedData);
- return $response;
- }
+ return $response;
+ }
}
diff --git a/src/Checkout/Service/Admin/GetOrderService.php b/src/Checkout/Service/Admin/GetOrderService.php
index f96fd67c..a555d862 100644
--- a/src/Checkout/Service/Admin/GetOrderService.php
+++ b/src/Checkout/Service/Admin/GetOrderService.php
@@ -6,49 +6,49 @@
class GetOrderService extends AdminImplementationService
{
- /**
- * @var QueryOrderBuilder $adminBuilder
- */
- public $adminBuilder;
-
- /**
- * Validate order data
- */
- public function validate()
- {
- $errors = array();
-
- $orderId = $this->adminBuilder->orderId;
- if (empty($orderId) || !is_int($orderId)) {
- $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
- }
-
- $this->processErrors($errors);
- }
-
- /**
- * Format given date so that will match data structure required for Admin API
- * @return mixed
- */
- public function prepareRequest()
- {
- $this->validate();
-
- $requestData = array(
- 'orderId' => $this->adminBuilder->orderId
- );
-
- return $requestData;
- }
-
- /**
- * Send call Connection Library
- */
- public function doRequest()
- {
- $preparedData = $this->prepareRequest();
- $response = $this->checkoutAdminConnection->getOrder($preparedData);
-
- return $response;
- }
+ /**
+ * @var QueryOrderBuilder $adminBuilder
+ */
+ public $adminBuilder;
+
+ /**
+ * Validate order data
+ */
+ public function validate()
+ {
+ $errors = [];
+
+ $orderId = $this->adminBuilder->orderId;
+ if (empty($orderId) || !is_int($orderId)) {
+ $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
+ }
+
+ $this->processErrors($errors);
+ }
+
+ /**
+ * Format given date so that will match data structure required for Admin API
+ * @return mixed
+ */
+ public function prepareRequest()
+ {
+ $this->validate();
+
+ $requestData = [
+ 'orderId' => $this->adminBuilder->orderId
+ ];
+
+ return $requestData;
+ }
+
+ /**
+ * Send call Connection Library
+ */
+ public function doRequest()
+ {
+ $preparedData = $this->prepareRequest();
+ $response = $this->checkoutAdminConnection->getOrder($preparedData);
+
+ return $response;
+ }
}
diff --git a/src/Checkout/Service/Admin/GetTaskInfoService.php b/src/Checkout/Service/Admin/GetTaskInfoService.php
index f8a23907..25b39142 100644
--- a/src/Checkout/Service/Admin/GetTaskInfoService.php
+++ b/src/Checkout/Service/Admin/GetTaskInfoService.php
@@ -6,51 +6,51 @@
class GetTaskInfoService extends AdminImplementationService
{
- /**
- * @var QueryTaskInfoBuilder $adminBuilder
- */
- public $adminBuilder;
-
- /**
- * Send call Connection Library
- */
- public function doRequest()
- {
- $preparedData = $this->prepareRequest();
- $response = $this->checkoutAdminConnection->getTask($preparedData);
-
- return $response;
- }
-
- /**
- * Format given date so that will match data structure required for Admin API
- * @return mixed
- */
- public function prepareRequest()
- {
- $this->validate();
-
- $requestData = array(
- 'locationUrl' => $this->adminBuilder->taskUrl
- );
-
- return $requestData;
- }
-
- /**
- * Validate order data
- */
- public function validate()
- {
- $errors = array();
-
- $taskUrl = $this->adminBuilder->taskUrl;
-
- if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $taskUrl)
- ) {
- $errors['incorrect Task URL'] = "Task Url must be valid Task Location URL string";
- }
-
- $this->processErrors($errors);
- }
+ /**
+ * @var QueryTaskInfoBuilder $adminBuilder
+ */
+ public $adminBuilder;
+
+ /**
+ * Send call Connection Library
+ */
+ public function doRequest()
+ {
+ $preparedData = $this->prepareRequest();
+ $response = $this->checkoutAdminConnection->getTask($preparedData);
+
+ return $response;
+ }
+
+ /**
+ * Format given date so that will match data structure required for Admin API
+ * @return mixed
+ */
+ public function prepareRequest()
+ {
+ $this->validate();
+
+ $requestData = [
+ 'locationUrl' => $this->adminBuilder->taskUrl
+ ];
+
+ return $requestData;
+ }
+
+ /**
+ * Validate order data
+ */
+ public function validate()
+ {
+ $errors = [];
+
+ $taskUrl = $this->adminBuilder->taskUrl;
+
+ if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $taskUrl)
+ ) {
+ $errors['incorrect Task URL'] = "Task Url must be valid Task Location URL string";
+ }
+
+ $this->processErrors($errors);
+ }
}
diff --git a/src/Checkout/Service/Admin/UpdateOrderRowsService.php b/src/Checkout/Service/Admin/UpdateOrderRowsService.php
index d0c57831..eed141f5 100644
--- a/src/Checkout/Service/Admin/UpdateOrderRowsService.php
+++ b/src/Checkout/Service/Admin/UpdateOrderRowsService.php
@@ -8,74 +8,74 @@
class UpdateOrderRowsService extends AdminImplementationService
{
- /**
- * @var UpdateOrderRowsBuilder $adminBuilder
- */
- public $adminBuilder;
+ /**
+ * @var UpdateOrderRowsBuilder $adminBuilder
+ */
+ public $adminBuilder;
- /**
- * Validate order data
- */
- public function validate()
- {
- $validator = new UpdateOrderRowValidator();
- $errors = $validator->validate($this->adminBuilder);
+ /**
+ * Validate order data
+ */
+ public function validate()
+ {
+ $validator = new UpdateOrderRowValidator();
+ $errors = $validator->validate($this->adminBuilder);
- $this->processErrors($errors);
- }
+ $this->processErrors($errors);
+ }
- /**
- * Format given date so that will match data structure required for Admin API
- * @return mixed
- */
- public function prepareRequest()
- {
- $this->validate();
+ /**
+ * Format given date so that will match data structure required for Admin API
+ * @return mixed
+ */
+ public function prepareRequest()
+ {
+ $this->validate();
- $requestData = array(
- 'orderId' => $this->adminBuilder->orderId,
- 'orderRowId' => $this->adminBuilder->numberedOrderRows[0]->rowNumber,
- 'orderRow' => $this->formatOrderRowValues()
- );
+ $requestData = [
+ 'orderId' => $this->adminBuilder->orderId,
+ 'orderRowId' => $this->adminBuilder->numberedOrderRows[0]->rowNumber,
+ 'orderRow' => $this->formatOrderRowValues()
+ ];
- return $requestData;
- }
+ return $requestData;
+ }
- /**
- * Send call Connection Library
- */
- public function doRequest()
- {
- $preparedData = $this->prepareRequest();
- $response = $this->checkoutAdminConnection->updateOrderRow($preparedData);
+ /**
+ * Send call Connection Library
+ */
+ public function doRequest()
+ {
+ $preparedData = $this->prepareRequest();
+ $response = $this->checkoutAdminConnection->updateOrderRow($preparedData);
- return $response;
- }
+ return $response;
+ }
- private function formatOrderRowValues()
- {
- $requestOrderRow = array();
+ private function formatOrderRowValues()
+ {
+ $requestOrderRow = [];
- $rowData = $this->adminBuilder->numberedOrderRows[0];
- foreach ($rowData as $orderRowKey => $orderRowValue) {
- switch ($orderRowKey) {
- case 'amountIncVat':
- $requestOrderRow['unitPrice'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
- break;
- case 'vatPercent':
- $requestOrderRow['vatPercent'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
- break;
- case 'discountPercent':
- $requestOrderRow['discountPercent'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
- break;
- case 'quantity':
- $requestOrderRow['quantity'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
- break;
- default:
- $requestOrderRow[$orderRowKey] = $orderRowValue;
- }
- }
+ $rowData = $this->adminBuilder->numberedOrderRows[0];
+ foreach ($rowData as $orderRowKey => $orderRowValue) {
+ switch ($orderRowKey) {
+ case 'amountIncVat':
+ $requestOrderRow['unitPrice'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
+ break;
+ case 'vatPercent':
+ $requestOrderRow['vatPercent'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
+ break;
+ case 'discountPercent':
+ $requestOrderRow['discountPercent'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
+ break;
+ case 'quantity':
+ $requestOrderRow['quantity'] = intval((string)Helper::bround($orderRowValue, 2) * 100);
+ break;
+ default:
+ $requestOrderRow[$orderRowKey] = $orderRowValue;
+ }
+ }
- return $requestOrderRow;
- }
+ return $requestOrderRow;
+ }
}
diff --git a/src/Checkout/Service/CheckoutService.php b/src/Checkout/Service/CheckoutService.php
index 810009d7..afd691cf 100644
--- a/src/Checkout/Service/CheckoutService.php
+++ b/src/Checkout/Service/CheckoutService.php
@@ -14,105 +14,105 @@
*/
abstract class CheckoutService
{
- protected $order;
-
- /**
- * @var ServiceConnection
- */
- protected $serviceConnection;
-
- /**
- * CheckoutService constructor.
- *
- * @param $order
- */
- public function __construct($order)
- {
- $this->order = $order;
- $this->serviceConnection = new CheckoutServiceConnection($this->order->conf, $this->order->getCountryCode());
- }
-
- /**
- * Validate order data
- */
- abstract protected function validateOrder();
-
- /**
- * Format given order so that will match data structure required for API
- */
- abstract protected function prepareRequest();
-
- /**
- * Send call Connection Library
- */
- abstract public function doRequest();
-
-
- /**
- * @return mixed
- */
- protected function formatOrderInformationWithOrderRows()
- {
- $formatter = new CheckoutRowFormatter($this->order);
- $formattedOrderRows = $formatter->formatRows();
-
- return $formattedOrderRows;
- }
-
- /**
- * Translate SveaOrderRow to CheckoutOrderRow and return result as array
- *
- * @param \Svea\WebPay\WebService\SveaSoap\SveaOrderRow $item
- * @return array
- */
- protected function mapOrderItem($item)
- {
- $checkoutOrderItem = new CheckoutOrderRow();
-
- if (isset($item->Name)) {
- $checkoutOrderItem->setName($item->Name);
- }
- if (isset($item->ArticleNumber)) {
- $checkoutOrderItem->setArticleNumber($item->ArticleNumber);
- }
- if (isset($item->PricePerUnit)) {
- $checkoutOrderItem->setUnitPrice($item->PricePerUnit);
- }
- if (isset($item->VatPercent)) {
- $checkoutOrderItem->setVatPercent($item->VatPercent);
- }
- if (isset($item->DiscountPercent)) {
- $checkoutOrderItem->setDiscountPercent($item->DiscountPercent);
- }
- if (isset($item->Unit)) {
- $checkoutOrderItem->setUnit($item->Unit);
- }
- if (isset($item->NumberOfUnits)) {
- $checkoutOrderItem->setQuantity($item->NumberOfUnits);
- }
- if (isset($item->TemporaryReference)) {
- $checkoutOrderItem->setTemporaryReference($item->TemporaryReference);
- }
- if (isset($item->MerchantData)) {
- $checkoutOrderItem->setMerchantData($item->MerchantData);
- }
-
- return $checkoutOrderItem->toArray();
- }
-
-
- /**
- * @param array $errors
- * @throws ValidationException
- */
- protected function processErrors(array $errors)
- {
- if (count($errors) > 0) {
- $message = '';
- foreach ($errors as $key => $val) {
- $message .= " - $key : $val" . PHP_EOL;
- }
- throw new ValidationException($message);
- }
- }
+ protected $order;
+
+ /**
+ * @var ServiceConnection
+ */
+ protected $serviceConnection;
+
+ /**
+ * CheckoutService constructor.
+ *
+ * @param $order
+ */
+ public function __construct($order)
+ {
+ $this->order = $order;
+ $this->serviceConnection = new CheckoutServiceConnection($this->order->conf, $this->order->getCountryCode());
+ }
+
+ /**
+ * Validate order data
+ */
+ abstract protected function validateOrder();
+
+ /**
+ * Format given order so that will match data structure required for API
+ */
+ abstract protected function prepareRequest();
+
+ /**
+ * Send call Connection Library
+ */
+ abstract public function doRequest();
+
+
+ /**
+ * @return mixed
+ */
+ protected function formatOrderInformationWithOrderRows()
+ {
+ $formatter = new CheckoutRowFormatter($this->order);
+ $formattedOrderRows = $formatter->formatRows();
+
+ return $formattedOrderRows;
+ }
+
+ /**
+ * Translate SveaOrderRow to CheckoutOrderRow and return result as array
+ *
+ * @param \Svea\WebPay\WebService\SveaSoap\SveaOrderRow $item
+ * @return array
+ */
+ protected function mapOrderItem($item)
+ {
+ $checkoutOrderItem = new CheckoutOrderRow();
+
+ if (isset($item->Name)) {
+ $checkoutOrderItem->setName($item->Name);
+ }
+ if (isset($item->ArticleNumber)) {
+ $checkoutOrderItem->setArticleNumber($item->ArticleNumber);
+ }
+ if (isset($item->PricePerUnit)) {
+ $checkoutOrderItem->setUnitPrice($item->PricePerUnit);
+ }
+ if (isset($item->VatPercent)) {
+ $checkoutOrderItem->setVatPercent($item->VatPercent);
+ }
+ if (isset($item->DiscountPercent)) {
+ $checkoutOrderItem->setDiscountPercent($item->DiscountPercent);
+ }
+ if (isset($item->Unit)) {
+ $checkoutOrderItem->setUnit($item->Unit);
+ }
+ if (isset($item->NumberOfUnits)) {
+ $checkoutOrderItem->setQuantity($item->NumberOfUnits);
+ }
+ if (isset($item->TemporaryReference)) {
+ $checkoutOrderItem->setTemporaryReference($item->TemporaryReference);
+ }
+ if (isset($item->MerchantData)) {
+ $checkoutOrderItem->setMerchantData($item->MerchantData);
+ }
+
+ return $checkoutOrderItem->toArray();
+ }
+
+
+ /**
+ * @param array $errors
+ * @throws ValidationException
+ */
+ protected function processErrors(array $errors)
+ {
+ if (count($errors) > 0) {
+ $message = '';
+ foreach ($errors as $key => $val) {
+ $message .= " - $key : $val" . PHP_EOL;
+ }
+ throw new ValidationException($message);
+ }
+ }
}
diff --git a/src/Checkout/Service/Connection/CheckoutAdminConnection.php b/src/Checkout/Service/Connection/CheckoutAdminConnection.php
index b24dcb6a..9a7087c7 100644
--- a/src/Checkout/Service/Connection/CheckoutAdminConnection.php
+++ b/src/Checkout/Service/Connection/CheckoutAdminConnection.php
@@ -9,106 +9,106 @@
class CheckoutAdminConnection
{
- /**
- * @var \Svea\WebPay\Config\ConfigurationProvider
- */
- protected $config;
-
- /**
- * @var Connector
- */
- protected $connector;
-
- /**
- * @var CheckoutAdminClient
- */
- protected $checkoutClient;
-
- /**
- * @var CheckoutAdminClient
- */
- protected $countryCode;
-
- /**
- * CheckoutServiceConnection constructor.
- * @param $config
- */
- public function __construct(ConfigurationProvider $config, $countryCode = NULL)
- {
- $this->config = $config;
- $this->countryCode = $countryCode;
-
- $this->setConnector();
- $this->setClient();
- }
-
- public function getOrder($requestData)
- {
- return CheckoutAdminResponseHelper::processResponse($this->checkoutClient->getOrder($requestData));
- }
-
- public function deliverOrder($requestData)
- {
- return $this->checkoutClient->deliverOrder($requestData);
- }
-
- public function cancelOrder($requestData)
- {
- return $this->checkoutClient->cancelOrder($requestData);
- }
-
- public function cancelOrderAmount($requestData)
- {
- return $this->checkoutClient->cancelOrderAmount($requestData);
- }
-
- public function cancelOrderRow($requestData)
- {
- return $this->checkoutClient->cancelOrderRow($requestData);
- }
-
- /* Credit */
- public function creditOrderRows($requestData)
- {
- return $this->checkoutClient->creditOrderRows($requestData);
- }
-
- public function creditNewOrderRow($requestData)
- {
- return $this->checkoutClient->creditNewOrderRow($requestData);
- }
-
- public function creditOrderAmount($requestData)
- {
- return $this->checkoutClient->creditOrderAmount($requestData);
- }
-
- public function addOrderRow($requestData)
- {
- return $this->checkoutClient->addOrderRow($requestData);
- }
-
- public function updateOrderRow($requestData)
- {
- return $this->checkoutClient->updateOrderRow($requestData);
- }
-
- public function getTask($requestData)
- {
- return $this->checkoutClient->getTask($requestData);
- }
-
- private function setConnector()
- {
- $this->connector = Connector::init(
- $this->config->getCheckoutMerchantId($this->countryCode),
- $this->config->getCheckoutSecret($this->countryCode),
- $this->config->getEndPoint(ConfigurationProvider::CHECKOUT_ADMIN)
- );
- }
-
- private function setClient()
- {
- $this->checkoutClient = new CheckoutAdminClient($this->connector);
- }
+ /**
+ * @var \Svea\WebPay\Config\ConfigurationProvider
+ */
+ protected $config;
+
+ /**
+ * @var Connector
+ */
+ protected $connector;
+
+ /**
+ * @var CheckoutAdminClient
+ */
+ protected $checkoutClient;
+
+ /**
+ * @var CheckoutAdminClient
+ */
+ protected $countryCode;
+
+ /**
+ * CheckoutServiceConnection constructor.
+ * @param $config
+ */
+ public function __construct(ConfigurationProvider $config, $countryCode = NULL)
+ {
+ $this->config = $config;
+ $this->countryCode = $countryCode;
+
+ $this->setConnector();
+ $this->setClient();
+ }
+
+ public function getOrder($requestData)
+ {
+ return CheckoutAdminResponseHelper::processResponse($this->checkoutClient->getOrder($requestData));
+ }
+
+ public function deliverOrder($requestData)
+ {
+ return $this->checkoutClient->deliverOrder($requestData);
+ }
+
+ public function cancelOrder($requestData)
+ {
+ return $this->checkoutClient->cancelOrder($requestData);
+ }
+
+ public function cancelOrderAmount($requestData)
+ {
+ return $this->checkoutClient->cancelOrderAmount($requestData);
+ }
+
+ public function cancelOrderRow($requestData)
+ {
+ return $this->checkoutClient->cancelOrderRow($requestData);
+ }
+
+ /* Credit */
+ public function creditOrderRows($requestData)
+ {
+ return $this->checkoutClient->creditOrderRows($requestData);
+ }
+
+ public function creditNewOrderRow($requestData)
+ {
+ return $this->checkoutClient->creditNewOrderRow($requestData);
+ }
+
+ public function creditOrderAmount($requestData)
+ {
+ return $this->checkoutClient->creditOrderAmount($requestData);
+ }
+
+ public function addOrderRow($requestData)
+ {
+ return $this->checkoutClient->addOrderRow($requestData);
+ }
+
+ public function updateOrderRow($requestData)
+ {
+ return $this->checkoutClient->updateOrderRow($requestData);
+ }
+
+ public function getTask($requestData)
+ {
+ return $this->checkoutClient->getTask($requestData);
+ }
+
+ private function setConnector()
+ {
+ $this->connector = Connector::init(
+ $this->config->getCheckoutMerchantId($this->countryCode),
+ $this->config->getCheckoutSecret($this->countryCode),
+ $this->config->getEndPoint(ConfigurationProvider::CHECKOUT_ADMIN)
+ );
+ }
+
+ private function setClient()
+ {
+ $this->checkoutClient = new CheckoutAdminClient($this->connector);
+ }
}
diff --git a/src/Checkout/Service/Connection/CheckoutServiceConnection.php b/src/Checkout/Service/Connection/CheckoutServiceConnection.php
index 6abb2de1..54f6ad0c 100644
--- a/src/Checkout/Service/Connection/CheckoutServiceConnection.php
+++ b/src/Checkout/Service/Connection/CheckoutServiceConnection.php
@@ -13,90 +13,90 @@
*/
class CheckoutServiceConnection implements ServiceConnection
{
- /**
- * @var \Svea\WebPay\Config\ConfigurationProvider
- */
- protected $config;
-
- /**
- * @var Connector
- */
- protected $connector;
-
- /**
- * @var CheckoutClient
- */
- protected $checkoutClient;
-
- /**
- * @var string
- */
- protected $countryCode;
-
- /**
- * CheckoutServiceConnection constructor.
- * @param $config
- * @param string $countryCode
- */
- public function __construct(ConfigurationProvider $config, $countryCode)
- {
- $this->config = $config;
- $this->countryCode = $countryCode;
-
- $this->setConnector();
- $this->setClient();
- }
-
-
- private function setConnector()
- {
- $this->connector = Connector::init(
- $this->config->getCheckoutMerchantId(strtolower($this->countryCode)),
- $this->config->getCheckoutSecret(strtolower($this->countryCode)),
- $this->config->getEndPoint(ConfigurationProvider::CHECKOUT)
- );
- }
-
- private function setClient()
- {
- $this->checkoutClient = new CheckoutClient($this->connector);
- }
-
- /**
- * @param mixed $requestData
- * @return mixed
- */
- public function create($requestData)
- {
- return CheckoutResponseHelper::processData($this->checkoutClient->create($requestData));
- }
-
- /**
- * @param mixed $requestData
- * @return mixed
- */
- public function get($requestData)
- {
- return CheckoutResponseHelper::processData($this->checkoutClient->get($requestData));
- }
-
- /**
- * @param mixed $requestData
- * @return mixed
- */
- public function update($requestData)
- {
- $data = $this->checkoutClient->update($requestData);
-
- return CheckoutResponseHelper::processData($data);
- }
-
- /**
- * @param mixed $requestData
- * @return mixed
- */
- public function getAvailablePartPaymentCampaigns($requestData)
- {
- return CheckoutResponseHelper::processData($this->checkoutClient->getAvailablePartPaymentCampaigns($requestData));
- }
+ /**
+ * @var \Svea\WebPay\Config\ConfigurationProvider
+ */
+ protected $config;
+
+ /**
+ * @var Connector
+ */
+ protected $connector;
+
+ /**
+ * @var CheckoutClient
+ */
+ protected $checkoutClient;
+
+ /**
+ * @var string
+ */
+ protected $countryCode;
+
+ /**
+ * CheckoutServiceConnection constructor.
+ * @param $config
+ * @param string $countryCode
+ */
+ public function __construct(ConfigurationProvider $config, $countryCode)
+ {
+ $this->config = $config;
+ $this->countryCode = $countryCode;
+
+ $this->setConnector();
+ $this->setClient();
+ }
+
+
+ private function setConnector()
+ {
+ $this->connector = Connector::init(
+ $this->config->getCheckoutMerchantId(strtolower($this->countryCode)),
+ $this->config->getCheckoutSecret(strtolower($this->countryCode)),
+ $this->config->getEndPoint(ConfigurationProvider::CHECKOUT)
+ );
+ }
+
+ private function setClient()
+ {
+ $this->checkoutClient = new CheckoutClient($this->connector);
+ }
+
+ /**
+ * @param mixed $requestData
+ * @return mixed
+ */
+ public function create($requestData)
+ {
+ return CheckoutResponseHelper::processData($this->checkoutClient->create($requestData));
+ }
+
+ /**
+ * @param mixed $requestData
+ * @return mixed
+ */
+ public function get($requestData)
+ {
+ return CheckoutResponseHelper::processData($this->checkoutClient->get($requestData));
+ }
+
+ /**
+ * @param mixed $requestData
+ * @return mixed
+ */
+ public function update($requestData)
+ {
+ $data = $this->checkoutClient->update($requestData);
+
+ return CheckoutResponseHelper::processData($data);
+ }
+
+ /**
+ * @param mixed $requestData
+ * @return mixed
+ */
+ public function getAvailablePartPaymentCampaigns($requestData)
+ {
+ return CheckoutResponseHelper::processData($this->checkoutClient->getAvailablePartPaymentCampaigns($requestData));
+ }
}
diff --git a/src/Checkout/Service/Connection/ServiceConnection.php b/src/Checkout/Service/Connection/ServiceConnection.php
index 6d877419..5d8dd800 100644
--- a/src/Checkout/Service/Connection/ServiceConnection.php
+++ b/src/Checkout/Service/Connection/ServiceConnection.php
@@ -8,8 +8,8 @@
*/
interface ServiceConnection
{
- public function create($requestData);
- public function get($requestData);
- public function update($requestData);
- public function getAvailablePartPaymentCampaigns($requestData);
+ public function create($requestData);
+ public function get($requestData);
+ public function update($requestData);
+ public function getAvailablePartPaymentCampaigns($requestData);
}
diff --git a/src/Checkout/Service/CreateOrderService.php b/src/Checkout/Service/CreateOrderService.php
index e840d2f1..457b9ce6 100644
--- a/src/Checkout/Service/CreateOrderService.php
+++ b/src/Checkout/Service/CreateOrderService.php
@@ -14,103 +14,103 @@
*/
class CreateOrderService extends CheckoutService
{
- public $requestObject;
-
- /**
- * Send call to Connection Library
- *
- * @return array
- */
- public function doRequest()
- {
- $requestData = $this->prepareRequest();
-
- $response = $this->serviceConnection->create($requestData);
-
- return $response;
- }
-
- /**
- * Process Order for request data for Svea Checkout API
- *
- * @return array
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- protected function prepareRequest()
- {
- $errors = $this->validateOrder();
- $this->processErrors($errors);
- $data = $this->mapCreateOrderData($this->order);
-
- return $data;
- }
-
- /**
- * Validate order data
- *
- * @return array of errors
- */
- protected function validateOrder()
- {
- $validator = new CreateOrderValidator();
- $errors = $validator->validate($this->order);
-
- return $errors;
- }
-
- /**
- * Map Order to array
- *
- * @param CheckoutOrderBuilder $order
- * @return array
- */
- protected function mapCreateOrderData(CheckoutOrderBuilder $order)
- {
- $data = array();
-
- /**
- * @var \Svea\WebPay\WebService\SveaSoap\SveaOrderRow [] $orderItems
- */
- $orderItems = $this->formatOrderInformationWithOrderRows();
-
- foreach ($orderItems as $item) {
- $data['cart']['items'][] = $this->mapOrderItem($item);
- }
-
- $data['currency'] = $order->currency;
- $data['countryCode'] = $order->countryCode;
- $data['locale'] = $order->getLocale();
-
- $data['merchantSettings'] = $order->getMerchantSettings()->getMerchantSettings();
-
- $data['clientOrderNumber'] = $order->getClientOrderNumber();
-
- if (count($order->getPresetValues()) > 0) {
- foreach ($order->getPresetValues() as $presetValue) {
- $data['presetValues'] [] = $presetValue->returnPresetArray();
- }
- }
-
- if ($order->getPartnerKey() != null)
- {
- $data['partnerKey'] = $order->getPartnerKey();
- }
-
- if ($order->getIdentityFlags() != null)
- {
- foreach ($order->getIdentityFlags() as $key => $identityFlag)
- {
- $data['identityFlags'][$identityFlag] = true;
- }
- }
-
- $data['merchantData'] = $order->getMerchantData();
-
- if($order->getRequireElectronicIdAuthentication() != null)
- {
- $data['requireElectronicIdAuthentication'] = $order->getRequireElectronicIdAuthentication();
- }
-
- return $data;
- }
+ public $requestObject;
+
+ /**
+ * Send call to Connection Library
+ *
+ * @return array
+ */
+ public function doRequest()
+ {
+ $requestData = $this->prepareRequest();
+
+ $response = $this->serviceConnection->create($requestData);
+
+ return $response;
+ }
+
+ /**
+ * Process Order for request data for Svea Checkout API
+ *
+ * @return array
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ protected function prepareRequest()
+ {
+ $errors = $this->validateOrder();
+ $this->processErrors($errors);
+ $data = $this->mapCreateOrderData($this->order);
+
+ return $data;
+ }
+
+ /**
+ * Validate order data
+ *
+ * @return array of errors
+ */
+ protected function validateOrder()
+ {
+ $validator = new CreateOrderValidator();
+ $errors = $validator->validate($this->order);
+
+ return $errors;
+ }
+
+ /**
+ * Map Order to array
+ *
+ * @param CheckoutOrderBuilder $order
+ * @return array
+ */
+ protected function mapCreateOrderData(CheckoutOrderBuilder $order)
+ {
+ $data = [];
+
+ /**
+ * @var \Svea\WebPay\WebService\SveaSoap\SveaOrderRow [] $orderItems
+ */
+ $orderItems = $this->formatOrderInformationWithOrderRows();
+
+ foreach ($orderItems as $item) {
+ $data['cart']['items'][] = $this->mapOrderItem($item);
+ }
+
+ $data['currency'] = $order->currency;
+ $data['countryCode'] = $order->countryCode;
+ $data['locale'] = $order->getLocale();
+
+ $data['merchantSettings'] = $order->getMerchantSettings()->getMerchantSettings();
+
+ $data['clientOrderNumber'] = $order->getClientOrderNumber();
+
+ if (count($order->getPresetValues()) > 0) {
+ foreach ($order->getPresetValues() as $presetValue) {
+ $data['presetValues'] [] = $presetValue->returnPresetArray();
+ }
+ }
+
+ if ($order->getPartnerKey() != null)
+ {
+ $data['partnerKey'] = $order->getPartnerKey();
+ }
+
+ if ($order->getIdentityFlags() != null)
+ {
+ foreach ($order->getIdentityFlags() as $key => $identityFlag)
+ {
+ $data['identityFlags'][$identityFlag] = true;
+ }
+ }
+
+ $data['merchantData'] = $order->getMerchantData();
+
+ if($order->getRequireElectronicIdAuthentication() != null)
+ {
+ $data['requireElectronicIdAuthentication'] = $order->getRequireElectronicIdAuthentication();
+ }
+
+ return $data;
+ }
}
diff --git a/src/Checkout/Service/GetAvailablePartPaymentCampaignsService.php b/src/Checkout/Service/GetAvailablePartPaymentCampaignsService.php
index b14b7c0b..92171e59 100644
--- a/src/Checkout/Service/GetAvailablePartPaymentCampaignsService.php
+++ b/src/Checkout/Service/GetAvailablePartPaymentCampaignsService.php
@@ -12,66 +12,66 @@
*/
class GetAvailablePartPaymentCampaignsService extends CheckoutService
{
- /*
- * Send call Connection Library
- * @return mixed
- */
- public function doRequest()
- {
- $requestData = $this->prepareRequest();
+ /*
+ * Send call Connection Library
+ * @return mixed
+ */
+ public function doRequest()
+ {
+ $requestData = $this->prepareRequest();
- foreach($requestData['presetValues'] as $presetValue)
- {
- if(strtolower($presetValue['typeName']) == 'iscompany')
- {
- $requestData = array(
- 'isCompany' => $presetValue['value']
- );
- }
- }
+ foreach($requestData['presetValues'] as $presetValue)
+ {
+ if(strtolower($presetValue['typeName']) == 'iscompany')
+ {
+ $requestData = [
+ 'isCompany' => $presetValue['value']
+ ];
+ }
+ }
- if(!isset($requestData))
- {
- $requestData = null;
- }
+ if(!isset($requestData))
+ {
+ $requestData = null;
+ }
- $response = $this->serviceConnection->getAvailablePartPaymentCampaigns($requestData);
+ $response = $this->serviceConnection->getAvailablePartPaymentCampaigns($requestData);
- return $response;
- }
+ return $response;
+ }
- /**
- * Validate order data
- * @return array|mixed
- */
- protected function validateOrder()
- {
- $validator = new GetAvailablePartPaymentCampaignsValidator();
- $errors = $validator->validate($this->order);
+ /**
+ * Validate order data
+ * @return array|mixed
+ */
+ protected function validateOrder()
+ {
+ $validator = new GetAvailablePartPaymentCampaignsValidator();
+ $errors = $validator->validate($this->order);
- return $errors;
- }
+ return $errors;
+ }
- /**
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- protected function prepareRequest()
- {
- $errors = $this->validateOrder();
- $this->processErrors($errors);
- $data = $this->mapPresetValue($this->order);
+ /**
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ protected function prepareRequest()
+ {
+ $errors = $this->validateOrder();
+ $this->processErrors($errors);
+ $data = $this->mapPresetValue($this->order);
- return $data;
- }
+ return $data;
+ }
- protected function mapPresetValue(CheckoutOrderBuilder $request)
- {
- $data = array();
- if (count($request->getPresetValues()) > 0) {
- foreach ($request->getPresetValues() as $presetValue) {
- $data['presetValues'] [] = $presetValue->returnPresetArray();
- }
- }
- return $data;
- }
+ protected function mapPresetValue(CheckoutOrderBuilder $request)
+ {
+ $data = [];
+ if (count($request->getPresetValues()) > 0) {
+ foreach ($request->getPresetValues() as $presetValue) {
+ $data['presetValues'] [] = $presetValue->returnPresetArray();
+ }
+ }
+ return $data;
+ }
}
diff --git a/src/Checkout/Service/GetOrderService.php b/src/Checkout/Service/GetOrderService.php
index d1796f6e..a02c5315 100644
--- a/src/Checkout/Service/GetOrderService.php
+++ b/src/Checkout/Service/GetOrderService.php
@@ -11,40 +11,40 @@
*/
class GetOrderService extends CheckoutService
{
- /**
- * Send call Connection Library
- * @return mixed
- */
- public function doRequest()
- {
- $this->prepareRequest();
-
- $requestData = array(
- 'orderId' => $this->order->getId()
- );
- $response = $this->serviceConnection->get($requestData);
-
- return $response;
- }
-
- /**
- * Validate order data
- * @return array|mixed
- */
- protected function validateOrder()
- {
- $validator = new GetOrderValidator();
- $errors = $validator->validate($this->order);
-
- return $errors;
- }
-
- /**
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- protected function prepareRequest()
- {
- $errors = $this->validateOrder();
- $this->processErrors($errors);
- }
+ /**
+ * Send call Connection Library
+ * @return mixed
+ */
+ public function doRequest()
+ {
+ $this->prepareRequest();
+
+ $requestData = [
+ 'orderId' => $this->order->getId()
+ ];
+ $response = $this->serviceConnection->get($requestData);
+
+ return $response;
+ }
+
+ /**
+ * Validate order data
+ * @return array|mixed
+ */
+ protected function validateOrder()
+ {
+ $validator = new GetOrderValidator();
+ $errors = $validator->validate($this->order);
+
+ return $errors;
+ }
+
+ /**
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ protected function prepareRequest()
+ {
+ $errors = $this->validateOrder();
+ $this->processErrors($errors);
+ }
}
diff --git a/src/Checkout/Service/UpdateOrderService.php b/src/Checkout/Service/UpdateOrderService.php
index a1e6f0a7..fcfbb037 100644
--- a/src/Checkout/Service/UpdateOrderService.php
+++ b/src/Checkout/Service/UpdateOrderService.php
@@ -11,61 +11,61 @@
*/
class UpdateOrderService extends CheckoutService
{
- public $requestObject;
+ public $requestObject;
- /**
- * Send call Connection Library
- */
- public function doRequest()
- {
- $requestData = $this->prepareRequest();
-
- $response = $this->serviceConnection->update($requestData);
+ /**
+ * Send call Connection Library
+ */
+ public function doRequest()
+ {
+ $requestData = $this->prepareRequest();
- return $response;
- }
+ $response = $this->serviceConnection->update($requestData);
- /**
- * Process Order for request data for Svea Checkout API
- * @return array
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- protected function prepareRequest()
- {
- $errors = $this->validateOrder();
- $this->processErrors($errors);
- $data = $this->mapCreateOrderData($this->order);
+ return $response;
+ }
- return $data;
- }
+ /**
+ * Process Order for request data for Svea Checkout API
+ * @return array
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ protected function prepareRequest()
+ {
+ $errors = $this->validateOrder();
+ $this->processErrors($errors);
+ $data = $this->mapCreateOrderData($this->order);
- /**
- * Validate order data
- */
- protected function validateOrder()
- {
- $validator = new UpdateOrderValidator();
- $errors = $validator->validate($this->order);
+ return $data;
+ }
- return $errors;
- }
+ /**
+ * Validate order data
+ */
+ protected function validateOrder()
+ {
+ $validator = new UpdateOrderValidator();
+ $errors = $validator->validate($this->order);
- /**
- * Map Order to array
- * @param CheckoutOrderBuilder $order
- * @return array
- */
- protected function mapCreateOrderData(CheckoutOrderBuilder $order)
- {
- $data = array();
- $orderItems = $this->formatOrderInformationWithOrderRows();
+ return $errors;
+ }
- foreach ($orderItems as $item) {
- $data['cart']['items'][] = $this->mapOrderItem($item);
- }
+ /**
+ * Map Order to array
+ * @param CheckoutOrderBuilder $order
+ * @return array
+ */
+ protected function mapCreateOrderData(CheckoutOrderBuilder $order)
+ {
+ $data = [];
+ $orderItems = $this->formatOrderInformationWithOrderRows();
- $data['orderId'] = $order->getId();
- $data['merchantData'] = $order->getMerchantData();
- return $data;
- }
+ foreach ($orderItems as $item) {
+ $data['cart']['items'][] = $this->mapOrderItem($item);
+ }
+
+ $data['orderId'] = $order->getId();
+ $data['merchantData'] = $order->getMerchantData();
+ return $data;
+ }
}
diff --git a/src/Checkout/Validation/Admin/AddOrderRowValidator.php b/src/Checkout/Validation/Admin/AddOrderRowValidator.php
index 17f54d2f..c1c57f84 100644
--- a/src/Checkout/Validation/Admin/AddOrderRowValidator.php
+++ b/src/Checkout/Validation/Admin/AddOrderRowValidator.php
@@ -7,58 +7,58 @@
class AddOrderRowValidator extends OrderValidator
{
- public $errors = array();
+ public $errors = [];
- /**
- * @param AddOrderRowsBuilder $adminBuilder
- * @return array
- */
- public function validate($adminBuilder)
- {
- $errors = $this->errors;
+ /**
+ * @param AddOrderRowsBuilder $adminBuilder
+ * @return array
+ */
+ public function validate($adminBuilder)
+ {
+ $errors = $this->errors;
- $orderId = $adminBuilder->orderId;
- $orderRow = $adminBuilder->orderRows;
+ $orderId = $adminBuilder->orderId;
+ $orderRow = $adminBuilder->orderRows;
- if (empty($orderId) || !is_int($orderId)) {
- $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
- }
+ if (empty($orderId) || !is_int($orderId)) {
+ $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
+ }
- if (empty($orderRow)) {
- $errors['incorrect Order Row data'] = "Order Row data can't be empty and must be Array";
- }
+ if (empty($orderRow)) {
+ $errors['incorrect Order Row data'] = "Order Row data can't be empty and must be Array";
+ }
- if (count($orderRow) > 1) {
- $errors['incorrect Order Row data'] = "You can Add just one Order Row";
- }
+ if (count($orderRow) > 1) {
+ $errors['incorrect Order Row data'] = "You can Add just one Order Row";
+ }
- $errors = $this->validateOrderRows($adminBuilder, $errors);
+ $errors = $this->validateOrderRows($adminBuilder, $errors);
- return $errors;
- }
+ return $errors;
+ }
- /**
- * @param object $order
- * @param array $errors
- * @return array
- */
- protected function validateOrderRows($order, $errors)
- {
- $errors = parent::validateOrderRows($order, $errors);
- $errors = $this->validateCheckoutOrderRows($order, $errors);
+ /**
+ * @param object $order
+ * @param array $errors
+ * @return array
+ */
+ protected function validateOrderRows($order, $errors)
+ {
+ $errors = parent::validateOrderRows($order, $errors);
+ $errors = $this->validateCheckoutOrderRows($order, $errors);
- if (empty($order->orderRows[0]->amountIncVat)) {
- $errors['incorrect Order Row data'] = "This function support only amountIncVat you need to use ->setAmountIncVat()";
- }
+ if (empty($order->orderRows[0]->amountIncVat)) {
+ $errors['incorrect Order Row data'] = "This function support only amountIncVat you need to use ->setAmountIncVat()";
+ }
- foreach ($order->orderRows as $row) {
- if (isset($row->discountPercent)) {
- if (!is_int($row->discountPercent) || ($row->discountPercent < 0 || $row->discountPercent > 99)) {
- $errors['bad discount percent'] = "Discount percent must be integer in value range of 0-99";
- }
- }
- }
+ foreach ($order->orderRows as $row) {
+ if (isset($row->discountPercent)) {
+ if (!is_int($row->discountPercent) || ($row->discountPercent < 0 || $row->discountPercent > 99)) {
+ $errors['bad discount percent'] = "Discount percent must be integer in value range of 0-99";
+ }
+ }
+ }
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/Checkout/Validation/Admin/UpdateOrderRowValidator.php b/src/Checkout/Validation/Admin/UpdateOrderRowValidator.php
index a8370b7e..872d13e8 100644
--- a/src/Checkout/Validation/Admin/UpdateOrderRowValidator.php
+++ b/src/Checkout/Validation/Admin/UpdateOrderRowValidator.php
@@ -7,63 +7,63 @@
class UpdateOrderRowValidator extends OrderValidator
{
- public $errors = array();
+ public $errors = [];
- /**
- * @param UpdateOrderRowsBuilder $adminBuilder
- * @return array
- */
- public function validate($adminBuilder)
- {
- $errors = $this->errors;
+ /**
+ * @param UpdateOrderRowsBuilder $adminBuilder
+ * @return array
+ */
+ public function validate($adminBuilder)
+ {
+ $errors = $this->errors;
- $orderId = $adminBuilder->orderId;
- $orderRow = $adminBuilder->numberedOrderRows;
+ $orderId = $adminBuilder->orderId;
+ $orderRow = $adminBuilder->numberedOrderRows;
- if (empty($orderId) || !is_int($orderId)) {
- $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
- }
+ if (empty($orderId) || !is_int($orderId)) {
+ $errors['incorrect Order Id'] = "Order Id can't be empty and must be Integer";
+ }
- if (count($orderRow) == 0) {
- $errors['incorrect Order Row data'] = "Order Row data can't be empty and must be Array";
+ if (count($orderRow) == 0) {
+ $errors['incorrect Order Row data'] = "Order Row data can't be empty and must be Array";
- return $errors;
- }
+ return $errors;
+ }
- if (count($orderRow) > 1) {
- $errors['incorrect Order Row data'] = "You can Update just one Order Row";
+ if (count($orderRow) > 1) {
+ $errors['incorrect Order Row data'] = "You can Update just one Order Row";
- return $errors;
- }
+ return $errors;
+ }
- $errors = $this->validateOrderRows($adminBuilder, $errors);
+ $errors = $this->validateOrderRows($adminBuilder, $errors);
- return $errors;
- }
+ return $errors;
+ }
- /**
- * @param object $order
- * @param array $errors
- * @return array
- */
- protected function validateOrderRows($order, $errors)
- {
- $errors = parent::validateOrderRows($order, $errors);
- $errors = $this->validateCheckoutOrderRows($order, $errors);
+ /**
+ * @param object $order
+ * @param array $errors
+ * @return array
+ */
+ protected function validateOrderRows($order, $errors)
+ {
+ $errors = parent::validateOrderRows($order, $errors);
+ $errors = $this->validateCheckoutOrderRows($order, $errors);
- foreach ($order->numberedOrderRows as $row) {
- if (isset($row->discountPercent)) {
- if (!is_int($row->discountPercent) || ($row->discountPercent < 0 || $row->discountPercent > 99)) {
- $errors['bad discount percent'] = "Discount percent must be integer in value range of 0-99";
- }
- }
- if (isset($row->amountIncVat)) {
- if (!is_float($row->amountIncVat) && $row->amountIncVat !== 0) {
- $errors['missing values'] = "amountIncVat is not of type float.";
- }
- }
- }
+ foreach ($order->numberedOrderRows as $row) {
+ if (isset($row->discountPercent)) {
+ if (!is_int($row->discountPercent) || ($row->discountPercent < 0 || $row->discountPercent > 99)) {
+ $errors['bad discount percent'] = "Discount percent must be integer in value range of 0-99";
+ }
+ }
+ if (isset($row->amountIncVat)) {
+ if (!is_float($row->amountIncVat) && $row->amountIncVat !== 0) {
+ $errors['missing values'] = "amountIncVat is not of type float.";
+ }
+ }
+ }
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/Checkout/Validation/CreateOrderValidator.php b/src/Checkout/Validation/CreateOrderValidator.php
index f012c4d0..da96049e 100644
--- a/src/Checkout/Validation/CreateOrderValidator.php
+++ b/src/Checkout/Validation/CreateOrderValidator.php
@@ -11,132 +11,132 @@
*/
class CreateOrderValidator extends OrderValidator
{
- public $errors = array();
-
- /**
- * @param CheckoutOrderBuilder $order
- * @return array|mixed
- */
- public function validate($order)
- {
- $errors = $this->errors;
-
- $errors = $this->restrictExVatValue($order, $errors);
-
- $errors = $this->validateRequiredOrderFields($order, $errors);
-
- $errors = $this->validateRequiredFieldsForOrder($order, $errors);
-
- $errors = $this->validateOrderRows($order, $errors);
-
- $errors = $this->validateMerchantSettings($order, $errors);
-
- $errors = $this->validatePartnerKey($order, $errors);
-
- $errors = $this->validateIdentityFlags($order, $errors);
-
- $errors = $this->validateRequireElectronicIdAuthentication($order, $errors);
-
- return $errors;
- }
-
- /**
- * @param CheckoutOrderBuilder $order
- * @param array $errors
- * @return array
- */
- private function validateRequireElectronicIdAuthentication($order, $errors)
- {
- if($order->getRequireElectronicIdAuthentication() != null)
- {
- if(!is_bool($order->getRequireElectronicIdAuthentication()))
- {
- $errors['invalid type'] = "requireElectronicIdAuthentication field isn't a boolean type, use setRequireElectronicIdAuthentication(true)";
- }
- }
- return $errors;
- }
-
- /**
- * @param CheckoutOrderBuilder $order
- * @param array $errors
- * @return array
- */
- private function validatePartnerKey($order, $errors)
- {
- $guid = $order->getPartnerKey();
- if($guid != null)
- {
- if (!preg_match('/^\{?[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}\}?$/', $guid)) {
- $errors['invalidFormatPartnerKey'] = "partnerKey is not in guid-format. The partnerKey is provided by Svea. If you're a partner to Svea and wish to use the partnerKey, please contact Svea in order to receive a guid.";
- }
- }
- return $errors;
- }
-
- /**
- * @param CheckoutOrderBuilder $order
- * @param array $errors
- * @return array
- */
- private function validateRequiredOrderFields($order, $errors)
- {
- // force correct order type of present attributes, see class OrderRow
- if ($order->countryCode === null ||
- !ctype_alpha($order->countryCode)
- ) {
- $errors['incorrectCountryCode'] = "countryCode must be defined, and string of alphabetic characters";
- }
-
- if (isset($order->currency) === false ||
- !ctype_alpha($order->currency)
- ) {
- $errors['incorrectCurrency'] = "currency must be defined, and must be string of alphabetic characters";
- }
-
- if ($order->getLocale() === null) {
- $errors['incorrectLocale'] = "locale must be defined";
- }
-
- return $errors;
- }
-
- /**
- * @param CheckoutOrderBuilder $order
- * @param array $errors
- * @return mixed
- */
- private function validateMerchantSettings(CheckoutOrderBuilder $order, $errors)
- {
- $merchantValidator = new MerchantValidator();
- $errors = $merchantValidator->validate($order->getMerchantSettings(), $errors);
-
- return $errors;
- }
-
- /**
- * @param CheckoutOrderBuilder $order
- * @param array $errors
- * @return array
- */
- protected function validateOrderRows($order, $errors)
- {
- $errors = parent::validateOrderRows($order, $errors);
- $errors = $this->validateCheckoutOrderRows($order, $errors);
-
- return $errors;
- }
-
- /**
- * @param CheckoutOrderBuilder $order
- * @param array $errors
- * @return array
- */
- private function validateIdentityFlags($order, $errors)
- {
- $identityFlagValidator = new IdentityFlagValidator();
- $errors = $identityFlagValidator->validate($order->getIdentityFlags(), $errors);
-
- return $errors;
- }
+ public $errors = [];
+
+ /**
+ * @param CheckoutOrderBuilder $order
+ * @return array|mixed
+ */
+ public function validate($order)
+ {
+ $errors = $this->errors;
+
+ $errors = $this->restrictExVatValue($order, $errors);
+
+ $errors = $this->validateRequiredOrderFields($order, $errors);
+
+ $errors = $this->validateRequiredFieldsForOrder($order, $errors);
+
+ $errors = $this->validateOrderRows($order, $errors);
+
+ $errors = $this->validateMerchantSettings($order, $errors);
+
+ $errors = $this->validatePartnerKey($order, $errors);
+
+ $errors = $this->validateIdentityFlags($order, $errors);
+
+ $errors = $this->validateRequireElectronicIdAuthentication($order, $errors);
+
+ return $errors;
+ }
+
+ /**
+ * @param CheckoutOrderBuilder $order
+ * @param array $errors
+ * @return array
+ */
+ private function validateRequireElectronicIdAuthentication($order, $errors)
+ {
+ if($order->getRequireElectronicIdAuthentication() != null)
+ {
+ if(!is_bool($order->getRequireElectronicIdAuthentication()))
+ {
+ $errors['invalid type'] = "requireElectronicIdAuthentication field isn't a boolean type, use setRequireElectronicIdAuthentication(true)";
+ }
+ }
+ return $errors;
+ }
+
+ /**
+ * @param CheckoutOrderBuilder $order
+ * @param array $errors
+ * @return array
+ */
+ private function validatePartnerKey($order, $errors)
+ {
+ $guid = $order->getPartnerKey();
+ if($guid != null)
+ {
+ if (!preg_match('/^\{?[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}\}?$/', $guid)) {
+ $errors['invalidFormatPartnerKey'] = "partnerKey is not in guid-format. The partnerKey is provided by Svea. If you're a partner to Svea and wish to use the partnerKey, please contact Svea in order to receive a guid.";
+ }
+ }
+ return $errors;
+ }
+
+ /**
+ * @param CheckoutOrderBuilder $order
+ * @param array $errors
+ * @return array
+ */
+ private function validateRequiredOrderFields($order, $errors)
+ {
+ // force correct order type of present attributes, see class OrderRow
+ if ($order->countryCode === null ||
+ !ctype_alpha($order->countryCode)
+ ) {
+ $errors['incorrectCountryCode'] = "countryCode must be defined, and string of alphabetic characters";
+ }
+
+ if (isset($order->currency) === false ||
+ !ctype_alpha($order->currency)
+ ) {
+ $errors['incorrectCurrency'] = "currency must be defined, and must be string of alphabetic characters";
+ }
+
+ if ($order->getLocale() === null) {
+ $errors['incorrectLocale'] = "locale must be defined";
+ }
+
+ return $errors;
+ }
+
+ /**
+ * @param CheckoutOrderBuilder $order
+ * @param array $errors
+ * @return mixed
+ */
+ private function validateMerchantSettings(CheckoutOrderBuilder $order, $errors)
+ {
+ $merchantValidator = new MerchantValidator();
+ $errors = $merchantValidator->validate($order->getMerchantSettings(), $errors);
+
+ return $errors;
+ }
+
+ /**
+ * @param CheckoutOrderBuilder $order
+ * @param array $errors
+ * @return array
+ */
+ protected function validateOrderRows($order, $errors)
+ {
+ $errors = parent::validateOrderRows($order, $errors);
+ $errors = $this->validateCheckoutOrderRows($order, $errors);
+
+ return $errors;
+ }
+
+ /**
+ * @param CheckoutOrderBuilder $order
+ * @param array $errors
+ * @return array
+ */
+ private function validateIdentityFlags($order, $errors)
+ {
+ $identityFlagValidator = new IdentityFlagValidator();
+ $errors = $identityFlagValidator->validate($order->getIdentityFlags(), $errors);
+
+ return $errors;
+ }
}
diff --git a/src/Checkout/Validation/ExVatRestrictionValidator.php b/src/Checkout/Validation/ExVatRestrictionValidator.php
index 9d8e54fb..4c7e21a6 100644
--- a/src/Checkout/Validation/ExVatRestrictionValidator.php
+++ b/src/Checkout/Validation/ExVatRestrictionValidator.php
@@ -4,16 +4,16 @@
class ExVatRestrictionValidator
{
- public function validate($order, $errors)
- {
- foreach ($order->rows as $orderItem)
- {
- if($orderItem->amountExVat != null)
- {
- $errors['exVatAmountRestriction'] = 'AmountExVat is not allowed for checkout functions, please use only AmountIncVat';
- }
- }
+ public function validate($order, $errors)
+ {
+ foreach ($order->rows as $orderItem)
+ {
+ if($orderItem->amountExVat != null)
+ {
+ $errors['exVatAmountRestriction'] = 'AmountExVat is not allowed for checkout functions, please use only AmountIncVat';
+ }
+ }
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/Checkout/Validation/GetAvailablePartPaymentCampaignsValidator.php b/src/Checkout/Validation/GetAvailablePartPaymentCampaignsValidator.php
index 2004e78d..6fdcb794 100644
--- a/src/Checkout/Validation/GetAvailablePartPaymentCampaignsValidator.php
+++ b/src/Checkout/Validation/GetAvailablePartPaymentCampaignsValidator.php
@@ -10,14 +10,14 @@
*/
class GetAvailablePartPaymentCampaignsValidator extends OrderValidator
{
- public $errors = array();
+ public $errors = [];
- public function validate($request)
- {
- $errors = $this->errors;
- $errors = $this->validatePresetIsCompanyIsSet($request, $errors);
- $errors = $this->validatePresetIsCompanyIsBoolean($request, $errors);
+ public function validate($request)
+ {
+ $errors = $this->errors;
+ $errors = $this->validatePresetIsCompanyIsSet($request, $errors);
+ $errors = $this->validatePresetIsCompanyIsBoolean($request, $errors);
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/Checkout/Validation/GetOrderValidator.php b/src/Checkout/Validation/GetOrderValidator.php
index 2cda45c5..eb1745e7 100644
--- a/src/Checkout/Validation/GetOrderValidator.php
+++ b/src/Checkout/Validation/GetOrderValidator.php
@@ -10,14 +10,14 @@
*/
class GetOrderValidator extends OrderValidator
{
- public $errors = array();
+ public $errors = [];
- public function validate($order)
- {
- $errors = $this->errors;
+ public function validate($order)
+ {
+ $errors = $this->errors;
- $errors = $this->validateOrderId($order, $errors);
+ $errors = $this->validateOrderId($order, $errors);
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/Checkout/Validation/IdentityFlagValidator.php b/src/Checkout/Validation/IdentityFlagValidator.php
index 67c3e071..6c42a641 100644
--- a/src/Checkout/Validation/IdentityFlagValidator.php
+++ b/src/Checkout/Validation/IdentityFlagValidator.php
@@ -8,28 +8,28 @@
*/
class IdentityFlagValidator
{
- public function validate($flags, $errors)
- {
- $reflection = new \ReflectionClass('Svea\WebPay\Checkout\Model\IdentityFlags');
- $consts = $reflection->getConstants();
+ public function validate($flags, $errors)
+ {
+ $reflection = new \ReflectionClass('Svea\WebPay\Checkout\Model\IdentityFlags');
+ $consts = $reflection->getConstants();
- foreach($flags as $flag)
- {
- $valid = false;
- foreach($consts as $const)
- {
- if($const == $flag)
- {
- $valid = true;
- break;
- }
- }
- if($valid == false)
- {
- $errors['NonValidIdentityFlag'] = $flag . " is not a valid identity flag.";
- }
- }
+ foreach($flags as $flag)
+ {
+ $valid = false;
+ foreach($consts as $const)
+ {
+ if($const == $flag)
+ {
+ $valid = true;
+ break;
+ }
+ }
+ if($valid == false)
+ {
+ $errors['NonValidIdentityFlag'] = $flag . " is not a valid identity flag.";
+ }
+ }
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/Checkout/Validation/MerchantValidator.php b/src/Checkout/Validation/MerchantValidator.php
index 15ec1df1..9a04e215 100644
--- a/src/Checkout/Validation/MerchantValidator.php
+++ b/src/Checkout/Validation/MerchantValidator.php
@@ -10,29 +10,29 @@
*/
class MerchantValidator
{
- public function validate(MerchantSettings $merchant, $errors)
- {
- $termsUri = $merchant->getTermsUri();
- $checkoutUri = $merchant->getCheckoutUri();
- $confirmationUri = $merchant->getConfirmationUri();
- $pushUri = $merchant->getPushUri();
-
- if (!isset($termsUri) || trim($termsUri) === '') {
- $errors['incorrectMerchantTermsUri'] = "termsUri must be defined";
- }
-
- if (!isset($checkoutUri) || trim($checkoutUri) === '') {
- $errors['incorrectMerchantCheckoutUri'] = "checkoutUri must be defined";
- }
-
- if (!isset($confirmationUri) || trim($confirmationUri) === '') {
- $errors['incorrectMerchantConfirmationUri'] = "confirmationUri must be defined";
- }
-
- if (!isset($pushUri) || trim($pushUri) === '') {
- $errors['incorrectMerchantPushUri'] = "pushUri must be defined";
- }
-
- return $errors;
- }
+ public function validate(MerchantSettings $merchant, $errors)
+ {
+ $termsUri = $merchant->getTermsUri();
+ $checkoutUri = $merchant->getCheckoutUri();
+ $confirmationUri = $merchant->getConfirmationUri();
+ $pushUri = $merchant->getPushUri();
+
+ if (!isset($termsUri) || trim($termsUri) === '') {
+ $errors['incorrectMerchantTermsUri'] = "termsUri must be defined";
+ }
+
+ if (!isset($checkoutUri) || trim($checkoutUri) === '') {
+ $errors['incorrectMerchantCheckoutUri'] = "checkoutUri must be defined";
+ }
+
+ if (!isset($confirmationUri) || trim($confirmationUri) === '') {
+ $errors['incorrectMerchantConfirmationUri'] = "confirmationUri must be defined";
+ }
+
+ if (!isset($pushUri) || trim($pushUri) === '') {
+ $errors['incorrectMerchantPushUri'] = "pushUri must be defined";
+ }
+
+ return $errors;
+ }
}
diff --git a/src/Checkout/Validation/UpdateOrderValidator.php b/src/Checkout/Validation/UpdateOrderValidator.php
index 5c912ce3..d061b2cc 100644
--- a/src/Checkout/Validation/UpdateOrderValidator.php
+++ b/src/Checkout/Validation/UpdateOrderValidator.php
@@ -10,28 +10,28 @@
*/
class UpdateOrderValidator extends OrderValidator
{
- public $errors = array();
+ public $errors = [];
- public function validate($order)
- {
- $errors = $this->errors;
- $errors = $this->restrictExVatValue($order, $errors);
- $errors = $this->validateOrderId($order, $errors);
- $errors = $this->validateOrderRows($order, $errors);
+ public function validate($order)
+ {
+ $errors = $this->errors;
+ $errors = $this->restrictExVatValue($order, $errors);
+ $errors = $this->validateOrderId($order, $errors);
+ $errors = $this->validateOrderRows($order, $errors);
- return $errors;
- }
+ return $errors;
+ }
- /**
- * @param object $order
- * @param array $errors
- * @return array
- */
- protected function validateOrderRows($order, $errors)
- {
- $errors = parent::validateOrderRows($order, $errors);
- $errors = $this->validateCheckoutOrderRows($order, $errors);
+ /**
+ * @param object $order
+ * @param array $errors
+ * @return array
+ */
+ protected function validateOrderRows($order, $errors)
+ {
+ $errors = parent::validateOrderRows($order, $errors);
+ $errors = $this->validateCheckoutOrderRows($order, $errors);
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/Config/ConfigurationProvider.php b/src/Config/ConfigurationProvider.php
index 39cac31d..8d590025 100644
--- a/src/Config/ConfigurationProvider.php
+++ b/src/Config/ConfigurationProvider.php
@@ -33,119 +33,119 @@
interface ConfigurationProvider
{
- const HOSTED_TYPE = 'HOSTED';
- const INVOICE_TYPE = 'Invoice';
- const PAYMENTPLAN_TYPE = 'PaymentPlan';
- const HOSTED_ADMIN_TYPE = 'HOSTED_ADMIN';
- const ADMIN_TYPE = 'ADMIN';
- const PREPARED_URL = 'PREPARED';
- const ACCOUNT_TYPE = 'Account';
- const CARD_TYPE = 'Card';
- const DIRECT_BANK = 'DirectBank';
- const ACCOUNTCREDIT_TYPE = 'AccountCredit';
-
- /*
- * Checkout
- */
- const CHECKOUT = 'CHECKOUT';
- const CHECKOUT_ADMIN = 'CHECKOUT_ADMIN';
-
- /**
- * fetch username, used with invoice or payment plan (i.e. Svea WebService Europe API)
- *
- * @return string
- * @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings
- * @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings
- * @throws InvalidTypeException in case of unsupported $type
- * @throws InvalidCountryException in case of unsupported $country
- */
- public function getUsername($type, $country);
-
- /**
- * fetch password, used with invoice or payment plan (i.e. Svea WebService Europe API)
- *
- * @return string
- * @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings
- * @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings
- * @throws InvalidTypeException in case of unsupported $type
- * @throws InvalidCountryException in case of unsupported $country
- */
- public function getPassword($type, $country);
-
- /**
- * fetch client number, used with invoice or payment plan (i.e. Svea WebService Europe API)
- *
- * @return ClientNumber
- * @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings
- * @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings
- * @throws InvalidTypeException in case of unsupported $type
- * @throws InvalidCountryException in case of unsupported $country
- */
- public function getClientNumber($type, $country);
-
- /**
- * fetch merchant id, used with card or direct bank payments (i.e. Svea Hosted Web Service API)
- *
- * @return string
- * @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings
- * $param string $country CountryCode eg. SE, NO, DK, FI, NL, DE
- */
- public function getMerchantId($type, $country);
-
- /**
- * fetch secret word, used with card or direct bank payments (i.e. Svea Hosted Web Service API)
- *
- * @return string
- * @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings
- * $param string $country CountryCode eg. SE, NO, DK, FI, NL, DE
- */
- public function getSecret($type, $country);
-
- /**
- * Constants for the endpoint url found in the class ConfigurationService.php
- * getEndPoint() should return an url corresponding to $type.
- *
- * @param string $type one of Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_ADMIN_TYPE, ::ADMIN_TYPE
- */
- public function getEndPoint($type);
-
- /**
- * fetch Checkout Merchant id, used for Checkout order type
- *
- * @return string
- */
- public function getCheckoutMerchantId($country = NULL);
-
- /**
- * fetch Checkout Secret word, used for Checkout order type
- *
- * @return string
- */
- public function getCheckoutSecret($country = NULL);
-
- /**
- * Use this to provide information about your integration platform (i.e. Magento, OpenCart et al), that will be sent to Svea with every service
- * request. Should return a string. The information provided is sent as plain text and should not include any confidential information.
- *
- * Uncomment this if you wish to provide this information from your Svea\WebPay\Config\ConfigurationProvider implementation.
- */
- // public function getIntegrationPlatform();
-
- /**
- * Use this to provide information about the company providing this particular integration (i.e. Svea Ekonomi, for the Svea Opencart module, et al), that
- * will be sent to Svea with every service request. Should return a string. The information provided is sent as plain text and should not include any
- * confidential information.
- *
- * Uncomment this if you wish to provide this information from your Svea\WebPay\Config\ConfigurationProvider implementation.
- */
- // public function getIntegrationCompany();
-
- /**
- * Use this to provide information about the version of this particular integration integration platform (i.e. 2.0.1 et al), that will be sent to Svea
- * with every service request. Should return a string. The information provided is sent as plain text and should not include any confidential information.
- *
- * Uncomment this if you wish to provide this information from your Svea\WebPay\Config\ConfigurationProvider implementation.
- */
- // public function getIntegrationVersion();
+ const HOSTED_TYPE = 'HOSTED';
+ const INVOICE_TYPE = 'Invoice';
+ const PAYMENTPLAN_TYPE = 'PaymentPlan';
+ const HOSTED_ADMIN_TYPE = 'HOSTED_ADMIN';
+ const ADMIN_TYPE = 'ADMIN';
+ const PREPARED_URL = 'PREPARED';
+ const ACCOUNT_TYPE = 'Account';
+ const CARD_TYPE = 'Card';
+ const DIRECT_BANK = 'DirectBank';
+ const ACCOUNTCREDIT_TYPE = 'AccountCredit';
+
+ /*
+ * Checkout
+ */
+ const CHECKOUT = 'CHECKOUT';
+ const CHECKOUT_ADMIN = 'CHECKOUT_ADMIN';
+
+ /**
+ * fetch username, used with invoice or payment plan (i.e. Svea WebService Europe API)
+ *
+ * @return string
+ * @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings
+ * @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings
+ * @throws InvalidTypeException in case of unsupported $type
+ * @throws InvalidCountryException in case of unsupported $country
+ */
+ public function getUsername($type, $country);
+
+ /**
+ * fetch password, used with invoice or payment plan (i.e. Svea WebService Europe API)
+ *
+ * @return string
+ * @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings
+ * @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings
+ * @throws InvalidTypeException in case of unsupported $type
+ * @throws InvalidCountryException in case of unsupported $country
+ */
+ public function getPassword($type, $country);
+
+ /**
+ * fetch client number, used with invoice or payment plan (i.e. Svea WebService Europe API)
+ *
+ * @return ClientNumber
+ * @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings
+ * @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings
+ * @throws InvalidTypeException in case of unsupported $type
+ * @throws InvalidCountryException in case of unsupported $country
+ */
+ public function getClientNumber($type, $country);
+
+ /**
+ * fetch merchant id, used with card or direct bank payments (i.e. Svea Hosted Web Service API)
+ *
+ * @return string
+ * @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings
+ * $param string $country CountryCode eg. SE, NO, DK, FI, NL, DE
+ */
+ public function getMerchantId($type, $country);
+
+ /**
+ * fetch secret word, used with card or direct bank payments (i.e. Svea Hosted Web Service API)
+ *
+ * @return string
+ * @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings
+ * $param string $country CountryCode eg. SE, NO, DK, FI, NL, DE
+ */
+ public function getSecret($type, $country);
+
+ /**
+ * Constants for the endpoint url found in the class ConfigurationService.php
+ * getEndPoint() should return an url corresponding to $type.
+ *
+ * @param string $type one of Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_ADMIN_TYPE, ::ADMIN_TYPE
+ */
+ public function getEndPoint($type);
+
+ /**
+ * fetch Checkout Merchant id, used for Checkout order type
+ *
+ * @return string
+ */
+ public function getCheckoutMerchantId($country = NULL);
+
+ /**
+ * fetch Checkout Secret word, used for Checkout order type
+ *
+ * @return string
+ */
+ public function getCheckoutSecret($country = NULL);
+
+ /**
+ * Use this to provide information about your integration platform (i.e. Magento, OpenCart et al), that will be sent to Svea with every service
+ * request. Should return a string. The information provided is sent as plain text and should not include any confidential information.
+ *
+ * Uncomment this if you wish to provide this information from your Svea\WebPay\Config\ConfigurationProvider implementation.
+ */
+ // public function getIntegrationPlatform();
+
+ /**
+ * Use this to provide information about the company providing this particular integration (i.e. Svea Ekonomi, for the Svea Opencart module, et al), that
+ * will be sent to Svea with every service request. Should return a string. The information provided is sent as plain text and should not include any
+ * confidential information.
+ *
+ * Uncomment this if you wish to provide this information from your Svea\WebPay\Config\ConfigurationProvider implementation.
+ */
+ // public function getIntegrationCompany();
+
+ /**
+ * Use this to provide information about the version of this particular integration integration platform (i.e. 2.0.1 et al), that will be sent to Svea
+ * with every service request. Should return a string. The information provided is sent as plain text and should not include any confidential information.
+ *
+ * Uncomment this if you wish to provide this information from your Svea\WebPay\Config\ConfigurationProvider implementation.
+ */
+ // public function getIntegrationVersion();
}
diff --git a/src/Config/ConfigurationService.php b/src/Config/ConfigurationService.php
index 33693d85..934f6d83 100644
--- a/src/Config/ConfigurationService.php
+++ b/src/Config/ConfigurationService.php
@@ -12,221 +12,221 @@
*/
class ConfigurationService
{
- const SWP_TEST_URL = "https://webpaypaymentgatewaystage.svea.com/webpay/payment";
- const SWP_PROD_URL = "https://webpaypaymentgateway.svea.com/webpay/payment";
- const SWP_TEST_WS_URL = "https://webpaywsstage.svea.com/SveaWebPay.asmx?WSDL";
- const SWP_PROD_WS_URL = "https://webpayws.svea.com/SveaWebPay.asmx?WSDL";
- const SWP_TEST_HOSTED_ADMIN_URL = "https://webpaypaymentgatewaystage.svea.com/webpay/rest/"; // ends with "/" as we need to add request method
- const SWP_PROD_HOSTED_ADMIN_URL = "https://webpaypaymentgateway.svea.com/webpay/rest/"; // ends with "/" as we need to add request method
-
- const SWP_TEST_ADMIN_URL = "https://webpayadminservicestage.svea.com/AdminService.svc/backward";
- const SWP_PROD_ADMIN_URL = "https://webpayadminservice.svea.com/AdminService.svc/backward";
-
- const SWP_TEST_PREPARED_URL = "https://webpaypaymentgatewaystage.svea.com/webpay/preparedpayment/";
- const SWP_PROD_PREPARED_URL = "https://webpaypaymentgateway.svea.com/webpay/preparedpayment/";
-
- const CHECKOUT_TEST_BASE_URL = Connector::TEST_BASE_URL;
- const CHECKOUT_PROD_BASE_URL = Connector::PROD_BASE_URL;
-
- const CHECKOUT_ADMIN_TEST_BASE_URL = Connector::TEST_ADMIN_BASE_URL;
- const CHECKOUT_ADMIN_PROD_BASE_URL = Connector::PROD_ADMIN_BASE_URL;
-
-
- /**
- * @return SveaConfigurationProvider
- */
- public static function getProdConfig()
- {
- return self::getConfig(true);
- }
-
- /**
- * @return SveaConfigurationProvider
- */
- public static function getDefaultConfig()
- {
- return self::getTestConfig();
- }
-
- /**
- * Replace the provided Svea test account credentials with your own to use
- * the package with your own account.
- *
- * @return SveaConfigurationProvider
- */
- public static function getTestConfig()
- {
- return self::getConfig(false);
- }
-
- /**
- * getSingleCountryConfig() may be used to provide a specific single configuration to use in i.e. the package test suite.
- *
- * Provide the following credentials as parameters. If a value is set to null, a default value will be provided instead.
- *
- * @param string $countryCode
- * @param string $invoiceUsername
- * @param string $invoicePassword
- * @param string $invoiceClientNo
- * @param string $paymentPlanUsername
- * @param string $paymentPlanPassword
- * @param string $paymentPlanClientNo
- * @param string $accountCreditUsername
- * @param string $accountCreditPassword
- * @param string $accountCreditClientNo
- * @param string $merchantId
- * @param string $secret
- * @param bool $prod
- * @return SveaConfigurationProvider
- */
- public static function getSingleCountryConfig(
- $countryCode,
- $invoiceUsername, $invoicePassword, $invoiceClientNo,
- $paymentPlanUsername, $paymentPlanPassword, $paymentPlanClientNo,
- $accountCreditUsername, $accountCreditPassword, $accountCreditClientNo,
- $merchantId, $secret, $prod)
- {
- $prod = ($prod == null) ? false : $prod;
-
- list($config, $urls) = self::retrieveConfigFile($prod);
-
- $defaultConfig = $config['credentials'];
- $defaultMerchantId = $config['commonCredentials']['merchantId'];
- $defaultSecretWord = $config['commonCredentials']['secret'];
- $defaultCountryCode = $config['defaultCountryCode'];
- $integrationProperties = $config['integrationParams'];
-
- $countryCode = ($countryCode == null) ? $defaultCountryCode : $countryCode;
- $configPerCountry = $defaultConfig[$countryCode];
-
- $configPerInvoiceType = $configPerCountry[ConfigurationProvider::INVOICE_TYPE];
- $invoiceUsername = ($invoiceUsername == null) ? $configPerInvoiceType['username'] : $invoiceUsername;
- $invoicePassword = ($invoicePassword == null) ? $configPerInvoiceType['password'] : $invoicePassword;
- $invoiceClientNo = ($invoiceClientNo == null) ? $configPerInvoiceType['clientNumber'] : $invoiceClientNo;
-
- $configPerPPType = $configPerCountry[ConfigurationProvider::PAYMENTPLAN_TYPE];
- $paymentPlanUsername = ($paymentPlanUsername == null) ? $configPerPPType['username'] : $paymentPlanUsername;
- $paymentPlanPassword = ($paymentPlanPassword == null) ? $configPerPPType['password'] : $paymentPlanPassword;
- $paymentPlanClientNo = ($paymentPlanClientNo == null) ? $configPerPPType['clientNumber'] : $paymentPlanClientNo;
-
- $configPerAccCredType = $configPerCountry[ConfigurationProvider::ACCOUNTCREDIT_TYPE];
- $accountCreditUsername = ($accountCreditUsername == null) ? $configPerAccCredType['username'] : $accountCreditUsername;
- $accountCreditPassword = ($accountCreditPassword == null) ? $configPerAccCredType['password'] : $accountCreditPassword;
- $accountCreditClientNo = ($accountCreditClientNo == null) ? $configPerAccCredType['clientNumber'] : $accountCreditClientNo;
-
- $merchantId = ($merchantId == null) ? $defaultMerchantId : $merchantId;
- $secret = ($secret == null) ? $defaultSecretWord : $secret;
-
- // set up credentials array for given country:
- $singleCountryConfig[$countryCode] = array("auth" =>
- array(
- ConfigurationProvider::INVOICE_TYPE => array(
- "username" => $invoiceUsername,
- "password" => $invoicePassword,
- "clientNumber" => $invoiceClientNo
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- "username" => $paymentPlanUsername,
- "password" => $paymentPlanPassword,
- "clientNumber" => $paymentPlanClientNo
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- "username" => $accountCreditUsername,
- "password" => $accountCreditPassword,
- "clientNumber" => $accountCreditClientNo
- ),
- ConfigurationProvider::HOSTED_TYPE => array(
- "merchantId" => $merchantId,
- "secret" => $secret
- )
- )
- );
-
- $singleCountryConfig['common']['auth'][ConfigurationProvider::HOSTED_TYPE] = array(
- "merchantId" => $merchantId,
- "secret" => $secret
- );
-
- $singleCountryConfig['common']['auth'][ConfigurationProvider::CHECKOUT] = array(
- "merchantId" => $merchantId,
- "secret" => $secret
- );
-
- // return a ConfigurationProvider object
- return new SveaConfigurationProvider(
- array("url" => $urls, "credentials" => $singleCountryConfig, "integrationproperties" => $integrationProperties)
- );
- }
-
- private static function getConfig($isProd)
- {
- list($config, $urls) = self::retrieveConfigFile($isProd);
-
- $credentialParams = array();
- $credentials = $config['credentials'];
-
- $commonCredentials = $config['commonCredentials'];
- $checkoutCredentials = $config['checkoutCredentials'];
- $credentialParams['common'] = array();
- foreach ($credentials as $countryCode => $configPerCountry) {
- $credentialParams[$countryCode] = array('auth' => array());
- foreach ($configPerCountry as $paymentType => $configPerType) {
- if ($paymentType === ConfigurationProvider::CHECKOUT && ($countryCode == "DE" || $countryCode == "NL")) {
- $configPerType = array_merge($configPerType, $checkoutCredentials);
- }
- $credentialParams[$countryCode]['auth'][$paymentType] = $configPerType;
- }
- $credentialParams[$countryCode]['auth'][ConfigurationProvider::HOSTED_TYPE] = $commonCredentials;
- }
-
- $credentialParams['common']['auth'][ConfigurationProvider::HOSTED_TYPE] = $commonCredentials;
- $credentialParams['common']['auth'][ConfigurationProvider::CHECKOUT] = $checkoutCredentials;
-
- $integrationProperties = $config['integrationParams'];
-
- return new SveaConfigurationProvider(array("url" => $urls, "credentials" => $credentialParams, "integrationproperties" => $integrationProperties));
- }
-
- private static function retrieveConfigFile($isProd)
- {
- if ($isProd === true) {
- $config = require 'config_prod.php';
- $urls = self::getProdUrls();
- } else {
- $config = require 'config_test.php';
- $urls = self::getTestUrls();
- }
-
- return array($config, $urls);
- }
-
- private static function getTestUrls()
- {
- return array(
- ConfigurationProvider::HOSTED_TYPE => self::SWP_TEST_URL,
- ConfigurationProvider::INVOICE_TYPE => self::SWP_TEST_WS_URL,
- ConfigurationProvider::PAYMENTPLAN_TYPE => self::SWP_TEST_WS_URL,
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => self::SWP_TEST_WS_URL,
- ConfigurationProvider::HOSTED_ADMIN_TYPE => self::SWP_TEST_HOSTED_ADMIN_URL,
- ConfigurationProvider::ADMIN_TYPE => self::SWP_TEST_ADMIN_URL,
- ConfigurationProvider::PREPARED_URL => self::SWP_TEST_PREPARED_URL,
- ConfigurationProvider::CHECKOUT => self::CHECKOUT_TEST_BASE_URL,
- ConfigurationProvider::CHECKOUT_ADMIN => self::CHECKOUT_ADMIN_TEST_BASE_URL
- );
- }
-
- private static function getProdUrls()
- {
- return array(
- ConfigurationProvider::HOSTED_TYPE => self::SWP_PROD_URL,
- ConfigurationProvider::INVOICE_TYPE => self::SWP_PROD_WS_URL,
- ConfigurationProvider::PAYMENTPLAN_TYPE => self::SWP_PROD_WS_URL,
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => self::SWP_PROD_WS_URL,
- ConfigurationProvider::HOSTED_ADMIN_TYPE => self::SWP_PROD_HOSTED_ADMIN_URL,
- ConfigurationProvider::ADMIN_TYPE => self::SWP_PROD_ADMIN_URL,
- ConfigurationProvider::PREPARED_URL => self::SWP_PROD_PREPARED_URL,
- ConfigurationProvider::CHECKOUT => self::CHECKOUT_PROD_BASE_URL,
- ConfigurationProvider::CHECKOUT_ADMIN => self::CHECKOUT_ADMIN_PROD_BASE_URL
- );
- }
+ const SWP_TEST_URL = "https://webpaypaymentgatewaystage.svea.com/webpay/payment";
+ const SWP_PROD_URL = "https://webpaypaymentgateway.svea.com/webpay/payment";
+ const SWP_TEST_WS_URL = "https://webpaywsstage.svea.com/SveaWebPay.asmx?WSDL";
+ const SWP_PROD_WS_URL = "https://webpayws.svea.com/SveaWebPay.asmx?WSDL";
+ const SWP_TEST_HOSTED_ADMIN_URL = "https://webpaypaymentgatewaystage.svea.com/webpay/rest/"; // ends with "/" as we need to add request method
+ const SWP_PROD_HOSTED_ADMIN_URL = "https://webpaypaymentgateway.svea.com/webpay/rest/"; // ends with "/" as we need to add request method
+
+ const SWP_TEST_ADMIN_URL = "https://webpayadminservicestage.svea.com/AdminService.svc/backward";
+ const SWP_PROD_ADMIN_URL = "https://webpayadminservice.svea.com/AdminService.svc/backward";
+
+ const SWP_TEST_PREPARED_URL = "https://webpaypaymentgatewaystage.svea.com/webpay/preparedpayment/";
+ const SWP_PROD_PREPARED_URL = "https://webpaypaymentgateway.svea.com/webpay/preparedpayment/";
+
+ const CHECKOUT_TEST_BASE_URL = Connector::TEST_BASE_URL;
+ const CHECKOUT_PROD_BASE_URL = Connector::PROD_BASE_URL;
+
+ const CHECKOUT_ADMIN_TEST_BASE_URL = Connector::TEST_ADMIN_BASE_URL;
+ const CHECKOUT_ADMIN_PROD_BASE_URL = Connector::PROD_ADMIN_BASE_URL;
+
+
+ /**
+ * @return SveaConfigurationProvider
+ */
+ public static function getProdConfig()
+ {
+ return self::getConfig(true);
+ }
+
+ /**
+ * @return SveaConfigurationProvider
+ */
+ public static function getDefaultConfig()
+ {
+ return self::getTestConfig();
+ }
+
+ /**
+ * Replace the provided Svea test account credentials with your own to use
+ * the package with your own account.
+ *
+ * @return SveaConfigurationProvider
+ */
+ public static function getTestConfig()
+ {
+ return self::getConfig(false);
+ }
+
+ /**
+ * getSingleCountryConfig() may be used to provide a specific single configuration to use in i.e. the package test suite.
+ *
+ * Provide the following credentials as parameters. If a value is set to null, a default value will be provided instead.
+ *
+ * @param string $countryCode
+ * @param string $invoiceUsername
+ * @param string $invoicePassword
+ * @param string $invoiceClientNo
+ * @param string $paymentPlanUsername
+ * @param string $paymentPlanPassword
+ * @param string $paymentPlanClientNo
+ * @param string $accountCreditUsername
+ * @param string $accountCreditPassword
+ * @param string $accountCreditClientNo
+ * @param string $merchantId
+ * @param string $secret
+ * @param bool $prod
+ * @return SveaConfigurationProvider
+ */
+ public static function getSingleCountryConfig(
+ $countryCode,
+ $invoiceUsername, $invoicePassword, $invoiceClientNo,
+ $paymentPlanUsername, $paymentPlanPassword, $paymentPlanClientNo,
+ $accountCreditUsername, $accountCreditPassword, $accountCreditClientNo,
+ $merchantId, $secret, $prod)
+ {
+ $prod = ($prod == null) ? false : $prod;
+
+ list($config, $urls) = self::retrieveConfigFile($prod);
+
+ $defaultConfig = $config['credentials'];
+ $defaultMerchantId = $config['commonCredentials']['merchantId'];
+ $defaultSecretWord = $config['commonCredentials']['secret'];
+ $defaultCountryCode = $config['defaultCountryCode'];
+ $integrationProperties = $config['integrationParams'];
+
+ $countryCode = ($countryCode == null) ? $defaultCountryCode : $countryCode;
+ $configPerCountry = $defaultConfig[$countryCode];
+
+ $configPerInvoiceType = $configPerCountry[ConfigurationProvider::INVOICE_TYPE];
+ $invoiceUsername = ($invoiceUsername == null) ? $configPerInvoiceType['username'] : $invoiceUsername;
+ $invoicePassword = ($invoicePassword == null) ? $configPerInvoiceType['password'] : $invoicePassword;
+ $invoiceClientNo = ($invoiceClientNo == null) ? $configPerInvoiceType['clientNumber'] : $invoiceClientNo;
+
+ $configPerPPType = $configPerCountry[ConfigurationProvider::PAYMENTPLAN_TYPE];
+ $paymentPlanUsername = ($paymentPlanUsername == null) ? $configPerPPType['username'] : $paymentPlanUsername;
+ $paymentPlanPassword = ($paymentPlanPassword == null) ? $configPerPPType['password'] : $paymentPlanPassword;
+ $paymentPlanClientNo = ($paymentPlanClientNo == null) ? $configPerPPType['clientNumber'] : $paymentPlanClientNo;
+
+ $configPerAccCredType = $configPerCountry[ConfigurationProvider::ACCOUNTCREDIT_TYPE];
+ $accountCreditUsername = ($accountCreditUsername == null) ? $configPerAccCredType['username'] : $accountCreditUsername;
+ $accountCreditPassword = ($accountCreditPassword == null) ? $configPerAccCredType['password'] : $accountCreditPassword;
+ $accountCreditClientNo = ($accountCreditClientNo == null) ? $configPerAccCredType['clientNumber'] : $accountCreditClientNo;
+
+ $merchantId = ($merchantId == null) ? $defaultMerchantId : $merchantId;
+ $secret = ($secret == null) ? $defaultSecretWord : $secret;
+
+ // set up credentials array for given country:
+ $singleCountryConfig[$countryCode] = ["auth" =>
+ [
+ ConfigurationProvider::INVOICE_TYPE => [
+ "username" => $invoiceUsername,
+ "password" => $invoicePassword,
+ "clientNumber" => $invoiceClientNo
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ "username" => $paymentPlanUsername,
+ "password" => $paymentPlanPassword,
+ "clientNumber" => $paymentPlanClientNo
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ "username" => $accountCreditUsername,
+ "password" => $accountCreditPassword,
+ "clientNumber" => $accountCreditClientNo
+ ],
+ ConfigurationProvider::HOSTED_TYPE => [
+ "merchantId" => $merchantId,
+ "secret" => $secret
+ ]
+ ]
+ ];
+
+ $singleCountryConfig['common']['auth'][ConfigurationProvider::HOSTED_TYPE] = [
+ "merchantId" => $merchantId,
+ "secret" => $secret
+ ];
+
+ $singleCountryConfig['common']['auth'][ConfigurationProvider::CHECKOUT] = [
+ "merchantId" => $merchantId,
+ "secret" => $secret
+ ];
+
+ // return a ConfigurationProvider object
+ return new SveaConfigurationProvider(
+ ["url" => $urls, "credentials" => $singleCountryConfig, "integrationproperties" => $integrationProperties]
+ );
+ }
+
+ private static function getConfig($isProd)
+ {
+ list($config, $urls) = self::retrieveConfigFile($isProd);
+
+ $credentialParams = [];
+ $credentials = $config['credentials'];
+
+ $commonCredentials = $config['commonCredentials'];
+ $checkoutCredentials = $config['checkoutCredentials'];
+ $credentialParams['common'] = [];
+ foreach ($credentials as $countryCode => $configPerCountry) {
+ $credentialParams[$countryCode] = ['auth' => []];
+ foreach ($configPerCountry as $paymentType => $configPerType) {
+ if ($paymentType === ConfigurationProvider::CHECKOUT && ($countryCode == "DE" || $countryCode == "NL")) {
+ $configPerType = array_merge($configPerType, $checkoutCredentials);
+ }
+ $credentialParams[$countryCode]['auth'][$paymentType] = $configPerType;
+ }
+ $credentialParams[$countryCode]['auth'][ConfigurationProvider::HOSTED_TYPE] = $commonCredentials;
+ }
+
+ $credentialParams['common']['auth'][ConfigurationProvider::HOSTED_TYPE] = $commonCredentials;
+ $credentialParams['common']['auth'][ConfigurationProvider::CHECKOUT] = $checkoutCredentials;
+
+ $integrationProperties = $config['integrationParams'];
+
+ return new SveaConfigurationProvider(["url" => $urls, "credentials" => $credentialParams, "integrationproperties" => $integrationProperties]);
+ }
+
+ private static function retrieveConfigFile($isProd)
+ {
+ if ($isProd === true) {
+ $config = require 'config_prod.php';
+ $urls = self::getProdUrls();
+ } else {
+ $config = require 'config_test.php';
+ $urls = self::getTestUrls();
+ }
+
+ return [$config, $urls];
+ }
+
+ private static function getTestUrls()
+ {
+ return [
+ ConfigurationProvider::HOSTED_TYPE => self::SWP_TEST_URL,
+ ConfigurationProvider::INVOICE_TYPE => self::SWP_TEST_WS_URL,
+ ConfigurationProvider::PAYMENTPLAN_TYPE => self::SWP_TEST_WS_URL,
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => self::SWP_TEST_WS_URL,
+ ConfigurationProvider::HOSTED_ADMIN_TYPE => self::SWP_TEST_HOSTED_ADMIN_URL,
+ ConfigurationProvider::ADMIN_TYPE => self::SWP_TEST_ADMIN_URL,
+ ConfigurationProvider::PREPARED_URL => self::SWP_TEST_PREPARED_URL,
+ ConfigurationProvider::CHECKOUT => self::CHECKOUT_TEST_BASE_URL,
+ ConfigurationProvider::CHECKOUT_ADMIN => self::CHECKOUT_ADMIN_TEST_BASE_URL
+ ];
+ }
+
+ private static function getProdUrls()
+ {
+ return [
+ ConfigurationProvider::HOSTED_TYPE => self::SWP_PROD_URL,
+ ConfigurationProvider::INVOICE_TYPE => self::SWP_PROD_WS_URL,
+ ConfigurationProvider::PAYMENTPLAN_TYPE => self::SWP_PROD_WS_URL,
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => self::SWP_PROD_WS_URL,
+ ConfigurationProvider::HOSTED_ADMIN_TYPE => self::SWP_PROD_HOSTED_ADMIN_URL,
+ ConfigurationProvider::ADMIN_TYPE => self::SWP_PROD_ADMIN_URL,
+ ConfigurationProvider::PREPARED_URL => self::SWP_PROD_PREPARED_URL,
+ ConfigurationProvider::CHECKOUT => self::CHECKOUT_PROD_BASE_URL,
+ ConfigurationProvider::CHECKOUT_ADMIN => self::CHECKOUT_ADMIN_PROD_BASE_URL
+ ];
+ }
}
diff --git a/src/Config/SveaConfigurationProvider.php b/src/Config/SveaConfigurationProvider.php
index 4a483dd4..1fb91c25 100644
--- a/src/Config/SveaConfigurationProvider.php
+++ b/src/Config/SveaConfigurationProvider.php
@@ -22,221 +22,221 @@
*/
class SveaConfigurationProvider implements ConfigurationProvider
{
- public $conf;
-
- /**
- * This class expects to be initialised with an array listing the various
- * configuration settings, see config_prod.php or config_test.php for details on the array structure.
- *
- * @param array $environmentConfig
- */
- public function __construct($environmentConfig)
- {
- $this->conf = (array)$environmentConfig;
- }
-
- /**
- * @param string $type one of { \Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE }
- * @param string $country
- * @return string
- * @throws Exception
- */
- public function getUsername($type, $country)
- {
- return $this->getCredentialsProperty('username', $type, $country);
- }
-
- /**
- * @param string $property
- * @param ConfigurationProvider ::HOSTED_TYPE | ConfigurationProvider::INVOICE_TYPE
- * | ConfigurationProvider::PAYMENTPLAN_TYPE
- * | ConfigurationProvider::ACCOUNTCREDIT_TYPE $type
- * @param string $country
- * @return string
- * @throws Exception
- */
- private function getCredentialsProperty($property, $type, $country)
- {
- if ($property === 'merchantId' || $property === 'secret') {
- if (array_key_exists($property, $this->conf['credentials']['common']['auth'][$type]) === false) {
- $this->throwInvalidCredentialProperty();
- }
-
- return $this->conf['credentials']['common']['auth'][$type][$property];
- } else {
- return $this->getCredentialsPropertyByCountry($property, $type, $country);
- }
- }
-
- private function getCredentialsPropertyByCountry($property, $type, $country)
- {
- $uCountry = strtoupper($country);
-
- if (array_key_exists($uCountry, $this->conf['credentials']) == FALSE) {
- $this->throwInvalidCountryException();
- } elseif (array_key_exists($type, $this->conf['credentials'][$uCountry]['auth']) == FALSE) {
- $this->throwInvalidTypeException($type);
- }
-
- return $this->conf['credentials'][$uCountry]['auth'][$type][$property];
- }
-
- /**
- * @throws \Svea\WebPay\HostedService\Helper\InvalidCountryException
- */
- private function throwInvalidCountryException()
- {
- throw new InvalidCountryException('Invalid or missing Country code');
- }
-
- /**
- * @throws Exception
- */
- private function throwInvalidCredentialProperty()
- {
- throw new Exception('Invalid or missing Credential property');
- }
-
- /**
- * @param $invalid_type
- * @throws InvalidTypeException
- */
- private function throwInvalidTypeException($invalid_type)
- {
- throw new InvalidTypeException(sprintf('Invalid Svea\WebPay\Config\ConfigurationProvider::XXX_TYPE \"%s\".', $invalid_type));
- }
-
- /**
- * @param string $type one of { \Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE }
- * @param string $country
- * @return string
- * @throws Exception
- */
- public function getPassword($type, $country)
- {
- return $this->getCredentialsProperty('password', $type, $country);
- }
-
- /**
- * @param string $type one of { \Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE }
- * @param string $country
- * @return string
- * @throws Exception
- */
- public function getClientNumber($type, $country)
- {
- return $this->getCredentialsProperty('clientNumber', $type, $country);
- }
-
- /**
- * @param string $type one of { \Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE }
- * @param string $country
- * @return string
- * @throws Exception
- */
- public function getMerchantId($type, $country)
- {
- return $this->getCredentialsProperty('merchantId', $type, $country);
- }
-
- /**
- * @param string $type one of { ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE }
- * @param string $country
- * @return string
- * @throws Exception
- */
- public function getSecret($type, $country)
- {
- return $this->getCredentialsProperty('secret', $type, $country);
- }
-
- /**
- * @param string $type one of { ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE,, ::ACCOUNTCREDIT_TYPE ::HOSTED_ADMIN_TYPE, ::ADMIN_TYPE}
- * @return string
- * @throws Exception
- */
- public function getEndPoint($type)
- {
- if (array_key_exists($type, $this->conf['url']) == FALSE) {
- $this->throwInvalidTypeException($type);
- }
-
- return $this->conf['url'][$type];
- }
-
- public function getIntegrationPlatform()
- {
- try {
- $integrationplatform = $this->getIntegrationProperty('integrationplatform');
- } catch (InvalidTypeException $e) {
- $integrationplatform = "Please provide your integration platform here.";
- }
-
- return $integrationplatform;
- }
-
- private function getIntegrationProperty($property)
- {
- if (array_key_exists('integrationproperties', $this->conf) == FALSE) {
- throw new InvalidTypeException("integration properties not set");
- }
-
- return $this->conf['integrationproperties'][$property];
- }
-
- public function getIntegrationVersion()
- {
- try {
- $integrationversion = $this->getIntegrationProperty('integrationversion');
- } catch (InvalidTypeException $e) {
- $integrationversion = "Please provide your integration version here.";
- }
-
- return $integrationversion;
- }
-
- public function getIntegrationCompany()
- {
- try {
- $integrationcompany = $this->getIntegrationProperty('integrationcompany');
- } catch (InvalidTypeException $e) {
- $integrationcompany = "Please provide your integration company here.";
- }
-
- return $integrationcompany;
- }
-
- /**
- * fetch Checkout Merchant id, used for Checkout order type
- *
- * @return string
- */
- public function getCheckoutMerchantId($country = NULL)
- {
- if($country != NULL)
- {
- return $this->getCredentialsProperty('checkoutMerchantId', ConfigurationProvider::CHECKOUT, $country);
- }
- else
- {
- return $this->getCredentialsProperty('checkoutMerchantId', ConfigurationProvider::CHECKOUT, 'SE');
- }
- }
-
- /**
- * fetch Checkout Secret word, used for Checkout order type
- *
- * @return string
- */
- public function getCheckoutSecret($country = NULL)
- {
- if($country != NULL)
- {
- return $this->getCredentialsProperty('checkoutSecret', ConfigurationProvider::CHECKOUT, $country);
- }
- else
- {
- return $this->getCredentialsProperty('checkoutSecret', ConfigurationProvider::CHECKOUT, 'SE');
- }
- }
+ public $conf;
+
+ /**
+ * This class expects to be initialised with an array listing the various
+ * configuration settings, see config_prod.php or config_test.php for details on the array structure.
+ *
+ * @param array $environmentConfig
+ */
+ public function __construct($environmentConfig)
+ {
+ $this->conf = (array)$environmentConfig;
+ }
+
+ /**
+ * @param string $type one of { \Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE }
+ * @param string $country
+ * @return string
+ * @throws Exception
+ */
+ public function getUsername($type, $country)
+ {
+ return $this->getCredentialsProperty('username', $type, $country);
+ }
+
+ /**
+ * @param string $property
+ * @param ConfigurationProvider ::HOSTED_TYPE | ConfigurationProvider::INVOICE_TYPE
+ * | ConfigurationProvider::PAYMENTPLAN_TYPE
+ * | ConfigurationProvider::ACCOUNTCREDIT_TYPE $type
+ * @param string $country
+ * @return string
+ * @throws Exception
+ */
+ private function getCredentialsProperty($property, $type, $country)
+ {
+ if ($property === 'merchantId' || $property === 'secret') {
+ if (array_key_exists($property, $this->conf['credentials']['common']['auth'][$type]) === false) {
+ $this->throwInvalidCredentialProperty();
+ }
+
+ return $this->conf['credentials']['common']['auth'][$type][$property];
+ } else {
+ return $this->getCredentialsPropertyByCountry($property, $type, $country);
+ }
+ }
+
+ private function getCredentialsPropertyByCountry($property, $type, $country)
+ {
+ $uCountry = strtoupper($country);
+
+ if (array_key_exists($uCountry, $this->conf['credentials']) == FALSE) {
+ $this->throwInvalidCountryException();
+ } elseif (array_key_exists($type, $this->conf['credentials'][$uCountry]['auth']) == FALSE) {
+ $this->throwInvalidTypeException($type);
+ }
+
+ return $this->conf['credentials'][$uCountry]['auth'][$type][$property];
+ }
+
+ /**
+ * @throws \Svea\WebPay\HostedService\Helper\InvalidCountryException
+ */
+ private function throwInvalidCountryException()
+ {
+ throw new InvalidCountryException('Invalid or missing Country code');
+ }
+
+ /**
+ * @throws Exception
+ */
+ private function throwInvalidCredentialProperty()
+ {
+ throw new Exception('Invalid or missing Credential property');
+ }
+
+ /**
+ * @param $invalid_type
+ * @throws InvalidTypeException
+ */
+ private function throwInvalidTypeException($invalid_type)
+ {
+ throw new InvalidTypeException(sprintf('Invalid Svea\WebPay\Config\ConfigurationProvider::XXX_TYPE \"%s\".', $invalid_type));
+ }
+
+ /**
+ * @param string $type one of { \Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE }
+ * @param string $country
+ * @return string
+ * @throws Exception
+ */
+ public function getPassword($type, $country)
+ {
+ return $this->getCredentialsProperty('password', $type, $country);
+ }
+
+ /**
+ * @param string $type one of { \Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE }
+ * @param string $country
+ * @return string
+ * @throws Exception
+ */
+ public function getClientNumber($type, $country)
+ {
+ return $this->getCredentialsProperty('clientNumber', $type, $country);
+ }
+
+ /**
+ * @param string $type one of { \Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE }
+ * @param string $country
+ * @return string
+ * @throws Exception
+ */
+ public function getMerchantId($type, $country)
+ {
+ return $this->getCredentialsProperty('merchantId', $type, $country);
+ }
+
+ /**
+ * @param string $type one of { ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::ACCOUNTCREDIT_TYPE }
+ * @param string $country
+ * @return string
+ * @throws Exception
+ */
+ public function getSecret($type, $country)
+ {
+ return $this->getCredentialsProperty('secret', $type, $country);
+ }
+
+ /**
+ * @param string $type one of { ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE,, ::ACCOUNTCREDIT_TYPE ::HOSTED_ADMIN_TYPE, ::ADMIN_TYPE}
+ * @return string
+ * @throws Exception
+ */
+ public function getEndPoint($type)
+ {
+ if (array_key_exists($type, $this->conf['url']) == FALSE) {
+ $this->throwInvalidTypeException($type);
+ }
+
+ return $this->conf['url'][$type];
+ }
+
+ public function getIntegrationPlatform()
+ {
+ try {
+ $integrationplatform = $this->getIntegrationProperty('integrationplatform');
+ } catch (InvalidTypeException $e) {
+ $integrationplatform = "Please provide your integration platform here.";
+ }
+
+ return $integrationplatform;
+ }
+
+ private function getIntegrationProperty($property)
+ {
+ if (array_key_exists('integrationproperties', $this->conf) == FALSE) {
+ throw new InvalidTypeException("integration properties not set");
+ }
+
+ return $this->conf['integrationproperties'][$property];
+ }
+
+ public function getIntegrationVersion()
+ {
+ try {
+ $integrationversion = $this->getIntegrationProperty('integrationversion');
+ } catch (InvalidTypeException $e) {
+ $integrationversion = "Please provide your integration version here.";
+ }
+
+ return $integrationversion;
+ }
+
+ public function getIntegrationCompany()
+ {
+ try {
+ $integrationcompany = $this->getIntegrationProperty('integrationcompany');
+ } catch (InvalidTypeException $e) {
+ $integrationcompany = "Please provide your integration company here.";
+ }
+
+ return $integrationcompany;
+ }
+
+ /**
+ * fetch Checkout Merchant id, used for Checkout order type
+ *
+ * @return string
+ */
+ public function getCheckoutMerchantId($country = NULL)
+ {
+ if($country != NULL)
+ {
+ return $this->getCredentialsProperty('checkoutMerchantId', ConfigurationProvider::CHECKOUT, $country);
+ }
+ else
+ {
+ return $this->getCredentialsProperty('checkoutMerchantId', ConfigurationProvider::CHECKOUT, 'SE');
+ }
+ }
+
+ /**
+ * fetch Checkout Secret word, used for Checkout order type
+ *
+ * @return string
+ */
+ public function getCheckoutSecret($country = NULL)
+ {
+ if($country != NULL)
+ {
+ return $this->getCredentialsProperty('checkoutSecret', ConfigurationProvider::CHECKOUT, $country);
+ }
+ else
+ {
+ return $this->getCredentialsProperty('checkoutSecret', ConfigurationProvider::CHECKOUT, 'SE');
+ }
+ }
}
diff --git a/src/Config/config_prod.php b/src/Config/config_prod.php
index f2a77e92..3de73061 100644
--- a/src/Config/config_prod.php
+++ b/src/Config/config_prod.php
@@ -7,135 +7,135 @@
* own account credentials. Replace the values in the arrays with your credentials
* (supplied by your Svea account manager).
*/
-return array(
- 'integrationParams' => array(
- 'integrationcompany' => "myIntegrationCompany",
- 'integrationversion' => "myIntegrationVersion",
- 'integrationplatform' => "myIntegrationPlatform"
- ),
- 'commonCredentials' => array(
- 'merchantId' => '',
- 'secret' => ''
- ),
- 'checkoutCredentials' => array(
- 'checkoutMerchantId' => '',
- 'checkoutSecret' => ''
- ),
- 'defaultCountryCode' => 'SE',
- 'credentials' => array(
- 'SE' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::CHECKOUT => array(
- 'username' => '',
- 'password' => ''
- )
- ),
- 'NO' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::CHECKOUT => array(
- 'username' => '',
- 'password' => ''
- )
- ),
- 'FI' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::CHECKOUT => array(
- 'username' => '',
- 'password' => ''
- )
- ),
- 'DK' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- )
- ),
- 'NL' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- )
- ),
- 'DE' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- )
- )
- )
-);
\ No newline at end of file
+return [
+ 'integrationParams' => [
+ 'integrationcompany' => "myIntegrationCompany",
+ 'integrationversion' => "myIntegrationVersion",
+ 'integrationplatform' => "myIntegrationPlatform"
+ ],
+ 'commonCredentials' => [
+ 'merchantId' => '',
+ 'secret' => ''
+ ],
+ 'checkoutCredentials' => [
+ 'checkoutMerchantId' => '',
+ 'checkoutSecret' => ''
+ ],
+ 'defaultCountryCode' => 'SE',
+ 'credentials' => [
+ 'SE' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::CHECKOUT => [
+ 'username' => '',
+ 'password' => ''
+ ]
+ ],
+ 'NO' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::CHECKOUT => [
+ 'username' => '',
+ 'password' => ''
+ ]
+ ],
+ 'FI' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::CHECKOUT => [
+ 'username' => '',
+ 'password' => ''
+ ]
+ ],
+ 'DK' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ]
+ ],
+ 'NL' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ]
+ ],
+ 'DE' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ]
+ ]
+ ]
+];
\ No newline at end of file
diff --git a/src/Config/config_test.php b/src/Config/config_test.php
index 546edf1a..119d74b4 100644
--- a/src/Config/config_test.php
+++ b/src/Config/config_test.php
@@ -6,135 +6,135 @@
* This is Svea Test credentials, and you can use this parameters during developing and testing
* For production parameters you have to change config_prod.php file
*/
-return array(
- 'integrationParams' => array(
- 'integrationcompany' => "myIntegrationCompany",
- 'integrationversion' => "myIntegrationVersion",
- 'integrationplatform' => "myIntegrationPlatform"
- ),
- 'commonCredentials' => array(
- 'merchantId' => '1130',
- 'secret' => '8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3'
- ),
- 'checkoutCredentials' => array(
- 'checkoutMerchantId' => '100002',
- 'checkoutSecret' => '3862e010913d7c44f104ddb4b2881f810b50d5385244571c3327802e241140cc692522c04aa21c942793c8a69a8e55ca7b6131d9ac2a2ae2f4f7c52634fe30d2',
- ),
- 'defaultCountryCode' => 'SE',
- 'credentials' => array(
- 'SE' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => 'sverigetest',
- 'password' => 'sverigetest',
- 'clientNumber' => 79021
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => 'sverigetest',
- 'password' => 'sverigetest',
- 'clientNumber' => 59999
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => 'sverigetest',
- 'password' => 'sverigetest',
- 'clientNumber' => 58702
- ),
- ConfigurationProvider::CHECKOUT => array(
- 'checkoutMerchantId' => '124842', // Swedish test merchant
- 'checkoutSecret' => '1NDxpT2WQ4PW6Ud95rLWKD98xVr45Q8O9Vd52nomC7U9B18jp7lHCu7nsiTJO1NWXjSx26vE41jJ4rul7FUP1cGKXm4wakxt3iF7k63ayleb1xX9Di2wW46t9felsSPW'
- )
- ),
- 'NO' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => 'norgetest2',
- 'password' => 'norgetest2',
- 'clientNumber' => 33308
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => 'norgetest2',
- 'password' => 'norgetest2',
- 'clientNumber' => 32503
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::CHECKOUT => array(
- 'checkoutMerchantId' => '124941', // Norwegian test merchant
- 'checkoutSecret' => 'XDyrnJnhbvmOch6brKPbF6mVx4NG7Wqzzhm92tsrx3H2IB3m82QxqwM4EUz5Cq9X8kEPpfZxzayB4pfkVEAC2uemgEikIUTf3v1pHxAuRlGuycWt6XyKkjBm9oQxR6pG'
- )
- ),
- 'FI' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => 'finlandtest2',
- 'password' => 'finlandtest2',
- 'clientNumber' => 26136
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => 'finlandtest2',
- 'password' => 'finlandtest2',
- 'clientNumber' => 27136
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- ),
- ConfigurationProvider::CHECKOUT => array(
- 'checkoutMerchantId' => '', // No finnish test merchant yet
- 'checkoutSecret' => ''
- )
- ),
- 'DK' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => 'danmarktest2',
- 'password' => 'danmarktest2',
- 'clientNumber' => 62008
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => 'danmarktest2',
- 'password' => 'danmarktest2',
- 'clientNumber' => 64008
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- )
- ),
- 'NL' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => 'hollandtest',
- 'password' => 'hollandtest',
- 'clientNumber' => 85997
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => 'hollandtest',
- 'password' => 'hollandtest',
- 'clientNumber' => 86997
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- )
- ),
- 'DE' => array(
- ConfigurationProvider::INVOICE_TYPE => array(
- 'username' => 'germanytest',
- 'password' => 'germanytest',
- 'clientNumber' => 14997
- ),
- ConfigurationProvider::PAYMENTPLAN_TYPE => array(
- 'username' => 'germanytest',
- 'password' => 'germanytest',
- 'clientNumber' => 16997
- ),
- ConfigurationProvider::ACCOUNTCREDIT_TYPE => array(
- 'username' => '',
- 'password' => '',
- 'clientNumber' => ''
- )
- )
- )
-);
+return [
+ 'integrationParams' => [
+ 'integrationcompany' => "myIntegrationCompany",
+ 'integrationversion' => "myIntegrationVersion",
+ 'integrationplatform' => "myIntegrationPlatform"
+ ],
+ 'commonCredentials' => [
+ 'merchantId' => '1130',
+ 'secret' => '8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3'
+ ],
+ 'checkoutCredentials' => [
+ 'checkoutMerchantId' => '100002',
+ 'checkoutSecret' => '3862e010913d7c44f104ddb4b2881f810b50d5385244571c3327802e241140cc692522c04aa21c942793c8a69a8e55ca7b6131d9ac2a2ae2f4f7c52634fe30d2',
+ ],
+ 'defaultCountryCode' => 'SE',
+ 'credentials' => [
+ 'SE' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => 'sverigetest',
+ 'password' => 'sverigetest',
+ 'clientNumber' => 79021
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => 'sverigetest',
+ 'password' => 'sverigetest',
+ 'clientNumber' => 59999
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => 'sverigetest',
+ 'password' => 'sverigetest',
+ 'clientNumber' => 58702
+ ],
+ ConfigurationProvider::CHECKOUT => [
+ 'checkoutMerchantId' => '124842', // Swedish test merchant
+ 'checkoutSecret' => '1NDxpT2WQ4PW6Ud95rLWKD98xVr45Q8O9Vd52nomC7U9B18jp7lHCu7nsiTJO1NWXjSx26vE41jJ4rul7FUP1cGKXm4wakxt3iF7k63ayleb1xX9Di2wW46t9felsSPW'
+ ]
+ ],
+ 'NO' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => 'norgetest2',
+ 'password' => 'norgetest2',
+ 'clientNumber' => 33308
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => 'norgetest2',
+ 'password' => 'norgetest2',
+ 'clientNumber' => 32503
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::CHECKOUT => [
+ 'checkoutMerchantId' => '124941', // Norwegian test merchant
+ 'checkoutSecret' => 'XDyrnJnhbvmOch6brKPbF6mVx4NG7Wqzzhm92tsrx3H2IB3m82QxqwM4EUz5Cq9X8kEPpfZxzayB4pfkVEAC2uemgEikIUTf3v1pHxAuRlGuycWt6XyKkjBm9oQxR6pG'
+ ]
+ ],
+ 'FI' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => 'finlandtest2',
+ 'password' => 'finlandtest2',
+ 'clientNumber' => 26136
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => 'finlandtest2',
+ 'password' => 'finlandtest2',
+ 'clientNumber' => 27136
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ],
+ ConfigurationProvider::CHECKOUT => [
+ 'checkoutMerchantId' => '', // No finnish test merchant yet
+ 'checkoutSecret' => ''
+ ]
+ ],
+ 'DK' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => 'danmarktest2',
+ 'password' => 'danmarktest2',
+ 'clientNumber' => 62008
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => 'danmarktest2',
+ 'password' => 'danmarktest2',
+ 'clientNumber' => 64008
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ]
+ ],
+ 'NL' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => 'hollandtest',
+ 'password' => 'hollandtest',
+ 'clientNumber' => 85997
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => 'hollandtest',
+ 'password' => 'hollandtest',
+ 'clientNumber' => 86997
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ]
+ ],
+ 'DE' => [
+ ConfigurationProvider::INVOICE_TYPE => [
+ 'username' => 'germanytest',
+ 'password' => 'germanytest',
+ 'clientNumber' => 14997
+ ],
+ ConfigurationProvider::PAYMENTPLAN_TYPE => [
+ 'username' => 'germanytest',
+ 'password' => 'germanytest',
+ 'clientNumber' => 16997
+ ],
+ ConfigurationProvider::ACCOUNTCREDIT_TYPE => [
+ 'username' => '',
+ 'password' => '',
+ 'clientNumber' => ''
+ ]
+ ]
+ ]
+];
diff --git a/src/Constant/DistributionType.php b/src/Constant/DistributionType.php
index 6d05dca4..75ea06b2 100644
--- a/src/Constant/DistributionType.php
+++ b/src/Constant/DistributionType.php
@@ -8,8 +8,8 @@
* @author anne-hal
*/
abstract class DistributionType
-{
- const POST = "Post";
- const EMAIL = "Email";
- const EINVOICEB2B ="EInvoiceB2B";
+{
+ const POST = "Post";
+ const EMAIL = "Email";
+ const EINVOICEB2B ="EInvoiceB2B";
}
diff --git a/src/Constant/PaymentMethod.php b/src/Constant/PaymentMethod.php
index 7ed67b81..95c1b45c 100644
--- a/src/Constant/PaymentMethod.php
+++ b/src/Constant/PaymentMethod.php
@@ -8,39 +8,39 @@
*/
abstract class PaymentMethod
{
- const INVOICE = 'INVOICE';
- const PAYMENTPLAN = 'PAYMENTPLAN';
+ const INVOICE = 'INVOICE';
+ const PAYMENTPLAN = 'PAYMENTPLAN';
- //DIRECT
- const BANKAXESS = 'BANKAXESS';
- const AKTIA_FI = 'DBAKTIAFI';
- const ALANDSBANKEN_FI = 'DBALANDSBANKENFI';
- const DANSKEBANK_SE = 'DBDANSKEBANKSE';
- const NORDEA_EE = 'DBNORDEAEE';
- const NORDEA_FI = 'DBNORDEAFI';
- const NORDEA_SE = 'DBNORDEASE';
- const POHJOLA_FI = 'DBPOHJOLAFI';
- const SAMPOFI = 'DBSAMPOFI';
- const SEB_SE = 'DBSEBSE';
- const SEBFTG_SE = 'DBSEBFTGSE';
- const SHB_SE = 'DBSHBSE';
- const SHB_FI = 'DBSHBFI';
- const SPANKKI_FI = 'DBSPANKKIFI';
- const SWEDBANK_SE = 'DBSWEDBANKSE';
- const TAPIOLA_FI = 'DBTAPIOLAFI';
- const SWISH = 'SWISH';
+ //DIRECT
+ const BANKAXESS = 'BANKAXESS';
+ const AKTIA_FI = 'DBAKTIAFI';
+ const ALANDSBANKEN_FI = 'DBALANDSBANKENFI';
+ const DANSKEBANK_SE = 'DBDANSKEBANKSE';
+ const NORDEA_EE = 'DBNORDEAEE';
+ const NORDEA_FI = 'DBNORDEAFI';
+ const NORDEA_SE = 'DBNORDEASE';
+ const POHJOLA_FI = 'DBPOHJOLAFI';
+ const SAMPOFI = 'DBSAMPOFI';
+ const SEB_SE = 'DBSEBSE';
+ const SEBFTG_SE = 'DBSEBFTGSE';
+ const SHB_SE = 'DBSHBSE';
+ const SHB_FI = 'DBSHBFI';
+ const SPANKKI_FI = 'DBSPANKKIFI';
+ const SWEDBANK_SE = 'DBSWEDBANKSE';
+ const TAPIOLA_FI = 'DBTAPIOLAFI';
+ const SWISH = 'SWISH';
- //PaymentMethodType::CARD
- const KORTCERT = 'KORTCERT';
- const SVEACARDPAY = 'SVEACARDPAY';
- const SVEACARDPAY_PF = 'SVEACARDPAY_PF';
- const SKRILL = 'SKRILL';
- const KORTWN = 'KORTWN';
-
- //PREPAID
- const MICRODEB = 'MICRODEB';
-
- //PSP
- const PAYGROUND = 'PAYGROUND';
- const PAYPAL = 'PAYPAL';
+ //PaymentMethodType::CARD
+ const KORTCERT = 'KORTCERT';
+ const SVEACARDPAY = 'SVEACARDPAY';
+ const SVEACARDPAY_PF = 'SVEACARDPAY_PF';
+ const SKRILL = 'SKRILL';
+ const KORTWN = 'KORTWN';
+
+ //PREPAID
+ const MICRODEB = 'MICRODEB';
+
+ //PSP
+ const PAYGROUND = 'PAYGROUND';
+ const PAYPAL = 'PAYPAL';
}
diff --git a/src/Constant/SystemPaymentMethod.php b/src/Constant/SystemPaymentMethod.php
index 71d5eecf..163f3071 100644
--- a/src/Constant/SystemPaymentMethod.php
+++ b/src/Constant/SystemPaymentMethod.php
@@ -7,54 +7,54 @@
*/
abstract class SystemPaymentMethod
{
- //PaymentMethodType::DIRECT
- const BANKAXESS = 'BANKAXESS';
- const DBAKTIAFI = 'DBAKTIAFI';
- const DBALANDSBANKENFI = 'DBALANDSBANKENFI';
- const DBDANSKEBANKSE = 'DBDANSKEBANKSE';
- const DBNORDEAEE = 'DBNORDEAEE';
- const DBNORDEAFI = 'DBNORDEAFI';
- const DBNORDEASE = 'DBNORDEASE';
- const DBPOHJOLAFI = 'DBPOHJOLAFI';
- const DBSAMPOFI = 'DBSAMPOFI';
- const DBSEBSE = 'DBSEBSE';
- const DBSEBFTGSE = 'DBSEBFTGSE';
- const DBSHBFI = 'DBSHBFI';
- const DBSHBSE = 'DBSHBSE';
- const DBSPANKKIFI = 'DBSPANKKIFI';
- const DBSWEDBANKSE = 'DBSWEDBANKSE';
- const DBTAPIOLAFI = 'DBTAPIOLAFI';
-
- //PaymentMethodType::CARD
- const KORTCERT = 'KORTCERT';
- const SVEACARDPAY = 'SVEACARDPAY';
- const SVEACARDPAY_PF = 'SVEACARDPAY_PF';
-
- const SKRILL = 'SKRILL';
- const KORTWN = 'KORTWN';
-
- //PREPAID
- const MICRODEB = 'MICRODEB';
-
- //PSP
- const PAYGROUND = 'PAYGROUND';
- const PAYPAL = 'PAYPAL';
-
- //PaymentMethodType::INVOICE
- const INVOICESE = 'SVEAINVOICESE';
- const PAYMENTPLANSE = 'SVEASPLITSE';
- const INVOICE_SE = 'SVEAINVOICEEU_SE';
- const INVOICE_NO = 'SVEAINVOICEEU_NO';
- const INVOICE_DK = 'SVEAINVOICEEU_DK';
- const INVOICE_FI = 'SVEAINVOICEEU_FI';
- const INVOICE_NL = 'SVEAINVOICEEU_NL';
- const INVOICE_DE = 'SVEAINVOICEEU_DE';
-
- //PaymentMethodType::PAYMENTPLAN
- const PAYMENTPLAN_SE = 'SVEASPLITEU_SE';
- const PAYMENTPLAN_NO = 'SVEASPLITEU_NO';
- const PAYMENTPLAN_DK = 'SVEASPLITEU_DK';
- const PAYMENTPLAN_FI = 'SVEASPLITEU_FI';
- const PAYMENTPLAN_DE = 'SVEASPLITEU_DE';
- const PAYMENTPLAN_NL = 'SVEASPLITEU_NL';
+ //PaymentMethodType::DIRECT
+ const BANKAXESS = 'BANKAXESS';
+ const DBAKTIAFI = 'DBAKTIAFI';
+ const DBALANDSBANKENFI = 'DBALANDSBANKENFI';
+ const DBDANSKEBANKSE = 'DBDANSKEBANKSE';
+ const DBNORDEAEE = 'DBNORDEAEE';
+ const DBNORDEAFI = 'DBNORDEAFI';
+ const DBNORDEASE = 'DBNORDEASE';
+ const DBPOHJOLAFI = 'DBPOHJOLAFI';
+ const DBSAMPOFI = 'DBSAMPOFI';
+ const DBSEBSE = 'DBSEBSE';
+ const DBSEBFTGSE = 'DBSEBFTGSE';
+ const DBSHBFI = 'DBSHBFI';
+ const DBSHBSE = 'DBSHBSE';
+ const DBSPANKKIFI = 'DBSPANKKIFI';
+ const DBSWEDBANKSE = 'DBSWEDBANKSE';
+ const DBTAPIOLAFI = 'DBTAPIOLAFI';
+
+ //PaymentMethodType::CARD
+ const KORTCERT = 'KORTCERT';
+ const SVEACARDPAY = 'SVEACARDPAY';
+ const SVEACARDPAY_PF = 'SVEACARDPAY_PF';
+
+ const SKRILL = 'SKRILL';
+ const KORTWN = 'KORTWN';
+
+ //PREPAID
+ const MICRODEB = 'MICRODEB';
+
+ //PSP
+ const PAYGROUND = 'PAYGROUND';
+ const PAYPAL = 'PAYPAL';
+
+ //PaymentMethodType::INVOICE
+ const INVOICESE = 'SVEAINVOICESE';
+ const PAYMENTPLANSE = 'SVEASPLITSE';
+ const INVOICE_SE = 'SVEAINVOICEEU_SE';
+ const INVOICE_NO = 'SVEAINVOICEEU_NO';
+ const INVOICE_DK = 'SVEAINVOICEEU_DK';
+ const INVOICE_FI = 'SVEAINVOICEEU_FI';
+ const INVOICE_NL = 'SVEAINVOICEEU_NL';
+ const INVOICE_DE = 'SVEAINVOICEEU_DE';
+
+ //PaymentMethodType::PAYMENTPLAN
+ const PAYMENTPLAN_SE = 'SVEASPLITEU_SE';
+ const PAYMENTPLAN_NO = 'SVEASPLITEU_NO';
+ const PAYMENTPLAN_DK = 'SVEASPLITEU_DK';
+ const PAYMENTPLAN_FI = 'SVEASPLITEU_FI';
+ const PAYMENTPLAN_DE = 'SVEASPLITEU_DE';
+ const PAYMENTPLAN_NL = 'SVEASPLITEU_NL';
}
diff --git a/src/Helper/Helper.php b/src/Helper/Helper.php
index 76134378..361e3b17 100644
--- a/src/Helper/Helper.php
+++ b/src/Helper/Helper.php
@@ -14,371 +14,371 @@
class Helper
{
- /**
- * Takes a total discount value ex. vat, a mean tax rate & an array of allowed tax rates.
- * returns an array of FixedDiscount objects representing the discount split
- * over the allowed Tax Rates, defined using AmountExVat & VatPercent.
- *
- * Note: only supports two allowed tax rates for now.
- *
- * @deprecated -- use Helper::splitMeanAcrossTaxRates() instead
- */
- static function splitMeanToTwoTaxRates($discountAmountExVat, $discountMeanVat, $discountName, $discountDescription, $allowedTaxRates)
- {
-
- $fixedDiscounts = array();
-
- if (sizeof($allowedTaxRates) > 1) {
-
- // m = $discountMeanVat
- // r0 = allowedTaxRates[0]; r1 = allowedTaxRates[1]
- // m = a r0 + b r1 => m = a r0 + (1-a) r1 => m = (r0-r1) a + r1 => a = (m-r1)/(r0-r1)
- // d = $discountAmountExVat;
- // d = d (a+b) => 1 = a+b => b = 1-a
-
- $a = ($discountMeanVat - $allowedTaxRates[1]) / ($allowedTaxRates[0] - $allowedTaxRates[1]);
- $b = 1 - $a;
-
- $discountA = WebPayItem::fixedDiscount()
- ->setAmountExVat(Helper::bround(($discountAmountExVat * $a), 2))
- ->setVatPercent($allowedTaxRates[0])
- ->setName(isset($discountName) ? $discountName : "")
- ->setDescription((isset($discountDescription) ? $discountDescription : "") . ' (' . $allowedTaxRates[0] . '%)');
-
- $discountB = WebPayItem::fixedDiscount()
- ->setAmountExVat(Helper::bround(($discountAmountExVat * $b), 2))
- ->setVatPercent($allowedTaxRates[1])
- ->setName(isset($discountName) ? $discountName : "")
- ->setDescription((isset($discountDescription) ? $discountDescription : "") . ' (' . $allowedTaxRates[1] . '%)');
-
- $fixedDiscounts[] = $discountA;
- $fixedDiscounts[] = $discountB;
-
- } // single tax rate, so use shop supplied mean as vat rate
- else {
- $discountA = WebPayItem::fixedDiscount()
- ->setAmountExVat(Helper::bround(($discountAmountExVat), 2))
- ->setVatPercent($allowedTaxRates[0])
- ->setName(isset($discountName) ? $discountName : "")
- ->setDescription((isset($discountDescription) ? $discountDescription : ""));
- $fixedDiscounts[] = $discountA;
- }
-
- return $fixedDiscounts;
- }
-
- /**
- * w/PHP_ROUND_HALF_EVEN instead
- * @param $dVal
- * @param int $iDec
- * @return float
- */
- static function bround($dVal, $iDec = 0)
- {
- return round($dVal, $iDec, PHP_ROUND_HALF_EVEN);
- }
-
- /**
- * Takes a createOrderBuilder object, iterates over its orderRows, and
- * returns an array containing the distinct taxrates present in the order
- */
- static function getTaxRatesInOrder($order)
- {
- $taxRates = array();
-
- foreach ($order->orderRows as $orderRow) {
-
- if (isset($orderRow->vatPercent)) {
- $seenRate = $orderRow->vatPercent; //count
- } elseif (isset($orderRow->amountIncVat) && isset($orderRow->amountExVat)) {
- $seenRate = Helper::bround((($orderRow->amountIncVat - $orderRow->amountExVat) / $orderRow->amountExVat), 2) * 100;
- }
-
- if (isset($seenRate)) {
- isset($taxRates[$seenRate]) ? $taxRates[$seenRate] += 1 : $taxRates[$seenRate] = 1; // increase count of seen rate
- }
- }
-
- return array_keys($taxRates); //we want the keys
- }
-
- /**
- * Takes a streetaddress string and splits the streetname and the housenumber, returning them in an array
- * Handles many different street address formats, see test suite SplitAddressTest.php test cases for examples.
- *
- * If no match found, will return input streetaddress in position 0 and streetname, empty string in housenumber positions.
- *
- * @param string $address --
- * @return string -- array with the entire streetaddress in position 0, the streetname in position 1 and housenumber in position 2
- */
- static function splitStreetAddress($address)
- {
- //Separates the street from the housenumber according to testcases, handles unicode combined code points
- $pattern =
- "/^" . // start of string
- "(?:\s)*" . // non-matching group, consumes any leading whitespace
- "(\X*?)?" . // streetname group, lazy match of any graphemes
- "(?:[\s,])+" . // non-matching group, 1+ separating whitespace or comma
- "(\pN+\X*?)?" . // housenumber group, something staring with 1+ number, followed w/lazy match of any graphemes
- "(?:\s)*" . // non-matching group, consumes any trailing whitespace
- "$/u" // end of string, use unicode
- ;
- preg_match($pattern, $address, $addressArr);
-
- // fallback if no match w/regexp
- if (!array_key_exists(2, $addressArr)) {
- $addressArr[2] = "";
- } //fix for addresses w/o housenumber
- if (!array_key_exists(1, $addressArr)) {
- $addressArr[1] = $address;
- } //fix for no match, return entire input as streetname
- if (!array_key_exists(0, $addressArr)) {
- $addressArr[0] = $address;
- }
-
- return $addressArr;
- }
-
- /**
- * Given a Svea\WebPay\Config\ConfigurationProvider, return a json string containing the Svea integration package (library)
- * and integration (from config) name, version et al. Used by HostedService requests.
- * @param ConfigurationProvider $config
- * @return string in json format
- */
- static function getLibraryAndPlatformPropertiesAsJson($config)
- {
-
- $libraryProperties = Helper::getSveaLibraryProperties();
- $libraryName = $libraryProperties['library_name'];
- $libraryVersion = $libraryProperties['library_version'];
-
- $integrationProperties = Helper::getSveaIntegrationProperties($config);
- $integrationPlatform = $integrationProperties['integration_platform'];
- $integrationCompany = $integrationProperties['integration_company'];
- $integrationVersion = $integrationProperties['integration_version'];
-
- $properties_json = '{' .
- '"X-Svea-Library-Name": "' . $libraryName . '", ' .
- '"X-Svea-Library-Version": "' . $libraryVersion . '", ' .
- '"X-Svea-Integration-Platform": "' . $integrationPlatform . '", ' .
- '"X-Svea-Integration-Company": "' . $integrationCompany . '", ' .
- '"X-Svea-Integration-Version": "' . $integrationVersion . '"' .
- '}';
-
- return $properties_json;
- }
-
- static function getSveaLibraryProperties()
- {
- if (!defined('SVEA_REQUEST_DIR')) {
- define('SVEA_REQUEST_DIR', dirname(__FILE__));
- }
- $versionFile = file_get_contents(SVEA_REQUEST_DIR . "/../../version.json");
- $versionFile= json_decode($versionFile, true);
-
-
- // @todo change this to properly defined information
- $library_properties = array(
- 'library_name' => 'PHP Integration Package',
- 'library_version' => $versionFile['version'],
- );
-
- return $library_properties;
- }
-
- /**
- * Checks Svea\WebPay\Config\ConfigurationProvider for getIntegrationXX() methods, and returns associative array containing Svea integration platform, version et al.
- * array contains keys "integration_platform", "integration_version", "integration_company"
- * @param ConfigurationProvider $config
- * @return array
- */
- static function getSveaIntegrationProperties($config)
- {
- $integrationPlatform =
- method_exists($config, "getIntegrationPlatform") ? $config->getIntegrationPlatform() : "Integration platform not available";
- $integrationCompany =
- method_exists($config, "getIntegrationCompany") ? $config->getIntegrationCompany() : "Integration company not available";
- $integrationVersion =
- method_exists($config, "getIntegrationVersion") ? $config->getIntegrationVersion() : "Integration version not available";
-
- $integration_properties = array(
- "integration_platform" => $integrationPlatform,
- "integration_version" => $integrationVersion,
- "integration_company" => $integrationCompany
- );
-
- return $integration_properties;
- }
-
- /**
- * From a given total discount value, mean tax rate & an array of tax rates,
- * this functions returns an array of FixedDiscount objects representing the
- * discount split across the given tax rates. The FixedDiscount rows are set
- * using setAmountIncVat & setVatPercent.
- *
- * Note: this function is limited to one or two given tax rates at most. For
- * a mean tax rate of zero, a single discount row is returned.
- * @param $discountAmount
- * @param $discountMeanVat
- * @param $discountName
- * @param $discountDescription
- * @param $allowedTaxRates
- * @param bool $amountExVatFlag
- * @return array
- */
- static function splitMeanAcrossTaxRates($discountAmount, $discountMeanVat, $discountName, $discountDescription, $allowedTaxRates, $amountExVatFlag = true)
- {
-
- $fixedDiscounts = array();
-
- if ($discountMeanVat > 0) {
-
- if (sizeof($allowedTaxRates) == 2) {
-
- // m = $discountMeanVat
- // r0 = allowedTaxRates[0]; r1 = allowedTaxRates[1]
- // m = a r0 + b r1 => m = a r0 + (1-a) r1 => m = (r0-r1) a + r1 => a = (m-r1)/(r0-r1)
- // d = $discountAmountExVat;
- // d = d (a+b) => 1 = a+b => b = 1-a
-
- $a = ($discountMeanVat - $allowedTaxRates[1]) / ($allowedTaxRates[0] - $allowedTaxRates[1]);
- $b = 1 - $a;
-
- $discountAAmount = $discountAmount * $a *
- ($amountExVatFlag ? (1 + ($allowedTaxRates[0] / 100.00)) : (1 + ($allowedTaxRates[0] / 100.00)) / (1 + ($discountMeanVat / 100.00)));
- $discountA = WebPayItem::fixedDiscount()
- ->setAmountIncVat(Helper::bround($discountAAmount, 2))
- ->setVatPercent($allowedTaxRates[0])
- ->setName(isset($discountName) ? $discountName : "")
- ->setDescription((isset($discountDescription) ? $discountDescription : "") . ' (' . $allowedTaxRates[0] . '%)');
-
- $discountBAmount = $discountAmount * $b *
- ($amountExVatFlag ? (1 + ($allowedTaxRates[1] / 100.00)) : (1 + ($allowedTaxRates[1] / 100.00)) / (1 + ($discountMeanVat / 100.00)));
- $discountB = WebPayItem::fixedDiscount()
- ->setAmountIncVat(Helper::bround($discountBAmount, 2))
- ->setVatPercent($allowedTaxRates[1])
- ->setName(isset($discountName) ? $discountName : "")
- ->setDescription((isset($discountDescription) ? $discountDescription : "") . ' (' . $allowedTaxRates[1] . '%)');
-
- $fixedDiscounts[] = $discountA;
- $fixedDiscounts[] = $discountB;
- } elseif (sizeof($allowedTaxRates) == 1) {
- $discountIncVat = $discountAmount * ($amountExVatFlag ? (1 + ($discountMeanVat / 100.00)) : 1.0); // get amount inc vat if needed
-
- $discountA = WebPayItem::fixedDiscount()
- ->setAmountIncVat(Helper::bround(($discountIncVat), 2))
- ->setVatPercent($allowedTaxRates[0])
- ->setName(isset($discountName) ? $discountName : "")
- ->setDescription((isset($discountDescription) ? $discountDescription : ""));
- $fixedDiscounts[] = $discountA;
- }
- } // discountMeanVat <= 0;
- else {
- $discount = WebPayItem::fixedDiscount()
- ->setAmountIncVat(Helper::bround(($discountAmount), 2))
- ->setVatPercent(0.0)
- ->setName(isset($discountName) ? $discountName : "")
- ->setDescription((isset($discountDescription) ? $discountDescription : ""));
- $fixedDiscounts[] = $discount;
- }
-
- return $fixedDiscounts;
- }
-
- /**
- * Calculates price per month for all available campaigns.
- *
- * This is a helper function provided to calculate the monthly price for the
- * different payment plan options for a given sum. This information may be
- * used when displaying i.e. payment options to the customer by checkout, or
- * to display the lowest amount due per month to display on a product level.
- *
- * If the ignoreMaxAndMinFlag is set to true, the returned array also
- * contains the theoretical monthly installments for a given amount, even if
- * the campaign may not actually be available to use in a payment request,
- * should the amount fall outside of the actual campaign min/max limit. If
- * the flag is set to false or left out, the values array will not include
- * such amounts, which may result in an empty values array in the result.
- *
- * @deprecated Use Svea\WebPay\Helper\PaymentPlanHelper instead, will be removed in the future
- * @param float $price
- * @param $paymentPlanParamsResponseObject
- * @param boolean $ignoreMaxAndMinFlag ; optional, defaults to false
- * @param int $decimals ; optional, defaults to 0
- * @return PaymentPlanPricePerMonth
- */
- public static function paymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag = false, $decimals = 0)
- {
- return new PaymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag, $decimals);
- }
-
- public static function getCardPayCurrencies()
- {
- $currencyList = array(
- "SEK",
- "NOK",
- "DKK",
- "EUR",
- "USD",
- "GBP",
- "PLN"
- );
- return $currencyList;
- }
-
- public static function isCardPayCurrency($currency)
- {
- foreach(self::getCardPayCurrencies() as $cardPayCurrency)
- {
- if(strtoupper($currency) === $cardPayCurrency)
- {
- return true;
- }
- }
- return false;
- }
-
- public static function isValidPeppolId($peppolId)
- {
-
- if(is_numeric(substr($peppolId,0,4)) == false ) // First 4 characters must be numeric
- {
- return false;
- }
-
- if(substr($peppolId,4,1) != ":") // Fifth character must be ':'.
- {
- return false;
- }
-
- if(ctype_alnum(substr($peppolId,6)) == false) // Rest of the characters must be alphanumeric
- {
- return false;
- }
-
- if(strlen($peppolId) > 55) // String cannot be longer 55 characters
- {
- return false;
- }
-
- if(strlen($peppolId) < 6) // String must be longer than 5 characters
- {
- return false;
- }
- return true;
- }
-
- public static function objectToArray($data)
- {
- if (is_array($data) || is_object($data))
- {
- $result = array();
- foreach ($data as $key => $value)
- {
- $result[$key] = Helper::objectToArray($value);
- }
- return $result;
- }
- return $data;
- }
+ /**
+ * Takes a total discount value ex. vat, a mean tax rate & an array of allowed tax rates.
+ * returns an array of FixedDiscount objects representing the discount split
+ * over the allowed Tax Rates, defined using AmountExVat & VatPercent.
+ *
+ * Note: only supports two allowed tax rates for now.
+ *
+ * @deprecated -- use Helper::splitMeanAcrossTaxRates() instead
+ */
+ static function splitMeanToTwoTaxRates($discountAmountExVat, $discountMeanVat, $discountName, $discountDescription, $allowedTaxRates)
+ {
+
+ $fixedDiscounts = [];
+
+ if (sizeof($allowedTaxRates) > 1) {
+
+ // m = $discountMeanVat
+ // r0 = allowedTaxRates[0]; r1 = allowedTaxRates[1]
+ // m = a r0 + b r1 => m = a r0 + (1-a) r1 => m = (r0-r1) a + r1 => a = (m-r1)/(r0-r1)
+ // d = $discountAmountExVat;
+ // d = d (a+b) => 1 = a+b => b = 1-a
+
+ $a = ($discountMeanVat - $allowedTaxRates[1]) / ($allowedTaxRates[0] - $allowedTaxRates[1]);
+ $b = 1 - $a;
+
+ $discountA = WebPayItem::fixedDiscount()
+ ->setAmountExVat(Helper::bround(($discountAmountExVat * $a), 2))
+ ->setVatPercent($allowedTaxRates[0])
+ ->setName(isset($discountName) ? $discountName : "")
+ ->setDescription((isset($discountDescription) ? $discountDescription : "") . ' (' . $allowedTaxRates[0] . '%)');
+
+ $discountB = WebPayItem::fixedDiscount()
+ ->setAmountExVat(Helper::bround(($discountAmountExVat * $b), 2))
+ ->setVatPercent($allowedTaxRates[1])
+ ->setName(isset($discountName) ? $discountName : "")
+ ->setDescription((isset($discountDescription) ? $discountDescription : "") . ' (' . $allowedTaxRates[1] . '%)');
+
+ $fixedDiscounts[] = $discountA;
+ $fixedDiscounts[] = $discountB;
+
+ } // single tax rate, so use shop supplied mean as vat rate
+ else {
+ $discountA = WebPayItem::fixedDiscount()
+ ->setAmountExVat(Helper::bround(($discountAmountExVat), 2))
+ ->setVatPercent($allowedTaxRates[0])
+ ->setName(isset($discountName) ? $discountName : "")
+ ->setDescription((isset($discountDescription) ? $discountDescription : ""));
+ $fixedDiscounts[] = $discountA;
+ }
+
+ return $fixedDiscounts;
+ }
+
+ /**
+ * w/PHP_ROUND_HALF_EVEN instead
+ * @param $dVal
+ * @param int $iDec
+ * @return float
+ */
+ static function bround($dVal, $iDec = 0)
+ {
+ return round($dVal, $iDec, PHP_ROUND_HALF_EVEN);
+ }
+
+ /**
+ * Takes a createOrderBuilder object, iterates over its orderRows, and
+ * returns an array containing the distinct taxrates present in the order
+ */
+ static function getTaxRatesInOrder($order)
+ {
+ $taxRates = [];
+
+ foreach ($order->orderRows as $orderRow) {
+
+ if (isset($orderRow->vatPercent)) {
+ $seenRate = $orderRow->vatPercent; //count
+ } elseif (isset($orderRow->amountIncVat) && isset($orderRow->amountExVat)) {
+ $seenRate = Helper::bround((($orderRow->amountIncVat - $orderRow->amountExVat) / $orderRow->amountExVat), 2) * 100;
+ }
+
+ if (isset($seenRate)) {
+ isset($taxRates[$seenRate]) ? $taxRates[$seenRate] += 1 : $taxRates[$seenRate] = 1; // increase count of seen rate
+ }
+ }
+
+ return array_keys($taxRates); //we want the keys
+ }
+
+ /**
+ * Takes a streetaddress string and splits the streetname and the housenumber, returning them in an array
+ * Handles many different street address formats, see test suite SplitAddressTest.php test cases for examples.
+ *
+ * If no match found, will return input streetaddress in position 0 and streetname, empty string in housenumber positions.
+ *
+ * @param string $address --
+ * @return string -- array with the entire streetaddress in position 0, the streetname in position 1 and housenumber in position 2
+ */
+ static function splitStreetAddress($address)
+ {
+ //Separates the street from the housenumber according to testcases, handles unicode combined code points
+ $pattern =
+ "/^" . // start of string
+ "(?:\s)*" . // non-matching group, consumes any leading whitespace
+ "(\X*?)?" . // streetname group, lazy match of any graphemes
+ "(?:[\s,])+" . // non-matching group, 1+ separating whitespace or comma
+ "(\pN+\X*?)?" . // housenumber group, something staring with 1+ number, followed w/lazy match of any graphemes
+ "(?:\s)*" . // non-matching group, consumes any trailing whitespace
+ "$/u" // end of string, use unicode
+ ;
+ preg_match($pattern, $address, $addressArr);
+
+ // fallback if no match w/regexp
+ if (!array_key_exists(2, $addressArr)) {
+ $addressArr[2] = "";
+ } //fix for addresses w/o housenumber
+ if (!array_key_exists(1, $addressArr)) {
+ $addressArr[1] = $address;
+ } //fix for no match, return entire input as streetname
+ if (!array_key_exists(0, $addressArr)) {
+ $addressArr[0] = $address;
+ }
+
+ return $addressArr;
+ }
+
+ /**
+ * Given a Svea\WebPay\Config\ConfigurationProvider, return a json string containing the Svea integration package (library)
+ * and integration (from config) name, version et al. Used by HostedService requests.
+ * @param ConfigurationProvider $config
+ * @return string in json format
+ */
+ static function getLibraryAndPlatformPropertiesAsJson($config)
+ {
+
+ $libraryProperties = Helper::getSveaLibraryProperties();
+ $libraryName = $libraryProperties['library_name'];
+ $libraryVersion = $libraryProperties['library_version'];
+
+ $integrationProperties = Helper::getSveaIntegrationProperties($config);
+ $integrationPlatform = $integrationProperties['integration_platform'];
+ $integrationCompany = $integrationProperties['integration_company'];
+ $integrationVersion = $integrationProperties['integration_version'];
+
+ $properties_json = '{' .
+ '"X-Svea-Library-Name": "' . $libraryName . '", ' .
+ '"X-Svea-Library-Version": "' . $libraryVersion . '", ' .
+ '"X-Svea-Integration-Platform": "' . $integrationPlatform . '", ' .
+ '"X-Svea-Integration-Company": "' . $integrationCompany . '", ' .
+ '"X-Svea-Integration-Version": "' . $integrationVersion . '"' .
+ '}';
+
+ return $properties_json;
+ }
+
+ static function getSveaLibraryProperties()
+ {
+ if (!defined('SVEA_REQUEST_DIR')) {
+ define('SVEA_REQUEST_DIR', dirname(__FILE__));
+ }
+ $versionFile = file_get_contents(SVEA_REQUEST_DIR . "/../../version.json");
+ $versionFile= json_decode($versionFile, true);
+
+
+ // @todo change this to properly defined information
+ $library_properties = [
+ 'library_name' => 'PHP Integration Package',
+ 'library_version' => $versionFile['version'],
+ ];
+
+ return $library_properties;
+ }
+
+ /**
+ * Checks Svea\WebPay\Config\ConfigurationProvider for getIntegrationXX() methods, and returns associative array containing Svea integration platform, version et al.
+ * array contains keys "integration_platform", "integration_version", "integration_company"
+ * @param ConfigurationProvider $config
+ * @return array
+ */
+ static function getSveaIntegrationProperties($config)
+ {
+ $integrationPlatform =
+ method_exists($config, "getIntegrationPlatform") ? $config->getIntegrationPlatform() : "Integration platform not available";
+ $integrationCompany =
+ method_exists($config, "getIntegrationCompany") ? $config->getIntegrationCompany() : "Integration company not available";
+ $integrationVersion =
+ method_exists($config, "getIntegrationVersion") ? $config->getIntegrationVersion() : "Integration version not available";
+
+ $integration_properties = [
+ "integration_platform" => $integrationPlatform,
+ "integration_version" => $integrationVersion,
+ "integration_company" => $integrationCompany
+ ];
+
+ return $integration_properties;
+ }
+
+ /**
+ * From a given total discount value, mean tax rate & an array of tax rates,
+ * this functions returns an array of FixedDiscount objects representing the
+ * discount split across the given tax rates. The FixedDiscount rows are set
+ * using setAmountIncVat & setVatPercent.
+ *
+ * Note: this function is limited to one or two given tax rates at most. For
+ * a mean tax rate of zero, a single discount row is returned.
+ * @param $discountAmount
+ * @param $discountMeanVat
+ * @param $discountName
+ * @param $discountDescription
+ * @param $allowedTaxRates
+ * @param bool $amountExVatFlag
+ * @return array
+ */
+ static function splitMeanAcrossTaxRates($discountAmount, $discountMeanVat, $discountName, $discountDescription, $allowedTaxRates, $amountExVatFlag = true)
+ {
+
+ $fixedDiscounts = [];
+
+ if ($discountMeanVat > 0) {
+
+ if (sizeof($allowedTaxRates) == 2) {
+
+ // m = $discountMeanVat
+ // r0 = allowedTaxRates[0]; r1 = allowedTaxRates[1]
+ // m = a r0 + b r1 => m = a r0 + (1-a) r1 => m = (r0-r1) a + r1 => a = (m-r1)/(r0-r1)
+ // d = $discountAmountExVat;
+ // d = d (a+b) => 1 = a+b => b = 1-a
+
+ $a = ($discountMeanVat - $allowedTaxRates[1]) / ($allowedTaxRates[0] - $allowedTaxRates[1]);
+ $b = 1 - $a;
+
+ $discountAAmount = $discountAmount * $a *
+ ($amountExVatFlag ? (1 + ($allowedTaxRates[0] / 100.00)) : (1 + ($allowedTaxRates[0] / 100.00)) / (1 + ($discountMeanVat / 100.00)));
+ $discountA = WebPayItem::fixedDiscount()
+ ->setAmountIncVat(Helper::bround($discountAAmount, 2))
+ ->setVatPercent($allowedTaxRates[0])
+ ->setName(isset($discountName) ? $discountName : "")
+ ->setDescription((isset($discountDescription) ? $discountDescription : "") . ' (' . $allowedTaxRates[0] . '%)');
+
+ $discountBAmount = $discountAmount * $b *
+ ($amountExVatFlag ? (1 + ($allowedTaxRates[1] / 100.00)) : (1 + ($allowedTaxRates[1] / 100.00)) / (1 + ($discountMeanVat / 100.00)));
+ $discountB = WebPayItem::fixedDiscount()
+ ->setAmountIncVat(Helper::bround($discountBAmount, 2))
+ ->setVatPercent($allowedTaxRates[1])
+ ->setName(isset($discountName) ? $discountName : "")
+ ->setDescription((isset($discountDescription) ? $discountDescription : "") . ' (' . $allowedTaxRates[1] . '%)');
+
+ $fixedDiscounts[] = $discountA;
+ $fixedDiscounts[] = $discountB;
+ } elseif (sizeof($allowedTaxRates) == 1) {
+ $discountIncVat = $discountAmount * ($amountExVatFlag ? (1 + ($discountMeanVat / 100.00)) : 1.0); // get amount inc vat if needed
+
+ $discountA = WebPayItem::fixedDiscount()
+ ->setAmountIncVat(Helper::bround(($discountIncVat), 2))
+ ->setVatPercent($allowedTaxRates[0])
+ ->setName(isset($discountName) ? $discountName : "")
+ ->setDescription((isset($discountDescription) ? $discountDescription : ""));
+ $fixedDiscounts[] = $discountA;
+ }
+ } // discountMeanVat <= 0;
+ else {
+ $discount = WebPayItem::fixedDiscount()
+ ->setAmountIncVat(Helper::bround(($discountAmount), 2))
+ ->setVatPercent(0.0)
+ ->setName(isset($discountName) ? $discountName : "")
+ ->setDescription((isset($discountDescription) ? $discountDescription : ""));
+ $fixedDiscounts[] = $discount;
+ }
+
+ return $fixedDiscounts;
+ }
+
+ /**
+ * Calculates price per month for all available campaigns.
+ *
+ * This is a helper function provided to calculate the monthly price for the
+ * different payment plan options for a given sum. This information may be
+ * used when displaying i.e. payment options to the customer by checkout, or
+ * to display the lowest amount due per month to display on a product level.
+ *
+ * If the ignoreMaxAndMinFlag is set to true, the returned array also
+ * contains the theoretical monthly installments for a given amount, even if
+ * the campaign may not actually be available to use in a payment request,
+ * should the amount fall outside of the actual campaign min/max limit. If
+ * the flag is set to false or left out, the values array will not include
+ * such amounts, which may result in an empty values array in the result.
+ *
+ * @deprecated Use Svea\WebPay\Helper\PaymentPlanHelper instead, will be removed in the future
+ * @param float $price
+ * @param $paymentPlanParamsResponseObject
+ * @param boolean $ignoreMaxAndMinFlag ; optional, defaults to false
+ * @param int $decimals ; optional, defaults to 0
+ * @return PaymentPlanPricePerMonth
+ */
+ public static function paymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag = false, $decimals = 0)
+ {
+ return new PaymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag, $decimals);
+ }
+
+ public static function getCardPayCurrencies()
+ {
+ $currencyList = [
+ "SEK",
+ "NOK",
+ "DKK",
+ "EUR",
+ "USD",
+ "GBP",
+ "PLN"
+ ];
+ return $currencyList;
+ }
+
+ public static function isCardPayCurrency($currency)
+ {
+ foreach(self::getCardPayCurrencies() as $cardPayCurrency)
+ {
+ if(strtoupper($currency) === $cardPayCurrency)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static function isValidPeppolId($peppolId)
+ {
+
+ if(is_numeric(substr($peppolId,0,4)) == false ) // First 4 characters must be numeric
+ {
+ return false;
+ }
+
+ if(substr($peppolId,4,1) != ":") // Fifth character must be ':'.
+ {
+ return false;
+ }
+
+ if(ctype_alnum(substr($peppolId,6)) == false) // Rest of the characters must be alphanumeric
+ {
+ return false;
+ }
+
+ if(strlen($peppolId) > 55) // String cannot be longer 55 characters
+ {
+ return false;
+ }
+
+ if(strlen($peppolId) < 6) // String must be longer than 5 characters
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public static function objectToArray($data)
+ {
+ if (is_array($data) || is_object($data))
+ {
+ $result = [];
+ foreach ($data as $key => $value)
+ {
+ $result[$key] = Helper::objectToArray($value);
+ }
+ return $result;
+ }
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/EffectiveInterestRateCalculator.php b/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/EffectiveInterestRateCalculator.php
index f0b5c64c..d63ce6ed 100644
--- a/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/EffectiveInterestRateCalculator.php
+++ b/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/EffectiveInterestRateCalculator.php
@@ -8,99 +8,99 @@
class EffectiveInterestRateCalculator
{
- private $oneMonth = 0.08327627652; // Factor of month average length divided by average year length (leap years etc)
- private $tolerance = 0.00000001;
- private $initialLowerBound = 0;
- private $initialUpperBound = 10000000;
- private $payments = array();
- private $sizeOfLoan;
-
- public function __construct($sizeOfLoan)
- {
- $this->sizeOfLoan = $sizeOfLoan;
- }
-
- /**
- * @param $sizeOfLoan
- * @param $firstPayment
- * @param $monthlyPayment
- * @param $contactLengthInMonths
- * @param $deferralPeriodInMonths
- * @return float|int
- * @throws ValidationException
- */
- public function calculate($sizeOfLoan, $firstPayment, $monthlyPayment, $contactLengthInMonths, $deferralPeriodInMonths)
- {
- if($monthlyPayment < 0)
- {
- throw new ValidationException("Monthly payment can not be below 0");
- }
- if($contactLengthInMonths < 1)
- {
- throw new ValidationException("Contract length must be at least 1 month");
- }
-
- $firstPaymentMonth = min($contactLengthInMonths, $deferralPeriodInMonths + 1);
- $this->addPayment($this->oneMonth * $firstPaymentMonth, $firstPayment);
-
- for($month = $firstPaymentMonth + 1; $month <= $contactLengthInMonths; $month++)
- {
- $this->addPayment($this->oneMonth * $month, $monthlyPayment);
- }
-
- if(array_sum(array_column($this->payments, 'amount')) - $sizeOfLoan < 0.1)
- {
- return 0;
- }
-
- return Helper::bround($this->solveUsingBisection() * 100, 2);
- }
-
- /**
- * @return float|int
- * @throws ValidationException
- */
- public function solveUsingBisection()
- {
- $lowerBound = $this->initialLowerBound;
- $upperBound = $this->initialUpperBound;
-
- while($upperBound - $lowerBound > $this->tolerance)
- {
- $newPoint = $lowerBound + ($upperBound - $lowerBound) / 2;
- if($this->sign($this->evaluate($lowerBound)) == $this->sign($this->evaluate($newPoint)))
- {
- $lowerBound = $newPoint;
- }
- else
- {
- $upperBound = $newPoint;
- }
- }
-
- if(abs($lowerBound - $this->initialLowerBound) < 2 * $this->tolerance || abs($upperBound - $this->initialUpperBound) < 2 * $this->tolerance)
- {
- throw new ValidationException("No solution found");
- }
- return $lowerBound;
- }
-
- private function sign( $number ) {
- return ( $number > 0 ) ? 1 : ( ( $number < 0 ) ? -1 : 0 );
- }
-
- private function evaluate($val)
- {
- $sum = 0;
- foreach($this->payments as $value)
- {
- $sum += $value['amount'] / pow(1 + $val, $value['timeToPaymentInYears']);
- }
- return $sum - $this->sizeOfLoan;
- }
-
- public function addPayment($timeToPaymentInYears, $amount)
- {
- array_push($this->payments, array('timeToPaymentInYears' => $timeToPaymentInYears, 'amount' => $amount));
- }
+ private $oneMonth = 0.08327627652; // Factor of month average length divided by average year length (leap years etc)
+ private $tolerance = 0.00000001;
+ private $initialLowerBound = 0;
+ private $initialUpperBound = 10000000;
+ private $payments = [];
+ private $sizeOfLoan;
+
+ public function __construct($sizeOfLoan)
+ {
+ $this->sizeOfLoan = $sizeOfLoan;
+ }
+
+ /**
+ * @param $sizeOfLoan
+ * @param $firstPayment
+ * @param $monthlyPayment
+ * @param $contactLengthInMonths
+ * @param $deferralPeriodInMonths
+ * @return float|int
+ * @throws ValidationException
+ */
+ public function calculate($sizeOfLoan, $firstPayment, $monthlyPayment, $contactLengthInMonths, $deferralPeriodInMonths)
+ {
+ if($monthlyPayment < 0)
+ {
+ throw new ValidationException("Monthly payment can not be below 0");
+ }
+ if($contactLengthInMonths < 1)
+ {
+ throw new ValidationException("Contract length must be at least 1 month");
+ }
+
+ $firstPaymentMonth = min($contactLengthInMonths, $deferralPeriodInMonths + 1);
+ $this->addPayment($this->oneMonth * $firstPaymentMonth, $firstPayment);
+
+ for($month = $firstPaymentMonth + 1; $month <= $contactLengthInMonths; $month++)
+ {
+ $this->addPayment($this->oneMonth * $month, $monthlyPayment);
+ }
+
+ if(array_sum(array_column($this->payments, 'amount')) - $sizeOfLoan < 0.1)
+ {
+ return 0;
+ }
+
+ return Helper::bround($this->solveUsingBisection() * 100, 2);
+ }
+
+ /**
+ * @return float|int
+ * @throws ValidationException
+ */
+ public function solveUsingBisection()
+ {
+ $lowerBound = $this->initialLowerBound;
+ $upperBound = $this->initialUpperBound;
+
+ while($upperBound - $lowerBound > $this->tolerance)
+ {
+ $newPoint = $lowerBound + ($upperBound - $lowerBound) / 2;
+ if($this->sign($this->evaluate($lowerBound)) == $this->sign($this->evaluate($newPoint)))
+ {
+ $lowerBound = $newPoint;
+ }
+ else
+ {
+ $upperBound = $newPoint;
+ }
+ }
+
+ if(abs($lowerBound - $this->initialLowerBound) < 2 * $this->tolerance || abs($upperBound - $this->initialUpperBound) < 2 * $this->tolerance)
+ {
+ throw new ValidationException("No solution found");
+ }
+ return $lowerBound;
+ }
+
+ private function sign( $number ) {
+ return ( $number > 0 ) ? 1 : ( ( $number < 0 ) ? -1 : 0 );
+ }
+
+ private function evaluate($val)
+ {
+ $sum = 0;
+ foreach($this->payments as $value)
+ {
+ $sum += $value['amount'] / pow(1 + $val, $value['timeToPaymentInYears']);
+ }
+ return $sum - $this->sizeOfLoan;
+ }
+
+ public function addPayment($timeToPaymentInYears, $amount)
+ {
+ array_push($this->payments, ['timeToPaymentInYears' => $timeToPaymentInYears, 'amount' => $amount]);
+ }
}
\ No newline at end of file
diff --git a/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/IPaymentPlanCalculator.php b/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/IPaymentPlanCalculator.php
index f203173f..c8409350 100644
--- a/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/IPaymentPlanCalculator.php
+++ b/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/IPaymentPlanCalculator.php
@@ -6,9 +6,9 @@
interface IPaymentPlanCalculator
{
- static public function calculateTotalAmountToPay($totalPrice, $campaign, $decimals = 0);
- static public function calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals = 0);
- static public function calculateEffectiveInterestRate($totalPrice, $campaign, $decimals = 0);
- static public function calculatePaymentFactor($numberOfPayments, $yearlyInterestRate, $paymentFrequencyPerYear = 12);
- static public function calculateMonthlyAnnuityAmount($totalPrice, $campaign);
+ static public function calculateTotalAmountToPay($totalPrice, $campaign, $decimals = 0);
+ static public function calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals = 0);
+ static public function calculateEffectiveInterestRate($totalPrice, $campaign, $decimals = 0);
+ static public function calculatePaymentFactor($numberOfPayments, $yearlyInterestRate, $paymentFrequencyPerYear = 12);
+ static public function calculateMonthlyAnnuityAmount($totalPrice, $campaign);
}
\ No newline at end of file
diff --git a/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/InterestAndAmortizationFreePaymentPlanCalculator.php b/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/InterestAndAmortizationFreePaymentPlanCalculator.php
index ec4ef41e..459dd393 100644
--- a/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/InterestAndAmortizationFreePaymentPlanCalculator.php
+++ b/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/InterestAndAmortizationFreePaymentPlanCalculator.php
@@ -7,32 +7,32 @@
class InterestAndAmortizationFreePaymentPlanCalculator implements IPaymentPlanCalculator
{
- public static function calculateTotalAmountToPay($totalPrice, $campaign, $decimals = 0)
- {
- return $totalPrice + $campaign['notificationFee'] + $campaign['initialFee'];
- }
-
- public static function calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals = 0)
- {
- return $totalPrice + $campaign['notificationFee'] + $campaign['initialFee'];
- }
-
- public static function calculateEffectiveInterestRate($totalPrice, $campaign, $decimals = 0)
- {
- $effectiveCalculator = new EffectiveInterestRateCalculator($totalPrice);
- $firstPayment = $campaign['initialFee'] + $campaign['notificationFee'] + Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals);
- $monthlyAmount = Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals) + $campaign['notificationFee'];
- return $effectiveCalculator->calculate($totalPrice, $firstPayment, $monthlyAmount, $campaign['contractLengthInMonths'], $campaign['numberOfPaymentFreeMonths']);
- }
-
- public static function calculatePaymentFactor($numberOfPayments, $yearlyInterestRate, $paymentFrequencyPerYear = 12)
- {
- return 1;
- }
-
- public static function calculateMonthlyAnnuityAmount($totalPrice, $campaign)
- {
- return $totalPrice;
- }
+ public static function calculateTotalAmountToPay($totalPrice, $campaign, $decimals = 0)
+ {
+ return $totalPrice + $campaign['notificationFee'] + $campaign['initialFee'];
+ }
+
+ public static function calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals = 0)
+ {
+ return $totalPrice + $campaign['notificationFee'] + $campaign['initialFee'];
+ }
+
+ public static function calculateEffectiveInterestRate($totalPrice, $campaign, $decimals = 0)
+ {
+ $effectiveCalculator = new EffectiveInterestRateCalculator($totalPrice);
+ $firstPayment = $campaign['initialFee'] + $campaign['notificationFee'] + Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals);
+ $monthlyAmount = Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals) + $campaign['notificationFee'];
+ return $effectiveCalculator->calculate($totalPrice, $firstPayment, $monthlyAmount, $campaign['contractLengthInMonths'], $campaign['numberOfPaymentFreeMonths']);
+ }
+
+ public static function calculatePaymentFactor($numberOfPayments, $yearlyInterestRate, $paymentFrequencyPerYear = 12)
+ {
+ return 1;
+ }
+
+ public static function calculateMonthlyAnnuityAmount($totalPrice, $campaign)
+ {
+ return $totalPrice;
+ }
}
\ No newline at end of file
diff --git a/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/InterestFreePaymentPlanCalculator.php b/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/InterestFreePaymentPlanCalculator.php
index 601f5735..3f77f00e 100644
--- a/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/InterestFreePaymentPlanCalculator.php
+++ b/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/InterestFreePaymentPlanCalculator.php
@@ -7,33 +7,33 @@
class InterestFreePaymentPlanCalculator implements IPaymentPlanCalculator
{
- public static function calculateTotalAmountToPay($totalPrice, $campaign, $decimals = 0)
- {
- return $totalPrice + $campaign['initialFee'] + $campaign['notificationFee'] * max(1, $campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths']);
- }
-
- public static function calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals = 0)
- {
- return Helper::bround(self::calculateTotalAmountToPay($totalPrice, $campaign) / max(1, $campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths']), $decimals);
- }
-
- public static function calculateEffectiveInterestRate($totalPrice, $campaign, $decimals = 0)
- {
- $effectiveCalculator = new EffectiveInterestRateCalculator($totalPrice);
- $firstPayment = $campaign['initialFee'] + $campaign['notificationFee'] + Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals);
- $monthlyAmount = Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals) + $campaign['notificationFee'];
- return $effectiveCalculator->calculate($totalPrice, $firstPayment, $monthlyAmount, $campaign['contractLengthInMonths'], $campaign['numberOfPaymentFreeMonths']);
- }
-
- public static function calculatePaymentFactor($numberOfPayments, $yearlyInterestRate, $paymentFrequencyPerYear = 12)
- {
- return 1 / $numberOfPayments;
- }
-
- public static function calculateMonthlyAnnuityAmount($totalPrice, $campaign)
- {
- $paymentFactor = self::calculatePaymentFactor($campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths'],
- $campaign['interestRatePercent']);
- return $totalPrice * $paymentFactor;
- }
+ public static function calculateTotalAmountToPay($totalPrice, $campaign, $decimals = 0)
+ {
+ return $totalPrice + $campaign['initialFee'] + $campaign['notificationFee'] * max(1, $campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths']);
+ }
+
+ public static function calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals = 0)
+ {
+ return Helper::bround(self::calculateTotalAmountToPay($totalPrice, $campaign) / max(1, $campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths']), $decimals);
+ }
+
+ public static function calculateEffectiveInterestRate($totalPrice, $campaign, $decimals = 0)
+ {
+ $effectiveCalculator = new EffectiveInterestRateCalculator($totalPrice);
+ $firstPayment = $campaign['initialFee'] + $campaign['notificationFee'] + Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals);
+ $monthlyAmount = Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals) + $campaign['notificationFee'];
+ return $effectiveCalculator->calculate($totalPrice, $firstPayment, $monthlyAmount, $campaign['contractLengthInMonths'], $campaign['numberOfPaymentFreeMonths']);
+ }
+
+ public static function calculatePaymentFactor($numberOfPayments, $yearlyInterestRate, $paymentFrequencyPerYear = 12)
+ {
+ return 1 / $numberOfPayments;
+ }
+
+ public static function calculateMonthlyAnnuityAmount($totalPrice, $campaign)
+ {
+ $paymentFactor = self::calculatePaymentFactor($campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths'],
+ $campaign['interestRatePercent']);
+ return $totalPrice * $paymentFactor;
+ }
}
\ No newline at end of file
diff --git a/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/StandardPaymentPlanCalculator.php b/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/StandardPaymentPlanCalculator.php
index 0d564593..5199dd4a 100644
--- a/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/StandardPaymentPlanCalculator.php
+++ b/src/Helper/PaymentPlanHelper/CampaignTypeCalculator/StandardPaymentPlanCalculator.php
@@ -7,34 +7,34 @@
class StandardPaymentPlanCalculator implements IPaymentPlanCalculator
{
- public static function calculateTotalAmountToPay($totalPrice, $campaign , $decimals = 0)
- {
- $numberOfPayments = max( 1, $campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths']);
- $paymentFactor = self::calculatePaymentFactor($numberOfPayments, $campaign['interestRatePercent']/ 100);
- return Helper::bround($campaign['initialFee'] + ($totalPrice * $paymentFactor + $campaign['notificationFee']) * $numberOfPayments, $decimals);
- }
- public static function calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals = 0)
- {
- return Helper::bround(self::calculateTotalAmountToPay($totalPrice, $campaign, $decimals) / max(1, $campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths']), $decimals);
- }
- public static function calculateEffectiveInterestRate($totalPrice, $campaign, $decimals = 0)
- {
- $effectiveCalculator = new EffectiveInterestRateCalculator($totalPrice);
- $firstPayment = $campaign['initialFee'] + $campaign['notificationFee'] + Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals);
- $monthlyAmount = Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals) + $campaign['notificationFee'];
- return $effectiveCalculator->calculate($totalPrice, $firstPayment, $monthlyAmount, $campaign['contractLengthInMonths'], $campaign['numberOfPaymentFreeMonths']);
- }
+ public static function calculateTotalAmountToPay($totalPrice, $campaign , $decimals = 0)
+ {
+ $numberOfPayments = max( 1, $campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths']);
+ $paymentFactor = self::calculatePaymentFactor($numberOfPayments, $campaign['interestRatePercent']/ 100);
+ return Helper::bround($campaign['initialFee'] + ($totalPrice * $paymentFactor + $campaign['notificationFee']) * $numberOfPayments, $decimals);
+ }
+ public static function calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals = 0)
+ {
+ return Helper::bround(self::calculateTotalAmountToPay($totalPrice, $campaign, $decimals) / max(1, $campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths']), $decimals);
+ }
+ public static function calculateEffectiveInterestRate($totalPrice, $campaign, $decimals = 0)
+ {
+ $effectiveCalculator = new EffectiveInterestRateCalculator($totalPrice);
+ $firstPayment = $campaign['initialFee'] + $campaign['notificationFee'] + Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals);
+ $monthlyAmount = Helper::bround(self::calculateMonthlyAnnuityAmount($totalPrice, $campaign), $decimals) + $campaign['notificationFee'];
+ return $effectiveCalculator->calculate($totalPrice, $firstPayment, $monthlyAmount, $campaign['contractLengthInMonths'], $campaign['numberOfPaymentFreeMonths']);
+ }
- public static function calculatePaymentFactor($numberOfPayments, $yearlyInterestRate, $paymentFrequencyPerYear = 12)
- {
- $monthlyInterestRate = $yearlyInterestRate / $paymentFrequencyPerYear;
- return $monthlyInterestRate / (1-pow(1+$monthlyInterestRate, -$numberOfPayments));
- }
+ public static function calculatePaymentFactor($numberOfPayments, $yearlyInterestRate, $paymentFrequencyPerYear = 12)
+ {
+ $monthlyInterestRate = $yearlyInterestRate / $paymentFrequencyPerYear;
+ return $monthlyInterestRate / (1-pow(1+$monthlyInterestRate, -$numberOfPayments));
+ }
- public static function calculateMonthlyAnnuityAmount($totalPrice, $campaign)
- {
- $paymentFactor = self::calculatePaymentFactor($campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths'],
- $campaign['interestRatePercent']/ 100);
- return $totalPrice * $paymentFactor;
- }
+ public static function calculateMonthlyAnnuityAmount($totalPrice, $campaign)
+ {
+ $paymentFactor = self::calculatePaymentFactor($campaign['contractLengthInMonths'] - $campaign['numberOfPaymentFreeMonths'],
+ $campaign['interestRatePercent']/ 100);
+ return $totalPrice * $paymentFactor;
+ }
}
\ No newline at end of file
diff --git a/src/Helper/PaymentPlanHelper/PaymentPlanCalculator.php b/src/Helper/PaymentPlanHelper/PaymentPlanCalculator.php
index 03782e30..7858e381 100644
--- a/src/Helper/PaymentPlanHelper/PaymentPlanCalculator.php
+++ b/src/Helper/PaymentPlanHelper/PaymentPlanCalculator.php
@@ -10,362 +10,362 @@
class PaymentPlanCalculator
{
- /**
- * Calculates total amount that has to be payed for a single campaign
- *
- * @param int $totalPrice ; Price for the whole order
- * @param $campaign ; Either array of campaign or CampaignCode object
- * @param $decimals ; default = 0, returned values will round to this precision
- * @return int ; Returns total amount that should be paid for the provided campaign
- * @throws ValidationException
- */
- public static function getTotalAmountToPay($totalPrice, $campaign, $decimals = 0)
- {
- $campaign = (array)$campaign;
-
- // The Checkout API returns array keys with the first letter, we have to convert the first letter to lowercase
- if(array_key_exists('PaymentPlanType', $campaign) == true)
- {
- $campaign = self::convertFromCheckoutArray($campaign);
- }
-
- switch($campaign['paymentPlanType'])
- {
- case "InterestAndAmortizationFree":
- return InterestAndAmortizationFreePaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
- break;
- case "InterestFree":
- return InterestFreePaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
- break;
- case "Standard":
- return StandardPaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
- break;
-
- }
- throw new ValidationException("paymentPlanType not recognized");
- }
-
- /**
- * Calculates monthly amount that has to be payed for a single campaign
- *
- * @param int $totalPrice ; Price for the whole order
- * @param $campaign ; Either array of campaign or CampaignCode object
- * @param $decimals ; default = 0, returned values will round to this precision
- * @return int ; Returns monthly amount that should be paid for the provided campaign
- * @throws ValidationException
- */
- public static function getMonthlyAmountToPay($totalPrice, $campaign, $decimals = 0)
- {
- $campaign = (array)$campaign;
-
- // The Checkout API returns array keys with the first letter, we have to convert the first letter to lowercase
- if(array_key_exists('PaymentPlanType', $campaign) == true)
- {
- $campaign = self::convertFromCheckoutArray($campaign);
- }
-
- switch($campaign['paymentPlanType'])
- {
- case "InterestAndAmortizationFree":
- return InterestAndAmortizationFreePaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
- break;
- case "InterestFree":
- return InterestFreePaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
- break;
- case "Standard":
- return StandardPaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
- break;
- }
- throw new ValidationException("paymentPlanType not recognized");
- }
-
- /**
- * Calculates effective interest rate for a single campaign
- *
- * @param int $totalPrice ; Price for the whole order
- * @param $campaign ; Either array of campaign or CampaignCode object
- * @param $decimals ; default = 0, Must be set to 2 if provided campaign is to be paid in euros
- * @return int ; Returns effective interest rate for the provided campaign
- * @throws ValidationException
- */
- public static function getEffectiveInterestRate($totalPrice, $campaign, $decimals = 0)
- {
- $campaign = (array)$campaign;
-
- // The Checkout API returns array keys with the first letter, we have to convert the first letter to lowercase
- if(array_key_exists('PaymentPlanType', $campaign) == true)
- {
- $campaign = self::convertFromCheckoutArray($campaign);
- }
-
- switch($campaign['paymentPlanType'])
- {
- case "InterestAndAmortizationFree":
- return InterestAndAmortizationFreePaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
- break;
- case "InterestFree":
- return InterestFreePaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
- break;
- case "Standard":
- return StandardPaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
- break;
- }
- throw new ValidationException("paymentPlanType not recognized");
- }
-
- /**
- * Calculates effective interest rate, monthly amount to pay and total amount to pay for a single campaign
- *
- * @param int $totalPrice ; Price for the whole order
- * @param $campaign ; Either array of campaign or CampaignCode object
- * @param $decimals ; default = 0, returned values will round to this precision. Value must be 2 if payment plan is to be paid in euros
- * @return array ; Returns array of campaign with effective interest rate, monthly amount to pay and total amount to pay
- * @throws ValidationException
- */
- public static function getAllCalculations($totalPrice, $campaign , $decimals = 0)
- {
- $campaign = (array)$campaign;
-
- // The Checkout API returns array keys with the first letter, we have to convert the first letter to lowercase
- if(array_key_exists('PaymentPlanType', $campaign) == true)
- {
- $campaign = self::convertFromCheckoutArray($campaign);
- }
-
- switch($campaign['paymentPlanType'])
- {
- case "InterestAndAmortizationFree":
- $campaign['effectiveInterestRate'] = InterestAndAmortizationFreePaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
- $campaign['monthlyAmountToPay'] = InterestAndAmortizationFreePaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
- $campaign['totalAmountToPay'] = InterestAndAmortizationFreePaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
- break;
- case "InterestFree":
- $campaign['effectiveInterestRate'] = InterestFreePaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
- $campaign['monthlyAmountToPay'] = InterestFreePaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
- $campaign['totalAmountToPay'] = InterestFreePaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
- break;
- case "Standard":
- $campaign['effectiveInterestRate'] = StandardPaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
- $campaign['monthlyAmountToPay'] = StandardPaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
- $campaign['totalAmountToPay'] = StandardPaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
- break;
- default:
- throw new ValidationException("paymentPlanType not recognized");
- }
- if(array_key_exists('checkout', $campaign) == true)
- {
- $campaign = self::convertToCheckoutArray($campaign);
- }
- return $campaign;
- }
-
-
- /**
- * Calculates total amount to be paid every campaign provided
- *
- * @param int $totalPrice ; Price for the whole order
- * @param $campaigns ; Either array of campaign or CampaignCode object
- * @param $decimals ; default = 0, returned values will round to this precision
- * @param $ignoreMinMaxFlag ; default = false, if set to true then all campaigns will be returned regardless of if the order total is within the campaigns fromAmount and toAmount
- * @return array ; Returns array of campaigns with their params and total amount to be paid
- * @throws ValidationException
- */
- public static function getTotalAmountToPayFromCampaigns($totalPrice, $campaigns, $decimals = 0, $ignoreMinMaxFlag = false)
- {
- $result = array();
-
- foreach($campaigns as $key => $campaign)
- {
- $campaign = (array)$campaign;
- if(array_key_exists('PaymentPlanType', $campaign) == true)
- {
- $campaign = self::convertFromCheckoutArray($campaign);
- }
- if($ignoreMinMaxFlag || $campaign['fromAmount'] <= $totalPrice && $campaign['toAmount'] >= $totalPrice) {
-
-
- $campaign['totalAmountToPay'] = self::getTotalAmountToPay($totalPrice, $campaign, $decimals);
-
- if (array_key_exists('checkout', $campaign) == true) {
- $campaign = self::convertToCheckoutArray($campaign);
- }
- array_push($result, $campaign);
- }
- }
-
- return $result;
- }
-
- /**
- * Calculates monthly amount to be paid every campaign provided
- *
- * @param int $totalPrice ; Price for the whole order
- * @param $campaigns ; Either array of campaign or CampaignCode object
- * @param $decimals ; default = 0, returned values will round to this precision
- * @param $ignoreMinMaxFlag ; default = false, if set to true then all campaigns will be returned regardless of if the order total is within the campaigns fromAmount and toAmount
- * @return array ; Returns array of campaigns with their params and monthly amount to be paid
- * @throws ValidationException
- */
- public static function getMonthlyAmountToPayFromCampaigns($totalPrice, $campaigns, $decimals = 0, $ignoreMinMaxFlag = false)
- {
- $result = array();
-
- foreach($campaigns as $key => $campaign)
- {
- $campaign = (array)$campaign;
- if(array_key_exists('PaymentPlanType', $campaign) == true)
- {
- $campaign = self::convertFromCheckoutArray($campaign);
- }
- if($ignoreMinMaxFlag || $campaign['fromAmount'] <= $totalPrice && $campaign['toAmount'] >= $totalPrice) {
-
-
- $campaign['monthlyAmountToPay'] = self::getMonthlyAmountToPay($totalPrice, $campaign, $decimals);
-
- if (array_key_exists('checkout', $campaign) == true) {
- $campaign = self::convertToCheckoutArray($campaign);
- }
- array_push($result, $campaign);
- }
- }
- return $result;
- }
-
- /**
- * Calculates effective interest rate on every campaign provided
- *
- * @param int $totalPrice ; Price for the whole order
- * @param $campaigns ; Either array of campaign or CampaignCode object
- * @param $decimals ; default = 0, returned values will round to this precision
- * @param $ignoreMinMaxFlag ; default = false, if set to true then all campaigns will be returned regardless of if the order total is within the campaigns fromAmount and toAmount
- * @return array ; Returns array of campaigns with their params and their respective effective interest rate
- * @throws ValidationException
- */
- public static function getEffectiveInterestRateFromCampaigns($totalPrice, $campaigns, $decimals = 0, $ignoreMinMaxFlag = false)
- {
- $result = array();
-
- foreach($campaigns as $key => $campaign)
- {
- $campaign = (array)$campaign;
- if(array_key_exists('PaymentPlanType', $campaign) == true)
- {
- $campaign = self::convertFromCheckoutArray($campaign);
- }
- if($ignoreMinMaxFlag || $campaign['fromAmount'] <= $totalPrice && $campaign['toAmount'] >= $totalPrice) {
-
-
- $campaign['effectiveInterestRate'] = self::getEffectiveInterestRate($totalPrice, $campaign, $decimals);
-
- if (array_key_exists('checkout', $campaign) == true) {
- $campaign = self::convertToCheckoutArray($campaign);
- }
- array_push($result, $campaign);
- }
- }
- return $result;
- }
-
- /**
- * Calculates effective interest rate, monthly amount to pay and total amount to pay on every campaign provided
- *
- * @param int $totalPrice ; Price for the whole order
- * @param $campaigns ; Either array of campaign or CampaignCode object
- * @param $decimals ; default = 0, returned values will round to this precision. Value must be 2 if payment plan is to be paid in euros
- * @param $ignoreMinMaxFlag ; default = false, if set to true then all campaigns will be returned regardless of if the order total is within the campaigns fromAmount and toAmount
- * @return array ; Returns array of campaigns with their params and the result of the calculations
- * @throws ValidationException
- */
- public static function getAllCalculationsFromCampaigns($totalPrice, $campaigns, $decimals = 0, $ignoreMinMaxFlag = false)
- {
- $result = array();
-
- foreach($campaigns as $key => $campaign)
- {
- $campaign = (array)$campaign;
- if(array_key_exists('PaymentPlanType', $campaign) == true)
- {
- $campaign = self::convertFromCheckoutArray($campaign);
- }
- if($ignoreMinMaxFlag || $campaign['fromAmount'] <= $totalPrice && $campaign['toAmount'] >= $totalPrice) {
-
-
- $campaign['totalAmountToPay'] = self::getTotalAmountToPay($totalPrice, $campaign, $decimals);
- $campaign['monthlyAmountToPay'] = self::getMonthlyAmountToPay($totalPrice, $campaign, $decimals);
- $campaign['effectiveInterestRate'] = self::getEffectiveInterestRate($totalPrice, $campaign, $decimals);
-
- if (array_key_exists('checkout', $campaign) == true) {
- $campaign = self::convertToCheckoutArray($campaign);
- }
- array_push($result, $campaign);
- }
- }
- return $result;
- }
-
- /**
- * Converts an array of a campaign that's returned by GetAvailablePartPaymentCampaigns to the same format as a regular campaign
- * @param array ; Campaign returned from GetAvailablePartPaymentCampaigns
- * @return array ; converted campaign
- */
- private static function convertFromCheckoutArray($campaign)
- {
- $campaign = self::convertFirstArrayKeyToLowerCase($campaign);
- $campaign['checkout'] = true;
- switch($campaign['paymentPlanType'])
- {
- case 0:
- $campaign['paymentPlanType'] = "Standard";
- break;
- case 1:
- $campaign['paymentPlanType'] = "InterestFree";
- break;
- case 2:
- $campaign['paymentPlanType'] = "InterestAndAmortizationFree";
- break;
- }
- return $campaign;
- }
-
- /**
- * Converts an array back to the checkout campaign format
- * @param array
- * @return array
- */
- private static function convertToCheckoutArray($campaign)
- {
- $campaign = self::convertFirstArrayKeyToUpperCase($campaign);
- unset($campaign['Checkout']);
- switch($campaign['PaymentPlanType'])
- {
- case "Standard":
- $campaign['PaymentPlanType'] = 0;
- break;
- case "InterestFree":
- $campaign['PaymentPlanType'] = 1;
- break;
- case "InterestAndAmortizationFree":
- $campaign['PaymentPlanType'] = 2;
- break;
- }
- return $campaign;
- }
-
- private static function convertFirstArrayKeyToLowerCase($campaign)
- {
- $campaign = array_combine(
- array_map('lcfirst', array_keys($campaign)),
- array_values($campaign)
- );
- return $campaign;
- }
-
- private static function convertFirstArrayKeyToUpperCase($campaign)
- {
- $campaign = array_combine(
- array_map('ucfirst', array_keys($campaign)),
- array_values($campaign)
- );
- return $campaign;
- }
+ /**
+ * Calculates total amount that has to be payed for a single campaign
+ *
+ * @param int $totalPrice ; Price for the whole order
+ * @param $campaign ; Either array of campaign or CampaignCode object
+ * @param $decimals ; default = 0, returned values will round to this precision
+ * @return int ; Returns total amount that should be paid for the provided campaign
+ * @throws ValidationException
+ */
+ public static function getTotalAmountToPay($totalPrice, $campaign, $decimals = 0)
+ {
+ $campaign = (array)$campaign;
+
+ // The Checkout API returns array keys with the first letter, we have to convert the first letter to lowercase
+ if(array_key_exists('PaymentPlanType', $campaign) == true)
+ {
+ $campaign = self::convertFromCheckoutArray($campaign);
+ }
+
+ switch($campaign['paymentPlanType'])
+ {
+ case "InterestAndAmortizationFree":
+ return InterestAndAmortizationFreePaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
+ break;
+ case "InterestFree":
+ return InterestFreePaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
+ break;
+ case "Standard":
+ return StandardPaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
+ break;
+
+ }
+ throw new ValidationException("paymentPlanType not recognized");
+ }
+
+ /**
+ * Calculates monthly amount that has to be payed for a single campaign
+ *
+ * @param int $totalPrice ; Price for the whole order
+ * @param $campaign ; Either array of campaign or CampaignCode object
+ * @param $decimals ; default = 0, returned values will round to this precision
+ * @return int ; Returns monthly amount that should be paid for the provided campaign
+ * @throws ValidationException
+ */
+ public static function getMonthlyAmountToPay($totalPrice, $campaign, $decimals = 0)
+ {
+ $campaign = (array)$campaign;
+
+ // The Checkout API returns array keys with the first letter, we have to convert the first letter to lowercase
+ if(array_key_exists('PaymentPlanType', $campaign) == true)
+ {
+ $campaign = self::convertFromCheckoutArray($campaign);
+ }
+
+ switch($campaign['paymentPlanType'])
+ {
+ case "InterestAndAmortizationFree":
+ return InterestAndAmortizationFreePaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
+ break;
+ case "InterestFree":
+ return InterestFreePaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
+ break;
+ case "Standard":
+ return StandardPaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
+ break;
+ }
+ throw new ValidationException("paymentPlanType not recognized");
+ }
+
+ /**
+ * Calculates effective interest rate for a single campaign
+ *
+ * @param int $totalPrice ; Price for the whole order
+ * @param $campaign ; Either array of campaign or CampaignCode object
+ * @param $decimals ; default = 0, Must be set to 2 if provided campaign is to be paid in euros
+ * @return int ; Returns effective interest rate for the provided campaign
+ * @throws ValidationException
+ */
+ public static function getEffectiveInterestRate($totalPrice, $campaign, $decimals = 0)
+ {
+ $campaign = (array)$campaign;
+
+ // The Checkout API returns array keys with the first letter, we have to convert the first letter to lowercase
+ if(array_key_exists('PaymentPlanType', $campaign) == true)
+ {
+ $campaign = self::convertFromCheckoutArray($campaign);
+ }
+
+ switch($campaign['paymentPlanType'])
+ {
+ case "InterestAndAmortizationFree":
+ return InterestAndAmortizationFreePaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
+ break;
+ case "InterestFree":
+ return InterestFreePaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
+ break;
+ case "Standard":
+ return StandardPaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
+ break;
+ }
+ throw new ValidationException("paymentPlanType not recognized");
+ }
+
+ /**
+ * Calculates effective interest rate, monthly amount to pay and total amount to pay for a single campaign
+ *
+ * @param int $totalPrice ; Price for the whole order
+ * @param $campaign ; Either array of campaign or CampaignCode object
+ * @param $decimals ; default = 0, returned values will round to this precision. Value must be 2 if payment plan is to be paid in euros
+ * @return array ; Returns array of campaign with effective interest rate, monthly amount to pay and total amount to pay
+ * @throws ValidationException
+ */
+ public static function getAllCalculations($totalPrice, $campaign , $decimals = 0)
+ {
+ $campaign = (array)$campaign;
+
+ // The Checkout API returns array keys with the first letter, we have to convert the first letter to lowercase
+ if(array_key_exists('PaymentPlanType', $campaign) == true)
+ {
+ $campaign = self::convertFromCheckoutArray($campaign);
+ }
+
+ switch($campaign['paymentPlanType'])
+ {
+ case "InterestAndAmortizationFree":
+ $campaign['effectiveInterestRate'] = InterestAndAmortizationFreePaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
+ $campaign['monthlyAmountToPay'] = InterestAndAmortizationFreePaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
+ $campaign['totalAmountToPay'] = InterestAndAmortizationFreePaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
+ break;
+ case "InterestFree":
+ $campaign['effectiveInterestRate'] = InterestFreePaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
+ $campaign['monthlyAmountToPay'] = InterestFreePaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
+ $campaign['totalAmountToPay'] = InterestFreePaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
+ break;
+ case "Standard":
+ $campaign['effectiveInterestRate'] = StandardPaymentPlanCalculator::calculateEffectiveInterestRate($totalPrice, $campaign, $decimals);
+ $campaign['monthlyAmountToPay'] = StandardPaymentPlanCalculator::calculateMonthlyAmountToPay($totalPrice, $campaign, $decimals);
+ $campaign['totalAmountToPay'] = StandardPaymentPlanCalculator::calculateTotalAmountToPay($totalPrice, $campaign, $decimals);
+ break;
+ default:
+ throw new ValidationException("paymentPlanType not recognized");
+ }
+ if(array_key_exists('checkout', $campaign) == true)
+ {
+ $campaign = self::convertToCheckoutArray($campaign);
+ }
+ return $campaign;
+ }
+
+
+ /**
+ * Calculates total amount to be paid every campaign provided
+ *
+ * @param int $totalPrice ; Price for the whole order
+ * @param $campaigns ; Either array of campaign or CampaignCode object
+ * @param $decimals ; default = 0, returned values will round to this precision
+ * @param $ignoreMinMaxFlag ; default = false, if set to true then all campaigns will be returned regardless of if the order total is within the campaigns fromAmount and toAmount
+ * @return array ; Returns array of campaigns with their params and total amount to be paid
+ * @throws ValidationException
+ */
+ public static function getTotalAmountToPayFromCampaigns($totalPrice, $campaigns, $decimals = 0, $ignoreMinMaxFlag = false)
+ {
+ $result = [];
+
+ foreach($campaigns as $key => $campaign)
+ {
+ $campaign = (array)$campaign;
+ if(array_key_exists('PaymentPlanType', $campaign) == true)
+ {
+ $campaign = self::convertFromCheckoutArray($campaign);
+ }
+ if($ignoreMinMaxFlag || $campaign['fromAmount'] <= $totalPrice && $campaign['toAmount'] >= $totalPrice) {
+
+
+ $campaign['totalAmountToPay'] = self::getTotalAmountToPay($totalPrice, $campaign, $decimals);
+
+ if (array_key_exists('checkout', $campaign) == true) {
+ $campaign = self::convertToCheckoutArray($campaign);
+ }
+ array_push($result, $campaign);
+ }
+ }
+
+ return $result;
+ }
+
+ /**
+ * Calculates monthly amount to be paid every campaign provided
+ *
+ * @param int $totalPrice ; Price for the whole order
+ * @param $campaigns ; Either array of campaign or CampaignCode object
+ * @param $decimals ; default = 0, returned values will round to this precision
+ * @param $ignoreMinMaxFlag ; default = false, if set to true then all campaigns will be returned regardless of if the order total is within the campaigns fromAmount and toAmount
+ * @return array ; Returns array of campaigns with their params and monthly amount to be paid
+ * @throws ValidationException
+ */
+ public static function getMonthlyAmountToPayFromCampaigns($totalPrice, $campaigns, $decimals = 0, $ignoreMinMaxFlag = false)
+ {
+ $result = [];
+
+ foreach($campaigns as $key => $campaign)
+ {
+ $campaign = (array)$campaign;
+ if(array_key_exists('PaymentPlanType', $campaign) == true)
+ {
+ $campaign = self::convertFromCheckoutArray($campaign);
+ }
+ if($ignoreMinMaxFlag || $campaign['fromAmount'] <= $totalPrice && $campaign['toAmount'] >= $totalPrice) {
+
+
+ $campaign['monthlyAmountToPay'] = self::getMonthlyAmountToPay($totalPrice, $campaign, $decimals);
+
+ if (array_key_exists('checkout', $campaign) == true) {
+ $campaign = self::convertToCheckoutArray($campaign);
+ }
+ array_push($result, $campaign);
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Calculates effective interest rate on every campaign provided
+ *
+ * @param int $totalPrice ; Price for the whole order
+ * @param $campaigns ; Either array of campaign or CampaignCode object
+ * @param $decimals ; default = 0, returned values will round to this precision
+ * @param $ignoreMinMaxFlag ; default = false, if set to true then all campaigns will be returned regardless of if the order total is within the campaigns fromAmount and toAmount
+ * @return array ; Returns array of campaigns with their params and their respective effective interest rate
+ * @throws ValidationException
+ */
+ public static function getEffectiveInterestRateFromCampaigns($totalPrice, $campaigns, $decimals = 0, $ignoreMinMaxFlag = false)
+ {
+ $result = [];
+
+ foreach($campaigns as $key => $campaign)
+ {
+ $campaign = (array)$campaign;
+ if(array_key_exists('PaymentPlanType', $campaign) == true)
+ {
+ $campaign = self::convertFromCheckoutArray($campaign);
+ }
+ if($ignoreMinMaxFlag || $campaign['fromAmount'] <= $totalPrice && $campaign['toAmount'] >= $totalPrice) {
+
+
+ $campaign['effectiveInterestRate'] = self::getEffectiveInterestRate($totalPrice, $campaign, $decimals);
+
+ if (array_key_exists('checkout', $campaign) == true) {
+ $campaign = self::convertToCheckoutArray($campaign);
+ }
+ array_push($result, $campaign);
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Calculates effective interest rate, monthly amount to pay and total amount to pay on every campaign provided
+ *
+ * @param int $totalPrice ; Price for the whole order
+ * @param $campaigns ; Either array of campaign or CampaignCode object
+ * @param $decimals ; default = 0, returned values will round to this precision. Value must be 2 if payment plan is to be paid in euros
+ * @param $ignoreMinMaxFlag ; default = false, if set to true then all campaigns will be returned regardless of if the order total is within the campaigns fromAmount and toAmount
+ * @return array ; Returns array of campaigns with their params and the result of the calculations
+ * @throws ValidationException
+ */
+ public static function getAllCalculationsFromCampaigns($totalPrice, $campaigns, $decimals = 0, $ignoreMinMaxFlag = false)
+ {
+ $result = [];
+
+ foreach($campaigns as $key => $campaign)
+ {
+ $campaign = (array)$campaign;
+ if(array_key_exists('PaymentPlanType', $campaign) == true)
+ {
+ $campaign = self::convertFromCheckoutArray($campaign);
+ }
+ if($ignoreMinMaxFlag || $campaign['fromAmount'] <= $totalPrice && $campaign['toAmount'] >= $totalPrice) {
+
+
+ $campaign['totalAmountToPay'] = self::getTotalAmountToPay($totalPrice, $campaign, $decimals);
+ $campaign['monthlyAmountToPay'] = self::getMonthlyAmountToPay($totalPrice, $campaign, $decimals);
+ $campaign['effectiveInterestRate'] = self::getEffectiveInterestRate($totalPrice, $campaign, $decimals);
+
+ if (array_key_exists('checkout', $campaign) == true) {
+ $campaign = self::convertToCheckoutArray($campaign);
+ }
+ array_push($result, $campaign);
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Converts an array of a campaign that's returned by GetAvailablePartPaymentCampaigns to the same format as a regular campaign
+ * @param array ; Campaign returned from GetAvailablePartPaymentCampaigns
+ * @return array ; converted campaign
+ */
+ private static function convertFromCheckoutArray($campaign)
+ {
+ $campaign = self::convertFirstArrayKeyToLowerCase($campaign);
+ $campaign['checkout'] = true;
+ switch($campaign['paymentPlanType'])
+ {
+ case 0:
+ $campaign['paymentPlanType'] = "Standard";
+ break;
+ case 1:
+ $campaign['paymentPlanType'] = "InterestFree";
+ break;
+ case 2:
+ $campaign['paymentPlanType'] = "InterestAndAmortizationFree";
+ break;
+ }
+ return $campaign;
+ }
+
+ /**
+ * Converts an array back to the checkout campaign format
+ * @param array
+ * @return array
+ */
+ private static function convertToCheckoutArray($campaign)
+ {
+ $campaign = self::convertFirstArrayKeyToUpperCase($campaign);
+ unset($campaign['Checkout']);
+ switch($campaign['PaymentPlanType'])
+ {
+ case "Standard":
+ $campaign['PaymentPlanType'] = 0;
+ break;
+ case "InterestFree":
+ $campaign['PaymentPlanType'] = 1;
+ break;
+ case "InterestAndAmortizationFree":
+ $campaign['PaymentPlanType'] = 2;
+ break;
+ }
+ return $campaign;
+ }
+
+ private static function convertFirstArrayKeyToLowerCase($campaign)
+ {
+ $campaign = array_combine(
+ array_map('lcfirst', array_keys($campaign)),
+ array_values($campaign)
+ );
+ return $campaign;
+ }
+
+ private static function convertFirstArrayKeyToUpperCase($campaign)
+ {
+ $campaign = array_combine(
+ array_map('ucfirst', array_keys($campaign)),
+ array_values($campaign)
+ );
+ return $campaign;
+ }
}
\ No newline at end of file
diff --git a/src/HostedService/Helper/ExcludePayments.php b/src/HostedService/Helper/ExcludePayments.php
index f3775152..eefeaa55 100644
--- a/src/HostedService/Helper/ExcludePayments.php
+++ b/src/HostedService/Helper/ExcludePayments.php
@@ -9,35 +9,35 @@
*/
class ExcludePayments
{
- /**
- * Fetch an array of all paymentmethods representing a payment plan or invoice payment.
- * @ignore @param type $countryCode -- ignored
- * @return string[]
- */
- public static function excludeInvoicesAndPaymentPlan()
- {
- $methods = array();
+ /**
+ * Fetch an array of all paymentmethods representing a payment plan or invoice payment.
+ * @ignore @param type $countryCode -- ignored
+ * @return string[]
+ */
+ public static function excludeInvoicesAndPaymentPlan()
+ {
+ $methods = [];
- $methods[] = SystemPaymentMethod::INVOICESE;
- $methods[] = SystemPaymentMethod::PAYMENTPLANSE;
- $methods[] = SystemPaymentMethod::INVOICE_SE;
- $methods[] = SystemPaymentMethod::PAYMENTPLAN_SE;
+ $methods[] = SystemPaymentMethod::INVOICESE;
+ $methods[] = SystemPaymentMethod::PAYMENTPLANSE;
+ $methods[] = SystemPaymentMethod::INVOICE_SE;
+ $methods[] = SystemPaymentMethod::PAYMENTPLAN_SE;
- $methods[] = SystemPaymentMethod::INVOICE_DE;
- $methods[] = SystemPaymentMethod::PAYMENTPLAN_DE;
+ $methods[] = SystemPaymentMethod::INVOICE_DE;
+ $methods[] = SystemPaymentMethod::PAYMENTPLAN_DE;
- $methods[] = SystemPaymentMethod::INVOICE_DK;
- $methods[] = SystemPaymentMethod::PAYMENTPLAN_DK;
+ $methods[] = SystemPaymentMethod::INVOICE_DK;
+ $methods[] = SystemPaymentMethod::PAYMENTPLAN_DK;
- $methods[] = SystemPaymentMethod::INVOICE_FI;
- $methods[] = SystemPaymentMethod::PAYMENTPLAN_FI;
+ $methods[] = SystemPaymentMethod::INVOICE_FI;
+ $methods[] = SystemPaymentMethod::PAYMENTPLAN_FI;
- $methods[] = SystemPaymentMethod::INVOICE_NL;
- $methods[] = SystemPaymentMethod::PAYMENTPLAN_NL;
+ $methods[] = SystemPaymentMethod::INVOICE_NL;
+ $methods[] = SystemPaymentMethod::PAYMENTPLAN_NL;
- $methods[] = SystemPaymentMethod::INVOICE_NO;
- $methods[] = SystemPaymentMethod::PAYMENTPLAN_NO;
+ $methods[] = SystemPaymentMethod::INVOICE_NO;
+ $methods[] = SystemPaymentMethod::PAYMENTPLAN_NO;
- return $methods;
- }
+ return $methods;
+ }
}
diff --git a/src/HostedService/Helper/HostedRowFormatter.php b/src/HostedService/Helper/HostedRowFormatter.php
index bc2c15a9..d11b2902 100644
--- a/src/HostedService/Helper/HostedRowFormatter.php
+++ b/src/HostedService/Helper/HostedRowFormatter.php
@@ -7,359 +7,359 @@
class HostedRowFormatter
{
- private $totalAmount; // order item rows, rounded to 2 decimals, multiplied by 100 to integer
- private $totalVat; // order item rows, rounded to 2 decimals, multiplied by 100 to integer
- private $newRows; // type HostedOrderRowBuilder -- all order rows, as above
- private $rawAmount; // unrounded, multiplied by 100, avoids cumulative rounding error (when summing up over rows)
- private $rawVat; // unrounded, multiplied by 100, avoids cumulative rounding error (when summing up over rows)
-
- private $shippingAmount;
- private $shippingVat;
-
- private $invoiceAmount;
- private $invoiceVat;
-
- private $discountAmount;
- private $discountVat;
-
- /**
- * HostedRowFormatter constructor.
- */
- public function __construct()
- {
- $this->totalAmount = 0;
- $this->totalVat = 0;
- $this->newRows = array();
- }
-
- /**
- * Format rows and calculate vat.
- * Includes order InvoiceFee rows, as InvoiceFee may be used for i.e. generic handling fee etc.
- *
- * @param type $order
- * @return int
- */
- public function formatRows($order)
- {
- foreach ($order->rows as $row) {
- switch (get_class($row)) {
- case 'Svea\WebPay\BuildOrder\RowBuilders\OrderRow':
- $this->formatOrderRows($row);
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\ShippingFee':
- $this->formatShippingFeeRows($row);
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee':
- $this->formatInvoiceFeeRows($row); // invoice fee stands in for all kinds of handling fees
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount':
- $this->formatFixedDiscountRows($row);
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount':
- $this->formatRelativeDiscountRows($row);
- break;
- default:
- break;
- }
- }
-
- return $this->newRows;
- }
-
- /**
- * formatOrderRows goes through the orderBuilder object order-, shipping & discount rows
- * and translates them to a format suitable for use by the HostedXmlBuilder.
- *
- * This includes translating all prices to integer, multiplying by 100 to remove fractions.
- * Svea employs Bankers rounding, also known as "half-to-even rounding".
- *
- * We also calculate a total amount including taxes, and the total tax amount, for the order.
- * When calculating the amounts, all rounding takes place last, in order to avoid cumulative
- * rounding errors. (See HostedPaymentTest for an example.)
- * @param $row
- */
- private function formatOrderRows($row)
- {
- $tempRow = new HostedOrderRowBuilder(); // new empty object
-
- if (isset($row->name)) {
- $tempRow->setName($row->name);
- }
-
- if (isset($row->description)) {
- $tempRow->setDescription($row->description);
- }
-
- $rawAmount = 0.0;
- $rawVat = 0.0;
- // calculate amount, vat from two out of three given by customer, see unit tests HostedRowFormater
- if (isset($row->amountExVat) && isset($row->vatPercent)) {
- $rawAmount = floatval($row->amountExVat) * ($row->vatPercent / 100 + 1);
- $rawVat = floatval($row->amountExVat) * ($row->vatPercent / 100);
-
- $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
-
- } elseif (isset($row->amountIncVat) && isset($row->vatPercent)) {
- $rawAmount = $row->amountIncVat;
- $rawVat = $row->amountIncVat - ($row->amountIncVat / ($row->vatPercent / 100 + 1));
- $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
-
- } else {
- $rawAmount = $row->amountIncVat;
- $rawVat = ($row->amountIncVat - $row->amountExVat);
- $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
- }
-
- if (isset($row->unit)) {
- $tempRow->setUnit($row->unit);
- }
-
- if (isset($row->articleNumber)) {
- $tempRow->setSku($row->articleNumber);
- }
-
- if (isset($row->quantity)) {
- $tempRow->setQuantity($row->quantity);
- }
-
- $this->newRows[] = $tempRow;
- $this->totalAmount += ($tempRow->amount * $row->quantity);
- $this->totalVat += ($tempRow->vat * $row->quantity);
- $this->rawAmount += Helper::bround(($rawAmount * $row->quantity), 2) * 100;
- $this->rawVat += Helper::bround(($rawVat * $row->quantity), 2) * 100;
- }
-
- private function formatShippingFeeRows($row)
- {
- $tempRow = new HostedOrderRowBuilder();
-
- if (isset($row->articleNumber)) {
- $tempRow->setSku($row->articleNumber);
- }
-
- if (isset($row->name)) {
- $tempRow->setName($row->name);
- }
-
- if (isset($row->description)) {
- $tempRow->setDescription($row->description);
- }
-
- $rawAmount = 0.0;
- $rawVat = 0.0;
- // calculate amount, vat from two out of three given by customer, see unit tests in HostedRowFormater
- if (isset($row->amountExVat) && isset($row->vatPercent)) {
- $rawAmount = floatval($row->amountExVat) * ($row->vatPercent / 100 + 1);
- $rawVat = floatval($row->amountExVat) * ($row->vatPercent / 100);
- $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
-
- } elseif (isset($row->amountIncVat) && isset($row->vatPercent)) {
- $rawAmount = $row->amountIncVat;
- $rawVat = $row->amountIncVat - ($row->amountIncVat / ($row->vatPercent / 100 + 1));
- $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
-
- } else {
- $rawAmount = $row->amountIncVat;
- $rawVat = ($row->amountIncVat - $row->amountExVat);
- $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
- }
-
- if (isset($row->unit)) {
- $tempRow->setUnit($row->unit);
- }
-
- if (isset($row->shippingId)) {
- $tempRow->setSku($row->shippingId);
- }
-
- $tempRow->setQuantity(1);
- $this->newRows[] = $tempRow;
- $this->shippingAmount += ($tempRow->amount);
- $this->shippingVat += ($tempRow->vat);
-
- }
-
- public function formatInvoiceFeeRows($row)
- {
- $tempRow = new HostedOrderRowBuilder();
-
- if (isset($row->name)) {
- $tempRow->setName($row->name);
- }
-
- if (isset($row->description)) {
- $tempRow->setDescription($row->description);
- }
-
- $rawAmount = 0.0;
- $rawVat = 0.0;
- // calculate amount, vat from two out of three given by customer, see unit tests in HostedRowFormater
- if (isset($row->amountExVat) && isset($row->vatPercent)) {
- $rawAmount = floatval($row->amountExVat) * ($row->vatPercent / 100 + 1);
- $rawVat = floatval($row->amountExVat) * ($row->vatPercent / 100);
- $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
-
- } elseif (isset($row->amountIncVat) && isset($row->vatPercent)) {
- $rawAmount = $row->amountIncVat;
- $rawVat = $row->amountIncVat - ($row->amountIncVat / ($row->vatPercent / 100 + 1));
- $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
-
- } else {
- $rawAmount = $row->amountIncVat;
- $rawVat = ($row->amountIncVat - $row->amountExVat);
- $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
- }
-
- if (isset($row->unit)) {
- $tempRow->setUnit($row->unit);
- }
-
- $tempRow->setQuantity(1);
- $this->newRows[] = $tempRow;
- $this->invoiceAmount += ($tempRow->amount);
- $this->invoiceVat += ($tempRow->vat);
- }
-
- public function formatFixedDiscountRows($row)
- {
- $tempRow = new HostedOrderRowBuilder();
-
- if (isset($row->name)) {
- $tempRow->setName($row->name);
- }
-
- if (isset($row->description)) {
- $tempRow->setDescription($row->description);
- }
-
- // switch on which were used of setAmountIncVat ($this->amount), setAmountExVat (->amountExVat), setVatPercent (->vatPercent)
- $rawAmount = 0.0;
- $rawVat = 0.0;
- // use old method of calculating discounts from single discount amount inc. vat, i.e. the amount specified includes vat.
- if (isset($row->amount) && !isset($row->amountExVat) && !isset($row->vatPercent)) {
- $discountInPercent = ($row->amount * 100) / $this->rawAmount; // discount as fraction of raw total order sum (raw doesn't decrease if multiple discounts in the same order
-
- $rawAmount = $row->amount;
- $rawVat = $this->rawVat / 100 * $discountInPercent; // divide by 100 so that our "round and multiply" works in setVat below
- $tempRow->setAmount(-Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
- }
-
- // if specified amount ex vat, split the discount across vat rates according to relative amounts taken ex vat. as we apply the discount before tax,
- // the total discount sum must include the vat on the discounted amount.
- elseif (!isset($row->amount) && isset($row->amountExVat) && !isset($row->vatPercent)) {
- $discountInPercent = ($row->amountExVat * 100) / ($this->totalAmount - $this->totalVat);
- $rawAmount = $row->amountExVat;
- $rawVat = $this->rawVat / 100 * $discountInPercent; // divide by 100 so that our "round and multiply" works in setVat below
- $tempRow->setAmount(-Helper::bround($rawAmount + $rawVat, 2) * 100);
- $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
- } // calculate amount, vat from two out of three given by customer, see unit tests in HostedPaymentTest
- elseif (isset($row->amountExVat) && isset($row->vatPercent)) {
- $rawAmount = $row->amountExVat * ($row->vatPercent / 100 + 1);
- $rawVat = $row->amountExVat * ($row->vatPercent / 100);
- $tempRow->setAmount(-Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
-
- } elseif (isset($row->amount) && isset($row->vatPercent)) {
- $rawAmount = $row->amount;
- $rawVat = $row->amount - ($row->amount / ($row->vatPercent / 100 + 1));
- $tempRow->setAmount(-Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
-
- } else {
- $rawAmount = $row->amount;
- $rawVat = ($row->amount - $row->amountExVat);
- $tempRow->setAmount(-Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
- }
-
- if (isset($row->unit)) {
- $tempRow->setUnit($row->unit);
- }
-
- if (isset($row->discountId)) {
- $tempRow->setSku($row->discountId);
- }
-
- $tempRow->setQuantity(1);
-
-
- $this->totalAmount += $tempRow->amount;
- $this->totalVat += $tempRow->vat;
- $this->newRows[] = $tempRow;
-
- $this->discountAmount += $tempRow->amount;
- $this->discountVat += $tempRow->vat;
- }
-
- public function formatRelativeDiscountRows($row)
- {
- $tempRow = new HostedOrderRowBuilder();
-
- if (isset($row->name)) {
- $tempRow->setName($row->name);
- }
-
- if (isset($row->description)) {
- $tempRow->setDescription($row->description);
- }
-
- if (isset($row->discountId)) {
- $tempRow->setSku($row->discountId);
- }
-
- if (isset($row->unit)) {
- $tempRow->setUnit($row->unit);
- }
-
- $rawAmount = $this->rawAmount / 100 * $row->discountPercent / 100;
- $rawVat = $this->rawVat / 100 * $row->discountPercent / 100;
-
- $tempRow->setAmount(-Helper::bround($rawAmount, 2) * 100);
- $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
-
- $tempRow->setQuantity(1);
-
- $this->totalAmount += $tempRow->amount;
- $this->totalVat += $tempRow->vat;
- $this->newRows[] = $tempRow;
-
- $this->discountAmount += $tempRow->amount;
- $this->discountVat += $tempRow->vat;
- }
-
- /**
- * formatTotalAmount() is used by i.e. HostedPayment calculateRequestValues to
- * get the total vat sum of the order.
- *
- * @deprecated @param array $rows $rows is no longer used, instead we return
- * the object rawAmount value, modified by shippinga and discounts
- * @return integer total order amount, including vat
- */
- public function formatTotalAmount($rows)
- {
- return $this->rawAmount + $this->shippingAmount + $this->discountAmount + $this->invoiceAmount;
- }
-
- /**
- * formatTotalVat() is used by i.e. HostedPayment calculateRequestValues to
- * get the total vat sum of the order.
- *
- * @deprecated @param array $rows $rows is no longer used, instead we return
- * the object rawAmount value, modified by shippinga and discounts
- * @return integer total amount of vat due in order
- */
- public function formatTotalVat($rows)
- {
- return $this->rawVat + $this->shippingVat + $this->discountVat + $this->invoiceVat;
- }
+ private $totalAmount; // order item rows, rounded to 2 decimals, multiplied by 100 to integer
+ private $totalVat; // order item rows, rounded to 2 decimals, multiplied by 100 to integer
+ private $newRows; // type HostedOrderRowBuilder -- all order rows, as above
+ private $rawAmount; // unrounded, multiplied by 100, avoids cumulative rounding error (when summing up over rows)
+ private $rawVat; // unrounded, multiplied by 100, avoids cumulative rounding error (when summing up over rows)
+
+ private $shippingAmount;
+ private $shippingVat;
+
+ private $invoiceAmount;
+ private $invoiceVat;
+
+ private $discountAmount;
+ private $discountVat;
+
+ /**
+ * HostedRowFormatter constructor.
+ */
+ public function __construct()
+ {
+ $this->totalAmount = 0;
+ $this->totalVat = 0;
+ $this->newRows = [];
+ }
+
+ /**
+ * Format rows and calculate vat.
+ * Includes order InvoiceFee rows, as InvoiceFee may be used for i.e. generic handling fee etc.
+ *
+ * @param type $order
+ * @return int
+ */
+ public function formatRows($order)
+ {
+ foreach ($order->rows as $row) {
+ switch (get_class($row)) {
+ case 'Svea\WebPay\BuildOrder\RowBuilders\OrderRow':
+ $this->formatOrderRows($row);
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\ShippingFee':
+ $this->formatShippingFeeRows($row);
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee':
+ $this->formatInvoiceFeeRows($row); // invoice fee stands in for all kinds of handling fees
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount':
+ $this->formatFixedDiscountRows($row);
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount':
+ $this->formatRelativeDiscountRows($row);
+ break;
+ default:
+ break;
+ }
+ }
+
+ return $this->newRows;
+ }
+
+ /**
+ * formatOrderRows goes through the orderBuilder object order-, shipping & discount rows
+ * and translates them to a format suitable for use by the HostedXmlBuilder.
+ *
+ * This includes translating all prices to integer, multiplying by 100 to remove fractions.
+ * Svea employs Bankers rounding, also known as "half-to-even rounding".
+ *
+ * We also calculate a total amount including taxes, and the total tax amount, for the order.
+ * When calculating the amounts, all rounding takes place last, in order to avoid cumulative
+ * rounding errors. (See HostedPaymentTest for an example.)
+ * @param $row
+ */
+ private function formatOrderRows($row)
+ {
+ $tempRow = new HostedOrderRowBuilder(); // new empty object
+
+ if (isset($row->name)) {
+ $tempRow->setName($row->name);
+ }
+
+ if (isset($row->description)) {
+ $tempRow->setDescription($row->description);
+ }
+
+ $rawAmount = 0.0;
+ $rawVat = 0.0;
+ // calculate amount, vat from two out of three given by customer, see unit tests HostedRowFormater
+ if (isset($row->amountExVat) && isset($row->vatPercent)) {
+ $rawAmount = floatval($row->amountExVat) * ($row->vatPercent / 100 + 1);
+ $rawVat = floatval($row->amountExVat) * ($row->vatPercent / 100);
+
+ $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
+
+ } elseif (isset($row->amountIncVat) && isset($row->vatPercent)) {
+ $rawAmount = $row->amountIncVat;
+ $rawVat = $row->amountIncVat - ($row->amountIncVat / ($row->vatPercent / 100 + 1));
+ $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
+
+ } else {
+ $rawAmount = $row->amountIncVat;
+ $rawVat = ($row->amountIncVat - $row->amountExVat);
+ $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
+ }
+
+ if (isset($row->unit)) {
+ $tempRow->setUnit($row->unit);
+ }
+
+ if (isset($row->articleNumber)) {
+ $tempRow->setSku($row->articleNumber);
+ }
+
+ if (isset($row->quantity)) {
+ $tempRow->setQuantity($row->quantity);
+ }
+
+ $this->newRows[] = $tempRow;
+ $this->totalAmount += ($tempRow->amount * $row->quantity);
+ $this->totalVat += ($tempRow->vat * $row->quantity);
+ $this->rawAmount += Helper::bround(($rawAmount * $row->quantity), 2) * 100;
+ $this->rawVat += Helper::bround(($rawVat * $row->quantity), 2) * 100;
+ }
+
+ private function formatShippingFeeRows($row)
+ {
+ $tempRow = new HostedOrderRowBuilder();
+
+ if (isset($row->articleNumber)) {
+ $tempRow->setSku($row->articleNumber);
+ }
+
+ if (isset($row->name)) {
+ $tempRow->setName($row->name);
+ }
+
+ if (isset($row->description)) {
+ $tempRow->setDescription($row->description);
+ }
+
+ $rawAmount = 0.0;
+ $rawVat = 0.0;
+ // calculate amount, vat from two out of three given by customer, see unit tests in HostedRowFormater
+ if (isset($row->amountExVat) && isset($row->vatPercent)) {
+ $rawAmount = floatval($row->amountExVat) * ($row->vatPercent / 100 + 1);
+ $rawVat = floatval($row->amountExVat) * ($row->vatPercent / 100);
+ $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
+
+ } elseif (isset($row->amountIncVat) && isset($row->vatPercent)) {
+ $rawAmount = $row->amountIncVat;
+ $rawVat = $row->amountIncVat - ($row->amountIncVat / ($row->vatPercent / 100 + 1));
+ $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
+
+ } else {
+ $rawAmount = $row->amountIncVat;
+ $rawVat = ($row->amountIncVat - $row->amountExVat);
+ $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
+ }
+
+ if (isset($row->unit)) {
+ $tempRow->setUnit($row->unit);
+ }
+
+ if (isset($row->shippingId)) {
+ $tempRow->setSku($row->shippingId);
+ }
+
+ $tempRow->setQuantity(1);
+ $this->newRows[] = $tempRow;
+ $this->shippingAmount += ($tempRow->amount);
+ $this->shippingVat += ($tempRow->vat);
+
+ }
+
+ public function formatInvoiceFeeRows($row)
+ {
+ $tempRow = new HostedOrderRowBuilder();
+
+ if (isset($row->name)) {
+ $tempRow->setName($row->name);
+ }
+
+ if (isset($row->description)) {
+ $tempRow->setDescription($row->description);
+ }
+
+ $rawAmount = 0.0;
+ $rawVat = 0.0;
+ // calculate amount, vat from two out of three given by customer, see unit tests in HostedRowFormater
+ if (isset($row->amountExVat) && isset($row->vatPercent)) {
+ $rawAmount = floatval($row->amountExVat) * ($row->vatPercent / 100 + 1);
+ $rawVat = floatval($row->amountExVat) * ($row->vatPercent / 100);
+ $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
+
+ } elseif (isset($row->amountIncVat) && isset($row->vatPercent)) {
+ $rawAmount = $row->amountIncVat;
+ $rawVat = $row->amountIncVat - ($row->amountIncVat / ($row->vatPercent / 100 + 1));
+ $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
+
+ } else {
+ $rawAmount = $row->amountIncVat;
+ $rawVat = ($row->amountIncVat - $row->amountExVat);
+ $tempRow->setAmount(Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(Helper::bround($rawVat, 2) * 100);
+ }
+
+ if (isset($row->unit)) {
+ $tempRow->setUnit($row->unit);
+ }
+
+ $tempRow->setQuantity(1);
+ $this->newRows[] = $tempRow;
+ $this->invoiceAmount += ($tempRow->amount);
+ $this->invoiceVat += ($tempRow->vat);
+ }
+
+ public function formatFixedDiscountRows($row)
+ {
+ $tempRow = new HostedOrderRowBuilder();
+
+ if (isset($row->name)) {
+ $tempRow->setName($row->name);
+ }
+
+ if (isset($row->description)) {
+ $tempRow->setDescription($row->description);
+ }
+
+ // switch on which were used of setAmountIncVat ($this->amount), setAmountExVat (->amountExVat), setVatPercent (->vatPercent)
+ $rawAmount = 0.0;
+ $rawVat = 0.0;
+ // use old method of calculating discounts from single discount amount inc. vat, i.e. the amount specified includes vat.
+ if (isset($row->amount) && !isset($row->amountExVat) && !isset($row->vatPercent)) {
+ $discountInPercent = ($row->amount * 100) / $this->rawAmount; // discount as fraction of raw total order sum (raw doesn't decrease if multiple discounts in the same order
+
+ $rawAmount = $row->amount;
+ $rawVat = $this->rawVat / 100 * $discountInPercent; // divide by 100 so that our "round and multiply" works in setVat below
+ $tempRow->setAmount(-Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
+ }
+
+ // if specified amount ex vat, split the discount across vat rates according to relative amounts taken ex vat. as we apply the discount before tax,
+ // the total discount sum must include the vat on the discounted amount.
+ elseif (!isset($row->amount) && isset($row->amountExVat) && !isset($row->vatPercent)) {
+ $discountInPercent = ($row->amountExVat * 100) / ($this->totalAmount - $this->totalVat);
+ $rawAmount = $row->amountExVat;
+ $rawVat = $this->rawVat / 100 * $discountInPercent; // divide by 100 so that our "round and multiply" works in setVat below
+ $tempRow->setAmount(-Helper::bround($rawAmount + $rawVat, 2) * 100);
+ $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
+ } // calculate amount, vat from two out of three given by customer, see unit tests in HostedPaymentTest
+ elseif (isset($row->amountExVat) && isset($row->vatPercent)) {
+ $rawAmount = $row->amountExVat * ($row->vatPercent / 100 + 1);
+ $rawVat = $row->amountExVat * ($row->vatPercent / 100);
+ $tempRow->setAmount(-Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
+
+ } elseif (isset($row->amount) && isset($row->vatPercent)) {
+ $rawAmount = $row->amount;
+ $rawVat = $row->amount - ($row->amount / ($row->vatPercent / 100 + 1));
+ $tempRow->setAmount(-Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
+
+ } else {
+ $rawAmount = $row->amount;
+ $rawVat = ($row->amount - $row->amountExVat);
+ $tempRow->setAmount(-Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
+ }
+
+ if (isset($row->unit)) {
+ $tempRow->setUnit($row->unit);
+ }
+
+ if (isset($row->discountId)) {
+ $tempRow->setSku($row->discountId);
+ }
+
+ $tempRow->setQuantity(1);
+
+
+ $this->totalAmount += $tempRow->amount;
+ $this->totalVat += $tempRow->vat;
+ $this->newRows[] = $tempRow;
+
+ $this->discountAmount += $tempRow->amount;
+ $this->discountVat += $tempRow->vat;
+ }
+
+ public function formatRelativeDiscountRows($row)
+ {
+ $tempRow = new HostedOrderRowBuilder();
+
+ if (isset($row->name)) {
+ $tempRow->setName($row->name);
+ }
+
+ if (isset($row->description)) {
+ $tempRow->setDescription($row->description);
+ }
+
+ if (isset($row->discountId)) {
+ $tempRow->setSku($row->discountId);
+ }
+
+ if (isset($row->unit)) {
+ $tempRow->setUnit($row->unit);
+ }
+
+ $rawAmount = $this->rawAmount / 100 * $row->discountPercent / 100;
+ $rawVat = $this->rawVat / 100 * $row->discountPercent / 100;
+
+ $tempRow->setAmount(-Helper::bround($rawAmount, 2) * 100);
+ $tempRow->setVat(-Helper::bround($rawVat, 2) * 100);
+
+ $tempRow->setQuantity(1);
+
+ $this->totalAmount += $tempRow->amount;
+ $this->totalVat += $tempRow->vat;
+ $this->newRows[] = $tempRow;
+
+ $this->discountAmount += $tempRow->amount;
+ $this->discountVat += $tempRow->vat;
+ }
+
+ /**
+ * formatTotalAmount() is used by i.e. HostedPayment calculateRequestValues to
+ * get the total vat sum of the order.
+ *
+ * @deprecated @param array $rows $rows is no longer used, instead we return
+ * the object rawAmount value, modified by shippinga and discounts
+ * @return integer total order amount, including vat
+ */
+ public function formatTotalAmount($rows)
+ {
+ return $this->rawAmount + $this->shippingAmount + $this->discountAmount + $this->invoiceAmount;
+ }
+
+ /**
+ * formatTotalVat() is used by i.e. HostedPayment calculateRequestValues to
+ * get the total vat sum of the order.
+ *
+ * @deprecated @param array $rows $rows is no longer used, instead we return
+ * the object rawAmount value, modified by shippinga and discounts
+ * @return integer total amount of vat due in order
+ */
+ public function formatTotalVat($rows)
+ {
+ return $this->rawVat + $this->shippingVat + $this->discountVat + $this->invoiceVat;
+ }
}
diff --git a/src/HostedService/Helper/HostedXmlBuilder.php b/src/HostedService/Helper/HostedXmlBuilder.php
index ad2ad029..7495efb4 100644
--- a/src/HostedService/Helper/HostedXmlBuilder.php
+++ b/src/HostedService/Helper/HostedXmlBuilder.php
@@ -17,343 +17,343 @@
*/
class HostedXmlBuilder
{
- /**
- * @var XMLWriter $XMLWriter
- */
- private $XMLWriter;
-
- private $isCompany = "FALSE"; // set to true by serializeCustomer if needed.
-
- /**
- * Returns the webservice payment request message xml
- *
- * @deprecated 2.0.0 use @see getPaymentXML instead
- * @param type $request
- * @param CreateOrderBuilder $order
- * This method expect UTF-8 input
- * @return string
- */
- public function getOrderXML($request, $order)
- {
- return $this->getPaymentXML($request, $order);
- }
-
- /**
- * Returns the webservice payment request message xml
- * payment request structure as in "Technical Specification Svea\WebPay\WebPay v 2.6.8"
- *
- * @param HostedPayment $request
- * @param CreateOrderBuilder $order
- * @return string
- * This method expect UTF-8 input
- */
- public function getPaymentXML($request, $order)
- {
- $this->setBaseXML($order->conf);
- $this->XMLWriter->startElement("payment");
-
- //paymentmethod -- optional
- if (isset($request['paymentMethod'])) {
- $this->XMLWriter->writeElement("paymentmethod", $request['paymentMethod']); // paymentmethod -- if not set, goes to paypage
- }
- //lang -- optional
- $this->XMLWriter->writeElement("lang", $request['langCode']);
- // currency
- $this->XMLWriter->writeElement("currency", $request['currency']);
- // amount
- $this->XMLWriter->writeElement("amount", Helper::bround($request['amount']));
-
- // vat -- optional
- if ($request['totalVat'] != null) {
- $this->XMLWriter->writeElement("vat", Helper::bround($request['totalVat']));
- }
- // customerrefno -- optional
- $this->XMLWriter->writeElement("customerrefno", $request['clientOrderNumber']);
- // returnurl -- optional
- $this->XMLWriter->writeElement("returnurl", $request['returnUrl']);
- // cancelurl -- optional
- $this->XMLWriter->writeElement("cancelurl", $request['cancelUrl']);
- // callbackurl -- optional
- if ($request['callbackUrl'] != null) {
- $this->XMLWriter->writeElement("callbackurl", $request['callbackUrl']);
- }
- // subscriptiontype -- optional
- if (isset($request['subscriptionType'])) {
- $this->XMLWriter->writeElement("subscriptiontype", $request['subscriptionType']); // subscriptiontype
- }
-
- // simulatorcode
-
- // excludepaymentmethods -- in exclude element
- if (isset($request['excludePaymentMethods'])) {
- $this->serializeExcludePayments($request['excludePaymentMethods']); // excludepaymentmethods
- }
-
- // orderrows -- in row element
- $this->serializeOrderRows($request['rows']); // orderrows
-
- // customer -- optional
- if(isset($request['paymentMethod']))
- {
- $this->serializeCustomer($order, $request['paymentMethod']); // customer // -- used by Invoice payment
- }
- else
- {
- $this->serializeCustomer($order); // customer // -- used by Invoice payment
- }
-
- $this->XMLWriter->writeElement("iscompany", $this->isCompany); // -- used by invoice payment
- $this->XMLWriter->writeElement("addinvoicefee", "FALSE"); // -- used by invoice payment
- // iscompany -- optional
- // addinvoicefee -- optional
- // addressid -- optional // -- used by invoice payment
-
- // not in specification, but seems legit
- if (isset($request['ipAddress'])) {
- $this->XMLWriter->writeElement("ipaddress", $request['ipAddress']);
- }
-
- if(isset($request['payerAlias']))
- {
- $this->XMLWriter->writeElement("payeralias", $request['payerAlias']);
- }
-
- $this->XMLWriter->endElement();
- $this->XMLWriter->endDocument();
-
- return $this->XMLWriter->flush();
- }
-
- private function setBaseXML($config)
- {
- $this->XMLWriter = new XMLWriter();
- $this->XMLWriter->openMemory();
- $this->XMLWriter->setIndent(true);
- $this->XMLWriter->startDocument("1.0", "UTF-8");
- $this->XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($config));
- }
-
- private function serializeExcludePayments($payMethods)
- {
- if (count($payMethods) > 0) {
- $this->XMLWriter->startElement("excludepaymentmethods");
-
- foreach ($payMethods as $payMethod) {
- $this->XMLWriter->writeElement('exclude', $payMethod);
- }
-
- $this->XMLWriter->endElement();
- }
- }
-
- private function serializeOrderRows($orderRows)
- {
- if (count($orderRows) > 0) {
- $this->XMLWriter->startElement("orderrows");
-
- foreach ($orderRows as $orderRow) {
- $this->serializeOrderRow($orderRow);
- }
-
- $this->XMLWriter->endElement();
- }
- }
-
- private function serializeOrderRow($orderRow)
- {
- $this->XMLWriter->startElement("row");
-
- if (!empty($orderRow->sku) && $orderRow->sku != null) {
- $this->XMLWriter->writeElement("sku", $orderRow->sku);
- } else {
- $this->XMLWriter->writeElement("sku", "");
- }
-
- if (!empty($orderRow->name) && $orderRow->name != null) {
- $this->XMLWriter->writeElement("name", $orderRow->name);
- } else {
- $this->XMLWriter->writeElement("name", "");
- }
-
- if (!empty($orderRow->description) && $orderRow->description != null) {
- $this->XMLWriter->writeElement("description", $orderRow->description);
- } else {
- $this->XMLWriter->writeElement("description", "");
- }
-
- if (!empty($orderRow->amount) && $orderRow->amount != null) {
- $this->XMLWriter->writeElement("amount", Helper::bround($orderRow->amount));
- } else {
- $this->XMLWriter->writeElement("amount", "0");
- }
-
- if (!empty($orderRow->vat) && $orderRow->vat != null) {
- $this->XMLWriter->writeElement("vat", Helper::bround($orderRow->vat));
- } else {
- $this->XMLWriter->writeElement("vat", "0");
- }
-
- if (!empty($orderRow->quantity) && $orderRow->quantity != null) {
- $this->XMLWriter->writeElement("quantity", $orderRow->quantity);
- }
-
- if (!empty($orderRow->unit) && $orderRow->unit != null) {
- $this->XMLWriter->writeElement("unit", $orderRow->unit);
- }
-
- $this->XMLWriter->endElement();
- }
-
- private function serializeCustomer($order, $paymentMethod = NULL)
- {
- $this->XMLWriter->startElement("customer");
-
- if(isset($paymentMethod) && $paymentMethod == "SVEACARDPAY_PF")
- {
- $this->XMLWriter->writeElement("unknowncustomer", "true");
- $this->XMLWriter->writeElement("country", $order->countryCode);
- }
- else {
- //nordic country individual
- if (isset($order->customerIdentity->ssn)) {
- $this->XMLWriter->writeElement("ssn", $order->customerIdentity->ssn);
- } elseif (isset($order->customerIdentity->birthDate)) {
- $this->XMLWriter->writeElement("ssn", $order->customerIdentity->birthDate);
- }
-
- //customer identity for NL and DE when choosing invoice or paymentplan
-
- if (isset($order->customerIdentity->firstname)) {
- $this->XMLWriter->writeElement("firstname", $order->customerIdentity->firstname);
- }
-
- if (isset($order->customerIdentity->lastname)) {
- $this->XMLWriter->writeElement("lastname", $order->customerIdentity->lastname);
- }
-
- if (isset($order->customerIdentity->initials)) {
- $this->XMLWriter->writeElement("initials", $order->customerIdentity->initials);
- }
-
- if (isset($order->customerIdentity->street)) {
- $this->XMLWriter->writeElement("address", $order->customerIdentity->street);
- }
-
- if (isset($order->customerIdentity->coAddress)) {
- $this->XMLWriter->writeElement("address2", $order->customerIdentity->coAddress);
- }
-
- if (isset($order->customerIdentity->housenumber)) {
- $this->XMLWriter->writeElement("housenumber", $order->customerIdentity->housenumber);
- }
-
- if (isset($order->customerIdentity->zipCode)) {
- $this->XMLWriter->writeElement("zip", $order->customerIdentity->zipCode);
- }
-
- if (isset($order->customerIdentity->locality)) {
- $this->XMLWriter->writeElement("city", $order->customerIdentity->locality);
- }
-
- if (isset($order->countryCode)) {
- $this->XMLWriter->writeElement("country", $order->countryCode);
- }
-
- if (isset($order->customerIdentity->phonenumber)) {
- $this->XMLWriter->writeElement("phone", $order->customerIdentity->phonenumber);
- }
-
- if (isset($order->customerIdentity->email)) {
- $this->XMLWriter->writeElement("email", $order->customerIdentity->email);
- }
-
- if (isset($order->customerIdentity->orgNumber) || isset($order->customerIdentity->companyVatNumber)) {
- if (isset($order->customerIdentity->orgNumber)) {
- $this->XMLWriter->writeElement("ssn", $order->customerIdentity->orgNumber);
- } else {
- $this->XMLWriter->writeElement("vatnumber", $order->customerIdentity->companyVatNumber); // -- used by Invoice payment
- }
-
- // companyname // -- used by Invoice payment
- // companyid // -- used by Invoice payment
-
- $this->isCompany = "TRUE";
- }
-
- $this->XMLWriter->endElement();
-
- if (isset($order->customerIdentity->addressSelector)) {
- $this->XMLWriter->writeElement("addressid", $order->customerIdentity->addressSelector); // -- used by Invoice payment
- }
- }
- }
-
- /**
- * Returns the webservice preparepayment request message xml
- * uses the same code as getPaymentXML above, with the addition of the lang and ipaddress fields
- *
- * @param type $request
- * @param CreateOrderBuilder $order
- * @return type
- * This method expect UTF-8 input
- */
- public function getPreparePaymentXML($request, $order)
- {
- $this->setBaseXML($order->conf);
- $this->XMLWriter->startElement("payment");
-
- if (isset($request['paymentMethod'])) {
- $this->XMLWriter->writeElement("paymentmethod", $request['paymentMethod']); // paymentmethod -- if not set, goes to paypage
- }
- $this->XMLWriter->writeElement("lang", $request['langCode']); // required in preparepayment
- $this->XMLWriter->writeElement("currency", $request['currency']);
- $this->XMLWriter->writeElement("amount", Helper::bround($request['amount']));
-
- if ($request['totalVat'] != null) {
- $this->XMLWriter->writeElement("vat", Helper::bround($request['totalVat']));
- }
- $this->XMLWriter->writeElement("customerrefno", $request['clientOrderNumber']);
- $this->XMLWriter->writeElement("returnurl", $request['returnUrl']);
- $this->XMLWriter->writeElement("cancelurl", $request['cancelUrl']);
- if ($request['callbackUrl'] != null) {
- $this->XMLWriter->writeElement("callbackurl", $request['callbackUrl']);
- }
- // subscriptiontype -- optional
- if (isset($request['subscriptionType'])) {
- $this->XMLWriter->writeElement("subscriptiontype", $request['subscriptionType']); // subscriptiontype
- }
- // simulatorcode
- if (isset($request['excludePaymentMethods'])) {
- $this->serializeExcludePayments($request['excludePaymentMethods']); // excludepaymentmethods
- }
- $this->serializeOrderRows($request['rows']); // orderrows
-
- $this->XMLWriter->writeElement("ipaddress", $request['ipAddress']); // required in preparepayment
-
- $this->serializeCustomer($order); // customer // -- used by Invoice payment
- $this->XMLWriter->writeElement("iscompany", $this->isCompany); // -- used by invoice payment
- $this->XMLWriter->writeElement("addinvoicefee", "FALSE"); // -- used by invoice payment
- // addressid // -- used by invoice payment
-
- $this->XMLWriter->endElement();
- $this->XMLWriter->endDocument();
-
- return $this->XMLWriter->flush();
- }
-
- /**
- * write xml for webservice getpaymentmethods
- * @param $merchantId
- * @return mixed
- */
- public function getPaymentMethodsXML($merchantId)
- {
- $this->setBaseXML();
- $this->XMLWriter->startElement("getpaymentmethods");
- $this->XMLWriter->writeElement("merchantid", $merchantId);
- $this->XMLWriter->endElement();
- $this->XMLWriter->endDocument();
-
- return $this->XMLWriter->flush();
- }
+ /**
+ * @var XMLWriter $XMLWriter
+ */
+ private $XMLWriter;
+
+ private $isCompany = "FALSE"; // set to true by serializeCustomer if needed.
+
+ /**
+ * Returns the webservice payment request message xml
+ *
+ * @deprecated 2.0.0 use @see getPaymentXML instead
+ * @param type $request
+ * @param CreateOrderBuilder $order
+ * This method expect UTF-8 input
+ * @return string
+ */
+ public function getOrderXML($request, $order)
+ {
+ return $this->getPaymentXML($request, $order);
+ }
+
+ /**
+ * Returns the webservice payment request message xml
+ * payment request structure as in "Technical Specification Svea\WebPay\WebPay v 2.6.8"
+ *
+ * @param HostedPayment $request
+ * @param CreateOrderBuilder $order
+ * @return string
+ * This method expect UTF-8 input
+ */
+ public function getPaymentXML($request, $order)
+ {
+ $this->setBaseXML($order->conf);
+ $this->XMLWriter->startElement("payment");
+
+ //paymentmethod -- optional
+ if (isset($request['paymentMethod'])) {
+ $this->XMLWriter->writeElement("paymentmethod", $request['paymentMethod']); // paymentmethod -- if not set, goes to paypage
+ }
+ //lang -- optional
+ $this->XMLWriter->writeElement("lang", $request['langCode']);
+ // currency
+ $this->XMLWriter->writeElement("currency", $request['currency']);
+ // amount
+ $this->XMLWriter->writeElement("amount", Helper::bround($request['amount']));
+
+ // vat -- optional
+ if ($request['totalVat'] != null) {
+ $this->XMLWriter->writeElement("vat", Helper::bround($request['totalVat']));
+ }
+ // customerrefno -- optional
+ $this->XMLWriter->writeElement("customerrefno", $request['clientOrderNumber']);
+ // returnurl -- optional
+ $this->XMLWriter->writeElement("returnurl", $request['returnUrl']);
+ // cancelurl -- optional
+ $this->XMLWriter->writeElement("cancelurl", $request['cancelUrl']);
+ // callbackurl -- optional
+ if ($request['callbackUrl'] != null) {
+ $this->XMLWriter->writeElement("callbackurl", $request['callbackUrl']);
+ }
+ // subscriptiontype -- optional
+ if (isset($request['subscriptionType'])) {
+ $this->XMLWriter->writeElement("subscriptiontype", $request['subscriptionType']); // subscriptiontype
+ }
+
+ // simulatorcode
+
+ // excludepaymentmethods -- in exclude element
+ if (isset($request['excludePaymentMethods'])) {
+ $this->serializeExcludePayments($request['excludePaymentMethods']); // excludepaymentmethods
+ }
+
+ // orderrows -- in row element
+ $this->serializeOrderRows($request['rows']); // orderrows
+
+ // customer -- optional
+ if(isset($request['paymentMethod']))
+ {
+ $this->serializeCustomer($order, $request['paymentMethod']); // customer // -- used by Invoice payment
+ }
+ else
+ {
+ $this->serializeCustomer($order); // customer // -- used by Invoice payment
+ }
+
+ $this->XMLWriter->writeElement("iscompany", $this->isCompany); // -- used by invoice payment
+ $this->XMLWriter->writeElement("addinvoicefee", "FALSE"); // -- used by invoice payment
+ // iscompany -- optional
+ // addinvoicefee -- optional
+ // addressid -- optional // -- used by invoice payment
+
+ // not in specification, but seems legit
+ if (isset($request['ipAddress'])) {
+ $this->XMLWriter->writeElement("ipaddress", $request['ipAddress']);
+ }
+
+ if(isset($request['payerAlias']))
+ {
+ $this->XMLWriter->writeElement("payeralias", $request['payerAlias']);
+ }
+
+ $this->XMLWriter->endElement();
+ $this->XMLWriter->endDocument();
+
+ return $this->XMLWriter->flush();
+ }
+
+ private function setBaseXML($config)
+ {
+ $this->XMLWriter = new XMLWriter();
+ $this->XMLWriter->openMemory();
+ $this->XMLWriter->setIndent(true);
+ $this->XMLWriter->startDocument("1.0", "UTF-8");
+ $this->XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($config));
+ }
+
+ private function serializeExcludePayments($payMethods)
+ {
+ if (count($payMethods) > 0) {
+ $this->XMLWriter->startElement("excludepaymentmethods");
+
+ foreach ($payMethods as $payMethod) {
+ $this->XMLWriter->writeElement('exclude', $payMethod);
+ }
+
+ $this->XMLWriter->endElement();
+ }
+ }
+
+ private function serializeOrderRows($orderRows)
+ {
+ if (count($orderRows) > 0) {
+ $this->XMLWriter->startElement("orderrows");
+
+ foreach ($orderRows as $orderRow) {
+ $this->serializeOrderRow($orderRow);
+ }
+
+ $this->XMLWriter->endElement();
+ }
+ }
+
+ private function serializeOrderRow($orderRow)
+ {
+ $this->XMLWriter->startElement("row");
+
+ if (!empty($orderRow->sku) && $orderRow->sku != null) {
+ $this->XMLWriter->writeElement("sku", $orderRow->sku);
+ } else {
+ $this->XMLWriter->writeElement("sku", "");
+ }
+
+ if (!empty($orderRow->name) && $orderRow->name != null) {
+ $this->XMLWriter->writeElement("name", $orderRow->name);
+ } else {
+ $this->XMLWriter->writeElement("name", "");
+ }
+
+ if (!empty($orderRow->description) && $orderRow->description != null) {
+ $this->XMLWriter->writeElement("description", $orderRow->description);
+ } else {
+ $this->XMLWriter->writeElement("description", "");
+ }
+
+ if (!empty($orderRow->amount) && $orderRow->amount != null) {
+ $this->XMLWriter->writeElement("amount", Helper::bround($orderRow->amount));
+ } else {
+ $this->XMLWriter->writeElement("amount", "0");
+ }
+
+ if (!empty($orderRow->vat) && $orderRow->vat != null) {
+ $this->XMLWriter->writeElement("vat", Helper::bround($orderRow->vat));
+ } else {
+ $this->XMLWriter->writeElement("vat", "0");
+ }
+
+ if (!empty($orderRow->quantity) && $orderRow->quantity != null) {
+ $this->XMLWriter->writeElement("quantity", $orderRow->quantity);
+ }
+
+ if (!empty($orderRow->unit) && $orderRow->unit != null) {
+ $this->XMLWriter->writeElement("unit", $orderRow->unit);
+ }
+
+ $this->XMLWriter->endElement();
+ }
+
+ private function serializeCustomer($order, $paymentMethod = NULL)
+ {
+ $this->XMLWriter->startElement("customer");
+
+ if(isset($paymentMethod) && $paymentMethod == "SVEACARDPAY_PF")
+ {
+ $this->XMLWriter->writeElement("unknowncustomer", "true");
+ $this->XMLWriter->writeElement("country", $order->countryCode);
+ }
+ else {
+ //nordic country individual
+ if (isset($order->customerIdentity->ssn)) {
+ $this->XMLWriter->writeElement("ssn", $order->customerIdentity->ssn);
+ } elseif (isset($order->customerIdentity->birthDate)) {
+ $this->XMLWriter->writeElement("ssn", $order->customerIdentity->birthDate);
+ }
+
+ //customer identity for NL and DE when choosing invoice or paymentplan
+
+ if (isset($order->customerIdentity->firstname)) {
+ $this->XMLWriter->writeElement("firstname", $order->customerIdentity->firstname);
+ }
+
+ if (isset($order->customerIdentity->lastname)) {
+ $this->XMLWriter->writeElement("lastname", $order->customerIdentity->lastname);
+ }
+
+ if (isset($order->customerIdentity->initials)) {
+ $this->XMLWriter->writeElement("initials", $order->customerIdentity->initials);
+ }
+
+ if (isset($order->customerIdentity->street)) {
+ $this->XMLWriter->writeElement("address", $order->customerIdentity->street);
+ }
+
+ if (isset($order->customerIdentity->coAddress)) {
+ $this->XMLWriter->writeElement("address2", $order->customerIdentity->coAddress);
+ }
+
+ if (isset($order->customerIdentity->housenumber)) {
+ $this->XMLWriter->writeElement("housenumber", $order->customerIdentity->housenumber);
+ }
+
+ if (isset($order->customerIdentity->zipCode)) {
+ $this->XMLWriter->writeElement("zip", $order->customerIdentity->zipCode);
+ }
+
+ if (isset($order->customerIdentity->locality)) {
+ $this->XMLWriter->writeElement("city", $order->customerIdentity->locality);
+ }
+
+ if (isset($order->countryCode)) {
+ $this->XMLWriter->writeElement("country", $order->countryCode);
+ }
+
+ if (isset($order->customerIdentity->phonenumber)) {
+ $this->XMLWriter->writeElement("phone", $order->customerIdentity->phonenumber);
+ }
+
+ if (isset($order->customerIdentity->email)) {
+ $this->XMLWriter->writeElement("email", $order->customerIdentity->email);
+ }
+
+ if (isset($order->customerIdentity->orgNumber) || isset($order->customerIdentity->companyVatNumber)) {
+ if (isset($order->customerIdentity->orgNumber)) {
+ $this->XMLWriter->writeElement("ssn", $order->customerIdentity->orgNumber);
+ } else {
+ $this->XMLWriter->writeElement("vatnumber", $order->customerIdentity->companyVatNumber); // -- used by Invoice payment
+ }
+
+ // companyname // -- used by Invoice payment
+ // companyid // -- used by Invoice payment
+
+ $this->isCompany = "TRUE";
+ }
+
+ $this->XMLWriter->endElement();
+
+ if (isset($order->customerIdentity->addressSelector)) {
+ $this->XMLWriter->writeElement("addressid", $order->customerIdentity->addressSelector); // -- used by Invoice payment
+ }
+ }
+ }
+
+ /**
+ * Returns the webservice preparepayment request message xml
+ * uses the same code as getPaymentXML above, with the addition of the lang and ipaddress fields
+ *
+ * @param type $request
+ * @param CreateOrderBuilder $order
+ * @return type
+ * This method expect UTF-8 input
+ */
+ public function getPreparePaymentXML($request, $order)
+ {
+ $this->setBaseXML($order->conf);
+ $this->XMLWriter->startElement("payment");
+
+ if (isset($request['paymentMethod'])) {
+ $this->XMLWriter->writeElement("paymentmethod", $request['paymentMethod']); // paymentmethod -- if not set, goes to paypage
+ }
+ $this->XMLWriter->writeElement("lang", $request['langCode']); // required in preparepayment
+ $this->XMLWriter->writeElement("currency", $request['currency']);
+ $this->XMLWriter->writeElement("amount", Helper::bround($request['amount']));
+
+ if ($request['totalVat'] != null) {
+ $this->XMLWriter->writeElement("vat", Helper::bround($request['totalVat']));
+ }
+ $this->XMLWriter->writeElement("customerrefno", $request['clientOrderNumber']);
+ $this->XMLWriter->writeElement("returnurl", $request['returnUrl']);
+ $this->XMLWriter->writeElement("cancelurl", $request['cancelUrl']);
+ if ($request['callbackUrl'] != null) {
+ $this->XMLWriter->writeElement("callbackurl", $request['callbackUrl']);
+ }
+ // subscriptiontype -- optional
+ if (isset($request['subscriptionType'])) {
+ $this->XMLWriter->writeElement("subscriptiontype", $request['subscriptionType']); // subscriptiontype
+ }
+ // simulatorcode
+ if (isset($request['excludePaymentMethods'])) {
+ $this->serializeExcludePayments($request['excludePaymentMethods']); // excludepaymentmethods
+ }
+ $this->serializeOrderRows($request['rows']); // orderrows
+
+ $this->XMLWriter->writeElement("ipaddress", $request['ipAddress']); // required in preparepayment
+
+ $this->serializeCustomer($order); // customer // -- used by Invoice payment
+ $this->XMLWriter->writeElement("iscompany", $this->isCompany); // -- used by invoice payment
+ $this->XMLWriter->writeElement("addinvoicefee", "FALSE"); // -- used by invoice payment
+ // addressid // -- used by invoice payment
+
+ $this->XMLWriter->endElement();
+ $this->XMLWriter->endDocument();
+
+ return $this->XMLWriter->flush();
+ }
+
+ /**
+ * write xml for webservice getpaymentmethods
+ * @param $merchantId
+ * @return mixed
+ */
+ public function getPaymentMethodsXML($merchantId)
+ {
+ $this->setBaseXML();
+ $this->XMLWriter->startElement("getpaymentmethods");
+ $this->XMLWriter->writeElement("merchantid", $merchantId);
+ $this->XMLWriter->endElement();
+ $this->XMLWriter->endDocument();
+
+ return $this->XMLWriter->flush();
+ }
}
diff --git a/src/HostedService/Helper/InvalidCountryException.php b/src/HostedService/Helper/InvalidCountryException.php
index 7ff24d23..de228be0 100644
--- a/src/HostedService/Helper/InvalidCountryException.php
+++ b/src/HostedService/Helper/InvalidCountryException.php
@@ -6,5 +6,5 @@
class InvalidCountryException extends Exception
{
- // \Exception referes to class Exception outside our \Svea\ namespace
+ // \Exception referes to class Exception outside our \Svea\ namespace
}
diff --git a/src/HostedService/Helper/InvalidTypeException.php b/src/HostedService/Helper/InvalidTypeException.php
index 7227b126..9ea5b73c 100644
--- a/src/HostedService/Helper/InvalidTypeException.php
+++ b/src/HostedService/Helper/InvalidTypeException.php
@@ -4,6 +4,6 @@
class InvalidTypeException extends \Exception
{
- // \Exception referes to class Exception outside our \Svea\ namespace
+ // \Exception referes to class Exception outside our \Svea\ namespace
}
diff --git a/src/HostedService/Helper/PaymentForm.php b/src/HostedService/Helper/PaymentForm.php
index 11af5745..8b0b3d20 100644
--- a/src/HostedService/Helper/PaymentForm.php
+++ b/src/HostedService/Helper/PaymentForm.php
@@ -16,91 +16,91 @@
*/
class PaymentForm
{
- public $endPointUrl;
- public $xmlMessage;
- public $xmlMessageBase64;
- public $merchantid;
- public $secretWord;
- public $mac;
- public $completeHtmlFormWithSubmitButton;
- public $htmlFormFieldsAsArray = array();
- private $submitMessage;
- private $noScriptMessage;
+ public $endPointUrl;
+ public $xmlMessage;
+ public $xmlMessageBase64;
+ public $merchantid;
+ public $secretWord;
+ public $mac;
+ public $completeHtmlFormWithSubmitButton;
+ public $htmlFormFieldsAsArray = [];
+ private $submitMessage;
+ private $noScriptMessage;
- /**
- * populates the payment form object from the given parameters and generates
- * the $completeHtmlFormWithSubmitButton & $htmlFormFieldsAsArray attributes
- *
- * @param type $xmlMessage
- * @param ConfigurationProvider $config
- * @param string $countryCode
- */
- function __construct($xmlMessage, $config, $countryCode = NULL)
- {
- $this->xmlMessage = $xmlMessage;
- $this->xmlMessageBase64 = base64_encode($xmlMessage);
- $this->endPointUrl = $config->getEndPoint(ConfigurationProvider::HOSTED_TYPE);
- $this->merchantid = $config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $this->secretWord = $config->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $this->mac = hash("sha512", $this->xmlMessageBase64 . $this->secretWord);
+ /**
+ * populates the payment form object from the given parameters and generates
+ * the $completeHtmlFormWithSubmitButton & $htmlFormFieldsAsArray attributes
+ *
+ * @param type $xmlMessage
+ * @param ConfigurationProvider $config
+ * @param string $countryCode
+ */
+ function __construct($xmlMessage, $config, $countryCode = NULL)
+ {
+ $this->xmlMessage = $xmlMessage;
+ $this->xmlMessageBase64 = base64_encode($xmlMessage);
+ $this->endPointUrl = $config->getEndPoint(ConfigurationProvider::HOSTED_TYPE);
+ $this->merchantid = $config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ $this->secretWord = $config->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ $this->mac = hash("sha512", $this->xmlMessageBase64 . $this->secretWord);
- $this->setForm();
- $this->setHtmlFields();
- $this->setRawFields();
+ $this->setForm();
+ $this->setHtmlFields();
+ $this->setRawFields();
- $this->setSubmitMessage();
- }
+ $this->setSubmitMessage();
+ }
- /**
- * Set complete html-form as string
- */
- public function setForm()
- {
- $formString = "";
+ /**
+ * Set complete html-form as string
+ */
+ public function setForm()
+ {
+ $formString = "";
- $this->completeHtmlFormWithSubmitButton = $formString;
- }
+ $this->completeHtmlFormWithSubmitButton = $formString;
+ }
- /**
- * Set form elements as Array
- */
- public function setHtmlFields()
- {
- $this->htmlFormFieldsAsArray['form_start_tag'] = "";
- }
+ /**
+ * Set form elements as Array
+ */
+ public function setHtmlFields()
+ {
+ $this->htmlFormFieldsAsArray['form_start_tag'] = "";
+ }
- public function setRawFields()
- {
- $this->rawFields['merchantid'] = $this->merchantid;
- $this->rawFields['message'] = $this->xmlMessageBase64;
- $this->rawFields['mac'] = $this->mac;
- $this->rawFields['htmlFormMethod'] = 'post';
- $this->rawFields['htmlFormAction'] = $this->endPointUrl;
- }
+ public function setRawFields()
+ {
+ $this->rawFields['merchantid'] = $this->merchantid;
+ $this->rawFields['message'] = $this->xmlMessageBase64;
+ $this->rawFields['mac'] = $this->mac;
+ $this->rawFields['htmlFormMethod'] = 'post';
+ $this->rawFields['htmlFormAction'] = $this->endPointUrl;
+ }
- public function setSubmitMessage($countryCode = FALSE)
- {
- switch ($countryCode) {
- case "SE":
- $this->submitMessage = "Betala";
- $this->noScriptMessage = "Javascript är inaktiverat i er webbläsare, så ni får manuellt omdirigera till paypage";
- break;
- default:
- $this->submitMessage = "Submit";
- $this->noScriptMessage = "Javascript is inactivated in your browser, you will manually have to redirect to the paypage";
- break;
- }
- }
+ public function setSubmitMessage($countryCode = FALSE)
+ {
+ switch ($countryCode) {
+ case "SE":
+ $this->submitMessage = "Betala";
+ $this->noScriptMessage = "Javascript är inaktiverat i er webbläsare, så ni får manuellt omdirigera till paypage";
+ break;
+ default:
+ $this->submitMessage = "Submit";
+ $this->noScriptMessage = "Javascript is inactivated in your browser, you will manually have to redirect to the paypage";
+ break;
+ }
+ }
}
diff --git a/src/HostedService/HostedAdminRequest/AnnulTransaction.php b/src/HostedService/HostedAdminRequest/AnnulTransaction.php
index 8954a8d0..f42070af 100644
--- a/src/HostedService/HostedAdminRequest/AnnulTransaction.php
+++ b/src/HostedService/HostedAdminRequest/AnnulTransaction.php
@@ -16,61 +16,61 @@
*/
class AnnulTransaction extends HostedRequest
{
- /**
- * @var string $transactionid
- */
- public $transactionId;
+ /**
+ * @var string $transactionid
+ */
+ public $transactionId;
- /**
- * Usage: create an instance, set all required attributes, then call doRequest().
- * Required: $transactionId
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- */
- function __construct($config)
- {
- $this->method = "annul";
- parent::__construct($config);
- }
+ /**
+ * Usage: create an instance, set all required attributes, then call doRequest().
+ * Required: $transactionId
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ */
+ function __construct($config)
+ {
+ $this->method = "annul";
+ parent::__construct($config);
+ }
- protected function validateRequestAttributes()
- {
- $errors = array();
- $errors = $this->validateTransactionId($this, $errors);
+ protected function validateRequestAttributes()
+ {
+ $errors = [];
+ $errors = $this->validateTransactionId($this, $errors);
- return $errors;
- }
+ return $errors;
+ }
- private function validateTransactionId($self, $errors)
- {
- if (isset($self->transactionId) == FALSE) {
- $errors['missing value'] = "transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.";
- }
+ private function validateTransactionId($self, $errors)
+ {
+ if (isset($self->transactionId) == FALSE) {
+ $errors['missing value'] = "transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.";
+ }
- return $errors;
- }
+ return $errors;
+ }
- /** returns xml for hosted webservice "annul" request */
- protected function createRequestXml()
- {
- $XMLWriter = new \XMLWriter();
+ /** returns xml for hosted webservice "annul" request */
+ protected function createRequestXml()
+ {
+ $XMLWriter = new \XMLWriter();
- $XMLWriter->openMemory();
- $XMLWriter->setIndent(true);
- $XMLWriter->startDocument("1.0", "UTF-8");
- $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
- $XMLWriter->startElement($this->method);
- $XMLWriter->writeElement("transactionid", $this->transactionId);
- $XMLWriter->endElement();
- $XMLWriter->endDocument();
+ $XMLWriter->openMemory();
+ $XMLWriter->setIndent(true);
+ $XMLWriter->startDocument("1.0", "UTF-8");
+ $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
+ $XMLWriter->startElement($this->method);
+ $XMLWriter->writeElement("transactionid", $this->transactionId);
+ $XMLWriter->endElement();
+ $XMLWriter->endDocument();
- return $XMLWriter->flush();
- }
+ return $XMLWriter->flush();
+ }
- protected function parseResponse($message)
- {
- $countryCode = $this->countryCode;
- $config = $this->config;
+ protected function parseResponse($message)
+ {
+ $countryCode = $this->countryCode;
+ $config = $this->config;
- return new AnnulTransactionResponse($message, $countryCode, $config);
- }
+ return new AnnulTransactionResponse($message, $countryCode, $config);
+ }
}
diff --git a/src/HostedService/HostedAdminRequest/CancelRecurSubscription.php b/src/HostedService/HostedAdminRequest/CancelRecurSubscription.php
index 21985b42..005580b4 100644
--- a/src/HostedService/HostedAdminRequest/CancelRecurSubscription.php
+++ b/src/HostedService/HostedAdminRequest/CancelRecurSubscription.php
@@ -14,65 +14,65 @@
*/
class CancelRecurSubscription extends HostedRequest
{
- /*
- * @var string $conf ConfigurationProvider $conf
- */
- public $conf;
+ /*
+ * @var string $conf ConfigurationProvider $conf
+ */
+ public $conf;
- /**
- * @var string $subscriptionId Required. This is the subscription id returned with the initial transaction that set up the subscription response.
- */
- public $subscriptionId;
+ /**
+ * @var string $subscriptionId Required. This is the subscription id returned with the initial transaction that set up the subscription response.
+ */
+ public $subscriptionId;
- /**
- * Usage: create an instance, set all required attributes, then call doRequest().
- * Required: $subscriptionId
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- */
- function __construct($config)
- {
- $this->method = "cancelrecursubscription";
- parent::__construct($config);
- }
+ /**
+ * Usage: create an instance, set all required attributes, then call doRequest().
+ * Required: $subscriptionId
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ */
+ function __construct($config)
+ {
+ $this->method = "cancelrecursubscription";
+ parent::__construct($config);
+ }
- protected function validateRequestAttributes()
- {
- $errors = array();
- $errors = $this->validateSubscriptionId($this, $errors);
+ protected function validateRequestAttributes()
+ {
+ $errors = [];
+ $errors = $this->validateSubscriptionId($this, $errors);
- return $errors;
- }
+ return $errors;
+ }
- private function validateSubscriptionId($self, $errors)
- {
- if (isset($self->subscriptionId) == FALSE) {
- $errors['missing value'] = "subscriptionId is required. Use function setSubscriptionId() with the subscriptionId from the createOrder response.";
- }
+ private function validateSubscriptionId($self, $errors)
+ {
+ if (isset($self->subscriptionId) == FALSE) {
+ $errors['missing value'] = "subscriptionId is required. Use function setSubscriptionId() with the subscriptionId from the createOrder response.";
+ }
- return $errors;
- }
+ return $errors;
+ }
- protected function createRequestXml()
- {
- $XMLWriter = new \XMLWriter();
+ protected function createRequestXml()
+ {
+ $XMLWriter = new \XMLWriter();
- $XMLWriter->openMemory();
- $XMLWriter->setIndent(true);
- $XMLWriter->startDocument("1.0", "UTF-8");
- $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
- $XMLWriter->startElement($this->method);
- $XMLWriter->writeElement("subscriptionid", $this->subscriptionId);
- $XMLWriter->endElement();
- $XMLWriter->endDocument();
+ $XMLWriter->openMemory();
+ $XMLWriter->setIndent(true);
+ $XMLWriter->startDocument("1.0", "UTF-8");
+ $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
+ $XMLWriter->startElement($this->method);
+ $XMLWriter->writeElement("subscriptionid", $this->subscriptionId);
+ $XMLWriter->endElement();
+ $XMLWriter->endDocument();
- return $XMLWriter->flush();
- }
+ return $XMLWriter->flush();
+ }
- protected function parseResponse($message)
- {
- $countryCode = $this->countryCode;
- $config = $this->config;
+ protected function parseResponse($message)
+ {
+ $countryCode = $this->countryCode;
+ $config = $this->config;
- return new CancelRecurSubscriptionResponse($message, $countryCode, $config);
- }
+ return new CancelRecurSubscriptionResponse($message, $countryCode, $config);
+ }
}
\ No newline at end of file
diff --git a/src/HostedService/HostedAdminRequest/ConfirmTransaction.php b/src/HostedService/HostedAdminRequest/ConfirmTransaction.php
index 970c9032..3e055264 100644
--- a/src/HostedService/HostedAdminRequest/ConfirmTransaction.php
+++ b/src/HostedService/HostedAdminRequest/ConfirmTransaction.php
@@ -19,78 +19,78 @@
class ConfirmTransaction extends HostedRequest
{
- /**
- * @var string $transactionId Required.
- */
- public $transactionId;
-
- /**
- * @var string $captureDate Required. Use ISO-8601 extended date format (YYYY-MM-DD)
- */
- public $captureDate;
-
- /**
- * Usage: create an instance, set all required attributes, then call doRequest().
- * Required: $transactionId, $captureDate
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- */
- function __construct($config)
- {
- $this->method = "confirm";
- parent::__construct($config);
- }
-
- protected function validateRequestAttributes()
- {
- $errors = array();
- $errors = $this->validateTransactionId($this, $errors);
- $errors = $this->validateCaptureDate($this, $errors);
-
- return $errors;
- }
-
- private function validateTransactionId($self, $errors)
- {
- if (isset($self->transactionId) == FALSE) {
- $errors['missing value'] = "transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.";
- }
-
- return $errors;
- }
-
- // this is optional coming through the api, as the orderbuilder deliverCardOrder sets a default capturedate
- private function validateCaptureDate($self, $errors)
- {
- if (isset($self->captureDate) == FALSE) {
- $errors['missing value'] = "captureDate is required. Use function setCaptureDate().";
- }
-
- return $errors;
- }
-
- /** returns xml for hosted webservice "confirm" request */
- protected function createRequestXml()
- {
- $XMLWriter = new \XMLWriter();
-
- $XMLWriter->openMemory();
- $XMLWriter->setIndent(true);
- $XMLWriter->startDocument("1.0", "UTF-8");
- $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
- $XMLWriter->startElement($this->method);
- $XMLWriter->writeElement("transactionid", $this->transactionId);
- $XMLWriter->writeElement("capturedate", $this->captureDate);
- $XMLWriter->endElement();
- $XMLWriter->endDocument();
-
- return $XMLWriter->flush();
- }
-
- protected function parseResponse($message)
- {
- $countryCode = $this->countryCode;
- $config = $this->config;
-
- return new ConfirmTransactionResponse($message, $countryCode, $config);
- }
+ /**
+ * @var string $transactionId Required.
+ */
+ public $transactionId;
+
+ /**
+ * @var string $captureDate Required. Use ISO-8601 extended date format (YYYY-MM-DD)
+ */
+ public $captureDate;
+
+ /**
+ * Usage: create an instance, set all required attributes, then call doRequest().
+ * Required: $transactionId, $captureDate
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ */
+ function __construct($config)
+ {
+ $this->method = "confirm";
+ parent::__construct($config);
+ }
+
+ protected function validateRequestAttributes()
+ {
+ $errors = [];
+ $errors = $this->validateTransactionId($this, $errors);
+ $errors = $this->validateCaptureDate($this, $errors);
+
+ return $errors;
+ }
+
+ private function validateTransactionId($self, $errors)
+ {
+ if (isset($self->transactionId) == FALSE) {
+ $errors['missing value'] = "transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.";
+ }
+
+ return $errors;
+ }
+
+ // this is optional coming through the api, as the orderbuilder deliverCardOrder sets a default capturedate
+ private function validateCaptureDate($self, $errors)
+ {
+ if (isset($self->captureDate) == FALSE) {
+ $errors['missing value'] = "captureDate is required. Use function setCaptureDate().";
+ }
+
+ return $errors;
+ }
+
+ /** returns xml for hosted webservice "confirm" request */
+ protected function createRequestXml()
+ {
+ $XMLWriter = new \XMLWriter();
+
+ $XMLWriter->openMemory();
+ $XMLWriter->setIndent(true);
+ $XMLWriter->startDocument("1.0", "UTF-8");
+ $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
+ $XMLWriter->startElement($this->method);
+ $XMLWriter->writeElement("transactionid", $this->transactionId);
+ $XMLWriter->writeElement("capturedate", $this->captureDate);
+ $XMLWriter->endElement();
+ $XMLWriter->endDocument();
+
+ return $XMLWriter->flush();
+ }
+
+ protected function parseResponse($message)
+ {
+ $countryCode = $this->countryCode;
+ $config = $this->config;
+
+ return new ConfirmTransactionResponse($message, $countryCode, $config);
+ }
}
\ No newline at end of file
diff --git a/src/HostedService/HostedAdminRequest/CreditTransaction.php b/src/HostedService/HostedAdminRequest/CreditTransaction.php
index 502dbda8..40ea030d 100644
--- a/src/HostedService/HostedAdminRequest/CreditTransaction.php
+++ b/src/HostedService/HostedAdminRequest/CreditTransaction.php
@@ -16,76 +16,76 @@
class CreditTransaction extends HostedRequest
{
- /**
- * @var string $transactionId Required.
- */
- public $transactionId;
-
- /**
- * @var string $creditAmount Required. Use minor currency (i.e. 1 SEK => 100 in minor currency)
- */
- public $creditAmount;
-
- /**
- * Usage: create an instance, set all required attributes, then call doRequest().
- * Required: $transactionId, $creditAmount
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- */
- function __construct($config)
- {
- $this->method = "credit";
- parent::__construct($config);
- }
-
- protected function validateRequestAttributes()
- {
- $errors = array();
- $errors = $this->validateTransactionId($this, $errors);
- $errors = $this->validateCreditAmount($this, $errors);
-
- return $errors;
- }
-
- private function validateTransactionId($self, $errors)
- {
- if (isset($self->transactionId) == FALSE) {
- $errors['missing value'] = "transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.";
- }
-
- return $errors;
- }
-
- private function validateCreditAmount($self, $errors)
- {
- if (isset($self->creditAmount) == FALSE) {
- $errors['missing value'] = "creditAmount is required. Use function setCreditAmount().";
- }
-
- return $errors;
- }
-
- protected function createRequestXml()
- {
- $XMLWriter = new \XMLWriter();
-
- $XMLWriter->openMemory();
- $XMLWriter->setIndent(true);
- $XMLWriter->startDocument("1.0", "UTF-8");
- $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
- $XMLWriter->startElement($this->method);
- $XMLWriter->writeElement("transactionid", $this->transactionId);
- $XMLWriter->writeElement("amounttocredit", $this->creditAmount);
- $XMLWriter->endElement();
- $XMLWriter->endDocument();
-
- return $XMLWriter->flush();
- }
-
- protected function parseResponse($message)
- {
- $countryCode = $this->countryCode;
- $config = $this->config;
-
- return new CreditTransactionResponse($message, $countryCode, $config);
- }
+ /**
+ * @var string $transactionId Required.
+ */
+ public $transactionId;
+
+ /**
+ * @var string $creditAmount Required. Use minor currency (i.e. 1 SEK => 100 in minor currency)
+ */
+ public $creditAmount;
+
+ /**
+ * Usage: create an instance, set all required attributes, then call doRequest().
+ * Required: $transactionId, $creditAmount
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ */
+ function __construct($config)
+ {
+ $this->method = "credit";
+ parent::__construct($config);
+ }
+
+ protected function validateRequestAttributes()
+ {
+ $errors = [];
+ $errors = $this->validateTransactionId($this, $errors);
+ $errors = $this->validateCreditAmount($this, $errors);
+
+ return $errors;
+ }
+
+ private function validateTransactionId($self, $errors)
+ {
+ if (isset($self->transactionId) == FALSE) {
+ $errors['missing value'] = "transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.";
+ }
+
+ return $errors;
+ }
+
+ private function validateCreditAmount($self, $errors)
+ {
+ if (isset($self->creditAmount) == FALSE) {
+ $errors['missing value'] = "creditAmount is required. Use function setCreditAmount().";
+ }
+
+ return $errors;
+ }
+
+ protected function createRequestXml()
+ {
+ $XMLWriter = new \XMLWriter();
+
+ $XMLWriter->openMemory();
+ $XMLWriter->setIndent(true);
+ $XMLWriter->startDocument("1.0", "UTF-8");
+ $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
+ $XMLWriter->startElement($this->method);
+ $XMLWriter->writeElement("transactionid", $this->transactionId);
+ $XMLWriter->writeElement("amounttocredit", $this->creditAmount);
+ $XMLWriter->endElement();
+ $XMLWriter->endDocument();
+
+ return $XMLWriter->flush();
+ }
+
+ protected function parseResponse($message)
+ {
+ $countryCode = $this->countryCode;
+ $config = $this->config;
+
+ return new CreditTransactionResponse($message, $countryCode, $config);
+ }
}
\ No newline at end of file
diff --git a/src/HostedService/HostedAdminRequest/GetPaymentMethods.php b/src/HostedService/HostedAdminRequest/GetPaymentMethods.php
index 4e622152..fd377501 100644
--- a/src/HostedService/HostedAdminRequest/GetPaymentMethods.php
+++ b/src/HostedService/HostedAdminRequest/GetPaymentMethods.php
@@ -10,35 +10,35 @@
*/
class GetPaymentMethods
{
- private $method = "getpaymentmethods";
- private $config;
- private $countryCode = "SE"; //Default SE
+ private $method = "getpaymentmethods";
+ private $config;
+ private $countryCode = "SE"; //Default SE
- /**
- * @deprecated 2.0 Use class ListPaymentMethods instead.
- */
- function __construct($config)
- {
- $this->config = $config;
- }
+ /**
+ * @deprecated 2.0 Use class ListPaymentMethods instead.
+ */
+ function __construct($config)
+ {
+ $this->config = $config;
+ }
- public function setContryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
+ public function setContryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
- return $this;
- }
+ return $this;
+ }
- /**
- * Wrapper for ListPaymentMethods->doRequest
- * @deprecated 2.0 Use class ListPaymentMethods instead.
- */
- public function doRequest()
- {
- $request = new ListPaymentMethods($this->config);
- $request->countryCode = $this->countryCode;
- $response = $request->doRequest();
+ /**
+ * Wrapper for ListPaymentMethods->doRequest
+ * @deprecated 2.0 Use class ListPaymentMethods instead.
+ */
+ public function doRequest()
+ {
+ $request = new ListPaymentMethods($this->config);
+ $request->countryCode = $this->countryCode;
+ $response = $request->doRequest();
- return $response->paymentmethods;
- }
+ return $response->paymentmethods;
+ }
}
\ No newline at end of file
diff --git a/src/HostedService/HostedAdminRequest/ListPaymentMethods.php b/src/HostedService/HostedAdminRequest/ListPaymentMethods.php
index a7739310..949cc1e2 100644
--- a/src/HostedService/HostedAdminRequest/ListPaymentMethods.php
+++ b/src/HostedService/HostedAdminRequest/ListPaymentMethods.php
@@ -12,65 +12,65 @@
*/
class ListPaymentMethods extends HostedRequest
{
- /**
- * Use the Svea\WebPay\WebPay::listPaymentMethods() entrypoint to get an instance of ListPaymentMethods.
- * Then provide more information about the transaction and send the request using ListPaymentMethod methods.
- *
- * $methods = Svea\WebPay\WebPay::listPaymentMethods( $config )
- * ->setCountryCode("SE") // required
- * ->doRequest()
- * ;
- *
- * Following the ->doRequest call you receive an instance of ListPaymentMethodsResponse.
- *
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- */
- function __construct($config)
- {
- $this->method = "getpaymentmethods";
- parent::__construct($config);
- }
+ /**
+ * Use the Svea\WebPay\WebPay::listPaymentMethods() entrypoint to get an instance of ListPaymentMethods.
+ * Then provide more information about the transaction and send the request using ListPaymentMethod methods.
+ *
+ * $methods = Svea\WebPay\WebPay::listPaymentMethods( $config )
+ * ->setCountryCode("SE") // required
+ * ->doRequest()
+ * ;
+ *
+ * Following the ->doRequest call you receive an instance of ListPaymentMethodsResponse.
+ *
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ */
+ function __construct($config)
+ {
+ $this->method = "getpaymentmethods";
+ parent::__construct($config);
+ }
- /**
- * setCountryCode needed here, as we don't come here via an OrderBuilder
- * @param $countryCode
- * @return $this
- */
- function setCountryCode($countryCode)
- {
- $this->countryCode = $countryCode;
+ /**
+ * setCountryCode needed here, as we don't come here via an OrderBuilder
+ * @param $countryCode
+ * @return $this
+ */
+ function setCountryCode($countryCode)
+ {
+ $this->countryCode = $countryCode;
- return $this;
- }
+ return $this;
+ }
- protected function validateRequestAttributes()
- {
- $errors = array();
+ protected function validateRequestAttributes()
+ {
+ $errors = [];
- return $errors;
- }
+ return $errors;
+ }
- protected function createRequestXml()
- {
- $XMLWriter = new \XMLWriter();
+ protected function createRequestXml()
+ {
+ $XMLWriter = new \XMLWriter();
- $XMLWriter->openMemory();
- $XMLWriter->setIndent(true);
- $XMLWriter->startDocument("1.0", "UTF-8");
- $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
- $XMLWriter->startElement($this->method);
- $XMLWriter->writeElement("merchantid", $this->config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $this->countryCode));
- $XMLWriter->endElement();
- $XMLWriter->endDocument();
+ $XMLWriter->openMemory();
+ $XMLWriter->setIndent(true);
+ $XMLWriter->startDocument("1.0", "UTF-8");
+ $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
+ $XMLWriter->startElement($this->method);
+ $XMLWriter->writeElement("merchantid", $this->config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $this->countryCode));
+ $XMLWriter->endElement();
+ $XMLWriter->endDocument();
- return $XMLWriter->flush();
- }
+ return $XMLWriter->flush();
+ }
- protected function parseResponse($message)
- {
- $countryCode = $this->countryCode;
- $config = $this->config;
+ protected function parseResponse($message)
+ {
+ $countryCode = $this->countryCode;
+ $config = $this->config;
- return new ListPaymentMethodsResponse($message, $countryCode, $config);
- }
+ return new ListPaymentMethodsResponse($message, $countryCode, $config);
+ }
}
diff --git a/src/HostedService/HostedAdminRequest/LowerTransaction.php b/src/HostedService/HostedAdminRequest/LowerTransaction.php
index 1ca507e6..0f10c378 100644
--- a/src/HostedService/HostedAdminRequest/LowerTransaction.php
+++ b/src/HostedService/HostedAdminRequest/LowerTransaction.php
@@ -19,146 +19,146 @@
*/
class LowerTransaction extends HostedRequest
{
- /**
- * @var string $transactionId Required.
- */
- public $transactionId;
-
- /**
- * @var string $amountToLower Required. Use minor currency (i.e. 1 SEK => 100 in minor currency)
- */
- public $amountToLower;
-
- /**
- * @var boolean $alsoDoConfirm Optional. Iff true, doRequest() will perform a ConfirmTransaction request following a successful doRequest
- */
- public $alsoDoConfirm;
-
- /**
- * Usage: create an instance, set all required attributes, then call doRequest().
- * Required: $transactionId, $amountToLower
- * Option: $alsoDoRequest
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- */
- function __construct($config)
- {
- $this->method = "loweramount";
- parent::__construct($config);
- }
-
- /**
- * Performs a request using cURL, parsing the response using Svea\WebPay\Response\SveaResponse
- * and returning the resulting HostedAdminResponse instance.
- *
- * Iff $alsoDoConfirm is true, LowerTransaction doRequest() will also
- * perform a ConfirmTransaction request following a successful doRequest
- * @return \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\HostedAdminResponse
- * @override
- */
- public function doRequest()
- {
- $fields = $this->prepareRequest();
-
- $fieldsString = "";
- foreach ($fields as $key => $value) {
- $fieldsString .= $key . '=' . $value . '&';
- }
- rtrim($fieldsString, '&');
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $this->config->getEndPoint(SveaConfigurationProvider::HOSTED_ADMIN_TYPE) . $this->method);
- curl_setopt($ch, CURLOPT_POST, count($fields));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- //force curl to trust https
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //returns a html page with redirecting to bank...
- $responseXML = curl_exec($ch);
- curl_close($ch);
-
- // create Svea\WebPay\Response\SveaResponse to handle response
- $responseObj = new \SimpleXMLElement($responseXML);
- $lowerTransactionResponse = $this->parseResponse($responseObj);
- $returnResponse = $lowerTransactionResponse;
-
- // handle alsoDoConfirm flag
- if ($this->alsoDoConfirm == true) {
-
- // if there were an error, return a ConfirmTransactionResponse with errormessage set
- if ($lowerTransactionResponse->accepted != true) {
- $confirmTransactionResponse = new ConfirmTransactionResponse(null, null, null); // hack to get empty response
- $confirmTransactionResponse->accepted = 0;
- $confirmTransactionResponse->resultcode = '100'; //INTERNAL_ERROR
- $confirmTransactionResponse->errormessage =
- "IntegrationPackage: LowerAmount request with flag alsoDoConfirm failed:" .
- $lowerTransactionResponse->resultcode . " " . $lowerTransactionResponse->errormessage;
- $returnResponse = $confirmTransactionResponse;
- } // lowerTransaction request went well, do confirmTransaction request
- else {
- $confirmTransactionRequest = new ConfirmTransaction($this->config);
- $confirmTransactionRequest->countryCode = $this->countryCode;
- $confirmTransactionRequest->transactionId = $this->transactionId;
-
- $defaultCaptureDate = explode("T", date('c')); // [0] contains date part
- $confirmTransactionRequest->captureDate = $defaultCaptureDate[0];
- $confirmTransactionResponse = $confirmTransactionRequest->doRequest();
-
- $returnResponse = $confirmTransactionResponse;
- }
- }
-
- return $returnResponse;
- }
-
- protected function parseResponse($message)
- {
- $countryCode = $this->countryCode;
- $config = $this->config;
-
- return new LowerTransactionResponse($message, $countryCode, $config);
- }
-
- protected function validateRequestAttributes()
- {
- $errors = array();
- $errors = $this->validateTransactionId($this, $errors);
- $errors = $this->validateAmountToLower($this, $errors);
-
- return $errors;
- }
-
- private function validateTransactionId($self, $errors)
- {
- if (isset($self->transactionId) == FALSE) {
- $errors['missing value'] = "transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.";
- }
-
- return $errors;
- }
-
- private function validateAmountToLower($self, $errors)
- {
- if (isset($self->amountToLower) == FALSE) {
- $errors['missing value'] = "amountToLower is required. Use function setAmountToLower().";
- }
-
- return $errors;
- }
-
- protected function createRequestXml()
- {
- $XMLWriter = new \XMLWriter();
-
- $XMLWriter->openMemory();
- $XMLWriter->setIndent(true);
- $XMLWriter->startDocument("1.0", "UTF-8");
- $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
- $XMLWriter->startElement($this->method);
- $XMLWriter->writeElement("transactionid", $this->transactionId);
- $XMLWriter->writeElement("amounttolower", $this->amountToLower);
- $XMLWriter->endElement();
- $XMLWriter->endDocument();
-
- return $XMLWriter->flush();
- }
+ /**
+ * @var string $transactionId Required.
+ */
+ public $transactionId;
+
+ /**
+ * @var string $amountToLower Required. Use minor currency (i.e. 1 SEK => 100 in minor currency)
+ */
+ public $amountToLower;
+
+ /**
+ * @var boolean $alsoDoConfirm Optional. Iff true, doRequest() will perform a ConfirmTransaction request following a successful doRequest
+ */
+ public $alsoDoConfirm;
+
+ /**
+ * Usage: create an instance, set all required attributes, then call doRequest().
+ * Required: $transactionId, $amountToLower
+ * Option: $alsoDoRequest
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ */
+ function __construct($config)
+ {
+ $this->method = "loweramount";
+ parent::__construct($config);
+ }
+
+ /**
+ * Performs a request using cURL, parsing the response using Svea\WebPay\Response\SveaResponse
+ * and returning the resulting HostedAdminResponse instance.
+ *
+ * Iff $alsoDoConfirm is true, LowerTransaction doRequest() will also
+ * perform a ConfirmTransaction request following a successful doRequest
+ * @return \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\HostedAdminResponse
+ * @override
+ */
+ public function doRequest()
+ {
+ $fields = $this->prepareRequest();
+
+ $fieldsString = "";
+ foreach ($fields as $key => $value) {
+ $fieldsString .= $key . '=' . $value . '&';
+ }
+ rtrim($fieldsString, '&');
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $this->config->getEndPoint(SveaConfigurationProvider::HOSTED_ADMIN_TYPE) . $this->method);
+ curl_setopt($ch, CURLOPT_POST, count($fields));
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ //force curl to trust https
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ //returns a html page with redirecting to bank...
+ $responseXML = curl_exec($ch);
+ curl_close($ch);
+
+ // create Svea\WebPay\Response\SveaResponse to handle response
+ $responseObj = new \SimpleXMLElement($responseXML);
+ $lowerTransactionResponse = $this->parseResponse($responseObj);
+ $returnResponse = $lowerTransactionResponse;
+
+ // handle alsoDoConfirm flag
+ if ($this->alsoDoConfirm == true) {
+
+ // if there were an error, return a ConfirmTransactionResponse with errormessage set
+ if ($lowerTransactionResponse->accepted != true) {
+ $confirmTransactionResponse = new ConfirmTransactionResponse(null, null, null); // hack to get empty response
+ $confirmTransactionResponse->accepted = 0;
+ $confirmTransactionResponse->resultcode = '100'; //INTERNAL_ERROR
+ $confirmTransactionResponse->errormessage =
+ "IntegrationPackage: LowerAmount request with flag alsoDoConfirm failed:" .
+ $lowerTransactionResponse->resultcode . " " . $lowerTransactionResponse->errormessage;
+ $returnResponse = $confirmTransactionResponse;
+ } // lowerTransaction request went well, do confirmTransaction request
+ else {
+ $confirmTransactionRequest = new ConfirmTransaction($this->config);
+ $confirmTransactionRequest->countryCode = $this->countryCode;
+ $confirmTransactionRequest->transactionId = $this->transactionId;
+
+ $defaultCaptureDate = explode("T", date('c')); // [0] contains date part
+ $confirmTransactionRequest->captureDate = $defaultCaptureDate[0];
+ $confirmTransactionResponse = $confirmTransactionRequest->doRequest();
+
+ $returnResponse = $confirmTransactionResponse;
+ }
+ }
+
+ return $returnResponse;
+ }
+
+ protected function parseResponse($message)
+ {
+ $countryCode = $this->countryCode;
+ $config = $this->config;
+
+ return new LowerTransactionResponse($message, $countryCode, $config);
+ }
+
+ protected function validateRequestAttributes()
+ {
+ $errors = [];
+ $errors = $this->validateTransactionId($this, $errors);
+ $errors = $this->validateAmountToLower($this, $errors);
+
+ return $errors;
+ }
+
+ private function validateTransactionId($self, $errors)
+ {
+ if (isset($self->transactionId) == FALSE) {
+ $errors['missing value'] = "transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.";
+ }
+
+ return $errors;
+ }
+
+ private function validateAmountToLower($self, $errors)
+ {
+ if (isset($self->amountToLower) == FALSE) {
+ $errors['missing value'] = "amountToLower is required. Use function setAmountToLower().";
+ }
+
+ return $errors;
+ }
+
+ protected function createRequestXml()
+ {
+ $XMLWriter = new \XMLWriter();
+
+ $XMLWriter->openMemory();
+ $XMLWriter->setIndent(true);
+ $XMLWriter->startDocument("1.0", "UTF-8");
+ $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
+ $XMLWriter->startElement($this->method);
+ $XMLWriter->writeElement("transactionid", $this->transactionId);
+ $XMLWriter->writeElement("amounttolower", $this->amountToLower);
+ $XMLWriter->endElement();
+ $XMLWriter->endDocument();
+
+ return $XMLWriter->flush();
+ }
}
diff --git a/src/HostedService/HostedAdminRequest/QueryTransaction.php b/src/HostedService/HostedAdminRequest/QueryTransaction.php
index f15ec2f2..ba9e31fc 100644
--- a/src/HostedService/HostedAdminRequest/QueryTransaction.php
+++ b/src/HostedService/HostedAdminRequest/QueryTransaction.php
@@ -16,60 +16,60 @@
*/
class QueryTransaction extends HostedRequest
{
- /**
- * @var string $transactionId Required.
- */
- public $transactionId;
+ /**
+ * @var string $transactionId Required.
+ */
+ public $transactionId;
- /**
- * Usage: create an instance, set all required attributes, then call doRequest().
- * Required: $transactionId
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- */
- function __construct($config)
- {
- $this->method = "querytransactionid";
- parent::__construct($config);
- }
+ /**
+ * Usage: create an instance, set all required attributes, then call doRequest().
+ * Required: $transactionId
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ */
+ function __construct($config)
+ {
+ $this->method = "querytransactionid";
+ parent::__construct($config);
+ }
- protected function validateRequestAttributes()
- {
- $errors = array();
- $errors = $this->validateTransactionId($this, $errors);
+ protected function validateRequestAttributes()
+ {
+ $errors = [];
+ $errors = $this->validateTransactionId($this, $errors);
- return $errors;
- }
+ return $errors;
+ }
- private function validateTransactionId($self, $errors)
- {
- if (isset($self->transactionId) == FALSE) {
- $errors['missing value'] = "transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.";
- }
+ private function validateTransactionId($self, $errors)
+ {
+ if (isset($self->transactionId) == FALSE) {
+ $errors['missing value'] = "transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.";
+ }
- return $errors;
- }
+ return $errors;
+ }
- protected function createRequestXml()
- {
- $XMLWriter = new \XMLWriter();
+ protected function createRequestXml()
+ {
+ $XMLWriter = new \XMLWriter();
- $XMLWriter->openMemory();
- $XMLWriter->setIndent(true);
- $XMLWriter->startDocument("1.0", "UTF-8");
- $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
- $XMLWriter->startElement("query"); // note, not the same as $this->method above
- $XMLWriter->writeElement("transactionid", $this->transactionId);
- $XMLWriter->endElement();
- $XMLWriter->endDocument();
+ $XMLWriter->openMemory();
+ $XMLWriter->setIndent(true);
+ $XMLWriter->startDocument("1.0", "UTF-8");
+ $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
+ $XMLWriter->startElement("query"); // note, not the same as $this->method above
+ $XMLWriter->writeElement("transactionid", $this->transactionId);
+ $XMLWriter->endElement();
+ $XMLWriter->endDocument();
- return $XMLWriter->flush();
- }
+ return $XMLWriter->flush();
+ }
- protected function parseResponse($message)
- {
- $countryCode = $this->countryCode;
- $config = $this->config;
+ protected function parseResponse($message)
+ {
+ $countryCode = $this->countryCode;
+ $config = $this->config;
- return new QueryTransactionResponse($message, $countryCode, $config);
- }
+ return new QueryTransactionResponse($message, $countryCode, $config);
+ }
}
diff --git a/src/HostedService/HostedAdminRequest/QueryTransactionByCustomerRefNo.php b/src/HostedService/HostedAdminRequest/QueryTransactionByCustomerRefNo.php
index b6e2d7c8..86418f13 100644
--- a/src/HostedService/HostedAdminRequest/QueryTransactionByCustomerRefNo.php
+++ b/src/HostedService/HostedAdminRequest/QueryTransactionByCustomerRefNo.php
@@ -16,60 +16,60 @@
*/
class QueryTransactionByCustomerRefNo extends HostedRequest
{
- /**
- * @var string $customerRefNo Required.
- */
- public $customerRefNo;
+ /**
+ * @var string $customerRefNo Required.
+ */
+ public $customerRefNo;
- /**
- * Usage: create an instance, set all required attributes, then call doRequest().
- * Required: $customerRefNo
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- */
- function __construct($config)
- {
- $this->method = "querycustomerrefno";
- parent::__construct($config);
- }
+ /**
+ * Usage: create an instance, set all required attributes, then call doRequest().
+ * Required: $customerRefNo
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ */
+ function __construct($config)
+ {
+ $this->method = "querycustomerrefno";
+ parent::__construct($config);
+ }
- protected function validateRequestAttributes()
- {
- $errors = array();
- $errors = $this->validateClientOrderNumber($this, $errors);
+ protected function validateRequestAttributes()
+ {
+ $errors = [];
+ $errors = $this->validateClientOrderNumber($this, $errors);
- return $errors;
- }
+ return $errors;
+ }
- private function validateClientOrderNumber($self, $errors)
- {
- if (isset($self->customerRefNo) == FALSE) {
- $errors['missing value'] = "customerRefNo is required. Use function setClientOrderNumber() with the order number you used when creating the transaction.";
- }
+ private function validateClientOrderNumber($self, $errors)
+ {
+ if (isset($self->customerRefNo) == FALSE) {
+ $errors['missing value'] = "customerRefNo is required. Use function setClientOrderNumber() with the order number you used when creating the transaction.";
+ }
- return $errors;
- }
+ return $errors;
+ }
- protected function createRequestXml()
- {
- $XMLWriter = new \XMLWriter();
+ protected function createRequestXml()
+ {
+ $XMLWriter = new \XMLWriter();
- $XMLWriter->openMemory();
- $XMLWriter->setIndent(true);
- $XMLWriter->startDocument("1.0", "UTF-8");
- $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
- $XMLWriter->startElement("query"); // note, not the same as $this->method above
- $XMLWriter->writeElement("customerrefno", $this->customerRefNo);
- $XMLWriter->endElement();
- $XMLWriter->endDocument();
+ $XMLWriter->openMemory();
+ $XMLWriter->setIndent(true);
+ $XMLWriter->startDocument("1.0", "UTF-8");
+ $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
+ $XMLWriter->startElement("query"); // note, not the same as $this->method above
+ $XMLWriter->writeElement("customerrefno", $this->customerRefNo);
+ $XMLWriter->endElement();
+ $XMLWriter->endDocument();
- return $XMLWriter->flush();
- }
+ return $XMLWriter->flush();
+ }
- protected function parseResponse($message)
- {
- $countryCode = $this->countryCode;
- $config = $this->config;
+ protected function parseResponse($message)
+ {
+ $countryCode = $this->countryCode;
+ $config = $this->config;
- return new QueryTransactionResponse($message, $countryCode, $config);
- }
+ return new QueryTransactionResponse($message, $countryCode, $config);
+ }
}
diff --git a/src/HostedService/HostedAdminRequest/RecurTransaction.php b/src/HostedService/HostedAdminRequest/RecurTransaction.php
index 5f6b1c17..f4adc8f8 100644
--- a/src/HostedService/HostedAdminRequest/RecurTransaction.php
+++ b/src/HostedService/HostedAdminRequest/RecurTransaction.php
@@ -17,109 +17,109 @@
*/
class RecurTransaction extends HostedRequest
{
- /**
- * @var string $subscriptionId Required. This is the subscription id returned with the inital transaction that set up the subscription response.
- */
- public $subscriptionId;
-
- /**
- * @var string $customerRefNo Required. This is the new unique customer reference number for the resulting recur transaction.
- */
- public $customerRefNo;
-
- /**
- * @var string $amount Required. Use minor currency (i.e. 1 SEK => 100 in minor currency)
- */
- public $amount;
-
- /**
- * @var string $vat Required. Use minor currency (i.e. 25% => 2500 in minor currency)
- */
- public $vat;
-
- /**
- * @var string $currency Optional.
- */
- public $currency;
-
- /**
- * Usage: create an instance, set all required attributes, then call doRequest().
- * Required: $subscriptionId, $customerRefNo, $amount
- * Optional: $currency
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- */
- function __construct($config)
- {
- $this->method = "recur";
- parent::__construct($config);
- }
-
- protected function validateRequestAttributes()
- {
- $errors = array();
- $errors = $this->validateAmount($this, $errors);
- $errors = $this->validateCustomerRefNo($this, $errors);
- $errors = $this->validateSubscriptionId($this, $errors);
-
- return $errors;
- }
-
- private function validateAmount($self, $errors)
- {
- if (isset($self->amount) == FALSE) {
- $errors['missing value'] = "amount is required. Use function setAmount().";
- }
-
- return $errors;
- }
-
- private function validateCustomerRefNo($self, $errors)
- {
- if (isset($self->customerRefNo) == FALSE) {
- $errors['missing value'] = "customerRefNo is required. Use function setCustomerRefNo (also check setClientOrderNumber in order builder).";
- }
-
- return $errors;
- }
-
- private function validateSubscriptionId($self, $errors)
- {
- if (isset($self->subscriptionId) == FALSE) {
- $errors['missing value'] = "subscriptionId is required. Use function setSubscriptionId() with the subscriptionId from the createOrder response.";
- }
-
- return $errors;
- }
-
- protected function createRequestXml()
- {
- $XMLWriter = new \XMLWriter();
-
- $XMLWriter->openMemory();
- $XMLWriter->setIndent(true);
- $XMLWriter->startDocument("1.0", "UTF-8");
- $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
- $XMLWriter->startElement($this->method);
- $XMLWriter->writeElement("amount", $this->amount);
- $XMLWriter->writeElement("customerrefno", $this->customerRefNo);
- $XMLWriter->writeElement("subscriptionid", $this->subscriptionId);
- if (isset($this->vat)) {
- $XMLWriter->writeElement("vat", $this->vat);
- }
- if (isset($this->currency)) {
- $XMLWriter->writeElement("currency", $this->currency);
- }
- $XMLWriter->endElement();
- $XMLWriter->endDocument();
-
- return $XMLWriter->flush();
- }
-
- protected function parseResponse($message)
- {
- $countryCode = $this->countryCode;
- $config = $this->config;
-
- return new RecurTransactionResponse($message, $countryCode, $config);
- }
+ /**
+ * @var string $subscriptionId Required. This is the subscription id returned with the inital transaction that set up the subscription response.
+ */
+ public $subscriptionId;
+
+ /**
+ * @var string $customerRefNo Required. This is the new unique customer reference number for the resulting recur transaction.
+ */
+ public $customerRefNo;
+
+ /**
+ * @var string $amount Required. Use minor currency (i.e. 1 SEK => 100 in minor currency)
+ */
+ public $amount;
+
+ /**
+ * @var string $vat Required. Use minor currency (i.e. 25% => 2500 in minor currency)
+ */
+ public $vat;
+
+ /**
+ * @var string $currency Optional.
+ */
+ public $currency;
+
+ /**
+ * Usage: create an instance, set all required attributes, then call doRequest().
+ * Required: $subscriptionId, $customerRefNo, $amount
+ * Optional: $currency
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ */
+ function __construct($config)
+ {
+ $this->method = "recur";
+ parent::__construct($config);
+ }
+
+ protected function validateRequestAttributes()
+ {
+ $errors = [];
+ $errors = $this->validateAmount($this, $errors);
+ $errors = $this->validateCustomerRefNo($this, $errors);
+ $errors = $this->validateSubscriptionId($this, $errors);
+
+ return $errors;
+ }
+
+ private function validateAmount($self, $errors)
+ {
+ if (isset($self->amount) == FALSE) {
+ $errors['missing value'] = "amount is required. Use function setAmount().";
+ }
+
+ return $errors;
+ }
+
+ private function validateCustomerRefNo($self, $errors)
+ {
+ if (isset($self->customerRefNo) == FALSE) {
+ $errors['missing value'] = "customerRefNo is required. Use function setCustomerRefNo (also check setClientOrderNumber in order builder).";
+ }
+
+ return $errors;
+ }
+
+ private function validateSubscriptionId($self, $errors)
+ {
+ if (isset($self->subscriptionId) == FALSE) {
+ $errors['missing value'] = "subscriptionId is required. Use function setSubscriptionId() with the subscriptionId from the createOrder response.";
+ }
+
+ return $errors;
+ }
+
+ protected function createRequestXml()
+ {
+ $XMLWriter = new \XMLWriter();
+
+ $XMLWriter->openMemory();
+ $XMLWriter->setIndent(true);
+ $XMLWriter->startDocument("1.0", "UTF-8");
+ $XMLWriter->writeComment(Helper::getLibraryAndPlatformPropertiesAsJson($this->config));
+ $XMLWriter->startElement($this->method);
+ $XMLWriter->writeElement("amount", $this->amount);
+ $XMLWriter->writeElement("customerrefno", $this->customerRefNo);
+ $XMLWriter->writeElement("subscriptionid", $this->subscriptionId);
+ if (isset($this->vat)) {
+ $XMLWriter->writeElement("vat", $this->vat);
+ }
+ if (isset($this->currency)) {
+ $XMLWriter->writeElement("currency", $this->currency);
+ }
+ $XMLWriter->endElement();
+ $XMLWriter->endDocument();
+
+ return $XMLWriter->flush();
+ }
+
+ protected function parseResponse($message)
+ {
+ $countryCode = $this->countryCode;
+ $config = $this->config;
+
+ return new RecurTransactionResponse($message, $countryCode, $config);
+ }
}
\ No newline at end of file
diff --git a/src/HostedService/HostedRequest.php b/src/HostedService/HostedRequest.php
index 314286c0..5b6e5655 100644
--- a/src/HostedService/HostedRequest.php
+++ b/src/HostedService/HostedRequest.php
@@ -14,140 +14,140 @@
*/
abstract class HostedRequest
{
- /**
- * @var string $countryCode used to disambiguate between the various credentials in Svea\WebPay\Config\ConfigurationProvider
- */
- public $countryCode;
-
- /**
- * @var ConfigurationProvider $config */
- protected $config;
-
- /**
- * @var string $method set by the subclass, defines what webservice is called (including payment)
- */
- protected $method;
-
- /**
- * @param ConfigurationProvider $config
- */
- function __construct($config)
- {
- $this->config = $config;
- }
-
- /**
- * Performs a request using cURL, parsing the response using Svea\WebPay\Response\SveaResponse
- * and returning the resulting HostedAdminResponse instance.
- *
- * @return HostedAdminResponse
- */
- public function doRequest()
- {
- $fields = $this->prepareRequest();
-
- $fieldsString = "";
- foreach ($fields as $key => $value) {
- $fieldsString .= $key . '=' . $value . '&';
- }
- rtrim($fieldsString, '&');
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $this->config->getEndPoint(SveaConfigurationProvider::HOSTED_ADMIN_TYPE) . $this->method);
- curl_setopt($ch, CURLOPT_POST, count($fields));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- //force curl to trust https
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //returns a html page with redirecting to bank...
- $responseXML = curl_exec($ch);
- curl_close($ch);
-
- // create Svea\WebPay\Response\SveaResponse to handle response
- $responseObj = new \SimpleXMLElement($responseXML);
-
- return $this->parseResponse($responseObj);
- }
-
- /**
- * returns the request fields to post to service
- */
- public function prepareRequest()
- {
- $this->validateRequest();
-
- //$xmlBuilder = new HostedXmlBuilder();
-
- // get our merchantid & secret
- $merchantId = $this->config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $this->countryCode);
- $secret = $this->config->getSecret(ConfigurationProvider::HOSTED_TYPE, $this->countryCode);
-
- $message = $this->createRequestXml();
-
- // calculate mac
- $mac = hash("sha512", base64_encode($message) . $secret);
-
- // encode the request elements
- $request_fields = array(
- 'merchantid' => urlencode($merchantId),
- 'message' => urlencode(base64_encode($message)),
- 'mac' => urlencode($mac)
- );
-
- return $request_fields;
- }
-
- /**
- * Validates the request to make sure that all required request attributes
- * are present. If not, throws an exception. Actual validation is delegated
- * to subclass validateAttributes() implementations.
- *
- * @throws ValidationException
- */
- public function validateRequest()
- {
- // validate subclass request required attributes
- $errors = $this->validateRequestAttributes();
-
- // validate countrycode
- $errors = $this->validateCountryCode($this, $errors);
-
- if (count($errors) > 0) {
- $exceptionString = "";
- foreach ($errors as $key => $value) {
- $exceptionString .= "-" . $key . " : " . $value . "\n";
- }
-
- throw new ValidationException($exceptionString);
- }
- }
-
- /**
- * implemented by child classes, should validate that all required attributes for the method are present
- */
- abstract protected function validateRequestAttributes();
-
- /**
- * @param $self
- * @param $errors
- * @return mixed
- */
- private function validateCountryCode($self, $errors)
- {
- if (isset($this->countryCode) == FALSE) {
- $errors['missing value'] = 'CountryCode is required. Use function setCountryCode().';
- }
-
- return $errors;
- }
-
- /**
- * implemented by child classes, should return the request xml for the method (i.e. "message" in the HostedAdminRequest request wrapper)
- */
- abstract protected function createRequestXml();
-
- /**
- * implemented by child classes, should return the request response class for the method
- */
- abstract protected function parseResponse($response);
+ /**
+ * @var string $countryCode used to disambiguate between the various credentials in Svea\WebPay\Config\ConfigurationProvider
+ */
+ public $countryCode;
+
+ /**
+ * @var ConfigurationProvider $config */
+ protected $config;
+
+ /**
+ * @var string $method set by the subclass, defines what webservice is called (including payment)
+ */
+ protected $method;
+
+ /**
+ * @param ConfigurationProvider $config
+ */
+ function __construct($config)
+ {
+ $this->config = $config;
+ }
+
+ /**
+ * Performs a request using cURL, parsing the response using Svea\WebPay\Response\SveaResponse
+ * and returning the resulting HostedAdminResponse instance.
+ *
+ * @return HostedAdminResponse
+ */
+ public function doRequest()
+ {
+ $fields = $this->prepareRequest();
+
+ $fieldsString = "";
+ foreach ($fields as $key => $value) {
+ $fieldsString .= $key . '=' . $value . '&';
+ }
+ rtrim($fieldsString, '&');
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $this->config->getEndPoint(SveaConfigurationProvider::HOSTED_ADMIN_TYPE) . $this->method);
+ curl_setopt($ch, CURLOPT_POST, count($fields));
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ //force curl to trust https
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ //returns a html page with redirecting to bank...
+ $responseXML = curl_exec($ch);
+ curl_close($ch);
+
+ // create Svea\WebPay\Response\SveaResponse to handle response
+ $responseObj = new \SimpleXMLElement($responseXML);
+
+ return $this->parseResponse($responseObj);
+ }
+
+ /**
+ * returns the request fields to post to service
+ */
+ public function prepareRequest()
+ {
+ $this->validateRequest();
+
+ //$xmlBuilder = new HostedXmlBuilder();
+
+ // get our merchantid & secret
+ $merchantId = $this->config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $this->countryCode);
+ $secret = $this->config->getSecret(ConfigurationProvider::HOSTED_TYPE, $this->countryCode);
+
+ $message = $this->createRequestXml();
+
+ // calculate mac
+ $mac = hash("sha512", base64_encode($message) . $secret);
+
+ // encode the request elements
+ $request_fields = [
+ 'merchantid' => urlencode($merchantId),
+ 'message' => urlencode(base64_encode($message)),
+ 'mac' => urlencode($mac)
+ ];
+
+ return $request_fields;
+ }
+
+ /**
+ * Validates the request to make sure that all required request attributes
+ * are present. If not, throws an exception. Actual validation is delegated
+ * to subclass validateAttributes() implementations.
+ *
+ * @throws ValidationException
+ */
+ public function validateRequest()
+ {
+ // validate subclass request required attributes
+ $errors = $this->validateRequestAttributes();
+
+ // validate countrycode
+ $errors = $this->validateCountryCode($this, $errors);
+
+ if (count($errors) > 0) {
+ $exceptionString = "";
+ foreach ($errors as $key => $value) {
+ $exceptionString .= "-" . $key . " : " . $value . "\n";
+ }
+
+ throw new ValidationException($exceptionString);
+ }
+ }
+
+ /**
+ * implemented by child classes, should validate that all required attributes for the method are present
+ */
+ abstract protected function validateRequestAttributes();
+
+ /**
+ * @param $self
+ * @param $errors
+ * @return mixed
+ */
+ private function validateCountryCode($self, $errors)
+ {
+ if (isset($this->countryCode) == FALSE) {
+ $errors['missing value'] = 'CountryCode is required. Use function setCountryCode().';
+ }
+
+ return $errors;
+ }
+
+ /**
+ * implemented by child classes, should return the request xml for the method (i.e. "message" in the HostedAdminRequest request wrapper)
+ */
+ abstract protected function createRequestXml();
+
+ /**
+ * implemented by child classes, should return the request response class for the method
+ */
+ abstract protected function parseResponse($response);
}
diff --git a/src/HostedService/HostedResponse/HostedAdminResponse/AnnulTransactionResponse.php b/src/HostedService/HostedResponse/HostedAdminResponse/AnnulTransactionResponse.php
index 6c1f83a6..abe8594b 100644
--- a/src/HostedService/HostedResponse/HostedAdminResponse/AnnulTransactionResponse.php
+++ b/src/HostedService/HostedResponse/HostedAdminResponse/AnnulTransactionResponse.php
@@ -9,46 +9,46 @@
*/
class AnnulTransactionResponse extends HostedAdminResponse
{
- /**
- * @var string $transactionId transaction id that uniquely identifies the order at Svea
- */
- public $transactionId;
+ /**
+ * @var string $transactionId transaction id that uniquely identifies the order at Svea
+ */
+ public $transactionId;
- /**
- * @var string $clientOrderNumber
- */
- public $clientOrderNumber;
+ /**
+ * @var string $clientOrderNumber
+ */
+ public $clientOrderNumber;
- /**
- * AnnulTransactionResponse constructor.
- * @param \SimpleXMLElement $message
- * @param string $countryCode
- * @param \Svea\WebPay\Config\SveaConfigurationProvider $config
- */
- function __construct($message, $countryCode, $config)
- {
- parent::__construct($message, $countryCode, $config);
- }
+ /**
+ * AnnulTransactionResponse constructor.
+ * @param \SimpleXMLElement $message
+ * @param string $countryCode
+ * @param \Svea\WebPay\Config\SveaConfigurationProvider $config
+ */
+ function __construct($message, $countryCode, $config)
+ {
+ parent::__construct($message, $countryCode, $config);
+ }
- /**
- * formatXml() parses the annul transaction response xml into an object, and
- * then sets the response attributes accordingly.
- *
- * @param string $hostedAdminResponseXML hostedAdminResponse as xml
- */
- protected function formatXml($hostedAdminResponseXML)
- {
- $hostedAdminResponse = new \SimpleXMLElement($hostedAdminResponseXML);
+ /**
+ * formatXml() parses the annul transaction response xml into an object, and
+ * then sets the response attributes accordingly.
+ *
+ * @param string $hostedAdminResponseXML hostedAdminResponse as xml
+ */
+ protected function formatXml($hostedAdminResponseXML)
+ {
+ $hostedAdminResponse = new \SimpleXMLElement($hostedAdminResponseXML);
- if ((string)$hostedAdminResponse->statuscode == '0') {
- $this->accepted = 1;
- $this->resultcode = '0';
- } else {
- $this->accepted = 0;
- $this->setErrorParams((string)$hostedAdminResponse->statuscode);
- }
- $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
+ if ((string)$hostedAdminResponse->statuscode == '0') {
+ $this->accepted = 1;
+ $this->resultcode = '0';
+ } else {
+ $this->accepted = 0;
+ $this->setErrorParams((string)$hostedAdminResponse->statuscode);
+ }
+ $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
- $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno;
- }
+ $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno;
+ }
}
diff --git a/src/HostedService/HostedResponse/HostedAdminResponse/CancelRecurSubscriptionResponse.php b/src/HostedService/HostedResponse/HostedAdminResponse/CancelRecurSubscriptionResponse.php
index 6de0b6ec..404bce51 100644
--- a/src/HostedService/HostedResponse/HostedAdminResponse/CancelRecurSubscriptionResponse.php
+++ b/src/HostedService/HostedResponse/HostedAdminResponse/CancelRecurSubscriptionResponse.php
@@ -11,33 +11,33 @@
*/
class CancelRecurSubscriptionResponse extends HostedAdminResponse
{
- /**
- * CancelRecurSubscriptionResponse constructor.
- * @param \SimpleXMLElement $message
- * @param string $countryCode
- * @param \Svea\WebPay\Config\SveaConfigurationProvider $config
- */
- function __construct($message, $countryCode, $config)
- {
- parent::__construct($message, $countryCode, $config);
- }
+ /**
+ * CancelRecurSubscriptionResponse constructor.
+ * @param \SimpleXMLElement $message
+ * @param string $countryCode
+ * @param \Svea\WebPay\Config\SveaConfigurationProvider $config
+ */
+ function __construct($message, $countryCode, $config)
+ {
+ parent::__construct($message, $countryCode, $config);
+ }
- /**
- * formatXml() parses the lower transaction response xml into an object, and
- * then sets the response attributes accordingly.
- *
- * @param string $hostedAdminResponseXML hostedAdminResponse as xml
- */
- protected function formatXml($hostedAdminResponseXML)
- {
- $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
+ /**
+ * formatXml() parses the lower transaction response xml into an object, and
+ * then sets the response attributes accordingly.
+ *
+ * @param string $hostedAdminResponseXML hostedAdminResponse as xml
+ */
+ protected function formatXml($hostedAdminResponseXML)
+ {
+ $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
- if ((string)$hostedAdminResponse->statuscode == '0') {
- $this->accepted = 1;
- $this->resultcode = '0';
- } else {
- $this->accepted = 0;
- $this->setErrorParams((string)$hostedAdminResponse->statuscode);
- }
- }
+ if ((string)$hostedAdminResponse->statuscode == '0') {
+ $this->accepted = 1;
+ $this->resultcode = '0';
+ } else {
+ $this->accepted = 0;
+ $this->setErrorParams((string)$hostedAdminResponse->statuscode);
+ }
+ }
}
diff --git a/src/HostedService/HostedResponse/HostedAdminResponse/ConfirmTransactionResponse.php b/src/HostedService/HostedResponse/HostedAdminResponse/ConfirmTransactionResponse.php
index 1910d647..b22fcdba 100644
--- a/src/HostedService/HostedResponse/HostedAdminResponse/ConfirmTransactionResponse.php
+++ b/src/HostedService/HostedResponse/HostedAdminResponse/ConfirmTransactionResponse.php
@@ -13,53 +13,53 @@
*/
class ConfirmTransactionResponse extends HostedAdminResponse
{
- /**
- * @var string $transactionId transaction id that uniquely identifies the order at Svea
- */
- public $transactionId;
+ /**
+ * @var string $transactionId transaction id that uniquely identifies the order at Svea
+ */
+ public $transactionId;
- /**
- * @var string $clientOrderNumber
- */
- public $clientOrderNumber;
+ /**
+ * @var string $clientOrderNumber
+ */
+ public $clientOrderNumber;
- /**
- * @var string $orderType -- set to \Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE for all
- * hosted confirm order requests (currently only confirm card orders)
- */
- public $orderType;
+ /**
+ * @var string $orderType -- set to \Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE for all
+ * hosted confirm order requests (currently only confirm card orders)
+ */
+ public $orderType;
- /**
- * ConfirmTransactionResponse constructor.
- * @param SimpleXMLElement $message
- * @param string $countryCode
- * @param SveaConfigurationProvider $config
- */
- function __construct($message, $countryCode, $config)
- {
- parent::__construct($message, $countryCode, $config);
- }
+ /**
+ * ConfirmTransactionResponse constructor.
+ * @param SimpleXMLElement $message
+ * @param string $countryCode
+ * @param SveaConfigurationProvider $config
+ */
+ function __construct($message, $countryCode, $config)
+ {
+ parent::__construct($message, $countryCode, $config);
+ }
- /**
- * formatXml() parses the confirm transaction response xml into an object, and
- * then sets the response attributes accordingly.
- *
- * @param string $hostedAdminResponseXML hostedAdminResponse as xml
- */
- protected function formatXml($hostedAdminResponseXML)
- {
- $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
+ /**
+ * formatXml() parses the confirm transaction response xml into an object, and
+ * then sets the response attributes accordingly.
+ *
+ * @param string $hostedAdminResponseXML hostedAdminResponse as xml
+ */
+ protected function formatXml($hostedAdminResponseXML)
+ {
+ $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
- if ((string)$hostedAdminResponse->statuscode == '0') {
- $this->accepted = 1;
- $this->resultcode = '0';
- } else {
- $this->accepted = 0;
- $this->setErrorParams((string)$hostedAdminResponse->statuscode);
- }
- $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
+ if ((string)$hostedAdminResponse->statuscode == '0') {
+ $this->accepted = 1;
+ $this->resultcode = '0';
+ } else {
+ $this->accepted = 0;
+ $this->setErrorParams((string)$hostedAdminResponse->statuscode);
+ }
+ $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
- $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno;
- $this->orderType = ConfigurationProvider::HOSTED_TYPE; // c.f. corresponding attribute in DeliverOrderResult
- }
+ $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno;
+ $this->orderType = ConfigurationProvider::HOSTED_TYPE; // c.f. corresponding attribute in DeliverOrderResult
+ }
}
diff --git a/src/HostedService/HostedResponse/HostedAdminResponse/CreditTransactionResponse.php b/src/HostedService/HostedResponse/HostedAdminResponse/CreditTransactionResponse.php
index 3dec6bcd..935e2cc7 100644
--- a/src/HostedService/HostedResponse/HostedAdminResponse/CreditTransactionResponse.php
+++ b/src/HostedService/HostedResponse/HostedAdminResponse/CreditTransactionResponse.php
@@ -12,46 +12,46 @@
*/
class CreditTransactionResponse extends HostedAdminResponse
{
- /**
- * @var string $transactionId transaction id that uniquely identifies the order at Svea
- */
- public $transactionId;
-
- /**
- * @var string $clientOrderNumber
- */
- public $clientOrderNumber;
-
- /**
- * CreditTransactionResponse constructor.
- * @param SimpleXMLElement $message
- * @param string $countryCode
- * @param SveaConfigurationProvider $config
- */
- function __construct($message, $countryCode, $config)
- {
- parent::__construct($message, $countryCode, $config);
- }
-
- /**
- * formatXml() parses the credit transaction response xml into an object, and
- * then sets the response attributes accordingly.
- *
- * @param string $hostedAdminResponseXML hostedAdminResponse as xml
- */
- protected function formatXml($hostedAdminResponseXML)
- {
- $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
-
- if ((string)$hostedAdminResponse->statuscode == '0') {
- $this->accepted = 1;
- $this->resultcode = '0';
- } else {
- $this->accepted = 0;
- $this->setErrorParams((string)$hostedAdminResponse->statuscode);
- }
- $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
-
- $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno;
- }
+ /**
+ * @var string $transactionId transaction id that uniquely identifies the order at Svea
+ */
+ public $transactionId;
+
+ /**
+ * @var string $clientOrderNumber
+ */
+ public $clientOrderNumber;
+
+ /**
+ * CreditTransactionResponse constructor.
+ * @param SimpleXMLElement $message
+ * @param string $countryCode
+ * @param SveaConfigurationProvider $config
+ */
+ function __construct($message, $countryCode, $config)
+ {
+ parent::__construct($message, $countryCode, $config);
+ }
+
+ /**
+ * formatXml() parses the credit transaction response xml into an object, and
+ * then sets the response attributes accordingly.
+ *
+ * @param string $hostedAdminResponseXML hostedAdminResponse as xml
+ */
+ protected function formatXml($hostedAdminResponseXML)
+ {
+ $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
+
+ if ((string)$hostedAdminResponse->statuscode == '0') {
+ $this->accepted = 1;
+ $this->resultcode = '0';
+ } else {
+ $this->accepted = 0;
+ $this->setErrorParams((string)$hostedAdminResponse->statuscode);
+ }
+ $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
+
+ $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno;
+ }
}
diff --git a/src/HostedService/HostedResponse/HostedAdminResponse/HostedAdminResponse.php b/src/HostedService/HostedResponse/HostedAdminResponse/HostedAdminResponse.php
index f4bedc3c..be1d713f 100644
--- a/src/HostedService/HostedResponse/HostedAdminResponse/HostedAdminResponse.php
+++ b/src/HostedService/HostedResponse/HostedAdminResponse/HostedAdminResponse.php
@@ -16,72 +16,72 @@
*/
class HostedAdminResponse extends HostedResponse
{
- protected $config;
+ protected $config;
- /**
- * Create an new HostedAdminResponse which handles the webservice response
- *
- * Will set response attribute accepted to 0 if the mac is invalid or the
- * response is malformed.
- *
- * @param SimpleXMLElement $message
- * @param string $countryCode
- * @param SveaConfigurationProvider $config
- */
- function __construct($message, $countryCode, $config)
- {
- $this->config = $config;
+ /**
+ * Create an new HostedAdminResponse which handles the webservice response
+ *
+ * Will set response attribute accepted to 0 if the mac is invalid or the
+ * response is malformed.
+ *
+ * @param SimpleXMLElement $message
+ * @param string $countryCode
+ * @param SveaConfigurationProvider $config
+ */
+ function __construct($message, $countryCode, $config)
+ {
+ $this->config = $config;
- if (is_object($message)) {
+ if (is_object($message)) {
- if (isset($message->mac) && isset($message->message)) {
- $decodedXml = base64_decode($message->message);
- $secret = $config->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ if (isset($message->mac) && isset($message->message)) {
+ $decodedXml = base64_decode($message->message);
+ $secret = $config->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- if ($this->validateMac($message->message, $message->mac, $secret)) {
- $this->formatXml($decodedXml);
- } else {
- $this->accepted = 0;
- $this->resultcode = '0';
- $this->errormessage = "Response failed authorization. MAC not valid.";
- }
- }
+ if ($this->validateMac($message->message, $message->mac, $secret)) {
+ $this->formatXml($decodedXml);
+ } else {
+ $this->accepted = 0;
+ $this->resultcode = '0';
+ $this->errormessage = "Response failed authorization. MAC not valid.";
+ }
+ }
- } else {
- $this->accepted = 0;
- $this->resultcode = '0';
- $this->errormessage = "Response is not recognized.";
- }
- }
+ } else {
+ $this->accepted = 0;
+ $this->resultcode = '0';
+ $this->errormessage = "Response is not recognized.";
+ }
+ }
- /**
- * formatXml() parses the hosted admin response xml into an object, and
- * then sets the response attributes accordingly.
- *
- * @param type $hostedAdminResponseXML
- */
- protected function formatXml($hostedAdminResponseXML)
- {
- $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
+ /**
+ * formatXml() parses the hosted admin response xml into an object, and
+ * then sets the response attributes accordingly.
+ *
+ * @param type $hostedAdminResponseXML
+ */
+ protected function formatXml($hostedAdminResponseXML)
+ {
+ $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
- if ((string)$hostedAdminResponse->statuscode == '0') {
- $this->accepted = 1;
- $this->resultcode = '0';
- } else {
- $this->accepted = 0;
- $this->setErrorParams((string)$hostedAdminResponse->statuscode);
- }
+ if ((string)$hostedAdminResponse->statuscode == '0') {
+ $this->accepted = 1;
+ $this->resultcode = '0';
+ } else {
+ $this->accepted = 0;
+ $this->setErrorParams((string)$hostedAdminResponse->statuscode);
+ }
- // getPaymentUrl/preparepayment request
- if (property_exists($hostedAdminResponse, "preparedpayment")) {
- $url = $this->config->getEndpoint(SveaConfigurationProvider::PREPARED_URL);
- $testurl = ConfigurationService::SWP_TEST_PREPARED_URL;
+ // getPaymentUrl/preparepayment request
+ if (property_exists($hostedAdminResponse, "preparedpayment")) {
+ $url = $this->config->getEndpoint(SveaConfigurationProvider::PREPARED_URL);
+ $testurl = ConfigurationService::SWP_TEST_PREPARED_URL;
- $this->id = (string)$hostedAdminResponse->preparedpayment->id;
- $this->created = (string)$hostedAdminResponse->preparedpayment->created;
+ $this->id = (string)$hostedAdminResponse->preparedpayment->id;
+ $this->created = (string)$hostedAdminResponse->preparedpayment->created;
- $this->url = $url . $this->id; // in integration package only
- $this->testurl = $testurl . $this->id; // in integration packge only
- }
- }
+ $this->url = $url . $this->id; // in integration package only
+ $this->testurl = $testurl . $this->id; // in integration packge only
+ }
+ }
}
diff --git a/src/HostedService/HostedResponse/HostedAdminResponse/ListPaymentMethodsResponse.php b/src/HostedService/HostedResponse/HostedAdminResponse/ListPaymentMethodsResponse.php
index f0572e59..003054e7 100644
--- a/src/HostedService/HostedResponse/HostedAdminResponse/ListPaymentMethodsResponse.php
+++ b/src/HostedService/HostedResponse/HostedAdminResponse/ListPaymentMethodsResponse.php
@@ -16,75 +16,75 @@
*/
class ListPaymentMethodsResponse extends HostedAdminResponse
{
- /**
- * string[] $paymentmethods array containing available paymentmethods for this merchantid, @see PaymentMethod
- */
- public $paymentmethods;
+ /**
+ * string[] $paymentmethods array containing available paymentmethods for this merchantid, @see PaymentMethod
+ */
+ public $paymentmethods;
- /**
- * used to add the invoice/paymentplan payment methods to those return with the getpaymentmethods request
- */
- private $countryCode;
+ /**
+ * used to add the invoice/paymentplan payment methods to those return with the getpaymentmethods request
+ */
+ private $countryCode;
- /**
- * ListPaymentMethodsResponse constructor.
- * @param \SimpleXMLElement $message
- * @param string $countryCode
- * @param \Svea\WebPay\Config\SveaConfigurationProvider $config
- */
- function __construct($message, $countryCode, $config)
- {
- $this->config = $config;
- $this->countryCode = $countryCode;
- parent::__construct($message, $countryCode, $config);
- }
+ /**
+ * ListPaymentMethodsResponse constructor.
+ * @param \SimpleXMLElement $message
+ * @param string $countryCode
+ * @param \Svea\WebPay\Config\SveaConfigurationProvider $config
+ */
+ function __construct($message, $countryCode, $config)
+ {
+ $this->config = $config;
+ $this->countryCode = $countryCode;
+ parent::__construct($message, $countryCode, $config);
+ }
- /**
- * formatXml() parses the getpaymentmethods transaction response xml into an object, and
- * then sets the response attributes accordingly.
- *
- * @param string $hostedAdminResponseXML hostedAdminResponse as xml
- */
- protected function formatXml($hostedAdminResponseXML)
- {
- $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
+ /**
+ * formatXml() parses the getpaymentmethods transaction response xml into an object, and
+ * then sets the response attributes accordingly.
+ *
+ * @param string $hostedAdminResponseXML hostedAdminResponse as xml
+ */
+ protected function formatXml($hostedAdminResponseXML)
+ {
+ $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
- if ((string)$hostedAdminResponse->statuscode == '0') {
- $this->accepted = 1;
- $this->resultcode = '0';
- } else {
- $this->accepted = 0;
- $this->setErrorParams((string)$hostedAdminResponse->statuscode);
- }
+ if ((string)$hostedAdminResponse->statuscode == '0') {
+ $this->accepted = 1;
+ $this->resultcode = '0';
+ } else {
+ $this->accepted = 0;
+ $this->setErrorParams((string)$hostedAdminResponse->statuscode);
+ }
- //$this->paymentMethods = (array)$hostedAdminResponse->paymentmethods->paymentmethod; // seems to break under php 5.3
- foreach ($hostedAdminResponse->paymentmethods->paymentmethod as $paymentmethod) { // compatibility w/php 5.3
- $this->paymentmethods[] = (string)$paymentmethod;
- }
+ //$this->paymentMethods = (array)$hostedAdminResponse->paymentmethods->paymentmethod; // seems to break under php 5.3
+ foreach ($hostedAdminResponse->paymentmethods->paymentmethod as $paymentmethod) { // compatibility w/php 5.3
+ $this->paymentmethods[] = (string)$paymentmethod;
+ }
- //Add Invoice and Paymentplan. If there is a clientnumber for i.e. invoice, we assume you have invoice payments configured at Svea
- try {
- $clientIdInvoice = $this->config->getClientNumber(ConfigurationProvider::INVOICE_TYPE, $this->countryCode);
+ //Add Invoice and Paymentplan. If there is a clientnumber for i.e. invoice, we assume you have invoice payments configured at Svea
+ try {
+ $clientIdInvoice = $this->config->getClientNumber(ConfigurationProvider::INVOICE_TYPE, $this->countryCode);
- if (is_numeric($clientIdInvoice) && strlen($clientIdInvoice) > 0) {
- $this->paymentmethods[] = PaymentMethod::INVOICE;
- }
- } catch (InvalidTypeException $e) {
- // assumes that the client configuration does not support $type INVOICE, so we ignore the exception
- }
+ if (is_numeric($clientIdInvoice) && strlen($clientIdInvoice) > 0) {
+ $this->paymentmethods[] = PaymentMethod::INVOICE;
+ }
+ } catch (InvalidTypeException $e) {
+ // assumes that the client configuration does not support $type INVOICE, so we ignore the exception
+ }
- try {
- $clientIdPaymentPlan = $this->config->getClientNumber(ConfigurationProvider::PAYMENTPLAN_TYPE, $this->countryCode);
+ try {
+ $clientIdPaymentPlan = $this->config->getClientNumber(ConfigurationProvider::PAYMENTPLAN_TYPE, $this->countryCode);
- if (is_numeric($clientIdPaymentPlan) && strlen($clientIdPaymentPlan) > 0) {
- $this->paymentmethods[] = PaymentMethod::PAYMENTPLAN;
- }
- } catch (InvalidTypeException $e) {
- // assumes that the client configuration does not support $type PAYMENTPLAN, so we ignore the exception
- }
+ if (is_numeric($clientIdPaymentPlan) && strlen($clientIdPaymentPlan) > 0) {
+ $this->paymentmethods[] = PaymentMethod::PAYMENTPLAN;
+ }
+ } catch (InvalidTypeException $e) {
+ // assumes that the client configuration does not support $type PAYMENTPLAN, so we ignore the exception
+ }
- // clean up response
- unset($this->config);
- unset($this->countryCode);
- }
+ // clean up response
+ unset($this->config);
+ unset($this->countryCode);
+ }
}
diff --git a/src/HostedService/HostedResponse/HostedAdminResponse/LowerTransactionResponse.php b/src/HostedService/HostedResponse/HostedAdminResponse/LowerTransactionResponse.php
index 18b47130..7ab9ce46 100644
--- a/src/HostedService/HostedResponse/HostedAdminResponse/LowerTransactionResponse.php
+++ b/src/HostedService/HostedResponse/HostedAdminResponse/LowerTransactionResponse.php
@@ -11,46 +11,46 @@
*/
class LowerTransactionResponse extends HostedAdminResponse
{
- /**
- * @var string $transactionId transaction id that uniquely identifies the order at Svea
- */
- public $transactionId;
-
- /**
- * @var string $clientOrderNumber
- */
- public $clientOrderNumber;
-
- /**
- * LowerTransactionResponse constructor.
- * @param \SimpleXMLElement $message
- * @param string $countryCode
- * @param \Svea\WebPay\Config\SveaConfigurationProvider $config
- */
- function __construct($message, $countryCode, $config)
- {
- parent::__construct($message, $countryCode, $config);
- }
-
- /**
- * formatXml() parses the lower transaction response xml into an object, and
- * then sets the response attributes accordingly.
- *
- * @param string $hostedAdminResponseXML hostedAdminResponse as xml
- */
- protected function formatXml($hostedAdminResponseXML)
- {
- $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
-
- if ((string)$hostedAdminResponse->statuscode == '0') {
- $this->accepted = 1;
- $this->resultcode = '0';
- } else {
- $this->accepted = 0;
- $this->setErrorParams((string)$hostedAdminResponse->statuscode);
- }
- $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
-
- $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno;
- }
+ /**
+ * @var string $transactionId transaction id that uniquely identifies the order at Svea
+ */
+ public $transactionId;
+
+ /**
+ * @var string $clientOrderNumber
+ */
+ public $clientOrderNumber;
+
+ /**
+ * LowerTransactionResponse constructor.
+ * @param \SimpleXMLElement $message
+ * @param string $countryCode
+ * @param \Svea\WebPay\Config\SveaConfigurationProvider $config
+ */
+ function __construct($message, $countryCode, $config)
+ {
+ parent::__construct($message, $countryCode, $config);
+ }
+
+ /**
+ * formatXml() parses the lower transaction response xml into an object, and
+ * then sets the response attributes accordingly.
+ *
+ * @param string $hostedAdminResponseXML hostedAdminResponse as xml
+ */
+ protected function formatXml($hostedAdminResponseXML)
+ {
+ $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
+
+ if ((string)$hostedAdminResponse->statuscode == '0') {
+ $this->accepted = 1;
+ $this->resultcode = '0';
+ } else {
+ $this->accepted = 0;
+ $this->setErrorParams((string)$hostedAdminResponse->statuscode);
+ }
+ $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
+
+ $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno;
+ }
}
diff --git a/src/HostedService/HostedResponse/HostedAdminResponse/QueryTransactionResponse.php b/src/HostedService/HostedResponse/HostedAdminResponse/QueryTransactionResponse.php
index c3968589..f5216a7c 100644
--- a/src/HostedService/HostedResponse/HostedAdminResponse/QueryTransactionResponse.php
+++ b/src/HostedService/HostedResponse/HostedAdminResponse/QueryTransactionResponse.php
@@ -22,292 +22,292 @@
class QueryTransactionResponse extends HostedAdminResponse
{
- /**
- * @var string $transactionId -- the order id at Svea
- */
- public $transactionId;
-
- /**
- * @var string $clientOrderNumber -- the customer reference number, i.e. order number
- */
- public $clientOrderNumber;
-
- /**
- * @var string $merchantId -- the merchant id
- */
- public $merchantId;
-
- /**
- * @var string $status -- Latest transaction status, one of {AUTHORIZED, CONFIRMED, SUCCESS}
- */
- public $status;
-
- /**
- * @var string $amount -- Total amount including VAT, in minor currency (e.g. SEK 10.50 = 1050)
- */
- public $amount;
-
- /**
- * @var string $currency -- ISO 4217 alphabetic, e.g. SEK
- */
- public $currency;
-
- /**
- * @var string $vat -- VAT, in minor currency
- */
- public $vat;
-
- /**
- * @var string $capturedamount -- Captured amount
- */
- public $capturedamount;
-
- /**
- * @var string $authorizedamount -- Authorized amount
- */
- public $authorizedamount;
-
- /**
- * @var string $created -- Timestamp when transaction was created in Sveas' system, e.g. 2011-09-27 16:55:01.21
- */
- public $created;
-
- /**
- * @var string $creditstatus -- Status of the last credit attempt
- */
- public $creditstatus;
-
- /**
- * @var string $creditedamount -- Total amount that has been credited, in minor currency
- */
- public $creditedamount;
-
- /**
- * @var string $merchantresponsecode -- Last statuscode response returned to merchant
- */
- public $merchantresponsecode;
-
- /**
- * @var string $paymentMethod
- */
- public $paymentMethod;
-
- /**
- * @var NumberedOrderRow[] $numberedOrderRows array of NumberedOrderRows w/set Name, Description, ArticleNumber, AmountExVat, VatPercent, Quantity and Unit, rowNumber
- */
- public $numberedOrderRows;
-
- /**
- * @var string $callbackurl
- */
- public $callbackurl;
-
- /**
- * @var string $capturedate -- The date the transaction was captured, e.g. 2011-09-27 16:55:01.21
- */
- public $capturedate;
-
- /**
- * @var string $subscriptionId
- */
- public $subscriptionId;
-
- /**
- * @var string $subscriptiontype
- */
- public $subscriptiontype;
-
- /**
- * @var string $cardType
- */
- public $cardType;
-
- /**
- * @var string $maskedCardNumber
- */
- public $maskedCardNumber;
-
- /**
- * @var string $eci -- Enrollment status from MPI. If the card is 3Dsecure enabled or not.
- */
- public $eci;
-
- /**
- * @var string $mdstatus -- Value calculated from eci as requested by acquiring bank.
- */
- public $mdstatus;
-
- /**
- * @var string $expiryYear -- Expire year of the card
- */
- public $expiryYear;
-
- /**
- * @var string $expiryMonth -- Expire month of the month
- */
- public $expiryMonth;
-
- /**
- * @var string $chname -- Cardholder name as entered by cardholder
- */
- public $chname;
-
- /**
- * @var string $authCode -- EDB authorization code
- */
- public $authCode;
-
- /**
- * QueryTransactionResponse constructor.
- * @param \SimpleXMLElement $message
- * @param string $countryCode
- * @param \Svea\WebPay\Config\SveaConfigurationProvider $config
- */
- function __construct($message, $countryCode, $config)
- {
- parent::__construct($message, $countryCode, $config);
- }
-
- /**
- * formatXml() parses the query transaction response xml and sets the
- * response attributes accordingly.
- *
- * @param string $hostedAdminResponseXML hostedAdminResponse as xml
- */
- protected function formatXml($hostedAdminResponseXML)
- {
- $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
-
- if ((string)$hostedAdminResponse->statuscode == '0') {
- $this->accepted = 1;
- $this->resultcode = '0';
- } else {
- $this->accepted = 0;
- $this->setErrorParams((string)$hostedAdminResponse->statuscode);
- }
-
- //print_r( $hostedAdminResponse ); // uncomment to dump raw request response
-
- // queryTransaction
- if (property_exists($hostedAdminResponse->transaction, "customerrefno") && property_exists($hostedAdminResponse->transaction, "merchantid")) {
-
- $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
-
- $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno; // to confirm with HostedPaymentResponse
- $this->merchantId = (string)$hostedAdminResponse->transaction->merchantid;
- $this->status = (string)$hostedAdminResponse->transaction->status;
- $this->amount = (string)$hostedAdminResponse->transaction->amount;
- $this->currency = (string)$hostedAdminResponse->transaction->currency;
- $this->vat = (string)$hostedAdminResponse->transaction->vat;
- $this->capturedamount = (string)$hostedAdminResponse->transaction->capturedamount;
- $this->authorizedamount = (string)$hostedAdminResponse->transaction->authorizedamount;
- $this->created = (string)$hostedAdminResponse->transaction->created;
- $this->creditstatus = (string)$hostedAdminResponse->transaction->creditstatus;
- $this->creditedamount = (string)$hostedAdminResponse->transaction->creditedamount;
- $this->merchantresponsecode = (string)$hostedAdminResponse->transaction->merchantresponsecode;
- $this->paymentMethod = (string)$hostedAdminResponse->transaction->paymentmethod;
- $this->callbackurl = (string)$hostedAdminResponse->transaction->callbackurl;
- $this->capturedate = (string)$hostedAdminResponse->transaction->capturedate;
- $this->subscriptionId = (string)$hostedAdminResponse->transaction->subscriptionid;
- $this->subscriptiontype = (string)$hostedAdminResponse->transaction->subscriptiontype;
- $this->cardType = (string)$hostedAdminResponse->transaction->cardtype;
- $this->maskedCardNumber = (string)$hostedAdminResponse->transaction->maskedcardno;
- $this->eci = (string)$hostedAdminResponse->transaction->eci;
- $this->mdstatus = (string)$hostedAdminResponse->transaction->mdstatus;
- $this->expiryYear = (string)$hostedAdminResponse->transaction->expiryyear;
- $this->expiryMonth = (string)$hostedAdminResponse->transaction->expirymonth;
- $this->chname = (string)$hostedAdminResponse->transaction->chname;
- $this->authCode = (string)$hostedAdminResponse->transaction->authcode;
-
- //SimpleXMLElement Object
- //(
- // [transaction] => SimpleXMLElement Object
- // (
- // [@attributes] => Array
- // (
- // [id] => 581497
- // )
- //
- // [customerrefno] => test_recur_1
- // [merchantid] => 1130
- // [status] => SUCCESS
- // [amount] => 500
- // [currency] => SEK
- // [vat] => 100
- // [capturedamount] => 500
- // [authorizedamount] => 500
- // [created] => 2014-04-16 14:51:34.917
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentmethod] => KORTCERT
- // [callbackurl] => SimpleXMLElement Object
- // (
- // )
- //
- // [capturedate] => 2014-04-18 00:15:12.287
- // [subscriptionid] => 2922
- // [subscriptiontype] => RECURRINGCAPTURE
- // )
- //
- // [statuscode] => 0
- //)
-
- if (property_exists($hostedAdminResponse->transaction, "orderrows")) {
- $rownumber = 1;
- foreach ($hostedAdminResponse->transaction->orderrows->row as $orderrow) {
-
- $orderrow = (array)$orderrow;
- //queried orderrow:
- // [name]
- // [amount]
- // [vat]
- // [description]
- // [quantity]
- // [sku]
- // [unit]
-
- $newrow = new NumberedOrderRow(); // webpay orderrow
- //Svea\WebPay\WebPayItem OrderRow:
- // $articleNumber
- // $quantity
- // $unit
- // $amountExVat
- // $amountIncVat
- // $vatPercent
- // $name
- // $description
- // $discountPercent
- // $vatDiscount
-
- $newrow
- ->setName((string)$orderrow['name'])
- ->setAmountExVat(floatval(($orderrow['amount'] - $orderrow['vat'])) / 100)
- ->setAmountIncVat(floatval($orderrow['amount'])/100)
- ->setDescription((string)$orderrow['description'])
- ->setQuantity(floatval((string)$orderrow['quantity']))
- ->setArticleNumber((string)$orderrow['sku'])
- ->setUnit((string)$orderrow['unit'])
- ->setVatPercent($this->calculateVatPercentFromVatAndAmount($orderrow['vat'], $orderrow['amount']));
-
- $newrow->creditInvoiceId = null;
- $newrow->invoiceId = null;
- $newrow->rowNumber = $rownumber;
- $newrow->status = null;
-
- $rownumber += 1;
-
- $this->numberedOrderRows[] = $newrow;
- }
- }
- }
- }
-
- function calculateVatPercentFromVatAndAmount($vat, $amount)
- {
- $amountExVat = ($amount - $vat);
- $unroundedVatPercent = ($amountExVat != 0) ? ($vat / $amountExVat) : 0.00; // catch potential divide by zero
- $vatPercent = Helper::bround($unroundedVatPercent, 2) * 100; // OrderRow has vatpercent as int.
- return $vatPercent;
- }
+ /**
+ * @var string $transactionId -- the order id at Svea
+ */
+ public $transactionId;
+
+ /**
+ * @var string $clientOrderNumber -- the customer reference number, i.e. order number
+ */
+ public $clientOrderNumber;
+
+ /**
+ * @var string $merchantId -- the merchant id
+ */
+ public $merchantId;
+
+ /**
+ * @var string $status -- Latest transaction status, one of {AUTHORIZED, CONFIRMED, SUCCESS}
+ */
+ public $status;
+
+ /**
+ * @var string $amount -- Total amount including VAT, in minor currency (e.g. SEK 10.50 = 1050)
+ */
+ public $amount;
+
+ /**
+ * @var string $currency -- ISO 4217 alphabetic, e.g. SEK
+ */
+ public $currency;
+
+ /**
+ * @var string $vat -- VAT, in minor currency
+ */
+ public $vat;
+
+ /**
+ * @var string $capturedamount -- Captured amount
+ */
+ public $capturedamount;
+
+ /**
+ * @var string $authorizedamount -- Authorized amount
+ */
+ public $authorizedamount;
+
+ /**
+ * @var string $created -- Timestamp when transaction was created in Sveas' system, e.g. 2011-09-27 16:55:01.21
+ */
+ public $created;
+
+ /**
+ * @var string $creditstatus -- Status of the last credit attempt
+ */
+ public $creditstatus;
+
+ /**
+ * @var string $creditedamount -- Total amount that has been credited, in minor currency
+ */
+ public $creditedamount;
+
+ /**
+ * @var string $merchantresponsecode -- Last statuscode response returned to merchant
+ */
+ public $merchantresponsecode;
+
+ /**
+ * @var string $paymentMethod
+ */
+ public $paymentMethod;
+
+ /**
+ * @var NumberedOrderRow[] $numberedOrderRows array of NumberedOrderRows w/set Name, Description, ArticleNumber, AmountExVat, VatPercent, Quantity and Unit, rowNumber
+ */
+ public $numberedOrderRows;
+
+ /**
+ * @var string $callbackurl
+ */
+ public $callbackurl;
+
+ /**
+ * @var string $capturedate -- The date the transaction was captured, e.g. 2011-09-27 16:55:01.21
+ */
+ public $capturedate;
+
+ /**
+ * @var string $subscriptionId
+ */
+ public $subscriptionId;
+
+ /**
+ * @var string $subscriptiontype
+ */
+ public $subscriptiontype;
+
+ /**
+ * @var string $cardType
+ */
+ public $cardType;
+
+ /**
+ * @var string $maskedCardNumber
+ */
+ public $maskedCardNumber;
+
+ /**
+ * @var string $eci -- Enrollment status from MPI. If the card is 3Dsecure enabled or not.
+ */
+ public $eci;
+
+ /**
+ * @var string $mdstatus -- Value calculated from eci as requested by acquiring bank.
+ */
+ public $mdstatus;
+
+ /**
+ * @var string $expiryYear -- Expire year of the card
+ */
+ public $expiryYear;
+
+ /**
+ * @var string $expiryMonth -- Expire month of the month
+ */
+ public $expiryMonth;
+
+ /**
+ * @var string $chname -- Cardholder name as entered by cardholder
+ */
+ public $chname;
+
+ /**
+ * @var string $authCode -- EDB authorization code
+ */
+ public $authCode;
+
+ /**
+ * QueryTransactionResponse constructor.
+ * @param \SimpleXMLElement $message
+ * @param string $countryCode
+ * @param \Svea\WebPay\Config\SveaConfigurationProvider $config
+ */
+ function __construct($message, $countryCode, $config)
+ {
+ parent::__construct($message, $countryCode, $config);
+ }
+
+ /**
+ * formatXml() parses the query transaction response xml and sets the
+ * response attributes accordingly.
+ *
+ * @param string $hostedAdminResponseXML hostedAdminResponse as xml
+ */
+ protected function formatXml($hostedAdminResponseXML)
+ {
+ $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
+
+ if ((string)$hostedAdminResponse->statuscode == '0') {
+ $this->accepted = 1;
+ $this->resultcode = '0';
+ } else {
+ $this->accepted = 0;
+ $this->setErrorParams((string)$hostedAdminResponse->statuscode);
+ }
+
+ //print_r( $hostedAdminResponse ); // uncomment to dump raw request response
+
+ // queryTransaction
+ if (property_exists($hostedAdminResponse->transaction, "customerrefno") && property_exists($hostedAdminResponse->transaction, "merchantid")) {
+
+ $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
+
+ $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno; // to confirm with HostedPaymentResponse
+ $this->merchantId = (string)$hostedAdminResponse->transaction->merchantid;
+ $this->status = (string)$hostedAdminResponse->transaction->status;
+ $this->amount = (string)$hostedAdminResponse->transaction->amount;
+ $this->currency = (string)$hostedAdminResponse->transaction->currency;
+ $this->vat = (string)$hostedAdminResponse->transaction->vat;
+ $this->capturedamount = (string)$hostedAdminResponse->transaction->capturedamount;
+ $this->authorizedamount = (string)$hostedAdminResponse->transaction->authorizedamount;
+ $this->created = (string)$hostedAdminResponse->transaction->created;
+ $this->creditstatus = (string)$hostedAdminResponse->transaction->creditstatus;
+ $this->creditedamount = (string)$hostedAdminResponse->transaction->creditedamount;
+ $this->merchantresponsecode = (string)$hostedAdminResponse->transaction->merchantresponsecode;
+ $this->paymentMethod = (string)$hostedAdminResponse->transaction->paymentmethod;
+ $this->callbackurl = (string)$hostedAdminResponse->transaction->callbackurl;
+ $this->capturedate = (string)$hostedAdminResponse->transaction->capturedate;
+ $this->subscriptionId = (string)$hostedAdminResponse->transaction->subscriptionid;
+ $this->subscriptiontype = (string)$hostedAdminResponse->transaction->subscriptiontype;
+ $this->cardType = (string)$hostedAdminResponse->transaction->cardtype;
+ $this->maskedCardNumber = (string)$hostedAdminResponse->transaction->maskedcardno;
+ $this->eci = (string)$hostedAdminResponse->transaction->eci;
+ $this->mdstatus = (string)$hostedAdminResponse->transaction->mdstatus;
+ $this->expiryYear = (string)$hostedAdminResponse->transaction->expiryyear;
+ $this->expiryMonth = (string)$hostedAdminResponse->transaction->expirymonth;
+ $this->chname = (string)$hostedAdminResponse->transaction->chname;
+ $this->authCode = (string)$hostedAdminResponse->transaction->authcode;
+
+ //SimpleXMLElement Object
+ //(
+ // [transaction] => SimpleXMLElement Object
+ // (
+ // [@attributes] => Array
+ // (
+ // [id] => 581497
+ // )
+ //
+ // [customerrefno] => test_recur_1
+ // [merchantid] => 1130
+ // [status] => SUCCESS
+ // [amount] => 500
+ // [currency] => SEK
+ // [vat] => 100
+ // [capturedamount] => 500
+ // [authorizedamount] => 500
+ // [created] => 2014-04-16 14:51:34.917
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentmethod] => KORTCERT
+ // [callbackurl] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [capturedate] => 2014-04-18 00:15:12.287
+ // [subscriptionid] => 2922
+ // [subscriptiontype] => RECURRINGCAPTURE
+ // )
+ //
+ // [statuscode] => 0
+ //)
+
+ if (property_exists($hostedAdminResponse->transaction, "orderrows")) {
+ $rownumber = 1;
+ foreach ($hostedAdminResponse->transaction->orderrows->row as $orderrow) {
+
+ $orderrow = (array)$orderrow;
+ //queried orderrow:
+ // [name]
+ // [amount]
+ // [vat]
+ // [description]
+ // [quantity]
+ // [sku]
+ // [unit]
+
+ $newrow = new NumberedOrderRow(); // webpay orderrow
+ //Svea\WebPay\WebPayItem OrderRow:
+ // $articleNumber
+ // $quantity
+ // $unit
+ // $amountExVat
+ // $amountIncVat
+ // $vatPercent
+ // $name
+ // $description
+ // $discountPercent
+ // $vatDiscount
+
+ $newrow
+ ->setName((string)$orderrow['name'])
+ ->setAmountExVat(floatval(($orderrow['amount'] - $orderrow['vat'])) / 100)
+ ->setAmountIncVat(floatval($orderrow['amount'])/100)
+ ->setDescription((string)$orderrow['description'])
+ ->setQuantity(floatval((string)$orderrow['quantity']))
+ ->setArticleNumber((string)$orderrow['sku'])
+ ->setUnit((string)$orderrow['unit'])
+ ->setVatPercent($this->calculateVatPercentFromVatAndAmount($orderrow['vat'], $orderrow['amount']));
+
+ $newrow->creditInvoiceId = null;
+ $newrow->invoiceId = null;
+ $newrow->rowNumber = $rownumber;
+ $newrow->status = null;
+
+ $rownumber += 1;
+
+ $this->numberedOrderRows[] = $newrow;
+ }
+ }
+ }
+ }
+
+ function calculateVatPercentFromVatAndAmount($vat, $amount)
+ {
+ $amountExVat = ($amount - $vat);
+ $unroundedVatPercent = ($amountExVat != 0) ? ($vat / $amountExVat) : 0.00; // catch potential divide by zero
+ $vatPercent = Helper::bround($unroundedVatPercent, 2) * 100; // OrderRow has vatpercent as int.
+ return $vatPercent;
+ }
}
diff --git a/src/HostedService/HostedResponse/HostedAdminResponse/RecurTransactionResponse.php b/src/HostedService/HostedResponse/HostedAdminResponse/RecurTransactionResponse.php
index 680195e8..38bbdca7 100644
--- a/src/HostedService/HostedResponse/HostedAdminResponse/RecurTransactionResponse.php
+++ b/src/HostedService/HostedResponse/HostedAdminResponse/RecurTransactionResponse.php
@@ -11,109 +11,109 @@
*/
class RecurTransactionResponse extends HostedAdminResponse
{
- /**
- * @var string $transactionId -- the order id at Svea
- */
- public $transactionId;
-
- /**
- * @var string $clientOrderNumber -- the customer reference number, i.e. order number
- */
- public $clientOrderNumber;
-
- /**
- * @var string $paymentMethod
- */
- public $paymentMethod;
-
- /**
- * @var string $merchantId -- the merchant id
- */
- public $merchantId;
-
- /**
- * @var string $amount The total amount in minor currency (e.g. SEK 10.50 => 1050).
- */
- public $amount;
-
- /**
- * @var string $currency -- ISO 4217 alphabetic, e.g. SEK
- */
- public $currency;
-
- /**
- * @var string $cardType
- */
- public $cardType;
-
- /**
- * @var string $maskedCardNumber
- */
- public $maskedCardNumber;
-
- /**
- * @var string $expiryMonth -- Expire month of the month
- */
- public $expiryMonth;
-
- /**
- * @var string $expiryYear -- Expire year of the card
- */
- public $expiryYear;
-
- /**
- * @var string $authCode -- EDB authorization code
- */
- public $authCode;
-
- /**
- * @var string $subscriptionId
- */
- public $subscriptionId;
-
- /**
- * @var $decimalamount - The total amount including VAT, presented as a decimal number.
- */
- public $decimalamount;
-
-
- function __construct($message, $countryCode, $config)
- {
- parent::__construct($message, $countryCode, $config);
- }
-
- /**
- * formatXml() parses the recur transaction response xml into an object, and
- * then sets the response attributes accordingly.
- *
- * @param string $hostedAdminResponseXML hostedAdminResponse as xml
- */
- protected function formatXml($hostedAdminResponseXML)
- {
-
- $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
-
- if ((string)$hostedAdminResponse->statuscode == '0') {
- $this->accepted = 1;
- $this->resultcode = '0';
- } else {
- $this->accepted = 0;
- $this->setErrorParams((string)$hostedAdminResponse->statuscode);
- }
-
- $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
-
- $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno;
- $this->paymentMethod = (string)$hostedAdminResponse->transaction->paymentmethod;
- $this->merchantId = (string)$hostedAdminResponse->transaction->merchantid;
- $this->amount = (string)$hostedAdminResponse->transaction->amount;
- $this->currency = (string)$hostedAdminResponse->transaction->currency;
- $this->cardType = (string)$hostedAdminResponse->transaction->cardtype;
- $this->maskedCardNumber = (string)$hostedAdminResponse->transaction->maskedcardno;
- $this->expiryMonth = (string)$hostedAdminResponse->transaction->expirymonth;
- $this->expiryYear = (string)$hostedAdminResponse->transaction->expiryyear;
- $this->authCode = (string)$hostedAdminResponse->transaction->authcode;
- $this->subscriptionId = (string)$hostedAdminResponse->transaction->subscriptionid;
- $this->decimalamount = number_format(($hostedAdminResponse->transaction->amount * 0.01), 2, ".", "");
- }
+ /**
+ * @var string $transactionId -- the order id at Svea
+ */
+ public $transactionId;
+
+ /**
+ * @var string $clientOrderNumber -- the customer reference number, i.e. order number
+ */
+ public $clientOrderNumber;
+
+ /**
+ * @var string $paymentMethod
+ */
+ public $paymentMethod;
+
+ /**
+ * @var string $merchantId -- the merchant id
+ */
+ public $merchantId;
+
+ /**
+ * @var string $amount The total amount in minor currency (e.g. SEK 10.50 => 1050).
+ */
+ public $amount;
+
+ /**
+ * @var string $currency -- ISO 4217 alphabetic, e.g. SEK
+ */
+ public $currency;
+
+ /**
+ * @var string $cardType
+ */
+ public $cardType;
+
+ /**
+ * @var string $maskedCardNumber
+ */
+ public $maskedCardNumber;
+
+ /**
+ * @var string $expiryMonth -- Expire month of the month
+ */
+ public $expiryMonth;
+
+ /**
+ * @var string $expiryYear -- Expire year of the card
+ */
+ public $expiryYear;
+
+ /**
+ * @var string $authCode -- EDB authorization code
+ */
+ public $authCode;
+
+ /**
+ * @var string $subscriptionId
+ */
+ public $subscriptionId;
+
+ /**
+ * @var $decimalamount - The total amount including VAT, presented as a decimal number.
+ */
+ public $decimalamount;
+
+
+ function __construct($message, $countryCode, $config)
+ {
+ parent::__construct($message, $countryCode, $config);
+ }
+
+ /**
+ * formatXml() parses the recur transaction response xml into an object, and
+ * then sets the response attributes accordingly.
+ *
+ * @param string $hostedAdminResponseXML hostedAdminResponse as xml
+ */
+ protected function formatXml($hostedAdminResponseXML)
+ {
+
+ $hostedAdminResponse = new SimpleXMLElement($hostedAdminResponseXML);
+
+ if ((string)$hostedAdminResponse->statuscode == '0') {
+ $this->accepted = 1;
+ $this->resultcode = '0';
+ } else {
+ $this->accepted = 0;
+ $this->setErrorParams((string)$hostedAdminResponse->statuscode);
+ }
+
+ $this->transactionId = (string)$hostedAdminResponse->transaction['id'];
+
+ $this->clientOrderNumber = (string)$hostedAdminResponse->transaction->customerrefno;
+ $this->paymentMethod = (string)$hostedAdminResponse->transaction->paymentmethod;
+ $this->merchantId = (string)$hostedAdminResponse->transaction->merchantid;
+ $this->amount = (string)$hostedAdminResponse->transaction->amount;
+ $this->currency = (string)$hostedAdminResponse->transaction->currency;
+ $this->cardType = (string)$hostedAdminResponse->transaction->cardtype;
+ $this->maskedCardNumber = (string)$hostedAdminResponse->transaction->maskedcardno;
+ $this->expiryMonth = (string)$hostedAdminResponse->transaction->expirymonth;
+ $this->expiryYear = (string)$hostedAdminResponse->transaction->expiryyear;
+ $this->authCode = (string)$hostedAdminResponse->transaction->authcode;
+ $this->subscriptionId = (string)$hostedAdminResponse->transaction->subscriptionid;
+ $this->decimalamount = number_format(($hostedAdminResponse->transaction->amount * 0.01), 2, ".", "");
+ }
}
diff --git a/src/HostedService/HostedResponse/HostedPaymentResponse.php b/src/HostedService/HostedResponse/HostedPaymentResponse.php
index 9531937d..86b1d6a6 100644
--- a/src/HostedService/HostedResponse/HostedPaymentResponse.php
+++ b/src/HostedService/HostedResponse/HostedPaymentResponse.php
@@ -10,113 +10,113 @@
*/
class HostedPaymentResponse extends HostedResponse
{
- /**
- * @var string $transactionId -- the order id at Svea
- */
- public $transactionId;
+ /**
+ * @var string $transactionId -- the order id at Svea
+ */
+ public $transactionId;
- /**
- * @var string $clientOrderNumber -- the customer reference number, i.e. order number
- */
- public $clientOrderNumber;
+ /**
+ * @var string $clientOrderNumber -- the customer reference number, i.e. order number
+ */
+ public $clientOrderNumber;
- /**
- * @var string $paymentMethod
- */
- public $paymentMethod;
+ /**
+ * @var string $paymentMethod
+ */
+ public $paymentMethod;
- /**
- * @var string $merchantId -- the merchant id
- */
- public $merchantId;
+ /**
+ * @var string $merchantId -- the merchant id
+ */
+ public $merchantId;
- /**
- * @var string $amount The total amount including VAT, presented as a decimal number
- */
- public $amount; // TODO java: Double
+ /**
+ * @var string $amount The total amount including VAT, presented as a decimal number
+ */
+ public $amount; // TODO java: Double
- /**
- * @var string $currency -- ISO 4217 alphabetic, e.g. SEK
- */
- public $currency;
+ /**
+ * @var string $currency -- ISO 4217 alphabetic, e.g. SEK
+ */
+ public $currency;
- /**
- * HostedPaymentResponse validates the hosted payment response.
- *
- * For successful payment requests it sets the accepted attribute to 1 and
- * other response attributes accordingly.
- *
- * In case of a response error, it sets the the accepted attribute to 0 and
- * the resultcode to 0. For responses indicating that something went wrong
- * at the service, it sets accepted to 0 and responsecode with corresponding
- * errormessage accordingly.
- *
- * @param string $response hosted request response xml message
- * @param string $countryCode two-letter country code
- * @param ConfigurationProvider $config
- */
- function __construct($response, $countryCode, $config)
- {
- if (is_array($response)) {
- if (array_key_exists("mac", $response)) {
- if (array_key_exists("response", $response)) {
- $decodedXml = base64_decode($response["response"]);
- $secret = $config->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- if ($this->validateMac($response["response"], $response['mac'], $secret)) {
- $this->formatXml($decodedXml);
- } else {
- $this->accepted = 0;
- $this->resultcode = '0';
- $this->errormessage = "Response failed authorization. MAC not valid.";
- }
- } else {
- $this->accepted = 0;
- $this->resultcode = '0';
- $this->errormessage = "Response is not recognized.";
+ /**
+ * HostedPaymentResponse validates the hosted payment response.
+ *
+ * For successful payment requests it sets the accepted attribute to 1 and
+ * other response attributes accordingly.
+ *
+ * In case of a response error, it sets the the accepted attribute to 0 and
+ * the resultcode to 0. For responses indicating that something went wrong
+ * at the service, it sets accepted to 0 and responsecode with corresponding
+ * errormessage accordingly.
+ *
+ * @param string $response hosted request response xml message
+ * @param string $countryCode two-letter country code
+ * @param ConfigurationProvider $config
+ */
+ function __construct($response, $countryCode, $config)
+ {
+ if (is_array($response)) {
+ if (array_key_exists("mac", $response)) {
+ if (array_key_exists("response", $response)) {
+ $decodedXml = base64_decode($response["response"]);
+ $secret = $config->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ if ($this->validateMac($response["response"], $response['mac'], $secret)) {
+ $this->formatXml($decodedXml);
+ } else {
+ $this->accepted = 0;
+ $this->resultcode = '0';
+ $this->errormessage = "Response failed authorization. MAC not valid.";
+ }
+ } else {
+ $this->accepted = 0;
+ $this->resultcode = '0';
+ $this->errormessage = "Response is not recognized.";
- }
- } else {
- $this->accepted = 0;
- $this->resultcode = '0';
- $this->errormessage = "Response is not recognized.";
- }
- } else {
- $this->accepted = 0;
- $this->resultcode = '0';
- $this->errormessage = "Response is not recognized.";
- }
- }
+ }
+ } else {
+ $this->accepted = 0;
+ $this->resultcode = '0';
+ $this->errormessage = "Response is not recognized.";
+ }
+ } else {
+ $this->accepted = 0;
+ $this->resultcode = '0';
+ $this->errormessage = "Response is not recognized.";
+ }
+ }
- protected function formatXml($xml)
- {
- $xmlElement = new SimpleXMLElement($xml);
+ protected function formatXml($xml)
+ {
+ $xmlElement = new SimpleXMLElement($xml);
- // we set accepted iff xml statuscode is 0;
- if ((string)$xmlElement->statuscode == 0) {
- $this->accepted = 1;
- } else {
- $this->accepted = 0;
- $this->setErrorParams($xmlElement->statuscode);
- }
+ // we set accepted iff xml statuscode is 0;
+ if ((string)$xmlElement->statuscode == 0) {
+ $this->accepted = 1;
+ } else {
+ $this->accepted = 0;
+ $this->setErrorParams($xmlElement->statuscode);
+ }
- $this->transactionId = (string)$xmlElement->transaction['id'];
- $this->paymentMethod = (string)$xmlElement->transaction->paymentmethod;
- $this->merchantId = (string)$xmlElement->transaction->merchantid;
- $this->clientOrderNumber = (string)$xmlElement->transaction->customerrefno;
- $minorAmount = (int)($xmlElement->transaction->amount);
- $this->amount = number_format(($minorAmount * 0.01), 2, ".", "");
- $this->currency = (string)$xmlElement->transaction->currency;
+ $this->transactionId = (string)$xmlElement->transaction['id'];
+ $this->paymentMethod = (string)$xmlElement->transaction->paymentmethod;
+ $this->merchantId = (string)$xmlElement->transaction->merchantid;
+ $this->clientOrderNumber = (string)$xmlElement->transaction->customerrefno;
+ $minorAmount = (int)($xmlElement->transaction->amount);
+ $this->amount = number_format(($minorAmount * 0.01), 2, ".", "");
+ $this->currency = (string)$xmlElement->transaction->currency;
- if (property_exists($xmlElement->transaction, "subscriptionid")) {
- $this->subscriptionId = (string)$xmlElement->transaction->subscriptionid;
- }
+ if (property_exists($xmlElement->transaction, "subscriptionid")) {
+ $this->subscriptionId = (string)$xmlElement->transaction->subscriptionid;
+ }
- if (property_exists($xmlElement->transaction, "cardtype")) {
- $this->cardType = (string)$xmlElement->transaction->cardtype;
- $this->maskedCardNumber = (string)$xmlElement->transaction->maskedcardno;
- $this->expiryMonth = (string)$xmlElement->transaction->expirymonth;
- $this->expiryYear = (string)$xmlElement->transaction->expiryyear;
- $this->authCode = (string)$xmlElement->transaction->authcode;
- }
- }
+ if (property_exists($xmlElement->transaction, "cardtype")) {
+ $this->cardType = (string)$xmlElement->transaction->cardtype;
+ $this->maskedCardNumber = (string)$xmlElement->transaction->maskedcardno;
+ $this->expiryMonth = (string)$xmlElement->transaction->expirymonth;
+ $this->expiryYear = (string)$xmlElement->transaction->expiryyear;
+ $this->authCode = (string)$xmlElement->transaction->authcode;
+ }
+ }
}
diff --git a/src/HostedService/HostedResponse/HostedResponse.php b/src/HostedService/HostedResponse/HostedResponse.php
index fea3eb68..72855751 100644
--- a/src/HostedService/HostedResponse/HostedResponse.php
+++ b/src/HostedService/HostedResponse/HostedResponse.php
@@ -8,405 +8,405 @@
class HostedResponse
{
- /**
- * @var int $accepted Set to 1 iff transaction was accepted by Svea. A value of 0 may indicate that the request failed, see $resultcode.
- */
- public $accepted;
+ /**
+ * @var int $accepted Set to 1 iff transaction was accepted by Svea. A value of 0 may indicate that the request failed, see $resultcode.
+ */
+ public $accepted;
- /**
- * @var string $resultcode A value >0 indicates that the service request failed at Svea, see $errormessage. 0 indicates a malformed message.
- */
- public $resultcode;
+ /**
+ * @var string $resultcode A value >0 indicates that the service request failed at Svea, see $errormessage. 0 indicates a malformed message.
+ */
+ public $resultcode;
- /**
- * @var string $errormessage Human readable explanation of the service resultcode.
- */
- public $errormessage;
+ /**
+ * @var string $errormessage Human readable explanation of the service resultcode.
+ */
+ public $errormessage;
- /**
- * Validates that the received mac can be reconstructed from the message and
- * the shared secret.
- *
- * @param string $messageEncoded
- * @param string $mac
- * @param string $secret
- * @return boolean true iff the mac can be validated
- */
- public function validateMac($messageEncoded, $mac, $secret)
- {
+ /**
+ * Validates that the received mac can be reconstructed from the message and
+ * the shared secret.
+ *
+ * @param string $messageEncoded
+ * @param string $mac
+ * @param string $secret
+ * @return boolean true iff the mac can be validated
+ */
+ public function validateMac($messageEncoded, $mac, $secret)
+ {
- $macKey = hash("sha512", $messageEncoded . $secret);
+ $macKey = hash("sha512", $messageEncoded . $secret);
- if ($mac == $macKey) {
- return TRUE;
- }
+ if ($mac == $macKey) {
+ return TRUE;
+ }
- return FALSE;
- }
+ return FALSE;
+ }
- protected function setErrorParams($resultcode)
- {
- switch ($resultcode) {
+ protected function setErrorParams($resultcode)
+ {
+ switch ($resultcode) {
- case '1':
- $this->resultcode = $resultcode . ' (REQUIRES_MANUAL_REVIEW)';
- $this->errormessage = 'Request performed successfully but requires manual review from merchant. Applicable paymentmethods: PAYPAL.';
- break;
+ case '1':
+ $this->resultcode = $resultcode . ' (REQUIRES_MANUAL_REVIEW)';
+ $this->errormessage = 'Request performed successfully but requires manual review from merchant. Applicable paymentmethods: PAYPAL.';
+ break;
- case '100':
- $this->resultcode = $resultcode . ' (INTERNAL_ERROR)';
- $this->errormessage = 'Invalid – contact integrator.';
- break;
- case '101':
- $this->resultcode = $resultcode . ' (XMLPARSEFAIL)';
- $this->errormessage = 'Invalid XML.';
- break;
- case '102':
- $this->resultcode = $resultcode . ' (ILLEGAL_ENCODING)';
- $this->errormessage = 'Invalid encoding.';
- break;
- case '104':
- $this->resultcode = $resultcode . ' (ILLEGAL_URL)';
- $this->errormessage = 'Illegal Url.';
- break;
- case '105':
- $this->resultcode = $resultcode . ' (ILLEGAL_TRANSACTIONSTATUS)';
- $this->errormessage = 'Invalid transaction status.';
- break;
- case '106':
- $this->resultcode = $resultcode . ' (EXTERNAL_ERROR)';
- $this->errormessage = 'Failure at third party e.g. failure at the bank.';
- break;
- case '107':
- $this->resultcode = $resultcode . ' (DENIED_BY_BANK)';
- $this->errormessage = 'Transaction rejected by bank.';
- break;
- case '108':
- $this->resultcode = $resultcode . ' (CANCELLED)';
- $this->errormessage = 'Transaction cancelled.';
- break;
- case '109':
- $this->resultcode = $resultcode . ' (NOT_FOUND_AT_BANK)';
- $this->errormessage = 'Transaction not found at the bank.';
- break;
- case '110':
- $this->resultcode = $resultcode . ' (ILLEGAL_TRANSACTIONID)';
- $this->errormessage = 'Invalid transaction ID.';
- break;
- case '111':
- $this->resultcode = $resultcode . ' (MERCHANT_NOT_CONFIGURED)';
- $this->errormessage = 'Merchant not configured.';
- break;
- case '112':
- $this->resultcode = $resultcode . ' (MERCHANT_NOT_CONFIGURED_AT_BANK)';
- $this->errormessage = 'Merchant not configured at the bank.';
- break;
- case '113':
- $this->resultcode = $resultcode . ' (PAYMENTMETHOD_NOT_CONFIGURED)';
- $this->errormessage = 'Payment method not configured for merchant.';
- break;
- case '114':
- $this->resultcode = $resultcode . ' (TIMEOUT_AT_BANK)';
- $this->errormessage = 'Timeout at the bank.';
- break;
- case '115':
- $this->resultcode = $resultcode . ' (MERCHANT_NOT_ACTIVE)';
- $this->errormessage = 'The merchant is disabled.';
- break;
- case '116':
- $this->resultcode = $resultcode . ' (PAYMENTMETHOD_NOT_ACTIVE)';
- $this->errormessage = 'The payment method is disabled.';
- break;
- case '117':
- $this->resultcode = $resultcode . ' (ILLEGAL_AUTHORIZED_AMOUNT)';
- $this->errormessage = 'Invalid authorized amount.';
- break;
- case '118':
- $this->resultcode = $resultcode . ' (ILLEGAL_CAPTURED_AMOUNT)';
- $this->errormessage = 'Invalid captured amount.';
- break;
- case '119':
- $this->resultcode = $resultcode . ' (ILLEGAL_CREDITED_AMOUNT)';
- $this->errormessage = 'Invalid credited amount.';
- break;
- case '120':
- $this->resultcode = $resultcode . ' (NOT_SUFFICIENT_FUNDS)';
- $this->errormessage = 'Not enough founds.';
- break;
- case '121':
- $this->resultcode = $resultcode . ' (EXPIRED_CARD)';
- $this->errormessage = 'The card has expired.';
- break;
- case '122':
- $this->resultcode = $resultcode . ' (STOLEN_CARD)';
- $this->errormessage = 'Stolen card.';
- break;
- case '123':
- $this->resultcode = $resultcode . ' (LOST_CARD)';
- $this->errormessage = 'Lost card.';
- break;
- case '124':
- $this->resultcode = $resultcode . ' (EXCEEDS_AMOUNT_LIMIT)';
- $this->errormessage = 'Amount exceeds the limit.';
- break;
- case '125':
- $this->resultcode = $resultcode . ' (EXCEEDS_FREQUENCY_LIMIT)';
- $this->errormessage = 'Frequency limit exceeded.';
- break;
- case '126':
- $this->resultcode = $resultcode . ' (TRANSACTION_NOT_BELONGING_TO_MERCHANT)';
- $this->errormessage = 'Transaction does not belong to merchant).';
- break;
- case '127':
- $this->resultcode = $resultcode . ' (CUSTOMERREFNO_ALREADY_USED)';
- $this->errormessage = 'Customer reference number already used in another transaction.';
- break;
- case '128':
- $this->resultcode = $resultcode . ' (NO_SUCH_TRANS)';
- $this->errormessage = 'Transaction does not exist.';
- break;
- case '129':
- $this->resultcode = $resultcode . ' (DUPLICATE_TRANSACTION)';
- $this->errormessage = 'More than one transaction found for the given customer reference number.';
- break;
- case '130':
- $this->resultcode = $resultcode . ' (ILLEGAL_OPERATION)';
- $this->errormessage = 'Operation not allowed for the given payment method.';
- break;
- case '131':
- $this->resultcode = $resultcode . ' (COMPANY_NOT_ACTIVE)';
- $this->errormessage = 'Company inactive.';
- break;
- case '132':
- $this->resultcode = $resultcode . ' (SUBSCRIPTION_NOT_FOUND)';
- $this->errormessage = 'No subscription exist.';
- break;
- case '133':
- $this->resultcode = $resultcode . ' (SUBSCRIPTION_NOT_ACTIVE)';
- $this->errormessage = 'Subscription not active.';
- break;
- case '134':
- $this->resultcode = $resultcode . ' (SUBSCRIPTION_NOT_SUPPORTED)';
- $this->errormessage = 'Payment method doesn’t support subscriptions.';
- break;
- case '135':
- $this->resultcode = $resultcode . ' (ILLEGAL_DATE_FORMAT)';
- $this->errormessage = 'Illegal date format.';
- break;
- case '136':
- $this->resultcode = $resultcode . ' (ILLEGAL_RESPONSE_DATA)';
- $this->errormessage = 'Illegal response data.';
- break;
- case '137':
- $this->resultcode = $resultcode . ' (IGNORE_CALLBACK)';
- $this->errormessage = 'Ignore callback.';
- break;
- case '138':
- $this->resultcode = $resultcode . ' (CURRENCY_NOT_CONFIGURED)';
- $this->errormessage = 'Currency not configured.';
- break;
- case '139':
- $this->resultcode = $resultcode . ' (CURRENCY_NOT_ACTIVE)';
- $this->errormessage = 'Currency not active.';
- break;
- case '140':
- $this->resultcode = $resultcode . ' (CURRENCY_ALREADY_CONFIGURED)';
- $this->errormessage = 'Currency is already configured.';
- break;
- case '141':
- $this->resultcode = $resultcode . ' (ILLEGAL_AMOUNT_OF_RECURS_TODAY)';
- $this->errormessage = 'Ilegal amount of recurs per day.';
- break;
- case '142':
- $this->resultcode = $resultcode . ' (NO_VALID_PAYMENT_METHODS)';
- $this->errormessage = 'No valid paymentmethods.';
- break;
- case '143':
- $this->resultcode = $resultcode . ' (CREDIT_DENIED_BY_BANK)';
- $this->errormessage = 'Credit denied by bank.';
- break;
- case '144':
- $this->resultcode = $resultcode . ' (ILLEGAL_CREDIT_USER)';
- $this->errormessage = 'User is not allowed to perform credit operation.';
- break;
- case '146':
- $this->resultcode = $resultcode . ' (CUSTOMER_NOT_FOUND)';
- $this->errormessage = 'Customer is not enrolled for Swish or if another payment method was used the address lookup returned no results.';
- break;
- case '300':
- $this->resultcode = $resultcode . ' (BAD_CARDHOLDER_NAME)';
- $this->errormessage = 'Invalid value for cardholder name.';
- break;
- case '301':
- $this->resultcode = $resultcode . ' (BAD_TRANSACTION_ID)';
- $this->errormessage = 'Invalid value for transaction id.';
- break;
- case '302':
- $this->resultcode = $resultcode . ' (BAD_REV)';
- $this->errormessage = 'Invalid value for rev.';
- break;
- case '303':
- $this->resultcode = $resultcode . ' (BAD_MERCHANT_ID)';
- $this->errormessage = 'Invalid value for merchant id.';
- break;
- case '304':
- $this->resultcode = $resultcode . ' (BAD_LANG)';
- $this->errormessage = 'Invalid value for lang.';
- break;
- case '305':
- $this->resultcode = $resultcode . ' (BAD_AMOUNT)';
- $this->errormessage = 'Invalid value for amount.';
- break;
- case '306':
- $this->resultcode = $resultcode . ' (BAD_CUSTOMERREFNO)';
- $this->errormessage = 'Invalid value for customer refno 307.';
- break;
- case '307':
- $this->resultcode = $resultcode . ' (BAD_CURRENCY)';
- $this->errormessage = 'Invalid value for currency.';
- break;
- case '308':
- $this->resultcode = $resultcode . ' (BAD_PAYMENTMETHOD)';
- $this->errormessage = 'Invalid value for payment method.';
- break;
- case '309':
- $this->resultcode = $resultcode . ' (BAD_RETURNURL)';
- $this->errormessage = 'Invalid value for return url.';
- break;
- case '310':
- $this->resultcode = $resultcode . ' (BAD_LASTBOOKINGDAY)';
- $this->errormessage = 'Invalid value for last booking day.';
- break;
- case '311':
- $this->resultcode = $resultcode . ' (BAD_MAC)';
- $this->errormessage = 'Invalid value for mac.';
- break;
- case '312':
- $this->resultcode = $resultcode . ' (BAD_TRNUMBER)';
- $this->errormessage = 'Invalid value for tr number.';
- break;
- case '313':
- $this->resultcode = $resultcode . ' (BAD_AUTHCODE)';
- $this->errormessage = 'Invalid value for authcode.';
- break;
- case '314':
- $this->resultcode = $resultcode . ' (BAD_CC_DESCR)';
- $this->errormessage = 'Invalid value for cc_descr.';
- break;
- case '315':
- $this->resultcode = $resultcode . ' (BAD_ERROR_CODE)';
- $this->errormessage = 'Invalid value for error_code.';
- break;
- case '316':
- $this->resultcode = $resultcode . ' (BAD_CARDNUMBER_OR_CARDTYPE_NOT_CONFIGURED)';
- $this->errormessage = 'Card type not configured for merchant.';
- break;
- case '317':
- $this->resultcode = $resultcode . ' (BAD_SSN)';
- $this->errormessage = 'Invalid value for ssn.';
- break;
- case '318':
- $this->resultcode = $resultcode . ' (BAD_VAT)';
- $this->errormessage = 'Invalid value for vat.';
- break;
- case '319':
- $this->resultcode = $resultcode . ' (BAD_CAPTURE_DATE)';
- $this->errormessage = 'Invalid value for capture date.';
- break;
- case '320':
- $this->resultcode = $resultcode . ' (BAD_CAMPAIGN_CODE_INVALID)';
- $this->errormessage = 'Invalid value for campaign code. There are no valid matching campaign codes.';
- break;
- case '321':
- $this->resultcode = $resultcode . ' (BAD_SUBSCRIPTION_TYPE)';
- $this->errormessage = 'Invalid subscription type.';
- break;
- case '322':
- $this->resultcode = $resultcode . ' (BAD_SUBSCRIPTION_ID)';
- $this->errormessage = 'Invalid subscription id.';
- break;
- case '323':
- $this->resultcode = $resultcode . ' (BAD_BASE64)';
- $this->errormessage = 'Invalid base64.';
- break;
- case '324':
- $this->resultcode = $resultcode . ' (BAD_CAMPAIGN_CODE)';
- $this->errormessage = 'Invalid campaign code. Missing value.';
- break;
- case '325':
- $this->resultcode = $resultcode . ' (BAD_CALLBACKURL)';
- $this->errormessage = 'Invalid callbackurl.';
- break;
- case '326':
- $this->resultcode = $resultcode . ' (THREE_D_CHECK_FAILED)';
- $this->errormessage = '3D check failed.';
- break;
- case '327':
- $this->resultcode = $resultcode . ' (CARD_NOT_ENROLLED)';
- $this->errormessage = 'Card not enrolled in 3D secure.';
- break;
- case '328':
- $this->resultcode = $resultcode . ' (BAD_IPADDRESS)';
- $this->errormessage = 'Provided ip address is incorrect.';
- break;
- case '329':
- $this->resultcode = $resultcode . ' (BAD_MOBILE)';
- $this->errormessage = 'Bad mobile phone number.';
- break;
- case '330':
- $this->resultcode = $resultcode . ' (BAD_COUNTRY)';
- $this->errormessage = 'Bad country parameter.';
- break;
- case '331':
- $this->resultcode = $resultcode . ' (THREE_D_CHECK_NOT_AVAILABLE)';
- $this->errormessage = 'Merchants 3D configuration invalid.';
- break;
- case '332':
- $this->resultcode = $resultcode . ' (TIMEOUT)';
- $this->errormessage = 'Timeout at Svea.';
- break;
- case '342':
- $this->resultcode = $resultcode . ' (TRANSACTION_ALREADY_IN_PROGRESS)';
- $this->errormessage = 'There is currently another transaction in progress on this payer alias.';
- break;
- case '500':
- $this->resultcode = $resultcode . ' (ANTIFRAUD_CARDBIN_NOT_ALLOWED)';
- $this->errormessage = 'Antifraud - cardbin not allowed.';
- break;
- case '501':
- $this->resultcode = $resultcode . ' (ANTIFRAUD_IPLOCATION_NOT_ALLOWED)';
- $this->errormessage = 'Antifraud – iplocation not allowed.';
- break;
- case '502':
- $this->resultcode = $resultcode . ' (ANTIFRAUD_IPLOCATION_AND_BIN_DOESNT_MATCH)';
- $this->errormessage = 'Antifraud – ip-location and bin does not match.';
- break;
- case '503':
- $this->resultcode = $resultcode . ' (ANTIFRAUD_MAX_AMOUNT_PER_IP_EXCEEDED)';
- $this->errormessage = 'Antofraud – max amount per ip exceeded.';
- break;
- case '504':
- $this->resultcode = $resultcode . ' (ANTIFRAUD_MAX_TRANSACTIONS_PER_IP_EXCEEDED)';
- $this->errormessage = 'Antifraud – max transactions per ip exceeded.';
- break;
- case '505':
- $this->resultcode = $resultcode . ' (ANTIFRAUD_MAX_TRANSACTIONS_PER_CARDNO_EXCEEDED)';
- $this->errormessage = 'Antifraud – max transactions per card number exceeded.';
- break;
- case '506':
- $this->resultcode = $resultcode . ' (ANTIFRAUD_MAX_AMOUNT_PER_CARDNO_EXCEEDED)';
- $this->errormessage = 'Antifraud – max amount per cardnumer exceeded.';
- break;
- case '507':
- $this->resultcode = $resultcode . ' (ANTIFRAUD_IP_ADDRESS_BLOCKED)';
- $this->errormessage = 'Antifraud – IP address blocked.';
- break;
+ case '100':
+ $this->resultcode = $resultcode . ' (INTERNAL_ERROR)';
+ $this->errormessage = 'Invalid – contact integrator.';
+ break;
+ case '101':
+ $this->resultcode = $resultcode . ' (XMLPARSEFAIL)';
+ $this->errormessage = 'Invalid XML.';
+ break;
+ case '102':
+ $this->resultcode = $resultcode . ' (ILLEGAL_ENCODING)';
+ $this->errormessage = 'Invalid encoding.';
+ break;
+ case '104':
+ $this->resultcode = $resultcode . ' (ILLEGAL_URL)';
+ $this->errormessage = 'Illegal Url.';
+ break;
+ case '105':
+ $this->resultcode = $resultcode . ' (ILLEGAL_TRANSACTIONSTATUS)';
+ $this->errormessage = 'Invalid transaction status.';
+ break;
+ case '106':
+ $this->resultcode = $resultcode . ' (EXTERNAL_ERROR)';
+ $this->errormessage = 'Failure at third party e.g. failure at the bank.';
+ break;
+ case '107':
+ $this->resultcode = $resultcode . ' (DENIED_BY_BANK)';
+ $this->errormessage = 'Transaction rejected by bank.';
+ break;
+ case '108':
+ $this->resultcode = $resultcode . ' (CANCELLED)';
+ $this->errormessage = 'Transaction cancelled.';
+ break;
+ case '109':
+ $this->resultcode = $resultcode . ' (NOT_FOUND_AT_BANK)';
+ $this->errormessage = 'Transaction not found at the bank.';
+ break;
+ case '110':
+ $this->resultcode = $resultcode . ' (ILLEGAL_TRANSACTIONID)';
+ $this->errormessage = 'Invalid transaction ID.';
+ break;
+ case '111':
+ $this->resultcode = $resultcode . ' (MERCHANT_NOT_CONFIGURED)';
+ $this->errormessage = 'Merchant not configured.';
+ break;
+ case '112':
+ $this->resultcode = $resultcode . ' (MERCHANT_NOT_CONFIGURED_AT_BANK)';
+ $this->errormessage = 'Merchant not configured at the bank.';
+ break;
+ case '113':
+ $this->resultcode = $resultcode . ' (PAYMENTMETHOD_NOT_CONFIGURED)';
+ $this->errormessage = 'Payment method not configured for merchant.';
+ break;
+ case '114':
+ $this->resultcode = $resultcode . ' (TIMEOUT_AT_BANK)';
+ $this->errormessage = 'Timeout at the bank.';
+ break;
+ case '115':
+ $this->resultcode = $resultcode . ' (MERCHANT_NOT_ACTIVE)';
+ $this->errormessage = 'The merchant is disabled.';
+ break;
+ case '116':
+ $this->resultcode = $resultcode . ' (PAYMENTMETHOD_NOT_ACTIVE)';
+ $this->errormessage = 'The payment method is disabled.';
+ break;
+ case '117':
+ $this->resultcode = $resultcode . ' (ILLEGAL_AUTHORIZED_AMOUNT)';
+ $this->errormessage = 'Invalid authorized amount.';
+ break;
+ case '118':
+ $this->resultcode = $resultcode . ' (ILLEGAL_CAPTURED_AMOUNT)';
+ $this->errormessage = 'Invalid captured amount.';
+ break;
+ case '119':
+ $this->resultcode = $resultcode . ' (ILLEGAL_CREDITED_AMOUNT)';
+ $this->errormessage = 'Invalid credited amount.';
+ break;
+ case '120':
+ $this->resultcode = $resultcode . ' (NOT_SUFFICIENT_FUNDS)';
+ $this->errormessage = 'Not enough founds.';
+ break;
+ case '121':
+ $this->resultcode = $resultcode . ' (EXPIRED_CARD)';
+ $this->errormessage = 'The card has expired.';
+ break;
+ case '122':
+ $this->resultcode = $resultcode . ' (STOLEN_CARD)';
+ $this->errormessage = 'Stolen card.';
+ break;
+ case '123':
+ $this->resultcode = $resultcode . ' (LOST_CARD)';
+ $this->errormessage = 'Lost card.';
+ break;
+ case '124':
+ $this->resultcode = $resultcode . ' (EXCEEDS_AMOUNT_LIMIT)';
+ $this->errormessage = 'Amount exceeds the limit.';
+ break;
+ case '125':
+ $this->resultcode = $resultcode . ' (EXCEEDS_FREQUENCY_LIMIT)';
+ $this->errormessage = 'Frequency limit exceeded.';
+ break;
+ case '126':
+ $this->resultcode = $resultcode . ' (TRANSACTION_NOT_BELONGING_TO_MERCHANT)';
+ $this->errormessage = 'Transaction does not belong to merchant).';
+ break;
+ case '127':
+ $this->resultcode = $resultcode . ' (CUSTOMERREFNO_ALREADY_USED)';
+ $this->errormessage = 'Customer reference number already used in another transaction.';
+ break;
+ case '128':
+ $this->resultcode = $resultcode . ' (NO_SUCH_TRANS)';
+ $this->errormessage = 'Transaction does not exist.';
+ break;
+ case '129':
+ $this->resultcode = $resultcode . ' (DUPLICATE_TRANSACTION)';
+ $this->errormessage = 'More than one transaction found for the given customer reference number.';
+ break;
+ case '130':
+ $this->resultcode = $resultcode . ' (ILLEGAL_OPERATION)';
+ $this->errormessage = 'Operation not allowed for the given payment method.';
+ break;
+ case '131':
+ $this->resultcode = $resultcode . ' (COMPANY_NOT_ACTIVE)';
+ $this->errormessage = 'Company inactive.';
+ break;
+ case '132':
+ $this->resultcode = $resultcode . ' (SUBSCRIPTION_NOT_FOUND)';
+ $this->errormessage = 'No subscription exist.';
+ break;
+ case '133':
+ $this->resultcode = $resultcode . ' (SUBSCRIPTION_NOT_ACTIVE)';
+ $this->errormessage = 'Subscription not active.';
+ break;
+ case '134':
+ $this->resultcode = $resultcode . ' (SUBSCRIPTION_NOT_SUPPORTED)';
+ $this->errormessage = 'Payment method doesn’t support subscriptions.';
+ break;
+ case '135':
+ $this->resultcode = $resultcode . ' (ILLEGAL_DATE_FORMAT)';
+ $this->errormessage = 'Illegal date format.';
+ break;
+ case '136':
+ $this->resultcode = $resultcode . ' (ILLEGAL_RESPONSE_DATA)';
+ $this->errormessage = 'Illegal response data.';
+ break;
+ case '137':
+ $this->resultcode = $resultcode . ' (IGNORE_CALLBACK)';
+ $this->errormessage = 'Ignore callback.';
+ break;
+ case '138':
+ $this->resultcode = $resultcode . ' (CURRENCY_NOT_CONFIGURED)';
+ $this->errormessage = 'Currency not configured.';
+ break;
+ case '139':
+ $this->resultcode = $resultcode . ' (CURRENCY_NOT_ACTIVE)';
+ $this->errormessage = 'Currency not active.';
+ break;
+ case '140':
+ $this->resultcode = $resultcode . ' (CURRENCY_ALREADY_CONFIGURED)';
+ $this->errormessage = 'Currency is already configured.';
+ break;
+ case '141':
+ $this->resultcode = $resultcode . ' (ILLEGAL_AMOUNT_OF_RECURS_TODAY)';
+ $this->errormessage = 'Ilegal amount of recurs per day.';
+ break;
+ case '142':
+ $this->resultcode = $resultcode . ' (NO_VALID_PAYMENT_METHODS)';
+ $this->errormessage = 'No valid paymentmethods.';
+ break;
+ case '143':
+ $this->resultcode = $resultcode . ' (CREDIT_DENIED_BY_BANK)';
+ $this->errormessage = 'Credit denied by bank.';
+ break;
+ case '144':
+ $this->resultcode = $resultcode . ' (ILLEGAL_CREDIT_USER)';
+ $this->errormessage = 'User is not allowed to perform credit operation.';
+ break;
+ case '146':
+ $this->resultcode = $resultcode . ' (CUSTOMER_NOT_FOUND)';
+ $this->errormessage = 'Customer is not enrolled for Swish or if another payment method was used the address lookup returned no results.';
+ break;
+ case '300':
+ $this->resultcode = $resultcode . ' (BAD_CARDHOLDER_NAME)';
+ $this->errormessage = 'Invalid value for cardholder name.';
+ break;
+ case '301':
+ $this->resultcode = $resultcode . ' (BAD_TRANSACTION_ID)';
+ $this->errormessage = 'Invalid value for transaction id.';
+ break;
+ case '302':
+ $this->resultcode = $resultcode . ' (BAD_REV)';
+ $this->errormessage = 'Invalid value for rev.';
+ break;
+ case '303':
+ $this->resultcode = $resultcode . ' (BAD_MERCHANT_ID)';
+ $this->errormessage = 'Invalid value for merchant id.';
+ break;
+ case '304':
+ $this->resultcode = $resultcode . ' (BAD_LANG)';
+ $this->errormessage = 'Invalid value for lang.';
+ break;
+ case '305':
+ $this->resultcode = $resultcode . ' (BAD_AMOUNT)';
+ $this->errormessage = 'Invalid value for amount.';
+ break;
+ case '306':
+ $this->resultcode = $resultcode . ' (BAD_CUSTOMERREFNO)';
+ $this->errormessage = 'Invalid value for customer refno 307.';
+ break;
+ case '307':
+ $this->resultcode = $resultcode . ' (BAD_CURRENCY)';
+ $this->errormessage = 'Invalid value for currency.';
+ break;
+ case '308':
+ $this->resultcode = $resultcode . ' (BAD_PAYMENTMETHOD)';
+ $this->errormessage = 'Invalid value for payment method.';
+ break;
+ case '309':
+ $this->resultcode = $resultcode . ' (BAD_RETURNURL)';
+ $this->errormessage = 'Invalid value for return url.';
+ break;
+ case '310':
+ $this->resultcode = $resultcode . ' (BAD_LASTBOOKINGDAY)';
+ $this->errormessage = 'Invalid value for last booking day.';
+ break;
+ case '311':
+ $this->resultcode = $resultcode . ' (BAD_MAC)';
+ $this->errormessage = 'Invalid value for mac.';
+ break;
+ case '312':
+ $this->resultcode = $resultcode . ' (BAD_TRNUMBER)';
+ $this->errormessage = 'Invalid value for tr number.';
+ break;
+ case '313':
+ $this->resultcode = $resultcode . ' (BAD_AUTHCODE)';
+ $this->errormessage = 'Invalid value for authcode.';
+ break;
+ case '314':
+ $this->resultcode = $resultcode . ' (BAD_CC_DESCR)';
+ $this->errormessage = 'Invalid value for cc_descr.';
+ break;
+ case '315':
+ $this->resultcode = $resultcode . ' (BAD_ERROR_CODE)';
+ $this->errormessage = 'Invalid value for error_code.';
+ break;
+ case '316':
+ $this->resultcode = $resultcode . ' (BAD_CARDNUMBER_OR_CARDTYPE_NOT_CONFIGURED)';
+ $this->errormessage = 'Card type not configured for merchant.';
+ break;
+ case '317':
+ $this->resultcode = $resultcode . ' (BAD_SSN)';
+ $this->errormessage = 'Invalid value for ssn.';
+ break;
+ case '318':
+ $this->resultcode = $resultcode . ' (BAD_VAT)';
+ $this->errormessage = 'Invalid value for vat.';
+ break;
+ case '319':
+ $this->resultcode = $resultcode . ' (BAD_CAPTURE_DATE)';
+ $this->errormessage = 'Invalid value for capture date.';
+ break;
+ case '320':
+ $this->resultcode = $resultcode . ' (BAD_CAMPAIGN_CODE_INVALID)';
+ $this->errormessage = 'Invalid value for campaign code. There are no valid matching campaign codes.';
+ break;
+ case '321':
+ $this->resultcode = $resultcode . ' (BAD_SUBSCRIPTION_TYPE)';
+ $this->errormessage = 'Invalid subscription type.';
+ break;
+ case '322':
+ $this->resultcode = $resultcode . ' (BAD_SUBSCRIPTION_ID)';
+ $this->errormessage = 'Invalid subscription id.';
+ break;
+ case '323':
+ $this->resultcode = $resultcode . ' (BAD_BASE64)';
+ $this->errormessage = 'Invalid base64.';
+ break;
+ case '324':
+ $this->resultcode = $resultcode . ' (BAD_CAMPAIGN_CODE)';
+ $this->errormessage = 'Invalid campaign code. Missing value.';
+ break;
+ case '325':
+ $this->resultcode = $resultcode . ' (BAD_CALLBACKURL)';
+ $this->errormessage = 'Invalid callbackurl.';
+ break;
+ case '326':
+ $this->resultcode = $resultcode . ' (THREE_D_CHECK_FAILED)';
+ $this->errormessage = '3D check failed.';
+ break;
+ case '327':
+ $this->resultcode = $resultcode . ' (CARD_NOT_ENROLLED)';
+ $this->errormessage = 'Card not enrolled in 3D secure.';
+ break;
+ case '328':
+ $this->resultcode = $resultcode . ' (BAD_IPADDRESS)';
+ $this->errormessage = 'Provided ip address is incorrect.';
+ break;
+ case '329':
+ $this->resultcode = $resultcode . ' (BAD_MOBILE)';
+ $this->errormessage = 'Bad mobile phone number.';
+ break;
+ case '330':
+ $this->resultcode = $resultcode . ' (BAD_COUNTRY)';
+ $this->errormessage = 'Bad country parameter.';
+ break;
+ case '331':
+ $this->resultcode = $resultcode . ' (THREE_D_CHECK_NOT_AVAILABLE)';
+ $this->errormessage = 'Merchants 3D configuration invalid.';
+ break;
+ case '332':
+ $this->resultcode = $resultcode . ' (TIMEOUT)';
+ $this->errormessage = 'Timeout at Svea.';
+ break;
+ case '342':
+ $this->resultcode = $resultcode . ' (TRANSACTION_ALREADY_IN_PROGRESS)';
+ $this->errormessage = 'There is currently another transaction in progress on this payer alias.';
+ break;
+ case '500':
+ $this->resultcode = $resultcode . ' (ANTIFRAUD_CARDBIN_NOT_ALLOWED)';
+ $this->errormessage = 'Antifraud - cardbin not allowed.';
+ break;
+ case '501':
+ $this->resultcode = $resultcode . ' (ANTIFRAUD_IPLOCATION_NOT_ALLOWED)';
+ $this->errormessage = 'Antifraud – iplocation not allowed.';
+ break;
+ case '502':
+ $this->resultcode = $resultcode . ' (ANTIFRAUD_IPLOCATION_AND_BIN_DOESNT_MATCH)';
+ $this->errormessage = 'Antifraud – ip-location and bin does not match.';
+ break;
+ case '503':
+ $this->resultcode = $resultcode . ' (ANTIFRAUD_MAX_AMOUNT_PER_IP_EXCEEDED)';
+ $this->errormessage = 'Antofraud – max amount per ip exceeded.';
+ break;
+ case '504':
+ $this->resultcode = $resultcode . ' (ANTIFRAUD_MAX_TRANSACTIONS_PER_IP_EXCEEDED)';
+ $this->errormessage = 'Antifraud – max transactions per ip exceeded.';
+ break;
+ case '505':
+ $this->resultcode = $resultcode . ' (ANTIFRAUD_MAX_TRANSACTIONS_PER_CARDNO_EXCEEDED)';
+ $this->errormessage = 'Antifraud – max transactions per card number exceeded.';
+ break;
+ case '506':
+ $this->resultcode = $resultcode . ' (ANTIFRAUD_MAX_AMOUNT_PER_CARDNO_EXCEEDED)';
+ $this->errormessage = 'Antifraud – max amount per cardnumer exceeded.';
+ break;
+ case '507':
+ $this->resultcode = $resultcode . ' (ANTIFRAUD_IP_ADDRESS_BLOCKED)';
+ $this->errormessage = 'Antifraud – IP address blocked.';
+ break;
- default:
- $this->resultcode = $resultcode . ' (UNKNOWN_ERROR)';
- $this->errormessage = 'Unknown error.';
- break;
- }
- }
+ default:
+ $this->resultcode = $resultcode . ' (UNKNOWN_ERROR)';
+ $this->errormessage = 'Unknown error.';
+ break;
+ }
+ }
}
diff --git a/src/HostedService/Payment/CardPayment.php b/src/HostedService/Payment/CardPayment.php
index f958db67..1b0b90ec 100644
--- a/src/HostedService/Payment/CardPayment.php
+++ b/src/HostedService/Payment/CardPayment.php
@@ -11,48 +11,48 @@
* @author Anneli Halld'n, Daniel Brolund, Kristian Grossman-Madsen for Svea Svea\WebPay\WebPay
*/
class CardPayment extends HostedPayment
-{
- /**
- * Creates a new CardPayment containing a given order.
- * @param CreateOrderBuilder $order
- */
- public function __construct($order)
- {
- parent::__construct($order);
- }
-
- /**
- * configureExcludedPaymentMethods returns a list of payment methods not to
- * present on the paypage for this payment method method class.
- * @return string[] the list of excluded payment methods, @see SystemPaymentMethod
- */
- protected function configureExcludedPaymentMethods()
- {
- // first, exclude all invoice/paymentplan payment methods
- $methods = ExcludePayments::excludeInvoicesAndPaymentPlan();
-
- //directbanks
- $methods[] = SystemPaymentMethod::BANKAXESS;
- $methods[] = SystemPaymentMethod::DBNORDEASE;
- $methods[] = SystemPaymentMethod::DBSEBSE;
- $methods[] = SystemPaymentMethod::DBSEBFTGSE;
- $methods[] = SystemPaymentMethod::DBSHBSE;
- $methods[] = SystemPaymentMethod::DBSWEDBANKSE;
-
- //other
- $methods[] = SystemPaymentMethod::PAYPAL;
-
- return $methods;
- }
-
- /**
- * calculateRequestValues adds the payment methods not to present on the
- * paypage to the request array
- */
- public function calculateRequestValues()
- {
- $this->request['excludePaymentMethods'] = $this->configureExcludedPaymentMethods();
-
- return parent::calculateRequestValues();
- }
+{
+ /**
+ * Creates a new CardPayment containing a given order.
+ * @param CreateOrderBuilder $order
+ */
+ public function __construct($order)
+ {
+ parent::__construct($order);
+ }
+
+ /**
+ * configureExcludedPaymentMethods returns a list of payment methods not to
+ * present on the paypage for this payment method method class.
+ * @return string[] the list of excluded payment methods, @see SystemPaymentMethod
+ */
+ protected function configureExcludedPaymentMethods()
+ {
+ // first, exclude all invoice/paymentplan payment methods
+ $methods = ExcludePayments::excludeInvoicesAndPaymentPlan();
+
+ //directbanks
+ $methods[] = SystemPaymentMethod::BANKAXESS;
+ $methods[] = SystemPaymentMethod::DBNORDEASE;
+ $methods[] = SystemPaymentMethod::DBSEBSE;
+ $methods[] = SystemPaymentMethod::DBSEBFTGSE;
+ $methods[] = SystemPaymentMethod::DBSHBSE;
+ $methods[] = SystemPaymentMethod::DBSWEDBANKSE;
+
+ //other
+ $methods[] = SystemPaymentMethod::PAYPAL;
+
+ return $methods;
+ }
+
+ /**
+ * calculateRequestValues adds the payment methods not to present on the
+ * paypage to the request array
+ */
+ public function calculateRequestValues()
+ {
+ $this->request['excludePaymentMethods'] = $this->configureExcludedPaymentMethods();
+
+ return parent::calculateRequestValues();
+ }
}
diff --git a/src/HostedService/Payment/DirectPayment.php b/src/HostedService/Payment/DirectPayment.php
index b829ce69..4803fc2a 100644
--- a/src/HostedService/Payment/DirectPayment.php
+++ b/src/HostedService/Payment/DirectPayment.php
@@ -16,43 +16,43 @@
*/
class DirectPayment extends HostedPayment
{
- /**
- * Creates a new DirectPayment containing a given order.
- * @param CreateOrderBuilder $order
- */
- public function __construct($order)
- {
- parent::__construct($order);
- }
-
- /**
- * calculateRequestValues adds the payment methods not to present on the
- * paypage to the request array
- */
- public function calculateRequestValues()
- {
- $this->request['excludePaymentMethods'] = $this->configureExcludedPaymentMethods();
-
- return parent::calculateRequestValues();
- }
-
- /**
- * configureExcludedPaymentMethods returns a list of payment methods not to present on the paypage for this payment method method class.
- * @return string[] the list of excluded payment methods, @see SystemPaymentMethod
- */
- protected function configureExcludedPaymentMethods()
- {
- // first, exclude all invoice/paymentplan payment methods
- $methods = ExcludePayments::excludeInvoicesAndPaymentPlan();
-
- //card
- $methods[] = SystemPaymentMethod::KORTCERT;
- $methods[] = SystemPaymentMethod::SKRILL;
- $methods[] = SystemPaymentMethod::SVEACARDPAY;
-
- //other
- $methods[] = SystemPaymentMethod::PAYPAL;
-
- return $methods;
- }
+ /**
+ * Creates a new DirectPayment containing a given order.
+ * @param CreateOrderBuilder $order
+ */
+ public function __construct($order)
+ {
+ parent::__construct($order);
+ }
+
+ /**
+ * calculateRequestValues adds the payment methods not to present on the
+ * paypage to the request array
+ */
+ public function calculateRequestValues()
+ {
+ $this->request['excludePaymentMethods'] = $this->configureExcludedPaymentMethods();
+
+ return parent::calculateRequestValues();
+ }
+
+ /**
+ * configureExcludedPaymentMethods returns a list of payment methods not to present on the paypage for this payment method method class.
+ * @return string[] the list of excluded payment methods, @see SystemPaymentMethod
+ */
+ protected function configureExcludedPaymentMethods()
+ {
+ // first, exclude all invoice/paymentplan payment methods
+ $methods = ExcludePayments::excludeInvoicesAndPaymentPlan();
+
+ //card
+ $methods[] = SystemPaymentMethod::KORTCERT;
+ $methods[] = SystemPaymentMethod::SKRILL;
+ $methods[] = SystemPaymentMethod::SVEACARDPAY;
+
+ //other
+ $methods[] = SystemPaymentMethod::PAYPAL;
+
+ return $methods;
+ }
}
diff --git a/src/HostedService/Payment/HostedOrderRowBuilder.php b/src/HostedService/Payment/HostedOrderRowBuilder.php
index 3550b57b..7f043084 100644
--- a/src/HostedService/Payment/HostedOrderRowBuilder.php
+++ b/src/HostedService/Payment/HostedOrderRowBuilder.php
@@ -4,80 +4,80 @@
class HostedOrderRowBuilder
{
- /**
- * @param string $skuAsString
- * @return $this
- */
- public function setSku($skuAsString)
- {
- $this->sku = $skuAsString;
+ /**
+ * @param string $skuAsString
+ * @return $this
+ */
+ public function setSku($skuAsString)
+ {
+ $this->sku = $skuAsString;
- return $this;
- }
+ return $this;
+ }
- /**
- * @param string $nameAsString
- * @return $this
- */
- public function setName($nameAsString)
- {
- $this->name = $nameAsString;
+ /**
+ * @param string $nameAsString
+ * @return $this
+ */
+ public function setName($nameAsString)
+ {
+ $this->name = $nameAsString;
- return $this;
- }
+ return $this;
+ }
- /**
- * @param string $descriptionAsString
- * @return $this
- */
- public function setDescription($descriptionAsString)
- {
- $this->description = $descriptionAsString;
+ /**
+ * @param string $descriptionAsString
+ * @return $this
+ */
+ public function setDescription($descriptionAsString)
+ {
+ $this->description = $descriptionAsString;
- return $this;
- }
+ return $this;
+ }
- /**
- * @param int $AmountAsInt
- * @return $this
- */
- public function setAmount($AmountAsInt)
- {
- $this->amount = $AmountAsInt;
+ /**
+ * @param int $AmountAsInt
+ * @return $this
+ */
+ public function setAmount($AmountAsInt)
+ {
+ $this->amount = $AmountAsInt;
- return $this;
- }
+ return $this;
+ }
- /**
- * @param int $vatAsInt
- * @return $this
- */
- public function setVat($vatAsInt)
- {
- $this->vat = $vatAsInt;
+ /**
+ * @param int $vatAsInt
+ * @return $this
+ */
+ public function setVat($vatAsInt)
+ {
+ $this->vat = $vatAsInt;
- return $this;
- }
+ return $this;
+ }
- /**
- * @param int $quantityAsInt
- * @return $this
- */
- public function setQuantity($quantityAsInt)
- {
- $this->quantity = $quantityAsInt;
+ /**
+ * @param int $quantityAsInt
+ * @return $this
+ */
+ public function setQuantity($quantityAsInt)
+ {
+ $this->quantity = $quantityAsInt;
- return $this;
- }
+ return $this;
+ }
- /**
- * @param string $unitAsString
- * @return $this
- */
- public function setUnit($unitAsString)
- {
- $this->unit = $unitAsString;
+ /**
+ * @param string $unitAsString
+ * @return $this
+ */
+ public function setUnit($unitAsString)
+ {
+ $this->unit = $unitAsString;
- return $this;
- }
+ return $this;
+ }
}
diff --git a/src/HostedService/Payment/HostedPayment.php b/src/HostedService/Payment/HostedPayment.php
index a9e008b7..17f328bb 100644
--- a/src/HostedService/Payment/HostedPayment.php
+++ b/src/HostedService/Payment/HostedPayment.php
@@ -41,414 +41,414 @@
*/
class HostedPayment
{
- const RECURRINGCAPTURE = "RECURRINGCAPTURE";
- const ONECLICKCAPTURE = "ONECLICKCAPTURE";
- const RECURRING = "RECURRING";
- const ONECLICK = "ONECLICK";
-
- /**
- * @var CreateOrderBuilder $order holds the order information
- */
- public $order;
-
- /**
- * @var string $xmlMessage holds the generated message XML used in request
- */
- public $xmlMessage;
-
- /**
- * @var string $xmlMessageBase64 holds the Base64-encoded $xmlMessage
- */
- public $xmlMessageBase64;
-
- /**
- * @var string $returnUrl holds the return URL used in request
- */
- public $returnUrl;
-
- /**
- * @var string $callbackUrl holds the callback URL used in request
- */
- public $callbackUrl;
-
- /**
- * @var string $cancelUrl holds the cancel URL used in request
- */
- public $cancelUrl;
-
- /**
- * @var string $langCode holds the language code used in request
- */
- public $langCode;
-
- /**
- * @var string[] $request placeholder for the request parameter key/value pair array
- */
- public $request;
-
- /**
- * Creates a HostedPayment, sets default language to english
- * @param CreateOrderBuilder $order
- */
- public function __construct($order)
- {
- $this->langCode = "en";
- $this->order = $order;
- $this->request = array();
- }
-
- /**
- * Required - sets up a return url for the hosted payment response
- *
- * When a hosted payment transaction completes the payment service will answer
- * with a response xml message sent to the return url. This is also the return
- * url used if the user cancels at i.e. the SveaCardPay card payment page.
- *
- * @param string $returnUrlAsString
- * @return $this
- */
- public function setReturnUrl($returnUrlAsString)
- {
- $this->returnUrl = $returnUrlAsString;
-
- return $this;
- }
-
- /**
- * Optional - sets up a callback url for use if the transaction does not return correctly
- *
- * In case the hosted payment service is unable to return a response to the return url,
- * Svea will retry several times using the callback url as a fallback, if specified.
- *
- * This may happen if i.e. the user closes the browser before the payment service
- * redirects back to the shop, or if the transaction times out in lieu of user input.
- * In the latter case, Svea will fail the transaction after at most 30 minutes, and will
- * try to redirect to the callback url.
- *
- * @param string $callbackUrlAsString
- * @return $this
- */
- public function setCallbackUrl($callbackUrlAsString)
- {
- $this->callbackUrl = $callbackUrlAsString;
-
- return $this;
- }
-
- /**
- * Optional - includes a cancel button on the hosted pay page and sets a cancel url for use with the cancel button
- *
- * In case the payment method selection is cancelled by the user, Svea will redirect back to the cancel url.
- * Unless a cancel url is specified, no cancel button will be presented at the PayPage.
- *
- * @param string $cancelUrlAsString
- * @return $this
- */
- public function setCancelUrl($cancelUrlAsString)
- {
- $this->cancelUrl = $cancelUrlAsString;
-
- return $this;
- }
-
- /* Optional - sets the pay page display language.
- *
- * Default pay page language is English, unless another is specified using this method.
- *
- * @param string $languageCodeAsISO639
- * @return $this
- */
- public function setPayPageLanguage($languageCodeAsISO639)
- {
- switch ($languageCodeAsISO639) {
- case "sv":
- case "en":
- case "da":
- case "no":
- case "fi":
- case "es":
- case "nl":
- case "fr":
- case "de":
- case "it":
- $this->langCode = $languageCodeAsISO639;
- break;
- default:
- $this->langCode = "en";
- break;
- }
-
- return $this;
- }
-
- /**
- * getPaymentForm returns a form object containing a webservice payment request
- *
- * @return PaymentForm
- * @throws ValidationException
- */
- public function getPaymentForm()
- {
- //validate the order
- $errors = $this->validateOrder();
- $exceptionString = "";
- if (count($errors) > 0 || (isset($this->returnUrl) == FALSE && isset($this->paymentMethod) == FALSE)) {
- if (isset($this->returnUrl) == FALSE) {
- $exceptionString .= "-missing value : ReturnUrl is required. Use function setReturnUrl().\n";
- }
-
- foreach ($errors as $key => $value) {
- $exceptionString .= "-" . $key . " : " . $value . "\n";
- }
-
- throw new ValidationException($exceptionString);
- }
-
- $xmlBuilder = new HostedXmlBuilder();
- $this->xmlMessage = $xmlBuilder->getPaymentXML($this->calculateRequestValues(), $this->order);
- $this->xmlMessageBase64 = base64_encode($this->xmlMessage);
-
- $formObject = new PaymentForm($this->xmlMessage, $this->order->conf, $this->order->countryCode);
-
- return $formObject;
- }
-
- /**
- * @return string[] $errors an array containing the validation errors found
- */
- public function validateOrder()
- {
- $validator = new HostedOrderValidator();
- $errors = $validator->validate($this);
- if (($this->order->countryCode == "NL" || $this->order->countryCode == "DE") && isset($this->paymentMethod)) {
- if (isset($this->paymentMethod) &&
- ($this->paymentMethod == PaymentMethod::INVOICE || $this->paymentMethod == PaymentMethod::PAYMENTPLAN)
- ) {
- $errors = $validator->validateEuroCustomer($this->order, $errors);
- }
- }
-
- return $errors;
- }
-
- /**
- * returns a list of request attributes-value pairs
- */
- public function calculateRequestValues()
- {
- // format order data
- $formatter = new HostedRowFormatter();
- $this->request['rows'] = $formatter->formatRows($this->order);
- $this->request['amount'] = $formatter->formatTotalAmount($this->request['rows']);
- $this->request['totalVat'] = $formatter->formatTotalVat($this->request['rows']);
-
- $this->request['clientOrderNumber'] = $this->order->clientOrderNumber; /// used by payment
-
- if (isset($this->order->customerIdentity->ipAddress)) {
- $this->request['ipAddress'] = $this->order->customerIdentity->ipAddress; /// used by payment (optional), preparepayment (required)
- }
-
- $this->request['langCode'] = $this->langCode;
-
- $this->request['returnUrl'] = $this->returnUrl;
- $this->request['callbackUrl'] = $this->callbackUrl;
- $this->request['cancelUrl'] = $this->cancelUrl;
-
- $this->request['currency'] = strtoupper(trim($this->order->currency));
-
- if (isset($this->subscriptionType)) {
- $this->request['subscriptionType'] = $this->subscriptionType;
- }
-
- if (isset($this->subscriptionId)) {
- $this->request['subscriptionId'] = $this->subscriptionId;
- }
-
- if (isset($this->order->payerAlias)) // used by Swish
- {
- $this->request['payerAlias'] = $this->order->payerAlias;
- }
-
- return $this->request;
- }
-
- /**
- * getPaymentURL returns an URL to a prepared hosted payment, use this to
- * to get a link which the customer can use to confirm a payment at a later
- * time after having received the url via i.e. an email message.
- *
- * Use function setIpAddress() on the order customer.";
- * Use function setPayPageLanguage().";
- *
- * @return \Svea\WebPay\HostedService\HostedResponse\HostedPaymentResponse
- * [accepted] => 1
- * [resultcode] => 0
- * [errormessage] =>
- * [id] => //the order id
- * [created]
- * [url] => https://webpaypaymentgateway.svea.com/webpay/preparedpayment/xxxxx Will return test or prod url depending on where the order was created
- * [testurl] => https://webpaypaymentgatewaystage.svea.com/webpay/preparedpayment/xxxxx Deprecated! Not valid if the order is created in prod.
- * @throws ValidationException
- */
- public function getPaymentUrl()
- {
-
- // follow the procedure set out in getPaymentForm, then
- //
- //validate the order
- $errors = $this->validateOrder();
-
- //additional validation for PreparedPayment request
- if (!isset($this->order->customerIdentity->ipAddress)) {
- $errors['missing value'] = "ipAddress is required. Use function setIpAddress() on the order customer.";
- }
- if (!isset($this->langCode)) {
- $errors['missing value'] = "langCode is required. Use function setPayPageLanguage().";
- }
-
- $exceptionString = "";
- if (count($errors) > 0 || (isset($this->returnUrl) == FALSE && isset($this->paymentMethod) == FALSE)) {
- if (isset($this->returnUrl) == FALSE) {
- $exceptionString .= "-missing value : ReturnUrl is required. Use function setReturnUrl().\n";
- }
-
- foreach ($errors as $key => $value) {
- $exceptionString .= "-" . $key . " : " . $value . "\n";
- }
-
- throw new ValidationException($exceptionString);
- }
-
- $xmlBuilder = new HostedXmlBuilder();
- $this->xmlMessage = $xmlBuilder->getPreparePaymentXML($this->calculateRequestValues(), $this->order);
-
- // curl away the request to Svea, and pick up the answer.
-
- // get our merchantid & secret
-
- // get the config, countryCode from the order object, $message from $this->xmlMessage;
- $this->config = $this->order->conf;
- $this->countryCode = $this->order->countryCode;
- $message = $this->xmlMessage;
-
- $merchantId = $this->config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $this->countryCode);
- $secret = $this->config->getSecret(ConfigurationProvider::HOSTED_TYPE, $this->countryCode);
-
- // calculate mac
- $mac = hash("sha512", base64_encode($message) . $secret);
-
- // encode the request elements
- $fields = array(
- 'merchantid' => urlencode($merchantId),
- 'message' => urlencode(base64_encode($message)),
- 'mac' => urlencode($mac)
- );
-
- // below taken from HostedRequest doRequest
- $fieldsString = "";
- foreach ($fields as $key => $value) {
- $fieldsString .= $key . '=' . $value . '&';
- }
- rtrim($fieldsString, '&');
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $this->config->getEndpoint(SveaConfigurationProvider::HOSTED_ADMIN_TYPE) . "preparepayment");
- curl_setopt($ch, CURLOPT_POST, count($fields));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- //force curl to trust https
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //returns a html page with redirecting to bank...
- $responseXML = curl_exec($ch);
- curl_close($ch);
-
- // create Svea\WebPay\Response\SveaResponse to handle response
- $responseObj = new SimpleXMLElement($responseXML);
- $sveaResponse = new SveaResponse($responseObj, $this->countryCode, $this->config);
-
- return $sveaResponse->response;
- }
-
- /**
- * Optional - set subscription type for recurring payments.
- *
- * Subscription type may be one of
- * HostedPayment::RECURRINGCAPTURE | HostedPayment::ONECLICKCAPTURE (all countries) or
- * HostedPayment::RECURRING | HostedPayment::ONECLICK (Scandinavian countries only)
- *
- * The merchant should use RECURRINGCAPTURE if all the recurring payments are
- * to be scheduled by the merchant, without any action taken from the card holder.
- *
- * The merchant should use ONECLICKCAPTURE if they want the initial transaction to
- * be captured. In this case a successful initial transaction will result in the
- * CONFIRMED status, which means that the transaction will be captured at night when
- * the daily capture job is finished.
- *
- * The initial transaction status will either be AUTHORIZED (i.e. it may be charged
- * after it has been confirmed) or REGISTERED (i.e. the initial amount will be
- * reserved for a time by the bank, and then released) for RECURRING and ONECLICK.
- *
- * Use of setSubscriptionType() will set the attributes subscriptionId and subscriptionType
- * in the HostedPaymentResponse.
- *
- * @param string $subscriptionType @see CardPayment constants
- * @return $this
- */
- public function setSubscriptionType($subscriptionType)
- {
- $this->subscriptionType = $subscriptionType;
-
- return $this;
- }
-
- /**
- * Set a subscriptionId to use in a recurring payment request
- *
- * The subscriptionId should have been obtained in an earlier payment request response using
- * setSubscriptionType()
- *
- * @see setSubscriptionType() setSubscriptionType()
- *
- * @param string $subscriptionType
- * @return $this
- */
- public function setSubscriptionId($subscriptionId)
- {
- $this->subscriptionId = $subscriptionId;
-
- return $this;
- }
-
-
- /**
- * Perform a recurring card payment request.
- *
- * Note that the specified row information in the order is used only to calculate the
- * recur order total amount. The order row information is not passed on in the request.
- * Neither is vat information passed to Svea, only the total order amount.
- *
- * If the original request subscription type was RECURRING or RECURRINGCAPTURE the currency
- * for the recur request must be the same as the currency in the initial transaction.
- *
- * @return RecurTransactionResponse
- */
- public function doRecur()
- {
- // calculate amount from order rows
- $formatter = new HostedRowFormatter();
- $this->request['rows'] = $formatter->formatRows($this->order);
- $this->request['amount'] = $formatter->formatTotalAmount($this->request['rows']);
- $this->request['totalVat'] = $formatter->formatTotalVat($this->request['rows']);
-
- $request = new RecurTransaction($this->order->conf);
- $request->currency = $this->order->currency;
- $request->amount = $this->request['amount'];
- $request->vat = $this->request['totalVat'];
- $request->customerRefNo = $this->order->clientOrderNumber;
- $request->countryCode = $this->order->countryCode;
- $request->subscriptionId = $this->subscriptionId;
- $response = $request->doRequest();
-
- return $response;
- }
+ const RECURRINGCAPTURE = "RECURRINGCAPTURE";
+ const ONECLICKCAPTURE = "ONECLICKCAPTURE";
+ const RECURRING = "RECURRING";
+ const ONECLICK = "ONECLICK";
+
+ /**
+ * @var CreateOrderBuilder $order holds the order information
+ */
+ public $order;
+
+ /**
+ * @var string $xmlMessage holds the generated message XML used in request
+ */
+ public $xmlMessage;
+
+ /**
+ * @var string $xmlMessageBase64 holds the Base64-encoded $xmlMessage
+ */
+ public $xmlMessageBase64;
+
+ /**
+ * @var string $returnUrl holds the return URL used in request
+ */
+ public $returnUrl;
+
+ /**
+ * @var string $callbackUrl holds the callback URL used in request
+ */
+ public $callbackUrl;
+
+ /**
+ * @var string $cancelUrl holds the cancel URL used in request
+ */
+ public $cancelUrl;
+
+ /**
+ * @var string $langCode holds the language code used in request
+ */
+ public $langCode;
+
+ /**
+ * @var string[] $request placeholder for the request parameter key/value pair array
+ */
+ public $request;
+
+ /**
+ * Creates a HostedPayment, sets default language to english
+ * @param CreateOrderBuilder $order
+ */
+ public function __construct($order)
+ {
+ $this->langCode = "en";
+ $this->order = $order;
+ $this->request = [];
+ }
+
+ /**
+ * Required - sets up a return url for the hosted payment response
+ *
+ * When a hosted payment transaction completes the payment service will answer
+ * with a response xml message sent to the return url. This is also the return
+ * url used if the user cancels at i.e. the SveaCardPay card payment page.
+ *
+ * @param string $returnUrlAsString
+ * @return $this
+ */
+ public function setReturnUrl($returnUrlAsString)
+ {
+ $this->returnUrl = $returnUrlAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional - sets up a callback url for use if the transaction does not return correctly
+ *
+ * In case the hosted payment service is unable to return a response to the return url,
+ * Svea will retry several times using the callback url as a fallback, if specified.
+ *
+ * This may happen if i.e. the user closes the browser before the payment service
+ * redirects back to the shop, or if the transaction times out in lieu of user input.
+ * In the latter case, Svea will fail the transaction after at most 30 minutes, and will
+ * try to redirect to the callback url.
+ *
+ * @param string $callbackUrlAsString
+ * @return $this
+ */
+ public function setCallbackUrl($callbackUrlAsString)
+ {
+ $this->callbackUrl = $callbackUrlAsString;
+
+ return $this;
+ }
+
+ /**
+ * Optional - includes a cancel button on the hosted pay page and sets a cancel url for use with the cancel button
+ *
+ * In case the payment method selection is cancelled by the user, Svea will redirect back to the cancel url.
+ * Unless a cancel url is specified, no cancel button will be presented at the PayPage.
+ *
+ * @param string $cancelUrlAsString
+ * @return $this
+ */
+ public function setCancelUrl($cancelUrlAsString)
+ {
+ $this->cancelUrl = $cancelUrlAsString;
+
+ return $this;
+ }
+
+ /* Optional - sets the pay page display language.
+ *
+ * Default pay page language is English, unless another is specified using this method.
+ *
+ * @param string $languageCodeAsISO639
+ * @return $this
+ */
+ public function setPayPageLanguage($languageCodeAsISO639)
+ {
+ switch ($languageCodeAsISO639) {
+ case "sv":
+ case "en":
+ case "da":
+ case "no":
+ case "fi":
+ case "es":
+ case "nl":
+ case "fr":
+ case "de":
+ case "it":
+ $this->langCode = $languageCodeAsISO639;
+ break;
+ default:
+ $this->langCode = "en";
+ break;
+ }
+
+ return $this;
+ }
+
+ /**
+ * getPaymentForm returns a form object containing a webservice payment request
+ *
+ * @return PaymentForm
+ * @throws ValidationException
+ */
+ public function getPaymentForm()
+ {
+ //validate the order
+ $errors = $this->validateOrder();
+ $exceptionString = "";
+ if (count($errors) > 0 || (isset($this->returnUrl) == FALSE && isset($this->paymentMethod) == FALSE)) {
+ if (isset($this->returnUrl) == FALSE) {
+ $exceptionString .= "-missing value : ReturnUrl is required. Use function setReturnUrl().\n";
+ }
+
+ foreach ($errors as $key => $value) {
+ $exceptionString .= "-" . $key . " : " . $value . "\n";
+ }
+
+ throw new ValidationException($exceptionString);
+ }
+
+ $xmlBuilder = new HostedXmlBuilder();
+ $this->xmlMessage = $xmlBuilder->getPaymentXML($this->calculateRequestValues(), $this->order);
+ $this->xmlMessageBase64 = base64_encode($this->xmlMessage);
+
+ $formObject = new PaymentForm($this->xmlMessage, $this->order->conf, $this->order->countryCode);
+
+ return $formObject;
+ }
+
+ /**
+ * @return string[] $errors an array containing the validation errors found
+ */
+ public function validateOrder()
+ {
+ $validator = new HostedOrderValidator();
+ $errors = $validator->validate($this);
+ if (($this->order->countryCode == "NL" || $this->order->countryCode == "DE") && isset($this->paymentMethod)) {
+ if (isset($this->paymentMethod) &&
+ ($this->paymentMethod == PaymentMethod::INVOICE || $this->paymentMethod == PaymentMethod::PAYMENTPLAN)
+ ) {
+ $errors = $validator->validateEuroCustomer($this->order, $errors);
+ }
+ }
+
+ return $errors;
+ }
+
+ /**
+ * returns a list of request attributes-value pairs
+ */
+ public function calculateRequestValues()
+ {
+ // format order data
+ $formatter = new HostedRowFormatter();
+ $this->request['rows'] = $formatter->formatRows($this->order);
+ $this->request['amount'] = $formatter->formatTotalAmount($this->request['rows']);
+ $this->request['totalVat'] = $formatter->formatTotalVat($this->request['rows']);
+
+ $this->request['clientOrderNumber'] = $this->order->clientOrderNumber; /// used by payment
+
+ if (isset($this->order->customerIdentity->ipAddress)) {
+ $this->request['ipAddress'] = $this->order->customerIdentity->ipAddress; /// used by payment (optional), preparepayment (required)
+ }
+
+ $this->request['langCode'] = $this->langCode;
+
+ $this->request['returnUrl'] = $this->returnUrl;
+ $this->request['callbackUrl'] = $this->callbackUrl;
+ $this->request['cancelUrl'] = $this->cancelUrl;
+
+ $this->request['currency'] = strtoupper(trim($this->order->currency));
+
+ if (isset($this->subscriptionType)) {
+ $this->request['subscriptionType'] = $this->subscriptionType;
+ }
+
+ if (isset($this->subscriptionId)) {
+ $this->request['subscriptionId'] = $this->subscriptionId;
+ }
+
+ if (isset($this->order->payerAlias)) // used by Swish
+ {
+ $this->request['payerAlias'] = $this->order->payerAlias;
+ }
+
+ return $this->request;
+ }
+
+ /**
+ * getPaymentURL returns an URL to a prepared hosted payment, use this to
+ * to get a link which the customer can use to confirm a payment at a later
+ * time after having received the url via i.e. an email message.
+ *
+ * Use function setIpAddress() on the order customer.";
+ * Use function setPayPageLanguage().";
+ *
+ * @return \Svea\WebPay\HostedService\HostedResponse\HostedPaymentResponse
+ * [accepted] => 1
+ * [resultcode] => 0
+ * [errormessage] =>
+ * [id] => //the order id
+ * [created]
+ * [url] => https://webpaypaymentgateway.svea.com/webpay/preparedpayment/xxxxx Will return test or prod url depending on where the order was created
+ * [testurl] => https://webpaypaymentgatewaystage.svea.com/webpay/preparedpayment/xxxxx Deprecated! Not valid if the order is created in prod.
+ * @throws ValidationException
+ */
+ public function getPaymentUrl()
+ {
+
+ // follow the procedure set out in getPaymentForm, then
+ //
+ //validate the order
+ $errors = $this->validateOrder();
+
+ //additional validation for PreparedPayment request
+ if (!isset($this->order->customerIdentity->ipAddress)) {
+ $errors['missing value'] = "ipAddress is required. Use function setIpAddress() on the order customer.";
+ }
+ if (!isset($this->langCode)) {
+ $errors['missing value'] = "langCode is required. Use function setPayPageLanguage().";
+ }
+
+ $exceptionString = "";
+ if (count($errors) > 0 || (isset($this->returnUrl) == FALSE && isset($this->paymentMethod) == FALSE)) {
+ if (isset($this->returnUrl) == FALSE) {
+ $exceptionString .= "-missing value : ReturnUrl is required. Use function setReturnUrl().\n";
+ }
+
+ foreach ($errors as $key => $value) {
+ $exceptionString .= "-" . $key . " : " . $value . "\n";
+ }
+
+ throw new ValidationException($exceptionString);
+ }
+
+ $xmlBuilder = new HostedXmlBuilder();
+ $this->xmlMessage = $xmlBuilder->getPreparePaymentXML($this->calculateRequestValues(), $this->order);
+
+ // curl away the request to Svea, and pick up the answer.
+
+ // get our merchantid & secret
+
+ // get the config, countryCode from the order object, $message from $this->xmlMessage;
+ $this->config = $this->order->conf;
+ $this->countryCode = $this->order->countryCode;
+ $message = $this->xmlMessage;
+
+ $merchantId = $this->config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $this->countryCode);
+ $secret = $this->config->getSecret(ConfigurationProvider::HOSTED_TYPE, $this->countryCode);
+
+ // calculate mac
+ $mac = hash("sha512", base64_encode($message) . $secret);
+
+ // encode the request elements
+ $fields = [
+ 'merchantid' => urlencode($merchantId),
+ 'message' => urlencode(base64_encode($message)),
+ 'mac' => urlencode($mac)
+ ];
+
+ // below taken from HostedRequest doRequest
+ $fieldsString = "";
+ foreach ($fields as $key => $value) {
+ $fieldsString .= $key . '=' . $value . '&';
+ }
+ rtrim($fieldsString, '&');
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $this->config->getEndpoint(SveaConfigurationProvider::HOSTED_ADMIN_TYPE) . "preparepayment");
+ curl_setopt($ch, CURLOPT_POST, count($fields));
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ //force curl to trust https
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ //returns a html page with redirecting to bank...
+ $responseXML = curl_exec($ch);
+ curl_close($ch);
+
+ // create Svea\WebPay\Response\SveaResponse to handle response
+ $responseObj = new SimpleXMLElement($responseXML);
+ $sveaResponse = new SveaResponse($responseObj, $this->countryCode, $this->config);
+
+ return $sveaResponse->response;
+ }
+
+ /**
+ * Optional - set subscription type for recurring payments.
+ *
+ * Subscription type may be one of
+ * HostedPayment::RECURRINGCAPTURE | HostedPayment::ONECLICKCAPTURE (all countries) or
+ * HostedPayment::RECURRING | HostedPayment::ONECLICK (Scandinavian countries only)
+ *
+ * The merchant should use RECURRINGCAPTURE if all the recurring payments are
+ * to be scheduled by the merchant, without any action taken from the card holder.
+ *
+ * The merchant should use ONECLICKCAPTURE if they want the initial transaction to
+ * be captured. In this case a successful initial transaction will result in the
+ * CONFIRMED status, which means that the transaction will be captured at night when
+ * the daily capture job is finished.
+ *
+ * The initial transaction status will either be AUTHORIZED (i.e. it may be charged
+ * after it has been confirmed) or REGISTERED (i.e. the initial amount will be
+ * reserved for a time by the bank, and then released) for RECURRING and ONECLICK.
+ *
+ * Use of setSubscriptionType() will set the attributes subscriptionId and subscriptionType
+ * in the HostedPaymentResponse.
+ *
+ * @param string $subscriptionType @see CardPayment constants
+ * @return $this
+ */
+ public function setSubscriptionType($subscriptionType)
+ {
+ $this->subscriptionType = $subscriptionType;
+
+ return $this;
+ }
+
+ /**
+ * Set a subscriptionId to use in a recurring payment request
+ *
+ * The subscriptionId should have been obtained in an earlier payment request response using
+ * setSubscriptionType()
+ *
+ * @see setSubscriptionType() setSubscriptionType()
+ *
+ * @param string $subscriptionType
+ * @return $this
+ */
+ public function setSubscriptionId($subscriptionId)
+ {
+ $this->subscriptionId = $subscriptionId;
+
+ return $this;
+ }
+
+
+ /**
+ * Perform a recurring card payment request.
+ *
+ * Note that the specified row information in the order is used only to calculate the
+ * recur order total amount. The order row information is not passed on in the request.
+ * Neither is vat information passed to Svea, only the total order amount.
+ *
+ * If the original request subscription type was RECURRING or RECURRINGCAPTURE the currency
+ * for the recur request must be the same as the currency in the initial transaction.
+ *
+ * @return RecurTransactionResponse
+ */
+ public function doRecur()
+ {
+ // calculate amount from order rows
+ $formatter = new HostedRowFormatter();
+ $this->request['rows'] = $formatter->formatRows($this->order);
+ $this->request['amount'] = $formatter->formatTotalAmount($this->request['rows']);
+ $this->request['totalVat'] = $formatter->formatTotalVat($this->request['rows']);
+
+ $request = new RecurTransaction($this->order->conf);
+ $request->currency = $this->order->currency;
+ $request->amount = $this->request['amount'];
+ $request->vat = $this->request['totalVat'];
+ $request->customerRefNo = $this->order->clientOrderNumber;
+ $request->countryCode = $this->order->countryCode;
+ $request->subscriptionId = $this->subscriptionId;
+ $response = $request->doRequest();
+
+ return $response;
+ }
}
diff --git a/src/HostedService/Payment/PayPagePayment.php b/src/HostedService/Payment/PayPagePayment.php
index de50a6c2..f282c126 100644
--- a/src/HostedService/Payment/PayPagePayment.php
+++ b/src/HostedService/Payment/PayPagePayment.php
@@ -11,132 +11,132 @@
*/
class PayPagePayment extends HostedPayment
{
- public $paymentMethod;
- public $excludedPaymentMethods;
-
- /**
- * Creates a new PayPagePayment containing a given order.
- * @param CreateOrderBuilder $order
- */
- public function __construct($order)
- {
- parent::__construct($order);
- }
-
- public function calculateRequestValues()
- {
- if (isset($this->paymentMethod)) {
- $this->request['paymentMethod'] = $this->paymentMethod;
- }
- if (isset($this->excludedPaymentMethods)) {
- $this->request['excludePaymentMethods'] = $this->excludedPaymentMethods;
- }
-
- return parent::calculateRequestValues();
- }
-
- /**
- * Exclude specific payment methods from being shown of the PayPage.
- * @params string $paymentMethod use the constants listed in Svea\WebPay\Constant\PaymentMethod
- * Flexible number of params
- * @return $this
- */
- public function excludePaymentMethods()
- {
- $excludes = func_get_args();
-
- foreach ($excludes as $method) {
- if ($method == PaymentMethod::INVOICE) {
- $this->excludedPaymentMethods[] = "SVEAINVOICEEU_" . $this->order->countryCode;
- $this->excludedPaymentMethods[] = "SVEAINVOICE" . $this->order->countryCode;
- } elseif ($this->paymentMethod == PaymentMethod::PAYMENTPLAN) {
- $this->excludedPaymentMethods[] = "SVEASPLITEU_" . $this->order->countryCode;
- } else {
- $this->excludedPaymentMethods[] = $method;
- }
- }
-
- return $this;
- }
-
- /**
- * Include specific payment methods to show on the PayPage.
- * @params string $paymentMethod use the constants listed in SystemPaymentMethod
- * Flexible number of params
- * @return $this
- */
- public function includePaymentMethods()
- {
- //get parameters sent no matter how many
- $include = func_get_args();
- //exclude all functions
- $this->excludedPaymentMethods[] = SystemPaymentMethod::BANKAXESS;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::KORTCERT;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::SKRILL;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::INVOICESE;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::PAYMENTPLANSE;
- $this->excludedPaymentMethods[] = "SVEAINVOICEEU_" . $this->order->countryCode;
- $this->excludedPaymentMethods[] = "SVEASPLITEU_" . $this->order->countryCode;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::PAYPAL;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSWEDBANKSE;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSHBSE;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSEBFTGSE;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSEBSE;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::DBNORDEASE;
-
- //remove the include functions from the excludedPaymentMethods
- foreach ($include as $key => $value) {
- $trimmed = trim($value);
- $cleanValue = strtoupper($trimmed);
- //loop through the include requests
- foreach ($this->excludedPaymentMethods as $k => $v) {
- //unset if a match in exlude array
- if ($cleanValue == $v) {
- unset($this->excludedPaymentMethods[$k]);
- //unset the invoice methods if INVOICE is desired
- } elseif ($cleanValue == PaymentMethod::INVOICE) {
- if ($v == "SVEAINVOICEEU_" . $this->order->countryCode || $k == SystemPaymentMethod::INVOICESE) {
- unset($this->excludedPaymentMethods[$k]);
- }
- //unset the paymentplan methods if PAYMENTPLAN is desired
- } elseif ($cleanValue == PaymentMethod::PAYMENTPLAN) {
- if ($k == "SVEASPLITEU_" . $this->order->countryCode || $k == SystemPaymentMethod::PAYMENTPLANSE) {
- unset($this->excludedPaymentMethods[$k]);
- }
- }
- }
- }
-
- return $this;
- }
-
- /**
- * Exclude all cardpayments from being shown on the PayPage.
- * @return $this
- */
- public function excludeCardPaymentMethods()
- {
- $this->excludedPaymentMethods[] = SystemPaymentMethod::KORTCERT;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::SKRILL;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::KORTWN;
-
- return $this;
- }
-
- /**
- * Exclude all direct bank payments from being shown on the PayPage.
- * @return $this
- *
- */
- public function excludeDirectPaymentMethods()
- {
- $this->excludedPaymentMethods[] = SystemPaymentMethod::BANKAXESS;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::DBNORDEASE;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSEBSE;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSEBFTGSE;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSHBSE;
- $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSWEDBANKSE;
-
- return $this;
- }
+ public $paymentMethod;
+ public $excludedPaymentMethods;
+
+ /**
+ * Creates a new PayPagePayment containing a given order.
+ * @param CreateOrderBuilder $order
+ */
+ public function __construct($order)
+ {
+ parent::__construct($order);
+ }
+
+ public function calculateRequestValues()
+ {
+ if (isset($this->paymentMethod)) {
+ $this->request['paymentMethod'] = $this->paymentMethod;
+ }
+ if (isset($this->excludedPaymentMethods)) {
+ $this->request['excludePaymentMethods'] = $this->excludedPaymentMethods;
+ }
+
+ return parent::calculateRequestValues();
+ }
+
+ /**
+ * Exclude specific payment methods from being shown of the PayPage.
+ * @params string $paymentMethod use the constants listed in Svea\WebPay\Constant\PaymentMethod
+ * Flexible number of params
+ * @return $this
+ */
+ public function excludePaymentMethods()
+ {
+ $excludes = func_get_args();
+
+ foreach ($excludes as $method) {
+ if ($method == PaymentMethod::INVOICE) {
+ $this->excludedPaymentMethods[] = "SVEAINVOICEEU_" . $this->order->countryCode;
+ $this->excludedPaymentMethods[] = "SVEAINVOICE" . $this->order->countryCode;
+ } elseif ($this->paymentMethod == PaymentMethod::PAYMENTPLAN) {
+ $this->excludedPaymentMethods[] = "SVEASPLITEU_" . $this->order->countryCode;
+ } else {
+ $this->excludedPaymentMethods[] = $method;
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * Include specific payment methods to show on the PayPage.
+ * @params string $paymentMethod use the constants listed in SystemPaymentMethod
+ * Flexible number of params
+ * @return $this
+ */
+ public function includePaymentMethods()
+ {
+ //get parameters sent no matter how many
+ $include = func_get_args();
+ //exclude all functions
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::BANKAXESS;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::KORTCERT;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::SKRILL;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::INVOICESE;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::PAYMENTPLANSE;
+ $this->excludedPaymentMethods[] = "SVEAINVOICEEU_" . $this->order->countryCode;
+ $this->excludedPaymentMethods[] = "SVEASPLITEU_" . $this->order->countryCode;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::PAYPAL;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSWEDBANKSE;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSHBSE;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSEBFTGSE;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSEBSE;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::DBNORDEASE;
+
+ //remove the include functions from the excludedPaymentMethods
+ foreach ($include as $key => $value) {
+ $trimmed = trim($value);
+ $cleanValue = strtoupper($trimmed);
+ //loop through the include requests
+ foreach ($this->excludedPaymentMethods as $k => $v) {
+ //unset if a match in exlude array
+ if ($cleanValue == $v) {
+ unset($this->excludedPaymentMethods[$k]);
+ //unset the invoice methods if INVOICE is desired
+ } elseif ($cleanValue == PaymentMethod::INVOICE) {
+ if ($v == "SVEAINVOICEEU_" . $this->order->countryCode || $k == SystemPaymentMethod::INVOICESE) {
+ unset($this->excludedPaymentMethods[$k]);
+ }
+ //unset the paymentplan methods if PAYMENTPLAN is desired
+ } elseif ($cleanValue == PaymentMethod::PAYMENTPLAN) {
+ if ($k == "SVEASPLITEU_" . $this->order->countryCode || $k == SystemPaymentMethod::PAYMENTPLANSE) {
+ unset($this->excludedPaymentMethods[$k]);
+ }
+ }
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * Exclude all cardpayments from being shown on the PayPage.
+ * @return $this
+ */
+ public function excludeCardPaymentMethods()
+ {
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::KORTCERT;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::SKRILL;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::KORTWN;
+
+ return $this;
+ }
+
+ /**
+ * Exclude all direct bank payments from being shown on the PayPage.
+ * @return $this
+ *
+ */
+ public function excludeDirectPaymentMethods()
+ {
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::BANKAXESS;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::DBNORDEASE;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSEBSE;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSEBFTGSE;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSHBSE;
+ $this->excludedPaymentMethods[] = SystemPaymentMethod::DBSWEDBANKSE;
+
+ return $this;
+ }
}
diff --git a/src/HostedService/Payment/PaymentMethodPayment.php b/src/HostedService/Payment/PaymentMethodPayment.php
index b92cedc6..72ce23ba 100644
--- a/src/HostedService/Payment/PaymentMethodPayment.php
+++ b/src/HostedService/Payment/PaymentMethodPayment.php
@@ -10,42 +10,42 @@
*/
class PaymentMethodPayment extends HostedPayment
{
- public $paymentMethod;
+ public $paymentMethod;
- /**
- * Creates a new PaymentMethodPayment containing a given order and using the given payment method.
- * @param CreateOrderBuilder $order
- * @param string $paymentmethod -- one of the constants defined in Svea\WebPay\Constant\PaymentMethod class @see Svea\WebPay\Constant\PaymentMethod
- */
- public function __construct($order, $paymentmethod)
- {
- parent::__construct($order);
- $this->paymentMethod = $paymentmethod;
- }
+ /**
+ * Creates a new PaymentMethodPayment containing a given order and using the given payment method.
+ * @param CreateOrderBuilder $order
+ * @param string $paymentmethod -- one of the constants defined in Svea\WebPay\Constant\PaymentMethod class @see Svea\WebPay\Constant\PaymentMethod
+ */
+ public function __construct($order, $paymentmethod)
+ {
+ parent::__construct($order);
+ $this->paymentMethod = $paymentmethod;
+ }
- public function calculateRequestValues()
- {
- if (isset($this->paymentMethod)) {
- if ($this->paymentMethod == PaymentMethod::INVOICE) {
- $this->request['paymentMethod'] = "SVEAINVOICEEU_" . $this->order->countryCode;
- } elseif ($this->paymentMethod == PaymentMethod::PAYMENTPLAN) {
- $this->request['paymentMethod'] = "PAYMENTPLAN_" . $this->order->countryCode;
- } else {
- $this->request['paymentMethod'] = $this->paymentMethod;
- }
- }
+ public function calculateRequestValues()
+ {
+ if (isset($this->paymentMethod)) {
+ if ($this->paymentMethod == PaymentMethod::INVOICE) {
+ $this->request['paymentMethod'] = "SVEAINVOICEEU_" . $this->order->countryCode;
+ } elseif ($this->paymentMethod == PaymentMethod::PAYMENTPLAN) {
+ $this->request['paymentMethod'] = "PAYMENTPLAN_" . $this->order->countryCode;
+ } else {
+ $this->request['paymentMethod'] = $this->paymentMethod;
+ }
+ }
- return parent::calculateRequestValues();
- }
+ return parent::calculateRequestValues();
+ }
- /**
- * Semantic wrapper for setPayPageLanguage
- * @see setPayPageLanguage
- * @param string $languageCodeAsISO639
- * @return $this
- */
- public function setCardPageLanguage($languageCodeAsISO639)
- {
- return $this->setPayPageLanguage($languageCodeAsISO639);
- }
+ /**
+ * Semantic wrapper for setPayPageLanguage
+ * @see setPayPageLanguage
+ * @param string $languageCodeAsISO639
+ * @return $this
+ */
+ public function setCardPageLanguage($languageCodeAsISO639)
+ {
+ return $this->setPayPageLanguage($languageCodeAsISO639);
+ }
}
diff --git a/src/Response/SveaResponse.php b/src/Response/SveaResponse.php
index c21abba7..90bd1ef1 100644
--- a/src/Response/SveaResponse.php
+++ b/src/Response/SveaResponse.php
@@ -46,138 +46,138 @@
*/
class SveaResponse
{
- /**
- * @deprecated, use Svea\WebPay\Response\SveaResponse->getResponse() to access the $response object directly
- * @var public $response , instance of HostedResponse or WebServiceResponse
- */
- public $response;
+ /**
+ * @deprecated, use Svea\WebPay\Response\SveaResponse->getResponse() to access the $response object directly
+ * @var public $response , instance of HostedResponse or WebServiceResponse
+ */
+ public $response;
- /**
- * The constructor accepts the returned Svea service response. $message, and
- * returns an instance of the corresponding service response class which
- * parses $message and sets any returned attributes, along with the common
- * response attributes $accepted, $resultcode and $errormessage.
- *
- * If the $method parameter is set, it is used to determind the service
- * type, if not, we check $message itself to see if the service response
- * has come in as a SimpleXMLElement object (i.e. a WebService response), or
- * a raw xml string (i.e. a HostedService response).
- *
- * The resulting parsed response attributes are available for inspection
- * through the getResponse() method. Inspect the individual response using
- * i.e. $myInstanceOfSveaResponse->getResponse()->theAttributeInQuestion
- *
- * @param mixed $message contains the Svea service response
- * @param string $countryCode needed along with $config to decode response
- * @param SveaConfigurationProvider $config
- * @param string $method set for i.e. HostedAdmin, AdminService requests
- * @param array $log array of logs from AdminService or WebpayWS
- * @throws Exception
- */
- public function __construct($message, $countryCode, $config = NULL, $method = NULL, $log = NULL)
- {
+ /**
+ * The constructor accepts the returned Svea service response. $message, and
+ * returns an instance of the corresponding service response class which
+ * parses $message and sets any returned attributes, along with the common
+ * response attributes $accepted, $resultcode and $errormessage.
+ *
+ * If the $method parameter is set, it is used to determind the service
+ * type, if not, we check $message itself to see if the service response
+ * has come in as a SimpleXMLElement object (i.e. a WebService response), or
+ * a raw xml string (i.e. a HostedService response).
+ *
+ * The resulting parsed response attributes are available for inspection
+ * through the getResponse() method. Inspect the individual response using
+ * i.e. $myInstanceOfSveaResponse->getResponse()->theAttributeInQuestion
+ *
+ * @param mixed $message contains the Svea service response
+ * @param string $countryCode needed along with $config to decode response
+ * @param SveaConfigurationProvider $config
+ * @param string $method set for i.e. HostedAdmin, AdminService requests
+ * @param array $log array of logs from AdminService or WebpayWS
+ * @throws Exception
+ */
+ public function __construct($message, $countryCode, $config = NULL, $method = NULL, $log = NULL)
+ {
- // WebService requests get a stdClass object back from the SoapClient instance
- if (is_object($message)) {
+ // WebService requests get a stdClass object back from the SoapClient instance
+ if (is_object($message)) {
- // Web Service EU responses
- if (property_exists($message, "CreateOrderEuResult"))
- {
- $this->response = new CreateOrderResponse($message, $log);
- }
- elseif (property_exists($message, "GetAddressesResult")) // also legacy getAddresses result
- {
- $this->response = new GetAddressesResponse($message, $log);
- }
- elseif (property_exists($message, "GetPaymentPlanParamsEuResult"))
- {
- $this->response = new PaymentPlanParamsResponse($message, $log);
- }
- elseif (property_exists($message, "DeliverOrderEuResult"))
- {
- $this->response = new DeliverOrderResult($message, $log);
- }
- elseif (property_exists($message, "GetAccountCreditParamsEuResult"))
- {
- $this->response = new AccountCreditParamsResponse($message, $log);
- }
- elseif (property_exists($message, "CloseOrderEuResult"))
- {
- $this->response = new CloseOrderResult($message, $log);
- } // $method is set for i.e. AdminService requests
- elseif (isset($method))
- {
- switch ($method)
- {
- case "CancelOrder":
- $this->response = new CancelOrderResponse($message, $log);
- break;
- case "DeliverOrders":
- $this->response = new DeliverOrdersResponse($message, $log);
- break;
- case "GetOrders":
- $this->response = new GetOrdersResponse($message, $log);
- break;
- case "GetAccountCredits":
- $this->response = new GetAccountCreditsResponse($message, $log);
- break;
- case "CancelOrderRows":
- $this->response = new CancelOrderRowsResponse($message, $log);
- break;
- case "AddOrderRows":
- $this->response = new AddOrderRowsResponse($message, $log);
- break;
- case "UpdateOrderRows":
- $this->response = new UpdateOrderRowsResponse($message, $log);
- break;
- case "UpdateOrder":
- $this->response = new UpdateOrderResponse($message, $log);
- break;
- case "CreditInvoiceRows":
- $this->response = new CreditInvoiceRowsResponse($message, $log);
- break;
- case "DeliverPartial":
- $this->response = new DeliverPartialResponse($message, $log);
- break;
- case "CancelPaymentPlanRows":
- $this->response = new CreditPaymentPlanResponse($message, $log);
- break;
- case "CancelPaymentPlanAmount":
- $this->response = new CreditPaymentPlanResponse($message, $log);
- break;
- case "CancelAccountCreditAmount":
- $this->response = new CancelAccountCreditAmount($message, $log);
- break;
- case "CancelAccountCreditRows":
- $this->response = new CancelAccountCreditRows($message, $log);
- break;
- default:
- throw new Exception("unknown method: $method");
- break;
- }
- } // legacy fallback -- webservice from hosted_admin -- used by preparedpayment
- elseif (property_exists($message, "message"))
- {
- $this->response = new HostedAdminResponse($message, $countryCode, $config);
- }
- } // webservice hosted payment
- elseif ($message != NULL)
- {
- $this->response = new HostedPaymentResponse($message, $countryCode, $config);
- }
- else
- {
- $this->response = "Response is not recognized.";
- }
- }
+ // Web Service EU responses
+ if (property_exists($message, "CreateOrderEuResult"))
+ {
+ $this->response = new CreateOrderResponse($message, $log);
+ }
+ elseif (property_exists($message, "GetAddressesResult")) // also legacy getAddresses result
+ {
+ $this->response = new GetAddressesResponse($message, $log);
+ }
+ elseif (property_exists($message, "GetPaymentPlanParamsEuResult"))
+ {
+ $this->response = new PaymentPlanParamsResponse($message, $log);
+ }
+ elseif (property_exists($message, "DeliverOrderEuResult"))
+ {
+ $this->response = new DeliverOrderResult($message, $log);
+ }
+ elseif (property_exists($message, "GetAccountCreditParamsEuResult"))
+ {
+ $this->response = new AccountCreditParamsResponse($message, $log);
+ }
+ elseif (property_exists($message, "CloseOrderEuResult"))
+ {
+ $this->response = new CloseOrderResult($message, $log);
+ } // $method is set for i.e. AdminService requests
+ elseif (isset($method))
+ {
+ switch ($method)
+ {
+ case "CancelOrder":
+ $this->response = new CancelOrderResponse($message, $log);
+ break;
+ case "DeliverOrders":
+ $this->response = new DeliverOrdersResponse($message, $log);
+ break;
+ case "GetOrders":
+ $this->response = new GetOrdersResponse($message, $log);
+ break;
+ case "GetAccountCredits":
+ $this->response = new GetAccountCreditsResponse($message, $log);
+ break;
+ case "CancelOrderRows":
+ $this->response = new CancelOrderRowsResponse($message, $log);
+ break;
+ case "AddOrderRows":
+ $this->response = new AddOrderRowsResponse($message, $log);
+ break;
+ case "UpdateOrderRows":
+ $this->response = new UpdateOrderRowsResponse($message, $log);
+ break;
+ case "UpdateOrder":
+ $this->response = new UpdateOrderResponse($message, $log);
+ break;
+ case "CreditInvoiceRows":
+ $this->response = new CreditInvoiceRowsResponse($message, $log);
+ break;
+ case "DeliverPartial":
+ $this->response = new DeliverPartialResponse($message, $log);
+ break;
+ case "CancelPaymentPlanRows":
+ $this->response = new CreditPaymentPlanResponse($message, $log);
+ break;
+ case "CancelPaymentPlanAmount":
+ $this->response = new CreditPaymentPlanResponse($message, $log);
+ break;
+ case "CancelAccountCreditAmount":
+ $this->response = new CancelAccountCreditAmount($message, $log);
+ break;
+ case "CancelAccountCreditRows":
+ $this->response = new CancelAccountCreditRows($message, $log);
+ break;
+ default:
+ throw new Exception("unknown method: $method");
+ break;
+ }
+ } // legacy fallback -- webservice from hosted_admin -- used by preparedpayment
+ elseif (property_exists($message, "message"))
+ {
+ $this->response = new HostedAdminResponse($message, $countryCode, $config);
+ }
+ } // webservice hosted payment
+ elseif ($message != NULL)
+ {
+ $this->response = new HostedPaymentResponse($message, $countryCode, $config);
+ }
+ else
+ {
+ $this->response = "Response is not recognized.";
+ }
+ }
- /**
- * Returns an instance of the corresponding service response object class (see constructor above)
- *
- * @return mixed
- */
- public function getResponse()
- {
- return $this->response;
- }
+ /**
+ * Returns an instance of the corresponding service response object class (see constructor above)
+ *
+ * @return mixed
+ */
+ public function getResponse()
+ {
+ return $this->response;
+ }
}
diff --git a/src/WebPay.php b/src/WebPay.php
index 6669261e..2d6e041e 100644
--- a/src/WebPay.php
+++ b/src/WebPay.php
@@ -54,298 +54,298 @@
class WebPay
{
- /**
- * Use Svea\WebPay\WebPay::createOrder() to create an order using invoice, payment plan, card, or direct bank payment methods.
- *
- * See the CreateOrderBuilder class for more info on methods used to specify the order builder contents
- * and chosing a payment method to use, followed by sending the request to Svea and parsing the response.
- *
- * Invoice and Payment plan orders will perform a synchronous payment on doRequest(), and will return a response
- * object immediately.
- *
- * Card, Direct bank, and other hosted methods accessed via PayPage are asynchronous. They provide an html form
- * containing a formatted message to send to Svea, which in turn will send a request response to a given return url,
- * where the response can be parsed using the Svea\WebPay\Response\SveaResponse class.
- *
- * $order = Svea\WebPay\WebPay::createOrder($config)
- * ->addOrderRow( $orderrow ) // required, see Svea\WebPay\WebPayItem::orderRow
- * ->addFee( $shippingfee ) // optional, see Svea\WebPay\WebPayItem for invoice, shipping fee
- * ->addDiscount( $discount ) // optional, see Svea\WebPay\WebPayItem for fixed, relative discount
- * ->addCustomerDetails( $customer ) // required for invoice and payment plan payments, see Svea\WebPay\WebPayItem for individual, company id.
- * ->setCountryCode("SE") // required
- * ->setOrderDate(date('c')) // required for invoice and payment plan payments
- * ->setCurrency("SEK") // required for card payment, direct bank & PayPage payments. Ignored for invoice and payment plan.
- * ->setClientOrderNumber("A123456") // required for card payment, direct payment, Svea\WebPay\Constant\PaymentMethod & PayPage payments, max length 30 chars.
- * ->setCustomerReference("att: kgm") // optional, ignored for card & direct bank orders, max length 30 chars.
- * ;
- *
- * @see \Svea\OrderRow \Svea\WebPay\BuildOrder\RowBuilders\OrderRow
- * @see \Svea\InvoiceFee \Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee
- * @see \Svea\ShippingFee \Svea\WebPay\BuildOrder\RowBuilders\ShippingFee
- * @see \Svea\FixedDiscount \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount
- * @see \Svea\Relativeiscount \Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount
- * @see \Svea\IndividualCustomer \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer
- * @see \Svea\CompanyCustomer \Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer
- * @return \Svea\WebPay\BuildOrder\CreateOrderBuilder
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider Interface
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- *
- */
- public static function createOrder($config = NULL)
- {
- if ($config == NULL) {
- WebPay::throwMissingConfigException();
- }
+ /**
+ * Use Svea\WebPay\WebPay::createOrder() to create an order using invoice, payment plan, card, or direct bank payment methods.
+ *
+ * See the CreateOrderBuilder class for more info on methods used to specify the order builder contents
+ * and chosing a payment method to use, followed by sending the request to Svea and parsing the response.
+ *
+ * Invoice and Payment plan orders will perform a synchronous payment on doRequest(), and will return a response
+ * object immediately.
+ *
+ * Card, Direct bank, and other hosted methods accessed via PayPage are asynchronous. They provide an html form
+ * containing a formatted message to send to Svea, which in turn will send a request response to a given return url,
+ * where the response can be parsed using the Svea\WebPay\Response\SveaResponse class.
+ *
+ * $order = Svea\WebPay\WebPay::createOrder($config)
+ * ->addOrderRow( $orderrow ) // required, see Svea\WebPay\WebPayItem::orderRow
+ * ->addFee( $shippingfee ) // optional, see Svea\WebPay\WebPayItem for invoice, shipping fee
+ * ->addDiscount( $discount ) // optional, see Svea\WebPay\WebPayItem for fixed, relative discount
+ * ->addCustomerDetails( $customer ) // required for invoice and payment plan payments, see Svea\WebPay\WebPayItem for individual, company id.
+ * ->setCountryCode("SE") // required
+ * ->setOrderDate(date('c')) // required for invoice and payment plan payments
+ * ->setCurrency("SEK") // required for card payment, direct bank & PayPage payments. Ignored for invoice and payment plan.
+ * ->setClientOrderNumber("A123456") // required for card payment, direct payment, Svea\WebPay\Constant\PaymentMethod & PayPage payments, max length 30 chars.
+ * ->setCustomerReference("att: kgm") // optional, ignored for card & direct bank orders, max length 30 chars.
+ * ;
+ *
+ * @see \Svea\OrderRow \Svea\WebPay\BuildOrder\RowBuilders\OrderRow
+ * @see \Svea\InvoiceFee \Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee
+ * @see \Svea\ShippingFee \Svea\WebPay\BuildOrder\RowBuilders\ShippingFee
+ * @see \Svea\FixedDiscount \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount
+ * @see \Svea\Relativeiscount \Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount
+ * @see \Svea\IndividualCustomer \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer
+ * @see \Svea\CompanyCustomer \Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer
+ * @return \Svea\WebPay\BuildOrder\CreateOrderBuilder
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider Interface
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ *
+ */
+ public static function createOrder($config = NULL)
+ {
+ if ($config == NULL) {
+ WebPay::throwMissingConfigException();
+ }
- return new CreateOrderBuilder($config);
- }
+ return new CreateOrderBuilder($config);
+ }
- /**
- * Helper function, throws exception if no config is given.
- *
- * @throws ValidationException
- */
- private static function throwMissingConfigException()
- {
- throw new ValidationException('-missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.');
- }
+ /**
+ * Helper function, throws exception if no config is given.
+ *
+ * @throws ValidationException
+ */
+ private static function throwMissingConfigException()
+ {
+ throw new ValidationException('-missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.');
+ }
- /**
- * Use the Svea\WebPay\WebPay::deliverOrder() entrypoint when you deliver an order to the customer.
- * Supports Invoice, Payment Plan and Card orders. (Direct Bank orders are not supported.)
- *
- * The deliver order request should generally be sent to Svea once the ordered
- * items have been sent out, or otherwise delivered, to the customer.
- *
- * For invoice and partpayment orders, the deliver order request triggers the
- * invoice being sent out to the customer by Svea. (This assumes that your account
- * has auto-approval of invoices turned on, please contact Svea if unsure).
- *
- * For card orders, the deliver order request confirms the card transaction,
- * which in turn allows nightly batch processing of the transaction by Svea.
- * (Delivering card orders is only needed if your account has auto-confirm
- * turned off, please contact Svea if unsure.)
- *
- * To deliver an invoice, partpayment or card order in full, you do not need to
- * specify order rows. To partially deliver an order, the recommended way is to
- * use Svea\WebPay\WebPayAdmin::deliverOrderRows().
- *
- * Get an order builder instance using the Svea\WebPay\WebPay::deliverOrder entrypoint, then
- * provide more information about the transaction using DeliverOrderBuilder methods:
- *
- * $request = Svea\WebPay\WebPay::deliverOrder($config)
- * ->setOrderId() // invoice or payment plan only, required
- * ->setTransactionId() // card only, optional, alias for setOrderId
- * ->setCountryCode() // required
- * ->setInvoiceDistributionType() // invoice only, required
- * ->setNumberOfCreditDays() // invoice only, optional
- * ->setCaptureDate() // card only, optional
- * ->addOrderRow() // deprecated, optional -- use Svea\WebPay\WebPayAdmin::deliverOrderRows instead
- * ->setCreditInvoice() // deprecated, optional -- use Svea\WebPay\WebPayAdmin::creditOrderRows instead
- * ;
- * // then select the corresponding request class and send request
- * $response = $request->deliverInvoiceOrder()->doRequest(); // returns DeliverOrdersResponse (no rows) or DeliverOrderResult (with rows)
- * $response = $request->deliverPaymentPlanOrder()->doRequest(); // returns DeliverOrdersResponse (no rows) or DeliverOrderResult (with rows)
- * $response = $request->deliverCardOrder()->doRequest(); // returns ConfirmTransactionResponse
- *
- * @see \Svea\WebPay\DeliverOrderBuilder \Svea\WebPay\BuildOrder\DeliverOrderBuilder
- * @see \Svea\WebPay\AdminService\DeliverOrdersResponse \Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse
- * @see \Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult
- * @see \Svea\WebPay\HostedService\ConfirmTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse
- *
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider Interface
- * @return \Svea\WebPay\BuildOrder\DeliverOrderBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function deliverOrder($config = NULL)
- {
- if ($config == NULL) {
- WebPay::throwMissingConfigException();
- }
+ /**
+ * Use the Svea\WebPay\WebPay::deliverOrder() entrypoint when you deliver an order to the customer.
+ * Supports Invoice, Payment Plan and Card orders. (Direct Bank orders are not supported.)
+ *
+ * The deliver order request should generally be sent to Svea once the ordered
+ * items have been sent out, or otherwise delivered, to the customer.
+ *
+ * For invoice and partpayment orders, the deliver order request triggers the
+ * invoice being sent out to the customer by Svea. (This assumes that your account
+ * has auto-approval of invoices turned on, please contact Svea if unsure).
+ *
+ * For card orders, the deliver order request confirms the card transaction,
+ * which in turn allows nightly batch processing of the transaction by Svea.
+ * (Delivering card orders is only needed if your account has auto-confirm
+ * turned off, please contact Svea if unsure.)
+ *
+ * To deliver an invoice, partpayment or card order in full, you do not need to
+ * specify order rows. To partially deliver an order, the recommended way is to
+ * use Svea\WebPay\WebPayAdmin::deliverOrderRows().
+ *
+ * Get an order builder instance using the Svea\WebPay\WebPay::deliverOrder entrypoint, then
+ * provide more information about the transaction using DeliverOrderBuilder methods:
+ *
+ * $request = Svea\WebPay\WebPay::deliverOrder($config)
+ * ->setOrderId() // invoice or payment plan only, required
+ * ->setTransactionId() // card only, optional, alias for setOrderId
+ * ->setCountryCode() // required
+ * ->setInvoiceDistributionType() // invoice only, required
+ * ->setNumberOfCreditDays() // invoice only, optional
+ * ->setCaptureDate() // card only, optional
+ * ->addOrderRow() // deprecated, optional -- use Svea\WebPay\WebPayAdmin::deliverOrderRows instead
+ * ->setCreditInvoice() // deprecated, optional -- use Svea\WebPay\WebPayAdmin::creditOrderRows instead
+ * ;
+ * // then select the corresponding request class and send request
+ * $response = $request->deliverInvoiceOrder()->doRequest(); // returns DeliverOrdersResponse (no rows) or DeliverOrderResult (with rows)
+ * $response = $request->deliverPaymentPlanOrder()->doRequest(); // returns DeliverOrdersResponse (no rows) or DeliverOrderResult (with rows)
+ * $response = $request->deliverCardOrder()->doRequest(); // returns ConfirmTransactionResponse
+ *
+ * @see \Svea\WebPay\DeliverOrderBuilder \Svea\WebPay\BuildOrder\DeliverOrderBuilder
+ * @see \Svea\WebPay\AdminService\DeliverOrdersResponse \Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse
+ * @see \Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult
+ * @see \Svea\WebPay\HostedService\ConfirmTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse
+ *
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider Interface
+ * @return \Svea\WebPay\BuildOrder\DeliverOrderBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function deliverOrder($config = NULL)
+ {
+ if ($config == NULL) {
+ WebPay::throwMissingConfigException();
+ }
- return new DeliverOrderBuilder($config);
- }
+ return new DeliverOrderBuilder($config);
+ }
- /**
- * The Svea\WebPay\WebPay::getAddresses() entrypoint is used to fetch a list validated addresses
- * associated with a given customer identity. This list can in turn be used to i.e.
- * verify that an order delivery address matches the invoice address used by Svea for
- * invoice and payment plan orders. Only applicable for SE, NO and DK customers.
- * Note that in Norway, company customers only are supported.
- *
- * Get an request class instance using the Svea\WebPay\WebPay::getAddresses entrypoint, then
- * provide more information about the transaction and send the request using the
- * request class methods:
- *
- * Use setCountryCode() to supply the country code that corresponds to the account
- * credentials used for the address lookup. Note that this means that you cannot
- * look up a user in a foreign country, this is a consequence of the fact that the
- * invoice and partpayment methods don't support foreign orders.
- *
- * Use setCustomerIdentifier() to provide the exact credentials needed to identify
- * the customer according to country:
- * SE: Personnummer (private individual) or Organisationsnummer (company/legal entity)
- * NO: Organisasjonsnummer (company or other legal entity)
- * DK: Cpr.nr (private individual) or CVR-nummer (company or other legal entity)
- *
- * Then use either getIndividualAddresses() or getCompanyAddresses() depending on what kind of customer you want to look up.
- *
- * The final doRequest() will send the getAddresses request to Svea and return the result.
- *
- * The doRequest() method will then check if there exists credentials to use for the request in the given configurationProvider.
- *
- * (Note that this behaviour may cause problems if your integration is set to use different (test/production) credentials
- * for invoice and payment plan -- if you get an error and this is the case, you may use one of the deprecated methods
- * setOrderTypeInvoice() or setOrderTupePaymentPlan() to explicity state which method credentials to use.)
- *
- * $request = Svea\WebPay\WebPay::getAddresses($config)
- * ->setCountryCode() // required -- the country to perform the customer address lookup in
- * ->setCustomerIdentifier() // required -- social security number, company vat number etc. used to identify customer
- * ->setOrderTypeInvoice() // deprecated -- method that corresponds to the Svea\WebPay\Config\ConfigurationProvider account credentials used
- * ->setOrderTypePaymentPlan() // deprecated -- method that corresponds to the Svea\WebPay\Config\ConfigurationProvider account credentials used
- * ;
- * // then select the corresponding request class and send request
- * $response = $request->getIndividualAddresses()->doRequest(); // returns GetAddressesResponse
- * $response = $request->getCompanyAddresses()->doRequest(); // returns GetAddressesResponse
- *
- * @see Svea\WebPay\WebService\GetAddress\GetAddress
- * @return \Svea\WebPay\WebService\GetAddress\GetAddresses
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider Interface
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function getAddresses($config = NULL)
- {
- if ($config == NULL) {
- WebPay::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPay::getAddresses() entrypoint is used to fetch a list validated addresses
+ * associated with a given customer identity. This list can in turn be used to i.e.
+ * verify that an order delivery address matches the invoice address used by Svea for
+ * invoice and payment plan orders. Only applicable for SE, NO and DK customers.
+ * Note that in Norway, company customers only are supported.
+ *
+ * Get an request class instance using the Svea\WebPay\WebPay::getAddresses entrypoint, then
+ * provide more information about the transaction and send the request using the
+ * request class methods:
+ *
+ * Use setCountryCode() to supply the country code that corresponds to the account
+ * credentials used for the address lookup. Note that this means that you cannot
+ * look up a user in a foreign country, this is a consequence of the fact that the
+ * invoice and partpayment methods don't support foreign orders.
+ *
+ * Use setCustomerIdentifier() to provide the exact credentials needed to identify
+ * the customer according to country:
+ * SE: Personnummer (private individual) or Organisationsnummer (company/legal entity)
+ * NO: Organisasjonsnummer (company or other legal entity)
+ * DK: Cpr.nr (private individual) or CVR-nummer (company or other legal entity)
+ *
+ * Then use either getIndividualAddresses() or getCompanyAddresses() depending on what kind of customer you want to look up.
+ *
+ * The final doRequest() will send the getAddresses request to Svea and return the result.
+ *
+ * The doRequest() method will then check if there exists credentials to use for the request in the given configurationProvider.
+ *
+ * (Note that this behaviour may cause problems if your integration is set to use different (test/production) credentials
+ * for invoice and payment plan -- if you get an error and this is the case, you may use one of the deprecated methods
+ * setOrderTypeInvoice() or setOrderTupePaymentPlan() to explicity state which method credentials to use.)
+ *
+ * $request = Svea\WebPay\WebPay::getAddresses($config)
+ * ->setCountryCode() // required -- the country to perform the customer address lookup in
+ * ->setCustomerIdentifier() // required -- social security number, company vat number etc. used to identify customer
+ * ->setOrderTypeInvoice() // deprecated -- method that corresponds to the Svea\WebPay\Config\ConfigurationProvider account credentials used
+ * ->setOrderTypePaymentPlan() // deprecated -- method that corresponds to the Svea\WebPay\Config\ConfigurationProvider account credentials used
+ * ;
+ * // then select the corresponding request class and send request
+ * $response = $request->getIndividualAddresses()->doRequest(); // returns GetAddressesResponse
+ * $response = $request->getCompanyAddresses()->doRequest(); // returns GetAddressesResponse
+ *
+ * @see Svea\WebPay\WebService\GetAddress\GetAddress
+ * @return \Svea\WebPay\WebService\GetAddress\GetAddresses
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider Interface
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function getAddresses($config = NULL)
+ {
+ if ($config == NULL) {
+ WebPay::throwMissingConfigException();
+ }
- return new GetAddresses($config);
- }
+ return new GetAddresses($config);
+ }
- /**
- * getPaymentPlanParams -- fetch current campaigns (payment plans) for a given client, used by i.e. paymentplan orders
- *
- * See the GetPaymentPlanParams request class for more info on required methods,
- * how to send the request to Svea, as well as the final response type.
- *
- * @return \Svea\WebPay\WebService\GetPaymentPlanParams\GetPaymentPlanParams
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function getPaymentPlanParams($config = NULL)
- {
- if ($config == NULL) {
- WebPay::throwMissingConfigException();
- }
+ /**
+ * getPaymentPlanParams -- fetch current campaigns (payment plans) for a given client, used by i.e. paymentplan orders
+ *
+ * See the GetPaymentPlanParams request class for more info on required methods,
+ * how to send the request to Svea, as well as the final response type.
+ *
+ * @return \Svea\WebPay\WebService\GetPaymentPlanParams\GetPaymentPlanParams
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function getPaymentPlanParams($config = NULL)
+ {
+ if ($config == NULL) {
+ WebPay::throwMissingConfigException();
+ }
- return new GetPaymentPlanParams($config);
- }
+ return new GetPaymentPlanParams($config);
+ }
- /**
- * getAccountCreditParams -- fetch current campaigns (AccountCredit) for the given client, used by i.e. accountCredit orders
- *
- * See the GetAccountCreditParams request class for more info on required methods,
- * how to send the request to Svea, as well as the final response type.
- *
- * @return \Svea\WebPay\WebService\GetAccountCreditParams\GetAccountCreditParams
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function getAccountCreditParams($config = NULL)
- {
- if ($config == NULL) {
- WebPay::throwMissingConfigException();
- }
+ /**
+ * getAccountCreditParams -- fetch current campaigns (AccountCredit) for the given client, used by i.e. accountCredit orders
+ *
+ * See the GetAccountCreditParams request class for more info on required methods,
+ * how to send the request to Svea, as well as the final response type.
+ *
+ * @return \Svea\WebPay\WebService\GetAccountCreditParams\GetAccountCreditParams
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function getAccountCreditParams($config = NULL)
+ {
+ if ($config == NULL) {
+ WebPay::throwMissingConfigException();
+ }
- return new GetAccountCreditParams($config);
- }
+ return new GetAccountCreditParams($config);
+ }
- /**
- * getPaymentMethods -- fetch available payment methods for a given client, used to define i.e. paymentmethod in payments
- *
- * See the GetPaymentMethods request class for more info on required methods,
- * how to send the request to Svea, as well as the final response type.
- *
- * @deprecated 2.0.0 use Svea\WebPay\WebPayAdmin::listPaymentMethods() instead, which returns a response object instead of an array
- * @see \Svea\WebPay\HostedService\HostedAdminRequest\ListPaymentMethods() \Svea\WebPay\HostedService\HostedAdminRequest\ListPaymentMethods()
- *
- * @param \Svea\WebPay\Config\ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return string[] array of available paymentmethods for this Svea\WebPay\Config\ConfigurationProvider
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function getPaymentMethods($config = NULL)
- {
- if ($config == NULL) {
- WebPay::throwMissingConfigException();
- }
+ /**
+ * getPaymentMethods -- fetch available payment methods for a given client, used to define i.e. paymentmethod in payments
+ *
+ * See the GetPaymentMethods request class for more info on required methods,
+ * how to send the request to Svea, as well as the final response type.
+ *
+ * @deprecated 2.0.0 use Svea\WebPay\WebPayAdmin::listPaymentMethods() instead, which returns a response object instead of an array
+ * @see \Svea\WebPay\HostedService\HostedAdminRequest\ListPaymentMethods() \Svea\WebPay\HostedService\HostedAdminRequest\ListPaymentMethods()
+ *
+ * @param \Svea\WebPay\Config\ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return string[] array of available paymentmethods for this Svea\WebPay\Config\ConfigurationProvider
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function getPaymentMethods($config = NULL)
+ {
+ if ($config == NULL) {
+ WebPay::throwMissingConfigException();
+ }
- return new GetPaymentMethods($config);
- }
+ return new GetPaymentMethods($config);
+ }
- /** @deprecated -- use Helper::paymentPlanPricePerMonth() instead */
- public static function paymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag = false)
- {
- return new PaymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag);
- }
+ /** @deprecated -- use Helper::paymentPlanPricePerMonth() instead */
+ public static function paymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag = false)
+ {
+ return new PaymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag);
+ }
- /**
- * Start building Request to close orders. Only supports Invoice or Payment plan orders.
- * @deprecated 2.0.0 -- use Svea\WebPay\WebPayAdmin::cancelOrder instead, which supports both synchronous and asynchronous orders
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return \Svea\WebPay\BuildOrder\CloseOrderBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function closeOrder($config = NULL)
- {
- if ($config == NULL) {
- WebPay::throwMissingConfigException();
- }
+ /**
+ * Start building Request to close orders. Only supports Invoice or Payment plan orders.
+ * @deprecated 2.0.0 -- use Svea\WebPay\WebPayAdmin::cancelOrder instead, which supports both synchronous and asynchronous orders
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return \Svea\WebPay\BuildOrder\CloseOrderBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function closeOrder($config = NULL)
+ {
+ if ($config == NULL) {
+ WebPay::throwMissingConfigException();
+ }
- return new CloseOrderBuilder($config);
- }
+ return new CloseOrderBuilder($config);
+ }
- /**
- * @param null $config
- * @return CheckoutOrderEntry
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function checkout($config = null)
- {
- if ($config === null) {
- WebPay::throwMissingConfigException();
- }
+ /**
+ * @param null $config
+ * @return CheckoutOrderEntry
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function checkout($config = null)
+ {
+ if ($config === null) {
+ WebPay::throwMissingConfigException();
+ }
- $checkoutOrderBuilder = new CheckoutOrderBuilder($config);
+ $checkoutOrderBuilder = new CheckoutOrderBuilder($config);
- return new CheckoutOrderEntry($checkoutOrderBuilder);
- }
+ return new CheckoutOrderEntry($checkoutOrderBuilder);
+ }
- /**
- * The Svea\WebPay\WebPay::listPaymentMethods method is used to fetch all available paymentmethods configured for a given country.
- *
- * Use the Svea\WebPay\WebPay::listPaymentMethods() entrypoint to get an instance of
- * ListPaymentMethods. Then provide more information about the transaction and
- * send the request using ListPaymentMethod methods.
- *
- * $methods = Svea\WebPay\WebPay::listPaymentMethods( $config )
- * ->setCountryCode("SE") // required
- * ->doRequest();
- *
- * Following the ->doRequest call you receive an instance of ListPaymentMethodsResponse.
- *
- * @see \Svea\WebPay\HostedService\ListPaymentMethods \Svea\WebPay\HostedService\HostedAdminRequest\ListPaymentMethods
- * @see \Svea\WebPay\HostedService\ListPaymentMethodsResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ListPaymentMethodsResponse
- *
- * @param ConfigurationProvider $config
- * @return \Svea\WebPay\HostedService\HostedAdminRequest\ListPaymentMethods
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- static function listPaymentMethods($config)
- {
- if ($config == NULL) {
- WebPay::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPay::listPaymentMethods method is used to fetch all available paymentmethods configured for a given country.
+ *
+ * Use the Svea\WebPay\WebPay::listPaymentMethods() entrypoint to get an instance of
+ * ListPaymentMethods. Then provide more information about the transaction and
+ * send the request using ListPaymentMethod methods.
+ *
+ * $methods = Svea\WebPay\WebPay::listPaymentMethods( $config )
+ * ->setCountryCode("SE") // required
+ * ->doRequest();
+ *
+ * Following the ->doRequest call you receive an instance of ListPaymentMethodsResponse.
+ *
+ * @see \Svea\WebPay\HostedService\ListPaymentMethods \Svea\WebPay\HostedService\HostedAdminRequest\ListPaymentMethods
+ * @see \Svea\WebPay\HostedService\ListPaymentMethodsResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ListPaymentMethodsResponse
+ *
+ * @param ConfigurationProvider $config
+ * @return \Svea\WebPay\HostedService\HostedAdminRequest\ListPaymentMethods
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ static function listPaymentMethods($config)
+ {
+ if ($config == NULL) {
+ WebPay::throwMissingConfigException();
+ }
- return new ListPaymentMethods($config);
- }
+ return new ListPaymentMethods($config);
+ }
}
diff --git a/src/WebPayAdmin.php b/src/WebPayAdmin.php
index a7624330..3efc4d77 100644
--- a/src/WebPayAdmin.php
+++ b/src/WebPayAdmin.php
@@ -54,456 +54,456 @@
class WebPayAdmin
{
- /**
- * The Svea\WebPay\WebPayAdmin::cancelOrder() entrypoint method is used to cancel an order with Svea,
- * that has not yet been delivered (invoice, payment plan) or confirmed (card).
- *
- * Supports Invoice, Payment Plan and Card orders. For Direct Bank orders, use Svea\WebPay\WebPayAdmin::creditOrderRows() instead.
- *
- * Get an instance using the Svea\WebPay\WebPayAdmin::cancelOrder entrypoint, then provide more information about the order and send
- * the request using the CancelOrderBuilder methods:
- *
- * ...
- * $request = Svea\WebPay\WebPayAdmin->cancelOrder($config)
- * ->setOrderId() // required, use SveaOrderId recieved with createOrder response
- * ->setTransactionId() // optional, card or direct bank only, alias for setOrderId
- * ->setCountryCode() // required, use same country code as in createOrder request
- * ;
- * // then select the corresponding request class and send request
- * $response = $request->cancelInvoiceOrder()->doRequest(); // returns CloseOrderResponse
- * $response = $request->cancelPaymentPlanOrder()->doRequest(); // returns CloseOrderResponse
- * $response = $request->cancelCardOrder()->doRequest(); // returns AnnulTransactionResponse
- * ...
- *
- * @see \Svea\CancelOrderBuilder \Svea\WebPay\BuildOrder\CancelOrderBuilder
- * @see \Svea\WebService\CloseOrderResult Svea\WebPay\WebService\WebServiceResponse\CloseOrderResult
- * @see \Svea\HostedService\AnnulTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\AnnulTransactionResponse
- *
- * @param \Svea\WebPay\Config\ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return \Svea\WebPay\BuildOrder\CancelOrderBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function cancelOrder($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPayAdmin::cancelOrder() entrypoint method is used to cancel an order with Svea,
+ * that has not yet been delivered (invoice, payment plan) or confirmed (card).
+ *
+ * Supports Invoice, Payment Plan and Card orders. For Direct Bank orders, use Svea\WebPay\WebPayAdmin::creditOrderRows() instead.
+ *
+ * Get an instance using the Svea\WebPay\WebPayAdmin::cancelOrder entrypoint, then provide more information about the order and send
+ * the request using the CancelOrderBuilder methods:
+ *
+ * ...
+ * $request = Svea\WebPay\WebPayAdmin->cancelOrder($config)
+ * ->setOrderId() // required, use SveaOrderId recieved with createOrder response
+ * ->setTransactionId() // optional, card or direct bank only, alias for setOrderId
+ * ->setCountryCode() // required, use same country code as in createOrder request
+ * ;
+ * // then select the corresponding request class and send request
+ * $response = $request->cancelInvoiceOrder()->doRequest(); // returns CloseOrderResponse
+ * $response = $request->cancelPaymentPlanOrder()->doRequest(); // returns CloseOrderResponse
+ * $response = $request->cancelCardOrder()->doRequest(); // returns AnnulTransactionResponse
+ * ...
+ *
+ * @see \Svea\CancelOrderBuilder \Svea\WebPay\BuildOrder\CancelOrderBuilder
+ * @see \Svea\WebService\CloseOrderResult Svea\WebPay\WebService\WebServiceResponse\CloseOrderResult
+ * @see \Svea\HostedService\AnnulTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\AnnulTransactionResponse
+ *
+ * @param \Svea\WebPay\Config\ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return \Svea\WebPay\BuildOrder\CancelOrderBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function cancelOrder($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new CancelOrderBuilder($config);
- }
+ return new CancelOrderBuilder($config);
+ }
- /** helper function, throws exception if no config is given */
- private static function throwMissingConfigException()
- {
- throw new ValidationException('-missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider
- object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider.
- Set returnvalues to configuration values. Create an object from that class.
- Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig().
- You can replace the default config values into config files to return your own config values.');
- }
+ /** helper function, throws exception if no config is given */
+ private static function throwMissingConfigException()
+ {
+ throw new ValidationException('-missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider
+ object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider.
+ Set returnvalues to configuration values. Create an object from that class.
+ Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig().
+ You can replace the default config values into config files to return your own config values.');
+ }
- /**
- * The Svea\WebPay\WebPayAdmin::queryOrder entrypoint method is used to get information about an order.
- *
- * Note that for invoice and payment plan orders, the order rows name and description is merged
- * into the description field in the query response.
- *
- * Get an instance using the Svea\WebPay\WebPayAdmin::queryOrder entrypoint, then provide more information
- * about the order and send the request using the QueryOrderBuilder methods:
- *
- * ...
- * $request = Svea\WebPay\WebPay::queryOrder($config)
- * ->setOrderId() // required, use SveaOrderId recieved with createOrder response
- * ->setTransactionId() // optional, card or direct bank only, alias for setOrderId
- * ->setCountryCode() // required, use same country code as in createOrder request
- * ;
- * // then select the corresponding request class and send request
- * $response = $request->queryInvoiceOrder()->doRequest(); // returns GetOrdersResponse
- * $response = $request->queryPaymentPlanOrder()->doRequest(); // returns GetOrdersResponse
- * $response = $request->queryCardOrder()->doRequest(); // returns QueryTransactionResponse
- * $response = $request->queryDirectBankOrder()->doRequest(); // returns QueryTransactionResponse
- * ...
- *
- * @see \Svea\QueryOrderBuilder \Svea\WebPay\BuildOrder\QueryOrderBuilder
- * @see \Svea\AdminService\GetOrdersResponse \Svea\WebPay\AdminService\AdminServiceResponse\GetOrdersResponse
- * @see \Svea\HostedService\QueryTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse
- *
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return \Svea\WebPay\BuildOrder\QueryOrderBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function queryOrder($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPayAdmin::queryOrder entrypoint method is used to get information about an order.
+ *
+ * Note that for invoice and payment plan orders, the order rows name and description is merged
+ * into the description field in the query response.
+ *
+ * Get an instance using the Svea\WebPay\WebPayAdmin::queryOrder entrypoint, then provide more information
+ * about the order and send the request using the QueryOrderBuilder methods:
+ *
+ * ...
+ * $request = Svea\WebPay\WebPay::queryOrder($config)
+ * ->setOrderId() // required, use SveaOrderId recieved with createOrder response
+ * ->setTransactionId() // optional, card or direct bank only, alias for setOrderId
+ * ->setCountryCode() // required, use same country code as in createOrder request
+ * ;
+ * // then select the corresponding request class and send request
+ * $response = $request->queryInvoiceOrder()->doRequest(); // returns GetOrdersResponse
+ * $response = $request->queryPaymentPlanOrder()->doRequest(); // returns GetOrdersResponse
+ * $response = $request->queryCardOrder()->doRequest(); // returns QueryTransactionResponse
+ * $response = $request->queryDirectBankOrder()->doRequest(); // returns QueryTransactionResponse
+ * ...
+ *
+ * @see \Svea\QueryOrderBuilder \Svea\WebPay\BuildOrder\QueryOrderBuilder
+ * @see \Svea\AdminService\GetOrdersResponse \Svea\WebPay\AdminService\AdminServiceResponse\GetOrdersResponse
+ * @see \Svea\HostedService\QueryTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse
+ *
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return \Svea\WebPay\BuildOrder\QueryOrderBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function queryOrder($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new QueryOrderBuilder($config);
- }
+ return new QueryOrderBuilder($config);
+ }
- /**
- * The Svea\WebPay\WebPayAdmin::cancelOrderRows entrypoint method is used to cancel rows in an order before it has been delivered.
- * Supports Invoice, AccountCredit, Payment Plan and Card orders. (Direct Bank orders are not supported, see CreditOrderRows instead.)
- *
- * For Invoice, AccountCredit and Payment Plan orders, the order row status is updated at Svea following each successful request.
- *
- * For card orders, the request can only be sent once, and if all original order rows are cancelled, the order then receives status ANNULLED at Svea.
- *
- * Get an instance using the Svea\WebPay\WebPayAdmin::queryOrder entrypoint, then provide more information about the order and
- * send the request using the queryOrderBuilder methods:
- *
- * Use setRowToCancel() or setRowsToCancel() to specify the order row(s) to cancel. The order row indexes should correspond to those returned by
- * i.e. Svea\WebPay\WebPayAdmin::queryOrder();
- *
- * For card orders, use addNumberedOrderRow() or addNumberedOrderRows() to pass in a copy of the original order rows. The original order rows can
- * be retrieved using Svea\WebPay\WebPayAdmin::queryOrder(); the numberedOrderRows attribute contains the serverside order rows w/indexes. Note that if a card
- * order has been modified (i.e. rows cancelled or credited) after the initial order creation, the returned order rows will not be accurate.
- *
- * ...
- * $request = Svea\WebPay\WebPayAdmin::cancelOrderRows($config)
- * ->setOrderId() // required
- * ->setTransactionId() // optional, card only, alias for setOrderId
- * ->setCountryCode() // required
- * ->setRowToCancel() // required, index of original order rows you wish to cancel
- * ->addNumberedOrderRow() // required for card orders, should match original row indexes
- * ;
- * // then select the corresponding request class and send request
- * $response = $request->deliverInvoiceOrderRows()->doRequest(); // returns CancelOrderRowsResponse
- * $response = $request->deliverPaymentPlanOrderRows()->doRequest(); // returns CancelOrderRowsResponse
- * $response = $request->deliverCardOrderRows()->doRequest(); // returns LowerTransactionResponse
- * ...
- *
- * @see \Svea\CancelOrderRowsBuilder \Svea\WebPay\BuildOrder\CancelOrderRowsBuilder
- * @see \Svea\AdminService\CancelOrderRowsResponse \Svea\WebPay\AdminService\AdminServiceResponse\CancelOrderRowsResponse
- * @see \Svea\HostedService\LowerTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\LowerTransactionResponse
- *
- * @param \Svea\WebPay\Config\ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return \Svea\WebPay\BuildOrder\CancelOrderRowsBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function cancelOrderRows($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPayAdmin::cancelOrderRows entrypoint method is used to cancel rows in an order before it has been delivered.
+ * Supports Invoice, AccountCredit, Payment Plan and Card orders. (Direct Bank orders are not supported, see CreditOrderRows instead.)
+ *
+ * For Invoice, AccountCredit and Payment Plan orders, the order row status is updated at Svea following each successful request.
+ *
+ * For card orders, the request can only be sent once, and if all original order rows are cancelled, the order then receives status ANNULLED at Svea.
+ *
+ * Get an instance using the Svea\WebPay\WebPayAdmin::queryOrder entrypoint, then provide more information about the order and
+ * send the request using the queryOrderBuilder methods:
+ *
+ * Use setRowToCancel() or setRowsToCancel() to specify the order row(s) to cancel. The order row indexes should correspond to those returned by
+ * i.e. Svea\WebPay\WebPayAdmin::queryOrder();
+ *
+ * For card orders, use addNumberedOrderRow() or addNumberedOrderRows() to pass in a copy of the original order rows. The original order rows can
+ * be retrieved using Svea\WebPay\WebPayAdmin::queryOrder(); the numberedOrderRows attribute contains the serverside order rows w/indexes. Note that if a card
+ * order has been modified (i.e. rows cancelled or credited) after the initial order creation, the returned order rows will not be accurate.
+ *
+ * ...
+ * $request = Svea\WebPay\WebPayAdmin::cancelOrderRows($config)
+ * ->setOrderId() // required
+ * ->setTransactionId() // optional, card only, alias for setOrderId
+ * ->setCountryCode() // required
+ * ->setRowToCancel() // required, index of original order rows you wish to cancel
+ * ->addNumberedOrderRow() // required for card orders, should match original row indexes
+ * ;
+ * // then select the corresponding request class and send request
+ * $response = $request->deliverInvoiceOrderRows()->doRequest(); // returns CancelOrderRowsResponse
+ * $response = $request->deliverPaymentPlanOrderRows()->doRequest(); // returns CancelOrderRowsResponse
+ * $response = $request->deliverCardOrderRows()->doRequest(); // returns LowerTransactionResponse
+ * ...
+ *
+ * @see \Svea\CancelOrderRowsBuilder \Svea\WebPay\BuildOrder\CancelOrderRowsBuilder
+ * @see \Svea\AdminService\CancelOrderRowsResponse \Svea\WebPay\AdminService\AdminServiceResponse\CancelOrderRowsResponse
+ * @see \Svea\HostedService\LowerTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\LowerTransactionResponse
+ *
+ * @param \Svea\WebPay\Config\ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return \Svea\WebPay\BuildOrder\CancelOrderRowsBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function cancelOrderRows($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new CancelOrderRowsBuilder($config);
- }
+ return new CancelOrderRowsBuilder($config);
+ }
- /**
- * The Svea\WebPay\WebPayAdmin::creditOrderRows entrypoint method is used to credit rows in an order after it has been delivered.
- * Supports invoice, PaymentPlan, card and direct bank orders.
- * (To credit a payment plan order, please contact Svea customer service first.)
- *
- * If you wish to credit an amount not present in the original order, use addCreditOrderRow() or addCreditOrderRows()
- * and supply a new order row for the amount to credit. This is the recommended way to credit a card or direct bank order.
- *
- * If you wish to credit an invoice or Payment Plan order row in full, you can specify the index of the order row to credit using setRowToCredit().
- * The corresponding order row at Svea will then be credited. (For card or direct bank orders you need to first query and then
- * supply the corresponding numbered order rows using the addNumberedOrderRows() method.)
- *
- * Following the request Svea will issue a credit invoice including the original order rows specified using setRowToCredit(),
- * as well as any new credit order rows specified using addCreditOrderRow(). For card or direct bank orders, the order row amount
- * will be credited to the customer.
- *
- * Get an order builder instance using the Svea\WebPay\WebPayAdmin::creditOrderRows entrypoint, then provide more information about the
- * transaction and send the request using the creditOrderRowsBuilder methods:
- *
- * ...
- * $request = Svea\WebPay\WebPay::creditOrder($config)
- * ->setInvoiceId() // invoice only, required
- * ->setInvoiceDistributionType() // invoice only, required
- * ->setContractNumber() // Paymentplan only, required
- * ->setOrderId() // card and direct bank only, required
- * ->setCountryCode() // required
- * ->addCreditOrderRow() // optional, use to specify a new credit row, i.e. for amounts not present in the original order
- * ->addCreditOrderRows() // optional
- * ->setRowToCredit() // optional, index of one of the original order row you wish to credit
- * ->setRowsToCredit() // optional
- * ->addNumberedOrderRow() // card and direct bank only, required with setRowToCredit()
- * ->addNumberedOrderRows() // card and direct bank only, optional
- * ;
- * // then select the corresponding request class and send request
- * $response = $request->creditInvoiceOrderRows()->doRequest(); // returns CreditInvoiceRowsResponse
- * $response = $request->creditPaymentplanOrderRows()->doRequest(); // returns CreditPaymentPlanRowsRequest
- * $response = $request->creditCardOrderRows()->doRequest(); // returns CreditTransactionResponse
- * $response = $request->creditDirectBankOrderRows()->doRequest(); // returns CreditTransactionResponse
- * ...
- *
- * @param ConfigurationProvider $config
- * @return \Svea\WebPay\BuildOrder\CreditOrderRowsBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- *
- * @see \Svea\CreditOrderRowsBuilder \Svea\WebPay\BuildOrder\CreditOrderRowsBuilder
- * @see \Svea\AdminService\CreditInvoiceRowsResponse \Svea\WebPay\AdminService\AdminServiceResponse\CreditInvoiceRowsResponse
- * @see \Svea\AdminService\CreditPaymentPlanResponse \Svea\WebPay\AdminService\AdminServiceResponse\CreditPaymentPlanResponse
- * @see \Svea\HostedService\CreditTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse
- *
- * @author Kristian Grossman-Madsen for Svea Svea\WebPay\WebPay
- */
- public static function creditOrderRows($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPayAdmin::creditOrderRows entrypoint method is used to credit rows in an order after it has been delivered.
+ * Supports invoice, PaymentPlan, card and direct bank orders.
+ * (To credit a payment plan order, please contact Svea customer service first.)
+ *
+ * If you wish to credit an amount not present in the original order, use addCreditOrderRow() or addCreditOrderRows()
+ * and supply a new order row for the amount to credit. This is the recommended way to credit a card or direct bank order.
+ *
+ * If you wish to credit an invoice or Payment Plan order row in full, you can specify the index of the order row to credit using setRowToCredit().
+ * The corresponding order row at Svea will then be credited. (For card or direct bank orders you need to first query and then
+ * supply the corresponding numbered order rows using the addNumberedOrderRows() method.)
+ *
+ * Following the request Svea will issue a credit invoice including the original order rows specified using setRowToCredit(),
+ * as well as any new credit order rows specified using addCreditOrderRow(). For card or direct bank orders, the order row amount
+ * will be credited to the customer.
+ *
+ * Get an order builder instance using the Svea\WebPay\WebPayAdmin::creditOrderRows entrypoint, then provide more information about the
+ * transaction and send the request using the creditOrderRowsBuilder methods:
+ *
+ * ...
+ * $request = Svea\WebPay\WebPay::creditOrder($config)
+ * ->setInvoiceId() // invoice only, required
+ * ->setInvoiceDistributionType() // invoice only, required
+ * ->setContractNumber() // Paymentplan only, required
+ * ->setOrderId() // card and direct bank only, required
+ * ->setCountryCode() // required
+ * ->addCreditOrderRow() // optional, use to specify a new credit row, i.e. for amounts not present in the original order
+ * ->addCreditOrderRows() // optional
+ * ->setRowToCredit() // optional, index of one of the original order row you wish to credit
+ * ->setRowsToCredit() // optional
+ * ->addNumberedOrderRow() // card and direct bank only, required with setRowToCredit()
+ * ->addNumberedOrderRows() // card and direct bank only, optional
+ * ;
+ * // then select the corresponding request class and send request
+ * $response = $request->creditInvoiceOrderRows()->doRequest(); // returns CreditInvoiceRowsResponse
+ * $response = $request->creditPaymentplanOrderRows()->doRequest(); // returns CreditPaymentPlanRowsRequest
+ * $response = $request->creditCardOrderRows()->doRequest(); // returns CreditTransactionResponse
+ * $response = $request->creditDirectBankOrderRows()->doRequest(); // returns CreditTransactionResponse
+ * ...
+ *
+ * @param ConfigurationProvider $config
+ * @return \Svea\WebPay\BuildOrder\CreditOrderRowsBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ *
+ * @see \Svea\CreditOrderRowsBuilder \Svea\WebPay\BuildOrder\CreditOrderRowsBuilder
+ * @see \Svea\AdminService\CreditInvoiceRowsResponse \Svea\WebPay\AdminService\AdminServiceResponse\CreditInvoiceRowsResponse
+ * @see \Svea\AdminService\CreditPaymentPlanResponse \Svea\WebPay\AdminService\AdminServiceResponse\CreditPaymentPlanResponse
+ * @see \Svea\HostedService\CreditTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse
+ *
+ * @author Kristian Grossman-Madsen for Svea Svea\WebPay\WebPay
+ */
+ public static function creditOrderRows($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new CreditOrderRowsBuilder($config);
- }
+ return new CreditOrderRowsBuilder($config);
+ }
- /**
- * The Svea\WebPay\WebPayAdmin::creditAmount entrypoint method is used to credit an amount in an order after it has been delivered.
- * Supports PaymentPlan and AccountCredit
- *
- *
- * Get an order builder instance using the Svea\WebPay\WebPayAdmin::creditAmount entrypoint, then provide more information about the
- * transaction and send the request using the CreditAmountBuilder methods:
- *
- * ...
- * $request = Svea\WebPay\WebPayAdmin::creditAmount($config)
- * ->setContractNumber($deliverorderInfo->contractNumber)
- * ->setCountryCode('SE')
- * ->setDescription('credit desc')
- * ->setAmountIncVat(100);
- *
- * $response = $request->cancelPaymentPlanAmount()->doRequest();
- * ...
- *
- * @param \Svea\WebPay\Config\ConfigurationProvider $config
- * @return \Svea\WebPay\BuildOrder\CreditAmountBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- *
- * @author ann-hal for Svea Ekonomi Ab | Svea\WebPay\WebPay
- */
- public static function creditAmount($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPayAdmin::creditAmount entrypoint method is used to credit an amount in an order after it has been delivered.
+ * Supports PaymentPlan and AccountCredit
+ *
+ *
+ * Get an order builder instance using the Svea\WebPay\WebPayAdmin::creditAmount entrypoint, then provide more information about the
+ * transaction and send the request using the CreditAmountBuilder methods:
+ *
+ * ...
+ * $request = Svea\WebPay\WebPayAdmin::creditAmount($config)
+ * ->setContractNumber($deliverorderInfo->contractNumber)
+ * ->setCountryCode('SE')
+ * ->setDescription('credit desc')
+ * ->setAmountIncVat(100);
+ *
+ * $response = $request->cancelPaymentPlanAmount()->doRequest();
+ * ...
+ *
+ * @param \Svea\WebPay\Config\ConfigurationProvider $config
+ * @return \Svea\WebPay\BuildOrder\CreditAmountBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ *
+ * @author ann-hal for Svea Ekonomi Ab | Svea\WebPay\WebPay
+ */
+ public static function creditAmount($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new CreditAmountBuilder($config);
- }
+ return new CreditAmountBuilder($config);
+ }
- /**
- * Add order rows to an order.
- *
- * Provide information about the new order rows and send the request using
- * addOrderRowsBuilder methods:
- *
- * ->setOrderId()
- * ->setCountryCode()
- * ->addOrderRow() (one or more)
- * ->addOrderRows() (optional)
- *
- * Finish by selecting the correct ordertype and perform the request:
- * ->addInvoiceOrderRows() | addPaymentPlanOrderRows()
- * ->doRequest()
- *
- * The final doRequest() returns an AddOrderRowsResponse
- *
- * @see \Svea\AddOrderRowsBuilder \Svea\WebPay\BuildOrder\AddOrderRowsBuilder
- * @see \Svea\AdminService\AddOrderRowsResponse \Svea\WebPay\AdminService\AdminServiceResponse\AddOrderRowsResponse
- *
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return \Svea\WebPay\BuildOrder\AddOrderRowsBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function addOrderRows($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * Add order rows to an order.
+ *
+ * Provide information about the new order rows and send the request using
+ * addOrderRowsBuilder methods:
+ *
+ * ->setOrderId()
+ * ->setCountryCode()
+ * ->addOrderRow() (one or more)
+ * ->addOrderRows() (optional)
+ *
+ * Finish by selecting the correct ordertype and perform the request:
+ * ->addInvoiceOrderRows() | addPaymentPlanOrderRows()
+ * ->doRequest()
+ *
+ * The final doRequest() returns an AddOrderRowsResponse
+ *
+ * @see \Svea\AddOrderRowsBuilder \Svea\WebPay\BuildOrder\AddOrderRowsBuilder
+ * @see \Svea\AdminService\AddOrderRowsResponse \Svea\WebPay\AdminService\AdminServiceResponse\AddOrderRowsResponse
+ *
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return \Svea\WebPay\BuildOrder\AddOrderRowsBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function addOrderRows($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new AddOrderRowsBuilder($config);
- }
+ return new AddOrderRowsBuilder($config);
+ }
- /**
- * The Svea\WebPay\WebPayAdmin::updateOrderRows() method is used to update individual order rows in non-delivered invoice and
- * payment plan orders. Supports invoice and payment plan orders.
- *
- * The order row status of the order is updated at Svea to reflect the updated order rows. If the updated rows'
- * order total amount exceeds the original order total amount, an error is returned by the service.
- *
- * Get an order builder instance using the Svea\WebPay\WebPayAdmin::updateOrderRows() entrypoint, then provide more information
- * about the transaction and send the request using the UpdateOrderRowsBuilder methods:
- *
- * Use setCountryCode() to specify the country code matching the original create order request.
- *
- * Use updateOrderRow() with a new Svea\WebPay\WebPayItem::numberedOrderRow() object to pass in the updated order row. Use the
- * NumberedOrderRowBuilder member functions to specifiy the updated order row contents. Notably, the setRowNumber()
- * method specifies which original order row contents is to be replaced, in full, by the NumberedOrderRow contents.
- *
- * Then use either updateInvoiceOrderRows() or updatePaymentPlanOrderRows() to get a request object, which ever
- * matches the payment method used in the original order.
- *
- * Calling doRequest() on the request object will send the request to Svea and return UpdateOrderRowsResponse.
- *
- * ...
- * $request = Svea\WebPay\WebPayAdmin.updateOrderRows($config)
- * ->setOrderId() // required
- * ->setCountryCode() // required
- * ->updateOrderRow() // required, NumberedOrderRowBuilder w/RowNumber attribute matching row index of original order row
- * ;
- * // then select the corresponding request class and send request
- * $response = $request->updateInvoiceOrderRows()->doRequest(); // returns UpdateOrderRowsResponse
- * $response = $request->updatePaymentPlanOrderRows()->doRequest(); // returns UpdateOrderRowsResponse
- * ...
- *
- * @author Kristian Grossman-Madsen
- *
- * @see \Svea\UpdateOrderRowsBuilder \Svea\WebPay\BuildOrder\UpdateOrderRowsBuilder
- * @see \Svea\AdminService\UpdateOrderRowsResponse \Svea\WebPay\AdminService\AdminServiceResponse\UpdateOrderRowsResponse
- *
- * @param \Svea\WebPay\Config\ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return \Svea\WebPay\BuildOrder\UpdateOrderRowsBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function updateOrderRows($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPayAdmin::updateOrderRows() method is used to update individual order rows in non-delivered invoice and
+ * payment plan orders. Supports invoice and payment plan orders.
+ *
+ * The order row status of the order is updated at Svea to reflect the updated order rows. If the updated rows'
+ * order total amount exceeds the original order total amount, an error is returned by the service.
+ *
+ * Get an order builder instance using the Svea\WebPay\WebPayAdmin::updateOrderRows() entrypoint, then provide more information
+ * about the transaction and send the request using the UpdateOrderRowsBuilder methods:
+ *
+ * Use setCountryCode() to specify the country code matching the original create order request.
+ *
+ * Use updateOrderRow() with a new Svea\WebPay\WebPayItem::numberedOrderRow() object to pass in the updated order row. Use the
+ * NumberedOrderRowBuilder member functions to specifiy the updated order row contents. Notably, the setRowNumber()
+ * method specifies which original order row contents is to be replaced, in full, by the NumberedOrderRow contents.
+ *
+ * Then use either updateInvoiceOrderRows() or updatePaymentPlanOrderRows() to get a request object, which ever
+ * matches the payment method used in the original order.
+ *
+ * Calling doRequest() on the request object will send the request to Svea and return UpdateOrderRowsResponse.
+ *
+ * ...
+ * $request = Svea\WebPay\WebPayAdmin.updateOrderRows($config)
+ * ->setOrderId() // required
+ * ->setCountryCode() // required
+ * ->updateOrderRow() // required, NumberedOrderRowBuilder w/RowNumber attribute matching row index of original order row
+ * ;
+ * // then select the corresponding request class and send request
+ * $response = $request->updateInvoiceOrderRows()->doRequest(); // returns UpdateOrderRowsResponse
+ * $response = $request->updatePaymentPlanOrderRows()->doRequest(); // returns UpdateOrderRowsResponse
+ * ...
+ *
+ * @author Kristian Grossman-Madsen
+ *
+ * @see \Svea\UpdateOrderRowsBuilder \Svea\WebPay\BuildOrder\UpdateOrderRowsBuilder
+ * @see \Svea\AdminService\UpdateOrderRowsResponse \Svea\WebPay\AdminService\AdminServiceResponse\UpdateOrderRowsResponse
+ *
+ * @param \Svea\WebPay\Config\ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return \Svea\WebPay\BuildOrder\UpdateOrderRowsBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function updateOrderRows($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new UpdateOrderRowsBuilder($config);
- }
+ return new UpdateOrderRowsBuilder($config);
+ }
- /**
- * The Svea\WebPay\WebPayAdmin::updateOrder() method is used to add or change ClientOrderNumber and/or NotesSupports invoice
- * and payment plan orders.
- *
- * Get an order builder instance using the Svea\WebPay\WebPayAdmin::updateOrder() entrypoint, then provide more information
- * about the transaction and send the request using the UpdateOrderBuilder methods:
- *
- * Use setCountryCode() to specify the country code matching the original create order request.
- * Use setOrderId() to specify which order
- * Use setClientOrderNumber() if you want to add or change the client order number.
- * Use setNotes() if you want to add or change the Notes on invoice from client to customer.
- * Then use either updateInvoiceOrder() or updatePaymentPlanOrder() to get a request object, which ever
- * matches the payment method used in the original order.
- *
- * Calling doRequest() on the request object will send the request to Svea and return UpdateOrderResponse.
- *
- * ...
- * $request = Svea\WebPay\WebPayAdmin.updateOrder($config)
- * ->setOrderId() // required
- * ->setCountryCode() // required
- * ->setClientOrderNumber() // optional
- * ->setNotes() // optional
- * ;
- * // then select the corresponding request class and send request
- * $response = $request->updateInvoiceOrder()->doRequest(); // returns UpdateOrderResponse
- * $response = $request->updatePaymentPlanOrder()->doRequest(); // returns UpdateOrderResponse
- * ...
- *
- * @see \Svea\UpdateOrderBuilder \Svea\WebPay\BuildOrder\UpdateOrderBuilder
- * @see \Svea\AdminService\UpdateOrderResponse \Svea\WebPay\AdminService\AdminServiceResponse\UpdateOrderResponse
- *
- * @param \Svea\WebPay\Config\ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return \Svea\WebPay\BuildOrder\UpdateOrderBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function updateOrder($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPayAdmin::updateOrder() method is used to add or change ClientOrderNumber and/or NotesSupports invoice
+ * and payment plan orders.
+ *
+ * Get an order builder instance using the Svea\WebPay\WebPayAdmin::updateOrder() entrypoint, then provide more information
+ * about the transaction and send the request using the UpdateOrderBuilder methods:
+ *
+ * Use setCountryCode() to specify the country code matching the original create order request.
+ * Use setOrderId() to specify which order
+ * Use setClientOrderNumber() if you want to add or change the client order number.
+ * Use setNotes() if you want to add or change the Notes on invoice from client to customer.
+ * Then use either updateInvoiceOrder() or updatePaymentPlanOrder() to get a request object, which ever
+ * matches the payment method used in the original order.
+ *
+ * Calling doRequest() on the request object will send the request to Svea and return UpdateOrderResponse.
+ *
+ * ...
+ * $request = Svea\WebPay\WebPayAdmin.updateOrder($config)
+ * ->setOrderId() // required
+ * ->setCountryCode() // required
+ * ->setClientOrderNumber() // optional
+ * ->setNotes() // optional
+ * ;
+ * // then select the corresponding request class and send request
+ * $response = $request->updateInvoiceOrder()->doRequest(); // returns UpdateOrderResponse
+ * $response = $request->updatePaymentPlanOrder()->doRequest(); // returns UpdateOrderResponse
+ * ...
+ *
+ * @see \Svea\UpdateOrderBuilder \Svea\WebPay\BuildOrder\UpdateOrderBuilder
+ * @see \Svea\AdminService\UpdateOrderResponse \Svea\WebPay\AdminService\AdminServiceResponse\UpdateOrderResponse
+ *
+ * @param \Svea\WebPay\Config\ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return \Svea\WebPay\BuildOrder\UpdateOrderBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function updateOrder($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new UpdateOrderBuilder($config);
- }
+ return new UpdateOrderBuilder($config);
+ }
- /**
- * The Svea\WebPay\WebPayAdmin::deliverOrderRows entrypoint method is used to deliver individual order rows. Supports invoice and card orders.
- * (To partially deliver PaymentPlan or Direct Bank orders, please contact Svea.)
- *
- * For Invoice orders, the order row status is updated at Svea following each successful request.
- *
- * For card orders, an order can only be delivered once, and any non-delivered order rows will be cancelled (i.e. the order amount
- * will be lowered by the sum of the non-delivered order rows). A delivered card order has status CONFIRMED at Svea.
- *
- * Get an order builder instance using the Svea\WebPay\WebPayAdmin::deliverOrderRows() entrypoint, then provide more information about the
- * transaction and send the request using the DeliverOrderRowsBuilder methods:
- *
- * Use setRowToDeliver() or setRowsToDeliver() to specify the order row(s) to deliver. The order row indexes should correspond to
- * those returned by i.e. Svea\WebPay\WebPayAdmin::queryOrder();
- *
- * For card orders, use addNumberedOrderRow() or addNumberedOrderRows() to pass in a copy of the original order rows. The original
- * order rows can be retrieved using Svea\WebPay\WebPayAdmin::queryOrder(); the numberedOrderRows attribute contains the serverside order rows
- * w/indexes. Note that if a card order has been modified (i.e. rows cancelled or credited) after the initial order creation, the
- * returned order rows will not be accurate.
- * ...
- * $request = Svea\WebPay\WebPayAdmin::deliverOrderRows($config)
- * ->setOrderId() // required
- * ->setTransactionId() // optional, card only, alias for setOrderId
- * ->setCountryCode() // required
- * ->setInvoiceDistributionType() // required, invoice only
- * ->setRowToDeliver() // required, index of original order rows you wish to cancel
- * ->addNumberedOrderRow() // required for card orders, should match original row indexes
- * ;
- * // then select the corresponding request class and send request
- * $response = $request->deliverInvoiceOrderRows()->doRequest(); // returns DeliverOrderRowsResponse
- * $response = $request->deliverPaymentPlanOrderRows()->doRequest(); // returns DeliverOrderRowsResponse
- * $response = $request->deliverCardOrderRows()->doRequest(); // returns ConfirmTransactionResponse
- * ...
- *
- * @see \Svea\DeliverOrderRowsBuilder \Svea\WebPay\BuildOrder\DeliverOrderRowsBuilder
- * @see \Svea\AdminService\DeliverOrderRowsResponse \Svea\AdminService\DeliverOrderRowsResponse
- * @see \Svea\HostedService\ConfirmTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse
- *
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return \Svea\WebPay\BuildOrder\DeliverOrderRowsBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function deliverOrderRows($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPayAdmin::deliverOrderRows entrypoint method is used to deliver individual order rows. Supports invoice and card orders.
+ * (To partially deliver PaymentPlan or Direct Bank orders, please contact Svea.)
+ *
+ * For Invoice orders, the order row status is updated at Svea following each successful request.
+ *
+ * For card orders, an order can only be delivered once, and any non-delivered order rows will be cancelled (i.e. the order amount
+ * will be lowered by the sum of the non-delivered order rows). A delivered card order has status CONFIRMED at Svea.
+ *
+ * Get an order builder instance using the Svea\WebPay\WebPayAdmin::deliverOrderRows() entrypoint, then provide more information about the
+ * transaction and send the request using the DeliverOrderRowsBuilder methods:
+ *
+ * Use setRowToDeliver() or setRowsToDeliver() to specify the order row(s) to deliver. The order row indexes should correspond to
+ * those returned by i.e. Svea\WebPay\WebPayAdmin::queryOrder();
+ *
+ * For card orders, use addNumberedOrderRow() or addNumberedOrderRows() to pass in a copy of the original order rows. The original
+ * order rows can be retrieved using Svea\WebPay\WebPayAdmin::queryOrder(); the numberedOrderRows attribute contains the serverside order rows
+ * w/indexes. Note that if a card order has been modified (i.e. rows cancelled or credited) after the initial order creation, the
+ * returned order rows will not be accurate.
+ * ...
+ * $request = Svea\WebPay\WebPayAdmin::deliverOrderRows($config)
+ * ->setOrderId() // required
+ * ->setTransactionId() // optional, card only, alias for setOrderId
+ * ->setCountryCode() // required
+ * ->setInvoiceDistributionType() // required, invoice only
+ * ->setRowToDeliver() // required, index of original order rows you wish to cancel
+ * ->addNumberedOrderRow() // required for card orders, should match original row indexes
+ * ;
+ * // then select the corresponding request class and send request
+ * $response = $request->deliverInvoiceOrderRows()->doRequest(); // returns DeliverOrderRowsResponse
+ * $response = $request->deliverPaymentPlanOrderRows()->doRequest(); // returns DeliverOrderRowsResponse
+ * $response = $request->deliverCardOrderRows()->doRequest(); // returns ConfirmTransactionResponse
+ * ...
+ *
+ * @see \Svea\DeliverOrderRowsBuilder \Svea\WebPay\BuildOrder\DeliverOrderRowsBuilder
+ * @see \Svea\AdminService\DeliverOrderRowsResponse \Svea\AdminService\DeliverOrderRowsResponse
+ * @see \Svea\HostedService\ConfirmTransactionResponse \Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse
+ *
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return \Svea\WebPay\BuildOrder\DeliverOrderRowsBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function deliverOrderRows($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new DeliverOrderRowsBuilder($config);
- }
+ return new DeliverOrderRowsBuilder($config);
+ }
- /**
- * The Svea\WebPay\WebPayAdmin::queryTaskInfo entry point method is used to retrieve information regarding desired task.
- *
- * For Invoice orders, the order row status is updated at Svea following each successful request.
- *
- * ...
- * $request = Svea\WebPay\WebPayAdmin::queryTaskInfo($config)
- * ->setTaskUrl($taskUrl);
- *
- * // then select the corresponding request class and send request
- * $response = $request->queryTaskInfo()->doRequest(); // returns TaskInfoResponse
- * ...
- *
- * @see \Svea\DeliverOrderRowsBuilder \Svea\WebPay\BuildOrder\DeliverOrderRowsBuilder
- *
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return \Svea\WebPay\BuildOrder\QueryTaskInfoBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function queryTaskInfo($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPayAdmin::queryTaskInfo entry point method is used to retrieve information regarding desired task.
+ *
+ * For Invoice orders, the order row status is updated at Svea following each successful request.
+ *
+ * ...
+ * $request = Svea\WebPay\WebPayAdmin::queryTaskInfo($config)
+ * ->setTaskUrl($taskUrl);
+ *
+ * // then select the corresponding request class and send request
+ * $response = $request->queryTaskInfo()->doRequest(); // returns TaskInfoResponse
+ * ...
+ *
+ * @see \Svea\DeliverOrderRowsBuilder \Svea\WebPay\BuildOrder\DeliverOrderRowsBuilder
+ *
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return \Svea\WebPay\BuildOrder\QueryTaskInfoBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function queryTaskInfo($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new QueryTaskInfoBuilder($config);
- }
+ return new QueryTaskInfoBuilder($config);
+ }
- /**
- * The Svea\WebPay\WebPayAdmin::cancelRecurSubscription entry point method is used to invalidate an active subscriptionId making it impossible to do new recurs.
- *
- * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
- * @return \Svea\WebPay\BuildOrder\CancelRecurSubscriptionBuilder
- * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public static function cancelRecurSubscription($config = null)
- {
- if ($config == null) {
- self::throwMissingConfigException();
- }
+ /**
+ * The Svea\WebPay\WebPayAdmin::cancelRecurSubscription entry point method is used to invalidate an active subscriptionId making it impossible to do new recurs.
+ *
+ * @param ConfigurationProvider $config instance implementing Svea\WebPay\Config\ConfigurationProvider
+ * @return \Svea\WebPay\BuildOrder\CancelRecurSubscriptionBuilder
+ * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public static function cancelRecurSubscription($config = null)
+ {
+ if ($config == null) {
+ self::throwMissingConfigException();
+ }
- return new BuildOrder\CancelRecurSubscriptionBuilder($config);
- }
+ return new BuildOrder\CancelRecurSubscriptionBuilder($config);
+ }
}
diff --git a/src/WebPayItem.php b/src/WebPayItem.php
index d75073e1..a1d5999f 100644
--- a/src/WebPayItem.php
+++ b/src/WebPayItem.php
@@ -38,229 +38,229 @@
class WebPayItem
{
- public static function orderDeliveryAddress()
- {
- return new OrderDeliveryAddress();
- }
- /**
- * The Svea\WebPay\WebPayItem::orderRow() entrypoint method is used to specify order items like products and services.
- * It is required to have a minimum of one order row in an order.
- *
- * Specify the item price using precisely two of these methods in order to specify the item price and tax rate:
- * setAmountExVat(), setAmountIncVat() and setVatPercent(). We recommend using setAmountExVat() and setVatPercentage().
- *
- * If you use setAmountIncVat(), note that this may introduce a cumulative rounding error when ordering large
- * quantities of an item, as the package bases the total order sum on a calculated price ex. vat.
- *
- * $orderrow = Svea\WebPay\WebPayItem::orderRow()
- * ->setAmountExVat(100.00) // optional, recommended, use precisely two of the price specification methods
- * ->setVatPercent(25) // optional, recommended, use precisely two of the price specification methods
- * ->setAmountIncVat(125.00) // optional, use precisely two of the price specification methods
- * ->setQuantity(2) // required
- * ->setUnit("pcs.") // optional
- * ->setName('name') // optional, invoice, accountCredit & payment plan orders will merge "name" with "description"
- * ->setDescription("description") // optional, invoice, accountCredit & payment plan orders will merge "name" with "description"
- * ->setArticleNumber("1") // optional
- * ->setDiscountPercent(0) // optional
- * );
- *
- * @return \Svea\WebPay\BuildOrder\RowBuilders\OrderRow
- */
- public static function orderRow()
- {
- return new OrderRow();
- }
+ public static function orderDeliveryAddress()
+ {
+ return new OrderDeliveryAddress();
+ }
+ /**
+ * The Svea\WebPay\WebPayItem::orderRow() entrypoint method is used to specify order items like products and services.
+ * It is required to have a minimum of one order row in an order.
+ *
+ * Specify the item price using precisely two of these methods in order to specify the item price and tax rate:
+ * setAmountExVat(), setAmountIncVat() and setVatPercent(). We recommend using setAmountExVat() and setVatPercentage().
+ *
+ * If you use setAmountIncVat(), note that this may introduce a cumulative rounding error when ordering large
+ * quantities of an item, as the package bases the total order sum on a calculated price ex. vat.
+ *
+ * $orderrow = Svea\WebPay\WebPayItem::orderRow()
+ * ->setAmountExVat(100.00) // optional, recommended, use precisely two of the price specification methods
+ * ->setVatPercent(25) // optional, recommended, use precisely two of the price specification methods
+ * ->setAmountIncVat(125.00) // optional, use precisely two of the price specification methods
+ * ->setQuantity(2) // required
+ * ->setUnit("pcs.") // optional
+ * ->setName('name') // optional, invoice, accountCredit & payment plan orders will merge "name" with "description"
+ * ->setDescription("description") // optional, invoice, accountCredit & payment plan orders will merge "name" with "description"
+ * ->setArticleNumber("1") // optional
+ * ->setDiscountPercent(0) // optional
+ * );
+ *
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\OrderRow
+ */
+ public static function orderRow()
+ {
+ return new OrderRow();
+ }
- /**
- * Use this only when supplying NumberedOrderRow items for the various Svea\WebPay\WebPayAdmin order row administration functions.
- * @return \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow
- */
- public static function numberedOrderRow()
- {
- return new NumberedOrderRow();
- }
+ /**
+ * Use this only when supplying NumberedOrderRow items for the various Svea\WebPay\WebPayAdmin order row administration functions.
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow
+ */
+ public static function numberedOrderRow()
+ {
+ return new NumberedOrderRow();
+ }
- /**
- * The Svea\WebPay\WebPayItem::shippingFee() entrypoint method is used to specify order shipping fee rows.
- * It is not required to have a shipping fee row in an order.
- *
- * Specify the item price using precisely two of these methods in order to specify the item price and tax rate:
- * setAmountExVat(), setAmountIncVat() and setVatPercent(). We recommend using setAmountExVat() and setVatPercentage().
- *
- * $shippingFee = Svea\WebPay\WebPayItem::shippingFee()
- * ->setAmountExVat(100.00) // optional, recommended, use precisely two of the price specification methods
- * ->setVatPercent(25) // optional, recommended, use precisely two of the price specification methods
- * ->setAmountIncVat(125.00) // optional, use precisely two of the price specification methods
- * ->setUnit("pcs.") // optional
- * ->setName('name') // optional
- * ->setDescription("description") // optional
- * ->setShippingId('33') // optional
- * ->setDiscountPercent(0) // optional
- * );
- *
- * @return \Svea\WebPay\BuildOrder\RowBuilders\ShippingFee
- */
- public static function shippingFee()
- {
- return new ShippingFee();
- }
+ /**
+ * The Svea\WebPay\WebPayItem::shippingFee() entrypoint method is used to specify order shipping fee rows.
+ * It is not required to have a shipping fee row in an order.
+ *
+ * Specify the item price using precisely two of these methods in order to specify the item price and tax rate:
+ * setAmountExVat(), setAmountIncVat() and setVatPercent(). We recommend using setAmountExVat() and setVatPercentage().
+ *
+ * $shippingFee = Svea\WebPay\WebPayItem::shippingFee()
+ * ->setAmountExVat(100.00) // optional, recommended, use precisely two of the price specification methods
+ * ->setVatPercent(25) // optional, recommended, use precisely two of the price specification methods
+ * ->setAmountIncVat(125.00) // optional, use precisely two of the price specification methods
+ * ->setUnit("pcs.") // optional
+ * ->setName('name') // optional
+ * ->setDescription("description") // optional
+ * ->setShippingId('33') // optional
+ * ->setDiscountPercent(0) // optional
+ * );
+ *
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\ShippingFee
+ */
+ public static function shippingFee()
+ {
+ return new ShippingFee();
+ }
- /**
- * The Svea\WebPay\WebPayItem::invoiceFee() entrypoint method is used to specify fees associated with a payment method (i.e. invoice fee).
- * It is not required to have an invoice fee row in an order.
- *
- * Specify the item price using precisely two of these methods in order to specify the item price and tax rate:
- * setAmountExVat(), setAmountIncVat() and setVatPercent(). We recommend using setAmountExVat() and setVatPercentage().
- *
- * $invoiceFee = Svea\WebPay\WebPayItem::invoiceFee()
- * ->setAmountExVat(100.00) // optional, recommended, use precisely two of the price specification methods
- * ->setVatPercent(25) // optional, recommended, use precisely two of the price specification methods
- * ->setAmountIncVat(125.00) // optional, use precisely two of the price specification methods
- * ->setUnit("pcs.") // optional
- * ->setName('name') // optional
- * ->setDescription("description") // optional
- * ->setDiscountPercent(0) // optional
- * );
- *
- * @return \Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee
- */
- public static function invoiceFee()
- {
- return new InvoiceFee();
- }
+ /**
+ * The Svea\WebPay\WebPayItem::invoiceFee() entrypoint method is used to specify fees associated with a payment method (i.e. invoice fee).
+ * It is not required to have an invoice fee row in an order.
+ *
+ * Specify the item price using precisely two of these methods in order to specify the item price and tax rate:
+ * setAmountExVat(), setAmountIncVat() and setVatPercent(). We recommend using setAmountExVat() and setVatPercentage().
+ *
+ * $invoiceFee = Svea\WebPay\WebPayItem::invoiceFee()
+ * ->setAmountExVat(100.00) // optional, recommended, use precisely two of the price specification methods
+ * ->setVatPercent(25) // optional, recommended, use precisely two of the price specification methods
+ * ->setAmountIncVat(125.00) // optional, use precisely two of the price specification methods
+ * ->setUnit("pcs.") // optional
+ * ->setName('name') // optional
+ * ->setDescription("description") // optional
+ * ->setDiscountPercent(0) // optional
+ * );
+ *
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee
+ */
+ public static function invoiceFee()
+ {
+ return new InvoiceFee();
+ }
- /**
- * Use Svea\WebPay\WebPayItem::fixedDiscount() when the discount or coupon is expressed as a fixed discount amount.
- *
- * If no vat rate is given, we calculate the discount split across the order row vat rates present in the order.
- * This will ensure that the correct discount vat is applied to the order.
- *
- * If there are several vat rates present in the order, the discount will be split proportionally across the order row vat
- * rates. For examples, including the resulting discount rows, see the test suite file UnitTest/InvoicePaymentTest.php.
- *
- * Otherwise, it is required to use at least two of the functions setAmountExVat(), setAmountIncVat() and setVatPercent().
- * If two of these three attributes are specified, we honour the amount indicated and the given discount tax rate.
- *
- * $fixedDiscount = Svea\WebPay\WebPayItem::fixedDiscount()
- * ->setAmountIncVat(100.00) // recommended, see info above
- * ->setAmountExVat(1.0) // optional, see info above
- * ->setVatPercent(25) // optional, see info above
- * ->setDiscountId("1") // optional
- * ->setUnit("st") // optional
- * ->setName("Fixed") // optional
- * ->setDescription("FixedDiscount") // optional
- * );
- *
- * @see \Svea\FixedDiscount
- *
- * @return \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount
- */
- public static function fixedDiscount()
- {
- return new FixedDiscount();
- }
+ /**
+ * Use Svea\WebPay\WebPayItem::fixedDiscount() when the discount or coupon is expressed as a fixed discount amount.
+ *
+ * If no vat rate is given, we calculate the discount split across the order row vat rates present in the order.
+ * This will ensure that the correct discount vat is applied to the order.
+ *
+ * If there are several vat rates present in the order, the discount will be split proportionally across the order row vat
+ * rates. For examples, including the resulting discount rows, see the test suite file UnitTest/InvoicePaymentTest.php.
+ *
+ * Otherwise, it is required to use at least two of the functions setAmountExVat(), setAmountIncVat() and setVatPercent().
+ * If two of these three attributes are specified, we honour the amount indicated and the given discount tax rate.
+ *
+ * $fixedDiscount = Svea\WebPay\WebPayItem::fixedDiscount()
+ * ->setAmountIncVat(100.00) // recommended, see info above
+ * ->setAmountExVat(1.0) // optional, see info above
+ * ->setVatPercent(25) // optional, see info above
+ * ->setDiscountId("1") // optional
+ * ->setUnit("st") // optional
+ * ->setName("Fixed") // optional
+ * ->setDescription("FixedDiscount") // optional
+ * );
+ *
+ * @see \Svea\FixedDiscount
+ *
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount
+ */
+ public static function fixedDiscount()
+ {
+ return new FixedDiscount();
+ }
- /**
- * Use Svea\WebPay\WebPayItem::relativeDiscount() when the discount or coupon is expressed as a percentage of the total product amount.
- *
- * The discount will be calculated based on the total sum of all order rows specified using addOrderRow(), it does not
- * apply to invoice or shipping fees.
- *
- * If there are several vat rates present in the order, the discount will be split proportionally across the order row vat
- * rates. For examples, including the resulting discount rows, see the test suite file UnitTest/InvoicePaymentTest.php.
- *
- * Specify the discount using RelativeDiscount methods:
- *
- * $relativeDiscount = Svea\WebPay\WebPayItem::relativeDiscount()
- * ->setDiscountPercent(10.0) // required,
- * ->setDiscountId("1") // optional
- * ->setUnit("st.") // optional
- * ->setName("DiscountName") // optional
- * ->setDescription("DiscountDesc.") // optional
- * );
- *
- * @see \Svea\RelativeDiscount
- *
- * @return \Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount
- */
- public static function relativeDiscount()
- {
- return new RelativeDiscount();
- }
+ /**
+ * Use Svea\WebPay\WebPayItem::relativeDiscount() when the discount or coupon is expressed as a percentage of the total product amount.
+ *
+ * The discount will be calculated based on the total sum of all order rows specified using addOrderRow(), it does not
+ * apply to invoice or shipping fees.
+ *
+ * If there are several vat rates present in the order, the discount will be split proportionally across the order row vat
+ * rates. For examples, including the resulting discount rows, see the test suite file UnitTest/InvoicePaymentTest.php.
+ *
+ * Specify the discount using RelativeDiscount methods:
+ *
+ * $relativeDiscount = Svea\WebPay\WebPayItem::relativeDiscount()
+ * ->setDiscountPercent(10.0) // required,
+ * ->setDiscountId("1") // optional
+ * ->setUnit("st.") // optional
+ * ->setName("DiscountName") // optional
+ * ->setDescription("DiscountDesc.") // optional
+ * );
+ *
+ * @see \Svea\RelativeDiscount
+ *
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount
+ */
+ public static function relativeDiscount()
+ {
+ return new RelativeDiscount();
+ }
- /**
- * Use Svea\WebPay\WebPayItem::individualCustomer() to add individual customer information to an order.
- *
- * Note that "required" below as a requirement only when using the invoice or payment plan
- * payment methods, and that the required attributes vary etween countries.
- *
- * (For card and direct bank orders, adding customer information to the order is optional,
- * unless you're using getPaymentUrl() to set up a prepared payment.)
- *
- * IndividualCustomer individual = Svea\WebPay\WebPayItem::individualCustomer()
- * ->setNationalIdNumber() // Numeric // invoice, accountCredit, paymentplan: required for customers in SE, NO, DK, FI
- * ->setName() // String // invoice, accountCredit, paymentplan: required, use (firstname, lastname) for customers in NL and DE
- * ->setBirthDate() // Numeric // invoice, accountCredit, paymentplan: required for individual customers in NL and DE
- * ->setInitials() // String // invoice, accountCredit, paymentplan: required for individual customers in NL
- * ->setCoAddress() // String // invoice, accountCredit, paymentplan: optional
- * ->setStreetAddress() // String // invoice, accountCredit, paymentplan: required, use (street, housenumber) in NL and DE
- * ->setZipCode) // String // invoice, accountCredit, paymentplan: required in NL and DE
- * ->setLocality() // String // invoice, accountCredit, paymentplan: required in NL and DE
- * ->setPhoneNumber() // String // invoice, accountCredit, paymentplan: optional but desirable
- * ->setEmail() // String // invoice, accountCredit, paymentplan: optional but desirable
- * ->setIpAddress() // String // invoice, accountCredit, paymentplan: optional but desirable; card: required for getPaymentUrl() orders only
- * ;
- *
- * @return \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer
- */
- public static function individualCustomer()
- {
- return new IndividualCustomer();
- }
+ /**
+ * Use Svea\WebPay\WebPayItem::individualCustomer() to add individual customer information to an order.
+ *
+ * Note that "required" below as a requirement only when using the invoice or payment plan
+ * payment methods, and that the required attributes vary etween countries.
+ *
+ * (For card and direct bank orders, adding customer information to the order is optional,
+ * unless you're using getPaymentUrl() to set up a prepared payment.)
+ *
+ * IndividualCustomer individual = Svea\WebPay\WebPayItem::individualCustomer()
+ * ->setNationalIdNumber() // Numeric // invoice, accountCredit, paymentplan: required for customers in SE, NO, DK, FI
+ * ->setName() // String // invoice, accountCredit, paymentplan: required, use (firstname, lastname) for customers in NL and DE
+ * ->setBirthDate() // Numeric // invoice, accountCredit, paymentplan: required for individual customers in NL and DE
+ * ->setInitials() // String // invoice, accountCredit, paymentplan: required for individual customers in NL
+ * ->setCoAddress() // String // invoice, accountCredit, paymentplan: optional
+ * ->setStreetAddress() // String // invoice, accountCredit, paymentplan: required, use (street, housenumber) in NL and DE
+ * ->setZipCode) // String // invoice, accountCredit, paymentplan: required in NL and DE
+ * ->setLocality() // String // invoice, accountCredit, paymentplan: required in NL and DE
+ * ->setPhoneNumber() // String // invoice, accountCredit, paymentplan: optional but desirable
+ * ->setEmail() // String // invoice, accountCredit, paymentplan: optional but desirable
+ * ->setIpAddress() // String // invoice, accountCredit, paymentplan: optional but desirable; card: required for getPaymentUrl() orders only
+ * ;
+ *
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer
+ */
+ public static function individualCustomer()
+ {
+ return new IndividualCustomer();
+ }
- /**
- * Use Svea\WebPay\WebPayItem::companyCustomer() to add individual customer information to an order.
- *
- * Note that "required" below as a requirement only when using the invoice or payment plan
- * payment methods, and that the required attributes vary etween countries.
- *
- * (For card and direct bank orders, adding customer information to the order is optional,
- * unless you're using getPaymentUrl() to set up a prepared payment.)
- *
- * CompanyCustomer company = Svea\WebPay\WebPayItem::companyCustomer()
- * ->setNationalIdNumber() // Numeric // invoice: required for customers in SE, NO, DK, FI
- * ->setCompanyName() // String // invoice: required (companyname) for company customers in NL and DE
- * ->setVatNumber() // Numeric // invoice: required for individual customers in NL and DE
- * ->setCoAddress() // String // invoice: optional
- * ->setStreetAddress() // String // invoice: required, use (street, housenumber) in NL and DE
- * ->setZipCode) // String // invoice: required in NL and DE
- * ->setLocality() // String // invoice: required in NL and DE
- * ->setPhoneNumber() // String // invoice: optional but desirable
- * ->setEmail() // String // invoice: optional but desirable
- * ->setIpAddress() // String // invoice: optional but desirable; card: required for getPaymentUrl() orders only
- * ->setAddressSelector() // String // invoice: optional but recommended; received from Svea\WebPay\WebPay::getAddresses() request response
- * ;
- *
- * @return \Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer
- */
- public static function companyCustomer()
- {
- return new CompanyCustomer();
- }
+ /**
+ * Use Svea\WebPay\WebPayItem::companyCustomer() to add individual customer information to an order.
+ *
+ * Note that "required" below as a requirement only when using the invoice or payment plan
+ * payment methods, and that the required attributes vary etween countries.
+ *
+ * (For card and direct bank orders, adding customer information to the order is optional,
+ * unless you're using getPaymentUrl() to set up a prepared payment.)
+ *
+ * CompanyCustomer company = Svea\WebPay\WebPayItem::companyCustomer()
+ * ->setNationalIdNumber() // Numeric // invoice: required for customers in SE, NO, DK, FI
+ * ->setCompanyName() // String // invoice: required (companyname) for company customers in NL and DE
+ * ->setVatNumber() // Numeric // invoice: required for individual customers in NL and DE
+ * ->setCoAddress() // String // invoice: optional
+ * ->setStreetAddress() // String // invoice: required, use (street, housenumber) in NL and DE
+ * ->setZipCode) // String // invoice: required in NL and DE
+ * ->setLocality() // String // invoice: required in NL and DE
+ * ->setPhoneNumber() // String // invoice: optional but desirable
+ * ->setEmail() // String // invoice: optional but desirable
+ * ->setIpAddress() // String // invoice: optional but desirable; card: required for getPaymentUrl() orders only
+ * ->setAddressSelector() // String // invoice: optional but recommended; received from Svea\WebPay\WebPay::getAddresses() request response
+ * ;
+ *
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer
+ */
+ public static function companyCustomer()
+ {
+ return new CompanyCustomer();
+ }
- /**
- * Use Svea\WebPay\WebPayItem::presetValue() to add individual preset value information to an order
- *
- * These information are important for creating order via checkout method
- *
- * $presetValue = new Svea\WebPay\WebPay::presetValue()
- * ->setValueAs
- *
- * @return \Svea\WebPay\Checkout\Model\PresetValue
- */
- public static function presetValue()
- {
- return new PresetValue();
- }
+ /**
+ * Use Svea\WebPay\WebPayItem::presetValue() to add individual preset value information to an order
+ *
+ * These information are important for creating order via checkout method
+ *
+ * $presetValue = new Svea\WebPay\WebPay::presetValue()
+ * ->setValueAs
+ *
+ * @return \Svea\WebPay\Checkout\Model\PresetValue
+ */
+ public static function presetValue()
+ {
+ return new PresetValue();
+ }
}
diff --git a/src/WebService/GetAccountCreditParams/GetAccountCreditParams.php b/src/WebService/GetAccountCreditParams/GetAccountCreditParams.php
index 33c61d5f..91145363 100644
--- a/src/WebService/GetAccountCreditParams/GetAccountCreditParams.php
+++ b/src/WebService/GetAccountCreditParams/GetAccountCreditParams.php
@@ -22,72 +22,72 @@
*/
class GetAccountCreditParams
{
- public $testmode = false;
- public $object;
- public $conf;
- public $countryCode;
- public $logging = false;
+ public $testmode = false;
+ public $object;
+ public $conf;
+ public $countryCode;
+ public $logging = false;
- function __construct($config)
- {
- $this->conf = $config;
- }
+ function __construct($config)
+ {
+ $this->conf = $config;
+ }
- /**
- * Required
- *
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
+ /**
+ * Required
+ *
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
- return $this;
- }
+ return $this;
+ }
- /**
- * Optional
- *
- * @param bool $logging
- * @return $this
- */
- public function enableLogging($logging)
- {
- $this->logging = $logging;
+ /**
+ * Optional
+ *
+ * @param bool $logging
+ * @return $this
+ */
+ public function enableLogging($logging)
+ {
+ $this->logging = $logging;
- return $this;
- }
+ return $this;
+ }
- /**
- * Prepares and sends request
- *
- * @return \Svea\WebPay\WebService\WebServiceResponse\PaymentPlanParamsResponse
- */
- public function doRequest()
- {
- $requestObject = $this->prepareRequest();
- $request = new SveaDoRequest($this->conf, ConfigurationProvider::ACCOUNTCREDIT_TYPE, "GetAccountCreditParamsEu", $requestObject, $this->logging);
+ /**
+ * Prepares and sends request
+ *
+ * @return \Svea\WebPay\WebService\WebServiceResponse\PaymentPlanParamsResponse
+ */
+ public function doRequest()
+ {
+ $requestObject = $this->prepareRequest();
+ $request = new SveaDoRequest($this->conf, ConfigurationProvider::ACCOUNTCREDIT_TYPE, "GetAccountCreditParamsEu", $requestObject, $this->logging);
- $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL,isset($request->result['logs']) ? $request->result['logs'] : NULL);
+ $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL,isset($request->result['logs']) ? $request->result['logs'] : NULL);
- return $responseObject->response;
- }
+ return $responseObject->response;
+ }
- /**
- * @return SveaRequest
- */
- public function prepareRequest()
- {
- $auth = new SveaAuth(
- $this->conf->getUsername(ConfigurationProvider::ACCOUNTCREDIT_TYPE, $this->countryCode),
- $this->conf->getPassword(ConfigurationProvider::ACCOUNTCREDIT_TYPE, $this->countryCode),
- $this->conf->getClientNumber(ConfigurationProvider::ACCOUNTCREDIT_TYPE, $this->countryCode)
- );
+ /**
+ * @return SveaRequest
+ */
+ public function prepareRequest()
+ {
+ $auth = new SveaAuth(
+ $this->conf->getUsername(ConfigurationProvider::ACCOUNTCREDIT_TYPE, $this->countryCode),
+ $this->conf->getPassword(ConfigurationProvider::ACCOUNTCREDIT_TYPE, $this->countryCode),
+ $this->conf->getClientNumber(ConfigurationProvider::ACCOUNTCREDIT_TYPE, $this->countryCode)
+ );
- $object = new SveaRequest();
- $object->request = (object)array("Auth" => $auth);
+ $object = new SveaRequest();
+ $object->request = (object)["Auth" => $auth];
- return $object;
- }
+ return $object;
+ }
}
diff --git a/src/WebService/GetAddress/GetAddresses.php b/src/WebService/GetAddress/GetAddresses.php
index c0908df1..8979253c 100644
--- a/src/WebService/GetAddress/GetAddresses.php
+++ b/src/WebService/GetAddress/GetAddresses.php
@@ -18,298 +18,298 @@
/**
* The following methods are deprecated starting with 2.2 of the package
- * ->setIndividual() (deprecated, -- lookup the address of a private individual, set to i.e. social security number)
- * ->setCompany() (deprecated -- lookup the addresses associated with a legal entity (i.e. company)
- * ->setOrderTypeInvoice() (deprecated -- supply the method that corresponds to the account credentials used for the address lookup)
- * ->setOrderTypePaymentPlan() (deprecated -- supply the method that corresponds to the account credentials used for the address lookup)
- * ->setOrderTypeAccountCredit() (deprecated -- supply the method that corresponds to the account credentials used for the address lookup)
+ * ->setIndividual() (deprecated, -- lookup the address of a private individual, set to i.e. social security number)
+ * ->setCompany() (deprecated -- lookup the addresses associated with a legal entity (i.e. company)
+ * ->setOrderTypeInvoice() (deprecated -- supply the method that corresponds to the account credentials used for the address lookup)
+ * ->setOrderTypePaymentPlan() (deprecated -- supply the method that corresponds to the account credentials used for the address lookup)
+ * ->setOrderTypeAccountCredit() (deprecated -- supply the method that corresponds to the account credentials used for the address lookup)
*
* @author Anneli Halld'n, Daniel Brolund, Kristian Grossman-Madsen, Fredrik Sundell for Svea WebPay
*/
class GetAddresses
{
- public $conf;
- public $countryCode;
- public $customerIdentifier;
- public $orderType;
- public $companyId;
- public $ssn;
- public $testmode = false;
- public $logging = false;
-
- /**
- * @param ConfigurationProvider $config
- */
- function __construct($config)
- {
- $this->conf = $config;
- }
-
- public function enableLogging($logging)
- {
- $this->logging = $logging;
- return $this;
- }
-
- /**
- * required -- supply the country code that corresponds to the account credentials used for the address lookup
- *
- * Use setCountryCode() to supply the country code that corresponds to the account credentials used for the address lookup.
- * Note: this means that you can only look up user addresses in a country where you have a corresponding client id.
- *
- * @param string $countryCodeAsString Country code as described by ISO 3166-1, one of "SE", "NO", "DK"
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
-
- return $this;
- }
-
- /**
- * required -- i.e. the social security number, company vat number et al for the country in question
- *
- * Use setCustomerIdentifier() to provide the exact credentials needed to identify the customer according to country:
- * SE: Personnummer (private individual) or Organisationsnummer (company or other legal entity)
- * NO: Organisasjonsnummer (company or other legal entity)
- * DK: Cpr.nr (private individual) or CVR-nummer (company or other legal entity)
- *
- * @param string $customerIdentifier
- * @return $this
- */
- public function setCustomerIdentifier($customerIdentifier)
- {
- $this->customerIdentifier = $customerIdentifier;
-
- return $this;
- }
-
- /**
- * required -- use to define the customer type to lookup address for.
- * @return $this
- */
- public function getIndividualAddresses()
- {
- $this->ssn = isset($this->customerIdentifier) ? $this->customerIdentifier : null;
-
- return $this;
- }
-
- /**
- * required -- use to define the customer type to lookup address for.
- * @return $this
- */
- public function getCompanyAddresses()
- {
- $this->companyId = isset($this->customerIdentifier) ? $this->customerIdentifier : null;
-
- return $this;
- }
-
- /**
- * @deprecated 2.2
- * Required for Invoice and Payment Plan orders - use this to identify a company customer
- *
- * @param string $companyIdAsString SE: Organisationsnummer, DK: CVR, NO: Vat number
- * @return $this
- */
- public function setCompany($companyIdAsString)
- {
- $this->companyId = $companyIdAsString;
-
- return $this;
- }
-
- /**
- * @deprecated 2.2
- * Required for Invoice and Payment Plan orders - use this to identify an individual customer
- *
- * @param string $NationalIdNumberAsString SE: Personnummer, DK: CPR, NO: N/A
- * @return $this
- */
- public function setIndividual($NationalIdNumberAsString)
- {
- $this->ssn = $NationalIdNumberAsString;
-
- return $this;
- }
-
- /**
- * @deprecated 2.2
- * Required - you need call the method that corresponds to the account credentials (i.e. invoice, accountCredit or paymentplan) used for the address lookup.
- * @return $this
- */
- public function setOrderTypeInvoice()
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
-
- return $this;
- }
-
- /**
- * @deprecated 2.2
- * Required - you need call the method that corresponds to the account credentials (i.e. invoice, accountCredit or paymentplan) used for the address lookup.
- * @return $this
- */
- public function setOrderTypePaymentPlan()
- {
- $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
-
- return $this;
- }
-
- public function setOrderTypeAccountCredit()
- {
- $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
-
- return $this;
- }
-
- /**
- * Prepares and Sends request
- * @return GetAddressesResponse
- */
- public function doRequest()
- {
- $preparedRequest = $this->prepareRequest();
- $request = new SveaDoRequest($this->conf, $this->orderType, "GetAddresses", $preparedRequest, $this->logging);
- $response = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
-
- return $response->response;
- }
-
- /**
- * Sets and returns prepared request object. Used by doRequest().
- *
- * (The prepared request object may be inspected to see what attributes will
- * be sent to Svea -- use ->prepareRequest() in place of ->doRequest() and
- * inspect the resulting SveaRequest object.)
- *
- * @return SveaRequest
- */
- public function prepareRequest()
- {
-
- $this->validateRequest();
-
- $auth = new SveaAuth(
- $this->conf->getUsername($this->orderType, $this->countryCode),
- $this->conf->getPassword($this->orderType, $this->countryCode),
- $this->conf->getClientNumber($this->orderType, $this->countryCode)
- );
-
- $address = new SveaAddress(
- $auth,
- (isset($this->companyId) ? true : false),
- $this->countryCode,
- (isset($this->companyId) ? $this->companyId : $this->ssn)
- );
-
- $this->request = new SveaRequest($address);
-
- return $this->request;
- }
-
- public function validateRequest()
- {
- $errors = $this->validate($this);
- if (count($errors) > 0) {
- $exceptionString = "";
- foreach ($errors as $key => $value) {
- $exceptionString .= "-" . $key . " : " . $value . "\n";
- }
-
- throw new ValidationException($exceptionString);
- }
- }
-
- public function validate($getaddressesrequest)
- {
- $errors = array();
-
- // countrycode -> ssn/companyid -> check credentials
- $errors = $this->validateCountryCode($getaddressesrequest, $errors);
- $errors = $this->validateCustomerIdentifier($getaddressesrequest, $errors);
- if (count($errors) == 0) {
- $this->orderType = $this->checkAndSetConfiguredPaymentMethod();
- }
- $errors = $this->validateCountryCodeConfigurationExists($getaddressesrequest, $errors);
-
- return $errors;
- }
-
- private function validateCountryCode($getaddressesrequest, $errors)
- {
- if (isset($getaddressesrequest->countryCode) == FALSE) {
- $errors[] = "countryCode is required. Use function setCountryCode().";
- }
-
- // TODO add validation of accepted countries
- return $errors;
- }
-
- private function validateCustomerIdentifier($getaddressesrequest, $errors)
- {
- if (!isset($getaddressesrequest->ssn) && !isset($getaddressesrequest->companyId)) {
- $errors[] = "customerIdentifier is required. Use function setCustomerIdentifer().";
- }
-
- return $errors;
- }
-
- private function checkAndSetConfiguredPaymentMethod()
- {
- if ($this->orderType == null) { // no order type set, so try and determine which configuration provider order type to use
- $orderType = ConfigurationProvider::INVOICE_TYPE;
- try {
- $u = $this->conf->getUsername($orderType, $this->countryCode);
- $p = $this->conf->getPassword($orderType, $this->countryCode);
- $c = $this->conf->getClientNumber($orderType, $this->countryCode);
- } catch (InvalidTypeException $e) { // thrown if no config found
- // go on
- }
- if (isset($u) && isset($p) && isset($c)) {
- return ConfigurationProvider::INVOICE_TYPE;
- }
-
- // set for accountCredit
- $orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
- try {
- $u = $this->conf->getUsername($orderType, $this->countryCode);
- $p = $this->conf->getPassword($orderType, $this->countryCode);
- $c = $this->conf->getClientNumber($orderType, $this->countryCode);
- } catch (InvalidTypeException $e) { // thrown if no config found
- // go on
- }
- if (isset($u) && isset($p) && isset($c)) {
- return ConfigurationProvider::ACCOUNTCREDIT_TYPE;
- }
-
- $orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
- try {
- $u = $this->conf->getUsername($orderType, $this->countryCode);
- $p = $this->conf->getPassword($orderType, $this->countryCode);
- $c = $this->conf->getClientNumber($orderType, $this->countryCode);
- } catch (InvalidTypeException $e) {
- return null; // i.e. will throw exception in validation
- }
- if (isset($u) && isset($p) && isset($c)) { // i.e. not set or null
- return ConfigurationProvider::PAYMENTPLAN_TYPE;
- } else {
- return null;
- }
- } else {
- return $this->orderType; // if set, honour given order type
- }
- }
-
- private function validateCountryCodeConfigurationExists($getaddressesrequest, $errors)
- {
- if (!isset($getaddressesrequest->orderType)) {
- $errors[] = "missing authentication credentials. Check configuration.";
- }
-
- return $errors;
- }
+ public $conf;
+ public $countryCode;
+ public $customerIdentifier;
+ public $orderType;
+ public $companyId;
+ public $ssn;
+ public $testmode = false;
+ public $logging = false;
+
+ /**
+ * @param ConfigurationProvider $config
+ */
+ function __construct($config)
+ {
+ $this->conf = $config;
+ }
+
+ public function enableLogging($logging)
+ {
+ $this->logging = $logging;
+ return $this;
+ }
+
+ /**
+ * required -- supply the country code that corresponds to the account credentials used for the address lookup
+ *
+ * Use setCountryCode() to supply the country code that corresponds to the account credentials used for the address lookup.
+ * Note: this means that you can only look up user addresses in a country where you have a corresponding client id.
+ *
+ * @param string $countryCodeAsString Country code as described by ISO 3166-1, one of "SE", "NO", "DK"
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
+
+ return $this;
+ }
+
+ /**
+ * required -- i.e. the social security number, company vat number et al for the country in question
+ *
+ * Use setCustomerIdentifier() to provide the exact credentials needed to identify the customer according to country:
+ * SE: Personnummer (private individual) or Organisationsnummer (company or other legal entity)
+ * NO: Organisasjonsnummer (company or other legal entity)
+ * DK: Cpr.nr (private individual) or CVR-nummer (company or other legal entity)
+ *
+ * @param string $customerIdentifier
+ * @return $this
+ */
+ public function setCustomerIdentifier($customerIdentifier)
+ {
+ $this->customerIdentifier = $customerIdentifier;
+
+ return $this;
+ }
+
+ /**
+ * required -- use to define the customer type to lookup address for.
+ * @return $this
+ */
+ public function getIndividualAddresses()
+ {
+ $this->ssn = isset($this->customerIdentifier) ? $this->customerIdentifier : null;
+
+ return $this;
+ }
+
+ /**
+ * required -- use to define the customer type to lookup address for.
+ * @return $this
+ */
+ public function getCompanyAddresses()
+ {
+ $this->companyId = isset($this->customerIdentifier) ? $this->customerIdentifier : null;
+
+ return $this;
+ }
+
+ /**
+ * @deprecated 2.2
+ * Required for Invoice and Payment Plan orders - use this to identify a company customer
+ *
+ * @param string $companyIdAsString SE: Organisationsnummer, DK: CVR, NO: Vat number
+ * @return $this
+ */
+ public function setCompany($companyIdAsString)
+ {
+ $this->companyId = $companyIdAsString;
+
+ return $this;
+ }
+
+ /**
+ * @deprecated 2.2
+ * Required for Invoice and Payment Plan orders - use this to identify an individual customer
+ *
+ * @param string $NationalIdNumberAsString SE: Personnummer, DK: CPR, NO: N/A
+ * @return $this
+ */
+ public function setIndividual($NationalIdNumberAsString)
+ {
+ $this->ssn = $NationalIdNumberAsString;
+
+ return $this;
+ }
+
+ /**
+ * @deprecated 2.2
+ * Required - you need call the method that corresponds to the account credentials (i.e. invoice, accountCredit or paymentplan) used for the address lookup.
+ * @return $this
+ */
+ public function setOrderTypeInvoice()
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ return $this;
+ }
+
+ /**
+ * @deprecated 2.2
+ * Required - you need call the method that corresponds to the account credentials (i.e. invoice, accountCredit or paymentplan) used for the address lookup.
+ * @return $this
+ */
+ public function setOrderTypePaymentPlan()
+ {
+ $this->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+
+ return $this;
+ }
+
+ public function setOrderTypeAccountCredit()
+ {
+ $this->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+
+ return $this;
+ }
+
+ /**
+ * Prepares and Sends request
+ * @return GetAddressesResponse
+ */
+ public function doRequest()
+ {
+ $preparedRequest = $this->prepareRequest();
+ $request = new SveaDoRequest($this->conf, $this->orderType, "GetAddresses", $preparedRequest, $this->logging);
+ $response = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
+
+ return $response->response;
+ }
+
+ /**
+ * Sets and returns prepared request object. Used by doRequest().
+ *
+ * (The prepared request object may be inspected to see what attributes will
+ * be sent to Svea -- use ->prepareRequest() in place of ->doRequest() and
+ * inspect the resulting SveaRequest object.)
+ *
+ * @return SveaRequest
+ */
+ public function prepareRequest()
+ {
+
+ $this->validateRequest();
+
+ $auth = new SveaAuth(
+ $this->conf->getUsername($this->orderType, $this->countryCode),
+ $this->conf->getPassword($this->orderType, $this->countryCode),
+ $this->conf->getClientNumber($this->orderType, $this->countryCode)
+ );
+
+ $address = new SveaAddress(
+ $auth,
+ (isset($this->companyId) ? true : false),
+ $this->countryCode,
+ (isset($this->companyId) ? $this->companyId : $this->ssn)
+ );
+
+ $this->request = new SveaRequest($address);
+
+ return $this->request;
+ }
+
+ public function validateRequest()
+ {
+ $errors = $this->validate($this);
+ if (count($errors) > 0) {
+ $exceptionString = "";
+ foreach ($errors as $key => $value) {
+ $exceptionString .= "-" . $key . " : " . $value . "\n";
+ }
+
+ throw new ValidationException($exceptionString);
+ }
+ }
+
+ public function validate($getaddressesrequest)
+ {
+ $errors = [];
+
+ // countrycode -> ssn/companyid -> check credentials
+ $errors = $this->validateCountryCode($getaddressesrequest, $errors);
+ $errors = $this->validateCustomerIdentifier($getaddressesrequest, $errors);
+ if (count($errors) == 0) {
+ $this->orderType = $this->checkAndSetConfiguredPaymentMethod();
+ }
+ $errors = $this->validateCountryCodeConfigurationExists($getaddressesrequest, $errors);
+
+ return $errors;
+ }
+
+ private function validateCountryCode($getaddressesrequest, $errors)
+ {
+ if (isset($getaddressesrequest->countryCode) == FALSE) {
+ $errors[] = "countryCode is required. Use function setCountryCode().";
+ }
+
+ // TODO add validation of accepted countries
+ return $errors;
+ }
+
+ private function validateCustomerIdentifier($getaddressesrequest, $errors)
+ {
+ if (!isset($getaddressesrequest->ssn) && !isset($getaddressesrequest->companyId)) {
+ $errors[] = "customerIdentifier is required. Use function setCustomerIdentifer().";
+ }
+
+ return $errors;
+ }
+
+ private function checkAndSetConfiguredPaymentMethod()
+ {
+ if ($this->orderType == null) { // no order type set, so try and determine which configuration provider order type to use
+ $orderType = ConfigurationProvider::INVOICE_TYPE;
+ try {
+ $u = $this->conf->getUsername($orderType, $this->countryCode);
+ $p = $this->conf->getPassword($orderType, $this->countryCode);
+ $c = $this->conf->getClientNumber($orderType, $this->countryCode);
+ } catch (InvalidTypeException $e) { // thrown if no config found
+ // go on
+ }
+ if (isset($u) && isset($p) && isset($c)) {
+ return ConfigurationProvider::INVOICE_TYPE;
+ }
+
+ // set for accountCredit
+ $orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+ try {
+ $u = $this->conf->getUsername($orderType, $this->countryCode);
+ $p = $this->conf->getPassword($orderType, $this->countryCode);
+ $c = $this->conf->getClientNumber($orderType, $this->countryCode);
+ } catch (InvalidTypeException $e) { // thrown if no config found
+ // go on
+ }
+ if (isset($u) && isset($p) && isset($c)) {
+ return ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+ }
+
+ $orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+ try {
+ $u = $this->conf->getUsername($orderType, $this->countryCode);
+ $p = $this->conf->getPassword($orderType, $this->countryCode);
+ $c = $this->conf->getClientNumber($orderType, $this->countryCode);
+ } catch (InvalidTypeException $e) {
+ return null; // i.e. will throw exception in validation
+ }
+ if (isset($u) && isset($p) && isset($c)) { // i.e. not set or null
+ return ConfigurationProvider::PAYMENTPLAN_TYPE;
+ } else {
+ return null;
+ }
+ } else {
+ return $this->orderType; // if set, honour given order type
+ }
+ }
+
+ private function validateCountryCodeConfigurationExists($getaddressesrequest, $errors)
+ {
+ if (!isset($getaddressesrequest->orderType)) {
+ $errors[] = "missing authentication credentials. Check configuration.";
+ }
+
+ return $errors;
+ }
}
diff --git a/src/WebService/GetPaymentPlanParams/GetPaymentPlanParams.php b/src/WebService/GetPaymentPlanParams/GetPaymentPlanParams.php
index 8dae4f19..7f1dcdb2 100644
--- a/src/WebService/GetPaymentPlanParams/GetPaymentPlanParams.php
+++ b/src/WebService/GetPaymentPlanParams/GetPaymentPlanParams.php
@@ -22,66 +22,66 @@
*/
class GetPaymentPlanParams
{
- public $testmode = false;
- public $object;
- public $conf;
- public $countryCode;
- public $logging;
+ public $testmode = false;
+ public $object;
+ public $conf;
+ public $countryCode;
+ public $logging;
- function __construct($config)
- {
- $this->conf = $config;
- }
+ function __construct($config)
+ {
+ $this->conf = $config;
+ }
- /*
- * Enables raw HTTP logs
- */
- public function enableLogging($logging)
- {
- $this->logging = $logging;
- }
- /**
- * Required
- *
- * @param string $countryCodeAsString
- * @return $this
- */
- public function setCountryCode($countryCodeAsString)
- {
- $this->countryCode = $countryCodeAsString;
+ /*
+ * Enables raw HTTP logs
+ */
+ public function enableLogging($logging)
+ {
+ $this->logging = $logging;
+ }
+ /**
+ * Required
+ *
+ * @param string $countryCodeAsString
+ * @return $this
+ */
+ public function setCountryCode($countryCodeAsString)
+ {
+ $this->countryCode = $countryCodeAsString;
- return $this;
- }
+ return $this;
+ }
- /**
- * Prepares and sends request
- *
- * @return \Svea\WebPay\WebService\WebServiceResponse\PaymentPlanParamsResponse
- */
- public function doRequest()
- {
- $requestObject = $this->prepareRequest();
- $request = new SveaDoRequest($this->conf, ConfigurationProvider::PAYMENTPLAN_TYPE, "GetPaymentPlanParamsEu", $requestObject, $this->logging);
+ /**
+ * Prepares and sends request
+ *
+ * @return \Svea\WebPay\WebService\WebServiceResponse\PaymentPlanParamsResponse
+ */
+ public function doRequest()
+ {
+ $requestObject = $this->prepareRequest();
+ $request = new SveaDoRequest($this->conf, ConfigurationProvider::PAYMENTPLAN_TYPE, "GetPaymentPlanParamsEu", $requestObject, $this->logging);
- $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
+ $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
- return $responseObject->response;
- }
+ return $responseObject->response;
+ }
- /**
- * @return SveaRequest
- */
- public function prepareRequest()
- {
- $auth = new SveaAuth(
- $this->conf->getUsername(ConfigurationProvider::PAYMENTPLAN_TYPE, $this->countryCode),
- $this->conf->getPassword(ConfigurationProvider::PAYMENTPLAN_TYPE, $this->countryCode),
- $this->conf->getClientNumber(ConfigurationProvider::PAYMENTPLAN_TYPE, $this->countryCode)
- );
+ /**
+ * @return SveaRequest
+ */
+ public function prepareRequest()
+ {
+ $auth = new SveaAuth(
+ $this->conf->getUsername(ConfigurationProvider::PAYMENTPLAN_TYPE, $this->countryCode),
+ $this->conf->getPassword(ConfigurationProvider::PAYMENTPLAN_TYPE, $this->countryCode),
+ $this->conf->getClientNumber(ConfigurationProvider::PAYMENTPLAN_TYPE, $this->countryCode)
+ );
- $object = new SveaRequest();
- $object->request = (object)array("Auth" => $auth);
+ $object = new SveaRequest();
+ $object->request = (object)["Auth" => $auth];
- return $object;
- }
+ return $object;
+ }
}
diff --git a/src/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonth.php b/src/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonth.php
index a3d6ae40..24912700 100644
--- a/src/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonth.php
+++ b/src/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonth.php
@@ -22,36 +22,36 @@
*/
class PaymentPlanPricePerMonth
{
- public $values = array();
+ public $values = [];
- /**
- * PaymentPlanPricePerMonth constructor.
- * @param $price
- * @param $params
- * @param bool $ignoreMaxAndMinFlag
- * @param int decimals
- */
- function __construct($price, $params, $ignoreMaxAndMinFlag = false, $decimals = 0)
- {
- $this->calculate($price, $params, $ignoreMaxAndMinFlag, $decimals);
- }
+ /**
+ * PaymentPlanPricePerMonth constructor.
+ * @param $price
+ * @param $params
+ * @param bool $ignoreMaxAndMinFlag
+ * @param int decimals
+ */
+ function __construct($price, $params, $ignoreMaxAndMinFlag = false, $decimals = 0)
+ {
+ $this->calculate($price, $params, $ignoreMaxAndMinFlag, $decimals);
+ }
- /**
- * @param $price
- * @param $params
- * @param $ignoreMaxAndMinFlag
- * @param $decimals
- */
- private function calculate($price, $params, $ignoreMaxAndMinFlag, $decimals)
- {
- if (!empty($params)) {
- foreach ($params->campaignCodes as $key => $value) {
- if ($ignoreMaxAndMinFlag || ($price >= $value->fromAmount && $price <= $value->toAmount)) {
- $pair = Helper::objectToArray($value);
- $pair['pricePerMonth'] = round(($value->initialFee + (ceil($price * $value->monthlyAnnuityFactor) + $value->notificationFee) * max(1, $value->contractLengthInMonths - $value->numberOfPaymentFreeMonths)) / max(1, $value->contractLengthInMonths - $value->numberOfPaymentFreeMonths), $decimals);
- array_push($this->values, $pair);
- }
- }
- }
- }
+ /**
+ * @param $price
+ * @param $params
+ * @param $ignoreMaxAndMinFlag
+ * @param $decimals
+ */
+ private function calculate($price, $params, $ignoreMaxAndMinFlag, $decimals)
+ {
+ if (!empty($params)) {
+ foreach ($params->campaignCodes as $key => $value) {
+ if ($ignoreMaxAndMinFlag || ($price >= $value->fromAmount && $price <= $value->toAmount)) {
+ $pair = Helper::objectToArray($value);
+ $pair['pricePerMonth'] = round(($value->initialFee + (ceil($price * $value->monthlyAnnuityFactor) + $value->notificationFee) * max(1, $value->contractLengthInMonths - $value->numberOfPaymentFreeMonths)) / max(1, $value->contractLengthInMonths - $value->numberOfPaymentFreeMonths), $decimals);
+ array_push($this->values, $pair);
+ }
+ }
+ }
+ }
}
diff --git a/src/WebService/HandleOrder/CloseOrder.php b/src/WebService/HandleOrder/CloseOrder.php
index 1efcb612..6cacb2c1 100644
--- a/src/WebService/HandleOrder/CloseOrder.php
+++ b/src/WebService/HandleOrder/CloseOrder.php
@@ -15,61 +15,61 @@
*/
class CloseOrder extends HandleOrder
{
- /**
- * @param CloseOrderBuilder $CloseOrderBuilder
- */
- public function __construct($CloseOrderBuilder)
- {
- parent::__construct($CloseOrderBuilder);
- }
+ /**
+ * @param CloseOrderBuilder $CloseOrderBuilder
+ */
+ public function __construct($CloseOrderBuilder)
+ {
+ parent::__construct($CloseOrderBuilder);
+ }
- /**
- * Prepare and sends request
- * @return type CloseOrderEuResponse
- */
- public function doRequest()
- {
- $requestObject = $this->prepareRequest();
- $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "CloseOrderEu", $requestObject, $this->orderBuilder->logging);
- $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
+ /**
+ * Prepare and sends request
+ * @return type CloseOrderEuResponse
+ */
+ public function doRequest()
+ {
+ $requestObject = $this->prepareRequest();
+ $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "CloseOrderEu", $requestObject, $this->orderBuilder->logging);
+ $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
- return $responseObject->response;
- }
+ return $responseObject->response;
+ }
- /**
- * Returns prepared closeOrder request
- * @return SveaRequest
- */
- public function prepareRequest()
- {
- $this->validateRequest();
+ /**
+ * Returns prepared closeOrder request
+ * @return SveaRequest
+ */
+ public function prepareRequest()
+ {
+ $this->validateRequest();
- $sveaCloseOrder = new SveaCloseOrder;
- $sveaCloseOrder->Auth = $this->getStoreAuthorization();
- $orderInfo = new SveaCloseOrderInformation();
- $orderInfo->SveaOrderId = $this->orderBuilder->orderId;
- $sveaCloseOrder->CloseOrderInformation = $orderInfo;
+ $sveaCloseOrder = new SveaCloseOrder;
+ $sveaCloseOrder->Auth = $this->getStoreAuthorization();
+ $orderInfo = new SveaCloseOrderInformation();
+ $orderInfo->SveaOrderId = $this->orderBuilder->orderId;
+ $sveaCloseOrder->CloseOrderInformation = $orderInfo;
- $object = new SveaRequest();
- $object->request = $sveaCloseOrder;
+ $object = new SveaRequest();
+ $object->request = $sveaCloseOrder;
- return $object;
- }
+ return $object;
+ }
- public function validate($order)
- {
- $errors = array();
- $errors = $this->validateOrderId($order, $errors);
+ public function validate($order)
+ {
+ $errors = [];
+ $errors = $this->validateOrderId($order, $errors);
- return $errors;
- }
+ return $errors;
+ }
- private function validateOrderId($order, $errors)
- {
- if (isset($order->orderId) == FALSE) {
- $errors['missing value'] = "OrderId is required. Use function setOrderId() with the SveaOrderId from the createOrder response.";
- }
+ private function validateOrderId($order, $errors)
+ {
+ if (isset($order->orderId) == FALSE) {
+ $errors['missing value'] = "OrderId is required. Use function setOrderId() with the SveaOrderId from the createOrder response.";
+ }
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/WebService/HandleOrder/DeliverAccountCredit.php b/src/WebService/HandleOrder/DeliverAccountCredit.php
index edcf1eef..954067a4 100644
--- a/src/WebService/HandleOrder/DeliverAccountCredit.php
+++ b/src/WebService/HandleOrder/DeliverAccountCredit.php
@@ -24,127 +24,127 @@
*/
class DeliverAccountCredit extends HandleOrder
{
- /**
- * @param DeliverOrderBuilder $DeliverOrderBuilder
- */
- public function __construct($DeliverOrderBuilder)
- {
- $DeliverOrderBuilder->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+ /**
+ * @param DeliverOrderBuilder $DeliverOrderBuilder
+ */
+ public function __construct($DeliverOrderBuilder)
+ {
+ $DeliverOrderBuilder->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
- parent::__construct($DeliverOrderBuilder);
- }
+ parent::__construct($DeliverOrderBuilder);
+ }
- /**
- * Prepare and sends request
- * @return DeliverOrderResult
- */
- public function doRequest()
- {
- $requestObject = $this->prepareRequest();
-
- $priceIncludingVat = $requestObject->request->DeliverOrderInformation->DeliverAccountCreditDetails->OrderRows['OrderRow'][0]->PriceIncludingVat;
-
- $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "DeliverOrderEu", $requestObject, $this->orderBuilder->logging);
-
- $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
-
- if ($responseObject->response->resultcode == "50036") {
- $requestObject = $this->prepareRequest($priceIncludingVat);
- $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "DeliverOrderEu", $requestObject);
- $responseObject = new SveaResponse($request->result, "");
- }
-
- return $responseObject->response;
- }
-
- /**
- * Returns prepared request
- * @return SveaRequest
- */
- public function prepareRequest($priceIncludingVat = NULL)
- {
- $errors = $this->validateRequest();
-
- $sveaDeliverOrder = new SveaDeliverOrder;
-
- $sveaDeliverOrder->Auth = $this->getStoreAuthorization();
-
- $orderInformation = new SveaDeliverOrderInformation($this->orderBuilder->orderType);
- $orderInformation->SveaOrderId = $this->orderBuilder->orderId;
- $orderInformation->OrderType = $this->orderBuilder->orderType;
-
- if ($this->orderBuilder->orderType == ConfigurationProvider::ACCOUNTCREDIT_TYPE) {
- $accountCreditDetails = new SveaDeliverInvoiceDetails();
- $accountCreditDetails->InvoiceDistributionType = $this->orderBuilder->distributionType;
- $accountCreditDetails->IsCreditInvoice = isset($this->orderBuilder->invoiceIdToCredit) ? TRUE : FALSE; // required
-
- if (isset($this->orderBuilder->invoiceIdToCredit)) {
- $accountCreditDetails->InvoiceIdToCredit = $this->orderBuilder->invoiceIdToCredit; // optional
- }
-
- $accountCreditDetails->NumberOfCreditDays = isset($this->orderBuilder->numberOfCreditDays) ? $this->orderBuilder->numberOfCreditDays : 0;
-
- $formatter = new WebServiceRowFormatter($this->orderBuilder, $priceIncludingVat);
- $orderRow['OrderRow'] = $formatter->formatRows();
-
- $accountCreditDetails->OrderRows = $orderRow;
- $orderInformation->DeliverAccountCreditDetails = $accountCreditDetails;
- }
-
- $sveaDeliverOrder->DeliverOrderInformation = $orderInformation;
-
- $object = new SveaRequest();
- $object->request = $sveaDeliverOrder;
-
- return $object;
- }
-
- public function validate($order)
- {
- $errors = array();
- $errors = $this->validateCountryCode($order, $errors);
- $errors = $this->validateOrderId($order, $errors);
- $errors = $this->validateInvoiceDetails($order, $errors);
- $errors = $this->validateOrderRows($order, $errors);
-
- return $errors;
- }
-
- private function validateCountryCode($order, $errors)
- {
- if (isset($order->countryCode) == FALSE) {
- $errors['missing value'] = "CountryCode is required. Use function setCountryCode().";
- }
-
- return $errors;
- }
-
- private function validateOrderId($order, $errors)
- {
- if (isset($order->orderId) == FALSE) {
- $errors['missing value'] = "OrderId is required. Use function setOrderId() with the SveaOrderId from the createOrder response.";
- }
-
- return $errors;
- }
+ /**
+ * Prepare and sends request
+ * @return DeliverOrderResult
+ */
+ public function doRequest()
+ {
+ $requestObject = $this->prepareRequest();
+
+ $priceIncludingVat = $requestObject->request->DeliverOrderInformation->DeliverAccountCreditDetails->OrderRows['OrderRow'][0]->PriceIncludingVat;
+
+ $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "DeliverOrderEu", $requestObject, $this->orderBuilder->logging);
+
+ $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
+
+ if ($responseObject->response->resultcode == "50036") {
+ $requestObject = $this->prepareRequest($priceIncludingVat);
+ $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "DeliverOrderEu", $requestObject);
+ $responseObject = new SveaResponse($request->result, "");
+ }
+
+ return $responseObject->response;
+ }
+
+ /**
+ * Returns prepared request
+ * @return SveaRequest
+ */
+ public function prepareRequest($priceIncludingVat = NULL)
+ {
+ $errors = $this->validateRequest();
+
+ $sveaDeliverOrder = new SveaDeliverOrder;
+
+ $sveaDeliverOrder->Auth = $this->getStoreAuthorization();
+
+ $orderInformation = new SveaDeliverOrderInformation($this->orderBuilder->orderType);
+ $orderInformation->SveaOrderId = $this->orderBuilder->orderId;
+ $orderInformation->OrderType = $this->orderBuilder->orderType;
+
+ if ($this->orderBuilder->orderType == ConfigurationProvider::ACCOUNTCREDIT_TYPE) {
+ $accountCreditDetails = new SveaDeliverInvoiceDetails();
+ $accountCreditDetails->InvoiceDistributionType = $this->orderBuilder->distributionType;
+ $accountCreditDetails->IsCreditInvoice = isset($this->orderBuilder->invoiceIdToCredit) ? TRUE : FALSE; // required
+
+ if (isset($this->orderBuilder->invoiceIdToCredit)) {
+ $accountCreditDetails->InvoiceIdToCredit = $this->orderBuilder->invoiceIdToCredit; // optional
+ }
+
+ $accountCreditDetails->NumberOfCreditDays = isset($this->orderBuilder->numberOfCreditDays) ? $this->orderBuilder->numberOfCreditDays : 0;
+
+ $formatter = new WebServiceRowFormatter($this->orderBuilder, $priceIncludingVat);
+ $orderRow['OrderRow'] = $formatter->formatRows();
+
+ $accountCreditDetails->OrderRows = $orderRow;
+ $orderInformation->DeliverAccountCreditDetails = $accountCreditDetails;
+ }
+
+ $sveaDeliverOrder->DeliverOrderInformation = $orderInformation;
+
+ $object = new SveaRequest();
+ $object->request = $sveaDeliverOrder;
+
+ return $object;
+ }
+
+ public function validate($order)
+ {
+ $errors = [];
+ $errors = $this->validateCountryCode($order, $errors);
+ $errors = $this->validateOrderId($order, $errors);
+ $errors = $this->validateInvoiceDetails($order, $errors);
+ $errors = $this->validateOrderRows($order, $errors);
+
+ return $errors;
+ }
+
+ private function validateCountryCode($order, $errors)
+ {
+ if (isset($order->countryCode) == FALSE) {
+ $errors['missing value'] = "CountryCode is required. Use function setCountryCode().";
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderId($order, $errors)
+ {
+ if (isset($order->orderId) == FALSE) {
+ $errors['missing value'] = "OrderId is required. Use function setOrderId() with the SveaOrderId from the createOrder response.";
+ }
+
+ return $errors;
+ }
- private function validateInvoiceDetails($order, $errors)
- {
- if (isset($order->orderId) && $order->orderType == ConfigurationProvider::INVOICE_TYPE && isset($order->distributionType) == FALSE) {
- $errors['missing value'] = "InvoiceDistributionType is required for deliverInvoiceOrder. Use function setInvoiceDistributionType().";
- }
+ private function validateInvoiceDetails($order, $errors)
+ {
+ if (isset($order->orderId) && $order->orderType == ConfigurationProvider::INVOICE_TYPE && isset($order->distributionType) == FALSE) {
+ $errors['missing value'] = "InvoiceDistributionType is required for deliverInvoiceOrder. Use function setInvoiceDistributionType().";
+ }
- return $errors;
- }
+ return $errors;
+ }
- private function validateOrderRows($order, $errors)
- {
- if ($order->orderType == ConfigurationProvider::INVOICE_TYPE && empty($order->orderRows) && empty($order->shippingFee) && empty($order->invoiceFee)) {
- $errors['missing values'] = "No rows has been included. Use function beginOrderRow(), beginShippingfee() or beginInvoiceFee().";
- }
+ private function validateOrderRows($order, $errors)
+ {
+ if ($order->orderType == ConfigurationProvider::INVOICE_TYPE && empty($order->orderRows) && empty($order->shippingFee) && empty($order->invoiceFee)) {
+ $errors['missing values'] = "No rows has been included. Use function beginOrderRow(), beginShippingfee() or beginInvoiceFee().";
+ }
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/WebService/HandleOrder/DeliverInvoice.php b/src/WebService/HandleOrder/DeliverInvoice.php
index 6a1b1c39..159d6cb3 100644
--- a/src/WebService/HandleOrder/DeliverInvoice.php
+++ b/src/WebService/HandleOrder/DeliverInvoice.php
@@ -24,116 +24,116 @@
*/
class DeliverInvoice extends HandleOrder
{
- /**
- * @param DeliverOrderBuilder $DeliverOrderBuilder
- */
- public function __construct($DeliverOrderBuilder)
- {
- $DeliverOrderBuilder->orderType = ConfigurationProvider::INVOICE_TYPE;
-
- parent::__construct($DeliverOrderBuilder);
- }
-
- /**
- * Prepare and sends request
- * @return DeliverOrderResult
- */
- public function doRequest()
- {
- $requestObject = $this->prepareRequest();
- $priceIncludingVat = $requestObject->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat;
- $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "DeliverOrderEu", $requestObject, $this->orderBuilder->logging);
- $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
- if ($responseObject->response->resultcode == "50036") {
- $requestObject = $this->prepareRequest($priceIncludingVat);
- $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "DeliverOrderEu", $requestObject, $this->orderBuilder->logging);
- $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
- }
-
- return $responseObject->response;
- }
-
- /**
- * Returns prepared request
- * @return SveaRequest
- */
- public function prepareRequest($priceIncludingVat = NULL)
- {
- $errors = $this->validateRequest();
-
- $sveaDeliverOrder = new SveaDeliverOrder;
- $sveaDeliverOrder->Auth = $this->getStoreAuthorization();
- $orderInformation = new SveaDeliverOrderInformation($this->orderBuilder->orderType);
- $orderInformation->SveaOrderId = $this->orderBuilder->orderId;
- $orderInformation->OrderType = $this->orderBuilder->orderType;
-
- if ($this->orderBuilder->orderType == ConfigurationProvider::INVOICE_TYPE) {
- $invoiceDetails = new SveaDeliverInvoiceDetails();
- $invoiceDetails->InvoiceDistributionType = $this->orderBuilder->distributionType;
- $invoiceDetails->IsCreditInvoice = isset($this->orderBuilder->invoiceIdToCredit) ? TRUE : FALSE; // required
- if (isset($this->orderBuilder->invoiceIdToCredit)) {
- $invoiceDetails->InvoiceIdToCredit = $this->orderBuilder->invoiceIdToCredit; // optional
- }
- $invoiceDetails->NumberOfCreditDays = isset($this->orderBuilder->numberOfCreditDays) ? $this->orderBuilder->numberOfCreditDays : 0;
- $formatter = new WebServiceRowFormatter($this->orderBuilder, $priceIncludingVat);
- $orderRow['OrderRow'] = $formatter->formatRows();
- $invoiceDetails->OrderRows = $orderRow;
- $orderInformation->DeliverInvoiceDetails = $invoiceDetails;
- }
-
- $sveaDeliverOrder->DeliverOrderInformation = $orderInformation;
- $object = new SveaRequest();
- $object->request = $sveaDeliverOrder;
-
- return $object;
- }
-
- public function validate($order)
- {
- $errors = array();
- $errors = $this->validateCountryCode($order, $errors);
- $errors = $this->validateOrderId($order, $errors);
- $errors = $this->validateInvoiceDetails($order, $errors);
- $errors = $this->validateOrderRows($order, $errors);
-
- return $errors;
- }
-
- private function validateCountryCode($order, $errors)
- {
- if (isset($order->countryCode) == FALSE) {
- $errors['missing value'] = "CountryCode is required. Use function setCountryCode().";
- }
-
- return $errors;
- }
-
- private function validateOrderId($order, $errors)
- {
- if (isset($order->orderId) == FALSE) {
- $errors['missing value'] = "OrderId is required. Use function setOrderId() with the SveaOrderId from the createOrder response.";
- }
-
- return $errors;
- }
-
- private function validateInvoiceDetails($order, $errors)
- {
- if (isset($order->orderId) && $order->orderType == ConfigurationProvider::INVOICE_TYPE && isset($order->distributionType) == FALSE) {
- $errors['missing value'] = "InvoiceDistributionType is required for deliverInvoiceOrder. Use function setInvoiceDistributionType().";
- }
-
- return $errors;
- }
-
- private function validateOrderRows($order, $errors)
- {
- if ($order->orderType == ConfigurationProvider::INVOICE_TYPE && empty($order->orderRows) && empty($order->shippingFee) && empty($order->invoiceFee)) {
- $errors['missing values'] = "No rows has been included. Use function beginOrderRow(), beginShippingfee() or beginInvoiceFee().";
- }
-
- return $errors;
- }
+ /**
+ * @param DeliverOrderBuilder $DeliverOrderBuilder
+ */
+ public function __construct($DeliverOrderBuilder)
+ {
+ $DeliverOrderBuilder->orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ parent::__construct($DeliverOrderBuilder);
+ }
+
+ /**
+ * Prepare and sends request
+ * @return DeliverOrderResult
+ */
+ public function doRequest()
+ {
+ $requestObject = $this->prepareRequest();
+ $priceIncludingVat = $requestObject->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat;
+ $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "DeliverOrderEu", $requestObject, $this->orderBuilder->logging);
+ $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
+ if ($responseObject->response->resultcode == "50036") {
+ $requestObject = $this->prepareRequest($priceIncludingVat);
+ $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "DeliverOrderEu", $requestObject, $this->orderBuilder->logging);
+ $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
+ }
+
+ return $responseObject->response;
+ }
+
+ /**
+ * Returns prepared request
+ * @return SveaRequest
+ */
+ public function prepareRequest($priceIncludingVat = NULL)
+ {
+ $errors = $this->validateRequest();
+
+ $sveaDeliverOrder = new SveaDeliverOrder;
+ $sveaDeliverOrder->Auth = $this->getStoreAuthorization();
+ $orderInformation = new SveaDeliverOrderInformation($this->orderBuilder->orderType);
+ $orderInformation->SveaOrderId = $this->orderBuilder->orderId;
+ $orderInformation->OrderType = $this->orderBuilder->orderType;
+
+ if ($this->orderBuilder->orderType == ConfigurationProvider::INVOICE_TYPE) {
+ $invoiceDetails = new SveaDeliverInvoiceDetails();
+ $invoiceDetails->InvoiceDistributionType = $this->orderBuilder->distributionType;
+ $invoiceDetails->IsCreditInvoice = isset($this->orderBuilder->invoiceIdToCredit) ? TRUE : FALSE; // required
+ if (isset($this->orderBuilder->invoiceIdToCredit)) {
+ $invoiceDetails->InvoiceIdToCredit = $this->orderBuilder->invoiceIdToCredit; // optional
+ }
+ $invoiceDetails->NumberOfCreditDays = isset($this->orderBuilder->numberOfCreditDays) ? $this->orderBuilder->numberOfCreditDays : 0;
+ $formatter = new WebServiceRowFormatter($this->orderBuilder, $priceIncludingVat);
+ $orderRow['OrderRow'] = $formatter->formatRows();
+ $invoiceDetails->OrderRows = $orderRow;
+ $orderInformation->DeliverInvoiceDetails = $invoiceDetails;
+ }
+
+ $sveaDeliverOrder->DeliverOrderInformation = $orderInformation;
+ $object = new SveaRequest();
+ $object->request = $sveaDeliverOrder;
+
+ return $object;
+ }
+
+ public function validate($order)
+ {
+ $errors = [];
+ $errors = $this->validateCountryCode($order, $errors);
+ $errors = $this->validateOrderId($order, $errors);
+ $errors = $this->validateInvoiceDetails($order, $errors);
+ $errors = $this->validateOrderRows($order, $errors);
+
+ return $errors;
+ }
+
+ private function validateCountryCode($order, $errors)
+ {
+ if (isset($order->countryCode) == FALSE) {
+ $errors['missing value'] = "CountryCode is required. Use function setCountryCode().";
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderId($order, $errors)
+ {
+ if (isset($order->orderId) == FALSE) {
+ $errors['missing value'] = "OrderId is required. Use function setOrderId() with the SveaOrderId from the createOrder response.";
+ }
+
+ return $errors;
+ }
+
+ private function validateInvoiceDetails($order, $errors)
+ {
+ if (isset($order->orderId) && $order->orderType == ConfigurationProvider::INVOICE_TYPE && isset($order->distributionType) == FALSE) {
+ $errors['missing value'] = "InvoiceDistributionType is required for deliverInvoiceOrder. Use function setInvoiceDistributionType().";
+ }
+
+ return $errors;
+ }
+
+ private function validateOrderRows($order, $errors)
+ {
+ if ($order->orderType == ConfigurationProvider::INVOICE_TYPE && empty($order->orderRows) && empty($order->shippingFee) && empty($order->invoiceFee)) {
+ $errors['missing values'] = "No rows has been included. Use function beginOrderRow(), beginShippingfee() or beginInvoiceFee().";
+ }
+
+ return $errors;
+ }
}
diff --git a/src/WebService/HandleOrder/DeliverPaymentPlan.php b/src/WebService/HandleOrder/DeliverPaymentPlan.php
index 2eedf41e..2cbe6264 100644
--- a/src/WebService/HandleOrder/DeliverPaymentPlan.php
+++ b/src/WebService/HandleOrder/DeliverPaymentPlan.php
@@ -17,73 +17,73 @@
*/
class DeliverPaymentPlan extends HandleOrder
{
- /**
- * @param DeliverOrderBuilder $order
- */
- public function __construct($order)
- {
- $order->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
- parent::__construct($order);
- }
+ /**
+ * @param DeliverOrderBuilder $order
+ */
+ public function __construct($order)
+ {
+ $order->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+ parent::__construct($order);
+ }
- /**
- * Prepare and sends request
- * @return CloseOrderResult
- */
- public function doRequest()
- {
- $requestObject = $this->prepareRequest();
- $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "DeliverOrderEu", $requestObject, $this->orderBuilder->logging);
- $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
+ /**
+ * Prepare and sends request
+ * @return CloseOrderResult
+ */
+ public function doRequest()
+ {
+ $requestObject = $this->prepareRequest();
+ $request = new SveaDoRequest($this->orderBuilder->conf, $this->orderBuilder->orderType, "DeliverOrderEu", $requestObject, $this->orderBuilder->logging);
+ $responseObject = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
- return $responseObject->response;
- }
+ return $responseObject->response;
+ }
- /**
- * Returns prepared request
- * @return SveaRequest
- */
- public function prepareRequest()
- {
- $errors = $this->validateRequest();
+ /**
+ * Returns prepared request
+ * @return SveaRequest
+ */
+ public function prepareRequest()
+ {
+ $errors = $this->validateRequest();
- $sveaDeliverOrder = new SveaDeliverOrder;
- $sveaDeliverOrder->Auth = $this->getStoreAuthorization();
- $orderInformation = new SveaDeliverOrderInformation($this->orderBuilder->orderType);
- $orderInformation->SveaOrderId = $this->orderBuilder->orderId;
- $orderInformation->OrderType = $this->orderBuilder->orderType;
+ $sveaDeliverOrder = new SveaDeliverOrder;
+ $sveaDeliverOrder->Auth = $this->getStoreAuthorization();
+ $orderInformation = new SveaDeliverOrderInformation($this->orderBuilder->orderType);
+ $orderInformation->SveaOrderId = $this->orderBuilder->orderId;
+ $orderInformation->OrderType = $this->orderBuilder->orderType;
- $sveaDeliverOrder->DeliverOrderInformation = $orderInformation;
- $object = new SveaRequest();
- $object->request = $sveaDeliverOrder;
+ $sveaDeliverOrder->DeliverOrderInformation = $orderInformation;
+ $object = new SveaRequest();
+ $object->request = $sveaDeliverOrder;
- return $object;
- }
+ return $object;
+ }
- public function validate($order)
- {
- $errors = array();
- $errors = $this->validateCountryCode($order, $errors);
- $errors = $this->validateOrderId($order, $errors);
+ public function validate($order)
+ {
+ $errors = [];
+ $errors = $this->validateCountryCode($order, $errors);
+ $errors = $this->validateOrderId($order, $errors);
- return $errors;
- }
+ return $errors;
+ }
- private function validateCountryCode($order, $errors)
- {
- if (isset($order->countryCode) == FALSE) {
- $errors['missing value'] = "CountryCode is required. Use function setCountryCode().";
- }
+ private function validateCountryCode($order, $errors)
+ {
+ if (isset($order->countryCode) == FALSE) {
+ $errors['missing value'] = "CountryCode is required. Use function setCountryCode().";
+ }
- return $errors;
- }
+ return $errors;
+ }
- private function validateOrderId($order, $errors)
- {
- if (isset($order->orderId) == FALSE) {
- $errors['missing value'] = "OrderId is required. Use function setOrderId() with the SveaOrderId from the createOrder response.";
- }
+ private function validateOrderId($order, $errors)
+ {
+ if (isset($order->orderId) == FALSE) {
+ $errors['missing value'] = "OrderId is required. Use function setOrderId() with the SveaOrderId from the createOrder response.";
+ }
- return $errors;
- }
+ return $errors;
+ }
}
diff --git a/src/WebService/HandleOrder/HandleOrder.php b/src/WebService/HandleOrder/HandleOrder.php
index 6fe86d1a..6f91b36d 100644
--- a/src/WebService/HandleOrder/HandleOrder.php
+++ b/src/WebService/HandleOrder/HandleOrder.php
@@ -14,53 +14,53 @@
*/
abstract class HandleOrder
{
- /**
- * CloseOrderBuilder|DeliverOrderBuilder $handler object containing the settings for the HandleOrder request
- */
- public $orderBuilder;
+ /**
+ * CloseOrderBuilder|DeliverOrderBuilder $handler object containing the settings for the HandleOrder request
+ */
+ public $orderBuilder;
- public $errors = array();
+ public $errors = [];
- /**
- * @param CloseOrderBuilder|DeliverOrderBuilder $handleOrderBuilder
- */
- public function __construct($handleOrderBuilder)
- {
- $this->orderBuilder = $handleOrderBuilder;
- }
+ /**
+ * @param CloseOrderBuilder|DeliverOrderBuilder $handleOrderBuilder
+ */
+ public function __construct($handleOrderBuilder)
+ {
+ $this->orderBuilder = $handleOrderBuilder;
+ }
- /**
- * Validates the orderBuilder object to make sure that all required settings
- * are present. If not, throws an exception. Actual validation is delegated
- * to subclass validate() implementations.
- *
- * @throws ValidationException
- */
- public function validateRequest()
- {
- $errors = $this->validate($this->orderBuilder);
- if (count($errors) > 0) {
- $exceptionString = "";
- foreach ($errors as $key => $value) {
- $exceptionString .= "-" . $key . " : " . $value . "\n";
- }
+ /**
+ * Validates the orderBuilder object to make sure that all required settings
+ * are present. If not, throws an exception. Actual validation is delegated
+ * to subclass validate() implementations.
+ *
+ * @throws ValidationException
+ */
+ public function validateRequest()
+ {
+ $errors = $this->validate($this->orderBuilder);
+ if (count($errors) > 0) {
+ $exceptionString = "";
+ foreach ($errors as $key => $value) {
+ $exceptionString .= "-" . $key . " : " . $value . "\n";
+ }
- throw new ValidationException($exceptionString);
- }
- }
+ throw new ValidationException($exceptionString);
+ }
+ }
- abstract function validate($orderBuilder);
+ abstract function validate($orderBuilder);
- /**
- * creates a SveaAuth object using the passed orderBuilder configuration
- * @return SveaAuth
- */
- protected function getStoreAuthorization()
- {
- return new SveaAuth(
- $this->orderBuilder->conf->getUsername($this->orderBuilder->orderType, $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getPassword($this->orderBuilder->orderType, $this->orderBuilder->countryCode),
- $this->orderBuilder->conf->getClientNumber($this->orderBuilder->orderType, $this->orderBuilder->countryCode)
- );
- } // validate is defined by subclasses, should validate all order fields required for call is present
+ /**
+ * creates a SveaAuth object using the passed orderBuilder configuration
+ * @return SveaAuth
+ */
+ protected function getStoreAuthorization()
+ {
+ return new SveaAuth(
+ $this->orderBuilder->conf->getUsername($this->orderBuilder->orderType, $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getPassword($this->orderBuilder->orderType, $this->orderBuilder->countryCode),
+ $this->orderBuilder->conf->getClientNumber($this->orderBuilder->orderType, $this->orderBuilder->countryCode)
+ );
+ } // validate is defined by subclasses, should validate all order fields required for call is present
}
diff --git a/src/WebService/Helper/WebServiceRowFormatter.php b/src/WebService/Helper/WebServiceRowFormatter.php
index b98f2018..18480f63 100644
--- a/src/WebService/Helper/WebServiceRowFormatter.php
+++ b/src/WebService/Helper/WebServiceRowFormatter.php
@@ -13,608 +13,608 @@
*/
class WebServiceRowFormatter
{
- protected $order;
- protected $totalAmountExVat; // summed in calculateTotals
- protected $totalVatAsAmount; // summed in calculateTotals
- protected $totalAmountIncVat; // derived from ExVat + IncVat
- protected $totalVatAsPercent; // derived from ExVat + IncVat
-
- protected $totalAmountPerVatRateIncVat; // summed in calculateTotals, used to calculate "mean vat" split into given vat rates
- protected $totalAmountPerVatRateExVat; // summed in calculateTotals, used to calculate "mean vat" split into given vat rates
-
- protected $newRows;
- protected $priceIncludingVat = false;
- protected $resendOrderVat; // used from admin service functions, when original request got a 50036 error
-
- /**
- * @param $order
- * @param $resendOrderVat
- */
- public function __construct($order, $resendOrderVat = NULL)
- {
- $this->order = $order;
- $this->resendOrderVat = $resendOrderVat;
-
- $this->totalAmountPerVatRateIncVat = array();
- $this->totalAmountPerVatRateExVat = array();
- }
-
- public function formatRows()
- {
- $this->newRows = array();
-
- $this->calculateTotals();
-
- if ($this->resendOrderVat === NULL) {
- $this->determineVatFlag();
- } else {
- $this->priceIncludingVat = $this->resendOrderVat ? FALSE : TRUE;
- }
-
- foreach ($this->order->rows as $row) {
- switch (get_class($row)) {
- case 'Svea\WebPay\BuildOrder\RowBuilders\OrderRow':
- $this->formatOrderRows($row);
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\ShippingFee':
- $this->formatShippingFeeRows($row);
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee':
- $this->formatInvoiceFeeRows($row);
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount':
- $this->formatFixedDiscountRows($row);
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount':
- $this->formatRelativeDiscountRows($row);
- break;
- default:
- break;
- }
- }
-
-
- return $this->newRows;
- }
-
- protected function calculateTotals()
- {
- $this->totalAmountExVat = 0;
- $this->totalVatAsAmount = 0;
-
- foreach ($this->order->orderRows as $product) {
-
- // amountExVat & vatPercent used to specify product price
- if (isset($product->vatPercent) && isset($product->amountExVat)) {
- $this->totalAmountExVat += $product->amountExVat * $product->quantity;
- $this->totalVatAsAmount += ($product->vatPercent / 100 * $product->amountExVat) * $product->quantity;
-
- $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateIncVat, $product->vatPercent,
- WebServiceRowFormatter::convertExVatToIncVat($product->amountExVat, $product->vatPercent) * $product->quantity);
- $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateExVat, $product->vatPercent,
- $product->amountExVat * $product->quantity);
- } // amountIncVat & vatPercent used to specify product price
- elseif (isset($product->vatPercent) && isset($product->amountIncVat)) {
- $amountExVat = WebServiceRowFormatter::convertIncVatToExVat($product->amountIncVat, $product->vatPercent);
- $this->totalAmountExVat += $amountExVat * $product->quantity;
- $this->totalVatAsAmount += ($product->vatPercent / 100 * $amountExVat) * $product->quantity;
-
- $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateIncVat, $product->vatPercent,
- $product->amountIncVat * $product->quantity);
- $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateExVat, $product->vatPercent,
- WebServiceRowFormatter::convertIncVatToExVat($product->amountIncVat, $product->vatPercent) * $product->quantity);
- } // no vatPercent given
- else {
- $this->totalAmountExVat += $product->amountExVat * $product->quantity;
- $this->totalVatAsAmount += ($product->amountIncVat - $product->amountExVat) * $product->quantity;
-
- $vatRate = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($product->amountIncVat, $product->amountExVat);
-
- $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateIncVat, $vatRate,
- $product->amountIncVat * $product->quantity);
- $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateExVat, $vatRate,
- $product->amountExVat * $product->quantity);
- }
- }
- $this->totalAmountIncVat = $this->totalAmountExVat + $this->totalVatAsAmount;
- $this->totalAmountExVat = $this->totalAmountIncVat - $this->totalVatAsAmount;
- if ($this->totalAmountExVat > 0) {
- $this->totalVatAsPercent = $this->totalVatAsAmount / $this->totalAmountIncVat; //e.g. 0,20 if percentage 20
- }
- }
-
- protected function increaseCumulativeVatRateAmounts(&$array, $key, $value)
- {
- if (isset($array[$key])) {
- $array[$key] += $value;
- } else {
- $array[$key] = $value;
- }
- }
-
- /**
- * Converts an amount excluding vat to amount including vat, given a vat rate in percent.
- *
- * @param float $amountExVat
- * @param isNumeric $vatPercent
- * @return float amountExVat
- */
- public static function convertExVatToIncVat($amountExVat, $vatPercent)
- {
- return ($amountExVat * (1 + $vatPercent / 100));
- }
-
- // used to create/increase the totalAmountPerVatRateIncVat and totalAmountPerVatRateExVat arrays in calculateTotals();
-
- /**
- * Converts an amount including vat to amount excluding vat, given a vat rate in percent.
- *
- * @param float $amountIncVat
- * @param isNumeric $vatPercent
- * @return float amountExVat
- */
- public static function convertIncVatToExVat($amountIncVat, $vatPercent)
- {
- $reverseVatPercent = (1 - (1 / (1 + $vatPercent / 100))); // calculate "reverse vat", i.e. 25% => 20%
- return ($amountIncVat - $amountIncVat * $reverseVatPercent);
- }
-
- /**
- * Helper function, calculates vat percentage as int from prices with and without vat.
- * Note: this function will drop any vat rate fractions, i.e. it only handles vat rates that can be expressed as integers.
- */
- public static function calculateVatPercentFromPriceExVatAndPriceIncVat($incVat, $exVat)
- {
- if ($exVat == 0.0 || $incVat == 0.0) // avoid -100% vat on i.e. free products or fees
- return 0;
- else
- return Helper::bround((($incVat / $exVat) - 1) * 100);
- }
-
- protected function determineVatFlag()
- {
- $exVat = 0;
- $incVat = 0;
- foreach ($this->order->rows as $row) {
- switch (get_class($row)) {
- //relative discount
- // ignored, as relative discount doesn't use setAmountExVat/-IncVat at all
- case 'Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount':
- break;
- case 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount':
- if (isset($row->amountExVat) && isset($row->amountIncVat)) {
- $incVat++;
- }
- if (isset($row->amountExVat) && !isset($row->amountIncVat)) {
- $exVat++;
- } else {
- $incVat++;
- }
- break;
- default:
- if (isset($row->amountExVat) && isset($row->amountIncVat)) {
- $incVat++;
- } elseif (isset($row->amountExVat) && isset ($row->vatPercent)) {
- $exVat++;
- } else {
- $incVat++;
- }
- break;
- }
-
- }
- //if at least one of the non-discount rows are defined exvat, need to use set priceIncludingVat to false
- if ($exVat >= 1) {
- $this->priceIncludingVat = FALSE;
- } else {
- $this->priceIncludingVat = TRUE;
- }
-
- }
-
- protected function formatOrderRows($row)
- {
-// foreach ($this->order->orderRows as $row) {
-
- $orderRow = new SveaOrderRow();
-
- if (isset($row->articleNumber)) {
- $orderRow->ArticleNumber = $row->articleNumber;
- }
-
- $orderRow->Description = $this->formatRowNameAndDescription($row);
-
- if (isset($row->unit)) {
- $orderRow->Unit = $row->unit;
- }
- $orderRow->DiscountPercent = (isset($row->discountPercent) ? $row->discountPercent : 0);
- $orderRow->NumberOfUnits = $row->quantity;
-
- // amountExVat & vatPercent used to specify product price
- if (isset($row->vatPercent) && isset($row->amountExVat)) {
- $orderRow->PricePerUnit = $this->priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($row->amountExVat, Helper::bround($row->vatPercent)) : $row->amountExVat;
- $orderRow->VatPercent = Helper::bround($row->vatPercent);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- } // amountIncVat & vatPercent used to specify product price
- elseif (isset($row->vatPercent) && isset($row->amountIncVat)) {
- $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amountIncVat, Helper::bround($row->vatPercent));
- $orderRow->VatPercent = Helper::bround($row->vatPercent);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- } // no vatPercent given
- else {
- $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : $row->amountExVat;
- $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($row->amountIncVat, $row->amountExVat);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- }
-
- $this->newRows[] = $orderRow;
-// }
- }
-
- /**
- * As the Europe Web Service API only has a description field, join name and description, if both are given.
- *
- * @param OrderRow|ShippingFee|et al . $webPayItemRow an instance of the order row classes from Svea\WebPay\WebPayItem
- * @return string the combined description string that should be written to Description
- */
- public function formatRowNameAndDescription($webPayItemRow)
- {
-
- $description = ""; //fallback to empty string if we haven't got either of name or description
-
- // if both name and description are set in the package orderrow, add both to the request row description field
- if (isset($webPayItemRow->name) && isset($webPayItemRow->description)) {
- $description = $webPayItemRow->name . ': ' . $webPayItemRow->description;
- } // else, use either description or name, if set
- else {
- if (isset($webPayItemRow->description)) {
- $description = $webPayItemRow->description;
- }
- if (isset($webPayItemRow->name)) {
- $description = $webPayItemRow->name;
- }
- }
-
- return $description;
- }
-
- protected function formatShippingFeeRows($row)
- {
-
- $orderRow = new SveaOrderRow();
-
- if (isset($row->shippingId)) {
- $orderRow->ArticleNumber = $row->shippingId;
- }
-
- $orderRow->Description = $this->formatRowNameAndDescription($row);
-
- if (isset($row->unit)) {
- $orderRow->Unit = $row->unit;
- }
- $orderRow->DiscountPercent = (isset($row->discountPercent) ? $row->discountPercent : 0);
- $orderRow->NumberOfUnits = 1; //only one fee per row
-
- // amountExVat & vatPercent used to specify product price
- if (isset($row->vatPercent) && isset($row->amountExVat)) {
- $orderRow->PricePerUnit = $this->priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($row->amountExVat, Helper::bround($row->vatPercent)) : $row->amountExVat;
- $orderRow->VatPercent = Helper::bround($row->vatPercent);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- } // amountIncVat & vatPercent used to specify product price
- elseif (isset($row->vatPercent) && isset($row->amountIncVat)) {
-// $orderRow->PricePerUnit =
-// WebServiceRowFormatter::convertIncVatToExVat( $row->amountIncVat, $row->vatPercent );
- $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amountIncVat, Helper::bround($row->vatPercent));
- $orderRow->VatPercent = Helper::bround($row->vatPercent);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- } // no vatPercent given, booth ExVat and IncVat
- elseif (isset($row->amountExVat) && isset($row->amountIncVat)) {
- $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : $row->amountExVat;
- $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($row->amountIncVat, $row->amountExVat);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- } // no vatPercent given
- else {
- $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amountIncVat, Helper::bround($row->vatPercent));
- $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($row->amountIncVat, $row->amountExVat);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- }
-
- if (!empty($row->name)) {
- $orderRow->Name = $row->name;
- }
-
- if (isset($row->temporaryReference)) {
- $orderRow->TemporaryReference = $row->temporaryReference;
- }
-
- $this->newRows[] = $orderRow;
- }
-
- protected function formatInvoiceFeeRows($row)
- {
- $orderRow = new SveaOrderRow();
-
- $orderRow->ArticleNumber = "";
-
- $orderRow->Description = $this->formatRowNameAndDescription($row);
-
- if (isset($row->unit)) {
- $orderRow->Unit = $row->unit;
- }
- $orderRow->DiscountPercent = isset($row->discountPercent) ? $row->discountPercent : 0;
- $orderRow->NumberOfUnits = 1; //only one fee per row
-
- // amountExVat & vatPercent used to specify product price
- if (isset($row->vatPercent) && isset($row->amountExVat)) {
- $orderRow->PricePerUnit = $this->priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($row->amountExVat, Helper::bround($row->vatPercent)) : $row->amountExVat;
- $orderRow->VatPercent = Helper::bround($row->vatPercent);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- } // amountIncVat & vatPercent used to specify product price
- elseif (isset($row->vatPercent) && isset($row->amountIncVat)) {
-// $orderRow->PricePerUnit =
-// WebServiceRowFormatter::convertIncVatToExVat( $row->amountIncVat, $row->vatPercent );
- $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amountIncVat, Helper::bround($row->vatPercent));
- $orderRow->VatPercent = Helper::bround($row->vatPercent);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- } // no vatPercent given, booth ExVat and IncVat
- elseif (isset($row->amountExVat) && isset($row->amountIncVat)) {
- $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : $row->amountExVat;
- $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($row->amountIncVat, $row->amountExVat);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- } else {
- $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amountIncVat, Helper::bround($row->vatPercent));
- $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($row->amountIncVat, $row->amountExVat);
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- }
-
- if (!empty($row->name)) {
- $orderRow->Name = $row->name;
- }
-
- if (isset($row->temporaryReference)) {
- $orderRow->TemporaryReference = $row->temporaryReference;
- }
-
- $this->newRows[] = $orderRow;
- }
-
- protected function formatFixedDiscountRows($row)
- {
- // only amountIncVat (i.e. amount) was specified:
- if (isset($row->amount) && !isset($row->vatPercent) && !isset($row->amountExVat)) {
- $this->newRows = array_merge($this->newRows, $this->formatFixedDiscountSpecifiedAsAmountIncVatOnly($row));
- }
-
- // only amountExVat was specified:
- if (!isset($row->amount) && !isset($row->vatPercent) && isset($row->amountExVat)) {
- $this->newRows = array_merge($this->newRows, $this->formatFixedDiscountSpecifiedAsAmountExVatOnly($row));
- }
-
- // amountIncVat (i.e. amount) and vatPercent is set, so we use that vatPercent:
- if (isset($row->amount) && isset($row->vatPercent) && !isset($row->amountExVat)) {
-
- $orderRow = new SveaOrderRow();
-
- if (isset($row->discountId)) {
- $orderRow->ArticleNumber = $row->discountId;
- }
-
- $orderRow->Description = $this->formatRowNameAndDescription($row);
-
- if (isset($row->unit)) {
- $orderRow->Unit = $row->unit;
- }
- $orderRow->DiscountPercent = 0; //no discount on discount
- $orderRow->NumberOfUnits = 1; //only one discount per row
-
- //calculate discount
- $vatRate = $row->vatPercent;
- $discountAtThisVatRateIncVat = $row->amount;
-// $discountAtThisVatRateExVat =
-// WebServiceRowFormatter::convertIncVatToExVat( $discountAtThisVatRateIncVat, $vatRate );
-
- $orderRow->PricePerUnit = (-1) * ($this->priceIncludingVat ? $discountAtThisVatRateIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amount, Helper::bround($row->vatPercent)));
- $orderRow->VatPercent = $vatRate;
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
-
- if (!empty($row->name)) {
- $orderRow->Name = $row->name;
- }
-
- if (isset($row->temporaryReference)) {
- $orderRow->TemporaryReference = $row->temporaryReference;
- }
-
- $this->newRows[] = $orderRow;
- }
-
- // amountExVat (i.e. amount) and vatPercent is set, so we use that vatPercent:
- if (!isset($row->amount) && isset($row->vatPercent) && isset($row->amountExVat)) {
-
- $orderRow = new SveaOrderRow();
-
- if (isset($row->discountId)) {
- $orderRow->ArticleNumber = $row->discountId;
- }
-
- $orderRow->Description = $this->formatRowNameAndDescription($row);
-
- if (isset($row->unit)) {
- $orderRow->Unit = $row->unit;
- }
- $orderRow->DiscountPercent = 0; //no discount on discount
- $orderRow->NumberOfUnits = 1; //only one discount per row
-
- //calculate discount
- $vatRate = $row->vatPercent;
- $discountAtThisVatRate = $this->priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($row->amountExVat, Helper::bround($row->vatPercent)) : $row->amountExVat;
-
- $orderRow->PricePerUnit = (-1) * $discountAtThisVatRate;
- $orderRow->VatPercent = $vatRate;
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
-
- if (!empty($row->name)) {
- $orderRow->Name = $row->name;
- }
-
- if (isset($row->temporaryReference)) {
- $orderRow->TemporaryReference = $row->temporaryReference;
- }
-
- $this->newRows[] = $orderRow;
- }
- }
-
- /**
- * Formats FixedDiscount rows specified with setAmountIncVat() only.
- * Returns one or more discount rows, one for each vat rate present in the order.
- *
- * @param FixedDiscount $discountRow
- * @return SveaOrderRow
- */
- protected function formatFixedDiscountSpecifiedAsAmountIncVatOnly($discountRow)
- {
-
- $splitRows = array(); // one (or more) formated discount rows, split across the vat rates in the order
-
- foreach ($this->totalAmountPerVatRateIncVat as $vatRate => $amountAtThisVatRateIncVat) {
-
- $orderRow = new SveaOrderRow();
-
- if (isset($discountRow->discountId)) {
- $orderRow->ArticleNumber = $discountRow->discountId;
- }
-
- if (!empty($discountRow->name)) {
- $orderRow->Name = $discountRow->name;
- }
-
- if (isset($discountRow->temporaryReference)) {
- $orderRow->TemporaryReference = $discountRow->temporaryReference;
- }
-
- $orderRow->Description = $this->formatRowNameAndDescription($discountRow);
-
- if (sizeof($this->totalAmountPerVatRateIncVat) > 1) { // add tax rate for split discount to description
- $orderRow->Description .= " (" . $vatRate . "%)";
- }
- if (isset($discountRow->unit)) {
- $orderRow->Unit = $discountRow->unit;
- }
- $orderRow->DiscountPercent = 0; //no discount on discount
- $orderRow->NumberOfUnits = 1; //only one discount per row
-
- //calculate discount
- $discountAtThisVatRateIncVat = $discountRow->amount * ($amountAtThisVatRateIncVat / $this->totalAmountIncVat);
- $discountAtThisVatRateExVat =
- WebServiceRowFormatter::convertIncVatToExVat($discountAtThisVatRateIncVat, $vatRate);
- $orderRow->PricePerUnit = (-1) * ($this->priceIncludingVat ? $discountAtThisVatRateIncVat : WebServiceRowFormatter::convertIncVatToExVat($discountAtThisVatRateIncVat, $vatRate));;
- $orderRow->VatPercent = $vatRate;
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
- $splitRows[] = $orderRow;
- }
-
- return $splitRows;
- }
-
- /**
- * Formats FixedDiscount rows specified with setAmountExVat() only.
- * Returns one or more discount rows, one for each vat rate present in the order.
- * If the
- *
- * @param FixedDiscount $discountRow
- * @return SveaOrderRow
- */
- protected function formatFixedDiscountSpecifiedAsAmountExVatOnly($discountRow)
- {
- $splitRows = array(); // one (or more) formated discount rows, split across the vat rates in the order
-
- foreach ($this->totalAmountPerVatRateExVat as $vatRate => $amountAtThisVatRateExVat) {
-
- $orderRow = new SveaOrderRow();
-
- if (isset($discountRow->discountId)) {
- $orderRow->ArticleNumber = $discountRow->discountId;
- }
-
- $orderRow->Description = $this->formatRowNameAndDescription($discountRow);
-
- if (sizeof($this->totalAmountPerVatRateExVat) > 1) { // add tax rate for split discount to description
- $orderRow->Description .= " (" . $vatRate . "%)";
- }
- if (isset($discountRow->unit)) {
- $orderRow->Unit = $discountRow->unit;
- }
-
- if (!empty($discountRow->name)) {
- $orderRow->Name = $discountRow->name;
- }
-
- if (isset($discountRow->temporaryReference)) {
- $orderRow->TemporaryReference = $discountRow->temporaryReference;
- }
-
- $orderRow->DiscountPercent = 0; //no discount on discount
- $orderRow->NumberOfUnits = 1; //only one discount per row
-
- //calculate discount
- $discountAtThisVatRateExVat = $discountRow->amountExVat * ($amountAtThisVatRateExVat / $this->totalAmountExVat);
-
- // iff priceIncludingVat set to true, write discount row as incvat
- if ($this->priceIncludingVat) {
- $orderRow->PricePerUnit = (-1) * WebServiceRowFormatter::convertExVatToIncVat($discountAtThisVatRateExVat, $vatRate);
- $orderRow->VatPercent = $vatRate;
- $orderRow->PriceIncludingVat = TRUE;
- } else {
- $orderRow->PricePerUnit = (-1) * $discountAtThisVatRateExVat;
- $orderRow->VatPercent = $vatRate;
- $orderRow->PriceIncludingVat = FALSE;
- }
-
- $splitRows[] = $orderRow;
- }
-
- return $splitRows;
- }
-
- protected function formatRelativeDiscountRows($row)
- {
- foreach ($this->totalAmountPerVatRateIncVat as $vatRate => $amountAtThisVatRateIncVat) {
- $orderRow = new SveaOrderRow();
-
- if (isset($row->discountId)) {
- $orderRow->ArticleNumber = $row->discountId;
- }
-
- $orderRow->Description = $this->formatRowNameAndDescription($row);
-
- if (sizeof($this->totalAmountPerVatRateIncVat) > 1) { // add tax rate for split discount to description
- $orderRow->Description .= " (" . $vatRate . "%)";
- }
- if (isset($row->unit)) {
- $orderRow->Unit = $row->unit;
- }
-
- if (!empty($row->name)) {
- $orderRow->Name = $row->name;
- }
-
- if (isset($row->temporaryReference)) {
- $orderRow->TemporaryReference = $row->temporaryReference;
- }
-
- $amountAtThisVatRateExVat = $amountAtThisVatRateIncVat - $amountAtThisVatRateIncVat * (1 - (1 / (1 + $vatRate / 100))); // calculate "reverse vat", i.e. 25% => 20%
-
- $discountIncVat = $amountAtThisVatRateIncVat * ($row->discountPercent * 0.01);
- $discountExVat = $amountAtThisVatRateExVat * ($row->discountPercent * 0.01);
- $orderRow->DiscountPercent = 0; //no discount on discount
- $orderRow->NumberOfUnits = 1; //only one discount per row
- $orderRow->PricePerUnit = $this->priceIncludingVat ? -number_format($discountIncVat, 5, '.', '') : -number_format($discountExVat, 5, '.', ''); //Discountpercent on total price inc vat.
- $orderRow->VatPercent = $vatRate;
- $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
-
- $this->newRows[] = $orderRow;
- }
- }
+ protected $order;
+ protected $totalAmountExVat; // summed in calculateTotals
+ protected $totalVatAsAmount; // summed in calculateTotals
+ protected $totalAmountIncVat; // derived from ExVat + IncVat
+ protected $totalVatAsPercent; // derived from ExVat + IncVat
+
+ protected $totalAmountPerVatRateIncVat; // summed in calculateTotals, used to calculate "mean vat" split into given vat rates
+ protected $totalAmountPerVatRateExVat; // summed in calculateTotals, used to calculate "mean vat" split into given vat rates
+
+ protected $newRows;
+ protected $priceIncludingVat = false;
+ protected $resendOrderVat; // used from admin service functions, when original request got a 50036 error
+
+ /**
+ * @param $order
+ * @param $resendOrderVat
+ */
+ public function __construct($order, $resendOrderVat = NULL)
+ {
+ $this->order = $order;
+ $this->resendOrderVat = $resendOrderVat;
+
+ $this->totalAmountPerVatRateIncVat = [];
+ $this->totalAmountPerVatRateExVat = [];
+ }
+
+ public function formatRows()
+ {
+ $this->newRows = [];
+
+ $this->calculateTotals();
+
+ if ($this->resendOrderVat === NULL) {
+ $this->determineVatFlag();
+ } else {
+ $this->priceIncludingVat = $this->resendOrderVat ? FALSE : TRUE;
+ }
+
+ foreach ($this->order->rows as $row) {
+ switch (get_class($row)) {
+ case 'Svea\WebPay\BuildOrder\RowBuilders\OrderRow':
+ $this->formatOrderRows($row);
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\ShippingFee':
+ $this->formatShippingFeeRows($row);
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\InvoiceFee':
+ $this->formatInvoiceFeeRows($row);
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount':
+ $this->formatFixedDiscountRows($row);
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount':
+ $this->formatRelativeDiscountRows($row);
+ break;
+ default:
+ break;
+ }
+ }
+
+
+ return $this->newRows;
+ }
+
+ protected function calculateTotals()
+ {
+ $this->totalAmountExVat = 0;
+ $this->totalVatAsAmount = 0;
+
+ foreach ($this->order->orderRows as $product) {
+
+ // amountExVat & vatPercent used to specify product price
+ if (isset($product->vatPercent) && isset($product->amountExVat)) {
+ $this->totalAmountExVat += $product->amountExVat * $product->quantity;
+ $this->totalVatAsAmount += ($product->vatPercent / 100 * $product->amountExVat) * $product->quantity;
+
+ $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateIncVat, $product->vatPercent,
+ WebServiceRowFormatter::convertExVatToIncVat($product->amountExVat, $product->vatPercent) * $product->quantity);
+ $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateExVat, $product->vatPercent,
+ $product->amountExVat * $product->quantity);
+ } // amountIncVat & vatPercent used to specify product price
+ elseif (isset($product->vatPercent) && isset($product->amountIncVat)) {
+ $amountExVat = WebServiceRowFormatter::convertIncVatToExVat($product->amountIncVat, $product->vatPercent);
+ $this->totalAmountExVat += $amountExVat * $product->quantity;
+ $this->totalVatAsAmount += ($product->vatPercent / 100 * $amountExVat) * $product->quantity;
+
+ $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateIncVat, $product->vatPercent,
+ $product->amountIncVat * $product->quantity);
+ $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateExVat, $product->vatPercent,
+ WebServiceRowFormatter::convertIncVatToExVat($product->amountIncVat, $product->vatPercent) * $product->quantity);
+ } // no vatPercent given
+ else {
+ $this->totalAmountExVat += $product->amountExVat * $product->quantity;
+ $this->totalVatAsAmount += ($product->amountIncVat - $product->amountExVat) * $product->quantity;
+
+ $vatRate = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($product->amountIncVat, $product->amountExVat);
+
+ $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateIncVat, $vatRate,
+ $product->amountIncVat * $product->quantity);
+ $this->increaseCumulativeVatRateAmounts($this->totalAmountPerVatRateExVat, $vatRate,
+ $product->amountExVat * $product->quantity);
+ }
+ }
+ $this->totalAmountIncVat = $this->totalAmountExVat + $this->totalVatAsAmount;
+ $this->totalAmountExVat = $this->totalAmountIncVat - $this->totalVatAsAmount;
+ if ($this->totalAmountExVat > 0) {
+ $this->totalVatAsPercent = $this->totalVatAsAmount / $this->totalAmountIncVat; //e.g. 0,20 if percentage 20
+ }
+ }
+
+ protected function increaseCumulativeVatRateAmounts(&$array, $key, $value)
+ {
+ if (isset($array[$key])) {
+ $array[$key] += $value;
+ } else {
+ $array[$key] = $value;
+ }
+ }
+
+ /**
+ * Converts an amount excluding vat to amount including vat, given a vat rate in percent.
+ *
+ * @param float $amountExVat
+ * @param isNumeric $vatPercent
+ * @return float amountExVat
+ */
+ public static function convertExVatToIncVat($amountExVat, $vatPercent)
+ {
+ return ($amountExVat * (1 + $vatPercent / 100));
+ }
+
+ // used to create/increase the totalAmountPerVatRateIncVat and totalAmountPerVatRateExVat arrays in calculateTotals();
+
+ /**
+ * Converts an amount including vat to amount excluding vat, given a vat rate in percent.
+ *
+ * @param float $amountIncVat
+ * @param isNumeric $vatPercent
+ * @return float amountExVat
+ */
+ public static function convertIncVatToExVat($amountIncVat, $vatPercent)
+ {
+ $reverseVatPercent = (1 - (1 / (1 + $vatPercent / 100))); // calculate "reverse vat", i.e. 25% => 20%
+ return ($amountIncVat - $amountIncVat * $reverseVatPercent);
+ }
+
+ /**
+ * Helper function, calculates vat percentage as int from prices with and without vat.
+ * Note: this function will drop any vat rate fractions, i.e. it only handles vat rates that can be expressed as integers.
+ */
+ public static function calculateVatPercentFromPriceExVatAndPriceIncVat($incVat, $exVat)
+ {
+ if ($exVat == 0.0 || $incVat == 0.0) // avoid -100% vat on i.e. free products or fees
+ return 0;
+ else
+ return Helper::bround((($incVat / $exVat) - 1) * 100);
+ }
+
+ protected function determineVatFlag()
+ {
+ $exVat = 0;
+ $incVat = 0;
+ foreach ($this->order->rows as $row) {
+ switch (get_class($row)) {
+ //relative discount
+ // ignored, as relative discount doesn't use setAmountExVat/-IncVat at all
+ case 'Svea\WebPay\BuildOrder\RowBuilders\RelativeDiscount':
+ break;
+ case 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount':
+ if (isset($row->amountExVat) && isset($row->amountIncVat)) {
+ $incVat++;
+ }
+ if (isset($row->amountExVat) && !isset($row->amountIncVat)) {
+ $exVat++;
+ } else {
+ $incVat++;
+ }
+ break;
+ default:
+ if (isset($row->amountExVat) && isset($row->amountIncVat)) {
+ $incVat++;
+ } elseif (isset($row->amountExVat) && isset ($row->vatPercent)) {
+ $exVat++;
+ } else {
+ $incVat++;
+ }
+ break;
+ }
+
+ }
+ //if at least one of the non-discount rows are defined exvat, need to use set priceIncludingVat to false
+ if ($exVat >= 1) {
+ $this->priceIncludingVat = FALSE;
+ } else {
+ $this->priceIncludingVat = TRUE;
+ }
+
+ }
+
+ protected function formatOrderRows($row)
+ {
+// foreach ($this->order->orderRows as $row) {
+
+ $orderRow = new SveaOrderRow();
+
+ if (isset($row->articleNumber)) {
+ $orderRow->ArticleNumber = $row->articleNumber;
+ }
+
+ $orderRow->Description = $this->formatRowNameAndDescription($row);
+
+ if (isset($row->unit)) {
+ $orderRow->Unit = $row->unit;
+ }
+ $orderRow->DiscountPercent = (isset($row->discountPercent) ? $row->discountPercent : 0);
+ $orderRow->NumberOfUnits = $row->quantity;
+
+ // amountExVat & vatPercent used to specify product price
+ if (isset($row->vatPercent) && isset($row->amountExVat)) {
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($row->amountExVat, Helper::bround($row->vatPercent)) : $row->amountExVat;
+ $orderRow->VatPercent = Helper::bround($row->vatPercent);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ } // amountIncVat & vatPercent used to specify product price
+ elseif (isset($row->vatPercent) && isset($row->amountIncVat)) {
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amountIncVat, Helper::bround($row->vatPercent));
+ $orderRow->VatPercent = Helper::bround($row->vatPercent);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ } // no vatPercent given
+ else {
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : $row->amountExVat;
+ $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($row->amountIncVat, $row->amountExVat);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ }
+
+ $this->newRows[] = $orderRow;
+// }
+ }
+
+ /**
+ * As the Europe Web Service API only has a description field, join name and description, if both are given.
+ *
+ * @param OrderRow|ShippingFee|et al . $webPayItemRow an instance of the order row classes from Svea\WebPay\WebPayItem
+ * @return string the combined description string that should be written to Description
+ */
+ public function formatRowNameAndDescription($webPayItemRow)
+ {
+
+ $description = ""; //fallback to empty string if we haven't got either of name or description
+
+ // if both name and description are set in the package orderrow, add both to the request row description field
+ if (isset($webPayItemRow->name) && isset($webPayItemRow->description)) {
+ $description = $webPayItemRow->name . ': ' . $webPayItemRow->description;
+ } // else, use either description or name, if set
+ else {
+ if (isset($webPayItemRow->description)) {
+ $description = $webPayItemRow->description;
+ }
+ if (isset($webPayItemRow->name)) {
+ $description = $webPayItemRow->name;
+ }
+ }
+
+ return $description;
+ }
+
+ protected function formatShippingFeeRows($row)
+ {
+
+ $orderRow = new SveaOrderRow();
+
+ if (isset($row->shippingId)) {
+ $orderRow->ArticleNumber = $row->shippingId;
+ }
+
+ $orderRow->Description = $this->formatRowNameAndDescription($row);
+
+ if (isset($row->unit)) {
+ $orderRow->Unit = $row->unit;
+ }
+ $orderRow->DiscountPercent = (isset($row->discountPercent) ? $row->discountPercent : 0);
+ $orderRow->NumberOfUnits = 1; //only one fee per row
+
+ // amountExVat & vatPercent used to specify product price
+ if (isset($row->vatPercent) && isset($row->amountExVat)) {
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($row->amountExVat, Helper::bround($row->vatPercent)) : $row->amountExVat;
+ $orderRow->VatPercent = Helper::bround($row->vatPercent);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ } // amountIncVat & vatPercent used to specify product price
+ elseif (isset($row->vatPercent) && isset($row->amountIncVat)) {
+// $orderRow->PricePerUnit =
+// WebServiceRowFormatter::convertIncVatToExVat( $row->amountIncVat, $row->vatPercent );
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amountIncVat, Helper::bround($row->vatPercent));
+ $orderRow->VatPercent = Helper::bround($row->vatPercent);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ } // no vatPercent given, booth ExVat and IncVat
+ elseif (isset($row->amountExVat) && isset($row->amountIncVat)) {
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : $row->amountExVat;
+ $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($row->amountIncVat, $row->amountExVat);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ } // no vatPercent given
+ else {
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amountIncVat, Helper::bround($row->vatPercent));
+ $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($row->amountIncVat, $row->amountExVat);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ }
+
+ if (!empty($row->name)) {
+ $orderRow->Name = $row->name;
+ }
+
+ if (isset($row->temporaryReference)) {
+ $orderRow->TemporaryReference = $row->temporaryReference;
+ }
+
+ $this->newRows[] = $orderRow;
+ }
+
+ protected function formatInvoiceFeeRows($row)
+ {
+ $orderRow = new SveaOrderRow();
+
+ $orderRow->ArticleNumber = "";
+
+ $orderRow->Description = $this->formatRowNameAndDescription($row);
+
+ if (isset($row->unit)) {
+ $orderRow->Unit = $row->unit;
+ }
+ $orderRow->DiscountPercent = isset($row->discountPercent) ? $row->discountPercent : 0;
+ $orderRow->NumberOfUnits = 1; //only one fee per row
+
+ // amountExVat & vatPercent used to specify product price
+ if (isset($row->vatPercent) && isset($row->amountExVat)) {
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($row->amountExVat, Helper::bround($row->vatPercent)) : $row->amountExVat;
+ $orderRow->VatPercent = Helper::bround($row->vatPercent);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ } // amountIncVat & vatPercent used to specify product price
+ elseif (isset($row->vatPercent) && isset($row->amountIncVat)) {
+// $orderRow->PricePerUnit =
+// WebServiceRowFormatter::convertIncVatToExVat( $row->amountIncVat, $row->vatPercent );
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amountIncVat, Helper::bround($row->vatPercent));
+ $orderRow->VatPercent = Helper::bround($row->vatPercent);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ } // no vatPercent given, booth ExVat and IncVat
+ elseif (isset($row->amountExVat) && isset($row->amountIncVat)) {
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : $row->amountExVat;
+ $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($row->amountIncVat, $row->amountExVat);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ } else {
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? $row->amountIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amountIncVat, Helper::bround($row->vatPercent));
+ $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat($row->amountIncVat, $row->amountExVat);
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ }
+
+ if (!empty($row->name)) {
+ $orderRow->Name = $row->name;
+ }
+
+ if (isset($row->temporaryReference)) {
+ $orderRow->TemporaryReference = $row->temporaryReference;
+ }
+
+ $this->newRows[] = $orderRow;
+ }
+
+ protected function formatFixedDiscountRows($row)
+ {
+ // only amountIncVat (i.e. amount) was specified:
+ if (isset($row->amount) && !isset($row->vatPercent) && !isset($row->amountExVat)) {
+ $this->newRows = array_merge($this->newRows, $this->formatFixedDiscountSpecifiedAsAmountIncVatOnly($row));
+ }
+
+ // only amountExVat was specified:
+ if (!isset($row->amount) && !isset($row->vatPercent) && isset($row->amountExVat)) {
+ $this->newRows = array_merge($this->newRows, $this->formatFixedDiscountSpecifiedAsAmountExVatOnly($row));
+ }
+
+ // amountIncVat (i.e. amount) and vatPercent is set, so we use that vatPercent:
+ if (isset($row->amount) && isset($row->vatPercent) && !isset($row->amountExVat)) {
+
+ $orderRow = new SveaOrderRow();
+
+ if (isset($row->discountId)) {
+ $orderRow->ArticleNumber = $row->discountId;
+ }
+
+ $orderRow->Description = $this->formatRowNameAndDescription($row);
+
+ if (isset($row->unit)) {
+ $orderRow->Unit = $row->unit;
+ }
+ $orderRow->DiscountPercent = 0; //no discount on discount
+ $orderRow->NumberOfUnits = 1; //only one discount per row
+
+ //calculate discount
+ $vatRate = $row->vatPercent;
+ $discountAtThisVatRateIncVat = $row->amount;
+// $discountAtThisVatRateExVat =
+// WebServiceRowFormatter::convertIncVatToExVat( $discountAtThisVatRateIncVat, $vatRate );
+
+ $orderRow->PricePerUnit = (-1) * ($this->priceIncludingVat ? $discountAtThisVatRateIncVat : WebServiceRowFormatter::convertIncVatToExVat($row->amount, Helper::bround($row->vatPercent)));
+ $orderRow->VatPercent = $vatRate;
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+
+ if (!empty($row->name)) {
+ $orderRow->Name = $row->name;
+ }
+
+ if (isset($row->temporaryReference)) {
+ $orderRow->TemporaryReference = $row->temporaryReference;
+ }
+
+ $this->newRows[] = $orderRow;
+ }
+
+ // amountExVat (i.e. amount) and vatPercent is set, so we use that vatPercent:
+ if (!isset($row->amount) && isset($row->vatPercent) && isset($row->amountExVat)) {
+
+ $orderRow = new SveaOrderRow();
+
+ if (isset($row->discountId)) {
+ $orderRow->ArticleNumber = $row->discountId;
+ }
+
+ $orderRow->Description = $this->formatRowNameAndDescription($row);
+
+ if (isset($row->unit)) {
+ $orderRow->Unit = $row->unit;
+ }
+ $orderRow->DiscountPercent = 0; //no discount on discount
+ $orderRow->NumberOfUnits = 1; //only one discount per row
+
+ //calculate discount
+ $vatRate = $row->vatPercent;
+ $discountAtThisVatRate = $this->priceIncludingVat ? WebServiceRowFormatter::convertExVatToIncVat($row->amountExVat, Helper::bround($row->vatPercent)) : $row->amountExVat;
+
+ $orderRow->PricePerUnit = (-1) * $discountAtThisVatRate;
+ $orderRow->VatPercent = $vatRate;
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+
+ if (!empty($row->name)) {
+ $orderRow->Name = $row->name;
+ }
+
+ if (isset($row->temporaryReference)) {
+ $orderRow->TemporaryReference = $row->temporaryReference;
+ }
+
+ $this->newRows[] = $orderRow;
+ }
+ }
+
+ /**
+ * Formats FixedDiscount rows specified with setAmountIncVat() only.
+ * Returns one or more discount rows, one for each vat rate present in the order.
+ *
+ * @param FixedDiscount $discountRow
+ * @return SveaOrderRow
+ */
+ protected function formatFixedDiscountSpecifiedAsAmountIncVatOnly($discountRow)
+ {
+
+ $splitRows = []; // one (or more) formated discount rows, split across the vat rates in the order
+
+ foreach ($this->totalAmountPerVatRateIncVat as $vatRate => $amountAtThisVatRateIncVat) {
+
+ $orderRow = new SveaOrderRow();
+
+ if (isset($discountRow->discountId)) {
+ $orderRow->ArticleNumber = $discountRow->discountId;
+ }
+
+ if (!empty($discountRow->name)) {
+ $orderRow->Name = $discountRow->name;
+ }
+
+ if (isset($discountRow->temporaryReference)) {
+ $orderRow->TemporaryReference = $discountRow->temporaryReference;
+ }
+
+ $orderRow->Description = $this->formatRowNameAndDescription($discountRow);
+
+ if (sizeof($this->totalAmountPerVatRateIncVat) > 1) { // add tax rate for split discount to description
+ $orderRow->Description .= " (" . $vatRate . "%)";
+ }
+ if (isset($discountRow->unit)) {
+ $orderRow->Unit = $discountRow->unit;
+ }
+ $orderRow->DiscountPercent = 0; //no discount on discount
+ $orderRow->NumberOfUnits = 1; //only one discount per row
+
+ //calculate discount
+ $discountAtThisVatRateIncVat = $discountRow->amount * ($amountAtThisVatRateIncVat / $this->totalAmountIncVat);
+ $discountAtThisVatRateExVat =
+ WebServiceRowFormatter::convertIncVatToExVat($discountAtThisVatRateIncVat, $vatRate);
+ $orderRow->PricePerUnit = (-1) * ($this->priceIncludingVat ? $discountAtThisVatRateIncVat : WebServiceRowFormatter::convertIncVatToExVat($discountAtThisVatRateIncVat, $vatRate));;
+ $orderRow->VatPercent = $vatRate;
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+ $splitRows[] = $orderRow;
+ }
+
+ return $splitRows;
+ }
+
+ /**
+ * Formats FixedDiscount rows specified with setAmountExVat() only.
+ * Returns one or more discount rows, one for each vat rate present in the order.
+ * If the
+ *
+ * @param FixedDiscount $discountRow
+ * @return SveaOrderRow
+ */
+ protected function formatFixedDiscountSpecifiedAsAmountExVatOnly($discountRow)
+ {
+ $splitRows = []; // one (or more) formated discount rows, split across the vat rates in the order
+
+ foreach ($this->totalAmountPerVatRateExVat as $vatRate => $amountAtThisVatRateExVat) {
+
+ $orderRow = new SveaOrderRow();
+
+ if (isset($discountRow->discountId)) {
+ $orderRow->ArticleNumber = $discountRow->discountId;
+ }
+
+ $orderRow->Description = $this->formatRowNameAndDescription($discountRow);
+
+ if (sizeof($this->totalAmountPerVatRateExVat) > 1) { // add tax rate for split discount to description
+ $orderRow->Description .= " (" . $vatRate . "%)";
+ }
+ if (isset($discountRow->unit)) {
+ $orderRow->Unit = $discountRow->unit;
+ }
+
+ if (!empty($discountRow->name)) {
+ $orderRow->Name = $discountRow->name;
+ }
+
+ if (isset($discountRow->temporaryReference)) {
+ $orderRow->TemporaryReference = $discountRow->temporaryReference;
+ }
+
+ $orderRow->DiscountPercent = 0; //no discount on discount
+ $orderRow->NumberOfUnits = 1; //only one discount per row
+
+ //calculate discount
+ $discountAtThisVatRateExVat = $discountRow->amountExVat * ($amountAtThisVatRateExVat / $this->totalAmountExVat);
+
+ // iff priceIncludingVat set to true, write discount row as incvat
+ if ($this->priceIncludingVat) {
+ $orderRow->PricePerUnit = (-1) * WebServiceRowFormatter::convertExVatToIncVat($discountAtThisVatRateExVat, $vatRate);
+ $orderRow->VatPercent = $vatRate;
+ $orderRow->PriceIncludingVat = TRUE;
+ } else {
+ $orderRow->PricePerUnit = (-1) * $discountAtThisVatRateExVat;
+ $orderRow->VatPercent = $vatRate;
+ $orderRow->PriceIncludingVat = FALSE;
+ }
+
+ $splitRows[] = $orderRow;
+ }
+
+ return $splitRows;
+ }
+
+ protected function formatRelativeDiscountRows($row)
+ {
+ foreach ($this->totalAmountPerVatRateIncVat as $vatRate => $amountAtThisVatRateIncVat) {
+ $orderRow = new SveaOrderRow();
+
+ if (isset($row->discountId)) {
+ $orderRow->ArticleNumber = $row->discountId;
+ }
+
+ $orderRow->Description = $this->formatRowNameAndDescription($row);
+
+ if (sizeof($this->totalAmountPerVatRateIncVat) > 1) { // add tax rate for split discount to description
+ $orderRow->Description .= " (" . $vatRate . "%)";
+ }
+ if (isset($row->unit)) {
+ $orderRow->Unit = $row->unit;
+ }
+
+ if (!empty($row->name)) {
+ $orderRow->Name = $row->name;
+ }
+
+ if (isset($row->temporaryReference)) {
+ $orderRow->TemporaryReference = $row->temporaryReference;
+ }
+
+ $amountAtThisVatRateExVat = $amountAtThisVatRateIncVat - $amountAtThisVatRateIncVat * (1 - (1 / (1 + $vatRate / 100))); // calculate "reverse vat", i.e. 25% => 20%
+
+ $discountIncVat = $amountAtThisVatRateIncVat * ($row->discountPercent * 0.01);
+ $discountExVat = $amountAtThisVatRateExVat * ($row->discountPercent * 0.01);
+ $orderRow->DiscountPercent = 0; //no discount on discount
+ $orderRow->NumberOfUnits = 1; //only one discount per row
+ $orderRow->PricePerUnit = $this->priceIncludingVat ? -number_format($discountIncVat, 5, '.', '') : -number_format($discountExVat, 5, '.', ''); //Discountpercent on total price inc vat.
+ $orderRow->VatPercent = $vatRate;
+ $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE;
+
+ $this->newRows[] = $orderRow;
+ }
+ }
}
diff --git a/src/WebService/Payment/AccountCredit.php b/src/WebService/Payment/AccountCredit.php
index 975145ef..85d8f7a0 100644
--- a/src/WebService/Payment/AccountCredit.php
+++ b/src/WebService/Payment/AccountCredit.php
@@ -9,40 +9,40 @@
class AccountCredit extends WebServicePayment
{
- public $orderType = 'AccountCredit';
-
- public function __construct($order)
- {
- parent::__construct($order);
- }
-
- public function setOrderType($orderInformation)
- {
- $orderInformation->AddressSelector = isset($this->order->customerIdentity->addressSelector) ? $this->order->customerIdentity->addressSelector : "";
- $orderInformation->OrderType = $this->orderType;
-
- return $orderInformation;
- }
-
- /**
- * Format Order row with svea_soap package and calculate vat
- * @param type $rows
- * @return \SveaCreateOrderInformation
- */
- protected function formatOrderInformationWithOrderRows($rows)
- {
- $orderInformation = new SveaCreateAccountCreditOrderInformation(
- (isset($this->order->campaignCode) ? $this->order->campaignCode : "")
- );
-
- // rewrite order rows to soap_class order rows
- $formatter = new WebServiceRowFormatter($this->order);
- $formattedOrderRows = $formatter->formatRows();
-
- foreach ($formattedOrderRows as $formattedOrderRow) {
- $orderInformation->addOrderRow($formattedOrderRow);
- }
-
- return $orderInformation;
- }
+ public $orderType = 'AccountCredit';
+
+ public function __construct($order)
+ {
+ parent::__construct($order);
+ }
+
+ public function setOrderType($orderInformation)
+ {
+ $orderInformation->AddressSelector = isset($this->order->customerIdentity->addressSelector) ? $this->order->customerIdentity->addressSelector : "";
+ $orderInformation->OrderType = $this->orderType;
+
+ return $orderInformation;
+ }
+
+ /**
+ * Format Order row with svea_soap package and calculate vat
+ * @param type $rows
+ * @return \SveaCreateOrderInformation
+ */
+ protected function formatOrderInformationWithOrderRows($rows)
+ {
+ $orderInformation = new SveaCreateAccountCreditOrderInformation(
+ (isset($this->order->campaignCode) ? $this->order->campaignCode : "")
+ );
+
+ // rewrite order rows to soap_class order rows
+ $formatter = new WebServiceRowFormatter($this->order);
+ $formattedOrderRows = $formatter->formatRows();
+
+ foreach ($formattedOrderRows as $formattedOrderRow) {
+ $orderInformation->addOrderRow($formattedOrderRow);
+ }
+
+ return $orderInformation;
+ }
}
\ No newline at end of file
diff --git a/src/WebService/Payment/InvoicePayment.php b/src/WebService/Payment/InvoicePayment.php
index 18ea66f4..29e4436a 100644
--- a/src/WebService/Payment/InvoicePayment.php
+++ b/src/WebService/Payment/InvoicePayment.php
@@ -12,42 +12,42 @@
*/
class InvoicePayment extends WebServicePayment
{
- public $orderType;
-
- public function __construct($order)
- {
- $this->orderType = ConfigurationProvider::INVOICE_TYPE;
- parent::__construct($order);
- }
-
- public function setOrderType($orderInformation)
- {
- $orderInformation->AddressSelector = isset($this->order->customerIdentity->addressSelector) ? $this->order->customerIdentity->addressSelector : "";
- $orderInformation->OrderType = $this->orderType;
-
- return $orderInformation;
- }
-
- /**
- * Format Order row with svea_soap package and calculate vat
- * @param type $rows
- * @return \SveaCreateOrderInformation
- */
- protected function formatOrderInformationWithOrderRows($rows)
- {
- $orderInformation = new SveaCreateOrderInformation(
- (isset($this->order->campaignCode) ? $this->order->campaignCode : ""),
- (isset($this->order->sendAutomaticGiroPaymentForm) ? $this->order->sendAutomaticGiroPaymentForm : 0)
- );
-
- // rewrite order rows to soap_class order rows
- $formatter = new WebServiceRowFormatter($this->order);
- $formattedOrderRows = $formatter->formatRows();
-
- foreach ($formattedOrderRows as $formattedOrderRow) {
- $orderInformation->addOrderRow($formattedOrderRow);
- }
-
- return $orderInformation;
- }
+ public $orderType;
+
+ public function __construct($order)
+ {
+ $this->orderType = ConfigurationProvider::INVOICE_TYPE;
+ parent::__construct($order);
+ }
+
+ public function setOrderType($orderInformation)
+ {
+ $orderInformation->AddressSelector = isset($this->order->customerIdentity->addressSelector) ? $this->order->customerIdentity->addressSelector : "";
+ $orderInformation->OrderType = $this->orderType;
+
+ return $orderInformation;
+ }
+
+ /**
+ * Format Order row with svea_soap package and calculate vat
+ * @param type $rows
+ * @return \SveaCreateOrderInformation
+ */
+ protected function formatOrderInformationWithOrderRows($rows)
+ {
+ $orderInformation = new SveaCreateOrderInformation(
+ (isset($this->order->campaignCode) ? $this->order->campaignCode : ""),
+ (isset($this->order->sendAutomaticGiroPaymentForm) ? $this->order->sendAutomaticGiroPaymentForm : 0)
+ );
+
+ // rewrite order rows to soap_class order rows
+ $formatter = new WebServiceRowFormatter($this->order);
+ $formattedOrderRows = $formatter->formatRows();
+
+ foreach ($formattedOrderRows as $formattedOrderRow) {
+ $orderInformation->addOrderRow($formattedOrderRow);
+ }
+
+ return $orderInformation;
+ }
}
diff --git a/src/WebService/Payment/PaymentPlanPayment.php b/src/WebService/Payment/PaymentPlanPayment.php
index 92804c90..8540a9dc 100644
--- a/src/WebService/Payment/PaymentPlanPayment.php
+++ b/src/WebService/Payment/PaymentPlanPayment.php
@@ -10,41 +10,41 @@
*/
class PaymentPlanPayment extends WebServicePayment
{
- public $orderType = 'PaymentPlan';
-
- public function __construct($order)
- {
- parent::__construct($order);
- }
-
- protected function setOrderType($orderInformation)
- {
- $orderInformation->AddressSelector = "";
- $orderInformation->OrderType = $this->orderType;
-
- return $orderInformation;
- }
-
- /**
- * Format Order row with svea_soap package and calculate vat
- * @param type $rows
- * @return \SveaCreateOrderInformation
- */
- protected function formatOrderInformationWithOrderRows($rows)
- {
- $orderInformation = new SveaCreateOrderInformation(
- (isset($this->order->campaignCode) ? $this->order->campaignCode : ""),
- (isset($this->order->sendAutomaticGiroPaymentForm) ? $this->order->sendAutomaticGiroPaymentForm : 0)
- );
-
- // rewrite order rows to soap_class order rows
- $formatter = new WebServiceRowFormatter($this->order);
- $formattedOrderRows = $formatter->formatRows();
-
- foreach ($formattedOrderRows as $formattedOrderRow) {
- $orderInformation->addOrderRow($formattedOrderRow);
- }
-
- return $orderInformation;
- }
+ public $orderType = 'PaymentPlan';
+
+ public function __construct($order)
+ {
+ parent::__construct($order);
+ }
+
+ protected function setOrderType($orderInformation)
+ {
+ $orderInformation->AddressSelector = "";
+ $orderInformation->OrderType = $this->orderType;
+
+ return $orderInformation;
+ }
+
+ /**
+ * Format Order row with svea_soap package and calculate vat
+ * @param type $rows
+ * @return \SveaCreateOrderInformation
+ */
+ protected function formatOrderInformationWithOrderRows($rows)
+ {
+ $orderInformation = new SveaCreateOrderInformation(
+ (isset($this->order->campaignCode) ? $this->order->campaignCode : ""),
+ (isset($this->order->sendAutomaticGiroPaymentForm) ? $this->order->sendAutomaticGiroPaymentForm : 0)
+ );
+
+ // rewrite order rows to soap_class order rows
+ $formatter = new WebServiceRowFormatter($this->order);
+ $formattedOrderRows = $formatter->formatRows();
+
+ foreach ($formattedOrderRows as $formattedOrderRow) {
+ $orderInformation->addOrderRow($formattedOrderRow);
+ }
+
+ return $orderInformation;
+ }
}
diff --git a/src/WebService/Payment/WebServicePayment.php b/src/WebService/Payment/WebServicePayment.php
index 6c4bd339..3420f0d3 100644
--- a/src/WebService/Payment/WebServicePayment.php
+++ b/src/WebService/Payment/WebServicePayment.php
@@ -26,328 +26,328 @@
class WebServicePayment
{
- public $order;
-
- public $requestObject;
-
- /**
- * WebServicePayment constructor.
- * @param $order
- */
- public function __construct($order)
- {
- $this->order = $order;
- }
-
- /**
- * Transforms object to array and sends it to SveaWebPay Europe Web service API by php SoapClient
- * @return CreateOrderResponse
- * @throws ValidationException
- */
- public function doRequest()
- {
- $object = $this->prepareRequest();
-
- $request = new SveaDoRequest($this->order->conf, $this->orderType, "CreateOrderEu", $object, $this->order->logging);
- $response = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
-
-
- return $response->getResponse();
- }
-
- /**
- * Rebuild $order with svea_soap package to be in right format for SveaWebPay Europe Web service API
- * @return SveaRequest SveaRequest
- * @throws ValidationException
- */
- public function prepareRequest()
- {
- // validate order, throw exception on validation failure
- $errors = $this->validateOrder();
- if (count($errors) > 0) {
- $exceptionString = "";
- foreach ($errors as $key => $value) {
- $exceptionString .= "-" . $key . " : " . $value . "\n";
- }
- throw new ValidationException($exceptionString);
- }
-
- // create soap order object, set authorization
- $sveaOrder = new SveaOrder;
- $sveaOrder->Auth = $this->getPasswordBasedAuthorization();
- //make orderrows and put in CreateOrderInformation
- $orderinformation = $this->formatOrderInformationWithOrderRows($this->order->orderRows);
-
- //parallel ways of creating customer
- if (isset($this->order->customerIdentity)) {
- $orderinformation->CustomerIdentity = $this->formatCustomerDetails();
- } else {
- $orderinformation->CustomerIdentity = $this->formatCustomerIdentity();
- }
-
- $orderinformation->ClientOrderNumber = $this->order->clientOrderNumber;
- $orderinformation->OrderDate = $this->order->orderDate;
- $orderinformation->CustomerReference = $this->order->customerReference;
- $orderinformation->PeppolId = $this->order->peppolId;
-
- if(isset($this->order->orderDeliveryAddress))
- {
- $orderinformation->OrderDeliveryAddress = $this->formatOrderDeliveryAddress();
-
- }
- $sveaOrder->CreateOrderInformation = $this->setOrderType($orderinformation);
-
- $object = new SveaRequest();
- $object->request = $sveaOrder;
-
- //do request
- $this->requestObject = $object;
-
- return $object;
- }
-
- public function validateOrder()
- {
- $this->order->orderType = $this->orderType;
- $validator = new WebServiceOrderValidator();
- $errors = $validator->validate($this->order);
-
- return $errors;
- }
-
- private function getPasswordBasedAuthorization()
- {
- $auth = new SveaAuth();
- $auth->Username = $this->order->conf->getUsername($this->orderType, $this->order->countryCode);
- $auth->Password = $this->order->conf->getPassword($this->orderType, $this->order->countryCode);
- $auth->ClientNumber = $this->order->conf->getClientNumber($this->orderType, $this->order->countryCode);
-
- return $auth;
- }
-
- /*
- *
- */
- private function formatOrderDeliveryAddress()
- {
- $formattedOrderDeliveryAddress = new SveaOrderDeliveryAddress();
-
- $formattedOrderDeliveryAddress->FullName = isset($this->order->orderDeliveryAddress->fullName) ? $this->order->orderDeliveryAddress->fullName : "";
- $formattedOrderDeliveryAddress->FirstName = isset($this->order->orderDeliveryAddress->firstName) ? $this->order->orderDeliveryAddress->firstName : "";
- $formattedOrderDeliveryAddress->LastName = isset($this->order->orderDeliveryAddress->lastName) ? $this->order->orderDeliveryAddress->lastName : "";
- $formattedOrderDeliveryAddress->CoAddress = isset($this->order->orderDeliveryAddress->coAddress) ? $this->order->orderDeliveryAddress->coAddress : "";
- $formattedOrderDeliveryAddress->ZipCode = isset($this->order->orderDeliveryAddress->zipCode) ? $this->order->orderDeliveryAddress->zipCode : "";
- $formattedOrderDeliveryAddress->HouseNumber = isset($this->order->orderDeliveryAddress->houseNumber) ? $this->order->orderDeliveryAddress->houseNumber : "";
- $formattedOrderDeliveryAddress->Locality = isset($this->order->orderDeliveryAddress->locality) ? $this->order->orderDeliveryAddress->locality : "";
- $formattedOrderDeliveryAddress->CountryCode = isset($this->order->orderDeliveryAddress->countryCode) ? $this->order->orderDeliveryAddress->countryCode : "";
-
- return $formattedOrderDeliveryAddress;
- }
- /**
- * if CustomerIdentity is created by addCustomerDetails()
- * @return SveaCustomerIdentity
- */
- public function formatCustomerDetails()
- {
- $isCompany = false;
- get_class($this->order->customerIdentity) == 'Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer' ? $isCompany = TRUE : $isCompany = FALSE;
-
- $companyId = "";
- if (isset($this->order->customerIdentity->orgNumber) || isset($this->order->customerIdentity->companyVatNumber)) {
- $isCompany = true;
- $companyId = isset($this->order->customerIdentity->orgNumber) ? $this->order->customerIdentity->orgNumber : $this->order->customerIdentity->companyVatNumber;
- }
-
- //For european countries Individual/Company - identity required
- $idValues = array();
-
- if ($this->order->countryCode != 'SE'
- && $this->order->countryCode != 'NO'
- && $this->order->countryCode != 'FI'
- && $this->order->countryCode != 'DK'
- ) {
- $euIdentity = new SveaIdentity($isCompany);
-
- if ($isCompany) {
- $euIdentity->CompanyVatNumber = $companyId;
- } else {
- $euIdentity->FirstName = $this->order->customerIdentity->firstname;
- $euIdentity->LastName = $this->order->customerIdentity->lastname;
- if ($this->order->countryCode == 'NL') {
- $euIdentity->Initials = $this->order->customerIdentity->initials;
- }
- $euIdentity->BirthDate = $this->order->customerIdentity->birthDate;
- }
-
- $type = ($isCompany ? "CompanyIdentity" : "IndividualIdentity");
- $idValues[$type] = $euIdentity;
- }
-
- $individualCustomerIdentity = new SveaCustomerIdentity($idValues);
- //For nordic countries NationalIdNumber is required
- if ($this->order->countryCode != 'NL' && $this->order->countryCode != 'DE') {
- //set with companyVatNumber for Company and NationalIdNumber for individual
- $individualCustomerIdentity->NationalIdNumber = $isCompany ? $companyId : $this->order->customerIdentity->ssn;
- }
-
- if ($isCompany) {
- $individualCustomerIdentity->FullName = isset($this->order->customerIdentity->companyName) ? $this->order->customerIdentity->companyName : "";
- } else {
- $individualCustomerIdentity->FullName = isset($this->order->customerIdentity->firstname) && isset($this->order->customerIdentity->lastname) ? $this->order->customerIdentity->firstname . ' ' . $this->order->customerIdentity->lastname : "";
- }
-
- $individualCustomerIdentity->PhoneNumber = isset($this->order->customerIdentity->phonenumber) ? $this->order->customerIdentity->phonenumber : "";
- $individualCustomerIdentity->Street = isset($this->order->customerIdentity->street) ? $this->order->customerIdentity->street : "";
- $individualCustomerIdentity->HouseNumber = isset($this->order->customerIdentity->housenumber) ? $this->order->customerIdentity->housenumber : "";
- $individualCustomerIdentity->CoAddress = isset($this->order->customerIdentity->coAddress) ? $this->order->customerIdentity->coAddress : "";
- $individualCustomerIdentity->ZipCode = isset($this->order->customerIdentity->zipCode) ? $this->order->customerIdentity->zipCode : "";
- $individualCustomerIdentity->Locality = isset($this->order->customerIdentity->locality) ? $this->order->customerIdentity->locality : "";
- $individualCustomerIdentity->Email = isset($this->order->customerIdentity->email) ? $this->order->customerIdentity->email : "";
- $individualCustomerIdentity->IpAddress = isset($this->order->customerIdentity->ipAddress) ? $this->order->customerIdentity->ipAddress : "";
-
- $individualCustomerIdentity->CountryCode = $this->order->countryCode;
- $individualCustomerIdentity->CustomerType = $isCompany ? "Company" : "Individual";
- $individualCustomerIdentity->PublicKey = isset($this->order->customerIdentity->publicKey) ? $this->order->customerIdentity->publicKey : "";
-
-
- return $individualCustomerIdentity;
- }
-
- /**
- * Format Customer Identity with svea_soap package
- * @return SveaCustomerIdentity
- */
- private function formatCustomerIdentity()
- {
- $isCompany = false;
- $companyId = "";
- if (isset($this->order->orgNumber) || isset($this->order->companyVatNumber)) {
- $isCompany = true;
- $companyId = isset($this->order->orgNumber) ? $this->order->orgNumber : $this->order->companyVatNumber;
- }
-
- //For european countries Individual/Company - identity required
- $idValues = array();
-
- if ($this->order->countryCode != 'SE'
- && $this->order->countryCode != 'NO'
- && $this->order->countryCode != 'FI'
- && $this->order->countryCode != 'DK'
- ) {
- $euIdentity = new SveaIdentity($isCompany);
-
- if ($isCompany) {
- $euIdentity->CompanyVatNumber = $companyId;
- } else {
- $euIdentity->FirstName = $this->order->firstname;
- $euIdentity->LastName = $this->order->lastname;
- if ($this->order->countryCode == 'NL') {
- $euIdentity->Initials = $this->order->initials;
- }
- $euIdentity->BirthDate = $this->order->birthDate;
- }
-
- $type = ($isCompany ? "CompanyIdentity" : "IndividualIdentity");
- $idValues[$type] = $euIdentity;
- }
-
- $individualCustomerIdentity = new SveaCustomerIdentity($idValues);
- //For nordic countries NationalIdNumber is required
- if ($this->order->countryCode != 'NL' && $this->order->countryCode != 'DE') {
- //set with companyVatNumber for Company and NationalIdNumber for individual
- $individualCustomerIdentity->NationalIdNumber = $isCompany ? $companyId : $this->order->ssn;
- }
-
- if ($isCompany) {
- $individualCustomerIdentity->FullName = isset($this->order->companyName) ? $this->order->companyName : "";
- } else {
- $individualCustomerIdentity->FullName = isset($this->order->firstname) && isset($this->order->lastname) ? $this->order->firstname . ' ' . $this->order->lastname : "";
- }
-
- $individualCustomerIdentity->PhoneNumber = isset($this->order->phonenumber) ? $this->order->phonenumber : "";
- $individualCustomerIdentity->Street = isset($this->order->street) ? $this->order->street : "";
- $individualCustomerIdentity->HouseNumber = isset($this->order->housenumber) ? $this->order->housenumber : "";
- $individualCustomerIdentity->CoAddress = isset($this->order->coAddress) ? $this->order->coAddress : "";
- $individualCustomerIdentity->ZipCode = isset($this->order->zipCode) ? $this->order->zipCode : "";
- $individualCustomerIdentity->Locality = isset($this->order->locality) ? $this->order->locality : "";
- $individualCustomerIdentity->Email = isset($this->order->email) ? $this->order->email : "";
- $individualCustomerIdentity->IpAddress = isset($this->order->ipAddress) ? $this->order->ipAddress : "";
-
- $individualCustomerIdentity->CountryCode = $this->order->countryCode;
- $individualCustomerIdentity->CustomerType = $isCompany ? "Company" : "Individual";
- $individualCustomerIdentity->PublicKey = isset($this->order->publicKey) ? $this->order->publicKey : "";
-
- return $individualCustomerIdentity;
- }
-
- /**
- * Get calculated totals before sending the request
- * Returns Array of the rounded sums of all orderrows as it will be sent to Svea
- * @returns array
- */
- public function getRequestTotals()
- {
- $object = $this->prepareRequest();
- $total_incvat = 0;
- $total_exvat = 0;
- $total_vat = 0;
- foreach ($object->request->CreateOrderInformation->OrderRows['OrderRow'] as $value) {
- $rowExVat = $this->calculateOrderRowExVat($value);
- $total_exvat += $rowExVat;
- $rowVat = $this->calculateTotalVatSumOfRows($value);
- $total_vat += $rowVat;
- $total_incvat += Helper::bround(($rowExVat + $rowVat), 2);
- }
-
- return array('total_exvat' => $total_exvat, 'total_incvat' => $total_incvat, 'total_vat' => $total_vat);
-
-
- }
-
- private function calculateOrderRowExVat($row)
- {
- if ($row->PriceIncludingVat == true) {
- $rowsum_incvat = $this->getRowAmount($row);
- $rowsum_exvat = $this->convertIncVatToExVat($row, $rowsum_incvat);
- } else {
- $rowsum_exvat = $this->getRowAmount($row);
- }
-
- return Helper::bround($rowsum_exvat, 2);
- }
-
- private function getRowAmount($row)
- {
- return Helper::bround($row->NumberOfUnits, 2) *
- Helper::bround($row->PricePerUnit, 2) *
- (1 - ($row->DiscountPercent / 100));
- }
-
- private function convertIncVatToExVat($row, $rowsum_incvat)
- {
- return Helper::bround(($rowsum_incvat / (1 + ($row->VatPercent / 100))), 2);
- }
-
- private function calculateTotalVatSumOfRows($row)
- {
- //if amount inc vat
- $sum = 0;
- //calculate the exvat sum
- if ($row->PriceIncludingVat == true) {
- $rowsum_incvat = $this->getRowAmount($row);
- $exvat = $this->convertIncVatToExVat($row, $rowsum_incvat);
-
- $vat = Helper::bround($rowsum_incvat, 2) - Helper::bround($exvat, 2);
- $sum += $vat;
- } else {
- $exvat = $this->getRowAmount($row);
-
- $vat = Helper::bround($exvat, 2) * ($row->VatPercent / 100);
- $sum += Helper::bround($vat, 2);
- }
-// $vat = \Svea\WebPay\Helper\Helper::bround($exvat,2) * ($row->VatPercent / 100 );
-// $sum += intval(100.00 * $vat) / 100.00; //php for .NET Math.Truncate -- round to nearest integer towards zero
-
- return $sum;
- }
+ public $order;
+
+ public $requestObject;
+
+ /**
+ * WebServicePayment constructor.
+ * @param $order
+ */
+ public function __construct($order)
+ {
+ $this->order = $order;
+ }
+
+ /**
+ * Transforms object to array and sends it to SveaWebPay Europe Web service API by php SoapClient
+ * @return CreateOrderResponse
+ * @throws ValidationException
+ */
+ public function doRequest()
+ {
+ $object = $this->prepareRequest();
+
+ $request = new SveaDoRequest($this->order->conf, $this->orderType, "CreateOrderEu", $object, $this->order->logging);
+ $response = new SveaResponse($request->result['requestResult'], "", NULL, NULL, isset($request->result['logs']) ? $request->result['logs'] : NULL);
+
+
+ return $response->getResponse();
+ }
+
+ /**
+ * Rebuild $order with svea_soap package to be in right format for SveaWebPay Europe Web service API
+ * @return SveaRequest SveaRequest
+ * @throws ValidationException
+ */
+ public function prepareRequest()
+ {
+ // validate order, throw exception on validation failure
+ $errors = $this->validateOrder();
+ if (count($errors) > 0) {
+ $exceptionString = "";
+ foreach ($errors as $key => $value) {
+ $exceptionString .= "-" . $key . " : " . $value . "\n";
+ }
+ throw new ValidationException($exceptionString);
+ }
+
+ // create soap order object, set authorization
+ $sveaOrder = new SveaOrder;
+ $sveaOrder->Auth = $this->getPasswordBasedAuthorization();
+ //make orderrows and put in CreateOrderInformation
+ $orderinformation = $this->formatOrderInformationWithOrderRows($this->order->orderRows);
+
+ //parallel ways of creating customer
+ if (isset($this->order->customerIdentity)) {
+ $orderinformation->CustomerIdentity = $this->formatCustomerDetails();
+ } else {
+ $orderinformation->CustomerIdentity = $this->formatCustomerIdentity();
+ }
+
+ $orderinformation->ClientOrderNumber = $this->order->clientOrderNumber;
+ $orderinformation->OrderDate = $this->order->orderDate;
+ $orderinformation->CustomerReference = $this->order->customerReference;
+ $orderinformation->PeppolId = $this->order->peppolId;
+
+ if(isset($this->order->orderDeliveryAddress))
+ {
+ $orderinformation->OrderDeliveryAddress = $this->formatOrderDeliveryAddress();
+
+ }
+ $sveaOrder->CreateOrderInformation = $this->setOrderType($orderinformation);
+
+ $object = new SveaRequest();
+ $object->request = $sveaOrder;
+
+ //do request
+ $this->requestObject = $object;
+
+ return $object;
+ }
+
+ public function validateOrder()
+ {
+ $this->order->orderType = $this->orderType;
+ $validator = new WebServiceOrderValidator();
+ $errors = $validator->validate($this->order);
+
+ return $errors;
+ }
+
+ private function getPasswordBasedAuthorization()
+ {
+ $auth = new SveaAuth();
+ $auth->Username = $this->order->conf->getUsername($this->orderType, $this->order->countryCode);
+ $auth->Password = $this->order->conf->getPassword($this->orderType, $this->order->countryCode);
+ $auth->ClientNumber = $this->order->conf->getClientNumber($this->orderType, $this->order->countryCode);
+
+ return $auth;
+ }
+
+ /*
+ *
+ */
+ private function formatOrderDeliveryAddress()
+ {
+ $formattedOrderDeliveryAddress = new SveaOrderDeliveryAddress();
+
+ $formattedOrderDeliveryAddress->FullName = isset($this->order->orderDeliveryAddress->fullName) ? $this->order->orderDeliveryAddress->fullName : "";
+ $formattedOrderDeliveryAddress->FirstName = isset($this->order->orderDeliveryAddress->firstName) ? $this->order->orderDeliveryAddress->firstName : "";
+ $formattedOrderDeliveryAddress->LastName = isset($this->order->orderDeliveryAddress->lastName) ? $this->order->orderDeliveryAddress->lastName : "";
+ $formattedOrderDeliveryAddress->CoAddress = isset($this->order->orderDeliveryAddress->coAddress) ? $this->order->orderDeliveryAddress->coAddress : "";
+ $formattedOrderDeliveryAddress->ZipCode = isset($this->order->orderDeliveryAddress->zipCode) ? $this->order->orderDeliveryAddress->zipCode : "";
+ $formattedOrderDeliveryAddress->HouseNumber = isset($this->order->orderDeliveryAddress->houseNumber) ? $this->order->orderDeliveryAddress->houseNumber : "";
+ $formattedOrderDeliveryAddress->Locality = isset($this->order->orderDeliveryAddress->locality) ? $this->order->orderDeliveryAddress->locality : "";
+ $formattedOrderDeliveryAddress->CountryCode = isset($this->order->orderDeliveryAddress->countryCode) ? $this->order->orderDeliveryAddress->countryCode : "";
+
+ return $formattedOrderDeliveryAddress;
+ }
+ /**
+ * if CustomerIdentity is created by addCustomerDetails()
+ * @return SveaCustomerIdentity
+ */
+ public function formatCustomerDetails()
+ {
+ $isCompany = false;
+ get_class($this->order->customerIdentity) == 'Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer' ? $isCompany = TRUE : $isCompany = FALSE;
+
+ $companyId = "";
+ if (isset($this->order->customerIdentity->orgNumber) || isset($this->order->customerIdentity->companyVatNumber)) {
+ $isCompany = true;
+ $companyId = isset($this->order->customerIdentity->orgNumber) ? $this->order->customerIdentity->orgNumber : $this->order->customerIdentity->companyVatNumber;
+ }
+
+ //For european countries Individual/Company - identity required
+ $idValues = [];
+
+ if ($this->order->countryCode != 'SE'
+ && $this->order->countryCode != 'NO'
+ && $this->order->countryCode != 'FI'
+ && $this->order->countryCode != 'DK'
+ ) {
+ $euIdentity = new SveaIdentity($isCompany);
+
+ if ($isCompany) {
+ $euIdentity->CompanyVatNumber = $companyId;
+ } else {
+ $euIdentity->FirstName = $this->order->customerIdentity->firstname;
+ $euIdentity->LastName = $this->order->customerIdentity->lastname;
+ if ($this->order->countryCode == 'NL') {
+ $euIdentity->Initials = $this->order->customerIdentity->initials;
+ }
+ $euIdentity->BirthDate = $this->order->customerIdentity->birthDate;
+ }
+
+ $type = ($isCompany ? "CompanyIdentity" : "IndividualIdentity");
+ $idValues[$type] = $euIdentity;
+ }
+
+ $individualCustomerIdentity = new SveaCustomerIdentity($idValues);
+ //For nordic countries NationalIdNumber is required
+ if ($this->order->countryCode != 'NL' && $this->order->countryCode != 'DE') {
+ //set with companyVatNumber for Company and NationalIdNumber for individual
+ $individualCustomerIdentity->NationalIdNumber = $isCompany ? $companyId : $this->order->customerIdentity->ssn;
+ }
+
+ if ($isCompany) {
+ $individualCustomerIdentity->FullName = isset($this->order->customerIdentity->companyName) ? $this->order->customerIdentity->companyName : "";
+ } else {
+ $individualCustomerIdentity->FullName = isset($this->order->customerIdentity->firstname) && isset($this->order->customerIdentity->lastname) ? $this->order->customerIdentity->firstname . ' ' . $this->order->customerIdentity->lastname : "";
+ }
+
+ $individualCustomerIdentity->PhoneNumber = isset($this->order->customerIdentity->phonenumber) ? $this->order->customerIdentity->phonenumber : "";
+ $individualCustomerIdentity->Street = isset($this->order->customerIdentity->street) ? $this->order->customerIdentity->street : "";
+ $individualCustomerIdentity->HouseNumber = isset($this->order->customerIdentity->housenumber) ? $this->order->customerIdentity->housenumber : "";
+ $individualCustomerIdentity->CoAddress = isset($this->order->customerIdentity->coAddress) ? $this->order->customerIdentity->coAddress : "";
+ $individualCustomerIdentity->ZipCode = isset($this->order->customerIdentity->zipCode) ? $this->order->customerIdentity->zipCode : "";
+ $individualCustomerIdentity->Locality = isset($this->order->customerIdentity->locality) ? $this->order->customerIdentity->locality : "";
+ $individualCustomerIdentity->Email = isset($this->order->customerIdentity->email) ? $this->order->customerIdentity->email : "";
+ $individualCustomerIdentity->IpAddress = isset($this->order->customerIdentity->ipAddress) ? $this->order->customerIdentity->ipAddress : "";
+
+ $individualCustomerIdentity->CountryCode = $this->order->countryCode;
+ $individualCustomerIdentity->CustomerType = $isCompany ? "Company" : "Individual";
+ $individualCustomerIdentity->PublicKey = isset($this->order->customerIdentity->publicKey) ? $this->order->customerIdentity->publicKey : "";
+
+
+ return $individualCustomerIdentity;
+ }
+
+ /**
+ * Format Customer Identity with svea_soap package
+ * @return SveaCustomerIdentity
+ */
+ private function formatCustomerIdentity()
+ {
+ $isCompany = false;
+ $companyId = "";
+ if (isset($this->order->orgNumber) || isset($this->order->companyVatNumber)) {
+ $isCompany = true;
+ $companyId = isset($this->order->orgNumber) ? $this->order->orgNumber : $this->order->companyVatNumber;
+ }
+
+ //For european countries Individual/Company - identity required
+ $idValues = [];
+
+ if ($this->order->countryCode != 'SE'
+ && $this->order->countryCode != 'NO'
+ && $this->order->countryCode != 'FI'
+ && $this->order->countryCode != 'DK'
+ ) {
+ $euIdentity = new SveaIdentity($isCompany);
+
+ if ($isCompany) {
+ $euIdentity->CompanyVatNumber = $companyId;
+ } else {
+ $euIdentity->FirstName = $this->order->firstname;
+ $euIdentity->LastName = $this->order->lastname;
+ if ($this->order->countryCode == 'NL') {
+ $euIdentity->Initials = $this->order->initials;
+ }
+ $euIdentity->BirthDate = $this->order->birthDate;
+ }
+
+ $type = ($isCompany ? "CompanyIdentity" : "IndividualIdentity");
+ $idValues[$type] = $euIdentity;
+ }
+
+ $individualCustomerIdentity = new SveaCustomerIdentity($idValues);
+ //For nordic countries NationalIdNumber is required
+ if ($this->order->countryCode != 'NL' && $this->order->countryCode != 'DE') {
+ //set with companyVatNumber for Company and NationalIdNumber for individual
+ $individualCustomerIdentity->NationalIdNumber = $isCompany ? $companyId : $this->order->ssn;
+ }
+
+ if ($isCompany) {
+ $individualCustomerIdentity->FullName = isset($this->order->companyName) ? $this->order->companyName : "";
+ } else {
+ $individualCustomerIdentity->FullName = isset($this->order->firstname) && isset($this->order->lastname) ? $this->order->firstname . ' ' . $this->order->lastname : "";
+ }
+
+ $individualCustomerIdentity->PhoneNumber = isset($this->order->phonenumber) ? $this->order->phonenumber : "";
+ $individualCustomerIdentity->Street = isset($this->order->street) ? $this->order->street : "";
+ $individualCustomerIdentity->HouseNumber = isset($this->order->housenumber) ? $this->order->housenumber : "";
+ $individualCustomerIdentity->CoAddress = isset($this->order->coAddress) ? $this->order->coAddress : "";
+ $individualCustomerIdentity->ZipCode = isset($this->order->zipCode) ? $this->order->zipCode : "";
+ $individualCustomerIdentity->Locality = isset($this->order->locality) ? $this->order->locality : "";
+ $individualCustomerIdentity->Email = isset($this->order->email) ? $this->order->email : "";
+ $individualCustomerIdentity->IpAddress = isset($this->order->ipAddress) ? $this->order->ipAddress : "";
+
+ $individualCustomerIdentity->CountryCode = $this->order->countryCode;
+ $individualCustomerIdentity->CustomerType = $isCompany ? "Company" : "Individual";
+ $individualCustomerIdentity->PublicKey = isset($this->order->publicKey) ? $this->order->publicKey : "";
+
+ return $individualCustomerIdentity;
+ }
+
+ /**
+ * Get calculated totals before sending the request
+ * Returns Array of the rounded sums of all orderrows as it will be sent to Svea
+ * @returns array
+ */
+ public function getRequestTotals()
+ {
+ $object = $this->prepareRequest();
+ $total_incvat = 0;
+ $total_exvat = 0;
+ $total_vat = 0;
+ foreach ($object->request->CreateOrderInformation->OrderRows['OrderRow'] as $value) {
+ $rowExVat = $this->calculateOrderRowExVat($value);
+ $total_exvat += $rowExVat;
+ $rowVat = $this->calculateTotalVatSumOfRows($value);
+ $total_vat += $rowVat;
+ $total_incvat += Helper::bround(($rowExVat + $rowVat), 2);
+ }
+
+ return ['total_exvat' => $total_exvat, 'total_incvat' => $total_incvat, 'total_vat' => $total_vat];
+
+
+ }
+
+ private function calculateOrderRowExVat($row)
+ {
+ if ($row->PriceIncludingVat == true) {
+ $rowsum_incvat = $this->getRowAmount($row);
+ $rowsum_exvat = $this->convertIncVatToExVat($row, $rowsum_incvat);
+ } else {
+ $rowsum_exvat = $this->getRowAmount($row);
+ }
+
+ return Helper::bround($rowsum_exvat, 2);
+ }
+
+ private function getRowAmount($row)
+ {
+ return Helper::bround($row->NumberOfUnits, 2) *
+ Helper::bround($row->PricePerUnit, 2) *
+ (1 - ($row->DiscountPercent / 100));
+ }
+
+ private function convertIncVatToExVat($row, $rowsum_incvat)
+ {
+ return Helper::bround(($rowsum_incvat / (1 + ($row->VatPercent / 100))), 2);
+ }
+
+ private function calculateTotalVatSumOfRows($row)
+ {
+ //if amount inc vat
+ $sum = 0;
+ //calculate the exvat sum
+ if ($row->PriceIncludingVat == true) {
+ $rowsum_incvat = $this->getRowAmount($row);
+ $exvat = $this->convertIncVatToExVat($row, $rowsum_incvat);
+
+ $vat = Helper::bround($rowsum_incvat, 2) - Helper::bround($exvat, 2);
+ $sum += $vat;
+ } else {
+ $exvat = $this->getRowAmount($row);
+
+ $vat = Helper::bround($exvat, 2) * ($row->VatPercent / 100);
+ $sum += Helper::bround($vat, 2);
+ }
+// $vat = \Svea\WebPay\Helper\Helper::bround($exvat,2) * ($row->VatPercent / 100 );
+// $sum += intval(100.00 * $vat) / 100.00; //php for .NET Math.Truncate -- round to nearest integer towards zero
+
+ return $sum;
+ }
}
diff --git a/src/WebService/SveaSoap/CreateOrderInformation.php b/src/WebService/SveaSoap/CreateOrderInformation.php
index c420e5a9..12e889fb 100644
--- a/src/WebService/SveaSoap/CreateOrderInformation.php
+++ b/src/WebService/SveaSoap/CreateOrderInformation.php
@@ -8,16 +8,16 @@
* */
abstract class CreateOrderInformation
{
- public $CustomerReference;
- public $OrderType;
- public $AddressSelector;
- public $ClientOrderNumber;
- public $OrderRows = array();
- public $CustomerIdentity;
- public $OrderDate;
+ public $CustomerReference;
+ public $OrderType;
+ public $AddressSelector;
+ public $ClientOrderNumber;
+ public $OrderRows = [];
+ public $CustomerIdentity;
+ public $OrderDate;
- public function addOrderRow($orderRow)
- {
- array_push($this->OrderRows['OrderRow'], $orderRow);
- }
+ public function addOrderRow($orderRow)
+ {
+ array_push($this->OrderRows['OrderRow'], $orderRow);
+ }
}
\ No newline at end of file
diff --git a/src/WebService/SveaSoap/SveaAddress.php b/src/WebService/SveaSoap/SveaAddress.php
index 5f6c9a32..9c9cdd23 100644
--- a/src/WebService/SveaSoap/SveaAddress.php
+++ b/src/WebService/SveaSoap/SveaAddress.php
@@ -7,26 +7,26 @@
class SveaAddress
{
- public $Auth;
+ public $Auth;
- public $IsCompany;
+ public $IsCompany;
- public $CountryCode;
+ public $CountryCode;
- public $SecurityNumber;
+ public $SecurityNumber;
- /**
- *
- * @param string $auth
- * @param boolean $isCompany
- * @param string $countryCode
- * @param string $securityNumber
- */
- function __construct($auth, $isCompany, $countryCode, $securityNumber)
- {
- $this->Auth = $auth;
- $this->IsCompany = $isCompany;
- $this->CountryCode = $countryCode;
- $this->SecurityNumber = $securityNumber;
- }
+ /**
+ *
+ * @param string $auth
+ * @param boolean $isCompany
+ * @param string $countryCode
+ * @param string $securityNumber
+ */
+ function __construct($auth, $isCompany, $countryCode, $securityNumber)
+ {
+ $this->Auth = $auth;
+ $this->IsCompany = $isCompany;
+ $this->CountryCode = $countryCode;
+ $this->SecurityNumber = $securityNumber;
+ }
}
diff --git a/src/WebService/SveaSoap/SveaAuth.php b/src/WebService/SveaSoap/SveaAuth.php
index b315e5b8..dc2a7922 100644
--- a/src/WebService/SveaSoap/SveaAuth.php
+++ b/src/WebService/SveaSoap/SveaAuth.php
@@ -10,23 +10,23 @@
*/
class SveaAuth
{
- public $Username;
+ public $Username;
- public $Password;
+ public $Password;
- public $ClientNumber;
+ public $ClientNumber;
- /**
- * creates a SveaAuth instance w/the given username, password & clientnumber
- *
- * @param string $Username
- * @param string $Password
- * @param string $ClientNumber
- */
- function __construct($Username = NULL, $Password = NULL, $ClientNumber = NULL)
- {
- if ($Username) $this->Username = $Username;
- if ($Password) $this->Password = $Password;
- if ($ClientNumber) $this->ClientNumber = $ClientNumber;
- }
+ /**
+ * creates a SveaAuth instance w/the given username, password & clientnumber
+ *
+ * @param string $Username
+ * @param string $Password
+ * @param string $ClientNumber
+ */
+ function __construct($Username = NULL, $Password = NULL, $ClientNumber = NULL)
+ {
+ if ($Username) $this->Username = $Username;
+ if ($Password) $this->Password = $Password;
+ if ($ClientNumber) $this->ClientNumber = $ClientNumber;
+ }
}
\ No newline at end of file
diff --git a/src/WebService/SveaSoap/SveaCloseOrder.php b/src/WebService/SveaSoap/SveaCloseOrder.php
index 91ec64bb..cd175c91 100644
--- a/src/WebService/SveaSoap/SveaCloseOrder.php
+++ b/src/WebService/SveaSoap/SveaCloseOrder.php
@@ -7,7 +7,7 @@
*/
class SveaCloseOrder
{
- public $Auth;
+ public $Auth;
- public $CloseOrderInformation;
+ public $CloseOrderInformation;
}
diff --git a/src/WebService/SveaSoap/SveaCloseOrderInformation.php b/src/WebService/SveaSoap/SveaCloseOrderInformation.php
index 5c1b2fd9..ee31286f 100644
--- a/src/WebService/SveaSoap/SveaCloseOrderInformation.php
+++ b/src/WebService/SveaSoap/SveaCloseOrderInformation.php
@@ -7,5 +7,5 @@
*/
class SveaCloseOrderInformation
{
- public $SveaOrderId;
+ public $SveaOrderId;
}
diff --git a/src/WebService/SveaSoap/SveaCreateAccountCreditOrderInformation.php b/src/WebService/SveaSoap/SveaCreateAccountCreditOrderInformation.php
index e66a9e1c..28e9c599 100644
--- a/src/WebService/SveaSoap/SveaCreateAccountCreditOrderInformation.php
+++ b/src/WebService/SveaSoap/SveaCreateAccountCreditOrderInformation.php
@@ -4,23 +4,23 @@
class SveaCreateAccountCreditOrderInformation extends CreateOrderInformation
{
- /**
- * @var array $CreateAccountCreditDetails
- */
- public $CreateAccountCreditDetails = array();
+ /**
+ * @var array $CreateAccountCreditDetails
+ */
+ public $CreateAccountCreditDetails = [];
- /**
- * Sets Variable if contains CampaignCode for AccountCredit
- * @param string $CampaignCode
- */
- public function __construct($CampaignCode = "")
- {
- $this->OrderRows['OrderRow'] = array();
+ /**
+ * Sets Variable if contains CampaignCode for AccountCredit
+ * @param string $CampaignCode
+ */
+ public function __construct($CampaignCode = "")
+ {
+ $this->OrderRows['OrderRow'] = [];
- if ($CampaignCode != "") {
- $this->CreateAccountCreditDetails = array(
- "CampaignCode" => $CampaignCode,
- );
- }
- }
+ if ($CampaignCode != "") {
+ $this->CreateAccountCreditDetails = [
+ "CampaignCode" => $CampaignCode,
+ ];
+ }
+ }
}
diff --git a/src/WebService/SveaSoap/SveaCreateOrderInformation.php b/src/WebService/SveaSoap/SveaCreateOrderInformation.php
index 840369de..c21c1b4a 100644
--- a/src/WebService/SveaSoap/SveaCreateOrderInformation.php
+++ b/src/WebService/SveaSoap/SveaCreateOrderInformation.php
@@ -4,20 +4,20 @@
class SveaCreateOrderInformation extends CreateOrderInformation
{
- /**
- * Sets Variable if contains CampaignCode for Paymentplan
- * @param string $CampaignCode
- * @param int $sendAutomaticGiroPaymentForm
- */
- public function __construct($CampaignCode = "", $sendAutomaticGiroPaymentForm = 0)
- {
- $this->OrderRows['OrderRow'] = array();
+ /**
+ * Sets Variable if contains CampaignCode for Paymentplan
+ * @param string $CampaignCode
+ * @param int $sendAutomaticGiroPaymentForm
+ */
+ public function __construct($CampaignCode = "", $sendAutomaticGiroPaymentForm = 0)
+ {
+ $this->OrderRows['OrderRow'] = [];
- if ($CampaignCode != "") {
- $this->CreatePaymentPlanDetails = array(
- "CampaignCode" => $CampaignCode,
- "SendAutomaticGiroPaymentForm" => $sendAutomaticGiroPaymentForm
- );
- }
- }
+ if ($CampaignCode != "") {
+ $this->CreatePaymentPlanDetails = [
+ "CampaignCode" => $CampaignCode,
+ "SendAutomaticGiroPaymentForm" => $sendAutomaticGiroPaymentForm
+ ];
+ }
+ }
}
diff --git a/src/WebService/SveaSoap/SveaCustomerIdentity.php b/src/WebService/SveaSoap/SveaCustomerIdentity.php
index 3176ea18..029b875a 100644
--- a/src/WebService/SveaSoap/SveaCustomerIdentity.php
+++ b/src/WebService/SveaSoap/SveaCustomerIdentity.php
@@ -4,37 +4,37 @@
class SveaCustomerIdentity
{
- /**
- * Only include in Nordic countries
- */
- public $NationalIdNumber;
- public $Email;
- public $PhoneNumber;
- public $IpAddress;
- public $FullName;
- public $Street;
- public $CoAddress;
- public $ZipCode;
- public $HouseNumber;
- public $Locality;
- public $CountryCode;
- public $CustomerType;
- public $PublicKey;
+ /**
+ * Only include in Nordic countries
+ */
+ public $NationalIdNumber;
+ public $Email;
+ public $PhoneNumber;
+ public $IpAddress;
+ public $FullName;
+ public $Street;
+ public $CoAddress;
+ public $ZipCode;
+ public $HouseNumber;
+ public $Locality;
+ public $CountryCode;
+ public $CustomerType;
+ public $PublicKey;
- /**
- * Dynamically crate an instancevariable depending on Company or Individual
- * @param array $identity
- */
- public function __construct($identity = array())
- {
- if (isset($identity)) {
- foreach ($identity as $key => $value) {
- if ($key == 'IndividualIdentity') {
- $this->IndividualIdentity = $value;
- } else {
- $this->CompanyIdentity = $value;
- }
- }
- }
- }
+ /**
+ * Dynamically crate an instancevariable depending on Company or Individual
+ * @param array $identity
+ */
+ public function __construct($identity = [])
+ {
+ if (isset($identity)) {
+ foreach ($identity as $key => $value) {
+ if ($key == 'IndividualIdentity') {
+ $this->IndividualIdentity = $value;
+ } else {
+ $this->CompanyIdentity = $value;
+ }
+ }
+ }
+ }
}
diff --git a/src/WebService/SveaSoap/SveaDeliverInvoiceDetails.php b/src/WebService/SveaSoap/SveaDeliverInvoiceDetails.php
index 1d4b4192..a53fc36f 100644
--- a/src/WebService/SveaSoap/SveaDeliverInvoiceDetails.php
+++ b/src/WebService/SveaSoap/SveaDeliverInvoiceDetails.php
@@ -7,42 +7,42 @@
*/
class SveaDeliverInvoiceDetails
{
- /**
- * Already set at Svea, but needs to be included in array
- */
- public $NumberOfCreditDays = "";
-
- /**
- * Post or Email
- */
- public $InvoiceDistributionType;
-
- /**
- * Can leave blank
- */
- public $IsCreditInvoice = "";
-
- public $InvoiceIdToCredit;
-
- /**
- * If order not changed, set with orderRowarray from CreateOrderEu
- */
- public $OrderRows = array();
-
- /**
- * SveaDeliverInvoiceDetails constructor.
- */
- public function __construct()
- {
- $this->OrderRows['OrderRow'] = array();
- }
-
- /**
- * only use if order is changed
- * @param $orderRow
- */
- public function addOrderRow($orderRow)
- {
- array_push($this->OrderRows['OrderRow'], $orderRow);
- }
+ /**
+ * Already set at Svea, but needs to be included in array
+ */
+ public $NumberOfCreditDays = "";
+
+ /**
+ * Post or Email
+ */
+ public $InvoiceDistributionType;
+
+ /**
+ * Can leave blank
+ */
+ public $IsCreditInvoice = "";
+
+ public $InvoiceIdToCredit;
+
+ /**
+ * If order not changed, set with orderRowarray from CreateOrderEu
+ */
+ public $OrderRows = [];
+
+ /**
+ * SveaDeliverInvoiceDetails constructor.
+ */
+ public function __construct()
+ {
+ $this->OrderRows['OrderRow'] = [];
+ }
+
+ /**
+ * only use if order is changed
+ * @param $orderRow
+ */
+ public function addOrderRow($orderRow)
+ {
+ array_push($this->OrderRows['OrderRow'], $orderRow);
+ }
}
diff --git a/src/WebService/SveaSoap/SveaDeliverOrder.php b/src/WebService/SveaSoap/SveaDeliverOrder.php
index 56cbae47..98b54546 100644
--- a/src/WebService/SveaSoap/SveaDeliverOrder.php
+++ b/src/WebService/SveaSoap/SveaDeliverOrder.php
@@ -7,6 +7,6 @@
*/
class SveaDeliverOrder
{
- public $Auth;
- public $DeliverOrderInformation;
+ public $Auth;
+ public $DeliverOrderInformation;
}
diff --git a/src/WebService/SveaSoap/SveaDeliverOrderInformation.php b/src/WebService/SveaSoap/SveaDeliverOrderInformation.php
index 47ace461..f98d0ddb 100644
--- a/src/WebService/SveaSoap/SveaDeliverOrderInformation.php
+++ b/src/WebService/SveaSoap/SveaDeliverOrderInformation.php
@@ -6,20 +6,20 @@
class SveaDeliverOrderInformation
{
- public $SveaOrderId;
- public $OrderType;
+ public $SveaOrderId;
+ public $OrderType;
- /**
- * SveaDeliverOrderInformation constructor.
- * @param $orderType
- */
- public function __construct($orderType)
- {
- if ($orderType == ConfigurationProvider::INVOICE_TYPE) {
- $this->DeliverInvoiceDetails = "";
- }
- else if ($orderType == ConfigurationProvider::ACCOUNTCREDIT_TYPE) {
- $this->DeliverAccountCreditDetails = "";
- }
- }
+ /**
+ * SveaDeliverOrderInformation constructor.
+ * @param $orderType
+ */
+ public function __construct($orderType)
+ {
+ if ($orderType == ConfigurationProvider::INVOICE_TYPE) {
+ $this->DeliverInvoiceDetails = "";
+ }
+ else if ($orderType == ConfigurationProvider::ACCOUNTCREDIT_TYPE) {
+ $this->DeliverAccountCreditDetails = "";
+ }
+ }
}
diff --git a/src/WebService/SveaSoap/SveaDoRequest.php b/src/WebService/SveaSoap/SveaDoRequest.php
index d829867f..645ec4eb 100644
--- a/src/WebService/SveaSoap/SveaDoRequest.php
+++ b/src/WebService/SveaSoap/SveaDoRequest.php
@@ -12,85 +12,85 @@
*/
class SveaDoRequest
{
- private $svea_server;
- private $client;
+ private $svea_server;
+ private $client;
- public $result;
+ public $result;
- /**
- * Constructor, sets up soap server and SoapClient
- * @param ConfigurationProvider $config
- * @param string $ordertype -- see Svea\WebPay\Config\ConfigurationProvider:: constants
- * @param string $method Method to call by soap
- * @param object $object Object to pass in soap call
- * @param bool $logging
- */
- public function __construct($config, $ordertype, $method, $object, $logging = false)
- {
- $this->svea_server = $config->getEndPoint($ordertype);
- $this->client = $this->SetSoapClient($config);
- $this->result = $this->CallSoap($method, $object, $logging);
- }
+ /**
+ * Constructor, sets up soap server and SoapClient
+ * @param ConfigurationProvider $config
+ * @param string $ordertype -- see Svea\WebPay\Config\ConfigurationProvider:: constants
+ * @param string $method Method to call by soap
+ * @param object $object Object to pass in soap call
+ * @param bool $logging
+ */
+ public function __construct($config, $ordertype, $method, $object, $logging = false)
+ {
+ $this->svea_server = $config->getEndPoint($ordertype);
+ $this->client = $this->SetSoapClient($config);
+ $this->result = $this->CallSoap($method, $object, $logging);
+ }
- private function CallSoap($method, $order, $logging)
- {
- $builder = new SveaSoapArrayBuilder();
- $headers = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'To', str_replace("/SveaWebPay.asmx?WSDL", "",$this->svea_server) . "/webpay/" . $method);
- $this->client->__setSoapHeaders($headers);
- $params = $builder->object_to_array($order);
- if($logging == true)
- {
- $timestampStart = time();
- $microtimeStart = microtime(true);
- }
- $result = array("requestResult" => $this->client->__soapCall($method, array($params)));
- if($logging == true)
- {
- $logs = array(
- "logs" => array(
- "request" => array(
- "timestamp" => $timestampStart,
- "headers" => $this->client->__getLastRequestHeaders(),
- "body" => htmlentities($this->client->__getLastRequest())
- ),
- "response" => array(
- "timestamp" => time(),
- "headers" => $this->client->__getLastResponseHeaders(),
- "body" => htmlentities($this->client->__getLastResponse()),
- "dataAmount" => strlen($this->client->__getLastResponseHeaders()) + strlen($this->client->__getLastResponse()),
- "duration" => round(microtime(true) - $microtimeStart, 3)
- )
- ));
- $result = array_merge($result, $logs);
- }
- return $result;
- }
+ private function CallSoap($method, $order, $logging)
+ {
+ $builder = new SveaSoapArrayBuilder();
+ $headers = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'To', str_replace("/SveaWebPay.asmx?WSDL", "",$this->svea_server) . "/webpay/" . $method);
+ $this->client->__setSoapHeaders($headers);
+ $params = $builder->object_to_array($order);
+ if($logging == true)
+ {
+ $timestampStart = time();
+ $microtimeStart = microtime(true);
+ }
+ $result = ["requestResult" => $this->client->__soapCall($method, [$params])];
+ if($logging == true)
+ {
+ $logs = [
+ "logs" => [
+ "request" => [
+ "timestamp" => $timestampStart,
+ "headers" => $this->client->__getLastRequestHeaders(),
+ "body" => htmlentities($this->client->__getLastRequest())
+ ],
+ "response" => [
+ "timestamp" => time(),
+ "headers" => $this->client->__getLastResponseHeaders(),
+ "body" => htmlentities($this->client->__getLastResponse()),
+ "dataAmount" => strlen($this->client->__getLastResponseHeaders()) + strlen($this->client->__getLastResponse()),
+ "duration" => round(microtime(true) - $microtimeStart, 3)
+ ]
+ ]];
+ $result = array_merge($result, $logs);
+ }
+ return $result;
+ }
- private function SetSoapClient($config)
- {
- $libraryProperties = Helper::getSveaLibraryProperties();
- $libraryName = $libraryProperties['library_name'];
- $libraryVersion = $libraryProperties['library_version'];
+ private function SetSoapClient($config)
+ {
+ $libraryProperties = Helper::getSveaLibraryProperties();
+ $libraryName = $libraryProperties['library_name'];
+ $libraryVersion = $libraryProperties['library_version'];
- $integrationProperties = Helper::getSveaIntegrationProperties($config);
- $integrationPlatform = $integrationProperties['integration_platform'];
- $integrationCompany = $integrationProperties['integration_company'];
- $integrationVersion = $integrationProperties['integration_version'];
+ $integrationProperties = Helper::getSveaIntegrationProperties($config);
+ $integrationPlatform = $integrationProperties['integration_platform'];
+ $integrationCompany = $integrationProperties['integration_company'];
+ $integrationVersion = $integrationProperties['integration_version'];
- $client = new \SoapClient(
- $this->svea_server,
- array(
- "trace" => 1,
- 'stream_context' => stream_context_create(array('http' => array(
- 'header' => 'X-Svea-Library-Name: ' . $libraryName . "\n" .
- 'X-Svea-Library-Version: ' . $libraryVersion . "\n" .
- 'X-Svea-Integration-Platform: ' . $integrationPlatform . "\n" .
- 'X-Svea-Integration-Company: ' . $integrationCompany . "\n" .
- 'X-Svea-Integration-Version: ' . $integrationVersion
- ))),
- "soap_version" => SOAP_1_2
- )
- );
- return $client;
- }
+ $client = new \SoapClient(
+ $this->svea_server,
+ [
+ "trace" => 1,
+ 'stream_context' => stream_context_create(['http' => [
+ 'header' => 'X-Svea-Library-Name: ' . $libraryName . "\n" .
+ 'X-Svea-Library-Version: ' . $libraryVersion . "\n" .
+ 'X-Svea-Integration-Platform: ' . $integrationPlatform . "\n" .
+ 'X-Svea-Integration-Company: ' . $integrationCompany . "\n" .
+ 'X-Svea-Integration-Version: ' . $integrationVersion
+ ]]),
+ "soap_version" => SOAP_1_2
+ ]
+ );
+ return $client;
+ }
}
\ No newline at end of file
diff --git a/src/WebService/SveaSoap/SveaIdentity.php b/src/WebService/SveaSoap/SveaIdentity.php
index ca422605..63f5d953 100644
--- a/src/WebService/SveaSoap/SveaIdentity.php
+++ b/src/WebService/SveaSoap/SveaIdentity.php
@@ -4,22 +4,22 @@
class SveaIdentity
{
- /**
- * Dynamically crate an instancevariable depending on Company or Individual
- * @param bool $bool - False means Individual
- */
- public function __construct($bool = false)
- {
- //if Individual
- if ($bool == FALSE) {
- $this->FirstName = "";
- $this->LastName = "";
- $this->Initials = "";
- $this->BirthDate = "";
+ /**
+ * Dynamically crate an instancevariable depending on Company or Individual
+ * @param bool $bool - False means Individual
+ */
+ public function __construct($bool = false)
+ {
+ //if Individual
+ if ($bool == FALSE) {
+ $this->FirstName = "";
+ $this->LastName = "";
+ $this->Initials = "";
+ $this->BirthDate = "";
- } //if Company
- else {
- $this->CompanyVatNumber = "";
- }
- }
+ } //if Company
+ else {
+ $this->CompanyVatNumber = "";
+ }
+ }
}
diff --git a/src/WebService/SveaSoap/SveaOrder.php b/src/WebService/SveaSoap/SveaOrder.php
index c5aac4fe..301318cf 100644
--- a/src/WebService/SveaSoap/SveaOrder.php
+++ b/src/WebService/SveaSoap/SveaOrder.php
@@ -7,6 +7,6 @@
*/
class SveaOrder
{
- public $Auth;
- public $CreateOrderInformation;
+ public $Auth;
+ public $CreateOrderInformation;
}
diff --git a/src/WebService/SveaSoap/SveaOrderDeliveryAddress.php b/src/WebService/SveaSoap/SveaOrderDeliveryAddress.php
index 00c6f544..47a843ce 100644
--- a/src/WebService/SveaSoap/SveaOrderDeliveryAddress.php
+++ b/src/WebService/SveaSoap/SveaOrderDeliveryAddress.php
@@ -11,13 +11,13 @@
class SveaOrderDeliveryAddress
{
- public $FullName;
- public $FirstName;
- public $LastName;
- public $StreetAddress;
- public $CoAddress;
- public $ZipCode;
- public $HouseNumber;
- public $Locality;
- public $CountryCode;
+ public $FullName;
+ public $FirstName;
+ public $LastName;
+ public $StreetAddress;
+ public $CoAddress;
+ public $ZipCode;
+ public $HouseNumber;
+ public $Locality;
+ public $CountryCode;
}
\ No newline at end of file
diff --git a/src/WebService/SveaSoap/SveaOrderRow.php b/src/WebService/SveaSoap/SveaOrderRow.php
index 1baac4c0..32e3c749 100644
--- a/src/WebService/SveaSoap/SveaOrderRow.php
+++ b/src/WebService/SveaSoap/SveaOrderRow.php
@@ -7,14 +7,14 @@
*/
class SveaOrderRow
{
- public $ArticleNumber;
- public $Name;
- public $Description;
- public $PricePerUnit;
- public $NumberOfUnits;
- public $Unit;
- public $TemporaryReference;
- public $VatPercent;
- public $DiscountPercent;
- public $PriceIncludingVat;
+ public $ArticleNumber;
+ public $Name;
+ public $Description;
+ public $PricePerUnit;
+ public $NumberOfUnits;
+ public $Unit;
+ public $TemporaryReference;
+ public $VatPercent;
+ public $DiscountPercent;
+ public $PriceIncludingVat;
}
diff --git a/src/WebService/SveaSoap/SveaRequest.php b/src/WebService/SveaSoap/SveaRequest.php
index 1bfc8b81..a6c80bcb 100644
--- a/src/WebService/SveaSoap/SveaRequest.php
+++ b/src/WebService/SveaSoap/SveaRequest.php
@@ -8,19 +8,19 @@
class SveaRequest
{
- /**
- * mixed $request the request contents in a format ready for consumption by
- * SveaDoRequest()
- */
- public $request;
+ /**
+ * mixed $request the request contents in a format ready for consumption by
+ * SveaDoRequest()
+ */
+ public $request;
- /**
- * @param mixed $request if not set, will do nothing
- */
- function __construct($request = NULL)
- {
- if ($request) {
- $this->request = $request;
- }
- }
+ /**
+ * @param mixed $request if not set, will do nothing
+ */
+ function __construct($request = NULL)
+ {
+ if ($request) {
+ $this->request = $request;
+ }
+ }
}
diff --git a/src/WebService/SveaSoap/SveaSoapArrayBuilder.php b/src/WebService/SveaSoap/SveaSoapArrayBuilder.php
index d7e0ee26..0c824e49 100644
--- a/src/WebService/SveaSoap/SveaSoapArrayBuilder.php
+++ b/src/WebService/SveaSoap/SveaSoapArrayBuilder.php
@@ -7,22 +7,22 @@
*/
class SveaSoapArrayBuilder
{
- /**
- * Turns firs level objects in object to arrays
- * @param $data
- * @return array
- */
- function object_to_array($data)
- {
- if (is_array($data) || is_object($data)) {
- $result = array();
- foreach ($data as $key => $value) {
- $result[$key] = $this->object_to_array($value);
- }
+ /**
+ * Turns firs level objects in object to arrays
+ * @param $data
+ * @return array
+ */
+ function object_to_array($data)
+ {
+ if (is_array($data) || is_object($data)) {
+ $result = [];
+ foreach ($data as $key => $value) {
+ $result[$key] = $this->object_to_array($value);
+ }
- return $result;
- }
+ return $result;
+ }
- return $data;
- }
+ return $data;
+ }
}
diff --git a/src/WebService/WebServiceResponse/AccountCreditParamsResponse.php b/src/WebService/WebServiceResponse/AccountCreditParamsResponse.php
index 906dc4fe..b91bc990 100644
--- a/src/WebService/WebServiceResponse/AccountCreditParamsResponse.php
+++ b/src/WebService/WebServiceResponse/AccountCreditParamsResponse.php
@@ -9,87 +9,87 @@
*
* formatObject() sets the following AccountCreditParamsResponse attributes:
*
- * $response->accepted // true iff request was accepted by the service
- * $response->errormessage // may be set iff accepted above is false
+ * $response->accepted // true iff request was accepted by the service
+ * $response->errormessage // may be set iff accepted above is false
*
- * $response->resultcode // 27xxx, reason
- * $response->AccountCreditCampaignCodes[0..n] // all available campaign account credit plans in an array
- * ->campaignCode
- * ->description
- * ->initialFee
- * ->lowestAmountToPayPerMonth
- * ->lowestPercentToPayPerMonth
- * ->lowestOrderAmount
- * ->interestRatePercent
+ * $response->resultcode // 27xxx, reason
+ * $response->AccountCreditCampaignCodes[0..n] // all available campaign account credit plans in an array
+ * ->campaignCode
+ * ->description
+ * ->initialFee
+ * ->lowestAmountToPayPerMonth
+ * ->lowestPercentToPayPerMonth
+ * ->lowestOrderAmount
+ * ->interestRatePercent
*
* For possible resultcodes (27xxx), see svea webpay_eu_webservice documentation
*
*/
class AccountCreditParamsResponse extends WebServiceResponse
{
- /**
- * @var AccountCreditCampaignCode[] $AccountCreditCampaignCodes - array of AccountCreditCampaignCode
- */
- public $AccountCreditCampaignCodes = array();
+ /**
+ * @var AccountCreditCampaignCode[] $AccountCreditCampaignCodes - array of AccountCreditCampaignCode
+ */
+ public $AccountCreditCampaignCodes = [];
- /**
- * AccountCreditParamsResponse constructor.
- * @param $response
- * @param $logs
- */
- public function __construct($response, $logs)
- {
- // was request accepted?
- $this->accepted = $response->GetAccountCreditParamsEuResult->Accepted;
+ /**
+ * AccountCreditParamsResponse constructor.
+ * @param $response
+ * @param $logs
+ */
+ public function __construct($response, $logs)
+ {
+ // was request accepted?
+ $this->accepted = $response->GetAccountCreditParamsEuResult->Accepted;
- // set response resultcode & errormessage, if any
- $this->resultcode = $response->GetAccountCreditParamsEuResult->ResultCode;
+ // set response resultcode & errormessage, if any
+ $this->resultcode = $response->GetAccountCreditParamsEuResult->ResultCode;
- $this->errormessage = isset($response->GetAccountCreditParamsEuResult->ErrorMessage) ? $response->GetAccountCreditParamsEuResult->ErrorMessage : "";
+ $this->errormessage = isset($response->GetAccountCreditParamsEuResult->ErrorMessage) ? $response->GetAccountCreditParamsEuResult->ErrorMessage : "";
- if(isset($logs))
- {
- $this->logs = $logs;
- }
+ if(isset($logs))
+ {
+ $this->logs = $logs;
+ }
- // set response attributes
- if ($this->accepted == 1) {
- if (is_array($response->GetAccountCreditParamsEuResult->AccountCreditCampaignCodes->AccountCreditCampaignCodeInfo)) {
- foreach ($response->GetAccountCreditParamsEuResult->AccountCreditCampaignCodes->AccountCreditCampaignCodeInfo as $code) {
- $campaign = $this->mapResponseData($code);
+ // set response attributes
+ if ($this->accepted == 1) {
+ if (is_array($response->GetAccountCreditParamsEuResult->AccountCreditCampaignCodes->AccountCreditCampaignCodeInfo)) {
+ foreach ($response->GetAccountCreditParamsEuResult->AccountCreditCampaignCodes->AccountCreditCampaignCodeInfo as $code) {
+ $campaign = $this->mapResponseData($code);
- array_push($this->AccountCreditCampaignCodes, $campaign); // add to available campaign payment plans array
- }
- } else {
+ array_push($this->AccountCreditCampaignCodes, $campaign); // add to available campaign payment plans array
+ }
+ } else {
- $code = $response->GetAccountCreditParamsEuResult->AccountCreditCampaignCodes->AccountCreditCampaignCodeInfo;
+ $code = $response->GetAccountCreditParamsEuResult->AccountCreditCampaignCodes->AccountCreditCampaignCodeInfo;
- $campaign = $this->mapResponseData($code);
+ $campaign = $this->mapResponseData($code);
- array_push($this->AccountCreditCampaignCodes, $campaign);
- }
- }
- }
+ array_push($this->AccountCreditCampaignCodes, $campaign);
+ }
+ }
+ }
- /**
- * Return AccountCreditCampaignCode mapped with AccountCreditCampaignCodeInfo
- *
- * @param $code
- * @return AccountCreditCampaignCode
- */
- private function mapResponseData($code)
- {
- $campaign = new AccountCreditCampaignCode();
+ /**
+ * Return AccountCreditCampaignCode mapped with AccountCreditCampaignCodeInfo
+ *
+ * @param $code
+ * @return AccountCreditCampaignCode
+ */
+ private function mapResponseData($code)
+ {
+ $campaign = new AccountCreditCampaignCode();
- $campaign->initialFee = $code->InitialFee;
- $campaign->description = $code->Description; // localised description string
- $campaign->campaignCode = $code->CampaignCode; // numeric campaign code identifier
- $campaign->notificationFee = $code->NotificationFee;
- $campaign->lowestOrderAmount = $code->LowestOrderAmount;
- $campaign->interestRatePercent = $code->InterestRatePercent;
- $campaign->lowestAmountToPayPerMonth = $code->LowestAmountToPayPerMonth;
- $campaign->lowestPercentToPayPerMonth = $code->LowestPercentToPayPerMonth;
+ $campaign->initialFee = $code->InitialFee;
+ $campaign->description = $code->Description; // localised description string
+ $campaign->campaignCode = $code->CampaignCode; // numeric campaign code identifier
+ $campaign->notificationFee = $code->NotificationFee;
+ $campaign->lowestOrderAmount = $code->LowestOrderAmount;
+ $campaign->interestRatePercent = $code->InterestRatePercent;
+ $campaign->lowestAmountToPayPerMonth = $code->LowestAmountToPayPerMonth;
+ $campaign->lowestPercentToPayPerMonth = $code->LowestPercentToPayPerMonth;
- return $campaign;
- }
+ return $campaign;
+ }
}
diff --git a/src/WebService/WebServiceResponse/CampaignCode/AccountCreditCampaignCode.php b/src/WebService/WebServiceResponse/CampaignCode/AccountCreditCampaignCode.php
index ee07646a..81b2d7d3 100644
--- a/src/WebService/WebServiceResponse/CampaignCode/AccountCreditCampaignCode.php
+++ b/src/WebService/WebServiceResponse/CampaignCode/AccountCreditCampaignCode.php
@@ -5,24 +5,24 @@
/**
* CampaignCodes structure
*
- * @attrib ->campaignCode // numeric campaign code identifier
- * @attrib ->description // localised description string
- * @attrib ->initialFee
- * @attrib ->lowestAmountToPayPerMonth
- * @attrib ->lowestPercentToPayPerMonth
- * @attrib ->lowestOrderAmount // amount lower limit for plan availability
- * @attrib ->interestRatePercent
- * @attrib ->notificationFee
+ * @attrib ->campaignCode // numeric campaign code identifier
+ * @attrib ->description // localised description string
+ * @attrib ->initialFee
+ * @attrib ->lowestAmountToPayPerMonth
+ * @attrib ->lowestPercentToPayPerMonth
+ * @attrib ->lowestOrderAmount // amount lower limit for plan availability
+ * @attrib ->interestRatePercent
+ * @attrib ->notificationFee
*
*/
class AccountCreditCampaignCode
{
- public $campaignCode;
- public $description;
- public $initialFee;
- public $lowestAmountToPayPerMonth;
- public $lowestPercentToPayPerMonth;
- public $lowestOrderAmount;
- public $interestRatePercent;
- public $notificationFee;
+ public $campaignCode;
+ public $description;
+ public $initialFee;
+ public $lowestAmountToPayPerMonth;
+ public $lowestPercentToPayPerMonth;
+ public $lowestOrderAmount;
+ public $interestRatePercent;
+ public $notificationFee;
}
diff --git a/src/WebService/WebServiceResponse/CampaignCode/CampaignCode.php b/src/WebService/WebServiceResponse/CampaignCode/CampaignCode.php
index ccfb53ee..d8769a95 100644
--- a/src/WebService/WebServiceResponse/CampaignCode/CampaignCode.php
+++ b/src/WebService/WebServiceResponse/CampaignCode/CampaignCode.php
@@ -5,33 +5,33 @@
/**
* CampaignCodes structure
*
- * @attrib ->campaignCode // numeric campaign code identifier
- * @attrib ->description // localised description string
- * @attrib ->paymentPlanType // human readable identifier (not guaranteed unique)
- * @attrib ->contractLengthInMonths
- * @attrib ->monthlyAnnuityFactor // pricePerMonth = price * monthlyAnnuityFactor + notificationFee
- * @attrib ->initialFee
- * @attrib ->notificationFee
- * @attrib ->interestRatePercent
- * @attrib ->numberOfInterestFreeMonths
- * @attrib ->numberOfPaymentFreeMonths
- * @attrib ->fromAmount // amount lower limit for plan availability
- * @attrib ->toAmount // amount upper limit for plan availability
+ * @attrib ->campaignCode // numeric campaign code identifier
+ * @attrib ->description // localised description string
+ * @attrib ->paymentPlanType // human readable identifier (not guaranteed unique)
+ * @attrib ->contractLengthInMonths
+ * @attrib ->monthlyAnnuityFactor // pricePerMonth = price * monthlyAnnuityFactor + notificationFee
+ * @attrib ->initialFee
+ * @attrib ->notificationFee
+ * @attrib ->interestRatePercent
+ * @attrib ->numberOfInterestFreeMonths
+ * @attrib ->numberOfPaymentFreeMonths
+ * @attrib ->fromAmount // amount lower limit for plan availability
+ * @attrib ->toAmount // amount upper limit for plan availability
*
* @author anne-hal, Kristian Grossman-Madsen
*/
class CampaignCode
{
- public $campaignCode;
- public $description;
- public $paymentPlanType;
- public $contractLengthInMonths;
- public $monthlyAnnuityFactor;
- public $initialFee;
- public $notificationFee;
- public $interestRatePercent;
- public $numberOfInterestFreeMonths;
- public $numberOfPaymentFreeMonths;
- public $fromAmount;
- public $toAmount;
+ public $campaignCode;
+ public $description;
+ public $paymentPlanType;
+ public $contractLengthInMonths;
+ public $monthlyAnnuityFactor;
+ public $initialFee;
+ public $notificationFee;
+ public $interestRatePercent;
+ public $numberOfInterestFreeMonths;
+ public $numberOfPaymentFreeMonths;
+ public $fromAmount;
+ public $toAmount;
}
diff --git a/src/WebService/WebServiceResponse/CloseOrderResult.php b/src/WebService/WebServiceResponse/CloseOrderResult.php
index ecdb34f9..f2839780 100644
--- a/src/WebService/WebServiceResponse/CloseOrderResult.php
+++ b/src/WebService/WebServiceResponse/CloseOrderResult.php
@@ -9,23 +9,23 @@
*/
class CloseOrderResult extends WebServiceResponse
{
- /**
- * CloseOrderResult constructor.
- * @param $response
- * @param $logs
- */
- public function __construct($response, $logs)
- {
- // was request accepted?
- $this->accepted = $response->CloseOrderEuResult->Accepted; // false or 1
- $this->errormessage = isset($response->CloseOrderEuResult->ErrorMessage) ? $response->CloseOrderEuResult->ErrorMessage : "";
+ /**
+ * CloseOrderResult constructor.
+ * @param $response
+ * @param $logs
+ */
+ public function __construct($response, $logs)
+ {
+ // was request accepted?
+ $this->accepted = $response->CloseOrderEuResult->Accepted; // false or 1
+ $this->errormessage = isset($response->CloseOrderEuResult->ErrorMessage) ? $response->CloseOrderEuResult->ErrorMessage : "";
- if(isset($logs))
- {
- $this->logs = $logs;
- }
+ if(isset($logs))
+ {
+ $this->logs = $logs;
+ }
- // set response resultcode
- $this->resultcode = $response->CloseOrderEuResult->ResultCode;
- }
+ // set response resultcode
+ $this->resultcode = $response->CloseOrderEuResult->ResultCode;
+ }
}
diff --git a/src/WebService/WebServiceResponse/CreateOrderResponse.php b/src/WebService/WebServiceResponse/CreateOrderResponse.php
index c0b03f65..decb7e85 100644
--- a/src/WebService/WebServiceResponse/CreateOrderResponse.php
+++ b/src/WebService/WebServiceResponse/CreateOrderResponse.php
@@ -16,94 +16,94 @@
*/
class CreateOrderResponse extends WebServiceResponse
{
- /**
- * @var string $sveaOrderId Always present. Unique Id for the created order. Used for any further webservice requests.
- */
- public $sveaOrderId;
-
- /**
- * @var string $orderType Always present. One of {Invoice|PaymentPlan}
- */
- public $orderType; // TODO java: enum
-
- /**
- * @var string $sveaWillBuyOrder Always present.
- */
- public $sveaWillBuyOrder; // TODO java: boolean
-
- /**
- * @var string $amount Always present. The total amount including VAT, presented as a decimal number.
- */
- public $amount;
-
- /**
- * @var CreateOrderIdentity $customerIdentity May be present. Contains invoice address.
- */
- public $customerIdentity;
-
- /**
- * @var string $expirationDate Always present. Order expiration date. If the order isn’t delivered before
- * this date the order is automatically closed.
- */
- public $expirationDate;
-
- /**
- * @var string $clientOrderNumber May be present. If passed in with request, a reference to the current order.
- */
- public $clientOrderNumber;
-
- /**
- * @var string $pending true if created order is pending at Svea
- */
- public $pending = 0;
-
- /**
- * @var string $pendingReason if pending is true then a reason can be found in this variable
- */
- public $pendingReasons;
- /**
- * CreateOrderResponse constructor.
- * @param $response
- * @param $logs
- */
- public function __construct($response, $logs = NULL)
- {
- // was request accepted?
- $this->accepted = $response->CreateOrderEuResult->Accepted;
- $this->errormessage = isset($response->CreateOrderEuResult->ErrorMessage) ? $response->CreateOrderEuResult->ErrorMessage : "";
-
- // set response resultcode
- $this->resultcode = $response->CreateOrderEuResult->ResultCode;
-
- if(isset($logs))
- {
- $this->logs = $logs;
- }
-
- // set response attributes
- if ($this->accepted == 1) {
-
- // always present
- $this->sveaOrderId = $response->CreateOrderEuResult->CreateOrderResult->SveaOrderId;
- $this->sveaWillBuyOrder = $response->CreateOrderEuResult->CreateOrderResult->SveaWillBuyOrder;
- $this->amount = $response->CreateOrderEuResult->CreateOrderResult->Amount;
- $this->expirationDate = $response->CreateOrderEuResult->CreateOrderResult->ExpirationDate;
-
- // presence not guaranteed
- if (isset($response->CreateOrderEuResult->CreateOrderResult->ClientOrderNumber)) {
- $this->clientOrderNumber = $response->CreateOrderEuResult->CreateOrderResult->ClientOrderNumber;
- }
- if (isset($response->CreateOrderEuResult->CreateOrderResult->OrderType)) {
- $this->orderType = $response->CreateOrderEuResult->CreateOrderResult->OrderType;
- }
- if (isset($response->CreateOrderEuResult->CreateOrderResult->CustomerIdentity)) {
- $this->customerIdentity = new CreateOrderIdentity($response->CreateOrderEuResult->CreateOrderResult->CustomerIdentity);
- }
- if (isset($response->CreateOrderEuResult->CreateOrderResult->PendingReasons))
- {
- $this->pending = 1;
- $this->pendingReasons = $response->CreateOrderEuResult->CreateOrderResult->PendingReasons;
- }
- }
- }
+ /**
+ * @var string $sveaOrderId Always present. Unique Id for the created order. Used for any further webservice requests.
+ */
+ public $sveaOrderId;
+
+ /**
+ * @var string $orderType Always present. One of {Invoice|PaymentPlan}
+ */
+ public $orderType; // TODO java: enum
+
+ /**
+ * @var string $sveaWillBuyOrder Always present.
+ */
+ public $sveaWillBuyOrder; // TODO java: boolean
+
+ /**
+ * @var string $amount Always present. The total amount including VAT, presented as a decimal number.
+ */
+ public $amount;
+
+ /**
+ * @var CreateOrderIdentity $customerIdentity May be present. Contains invoice address.
+ */
+ public $customerIdentity;
+
+ /**
+ * @var string $expirationDate Always present. Order expiration date. If the order isn’t delivered before
+ * this date the order is automatically closed.
+ */
+ public $expirationDate;
+
+ /**
+ * @var string $clientOrderNumber May be present. If passed in with request, a reference to the current order.
+ */
+ public $clientOrderNumber;
+
+ /**
+ * @var string $pending true if created order is pending at Svea
+ */
+ public $pending = 0;
+
+ /**
+ * @var string $pendingReason if pending is true then a reason can be found in this variable
+ */
+ public $pendingReasons;
+ /**
+ * CreateOrderResponse constructor.
+ * @param $response
+ * @param $logs
+ */
+ public function __construct($response, $logs = NULL)
+ {
+ // was request accepted?
+ $this->accepted = $response->CreateOrderEuResult->Accepted;
+ $this->errormessage = isset($response->CreateOrderEuResult->ErrorMessage) ? $response->CreateOrderEuResult->ErrorMessage : "";
+
+ // set response resultcode
+ $this->resultcode = $response->CreateOrderEuResult->ResultCode;
+
+ if(isset($logs))
+ {
+ $this->logs = $logs;
+ }
+
+ // set response attributes
+ if ($this->accepted == 1) {
+
+ // always present
+ $this->sveaOrderId = $response->CreateOrderEuResult->CreateOrderResult->SveaOrderId;
+ $this->sveaWillBuyOrder = $response->CreateOrderEuResult->CreateOrderResult->SveaWillBuyOrder;
+ $this->amount = $response->CreateOrderEuResult->CreateOrderResult->Amount;
+ $this->expirationDate = $response->CreateOrderEuResult->CreateOrderResult->ExpirationDate;
+
+ // presence not guaranteed
+ if (isset($response->CreateOrderEuResult->CreateOrderResult->ClientOrderNumber)) {
+ $this->clientOrderNumber = $response->CreateOrderEuResult->CreateOrderResult->ClientOrderNumber;
+ }
+ if (isset($response->CreateOrderEuResult->CreateOrderResult->OrderType)) {
+ $this->orderType = $response->CreateOrderEuResult->CreateOrderResult->OrderType;
+ }
+ if (isset($response->CreateOrderEuResult->CreateOrderResult->CustomerIdentity)) {
+ $this->customerIdentity = new CreateOrderIdentity($response->CreateOrderEuResult->CreateOrderResult->CustomerIdentity);
+ }
+ if (isset($response->CreateOrderEuResult->CreateOrderResult->PendingReasons))
+ {
+ $this->pending = 1;
+ $this->pendingReasons = $response->CreateOrderEuResult->CreateOrderResult->PendingReasons;
+ }
+ }
+ }
}
diff --git a/src/WebService/WebServiceResponse/CustomerIdentity/CreateOrderIdentity.php b/src/WebService/WebServiceResponse/CustomerIdentity/CreateOrderIdentity.php
index 461f6a54..89eef2e5 100644
--- a/src/WebService/WebServiceResponse/CustomerIdentity/CreateOrderIdentity.php
+++ b/src/WebService/WebServiceResponse/CustomerIdentity/CreateOrderIdentity.php
@@ -7,22 +7,22 @@
*/
class CreateOrderIdentity extends CustomerIdentityResponse
{
- public $email;
- public $ipAddress;
- public $countryCode;
- public $houseNumber;
+ public $email;
+ public $ipAddress;
+ public $countryCode;
+ public $houseNumber;
- /**
- * CreateOrderIdentity constructor.
- * @param object $customer
- */
- function __construct($customer)
- {
- $this->email = isset($customer->Email) ? $customer->Email : "";
- $this->ipAddress = isset($customer->IpAddress) ? $customer->IpAddress : "";
- $this->countryCode = isset($customer->CountryCode) ? $customer->CountryCode : "";
- $this->houseNumber = isset($customer->HouseNumber) ? $customer->HouseNumber : "";
+ /**
+ * CreateOrderIdentity constructor.
+ * @param object $customer
+ */
+ function __construct($customer)
+ {
+ $this->email = isset($customer->Email) ? $customer->Email : "";
+ $this->ipAddress = isset($customer->IpAddress) ? $customer->IpAddress : "";
+ $this->countryCode = isset($customer->CountryCode) ? $customer->CountryCode : "";
+ $this->houseNumber = isset($customer->HouseNumber) ? $customer->HouseNumber : "";
- parent::__construct($customer);
- }
+ parent::__construct($customer);
+ }
}
diff --git a/src/WebService/WebServiceResponse/CustomerIdentity/CustomerIdentityResponse.php b/src/WebService/WebServiceResponse/CustomerIdentity/CustomerIdentityResponse.php
index f6838f92..2e4511a4 100644
--- a/src/WebService/WebServiceResponse/CustomerIdentity/CustomerIdentityResponse.php
+++ b/src/WebService/WebServiceResponse/CustomerIdentity/CustomerIdentityResponse.php
@@ -9,80 +9,80 @@
*/
class CustomerIdentityResponse
{
- /**
- * @var string $customerType one of { Person, Business }
- */
- public $customerType;
+ /**
+ * @var string $customerType one of { Person, Business }
+ */
+ public $customerType;
- /**
- * @var string $nationalIdNumber
- */
- public $nationalIdNumber;
+ /**
+ * @var string $nationalIdNumber
+ */
+ public $nationalIdNumber;
- /**
- * @var string $phoneNumber
- */
- public $phoneNumber;
+ /**
+ * @var string $phoneNumber
+ */
+ public $phoneNumber;
- /**
- * @var string $fullName
- */
- public $fullName;
+ /**
+ * @var string $fullName
+ */
+ public $fullName;
- /**
- * @var string $street
- */
- public $street;
+ /**
+ * @var string $street
+ */
+ public $street;
- /**
- * @var string $coAddress
- */
- public $coAddress;
+ /**
+ * @var string $coAddress
+ */
+ public $coAddress;
- /**
- * @var string $zipCode
- */
- public $zipCode;
+ /**
+ * @var string $zipCode
+ */
+ public $zipCode;
- /**
- * @var string $locality
- */
- public $locality;
+ /**
+ * @var string $locality
+ */
+ public $locality;
- /**
- * @var string $publicKey
- */
- public $publicKey;
+ /**
+ * @var string $publicKey
+ */
+ public $publicKey;
- /**
- * populates the CustomerIdentityResponse object
- *
- * @param object $customer -- response from either legacy GetAddress or CreateOrderEU
- */
- function __construct($customer)
- {
- if (isset($customer->BusinessType)) { // GetAddressesResponse (Legacy webservice)
+ /**
+ * populates the CustomerIdentityResponse object
+ *
+ * @param object $customer -- response from either legacy GetAddress or CreateOrderEU
+ */
+ function __construct($customer)
+ {
+ if (isset($customer->BusinessType)) { // GetAddressesResponse (Legacy webservice)
- $this->customerType = $customer->BusinessType;
- $this->nationalIdNumber = isset($customer->SecurityNumber) ? $customer->SecurityNumber : "";
- $this->phoneNumber = isset($customer->PhoneNumber) ? $customer->PhoneNumber : "";
- $this->firstName = isset($customer->FirstName) ? $customer->FirstName : "";
- $this->lastName = isset($customer->LastName) ? $customer->LastName : "";
- $this->fullName = isset($customer->LegalName) ? $customer->LegalName : "";
- $this->street = isset($customer->AddressLine2) ? $customer->AddressLine2 : "";
- $this->coAddress = isset($customer->AddressLine1) ? $customer->AddressLine1 : "";
- $this->zipCode = isset($customer->Postcode) ? $customer->Postcode : "";
- $this->locality = isset($customer->Postarea) ? $customer->Postarea : "";
- } else { // CreateOrderResponse (EU webservice)
- $this->customerType = isset($customer->CustomerType) ? $customer->CustomerType : "";
- $this->nationalIdNumber = isset($customer->NationalIdNumber) ? $customer->NationalIdNumber : "";
- $this->phoneNumber = isset($customer->PhoneNumber) ? $customer->PhoneNumber : "";
- $this->fullName = isset($customer->FullName) ? $customer->FullName : "";
- $this->street = isset($customer->Street) ? $customer->Street : "";
- $this->coAddress = isset($customer->CoAddress) ? $customer->CoAddress : "";
- $this->zipCode = isset($customer->ZipCode) ? $customer->ZipCode : "";
- $this->locality = isset($customer->Locality) ? $customer->Locality : "";
- $this->publicKey = isset($customer->PublicKey) ? $customer->PublicKey : "";
- }
- }
+ $this->customerType = $customer->BusinessType;
+ $this->nationalIdNumber = isset($customer->SecurityNumber) ? $customer->SecurityNumber : "";
+ $this->phoneNumber = isset($customer->PhoneNumber) ? $customer->PhoneNumber : "";
+ $this->firstName = isset($customer->FirstName) ? $customer->FirstName : "";
+ $this->lastName = isset($customer->LastName) ? $customer->LastName : "";
+ $this->fullName = isset($customer->LegalName) ? $customer->LegalName : "";
+ $this->street = isset($customer->AddressLine2) ? $customer->AddressLine2 : "";
+ $this->coAddress = isset($customer->AddressLine1) ? $customer->AddressLine1 : "";
+ $this->zipCode = isset($customer->Postcode) ? $customer->Postcode : "";
+ $this->locality = isset($customer->Postarea) ? $customer->Postarea : "";
+ } else { // CreateOrderResponse (EU webservice)
+ $this->customerType = isset($customer->CustomerType) ? $customer->CustomerType : "";
+ $this->nationalIdNumber = isset($customer->NationalIdNumber) ? $customer->NationalIdNumber : "";
+ $this->phoneNumber = isset($customer->PhoneNumber) ? $customer->PhoneNumber : "";
+ $this->fullName = isset($customer->FullName) ? $customer->FullName : "";
+ $this->street = isset($customer->Street) ? $customer->Street : "";
+ $this->coAddress = isset($customer->CoAddress) ? $customer->CoAddress : "";
+ $this->zipCode = isset($customer->ZipCode) ? $customer->ZipCode : "";
+ $this->locality = isset($customer->Locality) ? $customer->Locality : "";
+ $this->publicKey = isset($customer->PublicKey) ? $customer->PublicKey : "";
+ }
+ }
}
diff --git a/src/WebService/WebServiceResponse/CustomerIdentity/GetAddressIdentity.php b/src/WebService/WebServiceResponse/CustomerIdentity/GetAddressIdentity.php
index 6024ed91..f84910df 100644
--- a/src/WebService/WebServiceResponse/CustomerIdentity/GetAddressIdentity.php
+++ b/src/WebService/WebServiceResponse/CustomerIdentity/GetAddressIdentity.php
@@ -9,28 +9,28 @@
*/
class GetAddressIdentity extends CustomerIdentityResponse
{
- /**
- * @var string $addressSelector
- */
- public $addressSelector;
+ /**
+ * @var string $addressSelector
+ */
+ public $addressSelector;
- /**
- * @var string $firstName only set in case of a createorder request
- */
- public $firstName;
+ /**
+ * @var string $firstName only set in case of a createorder request
+ */
+ public $firstName;
- /**
- * @var string $lastName only set in case of a createorder request
- */
- public $lastName;
+ /**
+ * @var string $lastName only set in case of a createorder request
+ */
+ public $lastName;
- /**
- * GetAddressIdentity constructor.
- * @param object $customer
- */
- function __construct($customer)
- {
- $this->addressSelector = isset($customer->AddressSelector) ? $customer->AddressSelector : "";
- parent::__construct($customer);
- }
+ /**
+ * GetAddressIdentity constructor.
+ * @param object $customer
+ */
+ function __construct($customer)
+ {
+ $this->addressSelector = isset($customer->AddressSelector) ? $customer->AddressSelector : "";
+ parent::__construct($customer);
+ }
}
diff --git a/src/WebService/WebServiceResponse/DeliverOrderResult.php b/src/WebService/WebServiceResponse/DeliverOrderResult.php
index bef5d605..3b66c83b 100644
--- a/src/WebService/WebServiceResponse/DeliverOrderResult.php
+++ b/src/WebService/WebServiceResponse/DeliverOrderResult.php
@@ -7,89 +7,89 @@
*/
class DeliverOrderResult extends WebServiceResponse
{
- /**
- * @var float $amount The sum of all the provided order rows.
- */
- public $amount;
+ /**
+ * @var float $amount The sum of all the provided order rows.
+ */
+ public $amount;
- /**
- * @var string $orderType Indicates the payment method selected.
- */
- public $orderType;
+ /**
+ * @var string $orderType Indicates the payment method selected.
+ */
+ public $orderType;
- /**
- * @var long $invoiceId May be present. Svea invoice id received when delivering an invoice order.
- */
- public $invoiceId;
+ /**
+ * @var long $invoiceId May be present. Svea invoice id received when delivering an invoice order.
+ */
+ public $invoiceId;
- /**
- * @var string $dueDate May be present. Due date for the invoice when SveaWebPay wants the invoice to be payed.
- */
- public $dueDate;
+ /**
+ * @var string $dueDate May be present. Due date for the invoice when SveaWebPay wants the invoice to be payed.
+ */
+ public $dueDate;
- /**
- * @var string $invoiceDate May be present. Date when the invoice is created in Svea’s system. Due date is InvoiceDate + Credit days.
- */
- public $invoiceDate;
+ /**
+ * @var string $invoiceDate May be present. Date when the invoice is created in Svea’s system. Due date is InvoiceDate + Credit days.
+ */
+ public $invoiceDate;
- /**
- * @var string $invoiceDistributionType May be present. See Svea\WebPay\Constant\DistributionType class for possible values.
- */
- public $invoiceDistributionType;
+ /**
+ * @var string $invoiceDistributionType May be present. See Svea\WebPay\Constant\DistributionType class for possible values.
+ */
+ public $invoiceDistributionType;
- /**
- * @var string $ocr May be present.
- */
- public $ocr;
+ /**
+ * @var string $ocr May be present.
+ */
+ public $ocr;
- /**
- * @var long $lowestAmountToPay May be present.
- */
- public $lowestAmountToPay;
+ /**
+ * @var long $lowestAmountToPay May be present.
+ */
+ public $lowestAmountToPay;
- /**
- * @var long $contractNumber May be present. Svea contract number received when delivering a payment plan order.
- */
- public $contractNumber;
+ /**
+ * @var long $contractNumber May be present. Svea contract number received when delivering a payment plan order.
+ */
+ public $contractNumber;
- /**
- * DeliverOrderResult constructor.
- * @param $response
- * @param $logs
- */
- public function __construct($response, $logs)
- {
- $this->accepted = $response->DeliverOrderEuResult->Accepted;
- $this->resultcode = $response->DeliverOrderEuResult->ResultCode;
+ /**
+ * DeliverOrderResult constructor.
+ * @param $response
+ * @param $logs
+ */
+ public function __construct($response, $logs)
+ {
+ $this->accepted = $response->DeliverOrderEuResult->Accepted;
+ $this->resultcode = $response->DeliverOrderEuResult->ResultCode;
- if(isset($logs))
- {
- $this->logs = $logs;
- }
+ if(isset($logs))
+ {
+ $this->logs = $logs;
+ }
- if (isset($response->DeliverOrderEuResult->ErrorMessage)) {
- $this->errormessage = $response->DeliverOrderEuResult->ErrorMessage;
- }
+ if (isset($response->DeliverOrderEuResult->ErrorMessage)) {
+ $this->errormessage = $response->DeliverOrderEuResult->ErrorMessage;
+ }
- if ($this->accepted == 1) {
- $this->amount = $response->DeliverOrderEuResult->DeliverOrderResult->Amount;
- $this->orderType = $response->DeliverOrderEuResult->DeliverOrderResult->OrderType;
- if (property_exists($response->DeliverOrderEuResult->DeliverOrderResult, "InvoiceResultDetails")) {
- $this->invoiceId = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->InvoiceId;
- $this->dueDate = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->DueDate;
- $this->invoiceDate = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->InvoiceDate;
- $this->invoiceDistributionType = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->InvoiceDistributionType;
- $this->ocr = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->Ocr;
- $this->lowestAmountToPay = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->LowestAmountToPay;
- } elseif (property_exists($response->DeliverOrderEuResult->DeliverOrderResult, "PaymentPlanResultDetails")) {
- $this->contractNumber = $response->DeliverOrderEuResult->DeliverOrderResult->PaymentPlanResultDetails->ContractNumber;
- }
- // - specific for accountCredit
- if(property_exists($response->DeliverOrderEuResult->DeliverOrderResult, "DeliveryReferenceNumber"))
- {
- $this->deliveryReferenceNumber = $response->DeliverOrderEuResult->DeliverOrderResult->DeliveryReferenceNumber;
- }
- }
- }
+ if ($this->accepted == 1) {
+ $this->amount = $response->DeliverOrderEuResult->DeliverOrderResult->Amount;
+ $this->orderType = $response->DeliverOrderEuResult->DeliverOrderResult->OrderType;
+ if (property_exists($response->DeliverOrderEuResult->DeliverOrderResult, "InvoiceResultDetails")) {
+ $this->invoiceId = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->InvoiceId;
+ $this->dueDate = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->DueDate;
+ $this->invoiceDate = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->InvoiceDate;
+ $this->invoiceDistributionType = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->InvoiceDistributionType;
+ $this->ocr = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->Ocr;
+ $this->lowestAmountToPay = $response->DeliverOrderEuResult->DeliverOrderResult->InvoiceResultDetails->LowestAmountToPay;
+ } elseif (property_exists($response->DeliverOrderEuResult->DeliverOrderResult, "PaymentPlanResultDetails")) {
+ $this->contractNumber = $response->DeliverOrderEuResult->DeliverOrderResult->PaymentPlanResultDetails->ContractNumber;
+ }
+ // - specific for accountCredit
+ if(property_exists($response->DeliverOrderEuResult->DeliverOrderResult, "DeliveryReferenceNumber"))
+ {
+ $this->deliveryReferenceNumber = $response->DeliverOrderEuResult->DeliverOrderResult->DeliveryReferenceNumber;
+ }
+ }
+ }
}
diff --git a/src/WebService/WebServiceResponse/GetAddressesResponse.php b/src/WebService/WebServiceResponse/GetAddressesResponse.php
index 27e8bad6..75879919 100644
--- a/src/WebService/WebServiceResponse/GetAddressesResponse.php
+++ b/src/WebService/WebServiceResponse/GetAddressesResponse.php
@@ -8,73 +8,73 @@
* The Webpay::getAddresses request returns an instance of GetAddressesResponse, containing the actual customer addresses in an array of
* GetAddressIdentity:
*
- * $response = Svea\WebPay\WebPay::getAddresses($testConfig);
+ * $response = Svea\WebPay\WebPay::getAddresses($testConfig);
*
- * // GetAddressResponse attributes:
- * $response->accepted; // Boolean // true iff request was accepted
- * $response->resultcode; // String // set iff accepted false
- * $response->errormessage; // String // set iff accepted false
- * $response->customerIdentity; // Array of GetAddressIdentity
+ * // GetAddressResponse attributes:
+ * $response->accepted; // Boolean // true iff request was accepted
+ * $response->resultcode; // String // set iff accepted false
+ * $response->errormessage; // String // set iff accepted false
+ * $response->customerIdentity; // Array of GetAddressIdentity
*
- * $firstCustomerAddress = $myGetAddressesResponse->customerIdentity[0];
+ * $firstCustomerAddress = $myGetAddressesResponse->customerIdentity[0];
*
- * // GetAddressIdentity attributes:
- * $firstCustomerAddress->customerType; // String // "Person" or "Business" for individual and company customers, respectively
- * $firstCustomerAddress->nationalIdNumber; // Numeric // national id number of individual or company
- * $firstCustomerAddress->fullName; // String // amalgated firstname and surname for indivdual, or company name for company customers
- * $firstCustomerAddress->coAddress; // String // optional
- * $firstCustomerAddress->street; // String // required, streetname including housenumber
- * $firstCustomerAddress->zipCode; // String // required
- * $firstCustomerAddress->locality; // String // required, city name
- * $firstCustomerAddress->phoneNumber; // String // optional
- * $firstCustomerAddress->firstName; // String // optional, present in GetAddressResponse, not returned in CreateOrderResponse
- * $firstCustomerAddress->lastName; // String // optional, present in GetAddressResponse, not returned in CreateOrderResponse
- * $firstCustomerAddress->addressSelector // String // optional, uniquely disambiguates company addresses
+ * // GetAddressIdentity attributes:
+ * $firstCustomerAddress->customerType; // String // "Person" or "Business" for individual and company customers, respectively
+ * $firstCustomerAddress->nationalIdNumber; // Numeric // national id number of individual or company
+ * $firstCustomerAddress->fullName; // String // amalgated firstname and surname for indivdual, or company name for company customers
+ * $firstCustomerAddress->coAddress; // String // optional
+ * $firstCustomerAddress->street; // String // required, streetname including housenumber
+ * $firstCustomerAddress->zipCode; // String // required
+ * $firstCustomerAddress->locality; // String // required, city name
+ * $firstCustomerAddress->phoneNumber; // String // optional
+ * $firstCustomerAddress->firstName; // String // optional, present in GetAddressResponse, not returned in CreateOrderResponse
+ * $firstCustomerAddress->lastName; // String // optional, present in GetAddressResponse, not returned in CreateOrderResponse
+ * $firstCustomerAddress->addressSelector // String // optional, uniquely disambiguates company addresses
*
* @author anne-hal, Kristian Grossman-Madsen
*/
class GetAddressesResponse extends WebServiceResponse
{
- /**
- * @var $customerIdentity - GetAddressIdentity array of GetAddressIdentity
- */
- public $customerIdentity = array();
+ /**
+ * @var $customerIdentity - GetAddressIdentity array of GetAddressIdentity
+ */
+ public $customerIdentity = [];
- /**
- * GetAddressesResponse constructor.
- * @param $response
- * @param $logs
- */
- public function __construct($response, $logs)
- {
- // was request accepted?
- if ($response->GetAddressesResult->RejectionCode == "Error") {
- $this->accepted = 0;
- } else {
- $this->accepted = $response->GetAddressesResult->Accepted;
- }
+ /**
+ * GetAddressesResponse constructor.
+ * @param $response
+ * @param $logs
+ */
+ public function __construct($response, $logs)
+ {
+ // was request accepted?
+ if ($response->GetAddressesResult->RejectionCode == "Error") {
+ $this->accepted = 0;
+ } else {
+ $this->accepted = $response->GetAddressesResult->Accepted;
+ }
- if(isset($logs))
- {
- $this->logs = $logs;
- }
+ if(isset($logs))
+ {
+ $this->logs = $logs;
+ }
- $this->resultcode = $response->GetAddressesResult->RejectionCode;
- $this->errormessage = isset($response->GetAddressesResult->ErrorMessage) ? $response->GetAddressesResult->ErrorMessage : "";
+ $this->resultcode = $response->GetAddressesResult->RejectionCode;
+ $this->errormessage = isset($response->GetAddressesResult->ErrorMessage) ? $response->GetAddressesResult->ErrorMessage : "";
- // set response attributes
- if (property_exists($response->GetAddressesResult, "Addresses") && $this->accepted == 1) {
- $this->formatCustomerIdentity($response->GetAddressesResult->Addresses);
- }
- }
+ // set response attributes
+ if (property_exists($response->GetAddressesResult, "Addresses") && $this->accepted == 1) {
+ $this->formatCustomerIdentity($response->GetAddressesResult->Addresses);
+ }
+ }
- private function formatCustomerIdentity($customers)
- {
- is_array($customers->CustomerAddress) ? $loopValue = $customers->CustomerAddress : $loopValue = $customers;
+ private function formatCustomerIdentity($customers)
+ {
+ is_array($customers->CustomerAddress) ? $loopValue = $customers->CustomerAddress : $loopValue = $customers;
- foreach ($loopValue as $customer) {
- $temp = new GetAddressIdentity($customer);
- array_push($this->customerIdentity, $temp);
- }
- }
+ foreach ($loopValue as $customer) {
+ $temp = new GetAddressIdentity($customer);
+ array_push($this->customerIdentity, $temp);
+ }
+ }
}
diff --git a/src/WebService/WebServiceResponse/PaymentPlanParamsResponse.php b/src/WebService/WebServiceResponse/PaymentPlanParamsResponse.php
index f886c9ba..9e7ab8b2 100644
--- a/src/WebService/WebServiceResponse/PaymentPlanParamsResponse.php
+++ b/src/WebService/WebServiceResponse/PaymentPlanParamsResponse.php
@@ -9,24 +9,24 @@
*
* formatObject() sets the following PaymentPlanParamsResponse attributes:
*
- * $response->accepted // true iff request was accepted by the service
- * $response->errormessage // may be set iff accepted above is false
+ * $response->accepted // true iff request was accepted by the service
+ * $response->errormessage // may be set iff accepted above is false
*
- * $response->resultcode // 27xxx, reason
- * $response->campaignCodes[0..n] // all available campaign payment plans in an array
- * ->campaignCode // numeric campaign code identifier
- * ->description // localised description string
- * ->paymentPlanType // human readable identifier (not guaranteed unique)
- * ->contractLengthInMonths
- * ->monthlyAnnuityFactor // pricePerMonth = price * monthlyAnnuityFactor + notificationFee
- * ->initialFee
- * ->notificationFee
- * ->interestRatePercent
- * ->numberOfInterestFreeMonths
- * ->numberOfPaymentFreeMonths
- * ->fromAmount // amount lower limit for plan availability
- * ->toAmount // amount upper limit for plan availability
- * ->campaignCode // numeric campaign code identifier
+ * $response->resultcode // 27xxx, reason
+ * $response->campaignCodes[0..n] // all available campaign payment plans in an array
+ * ->campaignCode // numeric campaign code identifier
+ * ->description // localised description string
+ * ->paymentPlanType // human readable identifier (not guaranteed unique)
+ * ->contractLengthInMonths
+ * ->monthlyAnnuityFactor // pricePerMonth = price * monthlyAnnuityFactor + notificationFee
+ * ->initialFee
+ * ->notificationFee
+ * ->interestRatePercent
+ * ->numberOfInterestFreeMonths
+ * ->numberOfPaymentFreeMonths
+ * ->fromAmount // amount lower limit for plan availability
+ * ->toAmount // amount upper limit for plan availability
+ * ->campaignCode // numeric campaign code identifier
*
* For possible resultcodes (27xxx), see svea webpay_eu_webservice documentation
*
@@ -34,68 +34,68 @@
*/
class PaymentPlanParamsResponse extends WebServiceResponse
{
- /**
- * @var CampaignCode[] $campaignCodes - array of CampaignCode
- */
- public $campaignCodes = array();
+ /**
+ * @var CampaignCode[] $campaignCodes - array of CampaignCode
+ */
+ public $campaignCodes = [];
- /**
- * PaymentPlanParamsResponse constructor.
- * @param $response
- * @param $logs
- */
- public function __construct($response, $logs)
- {
- // was request accepted?
- $this->accepted = $response->GetPaymentPlanParamsEuResult->Accepted;
+ /**
+ * PaymentPlanParamsResponse constructor.
+ * @param $response
+ * @param $logs
+ */
+ public function __construct($response, $logs)
+ {
+ // was request accepted?
+ $this->accepted = $response->GetPaymentPlanParamsEuResult->Accepted;
- if(isset($logs))
- {
- $this->logs = $logs;
- }
+ if(isset($logs))
+ {
+ $this->logs = $logs;
+ }
- // set response resultcode & errormessage, if any
- $this->resultcode = $response->GetPaymentPlanParamsEuResult->ResultCode;
- $this->errormessage = isset($response->GetPaymentPlanParamsEuResult->ErrorMessage) ? $response->GetPaymentPlanParamsEuResult->ErrorMessage : "";
+ // set response resultcode & errormessage, if any
+ $this->resultcode = $response->GetPaymentPlanParamsEuResult->ResultCode;
+ $this->errormessage = isset($response->GetPaymentPlanParamsEuResult->ErrorMessage) ? $response->GetPaymentPlanParamsEuResult->ErrorMessage : "";
- // set response attributes
- if ($this->accepted == 1) {
- if (is_array($response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo)) {
- foreach ($response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo as $code) {
- $campaign = new CampaignCode();
- $campaign->campaignCode = $code->CampaignCode; // numeric campaign code identifier
- $campaign->description = $code->Description; // localised description string
- $campaign->paymentPlanType = $code->PaymentPlanType; // human readable identifier (not guaranteed unique)
- $campaign->contractLengthInMonths = $code->ContractLengthInMonths;
- $campaign->monthlyAnnuityFactor = $code->MonthlyAnnuityFactor; // pricePerMonth = price * monthlyAnnuityFactor + notificationFee
- $campaign->initialFee = $code->InitialFee;
- $campaign->notificationFee = $code->NotificationFee;
- $campaign->interestRatePercent = $code->InterestRatePercent;
- $campaign->numberOfInterestFreeMonths = $code->NumberOfInterestFreeMonths;
- $campaign->numberOfPaymentFreeMonths = $code->NumberOfPaymentFreeMonths;
- $campaign->fromAmount = $code->FromAmount; // amount lower limit for plan availability
- $campaign->toAmount = $code->ToAmount; // amount upper limit for plan availability
+ // set response attributes
+ if ($this->accepted == 1) {
+ if (is_array($response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo)) {
+ foreach ($response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo as $code) {
+ $campaign = new CampaignCode();
+ $campaign->campaignCode = $code->CampaignCode; // numeric campaign code identifier
+ $campaign->description = $code->Description; // localised description string
+ $campaign->paymentPlanType = $code->PaymentPlanType; // human readable identifier (not guaranteed unique)
+ $campaign->contractLengthInMonths = $code->ContractLengthInMonths;
+ $campaign->monthlyAnnuityFactor = $code->MonthlyAnnuityFactor; // pricePerMonth = price * monthlyAnnuityFactor + notificationFee
+ $campaign->initialFee = $code->InitialFee;
+ $campaign->notificationFee = $code->NotificationFee;
+ $campaign->interestRatePercent = $code->InterestRatePercent;
+ $campaign->numberOfInterestFreeMonths = $code->NumberOfInterestFreeMonths;
+ $campaign->numberOfPaymentFreeMonths = $code->NumberOfPaymentFreeMonths;
+ $campaign->fromAmount = $code->FromAmount; // amount lower limit for plan availability
+ $campaign->toAmount = $code->ToAmount; // amount upper limit for plan availability
- array_push($this->campaignCodes, $campaign); // add to available campaign payment plans array
- }
- } else {
- $campaign = new CampaignCode();
- $campaign->campaignCode = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->CampaignCode; // numeric campaign code identifier
- $campaign->description = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->Description; // localised description string
- $campaign->paymentPlanType = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->PaymentPlanType; // human readable identifier (not guaranteed unique)
- $campaign->contractLengthInMonths = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->ContractLengthInMonths;
- $campaign->monthlyAnnuityFactor = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->MonthlyAnnuityFactor; // pricePerMonth = price * monthlyAnnuityFactor + notificationFee
- $campaign->initialFee = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->InitialFee;
- $campaign->notificationFee = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->NotificationFee;
- $campaign->interestRatePercent = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->InterestRatePercent;
- $campaign->numberOfInterestFreeMonths = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->NumberOfInterestFreeMonths;
- $campaign->numberOfPaymentFreeMonths = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->NumberOfPaymentFreeMonths;
- $campaign->fromAmount = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->FromAmount; // amount lower limit for plan availability
- $campaign->toAmount = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->ToAmount; // amount upper limit for plan availability
+ array_push($this->campaignCodes, $campaign); // add to available campaign payment plans array
+ }
+ } else {
+ $campaign = new CampaignCode();
+ $campaign->campaignCode = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->CampaignCode; // numeric campaign code identifier
+ $campaign->description = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->Description; // localised description string
+ $campaign->paymentPlanType = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->PaymentPlanType; // human readable identifier (not guaranteed unique)
+ $campaign->contractLengthInMonths = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->ContractLengthInMonths;
+ $campaign->monthlyAnnuityFactor = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->MonthlyAnnuityFactor; // pricePerMonth = price * monthlyAnnuityFactor + notificationFee
+ $campaign->initialFee = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->InitialFee;
+ $campaign->notificationFee = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->NotificationFee;
+ $campaign->interestRatePercent = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->InterestRatePercent;
+ $campaign->numberOfInterestFreeMonths = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->NumberOfInterestFreeMonths;
+ $campaign->numberOfPaymentFreeMonths = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->NumberOfPaymentFreeMonths;
+ $campaign->fromAmount = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->FromAmount; // amount lower limit for plan availability
+ $campaign->toAmount = $response->GetPaymentPlanParamsEuResult->CampaignCodes->CampaignCodeInfo->ToAmount; // amount upper limit for plan availability
+
+ array_push($this->campaignCodes, $campaign);
+ }
+ }
+ }
- array_push($this->campaignCodes, $campaign);
- }
- }
- }
-
}
diff --git a/src/WebService/WebServiceResponse/WebServiceResponse.php b/src/WebService/WebServiceResponse/WebServiceResponse.php
index 08bd5b8e..d281fbd8 100644
--- a/src/WebService/WebServiceResponse/WebServiceResponse.php
+++ b/src/WebService/WebServiceResponse/WebServiceResponse.php
@@ -11,23 +11,23 @@
*/
abstract class WebServiceResponse
{
- /**
- * @var bool $accepted true if the request succeeded, else false
- */
- public $accepted;
+ /**
+ * @var bool $accepted true if the request succeeded, else false
+ */
+ public $accepted;
- /**
- * @var string $errormessage set iff the request returned an unsuccessful response, see also the returncode attribute
- */
- public $errormessage;
+ /**
+ * @var string $errormessage set iff the request returned an unsuccessful response, see also the returncode attribute
+ */
+ public $errormessage;
- /**
- * @var int $resultcode response specific result code
- */
- public $resultcode;
+ /**
+ * @var int $resultcode response specific result code
+ */
+ public $resultcode;
- /**
- * @var array $logs Raw HTTP request / response logs
- */
- public $logs;
+ /**
+ * @var array $logs Raw HTTP request / response logs
+ */
+ public $logs;
}
diff --git a/test/IntegrationTest/AdminService/AddOrderRowsRequestIntegrationTest.php b/test/IntegrationTest/AdminService/AddOrderRowsRequestIntegrationTest.php
index df8cb75c..ed6008e9 100644
--- a/test/IntegrationTest/AdminService/AddOrderRowsRequestIntegrationTest.php
+++ b/test/IntegrationTest/AdminService/AddOrderRowsRequestIntegrationTest.php
@@ -19,331 +19,331 @@
class AddOrderRowsRequestIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public $builderObject;
-
- public function setUp()
- {
- $this->builderObject = new OrderBuilder(ConfigurationService::getDefaultConfig());
- $this->builderObject->orderId = 123456;
- $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
- $this->builderObject->countryCode = "SE";
- $this->builderObject->orderRows = array(TestUtil::createOrderRow(10.00));
- }
-
- public function test_add_single_orderRow()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- // add order rows to builderobject
- $this->builderObject->orderRows[] = TestUtil::createOrderRow(1.00, 1);
- $this->builderObject->orderId = $orderResponse->sveaOrderId;
-
- $addOrderRowsRequest = new AddOrderRowsRequest($this->builderObject);
- $addOrderRowsResponse = $addOrderRowsRequest->doRequest();
-
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\AddOrderRowsResponse', $addOrderRowsResponse);
- $this->assertEquals(1, $addOrderRowsResponse->accepted);
-
- }
-
- public function test_add_single_orderRow_with_vat_match()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- // add order rows to builderobject
- $response = WebPayAdmin::addOrderRows($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountExVat(80.00)
- ->setQuantity(1)
- )
- ->addInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- //print_r( "\n\ntest_dd_single_orderRow_with_vat_match: created w/ 145 ex @24% = 179,80 for " .$orderResponse->sveaOrderId );
- //print_r( "\ntest_dd_single_orderRow_with_vat_match: added w/ 80 ex @24% = +99,2" );
- //print_r( "\ntest_dd_single_orderRow_with_vat_match: total amount 179,80 +99,2 = 279,00 for ".$orderResponse->sveaOrderId );
- $this->assertEquals("145.00", $query->numberedOrderRows[0]->amountExVat); // => 179,80
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("80.00", $query->numberedOrderRows[1]->amountExVat); // => 99,20
- $this->assertEquals("24", $query->numberedOrderRows[1]->vatPercent);
- }
-
- public function test_add_single_orderRow_original_exvat_add_incvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- // add order rows to
- $response = WebPayAdmin::addOrderRows($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountIncVat(80.00)
- ->setQuantity(1)
- )
- ->addInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- //print_r( "\n\ntest_add_single_orderRow_with_vat_missmatch1: created w/ 145 ex @24% = 179,80 for " .$orderResponse->sveaOrderId );
- //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: added w/ 80 inc @24% = 80" );
- //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: total amount 179,80 +80 = 259,80 for ".$orderResponse->sveaOrderId );
- $this->assertEquals("145.00", $query->numberedOrderRows[0]->amountExVat); // => 179,80
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("64.52", $query->numberedOrderRows[1]->amountExVat); // 64,5161 *1,24 => 80.00
- $this->assertEquals("24", $query->numberedOrderRows[1]->vatPercent);
- //print_r( $orderResponse->sveaOrderId );
- }
-
- public function test_add_single_orderRow_original_incvat_add_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- // add order rows to builderobject
- $response = WebPayAdmin::addOrderRows($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountExVat(80.00)
- ->setQuantity(1)
- )
- ->addInvoiceOrderRows()
- ->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- //print_r( "\n\ntest_add_single_orderRow_with_vat_missmatch2: created w/ 145 inc @24% = 145,00 for " .$orderResponse->sveaOrderId );
- //print_r( "\ntest_add_single_orderRow_with_vat_missmatch2: added w/ 80 ex @24% = +99,2");
- //print_r( "\ntest_add_single_orderRow_with_vat_missmatch2: total amount 145 +99,2 = 244,2 for ".$orderResponse->sveaOrderId );
- $this->assertEquals("145.00", $query->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("24", $query->numberedOrderRows[1]->vatPercent);
- //print_r( $orderResponse->sveaOrderId );
- }
-
- //--------------------------------------------------------------------------------------------------
-
- public function test_add_single_orderRow_sent_with_ex_vat_may_have_rounding_errors_example()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- // add order rows to
- $response = WebPayAdmin::addOrderRows($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountIncVat(80.00)
- ->setQuantity(1)
- )
- ->addInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $response->accepted);
- // first sent as incvat, will cause error and resend:
- //true
- //80
- // resent as exvat:
- //false
- //64.516129032258
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- //print_r( "\n\ntest_add_single_orderRow_with_vat_missmatch1: created w/ 145 ex @24% = 179,80 for " .$orderResponse->sveaOrderId );
- //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: added w/ 80 inc @24% = 80" );
- //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: total amount 179,80 +80 = 259,80 for ".$orderResponse->sveaOrderId );
- $this->assertEquals("145.00", $query->numberedOrderRows[0]->amountExVat); // => 179,80 inc
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("64.52", $query->numberedOrderRows[1]->amountExVat); // => 80.00 inc
- //print_r( $orderResponse->sveaOrderId );
- }
-
- public function test_add_single_orderRow_sent_with_inc_vat_has_correct_amount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(179.80)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- // add order rows to
- $response = WebPayAdmin::addOrderRows($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountIncVat(80.00)
- ->setQuantity(1)
- )
- ->addInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- //print_r( "\n\ntest_add_single_orderRow_with_vat_missmatch1: created w/ 145 ex @24% = 179,80 for " .$orderResponse->sveaOrderId );
- //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: added w/ 80 inc @24% = 80" );
- //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: total amount 179,80 +80 = 259,80 for ".$orderResponse->sveaOrderId );
- $this->assertEquals("179.80", $query->numberedOrderRows[0]->amountIncVat); // => 179,80
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("80.00", $query->numberedOrderRows[1]->amountIncVat); // => 80.00 // ok, pga incvat in till Svea hela vägen
- $this->assertEquals("24", $query->numberedOrderRows[1]->vatPercent);
- //print_r( $orderResponse->sveaOrderId );
- }
-
-
- public function test_add_multiple_orderRow_type_mismatch_created_inc_updated_ex()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("123.99", $query->numberedOrderRows[0]->amountIncVat); // sent 123.9876 inc => 123.99 queried
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
-
- $response = WebPayAdmin::addOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->addOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addInvoiceOrderRows()->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("123.99", $query2->numberedOrderRows[0]->amountIncVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
- $this->assertEquals("24", $query2->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("123.99", $query2->numberedOrderRows[1]->amountIncVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
- $this->assertEquals("24", $query2->numberedOrderRows[1]->vatPercent);
- }
+ public $builderObject;
+
+ public function setUp()
+ {
+ $this->builderObject = new OrderBuilder(ConfigurationService::getDefaultConfig());
+ $this->builderObject->orderId = 123456;
+ $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
+ $this->builderObject->countryCode = "SE";
+ $this->builderObject->orderRows = [TestUtil::createOrderRow(10.00)];
+ }
+
+ public function test_add_single_orderRow()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(145.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ // add order rows to builderobject
+ $this->builderObject->orderRows[] = TestUtil::createOrderRow(1.00, 1);
+ $this->builderObject->orderId = $orderResponse->sveaOrderId;
+
+ $addOrderRowsRequest = new AddOrderRowsRequest($this->builderObject);
+ $addOrderRowsResponse = $addOrderRowsRequest->doRequest();
+
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\AddOrderRowsResponse', $addOrderRowsResponse);
+ $this->assertEquals(1, $addOrderRowsResponse->accepted);
+
+ }
+
+ public function test_add_single_orderRow_with_vat_match()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(145.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ // add order rows to builderobject
+ $response = WebPayAdmin::addOrderRows($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountExVat(80.00)
+ ->setQuantity(1)
+ )
+ ->addInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ //print_r( "\n\ntest_dd_single_orderRow_with_vat_match: created w/ 145 ex @24% = 179,80 for " .$orderResponse->sveaOrderId );
+ //print_r( "\ntest_dd_single_orderRow_with_vat_match: added w/ 80 ex @24% = +99,2" );
+ //print_r( "\ntest_dd_single_orderRow_with_vat_match: total amount 179,80 +99,2 = 279,00 for ".$orderResponse->sveaOrderId );
+ $this->assertEquals("145.00", $query->numberedOrderRows[0]->amountExVat); // => 179,80
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("80.00", $query->numberedOrderRows[1]->amountExVat); // => 99,20
+ $this->assertEquals("24", $query->numberedOrderRows[1]->vatPercent);
+ }
+
+ public function test_add_single_orderRow_original_exvat_add_incvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(145.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ // add order rows to
+ $response = WebPayAdmin::addOrderRows($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountIncVat(80.00)
+ ->setQuantity(1)
+ )
+ ->addInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ //print_r( "\n\ntest_add_single_orderRow_with_vat_missmatch1: created w/ 145 ex @24% = 179,80 for " .$orderResponse->sveaOrderId );
+ //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: added w/ 80 inc @24% = 80" );
+ //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: total amount 179,80 +80 = 259,80 for ".$orderResponse->sveaOrderId );
+ $this->assertEquals("145.00", $query->numberedOrderRows[0]->amountExVat); // => 179,80
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("64.52", $query->numberedOrderRows[1]->amountExVat); // 64,5161 *1,24 => 80.00
+ $this->assertEquals("24", $query->numberedOrderRows[1]->vatPercent);
+ //print_r( $orderResponse->sveaOrderId );
+ }
+
+ public function test_add_single_orderRow_original_incvat_add_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(145.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ // add order rows to builderobject
+ $response = WebPayAdmin::addOrderRows($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountExVat(80.00)
+ ->setQuantity(1)
+ )
+ ->addInvoiceOrderRows()
+ ->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ //print_r( "\n\ntest_add_single_orderRow_with_vat_missmatch2: created w/ 145 inc @24% = 145,00 for " .$orderResponse->sveaOrderId );
+ //print_r( "\ntest_add_single_orderRow_with_vat_missmatch2: added w/ 80 ex @24% = +99,2");
+ //print_r( "\ntest_add_single_orderRow_with_vat_missmatch2: total amount 145 +99,2 = 244,2 for ".$orderResponse->sveaOrderId );
+ $this->assertEquals("145.00", $query->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("24", $query->numberedOrderRows[1]->vatPercent);
+ //print_r( $orderResponse->sveaOrderId );
+ }
+
+ //--------------------------------------------------------------------------------------------------
+
+ public function test_add_single_orderRow_sent_with_ex_vat_may_have_rounding_errors_example()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(145.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ // add order rows to
+ $response = WebPayAdmin::addOrderRows($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountIncVat(80.00)
+ ->setQuantity(1)
+ )
+ ->addInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+ // first sent as incvat, will cause error and resend:
+ //true
+ //80
+ // resent as exvat:
+ //false
+ //64.516129032258
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ //print_r( "\n\ntest_add_single_orderRow_with_vat_missmatch1: created w/ 145 ex @24% = 179,80 for " .$orderResponse->sveaOrderId );
+ //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: added w/ 80 inc @24% = 80" );
+ //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: total amount 179,80 +80 = 259,80 for ".$orderResponse->sveaOrderId );
+ $this->assertEquals("145.00", $query->numberedOrderRows[0]->amountExVat); // => 179,80 inc
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("64.52", $query->numberedOrderRows[1]->amountExVat); // => 80.00 inc
+ //print_r( $orderResponse->sveaOrderId );
+ }
+
+ public function test_add_single_orderRow_sent_with_inc_vat_has_correct_amount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(179.80)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ // add order rows to
+ $response = WebPayAdmin::addOrderRows($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountIncVat(80.00)
+ ->setQuantity(1)
+ )
+ ->addInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ //print_r( "\n\ntest_add_single_orderRow_with_vat_missmatch1: created w/ 145 ex @24% = 179,80 for " .$orderResponse->sveaOrderId );
+ //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: added w/ 80 inc @24% = 80" );
+ //print_r( "\ntest_add_single_orderRow_with_vat_missmatch1: total amount 179,80 +80 = 259,80 for ".$orderResponse->sveaOrderId );
+ $this->assertEquals("179.80", $query->numberedOrderRows[0]->amountIncVat); // => 179,80
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("80.00", $query->numberedOrderRows[1]->amountIncVat); // => 80.00 // ok, pga incvat in till Svea hela vägen
+ $this->assertEquals("24", $query->numberedOrderRows[1]->vatPercent);
+ //print_r( $orderResponse->sveaOrderId );
+ }
+
+
+ public function test_add_multiple_orderRow_type_mismatch_created_inc_updated_ex()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("123.99", $query->numberedOrderRows[0]->amountIncVat); // sent 123.9876 inc => 123.99 queried
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+
+ $response = WebPayAdmin::addOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->addOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addInvoiceOrderRows()->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("123.99", $query2->numberedOrderRows[0]->amountIncVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
+ $this->assertEquals("24", $query2->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("123.99", $query2->numberedOrderRows[1]->amountIncVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
+ $this->assertEquals("24", $query2->numberedOrderRows[1]->vatPercent);
+ }
}
diff --git a/test/IntegrationTest/AdminService/CancelOrderRequestIntegrationTest.php b/test/IntegrationTest/AdminService/CancelOrderRequestIntegrationTest.php
index 4b820d31..5e8a9a3d 100644
--- a/test/IntegrationTest/AdminService/CancelOrderRequestIntegrationTest.php
+++ b/test/IntegrationTest/AdminService/CancelOrderRequestIntegrationTest.php
@@ -14,35 +14,35 @@
class CancelOrderRequestIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * 1. create an Invoice|PaymentPlan order
- * 2. note the client credentials, order number and type, and insert below
- * 3. run the test
- */
- public function test_manual_CancelOrderRequest()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for test_manual_CancelOrderRequest'
- );
-
- $countryCode = "SE";
- $sveaOrderIdToClose = 349698;
- $orderType = ConfigurationProvider::INVOICE_TYPE;
-
- $cancelOrderBuilder = new CancelOrderBuilder(ConfigurationService::getDefaultConfig());
- $cancelOrderBuilder->setCountryCode($countryCode);
- $cancelOrderBuilder->setOrderId($sveaOrderIdToClose);
- $cancelOrderBuilder->orderType = $orderType;
-
- $request = new CancelOrderRequest($cancelOrderBuilder);
- $response = $request->doRequest();
-
- ////print_r("cancelorderrequest: "); //print_r( $response );
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\CancelOrderResponse', $response);
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(0, $response->resultcode);
-
- }
+ /**
+ * 1. create an Invoice|PaymentPlan order
+ * 2. note the client credentials, order number and type, and insert below
+ * 3. run the test
+ */
+ public function test_manual_CancelOrderRequest()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for test_manual_CancelOrderRequest'
+ );
+
+ $countryCode = "SE";
+ $sveaOrderIdToClose = 349698;
+ $orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ $cancelOrderBuilder = new CancelOrderBuilder(ConfigurationService::getDefaultConfig());
+ $cancelOrderBuilder->setCountryCode($countryCode);
+ $cancelOrderBuilder->setOrderId($sveaOrderIdToClose);
+ $cancelOrderBuilder->orderType = $orderType;
+
+ $request = new CancelOrderRequest($cancelOrderBuilder);
+ $response = $request->doRequest();
+
+ ////print_r("cancelorderrequest: "); //print_r( $response );
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\CancelOrderResponse', $response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(0, $response->resultcode);
+
+ }
}
diff --git a/test/IntegrationTest/AdminService/CancelOrderRowsRequestIntegrationTest.php b/test/IntegrationTest/AdminService/CancelOrderRowsRequestIntegrationTest.php
index 60d3037c..ac223339 100644
--- a/test/IntegrationTest/AdminService/CancelOrderRowsRequestIntegrationTest.php
+++ b/test/IntegrationTest/AdminService/CancelOrderRowsRequestIntegrationTest.php
@@ -15,120 +15,120 @@
class CancelOrderRowsRequestIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public function test_cancel_single_invoice_orderRow_()
- {
-
- // create order
- $country = "SE";
-
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))
- ->addOrderRow(WebPayItem::orderRow()
- ->setDescription("second row")
- ->setQuantity(1)
- ->setAmountExVat(16.00)
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setDescription("third row")
- ->setQuantity(1)
- ->setAmountExVat(24.00)
- ->setVatPercent(25)
- );
-
- $orderResponse = $order->useInvoicePayment()->doRequest();
- //print_r( $orderResponse );
- $this->assertEquals(1, $orderResponse->accepted);
-
- $myOrderId = $orderResponse->sveaOrderId;
-
- // cancel first row in order
- $cancelOrderRowsRequest = WebPayAdmin::cancelOrderRows(ConfigurationService::getDefaultConfig());
- $cancelOrderRowsRequest->setCountryCode($country);
- $cancelOrderRowsRequest->setOrderId($myOrderId);
- $cancelOrderRowsRequest->setRowToCancel(1);
- $cancelOrderRowsResponse = $cancelOrderRowsRequest->cancelInvoiceOrderRows()->doRequest();
-
- ////print_r( $cancelOrderRowsResponse );
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\CancelOrderRowsResponse', $cancelOrderRowsResponse);
- $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
- }
-
- public function test_cancel_single_paymentplan_orderRow_()
- {
-
- // create order
- $country = "SE";
- $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
-
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))
- ->addOrderRow(WebPayItem::orderRow()
- ->setDescription("second row")
- ->setQuantity(1)
- ->setAmountExVat(1600.00)
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setDescription("third row")
- ->setQuantity(1)
- ->setAmountExVat(2400.00)
- ->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(ConfigurationService::getDefaultConfig());
- $cancelOrderRowsRequest->setCountryCode($country);
- $cancelOrderRowsRequest->setOrderId($myOrderId);
- $cancelOrderRowsRequest->setRowToCancel(1);
- $cancelOrderRowsResponse = $cancelOrderRowsRequest->cancelPaymentPlanOrderRows()->doRequest();
-
- ////print_r( $cancelOrderRowsResponse );
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\CancelOrderRowsResponse', $cancelOrderRowsResponse);
- $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
- }
-
- 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.00)
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setDescription("third row")
- ->setQuantity(1)
- ->setAmountExVat(2400.00)
- ->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(ConfigurationService::getDefaultConfig());
- $cancelOrderRowsRequest->setCountryCode($country);
- $cancelOrderRowsRequest->setOrderId($myOrderId);
- $cancelOrderRowsRequest->setRowsToCancel(array(1, 2));
- $cancelOrderRowsResponse = $cancelOrderRowsRequest->cancelPaymentPlanOrderRows()->doRequest();
-
- ////print_r( $cancelOrderRowsResponse );
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\CancelOrderRowsResponse', $cancelOrderRowsResponse);
- $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
- }
+ public function test_cancel_single_invoice_orderRow_()
+ {
+
+ // create order
+ $country = "SE";
+
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setDescription("second row")
+ ->setQuantity(1)
+ ->setAmountExVat(16.00)
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setDescription("third row")
+ ->setQuantity(1)
+ ->setAmountExVat(24.00)
+ ->setVatPercent(25)
+ );
+
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ //print_r( $orderResponse );
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $myOrderId = $orderResponse->sveaOrderId;
+
+ // cancel first row in order
+ $cancelOrderRowsRequest = WebPayAdmin::cancelOrderRows(ConfigurationService::getDefaultConfig());
+ $cancelOrderRowsRequest->setCountryCode($country);
+ $cancelOrderRowsRequest->setOrderId($myOrderId);
+ $cancelOrderRowsRequest->setRowToCancel(1);
+ $cancelOrderRowsResponse = $cancelOrderRowsRequest->cancelInvoiceOrderRows()->doRequest();
+
+ ////print_r( $cancelOrderRowsResponse );
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\CancelOrderRowsResponse', $cancelOrderRowsResponse);
+ $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
+ }
+
+ public function test_cancel_single_paymentplan_orderRow_()
+ {
+
+ // create order
+ $country = "SE";
+ $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
+
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setDescription("second row")
+ ->setQuantity(1)
+ ->setAmountExVat(1600.00)
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setDescription("third row")
+ ->setQuantity(1)
+ ->setAmountExVat(2400.00)
+ ->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(ConfigurationService::getDefaultConfig());
+ $cancelOrderRowsRequest->setCountryCode($country);
+ $cancelOrderRowsRequest->setOrderId($myOrderId);
+ $cancelOrderRowsRequest->setRowToCancel(1);
+ $cancelOrderRowsResponse = $cancelOrderRowsRequest->cancelPaymentPlanOrderRows()->doRequest();
+
+ ////print_r( $cancelOrderRowsResponse );
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\CancelOrderRowsResponse', $cancelOrderRowsResponse);
+ $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
+ }
+
+ 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.00)
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setDescription("third row")
+ ->setQuantity(1)
+ ->setAmountExVat(2400.00)
+ ->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(ConfigurationService::getDefaultConfig());
+ $cancelOrderRowsRequest->setCountryCode($country);
+ $cancelOrderRowsRequest->setOrderId($myOrderId);
+ $cancelOrderRowsRequest->setRowsToCancel([1, 2]);
+ $cancelOrderRowsResponse = $cancelOrderRowsRequest->cancelPaymentPlanOrderRows()->doRequest();
+
+ ////print_r( $cancelOrderRowsResponse );
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\CancelOrderRowsResponse', $cancelOrderRowsResponse);
+ $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
+ }
}
diff --git a/test/IntegrationTest/AdminService/CreditAmountRequestIntegrationTest.php b/test/IntegrationTest/AdminService/CreditAmountRequestIntegrationTest.php
index 16967998..0f5b7e09 100644
--- a/test/IntegrationTest/AdminService/CreditAmountRequestIntegrationTest.php
+++ b/test/IntegrationTest/AdminService/CreditAmountRequestIntegrationTest.php
@@ -1,7 +1,7 @@
setCountryCode('SE')
- ->doRequest();
+ $campaigns = $ppCampaign->setCountryCode('SE')
+ ->doRequest();
- return $campaigns->AccountCreditCampaignCodes[0]->campaignCode;
- }
+ return $campaigns->AccountCreditCampaignCodes[0]->campaignCode;
+ }
- public static function getCustomer()
- {
- return WebPayItem::individualCustomer()
- ->setNationalIdNumber("194605092222")
- ->setBirthDate(1986, 03, 31)
- ->setName("Janko", "Stevanovic")
- ->setStreetAddress("Neka tamo", 1)
- ->setCoAddress("c/o BB, Batajnica")
- ->setLocality("Okrug Beograda")
- ->setEmail('batajarules@svea.com')
- ->setZipCode("99999");
- }
+ public static function getCustomer()
+ {
+ return WebPayItem::individualCustomer()
+ ->setNationalIdNumber("194605092222")
+ ->setBirthDate(1986, 03, 31)
+ ->setName("Janko", "Stevanovic")
+ ->setStreetAddress("Neka tamo", 1)
+ ->setCoAddress("c/o BB, Batajnica")
+ ->setLocality("Okrug Beograda")
+ ->setEmail('batajarules@svea.com')
+ ->setZipCode("99999");
+ }
- /** helper function, returns invoice for delivered order with one row, sent with PriceIncludingVat flag set to true */
- public function get_orderInfo_sent_inc_vat($amount, $vat, $quantity)
- {
- $config = ConfigurationService::getDefaultConfig();
+ /** helper function, returns invoice for delivered order with one row, sent with PriceIncludingVat flag set to true */
+ public function get_orderInfo_sent_inc_vat($amount, $vat, $quantity)
+ {
+ $config = ConfigurationService::getDefaultConfig();
- $campaignCode = self::getAccountCreditParamsForTesting();
+ $campaignCode = self::getAccountCreditParamsForTesting();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat($amount)
- ->setVatPercent($vat)
- ->setQuantity($quantity)
- ->setDescription("IntegrationTest from php-integration")
- )
- ->addCustomerDetails(self::getCustomer())
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat($amount)
+ ->setVatPercent($vat)
+ ->setQuantity($quantity)
+ ->setDescription("IntegrationTest from php-integration")
+ )
+ ->addCustomerDetails(self::getCustomer())
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
- $orderResponse = $orderResponse->useAccountCredit($campaignCode)
- ->doRequest();
-
-
- $this->assertEquals(1, $orderResponse->accepted);
+ $orderResponse = $orderResponse->useAccountCredit($campaignCode)
+ ->doRequest();
+
+
+ $this->assertEquals(1, $orderResponse->accepted);
- $svea_order_id = $orderResponse->sveaOrderId;
-
- $svea_delivery_request = \Svea\WebPay\WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($svea_order_id)
- ->setOrderDate(date('c'))
- ->setCountryCode('SE')
- ->setInvoiceDistributionType(DistributionType::POST)
- ->deliverAccountCreditOrder()
- ->doRequest();
-
-
- $this->assertEquals(1, $svea_delivery_request->accepted);
-
- $response = new stdClass();
- $response->sveaOrderId = $orderResponse->sveaOrderId;
- $response->referenceNumber = $svea_delivery_request->deliveryReferenceNumber;
- return $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)
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $campaignCode = self::getAccountCreditParamsForTesting();
-
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat($amount)
- ->setVatPercent($vat)
- ->setQuantity($quantity)
- ->setDescription("IntegrationTest from php-integration")
- )
- ->addCustomerDetails(self::getCustomer())
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
-
-
- $orderResponse = $orderResponse->useAccountCredit($campaignCode)
- ->doRequest();
-
-
- $this->assertEquals(1, $orderResponse->accepted);
-
- $svea_order_id = $orderResponse->sveaOrderId;
-
- $svea_delivery_request = \Svea\WebPay\WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($svea_order_id)
- ->setOrderDate(date('c'))
- ->setCountryCode('SE')
- ->setInvoiceDistributionType(DistributionType::POST)
- ->deliverAccountCreditOrder()
- ->doRequest();
-
-
- $this->assertEquals(1, $svea_delivery_request->accepted);
-
- $response = new stdClass();
- $response->sveaOrderId = $orderResponse->sveaOrderId;
- $response->referenceNumber = $svea_delivery_request->deliveryReferenceNumber;
- return $response;
- }
-
-
- public function test_creditAmount_creditPaymentPlan_on_order_ex_vat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_ex_vat(999.99, 24, 1);
- $credit = WebPayAdmin::creditAmount($config)
- ->setOrderId($orderInfo->referenceNumber)
- ->setCountryCode('SE')
- ->setDescription('credit desc')
- ->setAmountIncVat(100)
- ->creditAccountCredit()->doRequest();
+ $svea_order_id = $orderResponse->sveaOrderId;
+
+ $svea_delivery_request = \Svea\WebPay\WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($svea_order_id)
+ ->setOrderDate(date('c'))
+ ->setCountryCode('SE')
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->deliverAccountCreditOrder()
+ ->doRequest();
+
+
+ $this->assertEquals(1, $svea_delivery_request->accepted);
+
+ $response = new stdClass();
+ $response->sveaOrderId = $orderResponse->sveaOrderId;
+ $response->referenceNumber = $svea_delivery_request->deliveryReferenceNumber;
+ return $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)
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $campaignCode = self::getAccountCreditParamsForTesting();
+
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat($amount)
+ ->setVatPercent($vat)
+ ->setQuantity($quantity)
+ ->setDescription("IntegrationTest from php-integration")
+ )
+ ->addCustomerDetails(self::getCustomer())
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
+
+
+ $orderResponse = $orderResponse->useAccountCredit($campaignCode)
+ ->doRequest();
+
+
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $svea_order_id = $orderResponse->sveaOrderId;
+
+ $svea_delivery_request = \Svea\WebPay\WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($svea_order_id)
+ ->setOrderDate(date('c'))
+ ->setCountryCode('SE')
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->deliverAccountCreditOrder()
+ ->doRequest();
+
+
+ $this->assertEquals(1, $svea_delivery_request->accepted);
+
+ $response = new stdClass();
+ $response->sveaOrderId = $orderResponse->sveaOrderId;
+ $response->referenceNumber = $svea_delivery_request->deliveryReferenceNumber;
+ return $response;
+ }
+
+
+ public function test_creditAmount_creditPaymentPlan_on_order_ex_vat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_ex_vat(999.99, 24, 1);
+ $credit = WebPayAdmin::creditAmount($config)
+ ->setOrderId($orderInfo->referenceNumber)
+ ->setCountryCode('SE')
+ ->setDescription('credit desc')
+ ->setAmountIncVat(100)
+ ->creditAccountCredit()->doRequest();
- $this->assertEquals(1, $credit->accepted);
- //print_r($credit);
- }
+ $this->assertEquals(1, $credit->accepted);
+ //print_r($credit);
+ }
- public function test_creditAmount_creditPaymentPlan_on_order_inc_vat()
- {
- $config = ConfigurationService::getDefaultConfig();
+ public function test_creditAmount_creditPaymentPlan_on_order_inc_vat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
- $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.00, 25, 1);
- $credit = WebPayAdmin::creditAmount($config)
- ->setOrderId($orderInfo->referenceNumber)
- ->setCountryCode('SE')
- ->setDescription('credit desc')
- ->setAmountIncVat(100.00)
- ->creditAccountCredit()->doRequest();
+ $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.00, 25, 1);
+ $credit = WebPayAdmin::creditAmount($config)
+ ->setOrderId($orderInfo->referenceNumber)
+ ->setCountryCode('SE')
+ ->setDescription('credit desc')
+ ->setAmountIncVat(100.00)
+ ->creditAccountCredit()->doRequest();
- $this->assertEquals(1, $credit->accepted);
- }
+ $this->assertEquals(1, $credit->accepted);
+ }
- public function test_creditAmount_creditPaymentPlan_amount_exceeds_orderamount()
- {
- $config = ConfigurationService::getDefaultConfig();
+ public function test_creditAmount_creditPaymentPlan_amount_exceeds_orderamount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
- $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.00, 25, 1);
- $credit = WebPayAdmin::creditAmount($config)
- ->setOrderId($orderInfo->referenceNumber)
- ->setCountryCode('SE')
- ->setDescription('credit desc')
- ->setAmountIncVat(1500.00)
- ->creditAccountCredit()->doRequest();
+ $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.00, 25, 1);
+ $credit = WebPayAdmin::creditAmount($config)
+ ->setOrderId($orderInfo->referenceNumber)
+ ->setCountryCode('SE')
+ ->setDescription('credit desc')
+ ->setAmountIncVat(1500.00)
+ ->creditAccountCredit()->doRequest();
- $this->assertEquals(0, $credit->accepted);
- }
+ $this->assertEquals(0, $credit->accepted);
+ }
}
\ No newline at end of file
diff --git a/test/IntegrationTest/AdminService/CreditOrderRowsRequestIntegrationTest.php b/test/IntegrationTest/AdminService/CreditOrderRowsRequestIntegrationTest.php
index dee3d93e..8bfa64c2 100644
--- a/test/IntegrationTest/AdminService/CreditOrderRowsRequestIntegrationTest.php
+++ b/test/IntegrationTest/AdminService/CreditOrderRowsRequestIntegrationTest.php
@@ -20,565 +20,565 @@
class CreditOrderRowsRequestIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /** helper function, returns invoice for delivered order with one row, sent with PriceIncludingVat flag set to true */
- public function get_orderInfo_sent_inc_vat($amount, $vat, $quantity, $is_paymentplan = NULL)
- {
- $config = ConfigurationService::getDefaultConfig();
- if ($is_paymentplan)
- $campaignCode = TestUtil::getGetPaymentPlanParamsForTesting();
-
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat($amount)
- ->setVatPercent($vat)
- ->setQuantity($quantity)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
- if ($is_paymentplan) {
- $orderResponse = $orderResponse->usePaymentPlanPayment($campaignCode)
- ->doRequest();
- } else {
- $orderResponse = $orderResponse
- ->useInvoicePayment()->doRequest();
- }
- $this->assertEquals(1, $orderResponse->accepted);
- if ($is_paymentplan) {
- $deliver = WebPay::deliverOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->deliverPaymentPlanOrder()->doRequest();
- } else {
- $deliver = WebPayAdmin::deliverOrderRows($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setRowToDeliver(1)
- ->deliverInvoiceOrderRows()->doRequest();
- }
- $this->assertEquals(1, $deliver->accepted);
-
- $orderInfo = $is_paymentplan ? new OrderToCredit($orderResponse->sveaOrderId, NULL, $deliver->contractNumber) : new orderToCredit($orderResponse->sveaOrderId, $deliver->invoiceId);
-
- return $orderInfo;
- }
-
- /** 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 = ConfigurationService::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();
- } else {
- $orderResponse = $orderResponse
- ->useInvoicePayment()->doRequest();
- }
- $this->assertEquals(1, $orderResponse->accepted);
-
- if ($is_paymentplan) {
- $deliver = WebPay::deliverOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->deliverPaymentPlanOrder()->doRequest();
- } else {
- $deliver = WebPayAdmin::deliverOrderRows($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setRowToDeliver(1)
- ->deliverInvoiceOrderRows()->doRequest();
- }
- $this->assertEquals(1, $deliver->accepted);
- $orderInfo = $is_paymentplan ? new OrderToCredit($orderResponse->sveaOrderId, NULL, $deliver->contractNumber) : new OrderToCredit($orderResponse->sveaOrderId, $deliver->invoiceId);
-
- return $orderInfo;
- }
-
-
- public function test_creditOrderRows_creditInvoiceOrderRows_credit_row_using_row_index()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_ex_vat(99.99, 24, 1);
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setInvoiceId($orderInfo->invoiceId)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->setRowToCredit(1)
- ->creditInvoiceOrderRows()->doRequest();
-
- $this->assertEquals(1, $credit->accepted);
- //print_r($credit);
- }
-
- public function test_creditOrderRows_creditPaymentPlanOrderRows_credit_row_using_row_index()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_ex_vat(999.99, 24, 1, TRUE);
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setContractNumber($orderInfo->contractNumber)
- ->setCountryCode('SE')
- ->setRowToCredit(1)
- ->creditPaymentPlanOrderRows()->doRequest();
- $this->assertEquals(1, $credit->accepted);
- //print_r($credit);
- }
-
- public function test_creditOrderRows_creditInvoiceOrderRows_credit_row_using_new_order_row_original_exvat_new_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_ex_vat(99.99, 24, 1);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderInfo->orderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("99.99", $query->numberedOrderRows[0]->amountExVat);
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
-
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setInvoiceId($orderInfo->invoiceId)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)// => 123.9876 inc
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->creditInvoiceOrderRows()->doRequest();
- //print_r($credit);
- $this->assertEquals(1, $credit->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderInfo->orderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- // NOTE the order row status/amount does not reflect that the corresponding invoice row has been credited
- // TODO implement queryInvoice and recurse invoices to get the current order row status
- $this->assertEquals("99.99", $query->numberedOrderRows[0]->amountExVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- }
-
- public function test_creditOrderRows_creditInvoiceOrderRows_credit_row_using_original_exvat_new_order_incvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_ex_vat(99.99, 24, 1);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderInfo->orderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("99.99", $query->numberedOrderRows[0]->amountExVat);
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
-
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setInvoiceId($orderInfo->invoiceId)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->setRowToCredit(1)
- ->creditInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $credit->accepted);
- //print_r($credit);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderInfo->orderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("99.99", $query->numberedOrderRows[0]->amountExVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- }
-
- /// characterizing unit tests for INTG-551
- function test_creditOrderRows_handles_creditOrderRows_specified_using_exvat_and_vatpercent()
- {
- // needs either setRow(s)ToCredit or addCreditOrderRow(s)
- $creditOrder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setInvoiceId("123456789")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode("SE")
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- );
- $request = $creditOrder->creditInvoiceOrderRows()->prepareRequest();
-
- $this->assertEquals("10", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertEquals("25", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->VatPercent->enc_value);
- $this->assertEquals(null, $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- }
-
- function test_creditOrderRows_handles_creditOrderRows_specified_using_incvat_and_vatpercent()
- {
- // needs either setRow(s)ToCredit or addCreditOrderRow(s)
- $creditOrder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setInvoiceId("123456789")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode("SE")
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- );
- $request = $creditOrder->creditInvoiceOrderRows()->prepareRequest();
-
- $this->assertEquals("10", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertEquals("25", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->VatPercent->enc_value);
- $this->assertEquals(true, $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- }
-
- function test_creditOrderRows_handles_creditOrderRows_specified_using_incvat_and_exvat()
- {
- // needs either setRow(s)ToCredit or addCreditOrderRow(s)
- $creditOrder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setInvoiceId("123456789")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode("SE")
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(12.50)
- ->setAmountExVat(10.00)
- ->setQuantity(1)
- );
- $request = $creditOrder->creditInvoiceOrderRows()->prepareRequest();
-
- $this->assertEquals("12.50", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertEquals("25", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->VatPercent->enc_value);
- $this->assertEquals(true, $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- }
-
- // INTG-551 integration tests
- public function test_credit_row_sent_exandvat_credit_sent_incandex()
- { // credit req. should be resent, see backoffice logs
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_ex_vat(100.00, 25, 2);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderInfo->orderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("100.00", $query->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(null, $query->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals("25", $query->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("2.00", $query->numberedOrderRows[0]->quantity);
-
- $creditOrder = WebPayAdmin::creditOrderRows($config)
- ->setInvoiceId($orderInfo->invoiceId)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode("SE")
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(20.00)
- ->setAmountExVat(16.00)
- ->setQuantity(1)
- );
- $request = $creditOrder->creditInvoiceOrderRows()->prepareRequest();
-
- $this->assertEquals("20", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertEquals("25", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->VatPercent->enc_value);
- $this->assertEquals(true, $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
-
- $response = $creditOrder->creditInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- // query order and assert row totals
- $query2 = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderInfo->orderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query2->accepted);
-
- // NOTE the order row status/amount does not reflect that the corresponding invoice row has been credited
- // TODO implement queryInvoice and recurse invoices to get the current order row status
- $this->assertEquals("100.00", $query2->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(null, $query2->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals("25", $query2->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("2.00", $query2->numberedOrderRows[0]->quantity);
- // nope, can't be seen in the order, only in backoffice in delivered invoice as cumulative discount amount
- // $this->assertEquals("-10.00", $query->numberedOrderRows[1]->amountExVat);
- // $this->assertEquals("25", $query->numberedOrderRows[1]->vatPercent);
- }
-
- public function test_credit_row_sent_inc_credit_sent_incandex()
- { // credit req. should not be resent, see backoffice logs
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_inc_vat(125.00, 25, 2);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderInfo->orderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals(null, $query->numberedOrderRows[0]->amountExVat);
- $this->assertEquals("125.00", $query->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals("25", $query->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("2.00", $query->numberedOrderRows[0]->quantity);
-
- $creditOrder = WebPayAdmin::creditOrderRows($config)
- ->setInvoiceId($orderInfo->invoiceId)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode("SE")
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(20.00)
- ->setAmountExVat(16.00)
- ->setQuantity(1)
- );
- $request = $creditOrder->creditInvoiceOrderRows()->prepareRequest();
- $this->assertEquals("20", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertEquals("25", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->VatPercent->enc_value);
- $this->assertEquals(true, $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
-
- $response = $creditOrder->creditInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- // query order and assert row totals
- $query2 = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderInfo->orderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query2->accepted);
-
- // NOTE the order row status/amount does not reflect that the corresponding invoice row has been credited
- // TODO implement queryInvoice and recurse invoices to get the current order row status
- $this->assertEquals(null, $query2->numberedOrderRows[0]->amountExVat);
- $this->assertEquals("125.00", $query2->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals("25", $query2->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("2.00", $query2->numberedOrderRows[0]->quantity);
- // nope, can't be seen in the order, only in backoffice in delivered invoice as cumulative discount amount
- // $this->assertEquals("-20.00", $query->numberedOrderRows[1]->amountExVat);
- // $this->assertEquals("25", $query->numberedOrderRows[1]->vatPercent);
- }
-
- /// characterising integration test for INTG-576
- public function test_creditOrderRows_creditInvoiceOrderRows_original_exvat_new_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_ex_vat(100.00, 25, 1);
-
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setInvoiceId($orderInfo->invoiceId)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->creditInvoiceOrderRows()->doRequest();
- // logs should createOrderEU (w/priceIncludingVat = false) => deliverOrderRows
- // => creditOrderRows (w/priceIncludingVat = false) success
- $this->assertEquals(1, $credit->accepted);
- }
-
- public function test_creditOrderRows_creditInvoiceOrderRows_original_exvat_new_incvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_ex_vat(100.00, 25, 1);
-
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setInvoiceId($orderInfo->invoiceId)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(12.50)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->creditInvoiceOrderRows()->doRequest();
- // logs should createOrderEU (w/priceIncludingVat = false) => deliverOrderRows
- // => creditOrderRows (w/priceIncludingVat = false) fail => creditOrderRows (w/priceIncludingVat = true) success
- $this->assertEquals(1, $credit->accepted);
- }
-
- public function test_creditOrderRows_creditInvoiceOrderRows_original_incvat_new_incvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_inc_vat(100.00, 25, 1);
-
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setInvoiceId($orderInfo->invoiceId)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(10)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->creditInvoiceOrderRows()->doRequest();
- // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows
- // => creditOrderRows (w/priceIncludingVat = true) success
- $this->assertEquals(1, $credit->accepted);
- }
-
- public function test_creditOrderRows_creditPaymentPlanOrderRows_original_incvat_new_incvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.00, 25, 1, TRUE);
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setContractNumber($orderInfo->contractNumber)
- ->setCountryCode('SE')
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(10)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("row")
- )
- ->creditPaymentplanOrderRows()->doRequest();
-
- // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows
- // => creditOrderRows (w/priceIncludingVat = true) success
- $this->assertEquals(1, $credit->accepted);
- }
-
- public function test_creditOrderRows_creditInvoiceOrderRows_original_incvat_new_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_inc_vat(100.00, 25, 1);
-
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setInvoiceId($orderInfo->invoiceId)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(8)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->creditInvoiceOrderRows()->doRequest();
- // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows
- // => creditOrderRows (w/priceIncludingVat = false) fail => creditOrderRows (w/priceIncludingVat = true) success
- $this->assertEquals(1, $credit->accepted);
-
- }
-
- public function test_creditOrderRows_creditPyamentplanOrderRows_original_incvat_new_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.00, 25, 1, TRUE);
- //ContractNumber
-// //ClientId
-// //CancellationRows
-// // AmountInclVat *
-// // VatPercent *
-// // Description *
-// // RowNumber (int)
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setContractNumber($orderInfo->contractNumber)
- ->setCountryCode('SE')
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(8)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("row")
- )
- ->creditPaymentplanOrderRows()->doRequest();
- // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows
- // => creditOrderRows (w/priceIncludingVat = false) fail => creditOrderRows (w/priceIncludingVat = true) success
- $this->assertEquals(1, $credit->accepted);
-
- }
-
- public function test_creditOrderRows_creditInvoiceOrderRows_multipleRows()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_inc_vat(100.00, 25, 1);
-
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("row 1");
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("row 2");
-
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setInvoiceId($orderInfo->invoiceId)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->addCreditOrderRows($orderRows)
- ->creditInvoiceOrderRows()->doRequest();
-
- $this->assertEquals(1, $credit->accepted);
-
- }
-
- public function test_creditOrderRows_creditPyamentplanOrderRows_multipleRows()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.00, 25, 1, TRUE);
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("row 1");
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("row 2");
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setContractNumber($orderInfo->contractNumber)
- ->setCountryCode('SE')
- ->addCreditOrderRows($orderRows)
- ->creditPaymentplanOrderRows()->doRequest();
- // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows
- // => creditOrderRows (w/priceIncludingVat = false) fail => creditOrderRows (w/priceIncludingVat = true) success
- $this->assertEquals(1, $credit->accepted);
-
- }
+ /** helper function, returns invoice for delivered order with one row, sent with PriceIncludingVat flag set to true */
+ public function get_orderInfo_sent_inc_vat($amount, $vat, $quantity, $is_paymentplan = NULL)
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ if ($is_paymentplan)
+ $campaignCode = TestUtil::getGetPaymentPlanParamsForTesting();
+
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat($amount)
+ ->setVatPercent($vat)
+ ->setQuantity($quantity)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
+ if ($is_paymentplan) {
+ $orderResponse = $orderResponse->usePaymentPlanPayment($campaignCode)
+ ->doRequest();
+ } else {
+ $orderResponse = $orderResponse
+ ->useInvoicePayment()->doRequest();
+ }
+ $this->assertEquals(1, $orderResponse->accepted);
+ if ($is_paymentplan) {
+ $deliver = WebPay::deliverOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->deliverPaymentPlanOrder()->doRequest();
+ } else {
+ $deliver = WebPayAdmin::deliverOrderRows($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setRowToDeliver(1)
+ ->deliverInvoiceOrderRows()->doRequest();
+ }
+ $this->assertEquals(1, $deliver->accepted);
+
+ $orderInfo = $is_paymentplan ? new OrderToCredit($orderResponse->sveaOrderId, NULL, $deliver->contractNumber) : new orderToCredit($orderResponse->sveaOrderId, $deliver->invoiceId);
+
+ return $orderInfo;
+ }
+
+ /** 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 = ConfigurationService::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();
+ } else {
+ $orderResponse = $orderResponse
+ ->useInvoicePayment()->doRequest();
+ }
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ if ($is_paymentplan) {
+ $deliver = WebPay::deliverOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->deliverPaymentPlanOrder()->doRequest();
+ } else {
+ $deliver = WebPayAdmin::deliverOrderRows($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setRowToDeliver(1)
+ ->deliverInvoiceOrderRows()->doRequest();
+ }
+ $this->assertEquals(1, $deliver->accepted);
+ $orderInfo = $is_paymentplan ? new OrderToCredit($orderResponse->sveaOrderId, NULL, $deliver->contractNumber) : new OrderToCredit($orderResponse->sveaOrderId, $deliver->invoiceId);
+
+ return $orderInfo;
+ }
+
+
+ public function test_creditOrderRows_creditInvoiceOrderRows_credit_row_using_row_index()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_ex_vat(99.99, 24, 1);
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setInvoiceId($orderInfo->invoiceId)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->setRowToCredit(1)
+ ->creditInvoiceOrderRows()->doRequest();
+
+ $this->assertEquals(1, $credit->accepted);
+ //print_r($credit);
+ }
+
+ public function test_creditOrderRows_creditPaymentPlanOrderRows_credit_row_using_row_index()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_ex_vat(999.99, 24, 1, TRUE);
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setContractNumber($orderInfo->contractNumber)
+ ->setCountryCode('SE')
+ ->setRowToCredit(1)
+ ->creditPaymentPlanOrderRows()->doRequest();
+ $this->assertEquals(1, $credit->accepted);
+ //print_r($credit);
+ }
+
+ public function test_creditOrderRows_creditInvoiceOrderRows_credit_row_using_new_order_row_original_exvat_new_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_ex_vat(99.99, 24, 1);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderInfo->orderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("99.99", $query->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setInvoiceId($orderInfo->invoiceId)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)// => 123.9876 inc
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->creditInvoiceOrderRows()->doRequest();
+ //print_r($credit);
+ $this->assertEquals(1, $credit->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderInfo->orderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ // NOTE the order row status/amount does not reflect that the corresponding invoice row has been credited
+ // TODO implement queryInvoice and recurse invoices to get the current order row status
+ $this->assertEquals("99.99", $query->numberedOrderRows[0]->amountExVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ }
+
+ public function test_creditOrderRows_creditInvoiceOrderRows_credit_row_using_original_exvat_new_order_incvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_ex_vat(99.99, 24, 1);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderInfo->orderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("99.99", $query->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setInvoiceId($orderInfo->invoiceId)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->setRowToCredit(1)
+ ->creditInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $credit->accepted);
+ //print_r($credit);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderInfo->orderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("99.99", $query->numberedOrderRows[0]->amountExVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ }
+
+ /// characterizing unit tests for INTG-551
+ function test_creditOrderRows_handles_creditOrderRows_specified_using_exvat_and_vatpercent()
+ {
+ // needs either setRow(s)ToCredit or addCreditOrderRow(s)
+ $creditOrder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setInvoiceId("123456789")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode("SE")
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ );
+ $request = $creditOrder->creditInvoiceOrderRows()->prepareRequest();
+
+ $this->assertEquals("10", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertEquals("25", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->VatPercent->enc_value);
+ $this->assertEquals(null, $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ }
+
+ function test_creditOrderRows_handles_creditOrderRows_specified_using_incvat_and_vatpercent()
+ {
+ // needs either setRow(s)ToCredit or addCreditOrderRow(s)
+ $creditOrder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setInvoiceId("123456789")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode("SE")
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ );
+ $request = $creditOrder->creditInvoiceOrderRows()->prepareRequest();
+
+ $this->assertEquals("10", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertEquals("25", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->VatPercent->enc_value);
+ $this->assertEquals(true, $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ }
+
+ function test_creditOrderRows_handles_creditOrderRows_specified_using_incvat_and_exvat()
+ {
+ // needs either setRow(s)ToCredit or addCreditOrderRow(s)
+ $creditOrder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setInvoiceId("123456789")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode("SE")
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(12.50)
+ ->setAmountExVat(10.00)
+ ->setQuantity(1)
+ );
+ $request = $creditOrder->creditInvoiceOrderRows()->prepareRequest();
+
+ $this->assertEquals("12.50", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertEquals("25", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->VatPercent->enc_value);
+ $this->assertEquals(true, $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ }
+
+ // INTG-551 integration tests
+ public function test_credit_row_sent_exandvat_credit_sent_incandex()
+ { // credit req. should be resent, see backoffice logs
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_ex_vat(100.00, 25, 2);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderInfo->orderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("100.00", $query->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(null, $query->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals("25", $query->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("2.00", $query->numberedOrderRows[0]->quantity);
+
+ $creditOrder = WebPayAdmin::creditOrderRows($config)
+ ->setInvoiceId($orderInfo->invoiceId)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode("SE")
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(20.00)
+ ->setAmountExVat(16.00)
+ ->setQuantity(1)
+ );
+ $request = $creditOrder->creditInvoiceOrderRows()->prepareRequest();
+
+ $this->assertEquals("20", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertEquals("25", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->VatPercent->enc_value);
+ $this->assertEquals(true, $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+
+ $response = $creditOrder->creditInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ // query order and assert row totals
+ $query2 = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderInfo->orderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query2->accepted);
+
+ // NOTE the order row status/amount does not reflect that the corresponding invoice row has been credited
+ // TODO implement queryInvoice and recurse invoices to get the current order row status
+ $this->assertEquals("100.00", $query2->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(null, $query2->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals("25", $query2->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("2.00", $query2->numberedOrderRows[0]->quantity);
+ // nope, can't be seen in the order, only in backoffice in delivered invoice as cumulative discount amount
+ // $this->assertEquals("-10.00", $query->numberedOrderRows[1]->amountExVat);
+ // $this->assertEquals("25", $query->numberedOrderRows[1]->vatPercent);
+ }
+
+ public function test_credit_row_sent_inc_credit_sent_incandex()
+ { // credit req. should not be resent, see backoffice logs
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_inc_vat(125.00, 25, 2);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderInfo->orderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals(null, $query->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals("125.00", $query->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals("25", $query->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("2.00", $query->numberedOrderRows[0]->quantity);
+
+ $creditOrder = WebPayAdmin::creditOrderRows($config)
+ ->setInvoiceId($orderInfo->invoiceId)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode("SE")
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(20.00)
+ ->setAmountExVat(16.00)
+ ->setQuantity(1)
+ );
+ $request = $creditOrder->creditInvoiceOrderRows()->prepareRequest();
+ $this->assertEquals("20", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertEquals("25", $request->NewCreditInvoiceRows->enc_value[0]->enc_value->VatPercent->enc_value);
+ $this->assertEquals(true, $request->NewCreditInvoiceRows->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+
+ $response = $creditOrder->creditInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ // query order and assert row totals
+ $query2 = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderInfo->orderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query2->accepted);
+
+ // NOTE the order row status/amount does not reflect that the corresponding invoice row has been credited
+ // TODO implement queryInvoice and recurse invoices to get the current order row status
+ $this->assertEquals(null, $query2->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals("125.00", $query2->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals("25", $query2->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("2.00", $query2->numberedOrderRows[0]->quantity);
+ // nope, can't be seen in the order, only in backoffice in delivered invoice as cumulative discount amount
+ // $this->assertEquals("-20.00", $query->numberedOrderRows[1]->amountExVat);
+ // $this->assertEquals("25", $query->numberedOrderRows[1]->vatPercent);
+ }
+
+ /// characterising integration test for INTG-576
+ public function test_creditOrderRows_creditInvoiceOrderRows_original_exvat_new_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_ex_vat(100.00, 25, 1);
+
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setInvoiceId($orderInfo->invoiceId)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->creditInvoiceOrderRows()->doRequest();
+ // logs should createOrderEU (w/priceIncludingVat = false) => deliverOrderRows
+ // => creditOrderRows (w/priceIncludingVat = false) success
+ $this->assertEquals(1, $credit->accepted);
+ }
+
+ public function test_creditOrderRows_creditInvoiceOrderRows_original_exvat_new_incvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_ex_vat(100.00, 25, 1);
+
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setInvoiceId($orderInfo->invoiceId)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(12.50)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->creditInvoiceOrderRows()->doRequest();
+ // logs should createOrderEU (w/priceIncludingVat = false) => deliverOrderRows
+ // => creditOrderRows (w/priceIncludingVat = false) fail => creditOrderRows (w/priceIncludingVat = true) success
+ $this->assertEquals(1, $credit->accepted);
+ }
+
+ public function test_creditOrderRows_creditInvoiceOrderRows_original_incvat_new_incvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_inc_vat(100.00, 25, 1);
+
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setInvoiceId($orderInfo->invoiceId)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(10)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->creditInvoiceOrderRows()->doRequest();
+ // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows
+ // => creditOrderRows (w/priceIncludingVat = true) success
+ $this->assertEquals(1, $credit->accepted);
+ }
+
+ public function test_creditOrderRows_creditPaymentPlanOrderRows_original_incvat_new_incvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.00, 25, 1, TRUE);
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setContractNumber($orderInfo->contractNumber)
+ ->setCountryCode('SE')
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(10)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("row")
+ )
+ ->creditPaymentplanOrderRows()->doRequest();
+
+ // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows
+ // => creditOrderRows (w/priceIncludingVat = true) success
+ $this->assertEquals(1, $credit->accepted);
+ }
+
+ public function test_creditOrderRows_creditInvoiceOrderRows_original_incvat_new_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_inc_vat(100.00, 25, 1);
+
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setInvoiceId($orderInfo->invoiceId)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(8)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->creditInvoiceOrderRows()->doRequest();
+ // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows
+ // => creditOrderRows (w/priceIncludingVat = false) fail => creditOrderRows (w/priceIncludingVat = true) success
+ $this->assertEquals(1, $credit->accepted);
+
+ }
+
+ public function test_creditOrderRows_creditPyamentplanOrderRows_original_incvat_new_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.00, 25, 1, TRUE);
+ //ContractNumber
+// //ClientId
+// //CancellationRows
+// // AmountInclVat *
+// // VatPercent *
+// // Description *
+// // RowNumber (int)
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setContractNumber($orderInfo->contractNumber)
+ ->setCountryCode('SE')
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(8)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("row")
+ )
+ ->creditPaymentplanOrderRows()->doRequest();
+ // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows
+ // => creditOrderRows (w/priceIncludingVat = false) fail => creditOrderRows (w/priceIncludingVat = true) success
+ $this->assertEquals(1, $credit->accepted);
+
+ }
+
+ public function test_creditOrderRows_creditInvoiceOrderRows_multipleRows()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_inc_vat(100.00, 25, 1);
+
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("row 1");
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("row 2");
+
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setInvoiceId($orderInfo->invoiceId)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->addCreditOrderRows($orderRows)
+ ->creditInvoiceOrderRows()->doRequest();
+
+ $this->assertEquals(1, $credit->accepted);
+
+ }
+
+ public function test_creditOrderRows_creditPyamentplanOrderRows_multipleRows()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderInfo = $this->get_orderInfo_sent_inc_vat(1000.00, 25, 1, TRUE);
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("row 1");
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("row 2");
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setContractNumber($orderInfo->contractNumber)
+ ->setCountryCode('SE')
+ ->addCreditOrderRows($orderRows)
+ ->creditPaymentplanOrderRows()->doRequest();
+ // logs should createOrderEU (w/priceIncludingVat = true) => deliverOrderRows
+ // => creditOrderRows (w/priceIncludingVat = false) fail => creditOrderRows (w/priceIncludingVat = true) success
+ $this->assertEquals(1, $credit->accepted);
+
+ }
}
\ No newline at end of file
diff --git a/test/IntegrationTest/AdminService/DeliverOrderRowsRequestIntegrationTest.php b/test/IntegrationTest/AdminService/DeliverOrderRowsRequestIntegrationTest.php
index c318b202..5075dd2d 100644
--- a/test/IntegrationTest/AdminService/DeliverOrderRowsRequestIntegrationTest.php
+++ b/test/IntegrationTest/AdminService/DeliverOrderRowsRequestIntegrationTest.php
@@ -17,325 +17,325 @@
class DeliverOrderRowsRequestIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public function test_deliver_single_invoice_orderRow_returns_accepted_with_invoiceId()
- {
-
- // create order
- $country = "SE";
-
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))
- ->addOrderRow(WebPayItem::orderRow()
- ->setDescription("second row")
- ->setQuantity(1)
- ->setAmountExVat(16.00)
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setDescription("third row")
- ->setQuantity(1)
- ->setAmountExVat(24.00)
- ->setVatPercent(25)
- );
-
- $orderResponse = $order->useInvoicePayment()->doRequest();
- ////print_r( $orderResponse );
-
- $myOrderId = $orderResponse->sveaOrderId;
-
- // deliver first row in order
- $deliverOrderRowsRequest = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig());
- $deliverOrderRowsRequest->setCountryCode($country);
- $deliverOrderRowsRequest->setOrderId($myOrderId);
- $deliverOrderRowsRequest->setInvoiceDistributionType(DistributionType::POST);
- $deliverOrderRowsRequest->setRowToDeliver(1);
- $deliverOrderRowsResponse = $deliverOrderRowsRequest->deliverInvoiceOrderRows()->doRequest();
-
- // Example DeliverPartial raw request response to parse:
- //
- //stdClass Object
- //(
- // [ErrorMessage] =>
- // [ResultCode] => 0
- // [OrdersDelivered] => stdClass Object
- // (
- // [DeliverOrderResult] => stdClass Object
- // (
- // [ClientId] => 79021
- // [DeliveredAmount] => 250.00
- // [DeliveryReferenceNumber] => 1033899
- // [OrderType] => Invoice
- // [SveaOrderId] => 414180
- // )
- //
- // )
- //
- //)
-
- ////print_r( $deliverOrderRowsResponse );
- //
- // Example DeliverPartialResponse
- //
- //Svea\WebPay\AdminService\AdminServiceResponse\DeliverPartialResponse Object
- //(
- // [clientId] => 79021
- // [amount] => 250.00
- // [invoiceId] => 1033902
- // [contractNumber] =>
- // [orderType] => Invoice
- // [orderId] => 414183
- // [accepted] => 1
- // [resultcode] => 0
- // [errormessage] =>
- //)
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\AdminServiceResponse\DeliverPartialResponse", $deliverOrderRowsResponse);
- $this->assertEquals(1, $deliverOrderRowsResponse->accepted);
- $this->assertEquals(0, $deliverOrderRowsResponse->resultcode);
- $this->assertEquals(null, $deliverOrderRowsResponse->errormessage);
-
- $this->assertEquals(79021, $deliverOrderRowsResponse->clientId);
- $this->assertEquals(250.00, $deliverOrderRowsResponse->amount);
- $this->assertStringMatchesFormat("%d", $deliverOrderRowsResponse->invoiceId); // %d => an unsigned integer value
- $this->assertEquals(null, $deliverOrderRowsResponse->contractNumber);
- $this->assertEquals("Invoice", $deliverOrderRowsResponse->orderType);
- $this->assertStringMatchesFormat("%d", $deliverOrderRowsResponse->orderId); // %d => an unsigned integer value
- }
-
- 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.00)
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setDescription("third row")
- ->setQuantity(1)
- ->setAmountExVat(24.00)
- ->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(ConfigurationService::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\WebPay\AdminService\AdminServiceResponse\DeliverPartialResponse', $deliverOrderRowsResponse);
- $this->assertEquals(true, $deliverOrderRowsResponse->accepted); // truth
- $this->assertEquals(1, $deliverOrderRowsResponse->accepted); // equals literal 1
- $this->assertEquals(0, $deliverOrderRowsResponse->resultcode);
- $this->assertEquals(270.00, $deliverOrderRowsResponse->amount);
- $this->assertEquals("Invoice", $deliverOrderRowsResponse->orderType);
- $this->assertNotNull($deliverOrderRowsResponse->invoiceId);
- }
-
- public function test_manual_deliver_single_card_orderRow_of_authorized_order_performs_loweramount_and_sets_status_confirmed()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'test_manual_query_card_queryTransaction_returntype'
- );
-
- // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 2. go to verktyg -> betalning
- // 3. enter our test merchantid: 1130
- // 4. use the following xml, making sure to update to a unique customerrefno:
- //KORTCERT EUR 600 120 test_14105300920232 https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml A 100 20 rowA 1 665 st |
B 200 40 rowB 1 666 st |
C 300 60 rowA 1 667 st |
- // 5. the result should be:
- //
- //
- // KORTCERT
- // 1130
- // test_1410530092038
- // 600
- // EUR
- // VISA
- // 444433xxxxxx1100
- // 01
- // 15
- // 763907
- //
- // 0
- //
- // 6. enter the received transaction id below and run the test
-
- // Set the below to match the transaction, then run the test.
- $transactionId = 586223;
-
- $queryRequest = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
- $queryResponse = $queryRequest->setCountryCode("SE")->setTransactionId($transactionId)->queryCardOrder()->doRequest();
-
- ////print_r( $queryResponse );
- $this->assertEquals(1, $queryResponse->accepted);
- $this->assertEquals("AUTHORIZED", $queryResponse->status);
- $this->assertEquals(600, $queryResponse->amount);
- $this->assertEquals(600, $queryResponse->authorizedamount); // not manipulated post creation
- $this->assertEquals(0, $queryResponse->creditedamount); // not manipulated post creation
-
- $deliverRequest = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig());
- $deliverRequest->setCountryCode("SE")->setOrderId($transactionId);
- $deliverRequest->setRowToDeliver(1)->addNumberedOrderRows($queryResponse->numberedOrderRows);
- $deliverResponse = $deliverRequest->deliverCardOrderRows()->doRequest();
-
- //print_r( $deliverResponse );
- $this->assertEquals(1, $deliverResponse->accepted);
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $deliverResponse);
-
- // query orderrows
- $queryResponse2 = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($transactionId)->setCountryCode("SE")->queryCardOrder()->doRequest();
-
- //print_r( $queryResponse2);
- $this->assertEquals(1, $queryResponse2->accepted);
- $this->assertEquals("CONFIRMED", $queryResponse2->status);
- $this->assertEquals(100, $queryResponse2->authorizedamount);
-
- }
-
- public function test_manual_deliver_single_card_orderRow_of_manipulated_order_returns_error()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'test_manual_deliver_single_card_orderRow_of_manipulated_order_returns_error'
- );
-
- // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 2. go to verktyg -> betalning
- // 3. enter our test merchantid: 1130
- // 4. use the following xml, making sure to update to a unique customerrefno:
- //KORTCERT EUR 600 120 test_14105300920232 https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml A 100 20 rowA 1 665 st |
B 200 40 rowB 1 666 st |
C 300 60 rowA 1 667 st |
- // 5. the result should be:
- //
- //
- // KORTCERT
- // 1130
- // test_1410530092038
- // 600
- // EUR
- // VISA
- // 444433xxxxxx1100
- // 01
- // 15
- // 763907
- //
- // 0
- //
- // 6. enter the received transaction id below and run the test
-
- // Set the below to match the transaction, then run the test.
- $transactionId = 586256;
-
- $queryRequest = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
- $queryResponse = $queryRequest->setCountryCode("SE")->setTransactionId($transactionId)->queryCardOrder()->doRequest();
-
- ////print_r( $queryResponse );
- $this->assertEquals(1, $queryResponse->accepted);
-
- $deliverRequest = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig());
- $deliverRequest->setCountryCode("SE")->setOrderId($transactionId);
- $deliverRequest->setRowToDeliver(1)->addNumberedOrderRows($queryResponse->numberedOrderRows);
- $deliverResponse = $deliverRequest->deliverCardOrderRows()->doRequest();
-
- ////print_r( $deliverResponse );
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $deliverResponse);
- $this->assertEquals(1, $deliverResponse->accepted);
-
- // again (i.e. lower too large an amount)
- $deliver2Request = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig());
- $deliver2Request->setCountryCode("SE")->setOrderId($transactionId);
- $deliver2Request->setRowToDeliver(1)->addNumberedOrderRows($queryResponse->numberedOrderRows);
- $deliver2Response = $deliver2Request->deliverCardOrderRows()->doRequest();
-
- ////print_r( $deliver2Response );
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $deliver2Response);
- $this->assertEquals(0, $deliver2Response->accepted);
- $this->assertEquals("100", $deliver2Response->resultcode);
- $this->assertEquals(
- "IntegrationPackage: LowerAmount request with flag alsoDoConfirm failed:305 (BAD_AMOUNT) Invalid value for amount.",
- $deliver2Response->errormessage
- );
-
- }
-
- public function test_manual_deliver_single_card_orderRow_of_confirmed_order_performs_loweramount_and_returns_ConfirmTransactionError()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'test_manual_deliver_single_card_orderRow_of_confirmed_order_performs_loweramount_and_returns_ConfirmTransactionError'
- );
-
- // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 2. go to verktyg -> betalning
- // 3. enter our test merchantid: 1130
- // 4. use the following xml, making sure to update to a unique customerrefno:
- //KORTCERT EUR 600 120 test_14105300920232 https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml A 100 20 rowA 1 665 st |
B 200 40 rowB 1 666 st |
C 300 60 rowA 1 667 st |
- // 5. the result should be:
- //
- //
- // KORTCERT
- // 1130
- // test_1410530092038
- // 600
- // EUR
- // VISA
- // 444433xxxxxx1100
- // 01
- // 15
- // 763907
- //
- // 0
- //
- // 6. enter the received transaction id below and run the test
-
- // Set the below to match the transaction, then run the test.
- $transactionId = 586263;
-
- // confirm the transaction
- $confirmRequest = new ConfirmTransaction(ConfigurationService::getDefaultConfig());
- $confirmRequest->transactionId = $transactionId;
- $confirmRequest->captureDate = date('c');
- $confirmRequest->countryCode = "SE";
- $confirmResponse = $confirmRequest->doRequest();
-
- ////print_r( $confirmResponse );
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $confirmResponse);
- $this->assertEquals(1, $confirmResponse->accepted);
-
- $queryRequest = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
- $queryResponse = $queryRequest->setCountryCode("SE")->setTransactionId($transactionId)->queryCardOrder()->doRequest();
-
- //print_r( $queryResponse );
- $this->assertEquals(1, $queryResponse->accepted);
- $this->assertEquals("CONFIRMED", $queryResponse->status);
-
- $deliverRequest = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig());
- $deliverRequest->setCountryCode("SE")->setOrderId($transactionId);
- $deliverRequest->setRowToDeliver(1)->addNumberedOrderRows($queryResponse->numberedOrderRows);
- $deliverResponse = $deliverRequest->deliverCardOrderRows()->doRequest();
-
- //print_r( $deliverResponse );
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $deliverResponse);
- $this->assertEquals(0, $deliverResponse->accepted);
- $this->assertEquals("105 (ILLEGAL_TRANSACTIONSTATUS)", $deliverResponse->resultcode); // confirm of confirmed order
- $this->assertEquals("Invalid transaction status.", $deliverResponse->errormessage);
- }
+ public function test_deliver_single_invoice_orderRow_returns_accepted_with_invoiceId()
+ {
+
+ // create order
+ $country = "SE";
+
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setDescription("second row")
+ ->setQuantity(1)
+ ->setAmountExVat(16.00)
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setDescription("third row")
+ ->setQuantity(1)
+ ->setAmountExVat(24.00)
+ ->setVatPercent(25)
+ );
+
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ ////print_r( $orderResponse );
+
+ $myOrderId = $orderResponse->sveaOrderId;
+
+ // deliver first row in order
+ $deliverOrderRowsRequest = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig());
+ $deliverOrderRowsRequest->setCountryCode($country);
+ $deliverOrderRowsRequest->setOrderId($myOrderId);
+ $deliverOrderRowsRequest->setInvoiceDistributionType(DistributionType::POST);
+ $deliverOrderRowsRequest->setRowToDeliver(1);
+ $deliverOrderRowsResponse = $deliverOrderRowsRequest->deliverInvoiceOrderRows()->doRequest();
+
+ // Example DeliverPartial raw request response to parse:
+ //
+ //stdClass Object
+ //(
+ // [ErrorMessage] =>
+ // [ResultCode] => 0
+ // [OrdersDelivered] => stdClass Object
+ // (
+ // [DeliverOrderResult] => stdClass Object
+ // (
+ // [ClientId] => 79021
+ // [DeliveredAmount] => 250.00
+ // [DeliveryReferenceNumber] => 1033899
+ // [OrderType] => Invoice
+ // [SveaOrderId] => 414180
+ // )
+ //
+ // )
+ //
+ //)
+
+ ////print_r( $deliverOrderRowsResponse );
+ //
+ // Example DeliverPartialResponse
+ //
+ //Svea\WebPay\AdminService\AdminServiceResponse\DeliverPartialResponse Object
+ //(
+ // [clientId] => 79021
+ // [amount] => 250.00
+ // [invoiceId] => 1033902
+ // [contractNumber] =>
+ // [orderType] => Invoice
+ // [orderId] => 414183
+ // [accepted] => 1
+ // [resultcode] => 0
+ // [errormessage] =>
+ //)
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\AdminServiceResponse\DeliverPartialResponse", $deliverOrderRowsResponse);
+ $this->assertEquals(1, $deliverOrderRowsResponse->accepted);
+ $this->assertEquals(0, $deliverOrderRowsResponse->resultcode);
+ $this->assertEquals(null, $deliverOrderRowsResponse->errormessage);
+
+ $this->assertEquals(79021, $deliverOrderRowsResponse->clientId);
+ $this->assertEquals(250.00, $deliverOrderRowsResponse->amount);
+ $this->assertStringMatchesFormat("%d", $deliverOrderRowsResponse->invoiceId); // %d => an unsigned integer value
+ $this->assertEquals(null, $deliverOrderRowsResponse->contractNumber);
+ $this->assertEquals("Invoice", $deliverOrderRowsResponse->orderType);
+ $this->assertStringMatchesFormat("%d", $deliverOrderRowsResponse->orderId); // %d => an unsigned integer value
+ }
+
+ 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.00)
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setDescription("third row")
+ ->setQuantity(1)
+ ->setAmountExVat(24.00)
+ ->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(ConfigurationService::getDefaultConfig());
+ $deliverOrderRowsRequest->setCountryCode($country);
+ $deliverOrderRowsRequest->setOrderId($myOrderId);
+ $deliverOrderRowsRequest->setInvoiceDistributionType(DistributionType::POST);
+ $deliverOrderRowsRequest->setRowsToDeliver([1, 2]);
+ $deliverOrderRowsResponse = $deliverOrderRowsRequest->deliverInvoiceOrderRows()->doRequest();
+
+ ////print_r( $deliverOrderRowsResponse );
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\DeliverPartialResponse', $deliverOrderRowsResponse);
+ $this->assertEquals(true, $deliverOrderRowsResponse->accepted); // truth
+ $this->assertEquals(1, $deliverOrderRowsResponse->accepted); // equals literal 1
+ $this->assertEquals(0, $deliverOrderRowsResponse->resultcode);
+ $this->assertEquals(270.00, $deliverOrderRowsResponse->amount);
+ $this->assertEquals("Invoice", $deliverOrderRowsResponse->orderType);
+ $this->assertNotNull($deliverOrderRowsResponse->invoiceId);
+ }
+
+ public function test_manual_deliver_single_card_orderRow_of_authorized_order_performs_loweramount_and_sets_status_confirmed()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'test_manual_query_card_queryTransaction_returntype'
+ );
+
+ // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 2. go to verktyg -> betalning
+ // 3. enter our test merchantid: 1130
+ // 4. use the following xml, making sure to update to a unique customerrefno:
+ //KORTCERT EUR 600 120 test_14105300920232 https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml A 100 20 rowA 1 665 st |
B 200 40 rowB 1 666 st |
C 300 60 rowA 1 667 st |
+ // 5. the result should be:
+ //
+ //
+ // KORTCERT
+ // 1130
+ // test_1410530092038
+ // 600
+ // EUR
+ // VISA
+ // 444433xxxxxx1100
+ // 01
+ // 15
+ // 763907
+ //
+ // 0
+ //
+ // 6. enter the received transaction id below and run the test
+
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 586223;
+
+ $queryRequest = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
+ $queryResponse = $queryRequest->setCountryCode("SE")->setTransactionId($transactionId)->queryCardOrder()->doRequest();
+
+ ////print_r( $queryResponse );
+ $this->assertEquals(1, $queryResponse->accepted);
+ $this->assertEquals("AUTHORIZED", $queryResponse->status);
+ $this->assertEquals(600, $queryResponse->amount);
+ $this->assertEquals(600, $queryResponse->authorizedamount); // not manipulated post creation
+ $this->assertEquals(0, $queryResponse->creditedamount); // not manipulated post creation
+
+ $deliverRequest = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig());
+ $deliverRequest->setCountryCode("SE")->setOrderId($transactionId);
+ $deliverRequest->setRowToDeliver(1)->addNumberedOrderRows($queryResponse->numberedOrderRows);
+ $deliverResponse = $deliverRequest->deliverCardOrderRows()->doRequest();
+
+ //print_r( $deliverResponse );
+ $this->assertEquals(1, $deliverResponse->accepted);
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $deliverResponse);
+
+ // query orderrows
+ $queryResponse2 = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($transactionId)->setCountryCode("SE")->queryCardOrder()->doRequest();
+
+ //print_r( $queryResponse2);
+ $this->assertEquals(1, $queryResponse2->accepted);
+ $this->assertEquals("CONFIRMED", $queryResponse2->status);
+ $this->assertEquals(100, $queryResponse2->authorizedamount);
+
+ }
+
+ public function test_manual_deliver_single_card_orderRow_of_manipulated_order_returns_error()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'test_manual_deliver_single_card_orderRow_of_manipulated_order_returns_error'
+ );
+
+ // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 2. go to verktyg -> betalning
+ // 3. enter our test merchantid: 1130
+ // 4. use the following xml, making sure to update to a unique customerrefno:
+ //KORTCERT EUR 600 120 test_14105300920232 https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml A 100 20 rowA 1 665 st |
B 200 40 rowB 1 666 st |
C 300 60 rowA 1 667 st |
+ // 5. the result should be:
+ //
+ //
+ // KORTCERT
+ // 1130
+ // test_1410530092038
+ // 600
+ // EUR
+ // VISA
+ // 444433xxxxxx1100
+ // 01
+ // 15
+ // 763907
+ //
+ // 0
+ //
+ // 6. enter the received transaction id below and run the test
+
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 586256;
+
+ $queryRequest = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
+ $queryResponse = $queryRequest->setCountryCode("SE")->setTransactionId($transactionId)->queryCardOrder()->doRequest();
+
+ ////print_r( $queryResponse );
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ $deliverRequest = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig());
+ $deliverRequest->setCountryCode("SE")->setOrderId($transactionId);
+ $deliverRequest->setRowToDeliver(1)->addNumberedOrderRows($queryResponse->numberedOrderRows);
+ $deliverResponse = $deliverRequest->deliverCardOrderRows()->doRequest();
+
+ ////print_r( $deliverResponse );
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $deliverResponse);
+ $this->assertEquals(1, $deliverResponse->accepted);
+
+ // again (i.e. lower too large an amount)
+ $deliver2Request = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig());
+ $deliver2Request->setCountryCode("SE")->setOrderId($transactionId);
+ $deliver2Request->setRowToDeliver(1)->addNumberedOrderRows($queryResponse->numberedOrderRows);
+ $deliver2Response = $deliver2Request->deliverCardOrderRows()->doRequest();
+
+ ////print_r( $deliver2Response );
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $deliver2Response);
+ $this->assertEquals(0, $deliver2Response->accepted);
+ $this->assertEquals("100", $deliver2Response->resultcode);
+ $this->assertEquals(
+ "IntegrationPackage: LowerAmount request with flag alsoDoConfirm failed:305 (BAD_AMOUNT) Invalid value for amount.",
+ $deliver2Response->errormessage
+ );
+
+ }
+
+ public function test_manual_deliver_single_card_orderRow_of_confirmed_order_performs_loweramount_and_returns_ConfirmTransactionError()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'test_manual_deliver_single_card_orderRow_of_confirmed_order_performs_loweramount_and_returns_ConfirmTransactionError'
+ );
+
+ // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 2. go to verktyg -> betalning
+ // 3. enter our test merchantid: 1130
+ // 4. use the following xml, making sure to update to a unique customerrefno:
+ //KORTCERT EUR 600 120 test_14105300920232 https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml A 100 20 rowA 1 665 st |
B 200 40 rowB 1 666 st |
C 300 60 rowA 1 667 st |
+ // 5. the result should be:
+ //
+ //
+ // KORTCERT
+ // 1130
+ // test_1410530092038
+ // 600
+ // EUR
+ // VISA
+ // 444433xxxxxx1100
+ // 01
+ // 15
+ // 763907
+ //
+ // 0
+ //
+ // 6. enter the received transaction id below and run the test
+
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 586263;
+
+ // confirm the transaction
+ $confirmRequest = new ConfirmTransaction(ConfigurationService::getDefaultConfig());
+ $confirmRequest->transactionId = $transactionId;
+ $confirmRequest->captureDate = date('c');
+ $confirmRequest->countryCode = "SE";
+ $confirmResponse = $confirmRequest->doRequest();
+
+ ////print_r( $confirmResponse );
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $confirmResponse);
+ $this->assertEquals(1, $confirmResponse->accepted);
+
+ $queryRequest = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
+ $queryResponse = $queryRequest->setCountryCode("SE")->setTransactionId($transactionId)->queryCardOrder()->doRequest();
+
+ //print_r( $queryResponse );
+ $this->assertEquals(1, $queryResponse->accepted);
+ $this->assertEquals("CONFIRMED", $queryResponse->status);
+
+ $deliverRequest = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig());
+ $deliverRequest->setCountryCode("SE")->setOrderId($transactionId);
+ $deliverRequest->setRowToDeliver(1)->addNumberedOrderRows($queryResponse->numberedOrderRows);
+ $deliverResponse = $deliverRequest->deliverCardOrderRows()->doRequest();
+
+ //print_r( $deliverResponse );
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $deliverResponse);
+ $this->assertEquals(0, $deliverResponse->accepted);
+ $this->assertEquals("105 (ILLEGAL_TRANSACTIONSTATUS)", $deliverResponse->resultcode); // confirm of confirmed order
+ $this->assertEquals("Invalid transaction status.", $deliverResponse->errormessage);
+ }
}
diff --git a/test/IntegrationTest/AdminService/DeliverOrdersRequestIntegrationTest.php b/test/IntegrationTest/AdminService/DeliverOrdersRequestIntegrationTest.php
index 6cca5446..f0fb70b6 100644
--- a/test/IntegrationTest/AdminService/DeliverOrdersRequestIntegrationTest.php
+++ b/test/IntegrationTest/AdminService/DeliverOrdersRequestIntegrationTest.php
@@ -17,72 +17,72 @@
class DeliverOrdersRequestIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * 1. create an Invoice|PaymentPlan order
- * 2. note the client credentials, order number and type, and insert below
- * 3. run the test
- */
- public function test_manual_DeliverOrdersRequest_on_closed_order_returns_resultcode_20000()
- {
-
- // Stop here and mark this test as incomplete.
-// $this->markTestIncomplete(
-// 'skeleton for test_manual_DeliverOrdersRequest'
-// );
-
- $countryCode = "SE";
- $sveaOrderIdToDeliver = 349699; // need to exist, be closed
- $orderType = ConfigurationProvider::INVOICE_TYPE;
-
- $DeliverOrderBuilder = new DeliverOrderBuilder(ConfigurationService::getDefaultConfig());
- $DeliverOrderBuilder->setCountryCode($countryCode);
- $DeliverOrderBuilder->setOrderId($sveaOrderIdToDeliver);
- $DeliverOrderBuilder->setInvoiceDistributionType(DistributionType::POST);
- $DeliverOrderBuilder->orderType = $orderType;
-
- $request = new DeliverOrdersRequest($DeliverOrderBuilder);
- $response = $request->doRequest();
-
- ////print_r( $response );
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse', $response);
- $this->assertEquals(0, $response->accepted); //
- $this->assertEquals(20000, $response->resultcode); // 20000, order is closed.
- }
-
- // create order and make sure you can deliver partial rows
- public function test_DeliverOrdersRequest_on_open_order_returns_accepted_true()
- {
-
- // create order
- $country = "SE";
-
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country));
-
- $orderResponse = $order->useInvoicePayment()->doRequest();
- ////print_r( $orderResponse );
- $this->assertEquals(1, $orderResponse->accepted);
-
- $myOrderId = $orderResponse->sveaOrderId;
-
- // deliver order
- $DeliverOrderBuilder = new DeliverOrderBuilder(ConfigurationService::getDefaultConfig());
- $DeliverOrderBuilder->setCountryCode($country);
- $DeliverOrderBuilder->setOrderId($myOrderId);
- $DeliverOrderBuilder->setInvoiceDistributionType(DistributionType::POST);
- $DeliverOrderBuilder->orderType = ConfigurationProvider::INVOICE_TYPE;
-
-
- $request = new DeliverOrdersRequest($DeliverOrderBuilder);
- $response = $request->doRequest();
-
- ////print_r( $response );
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse', $response);
- $this->assertEquals(true, $response->accepted); // truth
- $this->assertEquals(1, $response->accepted); // equals literal 1
- $this->assertEquals(0, $response->resultcode);
- $this->assertEquals(250.00, $response->amount);
- $this->assertEquals("Invoice", $response->orderType);
- $this->assertNotNull($response->invoiceId);
- $this->assertNull($response->contractNumber);
- }
+ /**
+ * 1. create an Invoice|PaymentPlan order
+ * 2. note the client credentials, order number and type, and insert below
+ * 3. run the test
+ */
+ public function test_manual_DeliverOrdersRequest_on_closed_order_returns_resultcode_20000()
+ {
+
+ // Stop here and mark this test as incomplete.
+// $this->markTestIncomplete(
+// 'skeleton for test_manual_DeliverOrdersRequest'
+// );
+
+ $countryCode = "SE";
+ $sveaOrderIdToDeliver = 349699; // need to exist, be closed
+ $orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ $DeliverOrderBuilder = new DeliverOrderBuilder(ConfigurationService::getDefaultConfig());
+ $DeliverOrderBuilder->setCountryCode($countryCode);
+ $DeliverOrderBuilder->setOrderId($sveaOrderIdToDeliver);
+ $DeliverOrderBuilder->setInvoiceDistributionType(DistributionType::POST);
+ $DeliverOrderBuilder->orderType = $orderType;
+
+ $request = new DeliverOrdersRequest($DeliverOrderBuilder);
+ $response = $request->doRequest();
+
+ ////print_r( $response );
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse', $response);
+ $this->assertEquals(0, $response->accepted); //
+ $this->assertEquals(20000, $response->resultcode); // 20000, order is closed.
+ }
+
+ // create order and make sure you can deliver partial rows
+ public function test_DeliverOrdersRequest_on_open_order_returns_accepted_true()
+ {
+
+ // create order
+ $country = "SE";
+
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country));
+
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ ////print_r( $orderResponse );
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $myOrderId = $orderResponse->sveaOrderId;
+
+ // deliver order
+ $DeliverOrderBuilder = new DeliverOrderBuilder(ConfigurationService::getDefaultConfig());
+ $DeliverOrderBuilder->setCountryCode($country);
+ $DeliverOrderBuilder->setOrderId($myOrderId);
+ $DeliverOrderBuilder->setInvoiceDistributionType(DistributionType::POST);
+ $DeliverOrderBuilder->orderType = ConfigurationProvider::INVOICE_TYPE;
+
+
+ $request = new DeliverOrdersRequest($DeliverOrderBuilder);
+ $response = $request->doRequest();
+
+ ////print_r( $response );
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse', $response);
+ $this->assertEquals(true, $response->accepted); // truth
+ $this->assertEquals(1, $response->accepted); // equals literal 1
+ $this->assertEquals(0, $response->resultcode);
+ $this->assertEquals(250.00, $response->amount);
+ $this->assertEquals("Invoice", $response->orderType);
+ $this->assertNotNull($response->invoiceId);
+ $this->assertNull($response->contractNumber);
+ }
}
diff --git a/test/IntegrationTest/AdminService/GetOrdersRequestIntegrationTest.php b/test/IntegrationTest/AdminService/GetOrdersRequestIntegrationTest.php
index c8880c8b..2ee9865b 100644
--- a/test/IntegrationTest/AdminService/GetOrdersRequestIntegrationTest.php
+++ b/test/IntegrationTest/AdminService/GetOrdersRequestIntegrationTest.php
@@ -19,617 +19,617 @@
class GetOrdersRequestIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * 1. create an Invoice|PaymentPlan order
- * 2. note the client credentials, order number and type, and insert below
- * 3. run the test
- */
- public function test_manual_GetOrdersRequest_for_invoice_individual_customer_order()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete( // 150626 -- removed due to corrupt customerids w/no ssn in test database (known error)
- 'skeleton for test_manual_GetOrdersRequest_for_invoice_individual_customer_order'
- );
-
- $countryCode = "SE";
- $sveaOrderIdToGet = 348629;
- $orderType = ConfigurationProvider::INVOICE_TYPE;
-
- $getOrdersBuilder = new QueryOrderBuilder(ConfigurationService::getDefaultConfig());
- $getOrdersBuilder->setOrderId($sveaOrderIdToGet);
- $getOrdersBuilder->setCountryCode($countryCode);
- $getOrdersBuilder->orderType = $orderType;
-
- // Example of test_manual_GetOrdersRequest_for_invoice_individual_customer_order 348629 raw request response to parse:
- // stdClass Object
- // (
- // [ErrorMessage] =>
- // [ResultCode] => 0
- // [Orders] => stdClass Object
- // (
- // [Order] => stdClass Object
- // (
- // [ChangedDate] =>
- // [ClientId] => 79021
- // [ClientOrderId] => 449
- // [CreatedDate] => 2014-05-19T16:04:54.787
- // [CreditReportStatus] => stdClass Object
- // (
- // [Accepted] => true
- // [CreationDate] => 2014-05-19T16:04:54.893
- // )
- //
- // [Currency] => SEK
- // [Customer] => stdClass Object
- // (
- // [CoAddress] => c/o Eriksson, Erik
- // [CompanyIdentity] =>
- // [CountryCode] => SE
- // [CustomerType] => Individual
- // [Email] => test@svea.com
- // [FullName] => Persson, Tess T
- // [HouseNumber] =>
- // [IndividualIdentity] => stdClass Object
- // (
- // [BirthDate] =>
- // [FirstName] =>
- // [Initials] =>
- // [LastName] =>
- // )
- //
- // [Locality] => Stan
- // [NationalIdNumber] => 194605092222
- // [PhoneNumber] => 999999
- // [PublicKey] =>
- // [Street] => Testgatan 1
- // [ZipCode] => 99999
- // )
- //
- // [CustomerId] => 1000117
- // [CustomerReference] =>
- // [DeliveryAddress] =>
- // [IsPossibleToAdminister] => false
- // [IsPossibleToCancel] => true
- // [Notes] =>
- // [OrderDeliveryStatus] => Created
- // [OrderRows] => stdClass Object
- // (
- // [NumberedOrderRow] => Array
- // (
- // [0] => stdClass Object
- // (
- // [ArticleNumber] =>
- // [Description] => Dyr produkt 25%
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 2.00
- // [PricePerUnit] => 2000.00
- // [Unit] =>
- // [VatPercent] => 25.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 1
- // [Status] => NotDelivered
- // )
- //
- // [1] => stdClass Object
- // (
- // [ArticleNumber] =>
- // [Description] => Testprodukt 1kr 25%
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 1.00
- // [PricePerUnit] => 1.00
- // [Unit] =>
- // [VatPercent] => 25.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 2
- // [Status] => NotDelivered
- // )
- //
- // [2] => stdClass Object
- // (
- // [ArticleNumber] =>
- // [Description] => Fastpris (Fast fraktpris)
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 1.00
- // [PricePerUnit] => 4.00
- // [Unit] =>
- // [VatPercent] => 25.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 3
- // [Status] => NotDelivered
- // )
- //
- // [3] => stdClass Object
- // (
- // [ArticleNumber] =>
- // [Description] => Svea Fakturaavgift:: 20.00kr (SE)
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 1.00
- // [PricePerUnit] => 20.00
- // [Unit] =>
- // [VatPercent] => 0.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 4
- // [Status] => NotDelivered
- // )
- //
- // )
- //
- // )
- //
- // [OrderStatus] => Active
- // [OrderType] => Invoice
- // [PaymentPlanDetails] =>
- // [PendingReasons] =>
- // [SveaOrderId] => 348629
- // [SveaWillBuy] => true
- // )
- //
- // )
- //
- // )
-
- $request = new GetOrdersRequest($getOrdersBuilder);
- $getOrdersResponse = $request->doRequest();
-
-// print_r( $getOrdersResponse );
-
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\GetOrdersResponse', $getOrdersResponse);
- $this->assertEquals(1, $getOrdersResponse->accepted);
- $this->assertEquals(0, $getOrdersResponse->resultcode);
- $this->assertEquals(null, $getOrdersResponse->errormessage);
-
- $this->assertEquals(null, $getOrdersResponse->changedDate); // TODO add test for changed order later
- $this->assertEquals(79021, $getOrdersResponse->clientId);
- $this->assertEquals(449, $getOrdersResponse->clientOrderId);
- $this->assertEquals("2014-05-19T16:04:54.787", $getOrdersResponse->createdDate);
-
- $this->assertEquals(true, $getOrdersResponse->creditReportStatusAccepted);
- $this->assertEquals("2014-05-19T16:04:54.893", $getOrdersResponse->creditReportStatusCreationDate);
-
- $this->assertEquals("SEK", $getOrdersResponse->currency);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer", $getOrdersResponse->customer);
- $this->assertEquals("194605092222", $getOrdersResponse->customer->ssn);
- $this->assertEquals(null, $getOrdersResponse->customer->initials);
- $this->assertEquals(null, $getOrdersResponse->customer->birthDate);
- $this->assertEquals(null, $getOrdersResponse->customer->firstname);
- $this->assertEquals(null, $getOrdersResponse->customer->lastname);
- //$this->assertEquals( "test@svea.com", $getOrdersResponse->customer->email ); // -- returns current customer stats, may change
- //$this->assertEquals( null, $getOrdersResponse->customer->phonenumber ); // -- returns current customer stats, may change
- $this->assertEquals("Persson, Tess T", $getOrdersResponse->customer->name); // FullName
- $this->assertEquals("Testgatan 1", $getOrdersResponse->customer->streetAddress);
- $this->assertEquals("Testgatan 1", $getOrdersResponse->customer->street);
- $this->assertEquals("c/o Eriksson, Erik", $getOrdersResponse->customer->coAddress);
- $this->assertEquals("99999", $getOrdersResponse->customer->zipCode);
- $this->assertEquals("Stan", $getOrdersResponse->customer->locality);
-
- $this->assertEquals("1000117", $getOrdersResponse->customerId);
- $this->assertEquals(null, $getOrdersResponse->customerReference);
- $this->assertClassNotHasAttribute("deliveryAddress", "\Svea\AdminService\GetOrdersResponse"); // deliveryAddress field is not supported
- $this->assertEquals(false, $getOrdersResponse->isPossibleToAdminister);
- $this->assertEquals(true, $getOrdersResponse->isPossibleToCancel);
- $this->assertEquals(null, $getOrdersResponse->notes);
- $this->assertEquals("Created", $getOrdersResponse->orderDeliveryStatus);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $getOrdersResponse->numberedOrderRows[0]);
- $this->assertEquals(1, $getOrdersResponse->numberedOrderRows[0]->rowNumber);
- $this->assertEquals(null, $getOrdersResponse->numberedOrderRows[0]->articleNumber);
- $this->assertEquals(2.00, $getOrdersResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals(null, $getOrdersResponse->numberedOrderRows[0]->unit);
- $this->assertEquals(2000.00, $getOrdersResponse->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(25.00, $getOrdersResponse->numberedOrderRows[0]->vatPercent);
- $this->assertEquals(null, $getOrdersResponse->numberedOrderRows[0]->name);
- $this->assertEquals("Dyr produkt 25%", $getOrdersResponse->numberedOrderRows[0]->description);
- $this->assertEquals(0, $getOrdersResponse->numberedOrderRows[0]->vatDiscount);
-
- // only check attributes of first row
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $getOrdersResponse->numberedOrderRows[3]);
- $this->assertEquals(4, $getOrdersResponse->numberedOrderRows[3]->rowNumber);
-
- $this->assertEquals("Active", $getOrdersResponse->orderStatus);
- $this->assertEquals("Invoice", $getOrdersResponse->orderType);
- $this->assertEquals(null, $getOrdersResponse->paymentPlanDetailsContractLengthMonths);
- $this->assertEquals(null, $getOrdersResponse->paymentPlanDetailsContractNumber);
- $this->assertEquals(null, $getOrdersResponse->pendingReasons);
- $this->assertEquals(348629, $getOrdersResponse->orderId);
- $this->assertEquals(true, $getOrdersResponse->sveaWillBuy);
- }
-
- public function test_GetOrdersRequest_for_invoice_sets_individual_customer_correctly()
- {
- // create order
- $country = "SE";
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country));
- //case( "SE" ):
- // return Svea\WebPay\WebPayItem::individualCustomer()
- // ->setNationalIdNumber("194605092222")
- // ->setBirthDate(1946, 05, 09)
- // ->setName("Tess T", "Persson")
- // ->setStreetAddress("Testgatan", 1)
- // ->setCoAddress("c/o Eriksson, Erik")
- // ->setLocality("Stan")
- // ->setZipCode("99999");
- // break;
- $order->addOrderRow(TestUtil::createOrderRow(1000.00));
- $orderResponse = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $countryCode = "SE";
- $sveaOrderIdToGet = $orderResponse->sveaOrderId;
- $orderType = ConfigurationProvider::INVOICE_TYPE;
-
- $getOrdersBuilder = new QueryOrderBuilder(ConfigurationService::getDefaultConfig());
- $getOrdersBuilder->setOrderId($sveaOrderIdToGet);
- $getOrdersBuilder->setCountryCode($countryCode);
- $getOrdersBuilder->orderType = $orderType;
-
- $request = new GetOrdersRequest($getOrdersBuilder);
- $getOrdersResponse = $request->doRequest();
-
- // Example test_GetOrdersRequest_for_invoice_company_customer_order raw request response
- //
- //stdClass Object
- //(
- // /.../
- // [Customer] => stdClass Object
- // (
- // [CoAddress] => c/o Eriksson, Erik
- // [CompanyIdentity] =>
- // [CountryCode] => SE
- // [CustomerType] => Individual
- // [Email] =>
- // [FullName] => Persson, Tess T
- // [HouseNumber] =>
- // [IndividualIdentity] => stdClass Object
- // (
- // [BirthDate] =>
- // [FirstName] =>
- // [Initials] =>
- // [LastName] =>
- // )
- //
- // [Locality] => Stan
- // [NationalIdNumber] => 194605092222
- // [PhoneNumber] =>
- // [PublicKey] =>
- // [Street] => Testgatan 1
- // [ZipCode] => 99999
- // )
- // /.../
- // )
-
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\GetOrdersResponse', $getOrdersResponse);
- $this->assertEquals(1, $getOrdersResponse->accepted);
- $this->assertEquals(0, $getOrdersResponse->resultcode);
- $this->assertEquals(null, $getOrdersResponse->errormessage);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer", $getOrdersResponse->customer);
- $this->assertEquals("194605092222", $getOrdersResponse->customer->ssn);
- $this->assertEquals(null, $getOrdersResponse->customer->initials);
- $this->assertEquals(null, $getOrdersResponse->customer->birthDate);
- $this->assertEquals("Tess", $getOrdersResponse->customer->firstname); // not set for SE order
- $this->assertEquals("Persson", $getOrdersResponse->customer->lastname);
- //$this->assertEquals( null, $getOrdersResponse->customer->email );
- //$this->assertEquals( null, $getOrdersResponse->customer->phonenumber );
- $this->assertEquals("Persson Tess T", $getOrdersResponse->customer->name); // FullName
- $this->assertEquals("Testgatan 1", $getOrdersResponse->customer->streetAddress);
- $this->assertEquals("Testgatan 1", $getOrdersResponse->customer->street);
- $this->assertEquals("c/o Eriksson, Erik", $getOrdersResponse->customer->coAddress);
- $this->assertEquals("99999", $getOrdersResponse->customer->zipCode);
- $this->assertEquals("Stan", $getOrdersResponse->customer->locality);
- }
-
- public function test_GetOrdersRequest_for_invoice_sets_company_customer_correctly()
- {
- // create order
- $country = "SE";
- $order = TestUtil::createOrder(TestUtil::createCompanyCustomer($country));
- //case( "SE" ):
- // return Svea\WebPay\WebPayItem::companyCustomer()
- // ->setNationalIdNumber("4608142222")
- // ->setCompanyName("Tess T", "Persson")
- // ->setStreetAddress("Testgatan", 1)
- // ->setCoAddress("c/o Eriksson, Erik")
- // ->setLocality("Stan")
- // ->setZipCode("99999");
- // break;
- $order->addOrderRow(TestUtil::createOrderRow(1000.00));
- $orderResponse = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $countryCode = "SE";
- $sveaOrderIdToGet = $orderResponse->sveaOrderId;
- $orderType = ConfigurationProvider::INVOICE_TYPE;
-
- $getOrdersBuilder = new QueryOrderBuilder(ConfigurationService::getDefaultConfig());
- $getOrdersBuilder->setOrderId($sveaOrderIdToGet);
- $getOrdersBuilder->setCountryCode($countryCode);
- $getOrdersBuilder->orderType = $orderType;
-
- $request = new GetOrdersRequest($getOrdersBuilder);
- $getOrdersResponse = $request->doRequest();
-
- // Example test_GetOrdersRequest_for_invoice_company_customer_order raw request response
- //
- //stdClass Object
- //(
- // /.../
- // [Customer] => stdClass Object
- // (
- // [CoAddress] => c/o Eriksson, Erik
- // [CompanyIdentity] => stdClass Object
- // (
- // [CompanyIdentification] =>
- // [CompanyVatNumber] =>
- // )
- //
- // [CountryCode] => SE
- // [CustomerType] => Company
- // [Email] =>
- // [FullName] => Persson, Tess T
- // [HouseNumber] =>
- // [IndividualIdentity] =>
- // [Locality] => Stan
- // [NationalIdNumber] => 164608142222
- // [PhoneNumber] =>
- // [PublicKey] =>
- // [Street] => Testgatan 1
- // [ZipCode] => 99999
- // )
- // /.../
- // )
-
- ////print_r( $getOrdersResponse );
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\GetOrdersResponse', $getOrdersResponse);
- $this->assertEquals(1, $getOrdersResponse->accepted);
- $this->assertEquals(0, $getOrdersResponse->resultcode);
- $this->assertEquals(null, $getOrdersResponse->errormessage);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer", $getOrdersResponse->customer);
- $this->assertEquals("194608142222", $getOrdersResponse->customer->orgNumber);
- $this->assertEquals(null, $getOrdersResponse->customer->companyVatNumber);
- $this->assertEquals("Test", $getOrdersResponse->customer->companyName);
- $this->assertEquals(null, $getOrdersResponse->customer->email);
- $this->assertEquals(null, $getOrdersResponse->customer->phonenumber);
- $this->assertEquals("Testaregatan 1", $getOrdersResponse->customer->streetAddress);
- $this->assertEquals("Testaregatan 1", $getOrdersResponse->customer->street);
- $this->assertEquals(null, $getOrdersResponse->customer->coAddress);
- $this->assertEquals("11111", $getOrdersResponse->customer->zipCode);
- $this->assertEquals("Solna", $getOrdersResponse->customer->locality);
- }
-
- public function test_manual_GetOrdersRequest_for_paymentplan_order()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for test_manual_GetOrdersRequest_for_paymentplan_order'
- );
-
- // create order
- $country = "SE";
- // $order = Svea\WebPay\Test\TestUtil::createOrder( Svea\WebPay\Test\TestUtil::createIndividualCustomer($country) );
- // $order->addOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow( 1000.00 ) );
- // $orderResponse = $order->usePaymentPlanPayment( Svea\WebPay\Test\TestUtil::getGetPaymentPlanParamsForTesting($country) )->doRequest();
- // $this->assertEquals(1, $orderResponse->accepted);
- //
- $getOrdersBuilder = new QueryOrderBuilder(ConfigurationService::getDefaultConfig());
- //$getOrdersBuilder->setOrderId($orderResponse->sveaOrderId);
- $getOrdersBuilder->setOrderId(414812);
- $getOrdersBuilder->setCountryCode($country);
- $getOrdersBuilder->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
-
- $request = new GetOrdersRequest($getOrdersBuilder);
- $getOrdersResponse = $request->doRequest();
-
- // Example test_GetOrdersRequest_for_invoice_company_customer_order raw request response
- //
- // stdClass Object
- //(
- // [ErrorMessage] =>
- // [ResultCode] => 0
- // [Orders] => stdClass Object
- // (
- // [Order] => stdClass Object
- // (
- // [ChangedDate] =>
- // [ClientId] => 59999
- // [ClientOrderId] => clientOrderNumber:2014-09-11T17:57:07+02:00
- // [CreatedDate] => 2014-09-11T17:57:08.777
- // [CreditReportStatus] => stdClass Object
- // (
- // [Accepted] => true
- // [CreationDate] => 2014-09-11T17:57:08.87
- // )
- //
- // [Currency] => SEK
- // [Customer] => stdClass Object
- // (
- // [CoAddress] => c/o Eriksson, Erik
- // [CompanyIdentity] =>
- // [CountryCode] => SE
- // [CustomerType] => Individual
- // [Email] =>
- // [FullName] => Persson, Tess T
- // [HouseNumber] =>
- // [IndividualIdentity] => stdClass Object
- // (
- // [BirthDate] =>
- // [FirstName] =>
- // [Initials] =>
- // [LastName] =>
- // )
- //
- // [Locality] => Stan
- // [NationalIdNumber] => 194605092222
- // [PhoneNumber] =>
- // [PublicKey] =>
- // [Street] => Testgatan 1
- // [ZipCode] => 99999
- // )
- //
- // [CustomerId] => 1000013
- // [CustomerReference] => created by Svea\WebPay\Test\TestUtil::createOrder()
- // [DeliveryAddress] =>
- // [IsPossibleToAdminister] => false
- // [IsPossibleToCancel] => true
- // [Notes] =>
- // [OrderDeliveryStatus] => Created
- // [OrderRows] => stdClass Object
- // (
- // [NumberedOrderRow] => Array
- // (
- // [0] => stdClass Object
- // (
- // [ArticleNumber] => 1
- // [Description] => Product: Specification
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 2.00
- // [PricePerUnit] => 100.00
- // [Unit] => st
- // [VatPercent] => 25.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 1
- // [Status] => NotDelivered
- // )
- //
- // [1] => stdClass Object
- // (
- // [ArticleNumber] => 1
- // [Description] => Product: Specification
- // [DiscountPercent] => 0.00
- // [NumberOfUnits] => 2.00
- // [PricePerUnit] => 1000.00
- // [Unit] => st
- // [VatPercent] => 25.00
- // [CreditInvoiceId] =>
- // [InvoiceId] =>
- // [RowNumber] => 2
- // [Status] => NotDelivered
- // )
- //
- // )
- //
- // )
- //
- // [OrderStatus] => Active
- // [OrderType] => PaymentPlan
- // [PaymentPlanDetails] => stdClass Object
- // (
- // [ContractLengthMonths] => 3
- // [ContractNumber] =>
- // )
- //
- // [PendingReasons] =>
- // [SveaOrderId] => 414812
- // [SveaWillBuy] => true
- // )
- //
- // )
- //
- //)
-
- ////print_r( $getOrdersResponse );
- $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\GetOrdersResponse', $getOrdersResponse);
- $this->assertEquals(1, $getOrdersResponse->accepted);
- $this->assertEquals(0, $getOrdersResponse->resultcode);
- $this->assertEquals(null, $getOrdersResponse->errormessage);
-
- $this->assertEquals(null, $getOrdersResponse->changedDate); // TODO add test for changed order later
- $this->assertEquals(59999, $getOrdersResponse->clientId);
- $this->assertEquals("clientOrderNumber:2014-09-11T17:57:07+02:00", $getOrdersResponse->clientOrderId);
- $this->assertEquals("2014-09-11T17:57:08.777", $getOrdersResponse->createdDate);
-
- $this->assertEquals(true, $getOrdersResponse->creditReportStatusAccepted);
- $this->assertEquals("2014-09-11T17:57:08.87", $getOrdersResponse->creditReportStatusCreationDate);
-
- $this->assertEquals("SEK", $getOrdersResponse->currency);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer", $getOrdersResponse->customer);
- // asserting customer attributes in other testcases
- //$this->assertEquals( null, $getOrdersResponse->customer->email ); // -- returns current customer id email, may change
-
- $this->assertEquals("1000013", $getOrdersResponse->customerId);
- $this->assertEquals("created by TestUtil::createOrder()", $getOrdersResponse->customerReference);
- $this->assertEquals(false, $getOrdersResponse->isPossibleToAdminister);
- $this->assertEquals(true, $getOrdersResponse->isPossibleToCancel);
- $this->assertEquals(null, $getOrdersResponse->notes);
- $this->assertEquals("Created", $getOrdersResponse->orderDeliveryStatus);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $getOrdersResponse->numberedOrderRows[0]);
- // asserting order row attributes in invoice testcase
-
- $this->assertEquals("Active", $getOrdersResponse->orderStatus);
- $this->assertEquals("PaymentPlan", $getOrdersResponse->orderType);
- $this->assertEquals(3, $getOrdersResponse->paymentPlanDetailsContractLengthMonths);
- $this->assertEquals(null, $getOrdersResponse->paymentPlanDetailsContractNumber);
- $this->assertEquals(null, $getOrdersResponse->pendingReasons);
- $this->assertEquals(414812, $getOrdersResponse->orderId);
- $this->assertEquals(true, $getOrdersResponse->sveaWillBuy);
- }
-
- function test_orderrow_response_incvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
-
- $response = WebPayAdmin::queryOrder($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->queryInvoiceOrder()
- ->doRequest();
- //print_r($response);
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(145.00, $response->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals(null, $response->numberedOrderRows[0]->amountExVat);
-
- }
-
- function test_orderrow_response_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
-
- $response = WebPayAdmin::queryOrder($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->queryInvoiceOrder()
- ->doRequest();
- //print_r($response);
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(145.00, $response->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(null, $response->numberedOrderRows[0]->amountIncVat);
- }
+ /**
+ * 1. create an Invoice|PaymentPlan order
+ * 2. note the client credentials, order number and type, and insert below
+ * 3. run the test
+ */
+ public function test_manual_GetOrdersRequest_for_invoice_individual_customer_order()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete( // 150626 -- removed due to corrupt customerids w/no ssn in test database (known error)
+ 'skeleton for test_manual_GetOrdersRequest_for_invoice_individual_customer_order'
+ );
+
+ $countryCode = "SE";
+ $sveaOrderIdToGet = 348629;
+ $orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ $getOrdersBuilder = new QueryOrderBuilder(ConfigurationService::getDefaultConfig());
+ $getOrdersBuilder->setOrderId($sveaOrderIdToGet);
+ $getOrdersBuilder->setCountryCode($countryCode);
+ $getOrdersBuilder->orderType = $orderType;
+
+ // Example of test_manual_GetOrdersRequest_for_invoice_individual_customer_order 348629 raw request response to parse:
+ // stdClass Object
+ // (
+ // [ErrorMessage] =>
+ // [ResultCode] => 0
+ // [Orders] => stdClass Object
+ // (
+ // [Order] => stdClass Object
+ // (
+ // [ChangedDate] =>
+ // [ClientId] => 79021
+ // [ClientOrderId] => 449
+ // [CreatedDate] => 2014-05-19T16:04:54.787
+ // [CreditReportStatus] => stdClass Object
+ // (
+ // [Accepted] => true
+ // [CreationDate] => 2014-05-19T16:04:54.893
+ // )
+ //
+ // [Currency] => SEK
+ // [Customer] => stdClass Object
+ // (
+ // [CoAddress] => c/o Eriksson, Erik
+ // [CompanyIdentity] =>
+ // [CountryCode] => SE
+ // [CustomerType] => Individual
+ // [Email] => test@svea.com
+ // [FullName] => Persson, Tess T
+ // [HouseNumber] =>
+ // [IndividualIdentity] => stdClass Object
+ // (
+ // [BirthDate] =>
+ // [FirstName] =>
+ // [Initials] =>
+ // [LastName] =>
+ // )
+ //
+ // [Locality] => Stan
+ // [NationalIdNumber] => 194605092222
+ // [PhoneNumber] => 999999
+ // [PublicKey] =>
+ // [Street] => Testgatan 1
+ // [ZipCode] => 99999
+ // )
+ //
+ // [CustomerId] => 1000117
+ // [CustomerReference] =>
+ // [DeliveryAddress] =>
+ // [IsPossibleToAdminister] => false
+ // [IsPossibleToCancel] => true
+ // [Notes] =>
+ // [OrderDeliveryStatus] => Created
+ // [OrderRows] => stdClass Object
+ // (
+ // [NumberedOrderRow] => Array
+ // (
+ // [0] => stdClass Object
+ // (
+ // [ArticleNumber] =>
+ // [Description] => Dyr produkt 25%
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 2.00
+ // [PricePerUnit] => 2000.00
+ // [Unit] =>
+ // [VatPercent] => 25.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 1
+ // [Status] => NotDelivered
+ // )
+ //
+ // [1] => stdClass Object
+ // (
+ // [ArticleNumber] =>
+ // [Description] => Testprodukt 1kr 25%
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 1.00
+ // [PricePerUnit] => 1.00
+ // [Unit] =>
+ // [VatPercent] => 25.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 2
+ // [Status] => NotDelivered
+ // )
+ //
+ // [2] => stdClass Object
+ // (
+ // [ArticleNumber] =>
+ // [Description] => Fastpris (Fast fraktpris)
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 1.00
+ // [PricePerUnit] => 4.00
+ // [Unit] =>
+ // [VatPercent] => 25.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 3
+ // [Status] => NotDelivered
+ // )
+ //
+ // [3] => stdClass Object
+ // (
+ // [ArticleNumber] =>
+ // [Description] => Svea Fakturaavgift:: 20.00kr (SE)
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 1.00
+ // [PricePerUnit] => 20.00
+ // [Unit] =>
+ // [VatPercent] => 0.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 4
+ // [Status] => NotDelivered
+ // )
+ //
+ // )
+ //
+ // )
+ //
+ // [OrderStatus] => Active
+ // [OrderType] => Invoice
+ // [PaymentPlanDetails] =>
+ // [PendingReasons] =>
+ // [SveaOrderId] => 348629
+ // [SveaWillBuy] => true
+ // )
+ //
+ // )
+ //
+ // )
+
+ $request = new GetOrdersRequest($getOrdersBuilder);
+ $getOrdersResponse = $request->doRequest();
+
+// print_r( $getOrdersResponse );
+
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\GetOrdersResponse', $getOrdersResponse);
+ $this->assertEquals(1, $getOrdersResponse->accepted);
+ $this->assertEquals(0, $getOrdersResponse->resultcode);
+ $this->assertEquals(null, $getOrdersResponse->errormessage);
+
+ $this->assertEquals(null, $getOrdersResponse->changedDate); // TODO add test for changed order later
+ $this->assertEquals(79021, $getOrdersResponse->clientId);
+ $this->assertEquals(449, $getOrdersResponse->clientOrderId);
+ $this->assertEquals("2014-05-19T16:04:54.787", $getOrdersResponse->createdDate);
+
+ $this->assertEquals(true, $getOrdersResponse->creditReportStatusAccepted);
+ $this->assertEquals("2014-05-19T16:04:54.893", $getOrdersResponse->creditReportStatusCreationDate);
+
+ $this->assertEquals("SEK", $getOrdersResponse->currency);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer", $getOrdersResponse->customer);
+ $this->assertEquals("194605092222", $getOrdersResponse->customer->ssn);
+ $this->assertEquals(null, $getOrdersResponse->customer->initials);
+ $this->assertEquals(null, $getOrdersResponse->customer->birthDate);
+ $this->assertEquals(null, $getOrdersResponse->customer->firstname);
+ $this->assertEquals(null, $getOrdersResponse->customer->lastname);
+ //$this->assertEquals( "test@svea.com", $getOrdersResponse->customer->email ); // -- returns current customer stats, may change
+ //$this->assertEquals( null, $getOrdersResponse->customer->phonenumber ); // -- returns current customer stats, may change
+ $this->assertEquals("Persson, Tess T", $getOrdersResponse->customer->name); // FullName
+ $this->assertEquals("Testgatan 1", $getOrdersResponse->customer->streetAddress);
+ $this->assertEquals("Testgatan 1", $getOrdersResponse->customer->street);
+ $this->assertEquals("c/o Eriksson, Erik", $getOrdersResponse->customer->coAddress);
+ $this->assertEquals("99999", $getOrdersResponse->customer->zipCode);
+ $this->assertEquals("Stan", $getOrdersResponse->customer->locality);
+
+ $this->assertEquals("1000117", $getOrdersResponse->customerId);
+ $this->assertEquals(null, $getOrdersResponse->customerReference);
+ $this->assertClassNotHasAttribute("deliveryAddress", "\Svea\AdminService\GetOrdersResponse"); // deliveryAddress field is not supported
+ $this->assertEquals(false, $getOrdersResponse->isPossibleToAdminister);
+ $this->assertEquals(true, $getOrdersResponse->isPossibleToCancel);
+ $this->assertEquals(null, $getOrdersResponse->notes);
+ $this->assertEquals("Created", $getOrdersResponse->orderDeliveryStatus);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $getOrdersResponse->numberedOrderRows[0]);
+ $this->assertEquals(1, $getOrdersResponse->numberedOrderRows[0]->rowNumber);
+ $this->assertEquals(null, $getOrdersResponse->numberedOrderRows[0]->articleNumber);
+ $this->assertEquals(2.00, $getOrdersResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals(null, $getOrdersResponse->numberedOrderRows[0]->unit);
+ $this->assertEquals(2000.00, $getOrdersResponse->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(25.00, $getOrdersResponse->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals(null, $getOrdersResponse->numberedOrderRows[0]->name);
+ $this->assertEquals("Dyr produkt 25%", $getOrdersResponse->numberedOrderRows[0]->description);
+ $this->assertEquals(0, $getOrdersResponse->numberedOrderRows[0]->vatDiscount);
+
+ // only check attributes of first row
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $getOrdersResponse->numberedOrderRows[3]);
+ $this->assertEquals(4, $getOrdersResponse->numberedOrderRows[3]->rowNumber);
+
+ $this->assertEquals("Active", $getOrdersResponse->orderStatus);
+ $this->assertEquals("Invoice", $getOrdersResponse->orderType);
+ $this->assertEquals(null, $getOrdersResponse->paymentPlanDetailsContractLengthMonths);
+ $this->assertEquals(null, $getOrdersResponse->paymentPlanDetailsContractNumber);
+ $this->assertEquals(null, $getOrdersResponse->pendingReasons);
+ $this->assertEquals(348629, $getOrdersResponse->orderId);
+ $this->assertEquals(true, $getOrdersResponse->sveaWillBuy);
+ }
+
+ public function test_GetOrdersRequest_for_invoice_sets_individual_customer_correctly()
+ {
+ // create order
+ $country = "SE";
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country));
+ //case( "SE" ):
+ // return Svea\WebPay\WebPayItem::individualCustomer()
+ // ->setNationalIdNumber("194605092222")
+ // ->setBirthDate(1946, 05, 09)
+ // ->setName("Tess T", "Persson")
+ // ->setStreetAddress("Testgatan", 1)
+ // ->setCoAddress("c/o Eriksson, Erik")
+ // ->setLocality("Stan")
+ // ->setZipCode("99999");
+ // break;
+ $order->addOrderRow(TestUtil::createOrderRow(1000.00));
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $countryCode = "SE";
+ $sveaOrderIdToGet = $orderResponse->sveaOrderId;
+ $orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ $getOrdersBuilder = new QueryOrderBuilder(ConfigurationService::getDefaultConfig());
+ $getOrdersBuilder->setOrderId($sveaOrderIdToGet);
+ $getOrdersBuilder->setCountryCode($countryCode);
+ $getOrdersBuilder->orderType = $orderType;
+
+ $request = new GetOrdersRequest($getOrdersBuilder);
+ $getOrdersResponse = $request->doRequest();
+
+ // Example test_GetOrdersRequest_for_invoice_company_customer_order raw request response
+ //
+ //stdClass Object
+ //(
+ // /.../
+ // [Customer] => stdClass Object
+ // (
+ // [CoAddress] => c/o Eriksson, Erik
+ // [CompanyIdentity] =>
+ // [CountryCode] => SE
+ // [CustomerType] => Individual
+ // [Email] =>
+ // [FullName] => Persson, Tess T
+ // [HouseNumber] =>
+ // [IndividualIdentity] => stdClass Object
+ // (
+ // [BirthDate] =>
+ // [FirstName] =>
+ // [Initials] =>
+ // [LastName] =>
+ // )
+ //
+ // [Locality] => Stan
+ // [NationalIdNumber] => 194605092222
+ // [PhoneNumber] =>
+ // [PublicKey] =>
+ // [Street] => Testgatan 1
+ // [ZipCode] => 99999
+ // )
+ // /.../
+ // )
+
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\GetOrdersResponse', $getOrdersResponse);
+ $this->assertEquals(1, $getOrdersResponse->accepted);
+ $this->assertEquals(0, $getOrdersResponse->resultcode);
+ $this->assertEquals(null, $getOrdersResponse->errormessage);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer", $getOrdersResponse->customer);
+ $this->assertEquals("194605092222", $getOrdersResponse->customer->ssn);
+ $this->assertEquals(null, $getOrdersResponse->customer->initials);
+ $this->assertEquals(null, $getOrdersResponse->customer->birthDate);
+ $this->assertEquals("Tess", $getOrdersResponse->customer->firstname); // not set for SE order
+ $this->assertEquals("Persson", $getOrdersResponse->customer->lastname);
+ //$this->assertEquals( null, $getOrdersResponse->customer->email );
+ //$this->assertEquals( null, $getOrdersResponse->customer->phonenumber );
+ $this->assertEquals("Persson Tess T", $getOrdersResponse->customer->name); // FullName
+ $this->assertEquals("Testgatan 1", $getOrdersResponse->customer->streetAddress);
+ $this->assertEquals("Testgatan 1", $getOrdersResponse->customer->street);
+ $this->assertEquals("c/o Eriksson, Erik", $getOrdersResponse->customer->coAddress);
+ $this->assertEquals("99999", $getOrdersResponse->customer->zipCode);
+ $this->assertEquals("Stan", $getOrdersResponse->customer->locality);
+ }
+
+ public function test_GetOrdersRequest_for_invoice_sets_company_customer_correctly()
+ {
+ // create order
+ $country = "SE";
+ $order = TestUtil::createOrder(TestUtil::createCompanyCustomer($country));
+ //case( "SE" ):
+ // return Svea\WebPay\WebPayItem::companyCustomer()
+ // ->setNationalIdNumber("4608142222")
+ // ->setCompanyName("Tess T", "Persson")
+ // ->setStreetAddress("Testgatan", 1)
+ // ->setCoAddress("c/o Eriksson, Erik")
+ // ->setLocality("Stan")
+ // ->setZipCode("99999");
+ // break;
+ $order->addOrderRow(TestUtil::createOrderRow(1000.00));
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $countryCode = "SE";
+ $sveaOrderIdToGet = $orderResponse->sveaOrderId;
+ $orderType = ConfigurationProvider::INVOICE_TYPE;
+
+ $getOrdersBuilder = new QueryOrderBuilder(ConfigurationService::getDefaultConfig());
+ $getOrdersBuilder->setOrderId($sveaOrderIdToGet);
+ $getOrdersBuilder->setCountryCode($countryCode);
+ $getOrdersBuilder->orderType = $orderType;
+
+ $request = new GetOrdersRequest($getOrdersBuilder);
+ $getOrdersResponse = $request->doRequest();
+
+ // Example test_GetOrdersRequest_for_invoice_company_customer_order raw request response
+ //
+ //stdClass Object
+ //(
+ // /.../
+ // [Customer] => stdClass Object
+ // (
+ // [CoAddress] => c/o Eriksson, Erik
+ // [CompanyIdentity] => stdClass Object
+ // (
+ // [CompanyIdentification] =>
+ // [CompanyVatNumber] =>
+ // )
+ //
+ // [CountryCode] => SE
+ // [CustomerType] => Company
+ // [Email] =>
+ // [FullName] => Persson, Tess T
+ // [HouseNumber] =>
+ // [IndividualIdentity] =>
+ // [Locality] => Stan
+ // [NationalIdNumber] => 164608142222
+ // [PhoneNumber] =>
+ // [PublicKey] =>
+ // [Street] => Testgatan 1
+ // [ZipCode] => 99999
+ // )
+ // /.../
+ // )
+
+ ////print_r( $getOrdersResponse );
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\GetOrdersResponse', $getOrdersResponse);
+ $this->assertEquals(1, $getOrdersResponse->accepted);
+ $this->assertEquals(0, $getOrdersResponse->resultcode);
+ $this->assertEquals(null, $getOrdersResponse->errormessage);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\CompanyCustomer", $getOrdersResponse->customer);
+ $this->assertEquals("194608142222", $getOrdersResponse->customer->orgNumber);
+ $this->assertEquals(null, $getOrdersResponse->customer->companyVatNumber);
+ $this->assertEquals("Test", $getOrdersResponse->customer->companyName);
+ $this->assertEquals(null, $getOrdersResponse->customer->email);
+ $this->assertEquals(null, $getOrdersResponse->customer->phonenumber);
+ $this->assertEquals("Testaregatan 1", $getOrdersResponse->customer->streetAddress);
+ $this->assertEquals("Testaregatan 1", $getOrdersResponse->customer->street);
+ $this->assertEquals(null, $getOrdersResponse->customer->coAddress);
+ $this->assertEquals("11111", $getOrdersResponse->customer->zipCode);
+ $this->assertEquals("Solna", $getOrdersResponse->customer->locality);
+ }
+
+ public function test_manual_GetOrdersRequest_for_paymentplan_order()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for test_manual_GetOrdersRequest_for_paymentplan_order'
+ );
+
+ // create order
+ $country = "SE";
+ // $order = Svea\WebPay\Test\TestUtil::createOrder( Svea\WebPay\Test\TestUtil::createIndividualCustomer($country) );
+ // $order->addOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow( 1000.00 ) );
+ // $orderResponse = $order->usePaymentPlanPayment( Svea\WebPay\Test\TestUtil::getGetPaymentPlanParamsForTesting($country) )->doRequest();
+ // $this->assertEquals(1, $orderResponse->accepted);
+ //
+ $getOrdersBuilder = new QueryOrderBuilder(ConfigurationService::getDefaultConfig());
+ //$getOrdersBuilder->setOrderId($orderResponse->sveaOrderId);
+ $getOrdersBuilder->setOrderId(414812);
+ $getOrdersBuilder->setCountryCode($country);
+ $getOrdersBuilder->orderType = ConfigurationProvider::PAYMENTPLAN_TYPE;
+
+ $request = new GetOrdersRequest($getOrdersBuilder);
+ $getOrdersResponse = $request->doRequest();
+
+ // Example test_GetOrdersRequest_for_invoice_company_customer_order raw request response
+ //
+ // stdClass Object
+ //(
+ // [ErrorMessage] =>
+ // [ResultCode] => 0
+ // [Orders] => stdClass Object
+ // (
+ // [Order] => stdClass Object
+ // (
+ // [ChangedDate] =>
+ // [ClientId] => 59999
+ // [ClientOrderId] => clientOrderNumber:2014-09-11T17:57:07+02:00
+ // [CreatedDate] => 2014-09-11T17:57:08.777
+ // [CreditReportStatus] => stdClass Object
+ // (
+ // [Accepted] => true
+ // [CreationDate] => 2014-09-11T17:57:08.87
+ // )
+ //
+ // [Currency] => SEK
+ // [Customer] => stdClass Object
+ // (
+ // [CoAddress] => c/o Eriksson, Erik
+ // [CompanyIdentity] =>
+ // [CountryCode] => SE
+ // [CustomerType] => Individual
+ // [Email] =>
+ // [FullName] => Persson, Tess T
+ // [HouseNumber] =>
+ // [IndividualIdentity] => stdClass Object
+ // (
+ // [BirthDate] =>
+ // [FirstName] =>
+ // [Initials] =>
+ // [LastName] =>
+ // )
+ //
+ // [Locality] => Stan
+ // [NationalIdNumber] => 194605092222
+ // [PhoneNumber] =>
+ // [PublicKey] =>
+ // [Street] => Testgatan 1
+ // [ZipCode] => 99999
+ // )
+ //
+ // [CustomerId] => 1000013
+ // [CustomerReference] => created by Svea\WebPay\Test\TestUtil::createOrder()
+ // [DeliveryAddress] =>
+ // [IsPossibleToAdminister] => false
+ // [IsPossibleToCancel] => true
+ // [Notes] =>
+ // [OrderDeliveryStatus] => Created
+ // [OrderRows] => stdClass Object
+ // (
+ // [NumberedOrderRow] => Array
+ // (
+ // [0] => stdClass Object
+ // (
+ // [ArticleNumber] => 1
+ // [Description] => Product: Specification
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 2.00
+ // [PricePerUnit] => 100.00
+ // [Unit] => st
+ // [VatPercent] => 25.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 1
+ // [Status] => NotDelivered
+ // )
+ //
+ // [1] => stdClass Object
+ // (
+ // [ArticleNumber] => 1
+ // [Description] => Product: Specification
+ // [DiscountPercent] => 0.00
+ // [NumberOfUnits] => 2.00
+ // [PricePerUnit] => 1000.00
+ // [Unit] => st
+ // [VatPercent] => 25.00
+ // [CreditInvoiceId] =>
+ // [InvoiceId] =>
+ // [RowNumber] => 2
+ // [Status] => NotDelivered
+ // )
+ //
+ // )
+ //
+ // )
+ //
+ // [OrderStatus] => Active
+ // [OrderType] => PaymentPlan
+ // [PaymentPlanDetails] => stdClass Object
+ // (
+ // [ContractLengthMonths] => 3
+ // [ContractNumber] =>
+ // )
+ //
+ // [PendingReasons] =>
+ // [SveaOrderId] => 414812
+ // [SveaWillBuy] => true
+ // )
+ //
+ // )
+ //
+ //)
+
+ ////print_r( $getOrdersResponse );
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AdminServiceResponse\GetOrdersResponse', $getOrdersResponse);
+ $this->assertEquals(1, $getOrdersResponse->accepted);
+ $this->assertEquals(0, $getOrdersResponse->resultcode);
+ $this->assertEquals(null, $getOrdersResponse->errormessage);
+
+ $this->assertEquals(null, $getOrdersResponse->changedDate); // TODO add test for changed order later
+ $this->assertEquals(59999, $getOrdersResponse->clientId);
+ $this->assertEquals("clientOrderNumber:2014-09-11T17:57:07+02:00", $getOrdersResponse->clientOrderId);
+ $this->assertEquals("2014-09-11T17:57:08.777", $getOrdersResponse->createdDate);
+
+ $this->assertEquals(true, $getOrdersResponse->creditReportStatusAccepted);
+ $this->assertEquals("2014-09-11T17:57:08.87", $getOrdersResponse->creditReportStatusCreationDate);
+
+ $this->assertEquals("SEK", $getOrdersResponse->currency);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer", $getOrdersResponse->customer);
+ // asserting customer attributes in other testcases
+ //$this->assertEquals( null, $getOrdersResponse->customer->email ); // -- returns current customer id email, may change
+
+ $this->assertEquals("1000013", $getOrdersResponse->customerId);
+ $this->assertEquals("created by TestUtil::createOrder()", $getOrdersResponse->customerReference);
+ $this->assertEquals(false, $getOrdersResponse->isPossibleToAdminister);
+ $this->assertEquals(true, $getOrdersResponse->isPossibleToCancel);
+ $this->assertEquals(null, $getOrdersResponse->notes);
+ $this->assertEquals("Created", $getOrdersResponse->orderDeliveryStatus);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $getOrdersResponse->numberedOrderRows[0]);
+ // asserting order row attributes in invoice testcase
+
+ $this->assertEquals("Active", $getOrdersResponse->orderStatus);
+ $this->assertEquals("PaymentPlan", $getOrdersResponse->orderType);
+ $this->assertEquals(3, $getOrdersResponse->paymentPlanDetailsContractLengthMonths);
+ $this->assertEquals(null, $getOrdersResponse->paymentPlanDetailsContractNumber);
+ $this->assertEquals(null, $getOrdersResponse->pendingReasons);
+ $this->assertEquals(414812, $getOrdersResponse->orderId);
+ $this->assertEquals(true, $getOrdersResponse->sveaWillBuy);
+ }
+
+ function test_orderrow_response_incvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(145.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $response = WebPayAdmin::queryOrder($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->queryInvoiceOrder()
+ ->doRequest();
+ //print_r($response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(145.00, $response->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals(null, $response->numberedOrderRows[0]->amountExVat);
+
+ }
+
+ function test_orderrow_response_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(145.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $response = WebPayAdmin::queryOrder($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->queryInvoiceOrder()
+ ->doRequest();
+ //print_r($response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(145.00, $response->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(null, $response->numberedOrderRows[0]->amountIncVat);
+ }
}
diff --git a/test/IntegrationTest/AdminService/OrderToCredit.php b/test/IntegrationTest/AdminService/OrderToCredit.php
index 921d31c0..73a40675 100644
--- a/test/IntegrationTest/AdminService/OrderToCredit.php
+++ b/test/IntegrationTest/AdminService/OrderToCredit.php
@@ -6,13 +6,13 @@
/** helper class, used to return information about an order */
class OrderToCredit {
- var $orderId;
- var $invoiceId;
- var $contractNumber;
+ var $orderId;
+ var $invoiceId;
+ var $contractNumber;
- public function __construct( $orderId, $invoiceId = NULL, $contractNumber = NULL ) {
- $this->orderId = $orderId;
- $this->invoiceId = $invoiceId;
- $this->contractNumber = $contractNumber;
- }
+ public function __construct( $orderId, $invoiceId = NULL, $contractNumber = NULL ) {
+ $this->orderId = $orderId;
+ $this->invoiceId = $invoiceId;
+ $this->contractNumber = $contractNumber;
+ }
}
diff --git a/test/IntegrationTest/AdminService/OrderToCreditAmount.php b/test/IntegrationTest/AdminService/OrderToCreditAmount.php
index b4e382fc..de341404 100644
--- a/test/IntegrationTest/AdminService/OrderToCreditAmount.php
+++ b/test/IntegrationTest/AdminService/OrderToCreditAmount.php
@@ -4,13 +4,13 @@
/** helper class, used to return information about an order */
class OrderToCreditAmount {
- var $orderId;
- var $invoiceId;
- var $contractNumber;
+ var $orderId;
+ var $invoiceId;
+ var $contractNumber;
- public function __construct( $orderId, $invoiceId = NULL, $contractNumber = NULL ) {
- $this->orderId = $orderId;
- $this->invoiceId = $invoiceId;
- $this->contractNumber = $contractNumber;
- }
+ public function __construct( $orderId, $invoiceId = NULL, $contractNumber = NULL ) {
+ $this->orderId = $orderId;
+ $this->invoiceId = $invoiceId;
+ $this->contractNumber = $contractNumber;
+ }
}
diff --git a/test/IntegrationTest/AdminService/UpdateOrderRequestIntegrationTest.php b/test/IntegrationTest/AdminService/UpdateOrderRequestIntegrationTest.php
index 5ee2d649..7d2e4da9 100644
--- a/test/IntegrationTest/AdminService/UpdateOrderRequestIntegrationTest.php
+++ b/test/IntegrationTest/AdminService/UpdateOrderRequestIntegrationTest.php
@@ -16,76 +16,76 @@
class UpdateOrderRequestIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public $notes = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
- Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
- penatibus et magnis';
+ public $notes = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
+ Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
+ penatibus et magnis';
- public function test_add_new_clientordernumber_invoice()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
+ public function test_add_new_clientordernumber_invoice()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(145.00)
+ ->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)
- ->setClientOrderNumber('123')//string
- ->updateInvoiceOrder()->doRequest();
- $this->assertEquals(1, $response->accepted);
+ $response = WebPayAdmin::updateOrder($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setClientOrderNumber('123')//string
+ ->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('123', $query2->clientOrderId);
- //print_r($orderResponse->sveaOrderId);
- }
+ // query order and assert row totals
+ $query2 = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query2->accepted);
+ $this->assertEquals('123', $query2->clientOrderId);
+ //print_r($orderResponse->sveaOrderId);
+ }
- public function test_add_new_notes_invoice()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
+ public function test_add_new_notes_invoice()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(145.00)
+ ->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)//string 200 chars
- ->updateInvoiceOrder()->doRequest();
- $this->assertEquals(1, $response->accepted);
+ $response = WebPayAdmin::updateOrder($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setNotes($this->notes)//string 200 chars
+ ->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);
- }
+ // 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);
+ }
}
\ No newline at end of file
diff --git a/test/IntegrationTest/AdminService/UpdateOrderRowsRequestIntegrationTest.php b/test/IntegrationTest/AdminService/UpdateOrderRowsRequestIntegrationTest.php
index 2169c2b2..37f7cdeb 100644
--- a/test/IntegrationTest/AdminService/UpdateOrderRowsRequestIntegrationTest.php
+++ b/test/IntegrationTest/AdminService/UpdateOrderRowsRequestIntegrationTest.php
@@ -16,346 +16,346 @@
class UpdateOrderRowsRequestIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public function test_update_orderRow_as_exvat_and_vatpercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $response = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setVatPercent(24)
- ->setAmountExVat(80.00)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("80.00", $query->numberedOrderRows[0]->amountExVat);
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- }
-
- public function test_update_orderRow_as_incvat_and_vatpercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $response = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setVatPercent(24)
- ->setAmountIncVat(80.00)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("80.00", $query->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- }
-
- public function test_update_orderRow_as_incvat_and_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("123.99", $query->numberedOrderRows[0]->amountIncVat); // 123.9876 => 123.99
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
-
- $response = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()
- ->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("123.99", $query2->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals("24", $query2->numberedOrderRows[0]->vatPercent);
- }
-
- public function test_UpdateOrderRows_created_exvat_updated_incvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $response = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("99.99", $query->numberedOrderRows[0]->amountExVat); // 123.99/1.24 = 99.99
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- }
-
- public function test_UpdateOrderRows_created_exvat_updated_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $response = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("123.99", $query->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
- }
-
- public function test_UpdateOrderRows_created_incvat_updated_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("123.99", $query->numberedOrderRows[0]->amountIncVat); // sent 123.9876 inc => 123.99 queried
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
-
- $response = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()->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("123.99", $query2->numberedOrderRows[0]->amountIncVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
- $this->assertEquals("24", $query2->numberedOrderRows[0]->vatPercent);
- //print_r($orderResponse->sveaOrderId);
- }
-
- public function test_add_single_orderRow_type_missmatch_3()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $response = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()
- ->doRequest();
-
- $this->assertEquals(1, $response->accepted);
- }
-
- public function test_add_single_orderRow_type_mismatch_created_inc_updated_ex()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- // query order and assert row totals
- $query = WebPayAdmin::queryOrder($config)
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals("123.99", $query->numberedOrderRows[0]->amountIncVat); // sent 123.9876 inc => 123.99 queried
- $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
-
- $response = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()->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("123.99", $query2->numberedOrderRows[0]->amountIncVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
- $this->assertEquals("24", $query2->numberedOrderRows[0]->vatPercent);
- //print_r($orderResponse->sveaOrderId);
- }
+ public function test_update_orderRow_as_exvat_and_vatpercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(145.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $response = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setVatPercent(24)
+ ->setAmountExVat(80.00)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("80.00", $query->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ }
+
+ public function test_update_orderRow_as_incvat_and_vatpercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(145.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $response = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setVatPercent(24)
+ ->setAmountIncVat(80.00)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("80.00", $query->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ }
+
+ public function test_update_orderRow_as_incvat_and_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("123.99", $query->numberedOrderRows[0]->amountIncVat); // 123.9876 => 123.99
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+
+ $response = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()
+ ->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("123.99", $query2->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals("24", $query2->numberedOrderRows[0]->vatPercent);
+ }
+
+ public function test_UpdateOrderRows_created_exvat_updated_incvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $response = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("99.99", $query->numberedOrderRows[0]->amountExVat); // 123.99/1.24 = 99.99
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ }
+
+ public function test_UpdateOrderRows_created_exvat_updated_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $response = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("123.99", $query->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+ }
+
+ public function test_UpdateOrderRows_created_incvat_updated_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("123.99", $query->numberedOrderRows[0]->amountIncVat); // sent 123.9876 inc => 123.99 queried
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+
+ $response = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()->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("123.99", $query2->numberedOrderRows[0]->amountIncVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
+ $this->assertEquals("24", $query2->numberedOrderRows[0]->vatPercent);
+ //print_r($orderResponse->sveaOrderId);
+ }
+
+ public function test_add_single_orderRow_type_missmatch_3()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $response = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()
+ ->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+ }
+
+ public function test_add_single_orderRow_type_mismatch_created_inc_updated_ex()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ // query order and assert row totals
+ $query = WebPayAdmin::queryOrder($config)
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals("123.99", $query->numberedOrderRows[0]->amountIncVat); // sent 123.9876 inc => 123.99 queried
+ $this->assertEquals("24", $query->numberedOrderRows[0]->vatPercent);
+
+ $response = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()->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("123.99", $query2->numberedOrderRows[0]->amountIncVat); // sent 99.99 ex * 1.24 => sent 123.9876 inc => 123.99 queried
+ $this->assertEquals("24", $query2->numberedOrderRows[0]->vatPercent);
+ //print_r($orderResponse->sveaOrderId);
+ }
}
\ No newline at end of file
diff --git a/test/IntegrationTest/BuildOrder/AddOrderRowsBuilderTest.php b/test/IntegrationTest/BuildOrder/AddOrderRowsBuilderTest.php
index 4dc91afd..8135a3ac 100644
--- a/test/IntegrationTest/BuildOrder/AddOrderRowsBuilderTest.php
+++ b/test/IntegrationTest/BuildOrder/AddOrderRowsBuilderTest.php
@@ -15,245 +15,243 @@
class AddOrderRowsBuilderIntegrationTest extends \PHPUnit\Framework\TestCase
{
- protected $invoiceIdToTest;
- protected $country;
+ protected $invoiceIdToTest;
+ protected $country;
- protected function setUp()
- {
- $this->country = "SE";
- $this->invoiceIdToTest = 123456; // set this to the approved invoice set up by test_manual_setup_CreditOrderRows_testdata()
- }
+ protected function setUp()
+ {
+ $this->country = "SE";
+ $this->invoiceIdToTest = 123456; // set this to the approved invoice set up by test_manual_setup_CreditOrderRows_testdata()
+ }
- function test_AddOrderRows_addInvoiceOrderRows_single_row_success()
- {
- $country = "SE";
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
- $order->addOrderRow(TestUtil::createOrderRow(1.00));
- $orderResponse = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
+ function test_AddOrderRows_addInvoiceOrderRows_single_row_success()
+ {
+ $country = "SE";
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
+ $order->addOrderRow(TestUtil::createOrderRow(1.00));
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $b_vatPercent = 12;
- $b_articleNumber = "1071e";
- $b_unit = "pcs.";
- $b_name = "B Name";
- $b_description = "B Description";
- $b_discount = 0;
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $b_vatPercent = 12;
+ $b_articleNumber = "1071e";
+ $b_unit = "pcs.";
+ $b_name = "B Name";
+ $b_description = "B Description";
+ $b_discount = 0;
- $addOrderRowsBuilder = new AddOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $addOrderRowsResponse = $addOrderRowsBuilder
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->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)
- )
- ->addInvoiceOrderRows()
- ->doRequest();
+ $addOrderRowsBuilder = new AddOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $addOrderRowsResponse = $addOrderRowsBuilder
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->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)
+ )
+ ->addInvoiceOrderRows()
+ ->doRequest();
- $this->assertEquals(1, $addOrderRowsResponse->accepted);
- $createdOrderId = $orderResponse->sveaOrderId;
- ////print_r("test_AddOrderRows_addInvoiceOrderRows_single_row_success: "); //print_r( $createdOrderId );
+ $this->assertEquals(1, $addOrderRowsResponse->accepted);
+ $createdOrderId = $orderResponse->sveaOrderId;
+ ////print_r("test_AddOrderRows_addInvoiceOrderRows_single_row_success: "); //print_r( $createdOrderId );
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
- $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
+ $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
- ////print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
- // assert that order rows are the same
- $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
- $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
- $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
- $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
- $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->description);
- $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
- $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
- $this->assertEquals(\Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED, $queryResponse->numberedOrderRows[1]->status);
- $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber);
- }
+ ////print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+ // assert that order rows are the same
+ $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
+ $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
+ $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
+ $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->description);
+ $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
+ $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
+ $this->assertEquals(\Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED, $queryResponse->numberedOrderRows[1]->status);
+ $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber);
+ }
- function test_AddOrderRows_addInvoiceOrderRows_multiple_rows_success()
- {
- $country = "SE";
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
- $order->addOrderRow(TestUtil::createOrderRow(1.00, 1));
- $orderResponse = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
+ function test_AddOrderRows_addInvoiceOrderRows_multiple_rows_success()
+ {
+ $country = "SE";
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
+ $order->addOrderRow(TestUtil::createOrderRow(1.00, 1));
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $b_vatPercent = 12;
- $b_articleNumber = "1071e";
- $b_unit = "pcs.";
- $b_name = "B Name";
- $b_description = "B Description";
- $b_discount = 0;
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $b_vatPercent = 12;
+ $b_articleNumber = "1071e";
+ $b_unit = "pcs.";
+ $b_name = "B Name";
+ $b_description = "B Description";
+ $b_discount = 0;
- $addOrderRowsBuilder = new AddOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $addOrderRowsResponse = $addOrderRowsBuilder
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->addOrderRow(TestUtil::createOrderRow(2.00, 1))
- ->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)
- )
- ->addInvoiceOrderRows()
- ->doRequest();
+ $addOrderRowsBuilder = new AddOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $addOrderRowsResponse = $addOrderRowsBuilder
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->addOrderRow(TestUtil::createOrderRow(2.00, 1))
+ ->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)
+ )
+ ->addInvoiceOrderRows()
+ ->doRequest();
- $this->assertEquals(1, $addOrderRowsResponse->accepted);
- $createdOrderId = $orderResponse->sveaOrderId;
- ////print_r("test_AddOrderRows_addInvoiceOrderRows_multiple_rows_success: "); //print_r( $createdOrderId );
+ $this->assertEquals(1, $addOrderRowsResponse->accepted);
+ $createdOrderId = $orderResponse->sveaOrderId;
+ ////print_r("test_AddOrderRows_addInvoiceOrderRows_multiple_rows_success: "); //print_r( $createdOrderId );
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
- $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
+ $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
- ////print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
- // assert that order rows are the same
- $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[2]->quantity);
- $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[2]->amountExVat);
- $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[2]->vatPercent);
- $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[2]->articleNumber);
- $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[2]->unit);
- $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[2]->description);
- $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[2]->description);
- $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[2]->discountPercent);
- $this->assertEquals("NotDelivered", $queryResponse->numberedOrderRows[2]->status);
- $this->assertEquals(3, $queryResponse->numberedOrderRows[2]->rowNumber);
- }
+ ////print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+ // assert that order rows are the same
+ $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[2]->quantity);
+ $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[2]->amountExVat);
+ $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[2]->vatPercent);
+ $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[2]->articleNumber);
+ $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[2]->unit);
+ $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[2]->description);
+ $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[2]->description);
+ $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[2]->discountPercent);
+ $this->assertEquals("NotDelivered", $queryResponse->numberedOrderRows[2]->status);
+ $this->assertEquals(3, $queryResponse->numberedOrderRows[2]->rowNumber);
+ }
- function test_AddOrderRows_addPaymentPlanOrderRows_multiple_rows_success()
- {
- $country = "SE";
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
- $order->addOrderRow(TestUtil::createOrderRow(1000.00, 1));
- $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
+ function test_AddOrderRows_addPaymentPlanOrderRows_multiple_rows_success()
+ {
+ $country = "SE";
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
+ $order->addOrderRow(TestUtil::createOrderRow(1000.00, 1));
+ $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $b_vatPercent = 12;
- $b_articleNumber = "1071e";
- $b_unit = "pcs.";
- $b_name = "B Name";
- $b_description = "B Description";
- $b_discount = 0;
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $b_vatPercent = 12;
+ $b_articleNumber = "1071e";
+ $b_unit = "pcs.";
+ $b_name = "B Name";
+ $b_description = "B Description";
+ $b_discount = 0;
- $addOrderRowsBuilder = new AddOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $addOrderRowsResponse = $addOrderRowsBuilder
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->addOrderRow(TestUtil::createOrderRow(2.00, 1))
- ->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)
- )
- ->addPaymentPlanOrderRows()
- ->doRequest();
+ $addOrderRowsBuilder = new AddOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $addOrderRowsResponse = $addOrderRowsBuilder
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->addOrderRow(TestUtil::createOrderRow(2.00, 1))
+ ->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)
+ )
+ ->addPaymentPlanOrderRows()
+ ->doRequest();
- $this->assertEquals(1, $addOrderRowsResponse->accepted);
- $createdOrderId = $orderResponse->sveaOrderId;
- ////print_r("test_AddOrderRows_addPaymentPlanOrderRows_multiple_rows_success: "); //print_r( $createdOrderId );
+ $this->assertEquals(1, $addOrderRowsResponse->accepted);
+ $createdOrderId = $orderResponse->sveaOrderId;
+ ////print_r("test_AddOrderRows_addPaymentPlanOrderRows_multiple_rows_success: "); //print_r( $createdOrderId );
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
- $queryResponse = $queryOrderBuilder->queryPaymentPlanOrder()->doRequest();
+ $queryResponse = $queryOrderBuilder->queryPaymentPlanOrder()->doRequest();
- ////print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
- // assert that order rows are the same
- $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[2]->quantity);
- $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[2]->amountExVat);
- $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[2]->vatPercent);
- $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[2]->articleNumber);
- $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[2]->unit);
- $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[2]->description);
- $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[2]->description);
- $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[2]->discountPercent);
- $this->assertEquals("NotDelivered", $queryResponse->numberedOrderRows[2]->status);
- $this->assertEquals(3, $queryResponse->numberedOrderRows[2]->rowNumber);
- }
+ ////print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+ // assert that order rows are the same
+ $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[2]->quantity);
+ $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[2]->amountExVat);
+ $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[2]->vatPercent);
+ $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[2]->articleNumber);
+ $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[2]->unit);
+ $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[2]->description);
+ $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[2]->description);
+ $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[2]->discountPercent);
+ $this->assertEquals("NotDelivered", $queryResponse->numberedOrderRows[2]->status);
+ $this->assertEquals(3, $queryResponse->numberedOrderRows[2]->rowNumber);
+ }
- 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.00)
- ->setVatPercent(25)
- ->setDescription("Specification")
- ->setName('Product')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $orderResponse = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
+ 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.00)
+ ->setVatPercent(25)
+ ->setDescription("Specification")
+ ->setName('Product')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
- $addOrderRowsBuilder = new AddOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $addOrderRowsResponse = $addOrderRowsBuilder
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- //->setAmountExVat( 1.00 )
- ->setAmountIncVat(1.00 * 1.25)
- ->setVatPercent(25)
- ->setDescription("Specification")
- ->setName('Product')
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(4.00)
- ->setAmountIncVat(4.00 * 1.25)
- //->setVatPercent(25)
- ->setDescription("Specification")
- ->setName('Product')
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->addInvoiceOrderRows()
- ->doRequest();
+ $addOrderRowsBuilder = new AddOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $addOrderRowsResponse = $addOrderRowsBuilder
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ //->setAmountExVat( 1.00 )
+ ->setAmountIncVat(1.00 * 1.25)
+ ->setVatPercent(25)
+ ->setDescription("Specification")
+ ->setName('Product')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(4.00)
+ ->setAmountIncVat(4.00 * 1.25)
+ //->setVatPercent(25)
+ ->setDescription("Specification")
+ ->setName('Product')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->addInvoiceOrderRows()
+ ->doRequest();
- $this->assertEquals(1, $addOrderRowsResponse->accepted);
- }
+ $this->assertEquals(1, $addOrderRowsResponse->accepted);
+ }
}
-
-?>
\ No newline at end of file
diff --git a/test/IntegrationTest/BuildOrder/CancelOrderBuilderTest.php b/test/IntegrationTest/BuildOrder/CancelOrderBuilderTest.php
index 2e25a335..645d050a 100644
--- a/test/IntegrationTest/BuildOrder/CancelOrderBuilderTest.php
+++ b/test/IntegrationTest/BuildOrder/CancelOrderBuilderTest.php
@@ -15,75 +15,75 @@
class CancelOrderBuilderIntegrationTest extends \PHPUnit\Framework\TestCase
{
- // CancelOrderBuilder endpoints: cancelInvoiceOrder(), cancelPaymentPlanOrder(), cancelCardOrder()
- function test_CancelOrderBuilder_Invoice_success()
- {
- $country = "SE";
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country));
- $orderResponse = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $orderResponse->accepted);
-
- $cancelResponse = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->cancelInvoiceOrder()
- ->doRequest();
-
- $this->assertEquals(1, $cancelResponse->accepted);
- }
-
- function test_CancelOrderBuilder_PaymentPlan_success()
- {
- $country = "SE";
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(1)
- ->setAmountExVat(1000.00)
- ->setVatPercent(25)
- );
- $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
-
- $this->assertEquals(1, $orderResponse->accepted);
-
- $cancelResponse = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->cancelPaymentPlanOrder()
- ->doRequest();
-
- $this->assertEquals(1, $cancelResponse->accepted);
- }
-
- /**
- * test_manual_CancelOrderBuilder_Card_success
- *
- * run this manually after you've performed a card transaction and have set
- * the transaction status to success using the tools in the logg admin.
- */
- function test_manual_CancelOrderBuilder_Card_success()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test of cancelOrder for a card order'
- );
-
- // Set the below to match the transaction, then run the test.
- $customerrefno = "test_1396964349955";
- $transactionId = 580658;
-
- $request = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($transactionId)
- ->setCountryCode("SE")
- ->cancelCardOrder()
- ->doRequest();
-
- $this->assertInstanceOf('Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\HostedAdminResponse', $response);
-
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals($customerrefno, $response->customerrefno);
- }
+ // CancelOrderBuilder endpoints: cancelInvoiceOrder(), cancelPaymentPlanOrder(), cancelCardOrder()
+ function test_CancelOrderBuilder_Invoice_success()
+ {
+ $country = "SE";
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country));
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $cancelResponse = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->cancelInvoiceOrder()
+ ->doRequest();
+
+ $this->assertEquals(1, $cancelResponse->accepted);
+ }
+
+ function test_CancelOrderBuilder_PaymentPlan_success()
+ {
+ $country = "SE";
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer($country))
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(1)
+ ->setAmountExVat(1000.00)
+ ->setVatPercent(25)
+ );
+ $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
+
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $cancelResponse = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->cancelPaymentPlanOrder()
+ ->doRequest();
+
+ $this->assertEquals(1, $cancelResponse->accepted);
+ }
+
+ /**
+ * test_manual_CancelOrderBuilder_Card_success
+ *
+ * run this manually after you've performed a card transaction and have set
+ * the transaction status to success using the tools in the logg admin.
+ */
+ function test_manual_CancelOrderBuilder_Card_success()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test of cancelOrder for a card order'
+ );
+
+ // Set the below to match the transaction, then run the test.
+ $customerrefno = "test_1396964349955";
+ $transactionId = 580658;
+
+ $request = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($transactionId)
+ ->setCountryCode("SE")
+ ->cancelCardOrder()
+ ->doRequest();
+
+ $this->assertInstanceOf('Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\HostedAdminResponse', $response);
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals($customerrefno, $response->customerrefno);
+ }
}
diff --git a/test/IntegrationTest/BuildOrder/CancelOrderRowsBuilderTest.php b/test/IntegrationTest/BuildOrder/CancelOrderRowsBuilderTest.php
index 9cd3dfb1..61f22e9d 100644
--- a/test/IntegrationTest/BuildOrder/CancelOrderRowsBuilderTest.php
+++ b/test/IntegrationTest/BuildOrder/CancelOrderRowsBuilderTest.php
@@ -16,320 +16,318 @@
class CancelOrderRowsBuilderIntegrationTest extends \PHPUnit\Framework\TestCase
{
- protected $invoiceIdToTest;
- protected $country;
-
- protected function setUp()
- {
- $this->country = "SE";
- $this->invoiceIdToTest = 583004; // set this to the approved invoice set up by test_manual_setup_CreditOrderRows_testdata()
- }
-
- // CancelOrderRowsBuilder endpoints: cancelInvoiceOrderRows(), cancelPaymentPlanOrderRows(), cancelCardOrderRows()
- function test_CancelOrderBuilderRows_Invoice_single_row_success()
- {
- $country = "SE";
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
- $order->addOrderRow(TestUtil::createOrderRow(1.00));
- $order->addOrderRow(TestUtil::createOrderRow(2.00));
- $orderResponse = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $orderResponse->accepted);
-
- $cancelBuilder = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $cancelResponse = $cancelBuilder
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->setRowToCancel(1)
- ->cancelInvoiceOrderRows()
- ->doRequest();
-
- $this->assertEquals(1, $cancelResponse->accepted);
- }
-
- // CancelOrderRowsBuilder endpoints: cancelInvoiceOrderRows(), cancelPaymentPlanOrderRows(), cancelCardOrderRows()
- function test_CancelOrderBuilderRows_Invoice_multiple_rows_success()
- {
- $country = "SE";
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
- $order->addOrderRow(TestUtil::createOrderRow(1.00));
- $order->addOrderRow(TestUtil::createOrderRow(2.00));
- $order->addOrderRow(TestUtil::createOrderRow(3.00));
- $orderResponse = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $orderResponse->accepted);
-
- $cancelBuilder = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $cancelResponse = $cancelBuilder
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->setRowsToCancel(array(1, 2))
- ->setRowToCancel(3)
- ->cancelInvoiceOrderRows()
- ->doRequest();
-
- $this->assertEquals(1, $cancelResponse->accepted);
- }
-
- // CancelOrderRowsBuilder endpoints: cancelInvoiceOrderRows(), cancelPaymentPlanOrderRows(), cancelCardOrderRows()
- function test_CancelOrderBuilderRows_PaymentPlan_single_row_success()
- {
- $country = "SE";
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
- $order->addOrderRow(TestUtil::createOrderRow(1000.00));
- $order->addOrderRow(TestUtil::createOrderRow(2000.00));
- $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting($country))->doRequest();
-
- $this->assertEquals(1, $orderResponse->accepted);
-
- $cancelBuilder = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $cancelResponse = $cancelBuilder
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->setRowToCancel(2)
- ->cancelPaymentPlanOrderRows()
- ->doRequest();
-
- $this->assertEquals(1, $cancelResponse->accepted);
- }
-
- /**
- * test_manual_CancelOrderBuilderRows_Card_single_row_success_step_1
- *
- */
- function test_manual_CancelOrderBuilderRows_Card_single_row_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 = "https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml";
- $ipAddress = "127.0.0.1";
-
- // create order w/three rows
- $order = \Svea\WebPay\Test\TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
-
- // 2x100 @25 = 25000 (5000)
- // amount = 25000, vat = 5000
- $country = "SE";
-
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(2)
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- );
-
- $response = $order
- ->setClientOrderNumber("foo" . date('c'))
- ->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 ");
- }
-
- /**
- * test_manual_CancelOrderBuilderRows_Card_single_row_success_step_2
- *
- * run this test manually after you've performed a direct bank transaction and have gotten the transaction details needed
- */
- function test_manual_CancelOrderBuilderRows_Card_single_row_success_step_2()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'test_manual_CancelOrderBuilderRows_Card_single_row_success_step_2, step 2'
- );
-
- // 1. remove (put in a comment) the above code to enable the test
- // 2. set $createdOrderId to the transactionid from the transaction log of the request done by following the url from step 1 above.
- // 3. below is an example of the xml generated by paypage for the request in step 1 above, along with the transaction id, for reference.
-
- $createdOrderId = 590634;
- $country = "SE";
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- //print_r( $queryResponse);
- // 2x100 @25 = 25000 (5000)
- // amount = 25000, vat = 5000
- $this->assertEquals(1, $queryResponse->accepted);
- $this->assertEquals(25000, $queryResponse->amount);
- $this->assertEquals(5000, $queryResponse->vat);
- $this->assertEquals(25000, $queryResponse->authorizedamount);
-
- // cancel first order row
- $cancelBuilder = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $cancelOrderRowsBuilder = $cancelBuilder
- ->setOrderId($createdOrderId)
- ->setCountryCode($country)
- ->setRowToCancel(1)
- ->addNumberedOrderRows($queryResponse->numberedOrderRows);
- $cancelOrderRowsResponse = $cancelOrderRowsBuilder->cancelCardOrderRows()->doRequest();
- $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
-
- $query2Response = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- //print_r( $query2Response);
- // 2x100 @25 = 25000 (5000) <- credited
- // amount = 25000 -25000, vat = 5000
- $this->assertEquals(1, $query2Response->accepted);
- $this->assertEquals(1, $query2Response->accepted);
- $this->assertEquals(25000, $query2Response->amount);
- $this->assertEquals(5000, $query2Response->vat);
- $this->assertEquals(00000, $query2Response->authorizedamount);
- $this->assertEquals("ANNULLED", $query2Response->status);
- }
-
- /**
- * 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 = \Svea\WebPay\Test\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.00)
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->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 ");
- }
-
- /**
- * test_manual_CancelOrderBuilderRows_Card_single_row_success_step_2
- *
- * run this test manually after you've performed a direct bank transaction and have gotten the transaction details needed
- */
- function test_manual_CancelOrderBuilderRows_Card_multiple_rows_success_step_2()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'test_manual_CancelOrderBuilderRows_Card_single_row_success_step_2, step 2'
- );
-
- // 1. remove (put in a comment) the above code to enable the test
- // 2. set $createdOrderId to the transactionid from the transaction log of the request done by following the url from step 1 above.
- // 3. below is an example of the xml generated by paypage for the request in step 1 above, along with the transaction id, for reference.
-
- $createdOrderId = 583620;
- $country = "SE";
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- //print_r( $queryResponse);
- // 2x100 @25 = 25000 (5000)
- // 1x100 @25 = 12500 (2500)
- // 1x100 @12 = 11200 (1200)
- // amount = 48700, vat = 8700
- $this->assertEquals(1, $queryResponse->accepted);
- $this->assertEquals(48700, $queryResponse->amount);
- $this->assertEquals(8700, $queryResponse->vat);
- $this->assertEquals(48700, $queryResponse->authorizedamount);
-
- // cancel second, third order row
- $cancelBuilder = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $cancelOrderRowsBuilder = $cancelBuilder
- ->setOrderId($createdOrderId)
- ->setCountryCode($country)
- ->setRowsToCancel(array(2, 3))
- ->addNumberedOrderRows($queryResponse->numberedOrderRows);
- $cancelOrderRowsResponse = $cancelOrderRowsBuilder->cancelCardOrderRows()->doRequest();
- $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
-
- $query2Response = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- //print_r( $query2Response);
- // 2x100 @25 = 25000 (5000)
- // 1x100 @25 = 12500 (2500) <- credited
- // 1x100 @12 = 11200 (1200) <- credited
- // amount = 48700-12500-11200, vat = 8700
- $this->assertEquals(1, $query2Response->accepted);
- $this->assertEquals(1, $query2Response->accepted);
- $this->assertEquals(48700, $query2Response->amount);
- $this->assertEquals(8700, $query2Response->vat);
- $this->assertEquals(25000, $query2Response->authorizedamount);
- $this->assertEquals("AUTHORIZED", $query2Response->status);
- }
+ protected $invoiceIdToTest;
+ protected $country;
+
+ protected function setUp()
+ {
+ $this->country = "SE";
+ $this->invoiceIdToTest = 583004; // set this to the approved invoice set up by test_manual_setup_CreditOrderRows_testdata()
+ }
+
+ // CancelOrderRowsBuilder endpoints: cancelInvoiceOrderRows(), cancelPaymentPlanOrderRows(), cancelCardOrderRows()
+ function test_CancelOrderBuilderRows_Invoice_single_row_success()
+ {
+ $country = "SE";
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
+ $order->addOrderRow(TestUtil::createOrderRow(1.00));
+ $order->addOrderRow(TestUtil::createOrderRow(2.00));
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $cancelBuilder = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $cancelResponse = $cancelBuilder
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->setRowToCancel(1)
+ ->cancelInvoiceOrderRows()
+ ->doRequest();
+
+ $this->assertEquals(1, $cancelResponse->accepted);
+ }
+
+ // CancelOrderRowsBuilder endpoints: cancelInvoiceOrderRows(), cancelPaymentPlanOrderRows(), cancelCardOrderRows()
+ function test_CancelOrderBuilderRows_Invoice_multiple_rows_success()
+ {
+ $country = "SE";
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
+ $order->addOrderRow(TestUtil::createOrderRow(1.00));
+ $order->addOrderRow(TestUtil::createOrderRow(2.00));
+ $order->addOrderRow(TestUtil::createOrderRow(3.00));
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $cancelBuilder = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $cancelResponse = $cancelBuilder
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->setRowsToCancel([1, 2])
+ ->setRowToCancel(3)
+ ->cancelInvoiceOrderRows()
+ ->doRequest();
+
+ $this->assertEquals(1, $cancelResponse->accepted);
+ }
+
+ // CancelOrderRowsBuilder endpoints: cancelInvoiceOrderRows(), cancelPaymentPlanOrderRows(), cancelCardOrderRows()
+ function test_CancelOrderBuilderRows_PaymentPlan_single_row_success()
+ {
+ $country = "SE";
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
+ $order->addOrderRow(TestUtil::createOrderRow(1000.00));
+ $order->addOrderRow(TestUtil::createOrderRow(2000.00));
+ $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting($country))->doRequest();
+
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $cancelBuilder = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $cancelResponse = $cancelBuilder
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->setRowToCancel(2)
+ ->cancelPaymentPlanOrderRows()
+ ->doRequest();
+
+ $this->assertEquals(1, $cancelResponse->accepted);
+ }
+
+ /**
+ * test_manual_CancelOrderBuilderRows_Card_single_row_success_step_1
+ *
+ */
+ function test_manual_CancelOrderBuilderRows_Card_single_row_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 = "https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml";
+ $ipAddress = "127.0.0.1";
+
+ // create order w/three rows
+ $order = \Svea\WebPay\Test\TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
+
+ // 2x100 @25 = 25000 (5000)
+ // amount = 25000, vat = 5000
+ $country = "SE";
+
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(2)
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ );
+
+ $response = $order
+ ->setClientOrderNumber("foo" . date('c'))
+ ->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 ");
+ }
+
+ /**
+ * test_manual_CancelOrderBuilderRows_Card_single_row_success_step_2
+ *
+ * run this test manually after you've performed a direct bank transaction and have gotten the transaction details needed
+ */
+ function test_manual_CancelOrderBuilderRows_Card_single_row_success_step_2()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'test_manual_CancelOrderBuilderRows_Card_single_row_success_step_2, step 2'
+ );
+
+ // 1. remove (put in a comment) the above code to enable the test
+ // 2. set $createdOrderId to the transactionid from the transaction log of the request done by following the url from step 1 above.
+ // 3. below is an example of the xml generated by paypage for the request in step 1 above, along with the transaction id, for reference.
+
+ $createdOrderId = 590634;
+ $country = "SE";
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ //print_r( $queryResponse);
+ // 2x100 @25 = 25000 (5000)
+ // amount = 25000, vat = 5000
+ $this->assertEquals(1, $queryResponse->accepted);
+ $this->assertEquals(25000, $queryResponse->amount);
+ $this->assertEquals(5000, $queryResponse->vat);
+ $this->assertEquals(25000, $queryResponse->authorizedamount);
+
+ // cancel first order row
+ $cancelBuilder = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $cancelOrderRowsBuilder = $cancelBuilder
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country)
+ ->setRowToCancel(1)
+ ->addNumberedOrderRows($queryResponse->numberedOrderRows);
+ $cancelOrderRowsResponse = $cancelOrderRowsBuilder->cancelCardOrderRows()->doRequest();
+ $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
+
+ $query2Response = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ //print_r( $query2Response);
+ // 2x100 @25 = 25000 (5000) <- credited
+ // amount = 25000 -25000, vat = 5000
+ $this->assertEquals(1, $query2Response->accepted);
+ $this->assertEquals(1, $query2Response->accepted);
+ $this->assertEquals(25000, $query2Response->amount);
+ $this->assertEquals(5000, $query2Response->vat);
+ $this->assertEquals(00000, $query2Response->authorizedamount);
+ $this->assertEquals("ANNULLED", $query2Response->status);
+ }
+
+ /**
+ * 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 = \Svea\WebPay\Test\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.00)
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->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 ");
+ }
+
+ /**
+ * test_manual_CancelOrderBuilderRows_Card_single_row_success_step_2
+ *
+ * run this test manually after you've performed a direct bank transaction and have gotten the transaction details needed
+ */
+ function test_manual_CancelOrderBuilderRows_Card_multiple_rows_success_step_2()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'test_manual_CancelOrderBuilderRows_Card_single_row_success_step_2, step 2'
+ );
+
+ // 1. remove (put in a comment) the above code to enable the test
+ // 2. set $createdOrderId to the transactionid from the transaction log of the request done by following the url from step 1 above.
+ // 3. below is an example of the xml generated by paypage for the request in step 1 above, along with the transaction id, for reference.
+
+ $createdOrderId = 583620;
+ $country = "SE";
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ //print_r( $queryResponse);
+ // 2x100 @25 = 25000 (5000)
+ // 1x100 @25 = 12500 (2500)
+ // 1x100 @12 = 11200 (1200)
+ // amount = 48700, vat = 8700
+ $this->assertEquals(1, $queryResponse->accepted);
+ $this->assertEquals(48700, $queryResponse->amount);
+ $this->assertEquals(8700, $queryResponse->vat);
+ $this->assertEquals(48700, $queryResponse->authorizedamount);
+
+ // cancel second, third order row
+ $cancelBuilder = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $cancelOrderRowsBuilder = $cancelBuilder
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country)
+ ->setRowsToCancel([2, 3])
+ ->addNumberedOrderRows($queryResponse->numberedOrderRows);
+ $cancelOrderRowsResponse = $cancelOrderRowsBuilder->cancelCardOrderRows()->doRequest();
+ $this->assertEquals(1, $cancelOrderRowsResponse->accepted);
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
+
+ $query2Response = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ //print_r( $query2Response);
+ // 2x100 @25 = 25000 (5000)
+ // 1x100 @25 = 12500 (2500) <- credited
+ // 1x100 @12 = 11200 (1200) <- credited
+ // amount = 48700-12500-11200, vat = 8700
+ $this->assertEquals(1, $query2Response->accepted);
+ $this->assertEquals(1, $query2Response->accepted);
+ $this->assertEquals(48700, $query2Response->amount);
+ $this->assertEquals(8700, $query2Response->vat);
+ $this->assertEquals(25000, $query2Response->authorizedamount);
+ $this->assertEquals("AUTHORIZED", $query2Response->status);
+ }
}
-
-?>
\ No newline at end of file
diff --git a/test/IntegrationTest/BuildOrder/CreateOrderBuilderTest.php b/test/IntegrationTest/BuildOrder/CreateOrderBuilderTest.php
index 290efbb4..b2301bca 100644
--- a/test/IntegrationTest/BuildOrder/CreateOrderBuilderTest.php
+++ b/test/IntegrationTest/BuildOrder/CreateOrderBuilderTest.php
@@ -18,66 +18,63 @@
class CreateOrderBuilderIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public function test_createOrder_Invoice_SE_Accepted()
- {
- $order = TestUtil::createOrder();
- $response = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $response->accepted);
- }
-
- public function test_createOrder_Paymentplan_SE_Accepted()
- {
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(1)
- ->setAmountExVat(1000.00)
- ->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_createCheckoutOrder_ValidationCallbackUri_Accepted()
- {
- $validationCallbackUri = 'http://localhost:51898/validation-callback';
- $myConfig = ConfigurationService::getTestConfig();
- $locale = 'sv-Se';
- $orderBuilder = WebPay::checkout($myConfig);
- $orderBuilder->setCountryCode('SE')// customer country, we recommend basing this on the customer billing address
- ->setCurrency('SEK')
- ->setClientOrderNumber(rand(270000, 670000))
- ->setCheckoutUri('http://localhost:51925/')
- ->setConfirmationUri('http://localhost:51925/checkout/confirm')
- ->setPushUri('https://svea.com/push.aspx?sid=123&svea_order=123')
- ->setTermsUri('http://localhost:51898/terms')
- ->setValidationCallbackUri($validationCallbackUri)
- ->setLocale($locale);
- $firstBoughtItem = WebPayItem::orderRow()
- ->setAmountIncVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setArticleNumber('123')
- ->setTemporaryReference('230')
- ->setName('Fork');
- $orderBuilder->addOrderRow($firstBoughtItem);
- $response = $orderBuilder->createOrder();
- $this->assertEquals($validationCallbackUri, $response['MerchantSettings']['CheckoutValidationCallBackUri']);
- }
-
- // CreateOrderBuilder card payment method
- // see Svea\WebPay\Test\IntegrationTest\HostedService\Payment\CardPaymentURLIntegrationTest->test_manual_CardPayment_getPaymentUrl()
-
- // CreateOrderBuilder direct bank payment method //TODO
+ public function test_createOrder_Invoice_SE_Accepted()
+ {
+ $order = TestUtil::createOrder();
+ $response = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+ }
+
+ public function test_createOrder_Paymentplan_SE_Accepted()
+ {
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(1)
+ ->setAmountExVat(1000.00)
+ ->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_createCheckoutOrder_ValidationCallbackUri_Accepted()
+ {
+ $validationCallbackUri = 'http://localhost:51898/validation-callback';
+ $myConfig = ConfigurationService::getTestConfig();
+ $locale = 'sv-Se';
+ $orderBuilder = WebPay::checkout($myConfig);
+ $orderBuilder->setCountryCode('SE')// customer country, we recommend basing this on the customer billing address
+ ->setCurrency('SEK')
+ ->setClientOrderNumber(rand(270000, 670000))
+ ->setCheckoutUri('http://localhost:51925/')
+ ->setConfirmationUri('http://localhost:51925/checkout/confirm')
+ ->setPushUri('https://svea.com/push.aspx?sid=123&svea_order=123')
+ ->setTermsUri('http://localhost:51898/terms')
+ ->setValidationCallbackUri($validationCallbackUri)
+ ->setLocale($locale);
+ $firstBoughtItem = WebPayItem::orderRow()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setArticleNumber('123')
+ ->setTemporaryReference('230')
+ ->setName('Fork');
+ $orderBuilder->addOrderRow($firstBoughtItem);
+ $response = $orderBuilder->createOrder();
+ $this->assertEquals($validationCallbackUri, $response['MerchantSettings']['CheckoutValidationCallBackUri']);
+ }
+
+ // CreateOrderBuilder card payment method
+ // see Svea\WebPay\Test\IntegrationTest\HostedService\Payment\CardPaymentURLIntegrationTest->test_manual_CardPayment_getPaymentUrl()
+
+ // CreateOrderBuilder direct bank payment method //TODO
}
-
-
-?>
\ No newline at end of file
diff --git a/test/IntegrationTest/BuildOrder/CreditOrderRowsBuilderTest.php b/test/IntegrationTest/BuildOrder/CreditOrderRowsBuilderTest.php
index befef0b7..1ce986bf 100644
--- a/test/IntegrationTest/BuildOrder/CreditOrderRowsBuilderTest.php
+++ b/test/IntegrationTest/BuildOrder/CreditOrderRowsBuilderTest.php
@@ -19,546 +19,544 @@
class CreditOrderRowsBuilderIntegrationTest extends \PHPUnit\Framework\TestCase
{
- protected $invoiceIdToTest;
- protected $country;
-
- protected function setUp()
- {
- $this->country = "SE";
- $this->invoiceIdToTest = 1028204; // set this to the approved invoice set up by test_manual_setup_CreditOrderRows_testdata()
- $this->successfulTransactionToTest = 583628; // set to a card transaction w/status success, see test_manual_setup_CreditCardOrderRows_testdata
- }
-
- // CreditCardOrderRows
-
- 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.00)
- ->setVatPercent(25)
- ->setDescription("A Specification")
- ->setName('A Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("2")
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->setVatPercent(12)
- ->setDescription("B Specification")
- ->setName('B Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("3")
- ->setQuantity(1)
- ->setAmountExVat(1.00)
- ->setVatPercent(25)
- ->setDescription("C Specification")
- ->setName('C Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("4")
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->setVatPercent(0)
- ->setDescription("D Specification")
- ->setName('D Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("5")
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->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(ConfigurationService::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");
-
- }
-
- function test_CreditOrderRows_creditInvoiceOrderRows_single_setRowToCredit_success()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'first set up approved invoice and enter id in setUp()'
- );
-
- $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $creditOrderRowsResponse = $creditOrderRowsRequest
- ->setInvoiceId($this->invoiceIdToTest)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode($this->country)
- ->setRowToCredit(1)
- ->creditInvoiceOrderRows()
- ->doRequest();
-
- //print_r("\ntest_CreditOrderRows_creditInvoiceOrderRows_single_row_success:\n");
- //print_r( $creditOrderRowsResponse );
- $this->assertEquals(1, $creditOrderRowsResponse->accepted);
- $this->assertEquals(-125.00, $creditOrderRowsResponse->amount);
- }
-
- function test_CreditOrderRows_creditInvoiceOrderRows_multiple_setRowsToCredit_success()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'first set up approved invoice and enter id in setUp()'
- );
-
- $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $creditOrderRowsResponse = $creditOrderRowsRequest
- ->setInvoiceId($this->invoiceIdToTest)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode($this->country)
- ->setRowsToCredit(array(2, 3))
- ->creditInvoiceOrderRows()
- ->doRequest();
-
- //print_r("test_CreditOrderRows_creditInvoiceOrderRows_multiple_setRowsToCredit_success:\n");
- //print_r( $creditOrderRowsResponse );
- $this->assertEquals(1, $creditOrderRowsResponse->accepted);
- $this->assertEquals(-113.25, $creditOrderRowsResponse->amount);
- }
-
- function test_CreditOrderRows_creditInvoiceOrderRows_single_addCreditOrderRow_success()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'first set up approved invoice and enter id in setUp()'
- );
-
- $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $creditOrderRowsResponse = $creditOrderRowsRequest
- ->setInvoiceId($this->invoiceIdToTest)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode($this->country)
- ->addCreditOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("101")
- ->setQuantity(1)
- ->setAmountExVat(10.00)
- ->setVatPercent(25)
- ->setDescription("101 Specification")
- ->setName('101 Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->creditInvoiceOrderRows()
- ->doRequest();
-
- //print_r("test_CreditOrderRows_creditInvoiceOrderRows_single_addCreditOrderRow_success:\n");
- //print_r( $creditOrderRowsResponse );
- $this->assertEquals(1, $creditOrderRowsResponse->accepted);
- $this->assertEquals(-12.50, $creditOrderRowsResponse->amount);
- }
-
- function test_CreditOrderRows_creditInvoiceOrderRows_multiple_addCreditOrderRow_success()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'first set up approved invoice and enter id in setUp()'
- );
-
- $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $creditOrderRowsResponse = $creditOrderRowsRequest
- ->setInvoiceId($this->invoiceIdToTest)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode($this->country)
- ->addCreditOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("101")
- ->setQuantity(1)
- ->setAmountExVat(10.00)
- ->setVatPercent(25)
- ->setDescription("101 Specification")
- ->setName('101 Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->addCreditOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("101")
- ->setQuantity(1)
- ->setAmountExVat(10.00)
- ->setVatPercent(25)
- ->setDescription("101 Specification")
- ->setName('101 Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->creditInvoiceOrderRows()
- ->doRequest();
-
- //print_r("test_CreditOrderRows_creditInvoiceOrderRows_multiple_addCreditOrderRow_success:\n");
- //print_r( $creditOrderRowsResponse );
- $this->assertEquals(1, $creditOrderRowsResponse->accepted);
- $this->assertEquals(-25.00, $creditOrderRowsResponse->amount);
- }
-
- function test_CreditOrderRows_creditInvoiceOrderRows_addCreditOrderRow_and_setRowToCredit_success()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'first set up approved invoice and enter id in setUp()'
- );
-
- $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $creditOrderRowsResponse = $creditOrderRowsRequest
- ->setInvoiceId($this->invoiceIdToTest)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode($this->country)
- ->setRowToCredit(4)
- ->addCreditOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("104")
- ->setQuantity(1)
- ->setAmountExVat(10.00)
- ->setVatPercent(25)
- ->setDescription("104 Specification")
- ->setName('104 Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->creditInvoiceOrderRows()
- ->doRequest();
-
- //print_r("test_CreditOrderRows_creditInvoiceOrderRows_addCreditOrderRow_and_setRowToCredit_success:\n");
- //print_r( $creditOrderRowsResponse );
- $this->assertEquals(1, $creditOrderRowsResponse->accepted);
- $this->assertEquals(-112.50, $creditOrderRowsResponse->amount);
- }
-
-
- function test_CreditOrderRows_creditInvoiceOrderRows_credit_amount_exceeds_original_order_fails()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'first set up approved invoice and enter id in setUp()'
- );
-
- $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $creditOrderRowsResponse = $creditOrderRowsRequest
- ->setInvoiceId($this->invoiceIdToTest)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode($this->country)
- ->setRowToCredit(5)
- ->creditInvoiceOrderRows()
- ->doRequest();
-
- //print_r("test_CreditOrderRows_creditInvoiceOrderRows_credit_amount_exceeds_original_order_fails:\n");
- //print_r( $creditOrderRowsResponse );
- $this->assertEquals(0, $creditOrderRowsResponse->accepted);
- $this->assertEquals(24502, $creditOrderRowsResponse->resultcode);
- $this->assertEquals("Credit amount exceeds invoiced amount", $creditOrderRowsResponse->errormessage);
- }
-
- // CreditCardOrderRows
-
- function test_manual_setup_CreditCardOrderRows_testdata()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- '1. test_manual_setup_CreditCardOrderRows_testdata -- run this first to setup order for CreditOrderRows tests to work with.
- Run once, then make sure to approve the invoice in the admin interface. Then uncomment and run CreditOrderRows tests.
-
- 2. verktyg / confirm, merchant 1130, use this xml w/correct transactionid, todays date => status = CONFIRMED
-
- 583004
- 2014-06-02
-
-
- 3. schemalagda jobb / dailycapture kortcert task => status = SUCCESS'
-
- );
-
- $orderLanguage = "sv";
- $returnUrl = "http://127.0.0.1";
- $ipAddress = "127.0.0.1";
-
- // create order
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->setCountryCode($this->country)
- ->setCurrency("SEK")
- ->setCustomerReference("CreditCardOrderRows_testdata" . date('c'))
- ->setClientOrderNumber("CreditCardOrderRows_testdata" . date('c'))
- ->setOrderDate(date('c'));
-
- $order->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("194605092222")
- ->setBirthDate(1946, 05, 9)
- ->setName("Tess T", "Persson")
- ->setStreetAddress("Testgatan", 1)
- ->setCoAddress("c/o Eriksson, Erik")
- ->setLocality("Stan")
- ->setZipCode("99999")
- ->setIpAddress($ipAddress)
- );
-
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setDescription("A Specification")
- ->setName('A Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("2")
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->setVatPercent(12)
- ->setDescription("B Specification")
- ->setName('B Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("3")
- ->setQuantity(1)
- ->setAmountExVat(1.00)
- ->setVatPercent(25)
- ->setDescription("C Specification")
- ->setName('C Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("4")
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->setVatPercent(0)
- ->setDescription("D Specification")
- ->setName('D Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("5")
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->setVatPercent(0)
- ->setDescription("E Specification")
- ->setName('E Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
-
- $orderResponse = $order
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setPayPageLanguage($orderLanguage)
- ->setReturnUrl($returnUrl)
- ->getPaymentUrl();
-
- //print_r( $orderResponse );
- $this->assertEquals(1, $orderResponse->accepted);
-
- //print_r( "test_manual_setup_CreditCardOrderRows_testdata finished, now go to " . $orderResponse->testurl ." and complete payment.\n" );
- }
-
- function test_CreditOrderRows_CreditCardOrderRows_credit_single_row_using_addNumberedOrderRows_setRowToCredit_success()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'first set up confirmed transaction and enter id in setUp()'
- );
-
- // query orderrows to pass in creditOrderRows->setNumberedOrderRows()
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country);
-
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- //print_r( $queryResponse );
- $this->assertEquals(1, $queryResponse->accepted);
-
- $creditOrderRowsBuilder = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $creditOrderRowsRequest = $creditOrderRowsBuilder
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country)
- ->setRowToCredit(1)
- ->addNumberedOrderRows($queryResponse->numberedOrderRows)// use the queried order rows as base for what amount to credit
- ->creditCardOrderRows();
- $creditOrderRowsResponse = $creditOrderRowsRequest->doRequest();
-
- //print_r("test_CreditOrderRows_CreditCardOrderRows_credit_single_row_using_addNumberedOrderRows_setRowToCredit_success:\n");
- //print_r( $creditOrderRowsResponse );
-
- $this->assertEquals(1, $creditOrderRowsResponse->accepted);
-
- // query orderrows again
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country);
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- $this->assertEquals(1, $queryResponse->accepted);
- //print_r( $queryResponse );
- // credit 100 @25 *100 = 12500 => 12500
- $this->assertEquals(12500, $queryResponse->creditedamount);
- }
-
- function test_CreditOrderRows_CreditCardOrderRows_credit_multiple_rows_using_addNumberedOrderRows_setRowToCredit_success()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'first set up confirmed transaction and enter id in setUp()'
- );
-
- // query orderrows to pass in creditOrderRows->setNumberedOrderRows()
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country);
-
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- //print_r( $queryResponse );
- $this->assertEquals(1, $queryResponse->accepted);
-
- $creditOrderRowsBuilder = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $creditOrderRowsRequest = $creditOrderRowsBuilder
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country)
- ->setRowsToCredit(array(2, 3))
- ->addNumberedOrderRows($queryResponse->numberedOrderRows)// use the queried order rows as base for what amount to credit
- ->creditCardOrderRows();
- $creditOrderRowsResponse = $creditOrderRowsRequest->doRequest();
-
- //print_r("test_CreditOrderRows_CreditCardOrderRows_credit_multiple_rows_using_addNumberedOrderRows_setRowToCredit_success:\n");
- //print_r( $creditOrderRowsResponse );
-
- $this->assertEquals(1, $creditOrderRowsResponse->accepted);
-
- // query orderrows again
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country);
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- $this->assertEquals(1, $queryResponse->accepted);
- //print_r( $queryResponse );
- // credited 12500
- // credit 100 @12 *100 = 11200
- // credit 1 @25 *100 = 125 => 23825
- $this->assertEquals(23825, $queryResponse->creditedamount);
- }
-
- function test_CreditOrderRows_CreditCardOrderRows_credit_single_row_and_new_row_using_addNewCreditRow_success()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'first set up confirmed transaction and enter id in setUp()'
- );
-
- // query orderrows to pass in creditOrderRows->setNumberedOrderRows()
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country);
-
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- //print_r( $queryResponse );
- $this->assertEquals(1, $queryResponse->accepted);
-
- $creditOrderRowsBuilder = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $creditOrderRowsRequest = $creditOrderRowsBuilder
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country)
- ->addNumberedOrderRows($queryResponse->numberedOrderRows)// use the queried order rows as base for what amount to credit
- ->setRowToCredit(4)
- ->addCreditOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("104")
- ->setQuantity(1)
- ->setAmountExVat(10.00)
- ->setVatPercent(25)
- ->setDescription("104 Specification")
- ->setName('104 Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->creditCardOrderRows();
- $creditOrderRowsResponse = $creditOrderRowsRequest->doRequest();
-
- //print_r("test_CreditOrderRows_CreditCardOrderRows_credit_single_row_and_new_row_using_addNewCreditRow_success:\n");
- //print_r( $creditOrderRowsResponse );
-
- $this->assertEquals(1, $creditOrderRowsResponse->accepted);
-
- // query orderrows again
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country);
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- $this->assertEquals(1, $queryResponse->accepted);
- //print_r( $queryResponse );
- // credited 23825
- // credit 100 @0 *100 = 10000
- // credit 10 @25 *100 = 1250 => 35075
- $this->assertEquals(35075, $queryResponse->creditedamount);
- }
-
- function test_CreditOrderRows_creditCardOrderRows_addCreditOrderRow_setRowToCredit_exceeds_original_order_fails()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'first set up approved invoice and enter id in setUp()'
- );
-
- // query orderrows to pass in creditOrderRows->setNumberedOrderRows()
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country);
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- //print_r( $queryResponse );
- $this->assertEquals(1, $queryResponse->accepted);
-
- $creditOrderRowsBuilder = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $creditOrderRowsRequest = $creditOrderRowsBuilder
- ->setOrderId($this->successfulTransactionToTest)
- ->setCountryCode($this->country)
- ->addNumberedOrderRows($queryResponse->numberedOrderRows)// use the queried order rows as base for what amount to credit
- ->setRowToCredit(5)
- ->creditCardOrderRows();
- $creditOrderRowsResponse = $creditOrderRowsRequest->doRequest();
-
- //print_r("test_CreditOrderRows_creditCardOrderRows_addCreditOrderRow_setRowToCredit_exceeds_original_order_fails:\n");
- //print_r( $creditOrderRowsResponse );
- $this->assertEquals(0, $creditOrderRowsResponse->accepted);
- $this->assertEquals("119 (ILLEGAL_CREDITED_AMOUNT)", $creditOrderRowsResponse->resultcode);
- }
+ protected $invoiceIdToTest;
+ protected $country;
+
+ protected function setUp()
+ {
+ $this->country = "SE";
+ $this->invoiceIdToTest = 1028204; // set this to the approved invoice set up by test_manual_setup_CreditOrderRows_testdata()
+ $this->successfulTransactionToTest = 583628; // set to a card transaction w/status success, see test_manual_setup_CreditCardOrderRows_testdata
+ }
+
+ // CreditCardOrderRows
+
+ 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.00)
+ ->setVatPercent(25)
+ ->setDescription("A Specification")
+ ->setName('A Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("2")
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->setVatPercent(12)
+ ->setDescription("B Specification")
+ ->setName('B Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("3")
+ ->setQuantity(1)
+ ->setAmountExVat(1.00)
+ ->setVatPercent(25)
+ ->setDescription("C Specification")
+ ->setName('C Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("4")
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->setVatPercent(0)
+ ->setDescription("D Specification")
+ ->setName('D Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("5")
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->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(ConfigurationService::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");
+
+ }
+
+ function test_CreditOrderRows_creditInvoiceOrderRows_single_setRowToCredit_success()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'first set up approved invoice and enter id in setUp()'
+ );
+
+ $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $creditOrderRowsResponse = $creditOrderRowsRequest
+ ->setInvoiceId($this->invoiceIdToTest)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode($this->country)
+ ->setRowToCredit(1)
+ ->creditInvoiceOrderRows()
+ ->doRequest();
+
+ //print_r("\ntest_CreditOrderRows_creditInvoiceOrderRows_single_row_success:\n");
+ //print_r( $creditOrderRowsResponse );
+ $this->assertEquals(1, $creditOrderRowsResponse->accepted);
+ $this->assertEquals(-125.00, $creditOrderRowsResponse->amount);
+ }
+
+ function test_CreditOrderRows_creditInvoiceOrderRows_multiple_setRowsToCredit_success()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'first set up approved invoice and enter id in setUp()'
+ );
+
+ $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $creditOrderRowsResponse = $creditOrderRowsRequest
+ ->setInvoiceId($this->invoiceIdToTest)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode($this->country)
+ ->setRowsToCredit([2, 3])
+ ->creditInvoiceOrderRows()
+ ->doRequest();
+
+ //print_r("test_CreditOrderRows_creditInvoiceOrderRows_multiple_setRowsToCredit_success:\n");
+ //print_r( $creditOrderRowsResponse );
+ $this->assertEquals(1, $creditOrderRowsResponse->accepted);
+ $this->assertEquals(-113.25, $creditOrderRowsResponse->amount);
+ }
+
+ function test_CreditOrderRows_creditInvoiceOrderRows_single_addCreditOrderRow_success()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'first set up approved invoice and enter id in setUp()'
+ );
+
+ $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $creditOrderRowsResponse = $creditOrderRowsRequest
+ ->setInvoiceId($this->invoiceIdToTest)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode($this->country)
+ ->addCreditOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("101")
+ ->setQuantity(1)
+ ->setAmountExVat(10.00)
+ ->setVatPercent(25)
+ ->setDescription("101 Specification")
+ ->setName('101 Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->creditInvoiceOrderRows()
+ ->doRequest();
+
+ //print_r("test_CreditOrderRows_creditInvoiceOrderRows_single_addCreditOrderRow_success:\n");
+ //print_r( $creditOrderRowsResponse );
+ $this->assertEquals(1, $creditOrderRowsResponse->accepted);
+ $this->assertEquals(-12.50, $creditOrderRowsResponse->amount);
+ }
+
+ function test_CreditOrderRows_creditInvoiceOrderRows_multiple_addCreditOrderRow_success()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'first set up approved invoice and enter id in setUp()'
+ );
+
+ $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $creditOrderRowsResponse = $creditOrderRowsRequest
+ ->setInvoiceId($this->invoiceIdToTest)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode($this->country)
+ ->addCreditOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("101")
+ ->setQuantity(1)
+ ->setAmountExVat(10.00)
+ ->setVatPercent(25)
+ ->setDescription("101 Specification")
+ ->setName('101 Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->addCreditOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("101")
+ ->setQuantity(1)
+ ->setAmountExVat(10.00)
+ ->setVatPercent(25)
+ ->setDescription("101 Specification")
+ ->setName('101 Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->creditInvoiceOrderRows()
+ ->doRequest();
+
+ //print_r("test_CreditOrderRows_creditInvoiceOrderRows_multiple_addCreditOrderRow_success:\n");
+ //print_r( $creditOrderRowsResponse );
+ $this->assertEquals(1, $creditOrderRowsResponse->accepted);
+ $this->assertEquals(-25.00, $creditOrderRowsResponse->amount);
+ }
+
+ function test_CreditOrderRows_creditInvoiceOrderRows_addCreditOrderRow_and_setRowToCredit_success()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'first set up approved invoice and enter id in setUp()'
+ );
+
+ $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $creditOrderRowsResponse = $creditOrderRowsRequest
+ ->setInvoiceId($this->invoiceIdToTest)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode($this->country)
+ ->setRowToCredit(4)
+ ->addCreditOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("104")
+ ->setQuantity(1)
+ ->setAmountExVat(10.00)
+ ->setVatPercent(25)
+ ->setDescription("104 Specification")
+ ->setName('104 Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->creditInvoiceOrderRows()
+ ->doRequest();
+
+ //print_r("test_CreditOrderRows_creditInvoiceOrderRows_addCreditOrderRow_and_setRowToCredit_success:\n");
+ //print_r( $creditOrderRowsResponse );
+ $this->assertEquals(1, $creditOrderRowsResponse->accepted);
+ $this->assertEquals(-112.50, $creditOrderRowsResponse->amount);
+ }
+
+
+ function test_CreditOrderRows_creditInvoiceOrderRows_credit_amount_exceeds_original_order_fails()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'first set up approved invoice and enter id in setUp()'
+ );
+
+ $creditOrderRowsRequest = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $creditOrderRowsResponse = $creditOrderRowsRequest
+ ->setInvoiceId($this->invoiceIdToTest)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode($this->country)
+ ->setRowToCredit(5)
+ ->creditInvoiceOrderRows()
+ ->doRequest();
+
+ //print_r("test_CreditOrderRows_creditInvoiceOrderRows_credit_amount_exceeds_original_order_fails:\n");
+ //print_r( $creditOrderRowsResponse );
+ $this->assertEquals(0, $creditOrderRowsResponse->accepted);
+ $this->assertEquals(24502, $creditOrderRowsResponse->resultcode);
+ $this->assertEquals("Credit amount exceeds invoiced amount", $creditOrderRowsResponse->errormessage);
+ }
+
+ // CreditCardOrderRows
+
+ function test_manual_setup_CreditCardOrderRows_testdata()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ '1. test_manual_setup_CreditCardOrderRows_testdata -- run this first to setup order for CreditOrderRows tests to work with.
+ Run once, then make sure to approve the invoice in the admin interface. Then uncomment and run CreditOrderRows tests.
+
+ 2. verktyg / confirm, merchant 1130, use this xml w/correct transactionid, todays date => status = CONFIRMED
+
+ 583004
+ 2014-06-02
+
+
+ 3. schemalagda jobb / dailycapture kortcert task => status = SUCCESS'
+
+ );
+
+ $orderLanguage = "sv";
+ $returnUrl = "http://127.0.0.1";
+ $ipAddress = "127.0.0.1";
+
+ // create order
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->setCountryCode($this->country)
+ ->setCurrency("SEK")
+ ->setCustomerReference("CreditCardOrderRows_testdata" . date('c'))
+ ->setClientOrderNumber("CreditCardOrderRows_testdata" . date('c'))
+ ->setOrderDate(date('c'));
+
+ $order->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("194605092222")
+ ->setBirthDate(1946, 05, 9)
+ ->setName("Tess T", "Persson")
+ ->setStreetAddress("Testgatan", 1)
+ ->setCoAddress("c/o Eriksson, Erik")
+ ->setLocality("Stan")
+ ->setZipCode("99999")
+ ->setIpAddress($ipAddress)
+ );
+
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setDescription("A Specification")
+ ->setName('A Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("2")
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->setVatPercent(12)
+ ->setDescription("B Specification")
+ ->setName('B Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("3")
+ ->setQuantity(1)
+ ->setAmountExVat(1.00)
+ ->setVatPercent(25)
+ ->setDescription("C Specification")
+ ->setName('C Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("4")
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->setVatPercent(0)
+ ->setDescription("D Specification")
+ ->setName('D Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("5")
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->setVatPercent(0)
+ ->setDescription("E Specification")
+ ->setName('E Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+
+ $orderResponse = $order
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setPayPageLanguage($orderLanguage)
+ ->setReturnUrl($returnUrl)
+ ->getPaymentUrl();
+
+ //print_r( $orderResponse );
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ //print_r( "test_manual_setup_CreditCardOrderRows_testdata finished, now go to " . $orderResponse->testurl ." and complete payment.\n" );
+ }
+
+ function test_CreditOrderRows_CreditCardOrderRows_credit_single_row_using_addNumberedOrderRows_setRowToCredit_success()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'first set up confirmed transaction and enter id in setUp()'
+ );
+
+ // query orderrows to pass in creditOrderRows->setNumberedOrderRows()
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country);
+
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ //print_r( $queryResponse );
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ $creditOrderRowsBuilder = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $creditOrderRowsRequest = $creditOrderRowsBuilder
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country)
+ ->setRowToCredit(1)
+ ->addNumberedOrderRows($queryResponse->numberedOrderRows)// use the queried order rows as base for what amount to credit
+ ->creditCardOrderRows();
+ $creditOrderRowsResponse = $creditOrderRowsRequest->doRequest();
+
+ //print_r("test_CreditOrderRows_CreditCardOrderRows_credit_single_row_using_addNumberedOrderRows_setRowToCredit_success:\n");
+ //print_r( $creditOrderRowsResponse );
+
+ $this->assertEquals(1, $creditOrderRowsResponse->accepted);
+
+ // query orderrows again
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country);
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ $this->assertEquals(1, $queryResponse->accepted);
+ //print_r( $queryResponse );
+ // credit 100 @25 *100 = 12500 => 12500
+ $this->assertEquals(12500, $queryResponse->creditedamount);
+ }
+
+ function test_CreditOrderRows_CreditCardOrderRows_credit_multiple_rows_using_addNumberedOrderRows_setRowToCredit_success()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'first set up confirmed transaction and enter id in setUp()'
+ );
+
+ // query orderrows to pass in creditOrderRows->setNumberedOrderRows()
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country);
+
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ //print_r( $queryResponse );
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ $creditOrderRowsBuilder = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $creditOrderRowsRequest = $creditOrderRowsBuilder
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country)
+ ->setRowsToCredit([2, 3])
+ ->addNumberedOrderRows($queryResponse->numberedOrderRows)// use the queried order rows as base for what amount to credit
+ ->creditCardOrderRows();
+ $creditOrderRowsResponse = $creditOrderRowsRequest->doRequest();
+
+ //print_r("test_CreditOrderRows_CreditCardOrderRows_credit_multiple_rows_using_addNumberedOrderRows_setRowToCredit_success:\n");
+ //print_r( $creditOrderRowsResponse );
+
+ $this->assertEquals(1, $creditOrderRowsResponse->accepted);
+
+ // query orderrows again
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country);
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ $this->assertEquals(1, $queryResponse->accepted);
+ //print_r( $queryResponse );
+ // credited 12500
+ // credit 100 @12 *100 = 11200
+ // credit 1 @25 *100 = 125 => 23825
+ $this->assertEquals(23825, $queryResponse->creditedamount);
+ }
+
+ function test_CreditOrderRows_CreditCardOrderRows_credit_single_row_and_new_row_using_addNewCreditRow_success()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'first set up confirmed transaction and enter id in setUp()'
+ );
+
+ // query orderrows to pass in creditOrderRows->setNumberedOrderRows()
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country);
+
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ //print_r( $queryResponse );
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ $creditOrderRowsBuilder = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $creditOrderRowsRequest = $creditOrderRowsBuilder
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country)
+ ->addNumberedOrderRows($queryResponse->numberedOrderRows)// use the queried order rows as base for what amount to credit
+ ->setRowToCredit(4)
+ ->addCreditOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("104")
+ ->setQuantity(1)
+ ->setAmountExVat(10.00)
+ ->setVatPercent(25)
+ ->setDescription("104 Specification")
+ ->setName('104 Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->creditCardOrderRows();
+ $creditOrderRowsResponse = $creditOrderRowsRequest->doRequest();
+
+ //print_r("test_CreditOrderRows_CreditCardOrderRows_credit_single_row_and_new_row_using_addNewCreditRow_success:\n");
+ //print_r( $creditOrderRowsResponse );
+
+ $this->assertEquals(1, $creditOrderRowsResponse->accepted);
+
+ // query orderrows again
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country);
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ $this->assertEquals(1, $queryResponse->accepted);
+ //print_r( $queryResponse );
+ // credited 23825
+ // credit 100 @0 *100 = 10000
+ // credit 10 @25 *100 = 1250 => 35075
+ $this->assertEquals(35075, $queryResponse->creditedamount);
+ }
+
+ function test_CreditOrderRows_creditCardOrderRows_addCreditOrderRow_setRowToCredit_exceeds_original_order_fails()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'first set up approved invoice and enter id in setUp()'
+ );
+
+ // query orderrows to pass in creditOrderRows->setNumberedOrderRows()
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country);
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ //print_r( $queryResponse );
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ $creditOrderRowsBuilder = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $creditOrderRowsRequest = $creditOrderRowsBuilder
+ ->setOrderId($this->successfulTransactionToTest)
+ ->setCountryCode($this->country)
+ ->addNumberedOrderRows($queryResponse->numberedOrderRows)// use the queried order rows as base for what amount to credit
+ ->setRowToCredit(5)
+ ->creditCardOrderRows();
+ $creditOrderRowsResponse = $creditOrderRowsRequest->doRequest();
+
+ //print_r("test_CreditOrderRows_creditCardOrderRows_addCreditOrderRow_setRowToCredit_exceeds_original_order_fails:\n");
+ //print_r( $creditOrderRowsResponse );
+ $this->assertEquals(0, $creditOrderRowsResponse->accepted);
+ $this->assertEquals("119 (ILLEGAL_CREDITED_AMOUNT)", $creditOrderRowsResponse->resultcode);
+ }
}
-
-?>
\ No newline at end of file
diff --git a/test/IntegrationTest/BuildOrder/DeliverOrderBuilderTest.php b/test/IntegrationTest/BuildOrder/DeliverOrderBuilderTest.php
index 2653fdab..c342e176 100644
--- a/test/IntegrationTest/BuildOrder/DeliverOrderBuilderTest.php
+++ b/test/IntegrationTest/BuildOrder/DeliverOrderBuilderTest.php
@@ -18,186 +18,184 @@
class DeliverOrderBuilderIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public function test_deliverOrder_deliverInvoiceOrder_with_orderrows_use_DeliverOrderEU_and_is_accepted()
- {
-
- // create order, get orderid to deliver
- $createOrderBuilder = TestUtil::createOrder();
- $response = $createOrderBuilder->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $response->accepted);
-
- $orderId = $response->sveaOrderId;
-
- $DeliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setOrderId($orderId)
- ->setInvoiceDistributionType(DistributionType::POST);
-
- $response = $DeliverOrderBuilder->deliverInvoiceOrder()->doRequest();
-
- ////print_r( $response );
- $this->assertEquals(1, $response->accepted);
- $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult", $response); // deliverOrderResult => deliverOrderEU
- }
-
- public function test_deliverOrder_deliverInvoiceOrder_without_orderrows_use_admin_service_deliverOrders_and_is_accepted()
- {
- // create order, get orderid to deliver
- $createOrderBuilder = TestUtil::createOrder();
- $createResponse = $createOrderBuilder->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $createResponse->accepted);
-
- $orderId = $createResponse->sveaOrderId;
- $DeliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- //->addOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
- ->setCountryCode("SE")
- ->setOrderId($orderId)
- ->setInvoiceDistributionType(DistributionType::POST);
-
- // example of raw deliver orders response to parse
- //
- //stdClass Object
- //(
- // [ErrorMessage] =>
- // [ResultCode] => 0
- // [OrdersDelivered] => stdClass Object
- // (
- // [DeliverOrderResult] => stdClass Object
- // (
- // [ClientId] => 79021
- // [DeliveredAmount] => 250.00
- // [DeliveryReferenceNumber] => 1033890
- // [OrderType] => Invoice
- // [SveaOrderId] => 414157
- // )
- //
- // )
- //
- //)
- $deliverResponse = $DeliverOrderBuilder->deliverInvoiceOrder()->doRequest();
-
- ////print_r( $deliverResponse );
- //Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse Object
- //(
- // [clientId] => 79021
- // [amount] => 250.00
- // [invoiceId] =>
- // [contractNumber] =>
- // [orderType] => Invoice
- // [orderId] => 414168
- // [accepted] => 1
- // [resultcode] => 0
- // [errormessage] =>
- //)
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse", $deliverResponse);
- $this->assertEquals(1, $deliverResponse->accepted);
- $this->assertEquals(0, $deliverResponse->resultcode);
- $this->assertEquals(null, $deliverResponse->errormessage);
-
- $this->assertEquals(79021, $deliverResponse->clientId);
- $this->assertEquals(250.00, $deliverResponse->amount);
- $this->assertStringMatchesFormat("%d", $deliverResponse->invoiceId); // %d => an unsigned integer value
- $this->assertEquals(null, $deliverResponse->contractNumber);
- $this->assertEquals("Invoice", $deliverResponse->orderType);
- $this->assertStringMatchesFormat("%d", $deliverResponse->orderId); // %d => an unsigned integer value
- }
-
- // orderrows are ignored by the service for paymentplan orders
- public function test_deliverOrder_deliverPaymentPlanOrder_with_orderrows_use_DeliverOrderEU_and_is_accepted()
- {
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(1)
- ->setAmountExVat(1000.00)
- ->setVatPercent(25)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate(date('c'));
- $response = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
-
- $this->assertEquals(1, $response->accepted);
-
- $orderId = $response->sveaOrderId;
-
- $DeliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(1)
- ->setAmountExVat(1000.00)
- ->setVatPercent(25)
- )
- ->setCountryCode("SE")
- ->setOrderId($orderId);
-
- $response = $DeliverOrderBuilder->deliverPaymentPlanOrder()->doRequest();
-
- ////print_r( $response );
- $this->assertEquals(1, $response->accepted);
- $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult", $response);
- }
-
- public function test_deliverOrder_deliverPaymentPlanOrder_without_orderrows_use_DeliverOrderEU_and_is_accepted()
- {
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(1)
- ->setAmountExVat(1000.00)
- ->setVatPercent(25)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate(date('c'));
- $response = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
-
- $this->assertEquals(1, $response->accepted);
-
- $orderId = $response->sveaOrderId;
-
- $DeliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- //->addOrderRow( Svea\WebPay\WebPayItem::orderRow()
- // ->setQuantity(1)
- // ->setAmountExVat(1000.00)
- // ->setVatPercent(25)
- //)
- ->setCountryCode("SE")
- ->setOrderId($orderId);
-
- $response = $DeliverOrderBuilder->deliverPaymentPlanOrder()->doRequest();
-
- ////print_r( $response );
- $this->assertEquals(1, $response->accepted);
- $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult", $response);
- }
-
- 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(ConfigurationService::getDefaultConfig())
- ->setCountryCode("SE")
- ->setOrderId($orderId);
-
- $response = $DeliverOrderBuilder->deliverCardOrder()->doRequest();
-
- ////print_r( $response );
- $this->assertEquals(1, $response->accepted);
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $response);
- }
+ public function test_deliverOrder_deliverInvoiceOrder_with_orderrows_use_DeliverOrderEU_and_is_accepted()
+ {
+
+ // create order, get orderid to deliver
+ $createOrderBuilder = TestUtil::createOrder();
+ $response = $createOrderBuilder->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+
+ $orderId = $response->sveaOrderId;
+
+ $DeliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setOrderId($orderId)
+ ->setInvoiceDistributionType(DistributionType::POST);
+
+ $response = $DeliverOrderBuilder->deliverInvoiceOrder()->doRequest();
+
+ ////print_r( $response );
+ $this->assertEquals(1, $response->accepted);
+ $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult", $response); // deliverOrderResult => deliverOrderEU
+ }
+
+ public function test_deliverOrder_deliverInvoiceOrder_without_orderrows_use_admin_service_deliverOrders_and_is_accepted()
+ {
+ // create order, get orderid to deliver
+ $createOrderBuilder = TestUtil::createOrder();
+ $createResponse = $createOrderBuilder->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $createResponse->accepted);
+
+ $orderId = $createResponse->sveaOrderId;
+ $DeliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ //->addOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
+ ->setCountryCode("SE")
+ ->setOrderId($orderId)
+ ->setInvoiceDistributionType(DistributionType::POST);
+
+ // example of raw deliver orders response to parse
+ //
+ //stdClass Object
+ //(
+ // [ErrorMessage] =>
+ // [ResultCode] => 0
+ // [OrdersDelivered] => stdClass Object
+ // (
+ // [DeliverOrderResult] => stdClass Object
+ // (
+ // [ClientId] => 79021
+ // [DeliveredAmount] => 250.00
+ // [DeliveryReferenceNumber] => 1033890
+ // [OrderType] => Invoice
+ // [SveaOrderId] => 414157
+ // )
+ //
+ // )
+ //
+ //)
+ $deliverResponse = $DeliverOrderBuilder->deliverInvoiceOrder()->doRequest();
+
+ ////print_r( $deliverResponse );
+ //Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse Object
+ //(
+ // [clientId] => 79021
+ // [amount] => 250.00
+ // [invoiceId] =>
+ // [contractNumber] =>
+ // [orderType] => Invoice
+ // [orderId] => 414168
+ // [accepted] => 1
+ // [resultcode] => 0
+ // [errormessage] =>
+ //)
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\AdminServiceResponse\DeliverOrdersResponse", $deliverResponse);
+ $this->assertEquals(1, $deliverResponse->accepted);
+ $this->assertEquals(0, $deliverResponse->resultcode);
+ $this->assertEquals(null, $deliverResponse->errormessage);
+
+ $this->assertEquals(79021, $deliverResponse->clientId);
+ $this->assertEquals(250.00, $deliverResponse->amount);
+ $this->assertStringMatchesFormat("%d", $deliverResponse->invoiceId); // %d => an unsigned integer value
+ $this->assertEquals(null, $deliverResponse->contractNumber);
+ $this->assertEquals("Invoice", $deliverResponse->orderType);
+ $this->assertStringMatchesFormat("%d", $deliverResponse->orderId); // %d => an unsigned integer value
+ }
+
+ // orderrows are ignored by the service for paymentplan orders
+ public function test_deliverOrder_deliverPaymentPlanOrder_with_orderrows_use_DeliverOrderEU_and_is_accepted()
+ {
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(1)
+ ->setAmountExVat(1000.00)
+ ->setVatPercent(25)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate(date('c'));
+ $response = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+
+ $orderId = $response->sveaOrderId;
+
+ $DeliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(1)
+ ->setAmountExVat(1000.00)
+ ->setVatPercent(25)
+ )
+ ->setCountryCode("SE")
+ ->setOrderId($orderId);
+
+ $response = $DeliverOrderBuilder->deliverPaymentPlanOrder()->doRequest();
+
+ ////print_r( $response );
+ $this->assertEquals(1, $response->accepted);
+ $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult", $response);
+ }
+
+ public function test_deliverOrder_deliverPaymentPlanOrder_without_orderrows_use_DeliverOrderEU_and_is_accepted()
+ {
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(1)
+ ->setAmountExVat(1000.00)
+ ->setVatPercent(25)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate(date('c'));
+ $response = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+
+ $orderId = $response->sveaOrderId;
+
+ $DeliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ //->addOrderRow( Svea\WebPay\WebPayItem::orderRow()
+ // ->setQuantity(1)
+ // ->setAmountExVat(1000.00)
+ // ->setVatPercent(25)
+ //)
+ ->setCountryCode("SE")
+ ->setOrderId($orderId);
+
+ $response = $DeliverOrderBuilder->deliverPaymentPlanOrder()->doRequest();
+
+ ////print_r( $response );
+ $this->assertEquals(1, $response->accepted);
+ $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult", $response);
+ }
+
+ 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(ConfigurationService::getDefaultConfig())
+ ->setCountryCode("SE")
+ ->setOrderId($orderId);
+
+ $response = $DeliverOrderBuilder->deliverCardOrder()->doRequest();
+
+ ////print_r( $response );
+ $this->assertEquals(1, $response->accepted);
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $response);
+ }
}
-
-?>
\ No newline at end of file
diff --git a/test/IntegrationTest/BuildOrder/QueryOrderBuilderTest.php b/test/IntegrationTest/BuildOrder/QueryOrderBuilderTest.php
index 83d5c369..ea1119bd 100644
--- a/test/IntegrationTest/BuildOrder/QueryOrderBuilderTest.php
+++ b/test/IntegrationTest/BuildOrder/QueryOrderBuilderTest.php
@@ -15,652 +15,649 @@
class QueryOrderBuilderIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * test_queryOrder_queryInvoiceOrder_order
- */
- function test_queryOrder_queryInvoiceOrder_multiple_order_rows()
- {
- // create invoice order w/three rows (2xA, 1xB)
- $country = "SE";
-
- $a_quantity = 2;
- $a_amountExVat = 1000.00;
- $a_vatPercent = 25;
-
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $b_vatPercent = 12;
- $b_articleNumber = "1071e";
- $b_unit = "pcs.";
- $b_name = "B Name";
- $b_description = "B Description";
- $b_discount = 0;
-
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country))
- ->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)
- );
- $orderResponse = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $createdOrderId = $orderResponse->sveaOrderId;
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
-
- $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
-
- ////print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
- // assert that order rows are the same
- $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
-
- $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
- $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
- $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
- $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
- $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->description);
- $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
- $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
-
- $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->creditInvoiceId); // not set
- $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->invoiceId); // not set
- $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber); // rows are 1-indexed
- $this->assertEquals("NotDelivered", $queryResponse->numberedOrderRows[1]->status);
- }
-
- function test_queryOrder_queryInvoiceOrder_single_order_row()
- {
- // create invoice order w/three rows (2xA, 1xB)
- $country = "SE";
-
- $a_quantity = 2;
- $a_amountExVat = 1000.00;
- $a_vatPercent = 25;
-
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country))
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity($a_quantity)
- ->setAmountExVat($a_amountExVat)
- ->setVatPercent($a_vatPercent)
- );
- $orderResponse = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $createdOrderId = $orderResponse->sveaOrderId;
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
-
- $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
-
- ////print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
- // assert that order rows are the same
- $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
- }
-
- /**
- * test_queryOrder_queryPaymentPlanOrder_order
- */
- function test_queryOrder_queryPaymentPlanOrder_order()
- {
- // create order w/three rows (2xA, 1xB)
- $country = "SE";
-
- $a_quantity = 2;
- $a_amountExVat = 1000.00;
- $a_vatPercent = 25;
-
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $b_vatPercent = 12;
- $b_articleNumber = "1071e";
- $b_unit = "pcs.";
- $b_name = "B Name";
- $b_description = "B Description";
- $b_discount = 0;
-
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country))
- ->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)
- );
- $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $createdOrderId = $orderResponse->sveaOrderId;
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
-
- $queryResponse = $queryOrderBuilder->queryPaymentPlanOrder()->doRequest();
-
- ////print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
- // assert that order rows are the same
- $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
-
- $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
- $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
- $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
- $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
- $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->description);
- $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
- $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
-
- $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->creditInvoiceId); // not set
- $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->invoiceId); // not set
- $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber); // rows are 1-indexed
- $this->assertEquals("NotDelivered", $queryResponse->numberedOrderRows[1]->status);
- }
-
- /**
- * test_manual_queryOrder_queryCard_order_step_1
- *
- */
- function test_manual_queryOrder_queryCard_order_step_1()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test_manual_queryOrder_queryCard_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.00;
- $a_vatPercent = 25;
-
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $b_vatPercent = 12;
- $b_articleNumber = "1071e";
- $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
- ->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( " test_manual_queryOrder_queryCard_order_step_1(): " . $response->testurl ." ");
- }
-
- /**
- * test_manual_queryOrder_queryCard_order_step_2
- *
- * run this test manually after you've performed a card transaction and have gotten the transaction details needed
- */
- function test_manual_queryOrder_queryCard_order_step_2()
- {
-
- // Stop here and mark this test as incomplete.
-// $this->markTestIncomplete(
-// 'skeleton for manual test_manual_queryOrder_queryCard_order_step_2, step 2'
-// );
-
- // 1. remove (put in a comment) the above code to enable the test
- // 2. set $createdOrderId to the transactionid from the transaction log of the request done by following the url from step 1 above.
- // 3. below is an example of the xml generated by paypage for the request in step 1 above, along with the transaction id, for reference.
-
- $createdOrderId = 582616;
-
- // create order w/three rows (2xA, 1xB) (from step 1 above)
- $country = "SE";
-
- $a_quantity = 2;
- $a_amountExVat = 1000.00;
- $a_vatPercent = 25;
-
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $b_vatPercent = 12;
- $b_articleNumber = "1071e";
- $b_unit = "pcs.";
- $b_name = "B Name";
- $b_description = "B Description";
- $b_discount = 0;
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
-
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- ////print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
-
- // assert that order rows are the same
- $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
-
- $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
- $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
- $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
- $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
- $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->name);
- $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
- $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
- }
-
- /**
- * 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.00;
- $a_vatPercent = 25;
-
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $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_queryOrder_queryDirectBank_order_step_2
- *
- * run this test manually after you've performed a direct bank transaction and have gotten the transaction details needed
- */
- function test_manual_queryOrder_queryDirectBank_order_step_2()
- {
-
- // Stop here and mark this test as incomplete.
-// $this->markTestIncomplete(
-// 'skeleton for test_manual_queryOrder_queryDirectBank_order_step_2, step 2'
-// );
-
- // 1. remove (put in a comment) the above code to enable the test
- // 2. set $createdOrderId to the transactionid from the transaction log of the request done by following the url from step 1 above.
- // 3. below is an example of the xml generated by paypage for the request in step 1 above, along with the transaction id, for reference.
-
- $createdOrderId = 583556;
-
- // create order w/three rows (2xA, 1xB) (from step 1 above)
- $country = "SE";
-
- $a_quantity = 2;
- $a_amountExVat = 1000.00;
- $a_vatPercent = 25;
-
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $b_vatPercent = 12;
- $b_articleNumber = "Red 5";
- $b_unit = "pcs.";
- $b_name = "B Name";
- $b_description = "B Description";
- $b_discount = 0;
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode($country);
-
- $queryResponse = $queryOrderBuilder->queryDirectBankOrder()->doRequest();
-
- ////print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
-
- //Svea\QueryTransactionResponse Object
- //(
- // [transactionId] => 582656
- // [customerrefno] => clientOrderNumber:2014-05-21T11:30:53 02:00
- // [merchantid] => 1130
- // [status] => SUCCESS
- // [amount] => 261200
- // [currency] => SEK
- // [vat] => 51200
- // [capturedamount] => 261200
- // [authorizedamount] => 261200
- // [created] => 2014-05-21 11:31:15.697
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentmethod] => DBNORDEASE
- // [orderrows] => Array
- // (
- // [0] => Svea\WebPay\BuildOrder\RowBuilders\OrderRow Object
- // (
- // [articleNumber] =>
- // [quantity] => 2
- // [unit] =>
- // [amountExVat] => 1000
- // [amountIncVat] =>
- // [vatPercent] => 25
- // [name] =>
- // [description] =>
- // [discountPercent] =>
- // [vatDiscount] => 0
- // )
- //
- // [1] => Svea\WebPay\BuildOrder\RowBuilders\OrderRow Object
- // (
- // [articleNumber] => Red 5
- // [quantity] => 1
- // [unit] => pcs.
- // [amountExVat] => 100
- // [amountIncVat] =>
- // [vatPercent] => 12
- // [name] => B Name
- // [description] => B Description
- // [discountPercent] =>
- // [vatDiscount] => 0
- // )
- //
- // )
- //
- // [accepted] => 1
- // [resultcode] => 0
- // [errormessage] =>
- //)
-
- // assert that order rows are the same
- $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
-
- $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
- $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
- $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
- $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
- $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->name);
- $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
- $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
- }
-
- function test_queryOrder_directbank_by_customerrefno()
- {
-
- // Stop here and mark this test as incomplete.
-// $this->markTestIncomplete(
-// 'skeleton for test_manual_queryOrder_queryDirectBank_order_step_2, step 2'
-// );
-
- // 1. remove (put in a comment) the above code to enable the test
- // 2. set $createdOrderId to the transactionid from the transaction log of the request done by following the url from step 1 above.
- // 3. below is an example of the xml generated by paypage for the request in step 1 above, along with the transaction id, for reference.
-
- $createdClientOrderNumber = "clientOrderNumber:2014-06-17T14:18:38 02:00";
-
- // create order w/three rows (2xA, 1xB) (from step 1 above)
- $country = "SE";
-
- $a_quantity = 2;
- $a_amountExVat = 1000.00;
- $a_vatPercent = 25;
-
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $b_vatPercent = 12;
- $b_articleNumber = "Red 5";
- $b_unit = "pcs.";
- $b_name = "B Name";
- $b_description = "B Description";
- $b_discount = 0;
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setClientOrderNumber($createdClientOrderNumber)
- ->setCountryCode($country);
-
- $queryResponse = $queryOrderBuilder->queryDirectBankOrder()->doRequest();
-
- ////print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
-
- //Svea\QueryTransactionResponse Object
- //(
- // [transactionId] => 582656
- // [customerrefno] => clientOrderNumber:2014-05-21T11:30:53 02:00
- // [merchantid] => 1130
- // [status] => SUCCESS
- // [amount] => 261200
- // [currency] => SEK
- // [vat] => 51200
- // [capturedamount] => 261200
- // [authorizedamount] => 261200
- // [created] => 2014-05-21 11:31:15.697
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentmethod] => DBNORDEASE
- // [orderrows] => Array
- // (
- // [0] => Svea\WebPay\BuildOrder\RowBuilders\OrderRow Object
- // (
- // [articleNumber] =>
- // [quantity] => 2
- // [unit] =>
- // [amountExVat] => 1000
- // [amountIncVat] =>
- // [vatPercent] => 25
- // [name] =>
- // [description] =>
- // [discountPercent] =>
- // [vatDiscount] => 0
- // )
- //
- // [1] => Svea\WebPay\BuildOrder\RowBuilders\OrderRow Object
- // (
- // [articleNumber] => Red 5
- // [quantity] => 1
- // [unit] => pcs.
- // [amountExVat] => 100
- // [amountIncVat] =>
- // [vatPercent] => 12
- // [name] => B Name
- // [description] => B Description
- // [discountPercent] =>
- // [vatDiscount] => 0
- // )
- //
- // )
- //
- // [accepted] => 1
- // [resultcode] => 0
- // [errormessage] =>
- //)
-
- // assert that order rows are the same
- $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
-
- $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
- $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
- $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
- $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
- $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->name);
- $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
- $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
- }
-
- function test_queryOrder_card_by_customerrefno()
- {
- $createdClientOrderNumber = "clientOrderNumber:2014-05-20T17:10:35 02:00";
-
- $country = "SE";
-
- $a_quantity = 2;
- $a_amountExVat = 1000.00;
- $a_vatPercent = 25;
-
- $b_quantity = 1;
- $b_amountExVat = 100.00;
- $b_vatPercent = 12;
- $b_articleNumber = "1071e";
- $b_unit = "pcs.";
- $b_name = "B Name";
- $b_description = "B Description";
- $b_discount = 0;
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setClientOrderNumber($createdClientOrderNumber)
- ->setCountryCode($country);
-
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- ////print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
-
- // assert that order rows are the same
- $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
-
- $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
- $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
- $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
- $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
- $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->name);
- $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
- $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
- }
-
- // query invoice order w/single order row
- // query invoice order w/multiple order rows
- // query payment plan order row(s)
- // query card order row(s)
- // query direct bank order row(s)
- // negative tests?
+ /**
+ * test_queryOrder_queryInvoiceOrder_order
+ */
+ function test_queryOrder_queryInvoiceOrder_multiple_order_rows()
+ {
+ // create invoice order w/three rows (2xA, 1xB)
+ $country = "SE";
+
+ $a_quantity = 2;
+ $a_amountExVat = 1000.00;
+ $a_vatPercent = 25;
+
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $b_vatPercent = 12;
+ $b_articleNumber = "1071e";
+ $b_unit = "pcs.";
+ $b_name = "B Name";
+ $b_description = "B Description";
+ $b_discount = 0;
+
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country))
+ ->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)
+ );
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $createdOrderId = $orderResponse->sveaOrderId;
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
+
+ $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
+
+ ////print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+ // assert that order rows are the same
+ $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
+
+ $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
+ $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
+ $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
+ $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->description);
+ $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
+ $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
+
+ $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->creditInvoiceId); // not set
+ $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->invoiceId); // not set
+ $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber); // rows are 1-indexed
+ $this->assertEquals("NotDelivered", $queryResponse->numberedOrderRows[1]->status);
+ }
+
+ function test_queryOrder_queryInvoiceOrder_single_order_row()
+ {
+ // create invoice order w/three rows (2xA, 1xB)
+ $country = "SE";
+
+ $a_quantity = 2;
+ $a_amountExVat = 1000.00;
+ $a_vatPercent = 25;
+
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country))
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity($a_quantity)
+ ->setAmountExVat($a_amountExVat)
+ ->setVatPercent($a_vatPercent)
+ );
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $createdOrderId = $orderResponse->sveaOrderId;
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
+
+ $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
+
+ ////print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+ // assert that order rows are the same
+ $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
+ }
+
+ /**
+ * test_queryOrder_queryPaymentPlanOrder_order
+ */
+ function test_queryOrder_queryPaymentPlanOrder_order()
+ {
+ // create order w/three rows (2xA, 1xB)
+ $country = "SE";
+
+ $a_quantity = 2;
+ $a_amountExVat = 1000.00;
+ $a_vatPercent = 25;
+
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $b_vatPercent = 12;
+ $b_articleNumber = "1071e";
+ $b_unit = "pcs.";
+ $b_name = "B Name";
+ $b_description = "B Description";
+ $b_discount = 0;
+
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country))
+ ->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)
+ );
+ $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $createdOrderId = $orderResponse->sveaOrderId;
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
+
+ $queryResponse = $queryOrderBuilder->queryPaymentPlanOrder()->doRequest();
+
+ ////print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+ // assert that order rows are the same
+ $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
+
+ $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
+ $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
+ $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
+ $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->description);
+ $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
+ $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
+
+ $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->creditInvoiceId); // not set
+ $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->invoiceId); // not set
+ $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber); // rows are 1-indexed
+ $this->assertEquals("NotDelivered", $queryResponse->numberedOrderRows[1]->status);
+ }
+
+ /**
+ * test_manual_queryOrder_queryCard_order_step_1
+ *
+ */
+ function test_manual_queryOrder_queryCard_order_step_1()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test_manual_queryOrder_queryCard_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.00;
+ $a_vatPercent = 25;
+
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $b_vatPercent = 12;
+ $b_articleNumber = "1071e";
+ $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
+ ->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( " test_manual_queryOrder_queryCard_order_step_1(): " . $response->testurl ." ");
+ }
+
+ /**
+ * test_manual_queryOrder_queryCard_order_step_2
+ *
+ * run this test manually after you've performed a card transaction and have gotten the transaction details needed
+ */
+ function test_manual_queryOrder_queryCard_order_step_2()
+ {
+
+ // Stop here and mark this test as incomplete.
+// $this->markTestIncomplete(
+// 'skeleton for manual test_manual_queryOrder_queryCard_order_step_2, step 2'
+// );
+
+ // 1. remove (put in a comment) the above code to enable the test
+ // 2. set $createdOrderId to the transactionid from the transaction log of the request done by following the url from step 1 above.
+ // 3. below is an example of the xml generated by paypage for the request in step 1 above, along with the transaction id, for reference.
+
+ $createdOrderId = 582616;
+
+ // create order w/three rows (2xA, 1xB) (from step 1 above)
+ $country = "SE";
+
+ $a_quantity = 2;
+ $a_amountExVat = 1000.00;
+ $a_vatPercent = 25;
+
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $b_vatPercent = 12;
+ $b_articleNumber = "1071e";
+ $b_unit = "pcs.";
+ $b_name = "B Name";
+ $b_description = "B Description";
+ $b_discount = 0;
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
+
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ ////print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ // assert that order rows are the same
+ $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
+
+ $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
+ $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
+ $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
+ $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->name);
+ $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
+ $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
+ }
+
+ /**
+ * 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.00;
+ $a_vatPercent = 25;
+
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $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_queryOrder_queryDirectBank_order_step_2
+ *
+ * run this test manually after you've performed a direct bank transaction and have gotten the transaction details needed
+ */
+ function test_manual_queryOrder_queryDirectBank_order_step_2()
+ {
+
+ // Stop here and mark this test as incomplete.
+// $this->markTestIncomplete(
+// 'skeleton for test_manual_queryOrder_queryDirectBank_order_step_2, step 2'
+// );
+
+ // 1. remove (put in a comment) the above code to enable the test
+ // 2. set $createdOrderId to the transactionid from the transaction log of the request done by following the url from step 1 above.
+ // 3. below is an example of the xml generated by paypage for the request in step 1 above, along with the transaction id, for reference.
+
+ $createdOrderId = 583556;
+
+ // create order w/three rows (2xA, 1xB) (from step 1 above)
+ $country = "SE";
+
+ $a_quantity = 2;
+ $a_amountExVat = 1000.00;
+ $a_vatPercent = 25;
+
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $b_vatPercent = 12;
+ $b_articleNumber = "Red 5";
+ $b_unit = "pcs.";
+ $b_name = "B Name";
+ $b_description = "B Description";
+ $b_discount = 0;
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode($country);
+
+ $queryResponse = $queryOrderBuilder->queryDirectBankOrder()->doRequest();
+
+ ////print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ //Svea\QueryTransactionResponse Object
+ //(
+ // [transactionId] => 582656
+ // [customerrefno] => clientOrderNumber:2014-05-21T11:30:53 02:00
+ // [merchantid] => 1130
+ // [status] => SUCCESS
+ // [amount] => 261200
+ // [currency] => SEK
+ // [vat] => 51200
+ // [capturedamount] => 261200
+ // [authorizedamount] => 261200
+ // [created] => 2014-05-21 11:31:15.697
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentmethod] => DBNORDEASE
+ // [orderrows] => Array
+ // (
+ // [0] => Svea\WebPay\BuildOrder\RowBuilders\OrderRow Object
+ // (
+ // [articleNumber] =>
+ // [quantity] => 2
+ // [unit] =>
+ // [amountExVat] => 1000
+ // [amountIncVat] =>
+ // [vatPercent] => 25
+ // [name] =>
+ // [description] =>
+ // [discountPercent] =>
+ // [vatDiscount] => 0
+ // )
+ //
+ // [1] => Svea\WebPay\BuildOrder\RowBuilders\OrderRow Object
+ // (
+ // [articleNumber] => Red 5
+ // [quantity] => 1
+ // [unit] => pcs.
+ // [amountExVat] => 100
+ // [amountIncVat] =>
+ // [vatPercent] => 12
+ // [name] => B Name
+ // [description] => B Description
+ // [discountPercent] =>
+ // [vatDiscount] => 0
+ // )
+ //
+ // )
+ //
+ // [accepted] => 1
+ // [resultcode] => 0
+ // [errormessage] =>
+ //)
+
+ // assert that order rows are the same
+ $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
+
+ $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
+ $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
+ $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
+ $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->name);
+ $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
+ $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
+ }
+
+ function test_queryOrder_directbank_by_customerrefno()
+ {
+
+ // Stop here and mark this test as incomplete.
+// $this->markTestIncomplete(
+// 'skeleton for test_manual_queryOrder_queryDirectBank_order_step_2, step 2'
+// );
+
+ // 1. remove (put in a comment) the above code to enable the test
+ // 2. set $createdOrderId to the transactionid from the transaction log of the request done by following the url from step 1 above.
+ // 3. below is an example of the xml generated by paypage for the request in step 1 above, along with the transaction id, for reference.
+
+ $createdClientOrderNumber = "clientOrderNumber:2014-06-17T14:18:38 02:00";
+
+ // create order w/three rows (2xA, 1xB) (from step 1 above)
+ $country = "SE";
+
+ $a_quantity = 2;
+ $a_amountExVat = 1000.00;
+ $a_vatPercent = 25;
+
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $b_vatPercent = 12;
+ $b_articleNumber = "Red 5";
+ $b_unit = "pcs.";
+ $b_name = "B Name";
+ $b_description = "B Description";
+ $b_discount = 0;
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setClientOrderNumber($createdClientOrderNumber)
+ ->setCountryCode($country);
+
+ $queryResponse = $queryOrderBuilder->queryDirectBankOrder()->doRequest();
+
+ ////print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ //Svea\QueryTransactionResponse Object
+ //(
+ // [transactionId] => 582656
+ // [customerrefno] => clientOrderNumber:2014-05-21T11:30:53 02:00
+ // [merchantid] => 1130
+ // [status] => SUCCESS
+ // [amount] => 261200
+ // [currency] => SEK
+ // [vat] => 51200
+ // [capturedamount] => 261200
+ // [authorizedamount] => 261200
+ // [created] => 2014-05-21 11:31:15.697
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentmethod] => DBNORDEASE
+ // [orderrows] => Array
+ // (
+ // [0] => Svea\WebPay\BuildOrder\RowBuilders\OrderRow Object
+ // (
+ // [articleNumber] =>
+ // [quantity] => 2
+ // [unit] =>
+ // [amountExVat] => 1000
+ // [amountIncVat] =>
+ // [vatPercent] => 25
+ // [name] =>
+ // [description] =>
+ // [discountPercent] =>
+ // [vatDiscount] => 0
+ // )
+ //
+ // [1] => Svea\WebPay\BuildOrder\RowBuilders\OrderRow Object
+ // (
+ // [articleNumber] => Red 5
+ // [quantity] => 1
+ // [unit] => pcs.
+ // [amountExVat] => 100
+ // [amountIncVat] =>
+ // [vatPercent] => 12
+ // [name] => B Name
+ // [description] => B Description
+ // [discountPercent] =>
+ // [vatDiscount] => 0
+ // )
+ //
+ // )
+ //
+ // [accepted] => 1
+ // [resultcode] => 0
+ // [errormessage] =>
+ //)
+
+ // assert that order rows are the same
+ $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
+
+ $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
+ $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
+ $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
+ $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->name);
+ $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
+ $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
+ }
+
+ function test_queryOrder_card_by_customerrefno()
+ {
+ $createdClientOrderNumber = "clientOrderNumber:2014-05-20T17:10:35 02:00";
+
+ $country = "SE";
+
+ $a_quantity = 2;
+ $a_amountExVat = 1000.00;
+ $a_vatPercent = 25;
+
+ $b_quantity = 1;
+ $b_amountExVat = 100.00;
+ $b_vatPercent = 12;
+ $b_articleNumber = "1071e";
+ $b_unit = "pcs.";
+ $b_name = "B Name";
+ $b_description = "B Description";
+ $b_discount = 0;
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setClientOrderNumber($createdClientOrderNumber)
+ ->setCountryCode($country);
+
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ ////print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ // assert that order rows are the same
+ $this->assertEquals($a_quantity, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals($a_amountExVat, $queryResponse->numberedOrderRows[0]->amountExVat);
+
+ $this->assertEquals($b_quantity, $queryResponse->numberedOrderRows[1]->quantity);
+ $this->assertEquals($b_amountExVat, $queryResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals($b_vatPercent, $queryResponse->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals($b_articleNumber, $queryResponse->numberedOrderRows[1]->articleNumber);
+ $this->assertEquals($b_unit, $queryResponse->numberedOrderRows[1]->unit);
+ $this->assertStringStartsWith($b_name, $queryResponse->numberedOrderRows[1]->name);
+ $this->assertStringEndsWith($b_description, $queryResponse->numberedOrderRows[1]->description);
+ $this->assertEquals($b_discount, $queryResponse->numberedOrderRows[1]->discountPercent);
+ }
+
+ // query invoice order w/single order row
+ // query invoice order w/multiple order rows
+ // query payment plan order row(s)
+ // query card order row(s)
+ // query direct bank order row(s)
+ // negative tests?
}
-
-
-?>
\ No newline at end of file
diff --git a/test/IntegrationTest/BuildOrder/UpdateOrderRowsBuilderTest.php b/test/IntegrationTest/BuildOrder/UpdateOrderRowsBuilderTest.php
index 6a9902e0..3e4cbb22 100644
--- a/test/IntegrationTest/BuildOrder/UpdateOrderRowsBuilderTest.php
+++ b/test/IntegrationTest/BuildOrder/UpdateOrderRowsBuilderTest.php
@@ -15,315 +15,313 @@
class UpdateOrderRowsBuilderIntegrationTest extends \PHPUnit\Framework\TestCase
{
- protected $invoiceIdToTest;
- protected $country;
+ protected $invoiceIdToTest;
+ protected $country;
- protected function setUp()
- {
- $this->country = "SE";
- $this->invoiceIdToTest = 583004; // set this to the approved invoice set up by test_manual_setup_CreditOrderRows_testdata()
- }
+ protected function setUp()
+ {
+ $this->country = "SE";
+ $this->invoiceIdToTest = 583004; // set this to the approved invoice set up by test_manual_setup_CreditOrderRows_testdata()
+ }
- function test_UpdateOrderRows_updateInvoiceOrderRows_single_row_success()
- {
- $country = "SE";
+ function test_UpdateOrderRows_updateInvoiceOrderRows_single_row_success()
+ {
+ $country = "SE";
- // create order
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(1.00)
- ->setVatPercent(25)
- ->setDescription("A Specification")
- ->setName('A Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("2")
- ->setQuantity(1)
- ->setAmountExVat(2.00)
- ->setVatPercent(25)
- ->setDescription("B Specification")
- ->setName('B Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
+ // create order
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(1.00)
+ ->setVatPercent(25)
+ ->setDescription("A Specification")
+ ->setName('A Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("2")
+ ->setQuantity(1)
+ ->setAmountExVat(2.00)
+ ->setVatPercent(25)
+ ->setDescription("B Specification")
+ ->setName('B Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
- $orderResponse = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
- // update all attributes for a numbered orderRow
- $updateOrderRowsResponse = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setArticleNumber("10")
- ->setQuantity(1)
- ->setAmountExVat(10.00)
- ->setVatPercent(26)
- ->setDescription("K Specification")
- ->setName('K Name')
- ->setUnit("st")
- ->setDiscountPercent(1)
- ->setRowNumber(1)
- ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
- )
- ->updateInvoiceOrderRows()
- ->doRequest();
+ // update all attributes for a numbered orderRow
+ $updateOrderRowsResponse = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setArticleNumber("10")
+ ->setQuantity(1)
+ ->setAmountExVat(10.00)
+ ->setVatPercent(26)
+ ->setDescription("K Specification")
+ ->setName('K Name')
+ ->setUnit("st")
+ ->setDiscountPercent(1)
+ ->setRowNumber(1)
+ ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
+ )
+ ->updateInvoiceOrderRows()
+ ->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
- }
+ ////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
+ }
- function test_UpdateOrderRows_updateInvoiceOrderRows_multiple_row_success()
- {
- $country = "SE";
+ function test_UpdateOrderRows_updateInvoiceOrderRows_multiple_row_success()
+ {
+ $country = "SE";
- // create order
- $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(1.00)
- ->setVatPercent(25)
- ->setDescription("A Specification")
- ->setName('A Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("2")
- ->setQuantity(1)
- ->setAmountExVat(2.00)
- ->setVatPercent(25)
- ->setDescription("B Specification")
- ->setName('B Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("3")
- ->setQuantity(1)
- ->setAmountExVat(3.00)
- ->setVatPercent(25)
- ->setDescription("C Specification")
- ->setName('C Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $orderResponse = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
+ // create order
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(1.00)
+ ->setVatPercent(25)
+ ->setDescription("A Specification")
+ ->setName('A Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("2")
+ ->setQuantity(1)
+ ->setAmountExVat(2.00)
+ ->setVatPercent(25)
+ ->setDescription("B Specification")
+ ->setName('B Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("3")
+ ->setQuantity(1)
+ ->setAmountExVat(3.00)
+ ->setVatPercent(25)
+ ->setDescription("C Specification")
+ ->setName('C Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $orderResponse = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
- // update all attributes for a numbered orderRow
- $updateOrderRowsResponse = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setArticleNumber("10")
- ->setQuantity(1)
- ->setAmountExVat(10.00)
- ->setVatPercent(25)
- ->setDescription("K Specification")
- ->setName('K Name')
- ->setUnit("st")
- ->setDiscountPercent(1)
- ->setRowNumber(1)
- ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
- )
- ->updateOrderRows(
- array(
- WebPayItem::numberedOrderRow()
- ->setArticleNumber("20")
- ->setQuantity(2)
- ->setAmountExVat(20.00)
- ->setVatPercent(25)
- ->setDescription("K2 Specification")
- ->setName('K2 Name')
- ->setUnit("st")
- ->setDiscountPercent(1)
- ->setRowNumber(2)
- ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
- ,
- WebPayItem::numberedOrderRow()
- ->setArticleNumber("30")
- ->setQuantity(3)
- ->setAmountExVat(30.00)
- ->setVatPercent(25)
- ->setDescription("K3 Specification")
- ->setName('K3 Name')
- ->setUnit("st")
- ->setDiscountPercent(1)
- ->setRowNumber(3)
- ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
- )
- )
- ->updateInvoiceOrderRows()
- ->doRequest();
+ // update all attributes for a numbered orderRow
+ $updateOrderRowsResponse = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setArticleNumber("10")
+ ->setQuantity(1)
+ ->setAmountExVat(10.00)
+ ->setVatPercent(25)
+ ->setDescription("K Specification")
+ ->setName('K Name')
+ ->setUnit("st")
+ ->setDiscountPercent(1)
+ ->setRowNumber(1)
+ ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
+ )
+ ->updateOrderRows(
+ [
+ WebPayItem::numberedOrderRow()
+ ->setArticleNumber("20")
+ ->setQuantity(2)
+ ->setAmountExVat(20.00)
+ ->setVatPercent(25)
+ ->setDescription("K2 Specification")
+ ->setName('K2 Name')
+ ->setUnit("st")
+ ->setDiscountPercent(1)
+ ->setRowNumber(2)
+ ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
+ ,
+ WebPayItem::numberedOrderRow()
+ ->setArticleNumber("30")
+ ->setQuantity(3)
+ ->setAmountExVat(30.00)
+ ->setVatPercent(25)
+ ->setDescription("K3 Specification")
+ ->setName('K3 Name')
+ ->setUnit("st")
+ ->setDiscountPercent(1)
+ ->setRowNumber(3)
+ ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
+ ]
+ )
+ ->updateInvoiceOrderRows()
+ ->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
- }
+ ////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
+ }
- function test_UpdateOrderRows_updatePaymentPlanOrderRows_multiple_row_success()
- {
- $country = "SE";
+ 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.00)
- ->setVatPercent(25)
- ->setDescription("A Specification")
- ->setName('A Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("2")
- ->setQuantity(1)
- ->setAmountExVat(2000.00)
- ->setVatPercent(25)
- ->setDescription("B Specification")
- ->setName('B Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("3")
- ->setQuantity(1)
- ->setAmountExVat(3000.00)
- ->setVatPercent(25)
- ->setDescription("C Specification")
- ->setName('C Name')
- ->setUnit("st")
- ->setDiscountPercent(0)
- );
- $orderResponse = $order->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
+ // create order
+ $order = TestUtil::createOrderWithoutOrderRows(TestUtil::createIndividualCustomer($country));
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(1000.00)
+ ->setVatPercent(25)
+ ->setDescription("A Specification")
+ ->setName('A Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("2")
+ ->setQuantity(1)
+ ->setAmountExVat(2000.00)
+ ->setVatPercent(25)
+ ->setDescription("B Specification")
+ ->setName('B Name')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ );
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("3")
+ ->setQuantity(1)
+ ->setAmountExVat(3000.00)
+ ->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(ConfigurationService::getDefaultConfig())
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode($country)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setArticleNumber("10")
- ->setQuantity(1)
- ->setAmountExVat(10.00)
- ->setVatPercent(25)
- ->setDescription("K Specification")
- ->setName('K Name')
- ->setUnit("st")
- ->setDiscountPercent(1)
- ->setRowNumber(1)
- ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
- )
- ->updateOrderRows(
- array(
- WebPayItem::numberedOrderRow()
- ->setArticleNumber("20")
- ->setQuantity(2)
- ->setAmountExVat(20.00)
- ->setVatPercent(25)
- ->setDescription("K2 Specification")
- ->setName('K2 Name')
- ->setUnit("st")
- ->setDiscountPercent(1)
- ->setRowNumber(2)
- ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
- ,
- WebPayItem::numberedOrderRow()
- ->setArticleNumber("30")
- ->setQuantity(3)
- ->setAmountExVat(500.00)
- ->setVatPercent(25)
- ->setDescription("K3 Specification")
- ->setName('K3 Name')
- ->setUnit("st")
- ->setDiscountPercent(1)
- ->setRowNumber(3)
- ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
- )
- )
- ->updatePaymentPlanOrderRows()
- ->doRequest();
+ // update all attributes for a numbered orderRow
+ $updateOrderRowsResponse = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode($country)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setArticleNumber("10")
+ ->setQuantity(1)
+ ->setAmountExVat(10.00)
+ ->setVatPercent(25)
+ ->setDescription("K Specification")
+ ->setName('K Name')
+ ->setUnit("st")
+ ->setDiscountPercent(1)
+ ->setRowNumber(1)
+ ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
+ )
+ ->updateOrderRows(
+ [
+ WebPayItem::numberedOrderRow()
+ ->setArticleNumber("20")
+ ->setQuantity(2)
+ ->setAmountExVat(20.00)
+ ->setVatPercent(25)
+ ->setDescription("K2 Specification")
+ ->setName('K2 Name')
+ ->setUnit("st")
+ ->setDiscountPercent(1)
+ ->setRowNumber(2)
+ ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
+ ,
+ WebPayItem::numberedOrderRow()
+ ->setArticleNumber("30")
+ ->setQuantity(3)
+ ->setAmountExVat(500.00)
+ ->setVatPercent(25)
+ ->setDescription("K3 Specification")
+ ->setName('K3 Name')
+ ->setUnit("st")
+ ->setDiscountPercent(1)
+ ->setRowNumber(3)
+ ->setStatus(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
- }
+ ////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
+ }
- function _test_UpdateOrderRows_manually_created_paymentplan()
- {
- $country = "SE";
+ function _test_UpdateOrderRows_manually_created_paymentplan()
+ {
+ $country = "SE";
-// // create order
-// $order = Svea\WebPay\Test\TestUtil::createOrderWithoutOrderRows( Svea\WebPay\Test\TestUtil::createIndividualCustomer($country) );
-// $order->addOrderRow( Svea\WebPay\WebPayItem::orderRow()
-// ->setArticleNumber("1")
-// ->setQuantity( 1 )
-// ->setAmountExVat( 1000.00 )
-// ->setVatPercent(25)
-// ->setDescription("A Specification")
-// ->setName('A Name')
-// ->setUnit("st")
-// ->setDiscountPercent(0)
-// );
-// $order->addOrderRow( Svea\WebPay\WebPayItem::orderRow()
-// ->setArticleNumber("2")
-// ->setQuantity( 1 )
-// ->setAmountExVat( 2000.00 )
-// ->setVatPercent(25)
-// ->setDescription("B Specification")
-// ->setName('B Name')
-// ->setUnit("st")
-// ->setDiscountPercent(0)
-// );
-// $order->addOrderRow( Svea\WebPay\WebPayItem::orderRow()
-// ->setArticleNumber("3")
-// ->setQuantity( 1 )
-// ->setAmountExVat( 3000.00 )
-// ->setVatPercent(25)
-// ->setDescription("C Specification")
-// ->setName('C Name')
-// ->setUnit("st")
-// ->setDiscountPercent(0)
-// );
-// $orderResponse = $order->usePaymentPlanPayment( Svea\WebPay\Test\TestUtil::getGetPaymentPlanParamsForTesting() )->doRequest();
-// $this->assertEquals(1, $orderResponse->accepted);
+// // create order
+// $order = Svea\WebPay\Test\TestUtil::createOrderWithoutOrderRows( Svea\WebPay\Test\TestUtil::createIndividualCustomer($country) );
+// $order->addOrderRow( Svea\WebPay\WebPayItem::orderRow()
+// ->setArticleNumber("1")
+// ->setQuantity( 1 )
+// ->setAmountExVat( 1000.00 )
+// ->setVatPercent(25)
+// ->setDescription("A Specification")
+// ->setName('A Name')
+// ->setUnit("st")
+// ->setDiscountPercent(0)
+// );
+// $order->addOrderRow( Svea\WebPay\WebPayItem::orderRow()
+// ->setArticleNumber("2")
+// ->setQuantity( 1 )
+// ->setAmountExVat( 2000.00 )
+// ->setVatPercent(25)
+// ->setDescription("B Specification")
+// ->setName('B Name')
+// ->setUnit("st")
+// ->setDiscountPercent(0)
+// );
+// $order->addOrderRow( Svea\WebPay\WebPayItem::orderRow()
+// ->setArticleNumber("3")
+// ->setQuantity( 1 )
+// ->setAmountExVat( 3000.00 )
+// ->setVatPercent(25)
+// ->setDescription("C Specification")
+// ->setName('C Name')
+// ->setUnit("st")
+// ->setDiscountPercent(0)
+// );
+// $orderResponse = $order->usePaymentPlanPayment( Svea\WebPay\Test\TestUtil::getGetPaymentPlanParamsForTesting() )->doRequest();
+// $this->assertEquals(1, $orderResponse->accepted);
- // update all attributes for a numbered orderRow
- $updateOrderRowsResponse = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId(364183)
- ->setCountryCode($country)
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setArticleNumber("10")
- ->setQuantity(1)
- ->setAmountExVat(1000.00)
- ->setVatPercent(25)
- ->setDescription("K Specification")
- ->setName('K Name')
- ->setUnit("st")
- ->setDiscountPercent(1)
- ->setRowNumber(1)
- ->setStatus(NumberedOrderRow::ORDERROWSTATUS_NOTDELIVERED)
- )
- ->updatePaymentPlanOrderRows()
- ->doRequest();
+ // update all attributes for a numbered orderRow
+ $updateOrderRowsResponse = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId(364183)
+ ->setCountryCode($country)
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setArticleNumber("10")
+ ->setQuantity(1)
+ ->setAmountExVat(1000.00)
+ ->setVatPercent(25)
+ ->setDescription("K Specification")
+ ->setName('K Name')
+ ->setUnit("st")
+ ->setDiscountPercent(1)
+ ->setRowNumber(1)
+ ->setStatus(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
- }
+ //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
+ }
}
-
-?>
\ No newline at end of file
diff --git a/test/IntegrationTest/Helper/HelperIntegrationTest.php b/test/IntegrationTest/Helper/HelperIntegrationTest.php
index b16c602e..90c3e061 100644
--- a/test/IntegrationTest/Helper/HelperIntegrationTest.php
+++ b/test/IntegrationTest/Helper/HelperIntegrationTest.php
@@ -16,238 +16,236 @@
class HelperIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * split mean vat given by shop (i.e. when using a coupon in OpenCart) into two fixedDiscountRows
- */
- public function test_splitMeanToTwoTaxRatesToFormatFixedDiscountRows_TwoRatesInOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- );
-
- $discountExVatFromShop = 100;
- $meanVatRateFromShop = 18.6667;
- $titleFromShop = "Coupon (1112)";
- $descriptionFromShop = "Value 100";
-
- $taxRates = Helper::getTaxRatesInOrder($order);
- $discountRows = Helper::splitMeanToTwoTaxRates($discountExVatFromShop, $meanVatRateFromShop, $titleFromShop, $descriptionFromShop, $taxRates);
- foreach ($discountRows as $row) {
- $order = $order->addDiscount($row);
- }
-
-
- $formatter = new WebServiceRowFormatter($order);
- $newRows = $formatter->formatRows();
-
- $newRow = $newRows[2];
- $this->assertEquals("Coupon (1112): Value 100 (25%)", $newRow->Description);
- $this->assertEquals(-66.67, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- $newRow = $newRows[3];
- $this->assertEquals("Coupon (1112): Value 100 (6%)", $newRow->Description);
- $this->assertEquals(-33.33, $newRow->PricePerUnit);
- $this->assertEquals(6, $newRow->VatPercent);
- }
-
- /**
- * split mean vat given by shop (i.e. when using a coupon in OpenCart) into two fixedDiscountRows
- */
- public function test_splitMeanToTwoTaxRatesToFormatFixedDiscountRows_OneRateInOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- );
-
- $discountExVatFromShop = 100;
- $meanVatRateFromShop = 25.00;
- $titleFromShop = "Coupon (1112)";
- $descriptionFromShop = "Value 100";
-
- $taxRates = Helper::getTaxRatesInOrder($order);
- $discountRows = Helper::splitMeanToTwoTaxRates($discountExVatFromShop, $meanVatRateFromShop, $titleFromShop, $descriptionFromShop, $taxRates);
- foreach ($discountRows as $row) {
- $order = $order->addDiscount($row);
- }
-
- $formatter = new 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);
- }
-
- /// Helper::paymentPlanPricePerMonth()
- public function test_paymentPlanPricePerMonth_returns_PaymentPlanPricePerMonth()
- {
- $campaigns =
- WebPay::getPaymentPlanParams(ConfigurationService::getDefaultConfig())
- ->setCountryCode("SE")
- ->doRequest();
- $this->assertTrue($campaigns->accepted);
-
- $pricesPerMonth = Helper::paymentPlanPricePerMonth(2000, $campaigns, true);
- $this->assertInstanceOf("Svea\WebPay\WebService\GetPaymentPlanParams\PaymentPlanPricePerMonth", $pricesPerMonth);
-// $this->assertEquals(213060, $pricesPerMonth->values[0]['campaignCode']);//don't test to be flexible
- $this->assertEquals(true, isset($pricesPerMonth->values[0]['pricePerMonth']));
- }
-
- // 3i. mean inc to single tax rate: 12i @20% -> 12i @25%, priceincvat = true => correct order total at Svea
- function test_splitMeanAcrossTaxRates_3()
- {
- $discountAmount = 12.0;
- $discountGivenExVat = false;
- $discountMeanVatPercent = 20.0;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(125.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addDiscount($discountRows[0])
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
- $response = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(113.00, $response->amount);
- }
-
- // 4i. mean inc to single tax rate: 12i @20% -> 12i @25%, priceincvat = false -> resent as 9.6e @25%, priceincvat = false => correct order total at Svea
- function test_splitMeanAcrossTaxRates_4()
- {
- $discountAmount = 12.0;
- $discountGivenExVat = false;
- $discountMeanVatPercent = 20.0;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addDiscount($discountRows[0])
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
- $response = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(113.00, $response->amount);
- }
-
- // 7i. mean inc to two tax rates: 8.62e @16% -> 5.67i @25%; 4.33i @6%, priceincvat = true => correct order total at Svea
- function test_splitMeanAcrossTaxRates_7()
- {
- $discountAmount = 10.0;
- $discountGivenExVat = false;
- $discountMeanVatPercent = 16.0;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25, 6);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
- $this->assertEquals(5.67, $discountRows[0]->amountIncVat);
- $this->assertEquals(25, $discountRows[0]->vatPercent);
- $this->assertEquals('Name', $discountRows[0]->name);
- $this->assertEquals('Description (25%)', $discountRows[0]->description);
- $this->assertEquals(null, $discountRows[0]->amountExVat);
-
- $this->assertEquals(4.33, $discountRows[1]->amountIncVat);
- $this->assertEquals(6, $discountRows[1]->vatPercent);
- $this->assertEquals('Name', $discountRows[1]->name);
- $this->assertEquals('Description (6%)', $discountRows[1]->description);
- $this->assertEquals(null, $discountRows[1]->amountExVat);
-
- $this->assertEquals(2, count($discountRows));
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(125.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addDiscount($discountRows[0])
- ->addDiscount($discountRows[1])
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
- $response = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(115.00, $response->amount);
- }
-
- // 8i. mean inc to two tax rates: 10i @16 % -> 5.67i @25%; 4.33i @6%, priceincvat = false -> resent w/priceincvat = false => correct order total at Svea
- function test_splitMeanAcrossTaxRates_8()
- {
- $discountAmount = 10.0;
- $discountGivenExVat = false;
- $discountMeanVatPercent = 16.0;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25, 6);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addDiscount($discountRows[0])
- ->addDiscount($discountRows[1])
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
- $response = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(115.00, $response->amount);
- }
+ /**
+ * split mean vat given by shop (i.e. when using a coupon in OpenCart) into two fixedDiscountRows
+ */
+ public function test_splitMeanToTwoTaxRatesToFormatFixedDiscountRows_TwoRatesInOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ );
+
+ $discountExVatFromShop = 100;
+ $meanVatRateFromShop = 18.6667;
+ $titleFromShop = "Coupon (1112)";
+ $descriptionFromShop = "Value 100";
+
+ $taxRates = Helper::getTaxRatesInOrder($order);
+ $discountRows = Helper::splitMeanToTwoTaxRates($discountExVatFromShop, $meanVatRateFromShop, $titleFromShop, $descriptionFromShop, $taxRates);
+ foreach ($discountRows as $row) {
+ $order = $order->addDiscount($row);
+ }
+
+
+ $formatter = new WebServiceRowFormatter($order);
+ $newRows = $formatter->formatRows();
+
+ $newRow = $newRows[2];
+ $this->assertEquals("Coupon (1112): Value 100 (25%)", $newRow->Description);
+ $this->assertEquals(-66.67, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ $newRow = $newRows[3];
+ $this->assertEquals("Coupon (1112): Value 100 (6%)", $newRow->Description);
+ $this->assertEquals(-33.33, $newRow->PricePerUnit);
+ $this->assertEquals(6, $newRow->VatPercent);
+ }
+
+ /**
+ * split mean vat given by shop (i.e. when using a coupon in OpenCart) into two fixedDiscountRows
+ */
+ public function test_splitMeanToTwoTaxRatesToFormatFixedDiscountRows_OneRateInOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ );
+
+ $discountExVatFromShop = 100;
+ $meanVatRateFromShop = 25.00;
+ $titleFromShop = "Coupon (1112)";
+ $descriptionFromShop = "Value 100";
+
+ $taxRates = Helper::getTaxRatesInOrder($order);
+ $discountRows = Helper::splitMeanToTwoTaxRates($discountExVatFromShop, $meanVatRateFromShop, $titleFromShop, $descriptionFromShop, $taxRates);
+ foreach ($discountRows as $row) {
+ $order = $order->addDiscount($row);
+ }
+
+ $formatter = new 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);
+ }
+
+ /// Helper::paymentPlanPricePerMonth()
+ public function test_paymentPlanPricePerMonth_returns_PaymentPlanPricePerMonth()
+ {
+ $campaigns =
+ WebPay::getPaymentPlanParams(ConfigurationService::getDefaultConfig())
+ ->setCountryCode("SE")
+ ->doRequest();
+ $this->assertTrue($campaigns->accepted);
+
+ $pricesPerMonth = Helper::paymentPlanPricePerMonth(2000, $campaigns, true);
+ $this->assertInstanceOf("Svea\WebPay\WebService\GetPaymentPlanParams\PaymentPlanPricePerMonth", $pricesPerMonth);
+// $this->assertEquals(213060, $pricesPerMonth->values[0]['campaignCode']);//don't test to be flexible
+ $this->assertEquals(true, isset($pricesPerMonth->values[0]['pricePerMonth']));
+ }
+
+ // 3i. mean inc to single tax rate: 12i @20% -> 12i @25%, priceincvat = true => correct order total at Svea
+ function test_splitMeanAcrossTaxRates_3()
+ {
+ $discountAmount = 12.0;
+ $discountGivenExVat = false;
+ $discountMeanVatPercent = 20.0;
+ $discountName = 'Name';
+ $discountDescription = 'Description';
+ $allowedTaxRates = [25];
+
+ $discountRows = Helper::splitMeanAcrossTaxRates(
+ $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
+ );
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(125.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addDiscount($discountRows[0])
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
+ $response = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(113.00, $response->amount);
+ }
+
+ // 4i. mean inc to single tax rate: 12i @20% -> 12i @25%, priceincvat = false -> resent as 9.6e @25%, priceincvat = false => correct order total at Svea
+ function test_splitMeanAcrossTaxRates_4()
+ {
+ $discountAmount = 12.0;
+ $discountGivenExVat = false;
+ $discountMeanVatPercent = 20.0;
+ $discountName = 'Name';
+ $discountDescription = 'Description';
+ $allowedTaxRates = [25];
+
+ $discountRows = Helper::splitMeanAcrossTaxRates(
+ $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
+ );
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addDiscount($discountRows[0])
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
+ $response = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(113.00, $response->amount);
+ }
+
+ // 7i. mean inc to two tax rates: 8.62e @16% -> 5.67i @25%; 4.33i @6%, priceincvat = true => correct order total at Svea
+ function test_splitMeanAcrossTaxRates_7()
+ {
+ $discountAmount = 10.0;
+ $discountGivenExVat = false;
+ $discountMeanVatPercent = 16.0;
+ $discountName = 'Name';
+ $discountDescription = 'Description';
+ $allowedTaxRates = [25, 6];
+
+ $discountRows = Helper::splitMeanAcrossTaxRates(
+ $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
+ );
+
+ $this->assertEquals(5.67, $discountRows[0]->amountIncVat);
+ $this->assertEquals(25, $discountRows[0]->vatPercent);
+ $this->assertEquals('Name', $discountRows[0]->name);
+ $this->assertEquals('Description (25%)', $discountRows[0]->description);
+ $this->assertEquals(null, $discountRows[0]->amountExVat);
+
+ $this->assertEquals(4.33, $discountRows[1]->amountIncVat);
+ $this->assertEquals(6, $discountRows[1]->vatPercent);
+ $this->assertEquals('Name', $discountRows[1]->name);
+ $this->assertEquals('Description (6%)', $discountRows[1]->description);
+ $this->assertEquals(null, $discountRows[1]->amountExVat);
+
+ $this->assertEquals(2, count($discountRows));
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(125.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addDiscount($discountRows[0])
+ ->addDiscount($discountRows[1])
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
+ $response = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(115.00, $response->amount);
+ }
+
+ // 8i. mean inc to two tax rates: 10i @16 % -> 5.67i @25%; 4.33i @6%, priceincvat = false -> resent w/priceincvat = false => correct order total at Svea
+ function test_splitMeanAcrossTaxRates_8()
+ {
+ $discountAmount = 10.0;
+ $discountGivenExVat = false;
+ $discountMeanVatPercent = 16.0;
+ $discountName = 'Name';
+ $discountDescription = 'Description';
+ $allowedTaxRates = [25, 6];
+
+ $discountRows = Helper::splitMeanAcrossTaxRates(
+ $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
+ );
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addDiscount($discountRows[0])
+ ->addDiscount($discountRows[1])
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
+ $response = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(115.00, $response->amount);
+ }
}
-
-?>
diff --git a/test/IntegrationTest/HostedService/HandleOrder/AnnulTransactionIntegrationTest.php b/test/IntegrationTest/HostedService/HandleOrder/AnnulTransactionIntegrationTest.php
index 0ae1f3e2..6014aadd 100644
--- a/test/IntegrationTest/HostedService/HandleOrder/AnnulTransactionIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/HandleOrder/AnnulTransactionIntegrationTest.php
@@ -13,58 +13,56 @@
class AnnulTransactionIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * test_annul_card_transaction_not_found
- *
- * used as initial acceptance criteria for annul transaction feature
- */
- function test_annul_card_transaction_not_found()
- {
+ /**
+ * test_annul_card_transaction_not_found
+ *
+ * used as initial acceptance criteria for annul transaction feature
+ */
+ function test_annul_card_transaction_not_found()
+ {
- $transactionId = 987654;
+ $transactionId = 987654;
- $request = new AnnulTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->countryCode = "SE";
- $response = $request->doRequest();
+ $request = new AnnulTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\AnnulTransactionResponse", $response);
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\AnnulTransactionResponse", $response);
- // if we receive an error from the service, the integration test passes
- $this->assertEquals(0, $response->accepted);
- $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
- }
+ // if we receive an error from the service, the integration test passes
+ $this->assertEquals(0, $response->accepted);
+ $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
+ }
- /**
- * test_manual_annul_card
- *
- * run this manually after you've performed a card transaction and have set
- * the transaction status to success using the tools in the logg admin.
- */
- function test_manual_annul_card()
- {
+ /**
+ * test_manual_annul_card
+ *
+ * run this manually after you've performed a card transaction and have set
+ * the transaction status to success using the tools in the logg admin.
+ */
+ function test_manual_annul_card()
+ {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test of annul card transaction' // TODO
- );
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test of annul card transaction' // TODO
+ );
- // Set the below to match the transaction, then run the test.
- $customerrefno = "794";
- $transactionId = 587947;
+ // Set the below to match the transaction, then run the test.
+ $customerrefno = "794";
+ $transactionId = 587947;
- $request = new AnnulTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->countryCode = "SE";
- $response = $request->doRequest();
+ $request = new AnnulTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
- //print_r( $response);
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\AnnulTransactionResponse", $response);
- $this->assertEquals(1, $response->accepted);
- $this->assertStringMatchesFormat("%d", $response->transactionId); // %d => an unsigned integer value
+ //print_r( $response);
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\AnnulTransactionResponse", $response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertStringMatchesFormat("%d", $response->transactionId); // %d => an unsigned integer value
- $this->assertEquals($customerrefno, $response->clientOrderNumber);
- }
+ $this->assertEquals($customerrefno, $response->clientOrderNumber);
+ }
}
-
-?>
diff --git a/test/IntegrationTest/HostedService/HandleOrder/CancelRecurSubscriptionIntegrationTest.php b/test/IntegrationTest/HostedService/HandleOrder/CancelRecurSubscriptionIntegrationTest.php
index e20c2cae..78b62152 100644
--- a/test/IntegrationTest/HostedService/HandleOrder/CancelRecurSubscriptionIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/HandleOrder/CancelRecurSubscriptionIntegrationTest.php
@@ -15,84 +15,82 @@
class CancelRecurSubscriptionIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * test_cancel_recur_subscriptionid_not_found
- *
- * used as initial acceptance criteria for cancel recur transaction feature
- */
- function test_cancel_recur_subscriptionid_not_found()
- {
-
- $subscriptionId = 987654;
-
- $request = new CancelRecurSubscription(ConfigurationService::getDefaultConfig());
- $request->subscriptionId = $subscriptionId;
-
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CancelRecurSubscriptionResponse", $response);
-
- // if we receive an error from the service, the integration test passes
- $this->assertEquals(0, $response->accepted);
- $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
- }
-
- /**
- * test_manual_recur_transaction_amount
- *
- * run this test manually after you've performed a card transaction with
- * subscriptiontype set and have gotten the transaction details needed
- */
- function test_manual_recur_transaction_amount()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test of cancel recur subscription'
- );
-
- // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 2. go to verktyg -> betalning
- // 3. enter our test merchantid: 1130
- // 4. use the following xml, making sure to update to a unique customerrefno:
- // SVEACARDPAY RECURRINGCAPTURE SEK 500 100 test_recur_NN https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml
- // 5. the result should be:
- //
- //
- //SVEACARDPAY
- //1130
- //test_recur_5958696
- //500
- //SEK
- //6169
- //VISA
- //491642******8102
- //1
- //20
- //-
- //042434
- //
- //0
- //
- // 6. enter the received subscription id, etc. below and run the test
-
-
- $subscriptionId = 6169;
-
-
- // below is actual test, shouldn't need to change it
- $request = new CancelRecurSubscription(ConfigurationService::getDefaultConfig());
- $request->subscriptionId = $subscriptionId;
-
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CancelRecurSubscriptionResponse", $response);
-
- ////print_r($response);
- $this->assertEquals(1, $response->accepted);
- }
+ /**
+ * test_cancel_recur_subscriptionid_not_found
+ *
+ * used as initial acceptance criteria for cancel recur transaction feature
+ */
+ function test_cancel_recur_subscriptionid_not_found()
+ {
+
+ $subscriptionId = 987654;
+
+ $request = new CancelRecurSubscription(ConfigurationService::getDefaultConfig());
+ $request->subscriptionId = $subscriptionId;
+
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CancelRecurSubscriptionResponse", $response);
+
+ // if we receive an error from the service, the integration test passes
+ $this->assertEquals(0, $response->accepted);
+ $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
+ }
+
+ /**
+ * test_manual_recur_transaction_amount
+ *
+ * run this test manually after you've performed a card transaction with
+ * subscriptiontype set and have gotten the transaction details needed
+ */
+ function test_manual_recur_transaction_amount()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test of cancel recur subscription'
+ );
+
+ // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 2. go to verktyg -> betalning
+ // 3. enter our test merchantid: 1130
+ // 4. use the following xml, making sure to update to a unique customerrefno:
+ // SVEACARDPAY RECURRINGCAPTURE SEK 500 100 test_recur_NN https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml
+ // 5. the result should be:
+ //
+ //
+ //SVEACARDPAY
+ //1130
+ //test_recur_5958696
+ //500
+ //SEK
+ //6169
+ //VISA
+ //491642******8102
+ //1
+ //20
+ //-
+ //042434
+ //
+ //0
+ //
+ // 6. enter the received subscription id, etc. below and run the test
+
+
+ $subscriptionId = 6169;
+
+
+ // below is actual test, shouldn't need to change it
+ $request = new CancelRecurSubscription(ConfigurationService::getDefaultConfig());
+ $request->subscriptionId = $subscriptionId;
+
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CancelRecurSubscriptionResponse", $response);
+
+ ////print_r($response);
+ $this->assertEquals(1, $response->accepted);
+ }
}
-
-?>
diff --git a/test/IntegrationTest/HostedService/HandleOrder/ConfirmTransactionIntegrationTest.php b/test/IntegrationTest/HostedService/HandleOrder/ConfirmTransactionIntegrationTest.php
index 649252c6..5e93005d 100644
--- a/test/IntegrationTest/HostedService/HandleOrder/ConfirmTransactionIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/HandleOrder/ConfirmTransactionIntegrationTest.php
@@ -16,103 +16,101 @@
class ConfirmTransactionIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * test_confirmTransaction_card_success creates an order using card payment,
- * pays using card & receives a transaction id, then confirms the transaction
- *
- * used as acceptance criteria/smoke test for credit transaction feature
- */
- function test_confirmTransaction_card_success()
- {
-
- // not yet implemented, requires webdriver support
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'not yet implemented, requires webdriver support'
- );
-
- // also, needs to have SUCCESS status set on transaction
-
- // set up order (from testUtil?)
- $order = TestUtil::createOrder();
-
- // pay with card, receive transactionId
- $form = $order
- ->UsePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.se")
- //->setCancelUrl()
- //->setCardPageLanguage("SE")
- ->getPaymentForm();
-
- $url = "https://webpaypaymentgatewaystage.svea.com/webpay/payment";
-
- // do request modeled on Svea\WebPay\Test\IntegrationTest\HostedService\Payment\CardPaymentIntegrationTest.php
-
- // make sure the transaction has status AUTHORIZED at Svea
-
- // confirm transcation using above the transaction transactionId
-
- // assert response from confirmTransaction equals success
- }
-
-
- /**
- * test_confirm_card_transaction_not_found
- *
- * used as initial acceptance criteria for credit transaction feature
- */
- function test_confirm_card_transaction_not_found()
- {
-
- $transactionId = 987654;
- $captureDate = "2014-03-21";
-
- $request = new ConfirmTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->captureDate = $captureDate;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $response);
-
- // if we receive an error from the service, the integration test passes
- $this->assertEquals(0, $response->accepted);
- $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
- }
-
- /**
- * test_manual_credit_card
- *
- * run this manually after you've performed a card transaction and have set
- * the transaction status to success using the tools in the logg admin.
- */
- function test_manual_confirm_card()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test of confirm card transaction'
- );
-
- // Set the below to match the transaction, then run the test.
- $clientOrderNumber = "798";
- $transactionId = 587950;
- $captureDate = date('c');
-
- $request = new ConfirmTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->captureDate = $captureDate;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- //print_r( $response );
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $response);
- $this->assertEquals(1, $response->accepted);
- $this->assertStringMatchesFormat("%d", $response->transactionId); // %d => an unsigned integer value
-
- $this->assertEquals($clientOrderNumber, $response->clientOrderNumber);
- }
+ /**
+ * test_confirmTransaction_card_success creates an order using card payment,
+ * pays using card & receives a transaction id, then confirms the transaction
+ *
+ * used as acceptance criteria/smoke test for credit transaction feature
+ */
+ function test_confirmTransaction_card_success()
+ {
+
+ // not yet implemented, requires webdriver support
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'not yet implemented, requires webdriver support'
+ );
+
+ // also, needs to have SUCCESS status set on transaction
+
+ // set up order (from testUtil?)
+ $order = TestUtil::createOrder();
+
+ // pay with card, receive transactionId
+ $form = $order
+ ->UsePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.se")
+ //->setCancelUrl()
+ //->setCardPageLanguage("SE")
+ ->getPaymentForm();
+
+ $url = "https://webpaypaymentgatewaystage.svea.com/webpay/payment";
+
+ // do request modeled on Svea\WebPay\Test\IntegrationTest\HostedService\Payment\CardPaymentIntegrationTest.php
+
+ // make sure the transaction has status AUTHORIZED at Svea
+
+ // confirm transcation using above the transaction transactionId
+
+ // assert response from confirmTransaction equals success
+ }
+
+
+ /**
+ * test_confirm_card_transaction_not_found
+ *
+ * used as initial acceptance criteria for credit transaction feature
+ */
+ function test_confirm_card_transaction_not_found()
+ {
+
+ $transactionId = 987654;
+ $captureDate = "2014-03-21";
+
+ $request = new ConfirmTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->captureDate = $captureDate;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $response);
+
+ // if we receive an error from the service, the integration test passes
+ $this->assertEquals(0, $response->accepted);
+ $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
+ }
+
+ /**
+ * test_manual_credit_card
+ *
+ * run this manually after you've performed a card transaction and have set
+ * the transaction status to success using the tools in the logg admin.
+ */
+ function test_manual_confirm_card()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test of confirm card transaction'
+ );
+
+ // Set the below to match the transaction, then run the test.
+ $clientOrderNumber = "798";
+ $transactionId = 587950;
+ $captureDate = date('c');
+
+ $request = new ConfirmTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->captureDate = $captureDate;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ //print_r( $response );
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertStringMatchesFormat("%d", $response->transactionId); // %d => an unsigned integer value
+
+ $this->assertEquals($clientOrderNumber, $response->clientOrderNumber);
+ }
}
-
-?>
diff --git a/test/IntegrationTest/HostedService/HandleOrder/CreditTransactionIntegrationTest.php b/test/IntegrationTest/HostedService/HandleOrder/CreditTransactionIntegrationTest.php
index 3b43114e..cc527aed 100644
--- a/test/IntegrationTest/HostedService/HandleOrder/CreditTransactionIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/HandleOrder/CreditTransactionIntegrationTest.php
@@ -14,61 +14,59 @@
class CreditTransactionIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * test_credit_card_transaction_not_found
- *
- * used as initial acceptance criteria for credit transaction feature
- */
- function test_credit_card_transaction_not_found()
- {
-
- $transactionId = 987654;
- $amount = 100;
-
- $request = new CreditTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->creditAmount = $amount;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse", $response);
-
- $this->assertEquals(0, $response->accepted);
- $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
- }
-
- /**
- * test_manual_credit_card
- *
- * run this manually after you've performed a card transaction and have set
- * the transaction status to success using the tools in the logg admin.
- */
- function test_manual_credit_card()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test of credit card transaction'
- );
-
- // Set the below to match the transaction, then run the test.
- $clientOrderNumber = "796";
- $transactionId = 587949;
- $amount = 100;
-
- $request = new CreditTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->creditAmount = $amount;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- //print_r( $response );
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse", $response);
- $this->assertEquals(1, $response->accepted);
- $this->assertStringMatchesFormat("%d", $response->transactionId); // %d => an unsigned integer value
-
- $this->assertEquals($clientOrderNumber, $response->clientOrderNumber);
- }
+ /**
+ * test_credit_card_transaction_not_found
+ *
+ * used as initial acceptance criteria for credit transaction feature
+ */
+ function test_credit_card_transaction_not_found()
+ {
+
+ $transactionId = 987654;
+ $amount = 100;
+
+ $request = new CreditTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->creditAmount = $amount;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse", $response);
+
+ $this->assertEquals(0, $response->accepted);
+ $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
+ }
+
+ /**
+ * test_manual_credit_card
+ *
+ * run this manually after you've performed a card transaction and have set
+ * the transaction status to success using the tools in the logg admin.
+ */
+ function test_manual_credit_card()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test of credit card transaction'
+ );
+
+ // Set the below to match the transaction, then run the test.
+ $clientOrderNumber = "796";
+ $transactionId = 587949;
+ $amount = 100;
+
+ $request = new CreditTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->creditAmount = $amount;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ //print_r( $response );
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\CreditTransactionResponse", $response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertStringMatchesFormat("%d", $response->transactionId); // %d => an unsigned integer value
+
+ $this->assertEquals($clientOrderNumber, $response->clientOrderNumber);
+ }
}
-
-?>
diff --git a/test/IntegrationTest/HostedService/HandleOrder/GetPaymentMethodIntegrationTest.php b/test/IntegrationTest/HostedService/HandleOrder/GetPaymentMethodIntegrationTest.php
index e33ed885..de2ea37f 100644
--- a/test/IntegrationTest/HostedService/HandleOrder/GetPaymentMethodIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/HandleOrder/GetPaymentMethodIntegrationTest.php
@@ -15,25 +15,23 @@
class GetPaymentMethodIntegrationTest extends \PHPUnit\Framework\TestCase
{
- function testGetAllPaymentMethods()
- {
- $this->markTestSkipped("deprecated function.");
-
- $config = ConfigurationService::getDefaultConfig();
- $response = WebPay::getPaymentMethods($config)
- ->setContryCode("SE")
- ->doRequest();
-
- //print_r( "testGetAllPaymentMethods: "); //print_r( $response );
- $this->assertEquals(PaymentMethod::BANKAXESS, $response[0]);
- $this->assertEquals(PaymentMethod::NORDEA_SE, $response[1]);
- $this->assertEquals(PaymentMethod::SEB_SE, $response[2]);
- $this->assertEquals(PaymentMethod::KORTCERT, $response[3]);
- $this->assertEquals(SystemPaymentMethod::INVOICE_SE, $response[4]);
- $this->assertEquals(SystemPaymentMethod::PAYMENTPLAN_SE, $response[5]);
- $this->assertEquals(PaymentMethod::INVOICE, $response[6]);
- $this->assertEquals(PaymentMethod::PAYMENTPLAN, $response[7]);
- }
+ function testGetAllPaymentMethods()
+ {
+ $this->markTestSkipped("deprecated function.");
+
+ $config = ConfigurationService::getDefaultConfig();
+ $response = WebPay::getPaymentMethods($config)
+ ->setContryCode("SE")
+ ->doRequest();
+
+ //print_r( "testGetAllPaymentMethods: "); //print_r( $response );
+ $this->assertEquals(PaymentMethod::BANKAXESS, $response[0]);
+ $this->assertEquals(PaymentMethod::NORDEA_SE, $response[1]);
+ $this->assertEquals(PaymentMethod::SEB_SE, $response[2]);
+ $this->assertEquals(PaymentMethod::KORTCERT, $response[3]);
+ $this->assertEquals(SystemPaymentMethod::INVOICE_SE, $response[4]);
+ $this->assertEquals(SystemPaymentMethod::PAYMENTPLAN_SE, $response[5]);
+ $this->assertEquals(PaymentMethod::INVOICE, $response[6]);
+ $this->assertEquals(PaymentMethod::PAYMENTPLAN, $response[7]);
+ }
}
-
-?>
diff --git a/test/IntegrationTest/HostedService/HandleOrder/ListPaymentMethodsIntegrationTest.php b/test/IntegrationTest/HostedService/HandleOrder/ListPaymentMethodsIntegrationTest.php
index f8458a26..cc8478ae 100644
--- a/test/IntegrationTest/HostedService/HandleOrder/ListPaymentMethodsIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/HandleOrder/ListPaymentMethodsIntegrationTest.php
@@ -17,32 +17,30 @@
class ListPaymentMethodsIntegrationTest extends \PHPUnit\Framework\TestCase
{
- function test_listPaymentMethods_request_success()
- {
- $this->markTestSkipped('deprecated');
-
- $request = new ListPaymentMethods(ConfigurationService::getDefaultConfig());
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ListPaymentMethodsResponse", $response);
-
- //print_r( "test_listPaymentMethods_request_success: "); //print_r( $response );
- $this->assertEquals(1, $response->accepted);
- $this->assertInternalType("array", $response->paymentmethods);
-
- // from getpaymentmethods call, tied to merchantid
- $this->assertEquals(PaymentMethod::BANKAXESS, $response->paymentmethods[0]);
- $this->assertEquals(PaymentMethod::NORDEA_SE, $response->paymentmethods[1]);
- $this->assertEquals(PaymentMethod::SEB_SE, $response->paymentmethods[2]);
- $this->assertEquals(PaymentMethod::KORTCERT, $response->paymentmethods[3]);
- $this->assertEquals(SystemPaymentMethod::INVOICE_SE, $response->paymentmethods[4]);
- $this->assertEquals(SystemPaymentMethod::PAYMENTPLAN_SE, $response->paymentmethods[5]);
-
- // from ListPaymentMethods implementation, tied to clientid
- $this->assertEquals(PaymentMethod::INVOICE, $response->paymentmethods[6]);
- $this->assertEquals(PaymentMethod::PAYMENTPLAN, $response->paymentmethods[7]);
- }
+ function test_listPaymentMethods_request_success()
+ {
+ $this->markTestSkipped('deprecated');
+
+ $request = new ListPaymentMethods(ConfigurationService::getDefaultConfig());
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ListPaymentMethodsResponse", $response);
+
+ //print_r( "test_listPaymentMethods_request_success: "); //print_r( $response );
+ $this->assertEquals(1, $response->accepted);
+ $this->assertInternalType("array", $response->paymentmethods);
+
+ // from getpaymentmethods call, tied to merchantid
+ $this->assertEquals(PaymentMethod::BANKAXESS, $response->paymentmethods[0]);
+ $this->assertEquals(PaymentMethod::NORDEA_SE, $response->paymentmethods[1]);
+ $this->assertEquals(PaymentMethod::SEB_SE, $response->paymentmethods[2]);
+ $this->assertEquals(PaymentMethod::KORTCERT, $response->paymentmethods[3]);
+ $this->assertEquals(SystemPaymentMethod::INVOICE_SE, $response->paymentmethods[4]);
+ $this->assertEquals(SystemPaymentMethod::PAYMENTPLAN_SE, $response->paymentmethods[5]);
+
+ // from ListPaymentMethods implementation, tied to clientid
+ $this->assertEquals(PaymentMethod::INVOICE, $response->paymentmethods[6]);
+ $this->assertEquals(PaymentMethod::PAYMENTPLAN, $response->paymentmethods[7]);
+ }
}
-
-?>
diff --git a/test/IntegrationTest/HostedService/HandleOrder/LowerTransactionIntegrationTest.php b/test/IntegrationTest/HostedService/HandleOrder/LowerTransactionIntegrationTest.php
index 426f9ac5..35a26784 100644
--- a/test/IntegrationTest/HostedService/HandleOrder/LowerTransactionIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/HandleOrder/LowerTransactionIntegrationTest.php
@@ -14,109 +14,107 @@
class LowerTransactionIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * test_lower_transaction_transaction_not_found
- *
- * used as initial acceptance criteria for credit transaction feature
- */
- function test_lower_transaction_transaction_not_found()
- {
-
- $transactionId = 987654;
- $amountToLower = 100;
-
- $request = new LowerTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->amountToLower = $amountToLower;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\LowerTransactionResponse", $response);
-
- // if we receive an error from the service, the integration test passes
- $this->assertEquals(0, $response->accepted);
- $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
- }
-
- /**
- * test_manual_lower_transaction_amount
- *
- * run this test manually after you've performed a card transaction and have
- * gotten the the transaction details needed
- */
- function test_manual_lower_transaction_amount()
- {
-
- // i.e. order of 117 kr => 11700 at Svea, Svea status AUTHORIZED
- // - 100 => success, 11600 at Svea, Svea status AUTHORIZED
- // - 11600 => success, Svea status ANNULLED
- // - 1 => failure, accepted = 0, resultcode = "105 (ILLEGAL_TRANSACTIONSTATUS)", errormessage = "Invalid transaction status."
- //
- // new order of 130 kr => 13000 at Svea
- // - 13001 => failure, accepted = 0, resultcode = "305 (BAD_AMOUNT), errormessage = "Invalid value for amount."
- // - 10000 => success, success, 3000 at Svea, Svea status AUTHORIZED
- // - 3001 => failure, accepted = 0, resultcode = "305 (BAD_AMOUNT), errormessage = "Invalid value for amount."
- // - 3000 => success, Svea status ANNULLED
-
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test of lower transaction amount'
- );
-
- // Set the below to match the transaction, then run the test.
- $clientOrderNumber = "800";
- $transactionId = 587951;
- $amountToLower = 100; // TODO also check that status if lower by entire amount == ANNULLED
-
- $request = new LowerTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->amountToLower = $amountToLower;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
-
- print_r($response);
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\LowerTransactionResponse", $response);
- $this->assertEquals(1, $response->accepted);
- $this->assertStringMatchesFormat("%d", $response->transactionId); // %d => an unsigned integer value
- $this->assertEquals($clientOrderNumber, $response->clientOrderNumber);
-
- }
-
- function test_manual_alsoDoConfim_set_to_true_does_lowerTransaction_followed_by_confirmTransaction()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'test_manual_query_card_queryTransaction_returntype'
- );
-
- // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 2. go to verktyg -> betalning
- // 3. enter our test merchantid: 1130
- // 4. use the following xml, making sure to update to a unique customerrefno:
- // KORTCERT SEK 25500 600 test_manual_query_card_2 https://webpaypaymentgatewaystage.svea.com/webpay/admin/merchantresponsetest.xhtml Orderrow1 500 100 Orderrow description 1 123 st |
Orderrow2 12500 2500 Orderrow2 description 2 124 m2 |
- // 5. the result should be:
- // KORTCERT 1130 test_manual_query_card_3 25500 SEK VISA 444433xxxxxx1100 02 15 898924 0
-
- // 6. enter the received transaction id below and run the test
-
- // Set the below to match the transaction, then run the test.
- $transactionId = 586184;
-
- $lowerTransactionRequest = new LowerTransaction(ConfigurationService::getDefaultConfig());
- $lowerTransactionRequest->countryCode = "SE";
- $lowerTransactionRequest->transactionId = $transactionId;
- $lowerTransactionRequest->amountToLower = "1";
- $lowerTransactionRequest->alsoDoConfirm = true;
-
- $response = $lowerTransactionRequest->doRequest();
-
- //print_r( $response);
-
- $this->assertEquals(1, $response->accepted);
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $response);
- }
+ /**
+ * test_lower_transaction_transaction_not_found
+ *
+ * used as initial acceptance criteria for credit transaction feature
+ */
+ function test_lower_transaction_transaction_not_found()
+ {
+
+ $transactionId = 987654;
+ $amountToLower = 100;
+
+ $request = new LowerTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->amountToLower = $amountToLower;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\LowerTransactionResponse", $response);
+
+ // if we receive an error from the service, the integration test passes
+ $this->assertEquals(0, $response->accepted);
+ $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
+ }
+
+ /**
+ * test_manual_lower_transaction_amount
+ *
+ * run this test manually after you've performed a card transaction and have
+ * gotten the the transaction details needed
+ */
+ function test_manual_lower_transaction_amount()
+ {
+
+ // i.e. order of 117 kr => 11700 at Svea, Svea status AUTHORIZED
+ // - 100 => success, 11600 at Svea, Svea status AUTHORIZED
+ // - 11600 => success, Svea status ANNULLED
+ // - 1 => failure, accepted = 0, resultcode = "105 (ILLEGAL_TRANSACTIONSTATUS)", errormessage = "Invalid transaction status."
+ //
+ // new order of 130 kr => 13000 at Svea
+ // - 13001 => failure, accepted = 0, resultcode = "305 (BAD_AMOUNT), errormessage = "Invalid value for amount."
+ // - 10000 => success, success, 3000 at Svea, Svea status AUTHORIZED
+ // - 3001 => failure, accepted = 0, resultcode = "305 (BAD_AMOUNT), errormessage = "Invalid value for amount."
+ // - 3000 => success, Svea status ANNULLED
+
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test of lower transaction amount'
+ );
+
+ // Set the below to match the transaction, then run the test.
+ $clientOrderNumber = "800";
+ $transactionId = 587951;
+ $amountToLower = 100; // TODO also check that status if lower by entire amount == ANNULLED
+
+ $request = new LowerTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->amountToLower = $amountToLower;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+
+ print_r($response);
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\LowerTransactionResponse", $response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertStringMatchesFormat("%d", $response->transactionId); // %d => an unsigned integer value
+ $this->assertEquals($clientOrderNumber, $response->clientOrderNumber);
+
+ }
+
+ function test_manual_alsoDoConfim_set_to_true_does_lowerTransaction_followed_by_confirmTransaction()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'test_manual_query_card_queryTransaction_returntype'
+ );
+
+ // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 2. go to verktyg -> betalning
+ // 3. enter our test merchantid: 1130
+ // 4. use the following xml, making sure to update to a unique customerrefno:
+ // KORTCERT SEK 25500 600 test_manual_query_card_2 https://webpaypaymentgatewaystage.svea.com/webpay/admin/merchantresponsetest.xhtml Orderrow1 500 100 Orderrow description 1 123 st |
Orderrow2 12500 2500 Orderrow2 description 2 124 m2 |
+ // 5. the result should be:
+ // KORTCERT 1130 test_manual_query_card_3 25500 SEK VISA 444433xxxxxx1100 02 15 898924 0
+
+ // 6. enter the received transaction id below and run the test
+
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 586184;
+
+ $lowerTransactionRequest = new LowerTransaction(ConfigurationService::getDefaultConfig());
+ $lowerTransactionRequest->countryCode = "SE";
+ $lowerTransactionRequest->transactionId = $transactionId;
+ $lowerTransactionRequest->amountToLower = "1";
+ $lowerTransactionRequest->alsoDoConfirm = true;
+
+ $response = $lowerTransactionRequest->doRequest();
+
+ //print_r( $response);
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ConfirmTransactionResponse", $response);
+ }
}
-
-?>
diff --git a/test/IntegrationTest/HostedService/HandleOrder/QueryTransactionIntegrationTest.php b/test/IntegrationTest/HostedService/HandleOrder/QueryTransactionIntegrationTest.php
index 8ba65248..45efda66 100644
--- a/test/IntegrationTest/HostedService/HandleOrder/QueryTransactionIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/HandleOrder/QueryTransactionIntegrationTest.php
@@ -16,943 +16,941 @@
class QueryTransactionIntegrationTest extends \PHPUnit\Framework\TestCase
{
- // Svea\WebPay\WebPayAdmin::queryOrder() -----------------------------------------------
- // returned type
- /// queryOrder()
- // invoice
- // partpayment
- // card
- function test_queryOrder_queryCardOrder()
- {
- // Set the below to match the transaction, then run the test.
- $transactionId = 590177;
-
- $request = WebPayAdmin::queryOrder(
- ConfigurationService::getSingleCountryConfig(
- "SE",
- "foo", "bar", "123456", // invoice
- "foo", "bar", "123456", // paymentplan
- "foo", "bar", "123456", // accountplan
- "1200", // merchantid, secret
- "27f18bfcbe4d7f39971cb3460fbe7234a82fb48f985cf22a068fa1a685fe7e6f93c7d0d92fee4e8fd7dc0c9f11e2507300e675220ee85679afa681407ee2416d",
- false // prod = false
- )
- )
- ->setTransactionId(strval($transactionId))
- ->setCountryCode("SE");
- $response = $request->queryCardOrder()->doRequest();
-// echo "foo: ";
-// var_dump($response); die;
-
- $this->assertEquals(1, $response->accepted);
-
- $this->assertEquals($transactionId, $response->transactionId);
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[0]);
- $this->assertEquals("Soft213s", $response->numberedOrderRows[0]->articleNumber);
- $this->assertEquals("1.0", $response->numberedOrderRows[0]->quantity);
- $this->assertEquals("st", $response->numberedOrderRows[0]->unit);
- $this->assertEquals(3212.00, $response->numberedOrderRows[0]->amountExVat); // amount = 401500, vat = 80300 => 3212.00 @25%
- $this->assertEquals(25, $response->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("Soft", $response->numberedOrderRows[0]->name);
-// $this->assertEquals( "Specification", $response->numberedOrderRows[1]->description );
- $this->assertEquals(0, $response->numberedOrderRows[0]->vatDiscount);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[1]);
- $this->assertEquals("07", $response->numberedOrderRows[1]->articleNumber);
- $this->assertEquals("1.0", $response->numberedOrderRows[1]->quantity);
- $this->assertEquals("st", $response->numberedOrderRows[1]->unit);
- $this->assertEquals(0, $response->numberedOrderRows[1]->amountExVat); // amount = 401500, vat = 80300 => 3212.00 @25%
- $this->assertEquals(0, $response->numberedOrderRows[1]->vatPercent);
- $this->assertEquals("Sits: Hatfield Beige 6", $response->numberedOrderRows[1]->name);
-// $this->assertEquals( "Specification", $response->numberedOrderRows[1]->description );
- $this->assertEquals(0, $response->numberedOrderRows[1]->vatDiscount);
- }
-
- /**
- * test_query_card_transaction_not_found
- *
- * used as initial acceptance criteria for query transaction feature
- */
- function test_query_card_transaction_not_found()
- {
-
- $transactionId = 987654;
-
- $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $response);
-
- // if we receive an error from the service, the integration test passes
- $this->assertEquals(0, $response->accepted);
- $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
- }
-
- /**
- * test_manual_parsing_of_queried_payment_order_works
- *
- * run this manually after you've performed a card transaction and have set the
- * transaction status to success using the tools in the backoffice admin menu.
- */
- function test_manual_parsing_of_queried_payment_order_works()
- {
- $this->markTestSkipped('deprecated.');
- // Stop here and mark this test as incomplete.
-// $this->markTestIncomplete(
-// 'test_manual_parsing_of_queried_payment_order_works'
-// );
-
- // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 2. go to verktyg -> betalning
- // 3. enter our test merchantid: 1130
- // 4. use the following xml, making sure to update to a unique customerrefno:
- // KORTCERT SEK 25500 600 test_manual_query_card_2xz https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml Orderrow1 500 100 Orderrow description 1 123 st |
Orderrow2 12500 2500 Orderrow2 description 2 124 m2 |
- // 5. the result should be:
- // KORTCERT 1130 test_manual_query_card_2xz 25500 SEK VISA 444433xxxxxx1100 02 15 878087 0
-
- // 6. enter the received transaction id below and run the test
-
- // Set the below to match the transaction, then run the test.
- $transactionId = 587401;
-
- $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- // Example of raw card order 580964 response to parse (from QueryTransactionResponse formatXml):
- //
- //SimpleXMLElement Object
- //(
- // [transaction] => SimpleXMLElement Object
- // (
- // [@attributes] => Array
- // (
- // [id] => 580964
- // )
- //
- // [customerrefno] => test_manual_query_card_3
- // [merchantid] => 1130
- // [status] => SUCCESS
- // [amount] => 25500
- // [currency] => SEK
- // [vat] => 600
- // [capturedamount] => 25500
- // [authorizedamount] => 25500
- // [created] => 2014-04-11 15:49:30.647
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentmethod] => KORTCERT
- // [callbackurl] => SimpleXMLElement Object
- // (
- // )
- //
- // [capturedate] => 2014-04-13 00:15:14.267
- // [subscriptionid] => SimpleXMLElement Object
- // (
- // )
- //
- // [subscriptiontype] => SimpleXMLElement Object
- // (
- // )
- //
- // [orderrows] => SimpleXMLElement Object
- // (
- // [row] => Array
- // (
- // [0] => SimpleXMLElement Object
- // (
- // [id] => 45355
- // [name] => Orderrow1
- // [amount] => 500
- // [vat] => 100
- // [description] => Orderrow description
- // [quantity] => 1.0
- // [sku] => 123
- // [unit] => st
- // )
- //
- // [1] => SimpleXMLElement Object
- // (
- // [id] => 45356
- // [name] => Orderrow2
- // [amount] => 12500
- // [vat] => 2500
- // [description] => Orderrow2 description
- // [quantity] => 2.0
- // [sku] => 124
- // [unit] => m2
- // )
- //
- // )
- //
- // )
- //
- // )
- //
- // [statuscode] => 0
- //)
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $response);
-
- ////print_r($response); // uncomment to dump our processed request response:
- //Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse Object
- //(
- // [transactionId] => 587401
- // [clientOrderNumber] => test_manual_query_card_2xz
- // [merchantId] => 1130
- // [status] => AUTHORIZED
- // [amount] => 25500
- // [currency] => SEK
- // [vat] => 600
- // [capturedamount] =>
- // [authorizedamount] => 25500
- // [created] => 2014-10-06 15:35:55.327
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentMethod] => KORTCERT
- // [numberedOrderRows] => Array
- // (
- // [0] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
- // (
- // [creditInvoiceId] =>
- // [invoiceId] =>
- // [rowNumber] => 1
- // [status] =>
- // [articleNumber] => 123
- // [quantity] => 1
- // [unit] => st
- // [amountExVat] => 4
- // [vatPercent] => 25
- // [amountIncVat] =>
- // [name] => Orderrow1
- // [description] => Orderrow description
- // [discountPercent] =>
- // [vatDiscount] => 0
- // )
- //
- // [1] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
- // (
- // [creditInvoiceId] =>
- // [invoiceId] =>
- // [rowNumber] => 2
- // [status] =>
- // [articleNumber] => 124
- // [quantity] => 2
- // [unit] => m2
- // [amountExVat] => 100
- // [vatPercent] => 25
- // [amountIncVat] =>
- // [name] => Orderrow2
- // [description] => Orderrow2 description
- // [discountPercent] =>
- // [vatDiscount] => 0
- // )
- //
- // )
- //
- // [callbackurl] =>
- // [capturedate] =>
- // [subscriptionId] =>
- // [subscriptiontype] =>
- // [cardType] =>
- // [maskedCardNumber] =>
- // [eci] =>
- // [mdstatus] =>
- // [expiryYear] =>
- // [expiryMonth] =>
- // [chname] =>
- // [authCode] =>
- // [accepted] => 1
- // [resultcode] => 0
- // [errormessage] =>
- //)
-
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(0, $response->resultcode);
- $this->assertEquals(null, $response->errormessage);
-
- $this->assertEquals($transactionId, $response->transactionId);
- $this->assertEquals("test_manual_query_card_2xz", $response->clientOrderNumber); //
- $this->assertEquals("1130", $response->merchantId);
- //$this->assertEquals( "AUTHORIZED", $response->status ); // if just created
- $this->assertEquals("SUCCESS", $response->status); // after having been confirmed & batch process by bank
- $this->assertEquals("25500", $response->amount);
- $this->assertEquals("SEK", $response->currency);
- $this->assertEquals("600", $response->vat);
- //$this->assertEquals( "", $response->capturedamount ); // if just created
- $this->assertEquals("25500", $response->capturedamount); // after having been confirmed & batch process by bank
- $this->assertEquals("25500", $response->authorizedamount);
- $this->assertEquals("2014-10-06 15:35:55.327", $response->created);
- $this->assertEquals("CREDNONE", $response->creditstatus);
- $this->assertEquals("0", $response->creditedamount);
- $this->assertEquals("0", $response->merchantresponsecode);
- $this->assertEquals("KORTCERT", $response->paymentMethod);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[0]);
- $this->assertEquals("123", $response->numberedOrderRows[0]->articleNumber);
- $this->assertEquals("1", $response->numberedOrderRows[0]->quantity);
- $this->assertEquals("st", $response->numberedOrderRows[0]->unit);
- $this->assertEquals(4, $response->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(25, $response->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("Orderrow1", $response->numberedOrderRows[0]->name);
- $this->assertEquals("Orderrow description", $response->numberedOrderRows[0]->description);
- $this->assertEquals(0, $response->numberedOrderRows[0]->vatDiscount);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\OrderRow", $response->numberedOrderRows[1]);
- $this->assertEquals("124", $response->numberedOrderRows[1]->articleNumber);
- $this->assertEquals("2", $response->numberedOrderRows[1]->quantity);
- $this->assertEquals("m2", $response->numberedOrderRows[1]->unit);
- $this->assertEquals(100, $response->numberedOrderRows[1]->amountExVat);
- $this->assertEquals(25, $response->numberedOrderRows[1]->vatPercent);
- $this->assertEquals("Orderrow2", $response->numberedOrderRows[1]->name);
- $this->assertEquals("Orderrow2 description", $response->numberedOrderRows[1]->description);
- $this->assertEquals(0, $response->numberedOrderRows[1]->vatDiscount);
-
- $this->assertEquals(null, $response->callbackurl);
- //$this->assertEquals( null, $response->capturedate ); // if just created
- $this->assertEquals("2014-10-07 00:15:17.857", $response->capturedate); // after having been confirmed & batch process by bank
- $this->assertEquals(null, $response->subscriptionId);
- $this->assertEquals(null, $response->subscriptiontype);
- $this->assertEquals(null, $response->cardType);
- $this->assertEquals(null, $response->maskedCardNumber);
- $this->assertEquals(null, $response->eci);
- $this->assertEquals(null, $response->mdstatus);
- $this->assertEquals(null, $response->expiryYear);
- $this->assertEquals(null, $response->expiryMonth);
- $this->assertEquals(null, $response->chname);
- $this->assertEquals(null, $response->authCode);
- }
-
- function test_manual_parsing_of_queried_recur_order_without_orderrows_works()
- {
- $this->markTestSkipped('deprecated');
- // Stop here and mark this test as incomplete.
-// $this->markTestIncomplete(
-// 'test_manual_parsing_of_queried_recur_order_without_orderrows_works'
-// );
-
- // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 2. go to verktyg -> betalning
- // 3. enter our test merchantid: 1130
- // 4. use the following xml, making sure to update to a unique customerrefno:
- // KORTCERT RECURRINGCAPTURE SEK 500 100 test_recur_NN https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml
- // 5. the result should be:
- // KORTCERT 1130 test_recur_1 500 SEK 2922 VISA 444433xxxxxx1100 02 16 993955 0
-
- // 6. enter the received subscription id, etc. below and run the test
-
- // Set the below to match the transaction, then run the test.
- $transactionId = 581497;
-
- $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- // Example of raw recur order 581497 response (see QueryTransactionResponse class) to parse
- //
- //SimpleXMLElement Object
- //(
- // [transaction] => SimpleXMLElement Object
- // (
- // [@attributes] => Array
- // (
- // [id] => 581497
- // )
- //
- // [customerrefno] => test_recur_1
- // [merchantid] => 1130
- // [status] => SUCCESS
- // [amount] => 500
- // [currency] => SEK
- // [vat] => 100
- // [capturedamount] => 500
- // [authorizedamount] => 500
- // [created] => 2014-04-16 14:51:34.917
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentmethod] => KORTCERT
- // [callbackurl] => SimpleXMLElement Object
- // (
- // )
- //
- // [capturedate] => 2014-04-18 00:15:12.287
- // [subscriptionid] => 2922
- // [subscriptiontype] => RECURRINGCAPTURE
- // )
- //
- // [statuscode] => 0
- //)
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $response);
-
- ////print_r($response); // uncomment to dump our processed request response:
- //Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse Object
- //(
- // [transactionId] => 581497
- // [clientOrderNumber] => test_recur_1
- // [merchantId] => 1130
- // [status] => SUCCESS
- // [amount] => 500
- // [currency] => SEK
- // [vat] => 100
- // [capturedamount] => 500
- // [authorizedamount] => 500
- // [created] => 2014-04-16 14:51:34.917
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentMethod] => KORTCERT
- // [numberedOrderRows] =>
- // [callbackurl] =>
- // [capturedate] => 2014-04-18 00:15:12.287
- // [subscriptionId] => 2922
- // [subscriptiontype] => RECURRINGCAPTURE
- // [cardType] =>
- // [maskedCardNumber] =>
- // [eci] =>
- // [mdstatus] =>
- // [expiryYear] =>
- // [expiryMonth] =>
- // [chname] =>
- // [authCode] =>
- // [accepted] => 1
- // [resultcode] => 0
- // [errormessage] =>
- //)
-
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(0, $response->resultcode);
- $this->assertEquals(null, $response->errormessage);
-
- $this->assertEquals($transactionId, $response->transactionId);
- $this->assertEquals("test_recur_1", $response->clientOrderNumber); //
- $this->assertEquals("1130", $response->merchantId);
- $this->assertEquals("SUCCESS", $response->status); // after having been confirmed & batch process by bank
- $this->assertEquals("500", $response->amount);
- $this->assertEquals("SEK", $response->currency);
- $this->assertEquals("100", $response->vat);
- $this->assertEquals("500", $response->capturedamount); // after having been confirmed & batch process by bank
- $this->assertEquals("500", $response->authorizedamount);
- $this->assertEquals("2014-04-16 14:51:34.917", $response->created);
- $this->assertEquals("CREDNONE", $response->creditstatus);
- $this->assertEquals("0", $response->creditedamount);
- $this->assertEquals("0", $response->merchantresponsecode);
- $this->assertEquals("KORTCERT", $response->paymentMethod);
- $this->assertEquals(null, $response->numberedOrderRows);
- $this->assertEquals(null, $response->callbackurl);
- $this->assertEquals("2014-04-18 00:15:12.287", $response->capturedate);
- $this->assertEquals("2922", $response->subscriptionId);
- $this->assertEquals("RECURRINGCAPTURE", $response->subscriptiontype);
- $this->assertEquals(null, $response->cardType);
- $this->assertEquals(null, $response->maskedCardNumber);
- $this->assertEquals(null, $response->eci);
- $this->assertEquals(null, $response->mdstatus);
- $this->assertEquals(null, $response->expiryYear);
- $this->assertEquals(null, $response->expiryMonth);
- $this->assertEquals(null, $response->chname);
- $this->assertEquals(null, $response->authCode);
- }
-
- // TODO not updated
- function test_manual_parsing_of_queried_preparepayment_order_works()
- {
- $this->markTestSkipped('deprecated');
- // Stop here and mark this test as incomplete.
-// $this->markTestIncomplete(
-// 'test_manual_parsing_of_queried_recur_order_without_orderrows_works'
-// );
-
- // 1. See Svea\WebPay\Test\IntegrationTest\HostedService\Payment\CardPaymentURLIntegrationTest::test_manual_CardPayment_getPaymentUrl():
- // 2. run the test, and get the subscription paymenturl from the output
- // 3. go to the paymenturl and complete the transaction.
- // 4. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 5. retrieve the transactionid from the response in the transaction log
-
- // Set the below to match the transaction, then run the test.
- $transactionId = 586076;
-
- $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- // Example of raw recur order 586076 response (see QueryTransactionResponse class) to parse
- //
- //SimpleXMLElement Object
- //(
- // [transaction] => SimpleXMLElement Object
- // (
- // [@attributes] => Array
- // (
- // [id] => 586076
- // )
- //
- // [customerrefno] => clientOrderNumber:2014-09-10T14:27:23 02:00
- // [merchantid] => 1130
- // [status] => AUTHORIZED
- // [amount] => 25000
- // [currency] => SEK
- // [vat] => 5000
- // [capturedamount] => SimpleXMLElement Object
- // (
- // )
- //
- // [authorizedamount] => 25000
- // [created] => 2014-09-10 14:27:23.04
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentmethod] => KORTCERT
- // [callbackurl] => SimpleXMLElement Object
- // (
- // )
- //
- // [capturedate] => SimpleXMLElement Object
- // (
- // )
- //
- // [subscriptionid] => SimpleXMLElement Object
- // (
- // )
- //
- // [subscriptiontype] => SimpleXMLElement Object
- // (
- // )
- //
- // [customer] => SimpleXMLElement Object
- // (
- // [@attributes] => Array
- // (
- // [id] => 12536
- // )
- //
- // [firstname] => Tess T
- // [lastname] => Persson
- // [initials] => SimpleXMLElement Object
- // (
- // )
- //
- // [email] => SimpleXMLElement Object
- // (
- // )
- //
- // [ssn] => 194605092222
- // [address] => Testgatan
- // [address2] => c/o Eriksson, Erik
- // [city] => Stan
- // [country] => SE
- // [zip] => 99999
- // [phone] => SimpleXMLElement Object
- // (
- // )
- //
- // [vatnumber] => SimpleXMLElement Object
- // (
- // )
- //
- // [housenumber] => 1
- // [companyname] => SimpleXMLElement Object
- // (
- // )
- //
- // [fullname] => SimpleXMLElement Object
- // (
- // )
- //
- // )
- //
- // [orderrows] => SimpleXMLElement Object
- // (
- // [row] => SimpleXMLElement Object
- // (
- // [id] => 53730
- // [name] => Product
- // [amount] => 12500
- // [vat] => 2500
- // [description] => Specification
- // [quantity] => 2.0
- // [sku] => 1
- // [unit] => st
- // )
- //
- // )
- //
- // )
- //
- // [statuscode] => 0
- //)
-
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(0, $response->resultcode);
- $this->assertEquals(null, $response->errormessage);
-
- $this->assertEquals($transactionId, $response->transactionId);
- $this->assertEquals("clientOrderNumber:2014-09-10T14:27:23 02:00", $response->clientOrderNumber); //
- $this->assertEquals("1130", $response->merchantId);
- //$this->assertEquals( "AUTHORIZED", $response->status ); // if just created
- $this->assertEquals("SUCCESS", $response->status);
- $this->assertEquals("25000", $response->amount);
- $this->assertEquals("SEK", $response->currency);
- $this->assertEquals("5000", $response->vat);
- //$this->assertEquals( null, $response->capturedamount ); // if just created
- $this->assertEquals("25000", $response->capturedamount);
- $this->assertEquals("25000", $response->authorizedamount);
- $this->assertEquals("2014-09-10 14:27:23.04", $response->created);
- $this->assertEquals("CREDNONE", $response->creditstatus);
- $this->assertEquals("0", $response->creditedamount);
- $this->assertEquals("0", $response->merchantresponsecode);
- $this->assertEquals("KORTCERT", $response->paymentMethod);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\OrderRow", $response->numberedOrderRows[0]);
- $this->assertEquals("1", $response->numberedOrderRows[0]->articleNumber);
- $this->assertEquals("2.0", $response->numberedOrderRows[0]->quantity);
- $this->assertEquals("st", $response->numberedOrderRows[0]->unit);
- $this->assertEquals(100.00, $response->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(25.00, $response->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("Product", $response->numberedOrderRows[0]->name);
- $this->assertEquals("Specification", $response->numberedOrderRows[0]->description);
- $this->assertEquals(0, $response->numberedOrderRows[0]->vatDiscount);
-
- $this->assertEquals(null, $response->callbackurl);
- //$this->assertEquals( null, $response->capturedate ); // if just created
- $this->assertEquals("2014-09-11 00:15:11.313", $response->capturedate);
- $this->assertEquals(null, $response->subscriptionId);
- $this->assertEquals(null, $response->subscriptiontype);
- $this->assertEquals(null, $response->cardType);
- $this->assertEquals(null, $response->maskedCardNumber);
- $this->assertEquals(null, $response->eci);
- $this->assertEquals(null, $response->mdstatus);
- $this->assertEquals(null, $response->expiryYear);
- $this->assertEquals(null, $response->expiryMonth);
- $this->assertEquals(null, $response->chname);
- $this->assertEquals(null, $response->authCode);
- }
-
- /**
- * test_manual_query_card_queryTransactionResponse
- *
- * run this manually after you've performed a card transaction and have set
- * the transaction status to success using the tools in the logg admin.
- */
- function test_manual_query_card_queryTransaction_returntype()
- {
-
- // Stop here and mark this test as incomplete.
-// $this->markTestIncomplete(
-// 'test_manual_query_card_queryTransaction_returntype'
-// );
-
- // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 2. go to verktyg -> betalning
- // 3. enter our test merchantid: 1130
- // 4. use the following xml, making sure to update to a unique customerrefno:
- // KORTCERT SEK 25500 600 test_manual_query_card_2 https://webpaypaymentgatewaystage.svea.com/webpay/admin/merchantresponsetest.xhtml Orderrow1 500 100 Orderrow description 1 123 st |
Orderrow2 12500 2500 Orderrow2 description 2 124 m2 |
- // 5. the result should be:
- // KORTCERT 1130 test_manual_query_card_3 25500 SEK VISA 444433xxxxxx1100 02 15 898924 0
-
- // 6. enter the received transaction id below and run the test
-
- // Set the below to match the transaction, then run the test.
- $transactionId = 582690;
-
- $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $response);
-
- ////print_r($response);
- $this->assertEquals(1, $response->accepted);
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[0]);
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[1]);
-
- $this->assertEquals(0, $response->numberedOrderRows[1]->vatDiscount);
- }
-
- function test_manual_query_recur_card_initial_transaction()
- {
-
- // Stop here and mark this test as incomplete.
-// $this->markTestIncomplete(
-// 'test_manual_query_recur_card_initial_transaction'
-// );
-
- // Set the below to match the transaction, then run the test.
- $transactionId = 586159;
-
- // Example of raw recur order 586159 response (see QueryTransactionResponse class) to parse
- //
- //SimpleXMLElement Object
- //(
- // [transaction] => SimpleXMLElement Object
- // (
- // [@attributes] => Array
- // (
- // [id] => 586159
- // )
- //
- // [customerrefno] => clientOrderNumber:2014-09-12T11:02:50 02:00
- // [merchantid] => 1130
- // [status] => AUTHORIZED
- // [amount] => 25000
- // [currency] => SEK
- // [vat] => 5000
- // [capturedamount] => SimpleXMLElement Object
- // (
- // )
- //
- // [authorizedamount] => 25000
- // [created] => 2014-09-12 11:04:24.347
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentmethod] => KORTCERT
- // [callbackurl] => SimpleXMLElement Object
- // (
- // )
- //
- // [capturedate] => SimpleXMLElement Object
- // (
- // )
- //
- // [subscriptionid] => 3050
- // [subscriptiontype] => RECURRINGCAPTURE
- // [customer] => SimpleXMLElement Object
- // (
- // [@attributes] => Array
- // (
- // [id] => 12615
- // )
- //
- // [firstname] => Tess T
- // [lastname] => Persson
- // [initials] => SimpleXMLElement Object
- // (
- // )
- //
- // [email] => SimpleXMLElement Object
- // (
- // )
- //
- // [ssn] => 194605092222
- // [address] => Testgatan
- // [address2] => c/o Eriksson, Erik
- // [city] => Stan
- // [country] => SE
- // [zip] => 99999
- // [phone] => SimpleXMLElement Object
- // (
- // )
- //
- // [vatnumber] => SimpleXMLElement Object
- // (
- // )
- //
- // [housenumber] => 1
- // [companyname] => SimpleXMLElement Object
- // (
- // )
- //
- // [fullname] => SimpleXMLElement Object
- // (
- // )
- //
- // )
- //
- // [orderrows] => SimpleXMLElement Object
- // (
- // [row] => SimpleXMLElement Object
- // (
- // [id] => 53878
- // [name] => Product
- // [amount] => 12500
- // [vat] => 2500
- // [description] => Specification
- // [quantity] => 2.0
- // [sku] => 1
- // [unit] => st
- // )
- //
- // )
- //
- // )
- //
- // [statuscode] => 0
- //)
-
- $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $response);
-
- ////print_r($response);
-
- $this->assertEquals(1, $response->accepted);
-
- $this->assertEquals(3050, $response->subscriptionId);
- $this->assertEquals("RECURRINGCAPTURE", $response->subscriptiontype);
- }
-
-
- function test_manual_query_recur_card_recur_transaction()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'test_manual_query_recur_card_initial_transaction'
- );
-
- // 1. enter the below values from the transaction log from test_manual_recurring_payment_step_1
- // 2. run the test and check the output for the subscriptionId and transactionid of the recur request
-
- // Set the below to match the original transaction, then run the test.
- $paymentmethod = "KORTCERT";
- $merchantid = 1130;
- $currency = "SEK";
- $cardType = "VISA";
- $maskedCardNumber = "444433xxxxxx1100";
- $expiryMonth = 01;
- $expiryYear = 15;
- $subscriptionId = 3050; // insert
-
- // the below applies to the recur request, and may differ from the original transaction
- $new_amount = "2500"; // in minor currency
- $new_customerrefno = "test_manual_recurring_payment_step_1 " . date('c');
-
- // below is actual test, shouldn't need to change it
- $request = new RecurTransaction(ConfigurationService::getDefaultConfig());
- $request->countryCode = "SE";
- $request->subscriptionId = $subscriptionId;
- $request->currency = $currency;
- $request->customerRefNo = $new_customerrefno;
- $request->amount = $new_amount;
- $response = $request->doRequest();
-
- // check that request was accepted
- $this->assertEquals(1, $response->accepted);
-
- ////print_r("Recur card transaction response: "); //print_r( $response );
- //
- //Recur card transaction response: Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\RecurTransactionResponse Object
- //(
- // [transactionid] => 586165
- // [customerrefno] => test_manual_recurring_payment_step_1 2014-09-12T11:38:30+02:00
- // [paymentmethod] => CARD
- // [merchantid] => 1130
- // [amount] => 2500
- // [currency] => SEK
- // [cardType] => VISA
- // [maskedCardNumber] => 444433xxxxxx1100
- // [expiryMonth] => 01
- // [expiryYear] => 15
- // [authCode] => 153124
- // [subscriptionid] => 3050
- // [accepted] => 1
- // [resultcode] => 0
- // [errormessage] =>
- //)
-
- // Set the below to match the transaction, then run the test.
- $transactionId = $response->transactionId;
-
- //SimpleXMLElement Object
- //(
- // [transaction] => SimpleXMLElement Object
- // (
- // [@attributes] => Array
- // (
- // [id] => 586165
- // )
- //
- // [customerrefno] => test_manual_recurring_payment_step_1 2014-09-12T11:38:30+02:00
- // [merchantid] => 1130
- // [status] => AUTHORIZED
- // [amount] => 2500
- // [currency] => SEK
- // [vat] => SimpleXMLElement Object
- // (
- // )
- //
- // [capturedamount] => SimpleXMLElement Object
- // (
- // )
- //
- // [authorizedamount] => 2500
- // [created] => 2014-09-12 11:38:32.557
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentmethod] => CARD
- // [callbackurl] => SimpleXMLElement Object
- // (
- // )
- //
- // [capturedate] => SimpleXMLElement Object
- // (
- // )
- //
- // [subscriptionid] => 3050
- // [subscriptiontype] => RECURRINGCAPTURE
- // )
- //
- // [statuscode] => 0
- //)
-
- $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
- $request->transactionId = $transactionId;
- $request->countryCode = "SE";
- $queryResponse = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $queryResponse);
-
- ////print_r($queryResponse);
- //
- //Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse Object
- //(
- // [transactionId] => 587424
- // [clientOrderNumber] => test_manual_recurring_payment_step_1 2014-10-06T15:53:45+02:00
- // [merchantId] => 1130
- // [status] => AUTHORIZED
- // [amount] => 2500
- // [currency] => SEK
- // [vat] =>
- // [capturedamount] =>
- // [authorizedamount] => 2500
- // [created] => 2014-10-06 15:53:45.367
- // [creditstatus] => CREDNONE
- // [creditedamount] => 0
- // [merchantresponsecode] => 0
- // [paymentMethod] => CARD
- // [numberedOrderRows] =>
- // [callbackurl] =>
- // [capturedate] =>
- // [subscriptionId] => 3050
- // [subscriptiontype] => RECURRINGCAPTURE
- // [cardType] =>
- // [maskedCardNumber] =>
- // [eci] =>
- // [mdstatus] =>
- // [expiryYear] =>
- // [expiryMonth] =>
- // [chname] =>
- // [authCode] =>
- // [accepted] => 1
- // [resultcode] => 0
- // [errormessage] =>
- //)
-
- $this->assertEquals(1, $response->accepted);
- }
+ // Svea\WebPay\WebPayAdmin::queryOrder() -----------------------------------------------
+ // returned type
+ /// queryOrder()
+ // invoice
+ // partpayment
+ // card
+ function test_queryOrder_queryCardOrder()
+ {
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 590177;
+
+ $request = WebPayAdmin::queryOrder(
+ ConfigurationService::getSingleCountryConfig(
+ "SE",
+ "foo", "bar", "123456", // invoice
+ "foo", "bar", "123456", // paymentplan
+ "foo", "bar", "123456", // accountplan
+ "1200", // merchantid, secret
+ "27f18bfcbe4d7f39971cb3460fbe7234a82fb48f985cf22a068fa1a685fe7e6f93c7d0d92fee4e8fd7dc0c9f11e2507300e675220ee85679afa681407ee2416d",
+ false // prod = false
+ )
+ )
+ ->setTransactionId(strval($transactionId))
+ ->setCountryCode("SE");
+ $response = $request->queryCardOrder()->doRequest();
+// echo "foo: ";
+// var_dump($response); die;
+
+ $this->assertEquals(1, $response->accepted);
+
+ $this->assertEquals($transactionId, $response->transactionId);
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[0]);
+ $this->assertEquals("Soft213s", $response->numberedOrderRows[0]->articleNumber);
+ $this->assertEquals("1.0", $response->numberedOrderRows[0]->quantity);
+ $this->assertEquals("st", $response->numberedOrderRows[0]->unit);
+ $this->assertEquals(3212.00, $response->numberedOrderRows[0]->amountExVat); // amount = 401500, vat = 80300 => 3212.00 @25%
+ $this->assertEquals(25, $response->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("Soft", $response->numberedOrderRows[0]->name);
+// $this->assertEquals( "Specification", $response->numberedOrderRows[1]->description );
+ $this->assertEquals(0, $response->numberedOrderRows[0]->vatDiscount);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[1]);
+ $this->assertEquals("07", $response->numberedOrderRows[1]->articleNumber);
+ $this->assertEquals("1.0", $response->numberedOrderRows[1]->quantity);
+ $this->assertEquals("st", $response->numberedOrderRows[1]->unit);
+ $this->assertEquals(0, $response->numberedOrderRows[1]->amountExVat); // amount = 401500, vat = 80300 => 3212.00 @25%
+ $this->assertEquals(0, $response->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals("Sits: Hatfield Beige 6", $response->numberedOrderRows[1]->name);
+// $this->assertEquals( "Specification", $response->numberedOrderRows[1]->description );
+ $this->assertEquals(0, $response->numberedOrderRows[1]->vatDiscount);
+ }
+
+ /**
+ * test_query_card_transaction_not_found
+ *
+ * used as initial acceptance criteria for query transaction feature
+ */
+ function test_query_card_transaction_not_found()
+ {
+
+ $transactionId = 987654;
+
+ $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $response);
+
+ // if we receive an error from the service, the integration test passes
+ $this->assertEquals(0, $response->accepted);
+ $this->assertEquals("128 (NO_SUCH_TRANS)", $response->resultcode);
+ }
+
+ /**
+ * test_manual_parsing_of_queried_payment_order_works
+ *
+ * run this manually after you've performed a card transaction and have set the
+ * transaction status to success using the tools in the backoffice admin menu.
+ */
+ function test_manual_parsing_of_queried_payment_order_works()
+ {
+ $this->markTestSkipped('deprecated.');
+ // Stop here and mark this test as incomplete.
+// $this->markTestIncomplete(
+// 'test_manual_parsing_of_queried_payment_order_works'
+// );
+
+ // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 2. go to verktyg -> betalning
+ // 3. enter our test merchantid: 1130
+ // 4. use the following xml, making sure to update to a unique customerrefno:
+ // KORTCERT SEK 25500 600 test_manual_query_card_2xz https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml Orderrow1 500 100 Orderrow description 1 123 st |
Orderrow2 12500 2500 Orderrow2 description 2 124 m2 |
+ // 5. the result should be:
+ // KORTCERT 1130 test_manual_query_card_2xz 25500 SEK VISA 444433xxxxxx1100 02 15 878087 0
+
+ // 6. enter the received transaction id below and run the test
+
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 587401;
+
+ $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ // Example of raw card order 580964 response to parse (from QueryTransactionResponse formatXml):
+ //
+ //SimpleXMLElement Object
+ //(
+ // [transaction] => SimpleXMLElement Object
+ // (
+ // [@attributes] => Array
+ // (
+ // [id] => 580964
+ // )
+ //
+ // [customerrefno] => test_manual_query_card_3
+ // [merchantid] => 1130
+ // [status] => SUCCESS
+ // [amount] => 25500
+ // [currency] => SEK
+ // [vat] => 600
+ // [capturedamount] => 25500
+ // [authorizedamount] => 25500
+ // [created] => 2014-04-11 15:49:30.647
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentmethod] => KORTCERT
+ // [callbackurl] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [capturedate] => 2014-04-13 00:15:14.267
+ // [subscriptionid] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [subscriptiontype] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [orderrows] => SimpleXMLElement Object
+ // (
+ // [row] => Array
+ // (
+ // [0] => SimpleXMLElement Object
+ // (
+ // [id] => 45355
+ // [name] => Orderrow1
+ // [amount] => 500
+ // [vat] => 100
+ // [description] => Orderrow description
+ // [quantity] => 1.0
+ // [sku] => 123
+ // [unit] => st
+ // )
+ //
+ // [1] => SimpleXMLElement Object
+ // (
+ // [id] => 45356
+ // [name] => Orderrow2
+ // [amount] => 12500
+ // [vat] => 2500
+ // [description] => Orderrow2 description
+ // [quantity] => 2.0
+ // [sku] => 124
+ // [unit] => m2
+ // )
+ //
+ // )
+ //
+ // )
+ //
+ // )
+ //
+ // [statuscode] => 0
+ //)
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $response);
+
+ ////print_r($response); // uncomment to dump our processed request response:
+ //Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse Object
+ //(
+ // [transactionId] => 587401
+ // [clientOrderNumber] => test_manual_query_card_2xz
+ // [merchantId] => 1130
+ // [status] => AUTHORIZED
+ // [amount] => 25500
+ // [currency] => SEK
+ // [vat] => 600
+ // [capturedamount] =>
+ // [authorizedamount] => 25500
+ // [created] => 2014-10-06 15:35:55.327
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentMethod] => KORTCERT
+ // [numberedOrderRows] => Array
+ // (
+ // [0] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
+ // (
+ // [creditInvoiceId] =>
+ // [invoiceId] =>
+ // [rowNumber] => 1
+ // [status] =>
+ // [articleNumber] => 123
+ // [quantity] => 1
+ // [unit] => st
+ // [amountExVat] => 4
+ // [vatPercent] => 25
+ // [amountIncVat] =>
+ // [name] => Orderrow1
+ // [description] => Orderrow description
+ // [discountPercent] =>
+ // [vatDiscount] => 0
+ // )
+ //
+ // [1] => Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow Object
+ // (
+ // [creditInvoiceId] =>
+ // [invoiceId] =>
+ // [rowNumber] => 2
+ // [status] =>
+ // [articleNumber] => 124
+ // [quantity] => 2
+ // [unit] => m2
+ // [amountExVat] => 100
+ // [vatPercent] => 25
+ // [amountIncVat] =>
+ // [name] => Orderrow2
+ // [description] => Orderrow2 description
+ // [discountPercent] =>
+ // [vatDiscount] => 0
+ // )
+ //
+ // )
+ //
+ // [callbackurl] =>
+ // [capturedate] =>
+ // [subscriptionId] =>
+ // [subscriptiontype] =>
+ // [cardType] =>
+ // [maskedCardNumber] =>
+ // [eci] =>
+ // [mdstatus] =>
+ // [expiryYear] =>
+ // [expiryMonth] =>
+ // [chname] =>
+ // [authCode] =>
+ // [accepted] => 1
+ // [resultcode] => 0
+ // [errormessage] =>
+ //)
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(0, $response->resultcode);
+ $this->assertEquals(null, $response->errormessage);
+
+ $this->assertEquals($transactionId, $response->transactionId);
+ $this->assertEquals("test_manual_query_card_2xz", $response->clientOrderNumber); //
+ $this->assertEquals("1130", $response->merchantId);
+ //$this->assertEquals( "AUTHORIZED", $response->status ); // if just created
+ $this->assertEquals("SUCCESS", $response->status); // after having been confirmed & batch process by bank
+ $this->assertEquals("25500", $response->amount);
+ $this->assertEquals("SEK", $response->currency);
+ $this->assertEquals("600", $response->vat);
+ //$this->assertEquals( "", $response->capturedamount ); // if just created
+ $this->assertEquals("25500", $response->capturedamount); // after having been confirmed & batch process by bank
+ $this->assertEquals("25500", $response->authorizedamount);
+ $this->assertEquals("2014-10-06 15:35:55.327", $response->created);
+ $this->assertEquals("CREDNONE", $response->creditstatus);
+ $this->assertEquals("0", $response->creditedamount);
+ $this->assertEquals("0", $response->merchantresponsecode);
+ $this->assertEquals("KORTCERT", $response->paymentMethod);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[0]);
+ $this->assertEquals("123", $response->numberedOrderRows[0]->articleNumber);
+ $this->assertEquals("1", $response->numberedOrderRows[0]->quantity);
+ $this->assertEquals("st", $response->numberedOrderRows[0]->unit);
+ $this->assertEquals(4, $response->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(25, $response->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("Orderrow1", $response->numberedOrderRows[0]->name);
+ $this->assertEquals("Orderrow description", $response->numberedOrderRows[0]->description);
+ $this->assertEquals(0, $response->numberedOrderRows[0]->vatDiscount);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\OrderRow", $response->numberedOrderRows[1]);
+ $this->assertEquals("124", $response->numberedOrderRows[1]->articleNumber);
+ $this->assertEquals("2", $response->numberedOrderRows[1]->quantity);
+ $this->assertEquals("m2", $response->numberedOrderRows[1]->unit);
+ $this->assertEquals(100, $response->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals(25, $response->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals("Orderrow2", $response->numberedOrderRows[1]->name);
+ $this->assertEquals("Orderrow2 description", $response->numberedOrderRows[1]->description);
+ $this->assertEquals(0, $response->numberedOrderRows[1]->vatDiscount);
+
+ $this->assertEquals(null, $response->callbackurl);
+ //$this->assertEquals( null, $response->capturedate ); // if just created
+ $this->assertEquals("2014-10-07 00:15:17.857", $response->capturedate); // after having been confirmed & batch process by bank
+ $this->assertEquals(null, $response->subscriptionId);
+ $this->assertEquals(null, $response->subscriptiontype);
+ $this->assertEquals(null, $response->cardType);
+ $this->assertEquals(null, $response->maskedCardNumber);
+ $this->assertEquals(null, $response->eci);
+ $this->assertEquals(null, $response->mdstatus);
+ $this->assertEquals(null, $response->expiryYear);
+ $this->assertEquals(null, $response->expiryMonth);
+ $this->assertEquals(null, $response->chname);
+ $this->assertEquals(null, $response->authCode);
+ }
+
+ function test_manual_parsing_of_queried_recur_order_without_orderrows_works()
+ {
+ $this->markTestSkipped('deprecated');
+ // Stop here and mark this test as incomplete.
+// $this->markTestIncomplete(
+// 'test_manual_parsing_of_queried_recur_order_without_orderrows_works'
+// );
+
+ // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 2. go to verktyg -> betalning
+ // 3. enter our test merchantid: 1130
+ // 4. use the following xml, making sure to update to a unique customerrefno:
+ // KORTCERT RECURRINGCAPTURE SEK 500 100 test_recur_NN https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml
+ // 5. the result should be:
+ // KORTCERT 1130 test_recur_1 500 SEK 2922 VISA 444433xxxxxx1100 02 16 993955 0
+
+ // 6. enter the received subscription id, etc. below and run the test
+
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 581497;
+
+ $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ // Example of raw recur order 581497 response (see QueryTransactionResponse class) to parse
+ //
+ //SimpleXMLElement Object
+ //(
+ // [transaction] => SimpleXMLElement Object
+ // (
+ // [@attributes] => Array
+ // (
+ // [id] => 581497
+ // )
+ //
+ // [customerrefno] => test_recur_1
+ // [merchantid] => 1130
+ // [status] => SUCCESS
+ // [amount] => 500
+ // [currency] => SEK
+ // [vat] => 100
+ // [capturedamount] => 500
+ // [authorizedamount] => 500
+ // [created] => 2014-04-16 14:51:34.917
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentmethod] => KORTCERT
+ // [callbackurl] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [capturedate] => 2014-04-18 00:15:12.287
+ // [subscriptionid] => 2922
+ // [subscriptiontype] => RECURRINGCAPTURE
+ // )
+ //
+ // [statuscode] => 0
+ //)
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $response);
+
+ ////print_r($response); // uncomment to dump our processed request response:
+ //Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse Object
+ //(
+ // [transactionId] => 581497
+ // [clientOrderNumber] => test_recur_1
+ // [merchantId] => 1130
+ // [status] => SUCCESS
+ // [amount] => 500
+ // [currency] => SEK
+ // [vat] => 100
+ // [capturedamount] => 500
+ // [authorizedamount] => 500
+ // [created] => 2014-04-16 14:51:34.917
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentMethod] => KORTCERT
+ // [numberedOrderRows] =>
+ // [callbackurl] =>
+ // [capturedate] => 2014-04-18 00:15:12.287
+ // [subscriptionId] => 2922
+ // [subscriptiontype] => RECURRINGCAPTURE
+ // [cardType] =>
+ // [maskedCardNumber] =>
+ // [eci] =>
+ // [mdstatus] =>
+ // [expiryYear] =>
+ // [expiryMonth] =>
+ // [chname] =>
+ // [authCode] =>
+ // [accepted] => 1
+ // [resultcode] => 0
+ // [errormessage] =>
+ //)
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(0, $response->resultcode);
+ $this->assertEquals(null, $response->errormessage);
+
+ $this->assertEquals($transactionId, $response->transactionId);
+ $this->assertEquals("test_recur_1", $response->clientOrderNumber); //
+ $this->assertEquals("1130", $response->merchantId);
+ $this->assertEquals("SUCCESS", $response->status); // after having been confirmed & batch process by bank
+ $this->assertEquals("500", $response->amount);
+ $this->assertEquals("SEK", $response->currency);
+ $this->assertEquals("100", $response->vat);
+ $this->assertEquals("500", $response->capturedamount); // after having been confirmed & batch process by bank
+ $this->assertEquals("500", $response->authorizedamount);
+ $this->assertEquals("2014-04-16 14:51:34.917", $response->created);
+ $this->assertEquals("CREDNONE", $response->creditstatus);
+ $this->assertEquals("0", $response->creditedamount);
+ $this->assertEquals("0", $response->merchantresponsecode);
+ $this->assertEquals("KORTCERT", $response->paymentMethod);
+ $this->assertEquals(null, $response->numberedOrderRows);
+ $this->assertEquals(null, $response->callbackurl);
+ $this->assertEquals("2014-04-18 00:15:12.287", $response->capturedate);
+ $this->assertEquals("2922", $response->subscriptionId);
+ $this->assertEquals("RECURRINGCAPTURE", $response->subscriptiontype);
+ $this->assertEquals(null, $response->cardType);
+ $this->assertEquals(null, $response->maskedCardNumber);
+ $this->assertEquals(null, $response->eci);
+ $this->assertEquals(null, $response->mdstatus);
+ $this->assertEquals(null, $response->expiryYear);
+ $this->assertEquals(null, $response->expiryMonth);
+ $this->assertEquals(null, $response->chname);
+ $this->assertEquals(null, $response->authCode);
+ }
+
+ // TODO not updated
+ function test_manual_parsing_of_queried_preparepayment_order_works()
+ {
+ $this->markTestSkipped('deprecated');
+ // Stop here and mark this test as incomplete.
+// $this->markTestIncomplete(
+// 'test_manual_parsing_of_queried_recur_order_without_orderrows_works'
+// );
+
+ // 1. See Svea\WebPay\Test\IntegrationTest\HostedService\Payment\CardPaymentURLIntegrationTest::test_manual_CardPayment_getPaymentUrl():
+ // 2. run the test, and get the subscription paymenturl from the output
+ // 3. go to the paymenturl and complete the transaction.
+ // 4. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 5. retrieve the transactionid from the response in the transaction log
+
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 586076;
+
+ $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ // Example of raw recur order 586076 response (see QueryTransactionResponse class) to parse
+ //
+ //SimpleXMLElement Object
+ //(
+ // [transaction] => SimpleXMLElement Object
+ // (
+ // [@attributes] => Array
+ // (
+ // [id] => 586076
+ // )
+ //
+ // [customerrefno] => clientOrderNumber:2014-09-10T14:27:23 02:00
+ // [merchantid] => 1130
+ // [status] => AUTHORIZED
+ // [amount] => 25000
+ // [currency] => SEK
+ // [vat] => 5000
+ // [capturedamount] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [authorizedamount] => 25000
+ // [created] => 2014-09-10 14:27:23.04
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentmethod] => KORTCERT
+ // [callbackurl] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [capturedate] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [subscriptionid] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [subscriptiontype] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [customer] => SimpleXMLElement Object
+ // (
+ // [@attributes] => Array
+ // (
+ // [id] => 12536
+ // )
+ //
+ // [firstname] => Tess T
+ // [lastname] => Persson
+ // [initials] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [email] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [ssn] => 194605092222
+ // [address] => Testgatan
+ // [address2] => c/o Eriksson, Erik
+ // [city] => Stan
+ // [country] => SE
+ // [zip] => 99999
+ // [phone] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [vatnumber] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [housenumber] => 1
+ // [companyname] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [fullname] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // )
+ //
+ // [orderrows] => SimpleXMLElement Object
+ // (
+ // [row] => SimpleXMLElement Object
+ // (
+ // [id] => 53730
+ // [name] => Product
+ // [amount] => 12500
+ // [vat] => 2500
+ // [description] => Specification
+ // [quantity] => 2.0
+ // [sku] => 1
+ // [unit] => st
+ // )
+ //
+ // )
+ //
+ // )
+ //
+ // [statuscode] => 0
+ //)
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(0, $response->resultcode);
+ $this->assertEquals(null, $response->errormessage);
+
+ $this->assertEquals($transactionId, $response->transactionId);
+ $this->assertEquals("clientOrderNumber:2014-09-10T14:27:23 02:00", $response->clientOrderNumber); //
+ $this->assertEquals("1130", $response->merchantId);
+ //$this->assertEquals( "AUTHORIZED", $response->status ); // if just created
+ $this->assertEquals("SUCCESS", $response->status);
+ $this->assertEquals("25000", $response->amount);
+ $this->assertEquals("SEK", $response->currency);
+ $this->assertEquals("5000", $response->vat);
+ //$this->assertEquals( null, $response->capturedamount ); // if just created
+ $this->assertEquals("25000", $response->capturedamount);
+ $this->assertEquals("25000", $response->authorizedamount);
+ $this->assertEquals("2014-09-10 14:27:23.04", $response->created);
+ $this->assertEquals("CREDNONE", $response->creditstatus);
+ $this->assertEquals("0", $response->creditedamount);
+ $this->assertEquals("0", $response->merchantresponsecode);
+ $this->assertEquals("KORTCERT", $response->paymentMethod);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\OrderRow", $response->numberedOrderRows[0]);
+ $this->assertEquals("1", $response->numberedOrderRows[0]->articleNumber);
+ $this->assertEquals("2.0", $response->numberedOrderRows[0]->quantity);
+ $this->assertEquals("st", $response->numberedOrderRows[0]->unit);
+ $this->assertEquals(100.00, $response->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(25.00, $response->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("Product", $response->numberedOrderRows[0]->name);
+ $this->assertEquals("Specification", $response->numberedOrderRows[0]->description);
+ $this->assertEquals(0, $response->numberedOrderRows[0]->vatDiscount);
+
+ $this->assertEquals(null, $response->callbackurl);
+ //$this->assertEquals( null, $response->capturedate ); // if just created
+ $this->assertEquals("2014-09-11 00:15:11.313", $response->capturedate);
+ $this->assertEquals(null, $response->subscriptionId);
+ $this->assertEquals(null, $response->subscriptiontype);
+ $this->assertEquals(null, $response->cardType);
+ $this->assertEquals(null, $response->maskedCardNumber);
+ $this->assertEquals(null, $response->eci);
+ $this->assertEquals(null, $response->mdstatus);
+ $this->assertEquals(null, $response->expiryYear);
+ $this->assertEquals(null, $response->expiryMonth);
+ $this->assertEquals(null, $response->chname);
+ $this->assertEquals(null, $response->authCode);
+ }
+
+ /**
+ * test_manual_query_card_queryTransactionResponse
+ *
+ * run this manually after you've performed a card transaction and have set
+ * the transaction status to success using the tools in the logg admin.
+ */
+ function test_manual_query_card_queryTransaction_returntype()
+ {
+
+ // Stop here and mark this test as incomplete.
+// $this->markTestIncomplete(
+// 'test_manual_query_card_queryTransaction_returntype'
+// );
+
+ // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 2. go to verktyg -> betalning
+ // 3. enter our test merchantid: 1130
+ // 4. use the following xml, making sure to update to a unique customerrefno:
+ // KORTCERT SEK 25500 600 test_manual_query_card_2 https://webpaypaymentgatewaystage.svea.com/webpay/admin/merchantresponsetest.xhtml Orderrow1 500 100 Orderrow description 1 123 st |
Orderrow2 12500 2500 Orderrow2 description 2 124 m2 |
+ // 5. the result should be:
+ // KORTCERT 1130 test_manual_query_card_3 25500 SEK VISA 444433xxxxxx1100 02 15 898924 0
+
+ // 6. enter the received transaction id below and run the test
+
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 582690;
+
+ $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $response);
+
+ ////print_r($response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[0]);
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[1]);
+
+ $this->assertEquals(0, $response->numberedOrderRows[1]->vatDiscount);
+ }
+
+ function test_manual_query_recur_card_initial_transaction()
+ {
+
+ // Stop here and mark this test as incomplete.
+// $this->markTestIncomplete(
+// 'test_manual_query_recur_card_initial_transaction'
+// );
+
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 586159;
+
+ // Example of raw recur order 586159 response (see QueryTransactionResponse class) to parse
+ //
+ //SimpleXMLElement Object
+ //(
+ // [transaction] => SimpleXMLElement Object
+ // (
+ // [@attributes] => Array
+ // (
+ // [id] => 586159
+ // )
+ //
+ // [customerrefno] => clientOrderNumber:2014-09-12T11:02:50 02:00
+ // [merchantid] => 1130
+ // [status] => AUTHORIZED
+ // [amount] => 25000
+ // [currency] => SEK
+ // [vat] => 5000
+ // [capturedamount] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [authorizedamount] => 25000
+ // [created] => 2014-09-12 11:04:24.347
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentmethod] => KORTCERT
+ // [callbackurl] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [capturedate] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [subscriptionid] => 3050
+ // [subscriptiontype] => RECURRINGCAPTURE
+ // [customer] => SimpleXMLElement Object
+ // (
+ // [@attributes] => Array
+ // (
+ // [id] => 12615
+ // )
+ //
+ // [firstname] => Tess T
+ // [lastname] => Persson
+ // [initials] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [email] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [ssn] => 194605092222
+ // [address] => Testgatan
+ // [address2] => c/o Eriksson, Erik
+ // [city] => Stan
+ // [country] => SE
+ // [zip] => 99999
+ // [phone] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [vatnumber] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [housenumber] => 1
+ // [companyname] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [fullname] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // )
+ //
+ // [orderrows] => SimpleXMLElement Object
+ // (
+ // [row] => SimpleXMLElement Object
+ // (
+ // [id] => 53878
+ // [name] => Product
+ // [amount] => 12500
+ // [vat] => 2500
+ // [description] => Specification
+ // [quantity] => 2.0
+ // [sku] => 1
+ // [unit] => st
+ // )
+ //
+ // )
+ //
+ // )
+ //
+ // [statuscode] => 0
+ //)
+
+ $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $response);
+
+ ////print_r($response);
+
+ $this->assertEquals(1, $response->accepted);
+
+ $this->assertEquals(3050, $response->subscriptionId);
+ $this->assertEquals("RECURRINGCAPTURE", $response->subscriptiontype);
+ }
+
+
+ function test_manual_query_recur_card_recur_transaction()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'test_manual_query_recur_card_initial_transaction'
+ );
+
+ // 1. enter the below values from the transaction log from test_manual_recurring_payment_step_1
+ // 2. run the test and check the output for the subscriptionId and transactionid of the recur request
+
+ // Set the below to match the original transaction, then run the test.
+ $paymentmethod = "KORTCERT";
+ $merchantid = 1130;
+ $currency = "SEK";
+ $cardType = "VISA";
+ $maskedCardNumber = "444433xxxxxx1100";
+ $expiryMonth = 01;
+ $expiryYear = 15;
+ $subscriptionId = 3050; // insert
+
+ // the below applies to the recur request, and may differ from the original transaction
+ $new_amount = "2500"; // in minor currency
+ $new_customerrefno = "test_manual_recurring_payment_step_1 " . date('c');
+
+ // below is actual test, shouldn't need to change it
+ $request = new RecurTransaction(ConfigurationService::getDefaultConfig());
+ $request->countryCode = "SE";
+ $request->subscriptionId = $subscriptionId;
+ $request->currency = $currency;
+ $request->customerRefNo = $new_customerrefno;
+ $request->amount = $new_amount;
+ $response = $request->doRequest();
+
+ // check that request was accepted
+ $this->assertEquals(1, $response->accepted);
+
+ ////print_r("Recur card transaction response: "); //print_r( $response );
+ //
+ //Recur card transaction response: Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\RecurTransactionResponse Object
+ //(
+ // [transactionid] => 586165
+ // [customerrefno] => test_manual_recurring_payment_step_1 2014-09-12T11:38:30+02:00
+ // [paymentmethod] => CARD
+ // [merchantid] => 1130
+ // [amount] => 2500
+ // [currency] => SEK
+ // [cardType] => VISA
+ // [maskedCardNumber] => 444433xxxxxx1100
+ // [expiryMonth] => 01
+ // [expiryYear] => 15
+ // [authCode] => 153124
+ // [subscriptionid] => 3050
+ // [accepted] => 1
+ // [resultcode] => 0
+ // [errormessage] =>
+ //)
+
+ // Set the below to match the transaction, then run the test.
+ $transactionId = $response->transactionId;
+
+ //SimpleXMLElement Object
+ //(
+ // [transaction] => SimpleXMLElement Object
+ // (
+ // [@attributes] => Array
+ // (
+ // [id] => 586165
+ // )
+ //
+ // [customerrefno] => test_manual_recurring_payment_step_1 2014-09-12T11:38:30+02:00
+ // [merchantid] => 1130
+ // [status] => AUTHORIZED
+ // [amount] => 2500
+ // [currency] => SEK
+ // [vat] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [capturedamount] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [authorizedamount] => 2500
+ // [created] => 2014-09-12 11:38:32.557
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentmethod] => CARD
+ // [callbackurl] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [capturedate] => SimpleXMLElement Object
+ // (
+ // )
+ //
+ // [subscriptionid] => 3050
+ // [subscriptiontype] => RECURRINGCAPTURE
+ // )
+ //
+ // [statuscode] => 0
+ //)
+
+ $request = new QueryTransaction(ConfigurationService::getDefaultConfig());
+ $request->transactionId = $transactionId;
+ $request->countryCode = "SE";
+ $queryResponse = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse", $queryResponse);
+
+ ////print_r($queryResponse);
+ //
+ //Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\QueryTransactionResponse Object
+ //(
+ // [transactionId] => 587424
+ // [clientOrderNumber] => test_manual_recurring_payment_step_1 2014-10-06T15:53:45+02:00
+ // [merchantId] => 1130
+ // [status] => AUTHORIZED
+ // [amount] => 2500
+ // [currency] => SEK
+ // [vat] =>
+ // [capturedamount] =>
+ // [authorizedamount] => 2500
+ // [created] => 2014-10-06 15:53:45.367
+ // [creditstatus] => CREDNONE
+ // [creditedamount] => 0
+ // [merchantresponsecode] => 0
+ // [paymentMethod] => CARD
+ // [numberedOrderRows] =>
+ // [callbackurl] =>
+ // [capturedate] =>
+ // [subscriptionId] => 3050
+ // [subscriptiontype] => RECURRINGCAPTURE
+ // [cardType] =>
+ // [maskedCardNumber] =>
+ // [eci] =>
+ // [mdstatus] =>
+ // [expiryYear] =>
+ // [expiryMonth] =>
+ // [chname] =>
+ // [authCode] =>
+ // [accepted] => 1
+ // [resultcode] => 0
+ // [errormessage] =>
+ //)
+
+ $this->assertEquals(1, $response->accepted);
+ }
}
-
-?>
diff --git a/test/IntegrationTest/HostedService/HandleOrder/RecurTransactionIntegrationTest.php b/test/IntegrationTest/HostedService/HandleOrder/RecurTransactionIntegrationTest.php
index 2a963ea1..bab350d2 100644
--- a/test/IntegrationTest/HostedService/HandleOrder/RecurTransactionIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/HandleOrder/RecurTransactionIntegrationTest.php
@@ -14,101 +14,99 @@
class RecurTransactionIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * test_recur_subscriptionid_not_found
- *
- * used as initial acceptance criteria for credit transaction feature
- */
- function test_recur_subscriptionid_not_found()
- {
-
- $subscriptionId = 987654;
- $customerRefNo = "myCustomerRefNo";
- $currency = "SEK";
- $amount = 100;
-
- $request = new RecurTransaction(ConfigurationService::getDefaultConfig());
- $request->subscriptionId = $subscriptionId;
- $request->customerRefNo = $customerRefNo;
- $request->amount = $amount;
- $request->currency = $currency;
-
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\RecurTransactionResponse", $response);
-
- // if we receive an error from the service, the integration test passes
- $this->assertEquals(0, $response->accepted);
- $this->assertEquals("322 (BAD_SUBSCRIPTION_ID)", $response->resultcode);
- }
-
- /**
- * test_manual_recur_transaction_amount
- *
- * run this test manually after you've performed a card transaction with
- * subscriptiontype set and have gotten the transaction details needed
- */
- function test_manual_recur_transaction_amount()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test of recur transaction amount'
- );
-
- // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 2. go to verktyg -> betalning
- // 3. enter our test merchantid: 1130
- // 4. use the following xml, making sure to update to a unique customerrefno:
- // KORTCERT RECURRINGCAPTURE SEK 500 100 test_recur_NN https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml
- // 5. the result should be:
- // KORTCERT 1130 test_recur_1 500 SEK 2922 VISA 444433xxxxxx1100 02 16 993955 0
-
- // 6. enter the received subscription id, etc. below and run the test
-
- // Set the below to match the original transaction, then run the test.
- $paymentMethod = "KORTCERT";
- $merchantId = 1130;
- $currency = "SEK";
- $cardType = "VISA";
- $maskedCardNumber = "444433xxxxxx1100";
- $expiryMonth = 02;
- $expiryYear = 15;
- $subscriptionId = 3036;
-
- // the below applies to the recur request, and may differ from the original transaction
- $new_amount = "2500"; // in minor currency
- $new_clientOrderNumber = "test_recur_" . date('c');
-
- // below is actual test, shouldn't need to change it
- $request = new RecurTransaction(ConfigurationService::getDefaultConfig());
- $request->subscriptionId = $subscriptionId;
- $request->customerRefNo = $new_clientOrderNumber;
- $request->amount = $new_amount;
- $request->currency = $currency;
-
- $request->countryCode = "SE";
- $response = $request->doRequest();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\RecurTransactionResponse", $response);
-
- ////print_r($response);
- $this->assertEquals(1, $response->accepted);
-
- $this->assertEquals("CARD", $response->paymentMethod); // CARD is alias for KORTCERT, and this alias is returned by webservice
- $this->assertEquals($merchantId, $response->merchantId);
- $this->assertEquals($currency, $response->currency);
- $this->assertEquals($cardType, $response->cardType);
- $this->assertEquals($maskedCardNumber, $response->maskedCardNumber);
- $this->assertEquals($expiryMonth, $response->expiryMonth);
- $this->assertEquals($expiryYear, $response->expiryYear);
- $this->assertEquals($subscriptionId, $response->subscriptionId);
-
- $this->assertObjectHasAttribute("transactionId", $response);
- $this->assertEquals($new_clientOrderNumber, $response->clientOrderNumber);
- $this->assertEquals($new_amount, $response->amount);
- }
+ /**
+ * test_recur_subscriptionid_not_found
+ *
+ * used as initial acceptance criteria for credit transaction feature
+ */
+ function test_recur_subscriptionid_not_found()
+ {
+
+ $subscriptionId = 987654;
+ $customerRefNo = "myCustomerRefNo";
+ $currency = "SEK";
+ $amount = 100;
+
+ $request = new RecurTransaction(ConfigurationService::getDefaultConfig());
+ $request->subscriptionId = $subscriptionId;
+ $request->customerRefNo = $customerRefNo;
+ $request->amount = $amount;
+ $request->currency = $currency;
+
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\RecurTransactionResponse", $response);
+
+ // if we receive an error from the service, the integration test passes
+ $this->assertEquals(0, $response->accepted);
+ $this->assertEquals("322 (BAD_SUBSCRIPTION_ID)", $response->resultcode);
+ }
+
+ /**
+ * test_manual_recur_transaction_amount
+ *
+ * run this test manually after you've performed a card transaction with
+ * subscriptiontype set and have gotten the transaction details needed
+ */
+ function test_manual_recur_transaction_amount()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test of recur transaction amount'
+ );
+
+ // 1. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 2. go to verktyg -> betalning
+ // 3. enter our test merchantid: 1130
+ // 4. use the following xml, making sure to update to a unique customerrefno:
+ // KORTCERT RECURRINGCAPTURE SEK 500 100 test_recur_NN https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml
+ // 5. the result should be:
+ // KORTCERT 1130 test_recur_1 500 SEK 2922 VISA 444433xxxxxx1100 02 16 993955 0
+
+ // 6. enter the received subscription id, etc. below and run the test
+
+ // Set the below to match the original transaction, then run the test.
+ $paymentMethod = "KORTCERT";
+ $merchantId = 1130;
+ $currency = "SEK";
+ $cardType = "VISA";
+ $maskedCardNumber = "444433xxxxxx1100";
+ $expiryMonth = 02;
+ $expiryYear = 15;
+ $subscriptionId = 3036;
+
+ // the below applies to the recur request, and may differ from the original transaction
+ $new_amount = "2500"; // in minor currency
+ $new_clientOrderNumber = "test_recur_" . date('c');
+
+ // below is actual test, shouldn't need to change it
+ $request = new RecurTransaction(ConfigurationService::getDefaultConfig());
+ $request->subscriptionId = $subscriptionId;
+ $request->customerRefNo = $new_clientOrderNumber;
+ $request->amount = $new_amount;
+ $request->currency = $currency;
+
+ $request->countryCode = "SE";
+ $response = $request->doRequest();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\RecurTransactionResponse", $response);
+
+ ////print_r($response);
+ $this->assertEquals(1, $response->accepted);
+
+ $this->assertEquals("CARD", $response->paymentMethod); // CARD is alias for KORTCERT, and this alias is returned by webservice
+ $this->assertEquals($merchantId, $response->merchantId);
+ $this->assertEquals($currency, $response->currency);
+ $this->assertEquals($cardType, $response->cardType);
+ $this->assertEquals($maskedCardNumber, $response->maskedCardNumber);
+ $this->assertEquals($expiryMonth, $response->expiryMonth);
+ $this->assertEquals($expiryYear, $response->expiryYear);
+ $this->assertEquals($subscriptionId, $response->subscriptionId);
+
+ $this->assertObjectHasAttribute("transactionId", $response);
+ $this->assertEquals($new_clientOrderNumber, $response->clientOrderNumber);
+ $this->assertEquals($new_amount, $response->amount);
+ }
}
-
-?>
diff --git a/test/IntegrationTest/HostedService/Payment/CardPaymentIntegrationTest.php b/test/IntegrationTest/HostedService/Payment/CardPaymentIntegrationTest.php
index ff391a6b..2c9aeb43 100644
--- a/test/IntegrationTest/HostedService/Payment/CardPaymentIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/Payment/CardPaymentIntegrationTest.php
@@ -15,56 +15,56 @@
class CardPaymentIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public function test_createOrder_usePayPage_redirects_to_paypage()
- {
- $config = ConfigurationService::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()// PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
- $url = "https://webpaypaymentgatewaystage.svea.com/webpay/payment";
+ public function test_createOrder_usePayPage_redirects_to_paypage()
+ {
+ $config = ConfigurationService::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()// PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+ $url = "https://webpaypaymentgatewaystage.svea.com/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, '&');
+ /** CURL **/
+ $fields = ['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);
+ $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);
+ $info = curl_getinfo($ch);
- curl_close($ch);
+ curl_close($ch);
- //print_r( $cr);
- $this->assertEquals(200, $info['http_code']);
- $this->assertEquals(1, $info['redirect_count']);
- $expected_infourl = "https://webpaypaymentgatewaystage.svea.com/webpay/public/static/paypage.html";
- $start_of_actual_infourl = substr($info['url'], 0, strlen($expected_infourl));
- $this->assertEquals($expected_infourl, $start_of_actual_infourl);
- }
+ //print_r( $cr);
+ $this->assertEquals(200, $info['http_code']);
+ $this->assertEquals(1, $info['redirect_count']);
+ $expected_infourl = "https://webpaypaymentgatewaystage.svea.com/webpay/public/static/paypage.html";
+ $start_of_actual_infourl = substr($info['url'], 0, strlen($expected_infourl));
+ $this->assertEquals($expected_infourl, $start_of_actual_infourl);
+ }
}
diff --git a/test/IntegrationTest/HostedService/Payment/CardPaymentURLIntegrationTest.php b/test/IntegrationTest/HostedService/Payment/CardPaymentURLIntegrationTest.php
index 1474f284..39fb695b 100644
--- a/test/IntegrationTest/HostedService/Payment/CardPaymentURLIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/Payment/CardPaymentURLIntegrationTest.php
@@ -13,160 +13,160 @@
class CardPaymentURLIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage ipAddress is required. Use function setIpAddress() on the order customer.
- *
- * @todo move to unit test for getPaymentURL validation
- */
- public function test_CardPayment_getPaymentURL_throws_validationException_if_missing_ipAddress()
- {
- $orderLanguage = "sv";
- $returnUrl = "returnUrl";
- $ipAddress = "127.0.0.1";
-
- // create order
- $order = TestUtil::createOrder(); // default customer has no ipAddress set
- // set payment method
- // call getPaymentURL
- $payment = $order
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setPayPageLanguage($orderLanguage)
- ->setReturnUrl($returnUrl)
- ->getPaymentUrl();
- // check that request response contains an URL
- $this->assertInstanceOf('Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\HostedAdminResponse', $response);
- }
-
- public function test_CardPayment_getPaymentURL_returns_HostedResponse()
- {
- $orderLanguage = "sv";
- $returnUrl = "http://foo.bar.com";
- $ipAddress = "127.0.0.1";
-
- // create order
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
- $order->setClientOrderNumber("foobar" . date('c'));
- // set payment method
- // call getPaymentURL
- $response = $order
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setPayPageLanguage($orderLanguage)
- ->setReturnUrl($returnUrl)
- ->getPaymentUrl();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\HostedAdminResponse", $response);
- }
-
- public function test_manual_CardPayment_getPaymentURL_response_is_accepted_and_contains_response_attributes()
- {
- // Stop here and mark this test as incomplete. -- run manual as this seems to fail randomly at the service
- $this->markTestIncomplete(
- 'skeleton for manual test of card payment'
- );
-
- $orderLanguage = "sv";
- $returnUrl = "http://foo.bar.com";
- $ipAddress = "127.0.0.1";
-
- // create order
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
- $order->setClientOrderNumber("foobar" . date('c'));
- // set payment method
- // call getPaymentURL
- $response = $order
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setPayPageLanguage($orderLanguage)
- ->setReturnUrl($returnUrl)
- ->getPaymentUrl();
-
- // check that request was accepted
- ////print_r($response);
- $this->assertEquals(1, $response->accepted);
-
- // check that response set id, created exist and not null
- $this->assertTrue(isset($response->id));
- $this->assertTrue(isset($response->created));
- // check that request response contains url
- $this->assertEquals("https://test", substr($response->url, 0, 12));
- // check that request response contains testurl
- $this->assertEquals("https://test", substr($response->testurl, 0, 12));
- }
-
- /**
- * test_manual_CardPayment_getPaymentURL
- */
- public function test_manual_CardPayment_getPaymentUrl()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test of card payment'
- );
-
- // 1. remove (put in a comment) the above code to enable the test
- // 2. run the test, and get the subscription paymenturl from the output
- // 3. go to the paymenturl and complete the transaction.
- // 4. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 5. retrieve the transactionid from the response in the transaction log
-
- $orderLanguage = "sv";
- $returnUrl = "http://foo.bar.com";
- $ipAddress = "127.0.0.1";
-
- // create order
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
- // set payment method
- // call getPaymentURL
- $response = $order
- ->setClientOrderNumber("foobar" . date('c'))
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->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_card_payment by going to: " . $response->testurl ." and complete payment manually" );
- }
-
- /**
- * test_manual_CardPayment_getPaymentURL
- */
- public function test_CardPayment_getPaymentUrl_response_remake()
- {
- // Stop here and mark this test as incomplete.
-// $this->markTestIncomplete(
-// 'skeleton for manual test of card payment'
-// );
-
- // 1. remove (put in a comment) the above code to enable the test
- // 2. run the test, and get the subscription paymenturl from the output
- // 3. go to the paymenturl and complete the transaction.
- // 4. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 5. retrieve the transactionid from the response in the transaction log
-
- $orderLanguage = "sv";
- $returnUrl = "http://foo.bar.com";
- $ipAddress = "127.0.0.1";
-
- // create order
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
- // set payment method
- // call getPaymentURL
- $response = $order
- ->setClientOrderNumber("foobar" . date('c'))
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setPayPageLanguage($orderLanguage)
- ->setReturnUrl($returnUrl)
- ->getPaymentUrl();
-
- // check that request was accepted
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals($response->testurl, $response->url); //url should always contain the url where the order is created in
- //and test is always test. In this case booth should therefore be test
-
-
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage ipAddress is required. Use function setIpAddress() on the order customer.
+ *
+ * @todo move to unit test for getPaymentURL validation
+ */
+ public function test_CardPayment_getPaymentURL_throws_validationException_if_missing_ipAddress()
+ {
+ $orderLanguage = "sv";
+ $returnUrl = "returnUrl";
+ $ipAddress = "127.0.0.1";
+
+ // create order
+ $order = TestUtil::createOrder(); // default customer has no ipAddress set
+ // set payment method
+ // call getPaymentURL
+ $payment = $order
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setPayPageLanguage($orderLanguage)
+ ->setReturnUrl($returnUrl)
+ ->getPaymentUrl();
+ // check that request response contains an URL
+ $this->assertInstanceOf('Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\HostedAdminResponse', $response);
+ }
+
+ public function test_CardPayment_getPaymentURL_returns_HostedResponse()
+ {
+ $orderLanguage = "sv";
+ $returnUrl = "http://foo.bar.com";
+ $ipAddress = "127.0.0.1";
+
+ // create order
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
+ $order->setClientOrderNumber("foobar" . date('c'));
+ // set payment method
+ // call getPaymentURL
+ $response = $order
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setPayPageLanguage($orderLanguage)
+ ->setReturnUrl($returnUrl)
+ ->getPaymentUrl();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\HostedAdminResponse", $response);
+ }
+
+ public function test_manual_CardPayment_getPaymentURL_response_is_accepted_and_contains_response_attributes()
+ {
+ // Stop here and mark this test as incomplete. -- run manual as this seems to fail randomly at the service
+ $this->markTestIncomplete(
+ 'skeleton for manual test of card payment'
+ );
+
+ $orderLanguage = "sv";
+ $returnUrl = "http://foo.bar.com";
+ $ipAddress = "127.0.0.1";
+
+ // create order
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
+ $order->setClientOrderNumber("foobar" . date('c'));
+ // set payment method
+ // call getPaymentURL
+ $response = $order
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setPayPageLanguage($orderLanguage)
+ ->setReturnUrl($returnUrl)
+ ->getPaymentUrl();
+
+ // check that request was accepted
+ ////print_r($response);
+ $this->assertEquals(1, $response->accepted);
+
+ // check that response set id, created exist and not null
+ $this->assertTrue(isset($response->id));
+ $this->assertTrue(isset($response->created));
+ // check that request response contains url
+ $this->assertEquals("https://test", substr($response->url, 0, 12));
+ // check that request response contains testurl
+ $this->assertEquals("https://test", substr($response->testurl, 0, 12));
+ }
+
+ /**
+ * test_manual_CardPayment_getPaymentURL
+ */
+ public function test_manual_CardPayment_getPaymentUrl()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test of card payment'
+ );
+
+ // 1. remove (put in a comment) the above code to enable the test
+ // 2. run the test, and get the subscription paymenturl from the output
+ // 3. go to the paymenturl and complete the transaction.
+ // 4. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 5. retrieve the transactionid from the response in the transaction log
+
+ $orderLanguage = "sv";
+ $returnUrl = "http://foo.bar.com";
+ $ipAddress = "127.0.0.1";
+
+ // create order
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
+ // set payment method
+ // call getPaymentURL
+ $response = $order
+ ->setClientOrderNumber("foobar" . date('c'))
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->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_card_payment by going to: " . $response->testurl ." and complete payment manually" );
+ }
+
+ /**
+ * test_manual_CardPayment_getPaymentURL
+ */
+ public function test_CardPayment_getPaymentUrl_response_remake()
+ {
+ // Stop here and mark this test as incomplete.
+// $this->markTestIncomplete(
+// 'skeleton for manual test of card payment'
+// );
+
+ // 1. remove (put in a comment) the above code to enable the test
+ // 2. run the test, and get the subscription paymenturl from the output
+ // 3. go to the paymenturl and complete the transaction.
+ // 4. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 5. retrieve the transactionid from the response in the transaction log
+
+ $orderLanguage = "sv";
+ $returnUrl = "http://foo.bar.com";
+ $ipAddress = "127.0.0.1";
+
+ // create order
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
+ // set payment method
+ // call getPaymentURL
+ $response = $order
+ ->setClientOrderNumber("foobar" . date('c'))
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setPayPageLanguage($orderLanguage)
+ ->setReturnUrl($returnUrl)
+ ->getPaymentUrl();
+
+ // check that request was accepted
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals($response->testurl, $response->url); //url should always contain the url where the order is created in
+ //and test is always test. In this case booth should therefore be test
+
+
+ }
}
diff --git a/test/IntegrationTest/HostedService/Payment/RecurCardPaymentIntegrationTest.php b/test/IntegrationTest/HostedService/Payment/RecurCardPaymentIntegrationTest.php
index 7fc5c833..fbee23b3 100644
--- a/test/IntegrationTest/HostedService/Payment/RecurCardPaymentIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/Payment/RecurCardPaymentIntegrationTest.php
@@ -15,95 +15,95 @@
class RecurCardPaymentIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * test_manual_recurring_payment_step_1
- *
- * run this manually after you've performed a card transaction and have set
- * the transaction status to success using the tools in the logg admin.
- */
- public function test_manual_recurring_payment_step_1()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test of recurring payment' // TODO
- );
-
- // 1. remove (put in a comment) the above code to enable the test
- // 2. run the test, and get the subscription paymenturl from the output
- // 3. go to the paymenturl and complete the transaction.
- // 4. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
- // 5. retrieve the subscriptionId from the response in the transaction log
- // 6. use the subscriptionId to run
-
- $orderLanguage = "sv";
- $returnUrl = "http://foo.bar.com";
- $ipAddress = "127.0.0.1";
-
- // create order
- $order = TestUtil::createOrder(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
- // set payment method
- // call getPaymentURL
- $response = $order
- ->usePayPageCardOnly()
- ->setPayPageLanguage($orderLanguage)
- ->setReturnUrl($returnUrl)
- ->setSubscriptionType(CardPayment::RECURRINGCAPTURE)
- ->getPaymentUrl();
-
- // check that request was accepted
- $this->assertEquals(1, $response->accepted);
-
- // print the url to use to confirm the transaction
- //print_r( " test_manual_recurring_payment_step_1(): " . $response->testurl ." ");
- }
-
- /**
- * test_manual_recurring_payment_step_2
- *
- * run this test manually after you've performed a card transaction with
- * subscriptiontype set and have gotten the transaction details needed
- */
- function test_manual_recurring_payment_step_2()
- {
-
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'skeleton for manual test of recur transaction amount'
- );
-
- // 1. enter the below values from the transaction log from test_manual_recurring_payment_step_1
- // 2. run the test and check the output for the subscriptionid and transactionid of the recur request
-
- // Set the below to match the original transaction, then run the test.
- $paymentmethod = "KORTCERT";
- $merchantid = 1130;
- $currency = "SEK";
- $cardtype = "VISA";
- $maskedcardno = "444433xxxxxx1100";
- $expirymonth = 02;
- $expiryyear = 16;
- $subscriptionid = 2960; // insert
-
- // the below applies to the recur request, and may differ from the original transaction
- $new_amount = "2500"; // in minor currency
- $new_customerrefno = "test_manual_recurring_payment_step_1 " . date('c');
-
- // below is actual test, shouldn't need to change it
- $request = new RecurTransaction(ConfigurationService::getDefaultConfig());
- $request->countryCode = "SE";
- $request->subscriptionId = $subscriptionid;
- $request->currency = $currency;
- $request->customerRefNo = $new_customerrefno;
- $request->amount = $new_amount;
- $response = $request->doRequest();
-
- // check that request was accepted
- $this->assertEquals(1, $response->accepted);
-
- // print the subscription id that succeeded to use to confirm the transaction
- //print_r( " test_manual_recurring_payment_step_2() recur succeded using subscriptionid: " . $response->subscriptionid ." " );
- //print_r( " test_manual_recurring_payment_step_2() for more info, check logs for transaction: " . $response->transactionid ." " );
- }
+ /**
+ * test_manual_recurring_payment_step_1
+ *
+ * run this manually after you've performed a card transaction and have set
+ * the transaction status to success using the tools in the logg admin.
+ */
+ public function test_manual_recurring_payment_step_1()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test of recurring payment' // TODO
+ );
+
+ // 1. remove (put in a comment) the above code to enable the test
+ // 2. run the test, and get the subscription paymenturl from the output
+ // 3. go to the paymenturl and complete the transaction.
+ // 4. go to https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/start.xhtml
+ // 5. retrieve the subscriptionId from the response in the transaction log
+ // 6. use the subscriptionId to run
+
+ $orderLanguage = "sv";
+ $returnUrl = "http://foo.bar.com";
+ $ipAddress = "127.0.0.1";
+
+ // create order
+ $order = TestUtil::createOrder(TestUtil::createIndividualCustomer("SE")->setIpAddress($ipAddress));
+ // set payment method
+ // call getPaymentURL
+ $response = $order
+ ->usePayPageCardOnly()
+ ->setPayPageLanguage($orderLanguage)
+ ->setReturnUrl($returnUrl)
+ ->setSubscriptionType(CardPayment::RECURRINGCAPTURE)
+ ->getPaymentUrl();
+
+ // check that request was accepted
+ $this->assertEquals(1, $response->accepted);
+
+ // print the url to use to confirm the transaction
+ //print_r( " test_manual_recurring_payment_step_1(): " . $response->testurl ." ");
+ }
+
+ /**
+ * test_manual_recurring_payment_step_2
+ *
+ * run this test manually after you've performed a card transaction with
+ * subscriptiontype set and have gotten the transaction details needed
+ */
+ function test_manual_recurring_payment_step_2()
+ {
+
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'skeleton for manual test of recur transaction amount'
+ );
+
+ // 1. enter the below values from the transaction log from test_manual_recurring_payment_step_1
+ // 2. run the test and check the output for the subscriptionid and transactionid of the recur request
+
+ // Set the below to match the original transaction, then run the test.
+ $paymentmethod = "KORTCERT";
+ $merchantid = 1130;
+ $currency = "SEK";
+ $cardtype = "VISA";
+ $maskedcardno = "444433xxxxxx1100";
+ $expirymonth = 02;
+ $expiryyear = 16;
+ $subscriptionid = 2960; // insert
+
+ // the below applies to the recur request, and may differ from the original transaction
+ $new_amount = "2500"; // in minor currency
+ $new_customerrefno = "test_manual_recurring_payment_step_1 " . date('c');
+
+ // below is actual test, shouldn't need to change it
+ $request = new RecurTransaction(ConfigurationService::getDefaultConfig());
+ $request->countryCode = "SE";
+ $request->subscriptionId = $subscriptionid;
+ $request->currency = $currency;
+ $request->customerRefNo = $new_customerrefno;
+ $request->amount = $new_amount;
+ $response = $request->doRequest();
+
+ // check that request was accepted
+ $this->assertEquals(1, $response->accepted);
+
+ // print the subscription id that succeeded to use to confirm the transaction
+ //print_r( " test_manual_recurring_payment_step_2() recur succeded using subscriptionid: " . $response->subscriptionid ." " );
+ //print_r( " test_manual_recurring_payment_step_2() for more info, check logs for transaction: " . $response->transactionid ." " );
+ }
}
diff --git a/test/IntegrationTest/HostedService/Payment/SwishPaymentIntegrationTest.php b/test/IntegrationTest/HostedService/Payment/SwishPaymentIntegrationTest.php
index 9d632de2..430e111c 100644
--- a/test/IntegrationTest/HostedService/Payment/SwishPaymentIntegrationTest.php
+++ b/test/IntegrationTest/HostedService/Payment/SwishPaymentIntegrationTest.php
@@ -14,53 +14,53 @@
class SwishPaymentIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public function testCreateOrderWithSwish()
- {
-
- $clientOrderNumber = "test_swish_". rand(100000,300000);
-
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setClientOrderNumber($clientOrderNumber)
- ->setCurrency("SEK")
- ->setPayerAlias("46701234567")
- ->usePaymentMethod(PaymentMethod::SWISH)
- ->setReturnUrl("https://eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.se")
- ->getPaymentForm();
-
- $url = "https://webpaypaymentgatewaystage.svea.com/webpay/payment";
-
-
- $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);
-
- $swishOrder = WebpayAdmin::queryOrder($config)
- ->setCountryCode("SE")
- ->setClientOrderNumber($clientOrderNumber)
- ->queryCardOrder()
- ->doRequest();
-
- $this->assertEquals("SWISH", $swishOrder->paymentMethod);
- $this->assertEquals("VALID", $swishOrder->status);
- }
+ public function testCreateOrderWithSwish()
+ {
+
+ $clientOrderNumber = "test_swish_". rand(100000,300000);
+
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setClientOrderNumber($clientOrderNumber)
+ ->setCurrency("SEK")
+ ->setPayerAlias("46701234567")
+ ->usePaymentMethod(PaymentMethod::SWISH)
+ ->setReturnUrl("https://eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.se")
+ ->getPaymentForm();
+
+ $url = "https://webpaypaymentgatewaystage.svea.com/webpay/payment";
+
+
+ $fields = ['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);
+
+ $swishOrder = WebpayAdmin::queryOrder($config)
+ ->setCountryCode("SE")
+ ->setClientOrderNumber($clientOrderNumber)
+ ->queryCardOrder()
+ ->doRequest();
+
+ $this->assertEquals("SWISH", $swishOrder->paymentMethod);
+ $this->assertEquals("VALID", $swishOrder->status);
+ }
}
\ No newline at end of file
diff --git a/test/IntegrationTest/WebPayAdminIntegrationTest.php b/test/IntegrationTest/WebPayAdminIntegrationTest.php
index 4570b529..0c1d166b 100644
--- a/test/IntegrationTest/WebPayAdminIntegrationTest.php
+++ b/test/IntegrationTest/WebPayAdminIntegrationTest.php
@@ -17,376 +17,376 @@
class WebPayAdminIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /// cancelOrder()
- // TODO
-
- /// queryOrder()
- // invoice
- public function test_queryOrder_queryInvoiceOrder_is_accepted()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)// => 123.9876 inc
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $queryResponse = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $queryResponse->accepted);
- }
-
- // paymentplan
- public function test_queryOrder_queryPaymentPlanOrder_is_accepted()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(999.9)// => 12398.76 inc
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
-
- $queryResponse = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($orderResponse->sveaOrderId)
- ->setCountryCode('SE')
- ->queryPaymentPlanOrder()->doRequest();
- $this->assertEquals(1, $queryResponse->accepted);
- }
-
- // card
- function test_queryOrder_queryCardOrder()
- {
- // Set the below to match the transaction, then run the test.
- $transactionId = 590177;
-
- $request = WebPayAdmin::queryOrder(
- ConfigurationService::getSingleCountryConfig(
- "SE",
- "foo", "bar", "123456", // invoice
- "foo", "bar", "123456", // paymentplan
- "foo", "bar", "123456", // accountCredit
- "1200", // merchantid, secret
- "27f18bfcbe4d7f39971cb3460fbe7234a82fb48f985cf22a068fa1a685fe7e6f93c7d0d92fee4e8fd7dc0c9f11e2507300e675220ee85679afa681407ee2416d",
- false // prod = false
- )
- )
- ->setTransactionId(strval($transactionId))
- ->setCountryCode("SE");
- $response = $request->queryCardOrder()->doRequest();
-
- $this->assertEquals(1, $response->accepted);
-
- $this->assertEquals($transactionId, $response->transactionId);
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[0]);
- $this->assertEquals("Soft213s", $response->numberedOrderRows[0]->articleNumber);
- $this->assertEquals("1.0", $response->numberedOrderRows[0]->quantity);
- $this->assertEquals("st", $response->numberedOrderRows[0]->unit);
- $this->assertEquals(3212.00, $response->numberedOrderRows[0]->amountExVat); // amount = 401500, vat = 80300 => 3212.00 @25%
- $this->assertEquals(25, $response->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("Soft", $response->numberedOrderRows[0]->name);
-// $this->assertEquals( "Specification", $response->numberedOrderRows[1]->description );
- $this->assertEquals(0, $response->numberedOrderRows[0]->vatDiscount);
-
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[1]);
- $this->assertEquals("07", $response->numberedOrderRows[1]->articleNumber);
- $this->assertEquals("1.0", $response->numberedOrderRows[1]->quantity);
- $this->assertEquals("st", $response->numberedOrderRows[1]->unit);
- $this->assertEquals(0, $response->numberedOrderRows[1]->amountExVat); // amount = 401500, vat = 80300 => 3212.00 @25%
- $this->assertEquals(0, $response->numberedOrderRows[1]->vatPercent);
- $this->assertEquals("Sits: Hatfield Beige 6", $response->numberedOrderRows[1]->name);
-// $this->assertEquals( "Specification", $response->numberedOrderRows[1]->description );
- $this->assertEquals(0, $response->numberedOrderRows[1]->vatDiscount);
- }
-
-
- /// creditOrderRows()
- // invoice
- public function test_creditOrderRows_creditInvoiceOrderRows_returns_CreditOrderRowsRequest()
- {
- $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig());
- $request = $creditOrderRowsBuilder->creditInvoiceOrderRows();
- $this->assertInstanceOf("Svea\WebPay\AdminService\CreditInvoiceRowsRequest", $request);
- }
-
- // card
- public function test_creditOrderRows_creditCardOrderRows_returns_CreditTransaction()
- {
- $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setCountryCode("SE")
- ->setOrderId(123456)
- ->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.00, 1, 1))
- ->setRowToCredit(1);
- $request = $creditOrderRowsBuilder->creditCardOrderRows();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CreditTransaction", $request);
- }
-
- // direct bank
- public function test_creditOrderRows_creditDirectBankOrderRows_returns_CreditTransaction()
- {
- $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setCountryCode("SE")
- ->setOrderId(123456)
- ->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.00, 1, 1))
- ->setRowToCredit(1);
- $request = $creditOrderRowsBuilder->creditDirectBankOrderRows();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CreditTransaction", $request);
- }
-
- /// addOrderRows()
- // invoice
- // paymentplan
- public function test_addOrderRows_addInvoiceOrderRows_returns_AddOrderRowsRequest()
- {
- $addOrderRowsBuilder = WebPayAdmin::addOrderRows(ConfigurationService::getDefaultConfig());
- $request = $addOrderRowsBuilder->addInvoiceOrderRows();
- $this->assertInstanceOf("Svea\WebPay\AdminService\AddOrderRowsRequest", $request);
- }
-
- public function test_addOrderRows_addPaymentPlanOrderRows_returns_AddOrderRowsRequest()
- {
- $addOrderRowsBuilder = WebPayAdmin::addOrderRows(ConfigurationService::getDefaultConfig());
- $request = $addOrderRowsBuilder->addPaymentPlanOrderRows();
- $this->assertInstanceOf("Svea\WebPay\AdminService\AddOrderRowsRequest", $request);
- }
-
- /// updateOrderRows()
- // invoice
- public function test_updateOrderRows_updateInvoiceOrderRows_returns_UpdateOrderRowsRequest()
- {
- $updateOrderRowsBuilder = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig());
- $request = $updateOrderRowsBuilder->updateInvoiceOrderRows();
- $this->assertInstanceOf("Svea\WebPay\AdminService\UpdateOrderRowsRequest", $request);
- }
-
- // paymentplan
- public function test_updateOrderRows_updatePaymentPlanOrderRows_returns_UpdateOrderRowsRequest()
- {
- $updateOrderRowsBuilder = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig());
- $request = $updateOrderRowsBuilder->updatePaymentPlanOrderRows();
- $this->assertInstanceOf("Svea\WebPay\AdminService\UpdateOrderRowsRequest", $request);
- }
-
- // deliverOrderRows()
- // invoice
- public function test_deliverOrderRows_deliverInvoiceOrderRows_returns_DeliverOrderRowsRequest()
- {
- $request = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig())
- ->setCountryCode("SE")
- ->setOrderId(123456)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setRowTodeliver(1)
- ->deliverInvoiceOrderRows();
- $this->assertInstanceOf("Svea\WebPay\AdminService\DeliverOrderRowsRequest", $request);
- }
-
- //Svea\WebPay\WebPayAdmin::queryOrder()
- //.queryInvoiceOrder
- public function test_queryOrder_queryInvoiceOrder_single_order_row_with_invoice_fee_and_shipping_fee()
- {
-
- // create order using order row specified with ->setName() and ->setDescription
- $specifiedOrderRow = WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setName("orderrow 1")
- ->setDescription("description 1");
-
- $invoiceFeeOrderRow = WebPayItem::invoiceFee()
- ->setAmountExVat(20.00)
- ->setVatPercent(25)
- ->setName("invoicefee 1")
- ->setDescription("invoicefee description 1");
-
- $shippingFeeOrderRow = WebPayItem::shippingFee()
- ->setAmountExVat(40.00)
- ->setVatPercent(25)
- ->setName("shippingfee 1")
- ->setDescription("shippingfee description 1");
-
- $order = TestUtil::createOrderWithoutOrderRows()
- ->addOrderRow($specifiedOrderRow)
- ->addOrderRow($invoiceFeeOrderRow)
- ->addOrderRow($shippingFeeOrderRow);
-
- $createOrderResponse = $order->useInvoicePayment()->doRequest();
-
- //print_r( $createOrderResponse );
- $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\CreateOrderResponse", $createOrderResponse);
- $this->assertTrue($createOrderResponse->accepted);
-
- $createdOrderId = $createOrderResponse->sveaOrderId;
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode("SE");
-
- $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
-
- //print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
-
- $this->assertEquals(1, $queryResponse->numberedOrderRows[0]->rowNumber);
- $this->assertEquals(1.00, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals(100.00, $queryResponse->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(25, $queryResponse->numberedOrderRows[0]->vatPercent);
- $this->assertEquals(null, $queryResponse->numberedOrderRows[0]->name);
- $this->assertEquals("orderrow 1: description 1", $queryResponse->numberedOrderRows[0]->description);
-
- $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber);
- $this->assertEquals(1.00, $queryResponse->numberedOrderRows[1]->quantity);
- $this->assertEquals(20.00, $queryResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals(25, $queryResponse->numberedOrderRows[1]->vatPercent);
- $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->name);
- $this->assertEquals("invoicefee 1: invoicefee description 1", $queryResponse->numberedOrderRows[1]->description);
-
- $this->assertEquals(3, $queryResponse->numberedOrderRows[2]->rowNumber);
- $this->assertEquals(1.00, $queryResponse->numberedOrderRows[2]->quantity);
- $this->assertEquals(40.00, $queryResponse->numberedOrderRows[2]->amountExVat);
- $this->assertEquals(25, $queryResponse->numberedOrderRows[2]->vatPercent);
- $this->assertEquals(null, $queryResponse->numberedOrderRows[2]->name);
- $this->assertEquals("shippingfee 1: shippingfee description 1", $queryResponse->numberedOrderRows[2]->description);
- }
-
- public function test_queryOrder_queryInvoiceOrder_multiple_order_rows()
- {
-
- // create order using order row specified with ->setName() and ->setDescription
- $specifiedOrderRow = WebPayItem::orderRow()
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setName("orderrow 1")// optional
- ->setDescription("description 1") // optional
- ;
-
- // create order using order row specified with ->setName() and ->setDescription
- $specifiedOrderRow2 = WebPayItem::orderRow()
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setName("orderrow 2")// optional
- ->setDescription("description 2") // optional
- ;
-
- $order = TestUtil::createOrderWithoutOrderRows()
- ->addOrderRow($specifiedOrderRow)
- ->addOrderRow($specifiedOrderRow2);
-
- $createOrderResponse = $order->useInvoicePayment()->doRequest();
-
- ////print_r( $createOrderResponse );
- $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\CreateOrderResponse", $createOrderResponse);
- $this->assertTrue($createOrderResponse->accepted);
-
- $createdOrderId = $createOrderResponse->sveaOrderId;
-
- // WPA::queryOrder()
- // ->queryInvoiceOrder()
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode("SE");
-
- $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
-
- //print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
-
- // assert that order rows are the same
- $this->assertEquals(1, $queryResponse->accepted);
-
- $this->assertEquals(1, $queryResponse->numberedOrderRows[0]->rowNumber);
- $this->assertEquals(1.00, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals(100.00, $queryResponse->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(25, $queryResponse->numberedOrderRows[0]->vatPercent);
- $this->assertEquals(null, $queryResponse->numberedOrderRows[0]->name);
- $this->assertEquals("orderrow 1: description 1", $queryResponse->numberedOrderRows[0]->description);
-
- $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber);
- $this->assertEquals(1.00, $queryResponse->numberedOrderRows[1]->quantity);
- $this->assertEquals(100.00, $queryResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals(25, $queryResponse->numberedOrderRows[1]->vatPercent);
- $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->name);
- $this->assertEquals("orderrow 2: description 2", $queryResponse->numberedOrderRows[1]->description);
- }
-
- //-queryPaymentPlanOrder
- // TODO
-
- //.queryCardOrder
- public function test_queryOrder_queryCardOrder_single_order_row()
- {
-
- // created w/java package TODO make self-contained using webdriver to create card order
- $createdOrderId = 587673;
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode("SE");
-
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- //print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
-
- $this->assertEquals(1, $queryResponse->numberedOrderRows[0]->rowNumber);
- $this->assertEquals(1.00, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals(100.00, $queryResponse->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(25, $queryResponse->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("orderrow 1", $queryResponse->numberedOrderRows[0]->name);
- $this->assertEquals("description 1", $queryResponse->numberedOrderRows[0]->description);
- }
-
- public function test_queryOrder_queryCardOrder_multiple_order_rows()
- {
-
- // created w/java package TODO make self-contained using webdriver to create card order
- $createdOrderId = 587679;
-
- // query orderrows
- $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode("SE");
-
- $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
-
- //print_r( $queryResponse);
- $this->assertEquals(1, $queryResponse->accepted);
-
- $this->assertEquals(1, $queryResponse->numberedOrderRows[0]->rowNumber);
- $this->assertEquals(1.00, $queryResponse->numberedOrderRows[0]->quantity);
- $this->assertEquals(100.00, $queryResponse->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(25, $queryResponse->numberedOrderRows[0]->vatPercent);
- $this->assertEquals("orderrow 1", $queryResponse->numberedOrderRows[0]->name);
- $this->assertEquals("description 1", $queryResponse->numberedOrderRows[0]->description);
-
- $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber);
- $this->assertEquals(1.00, $queryResponse->numberedOrderRows[1]->quantity);
- $this->assertEquals(100.00, $queryResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals(25, $queryResponse->numberedOrderRows[1]->vatPercent);
- $this->assertEquals("orderrow 2", $queryResponse->numberedOrderRows[1]->name);
- $this->assertEquals("description 2", $queryResponse->numberedOrderRows[1]->description);
- }
-
- //-queryDirectBankOrder
- // TODO
+ /// cancelOrder()
+ // TODO
+
+ /// queryOrder()
+ // invoice
+ public function test_queryOrder_queryInvoiceOrder_is_accepted()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)// => 123.9876 inc
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $queryResponse = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $queryResponse->accepted);
+ }
+
+ // paymentplan
+ public function test_queryOrder_queryPaymentPlanOrder_is_accepted()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(999.9)// => 12398.76 inc
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+
+ $queryResponse = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->setCountryCode('SE')
+ ->queryPaymentPlanOrder()->doRequest();
+ $this->assertEquals(1, $queryResponse->accepted);
+ }
+
+ // card
+ function test_queryOrder_queryCardOrder()
+ {
+ // Set the below to match the transaction, then run the test.
+ $transactionId = 590177;
+
+ $request = WebPayAdmin::queryOrder(
+ ConfigurationService::getSingleCountryConfig(
+ "SE",
+ "foo", "bar", "123456", // invoice
+ "foo", "bar", "123456", // paymentplan
+ "foo", "bar", "123456", // accountCredit
+ "1200", // merchantid, secret
+ "27f18bfcbe4d7f39971cb3460fbe7234a82fb48f985cf22a068fa1a685fe7e6f93c7d0d92fee4e8fd7dc0c9f11e2507300e675220ee85679afa681407ee2416d",
+ false // prod = false
+ )
+ )
+ ->setTransactionId(strval($transactionId))
+ ->setCountryCode("SE");
+ $response = $request->queryCardOrder()->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+
+ $this->assertEquals($transactionId, $response->transactionId);
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[0]);
+ $this->assertEquals("Soft213s", $response->numberedOrderRows[0]->articleNumber);
+ $this->assertEquals("1.0", $response->numberedOrderRows[0]->quantity);
+ $this->assertEquals("st", $response->numberedOrderRows[0]->unit);
+ $this->assertEquals(3212.00, $response->numberedOrderRows[0]->amountExVat); // amount = 401500, vat = 80300 => 3212.00 @25%
+ $this->assertEquals(25, $response->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("Soft", $response->numberedOrderRows[0]->name);
+// $this->assertEquals( "Specification", $response->numberedOrderRows[1]->description );
+ $this->assertEquals(0, $response->numberedOrderRows[0]->vatDiscount);
+
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\RowBuilders\NumberedOrderRow", $response->numberedOrderRows[1]);
+ $this->assertEquals("07", $response->numberedOrderRows[1]->articleNumber);
+ $this->assertEquals("1.0", $response->numberedOrderRows[1]->quantity);
+ $this->assertEquals("st", $response->numberedOrderRows[1]->unit);
+ $this->assertEquals(0, $response->numberedOrderRows[1]->amountExVat); // amount = 401500, vat = 80300 => 3212.00 @25%
+ $this->assertEquals(0, $response->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals("Sits: Hatfield Beige 6", $response->numberedOrderRows[1]->name);
+// $this->assertEquals( "Specification", $response->numberedOrderRows[1]->description );
+ $this->assertEquals(0, $response->numberedOrderRows[1]->vatDiscount);
+ }
+
+
+ /// creditOrderRows()
+ // invoice
+ public function test_creditOrderRows_creditInvoiceOrderRows_returns_CreditOrderRowsRequest()
+ {
+ $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig());
+ $request = $creditOrderRowsBuilder->creditInvoiceOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\CreditInvoiceRowsRequest", $request);
+ }
+
+ // card
+ public function test_creditOrderRows_creditCardOrderRows_returns_CreditTransaction()
+ {
+ $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setCountryCode("SE")
+ ->setOrderId(123456)
+ ->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.00, 1, 1))
+ ->setRowToCredit(1);
+ $request = $creditOrderRowsBuilder->creditCardOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CreditTransaction", $request);
+ }
+
+ // direct bank
+ public function test_creditOrderRows_creditDirectBankOrderRows_returns_CreditTransaction()
+ {
+ $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setCountryCode("SE")
+ ->setOrderId(123456)
+ ->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.00, 1, 1))
+ ->setRowToCredit(1);
+ $request = $creditOrderRowsBuilder->creditDirectBankOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CreditTransaction", $request);
+ }
+
+ /// addOrderRows()
+ // invoice
+ // paymentplan
+ public function test_addOrderRows_addInvoiceOrderRows_returns_AddOrderRowsRequest()
+ {
+ $addOrderRowsBuilder = WebPayAdmin::addOrderRows(ConfigurationService::getDefaultConfig());
+ $request = $addOrderRowsBuilder->addInvoiceOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\AddOrderRowsRequest", $request);
+ }
+
+ public function test_addOrderRows_addPaymentPlanOrderRows_returns_AddOrderRowsRequest()
+ {
+ $addOrderRowsBuilder = WebPayAdmin::addOrderRows(ConfigurationService::getDefaultConfig());
+ $request = $addOrderRowsBuilder->addPaymentPlanOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\AddOrderRowsRequest", $request);
+ }
+
+ /// updateOrderRows()
+ // invoice
+ public function test_updateOrderRows_updateInvoiceOrderRows_returns_UpdateOrderRowsRequest()
+ {
+ $updateOrderRowsBuilder = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig());
+ $request = $updateOrderRowsBuilder->updateInvoiceOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\UpdateOrderRowsRequest", $request);
+ }
+
+ // paymentplan
+ public function test_updateOrderRows_updatePaymentPlanOrderRows_returns_UpdateOrderRowsRequest()
+ {
+ $updateOrderRowsBuilder = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig());
+ $request = $updateOrderRowsBuilder->updatePaymentPlanOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\UpdateOrderRowsRequest", $request);
+ }
+
+ // deliverOrderRows()
+ // invoice
+ public function test_deliverOrderRows_deliverInvoiceOrderRows_returns_DeliverOrderRowsRequest()
+ {
+ $request = WebPayAdmin::deliverOrderRows(ConfigurationService::getDefaultConfig())
+ ->setCountryCode("SE")
+ ->setOrderId(123456)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setRowTodeliver(1)
+ ->deliverInvoiceOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\DeliverOrderRowsRequest", $request);
+ }
+
+ //Svea\WebPay\WebPayAdmin::queryOrder()
+ //.queryInvoiceOrder
+ public function test_queryOrder_queryInvoiceOrder_single_order_row_with_invoice_fee_and_shipping_fee()
+ {
+
+ // create order using order row specified with ->setName() and ->setDescription
+ $specifiedOrderRow = WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setName("orderrow 1")
+ ->setDescription("description 1");
+
+ $invoiceFeeOrderRow = WebPayItem::invoiceFee()
+ ->setAmountExVat(20.00)
+ ->setVatPercent(25)
+ ->setName("invoicefee 1")
+ ->setDescription("invoicefee description 1");
+
+ $shippingFeeOrderRow = WebPayItem::shippingFee()
+ ->setAmountExVat(40.00)
+ ->setVatPercent(25)
+ ->setName("shippingfee 1")
+ ->setDescription("shippingfee description 1");
+
+ $order = TestUtil::createOrderWithoutOrderRows()
+ ->addOrderRow($specifiedOrderRow)
+ ->addOrderRow($invoiceFeeOrderRow)
+ ->addOrderRow($shippingFeeOrderRow);
+
+ $createOrderResponse = $order->useInvoicePayment()->doRequest();
+
+ //print_r( $createOrderResponse );
+ $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\CreateOrderResponse", $createOrderResponse);
+ $this->assertTrue($createOrderResponse->accepted);
+
+ $createdOrderId = $createOrderResponse->sveaOrderId;
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode("SE");
+
+ $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
+
+ //print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ $this->assertEquals(1, $queryResponse->numberedOrderRows[0]->rowNumber);
+ $this->assertEquals(1.00, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals(100.00, $queryResponse->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(25, $queryResponse->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals(null, $queryResponse->numberedOrderRows[0]->name);
+ $this->assertEquals("orderrow 1: description 1", $queryResponse->numberedOrderRows[0]->description);
+
+ $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber);
+ $this->assertEquals(1.00, $queryResponse->numberedOrderRows[1]->quantity);
+ $this->assertEquals(20.00, $queryResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals(25, $queryResponse->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->name);
+ $this->assertEquals("invoicefee 1: invoicefee description 1", $queryResponse->numberedOrderRows[1]->description);
+
+ $this->assertEquals(3, $queryResponse->numberedOrderRows[2]->rowNumber);
+ $this->assertEquals(1.00, $queryResponse->numberedOrderRows[2]->quantity);
+ $this->assertEquals(40.00, $queryResponse->numberedOrderRows[2]->amountExVat);
+ $this->assertEquals(25, $queryResponse->numberedOrderRows[2]->vatPercent);
+ $this->assertEquals(null, $queryResponse->numberedOrderRows[2]->name);
+ $this->assertEquals("shippingfee 1: shippingfee description 1", $queryResponse->numberedOrderRows[2]->description);
+ }
+
+ public function test_queryOrder_queryInvoiceOrder_multiple_order_rows()
+ {
+
+ // create order using order row specified with ->setName() and ->setDescription
+ $specifiedOrderRow = WebPayItem::orderRow()
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setName("orderrow 1")// optional
+ ->setDescription("description 1") // optional
+ ;
+
+ // create order using order row specified with ->setName() and ->setDescription
+ $specifiedOrderRow2 = WebPayItem::orderRow()
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setName("orderrow 2")// optional
+ ->setDescription("description 2") // optional
+ ;
+
+ $order = TestUtil::createOrderWithoutOrderRows()
+ ->addOrderRow($specifiedOrderRow)
+ ->addOrderRow($specifiedOrderRow2);
+
+ $createOrderResponse = $order->useInvoicePayment()->doRequest();
+
+ ////print_r( $createOrderResponse );
+ $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\CreateOrderResponse", $createOrderResponse);
+ $this->assertTrue($createOrderResponse->accepted);
+
+ $createdOrderId = $createOrderResponse->sveaOrderId;
+
+ // WPA::queryOrder()
+ // ->queryInvoiceOrder()
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode("SE");
+
+ $queryResponse = $queryOrderBuilder->queryInvoiceOrder()->doRequest();
+
+ //print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ // assert that order rows are the same
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ $this->assertEquals(1, $queryResponse->numberedOrderRows[0]->rowNumber);
+ $this->assertEquals(1.00, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals(100.00, $queryResponse->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(25, $queryResponse->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals(null, $queryResponse->numberedOrderRows[0]->name);
+ $this->assertEquals("orderrow 1: description 1", $queryResponse->numberedOrderRows[0]->description);
+
+ $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber);
+ $this->assertEquals(1.00, $queryResponse->numberedOrderRows[1]->quantity);
+ $this->assertEquals(100.00, $queryResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals(25, $queryResponse->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals(null, $queryResponse->numberedOrderRows[1]->name);
+ $this->assertEquals("orderrow 2: description 2", $queryResponse->numberedOrderRows[1]->description);
+ }
+
+ //-queryPaymentPlanOrder
+ // TODO
+
+ //.queryCardOrder
+ public function test_queryOrder_queryCardOrder_single_order_row()
+ {
+
+ // created w/java package TODO make self-contained using webdriver to create card order
+ $createdOrderId = 587673;
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode("SE");
+
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ //print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ $this->assertEquals(1, $queryResponse->numberedOrderRows[0]->rowNumber);
+ $this->assertEquals(1.00, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals(100.00, $queryResponse->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(25, $queryResponse->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("orderrow 1", $queryResponse->numberedOrderRows[0]->name);
+ $this->assertEquals("description 1", $queryResponse->numberedOrderRows[0]->description);
+ }
+
+ public function test_queryOrder_queryCardOrder_multiple_order_rows()
+ {
+
+ // created w/java package TODO make self-contained using webdriver to create card order
+ $createdOrderId = 587679;
+
+ // query orderrows
+ $queryOrderBuilder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode("SE");
+
+ $queryResponse = $queryOrderBuilder->queryCardOrder()->doRequest();
+
+ //print_r( $queryResponse);
+ $this->assertEquals(1, $queryResponse->accepted);
+
+ $this->assertEquals(1, $queryResponse->numberedOrderRows[0]->rowNumber);
+ $this->assertEquals(1.00, $queryResponse->numberedOrderRows[0]->quantity);
+ $this->assertEquals(100.00, $queryResponse->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(25, $queryResponse->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals("orderrow 1", $queryResponse->numberedOrderRows[0]->name);
+ $this->assertEquals("description 1", $queryResponse->numberedOrderRows[0]->description);
+
+ $this->assertEquals(2, $queryResponse->numberedOrderRows[1]->rowNumber);
+ $this->assertEquals(1.00, $queryResponse->numberedOrderRows[1]->quantity);
+ $this->assertEquals(100.00, $queryResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals(25, $queryResponse->numberedOrderRows[1]->vatPercent);
+ $this->assertEquals("orderrow 2", $queryResponse->numberedOrderRows[1]->name);
+ $this->assertEquals("description 2", $queryResponse->numberedOrderRows[1]->description);
+ }
+
+ //-queryDirectBankOrder
+ // TODO
}
diff --git a/test/IntegrationTest/WebPayIntegrationTest.php b/test/IntegrationTest/WebPayIntegrationTest.php
index 65cb20ed..b3243dab 100644
--- a/test/IntegrationTest/WebPayIntegrationTest.php
+++ b/test/IntegrationTest/WebPayIntegrationTest.php
@@ -18,450 +18,450 @@
class WebPayIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /// Svea\WebPay\WebPay::createOrder() --------------------------------------------------
- //useInvoicePayment
- public function test_createOrder_useInvoicePayment()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
- }
-
- //usePaymentPlanPayment
- public function test_createOrder_usePaymentPlanPayment()
- {
- $config = ConfigurationService::getDefaultConfig();
- $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountExVat(1000.00)
- ->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("test@svea.com")
- ->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);
- }
-
- // card
- public function test_createOrder_usePaymentMethod_KORTCERT_redirects_to_certitrade()
- {
- $this->markTestIncomplete(
- 'CertiTrade no longer used'
- );
- $config = ConfigurationService::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")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
- $url = "https://webpaypaymentgatewaystage.svea.com/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);
-
- $this->assertEquals(200, $info['http_code']);
- $this->assertEquals(1, $info['redirect_count']);
- $this->assertEquals("https://etest.certitrade.net/card/paywin/index", substr($info['url'], 0, 46));
- }
-
- // TODO Move below to unit tests?
- //
- /// Svea\WebPay\WebPay::createOrder()
- // web service eu: invoice
- public function test_createOrder_useInvoicePayment_returns_InvoicePayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- // we should set attributes here if real request
- $request = $createOrder->useInvoicePayment();
- $this->assertInstanceOf("Svea\WebPay\WebService\Payment\InvoicePayment", $request);
- }
-
- // web service eu: paymentplan
- public function test_createOrder_usePaymentPlanPayment_returns_PaymentPlanPayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- $request = $createOrder->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting());
- $this->assertInstanceOf("Svea\WebPay\WebService\Payment\PaymentPlanPayment", $request);
- }
-
- // paypage: cardonly
- public function test_createOrder_usePayPageCardOnly_returns_CardPayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- $request = $createOrder->usePayPageCardOnly();
- $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\CardPayment", $request);
- }
-
- // paypage: directbankonly
- public function test_createOrder_usePayPageDirectBankOnly_returns_DirectPayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- $request = $createOrder->usePayPageDirectBankOnly();
- $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\DirectPayment", $request);
- }
-
- // bypass paypage: usepaymentmethod
- public function test_createOrder_usePaymentMethod_returns_PaymentMethodPayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- $request = $createOrder->usePaymentMethod("mocked_paymentMethod");
- $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\PaymentMethodPayment", $request);
- }
-
- // usepaymentmethod KORTCERT with recurring payment
- // TODO add recur example when implementing webdriver integration tests
-
- // paypage
- public function test_createOrder_usePayPage_returns_PayPagePayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- $request = $createOrder->usePayPage();
- $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\PayPagePayment", $request);
- }
-
- /// Svea\WebPay\WebPay::deliverOrder()
- // invoice
- // TODO actual integration test
-
- // DeliverOrderEU - deliver order and credit order
- public function test_deliverOrder_deliverInvoiceOrder_with_order_rows_first_deliver_then_credit_order()
- {
- // create order using order row specified with ->setName() and ->setDescription
- $specifiedOrderRow = WebPayItem::orderRow()
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1) // required
- ;
-
- $order = TestUtil::createOrderWithoutOrderRows()
- ->addOrderRow($specifiedOrderRow);
-
- $createOrderResponse = $order->useInvoicePayment()->doRequest();
-
- //print_r( $createOrderResponse );
- $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\CreateOrderResponse", $createOrderResponse);
- $this->assertTrue($createOrderResponse->accepted);
-
- $createdOrderId = $createOrderResponse->sveaOrderId;
-
- // deliver order
- $deliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->addOrderRow($specifiedOrderRow);
- $deliverOrderResponse = $deliverOrderBuilder->deliverInvoiceOrder()->doRequest();
-
- //print_r( $deliverOrderResponse );
- $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult", $deliverOrderResponse);
- $this->assertTrue($createOrderResponse->accepted);
-
- $deliveredInvoiceId = $deliverOrderResponse->invoiceId;
-
- // credit order
- $creditOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($createdOrderId)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->addOrderRow($specifiedOrderRow)
- ->setCreditInvoice($deliveredInvoiceId);
- $creditOrderResponse = $creditOrderBuilder->deliverInvoiceOrder()->doRequest();
-
- //print_r( $creditOrderResponse );
- $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult", $deliverOrderResponse);
- $this->assertTrue($creditOrderResponse->accepted);
- }
-
- // paymentplan
- public function test_deliverOrder_deliverPaymentPlanOrder_without_orderrows_delivers_order_in_full()
- {
- // create order
- $config = ConfigurationService::getDefaultConfig();
- $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
- $order = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountExVat(1000.00)
- ->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("test@svea.com")
- ->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)// returnerar InvoiceOrder object
- ->doRequest();
-
- //print_r($order);
- $this->assertEquals(1, $order->accepted);
-
- // deliver order
- $orderId = $order->sveaOrderId;
- $orderBuilder = WebPay::deliverOrder($config);
- $deliverResponse = $orderBuilder
- //->addOrderRow(Svea\WebPay\WebPayItem::orderRow()
- // ->setArticleNumber("1")
- // ->setQuantity(2)
- // ->setAmountExVat(1000.00)
- // ->setDescription("Specification")
- // ->setName('Prod')
- // ->setUnit("st")
- // ->setVatPercent(25)
- // ->setDiscountPercent(0)
- //)
- ->setOrderId($orderId)
- ->setCountryCode("SE")
- ->deliverPaymentPlanOrder()
- ->doRequest();
-
- //print_r($deliverResponse);
- $this->assertEquals(1, $deliverResponse->accepted);
- $this->assertEquals(0, $deliverResponse->resultcode);
- $this->assertEquals(2500, $deliverResponse->amount);
- $this->assertEquals('PaymentPlan', $deliverResponse->orderType);
- }
-
- public function test_deliverOrder_deliverPaymentPlanOrder_with_orderrows_misleadingly_delivers_order_in_full()
- {
- // create order
- $config = ConfigurationService::getDefaultConfig();
- $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
- $order = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountExVat(1000.00)
- ->setDescription("Specification")
- ->setName('Prod')
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("2")
- ->setQuantity(2)
- ->setAmountExVat(1000.00)
- ->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("test@svea.com")
- ->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)// returnerar InvoiceOrder object
- ->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()// TODO should raise validation exception
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountExVat(1000.00)
- ->setDescription("Specification")
- ->setName('Prod')
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->setOrderId($orderId)
- ->setInvoiceDistributionType("Post")// TODO should raise validation exception
- ->setCountryCode("SE")
- ->deliverPaymentPlanOrder()
- ->doRequest();
-
- //print_r($deliverResponse);
- $this->assertEquals(1, $deliverResponse->accepted);
- $this->assertEquals(5000, $deliverResponse->amount);
- }
-
- // card
- // TODO actual integration test
-
- /// Svea\WebPay\WebPay::getAddresses()
- // TODO
-
- /// Svea\WebPay\WebPay::getPaymentPlanParams()
- // TODO
-
- /// Svea\WebPay\WebPay::listPaymentMethods()
- public function test_listPaymentMethods_returns_ListPaymentMethods()
- {
- $response = WebPay::listPaymentMethods(ConfigurationService::getDefaultConfig())
- ->setCountryCode("SE")
- ->doRequest();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ListPaymentMethodsResponse", $response);
- $this->assertEquals(true, $response->accepted);
- }
-
- /// Svea\WebPay\WebPay::paymentPlanPricePerMonth()
- public function test_paymentPlanPricePerMonth_returns_PaymentPlanPricePerMonth()
- {
- $campaigns =
- WebPay::getPaymentPlanParams(ConfigurationService::getDefaultConfig())
- ->setCountryCode("SE")
- ->doRequest();
- $this->assertTrue($campaigns->accepted);
-
- $pricesPerMonth = Helper::paymentPlanPricePerMonth(2000, $campaigns, true);
- $this->assertInstanceOf("Svea\WebPay\WebService\GetPaymentPlanParams\PaymentPlanPricePerMonth", $pricesPerMonth);
-
-// $this->assertEquals(213060, $pricesPerMonth->values[0]['campaignCode']); //don't test to be flexible
- $this->assertEquals(true, isset($pricesPerMonth->values[0]['pricePerMonth']));
- }
-
- public function test_Checkout_SveaConfigurationProvider()
- {
- $responseSE = WebPay::checkout(ConfigurationService::getTestConfig())
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setLocale("sv-se")
- ->setCheckoutUri("http://localhost")
- ->setTermsUri("http://localhost")
- ->setPushUri("http://localhost")
- ->setConfirmationUri("http://localhost")
- ->setClientOrderNumber("PHP_IntegrationTest_" . rand(0, 10000000))
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountIncVat(1000.00)
- ->setDescription("Specification")
- ->setName('Prod')
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )->createOrder();
-
- $this->assertEquals($responseSE['CountryCode'], "SE");
-
- $responseNO = WebPay::checkout(ConfigurationService::getTestConfig())
- ->setCountryCode("NO")
- ->setCurrency("NOK")
- ->setLocale("nn-no")
- ->setCheckoutUri("http://localhost")
- ->setTermsUri("http://localhost")
- ->setPushUri("http://localhost")
- ->setConfirmationUri("http://localhost")
- ->setClientOrderNumber("PHP_IntegrationTest_" .rand(0, 10000000))
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountIncVat(1000.00)
- ->setDescription("Specification")
- ->setName('Prod')
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )->createOrder();
-
- $this->assertEquals($responseNO['CountryCode'], "NO");
- }
+ /// Svea\WebPay\WebPay::createOrder() --------------------------------------------------
+ //useInvoicePayment
+ public function test_createOrder_useInvoicePayment()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+ }
+
+ //usePaymentPlanPayment
+ public function test_createOrder_usePaymentPlanPayment()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountExVat(1000.00)
+ ->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("test@svea.com")
+ ->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);
+ }
+
+ // card
+ public function test_createOrder_usePaymentMethod_KORTCERT_redirects_to_certitrade()
+ {
+ $this->markTestIncomplete(
+ 'CertiTrade no longer used'
+ );
+ $config = ConfigurationService::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")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+ $url = "https://webpaypaymentgatewaystage.svea.com/webpay/payment";
+
+ /** CURL **/
+ $fields = ['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);
+
+ $this->assertEquals(200, $info['http_code']);
+ $this->assertEquals(1, $info['redirect_count']);
+ $this->assertEquals("https://etest.certitrade.net/card/paywin/index", substr($info['url'], 0, 46));
+ }
+
+ // TODO Move below to unit tests?
+ //
+ /// Svea\WebPay\WebPay::createOrder()
+ // web service eu: invoice
+ public function test_createOrder_useInvoicePayment_returns_InvoicePayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ // we should set attributes here if real request
+ $request = $createOrder->useInvoicePayment();
+ $this->assertInstanceOf("Svea\WebPay\WebService\Payment\InvoicePayment", $request);
+ }
+
+ // web service eu: paymentplan
+ public function test_createOrder_usePaymentPlanPayment_returns_PaymentPlanPayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ $request = $createOrder->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting());
+ $this->assertInstanceOf("Svea\WebPay\WebService\Payment\PaymentPlanPayment", $request);
+ }
+
+ // paypage: cardonly
+ public function test_createOrder_usePayPageCardOnly_returns_CardPayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ $request = $createOrder->usePayPageCardOnly();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\CardPayment", $request);
+ }
+
+ // paypage: directbankonly
+ public function test_createOrder_usePayPageDirectBankOnly_returns_DirectPayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ $request = $createOrder->usePayPageDirectBankOnly();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\DirectPayment", $request);
+ }
+
+ // bypass paypage: usepaymentmethod
+ public function test_createOrder_usePaymentMethod_returns_PaymentMethodPayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ $request = $createOrder->usePaymentMethod("mocked_paymentMethod");
+ $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\PaymentMethodPayment", $request);
+ }
+
+ // usepaymentmethod KORTCERT with recurring payment
+ // TODO add recur example when implementing webdriver integration tests
+
+ // paypage
+ public function test_createOrder_usePayPage_returns_PayPagePayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ $request = $createOrder->usePayPage();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\PayPagePayment", $request);
+ }
+
+ /// Svea\WebPay\WebPay::deliverOrder()
+ // invoice
+ // TODO actual integration test
+
+ // DeliverOrderEU - deliver order and credit order
+ public function test_deliverOrder_deliverInvoiceOrder_with_order_rows_first_deliver_then_credit_order()
+ {
+ // create order using order row specified with ->setName() and ->setDescription
+ $specifiedOrderRow = WebPayItem::orderRow()
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1) // required
+ ;
+
+ $order = TestUtil::createOrderWithoutOrderRows()
+ ->addOrderRow($specifiedOrderRow);
+
+ $createOrderResponse = $order->useInvoicePayment()->doRequest();
+
+ //print_r( $createOrderResponse );
+ $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\CreateOrderResponse", $createOrderResponse);
+ $this->assertTrue($createOrderResponse->accepted);
+
+ $createdOrderId = $createOrderResponse->sveaOrderId;
+
+ // deliver order
+ $deliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->addOrderRow($specifiedOrderRow);
+ $deliverOrderResponse = $deliverOrderBuilder->deliverInvoiceOrder()->doRequest();
+
+ //print_r( $deliverOrderResponse );
+ $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult", $deliverOrderResponse);
+ $this->assertTrue($createOrderResponse->accepted);
+
+ $deliveredInvoiceId = $deliverOrderResponse->invoiceId;
+
+ // credit order
+ $creditOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($createdOrderId)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->addOrderRow($specifiedOrderRow)
+ ->setCreditInvoice($deliveredInvoiceId);
+ $creditOrderResponse = $creditOrderBuilder->deliverInvoiceOrder()->doRequest();
+
+ //print_r( $creditOrderResponse );
+ $this->assertInstanceOf("Svea\WebPay\WebService\WebServiceResponse\DeliverOrderResult", $deliverOrderResponse);
+ $this->assertTrue($creditOrderResponse->accepted);
+ }
+
+ // paymentplan
+ public function test_deliverOrder_deliverPaymentPlanOrder_without_orderrows_delivers_order_in_full()
+ {
+ // create order
+ $config = ConfigurationService::getDefaultConfig();
+ $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountExVat(1000.00)
+ ->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("test@svea.com")
+ ->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)// returnerar InvoiceOrder object
+ ->doRequest();
+
+ //print_r($order);
+ $this->assertEquals(1, $order->accepted);
+
+ // deliver order
+ $orderId = $order->sveaOrderId;
+ $orderBuilder = WebPay::deliverOrder($config);
+ $deliverResponse = $orderBuilder
+ //->addOrderRow(Svea\WebPay\WebPayItem::orderRow()
+ // ->setArticleNumber("1")
+ // ->setQuantity(2)
+ // ->setAmountExVat(1000.00)
+ // ->setDescription("Specification")
+ // ->setName('Prod')
+ // ->setUnit("st")
+ // ->setVatPercent(25)
+ // ->setDiscountPercent(0)
+ //)
+ ->setOrderId($orderId)
+ ->setCountryCode("SE")
+ ->deliverPaymentPlanOrder()
+ ->doRequest();
+
+ //print_r($deliverResponse);
+ $this->assertEquals(1, $deliverResponse->accepted);
+ $this->assertEquals(0, $deliverResponse->resultcode);
+ $this->assertEquals(2500, $deliverResponse->amount);
+ $this->assertEquals('PaymentPlan', $deliverResponse->orderType);
+ }
+
+ public function test_deliverOrder_deliverPaymentPlanOrder_with_orderrows_misleadingly_delivers_order_in_full()
+ {
+ // create order
+ $config = ConfigurationService::getDefaultConfig();
+ $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountExVat(1000.00)
+ ->setDescription("Specification")
+ ->setName('Prod')
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("2")
+ ->setQuantity(2)
+ ->setAmountExVat(1000.00)
+ ->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("test@svea.com")
+ ->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)// returnerar InvoiceOrder object
+ ->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()// TODO should raise validation exception
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountExVat(1000.00)
+ ->setDescription("Specification")
+ ->setName('Prod')
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->setOrderId($orderId)
+ ->setInvoiceDistributionType("Post")// TODO should raise validation exception
+ ->setCountryCode("SE")
+ ->deliverPaymentPlanOrder()
+ ->doRequest();
+
+ //print_r($deliverResponse);
+ $this->assertEquals(1, $deliverResponse->accepted);
+ $this->assertEquals(5000, $deliverResponse->amount);
+ }
+
+ // card
+ // TODO actual integration test
+
+ /// Svea\WebPay\WebPay::getAddresses()
+ // TODO
+
+ /// Svea\WebPay\WebPay::getPaymentPlanParams()
+ // TODO
+
+ /// Svea\WebPay\WebPay::listPaymentMethods()
+ public function test_listPaymentMethods_returns_ListPaymentMethods()
+ {
+ $response = WebPay::listPaymentMethods(ConfigurationService::getDefaultConfig())
+ ->setCountryCode("SE")
+ ->doRequest();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedResponse\HostedAdminResponse\ListPaymentMethodsResponse", $response);
+ $this->assertEquals(true, $response->accepted);
+ }
+
+ /// Svea\WebPay\WebPay::paymentPlanPricePerMonth()
+ public function test_paymentPlanPricePerMonth_returns_PaymentPlanPricePerMonth()
+ {
+ $campaigns =
+ WebPay::getPaymentPlanParams(ConfigurationService::getDefaultConfig())
+ ->setCountryCode("SE")
+ ->doRequest();
+ $this->assertTrue($campaigns->accepted);
+
+ $pricesPerMonth = Helper::paymentPlanPricePerMonth(2000, $campaigns, true);
+ $this->assertInstanceOf("Svea\WebPay\WebService\GetPaymentPlanParams\PaymentPlanPricePerMonth", $pricesPerMonth);
+
+// $this->assertEquals(213060, $pricesPerMonth->values[0]['campaignCode']); //don't test to be flexible
+ $this->assertEquals(true, isset($pricesPerMonth->values[0]['pricePerMonth']));
+ }
+
+ public function test_Checkout_SveaConfigurationProvider()
+ {
+ $responseSE = WebPay::checkout(ConfigurationService::getTestConfig())
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setLocale("sv-se")
+ ->setCheckoutUri("http://localhost")
+ ->setTermsUri("http://localhost")
+ ->setPushUri("http://localhost")
+ ->setConfirmationUri("http://localhost")
+ ->setClientOrderNumber("PHP_IntegrationTest_" . rand(0, 10000000))
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountIncVat(1000.00)
+ ->setDescription("Specification")
+ ->setName('Prod')
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )->createOrder();
+
+ $this->assertEquals($responseSE['CountryCode'], "SE");
+
+ $responseNO = WebPay::checkout(ConfigurationService::getTestConfig())
+ ->setCountryCode("NO")
+ ->setCurrency("NOK")
+ ->setLocale("nn-no")
+ ->setCheckoutUri("http://localhost")
+ ->setTermsUri("http://localhost")
+ ->setPushUri("http://localhost")
+ ->setConfirmationUri("http://localhost")
+ ->setClientOrderNumber("PHP_IntegrationTest_" .rand(0, 10000000))
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountIncVat(1000.00)
+ ->setDescription("Specification")
+ ->setName('Prod')
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )->createOrder();
+
+ $this->assertEquals($responseNO['CountryCode'], "NO");
+ }
}
\ No newline at end of file
diff --git a/test/IntegrationTest/WebService/GetAddresses/GetAddressesIntegrationTest.php b/test/IntegrationTest/WebService/GetAddresses/GetAddressesIntegrationTest.php
index 3064ae14..1de7883a 100644
--- a/test/IntegrationTest/WebService/GetAddresses/GetAddressesIntegrationTest.php
+++ b/test/IntegrationTest/WebService/GetAddresses/GetAddressesIntegrationTest.php
@@ -14,299 +14,299 @@
class GetAddressesIntegrationTest extends \PHPUnit\Framework\TestCase
{
- private $config;
- private $addressRequest;
-
- public function SetUp()
- {
- $this->config = ConfigurationService::getDefaultConfig();
- $this->addressRequest = new GetAddresses($this->config);
- }
-
- // private, company
- public function testGetAddressesResult_Private()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier("194605092222")
- ->getIndividualAddresses()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
- }
-
- public function testGetAddressesResult_Company()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4608142222")
- ->getCompanyAddresses()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
- }
-
- public function testGetAddressesResult_PaymentPlan()
- {
- $request = $this->addressRequest
- ->setOrderTypePaymentPlan()
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4608142222")
- ->getCompanyAddresses()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
- }
-
- public function testGetAddressesResult_Invoice()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4608142222")
- ->getCompanyAddresses()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
- }
-
- public function test_GetAddressesResult_Invoice_NoSuchEntity()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4608142222")
- ->getIndividualAddresses()
- ->doRequest();
- $this->assertEquals(0, $request->accepted);
- $this->assertEquals("NoSuchEntity", $request->resultcode);
- }
-
- public function test_GetAddressesResult_Invoice_Errormessage()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4608142222")
- ->getIndividualAddresses()
- ->doRequest();
- $this->assertEquals(0, $request->accepted);
- $this->assertEquals("NoSuchEntity", $request->resultcode);
- $this->assertEquals("No customer address was found", $request->errormessage);
- }
-
- public function test_GetAddresses_CredentialsForPrivate_areCorrect()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier("194605092222")
- ->getIndividualAddresses()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals('Accepted', $request->resultcode);
- $this->assertEquals('7d97a7f100744f419607fb654202cdc9', $request->customerIdentity[0]->addressSelector);
- $this->assertEquals('Person', $request->customerIdentity[0]->customerType);
- $this->assertEquals('+46811111111', $request->customerIdentity[0]->phoneNumber);
- $this->assertEquals('Persson Tess T', $request->customerIdentity[0]->fullName);
- $this->assertEquals('Tess', $request->customerIdentity[0]->firstName);
- $this->assertEquals('Persson', $request->customerIdentity[0]->lastName);
- $this->assertEquals('Testgatan 1', $request->customerIdentity[0]->street);
- $this->assertEquals('c/o Eriksson, Erik', $request->customerIdentity[0]->coAddress);
- $this->assertEquals(99999, $request->customerIdentity[0]->zipCode);
- $this->assertEquals('Stan', $request->customerIdentity[0]->locality);
- $this->assertEquals(4605092222, $request->customerIdentity[0]->nationalIdNumber);
- }
-
- /**
- * out commented because it's too detaild and breaks on changes
- */
- public function t_est_GetAddresses_CredentialsForCompany_areCorrect()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier("194608142222")// 12 digit orgnr should start with 16 or be 10 digits.
- ->getCompanyAddresses()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals('Accepted', $request->resultcode);
- $this->assertEquals('5F445B19E8C87954904FB7531A51AEE57C5E9413', $request->customerIdentity[0]->addressSelector);
- $this->assertEquals('Business', $request->customerIdentity[0]->customerType);
- $this->assertEquals('08 - 111 111 11', $request->customerIdentity[0]->phoneNumber);
- $this->assertEquals('Persson, Tess T', $request->customerIdentity[0]->fullName);
- $this->assertEquals('Tess T', $request->customerIdentity[0]->firstName);
- $this->assertEquals('Persson', $request->customerIdentity[0]->lastName);
- $this->assertEquals('Testgatan 1', $request->customerIdentity[0]->street);
- $this->assertEquals('c/o Eriksson, Erik', $request->customerIdentity[0]->coAddress);
- $this->assertEquals(99999, $request->customerIdentity[0]->zipCode);
- $this->assertEquals('Stan', $request->customerIdentity[0]->locality);
- $this->assertEquals(4608142222, $request->customerIdentity[0]->nationalIdNumber);
-
- $this->assertEquals('F09E3CC5AFB627CACBE22A7BC371DE0047222F7F', $request->customerIdentity[1]->addressSelector);
- $this->assertEquals('Business', $request->customerIdentity[1]->customerType);
- $this->assertEquals('08 - 111 111 11', $request->customerIdentity[1]->phoneNumber);
- $this->assertEquals('Persson, Tess T', $request->customerIdentity[1]->fullName);
- $this->assertEquals('Tess T', $request->customerIdentity[1]->firstName);
- $this->assertEquals('Persson', $request->customerIdentity[1]->lastName);
- $this->assertEquals('Testgatan 1, 2', $request->customerIdentity[1]->street);
- $this->assertEquals('c/o Eriksson, Erik', $request->customerIdentity[1]->coAddress);
- $this->assertEquals(99999, $request->customerIdentity[1]->zipCode);
- $this->assertEquals('Stan', $request->customerIdentity[1]->locality);
- $this->assertEquals(4608142222, $request->customerIdentity[1]->nationalIdNumber);
- }
-
- // getAddresses is supported for the following countries and customer types
- // SE/private
- public function test_GetAddresses_Sweden_Private_isAccepted()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier("194605092222")
- ->getIndividualAddresses()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals('Accepted', $request->resultcode);
- }
-
- // DK/private
- public function test_GetAddresses_Denmark_Private_isAccepted()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("DK")
- ->setCustomerIdentifier("2603692503")
- ->getIndividualAddresses()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals('Accepted', $request->resultcode);
- }
-
- // SE/company
- public function test_GetAddresses_Sweden_Company_isAccepted()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4608142222")
- ->getCompanyAddresses()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals('Accepted', $request->resultcode);
- }
-
- // DK/company
- public function test_GetAddresses_Denmark_Company_isAccepted()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("DK")
- ->setCustomerIdentifier("99999993")
- ->getCompanyAddresses()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals('Accepted', $request->resultcode);
- }
-
- // NO/company
- public function test_GetAddresses_Norway_Company_isAccepted()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("NO")
- ->setCustomerIdentifier("923313850")
- ->getCompanyAddresses()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals('Accepted', $request->resultcode);
- }
-
- // NO/private
- public function test_GetAddresses_Norway_Private_isDisabled()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("NO")
- ->setCustomerIdentifier("17054512066")
- ->getCompanyAddresses()
- ->doRequest();
-
- //disabled oct-13
- $this->assertEquals(0, $request->accepted);
- $this->assertEquals('Error', $request->resultcode);
- }
-
- // DE/private
- public function test_GetAddresses_Germany_Private_isNotImplemented()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("DE")
- ->setCustomerIdentifier("foo")
- ->getIndividualAddresses()
- ->doRequest();
-
- $this->assertEquals(0, $request->accepted);
- $this->assertEquals('Error', $request->resultcode);
- }
-
- // DE/company
- public function test_GetAddresses_Germany_Company_isNotImplemented()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("DE")
- ->setCustomerIdentifier("19680403")
- ->getCompanyAddresses()
- ->doRequest();
-
- $this->assertEquals(0, $request->accepted);
- $this->assertEquals('Error', $request->resultcode);
- }
-
- // NL
- // NL/private
- public function test_GetAddresses_Netherlands_Private_isNotImplemented()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("NL")
- ->setCustomerIdentifier("foo")
- ->getIndividualAddresses()
- ->doRequest();
-
- $this->assertEquals(0, $request->accepted);
- $this->assertEquals('Error', $request->resultcode);
- }
-
- // NL/company
- public function test_GetAddresses_Netherlands_Company_isNotImplemented()
- {
- $request = $this->addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("NL")
- ->setCustomerIdentifier("19550307")
- ->getCompanyAddresses()
- ->doRequest();
-
- $this->assertEquals(0, $request->accepted);
- $this->assertEquals('Error', $request->resultcode);
- }
-
- public function test_GetAddresses_checkAndSetConfiguredPaymentMethod_Accepted()
- {
- $request =$this->addressRequest
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4605092222")
- ->getIndividualAddresses()
- ->doRequest();
- $this->assertEquals(1,$request->accepted);
- }
+ private $config;
+ private $addressRequest;
+
+ public function SetUp()
+ {
+ $this->config = ConfigurationService::getDefaultConfig();
+ $this->addressRequest = new GetAddresses($this->config);
+ }
+
+ // private, company
+ public function testGetAddressesResult_Private()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("194605092222")
+ ->getIndividualAddresses()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+ }
+
+ public function testGetAddressesResult_Company()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4608142222")
+ ->getCompanyAddresses()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+ }
+
+ public function testGetAddressesResult_PaymentPlan()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypePaymentPlan()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4608142222")
+ ->getCompanyAddresses()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+ }
+
+ public function testGetAddressesResult_Invoice()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4608142222")
+ ->getCompanyAddresses()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+ }
+
+ public function test_GetAddressesResult_Invoice_NoSuchEntity()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4608142222")
+ ->getIndividualAddresses()
+ ->doRequest();
+ $this->assertEquals(0, $request->accepted);
+ $this->assertEquals("NoSuchEntity", $request->resultcode);
+ }
+
+ public function test_GetAddressesResult_Invoice_Errormessage()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4608142222")
+ ->getIndividualAddresses()
+ ->doRequest();
+ $this->assertEquals(0, $request->accepted);
+ $this->assertEquals("NoSuchEntity", $request->resultcode);
+ $this->assertEquals("No customer address was found", $request->errormessage);
+ }
+
+ public function test_GetAddresses_CredentialsForPrivate_areCorrect()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("194605092222")
+ ->getIndividualAddresses()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals('Accepted', $request->resultcode);
+ $this->assertEquals('7d97a7f100744f419607fb654202cdc9', $request->customerIdentity[0]->addressSelector);
+ $this->assertEquals('Person', $request->customerIdentity[0]->customerType);
+ $this->assertEquals('+46811111111', $request->customerIdentity[0]->phoneNumber);
+ $this->assertEquals('Persson Tess T', $request->customerIdentity[0]->fullName);
+ $this->assertEquals('Tess', $request->customerIdentity[0]->firstName);
+ $this->assertEquals('Persson', $request->customerIdentity[0]->lastName);
+ $this->assertEquals('Testgatan 1', $request->customerIdentity[0]->street);
+ $this->assertEquals('c/o Eriksson, Erik', $request->customerIdentity[0]->coAddress);
+ $this->assertEquals(99999, $request->customerIdentity[0]->zipCode);
+ $this->assertEquals('Stan', $request->customerIdentity[0]->locality);
+ $this->assertEquals(4605092222, $request->customerIdentity[0]->nationalIdNumber);
+ }
+
+ /**
+ * out commented because it's too detaild and breaks on changes
+ */
+ public function t_est_GetAddresses_CredentialsForCompany_areCorrect()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("194608142222")// 12 digit orgnr should start with 16 or be 10 digits.
+ ->getCompanyAddresses()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals('Accepted', $request->resultcode);
+ $this->assertEquals('5F445B19E8C87954904FB7531A51AEE57C5E9413', $request->customerIdentity[0]->addressSelector);
+ $this->assertEquals('Business', $request->customerIdentity[0]->customerType);
+ $this->assertEquals('08 - 111 111 11', $request->customerIdentity[0]->phoneNumber);
+ $this->assertEquals('Persson, Tess T', $request->customerIdentity[0]->fullName);
+ $this->assertEquals('Tess T', $request->customerIdentity[0]->firstName);
+ $this->assertEquals('Persson', $request->customerIdentity[0]->lastName);
+ $this->assertEquals('Testgatan 1', $request->customerIdentity[0]->street);
+ $this->assertEquals('c/o Eriksson, Erik', $request->customerIdentity[0]->coAddress);
+ $this->assertEquals(99999, $request->customerIdentity[0]->zipCode);
+ $this->assertEquals('Stan', $request->customerIdentity[0]->locality);
+ $this->assertEquals(4608142222, $request->customerIdentity[0]->nationalIdNumber);
+
+ $this->assertEquals('F09E3CC5AFB627CACBE22A7BC371DE0047222F7F', $request->customerIdentity[1]->addressSelector);
+ $this->assertEquals('Business', $request->customerIdentity[1]->customerType);
+ $this->assertEquals('08 - 111 111 11', $request->customerIdentity[1]->phoneNumber);
+ $this->assertEquals('Persson, Tess T', $request->customerIdentity[1]->fullName);
+ $this->assertEquals('Tess T', $request->customerIdentity[1]->firstName);
+ $this->assertEquals('Persson', $request->customerIdentity[1]->lastName);
+ $this->assertEquals('Testgatan 1, 2', $request->customerIdentity[1]->street);
+ $this->assertEquals('c/o Eriksson, Erik', $request->customerIdentity[1]->coAddress);
+ $this->assertEquals(99999, $request->customerIdentity[1]->zipCode);
+ $this->assertEquals('Stan', $request->customerIdentity[1]->locality);
+ $this->assertEquals(4608142222, $request->customerIdentity[1]->nationalIdNumber);
+ }
+
+ // getAddresses is supported for the following countries and customer types
+ // SE/private
+ public function test_GetAddresses_Sweden_Private_isAccepted()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("194605092222")
+ ->getIndividualAddresses()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals('Accepted', $request->resultcode);
+ }
+
+ // DK/private
+ public function test_GetAddresses_Denmark_Private_isAccepted()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("DK")
+ ->setCustomerIdentifier("2603692503")
+ ->getIndividualAddresses()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals('Accepted', $request->resultcode);
+ }
+
+ // SE/company
+ public function test_GetAddresses_Sweden_Company_isAccepted()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4608142222")
+ ->getCompanyAddresses()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals('Accepted', $request->resultcode);
+ }
+
+ // DK/company
+ public function test_GetAddresses_Denmark_Company_isAccepted()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("DK")
+ ->setCustomerIdentifier("99999993")
+ ->getCompanyAddresses()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals('Accepted', $request->resultcode);
+ }
+
+ // NO/company
+ public function test_GetAddresses_Norway_Company_isAccepted()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("NO")
+ ->setCustomerIdentifier("923313850")
+ ->getCompanyAddresses()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals('Accepted', $request->resultcode);
+ }
+
+ // NO/private
+ public function test_GetAddresses_Norway_Private_isDisabled()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("NO")
+ ->setCustomerIdentifier("17054512066")
+ ->getCompanyAddresses()
+ ->doRequest();
+
+ //disabled oct-13
+ $this->assertEquals(0, $request->accepted);
+ $this->assertEquals('Error', $request->resultcode);
+ }
+
+ // DE/private
+ public function test_GetAddresses_Germany_Private_isNotImplemented()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("DE")
+ ->setCustomerIdentifier("foo")
+ ->getIndividualAddresses()
+ ->doRequest();
+
+ $this->assertEquals(0, $request->accepted);
+ $this->assertEquals('Error', $request->resultcode);
+ }
+
+ // DE/company
+ public function test_GetAddresses_Germany_Company_isNotImplemented()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("DE")
+ ->setCustomerIdentifier("19680403")
+ ->getCompanyAddresses()
+ ->doRequest();
+
+ $this->assertEquals(0, $request->accepted);
+ $this->assertEquals('Error', $request->resultcode);
+ }
+
+ // NL
+ // NL/private
+ public function test_GetAddresses_Netherlands_Private_isNotImplemented()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("NL")
+ ->setCustomerIdentifier("foo")
+ ->getIndividualAddresses()
+ ->doRequest();
+
+ $this->assertEquals(0, $request->accepted);
+ $this->assertEquals('Error', $request->resultcode);
+ }
+
+ // NL/company
+ public function test_GetAddresses_Netherlands_Company_isNotImplemented()
+ {
+ $request = $this->addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("NL")
+ ->setCustomerIdentifier("19550307")
+ ->getCompanyAddresses()
+ ->doRequest();
+
+ $this->assertEquals(0, $request->accepted);
+ $this->assertEquals('Error', $request->resultcode);
+ }
+
+ public function test_GetAddresses_checkAndSetConfiguredPaymentMethod_Accepted()
+ {
+ $request =$this->addressRequest
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4605092222")
+ ->getIndividualAddresses()
+ ->doRequest();
+ $this->assertEquals(1,$request->accepted);
+ }
}
diff --git a/test/IntegrationTest/WebService/GetPaymentPlanParams/GetPaymentPlanParamsIntegrationTest.php b/test/IntegrationTest/WebService/GetPaymentPlanParams/GetPaymentPlanParamsIntegrationTest.php
index 4f037c2e..170a810a 100644
--- a/test/IntegrationTest/WebService/GetPaymentPlanParams/GetPaymentPlanParamsIntegrationTest.php
+++ b/test/IntegrationTest/WebService/GetPaymentPlanParams/GetPaymentPlanParamsIntegrationTest.php
@@ -11,61 +11,61 @@
class GetPaymentPlanParamsIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public function testPaymentPlanParamsResult()
- {
- $config = ConfigurationService::getDefaultConfig();
- $paymentPlanRequest = new GetPaymentPlanParams($config);
- $request = $paymentPlanRequest
- ->setCountryCode("SE")
- ->doRequest();
+ public function testPaymentPlanParamsResult()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $paymentPlanRequest = new GetPaymentPlanParams($config);
+ $request = $paymentPlanRequest
+ ->setCountryCode("SE")
+ ->doRequest();
- $this->assertEquals(1, $request->accepted);
- }
+ $this->assertEquals(1, $request->accepted);
+ }
- public function testResultGetPaymentPlanParams()
- {
- $config = ConfigurationService::getDefaultConfig();
- $paymentPlanRequest = new GetPaymentPlanParams($config);
- $request = $paymentPlanRequest
- ->setCountryCode("SE")
- ->doRequest();
+ public function testResultGetPaymentPlanParams()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $paymentPlanRequest = new GetPaymentPlanParams($config);
+ $request = $paymentPlanRequest
+ ->setCountryCode("SE")
+ ->doRequest();
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(0, $request->resultcode);
- $this->assertEquals(213060, $request->campaignCodes[0]->campaignCode);
- $this->assertEquals('Dela upp betalningen på 60 månader', $request->campaignCodes[0]->description);
- $this->assertEquals('Standard', $request->campaignCodes[0]->paymentPlanType);
- $this->assertEquals(60, $request->campaignCodes[0]->contractLengthInMonths);
- $this->assertEquals(0.02555, $request->campaignCodes[0]->monthlyAnnuityFactor);
- $this->assertEquals(100, $request->campaignCodes[0]->initialFee);
- $this->assertEquals(29, $request->campaignCodes[0]->notificationFee);
- $this->assertEquals(16.75, $request->campaignCodes[0]->interestRatePercent);
- $this->assertEquals(3, $request->campaignCodes[0]->numberOfInterestFreeMonths);
- $this->assertEquals(3, $request->campaignCodes[0]->numberOfPaymentFreeMonths);
- $this->assertEquals(1000, $request->campaignCodes[0]->fromAmount);
- $this->assertEquals(50000, $request->campaignCodes[0]->toAmount);
- }
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(0, $request->resultcode);
+ $this->assertEquals(213060, $request->campaignCodes[0]->campaignCode);
+ $this->assertEquals('Dela upp betalningen på 60 månader', $request->campaignCodes[0]->description);
+ $this->assertEquals('Standard', $request->campaignCodes[0]->paymentPlanType);
+ $this->assertEquals(60, $request->campaignCodes[0]->contractLengthInMonths);
+ $this->assertEquals(0.02555, $request->campaignCodes[0]->monthlyAnnuityFactor);
+ $this->assertEquals(100, $request->campaignCodes[0]->initialFee);
+ $this->assertEquals(29, $request->campaignCodes[0]->notificationFee);
+ $this->assertEquals(16.75, $request->campaignCodes[0]->interestRatePercent);
+ $this->assertEquals(3, $request->campaignCodes[0]->numberOfInterestFreeMonths);
+ $this->assertEquals(3, $request->campaignCodes[0]->numberOfPaymentFreeMonths);
+ $this->assertEquals(1000, $request->campaignCodes[0]->fromAmount);
+ $this->assertEquals(50000, $request->campaignCodes[0]->toAmount);
+ }
- //outcommented cause need to use client with only one campaign to test
-// public function testResultGetPaymentPlanParams_only_one_campaign() {
+ //outcommented cause need to use client with only one campaign to test
+// public function testResultGetPaymentPlanParams_only_one_campaign() {
//
-// $paymentPlanRequest = new GetPaymentPlanParams(Svea\WebPay\Config\ConfigurationService::getTestConfig());
-// $request = $paymentPlanRequest
-// ->setCountryCode("SE")
-// ->doRequest();
-// print_r($request);
-// $this->assertEquals(1, $request->accepted);
-// $this->assertEquals(0, $request->resultcode);
-// $this->assertEquals(213060, $request->campaignCodes[0]->campaignCode);
-// $this->assertEquals('Köp nu betala om 3 månader (räntefritt)', $request->campaignCodes[0]->description);
-// $this->assertEquals('InterestAndAmortizationFree', $request->campaignCodes[0]->paymentPlanType);
-// $this->assertEquals(3, $request->campaignCodes[0]->contractLengthInMonths);
-// $this->assertEquals(100, $request->campaignCodes[0]->initialFee);
-// $this->assertEquals(29, $request->campaignCodes[0]->notificationFee);
-// $this->assertEquals(0, $request->campaignCodes[0]->interestRatePercent);
-// $this->assertEquals(3, $request->campaignCodes[0]->numberOfInterestFreeMonths);
-// $this->assertEquals(3, $request->campaignCodes[0]->numberOfPaymentFreeMonths);
-// $this->assertEquals(1000, $request->campaignCodes[0]->fromAmount);
-// $this->assertEquals(50000, $request->campaignCodes[0]->toAmount);
-// }
+// $paymentPlanRequest = new GetPaymentPlanParams(Svea\WebPay\Config\ConfigurationService::getTestConfig());
+// $request = $paymentPlanRequest
+// ->setCountryCode("SE")
+// ->doRequest();
+// print_r($request);
+// $this->assertEquals(1, $request->accepted);
+// $this->assertEquals(0, $request->resultcode);
+// $this->assertEquals(213060, $request->campaignCodes[0]->campaignCode);
+// $this->assertEquals('Köp nu betala om 3 månader (räntefritt)', $request->campaignCodes[0]->description);
+// $this->assertEquals('InterestAndAmortizationFree', $request->campaignCodes[0]->paymentPlanType);
+// $this->assertEquals(3, $request->campaignCodes[0]->contractLengthInMonths);
+// $this->assertEquals(100, $request->campaignCodes[0]->initialFee);
+// $this->assertEquals(29, $request->campaignCodes[0]->notificationFee);
+// $this->assertEquals(0, $request->campaignCodes[0]->interestRatePercent);
+// $this->assertEquals(3, $request->campaignCodes[0]->numberOfInterestFreeMonths);
+// $this->assertEquals(3, $request->campaignCodes[0]->numberOfPaymentFreeMonths);
+// $this->assertEquals(1000, $request->campaignCodes[0]->fromAmount);
+// $this->assertEquals(50000, $request->campaignCodes[0]->toAmount);
+// }
}
diff --git a/test/IntegrationTest/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonthIntegrationTest.php b/test/IntegrationTest/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonthIntegrationTest.php
index e46bc15d..6fc8017c 100644
--- a/test/IntegrationTest/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonthIntegrationTest.php
+++ b/test/IntegrationTest/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonthIntegrationTest.php
@@ -13,43 +13,43 @@
class PaymentPlanPricePerMonthTest extends \PHPUnit\Framework\TestCase
{
- private function getGetPaymentPlanParamsResponseForTesting()
- {
- $config = ConfigurationService::getDefaultConfig();
- $addressRequest = new GetPaymentPlanParams($config);
- $response = $addressRequest
- ->setCountryCode("SE")
- ->doRequest();
-
- return $response;
- }
-
- public function testBuildPriceCalculator()
- {
- $params = $this->getGetPaymentPlanParamsResponseForTesting();
- $response = new PaymentPlanPricePerMonth(2000, $params);
-// $this->assertEquals(213060, $response->values[0]['campaignCode']);//don't test to be flexible
- $this->assertEquals(83, $response->values[0]['pricePerMonth']);
- }
-
- function testBuildPriceCalculatorWithLowPrice_should_not_return_anything_if_price_is_less_than_all_campaign_min_prices()
- {
- $params = $this->getGetPaymentPlanParamsResponseForTesting();
- $response = new PaymentPlanPricePerMonth(99, $params);
- $this->assertEmpty($response->values);
- }
-
- function testBuildPriceCalculatorWithLowPrice_should_return_prices_if_IgnoreCampaignMinAndMax_flag_is_set()
- {
- $params = $this->getGetPaymentPlanParamsResponseForTesting();
- $response = new PaymentPlanPricePerMonth(200, $params, true);
- $this->assertNotEmpty($response->values);
- }
-
- function testPaymentPlanPricePerMonth_returns_paymentPlanType()
- {
- $params = $this->getGetPaymentPlanParamsResponseForTesting();
- $response = new PaymentPlanPricePerMonth(200, $params, true);
- $this->assertArrayHasKey("paymentPlanType", $response->values[0]);
- }
+ private function getGetPaymentPlanParamsResponseForTesting()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $addressRequest = new GetPaymentPlanParams($config);
+ $response = $addressRequest
+ ->setCountryCode("SE")
+ ->doRequest();
+
+ return $response;
+ }
+
+ public function testBuildPriceCalculator()
+ {
+ $params = $this->getGetPaymentPlanParamsResponseForTesting();
+ $response = new PaymentPlanPricePerMonth(2000, $params);
+// $this->assertEquals(213060, $response->values[0]['campaignCode']);//don't test to be flexible
+ $this->assertEquals(83, $response->values[0]['pricePerMonth']);
+ }
+
+ function testBuildPriceCalculatorWithLowPrice_should_not_return_anything_if_price_is_less_than_all_campaign_min_prices()
+ {
+ $params = $this->getGetPaymentPlanParamsResponseForTesting();
+ $response = new PaymentPlanPricePerMonth(99, $params);
+ $this->assertEmpty($response->values);
+ }
+
+ function testBuildPriceCalculatorWithLowPrice_should_return_prices_if_IgnoreCampaignMinAndMax_flag_is_set()
+ {
+ $params = $this->getGetPaymentPlanParamsResponseForTesting();
+ $response = new PaymentPlanPricePerMonth(200, $params, true);
+ $this->assertNotEmpty($response->values);
+ }
+
+ function testPaymentPlanPricePerMonth_returns_paymentPlanType()
+ {
+ $params = $this->getGetPaymentPlanParamsResponseForTesting();
+ $response = new PaymentPlanPricePerMonth(200, $params, true);
+ $this->assertArrayHasKey("paymentPlanType", $response->values[0]);
+ }
}
diff --git a/test/IntegrationTest/WebService/HandleOrder/CloseOrderIntegrationTest.php b/test/IntegrationTest/WebService/HandleOrder/CloseOrderIntegrationTest.php
index 61d292c9..2a3de778 100644
--- a/test/IntegrationTest/WebService/HandleOrder/CloseOrderIntegrationTest.php
+++ b/test/IntegrationTest/WebService/HandleOrder/CloseOrderIntegrationTest.php
@@ -13,54 +13,54 @@
class CloseOrderIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * Function to use in testfunctions
- * @return integer SveaOrderId
- */
- private function getInvoiceOrderId()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- //->setPasswordBasedAuthorization("sverigetest", "sverigetest", 79021)
- ->doRequest();
+ /**
+ * Function to use in testfunctions
+ * @return integer SveaOrderId
+ */
+ private function getInvoiceOrderId()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ //->setPasswordBasedAuthorization("sverigetest", "sverigetest", 79021)
+ ->doRequest();
- return $request->sveaOrderId;
- }
+ return $request->sveaOrderId;
+ }
- public function testCloseInvoiceOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderId = $this->getInvoiceOrderId();
- $orderBuilder = WebPay::closeOrder($config);
- $request = $orderBuilder
- ->setOrderId($orderId)
- ->setCountryCode("SE")
- ->closeInvoiceOrder()
- ->doRequest();
+ public function testCloseInvoiceOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderId = $this->getInvoiceOrderId();
+ $orderBuilder = WebPay::closeOrder($config);
+ $request = $orderBuilder
+ ->setOrderId($orderId)
+ ->setCountryCode("SE")
+ ->closeInvoiceOrder()
+ ->doRequest();
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(0, $request->resultcode);
- }
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(0, $request->resultcode);
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public function testCloseInvoiceOrder_missing_setOrderId_throws_ValidationException()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderId = $this->getInvoiceOrderId();
- $orderBuilder = WebPay::closeOrder($config);
- $request = $orderBuilder
-// ->setOrderId($orderId)
- ->setCountryCode("SE")
- ->closeInvoiceOrder()
- ->doRequest();
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public function testCloseInvoiceOrder_missing_setOrderId_throws_ValidationException()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderId = $this->getInvoiceOrderId();
+ $orderBuilder = WebPay::closeOrder($config);
+ $request = $orderBuilder
+// ->setOrderId($orderId)
+ ->setCountryCode("SE")
+ ->closeInvoiceOrder()
+ ->doRequest();
+ }
}
diff --git a/test/IntegrationTest/WebService/HandleOrder/DeliverInvoiceIntegrationTest.php b/test/IntegrationTest/WebService/HandleOrder/DeliverInvoiceIntegrationTest.php
index 925a366d..820cf17d 100644
--- a/test/IntegrationTest/WebService/HandleOrder/DeliverInvoiceIntegrationTest.php
+++ b/test/IntegrationTest/WebService/HandleOrder/DeliverInvoiceIntegrationTest.php
@@ -19,444 +19,444 @@
class DeliverInvoiceIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * Function to use in testfunctions
- * @return SveaOrderId
- */
- private function getInvoiceOrderId()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->doRequest();
+ /**
+ * Function to use in testfunctions
+ * @return SveaOrderId
+ */
+ private function getInvoiceOrderId()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->doRequest();
- return $request->sveaOrderId;
- }
+ return $request->sveaOrderId;
+ }
- public function testDeliverInvoiceOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderId = $this->getInvoiceOrderId();
- $orderBuilder = WebPay::deliverOrder($config);
- $request = $orderBuilder
- ->addOrderRow(TestUtil::createOrderRow())
- ->setOrderId($orderId)
- ->setNumberOfCreditDays(1)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType('Post')//Post or Email
- ->deliverInvoiceOrder()
- ->doRequest();
+ public function testDeliverInvoiceOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderId = $this->getInvoiceOrderId();
+ $orderBuilder = WebPay::deliverOrder($config);
+ $request = $orderBuilder
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setOrderId($orderId)
+ ->setNumberOfCreditDays(1)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType('Post')//Post or Email
+ ->deliverInvoiceOrder()
+ ->doRequest();
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(0, $request->resultcode);
- $this->assertEquals(250, $request->amount);
- $this->assertEquals('Invoice', $request->orderType);
- //Invoice specifics
- //$this->assertEquals(0000, $request->invoiceId); //differs in every test
- //$this->assertEquals(date(), $request->dueDate); //differs in every test
- //$this->assertEquals(date(), $request->invoiceDate); //differs in every test
- $this->assertEquals('Post', $request->invoiceDistributionType);
- //$this->assertEquals('Invoice', $request->contractNumber); //for paymentplan
- }
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(0, $request->resultcode);
+ $this->assertEquals(250, $request->amount);
+ $this->assertEquals('Invoice', $request->orderType);
+ //Invoice specifics
+ //$this->assertEquals(0000, $request->invoiceId); //differs in every test
+ //$this->assertEquals(date(), $request->dueDate); //differs in every test
+ //$this->assertEquals(date(), $request->invoiceDate); //differs in every test
+ $this->assertEquals('Post', $request->invoiceDistributionType);
+ //$this->assertEquals('Invoice', $request->contractNumber); //for paymentplan
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public function testDeliverInvoiceOrder_missing_setOrderId_throws_ValidationException()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderId = $this->getInvoiceOrderId();
- $orderBuilder = WebPay::deliverOrder($config);
- $request = $orderBuilder
- ->addOrderRow(TestUtil::createOrderRow())
- //->setOrderId($orderId)
- ->setNumberOfCreditDays(1)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType('Post')//Post or Email
- ->deliverInvoiceOrder()
- ->doRequest();
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public function testDeliverInvoiceOrder_missing_setOrderId_throws_ValidationException()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderId = $this->getInvoiceOrderId();
+ $orderBuilder = WebPay::deliverOrder($config);
+ $request = $orderBuilder
+ ->addOrderRow(TestUtil::createOrderRow())
+ //->setOrderId($orderId)
+ ->setNumberOfCreditDays(1)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType('Post')//Post or Email
+ ->deliverInvoiceOrder()
+ ->doRequest();
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- *
- * bypasses Svea\WebPay\WebPay::deliverOrders, as 2.0 allows deliverOrder w/o orderRows
- */
- public function test_DeliverInvoice_missing_addOrderRow_throws_ValidationException()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderId = $this->getInvoiceOrderId();
- $orderBuilder = new DeliverOrderBuilder($config);
- $orderBuilder = $orderBuilder
- //->addOrderRow(Svea\WebPay\Test\TestUtil::createOrderRow())
- ->setOrderId($orderId)
- ->setNumberOfCreditDays(1)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType('Post')//Post or Email
- ;
- $deliverInvoiceObject = new DeliverInvoice($orderBuilder);
- $response = $deliverInvoiceObject->doRequest();
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ *
+ * bypasses Svea\WebPay\WebPay::deliverOrders, as 2.0 allows deliverOrder w/o orderRows
+ */
+ public function test_DeliverInvoice_missing_addOrderRow_throws_ValidationException()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderId = $this->getInvoiceOrderId();
+ $orderBuilder = new DeliverOrderBuilder($config);
+ $orderBuilder = $orderBuilder
+ //->addOrderRow(Svea\WebPay\Test\TestUtil::createOrderRow())
+ ->setOrderId($orderId)
+ ->setNumberOfCreditDays(1)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType('Post')//Post or Email
+ ;
+ $deliverInvoiceObject = new DeliverInvoice($orderBuilder);
+ $response = $deliverInvoiceObject->doRequest();
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public function testDeliverInvoiceOrder_missing_setInvoiceDistributionType_throws_ValidationException()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderId = $this->getInvoiceOrderId();
- $orderBuilder = WebPay::deliverOrder($config);
- $request = $orderBuilder
- ->addOrderRow(TestUtil::createOrderRow())
- ->setOrderId($orderId)
- ->setNumberOfCreditDays(1)
- ->setCountryCode("SE")
- //->setInvoiceDistributionType('Post')//Post or Email
- ->deliverInvoiceOrder()
- ->doRequest();
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public function testDeliverInvoiceOrder_missing_setInvoiceDistributionType_throws_ValidationException()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderId = $this->getInvoiceOrderId();
+ $orderBuilder = WebPay::deliverOrder($config);
+ $request = $orderBuilder
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setOrderId($orderId)
+ ->setNumberOfCreditDays(1)
+ ->setCountryCode("SE")
+ //->setInvoiceDistributionType('Post')//Post or Email
+ ->deliverInvoiceOrder()
+ ->doRequest();
+ }
- /**
- * rounding**
- */
+ /**
+ * rounding**
+ */
- public function testDeliverOrderWithAmountExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(8)
- ->setVatPercent(24)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(8)
- ->setVatPercent(24)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->doRequest();
+ public function testDeliverOrderWithAmountExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(8)
+ ->setVatPercent(24)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(8)
+ ->setVatPercent(24)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->doRequest();
- $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(1, $request->accepted);
- }
+ }
- public function testDeliverOrderWithAmountIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(80.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(80.00)
- ->setVatPercent(24)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(8)
- ->setVatPercent(24)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(80.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(80.00)
- ->setVatPercent(24)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(8)
- ->setVatPercent(24)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->doRequest();
+ public function testDeliverOrderWithAmountIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(8)
+ ->setVatPercent(24)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(8)
+ ->setVatPercent(24)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->doRequest();
- $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(1, $request->accepted);
- }
+ }
- public function testCreateOrderWithAmountIncAndDeliverWithAmountExvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
+ public function testCreateOrderWithAmountIncAndDeliverWithAmountExvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
- }
+ }
- public function testCreateOrderWithAmountExAndDeliverWithAmountIncvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->doRequest();
-// print_r($request);
- $this->assertEquals(1, $request->accepted);
+ public function testCreateOrderWithAmountExAndDeliverWithAmountIncvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->doRequest();
+// print_r($request);
+ $this->assertEquals(1, $request->accepted);
- }
+ }
- public function testCreateOrderWithFeesAsAmountIncAndDeliverWithAmountExvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
+ public function testCreateOrderWithFeesAsAmountIncAndDeliverWithAmountExvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
- }
+ }
- public function testCreateOrderWithFeesAsAmountExAndDeliverWithAmountIncvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
+ public function testCreateOrderWithFeesAsAmountExAndDeliverWithAmountIncvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
- }
+ }
- public function testCreateOrderWithDiscountAsAmountExAndDeliverWithAmountIncvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->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")
- ->useInvoicePayment()
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(8)
- ->setVatPercent(24)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
+ public function testCreateOrderWithDiscountAsAmountExAndDeliverWithAmountIncvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->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")
+ ->useInvoicePayment()
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(8)
+ ->setVatPercent(24)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
- }
+ }
}
diff --git a/test/IntegrationTest/WebService/HandleOrder/DeliverPaymentPlanIntegrationTest.php b/test/IntegrationTest/WebService/HandleOrder/DeliverPaymentPlanIntegrationTest.php
index 5251b1de..efa8bab2 100644
--- a/test/IntegrationTest/WebService/HandleOrder/DeliverPaymentPlanIntegrationTest.php
+++ b/test/IntegrationTest/WebService/HandleOrder/DeliverPaymentPlanIntegrationTest.php
@@ -16,274 +16,274 @@
class DeliverPaymentPlanIntegrationTest extends \PHPUnit\Framework\TestCase
{
- /**
- * Function to use in testfunctions
- * @return SveaOrderId
- */
- private function getPaymentPlanOrderId()
- {
- $config = ConfigurationService::getDefaultConfig();
- $response = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow(1000.00, 1))
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())
- ->doRequest();
+ /**
+ * Function to use in testfunctions
+ * @return SveaOrderId
+ */
+ private function getPaymentPlanOrderId()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $response = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow(1000.00, 1))
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePaymentPlanPayment(TestUtil::getGetPaymentPlanParamsForTesting())
+ ->doRequest();
- return $response->sveaOrderId;
- }
+ return $response->sveaOrderId;
+ }
- public function testDeliverPaymentPlanOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderId = $this->getPaymentPlanOrderId();
- $orderBuilder = WebPay::deliverOrder($config);
- $request = $orderBuilder
- ->addOrderRow(TestUtil::createOrderRow(1000.00, 1))
- ->setOrderId($orderId)
- ->setCountryCode("SE")
- ->deliverPaymentPlanOrder()
- ->doRequest();
+ public function testDeliverPaymentPlanOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderId = $this->getPaymentPlanOrderId();
+ $orderBuilder = WebPay::deliverOrder($config);
+ $request = $orderBuilder
+ ->addOrderRow(TestUtil::createOrderRow(1000.00, 1))
+ ->setOrderId($orderId)
+ ->setCountryCode("SE")
+ ->deliverPaymentPlanOrder()
+ ->doRequest();
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(0, $request->resultcode);
- $this->assertEquals(1250, $request->amount);
- $this->assertEquals('PaymentPlan', $request->orderType);
- }
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(0, $request->resultcode);
+ $this->assertEquals(1250, $request->amount);
+ $this->assertEquals('PaymentPlan', $request->orderType);
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public function testDeliverPaymentPlanOrder_missing_setOrderId_throws_ValidationException()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderId = $this->getPaymentPlanOrderId();
- $orderBuilder = WebPay::deliverOrder($config);
- $request = $orderBuilder
- //->setOrderId($orderId)
- ->setCountryCode("SE")
- ->deliverPaymentPlanOrder()
- ->doRequest();
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public function testDeliverPaymentPlanOrder_missing_setOrderId_throws_ValidationException()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderId = $this->getPaymentPlanOrderId();
+ $orderBuilder = WebPay::deliverOrder($config);
+ $request = $orderBuilder
+ //->setOrderId($orderId)
+ ->setCountryCode("SE")
+ ->deliverPaymentPlanOrder()
+ ->doRequest();
+ }
- /**
- * rounding
- */
+ /**
+ * rounding
+ */
- public function testCreateOrderWithAmountIncAndDeliverWithAmountExvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1239.876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment($campaigncode)
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(999.90)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverPaymentPlanOrder()
- ->doRequest();
-// print_r($request);
- $this->assertEquals(1, $request->accepted);
+ public function testCreateOrderWithAmountIncAndDeliverWithAmountExvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1239.876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment($campaigncode)
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(999.90)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverPaymentPlanOrder()
+ ->doRequest();
+// print_r($request);
+ $this->assertEquals(1, $request->accepted);
- }
+ }
- public function testCreateOrderWithAmountExAndDeliverWithAmountIncvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(9999.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment($campaigncode)
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(12398.76)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverPaymentPlanOrder()
- ->doRequest();
-// print_r($request);
- $this->assertEquals(1, $request->accepted);
+ public function testCreateOrderWithAmountExAndDeliverWithAmountIncvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(9999.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment($campaigncode)
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(12398.76)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverPaymentPlanOrder()
+ ->doRequest();
+// print_r($request);
+ $this->assertEquals(1, $request->accepted);
- }
+ }
- public function testCreateOrderWithFeesAsAmountIncAndDeliverWithAmountExvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1239.876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment($campaigncode)
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(999.9)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverPaymentPlanOrder()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
+ public function testCreateOrderWithFeesAsAmountIncAndDeliverWithAmountExvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1239.876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment($campaigncode)
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(999.9)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverPaymentPlanOrder()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
- }
+ }
- public function testCreateOrderWithFeesAsAmountExAndDeliverWithAmountIncvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1239.876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment($campaigncode)
- ->doRequest();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(999.90)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverPaymentPlanOrder()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
+ public function testCreateOrderWithFeesAsAmountExAndDeliverWithAmountIncvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1239.876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment($campaigncode)
+ ->doRequest();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(999.90)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverPaymentPlanOrder()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
- }
+ }
- public function testCreateOrderWithDiscountAsAmountExAndDeliverWithAmountIncvat()
- {
- $config = ConfigurationService::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.90)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(8)
- ->setVatPercent(24)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->setOrderId($order->sveaOrderId)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCountryCode("SE")
- ->deliverPaymentPlanOrder()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
+ public function testCreateOrderWithDiscountAsAmountExAndDeliverWithAmountIncvat()
+ {
+ $config = ConfigurationService::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.90)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(8)
+ ->setVatPercent(24)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->setOrderId($order->sveaOrderId)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCountryCode("SE")
+ ->deliverPaymentPlanOrder()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
- }
+ }
}
diff --git a/test/IntegrationTest/WebService/Payment/AccountCreditPaymentIntegrationTest.php b/test/IntegrationTest/WebService/Payment/AccountCreditPaymentIntegrationTest.php
index dc3826f6..0931cdcb 100644
--- a/test/IntegrationTest/WebService/Payment/AccountCreditPaymentIntegrationTest.php
+++ b/test/IntegrationTest/WebService/Payment/AccountCreditPaymentIntegrationTest.php
@@ -13,214 +13,214 @@
class AccountCreditPaymentIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public function getCustomerRow()
- {
- return WebPayItem::individualCustomer()
- ->setNationalIdNumber("194605092222")
- ->setBirthDate(1946, 05, 9)
- ->setName("Tess T", "Persson")
- ->setStreetAddress("Testgatan", 1)
- ->setCoAddress("c/o Eriksson, Erik")
- ->setLocality("Stan")
- ->setEmail('testt@svea.com')->
- setZipCode("99999");
- }
-
- // single order rows vat rate
- public function test_fixedDiscount_amount_with_exvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails($this->getCustomerRow())
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
-
- $response = $order->useAccountCredit('111111')->doRequest();
- $this->assertEquals(true, $response->accepted);
- }
-
- // fixed discount -- created discount rows should use incvat + vatpercent
- /// fixed discount examples:
- // single order rows vat rate
- public function test_fixedDiscount_amount_with_incvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails($this->getCustomerRow())
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("incvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("incvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- ->setName("incvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
-
- // check that service accepts order
- $response = $order->useAccountCredit('111111')->doRequest();
- $this->assertEquals(true, $response->accepted);
- }
-
- public function testOrderAndFixedDiscountSetWithMixedVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- ->setDescription("Test")
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDescription("TestDiscount")
- ->setAmountExVat(9.999)
- )
- ->addCustomerDetails($this->getCustomerRow())
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
-
- $request = $order->useAccountCredit('111111')->prepareRequest();
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- // 9.999 *1.24 = 12.39876
- $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- // check that service accepts order
- $response = $order->useAccountCredit('111111')->doRequest();
- $this->assertEquals(true, $response->accepted);
- }
-
- public function testOrderAndFixedDiscountSetWithMixedVat3()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- ->setDescription("Test")
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(9.999)
- ->setDescription("TestDiscount")
- )
- ->addCustomerDetails($this->getCustomerRow())
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
- $request = $order->useAccountCredit('111111')->prepareRequest();
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- // 9.999 *1.24 = 12.39876
- $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- // check that service accepts order
- $response = $order->useAccountCredit('111111')->doRequest();
- $this->assertEquals(true, $response->accepted);
- }
+ public function getCustomerRow()
+ {
+ return WebPayItem::individualCustomer()
+ ->setNationalIdNumber("194605092222")
+ ->setBirthDate(1946, 05, 9)
+ ->setName("Tess T", "Persson")
+ ->setStreetAddress("Testgatan", 1)
+ ->setCoAddress("c/o Eriksson, Erik")
+ ->setLocality("Stan")
+ ->setEmail('testt@svea.com')->
+ setZipCode("99999");
+ }
+
+ // single order rows vat rate
+ public function test_fixedDiscount_amount_with_exvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails($this->getCustomerRow())
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+
+ $response = $order->useAccountCredit('111111')->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ }
+
+ // fixed discount -- created discount rows should use incvat + vatpercent
+ /// fixed discount examples:
+ // single order rows vat rate
+ public function test_fixedDiscount_amount_with_incvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails($this->getCustomerRow())
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("incvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("incvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ ->setName("incvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+
+ // check that service accepts order
+ $response = $order->useAccountCredit('111111')->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ }
+
+ public function testOrderAndFixedDiscountSetWithMixedVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ ->setDescription("Test")
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDescription("TestDiscount")
+ ->setAmountExVat(9.999)
+ )
+ ->addCustomerDetails($this->getCustomerRow())
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
+
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ // 9.999 *1.24 = 12.39876
+ $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ // check that service accepts order
+ $response = $order->useAccountCredit('111111')->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ }
+
+ public function testOrderAndFixedDiscountSetWithMixedVat3()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ ->setDescription("Test")
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(9.999)
+ ->setDescription("TestDiscount")
+ )
+ ->addCustomerDetails($this->getCustomerRow())
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ // 9.999 *1.24 = 12.39876
+ $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ // check that service accepts order
+ $response = $order->useAccountCredit('111111')->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ }
}
\ No newline at end of file
diff --git a/test/IntegrationTest/WebService/Payment/FixedDiscountRowsIntegrationTest.php b/test/IntegrationTest/WebService/Payment/FixedDiscountRowsIntegrationTest.php
index 7e85e94a..15c60b45 100644
--- a/test/IntegrationTest/WebService/Payment/FixedDiscountRowsIntegrationTest.php
+++ b/test/IntegrationTest/WebService/Payment/FixedDiscountRowsIntegrationTest.php
@@ -14,500 +14,500 @@
class FixedDiscountRowsIntegrationTest extends \PHPUnit\Framework\TestCase
{
- // This file contains the same tests as UnitTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest
- // but also sends the create order request to the service and checks response for success and order amount.
+ // This file contains the same tests as UnitTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest
+ // but also sends the create order request to the service and checks response for success and order amount.
- /**
- * Tests that orders created with a mix of order and fee rows specified as exvat/incvat and vatpercent
- * are sent to the webservice using the correct PriceIncludingVat flag.
- *
- * Also tests that fixed discount rows specified as amount inc/exvat only are split correctly across
- * all the order vat rates, and that the split discount rows are sent to the service using the correct
- * PriceIncludingVat flag.
- */
- private static function create_mixed_exvat_and_incvat_order_and_fee_rows_order()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("incvatRow")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- );
+ /**
+ * Tests that orders created with a mix of order and fee rows specified as exvat/incvat and vatpercent
+ * are sent to the webservice using the correct PriceIncludingVat flag.
+ *
+ * Also tests that fixed discount rows specified as amount inc/exvat only are split correctly across
+ * all the order vat rates, and that the split discount rows are sent to the service using the correct
+ * PriceIncludingVat flag.
+ */
+ private static function create_mixed_exvat_and_incvat_order_and_fee_rows_order()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("incvatRow")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ );
- return $order;
- }
+ return $order;
+ }
- // order with order/fee rows mixed exvat+vat / incvat+vat should be sent with PriceIncludingVat = false
- public function test_mixed_order_row_and_shipping_fees_only_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsIntegrationTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
+ // order with order/fee rows mixed exvat+vat / incvat+vat should be sent with PriceIncludingVat = false
+ public function test_mixed_order_row_and_shipping_fees_only_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsIntegrationTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // check that service accepts order
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(true, $response->accepted);
- $this->assertEquals("131.4", $response->amount);
- }
+ // check that service accepts order
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ $this->assertEquals("131.4", $response->amount);
+ }
- // same order with discount exvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts ex vat
- public function test_mixed_order_with_fixedDiscount_as_exvat_only_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsIntegrationTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- //->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10e")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // same order with discount exvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts ex vat
+ public function test_mixed_order_with_fixedDiscount_as_exvat_only_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsIntegrationTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ //->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10e")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.67e @20% + 3.33e @10%
- $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP); //=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.67e @20% + 3.33e @10%
+ $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP); //=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // 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(60*1.20*1) + r(30*1.10*1) + r(16*1.10*1) + r(8*1.10*1) + r(-6.67*1.20*1) + r(-3.33*1.10*1) => 72.00+33.00+17.60+8.80-8.00-3.66 => 119.74
- $this->assertEquals("119.74", $response->amount);
- }
+ // 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(60*1.20*1) + r(30*1.10*1) + r(16*1.10*1) + r(8*1.10*1) + r(-6.67*1.20*1) + r(-3.33*1.10*1) => 72.00+33.00+17.60+8.80-8.00-3.66 => 119.74
+ $this->assertEquals("119.74", $response->amount);
+ }
- // same order with discount incvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts inc vat
- public function test_mixed_order_with_fixedDiscount_as_incvat_only_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsIntegrationTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(10.0)
- //->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10i")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 incvat => split across 10i *(72/72+33) @20% + 10i *(33/72+33) @10% => 6.8571i @20% + 3.1428i @10% =>5.71 + 2.86
- $this->assertEquals(-5.71, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-2.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ // same order with discount incvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts inc vat
+ public function test_mixed_order_with_fixedDiscount_as_incvat_only_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsIntegrationTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10.0)
+ //->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10i")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 incvat => split across 10i *(72/72+33) @20% + 10i *(33/72+33) @10% => 6.8571i @20% + 3.1428i @10% =>5.71 + 2.86
+ $this->assertEquals(-5.71, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-2.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // 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(60*1.20*1) + r(30*1.10*1) + r(16*1.10*1) + r(8*1.10*1) + r(-5.72*1.20*1) + r(-2.85*1.10*1) => 72.00+33.00+17.60+8.80-6.85-3.15 => 121.40
- $this->assertEquals("121.40", $response->amount);
- }
+ // 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(60*1.20*1) + r(30*1.10*1) + r(16*1.10*1) + r(8*1.10*1) + r(-5.72*1.20*1) + r(-2.85*1.10*1) => 72.00+33.00+17.60+8.80-6.85-3.15 => 121.40
+ $this->assertEquals("121.40", $response->amount);
+ }
- // same order with discount exvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given exvat + vat
- public function test_mixed_order_with_fixedDiscount_as_exvat_and_vatpercent_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsIntegrationTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10e@10%")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 11 incvat @10% => -10e @10%
- $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
+ // same order with discount exvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given exvat + vat
+ public function test_mixed_order_with_fixedDiscount_as_exvat_and_vatpercent_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsIntegrationTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10e@10%")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 11 incvat @10% => -10e @10%
+ $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $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(60*1.20*1) + r(30*1.10*1) + r(16*1.10*1) + r(8*1.10*1) + r(-10*1.10*1) = 72+33+17.60 + 8.80 -11.00 = 120.40
- $this->assertEquals("120.4", $response->amount);
- }
+ // 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(60*1.20*1) + r(30*1.10*1) + r(16*1.10*1) + r(8*1.10*1) + r(-10*1.10*1) = 72+33+17.60 + 8.80 -11.00 = 120.40
+ $this->assertEquals("120.4", $response->amount);
+ }
- // same order with discount incvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given incvat + vat
- public function test_mixed_order_with_fixedDiscount_as_incvat_and_vatpercent_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsIntegrationTest::create_mixed_exvat_and_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(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 11 incvat @10% => -10e @10%
- $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
+ // same order with discount incvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given incvat + vat
+ public function test_mixed_order_with_fixedDiscount_as_incvat_and_vatpercent_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsIntegrationTest::create_mixed_exvat_and_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(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 11 incvat @10% => -10e @10%
+ $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $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(60*1.20*1) + r(30*1.10*1) + r(16*1.10*1) + r(8*1.10*1) + r(-10*1.10*1) = 72+33+17.60 + 8.80 -11.00 = 120.40
- $this->assertEquals("120.4", $response->amount);
- }
+ // 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(60*1.20*1) + r(30*1.10*1) + r(16*1.10*1) + r(8*1.10*1) + r(-10*1.10*1) = 72+33+17.60 + 8.80 -11.00 = 120.40
+ $this->assertEquals("120.4", $response->amount);
+ }
- private static function create_only_incvat_order_and_fee_rows_order()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("incvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("incvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- ->setName("incvatShippingFee")
- );
+ private static function create_only_incvat_order_and_fee_rows_order()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("incvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("incvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ ->setName("incvatShippingFee")
+ );
- return $order;
- }
+ return $order;
+ }
- // order with order/fee rows all having incvat should be sent with PriceIncludingVat = true
- public function test_incvat_order_row_and_shipping_fees_only_has_priceIncludingVat_true()
- {
- $order = FixedDiscountRowsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
+ // order with order/fee rows all having incvat should be sent with PriceIncludingVat = true
+ public function test_incvat_order_row_and_shipping_fees_only_has_priceIncludingVat_true()
+ {
+ $order = FixedDiscountRowsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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);
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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);
- // check that service accepts order
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(true, $response->accepted);
- $this->assertEquals("131.4", $response->amount);
- }
+ // check that service accepts order
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ $this->assertEquals("131.4", $response->amount);
+ }
- // same order with discount exvat should be sent with PriceIncludingVat = true but with split discount rows based on order amounts ex vat
- public function test_incvat_order_with_fixedDiscount_as_exvat_only_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- //->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10e")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
- $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ // same order with discount exvat should be sent with PriceIncludingVat = true but with split discount rows based on order amounts ex vat
+ public function test_incvat_order_with_fixedDiscount_as_exvat_only_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ //->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10e")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
+ $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // 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.00*1) + r(33.00*1) + r(17.60*1) + r(8.80*1) + r(-8.00*1) + r(-3.66*1) => 72.00+33.00+17.60+8.80-8.00-3.67 => 119.73
- //$this->assertEquals( "119.73", $response->amount ); // TODO check that this is the amount in S1 invoice, vs 119.74 w/PriceIncludingVat = false
- $this->assertEquals("119.74", $response->amount); // jfr vs 119.73 w/PriceIncludingVat = true
- }
+ // 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.00*1) + r(33.00*1) + r(17.60*1) + r(8.80*1) + r(-8.00*1) + r(-3.66*1) => 72.00+33.00+17.60+8.80-8.00-3.67 => 119.73
+ //$this->assertEquals( "119.73", $response->amount ); // TODO check that this is the amount in S1 invoice, vs 119.74 w/PriceIncludingVat = false
+ $this->assertEquals("119.74", $response->amount); // jfr vs 119.73 w/PriceIncludingVat = true
+ }
- // same order with discount incvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts inc vat
- public function test_incvat_order_with_fixedDiscount_as_incvat_only_has_priceIncludingVat_true()
- {
- $order = FixedDiscountRowsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(10.0)
- //->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10i")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10 incvat => split across 10i *(72/72+33) @20% + 10i *(33/72+33) @10% => 6.8571i @20% + 3.1428i @10% =>5.71 + 2.86
- $this->assertEquals(-6.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.14, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ // same order with discount incvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts inc vat
+ public function test_incvat_order_with_fixedDiscount_as_incvat_only_has_priceIncludingVat_true()
+ {
+ $order = FixedDiscountRowsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10.0)
+ //->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10i")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10 incvat => split across 10i *(72/72+33) @20% + 10i *(33/72+33) @10% => 6.8571i @20% + 3.1428i @10% =>5.71 + 2.86
+ $this->assertEquals(-6.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.14, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // 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-6.86-3.14 => 121.40
- $this->assertEquals("121.40", $response->amount);
- }
+ // 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-6.86-3.14 => 121.40
+ $this->assertEquals("121.40", $response->amount);
+ }
- // same order with discount exvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given exvat + vat
- public function test_incvat_order_with_fixedDiscount_as_exvat_and_vatpercent_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10e@10%")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10exvat @10% = -11.00
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
+ // same order with discount exvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given exvat + vat
+ public function test_incvat_order_with_fixedDiscount_as_exvat_and_vatpercent_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10e@10%")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10exvat @10% = -11.00
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $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.4", $response->amount);
- }
+ // 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.4", $response->amount);
+ }
- // same order with discount incvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given incvat + vat
- 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.00, $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.00, $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.80, $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.60, $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.00, $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]));
+ // same order with discount incvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given incvat + vat
+ 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.00, $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.00, $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.80, $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.60, $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.00, $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.4", $response->amount);
- }
+ // 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.4", $response->amount);
+ }
}
\ No newline at end of file
diff --git a/test/IntegrationTest/WebService/Payment/GetRequestTotalsIntegrationTest.php b/test/IntegrationTest/WebService/Payment/GetRequestTotalsIntegrationTest.php
index 58186af4..cbb0a96d 100644
--- a/test/IntegrationTest/WebService/Payment/GetRequestTotalsIntegrationTest.php
+++ b/test/IntegrationTest/WebService/Payment/GetRequestTotalsIntegrationTest.php
@@ -16,456 +16,456 @@
class GetRequestTotalsIntegrationTest extends \PHPUnit\Framework\TestCase
{
- function test_get_invoice_total_amount_before_createorder()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK");
- $order->addOrderRow(WebPayItem::orderRow()
- ->setName('Universal Camera Charger')
- ->setAmountIncVat(19.60)
- ->setVatPercent(25)
- ->setQuantity(100)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(29.00)
- ->setVatPercent(25)
- ->setName('Svea Invoice Fee')
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(294.00)
- ->setName('Discount')
- );
- $total = $order->useInvoicePayment()->getRequestTotals();
-
- $this->assertEquals(1695.0, $total['total_incvat']);
- $this->assertEquals(1356.0, $total['total_exvat']);
- $this->assertEquals(339.0, $total['total_vat']);
-
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals($total['total_incvat'], $response->amount);
- }
-
- function test_get_invoice_total_amount_before_createorder_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK");
- $order->addOrderRow(WebPayItem::orderRow()
- ->setName('Universal Camera Charger')
- ->setAmountIncVat(19.60)
- ->setVatPercent(25)
- ->setQuantity(100)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(29.00)
- ->setVatPercent(25)
- ->setName('Svea Invoice Fee')
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(294.00)
- ->setName('Discount')
- );
- $total = $order->useInvoicePayment()->getRequestTotals();
-
- $this->assertEquals(1695.0, $total['total_incvat']);
- $this->assertEquals(1356.0, $total['total_exvat']);
- $this->assertEquals(339.0, $total['total_vat']);
-
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals($total['total_incvat'], $response->amount);
- }
-
- /// example of order differing when sent incvat and exvat ----------------------------------------------------------------------
-
- private static function create_only_incvat_order_and_fee_rows_order()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("incvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("incvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- ->setName("incvatShippingFee")
- );
-
- return $order;
- }
-
- public function test_getOrderTotals_has_same_amounts_as_service_when_order_sent_priceIncludingVat_false()
- {
- $order = GetRequestTotalsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- //->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10e")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
- $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
-
- // 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.00*1) + r(33.00*1) + r(17.60*1) + r(8.80*1) + r(-8.00*1) + r(-3.66*1) => 72.00+33.00+17.60+8.80-8.00-3.67 => 119.73
- //$this->assertEquals( "119.73", $response->amount ); // TODO check that this is the amount in S1 invoice, vs 119.74 w/PriceIncludingVat = false
- $this->assertEquals("119.74", $response->amount); // jfr vs 119.73 w/PriceIncludingVat = true
-
- // verify that getRequestTotals() got the same amount as the service
- $preview = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals("119.74", $preview['total_incvat']);
- $this->assertEquals($preview['total_incvat'], $response->amount);
- }
-
- public function test_getOrderTotals_has_same_amounts_as_service_when_order_sent_priceIncludingVat_true()
- {
- $order = GetRequestTotalsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(8.00)
- ->setVatPercent(20)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 8.00i@20%")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(3.67)
- ->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 3.67ie@10%")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
- $this->assertEquals(-8.00, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
-
- // 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.00*1) + r(33.00*1) + r(17.60*1) + r(8.80*1) + r(-8.00*1) + r(-3.66*1) => 72.00+33.00+17.60+8.80-8.00-3.67 => 119.73
- //$this->assertEquals( "119.73", $response->amount ); // TODO check that this is the amount in S1 invoice, vs 119.74 w/PriceIncludingVat = false
- $this->assertEquals("119.73", $response->amount); // jfr vs 119.73 w/PriceIncludingVat = true
-
- // verify that getRequestTotals() got the same amount as the service
- $preview = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals("119.73", $preview['total_incvat']);
- $this->assertEquals($preview['total_incvat'], $response->amount);
- }
-
- /// example of getRequestTotals() not matching service --------------------------------------------------------------------------
- public function test_integrationtest_reference_1400_00_inc_behaviour()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1400.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2016-04-14");
- $response = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(1400, $response->amount);
-
- // verify that getRequestTotals() got the same amount as the service
- $preview = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals($preview['total_incvat'], $response->amount);
-
-
- }
-
- public function test_integrationtest_reference_1321_00_ex_behaviour()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(1321.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2016-04-14");
- $response = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals(1400.26, $response->amount);
-
- // verify that getRequestTotals() got the same amount as the service
- $preview = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals($preview['total_incvat'], $response->amount);
- }
-
- public function test_getRequestTotals_reference_1400_00_inc_behaviour()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1400.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2016-04-14");
-
- $preview_total = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals(1400.00, $preview_total['total_incvat']);
- $this->assertEquals(1320.75, $preview_total['total_exvat']);
- $this->assertEquals(79.25, $preview_total['total_vat']);
-
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals($preview_total['total_incvat'], $response->amount);
- }
-
- public function test_getRequestTotals_reference_1400_26_inc_behaviour()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1400.26)
- ->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.00, $preview_total['total_exvat']);
- $this->assertEquals(79.26, $preview_total['total_vat']);
-
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals($preview_total['total_incvat'], $response->amount);
- }
-
- public function test_getRequestTotals_reference_1321_00_ex_behaviour()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(1321.00)
- ->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.00, $preview_total['total_exvat']);
- $this->assertEquals(79.26, $preview_total['total_vat']);
-
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals($preview_total['total_incvat'], $response->amount);
- }
-
-
- public function test_getRequestTotals_reference_1321_00_ex_with_compensation_row()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(1321.00)
- ->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.00, $preview_total['total_exvat']);
- $this->assertEquals(79.26, $preview_total['total_vat']);
-
- $target_total = 1400.00;
- $compensation_amount = (double)$preview_total['total_incvat'] - $target_total;
-
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat($compensation_amount)
- ->setVatPercent(0)
- );
-
- $compensated_preview_total = $order->useInvoicePayment()->getRequestTotals();
-
- $this->assertEquals(1400.00, $compensated_preview_total['total_incvat']);
- $this->assertEquals(1320.74, $compensated_preview_total['total_exvat']);
- $this->assertEquals(79.26, $compensated_preview_total['total_vat']);
-
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals($compensated_preview_total['total_incvat'], $response->amount);
- //print_r( "test_getRequestTotals_reference_1321_00_ex_with_compensation_row: " + $response->sveaOrderId );
- }
-
- public function test_getRequestTotals_reference_1400_26_inc_with_compensation_row()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1400.26)
- ->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.00, $preview_total['total_exvat']);
- $this->assertEquals(79.26, $preview_total['total_vat']);
-
- $target_total = 1400.00;
- $compensation_amount = (double)$preview_total['total_incvat'] - $target_total;
-
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat($compensation_amount)
- ->setVatPercent(0)
- );
-
- $compensated_preview_total = $order->useInvoicePayment()->getRequestTotals();
-
- $this->assertEquals(1400.00, $compensated_preview_total['total_incvat']);
- $this->assertEquals(1320.74, $compensated_preview_total['total_exvat']);
- $this->assertEquals(79.26, $compensated_preview_total['total_vat']);
-
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals($compensated_preview_total['total_incvat'], $response->amount);
- //print_r( "test_getRequestTotals_reference_1400_26_inc_with_compensation_row: " + $response->sveaOrderId );
-
- }
-
- public function test_getRequestTotals_reference_1400_00_inc_cant_be_done_with_compensation_row()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1400.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2016-04-14");
-
- $preview_total = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals(1400.00, $preview_total['total_incvat']);
- $this->assertEquals(1320.75, $preview_total['total_exvat']);
- $this->assertEquals(79.25, $preview_total['total_vat']);
-
- $target_total = 1400.00;
-
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(-0.25)
- ->setVatPercent(0)
- );
-
- $compensated_preview_total = $order->useInvoicePayment()->getRequestTotals();
-
- $this->assertEquals(1400.25, $compensated_preview_total['total_incvat']); // should be 1400.00!
- $this->assertEquals(1321.00, $compensated_preview_total['total_exvat']);
- $this->assertEquals(79.25, $compensated_preview_total['total_vat']);
-
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $response->accepted);
- $this->assertEquals($compensated_preview_total['total_incvat'], $response->amount);
- }
+ function test_get_invoice_total_amount_before_createorder()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK");
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setName('Universal Camera Charger')
+ ->setAmountIncVat(19.60)
+ ->setVatPercent(25)
+ ->setQuantity(100)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(29.00)
+ ->setVatPercent(25)
+ ->setName('Svea Invoice Fee')
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(294.00)
+ ->setName('Discount')
+ );
+ $total = $order->useInvoicePayment()->getRequestTotals();
+
+ $this->assertEquals(1695.0, $total['total_incvat']);
+ $this->assertEquals(1356.0, $total['total_exvat']);
+ $this->assertEquals(339.0, $total['total_vat']);
+
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals($total['total_incvat'], $response->amount);
+ }
+
+ function test_get_invoice_total_amount_before_createorder_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK");
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setName('Universal Camera Charger')
+ ->setAmountIncVat(19.60)
+ ->setVatPercent(25)
+ ->setQuantity(100)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(29.00)
+ ->setVatPercent(25)
+ ->setName('Svea Invoice Fee')
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(294.00)
+ ->setName('Discount')
+ );
+ $total = $order->useInvoicePayment()->getRequestTotals();
+
+ $this->assertEquals(1695.0, $total['total_incvat']);
+ $this->assertEquals(1356.0, $total['total_exvat']);
+ $this->assertEquals(339.0, $total['total_vat']);
+
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals($total['total_incvat'], $response->amount);
+ }
+
+ /// example of order differing when sent incvat and exvat ----------------------------------------------------------------------
+
+ private static function create_only_incvat_order_and_fee_rows_order()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("incvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("incvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ ->setName("incvatShippingFee")
+ );
+
+ return $order;
+ }
+
+ public function test_getOrderTotals_has_same_amounts_as_service_when_order_sent_priceIncludingVat_false()
+ {
+ $order = GetRequestTotalsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ //->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10e")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
+ $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+
+ // 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.00*1) + r(33.00*1) + r(17.60*1) + r(8.80*1) + r(-8.00*1) + r(-3.66*1) => 72.00+33.00+17.60+8.80-8.00-3.67 => 119.73
+ //$this->assertEquals( "119.73", $response->amount ); // TODO check that this is the amount in S1 invoice, vs 119.74 w/PriceIncludingVat = false
+ $this->assertEquals("119.74", $response->amount); // jfr vs 119.73 w/PriceIncludingVat = true
+
+ // verify that getRequestTotals() got the same amount as the service
+ $preview = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals("119.74", $preview['total_incvat']);
+ $this->assertEquals($preview['total_incvat'], $response->amount);
+ }
+
+ public function test_getOrderTotals_has_same_amounts_as_service_when_order_sent_priceIncludingVat_true()
+ {
+ $order = GetRequestTotalsIntegrationTest::create_only_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(8.00)
+ ->setVatPercent(20)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 8.00i@20%")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(3.67)
+ ->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 3.67ie@10%")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
+ $this->assertEquals(-8.00, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+
+ // 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.00*1) + r(33.00*1) + r(17.60*1) + r(8.80*1) + r(-8.00*1) + r(-3.66*1) => 72.00+33.00+17.60+8.80-8.00-3.67 => 119.73
+ //$this->assertEquals( "119.73", $response->amount ); // TODO check that this is the amount in S1 invoice, vs 119.74 w/PriceIncludingVat = false
+ $this->assertEquals("119.73", $response->amount); // jfr vs 119.73 w/PriceIncludingVat = true
+
+ // verify that getRequestTotals() got the same amount as the service
+ $preview = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals("119.73", $preview['total_incvat']);
+ $this->assertEquals($preview['total_incvat'], $response->amount);
+ }
+
+ /// example of getRequestTotals() not matching service --------------------------------------------------------------------------
+ public function test_integrationtest_reference_1400_00_inc_behaviour()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1400.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2016-04-14");
+ $response = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(1400, $response->amount);
+
+ // verify that getRequestTotals() got the same amount as the service
+ $preview = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals($preview['total_incvat'], $response->amount);
+
+
+ }
+
+ public function test_integrationtest_reference_1321_00_ex_behaviour()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(1321.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2016-04-14");
+ $response = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals(1400.26, $response->amount);
+
+ // verify that getRequestTotals() got the same amount as the service
+ $preview = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals($preview['total_incvat'], $response->amount);
+ }
+
+ public function test_getRequestTotals_reference_1400_00_inc_behaviour()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1400.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2016-04-14");
+
+ $preview_total = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals(1400.00, $preview_total['total_incvat']);
+ $this->assertEquals(1320.75, $preview_total['total_exvat']);
+ $this->assertEquals(79.25, $preview_total['total_vat']);
+
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals($preview_total['total_incvat'], $response->amount);
+ }
+
+ public function test_getRequestTotals_reference_1400_26_inc_behaviour()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1400.26)
+ ->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.00, $preview_total['total_exvat']);
+ $this->assertEquals(79.26, $preview_total['total_vat']);
+
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals($preview_total['total_incvat'], $response->amount);
+ }
+
+ public function test_getRequestTotals_reference_1321_00_ex_behaviour()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(1321.00)
+ ->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.00, $preview_total['total_exvat']);
+ $this->assertEquals(79.26, $preview_total['total_vat']);
+
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals($preview_total['total_incvat'], $response->amount);
+ }
+
+
+ public function test_getRequestTotals_reference_1321_00_ex_with_compensation_row()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(1321.00)
+ ->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.00, $preview_total['total_exvat']);
+ $this->assertEquals(79.26, $preview_total['total_vat']);
+
+ $target_total = 1400.00;
+ $compensation_amount = (double)$preview_total['total_incvat'] - $target_total;
+
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat($compensation_amount)
+ ->setVatPercent(0)
+ );
+
+ $compensated_preview_total = $order->useInvoicePayment()->getRequestTotals();
+
+ $this->assertEquals(1400.00, $compensated_preview_total['total_incvat']);
+ $this->assertEquals(1320.74, $compensated_preview_total['total_exvat']);
+ $this->assertEquals(79.26, $compensated_preview_total['total_vat']);
+
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals($compensated_preview_total['total_incvat'], $response->amount);
+ //print_r( "test_getRequestTotals_reference_1321_00_ex_with_compensation_row: " + $response->sveaOrderId );
+ }
+
+ public function test_getRequestTotals_reference_1400_26_inc_with_compensation_row()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1400.26)
+ ->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.00, $preview_total['total_exvat']);
+ $this->assertEquals(79.26, $preview_total['total_vat']);
+
+ $target_total = 1400.00;
+ $compensation_amount = (double)$preview_total['total_incvat'] - $target_total;
+
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat($compensation_amount)
+ ->setVatPercent(0)
+ );
+
+ $compensated_preview_total = $order->useInvoicePayment()->getRequestTotals();
+
+ $this->assertEquals(1400.00, $compensated_preview_total['total_incvat']);
+ $this->assertEquals(1320.74, $compensated_preview_total['total_exvat']);
+ $this->assertEquals(79.26, $compensated_preview_total['total_vat']);
+
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals($compensated_preview_total['total_incvat'], $response->amount);
+ //print_r( "test_getRequestTotals_reference_1400_26_inc_with_compensation_row: " + $response->sveaOrderId );
+
+ }
+
+ public function test_getRequestTotals_reference_1400_00_inc_cant_be_done_with_compensation_row()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1400.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2016-04-14");
+
+ $preview_total = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals(1400.00, $preview_total['total_incvat']);
+ $this->assertEquals(1320.75, $preview_total['total_exvat']);
+ $this->assertEquals(79.25, $preview_total['total_vat']);
+
+ $target_total = 1400.00;
+
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(-0.25)
+ ->setVatPercent(0)
+ );
+
+ $compensated_preview_total = $order->useInvoicePayment()->getRequestTotals();
+
+ $this->assertEquals(1400.25, $compensated_preview_total['total_incvat']); // should be 1400.00!
+ $this->assertEquals(1321.00, $compensated_preview_total['total_exvat']);
+ $this->assertEquals(79.25, $compensated_preview_total['total_vat']);
+
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $response->accepted);
+ $this->assertEquals($compensated_preview_total['total_incvat'], $response->amount);
+ }
}
\ No newline at end of file
diff --git a/test/IntegrationTest/WebService/Payment/InvoicePaymentIntegrationTest.php b/test/IntegrationTest/WebService/Payment/InvoicePaymentIntegrationTest.php
index bc1af38a..324a9b9d 100644
--- a/test/IntegrationTest/WebService/Payment/InvoicePaymentIntegrationTest.php
+++ b/test/IntegrationTest/WebService/Payment/InvoicePaymentIntegrationTest.php
@@ -17,1663 +17,1663 @@
class InvoicePaymentIntegrationTest extends \PHPUnit\Framework\TestCase
{
- // order with order/fee rows mixed exvat+vat / incvat+vat should be sent with PriceIncludingVat = false
- public function test_mixed_order_row_and_shipping_fees_only_has_priceIncludingVat_false()
- {
- $order = $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("incvatRow")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
-
- // check that service accepts order
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(true, $response->accepted);
- $this->assertEquals("131.4", $response->amount);
- }
-
- public function testInvoiceRequestwithPeppolId()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(
- WebPayItem::companyCustomer()
- ->setNationalIdNumber(194608142222))
- ->setOrderDate("2019-04-01")
- ->setCountryCode("SE")
- ->setPeppolId("1234:asdf")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- }
-
- public function testInvoiceRequestAccepted()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setNationalIdNumber(4605092222)
- )
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- }
-
-
- public function testInvoiceRequestNLAcceptedWithDoubleHousenumber()
- {
- $this->markTestIncomplete("NL flow not maintained by webpay-dev");
-
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setBirthDate(1955, 03, 07)
- ->setName("Sneider", "Boasman")
- ->setStreetAddress("Gate 42", "23")// result of splitStreetAddress w/Svea testperson
- ->setCoAddress(138)
- ->setLocality("BARENDRECHT")
- ->setZipCode("1102 HG")
- ->setInitials("SB")
- )
- ->setCountryCode("NL")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- }
-
-
- public function testInvoiceRequestUsingISO8601dateAccepted()
- {
- $this->markTestIncomplete("NL flow not maintained by webpay-dev");
-
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(4605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate(date('c'))
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- }
-
-
- public function testInvoiceRequestDenied()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(4606082222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(0, $request->accepted);
- }
-
- //Turned off?
- public function testInvoiceIndividualForDk()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(2603692503))
- ->setCountryCode("DK")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("DKK")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- }
-
- public function testInvoiceCompanySE()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(4608142222))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(true, $request->accepted);
- }
-
- public function testAcceptsFractionalQuantities()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(25)
- ->setQuantity(1.25)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("EUR")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(0, $request->resultcode);
- $this->assertEquals('Invoice', $request->orderType);
- $this->assertEquals(1, $request->sveaWillBuyOrder);
- $this->assertEquals(125, $request->amount);
- }
-
- public function testAcceptsIntegerQuantities()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("EUR")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(0, $request->resultcode);
- $this->assertEquals('Invoice', $request->orderType);
- $this->assertEquals(1, $request->sveaWillBuyOrder);
- $this->assertEquals(100, $request->amount);
- }
-
- /**
- * NL vat rates are 6%, 21% (as of 131018, see https://www.government.nl/topics/vat/vat-rates-and-exemptions)
- */
- public function t___estNLInvoicePaymentAcceptsVatRates()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRowWithVat(6))
- ->addOrderRow(TestUtil::createOrderRowWithVat(21))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("NL"))
- ->setCountryCode("NL")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("EUR")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(0, $request->resultcode);
- $this->assertEquals('Invoice', $request->orderType);
- $this->assertEquals(1, $request->sveaWillBuyOrder);
- $this->assertEquals(106 + 121, $request->amount); // 1x100 @ 6% vat + 1x100 @ 21%
- $this->assertEquals('', $request->customerIdentity->email);
- $this->assertEquals('', $request->customerIdentity->ipAddress);
- $this->assertEquals('NL', $request->customerIdentity->countryCode);
- $this->assertEquals(23, $request->customerIdentity->houseNumber);
- $this->assertEquals('Individual', $request->customerIdentity->customerType);
- $this->assertEquals('', $request->customerIdentity->phoneNumber);
- $this->assertEquals('Sneider Boasman', $request->customerIdentity->fullName);
- $this->assertEquals('Gate 42', $request->customerIdentity->street);
- $this->assertEquals(138, $request->customerIdentity->coAddress);
- $this->assertEquals('1102 HG', $request->customerIdentity->zipCode);
- $this->assertEquals('BARENDRECHT', $request->customerIdentity->locality);
- }
-
- /**
- * make sure opencart bug w/corporate invoice payments for one 25% vat product with free shipping (0% vat)
- * resulting in request with illegal vat rows of 24% not originating in integration package
- */
-
- public function test_InvoiceFee_ExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(2032.80)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::shippingFee()
- ->setAmountExVat(0.00)
- ->setVatPercent(0)
- )
- ->addOrderRow(WebPayItem::invoiceFee()
- ->setAmountExVat(29.00)
- ->setVatPercent(25)
- )
- ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2013-10-28")
- ->setCurrency("SEK");
-
- // asserts on request
- $request = $order->useInvoicePayment()->prepareRequest();
-
- $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
-
- $newRow = $newRows[0];
- $this->assertEquals(2032.80, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- $newRow = $newRows[1];
- $this->assertEquals(0, $newRow->PricePerUnit);
- $this->assertEquals(0, $newRow->VatPercent);
-
- $newRow = $newRows[2];
- $this->assertEquals(29.00, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- // asserts on result
- $result = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $result->accepted);
- $this->assertEquals(0, $result->resultcode);
- $this->assertEquals('Invoice', $result->orderType);
- $this->assertEquals(1, $result->sveaWillBuyOrder);
- $this->assertEquals(2577.25, $result->amount);
-
- }
-
- public function test_InvoiceFee_IncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::shippingFee()
- ->setAmountIncVat(0.00)
- ->setVatPercent(0)
- )
- ->addOrderRow(WebPayItem::invoiceFee()
- ->setAmountIncVat(29.00)
- ->setVatPercent(25)
- )
- ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2013-10-28")
- ->setCurrency("SEK");
-
- // asserts on request
- $request = $order->useInvoicePayment()->prepareRequest();
-
- $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
-
- $newRow = $newRows[0];
- $this->assertEquals(100, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- $newRow = $newRows[1];
- $this->assertEquals(0, $newRow->PricePerUnit);
- $this->assertEquals(0, $newRow->VatPercent);
-
- $newRow = $newRows[2];
- $this->assertEquals(23.20, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- // asserts on result
- $result = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $result->accepted);
- $this->assertEquals(0, $result->resultcode);
- $this->assertEquals('Invoice', $result->orderType);
- $this->assertEquals(1, $result->sveaWillBuyOrder);
- $this->assertEquals(154, $result->amount);
- }
-
- public function test_InvoiceFee_IncVatAndExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::shippingFee()
- ->setAmountIncVat(0.00)
- ->setVatPercent(0)
- )
- ->addOrderRow(WebPayItem::invoiceFee()
- ->setAmountIncVat(29.00)
- ->setAmountExVat(23.20)
- )
- ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2013-10-28")
- ->setCurrency("SEK");
-
- // asserts on request
- $request = $order->useInvoicePayment()->prepareRequest();
- $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
-
- $newRow = $newRows[0];
- $this->assertEquals(100, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- $newRow = $newRows[1];
- $this->assertEquals(0, $newRow->PricePerUnit);
- $this->assertEquals(0, $newRow->VatPercent);
-
- $newRow = $newRows[2];
- $this->assertEquals(23.20, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- // asserts on result
- $result = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $result->accepted);
- $this->assertEquals(0, $result->resultcode);
- $this->assertEquals('Invoice', $result->orderType);
- $this->assertEquals(1, $result->sveaWillBuyOrder);
- $this->assertEquals(154, $result->amount);
- }
-
- public function test_ShippingFee_ExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::shippingFee()
- ->setAmountExVat(20.00)
- ->setVatPercent(6)
- )
- ->addOrderRow(WebPayItem::invoiceFee()
- ->setAmountExVat(23.20)
- ->setVatPercent(25)
- )
- ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2013-10-28")
- ->setCurrency("SEK");
-
- // asserts on request
- $request = $order->useInvoicePayment()->prepareRequest();
-
- $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
-
- $newRow = $newRows[0];
- $this->assertEquals(100, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- $newRow = $newRows[1];
- $this->assertEquals(20.00, $newRow->PricePerUnit);
- $this->assertEquals(6, $newRow->VatPercent);
-
- $newRow = $newRows[2];
- $this->assertEquals(23.20, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- // asserts on result
- $result = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $result->accepted);
- $this->assertEquals(0, $result->resultcode);
- $this->assertEquals('Invoice', $result->orderType);
- $this->assertEquals(1, $result->sveaWillBuyOrder);
- $this->assertEquals(175.2, $result->amount);
- }
-
- public function test_ShippingFee_IncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::shippingFee()
- ->setAmountIncVat(21.20)
- ->setVatPercent(6)
- )
- ->addOrderRow(WebPayItem::invoiceFee()
- ->setAmountExVat(23.20)
- ->setVatPercent(25)
- )
- ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2013-10-28")
- ->setCurrency("SEK");
-
- // asserts on request
- $request = $order->useInvoicePayment()->prepareRequest();
-
- $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
-
- $newRow = $newRows[0];
- $this->assertEquals(100, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- $newRow = $newRows[1];
- $this->assertEquals(20.00, $newRow->PricePerUnit);
- $this->assertEquals(6, $newRow->VatPercent);
-
- $newRow = $newRows[2];
- $this->assertEquals(23.20, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- // asserts on result
- $result = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $result->accepted);
- $this->assertEquals(0, $result->resultcode);
- $this->assertEquals('Invoice', $result->orderType);
- $this->assertEquals(1, $result->sveaWillBuyOrder);
- $this->assertEquals(175.2, $result->amount);
- }
-
- public function test_ShippingFee_IncVatAndExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::shippingFee()
- ->setAmountExVat(20.00)
- ->setAmountIncVat(21.20)
- )
- ->addOrderRow(WebPayItem::invoiceFee()
- ->setAmountExVat(23.20)
- ->setVatPercent(25)
- )
- ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2013-10-28")
- ->setCurrency("SEK");
-
- // asserts on request
- $request = $order->useInvoicePayment()->prepareRequest();
-
- $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
-
- $newRow = $newRows[0];
- $this->assertEquals(100, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- $newRow = $newRows[1];
- $this->assertEquals(20.00, $newRow->PricePerUnit);
- $this->assertEquals(6, $newRow->VatPercent);
-
- $newRow = $newRows[2];
- $this->assertEquals(23.20, $newRow->PricePerUnit);
- $this->assertEquals(25, $newRow->VatPercent);
-
- // asserts on result
- $result = $order->useInvoicePayment()->doRequest();
-
- $this->assertEquals(1, $result->accepted);
- $this->assertEquals(0, $result->resultcode);
- $this->assertEquals('Invoice', $result->orderType);
- $this->assertEquals(1, $result->sveaWillBuyOrder);
- $this->assertEquals(175.2, $result->amount);
- }
-
- public function testInvoiceRequest_optional_clientOrderNumber_present_in_response_if_sent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setNationalIdNumber(4605092222)
- )
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->setClientOrderNumber("I_exist!")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(true, isset($request->clientOrderNumber));
- $this->assertEquals("I_exist!", $request->clientOrderNumber);
- }
-
- public function testInvoiceRequest_optional_clientOrderNumber_not_present_in_response_if_not_sent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setNationalIdNumber(4605092222)
- )
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(false, isset($request->clientOrderNumber));
- }
-
- public function testInvoiceRequest_OrderType_set_in_response_if_useInvoicePayment_set()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals("Invoice", $request->orderType);
- }
-
- /**
- * Tests for rounding**
- */
-
- public function testPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
-
- }
-
- public function testFixedDiscountSetAsExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(8)
- ->setVatPercent(0))
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
-
- }
-
- public function testResponseOrderRowPriceSetAsInkVatAndVatPercentSetAmountAsIncVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
-
- }
-
- public function testResponseFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(100.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(100.00)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
-
- }
-
- public function testResponseDiscountSetAsIncVatWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
-
-
- }
-
- public function testResponseDiscountSetAsExVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(10)
- ->setVatPercent(0))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
-
- }
-
-
- public function testResponseDiscountPercentAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
-
- }
-
- public function testResponseOrderSetAsIncVatAndExVatAndRelativeDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
-
- }
-
- public function testResponseOrderAndFixedDiscountSetWithMixedVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(9.999)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
-
- }
-
- public function testResponseOrderAndFixedDiscountSetWithMixedVat2()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(12.39876)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
-
- }
-
- public function testResponseOrderAndFixedDiscountSetWithMixedVat3()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(9.999)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
-
- }
-
- public function testTaloonRoundingExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(116.94)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(7.26)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(4.03)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("FI"))
- ->setCountryCode("FI")
- ->setCurrency("EUR")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(159.01, $request->amount);//sends the old way, so still wrong rounding
-
- }
-
- public function testTaloonRoundingIncVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(145.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(9.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(5.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("FI"))
- ->setCountryCode("FI")
- ->setCurrency("EUR")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->doRequest();
- $this->assertEquals(1, $request->accepted);
- $this->assertEquals(159.0, $request->amount);
-
- }
-
- // Test that test suite returns complete address in each country
- // SE
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_SE()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("4605092222")
- )
- ->setCountryCode("SE")
- ->setOrderDate(date('c'));
- $response = $order->useInvoicePayment()->doRequest();
- //print_r($response);
- $this->assertEquals(1, $response->accepted);
- $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
- // verify returned address
- $this->assertEquals("Persson Tess T", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
- $this->assertEquals("Testgatan 1", $response->customerIdentity->street);
- $this->assertEquals("c/o Eriksson, Erik", $response->customerIdentity->coAddress);
- $this->assertEquals("99999", $response->customerIdentity->zipCode);
- $this->assertEquals("Stan", $response->customerIdentity->locality);
- }
-
- // NO
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_NO()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("17054512066")
- )
- ->setCountryCode("NO")
- ->setOrderDate(date('c'));
- $response = $order->useInvoicePayment()->doRequest();
- //print_r($response);
- $this->assertEquals(1, $response->accepted);
- $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
- // verify returned address
- $this->assertEquals("Ola Normann", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
- $this->assertEquals("Testveien 2", $response->customerIdentity->street);
- $this->assertEquals("", $response->customerIdentity->coAddress);
- $this->assertEquals("0359", $response->customerIdentity->zipCode);
- $this->assertEquals("Oslo", $response->customerIdentity->locality);
- }
-
- // DK
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_DK()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("2603692503")
- )
- ->setCountryCode("DK")
- ->setOrderDate(date('c'));
- $response = $order->useInvoicePayment()->doRequest();
- //print_r($response);
- $this->assertEquals(1, $response->accepted);
- $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
- // verify returned address
- $this->assertEquals("Hanne Jensen", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
- $this->assertEquals("Testvejen 42", $response->customerIdentity->street);
- $this->assertEquals("c/o Test A/s", $response->customerIdentity->coAddress);
- $this->assertEquals("2100", $response->customerIdentity->zipCode);
- $this->assertEquals("Københvn Ø", $response->customerIdentity->locality);
- }
-
- // FI
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_FI()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("160264-999N")
- )
- ->setCountryCode("FI")
- ->setOrderDate(date('c'));
- $response = $order->useInvoicePayment()->doRequest();
- //print_r($response);
- $this->assertEquals(1, $response->accepted);
- $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
- // verify returned address
- $this->assertEquals("Kanerva Haapakoski Kukka-Maaria", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
- $this->assertEquals("Atomitie 2 C", $response->customerIdentity->street);
- $this->assertEquals("", $response->customerIdentity->coAddress);
- $this->assertEquals("00370", $response->customerIdentity->zipCode);
- $this->assertEquals("Helsinki", $response->customerIdentity->locality);
- }
-
- // DE
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_DE()
- {
- $this->markTestIncomplete("NL flow not maintained by webpay-dev");
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- ->setDescription("IntegrationTest")
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setBirthDate("19680403")
- ->setName("Theo", "Giebel")
- ->setStreetAddress("Zörgiebelweg", 21)
- ->setZipCode("13591")
- ->setLocality("BERLIN")
- )
- ->setCountryCode("DE")
- ->setOrderDate(date('c'));
- $response = $order->useInvoicePayment()->doRequest();
- //print_r($response);
- $this->assertEquals(1, $response->accepted);
- $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
- // verify returned address
- $this->assertEquals("Theo Giebel", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
- $this->assertEquals("Zörgiebelweg", $response->customerIdentity->street);
- $this->assertEquals("21", $response->customerIdentity->houseNumber);
- $this->assertEquals("", $response->customerIdentity->coAddress);
- $this->assertEquals("13591", $response->customerIdentity->zipCode);
- $this->assertEquals("BERLIN", $response->customerIdentity->locality);
- }
-
- // NL
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_NL()
- {
- $this->markTestIncomplete("NL flow not maintained by webpay-dev");
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- ->setDescription("IntegrationTest")
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setBirthDate("19550307")
- ->setInitials("SB")
- ->setName("Sneider", "Boasman")
- ->setStreetAddress("Gate 42", 23)
- ->setZipCode("1102 HG")
- ->setLocality("BARENDRECHT")
- )
- ->setCountryCode("NL")
- ->setOrderDate(date('c'));
- $response = $order->useInvoicePayment()->doRequest();
- //print_r($response);
- $this->assertEquals(1, $response->accepted);
- $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
- // verify returned address
- $this->assertEquals("Sneider Boasman", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
- $this->assertEquals("Gate 42", $response->customerIdentity->street);
- $this->assertEquals("23", $response->customerIdentity->houseNumber);
- $this->assertEquals("", $response->customerIdentity->coAddress);
- $this->assertEquals("1102 HG", $response->customerIdentity->zipCode);
- $this->assertEquals("BARENDRECHT", $response->customerIdentity->locality);
- }
-
- public function testInvoiceRequestNLReturnsSameAddress()
- {
- $this->markTestIncomplete("NL flow not maintained by webpay-dev");
-
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setBirthDate(1955, 03, 07)
- ->setName("Sneider", "Boasman")
- ->setStreetAddress("Gate 42", "23")// result of splitStreetAddress w/Svea testperson
- ->setCoAddress(138)
- ->setLocality("BARENDRECHT")
- ->setZipCode("1102 HG")
- ->setInitials("SB")
- )
- ->setCountryCode("NL")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertTrue($request->customerIdentity instanceof CreateOrderIdentity);
- // verify returned address
- $this->assertEquals("Sneider Boasman", $request->customerIdentity->fullName);
- $this->assertEquals("Gate 42", $request->customerIdentity->street);
- $this->assertEquals("23", $request->customerIdentity->houseNumber);
- $this->assertEquals("1102 HG", $request->customerIdentity->zipCode);
- $this->assertEquals("BARENDRECHT", $request->customerIdentity->locality);
- }
-
- public function testInvoiceRequestNLReturnsCorrectAddress()
- {
- $this->markTestIncomplete("NL flow not maintained by webpay-dev");
-
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setBirthDate(1955, 03, 07)
- ->setName("Sneider", "Boasman")
- ->setStreetAddress("Gate 42", "23")// result of splitStreetAddress w/Svea testperson
- ->setCoAddress(138)
- ->setLocality("BARENDRECHT")
- ->setZipCode("1102 HG")
- ->setInitials("SB")
- )
- ->setCountryCode("NL")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->doRequest();
-
- $this->assertEquals(1, $request->accepted);
- $this->assertTrue($request->customerIdentity instanceof CreateOrderIdentity);
- // verify returned address
- $this->assertEquals("Sneider Boasman", $request->customerIdentity->fullName);
- $this->assertEquals("Gate 42", $request->customerIdentity->street);
- $this->assertEquals("23", $request->customerIdentity->houseNumber);
- $this->assertEquals("1102 HG", $request->customerIdentity->zipCode);
- $this->assertEquals("BARENDRECHT", $request->customerIdentity->locality);
-
- //
- //
- //
- //
- //
- // 85997
- // hollandtest
- // hollandtest
- //
- //
- //
- //
- // 1
- // Product: Specification
- // 100
- // false
- // 2
- // st
- // 25
- // 0
- //
- //
- //
- //
- //
- //
- //
- //
- //
- // Sneider Boasman
- // Gate 42
- // 138
- // 1102 HG
- // 23
- // BARENDRECHT
- // NL
- // Individual
- //
- // Sneider
- // Boasman
- // SB
- // 19550307
- //
- //
- // 2012-12-12
- //
- //
- // 33
- // Invoice
- //
- //
- //
- //
- //
- }
-
- public function testInvoiceRequestNLReproduceErrorIn471193()
- {
- $this->markTestIncomplete("NL flow not maintained by webpay-dev");
-
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setBirthDate(1955, 03, 07)// BirthDate and ZipCode is sufficient for a successful test order
- ->setZipCode("1102 HG")//
- ->setName("foo", "bar")
- ->setStreetAddress("foo", "bar")
- ->setCoAddress(1337)
- ->setLocality("dns")
- ->setInitials("nsl")
- )
- ->setCountryCode("NL")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->doRequest();
- //->prepareRequest();
- //var_dump($request->request->CreateOrderInformation->CustomerIdentity);
-
- $this->assertEquals(1, $request->accepted);
- $this->assertTrue($request->customerIdentity instanceof CreateOrderIdentity);
-
- //print_r( $request->sveaOrderId);
- // verify returned address is wrong
- $this->assertNotEquals("Sneider Boasman", $request->customerIdentity->fullName);
- $this->assertNotEquals("Gate 42", $request->customerIdentity->street);
- $this->assertNotEquals("23", $request->customerIdentity->houseNumber);
- $this->assertNotEquals("BARENDRECHT", $request->customerIdentity->locality);
- //$this->assertNotEquals( "1102 HG", $request->customerIdentity->zipCode );
-
- $this->assertEquals("foo bar", $request->customerIdentity->fullName);
- $this->assertEquals("foo", $request->customerIdentity->street);
- $this->assertEquals("bar", $request->customerIdentity->houseNumber);
- $this->assertEquals("dns", $request->customerIdentity->locality);
- $this->assertEquals("1102 HG", $request->customerIdentity->zipCode);
-
-
- //
- //
- //
- //
- //
- // 85997
- // hollandtest
- // hollandtest
- //
- //
- // 133
- //
- //
- // NTB03
- // Making candles and soaps for dummies: Making candles and soaps for dummies
- // 12.12
- //
- // 2
- // st
- // 25
- // 0
- //
- //
- // SHIP25
- // Frakt / Shipping
- // 8.66
- //
- // 1
- // st
- // 25
- // 0
- //
- //
- // HAND25
- // Expeditionsavgift / Handling
- // 2.51
- //
- // 1
- // st
- // 25
- // 0
- //
- //
- //
- //
- //
- //
- //
- //
- //
- // asdf ghij
- // Postbus
- //
- //
- // 1010 AB
- // 626
- // Amsterdam
- // NL
- // Individual
- //
- // asdf
- // ghij
- // ag
- // 19550307
- //
- //
- // 2014-11-19
- //
- //
- // Invoice
- //
- //
- //
- //
- //
-
- }
-
- function test_orderRow_discountPercent_not_used()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
- $this->assertEquals("125.00", $orderResponse->amount);
- //print_r($orderResponse);
-
- $query = WebPayAdmin::queryOrder($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals(100.00, $query->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(25.00, $query->numberedOrderRows[0]->vatPercent);
- $this->assertEquals(0.00, $query->numberedOrderRows[0]->discountPercent);
- }
-
- function test_orderRow_discountPercent_50percent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDiscountPercent(50)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
- $this->assertEquals("62.50", $orderResponse->amount);
-
- $query = WebPayAdmin::queryOrder($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals(100.00, $query->numberedOrderRows[0]->amountExVat);
- $this->assertEquals(25.00, $query->numberedOrderRows[0]->vatPercent);
- $this->assertEquals(50.00, $query->numberedOrderRows[0]->discountPercent);
- }
-
- function test_orderRow_discountPercent_50_percent_order_sent_as_incvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderResponse = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(125.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDiscountPercent(50)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()->doRequest();
- $this->assertEquals(1, $orderResponse->accepted);
- $this->assertEquals("62.5", $orderResponse->amount); // this is where
-
- $query = WebPayAdmin::queryOrder($config)
- ->setCountryCode('SE')
- ->setOrderId($orderResponse->sveaOrderId)
- ->queryInvoiceOrder()->doRequest();
- $this->assertEquals(1, $query->accepted);
- $this->assertEquals(125.00, $query->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals(25.00, $query->numberedOrderRows[0]->vatPercent);
- $this->assertEquals(50.00, $query->numberedOrderRows[0]->discountPercent);
- }
-
- // fixed discount -- created discount rows should use incvat + vatpercent
- /// fixed discount examples:
- // single order rows vat rate
- public function test_fixedDiscount_amount_with_incvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("incvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("incvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- ->setName("incvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
-
- // check that service accepts order
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(true, $response->accepted);
- }
-
- // single order rows vat rate
- public function test_fixedDiscount_amount_with_exvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
-
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(true, $response->accepted);
- }
-
- public function testOrderAndFixedDiscountSetWithMixedVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(9.999)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
-
- $request = $order->useInvoicePayment()->prepareRequest();
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- // 9.999 *1.24 = 12.39876
- $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- // check that service accepts order
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(true, $response->accepted);
- }
-
- public function testOrderAndFixedDiscountSetWithMixedVat3()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(9.999)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12");
- $request = $order->useInvoicePayment()->prepareRequest();
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- // 9.999 *1.24 = 12.39876
- $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- // check that service accepts order
- $response = $order->useInvoicePayment()->doRequest();
- $this->assertEquals(true, $response->accepted);
- }
+ // order with order/fee rows mixed exvat+vat / incvat+vat should be sent with PriceIncludingVat = false
+ public function test_mixed_order_row_and_shipping_fees_only_has_priceIncludingVat_false()
+ {
+ $order = $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("incvatRow")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+
+ // check that service accepts order
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ $this->assertEquals("131.4", $response->amount);
+ }
+
+ public function testInvoiceRequestwithPeppolId()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(
+ WebPayItem::companyCustomer()
+ ->setNationalIdNumber(194608142222))
+ ->setOrderDate("2019-04-01")
+ ->setCountryCode("SE")
+ ->setPeppolId("1234:asdf")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ }
+
+ public function testInvoiceRequestAccepted()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setNationalIdNumber(4605092222)
+ )
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ }
+
+
+ public function testInvoiceRequestNLAcceptedWithDoubleHousenumber()
+ {
+ $this->markTestIncomplete("NL flow not maintained by webpay-dev");
+
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setBirthDate(1955, 03, 07)
+ ->setName("Sneider", "Boasman")
+ ->setStreetAddress("Gate 42", "23")// result of splitStreetAddress w/Svea testperson
+ ->setCoAddress(138)
+ ->setLocality("BARENDRECHT")
+ ->setZipCode("1102 HG")
+ ->setInitials("SB")
+ )
+ ->setCountryCode("NL")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ }
+
+
+ public function testInvoiceRequestUsingISO8601dateAccepted()
+ {
+ $this->markTestIncomplete("NL flow not maintained by webpay-dev");
+
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(4605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate(date('c'))
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ }
+
+
+ public function testInvoiceRequestDenied()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(4606082222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(0, $request->accepted);
+ }
+
+ //Turned off?
+ public function testInvoiceIndividualForDk()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(2603692503))
+ ->setCountryCode("DK")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("DKK")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ }
+
+ public function testInvoiceCompanySE()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(4608142222))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(true, $request->accepted);
+ }
+
+ public function testAcceptsFractionalQuantities()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(25)
+ ->setQuantity(1.25)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("EUR")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(0, $request->resultcode);
+ $this->assertEquals('Invoice', $request->orderType);
+ $this->assertEquals(1, $request->sveaWillBuyOrder);
+ $this->assertEquals(125, $request->amount);
+ }
+
+ public function testAcceptsIntegerQuantities()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("EUR")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(0, $request->resultcode);
+ $this->assertEquals('Invoice', $request->orderType);
+ $this->assertEquals(1, $request->sveaWillBuyOrder);
+ $this->assertEquals(100, $request->amount);
+ }
+
+ /**
+ * NL vat rates are 6%, 21% (as of 131018, see https://www.government.nl/topics/vat/vat-rates-and-exemptions)
+ */
+ public function t___estNLInvoicePaymentAcceptsVatRates()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRowWithVat(6))
+ ->addOrderRow(TestUtil::createOrderRowWithVat(21))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("NL"))
+ ->setCountryCode("NL")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("EUR")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(0, $request->resultcode);
+ $this->assertEquals('Invoice', $request->orderType);
+ $this->assertEquals(1, $request->sveaWillBuyOrder);
+ $this->assertEquals(106 + 121, $request->amount); // 1x100 @ 6% vat + 1x100 @ 21%
+ $this->assertEquals('', $request->customerIdentity->email);
+ $this->assertEquals('', $request->customerIdentity->ipAddress);
+ $this->assertEquals('NL', $request->customerIdentity->countryCode);
+ $this->assertEquals(23, $request->customerIdentity->houseNumber);
+ $this->assertEquals('Individual', $request->customerIdentity->customerType);
+ $this->assertEquals('', $request->customerIdentity->phoneNumber);
+ $this->assertEquals('Sneider Boasman', $request->customerIdentity->fullName);
+ $this->assertEquals('Gate 42', $request->customerIdentity->street);
+ $this->assertEquals(138, $request->customerIdentity->coAddress);
+ $this->assertEquals('1102 HG', $request->customerIdentity->zipCode);
+ $this->assertEquals('BARENDRECHT', $request->customerIdentity->locality);
+ }
+
+ /**
+ * make sure opencart bug w/corporate invoice payments for one 25% vat product with free shipping (0% vat)
+ * resulting in request with illegal vat rows of 24% not originating in integration package
+ */
+
+ public function test_InvoiceFee_ExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(2032.80)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::shippingFee()
+ ->setAmountExVat(0.00)
+ ->setVatPercent(0)
+ )
+ ->addOrderRow(WebPayItem::invoiceFee()
+ ->setAmountExVat(29.00)
+ ->setVatPercent(25)
+ )
+ ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2013-10-28")
+ ->setCurrency("SEK");
+
+ // asserts on request
+ $request = $order->useInvoicePayment()->prepareRequest();
+
+ $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
+
+ $newRow = $newRows[0];
+ $this->assertEquals(2032.80, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ $newRow = $newRows[1];
+ $this->assertEquals(0, $newRow->PricePerUnit);
+ $this->assertEquals(0, $newRow->VatPercent);
+
+ $newRow = $newRows[2];
+ $this->assertEquals(29.00, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ // asserts on result
+ $result = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $result->accepted);
+ $this->assertEquals(0, $result->resultcode);
+ $this->assertEquals('Invoice', $result->orderType);
+ $this->assertEquals(1, $result->sveaWillBuyOrder);
+ $this->assertEquals(2577.25, $result->amount);
+
+ }
+
+ public function test_InvoiceFee_IncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::shippingFee()
+ ->setAmountIncVat(0.00)
+ ->setVatPercent(0)
+ )
+ ->addOrderRow(WebPayItem::invoiceFee()
+ ->setAmountIncVat(29.00)
+ ->setVatPercent(25)
+ )
+ ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2013-10-28")
+ ->setCurrency("SEK");
+
+ // asserts on request
+ $request = $order->useInvoicePayment()->prepareRequest();
+
+ $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
+
+ $newRow = $newRows[0];
+ $this->assertEquals(100, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ $newRow = $newRows[1];
+ $this->assertEquals(0, $newRow->PricePerUnit);
+ $this->assertEquals(0, $newRow->VatPercent);
+
+ $newRow = $newRows[2];
+ $this->assertEquals(23.20, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ // asserts on result
+ $result = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $result->accepted);
+ $this->assertEquals(0, $result->resultcode);
+ $this->assertEquals('Invoice', $result->orderType);
+ $this->assertEquals(1, $result->sveaWillBuyOrder);
+ $this->assertEquals(154, $result->amount);
+ }
+
+ public function test_InvoiceFee_IncVatAndExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::shippingFee()
+ ->setAmountIncVat(0.00)
+ ->setVatPercent(0)
+ )
+ ->addOrderRow(WebPayItem::invoiceFee()
+ ->setAmountIncVat(29.00)
+ ->setAmountExVat(23.20)
+ )
+ ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2013-10-28")
+ ->setCurrency("SEK");
+
+ // asserts on request
+ $request = $order->useInvoicePayment()->prepareRequest();
+ $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
+
+ $newRow = $newRows[0];
+ $this->assertEquals(100, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ $newRow = $newRows[1];
+ $this->assertEquals(0, $newRow->PricePerUnit);
+ $this->assertEquals(0, $newRow->VatPercent);
+
+ $newRow = $newRows[2];
+ $this->assertEquals(23.20, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ // asserts on result
+ $result = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $result->accepted);
+ $this->assertEquals(0, $result->resultcode);
+ $this->assertEquals('Invoice', $result->orderType);
+ $this->assertEquals(1, $result->sveaWillBuyOrder);
+ $this->assertEquals(154, $result->amount);
+ }
+
+ public function test_ShippingFee_ExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::shippingFee()
+ ->setAmountExVat(20.00)
+ ->setVatPercent(6)
+ )
+ ->addOrderRow(WebPayItem::invoiceFee()
+ ->setAmountExVat(23.20)
+ ->setVatPercent(25)
+ )
+ ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2013-10-28")
+ ->setCurrency("SEK");
+
+ // asserts on request
+ $request = $order->useInvoicePayment()->prepareRequest();
+
+ $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
+
+ $newRow = $newRows[0];
+ $this->assertEquals(100, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ $newRow = $newRows[1];
+ $this->assertEquals(20.00, $newRow->PricePerUnit);
+ $this->assertEquals(6, $newRow->VatPercent);
+
+ $newRow = $newRows[2];
+ $this->assertEquals(23.20, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ // asserts on result
+ $result = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $result->accepted);
+ $this->assertEquals(0, $result->resultcode);
+ $this->assertEquals('Invoice', $result->orderType);
+ $this->assertEquals(1, $result->sveaWillBuyOrder);
+ $this->assertEquals(175.2, $result->amount);
+ }
+
+ public function test_ShippingFee_IncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::shippingFee()
+ ->setAmountIncVat(21.20)
+ ->setVatPercent(6)
+ )
+ ->addOrderRow(WebPayItem::invoiceFee()
+ ->setAmountExVat(23.20)
+ ->setVatPercent(25)
+ )
+ ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2013-10-28")
+ ->setCurrency("SEK");
+
+ // asserts on request
+ $request = $order->useInvoicePayment()->prepareRequest();
+
+ $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
+
+ $newRow = $newRows[0];
+ $this->assertEquals(100, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ $newRow = $newRows[1];
+ $this->assertEquals(20.00, $newRow->PricePerUnit);
+ $this->assertEquals(6, $newRow->VatPercent);
+
+ $newRow = $newRows[2];
+ $this->assertEquals(23.20, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ // asserts on result
+ $result = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $result->accepted);
+ $this->assertEquals(0, $result->resultcode);
+ $this->assertEquals('Invoice', $result->orderType);
+ $this->assertEquals(1, $result->sveaWillBuyOrder);
+ $this->assertEquals(175.2, $result->amount);
+ }
+
+ public function test_ShippingFee_IncVatAndExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::shippingFee()
+ ->setAmountExVat(20.00)
+ ->setAmountIncVat(21.20)
+ )
+ ->addOrderRow(WebPayItem::invoiceFee()
+ ->setAmountExVat(23.20)
+ ->setVatPercent(25)
+ )
+ ->addCustomerDetails(TestUtil::createCompanyCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2013-10-28")
+ ->setCurrency("SEK");
+
+ // asserts on request
+ $request = $order->useInvoicePayment()->prepareRequest();
+
+ $newRows = $request->request->CreateOrderInformation->OrderRows['OrderRow'];
+
+ $newRow = $newRows[0];
+ $this->assertEquals(100, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ $newRow = $newRows[1];
+ $this->assertEquals(20.00, $newRow->PricePerUnit);
+ $this->assertEquals(6, $newRow->VatPercent);
+
+ $newRow = $newRows[2];
+ $this->assertEquals(23.20, $newRow->PricePerUnit);
+ $this->assertEquals(25, $newRow->VatPercent);
+
+ // asserts on result
+ $result = $order->useInvoicePayment()->doRequest();
+
+ $this->assertEquals(1, $result->accepted);
+ $this->assertEquals(0, $result->resultcode);
+ $this->assertEquals('Invoice', $result->orderType);
+ $this->assertEquals(1, $result->sveaWillBuyOrder);
+ $this->assertEquals(175.2, $result->amount);
+ }
+
+ public function testInvoiceRequest_optional_clientOrderNumber_present_in_response_if_sent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setNationalIdNumber(4605092222)
+ )
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->setClientOrderNumber("I_exist!")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(true, isset($request->clientOrderNumber));
+ $this->assertEquals("I_exist!", $request->clientOrderNumber);
+ }
+
+ public function testInvoiceRequest_optional_clientOrderNumber_not_present_in_response_if_not_sent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setNationalIdNumber(4605092222)
+ )
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(false, isset($request->clientOrderNumber));
+ }
+
+ public function testInvoiceRequest_OrderType_set_in_response_if_useInvoicePayment_set()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals("Invoice", $request->orderType);
+ }
+
+ /**
+ * Tests for rounding**
+ */
+
+ public function testPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+
+ }
+
+ public function testFixedDiscountSetAsExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(8)
+ ->setVatPercent(0))
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+
+ }
+
+ public function testResponseOrderRowPriceSetAsInkVatAndVatPercentSetAmountAsIncVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+
+ }
+
+ public function testResponseFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+
+ }
+
+ public function testResponseDiscountSetAsIncVatWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+
+
+ }
+
+ public function testResponseDiscountSetAsExVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10)
+ ->setVatPercent(0))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+
+ }
+
+
+ public function testResponseDiscountPercentAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+
+ }
+
+ public function testResponseOrderSetAsIncVatAndExVatAndRelativeDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+
+ }
+
+ public function testResponseOrderAndFixedDiscountSetWithMixedVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(9.999)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+
+ }
+
+ public function testResponseOrderAndFixedDiscountSetWithMixedVat2()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(12.39876)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+
+ }
+
+ public function testResponseOrderAndFixedDiscountSetWithMixedVat3()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(9.999)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+
+ }
+
+ public function testTaloonRoundingExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(116.94)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(7.26)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(4.03)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("FI"))
+ ->setCountryCode("FI")
+ ->setCurrency("EUR")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(159.01, $request->amount);//sends the old way, so still wrong rounding
+
+ }
+
+ public function testTaloonRoundingIncVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(145.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(9.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(5.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("FI"))
+ ->setCountryCode("FI")
+ ->setCurrency("EUR")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->doRequest();
+ $this->assertEquals(1, $request->accepted);
+ $this->assertEquals(159.0, $request->amount);
+
+ }
+
+ // Test that test suite returns complete address in each country
+ // SE
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_SE()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("4605092222")
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate(date('c'));
+ $response = $order->useInvoicePayment()->doRequest();
+ //print_r($response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
+ // verify returned address
+ $this->assertEquals("Persson Tess T", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
+ $this->assertEquals("Testgatan 1", $response->customerIdentity->street);
+ $this->assertEquals("c/o Eriksson, Erik", $response->customerIdentity->coAddress);
+ $this->assertEquals("99999", $response->customerIdentity->zipCode);
+ $this->assertEquals("Stan", $response->customerIdentity->locality);
+ }
+
+ // NO
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_NO()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("17054512066")
+ )
+ ->setCountryCode("NO")
+ ->setOrderDate(date('c'));
+ $response = $order->useInvoicePayment()->doRequest();
+ //print_r($response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
+ // verify returned address
+ $this->assertEquals("Ola Normann", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
+ $this->assertEquals("Testveien 2", $response->customerIdentity->street);
+ $this->assertEquals("", $response->customerIdentity->coAddress);
+ $this->assertEquals("0359", $response->customerIdentity->zipCode);
+ $this->assertEquals("Oslo", $response->customerIdentity->locality);
+ }
+
+ // DK
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_DK()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("2603692503")
+ )
+ ->setCountryCode("DK")
+ ->setOrderDate(date('c'));
+ $response = $order->useInvoicePayment()->doRequest();
+ //print_r($response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
+ // verify returned address
+ $this->assertEquals("Hanne Jensen", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
+ $this->assertEquals("Testvejen 42", $response->customerIdentity->street);
+ $this->assertEquals("c/o Test A/s", $response->customerIdentity->coAddress);
+ $this->assertEquals("2100", $response->customerIdentity->zipCode);
+ $this->assertEquals("Københvn Ø", $response->customerIdentity->locality);
+ }
+
+ // FI
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_FI()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("160264-999N")
+ )
+ ->setCountryCode("FI")
+ ->setOrderDate(date('c'));
+ $response = $order->useInvoicePayment()->doRequest();
+ //print_r($response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
+ // verify returned address
+ $this->assertEquals("Kanerva Haapakoski Kukka-Maaria", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
+ $this->assertEquals("Atomitie 2 C", $response->customerIdentity->street);
+ $this->assertEquals("", $response->customerIdentity->coAddress);
+ $this->assertEquals("00370", $response->customerIdentity->zipCode);
+ $this->assertEquals("Helsinki", $response->customerIdentity->locality);
+ }
+
+ // DE
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_DE()
+ {
+ $this->markTestIncomplete("NL flow not maintained by webpay-dev");
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ ->setDescription("IntegrationTest")
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setBirthDate("19680403")
+ ->setName("Theo", "Giebel")
+ ->setStreetAddress("Zörgiebelweg", 21)
+ ->setZipCode("13591")
+ ->setLocality("BERLIN")
+ )
+ ->setCountryCode("DE")
+ ->setOrderDate(date('c'));
+ $response = $order->useInvoicePayment()->doRequest();
+ //print_r($response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
+ // verify returned address
+ $this->assertEquals("Theo Giebel", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
+ $this->assertEquals("Zörgiebelweg", $response->customerIdentity->street);
+ $this->assertEquals("21", $response->customerIdentity->houseNumber);
+ $this->assertEquals("", $response->customerIdentity->coAddress);
+ $this->assertEquals("13591", $response->customerIdentity->zipCode);
+ $this->assertEquals("BERLIN", $response->customerIdentity->locality);
+ }
+
+ // NL
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_NL()
+ {
+ $this->markTestIncomplete("NL flow not maintained by webpay-dev");
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ ->setDescription("IntegrationTest")
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setBirthDate("19550307")
+ ->setInitials("SB")
+ ->setName("Sneider", "Boasman")
+ ->setStreetAddress("Gate 42", 23)
+ ->setZipCode("1102 HG")
+ ->setLocality("BARENDRECHT")
+ )
+ ->setCountryCode("NL")
+ ->setOrderDate(date('c'));
+ $response = $order->useInvoicePayment()->doRequest();
+ //print_r($response);
+ $this->assertEquals(1, $response->accepted);
+ $this->assertTrue($response->customerIdentity instanceof CreateOrderIdentity);
+ // verify returned address
+ $this->assertEquals("Sneider Boasman", $response->customerIdentity->fullName); // Note: order may vary between countries, given by UC
+ $this->assertEquals("Gate 42", $response->customerIdentity->street);
+ $this->assertEquals("23", $response->customerIdentity->houseNumber);
+ $this->assertEquals("", $response->customerIdentity->coAddress);
+ $this->assertEquals("1102 HG", $response->customerIdentity->zipCode);
+ $this->assertEquals("BARENDRECHT", $response->customerIdentity->locality);
+ }
+
+ public function testInvoiceRequestNLReturnsSameAddress()
+ {
+ $this->markTestIncomplete("NL flow not maintained by webpay-dev");
+
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setBirthDate(1955, 03, 07)
+ ->setName("Sneider", "Boasman")
+ ->setStreetAddress("Gate 42", "23")// result of splitStreetAddress w/Svea testperson
+ ->setCoAddress(138)
+ ->setLocality("BARENDRECHT")
+ ->setZipCode("1102 HG")
+ ->setInitials("SB")
+ )
+ ->setCountryCode("NL")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertTrue($request->customerIdentity instanceof CreateOrderIdentity);
+ // verify returned address
+ $this->assertEquals("Sneider Boasman", $request->customerIdentity->fullName);
+ $this->assertEquals("Gate 42", $request->customerIdentity->street);
+ $this->assertEquals("23", $request->customerIdentity->houseNumber);
+ $this->assertEquals("1102 HG", $request->customerIdentity->zipCode);
+ $this->assertEquals("BARENDRECHT", $request->customerIdentity->locality);
+ }
+
+ public function testInvoiceRequestNLReturnsCorrectAddress()
+ {
+ $this->markTestIncomplete("NL flow not maintained by webpay-dev");
+
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setBirthDate(1955, 03, 07)
+ ->setName("Sneider", "Boasman")
+ ->setStreetAddress("Gate 42", "23")// result of splitStreetAddress w/Svea testperson
+ ->setCoAddress(138)
+ ->setLocality("BARENDRECHT")
+ ->setZipCode("1102 HG")
+ ->setInitials("SB")
+ )
+ ->setCountryCode("NL")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->doRequest();
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertTrue($request->customerIdentity instanceof CreateOrderIdentity);
+ // verify returned address
+ $this->assertEquals("Sneider Boasman", $request->customerIdentity->fullName);
+ $this->assertEquals("Gate 42", $request->customerIdentity->street);
+ $this->assertEquals("23", $request->customerIdentity->houseNumber);
+ $this->assertEquals("1102 HG", $request->customerIdentity->zipCode);
+ $this->assertEquals("BARENDRECHT", $request->customerIdentity->locality);
+
+ //
+ //
+ //
+ //
+ //
+ // 85997
+ // hollandtest
+ // hollandtest
+ //
+ //
+ //
+ //
+ // 1
+ // Product: Specification
+ // 100
+ // false
+ // 2
+ // st
+ // 25
+ // 0
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // Sneider Boasman
+ // Gate 42
+ // 138
+ // 1102 HG
+ // 23
+ // BARENDRECHT
+ // NL
+ // Individual
+ //
+ // Sneider
+ // Boasman
+ // SB
+ // 19550307
+ //
+ //
+ // 2012-12-12
+ //
+ //
+ // 33
+ // Invoice
+ //
+ //
+ //
+ //
+ //
+ }
+
+ public function testInvoiceRequestNLReproduceErrorIn471193()
+ {
+ $this->markTestIncomplete("NL flow not maintained by webpay-dev");
+
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setBirthDate(1955, 03, 07)// BirthDate and ZipCode is sufficient for a successful test order
+ ->setZipCode("1102 HG")//
+ ->setName("foo", "bar")
+ ->setStreetAddress("foo", "bar")
+ ->setCoAddress(1337)
+ ->setLocality("dns")
+ ->setInitials("nsl")
+ )
+ ->setCountryCode("NL")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->doRequest();
+ //->prepareRequest();
+ //var_dump($request->request->CreateOrderInformation->CustomerIdentity);
+
+ $this->assertEquals(1, $request->accepted);
+ $this->assertTrue($request->customerIdentity instanceof CreateOrderIdentity);
+
+ //print_r( $request->sveaOrderId);
+ // verify returned address is wrong
+ $this->assertNotEquals("Sneider Boasman", $request->customerIdentity->fullName);
+ $this->assertNotEquals("Gate 42", $request->customerIdentity->street);
+ $this->assertNotEquals("23", $request->customerIdentity->houseNumber);
+ $this->assertNotEquals("BARENDRECHT", $request->customerIdentity->locality);
+ //$this->assertNotEquals( "1102 HG", $request->customerIdentity->zipCode );
+
+ $this->assertEquals("foo bar", $request->customerIdentity->fullName);
+ $this->assertEquals("foo", $request->customerIdentity->street);
+ $this->assertEquals("bar", $request->customerIdentity->houseNumber);
+ $this->assertEquals("dns", $request->customerIdentity->locality);
+ $this->assertEquals("1102 HG", $request->customerIdentity->zipCode);
+
+
+ //
+ //
+ //
+ //
+ //
+ // 85997
+ // hollandtest
+ // hollandtest
+ //
+ //
+ // 133
+ //
+ //
+ // NTB03
+ // Making candles and soaps for dummies: Making candles and soaps for dummies
+ // 12.12
+ //
+ // 2
+ // st
+ // 25
+ // 0
+ //
+ //
+ // SHIP25
+ // Frakt / Shipping
+ // 8.66
+ //
+ // 1
+ // st
+ // 25
+ // 0
+ //
+ //
+ // HAND25
+ // Expeditionsavgift / Handling
+ // 2.51
+ //
+ // 1
+ // st
+ // 25
+ // 0
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // asdf ghij
+ // Postbus
+ //
+ //
+ // 1010 AB
+ // 626
+ // Amsterdam
+ // NL
+ // Individual
+ //
+ // asdf
+ // ghij
+ // ag
+ // 19550307
+ //
+ //
+ // 2014-11-19
+ //
+ //
+ // Invoice
+ //
+ //
+ //
+ //
+ //
+
+ }
+
+ function test_orderRow_discountPercent_not_used()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+ $this->assertEquals("125.00", $orderResponse->amount);
+ //print_r($orderResponse);
+
+ $query = WebPayAdmin::queryOrder($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals(100.00, $query->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(25.00, $query->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals(0.00, $query->numberedOrderRows[0]->discountPercent);
+ }
+
+ function test_orderRow_discountPercent_50percent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDiscountPercent(50)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+ $this->assertEquals("62.50", $orderResponse->amount);
+
+ $query = WebPayAdmin::queryOrder($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals(100.00, $query->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals(25.00, $query->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals(50.00, $query->numberedOrderRows[0]->discountPercent);
+ }
+
+ function test_orderRow_discountPercent_50_percent_order_sent_as_incvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderResponse = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(125.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDiscountPercent(50)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()->doRequest();
+ $this->assertEquals(1, $orderResponse->accepted);
+ $this->assertEquals("62.5", $orderResponse->amount); // this is where
+
+ $query = WebPayAdmin::queryOrder($config)
+ ->setCountryCode('SE')
+ ->setOrderId($orderResponse->sveaOrderId)
+ ->queryInvoiceOrder()->doRequest();
+ $this->assertEquals(1, $query->accepted);
+ $this->assertEquals(125.00, $query->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals(25.00, $query->numberedOrderRows[0]->vatPercent);
+ $this->assertEquals(50.00, $query->numberedOrderRows[0]->discountPercent);
+ }
+
+ // fixed discount -- created discount rows should use incvat + vatpercent
+ /// fixed discount examples:
+ // single order rows vat rate
+ public function test_fixedDiscount_amount_with_incvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("incvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("incvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ ->setName("incvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+
+ // check that service accepts order
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ }
+
+ // single order rows vat rate
+ public function test_fixedDiscount_amount_with_exvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ }
+
+ public function testOrderAndFixedDiscountSetWithMixedVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(9.999)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ // 9.999 *1.24 = 12.39876
+ $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ // check that service accepts order
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ }
+
+ public function testOrderAndFixedDiscountSetWithMixedVat3()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(9.999)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12");
+ $request = $order->useInvoicePayment()->prepareRequest();
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ // 9.999 *1.24 = 12.39876
+ $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ // check that service accepts order
+ $response = $order->useInvoicePayment()->doRequest();
+ $this->assertEquals(true, $response->accepted);
+ }
}
\ No newline at end of file
diff --git a/test/IntegrationTest/WebService/Payment/PaymentPlanPaymentIntegrationTest.php b/test/IntegrationTest/WebService/Payment/PaymentPlanPaymentIntegrationTest.php
index 8017095b..169eb8bd 100644
--- a/test/IntegrationTest/WebService/Payment/PaymentPlanPaymentIntegrationTest.php
+++ b/test/IntegrationTest/WebService/Payment/PaymentPlanPaymentIntegrationTest.php
@@ -16,43 +16,43 @@
class PaymentPlanPaymentIntegrationTest extends \PHPUnit\Framework\TestCase
{
- public function testPaymentPlanRequestReturnsAcceptedResult()
- {
- $config = ConfigurationService::getDefaultConfig();
- $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountExVat(1000.00)
- ->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("test@svea.com")
- ->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();
+ public function testPaymentPlanRequestReturnsAcceptedResult()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $campaigncode = TestUtil::getGetPaymentPlanParamsForTesting();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountExVat(1000.00)
+ ->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("test@svea.com")
+ ->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);
- }
+ $this->assertEquals(1, $request->accepted);
+ }
}
diff --git a/test/TestUtil.php b/test/TestUtil.php
index c00e31dd..cbdc2902 100644
--- a/test/TestUtil.php
+++ b/test/TestUtil.php
@@ -14,281 +14,281 @@
class TestUtil
{
- /**
- * creates a populated order object for use in tests
- *
- * @return \Svea\WebPay\BuildOrder\createOrderBuilder object
- *
- */
- public static function createOrder($customer = NULL)
- {
+ /**
+ * creates a populated order object for use in tests
+ *
+ * @return \Svea\WebPay\BuildOrder\createOrderBuilder object
+ *
+ */
+ public static function createOrder($customer = NULL)
+ {
- // poor man's overloading
- if ($customer == NULL) {
- $customer = TestUtil::createIndividualCustomer("SE");
- }
+ // poor man's overloading
+ if ($customer == NULL) {
+ $customer = TestUtil::createIndividualCustomer("SE");
+ }
- $config = ConfigurationService::getDefaultConfig();
+ $config = ConfigurationService::getDefaultConfig();
- $orderObject = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails($customer)
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate(date('c'));
+ $orderObject = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails($customer)
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate(date('c'));
- return $orderObject;
- }
+ return $orderObject;
+ }
- /**
- * Returns an individual customer object.
- * The object is populated using test customer data for the given country.
- *
- * Defaults to a SE customer in good credit standing with Svea, i.e. any
- * transaction using this customer should be accepted by Svea services.
- *
- * @param string $country -- accepts SE (default) and NL
- * @return \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer
- * @throws Exception
- */
- public static function createIndividualCustomer($country = "SE")
- {
- switch (strtoupper($country)) {
+ /**
+ * Returns an individual customer object.
+ * The object is populated using test customer data for the given country.
+ *
+ * Defaults to a SE customer in good credit standing with Svea, i.e. any
+ * transaction using this customer should be accepted by Svea services.
+ *
+ * @param string $country -- accepts SE (default) and NL
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\IndividualCustomer
+ * @throws Exception
+ */
+ public static function createIndividualCustomer($country = "SE")
+ {
+ switch (strtoupper($country)) {
- //####1.3.1 Options for individual customers
- //```php
- //->addCustomerDetails(
- // Svea\WebPay\WebPayItem::individualCustomer()
- // ->setNationalIdNumber(194605092222) //Required for individual customers in SE, NO, DK, FI
- // ->setInitials("SB") //Required for individual customers in NL
- // ->setBirthDate(1923, 12, 20) //Required for individual customers in NL and DE
- // ->setName("Tess", "Testson") //Required for individual customers in NL and DE
- // ->setStreetAddress("Gatan", 23) //Required in NL and DE
- // ->setZipCode(9999) //Required in NL and DE
- // ->setLocality("Stan") //Required in NL and DE
- // ->setEmail("test@svea.com") //Optional but desirable
- // ->setIpAddress("123.123.123") //Optional but desirable
- // ->setCoAddress("c/o Eriksson") //Optional
- // ->setPhoneNumber(999999) //Optional
- // )
+ //####1.3.1 Options for individual customers
+ //```php
+ //->addCustomerDetails(
+ // Svea\WebPay\WebPayItem::individualCustomer()
+ // ->setNationalIdNumber(194605092222) //Required for individual customers in SE, NO, DK, FI
+ // ->setInitials("SB") //Required for individual customers in NL
+ // ->setBirthDate(1923, 12, 20) //Required for individual customers in NL and DE
+ // ->setName("Tess", "Testson") //Required for individual customers in NL and DE
+ // ->setStreetAddress("Gatan", 23) //Required in NL and DE
+ // ->setZipCode(9999) //Required in NL and DE
+ // ->setLocality("Stan") //Required in NL and DE
+ // ->setEmail("test@svea.com") //Optional but desirable
+ // ->setIpAddress("123.123.123") //Optional but desirable
+ // ->setCoAddress("c/o Eriksson") //Optional
+ // ->setPhoneNumber(999999) //Optional
+ // )
- case("NL"):
- return WebPayItem::individualCustomer()
- ->setBirthDate(1955, 03, 07)
- ->setName("Sneider", "Boasman")
- ->setStreetAddress("Gate", 42)
- ->setCoAddress(138)
- ->setLocality("BARENDRECHT")
- ->setZipCode("1102 HG")
- ->setInitials("SB");
- break;
+ case("NL"):
+ return WebPayItem::individualCustomer()
+ ->setBirthDate(1955, 03, 07)
+ ->setName("Sneider", "Boasman")
+ ->setStreetAddress("Gate", 42)
+ ->setCoAddress(138)
+ ->setLocality("BARENDRECHT")
+ ->setZipCode("1102 HG")
+ ->setInitials("SB");
+ break;
- case("SE"):
- return WebPayItem::individualCustomer()
- ->setNationalIdNumber("194605092222")
- ->setBirthDate(1946, 05, 9)
- ->setName("Tess T", "Persson")
- ->setStreetAddress("Testgatan", 1)
- ->setCoAddress("c/o Eriksson, Erik")
- ->setLocality("Stan")
- ->setZipCode("99999");
- break;
- case("FI"):
- return WebPayItem::individualCustomer()
- ->setNationalIdNumber("160264-999N");
- break;
+ case("SE"):
+ return WebPayItem::individualCustomer()
+ ->setNationalIdNumber("194605092222")
+ ->setBirthDate(1946, 05, 9)
+ ->setName("Tess T", "Persson")
+ ->setStreetAddress("Testgatan", 1)
+ ->setCoAddress("c/o Eriksson, Erik")
+ ->setLocality("Stan")
+ ->setZipCode("99999");
+ break;
+ case("FI"):
+ return WebPayItem::individualCustomer()
+ ->setNationalIdNumber("160264-999N");
+ break;
- default:
- throw new Exception("undefined IndividualCustomerCountry in Svea\WebPay\Test\TestUtil -- add country and credentials");
- break;
- }
- }
+ default:
+ throw new Exception("undefined IndividualCustomerCountry in Svea\WebPay\Test\TestUtil -- add country and credentials");
+ break;
+ }
+ }
- /**
- * Creates an OrderRow object for use in populating order objects.
- * @param float $amount , defaults to 100
- * @param int $amount , defaults to 2
- *
- * @return \Svea\WebPay\BuildOrder\RowBuilders\OrderRow object
- */
- public static function createOrderRow($amount = 100.00, $quantity = 2)
- {
- return WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity($quantity)
- ->setAmountExVat($amount)
- ->setDescription("Specification")
- ->setName('Product')
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0);
- }
+ /**
+ * Creates an OrderRow object for use in populating order objects.
+ * @param float $amount , defaults to 100
+ * @param int $amount , defaults to 2
+ *
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\OrderRow object
+ */
+ public static function createOrderRow($amount = 100.00, $quantity = 2)
+ {
+ return WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity($quantity)
+ ->setAmountExVat($amount)
+ ->setDescription("Specification")
+ ->setName('Product')
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0);
+ }
- /**
- * creates a populated order object for use in tests
- *
- * @return \Svea\WebPay\BuildOrder\createOrderBuilder object
- *
- */
- public static function createOrderWithoutOrderRows($customer = NULL)
- {
+ /**
+ * creates a populated order object for use in tests
+ *
+ * @return \Svea\WebPay\BuildOrder\createOrderBuilder object
+ *
+ */
+ public static function createOrderWithoutOrderRows($customer = NULL)
+ {
- // poor man's overloading
- if ($customer == NULL) {
- $customer = TestUtil::createIndividualCustomer("SE");
- }
+ // poor man's overloading
+ if ($customer == NULL) {
+ $customer = TestUtil::createIndividualCustomer("SE");
+ }
- $config = ConfigurationService::getDefaultConfig();
+ $config = ConfigurationService::getDefaultConfig();
- $orderObject = WebPay::createOrder($config)
- ->addCustomerDetails($customer)
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate(date('c'));
+ $orderObject = WebPay::createOrder($config)
+ ->addCustomerDetails($customer)
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate(date('c'));
- return $orderObject;
- }
+ return $orderObject;
+ }
- /**
- * Creates an NumberedOrderRow object for use in populating order objects.
- * @param float $amount , defaults to 100
- * @param int $amount , defaults to 2
- *
- * @return \Svea\WebPay\BuildOrder\RowBuilders\OrderRow object
- */
- public static function createNumberedOrderRow($amount = 100.00, $quantity = 1, $number = 1)
- {
- return WebPayItem::numberedOrderRow()
- ->setArticleNumber("1")
- ->setQuantity($quantity)
- ->setAmountExVat($amount)
- ->setDescription("Specification")
- ->setName('Product')
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- ->setRowNumber($number);
- }
+ /**
+ * Creates an NumberedOrderRow object for use in populating order objects.
+ * @param float $amount , defaults to 100
+ * @param int $amount , defaults to 2
+ *
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\OrderRow object
+ */
+ public static function createNumberedOrderRow($amount = 100.00, $quantity = 1, $number = 1)
+ {
+ return WebPayItem::numberedOrderRow()
+ ->setArticleNumber("1")
+ ->setQuantity($quantity)
+ ->setAmountExVat($amount)
+ ->setDescription("Specification")
+ ->setName('Product')
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ ->setRowNumber($number);
+ }
- public static function createCompanyCustomer($country = "SE")
- {
- switch (strtoupper($country)) {
+ public static function createCompanyCustomer($country = "SE")
+ {
+ switch (strtoupper($country)) {
- //####1.3.2 Options for company customers
- //```php
- //->addCustomerDetails(
- // Svea\WebPay\WebPayItem::companyCustomer()
- // ->setNationalIdNumber(2345234) //Required in SE, NO, DK, FI
- // ->setVatNumber("NL2345234") //Required in NL and DE
- // ->setCompanyName("TestCompagniet") //Required in NL and DE
- // ->setStreetAddress("Gatan", 23) //Required in NL and DE
- // ->setZipCode(9999) //Required in NL and DE
- // ->setLocality("Stan") //Required in NL and DE
- // ->setEmail("test@svea.com") //Optional but desirable
- // ->setIpAddress("123.123.123") //Optional but desirable
- // ->setCoAddress("c/o Eriksson") //Optional
- // ->setPhoneNumber(999999) //Optional
- // ->setAddressSelector("7fd7768") //Optional, string recieved from Svea\WebPay\WebPay::getAddress() request
- // )
+ //####1.3.2 Options for company customers
+ //```php
+ //->addCustomerDetails(
+ // Svea\WebPay\WebPayItem::companyCustomer()
+ // ->setNationalIdNumber(2345234) //Required in SE, NO, DK, FI
+ // ->setVatNumber("NL2345234") //Required in NL and DE
+ // ->setCompanyName("TestCompagniet") //Required in NL and DE
+ // ->setStreetAddress("Gatan", 23) //Required in NL and DE
+ // ->setZipCode(9999) //Required in NL and DE
+ // ->setLocality("Stan") //Required in NL and DE
+ // ->setEmail("test@svea.com") //Optional but desirable
+ // ->setIpAddress("123.123.123") //Optional but desirable
+ // ->setCoAddress("c/o Eriksson") //Optional
+ // ->setPhoneNumber(999999) //Optional
+ // ->setAddressSelector("7fd7768") //Optional, string recieved from Svea\WebPay\WebPay::getAddress() request
+ // )
- case("SE"):
- return WebPayItem::companyCustomer()
- ->setNationalIdNumber("4608142222")
- ->setCompanyName("Tess T", "Persson")
- ->setStreetAddress("Testgatan", 1)
- ->setCoAddress("c/o Eriksson, Erik")
- ->setLocality("Stan")
- ->setZipCode("99999");
- break;
+ case("SE"):
+ return WebPayItem::companyCustomer()
+ ->setNationalIdNumber("4608142222")
+ ->setCompanyName("Tess T", "Persson")
+ ->setStreetAddress("Testgatan", 1)
+ ->setCoAddress("c/o Eriksson, Erik")
+ ->setLocality("Stan")
+ ->setZipCode("99999");
+ break;
- default:
- throw new Exception("undefined CompanyCustomerCountry in Svea\WebPay\Test\TestUtil -- add country and credentials");
- break;
- }
- }
+ default:
+ throw new Exception("undefined CompanyCustomerCountry in Svea\WebPay\Test\TestUtil -- add country and credentials");
+ break;
+ }
+ }
- /**
- * Creates an OrderRow object with amount 100 and a given tax rate
- *
- * @param int vatPercent the tax rate for this order row (defaults to 25 if omitted)
- * @return \Svea\WebPay\BuildOrder\RowBuilders\OrderRow object
- */
- public static function createOrderRowWithVat($vatPercent = 25)
- {
- return WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->setDescription("Specification")
- ->setName('Prod')
- ->setUnit("st")
- ->setVatPercent($vatPercent)
- ->setDiscountPercent(0);
- }
+ /**
+ * Creates an OrderRow object with amount 100 and a given tax rate
+ *
+ * @param int vatPercent the tax rate for this order row (defaults to 25 if omitted)
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\OrderRow object
+ */
+ public static function createOrderRowWithVat($vatPercent = 25)
+ {
+ return WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->setDescription("Specification")
+ ->setName('Prod')
+ ->setUnit("st")
+ ->setVatPercent($vatPercent)
+ ->setDiscountPercent(0);
+ }
- public static function createHostedOrderRow()
- {
- return WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1);
- }
+ public static function createHostedOrderRow()
+ {
+ return WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1);
+ }
- /**
- * Use to get a campaign code to i.e. use as argument to usePaymentPlanPayment()
- * @param string $country
- * @return string the first available campaignCode
- */
- public static function getGetPaymentPlanParamsForTesting($country = "SE")
- {
- $addressRequest = WebPay::getPaymentPlanParams(ConfigurationService::getDefaultConfig());
- $response = $addressRequest
- ->setCountryCode($country)
- ->doRequest();
+ /**
+ * Use to get a campaign code to i.e. use as argument to usePaymentPlanPayment()
+ * @param string $country
+ * @return string the first available campaignCode
+ */
+ public static function getGetPaymentPlanParamsForTesting($country = "SE")
+ {
+ $addressRequest = WebPay::getPaymentPlanParams(ConfigurationService::getDefaultConfig());
+ $response = $addressRequest
+ ->setCountryCode($country)
+ ->doRequest();
- return $response->campaignCodes[0]->campaignCode;
- }
+ return $response->campaignCodes[0]->campaignCode;
+ }
- /**
- * Returns ShippingFeeRow to use as shorthand in testFunctions
- * Use function run($functionname) to run shorthand function
- * @return type
- */
- public function buildShippingFee()
- {
- return function ($orderbuilder) {
- return $orderbuilder
- ->addFee(
- WebPayItem::shippingFee()
- ->setShippingId('33')
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountExVat(50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- );
- };
- }
+ /**
+ * Returns ShippingFeeRow to use as shorthand in testFunctions
+ * Use function run($functionname) to run shorthand function
+ * @return type
+ */
+ public function buildShippingFee()
+ {
+ return function ($orderbuilder) {
+ return $orderbuilder
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setShippingId('33')
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountExVat(50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ );
+ };
+ }
- /**
- * Returns InvoicefeeRow to use as shorthand in testFunctions
- * Use function run($functionname) to run shorthand function
- * @return type
- */
- public function buildInvoiceFee()
- {
- return function ($orderbuilder) {
- return $orderbuilder
- ->addFee(
- WebPayItem::invoiceFee()
- ->setName('Svea fee')
- ->setDescription("Fee for invoice")
- ->setAmountExVat(50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- );
- };
- }
+ /**
+ * Returns InvoicefeeRow to use as shorthand in testFunctions
+ * Use function run($functionname) to run shorthand function
+ * @return type
+ */
+ public function buildInvoiceFee()
+ {
+ return function ($orderbuilder) {
+ return $orderbuilder
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setName('Svea fee')
+ ->setDescription("Fee for invoice")
+ ->setAmountExVat(50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ );
+ };
+ }
}
diff --git a/test/UnitTest/AdminService/AddOrderRowsRequestTest.php b/test/UnitTest/AdminService/AddOrderRowsRequestTest.php
index 8af914e3..92c4b54a 100644
--- a/test/UnitTest/AdminService/AddOrderRowsRequestTest.php
+++ b/test/UnitTest/AdminService/AddOrderRowsRequestTest.php
@@ -17,595 +17,595 @@
class AddOrderRowsRequestTest extends \PHPUnit\Framework\TestCase
{
- public $builderObject;
-
- public function setUp()
- {
- $this->builderObject = new OrderBuilder(ConfigurationService::getDefaultConfig());
- $this->builderObject->orderId = 123456;
- $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
- $this->builderObject->countryCode = "SE";
- $this->builderObject->orderRows = array(TestUtil::createOrderRow(10.00));
- }
-
- public function testClassExists()
- {
- $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
- $this->assertInstanceOf('Svea\WebPay\AdminService\AddOrderRowsRequest', $AddOrderRowsRequestObject);
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderId is required.
- */
- public function test_validate_throws_exception_on_missing_OrderId()
- {
- unset($this->builderObject->orderId);
- $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
- $request = $AddOrderRowsRequestObject->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderType is required.
- */
- public function test_validate_throws_exception_on_missing_OrderType()
- {
- unset($this->builderObject->orderType);
- $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
- $request = $AddOrderRowsRequestObject->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : countryCode is required.
- */
- public function test_validate_throws_exception_on_missing_CountryCode()
- {
- unset($this->builderObject->countryCode);
- $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
- $request = $AddOrderRowsRequestObject->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderRows is required.
- */
- public function test_validate_throws_exception_on_missing_orderRows()
- {
- unset($this->builderObject->orderRows);
- $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
- $request = $AddOrderRowsRequestObject->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing order row vat information : cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent.
- */
- public function test_validate_throws_exception_on_orderRows_missing_vat_information_none()
- {
- $this->builderObject->orderRows[] = WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- //->setAmountExVat( 1.00 )
- //->setAmountIncVat( 1.00 * 1.25 )
- //->setVatPercent(25)
- ->setDescription("Specification")
- ->setName('Product')
- ->setUnit("st")
- ->setDiscountPercent(0);
- $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
- $request = $AddOrderRowsRequestObject->prepareRequest();
- }
-
- //outcommented cause added param that make test fail
-// public function test_prepareRequest_is_well_formed() {
+ public $builderObject;
+
+ public function setUp()
+ {
+ $this->builderObject = new OrderBuilder(ConfigurationService::getDefaultConfig());
+ $this->builderObject->orderId = 123456;
+ $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
+ $this->builderObject->countryCode = "SE";
+ $this->builderObject->orderRows = [TestUtil::createOrderRow(10.00)];
+ }
+
+ public function testClassExists()
+ {
+ $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
+ $this->assertInstanceOf('Svea\WebPay\AdminService\AddOrderRowsRequest', $AddOrderRowsRequestObject);
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderId is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderId()
+ {
+ unset($this->builderObject->orderId);
+ $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
+ $request = $AddOrderRowsRequestObject->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderType is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderType()
+ {
+ unset($this->builderObject->orderType);
+ $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
+ $request = $AddOrderRowsRequestObject->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : countryCode is required.
+ */
+ public function test_validate_throws_exception_on_missing_CountryCode()
+ {
+ unset($this->builderObject->countryCode);
+ $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
+ $request = $AddOrderRowsRequestObject->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderRows is required.
+ */
+ public function test_validate_throws_exception_on_missing_orderRows()
+ {
+ unset($this->builderObject->orderRows);
+ $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
+ $request = $AddOrderRowsRequestObject->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing order row vat information : cannot calculate orderRow vatPercent, need at least two of amountExVat, amountIncVat and vatPercent.
+ */
+ public function test_validate_throws_exception_on_orderRows_missing_vat_information_none()
+ {
+ $this->builderObject->orderRows[] = WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ //->setAmountExVat( 1.00 )
+ //->setAmountIncVat( 1.00 * 1.25 )
+ //->setVatPercent(25)
+ ->setDescription("Specification")
+ ->setName('Product')
+ ->setUnit("st")
+ ->setDiscountPercent(0);
+ $AddOrderRowsRequestObject = new AddOrderRowsRequest($this->builderObject);
+ $request = $AddOrderRowsRequestObject->prepareRequest();
+ }
+
+ //outcommented cause added param that make test fail
+// public function test_prepareRequest_is_well_formed() {
//
-// // add order rows to builderobject
-// $this->builderObject->orderRows[] = Svea\WebPay\Test\TestUtil::createOrderRow( 1.00, 1 );
-// $this->builderObject->orderId = 123456;
+// // add order rows to builderobject
+// $this->builderObject->orderRows[] = Svea\WebPay\Test\TestUtil::createOrderRow( 1.00, 1 );
+// $this->builderObject->orderId = 123456;
//
-// $addOrderRowsRequest = new Svea\WebPay\AdminService\AddOrderRowsRequest( $this->builderObject );
-// $addOrderRowsSoapRequest = $addOrderRowsRequest->prepareRequest();
+// $addOrderRowsRequest = new Svea\WebPay\AdminService\AddOrderRowsRequest( $this->builderObject );
+// $addOrderRowsSoapRequest = $addOrderRowsRequest->prepareRequest();
//
-// print_r( $addOrderRowsSoapRequest );
-// $this->assertEquals($this->prepareRequest_addOrderRowsSoapRequest(), $addOrderRowsSoapRequest);
-// }
+// print_r( $addOrderRowsSoapRequest );
+// $this->assertEquals($this->prepareRequest_addOrderRowsSoapRequest(), $addOrderRowsSoapRequest);
+// }
- public function test_generate_prepareRequest_addOrderRowsSoapRequest()
- {
+ public function test_generate_prepareRequest_addOrderRowsSoapRequest()
+ {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'run once to generate testdata for prepareRequest_addOrderRowsSoapRequest()'
- );
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'run once to generate testdata for prepareRequest_addOrderRowsSoapRequest()'
+ );
- // add order rows to builderobject
- $this->builderObject->orderRows[] = TestUtil::createOrderRow(1.00, 1);
- $this->builderObject->orderId = 123456;
+ // add order rows to builderobject
+ $this->builderObject->orderRows[] = TestUtil::createOrderRow(1.00, 1);
+ $this->builderObject->orderId = 123456;
- $addOrderRowsRequest = new AddOrderRowsRequest($this->builderObject);
- $addOrderRowsSoapRequest = $addOrderRowsRequest->prepareRequest();
+ $addOrderRowsRequest = new AddOrderRowsRequest($this->builderObject);
+ $addOrderRowsSoapRequest = $addOrderRowsRequest->prepareRequest();
- // used once to get data for addOrderRowsRequest() below
- //print_r( "\ncopy the following to prepareRequest_addOrderRowsSoapRequest:\n\n".serialize($addOrderRowsSoapRequest)."\n\n" );
- }
+ // used once to get data for addOrderRowsRequest() below
+ //print_r( "\ncopy the following to prepareRequest_addOrderRowsSoapRequest:\n\n".serialize($addOrderRowsSoapRequest)."\n\n" );
+ }
- private function prepareRequest_addOrderRowsSoapRequest()
- {
+ private function prepareRequest_addOrderRowsSoapRequest()
+ {
- $serialised_addOrderRowsSoapResponse = 'O:47:"Svea\WebPay\AdminService\AdminSoap\AddOrderRowsRequest":5:{s:14:"Authentication";O:7:"SoapVar":6:{s:8:"enc_type";i:301;s:9:"enc_value";O:42:"Svea\WebPay\AdminService\AdminSoap\Authentication":2:{s:8:"Password";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:11:"sverigetest";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:8:"Password";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}s:8:"Username";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:11:"sverigetest";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:8:"Username";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}}s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:14:"Authentication";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}s:8:"ClientId";O:7:"SoapVar":6:{s:8:"enc_type";i:134;s:9:"enc_value";i:79021;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:8:"ClientId";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}s:9:"OrderRows";O:7:"SoapVar":6:{s:8:"enc_type";i:301;s:9:"enc_value";O:7:"SoapVar":2:{s:8:"enc_type";i:301;s:9:"enc_value";a:2:{i:0;O:7:"SoapVar":4:{s:8:"enc_type";i:301;s:9:"enc_value";O:36:"Svea\WebPay\AdminService\AdminSoap\OrderRow":7:{s:13:"ArticleNumber";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:1:"1";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:13:"ArticleNumber";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:11:"Description";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:22:"Product: Specification";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:11:"Description";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:15:"DiscountPercent";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:0;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:15:"DiscountPercent";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:13:"NumberOfUnits";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:2;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:13:"NumberOfUnits";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:12:"PricePerUnit";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";d:10;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:12:"PricePerUnit";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:4:"Unit";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:2:"st";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:4:"Unit";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:10:"VatPercent";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:25;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:10:"VatPercent";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}}s:8:"enc_name";s:8:"OrderRow";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}i:1;O:7:"SoapVar":4:{s:8:"enc_type";i:301;s:9:"enc_value";O:36:"Svea\WebPay\AdminService\AdminSoap\OrderRow":7:{s:13:"ArticleNumber";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:1:"1";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:13:"ArticleNumber";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:11:"Description";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:22:"Product: Specification";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:11:"Description";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:15:"DiscountPercent";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:0;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:15:"DiscountPercent";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:13:"NumberOfUnits";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:1;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:13:"NumberOfUnits";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:12:"PricePerUnit";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";d:1;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:12:"PricePerUnit";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:4:"Unit";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:2:"st";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:4:"Unit";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:10:"VatPercent";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:25;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:10:"VatPercent";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}}s:8:"enc_name";s:8:"OrderRow";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}}}s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:9:"OrderRows";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}s:9:"OrderType";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:7:"Invoice";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:9:"OrderType";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}s:11:"SveaOrderId";O:7:"SoapVar":6:{s:8:"enc_type";i:134;s:9:"enc_value";i:123456;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:11:"SveaOrderId";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}}';
+ $serialised_addOrderRowsSoapResponse = 'O:47:"Svea\WebPay\AdminService\AdminSoap\AddOrderRowsRequest":5:{s:14:"Authentication";O:7:"SoapVar":6:{s:8:"enc_type";i:301;s:9:"enc_value";O:42:"Svea\WebPay\AdminService\AdminSoap\Authentication":2:{s:8:"Password";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:11:"sverigetest";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:8:"Password";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}s:8:"Username";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:11:"sverigetest";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:8:"Username";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}}s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:14:"Authentication";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}s:8:"ClientId";O:7:"SoapVar":6:{s:8:"enc_type";i:134;s:9:"enc_value";i:79021;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:8:"ClientId";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}s:9:"OrderRows";O:7:"SoapVar":6:{s:8:"enc_type";i:301;s:9:"enc_value";O:7:"SoapVar":2:{s:8:"enc_type";i:301;s:9:"enc_value";a:2:{i:0;O:7:"SoapVar":4:{s:8:"enc_type";i:301;s:9:"enc_value";O:36:"Svea\WebPay\AdminService\AdminSoap\OrderRow":7:{s:13:"ArticleNumber";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:1:"1";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:13:"ArticleNumber";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:11:"Description";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:22:"Product: Specification";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:11:"Description";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:15:"DiscountPercent";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:0;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:15:"DiscountPercent";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:13:"NumberOfUnits";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:2;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:13:"NumberOfUnits";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:12:"PricePerUnit";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";d:10;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:12:"PricePerUnit";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:4:"Unit";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:2:"st";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:4:"Unit";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:10:"VatPercent";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:25;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:10:"VatPercent";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}}s:8:"enc_name";s:8:"OrderRow";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}i:1;O:7:"SoapVar":4:{s:8:"enc_type";i:301;s:9:"enc_value";O:36:"Svea\WebPay\AdminService\AdminSoap\OrderRow":7:{s:13:"ArticleNumber";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:1:"1";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:13:"ArticleNumber";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:11:"Description";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:22:"Product: Specification";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:11:"Description";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:15:"DiscountPercent";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:0;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:15:"DiscountPercent";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:13:"NumberOfUnits";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:1;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:13:"NumberOfUnits";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:12:"PricePerUnit";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";d:1;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:12:"PricePerUnit";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:4:"Unit";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:2:"st";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:4:"Unit";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}s:10:"VatPercent";O:7:"SoapVar":6:{s:8:"enc_type";i:103;s:9:"enc_value";i:25;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:10:"VatPercent";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}}s:8:"enc_name";s:8:"OrderRow";s:10:"enc_namens";s:62:"http://schemas.datacontract.org/2004/07/DataObjects.Webservice";}}}s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:9:"OrderRows";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}s:9:"OrderType";O:7:"SoapVar":6:{s:8:"enc_type";i:101;s:9:"enc_value";s:7:"Invoice";s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:9:"OrderType";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}s:11:"SveaOrderId";O:7:"SoapVar":6:{s:8:"enc_type";i:134;s:9:"enc_value";i:123456;s:9:"enc_stype";s:1:"-";s:6:"enc_ns";s:2:"--";s:8:"enc_name";s:11:"SveaOrderId";s:10:"enc_namens";s:65:"http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service";}}';
//Svea\WebPay\AdminService\AdminSoap\AddOrderRowsRequest Object
//(
-// [Authentication] => SoapVar Object
-// (
-// [enc_type] => 301
-// [enc_value] => Svea\WebPay\AdminService\AdminSoap\Authentication Object
-// (
-// [Password] => SoapVar Object
-// (
-// [enc_type] => 101
-// [enc_value] => sverigetest
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => Password
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
-// )
+// [Authentication] => SoapVar Object
+// (
+// [enc_type] => 301
+// [enc_value] => Svea\WebPay\AdminService\AdminSoap\Authentication Object
+// (
+// [Password] => SoapVar Object
+// (
+// [enc_type] => 101
+// [enc_value] => sverigetest
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => Password
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
+// )
//
-// [Username] => SoapVar Object
-// (
-// [enc_type] => 101
-// [enc_value] => sverigetest
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => Username
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
-// )
+// [Username] => SoapVar Object
+// (
+// [enc_type] => 101
+// [enc_value] => sverigetest
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => Username
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
+// )
//
-// )
+// )
//
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => Authentication
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
-// )
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => Authentication
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
+// )
//
-// [ClientId] => SoapVar Object
-// (
-// [enc_type] => 134
-// [enc_value] => 79021
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => ClientId
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
-// )
+// [ClientId] => SoapVar Object
+// (
+// [enc_type] => 134
+// [enc_value] => 79021
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => ClientId
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
+// )
//
-// [OrderRows] => SoapVar Object
-// (
-// [enc_type] => 301
-// [enc_value] => SoapVar Object
-// (
-// [enc_type] => 301
-// [enc_value] => Array
-// (
-// [0] => SoapVar Object
-// (
-// [enc_type] => 301
-// [enc_value] => Svea\WebPay\AdminService\AdminSoap\OrderRow Object
-// (
-// [ArticleNumber] => SoapVar Object
-// (
-// [enc_type] => 101
-// [enc_value] => 1
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => ArticleNumber
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [OrderRows] => SoapVar Object
+// (
+// [enc_type] => 301
+// [enc_value] => SoapVar Object
+// (
+// [enc_type] => 301
+// [enc_value] => Array
+// (
+// [0] => SoapVar Object
+// (
+// [enc_type] => 301
+// [enc_value] => Svea\WebPay\AdminService\AdminSoap\OrderRow Object
+// (
+// [ArticleNumber] => SoapVar Object
+// (
+// [enc_type] => 101
+// [enc_value] => 1
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => ArticleNumber
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [Description] => SoapVar Object
-// (
-// [enc_type] => 101
-// [enc_value] => Product: Specification
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => Description
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [Description] => SoapVar Object
+// (
+// [enc_type] => 101
+// [enc_value] => Product: Specification
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => Description
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [DiscountPercent] => SoapVar Object
-// (
-// [enc_type] => 103
-// [enc_value] => 0
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => DiscountPercent
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [DiscountPercent] => SoapVar Object
+// (
+// [enc_type] => 103
+// [enc_value] => 0
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => DiscountPercent
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [NumberOfUnits] => SoapVar Object
-// (
-// [enc_type] => 103
-// [enc_value] => 2
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => NumberOfUnits
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [NumberOfUnits] => SoapVar Object
+// (
+// [enc_type] => 103
+// [enc_value] => 2
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => NumberOfUnits
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [PricePerUnit] => SoapVar Object
-// (
-// [enc_type] => 103
-// [enc_value] => 10
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => PricePerUnit
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [PricePerUnit] => SoapVar Object
+// (
+// [enc_type] => 103
+// [enc_value] => 10
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => PricePerUnit
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [Unit] => SoapVar Object
-// (
-// [enc_type] => 101
-// [enc_value] => st
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => Unit
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [Unit] => SoapVar Object
+// (
+// [enc_type] => 101
+// [enc_value] => st
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => Unit
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [VatPercent] => SoapVar Object
-// (
-// [enc_type] => 103
-// [enc_value] => 25
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => VatPercent
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [VatPercent] => SoapVar Object
+// (
+// [enc_type] => 103
+// [enc_value] => 25
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => VatPercent
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// )
+// )
//
-// [enc_name] => OrderRow
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [enc_name] => OrderRow
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [1] => SoapVar Object
-// (
-// [enc_type] => 301
-// [enc_value] => Svea\WebPay\AdminService\AdminSoap\OrderRow Object
-// (
-// [ArticleNumber] => SoapVar Object
-// (
-// [enc_type] => 101
-// [enc_value] => 1
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => ArticleNumber
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [1] => SoapVar Object
+// (
+// [enc_type] => 301
+// [enc_value] => Svea\WebPay\AdminService\AdminSoap\OrderRow Object
+// (
+// [ArticleNumber] => SoapVar Object
+// (
+// [enc_type] => 101
+// [enc_value] => 1
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => ArticleNumber
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [Description] => SoapVar Object
-// (
-// [enc_type] => 101
-// [enc_value] => Product: Specification
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => Description
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [Description] => SoapVar Object
+// (
+// [enc_type] => 101
+// [enc_value] => Product: Specification
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => Description
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [DiscountPercent] => SoapVar Object
-// (
-// [enc_type] => 103
-// [enc_value] => 0
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => DiscountPercent
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [DiscountPercent] => SoapVar Object
+// (
+// [enc_type] => 103
+// [enc_value] => 0
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => DiscountPercent
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [NumberOfUnits] => SoapVar Object
-// (
-// [enc_type] => 103
-// [enc_value] => 1
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => NumberOfUnits
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [NumberOfUnits] => SoapVar Object
+// (
+// [enc_type] => 103
+// [enc_value] => 1
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => NumberOfUnits
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [PricePerUnit] => SoapVar Object
-// (
-// [enc_type] => 103
-// [enc_value] => 1
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => PricePerUnit
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [PricePerUnit] => SoapVar Object
+// (
+// [enc_type] => 103
+// [enc_value] => 1
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => PricePerUnit
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [Unit] => SoapVar Object
-// (
-// [enc_type] => 101
-// [enc_value] => st
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => Unit
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [Unit] => SoapVar Object
+// (
+// [enc_type] => 101
+// [enc_value] => st
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => Unit
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// [VatPercent] => SoapVar Object
-// (
-// [enc_type] => 103
-// [enc_value] => 25
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => VatPercent
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [VatPercent] => SoapVar Object
+// (
+// [enc_type] => 103
+// [enc_value] => 25
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => VatPercent
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// )
+// )
//
-// [enc_name] => OrderRow
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
-// )
+// [enc_name] => OrderRow
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Webservice
+// )
//
-// )
+// )
//
-// )
+// )
//
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => OrderRows
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
-// )
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => OrderRows
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
+// )
//
-// [OrderType] => SoapVar Object
-// (
-// [enc_type] => 101
-// [enc_value] => Invoice
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => OrderType
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
-// )
+// [OrderType] => SoapVar Object
+// (
+// [enc_type] => 101
+// [enc_value] => Invoice
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => OrderType
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
+// )
//
-// [SveaOrderId] => SoapVar Object
-// (
-// [enc_type] => 134
-// [enc_value] => 123456
-// [enc_stype] => -
-// [enc_ns] => --
-// [enc_name] => SveaOrderId
-// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
-// )
+// [SveaOrderId] => SoapVar Object
+// (
+// [enc_type] => 134
+// [enc_value] => 123456
+// [enc_stype] => -
+// [enc_ns] => --
+// [enc_name] => SveaOrderId
+// [enc_namens] => http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service
+// )
//
//)
- return unserialize($serialised_addOrderRowsSoapResponse);
- }
-
- /**
- * rounding
- */
-
- public function test_add_single_orderRow_as_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $request = WebPayAdmin::addOrderRows($config)
- ->setOrderId('sveaOrderId')
- ->setCountryCode('SE')
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountExVat(80.00)
- ->setQuantity(1)
- )
- ->addInvoiceOrderRows()
- ->prepareRequest();
-
- $this->assertEquals(80, $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);
- }
-
- public function test_add_rows_as_exvat()
- {
- $orderrowArray[] = WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountExVat(80.00)
- ->setQuantity(1);
- $orderrowArray[] = WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountExVat(10.00)
- ->setQuantity(1);
- $config = ConfigurationService::getDefaultConfig();
-
- $request = WebPayAdmin::addOrderRows($config)
- ->setOrderId('sveaOrderId')
- ->setCountryCode('SE')
- ->addOrderRows($orderrowArray)
- ->addInvoiceOrderRows()
- ->prepareRequest();
-
- $this->assertEquals(80, $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(10, $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);
- }
-
- public function test_add_single_orderRow_as_incvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $request = WebPayAdmin::addOrderRows($config)
- ->setOrderId('sveaOrderId')
- ->setCountryCode('SE')
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->addInvoiceOrderRows()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->OrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertTrue($request->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- }
-
- public function test_add_rows_as_incvat()
- {
- $orderrowArray[] = WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1);
- $orderrowArray[] = WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountIncVat(12.39876)
- ->setQuantity(1);
- $config = ConfigurationService::getDefaultConfig();
-
- $request = WebPayAdmin::addOrderRows($config)
- ->setOrderId('sveaOrderId')
- ->setCountryCode('SE')
- ->addOrderRows($orderrowArray)
- ->addInvoiceOrderRows()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->OrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertTrue($request->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- $this->assertEquals(12.39876, $request->OrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
- $this->assertTrue($request->OrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
- }
-
- public function test_add_single_orderRow_as_incvat_and_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $request = WebPayAdmin::addOrderRows($config)
- ->setOrderId('sveaOrderId')
- ->setCountryCode('SE')
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->addInvoiceOrderRows()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->OrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertTrue($request->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- }
-
- public function test_add_rows_as_incvat_and_exvat()
- {
- $orderrowArray[] = WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1);
- $orderrowArray[] = WebPayItem::orderRow()
- ->setAmountExVat(9.999)
- ->setAmountIncVat(12.39876)
- ->setQuantity(1);
- $config = ConfigurationService::getDefaultConfig();
-
- $request = WebPayAdmin::addOrderRows($config)
- ->setOrderId('sveaOrderId')
- ->setCountryCode('SE')
- ->addOrderRows($orderrowArray)
- ->addInvoiceOrderRows()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->OrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertTrue($request->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- $this->assertEquals(12.39876, $request->OrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
- $this->assertTrue($request->OrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
- }
-
- public function test_add_rows_as_incvat_mixed_with_exvat()
- {
- $orderrowArray[] = WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1);
- $orderrowArray[] = WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1);
- $orderrowArray[] = WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1);
-
- $config = ConfigurationService::getDefaultConfig();
-
- $request = WebPayAdmin::addOrderRows($config)
- ->setOrderId('sveaOrderId')
- ->setCountryCode('SE')
- ->addOrderRows($orderrowArray)
- ->addInvoiceOrderRows()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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.99, $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.99, $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_add_row_multiple_times_as_incvat_mixed_with_exvat()
- {
- $orderrowArray[] = WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1);
- $orderrowArray[] = WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1);
- $orderrowArray[] = WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1);
-
- $config = ConfigurationService::getDefaultConfig();
-
- $request = WebPayAdmin::addOrderRows($config)
- ->setOrderId('sveaOrderId')
- ->setCountryCode('SE')
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setVatPercent(24)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->addInvoiceOrderRows()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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.99, $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.99, $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);
- }
+ return unserialize($serialised_addOrderRowsSoapResponse);
+ }
+
+ /**
+ * rounding
+ */
+
+ public function test_add_single_orderRow_as_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $request = WebPayAdmin::addOrderRows($config)
+ ->setOrderId('sveaOrderId')
+ ->setCountryCode('SE')
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountExVat(80.00)
+ ->setQuantity(1)
+ )
+ ->addInvoiceOrderRows()
+ ->prepareRequest();
+
+ $this->assertEquals(80, $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);
+ }
+
+ public function test_add_rows_as_exvat()
+ {
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountExVat(80.00)
+ ->setQuantity(1);
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountExVat(10.00)
+ ->setQuantity(1);
+ $config = ConfigurationService::getDefaultConfig();
+
+ $request = WebPayAdmin::addOrderRows($config)
+ ->setOrderId('sveaOrderId')
+ ->setCountryCode('SE')
+ ->addOrderRows($orderrowArray)
+ ->addInvoiceOrderRows()
+ ->prepareRequest();
+
+ $this->assertEquals(80, $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(10, $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);
+ }
+
+ public function test_add_single_orderRow_as_incvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $request = WebPayAdmin::addOrderRows($config)
+ ->setOrderId('sveaOrderId')
+ ->setCountryCode('SE')
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->addInvoiceOrderRows()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->OrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertTrue($request->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ }
+
+ public function test_add_rows_as_incvat()
+ {
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1);
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountIncVat(12.39876)
+ ->setQuantity(1);
+ $config = ConfigurationService::getDefaultConfig();
+
+ $request = WebPayAdmin::addOrderRows($config)
+ ->setOrderId('sveaOrderId')
+ ->setCountryCode('SE')
+ ->addOrderRows($orderrowArray)
+ ->addInvoiceOrderRows()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->OrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertTrue($request->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ $this->assertEquals(12.39876, $request->OrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
+ $this->assertTrue($request->OrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
+ }
+
+ public function test_add_single_orderRow_as_incvat_and_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $request = WebPayAdmin::addOrderRows($config)
+ ->setOrderId('sveaOrderId')
+ ->setCountryCode('SE')
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->addInvoiceOrderRows()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->OrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertTrue($request->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ }
+
+ public function test_add_rows_as_incvat_and_exvat()
+ {
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1);
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setAmountExVat(9.999)
+ ->setAmountIncVat(12.39876)
+ ->setQuantity(1);
+ $config = ConfigurationService::getDefaultConfig();
+
+ $request = WebPayAdmin::addOrderRows($config)
+ ->setOrderId('sveaOrderId')
+ ->setCountryCode('SE')
+ ->addOrderRows($orderrowArray)
+ ->addInvoiceOrderRows()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->OrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertTrue($request->OrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ $this->assertEquals(12.39876, $request->OrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
+ $this->assertTrue($request->OrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
+ }
+
+ public function test_add_rows_as_incvat_mixed_with_exvat()
+ {
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1);
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1);
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1);
+
+ $config = ConfigurationService::getDefaultConfig();
+
+ $request = WebPayAdmin::addOrderRows($config)
+ ->setOrderId('sveaOrderId')
+ ->setCountryCode('SE')
+ ->addOrderRows($orderrowArray)
+ ->addInvoiceOrderRows()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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.99, $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.99, $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_add_row_multiple_times_as_incvat_mixed_with_exvat()
+ {
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1);
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1);
+ $orderrowArray[] = WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1);
+
+ $config = ConfigurationService::getDefaultConfig();
+
+ $request = WebPayAdmin::addOrderRows($config)
+ ->setOrderId('sveaOrderId')
+ ->setCountryCode('SE')
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setVatPercent(24)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->addInvoiceOrderRows()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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.99, $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.99, $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);
+ }
}
diff --git a/test/UnitTest/AdminService/CancelOrderRequestTest.php b/test/UnitTest/AdminService/CancelOrderRequestTest.php
index 1496ff92..a31c8880 100644
--- a/test/UnitTest/AdminService/CancelOrderRequestTest.php
+++ b/test/UnitTest/AdminService/CancelOrderRequestTest.php
@@ -13,40 +13,40 @@
class CancelOrderRequestTest extends \PHPUnit\Framework\TestCase
{
- public $builderObject;
-
- public function setUp()
- {
- $this->builderObject = new CancelOrderBuilder(ConfigurationService::getDefaultConfig());
- $this->builderObject->setOrderId(123456);
- $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
- }
-
- public function testClassExists()
- {
- $cancelOrderRequestObject = new CancelOrderRequest(new CancelOrderBuilder(ConfigurationService::getDefaultConfig()));
- $this->assertInstanceOf('Svea\WebPay\AdminService\CancelOrderRequest', $cancelOrderRequestObject);
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderId is required.
- */
- public function test_validate_throws_exception_on_missing_OrderId()
- {
- unset($this->builderObject->orderId);
- $cancelOrderRequestObject = new CancelOrderRequest($this->builderObject);
- $request = $cancelOrderRequestObject->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderType is required.
- */
- public function test_validate_throws_exception_on_missing_OrderType()
- {
- unset($this->builderObject->orderType);
- $cancelOrderRequestObject = new CancelOrderRequest($this->builderObject);
- $request = $cancelOrderRequestObject->prepareRequest();
- }
+ public $builderObject;
+
+ public function setUp()
+ {
+ $this->builderObject = new CancelOrderBuilder(ConfigurationService::getDefaultConfig());
+ $this->builderObject->setOrderId(123456);
+ $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
+ }
+
+ public function testClassExists()
+ {
+ $cancelOrderRequestObject = new CancelOrderRequest(new CancelOrderBuilder(ConfigurationService::getDefaultConfig()));
+ $this->assertInstanceOf('Svea\WebPay\AdminService\CancelOrderRequest', $cancelOrderRequestObject);
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderId is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderId()
+ {
+ unset($this->builderObject->orderId);
+ $cancelOrderRequestObject = new CancelOrderRequest($this->builderObject);
+ $request = $cancelOrderRequestObject->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderType is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderType()
+ {
+ unset($this->builderObject->orderType);
+ $cancelOrderRequestObject = new CancelOrderRequest($this->builderObject);
+ $request = $cancelOrderRequestObject->prepareRequest();
+ }
}
diff --git a/test/UnitTest/AdminService/CancelOrderRowsRequestTest.php b/test/UnitTest/AdminService/CancelOrderRowsRequestTest.php
index 9caf3740..ec6a3b69 100644
--- a/test/UnitTest/AdminService/CancelOrderRowsRequestTest.php
+++ b/test/UnitTest/AdminService/CancelOrderRowsRequestTest.php
@@ -13,64 +13,64 @@
class CancelOrderRowsRequestTest extends \PHPUnit\Framework\TestCase
{
- public $builderObject;
+ public $builderObject;
- public function setUp()
- {
- $this->builderObject = new OrderBuilder(ConfigurationService::getDefaultConfig());
- $this->builderObject->orderId = 123456;
- $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
- $this->builderObject->countryCode = "SE";
- $this->builderObject->rowsToCancel = array(1);
- }
+ public function setUp()
+ {
+ $this->builderObject = new OrderBuilder(ConfigurationService::getDefaultConfig());
+ $this->builderObject->orderId = 123456;
+ $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
+ $this->builderObject->countryCode = "SE";
+ $this->builderObject->rowsToCancel = [1];
+ }
- public function testClassExists()
- {
- $CancelOrderRowsRequestObject = new CancelOrderRowsRequest($this->builderObject);
- $this->assertInstanceOf('Svea\WebPay\AdminService\CancelOrderRowsRequest', $CancelOrderRowsRequestObject);
- }
+ public function testClassExists()
+ {
+ $CancelOrderRowsRequestObject = new CancelOrderRowsRequest($this->builderObject);
+ $this->assertInstanceOf('Svea\WebPay\AdminService\CancelOrderRowsRequest', $CancelOrderRowsRequestObject);
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderId is required.
- */
- public function test_validate_throws_exception_on_missing_OrderId()
- {
- unset($this->builderObject->orderId);
- $CancelOrderRowsRequestObject = new CancelOrderRowsRequest($this->builderObject);
- $request = $CancelOrderRowsRequestObject->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderId is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderId()
+ {
+ unset($this->builderObject->orderId);
+ $CancelOrderRowsRequestObject = new CancelOrderRowsRequest($this->builderObject);
+ $request = $CancelOrderRowsRequestObject->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderType is required.
- */
- public function test_validate_throws_exception_on_missing_OrderType()
- {
- unset($this->builderObject->orderType);
- $CancelOrderRowsRequestObject = new CancelOrderRowsRequest($this->builderObject);
- $request = $CancelOrderRowsRequestObject->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderType is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderType()
+ {
+ unset($this->builderObject->orderType);
+ $CancelOrderRowsRequestObject = new CancelOrderRowsRequest($this->builderObject);
+ $request = $CancelOrderRowsRequestObject->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : countryCode is required.
- */
- public function test_validate_throws_exception_on_missing_CountryCode()
- {
- unset($this->builderObject->countryCode);
- $CancelOrderRowsRequestObject = new CancelOrderRowsRequest($this->builderObject);
- $request = $CancelOrderRowsRequestObject->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : countryCode is required.
+ */
+ public function test_validate_throws_exception_on_missing_CountryCode()
+ {
+ unset($this->builderObject->countryCode);
+ $CancelOrderRowsRequestObject = new CancelOrderRowsRequest($this->builderObject);
+ $request = $CancelOrderRowsRequestObject->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : rowsToCancel is required.
- */
- public function test_validate_throws_exception_on_missing_RowsToCancel()
- {
- unset($this->builderObject->rowsToCancel);
- $CancelOrderRowsRequestObject = new CancelOrderRowsRequest($this->builderObject);
- $request = $CancelOrderRowsRequestObject->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : rowsToCancel is required.
+ */
+ public function test_validate_throws_exception_on_missing_RowsToCancel()
+ {
+ unset($this->builderObject->rowsToCancel);
+ $CancelOrderRowsRequestObject = new CancelOrderRowsRequest($this->builderObject);
+ $request = $CancelOrderRowsRequestObject->prepareRequest();
+ }
}
diff --git a/test/UnitTest/AdminService/CreditAccountCreditRowsTest.php b/test/UnitTest/AdminService/CreditAccountCreditRowsTest.php
index 4e905d3c..cdcfe5ea 100644
--- a/test/UnitTest/AdminService/CreditAccountCreditRowsTest.php
+++ b/test/UnitTest/AdminService/CreditAccountCreditRowsTest.php
@@ -10,66 +10,66 @@
class CreditAccountCreditRowsTest extends \PHPUnit\Framework\TestCase
{
- public $builderObject;
+ public $builderObject;
- public function setUp()
- {
- $this->builderObject = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $this->builderObject->orderId = 123456;
- $this->builderObject->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
- $this->builderObject->countryCode = "SE";
- $this->builderObject->rowsToCredit = array(TestUtil::createOrderRow(10.00));
- $this->builderObject->creditOrderRows = array(TestUtil::createOrderRow(10.00));
- }
+ public function setUp()
+ {
+ $this->builderObject = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $this->builderObject->orderId = 123456;
+ $this->builderObject->orderType = ConfigurationProvider::ACCOUNTCREDIT_TYPE;
+ $this->builderObject->countryCode = "SE";
+ $this->builderObject->rowsToCredit = [TestUtil::createOrderRow(10.00)];
+ $this->builderObject->creditOrderRows = [TestUtil::createOrderRow(10.00)];
+ }
- public function testClassExists()
- {
- $AddOrderRowsRequestObject = new CreditAccountCreditRowsRequest($this->builderObject);
- $this->assertInstanceOf('Svea\WebPay\AdminService\CreditAccountCreditRowsRequest', $AddOrderRowsRequestObject);
- }
+ public function testClassExists()
+ {
+ $AddOrderRowsRequestObject = new CreditAccountCreditRowsRequest($this->builderObject);
+ $this->assertInstanceOf('Svea\WebPay\AdminService\CreditAccountCreditRowsRequest', $AddOrderRowsRequestObject);
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage orderId is required, use setOrderId().
- */
- public function test_validate_throws_exception_on_missing_OrderId()
- {
- unset($this->builderObject->orderId);
- $creditRequest = new CreditAccountCreditRowsRequest($this->builderObject);
- $request = $creditRequest->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage orderId is required, use setOrderId().
+ */
+ public function test_validate_throws_exception_on_missing_OrderId()
+ {
+ unset($this->builderObject->orderId);
+ $creditRequest = new CreditAccountCreditRowsRequest($this->builderObject);
+ $request = $creditRequest->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderType is required.
- */
- public function test_validate_throws_exception_on_missing_OrderType()
- {
- unset($this->builderObject->orderType);
- $creditRequest = new CreditAccountCreditRowsRequest($this->builderObject);
- $request = $creditRequest->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderType is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderType()
+ {
+ unset($this->builderObject->orderType);
+ $creditRequest = new CreditAccountCreditRowsRequest($this->builderObject);
+ $request = $creditRequest->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : countryCode is required, use setCountryCode().
- */
- public function test_validate_throws_exception_on_missing_CountryCode()
- {
- unset($this->builderObject->countryCode);
- $creditRequest = new CreditAccountCreditRowsRequest($this->builderObject);
- $request = $creditRequest->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : countryCode is required, use setCountryCode().
+ */
+ public function test_validate_throws_exception_on_missing_CountryCode()
+ {
+ unset($this->builderObject->countryCode);
+ $creditRequest = new CreditAccountCreditRowsRequest($this->builderObject);
+ $request = $creditRequest->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : no rows to credit, use setRow(s)ToCredit() or addCreditOrderRow(s)().
- */
- public function test_validate_throws_exception_on_missing_RowsToCredit()
- {
- $this->builderObject->rowsToCredit = array();
- $this->builderObject->creditOrderRows = array();
- $creditRequest = new CreditAccountCreditRowsRequest($this->builderObject);
- $request = $creditRequest->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : no rows to credit, use setRow(s)ToCredit() or addCreditOrderRow(s)().
+ */
+ public function test_validate_throws_exception_on_missing_RowsToCredit()
+ {
+ $this->builderObject->rowsToCredit = [];
+ $this->builderObject->creditOrderRows = [];
+ $creditRequest = new CreditAccountCreditRowsRequest($this->builderObject);
+ $request = $creditRequest->prepareRequest();
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/AdminService/CreditAmountAccountCreditTest.php b/test/UnitTest/AdminService/CreditAmountAccountCreditTest.php
index 62b6774b..e20cbfa6 100644
--- a/test/UnitTest/AdminService/CreditAmountAccountCreditTest.php
+++ b/test/UnitTest/AdminService/CreditAmountAccountCreditTest.php
@@ -12,66 +12,66 @@
class CreditAmountAccountCreditTestextends extends \PHPUnit\Framework\TestCase
{
- public $builderObject;
+ public $builderObject;
- public function setUp()
- {
- $this->builderObject = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- $this->builderObject->orderId = 123456;
- $this->builderObject->countryCode = "SE";
- $this->builderObject->amountIncVat = 150.00;
- }
+ public function setUp()
+ {
+ $this->builderObject = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ $this->builderObject->orderId = 123456;
+ $this->builderObject->countryCode = "SE";
+ $this->builderObject->amountIncVat = 150.00;
+ }
- public function testClassExists()
- {
- $AddOrderRowsRequestObject = new CreditAmountAccountCreditRequest($this->builderObject);
- $this->assertInstanceOf('Svea\WebPay\AdminService\CreditAmountAccountCreditRequest', $AddOrderRowsRequestObject);
- }
+ public function testClassExists()
+ {
+ $AddOrderRowsRequestObject = new CreditAmountAccountCreditRequest($this->builderObject);
+ $this->assertInstanceOf('Svea\WebPay\AdminService\CreditAmountAccountCreditRequest', $AddOrderRowsRequestObject);
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage orderId is required, use setOrderId().
- */
- public function test_validate_throws_exception_on_missing_OrderId()
- {
- unset($this->builderObject->orderId);
- $creditRequest = new CreditAmountAccountCreditRequest($this->builderObject);
- $request = $creditRequest->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage orderId is required, use setOrderId().
+ */
+ public function test_validate_throws_exception_on_missing_OrderId()
+ {
+ unset($this->builderObject->orderId);
+ $creditRequest = new CreditAmountAccountCreditRequest($this->builderObject);
+ $request = $creditRequest->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : countryCode is required, use setCountryCode().
- */
- public function test_validate_throws_exception_on_missing_CountryCode()
- {
- unset($this->builderObject->countryCode);
- $creditRequest = new CreditAmountAccountCreditRequest($this->builderObject);
- $request = $creditRequest->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : countryCode is required, use setCountryCode().
+ */
+ public function test_validate_throws_exception_on_missing_CountryCode()
+ {
+ unset($this->builderObject->countryCode);
+ $creditRequest = new CreditAmountAccountCreditRequest($this->builderObject);
+ $request = $creditRequest->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect value : amountIncVat is too small
- */
- public function test_validate_throws_exception_on_missing_amountIncVat()
- {
- unset($this->builderObject->amountIncVat);
- $creditRequest = new CreditAmountAccountCreditRequest($this->builderObject);
- $request = $creditRequest->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect value : amountIncVat is too small
+ */
+ public function test_validate_throws_exception_on_missing_amountIncVat()
+ {
+ unset($this->builderObject->amountIncVat);
+ $creditRequest = new CreditAmountAccountCreditRequest($this->builderObject);
+ $request = $creditRequest->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect value : amountIncVat is too small
- */
- public function test_validate_throws_exception_on_bad_amount_value()
- {
- $this->builderObject->amountIncVat = "badValue";
- $creditRequest = new CreditAmountAccountCreditRequest($this->builderObject);
- $request = $creditRequest->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect value : amountIncVat is too small
+ */
+ public function test_validate_throws_exception_on_bad_amount_value()
+ {
+ $this->builderObject->amountIncVat = "badValue";
+ $creditRequest = new CreditAmountAccountCreditRequest($this->builderObject);
+ $request = $creditRequest->prepareRequest();
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/AdminService/CreditOrderRowsRequestTest.php b/test/UnitTest/AdminService/CreditOrderRowsRequestTest.php
index 2a79e365..f204fe8a 100644
--- a/test/UnitTest/AdminService/CreditOrderRowsRequestTest.php
+++ b/test/UnitTest/AdminService/CreditOrderRowsRequestTest.php
@@ -15,239 +15,239 @@
class CreditOrderRowsRequestTest extends \PHPUnit\Framework\TestCase
{
- /// characterising test for INTG-462
- // invoice
- /**
- * @doesNotPerformAssertions
- */
- public function test_creditOrderRows_creditInvoiceOrderRows_does_not_validate_setOrderId()
- {
- $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setInvoiceId(987654)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->setRowToCredit(1);
-
- // shouldn't raise any exception
-
- $request = $creditOrderRowsBuilder->creditInvoiceOrderRows()->prepareRequest();
- }
-
- // card
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage orderId is required for creditCardOrderRows(). Use method setOrderId().
- */
- public function test_creditOrderRows_creditCardOrderRows_validates_setOrderId()
- {
- $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- //->setOrderId(987654) // i.e. setTransactionId()
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->setRowToCredit(1);
-
- $request = $creditOrderRowsBuilder->creditCardOrderRows()->prepareRequest();
- }
-
- // direct bank
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage orderId is required for creditCardOrderRows(). Use method setOrderId().
- */
- public function test_creditOrderRows_creditDirectBankOrderRows_validates_setOrderId()
- {
- $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- //->setTransactionId(987654) // alias for setOrderId()
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode('SE')
- ->setRowToCredit(1);
-
- $request = $creditOrderRowsBuilder->creditDirectBankOrderRows()->prepareRequest();
- }
-
- public function test_creditOrderRows_creditPaymentPlanOrderRows_credit_row_using_row_index()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $request = WebPayAdmin::creditOrderRows($config)
- ->setContractNumber('123123')
- ->setCountryCode('SE')
- ->setRowToCredit(1)
- ->creditPaymentPlanOrderRows()->prepareRequest();
- $this->assertEquals(1, $request->CancellationRows->enc_value[0]->enc_value->RowNumber->enc_value);
- $this->assertEquals('123123', $request->ContractNumber->enc_value);
- }
-
- public function test_creditOrderRows_creditPyamentplanOrderRows()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("row 1");
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("row 2");
- $request = WebPayAdmin::creditOrderRows($config)
- ->setContractNumber('123132')
- ->setCountryCode('SE')
- ->addCreditOrderRows($orderRows)
- ->creditPaymentplanOrderRows()->prepareRequest();
-
- $this->assertEquals(123.9876, $request->CancellationRows->enc_value[0]->enc_value->AmountInclVat->enc_value);
- $this->assertEquals('123132', $request->ContractNumber->enc_value);
-
-
- }
-
- public function test_creditOrderRows_creditCardOrderRowsAsIncvatAndVatPercent()
- {
- $amount_inc_vat = 350;
- $vat_percent = 6;
- $quantity = 2;
-
- $config = ConfigurationService::getDefaultConfig();
-
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountIncVat($amount_inc_vat)
- ->setVatPercent($vat_percent)
- ->setQuantity($quantity)
- ->setDescription("row 1");
-
- $request = WebPayAdmin::creditOrderRows($config)
- ->setTransactionId(987654)
- ->setCountryCode('SE')
- ->addCreditOrderRows($orderRows)
- ->creditCardOrderRows();
-
- $expected_amount = Helper::bround($amount_inc_vat * $quantity) * 100;
- $this->assertEquals($expected_amount, $request->creditAmount);
- $this->assertEquals('987654', $request->transactionId);
- }
-
- public function test_creditOrderRows_creditCardOrderRowsAsAmountExVatAndVatPercent()
- {
- $amount_ex_vat = 330.19;
- $vat_percent = 6;
- $quantity = 1;
-
- $config = ConfigurationService::getDefaultConfig();
-
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountExVat($amount_ex_vat)
- ->setVatPercent($vat_percent)
- ->setQuantity($quantity)
- ->setDescription("row 1");
-
- $request = WebPayAdmin::creditOrderRows($config)
- ->setTransactionId(987654)
- ->setCountryCode('SE')
- ->addCreditOrderRows($orderRows)
- ->creditCardOrderRows();
-
- $expected_amount = Helper::bround($amount_ex_vat * (1 + $vat_percent / 100) * $quantity) * 100;
- $this->assertEquals($expected_amount, $request->creditAmount);
- $this->assertEquals('987654', $request->transactionId);
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage Order with amountExVat must have vatPercent
- */
- public function test_creditOrderRowsCreditCardOrderRowsAsAmountExVatAndWithoutVatPercent()
- {
- $amount_ex_vat = 330.19;
- $quantity = 1;
-
- $config = ConfigurationService::getDefaultConfig();
-
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountExVat($amount_ex_vat)
- ->setQuantity($quantity)
- ->setDescription("row 1");
-
- WebPayAdmin::creditOrderRows($config)
- ->setTransactionId(987654)
- ->setCountryCode('SE')
- ->addCreditOrderRows($orderRows)
- ->creditCardOrderRows();
- }
-
- public function test_creditOrderRows_creditCardOrderRowsAsAmountExVatAndAmountIncVat()
- {
- $amount_inc_vat = 350;
- $amount_ex_vat = 330.19;
- $quantity = 2;
-
- $config = ConfigurationService::getDefaultConfig();
-
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountIncVat($amount_inc_vat)
- ->setAmountExVat($amount_ex_vat)
- ->setVatPercent(25)
- ->setQuantity($quantity)
- ->setDescription("row 1");
-
- $request = WebPayAdmin::creditOrderRows($config)
- ->setTransactionId(987654)
- ->setCountryCode('SE')
- ->addCreditOrderRows($orderRows)
- ->creditCardOrderRows();
-
- $expected_amount = Helper::bround($amount_inc_vat) * $quantity * 100;
- $this->assertEquals($expected_amount, $request->creditAmount);
- $this->assertEquals('987654', $request->transactionId);
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage amountExVat or amountIncVat must be set
- */
- public function test_creditOrderRowsWithoutAmount()
- {
-
- $config = ConfigurationService::getDefaultConfig();
-
- $orderRows[] = WebPayItem::orderRow()
- ->setQuantity(1)
- ->setDescription("row 1");
-
- WebPayAdmin::creditOrderRows($config)
- ->setTransactionId(987654)
- ->setCountryCode('SE')
- ->addCreditOrderRows($orderRows)
- ->creditCardOrderRows()
- ->prepareRequest();
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : Description is required.
- */
- public function test_creditOrderRows_creditPyamentplanOrderRows_noDesciription()
- {
-
- $config = ConfigurationService::getDefaultConfig();
-
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(1);
- $orderRows[] = WebPayItem::orderRow()
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- ->setQuantity(1);
- $credit = WebPayAdmin::creditOrderRows($config)
- ->setContractNumber(123123)
- ->setCountryCode('SE')
- ->addCreditOrderRows($orderRows)
- ->creditPaymentplanOrderRows()->prepareRequest();
-
- }
+ /// characterising test for INTG-462
+ // invoice
+ /**
+ * @doesNotPerformAssertions
+ */
+ public function test_creditOrderRows_creditInvoiceOrderRows_does_not_validate_setOrderId()
+ {
+ $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setInvoiceId(987654)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->setRowToCredit(1);
+
+ // shouldn't raise any exception
+
+ $request = $creditOrderRowsBuilder->creditInvoiceOrderRows()->prepareRequest();
+ }
+
+ // card
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage orderId is required for creditCardOrderRows(). Use method setOrderId().
+ */
+ public function test_creditOrderRows_creditCardOrderRows_validates_setOrderId()
+ {
+ $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ //->setOrderId(987654) // i.e. setTransactionId()
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->setRowToCredit(1);
+
+ $request = $creditOrderRowsBuilder->creditCardOrderRows()->prepareRequest();
+ }
+
+ // direct bank
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage orderId is required for creditCardOrderRows(). Use method setOrderId().
+ */
+ public function test_creditOrderRows_creditDirectBankOrderRows_validates_setOrderId()
+ {
+ $creditOrderRowsBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ //->setTransactionId(987654) // alias for setOrderId()
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode('SE')
+ ->setRowToCredit(1);
+
+ $request = $creditOrderRowsBuilder->creditDirectBankOrderRows()->prepareRequest();
+ }
+
+ public function test_creditOrderRows_creditPaymentPlanOrderRows_credit_row_using_row_index()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $request = WebPayAdmin::creditOrderRows($config)
+ ->setContractNumber('123123')
+ ->setCountryCode('SE')
+ ->setRowToCredit(1)
+ ->creditPaymentPlanOrderRows()->prepareRequest();
+ $this->assertEquals(1, $request->CancellationRows->enc_value[0]->enc_value->RowNumber->enc_value);
+ $this->assertEquals('123123', $request->ContractNumber->enc_value);
+ }
+
+ public function test_creditOrderRows_creditPyamentplanOrderRows()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("row 1");
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("row 2");
+ $request = WebPayAdmin::creditOrderRows($config)
+ ->setContractNumber('123132')
+ ->setCountryCode('SE')
+ ->addCreditOrderRows($orderRows)
+ ->creditPaymentplanOrderRows()->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->CancellationRows->enc_value[0]->enc_value->AmountInclVat->enc_value);
+ $this->assertEquals('123132', $request->ContractNumber->enc_value);
+
+
+ }
+
+ public function test_creditOrderRows_creditCardOrderRowsAsIncvatAndVatPercent()
+ {
+ $amount_inc_vat = 350;
+ $vat_percent = 6;
+ $quantity = 2;
+
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountIncVat($amount_inc_vat)
+ ->setVatPercent($vat_percent)
+ ->setQuantity($quantity)
+ ->setDescription("row 1");
+
+ $request = WebPayAdmin::creditOrderRows($config)
+ ->setTransactionId(987654)
+ ->setCountryCode('SE')
+ ->addCreditOrderRows($orderRows)
+ ->creditCardOrderRows();
+
+ $expected_amount = Helper::bround($amount_inc_vat * $quantity) * 100;
+ $this->assertEquals($expected_amount, $request->creditAmount);
+ $this->assertEquals('987654', $request->transactionId);
+ }
+
+ public function test_creditOrderRows_creditCardOrderRowsAsAmountExVatAndVatPercent()
+ {
+ $amount_ex_vat = 330.19;
+ $vat_percent = 6;
+ $quantity = 1;
+
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountExVat($amount_ex_vat)
+ ->setVatPercent($vat_percent)
+ ->setQuantity($quantity)
+ ->setDescription("row 1");
+
+ $request = WebPayAdmin::creditOrderRows($config)
+ ->setTransactionId(987654)
+ ->setCountryCode('SE')
+ ->addCreditOrderRows($orderRows)
+ ->creditCardOrderRows();
+
+ $expected_amount = Helper::bround($amount_ex_vat * (1 + $vat_percent / 100) * $quantity) * 100;
+ $this->assertEquals($expected_amount, $request->creditAmount);
+ $this->assertEquals('987654', $request->transactionId);
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage Order with amountExVat must have vatPercent
+ */
+ public function test_creditOrderRowsCreditCardOrderRowsAsAmountExVatAndWithoutVatPercent()
+ {
+ $amount_ex_vat = 330.19;
+ $quantity = 1;
+
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountExVat($amount_ex_vat)
+ ->setQuantity($quantity)
+ ->setDescription("row 1");
+
+ WebPayAdmin::creditOrderRows($config)
+ ->setTransactionId(987654)
+ ->setCountryCode('SE')
+ ->addCreditOrderRows($orderRows)
+ ->creditCardOrderRows();
+ }
+
+ public function test_creditOrderRows_creditCardOrderRowsAsAmountExVatAndAmountIncVat()
+ {
+ $amount_inc_vat = 350;
+ $amount_ex_vat = 330.19;
+ $quantity = 2;
+
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountIncVat($amount_inc_vat)
+ ->setAmountExVat($amount_ex_vat)
+ ->setVatPercent(25)
+ ->setQuantity($quantity)
+ ->setDescription("row 1");
+
+ $request = WebPayAdmin::creditOrderRows($config)
+ ->setTransactionId(987654)
+ ->setCountryCode('SE')
+ ->addCreditOrderRows($orderRows)
+ ->creditCardOrderRows();
+
+ $expected_amount = Helper::bround($amount_inc_vat) * $quantity * 100;
+ $this->assertEquals($expected_amount, $request->creditAmount);
+ $this->assertEquals('987654', $request->transactionId);
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage amountExVat or amountIncVat must be set
+ */
+ public function test_creditOrderRowsWithoutAmount()
+ {
+
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderRows[] = WebPayItem::orderRow()
+ ->setQuantity(1)
+ ->setDescription("row 1");
+
+ WebPayAdmin::creditOrderRows($config)
+ ->setTransactionId(987654)
+ ->setCountryCode('SE')
+ ->addCreditOrderRows($orderRows)
+ ->creditCardOrderRows()
+ ->prepareRequest();
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : Description is required.
+ */
+ public function test_creditOrderRows_creditPyamentplanOrderRows_noDesciription()
+ {
+
+ $config = ConfigurationService::getDefaultConfig();
+
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(1);
+ $orderRows[] = WebPayItem::orderRow()
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ ->setQuantity(1);
+ $credit = WebPayAdmin::creditOrderRows($config)
+ ->setContractNumber(123123)
+ ->setCountryCode('SE')
+ ->addCreditOrderRows($orderRows)
+ ->creditPaymentplanOrderRows()->prepareRequest();
+
+ }
}
diff --git a/test/UnitTest/AdminService/DeliverOrderRowsRequestTest.php b/test/UnitTest/AdminService/DeliverOrderRowsRequestTest.php
index 2fadf70b..f6737607 100644
--- a/test/UnitTest/AdminService/DeliverOrderRowsRequestTest.php
+++ b/test/UnitTest/AdminService/DeliverOrderRowsRequestTest.php
@@ -13,64 +13,64 @@
class DeliverOrderRowsRequestTest extends \PHPUnit\Framework\TestCase
{
- public $builderObject;
+ public $builderObject;
- public function setUp()
- {
- $this->builderObject = new OrderBuilder(ConfigurationService::getDefaultConfig());
- $this->builderObject->orderId = 123456;
- $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
- $this->builderObject->countryCode = "SE";
- $this->builderObject->rowsToDeliver = array(1);
- }
+ public function setUp()
+ {
+ $this->builderObject = new OrderBuilder(ConfigurationService::getDefaultConfig());
+ $this->builderObject->orderId = 123456;
+ $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
+ $this->builderObject->countryCode = "SE";
+ $this->builderObject->rowsToDeliver = [1];
+ }
- public function testClassExists()
- {
- $DeliverOrderRowsRequestObject = new DeliverOrderRowsRequest($this->builderObject);
- $this->assertInstanceOf('Svea\WebPay\AdminService\DeliverOrderRowsRequest', $DeliverOrderRowsRequestObject);
- }
+ public function testClassExists()
+ {
+ $DeliverOrderRowsRequestObject = new DeliverOrderRowsRequest($this->builderObject);
+ $this->assertInstanceOf('Svea\WebPay\AdminService\DeliverOrderRowsRequest', $DeliverOrderRowsRequestObject);
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderId is required.
- */
- public function test_validate_throws_exception_on_missing_OrderId()
- {
- unset($this->builderObject->orderId);
- $DeliverOrderRowsRequestObject = new DeliverOrderRowsRequest($this->builderObject);
- $request = $DeliverOrderRowsRequestObject->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderId is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderId()
+ {
+ unset($this->builderObject->orderId);
+ $DeliverOrderRowsRequestObject = new DeliverOrderRowsRequest($this->builderObject);
+ $request = $DeliverOrderRowsRequestObject->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderType is required.
- */
- public function test_validate_throws_exception_on_missing_OrderType()
- {
- unset($this->builderObject->orderType);
- $DeliverOrderRowsRequestObject = new DeliverOrderRowsRequest($this->builderObject);
- $request = $DeliverOrderRowsRequestObject->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderType is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderType()
+ {
+ unset($this->builderObject->orderType);
+ $DeliverOrderRowsRequestObject = new DeliverOrderRowsRequest($this->builderObject);
+ $request = $DeliverOrderRowsRequestObject->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : countryCode is required.
- */
- public function test_validate_throws_exception_on_missing_CountryCode()
- {
- unset($this->builderObject->countryCode);
- $DeliverOrderRowsRequestObject = new DeliverOrderRowsRequest($this->builderObject);
- $request = $DeliverOrderRowsRequestObject->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : countryCode is required.
+ */
+ public function test_validate_throws_exception_on_missing_CountryCode()
+ {
+ unset($this->builderObject->countryCode);
+ $DeliverOrderRowsRequestObject = new DeliverOrderRowsRequest($this->builderObject);
+ $request = $DeliverOrderRowsRequestObject->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : rowsToDeliver is required.
- */
- public function test_validate_throws_exception_on_missing_RowsToDeliver()
- {
- unset($this->builderObject->rowsToDeliver);
- $DeliverOrderRowsRequestObject = new DeliverOrderRowsRequest($this->builderObject);
- $request = $DeliverOrderRowsRequestObject->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : rowsToDeliver is required.
+ */
+ public function test_validate_throws_exception_on_missing_RowsToDeliver()
+ {
+ unset($this->builderObject->rowsToDeliver);
+ $DeliverOrderRowsRequestObject = new DeliverOrderRowsRequest($this->builderObject);
+ $request = $DeliverOrderRowsRequestObject->prepareRequest();
+ }
}
diff --git a/test/UnitTest/AdminService/DeliverOrdersRequestTest.php b/test/UnitTest/AdminService/DeliverOrdersRequestTest.php
index dcc49757..5a12085a 100644
--- a/test/UnitTest/AdminService/DeliverOrdersRequestTest.php
+++ b/test/UnitTest/AdminService/DeliverOrdersRequestTest.php
@@ -14,56 +14,56 @@
class DeliverOrdersRequestTest extends \PHPUnit\Framework\TestCase
{
- public $builderObject;
+ public $builderObject;
- public function setUp()
- {
- $this->builderObject = new DeliverOrderBuilder(ConfigurationService::getDefaultConfig());
- $this->builderObject->setOrderId(123456);
- $this->builderObject->setCountryCode("SE");
- $this->builderObject->setInvoiceDistributionType(DistributionType::POST);
- $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
- }
+ public function setUp()
+ {
+ $this->builderObject = new DeliverOrderBuilder(ConfigurationService::getDefaultConfig());
+ $this->builderObject->setOrderId(123456);
+ $this->builderObject->setCountryCode("SE");
+ $this->builderObject->setInvoiceDistributionType(DistributionType::POST);
+ $this->builderObject->orderType = ConfigurationProvider::INVOICE_TYPE;
+ }
- public function testClassExists()
- {
- $deliverOrdersRequestObject = new DeliverOrdersRequest(new DeliverOrderBuilder(ConfigurationService::getDefaultConfig()));
- $this->assertInstanceOf('Svea\WebPay\AdminService\DeliverOrdersRequest', $deliverOrdersRequestObject);
- }
+ public function testClassExists()
+ {
+ $deliverOrdersRequestObject = new DeliverOrdersRequest(new DeliverOrderBuilder(ConfigurationService::getDefaultConfig()));
+ $this->assertInstanceOf('Svea\WebPay\AdminService\DeliverOrdersRequest', $deliverOrdersRequestObject);
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : distributionType is required.
- */
- public function test_validate_throws_exception_on_missing_DistributionType()
- {
- unset($this->builderObject->distributionType);
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : distributionType is required.
+ */
+ public function test_validate_throws_exception_on_missing_DistributionType()
+ {
+ unset($this->builderObject->distributionType);
- $deliverOrderRequestObject = new DeliverOrdersRequest($this->builderObject);
- $request = $deliverOrderRequestObject->prepareRequest();
- }
+ $deliverOrderRequestObject = new DeliverOrdersRequest($this->builderObject);
+ $request = $deliverOrderRequestObject->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderId is required.
- */
- public function test_validate_throws_exception_on_missing_OrderId()
- {
- unset($this->builderObject->orderId);
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderId is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderId()
+ {
+ unset($this->builderObject->orderId);
- $deliverOrderRequestObject = new DeliverOrdersRequest($this->builderObject);
- $request = $deliverOrderRequestObject->prepareRequest();
- }
+ $deliverOrderRequestObject = new DeliverOrdersRequest($this->builderObject);
+ $request = $deliverOrderRequestObject->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderType is required.
- */
- public function test_validate_throws_exception_on_missing_OrderType()
- {
- unset($this->builderObject->orderType);
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderType is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderType()
+ {
+ unset($this->builderObject->orderType);
- $deliverOrderRequestObject = new DeliverOrdersRequest($this->builderObject);
- $request = $deliverOrderRequestObject->prepareRequest();
- }
+ $deliverOrderRequestObject = new DeliverOrdersRequest($this->builderObject);
+ $request = $deliverOrderRequestObject->prepareRequest();
+ }
}
diff --git a/test/UnitTest/AdminService/GetOrdersRequestTest.php b/test/UnitTest/AdminService/GetOrdersRequestTest.php
index 74cda0fd..000a3fe2 100644
--- a/test/UnitTest/AdminService/GetOrdersRequestTest.php
+++ b/test/UnitTest/AdminService/GetOrdersRequestTest.php
@@ -12,51 +12,51 @@
class GetOrdersRequestTest extends \PHPUnit\Framework\TestCase
{
- public $builderObject;
-
- public function setUp()
- {
- $this->builderObject = new OrderBuilder(ConfigurationService::getDefaultConfig());
- // TODO create classes w/methods for below
- $this->builderObject->orderId = 123456;
- }
-
- public function testClassExists()
- {
- $getOrdersRequestObject = new GetOrdersRequest($this->builderObject);
- $this->assertInstanceOf('Svea\WebPay\AdminService\GetOrdersRequest', $getOrdersRequestObject);
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderId is required.
- */
- public function test_validate_throws_exception_on_missing_OrderId()
- {
- unset($this->builderObject->orderId);
- $getOrdersRequestObject = new GetOrdersRequest($this->builderObject);
- $request = $getOrdersRequestObject->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : orderType is required.
- */
- public function test_validate_throws_exception_on_missing_OrderType()
- {
- unset($this->builderObject->orderType);
- $getOrdersRequestObject = new GetOrdersRequest($this->builderObject);
- $request = $getOrdersRequestObject->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : countryCode is required.
- */
- public function test_validate_throws_exception_on_missing_CountryCode()
- {
- unset($this->builderObject->countryCode);
- $getOrdersRequestObject = new GetOrdersRequest($this->builderObject);
- $request = $getOrdersRequestObject->prepareRequest();
- }
+ public $builderObject;
+
+ public function setUp()
+ {
+ $this->builderObject = new OrderBuilder(ConfigurationService::getDefaultConfig());
+ // TODO create classes w/methods for below
+ $this->builderObject->orderId = 123456;
+ }
+
+ public function testClassExists()
+ {
+ $getOrdersRequestObject = new GetOrdersRequest($this->builderObject);
+ $this->assertInstanceOf('Svea\WebPay\AdminService\GetOrdersRequest', $getOrdersRequestObject);
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderId is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderId()
+ {
+ unset($this->builderObject->orderId);
+ $getOrdersRequestObject = new GetOrdersRequest($this->builderObject);
+ $request = $getOrdersRequestObject->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : orderType is required.
+ */
+ public function test_validate_throws_exception_on_missing_OrderType()
+ {
+ unset($this->builderObject->orderType);
+ $getOrdersRequestObject = new GetOrdersRequest($this->builderObject);
+ $request = $getOrdersRequestObject->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : countryCode is required.
+ */
+ public function test_validate_throws_exception_on_missing_CountryCode()
+ {
+ unset($this->builderObject->countryCode);
+ $getOrdersRequestObject = new GetOrdersRequest($this->builderObject);
+ $request = $getOrdersRequestObject->prepareRequest();
+ }
}
diff --git a/test/UnitTest/AdminService/UpdateOrderRequestTest.php b/test/UnitTest/AdminService/UpdateOrderRequestTest.php
index 6cd4c7cd..1f28417a 100644
--- a/test/UnitTest/AdminService/UpdateOrderRequestTest.php
+++ b/test/UnitTest/AdminService/UpdateOrderRequestTest.php
@@ -12,91 +12,91 @@
class UpdateOrderRequestTest extends \PHPUnit\Framework\TestCase
{
- public $notes = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
- Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
- penatibus et magnis';
+ public $notes = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
+ Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
+ penatibus et magnis';
- /**
- * req: SveaOrderId, ClientId
- * update: Notes, ClientOrderNumber
- */
- public function test_updateorder_clientnr_invoice()
- {
- print_r(strlen($this->notes));
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrder($config)//only need clientid
- ->setCountryCode('SE')//req for config
- ->setOrderId('test')
- ->setClientOrderNumber('123')//string
- ->updateInvoiceOrder()
- ->prepareRequest();
+ /**
+ * req: SveaOrderId, ClientId
+ * update: Notes, ClientOrderNumber
+ */
+ public function test_updateorder_clientnr_invoice()
+ {
+ print_r(strlen($this->notes));
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrder($config)//only need clientid
+ ->setCountryCode('SE')//req for config
+ ->setOrderId('test')
+ ->setClientOrderNumber('123')//string
+ ->updateInvoiceOrder()
+ ->prepareRequest();
- $this->assertEquals('123', $request->ClientOrderNumber->enc_value);
- }
+ $this->assertEquals('123', $request->ClientOrderNumber->enc_value);
+ }
- public function test_updateorder_addnotes_invoice()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrder($config)//only need clientid
- ->setCountryCode('SE')//req for config
- ->setOrderId('test')
- ->setNotes($this->notes)//string 200 chars
- ->updateInvoiceOrder()
- ->prepareRequest();
+ public function test_updateorder_addnotes_invoice()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrder($config)//only need clientid
+ ->setCountryCode('SE')//req for config
+ ->setOrderId('test')
+ ->setNotes($this->notes)//string 200 chars
+ ->updateInvoiceOrder()
+ ->prepareRequest();
- $this->assertEquals($this->notes, $request->Notes->enc_value);
- }
+ $this->assertEquals($this->notes, $request->Notes->enc_value);
+ }
- public function test_updateorder_clientnr_paymentplan()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrder($config)//only need clientid
- ->setCountryCode('SE')//req for config
- ->setOrderId('test')
- ->setClientOrderNumber('123')//string
- ->updateInvoiceOrder()
- ->prepareRequest();
+ public function test_updateorder_clientnr_paymentplan()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrder($config)//only need clientid
+ ->setCountryCode('SE')//req for config
+ ->setOrderId('test')
+ ->setClientOrderNumber('123')//string
+ ->updateInvoiceOrder()
+ ->prepareRequest();
- $this->assertEquals('123', $request->ClientOrderNumber->enc_value);
- }
+ $this->assertEquals('123', $request->ClientOrderNumber->enc_value);
+ }
- public function test_updateorder_addnotes_paymentplan()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrder($config)//only need clientid
- ->setCountryCode('SE')//req for config
- ->setOrderId('test')
- ->setNotes($this->notes)//string 200 chars
- ->updateInvoiceOrder()
- ->prepareRequest();
+ public function test_updateorder_addnotes_paymentplan()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrder($config)//only need clientid
+ ->setCountryCode('SE')//req for config
+ ->setOrderId('test')
+ ->setNotes($this->notes)//string 200 chars
+ ->updateInvoiceOrder()
+ ->prepareRequest();
- $this->assertEquals($this->notes, $request->Notes->enc_value);
- }
+ $this->assertEquals($this->notes, $request->Notes->enc_value);
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -String length : The field Notes must be a string with a maximum length of 200.
- *
- */
- public function test_updateorder_addnotes_chars_validate_invoice()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrder($config)//only need clientid
- ->setCountryCode('SE')//req for config
- ->setOrderId('test')
- ->setNotes('Lorem ipsum dolor sit amet, consectetur adipiscing elit.
- Nullam faucibus turpis ut nibh cursus, volutpat consectetur odio
- consequat. Quisque fermentum, augue eget scelerisque hendrerit,
- libero odio mollis metus, eleifend semper enim ligula eu eros.
- Nullam varius, nunc sit amet tincidunt volutpat, sem sapien semper
- libero, at consectetur arcu nulla quis dolor. Nunc bibendum vulputate
- consequat. Mauris luctus dolor non dui aliquet, ut finibus metus porttitor.
- Etiam ut lacinia augue, id fringilla lorem. Duis vel pellentesque purus,
- in feugiat ligula. Curabitur efficitur, nunc et mattis volutpat,
- urna turpis tempus magna, nec convallis nisi mauris ut eros. ')//string to long
- ->updateInvoiceOrder()
- ->prepareRequest();
- $this->assertEquals($this->notes, $request->Notes->enc_value);
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -String length : The field Notes must be a string with a maximum length of 200.
+ *
+ */
+ public function test_updateorder_addnotes_chars_validate_invoice()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrder($config)//only need clientid
+ ->setCountryCode('SE')//req for config
+ ->setOrderId('test')
+ ->setNotes('Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+ Nullam faucibus turpis ut nibh cursus, volutpat consectetur odio
+ consequat. Quisque fermentum, augue eget scelerisque hendrerit,
+ libero odio mollis metus, eleifend semper enim ligula eu eros.
+ Nullam varius, nunc sit amet tincidunt volutpat, sem sapien semper
+ libero, at consectetur arcu nulla quis dolor. Nunc bibendum vulputate
+ consequat. Mauris luctus dolor non dui aliquet, ut finibus metus porttitor.
+ Etiam ut lacinia augue, id fringilla lorem. Duis vel pellentesque purus,
+ in feugiat ligula. Curabitur efficitur, nunc et mattis volutpat,
+ urna turpis tempus magna, nec convallis nisi mauris ut eros. ')//string to long
+ ->updateInvoiceOrder()
+ ->prepareRequest();
+ $this->assertEquals($this->notes, $request->Notes->enc_value);
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/AdminService/UpdateOrderRowsRequestTest.php b/test/UnitTest/AdminService/UpdateOrderRowsRequestTest.php
index a26bef67..b559919e 100644
--- a/test/UnitTest/AdminService/UpdateOrderRowsRequestTest.php
+++ b/test/UnitTest/AdminService/UpdateOrderRowsRequestTest.php
@@ -13,170 +13,170 @@
class UpdateOrderRowsRequestTest extends \PHPUnit\Framework\TestCase
{
- public function test_add_single_orderRow_as_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId('test')
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setVatPercent(24)
- ->setAmountExVat(80.00)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()
- ->prepareRequest();
- $this->assertEquals(80, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- }
+ public function test_add_single_orderRow_as_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId('test')
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setVatPercent(24)
+ ->setAmountExVat(80.00)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()
+ ->prepareRequest();
+ $this->assertEquals(80, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ }
- public function test_add_single_orderRow_as_incvat_and_vatpercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId('test')
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setVatPercent(24)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()
- ->prepareRequest();
-// print_r($request);
- $this->assertEquals(123.9876, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertTrue($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- }
+ public function test_add_single_orderRow_as_incvat_and_vatpercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId('test')
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setVatPercent(24)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()
+ ->prepareRequest();
+// print_r($request);
+ $this->assertEquals(123.9876, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertTrue($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ }
- public function test_add_single_orderRow_as_incvat_and_exvat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId('test')
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()
- ->prepareRequest();
-// print_r($request);
- $this->assertEquals(123.9876, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertTrue($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- }
+ public function test_add_single_orderRow_as_incvat_and_exvat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId('test')
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()
+ ->prepareRequest();
+// print_r($request);
+ $this->assertEquals(123.9876, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertTrue($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ }
- public function test_add_single_orderRow_mixed_types_1()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId('test')
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()
- ->prepareRequest();
-// print_r($request);
- $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
- $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
- }
+ public function test_add_single_orderRow_mixed_types_1()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId('test')
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()
+ ->prepareRequest();
+// print_r($request);
+ $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
+ $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
+ }
- public function test_add_single_orderRow_mixed_types_2()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId('test')
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()
- ->prepareRequest();
-// print_r($request);
- $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
- $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
- }
+ public function test_add_single_orderRow_mixed_types_2()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId('test')
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()
+ ->prepareRequest();
+// print_r($request);
+ $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
+ $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
+ }
- public function test_add_single_orderRow_mixed_types_3()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId('test')
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->updateOrderRow(WebPayItem::numberedOrderRow()
- ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()
- ->prepareRequest();
-// print_r($request);
- $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
- $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
- $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
- $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
- $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[2]->enc_value->PricePerUnit->enc_value);
- $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[2]->enc_value->PriceIncludingVat->enc_value);
- }
+ public function test_add_single_orderRow_mixed_types_3()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId('test')
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+ ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()
+ ->prepareRequest();
+// print_r($request);
+ $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PricePerUnit->enc_value);
+ $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[0]->enc_value->PriceIncludingVat->enc_value);
+ $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PricePerUnit->enc_value);
+ $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[1]->enc_value->PriceIncludingVat->enc_value);
+ $this->assertEquals(99.99, $request->UpdatedOrderRows->enc_value->enc_value[2]->enc_value->PricePerUnit->enc_value);
+ $this->assertFalse($request->UpdatedOrderRows->enc_value->enc_value[2]->enc_value->PriceIncludingVat->enc_value);
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : rowNumber is required
- */
- public function test_add_single_orderRow_missing_rownumber()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPayAdmin::updateOrderRows($config)
- ->setCountryCode('SE')
- ->setOrderId('test')
- ->updateOrderRow(WebPayItem::numberedOrderRow()
-// ->setRowNumber(1)
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->updateInvoiceOrderRows()
- ->prepareRequest();
-// print_r($request);
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : rowNumber is required
+ */
+ public function test_add_single_orderRow_missing_rownumber()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPayAdmin::updateOrderRows($config)
+ ->setCountryCode('SE')
+ ->setOrderId('test')
+ ->updateOrderRow(WebPayItem::numberedOrderRow()
+// ->setRowNumber(1)
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->updateInvoiceOrderRows()
+ ->prepareRequest();
+// print_r($request);
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/BuildOrder/AddOrderRowsBuilderTest.php b/test/UnitTest/BuildOrder/AddOrderRowsBuilderTest.php
index bd143a64..3ef75b31 100644
--- a/test/UnitTest/BuildOrder/AddOrderRowsBuilderTest.php
+++ b/test/UnitTest/BuildOrder/AddOrderRowsBuilderTest.php
@@ -13,65 +13,65 @@
class AddOrderRowsBuilderTest extends \PHPUnit\Framework\TestCase
{
- protected $addOrderRowsObject;
+ protected $addOrderRowsObject;
- function setUp()
- {
- $this->addOrderRowsObject = new AddOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- }
+ function setUp()
+ {
+ $this->addOrderRowsObject = new AddOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ }
- public function test_addOrderRowsBuilder_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\AddOrderRowsBuilder", $this->addOrderRowsObject);
- }
+ public function test_addOrderRowsBuilder_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\AddOrderRowsBuilder", $this->addOrderRowsObject);
+ }
- public function test_addOrderRowsBuilder_setOrderId()
- {
- $orderId = "123456";
- $this->addOrderRowsObject->setOrderId($orderId);
- $this->assertEquals($orderId, $this->addOrderRowsObject->orderId);
- }
+ public function test_addOrderRowsBuilder_setOrderId()
+ {
+ $orderId = "123456";
+ $this->addOrderRowsObject->setOrderId($orderId);
+ $this->assertEquals($orderId, $this->addOrderRowsObject->orderId);
+ }
- public function test_addOrderRowsBuilder_setCountryCode()
- {
- $country = "SE";
- $this->addOrderRowsObject->setCountryCode($country);
- $this->assertEquals($country, $this->addOrderRowsObject->countryCode);
- }
+ public function test_addOrderRowsBuilder_setCountryCode()
+ {
+ $country = "SE";
+ $this->addOrderRowsObject->setCountryCode($country);
+ $this->assertEquals($country, $this->addOrderRowsObject->countryCode);
+ }
- public function test_addOrderRowsBuilder_addInvoiceOrderRowsBuilder_returns_AddOrderRowsRequest()
- {
- $orderId = "123456";
- $addOrderRowsObject = $this->addOrderRowsObject
- ->setOrderId($orderId)
- ->addOrderRow(TestUtil::createOrderRow(1.00))
- ->addInvoiceOrderRows();
+ public function test_addOrderRowsBuilder_addInvoiceOrderRowsBuilder_returns_AddOrderRowsRequest()
+ {
+ $orderId = "123456";
+ $addOrderRowsObject = $this->addOrderRowsObject
+ ->setOrderId($orderId)
+ ->addOrderRow(TestUtil::createOrderRow(1.00))
+ ->addInvoiceOrderRows();
- $this->assertInstanceOf("Svea\WebPay\AdminService\AddOrderRowsRequest", $addOrderRowsObject);
- }
+ $this->assertInstanceOf("Svea\WebPay\AdminService\AddOrderRowsRequest", $addOrderRowsObject);
+ }
- public function test_addOrderRowsBuilder_addPaymentPlanOrderRowsBuilder_returns_AddOrderRowsRequest()
- {
- $orderId = "123456";
- $addOrderRowsObject = $this->addOrderRowsObject
- ->setOrderId($orderId)
- ->addOrderRow(TestUtil::createOrderRow(1.00))
- ->addPaymentPlanOrderRows();
+ public function test_addOrderRowsBuilder_addPaymentPlanOrderRowsBuilder_returns_AddOrderRowsRequest()
+ {
+ $orderId = "123456";
+ $addOrderRowsObject = $this->addOrderRowsObject
+ ->setOrderId($orderId)
+ ->addOrderRow(TestUtil::createOrderRow(1.00))
+ ->addPaymentPlanOrderRows();
- $this->assertInstanceOf("Svea\WebPay\AdminService\AddOrderRowsRequest", $addOrderRowsObject);
- }
+ $this->assertInstanceOf("Svea\WebPay\AdminService\AddOrderRowsRequest", $addOrderRowsObject);
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public function test_addOrderRowsBuilder_missing_orderRows_throws_exception()
- {
- $orderId = "123456";
- $addOrderRowsObject = $this->addOrderRowsObject
- ->setOrderId($orderId)
- //->addOrderRow( \Svea\WebPay\Test\TestUtil::createOrderRow(1.00) )
- ->addInvoiceOrderRows();;
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public function test_addOrderRowsBuilder_missing_orderRows_throws_exception()
+ {
+ $orderId = "123456";
+ $addOrderRowsObject = $this->addOrderRowsObject
+ ->setOrderId($orderId)
+ //->addOrderRow( \Svea\WebPay\Test\TestUtil::createOrderRow(1.00) )
+ ->addInvoiceOrderRows();;
- $addOrderRowsObject->doRequest();
- }
+ $addOrderRowsObject->doRequest();
+ }
}
diff --git a/test/UnitTest/BuildOrder/CancelOrderBuilderTest.php b/test/UnitTest/BuildOrder/CancelOrderBuilderTest.php
index 91deb2b3..837d84ba 100644
--- a/test/UnitTest/BuildOrder/CancelOrderBuilderTest.php
+++ b/test/UnitTest/BuildOrder/CancelOrderBuilderTest.php
@@ -13,79 +13,79 @@
class CancelOrderBuilderTest extends \PHPUnit\Framework\TestCase
{
- protected $cancelOrderObject;
+ protected $cancelOrderObject;
- function setUp()
- {
- $this->cancelOrderObject = new CancelOrderBuilder(ConfigurationService::getDefaultConfig());
- }
+ function setUp()
+ {
+ $this->cancelOrderObject = new CancelOrderBuilder(ConfigurationService::getDefaultConfig());
+ }
- public function test_CancelOrderBuilder_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\CancelOrderBuilder", $this->cancelOrderObject);
- }
+ public function test_CancelOrderBuilder_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\CancelOrderBuilder", $this->cancelOrderObject);
+ }
- public function test_CancelOrderBuilder_setOrderId()
- {
- $orderId = "123456";
- $this->cancelOrderObject->setOrderId($orderId);
- $this->assertEquals($orderId, $this->cancelOrderObject->orderId);
- }
+ public function test_CancelOrderBuilder_setOrderId()
+ {
+ $orderId = "123456";
+ $this->cancelOrderObject->setOrderId($orderId);
+ $this->assertEquals($orderId, $this->cancelOrderObject->orderId);
+ }
- public function test_CancelOrderBuilder_setTransactionId()
- {
- $orderId = "123456";
- $this->cancelOrderObject->setTransactionId($orderId);
- $this->assertEquals($orderId, $this->cancelOrderObject->orderId);
- }
+ public function test_CancelOrderBuilder_setTransactionId()
+ {
+ $orderId = "123456";
+ $this->cancelOrderObject->setTransactionId($orderId);
+ $this->assertEquals($orderId, $this->cancelOrderObject->orderId);
+ }
- public function test_CancelOrderBuilder_setCountryCode()
- {
- $country = "SE";
- $this->cancelOrderObject->setCountryCode($country);
- $this->assertEquals($country, $this->cancelOrderObject->countryCode);
- }
+ public function test_CancelOrderBuilder_setCountryCode()
+ {
+ $country = "SE";
+ $this->cancelOrderObject->setCountryCode($country);
+ $this->assertEquals($country, $this->cancelOrderObject->countryCode);
+ }
- public function test_CancelOrderBuilder_setPaymentMethod_INVOICE_returns_CloseOrder_with_correct_orderType()
- {
- $orderId = "123456";
- $paymentMethod = PaymentMethod::INVOICE;
+ public function test_CancelOrderBuilder_setPaymentMethod_INVOICE_returns_CloseOrder_with_correct_orderType()
+ {
+ $orderId = "123456";
+ $paymentMethod = PaymentMethod::INVOICE;
- $closeOrderObject = $this->cancelOrderObject->setOrderId($orderId)->cancelInvoiceOrder();
+ $closeOrderObject = $this->cancelOrderObject->setOrderId($orderId)->cancelInvoiceOrder();
- $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\CloseOrder", $closeOrderObject);
- $this->assertEquals(ConfigurationProvider::INVOICE_TYPE, $closeOrderObject->orderBuilder->orderType);
+ $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\CloseOrder", $closeOrderObject);
+ $this->assertEquals(ConfigurationProvider::INVOICE_TYPE, $closeOrderObject->orderBuilder->orderType);
- }
+ }
- public function test_CancelOrderBuilder_setPaymentMethod_PAYMENTPLAN_returns_CloseOrder_with_correct_orderType()
- {
- $orderId = "123456";
- $paymentMethod = PaymentMethod::PAYMENTPLAN;
+ public function test_CancelOrderBuilder_setPaymentMethod_PAYMENTPLAN_returns_CloseOrder_with_correct_orderType()
+ {
+ $orderId = "123456";
+ $paymentMethod = PaymentMethod::PAYMENTPLAN;
- $closeOrderObject = $this->cancelOrderObject->setOrderId($orderId)->cancelPaymentPlanOrder();
+ $closeOrderObject = $this->cancelOrderObject->setOrderId($orderId)->cancelPaymentPlanOrder();
- $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\CloseOrder", $closeOrderObject);
- $this->assertEquals(ConfigurationProvider::PAYMENTPLAN_TYPE, $closeOrderObject->orderBuilder->orderType);
- }
+ $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\CloseOrder", $closeOrderObject);
+ $this->assertEquals(ConfigurationProvider::PAYMENTPLAN_TYPE, $closeOrderObject->orderBuilder->orderType);
+ }
- public function test_CancelOrderBuilder_setPaymentMethod_KORTCERT_returns_CloseOrder()
- {
- $orderId = "123456";
- $paymentMethod = PaymentMethod::KORTCERT;
+ public function test_CancelOrderBuilder_setPaymentMethod_KORTCERT_returns_CloseOrder()
+ {
+ $orderId = "123456";
+ $paymentMethod = PaymentMethod::KORTCERT;
- $annulTransactionObject = $this->cancelOrderObject->setOrderId($orderId)->cancelCardOrder();
+ $annulTransactionObject = $this->cancelOrderObject->setOrderId($orderId)->cancelCardOrder();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\AnnulTransaction", $annulTransactionObject);
- }
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\AnnulTransaction", $annulTransactionObject);
+ }
- public function test_CancelOrderBuilder_AccountCredit_returns_CloseOrder_with_correct_orderType()
- {
- $orderId = "123456";
+ public function test_CancelOrderBuilder_AccountCredit_returns_CloseOrder_with_correct_orderType()
+ {
+ $orderId = "123456";
- $closeOrderObject = $this->cancelOrderObject->setOrderId($orderId)->cancelAccountCreditOrder();
+ $closeOrderObject = $this->cancelOrderObject->setOrderId($orderId)->cancelAccountCreditOrder();
- $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\CloseOrder", $closeOrderObject);
- $this->assertEquals(ConfigurationProvider::ACCOUNTCREDIT_TYPE, $closeOrderObject->orderBuilder->orderType);
- }
+ $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\CloseOrder", $closeOrderObject);
+ $this->assertEquals(ConfigurationProvider::ACCOUNTCREDIT_TYPE, $closeOrderObject->orderBuilder->orderType);
+ }
}
diff --git a/test/UnitTest/BuildOrder/CancelOrderRowsBuilderTest.php b/test/UnitTest/BuildOrder/CancelOrderRowsBuilderTest.php
index 08aa870f..ad21ac8f 100644
--- a/test/UnitTest/BuildOrder/CancelOrderRowsBuilderTest.php
+++ b/test/UnitTest/BuildOrder/CancelOrderRowsBuilderTest.php
@@ -12,145 +12,145 @@
class CancelOrderRowsBuilderTest extends \PHPUnit\Framework\TestCase
{
- protected $cancelOrderRowsObject;
-
- function setUp()
- {
- $this->cancelOrderRowsObject = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- }
-
- public function test_cancelOrderRowsBuilder_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\CancelOrderRowsBuilder", $this->cancelOrderRowsObject);
- }
-
- public function test_cancelOrderRowsBuilder_setOrderId()
- {
- $orderId = "123456";
- $this->cancelOrderRowsObject->setOrderId($orderId);
- $this->assertEquals($orderId, $this->cancelOrderRowsObject->orderId);
- }
-
- public function test_cancelOrderRowsBuilder_setTransactionId()
- {
- $orderId = "123456";
- $this->cancelOrderRowsObject->setTransactionId($orderId);
- $this->assertEquals($orderId, $this->cancelOrderRowsObject->orderId);
- }
-
- public function test_cancelOrderRowsBuilder_setCountryCode()
- {
- $country = "SE";
- $this->cancelOrderRowsObject->setCountryCode($country);
- $this->assertEquals($country, $this->cancelOrderRowsObject->countryCode);
- }
-
- public function test_addNumberedOrderRow()
- {
- $numberedOrderRow = new NumberedOrderRow();
- $numberedOrderRow
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
-
- $this->cancelOrderRowsObject->addNumberedOrderRow($numberedOrderRow);
- $this->assertInternalType('array', $this->cancelOrderRowsObject->numberedOrderRows);
- }
-
- public function test_addNumberedOrderRows()
- {
- $numberedOrderRow1 = new NumberedOrderRow();
- $numberedOrderRow1
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
- $numberedOrderRow2 = new NumberedOrderRow();
- $numberedOrderRow2
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(2);
-
- $this->cancelOrderRowsObject->addNumberedOrderRows(array($numberedOrderRow1, $numberedOrderRow2));
- $this->assertInternalType('array', $this->cancelOrderRowsObject->numberedOrderRows);
- }
-
- public function test_cancelOrderRowsBuilder_cancelInvoiceOrderRowsBuilder_returns_CancelOrderRowsRequest()
- {
- $orderId = "123456";
- $cancelOrderRowsObject = $this->cancelOrderRowsObject->setOrderId($orderId)->cancelInvoiceOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\CancelOrderRowsRequest", $cancelOrderRowsObject);
- }
-
- public function test_cancelOrderRowsBuilder_cancelPaymentPlanOrderRowsBuilder_returns_CancelOrderRowsRequest()
- {
- $orderId = "123456";
- $cancelOrderRowsObject = $this->cancelOrderRowsObject->setOrderId($orderId)->cancelPaymentPlanOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\CancelOrderRowsRequest", $cancelOrderRowsObject);
- }
-
- public function test_cancelOrderRowsBuilder_cancelAccountCreditOrderRowsBuilder_returns_CancelOrderRowsRequest()
- {
- $orderId = "123456";
- $cancelOrderRowsObject = $this->cancelOrderRowsObject->setOrderId($orderId)->cancelAccountCreditOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\CancelOrderRowsRequest", $cancelOrderRowsObject);
- }
-
- public function test_cancelOrderRowsBuilder_cancelCardOrderRowsBuilder_returns_LowerTransaction()
- {
- $orderId = "123456";
- $mockedNumberedOrderRow = new NumberedOrderRow();
- $mockedNumberedOrderRow
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
-
- $cancelOrderRowsObject = $this->cancelOrderRowsObject
- ->setOrderId($orderId)
- ->addNumberedOrderRow($mockedNumberedOrderRow)
- ->setRowToCancel(1);
-
- $request = $cancelOrderRowsObject->cancelCardOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\LowerTransaction", $request);
- }
-
- public function test_cancelOrderRowsBuilder_cancelAccountCreditRowsBuilder_returns_LowerTransaction()
- {
- $orderId = "123456";
- $mockedNumberedOrderRow = new NumberedOrderRow();
- $mockedNumberedOrderRow
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
-
- $cancelOrderRowsObject = $this->cancelOrderRowsObject
- ->setOrderId($orderId)
- ->addNumberedOrderRow($mockedNumberedOrderRow)
- ->setRowToCancel(1);
-
- $request = $cancelOrderRowsObject->cancelCardOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\LowerTransaction", $request);
- }
-
-
- public function returnProduct()
- {
- $mockedNumberedOrderRow = new NumberedOrderRow();
- $mockedNumberedOrderRow
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
-
- return $mockedNumberedOrderRow;
- }
+ protected $cancelOrderRowsObject;
+
+ function setUp()
+ {
+ $this->cancelOrderRowsObject = new CancelOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ }
+
+ public function test_cancelOrderRowsBuilder_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\CancelOrderRowsBuilder", $this->cancelOrderRowsObject);
+ }
+
+ public function test_cancelOrderRowsBuilder_setOrderId()
+ {
+ $orderId = "123456";
+ $this->cancelOrderRowsObject->setOrderId($orderId);
+ $this->assertEquals($orderId, $this->cancelOrderRowsObject->orderId);
+ }
+
+ public function test_cancelOrderRowsBuilder_setTransactionId()
+ {
+ $orderId = "123456";
+ $this->cancelOrderRowsObject->setTransactionId($orderId);
+ $this->assertEquals($orderId, $this->cancelOrderRowsObject->orderId);
+ }
+
+ public function test_cancelOrderRowsBuilder_setCountryCode()
+ {
+ $country = "SE";
+ $this->cancelOrderRowsObject->setCountryCode($country);
+ $this->assertEquals($country, $this->cancelOrderRowsObject->countryCode);
+ }
+
+ public function test_addNumberedOrderRow()
+ {
+ $numberedOrderRow = new NumberedOrderRow();
+ $numberedOrderRow
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+
+ $this->cancelOrderRowsObject->addNumberedOrderRow($numberedOrderRow);
+ $this->assertInternalType('array', $this->cancelOrderRowsObject->numberedOrderRows);
+ }
+
+ public function test_addNumberedOrderRows()
+ {
+ $numberedOrderRow1 = new NumberedOrderRow();
+ $numberedOrderRow1
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+ $numberedOrderRow2 = new NumberedOrderRow();
+ $numberedOrderRow2
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(2);
+
+ $this->cancelOrderRowsObject->addNumberedOrderRows([$numberedOrderRow1, $numberedOrderRow2]);
+ $this->assertInternalType('array', $this->cancelOrderRowsObject->numberedOrderRows);
+ }
+
+ public function test_cancelOrderRowsBuilder_cancelInvoiceOrderRowsBuilder_returns_CancelOrderRowsRequest()
+ {
+ $orderId = "123456";
+ $cancelOrderRowsObject = $this->cancelOrderRowsObject->setOrderId($orderId)->cancelInvoiceOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\CancelOrderRowsRequest", $cancelOrderRowsObject);
+ }
+
+ public function test_cancelOrderRowsBuilder_cancelPaymentPlanOrderRowsBuilder_returns_CancelOrderRowsRequest()
+ {
+ $orderId = "123456";
+ $cancelOrderRowsObject = $this->cancelOrderRowsObject->setOrderId($orderId)->cancelPaymentPlanOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\CancelOrderRowsRequest", $cancelOrderRowsObject);
+ }
+
+ public function test_cancelOrderRowsBuilder_cancelAccountCreditOrderRowsBuilder_returns_CancelOrderRowsRequest()
+ {
+ $orderId = "123456";
+ $cancelOrderRowsObject = $this->cancelOrderRowsObject->setOrderId($orderId)->cancelAccountCreditOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\CancelOrderRowsRequest", $cancelOrderRowsObject);
+ }
+
+ public function test_cancelOrderRowsBuilder_cancelCardOrderRowsBuilder_returns_LowerTransaction()
+ {
+ $orderId = "123456";
+ $mockedNumberedOrderRow = new NumberedOrderRow();
+ $mockedNumberedOrderRow
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+
+ $cancelOrderRowsObject = $this->cancelOrderRowsObject
+ ->setOrderId($orderId)
+ ->addNumberedOrderRow($mockedNumberedOrderRow)
+ ->setRowToCancel(1);
+
+ $request = $cancelOrderRowsObject->cancelCardOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\LowerTransaction", $request);
+ }
+
+ public function test_cancelOrderRowsBuilder_cancelAccountCreditRowsBuilder_returns_LowerTransaction()
+ {
+ $orderId = "123456";
+ $mockedNumberedOrderRow = new NumberedOrderRow();
+ $mockedNumberedOrderRow
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+
+ $cancelOrderRowsObject = $this->cancelOrderRowsObject
+ ->setOrderId($orderId)
+ ->addNumberedOrderRow($mockedNumberedOrderRow)
+ ->setRowToCancel(1);
+
+ $request = $cancelOrderRowsObject->cancelCardOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\LowerTransaction", $request);
+ }
+
+
+ public function returnProduct()
+ {
+ $mockedNumberedOrderRow = new NumberedOrderRow();
+ $mockedNumberedOrderRow
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+
+ return $mockedNumberedOrderRow;
+ }
}
diff --git a/test/UnitTest/BuildOrder/CreditOrderRowsBuilderTest.php b/test/UnitTest/BuildOrder/CreditOrderRowsBuilderTest.php
index 4d1b863d..4f99b3c5 100644
--- a/test/UnitTest/BuildOrder/CreditOrderRowsBuilderTest.php
+++ b/test/UnitTest/BuildOrder/CreditOrderRowsBuilderTest.php
@@ -14,155 +14,155 @@
class CreditOrderRowsBuilderTest extends \PHPUnit\Framework\TestCase
{
- protected $creditOrderRowsObject;
-
- function setUp()
- {
- $this->creditOrderRowsObject = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- }
-
- public function test_creditOrderRowsBuilder_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\CreditOrderRowsBuilder", $this->creditOrderRowsObject);
- }
-
- public function test_creditOrderRowsBuilder_setOrderId()
- {
- $orderId = "123456";
- $this->creditOrderRowsObject->setOrderId($orderId);
- $this->assertEquals($orderId, $this->creditOrderRowsObject->orderId);
- }
-
- public function test_creditOrderRowsBuilder_setTransactionId()
- {
- $orderId = "123456";
- $this->creditOrderRowsObject->setTransactionId($orderId);
- $this->assertEquals($orderId, $this->creditOrderRowsObject->orderId);
- }
-
- public function test_creditOrderRowsBuilder_setInvoiceId()
- {
- $orderId = "123456";
- $this->creditOrderRowsObject->setInvoiceId($orderId);
- $this->assertEquals($orderId, $this->creditOrderRowsObject->invoiceId);
- }
-
- public function test_creditOrderRowsBuilder_setCountryCode()
- {
- $country = "SE";
- $this->creditOrderRowsObject->setCountryCode($country);
- $this->assertEquals($country, $this->creditOrderRowsObject->countryCode);
- }
-
- public function test_creditOrderRowsBuilder_setInvoiceDistributionType()
- {
- $distributionType = DistributionType::POST;
- $this->creditOrderRowsObject->setInvoiceDistributionType($distributionType);
- $this->assertEquals($distributionType, $this->creditOrderRowsObject->distributionType);
- }
-
- public function test_addNumberedOrderRow()
- {
- $numberedOrderRow = new NumberedOrderRow();
- $numberedOrderRow
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
-
- $this->creditOrderRowsObject->addNumberedOrderRow($numberedOrderRow);
- $this->assertInternalType('array', $this->creditOrderRowsObject->numberedOrderRows);
- }
-
- public function test_addNumberedOrderRows()
- {
- $numberedOrderRow1 = new NumberedOrderRow();
- $numberedOrderRow1
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
- $numberedOrderRow2 = new NumberedOrderRow();
- $numberedOrderRow2
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(2);
-
- $this->creditOrderRowsObject->addNumberedOrderRows(array($numberedOrderRow1, $numberedOrderRow2));
- $this->assertInternalType('array', $this->creditOrderRowsObject->numberedOrderRows);
- }
-
- public function test_creditOrderRowsBuilder_creditInvoiceOrderRowsBuilder_returns_CreditOrderRowsRequest()
- {
- $orderId = "123456";
- $creditOrderRowsObject = $this->creditOrderRowsObject->setOrderId($orderId)->creditInvoiceOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\CreditInvoiceRowsRequest", $creditOrderRowsObject);
- }
-
- public function test_creditOrderRowsBuilder_creditCardOrderRowsBuilder_returns_LowerTransaction()
- {
- $orderId = "123456";
- $mockedNumberedOrderRow = new NumberedOrderRow();
- $mockedNumberedOrderRow
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
-
- $creditOrderRowsObject = $this->creditOrderRowsObject
- ->setCountryCode("SE")
- ->setOrderId($orderId)
- ->addNumberedOrderRow($mockedNumberedOrderRow)
- ->setRowToCredit(1);
-
- $request = $creditOrderRowsObject->creditCardOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CreditTransaction", $request);
- }
-
- public function test_creditOrderRowsBuilder_creditDirectBankOrderRowsBuilder_returns_LowerTransaction()
- {
- $orderId = "123456";
- $mockedNumberedOrderRow = new NumberedOrderRow();
- $mockedNumberedOrderRow
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
-
- $creditOrderRowsObject = $this->creditOrderRowsObject
- ->setCountryCode("SE")
- ->setOrderId($orderId)
- ->addNumberedOrderRow($mockedNumberedOrderRow)
- ->setRowToCredit(1);
-
- $request = $creditOrderRowsObject->creditDirectBankOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CreditTransaction", $request);
- }
-
-
-
- public function returnProduct()
- {
- $mockedNumberedOrderRow = new NumberedOrderRow();
- $mockedNumberedOrderRow
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
-
- return $mockedNumberedOrderRow;
- }
-
- public function test_if_creditAccountCreditOrderRows_returns_appropriate_class()
- {
- $orderId = "123456";
- $creditOrderRowsObject = $this->creditOrderRowsObject->setOrderId($orderId)->creditPaymentPlanOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\CreditPaymentPlanRowsRequest", $creditOrderRowsObject);
- }
+ protected $creditOrderRowsObject;
+
+ function setUp()
+ {
+ $this->creditOrderRowsObject = new CreditOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ }
+
+ public function test_creditOrderRowsBuilder_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\CreditOrderRowsBuilder", $this->creditOrderRowsObject);
+ }
+
+ public function test_creditOrderRowsBuilder_setOrderId()
+ {
+ $orderId = "123456";
+ $this->creditOrderRowsObject->setOrderId($orderId);
+ $this->assertEquals($orderId, $this->creditOrderRowsObject->orderId);
+ }
+
+ public function test_creditOrderRowsBuilder_setTransactionId()
+ {
+ $orderId = "123456";
+ $this->creditOrderRowsObject->setTransactionId($orderId);
+ $this->assertEquals($orderId, $this->creditOrderRowsObject->orderId);
+ }
+
+ public function test_creditOrderRowsBuilder_setInvoiceId()
+ {
+ $orderId = "123456";
+ $this->creditOrderRowsObject->setInvoiceId($orderId);
+ $this->assertEquals($orderId, $this->creditOrderRowsObject->invoiceId);
+ }
+
+ public function test_creditOrderRowsBuilder_setCountryCode()
+ {
+ $country = "SE";
+ $this->creditOrderRowsObject->setCountryCode($country);
+ $this->assertEquals($country, $this->creditOrderRowsObject->countryCode);
+ }
+
+ public function test_creditOrderRowsBuilder_setInvoiceDistributionType()
+ {
+ $distributionType = DistributionType::POST;
+ $this->creditOrderRowsObject->setInvoiceDistributionType($distributionType);
+ $this->assertEquals($distributionType, $this->creditOrderRowsObject->distributionType);
+ }
+
+ public function test_addNumberedOrderRow()
+ {
+ $numberedOrderRow = new NumberedOrderRow();
+ $numberedOrderRow
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+
+ $this->creditOrderRowsObject->addNumberedOrderRow($numberedOrderRow);
+ $this->assertInternalType('array', $this->creditOrderRowsObject->numberedOrderRows);
+ }
+
+ public function test_addNumberedOrderRows()
+ {
+ $numberedOrderRow1 = new NumberedOrderRow();
+ $numberedOrderRow1
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+ $numberedOrderRow2 = new NumberedOrderRow();
+ $numberedOrderRow2
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(2);
+
+ $this->creditOrderRowsObject->addNumberedOrderRows([$numberedOrderRow1, $numberedOrderRow2]);
+ $this->assertInternalType('array', $this->creditOrderRowsObject->numberedOrderRows);
+ }
+
+ public function test_creditOrderRowsBuilder_creditInvoiceOrderRowsBuilder_returns_CreditOrderRowsRequest()
+ {
+ $orderId = "123456";
+ $creditOrderRowsObject = $this->creditOrderRowsObject->setOrderId($orderId)->creditInvoiceOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\CreditInvoiceRowsRequest", $creditOrderRowsObject);
+ }
+
+ public function test_creditOrderRowsBuilder_creditCardOrderRowsBuilder_returns_LowerTransaction()
+ {
+ $orderId = "123456";
+ $mockedNumberedOrderRow = new NumberedOrderRow();
+ $mockedNumberedOrderRow
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+
+ $creditOrderRowsObject = $this->creditOrderRowsObject
+ ->setCountryCode("SE")
+ ->setOrderId($orderId)
+ ->addNumberedOrderRow($mockedNumberedOrderRow)
+ ->setRowToCredit(1);
+
+ $request = $creditOrderRowsObject->creditCardOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CreditTransaction", $request);
+ }
+
+ public function test_creditOrderRowsBuilder_creditDirectBankOrderRowsBuilder_returns_LowerTransaction()
+ {
+ $orderId = "123456";
+ $mockedNumberedOrderRow = new NumberedOrderRow();
+ $mockedNumberedOrderRow
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+
+ $creditOrderRowsObject = $this->creditOrderRowsObject
+ ->setCountryCode("SE")
+ ->setOrderId($orderId)
+ ->addNumberedOrderRow($mockedNumberedOrderRow)
+ ->setRowToCredit(1);
+
+ $request = $creditOrderRowsObject->creditDirectBankOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CreditTransaction", $request);
+ }
+
+
+
+ public function returnProduct()
+ {
+ $mockedNumberedOrderRow = new NumberedOrderRow();
+ $mockedNumberedOrderRow
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+
+ return $mockedNumberedOrderRow;
+ }
+
+ public function test_if_creditAccountCreditOrderRows_returns_appropriate_class()
+ {
+ $orderId = "123456";
+ $creditOrderRowsObject = $this->creditOrderRowsObject->setOrderId($orderId)->creditPaymentPlanOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\CreditPaymentPlanRowsRequest", $creditOrderRowsObject);
+ }
}
diff --git a/test/UnitTest/BuildOrder/DeliverOrderBuilderTest.php b/test/UnitTest/BuildOrder/DeliverOrderBuilderTest.php
index b5f7fde5..987e3947 100644
--- a/test/UnitTest/BuildOrder/DeliverOrderBuilderTest.php
+++ b/test/UnitTest/BuildOrder/DeliverOrderBuilderTest.php
@@ -12,50 +12,50 @@
class DeliverOrderBuilderTest extends \PHPUnit\Framework\TestCase
{
- protected $deliverOrderObject;
-
- function setUp()
- {
- $this->deliverOrderObject = new DeliverOrderBuilder(ConfigurationService::getDefaultConfig());
- }
-
- public function test_DeliverOrderBuilder_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\DeliverOrderBuilder", $this->deliverOrderObject);
- }
-
- public function test_DeliverOrderBuilder_setOrderId()
- {
- $orderId = "123456";
- $this->deliverOrderObject->setOrderId($orderId);
- $this->assertEquals($orderId, $this->deliverOrderObject->orderId);
- }
-
- public function test_DeliverOrderBuilder_setTransactionId()
- {
- $orderId = "123456";
- $this->deliverOrderObject->setTransactionId($orderId);
- $this->assertEquals($orderId, $this->deliverOrderObject->orderId);
- }
-
- public function test_DeliverOrderBuilder_setCountryCode()
- {
- $country = "SE";
- $this->deliverOrderObject->setCountryCode($country);
- $this->assertEquals($country, $this->deliverOrderObject->countryCode);
- }
-
-
-
- public function returnProduct()
- {
- $mockedNumberedOrderRow = new NumberedOrderRow();
- $mockedNumberedOrderRow
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
-
- return $mockedNumberedOrderRow;
- }
+ protected $deliverOrderObject;
+
+ function setUp()
+ {
+ $this->deliverOrderObject = new DeliverOrderBuilder(ConfigurationService::getDefaultConfig());
+ }
+
+ public function test_DeliverOrderBuilder_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\DeliverOrderBuilder", $this->deliverOrderObject);
+ }
+
+ public function test_DeliverOrderBuilder_setOrderId()
+ {
+ $orderId = "123456";
+ $this->deliverOrderObject->setOrderId($orderId);
+ $this->assertEquals($orderId, $this->deliverOrderObject->orderId);
+ }
+
+ public function test_DeliverOrderBuilder_setTransactionId()
+ {
+ $orderId = "123456";
+ $this->deliverOrderObject->setTransactionId($orderId);
+ $this->assertEquals($orderId, $this->deliverOrderObject->orderId);
+ }
+
+ public function test_DeliverOrderBuilder_setCountryCode()
+ {
+ $country = "SE";
+ $this->deliverOrderObject->setCountryCode($country);
+ $this->assertEquals($country, $this->deliverOrderObject->countryCode);
+ }
+
+
+
+ public function returnProduct()
+ {
+ $mockedNumberedOrderRow = new NumberedOrderRow();
+ $mockedNumberedOrderRow
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+
+ return $mockedNumberedOrderRow;
+ }
}
diff --git a/test/UnitTest/BuildOrder/DeliverOrderRowsBuilderTest.php b/test/UnitTest/BuildOrder/DeliverOrderRowsBuilderTest.php
index 062ffc45..ae3947da 100644
--- a/test/UnitTest/BuildOrder/DeliverOrderRowsBuilderTest.php
+++ b/test/UnitTest/BuildOrder/DeliverOrderRowsBuilderTest.php
@@ -14,136 +14,136 @@
class DeliverOrderRowsBuilderTest extends \PHPUnit\Framework\TestCase
{
- protected $deliverOrderRowsObject;
-
- function setUp()
- {
- $this->deliverOrderRowsObject = new DeliverOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- }
-
- public function test_deliverOrderRowsBuilder_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\DeliverOrderRowsBuilder", $this->deliverOrderRowsObject);
- }
-
- public function test_deliverOrderRowsBuilder_setOrderId()
- {
- $orderId = "123456";
- $this->deliverOrderRowsObject->setOrderId($orderId);
- $this->assertEquals($orderId, $this->deliverOrderRowsObject->orderId);
- }
-
- public function test_deliverOrderRowsBuilder_setCountryCode()
- {
- $country = "SE";
- $this->deliverOrderRowsObject->setCountryCode($country);
- $this->assertEquals($country, $this->deliverOrderRowsObject->countryCode);
- }
-
- public function test_deliverOrderRowsBuilder_setInvoiceDistributionType()
- {
- $distributionType = DistributionType::POST;
- $this->deliverOrderRowsObject->setInvoiceDistributionType($distributionType);
- $this->assertEquals($distributionType, $this->deliverOrderRowsObject->distributionType);
- }
-
- public function test_deliverOrderRowsBuilder_deliverInvoiceOrderRowsBuilder_returns_deliverOrderRowsRequest()
- {
- $deliverOrderRowsObject = $this->deliverOrderRowsObject
- ->setCountryCode("SE")
- ->setOrderId(123456)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setRowTodeliver(1)
- ->deliverInvoiceOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\deliverOrderRowsRequest", $deliverOrderRowsObject);
- }
-
- public function test_deliverOrderRowsBuilder_deliverAccountCreditRowsBuilder_returns_deliverOrderRowsRequest()
- {
- $deliverOrderRowsObject = $this->deliverOrderRowsObject
- ->setCountryCode("SE")
- ->setOrderId(123456)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setRowTodeliver(1)
- ->deliverAccountCreditOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\deliverOrderRowsRequest", $deliverOrderRowsObject);
- }
-
-
- /// validations
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage countryCode is required for deliverInvoiceOrderRows(). Use method setCountryCode().
- */
- public function test_deliverInvoiceOrderRows_throws_ValidationException_on_missing_setCountryCode()
- {
- $deliverOrderRowsObject = $this->deliverOrderRowsObject
- //->setCountryCode("SE")
- ->setOrderId(123456)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setRowTodeliver(1);
-
- $deliverOrderRowsObject->deliverInvoiceOrderRows();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage orderId is required for deliverInvoiceOrderRows(). Use method setOrderId().
- */
- public function test_deliverInvoiceOrderRows_throws_ValidationException_on_missing_setOrderId()
- {
- $deliverOrderRowsObject = $this->deliverOrderRowsObject
- ->setCountryCode("SE")
- //->setOrderId(123456)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setRowTodeliver(1);
-
- $deliverOrderRowsObject->deliverInvoiceOrderRows();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage distributionType is required for deliverInvoiceOrderRows(). Use method setInvoiceDistributionType().
- */
- public function test_deliverInvoiceOrderRows_throws_ValidationException_on_missing_setInvoiceDistributionType()
- {
- $deliverOrderRowsObject = $this->deliverOrderRowsObject
- ->setCountryCode("SE")
- ->setOrderId(123456)
- //->setInvoiceDistributionType( \Svea\WebPay\Constant\DistributionType::POST )
- ->setRowTodeliver(1);
-
- $deliverOrderRowsObject->deliverInvoiceOrderRows();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage rowsToDeliver is required for deliverInvoiceOrderRows(). Use methods setRowToDeliver() or setRowsToDeliver().
- */
- public function test_deliverInvoiceOrderRows_throws_ValidationException_on_missing_setRowToDeliver()
- {
- $deliverOrderRowsObject = $this->deliverOrderRowsObject
- ->setCountryCode("SE")
- ->setOrderId(123456)
- ->setInvoiceDistributionType(DistributionType::POST)//->setRowTodeliver(1)
- ;
-
- $deliverOrderRowsObject->deliverInvoiceOrderRows();
- }
-
-
- public function returnProduct()
- {
- $mockedNumberedOrderRow = new NumberedOrderRow();
- $mockedNumberedOrderRow
- ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(1)// required
- ->setRowNumber(1);
-
- return $mockedNumberedOrderRow;
- }
+ protected $deliverOrderRowsObject;
+
+ function setUp()
+ {
+ $this->deliverOrderRowsObject = new DeliverOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ }
+
+ public function test_deliverOrderRowsBuilder_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\DeliverOrderRowsBuilder", $this->deliverOrderRowsObject);
+ }
+
+ public function test_deliverOrderRowsBuilder_setOrderId()
+ {
+ $orderId = "123456";
+ $this->deliverOrderRowsObject->setOrderId($orderId);
+ $this->assertEquals($orderId, $this->deliverOrderRowsObject->orderId);
+ }
+
+ public function test_deliverOrderRowsBuilder_setCountryCode()
+ {
+ $country = "SE";
+ $this->deliverOrderRowsObject->setCountryCode($country);
+ $this->assertEquals($country, $this->deliverOrderRowsObject->countryCode);
+ }
+
+ public function test_deliverOrderRowsBuilder_setInvoiceDistributionType()
+ {
+ $distributionType = DistributionType::POST;
+ $this->deliverOrderRowsObject->setInvoiceDistributionType($distributionType);
+ $this->assertEquals($distributionType, $this->deliverOrderRowsObject->distributionType);
+ }
+
+ public function test_deliverOrderRowsBuilder_deliverInvoiceOrderRowsBuilder_returns_deliverOrderRowsRequest()
+ {
+ $deliverOrderRowsObject = $this->deliverOrderRowsObject
+ ->setCountryCode("SE")
+ ->setOrderId(123456)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setRowTodeliver(1)
+ ->deliverInvoiceOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\deliverOrderRowsRequest", $deliverOrderRowsObject);
+ }
+
+ public function test_deliverOrderRowsBuilder_deliverAccountCreditRowsBuilder_returns_deliverOrderRowsRequest()
+ {
+ $deliverOrderRowsObject = $this->deliverOrderRowsObject
+ ->setCountryCode("SE")
+ ->setOrderId(123456)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setRowTodeliver(1)
+ ->deliverAccountCreditOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\deliverOrderRowsRequest", $deliverOrderRowsObject);
+ }
+
+
+ /// validations
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage countryCode is required for deliverInvoiceOrderRows(). Use method setCountryCode().
+ */
+ public function test_deliverInvoiceOrderRows_throws_ValidationException_on_missing_setCountryCode()
+ {
+ $deliverOrderRowsObject = $this->deliverOrderRowsObject
+ //->setCountryCode("SE")
+ ->setOrderId(123456)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setRowTodeliver(1);
+
+ $deliverOrderRowsObject->deliverInvoiceOrderRows();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage orderId is required for deliverInvoiceOrderRows(). Use method setOrderId().
+ */
+ public function test_deliverInvoiceOrderRows_throws_ValidationException_on_missing_setOrderId()
+ {
+ $deliverOrderRowsObject = $this->deliverOrderRowsObject
+ ->setCountryCode("SE")
+ //->setOrderId(123456)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setRowTodeliver(1);
+
+ $deliverOrderRowsObject->deliverInvoiceOrderRows();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage distributionType is required for deliverInvoiceOrderRows(). Use method setInvoiceDistributionType().
+ */
+ public function test_deliverInvoiceOrderRows_throws_ValidationException_on_missing_setInvoiceDistributionType()
+ {
+ $deliverOrderRowsObject = $this->deliverOrderRowsObject
+ ->setCountryCode("SE")
+ ->setOrderId(123456)
+ //->setInvoiceDistributionType( \Svea\WebPay\Constant\DistributionType::POST )
+ ->setRowTodeliver(1);
+
+ $deliverOrderRowsObject->deliverInvoiceOrderRows();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage rowsToDeliver is required for deliverInvoiceOrderRows(). Use methods setRowToDeliver() or setRowsToDeliver().
+ */
+ public function test_deliverInvoiceOrderRows_throws_ValidationException_on_missing_setRowToDeliver()
+ {
+ $deliverOrderRowsObject = $this->deliverOrderRowsObject
+ ->setCountryCode("SE")
+ ->setOrderId(123456)
+ ->setInvoiceDistributionType(DistributionType::POST)//->setRowTodeliver(1)
+ ;
+
+ $deliverOrderRowsObject->deliverInvoiceOrderRows();
+ }
+
+
+ public function returnProduct()
+ {
+ $mockedNumberedOrderRow = new NumberedOrderRow();
+ $mockedNumberedOrderRow
+ ->setAmountExVat(100.00)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(25)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(1)// required
+ ->setRowNumber(1);
+
+ return $mockedNumberedOrderRow;
+ }
}
diff --git a/test/UnitTest/BuildOrder/NewOrderBuilderTest.php b/test/UnitTest/BuildOrder/NewOrderBuilderTest.php
index 5cbe4729..cc667c47 100644
--- a/test/UnitTest/BuildOrder/NewOrderBuilderTest.php
+++ b/test/UnitTest/BuildOrder/NewOrderBuilderTest.php
@@ -15,626 +15,626 @@
class NewOrderBuilderTest extends \PHPUnit\Framework\TestCase
{
- public function testNewInvoiceOrderCompanyAddresselector()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow());
- $request = $request
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(4608142222)->setAddressSelector("4446e9b2501d4cfca6cc888bf5960379"))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
- $this->assertEquals("4446e9b2501d4cfca6cc888bf5960379", $request->request->CreateOrderInformation->AddressSelector);
- }
-
- public function testNewInvoiceOrderWithOrderRow()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow());
- $request = $request
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals(194605092222, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals(100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals("Product: Specification", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
- }
-
- public function testNewInvoiceOrderWithArray()
- {
- $orderRows[] = TestUtil::createOrderRow();
- $orderRows[] = WebPayItem::orderrow()
- ->setArticleNumber("2")
- ->setQuantity(2)
- ->setAmountExVat(110.00)
- ->setDescription("Specification")
- ->setName('Prod')
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0);
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow($orderRows)
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals(194605092222, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
- }
-
- public function testOrderWithShippingFee()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId(1)
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountExVat(50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- );
- $request = $request
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals(50.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals("shipping: Specification", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- }
-
- public function testOrderWithShippingFeeZero()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId(1)
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountExVat(0)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- );
- $request = $request
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals(0.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals("shipping: Specification", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- }
-
- public function testOrderWithShippingFeeZeroVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId(1)
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountExVat(50)
- ->setUnit("st")
- ->setVatPercent(0)
- ->setDiscountPercent(0)
- );
- $request = $request
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals(50.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals("shipping: Specification", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- }
-
- public function testOrderWithInvoiceFee()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addFee(WebPayItem::invoiceFee()
- ->setName('Svea fee')
- ->setDescription("Fee for invoice")
- ->setAmountExVat(50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- );
- $request = $request
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals(50.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals("Svea fee: Fee for invoice", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- }
-
- public function testOrderWithFixedDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("1")
- ->setAmountIncVat(100.00)
- ->setUnit("st")
- ->setDescription("testOrderWithFixedDiscount")
- ->setName("Fixed")
- );
- $request = $request
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals(-80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals("Fixed: testOrderWithFixedDiscount", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- }
-
- public function testOrderWithRelativeDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addDiscount(
- WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(50)
- ->setUnit("st")
- ->setName('Relative')
- ->setDescription("RelativeDiscount")
- );
- $request = $request
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals(-100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals("Relative: RelativeDiscount", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- }
-
- public function testBuildOrderWithIndividualCustomer()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setNationalIdNumber(194605092222)
- ->setInitials("SB")
- ->setBirthDate(1923, 12, 12)
- ->setName("Tess", "Testson")
- ->setEmail("test@svea.com")
- ->setPhoneNumber(999999)
- ->setIpAddress("123.123.123")
- ->setStreetAddress("Gatan", 23)
- ->setCoAddress("c/o Eriksson")
- ->setZipCode(9999)
- ->setLocality("Stan")
- );
- $request = $request
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals(194605092222, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber);
- $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber);
- $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street);
- $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber);
- $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode);
- $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality);
- $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType);
- }
-
- public function testBuildOrderWithCompanyCustomer()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::companyCustomer()
- ->setNationalIdNumber(666666)
- ->setEmail("test@svea.com")
- ->setPhoneNumber(999999)
- ->setIpAddress("123.123.123")
- ->setStreetAddress("Gatan", 23)
- ->setCoAddress("c/o Eriksson")
- ->setZipCode(9999)
- ->setLocality("Stan")
- );
- $request = $request
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals(666666, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber);
- $this->assertEquals("Company", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType);
- }
-
- public function testBuildOrderWithCompanyCustomerDE()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::companyCustomer()
- ->setVatNumber("SE666666")
- ->setCompanyName("MyCompany")
- ->setEmail("test@svea.com")
- ->setPhoneNumber(999999)
- ->setIpAddress("123.123.123")
- ->setStreetAddress("Gatan", 23)
- ->setCoAddress("c/o Eriksson")
- ->setZipCode(9999)
- ->setLocality("Stan")
- );
- $request = $request
- ->setCountryCode("DE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("EUR")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("SE666666", $request->request->CreateOrderInformation->CustomerIdentity->CompanyIdentity->CompanyVatNumber);
- $this->assertEquals("Company", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType);
- $this->assertEquals("MyCompany", $request->request->CreateOrderInformation->CustomerIdentity->FullName);
- }
-
- public function testAmountsZero()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(0.00)
- ->setAmountIncVat(0.00)
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- }
-
- public function testAmountIncVatZero()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setVatPercent(25)
- ->setAmountIncVat(0.00)
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- }
-
- public function testAmountExVatZero()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(0.00)
- ->setVatPercent(25)
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(25.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- }
-
- public function testOrderRowsInOrderAsAdded()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setDescription("1")
- ->setQuantity(1)
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setDescription("2")
- ->setVatPercent(25)
- ->setAmountIncVat(30)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setDescription("3")
- ->setQuantity(1)
- ->setAmountIncVat(20.00)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDescription("4")
- ->setAmountIncVat(10))
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals("2", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals("3", $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals("4", $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Description);
- }
-
- public function testOrderRowsInOrderAsAdded2()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $request = $request
- ->addFee(WebPayItem::shippingFee()
- ->setDescription("1")
- ->setVatPercent(25)
- ->setAmountIncVat(30.00)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setDescription("2")
- ->setQuantity(1)
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setDescription("3")
- ->setQuantity(1)
- ->setAmountIncVat(20.00)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDescription("4")
- ->setDiscountPercent(10))
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals("2", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals("3", $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals("4", $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Description);
- }
-
- public function testOrderRowsInOrderAsAddedOnHosted()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $form = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setDescription("1")
- ->setQuantity(1)
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setDescription("2")
- ->setVatPercent(25)
- ->setAmountIncVat(30)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setDescription("3")
- ->setQuantity(1)
- ->setAmountIncVat(20.00)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDescription("4")
- ->setAmountIncVat(10))
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::SVEACARDPAY)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
-
- $this->assertEquals('1', $xmlMessage->orderrows->row[0]->description);
- $this->assertEquals('2', $xmlMessage->orderrows->row[1]->description);
- $this->assertEquals('3', $xmlMessage->orderrows->row[2]->description);
- $this->assertEquals('4', $xmlMessage->orderrows->row[3]->description);
-
- }
-
- public function testOrderRowsInOrderAsAdded2OnHosted()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config);
- $form = $request
- ->addFee(WebPayItem::shippingFee()
- ->setDescription("1")
- ->setVatPercent(25)
- ->setAmountIncVat(30)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setDescription("2")
- ->setQuantity(1)
- ->setAmountIncVat(10.00)
- ->setVatPercent(25)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setDescription("3")
- ->setQuantity(1)
- ->setAmountIncVat(20.00)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDescription("4")
- ->setDiscountPercent(10))
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::SVEACARDPAY)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
-
- $this->assertEquals('1', $xmlMessage->orderrows->row[0]->description);
- $this->assertEquals('2', $xmlMessage->orderrows->row[1]->description);
- $this->assertEquals('3', $xmlMessage->orderrows->row[2]->description);
- $this->assertEquals('4', $xmlMessage->orderrows->row[3]->description);
- }
-
-
- /** example how to integrate with array_map
- * function testOrderRowsUsingMap() {
- * $orderRows[] = array_map(magentoRowToOrderRow, $magentoRows);
- *
- * \Svea\WebPay\WebPay::createOrder($config)->addOrderRow(array_map(magentoRowToOrderRow, $magentoRows));
- * }
- *
- * function magentoRowToOrderRow($magentoRow) {
- * return \Svea\WebPay\WebPay::orderrow()
- * ->setArticleNumber($magentoRow->productId)
- * ->setQuantity(..)
- * ->setAmountExVat(...)
- * ->setDescription(...)
- * ->setName('Prod')
- * ->setUnit("st")
- * ->setVatPercent(25)
- * ->setDiscountPercent(0);
- * }
- */
+ public function testNewInvoiceOrderCompanyAddresselector()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow());
+ $request = $request
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(4608142222)->setAddressSelector("4446e9b2501d4cfca6cc888bf5960379"))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+ $this->assertEquals("4446e9b2501d4cfca6cc888bf5960379", $request->request->CreateOrderInformation->AddressSelector);
+ }
+
+ public function testNewInvoiceOrderWithOrderRow()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow());
+ $request = $request
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals(194605092222, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals(100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals("Product: Specification", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
+ }
+
+ public function testNewInvoiceOrderWithArray()
+ {
+ $orderRows[] = TestUtil::createOrderRow();
+ $orderRows[] = WebPayItem::orderrow()
+ ->setArticleNumber("2")
+ ->setQuantity(2)
+ ->setAmountExVat(110.00)
+ ->setDescription("Specification")
+ ->setName('Prod')
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0);
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow($orderRows)
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals(194605092222, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
+ }
+
+ public function testOrderWithShippingFee()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId(1)
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountExVat(50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ );
+ $request = $request
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals(50.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals("shipping: Specification", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ }
+
+ public function testOrderWithShippingFeeZero()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId(1)
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountExVat(0)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ );
+ $request = $request
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals(0.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals("shipping: Specification", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ }
+
+ public function testOrderWithShippingFeeZeroVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId(1)
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountExVat(50)
+ ->setUnit("st")
+ ->setVatPercent(0)
+ ->setDiscountPercent(0)
+ );
+ $request = $request
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals(50.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals("shipping: Specification", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ }
+
+ public function testOrderWithInvoiceFee()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addFee(WebPayItem::invoiceFee()
+ ->setName('Svea fee')
+ ->setDescription("Fee for invoice")
+ ->setAmountExVat(50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ );
+ $request = $request
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals(50.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals("Svea fee: Fee for invoice", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ }
+
+ public function testOrderWithFixedDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("1")
+ ->setAmountIncVat(100.00)
+ ->setUnit("st")
+ ->setDescription("testOrderWithFixedDiscount")
+ ->setName("Fixed")
+ );
+ $request = $request
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals(-80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals("Fixed: testOrderWithFixedDiscount", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ }
+
+ public function testOrderWithRelativeDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addDiscount(
+ WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(50)
+ ->setUnit("st")
+ ->setName('Relative')
+ ->setDescription("RelativeDiscount")
+ );
+ $request = $request
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals(-100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals("Relative: RelativeDiscount", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals("st", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ }
+
+ public function testBuildOrderWithIndividualCustomer()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setNationalIdNumber(194605092222)
+ ->setInitials("SB")
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Tess", "Testson")
+ ->setEmail("test@svea.com")
+ ->setPhoneNumber(999999)
+ ->setIpAddress("123.123.123")
+ ->setStreetAddress("Gatan", 23)
+ ->setCoAddress("c/o Eriksson")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ );
+ $request = $request
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals(194605092222, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber);
+ $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber);
+ $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street);
+ $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber);
+ $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode);
+ $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality);
+ $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType);
+ }
+
+ public function testBuildOrderWithCompanyCustomer()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::companyCustomer()
+ ->setNationalIdNumber(666666)
+ ->setEmail("test@svea.com")
+ ->setPhoneNumber(999999)
+ ->setIpAddress("123.123.123")
+ ->setStreetAddress("Gatan", 23)
+ ->setCoAddress("c/o Eriksson")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ );
+ $request = $request
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals(666666, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber);
+ $this->assertEquals("Company", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType);
+ }
+
+ public function testBuildOrderWithCompanyCustomerDE()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::companyCustomer()
+ ->setVatNumber("SE666666")
+ ->setCompanyName("MyCompany")
+ ->setEmail("test@svea.com")
+ ->setPhoneNumber(999999)
+ ->setIpAddress("123.123.123")
+ ->setStreetAddress("Gatan", 23)
+ ->setCoAddress("c/o Eriksson")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ );
+ $request = $request
+ ->setCountryCode("DE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("EUR")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("SE666666", $request->request->CreateOrderInformation->CustomerIdentity->CompanyIdentity->CompanyVatNumber);
+ $this->assertEquals("Company", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType);
+ $this->assertEquals("MyCompany", $request->request->CreateOrderInformation->CustomerIdentity->FullName);
+ }
+
+ public function testAmountsZero()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(0.00)
+ ->setAmountIncVat(0.00)
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ }
+
+ public function testAmountIncVatZero()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setVatPercent(25)
+ ->setAmountIncVat(0.00)
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ }
+
+ public function testAmountExVatZero()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(0.00)
+ ->setVatPercent(25)
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(25.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ }
+
+ public function testOrderRowsInOrderAsAdded()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setDescription("1")
+ ->setQuantity(1)
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setDescription("2")
+ ->setVatPercent(25)
+ ->setAmountIncVat(30)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setDescription("3")
+ ->setQuantity(1)
+ ->setAmountIncVat(20.00)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDescription("4")
+ ->setAmountIncVat(10))
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals("2", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals("3", $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals("4", $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Description);
+ }
+
+ public function testOrderRowsInOrderAsAdded2()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $request = $request
+ ->addFee(WebPayItem::shippingFee()
+ ->setDescription("1")
+ ->setVatPercent(25)
+ ->setAmountIncVat(30.00)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setDescription("2")
+ ->setQuantity(1)
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setDescription("3")
+ ->setQuantity(1)
+ ->setAmountIncVat(20.00)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDescription("4")
+ ->setDiscountPercent(10))
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("1", $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals("2", $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals("3", $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals("4", $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Description);
+ }
+
+ public function testOrderRowsInOrderAsAddedOnHosted()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $form = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setDescription("1")
+ ->setQuantity(1)
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setDescription("2")
+ ->setVatPercent(25)
+ ->setAmountIncVat(30)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setDescription("3")
+ ->setQuantity(1)
+ ->setAmountIncVat(20.00)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDescription("4")
+ ->setAmountIncVat(10))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::SVEACARDPAY)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+
+ $this->assertEquals('1', $xmlMessage->orderrows->row[0]->description);
+ $this->assertEquals('2', $xmlMessage->orderrows->row[1]->description);
+ $this->assertEquals('3', $xmlMessage->orderrows->row[2]->description);
+ $this->assertEquals('4', $xmlMessage->orderrows->row[3]->description);
+
+ }
+
+ public function testOrderRowsInOrderAsAdded2OnHosted()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config);
+ $form = $request
+ ->addFee(WebPayItem::shippingFee()
+ ->setDescription("1")
+ ->setVatPercent(25)
+ ->setAmountIncVat(30)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setDescription("2")
+ ->setQuantity(1)
+ ->setAmountIncVat(10.00)
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setDescription("3")
+ ->setQuantity(1)
+ ->setAmountIncVat(20.00)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDescription("4")
+ ->setDiscountPercent(10))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::SVEACARDPAY)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+
+ $this->assertEquals('1', $xmlMessage->orderrows->row[0]->description);
+ $this->assertEquals('2', $xmlMessage->orderrows->row[1]->description);
+ $this->assertEquals('3', $xmlMessage->orderrows->row[2]->description);
+ $this->assertEquals('4', $xmlMessage->orderrows->row[3]->description);
+ }
+
+
+ /** example how to integrate with array_map
+ * function testOrderRowsUsingMap() {
+ * $orderRows[] = array_map(magentoRowToOrderRow, $magentoRows);
+ *
+ * \Svea\WebPay\WebPay::createOrder($config)->addOrderRow(array_map(magentoRowToOrderRow, $magentoRows));
+ * }
+ *
+ * function magentoRowToOrderRow($magentoRow) {
+ * return \Svea\WebPay\WebPay::orderrow()
+ * ->setArticleNumber($magentoRow->productId)
+ * ->setQuantity(..)
+ * ->setAmountExVat(...)
+ * ->setDescription(...)
+ * ->setName('Prod')
+ * ->setUnit("st")
+ * ->setVatPercent(25)
+ * ->setDiscountPercent(0);
+ * }
+ */
}
diff --git a/test/UnitTest/BuildOrder/OrderBuilderTest.php b/test/UnitTest/BuildOrder/OrderBuilderTest.php
index b2538238..321f2722 100644
--- a/test/UnitTest/BuildOrder/OrderBuilderTest.php
+++ b/test/UnitTest/BuildOrder/OrderBuilderTest.php
@@ -15,259 +15,259 @@
class OrderBuilderTest extends \PHPUnit\Framework\TestCase
{
- //Set up orderobject
-
- protected function setUp()
- {
- $config = ConfigurationService::getDefaultConfig();
- $this->orderBuilder = WebPay::createOrder($config);
-// $this->orderBuilder->validator = new Svea\WebPay\Test\UnitTest\BuildOrder\Validator\VoidValidator();
- }
-
- public function testBuildOrderWithOrderRow()
- {
- $sveaRequest = WebPay::createOrder(ConfigurationService::getProdConfig())
- ->addOrderRow(TestUtil::createOrderRow());
-
- $this->assertEquals(1, $sveaRequest->orderRows[0]->articleNumber);
- $this->assertEquals(2, $sveaRequest->orderRows[0]->quantity);
- $this->assertEquals(100.00, $sveaRequest->orderRows[0]->amountExVat);
- $this->assertEquals("Specification", $sveaRequest->orderRows[0]->description);
- $this->assertEquals("st", $sveaRequest->orderRows[0]->unit);
- $this->assertEquals(25, $sveaRequest->orderRows[0]->vatPercent);
- $this->assertEquals(0, $sveaRequest->orderRows[0]->vatDiscount);
- //test type
- $this->assertInternalType("int", $sveaRequest->orderRows[0]->quantity);
- $this->assertInternalType("int", $sveaRequest->orderRows[0]->vatPercent);
- }
-
- public function testBuildOrderWithShippingFee()
- {
- $rowFactory = new TestUtil();
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest =
- WebPay::createOrder($config)
- ->run($rowFactory->buildShippingFee());
-
- $this->assertEquals("Specification", $sveaRequest->shippingFeeRows[0]->description);
- $this->assertEquals(50, $sveaRequest->shippingFeeRows[0]->amountExVat);
- $this->assertEquals(25, $sveaRequest->shippingFeeRows[0]->vatPercent);
- }
-
- public function testBuildOrderWithInvoicefee()
- {
- $rowFactory = new TestUtil();
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->run($rowFactory->buildInvoiceFee());
-
- $this->assertEquals("Svea fee", $sveaRequest->invoiceFeeRows[0]->name);
- $this->assertEquals("Fee for invoice", $sveaRequest->invoiceFeeRows[0]->description);
- $this->assertEquals(50, $sveaRequest->invoiceFeeRows[0]->amountExVat);
- $this->assertEquals("st", $sveaRequest->invoiceFeeRows[0]->unit);
- $this->assertEquals(25, $sveaRequest->invoiceFeeRows[0]->vatPercent);
- $this->assertEquals(0, $sveaRequest->invoiceFeeRows[0]->discountPercent);
- }
-
- public function testBuildOrderWithFixedDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest = WebPay::createOrder($config)
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("1")
- ->setAmountIncVat(100.00)
- ->setUnit("st")
- ->setDescription("FixedDiscount")
- ->setName("Fixed")
- );
-
- $this->assertEquals("1", $sveaRequest->fixedDiscountRows[0]->discountId);
- $this->assertEquals(100.00, $sveaRequest->fixedDiscountRows[0]->amount);
- $this->assertEquals("FixedDiscount", $sveaRequest->fixedDiscountRows[0]->description);
- //test type
- $this->assertInternalType("float", $sveaRequest->fixedDiscountRows[0]->amount);
- }
-
- public function testBuildOrderWithRelativeDiscountAsInt()
- {
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest =
- WebPay::createOrder($config)
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(50)
- ->setUnit("st")
- ->setName('Relative')
- ->setDescription("RelativeDiscount")
- );
-
- $this->assertEquals("1", $sveaRequest->relativeDiscountRows[0]->discountId);
- $this->assertEquals(50, $sveaRequest->relativeDiscountRows[0]->discountPercent);
- $this->assertEquals("RelativeDiscount", $sveaRequest->relativeDiscountRows[0]->description);
- //test type
- $this->assertInternalType("int", $sveaRequest->relativeDiscountRows[0]->discountPercent);
- }
-
- public function testBuildOrderWithRelativeDiscountAsFloat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest =
- WebPay::createOrder($config)
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(12.75)
- ->setUnit("st")
- ->setName('Relative')
- ->setDescription("RelativeDiscount")
- );
-
- $this->assertEquals("1", $sveaRequest->relativeDiscountRows[0]->discountId);
- $this->assertEquals(12.75, $sveaRequest->relativeDiscountRows[0]->discountPercent);
- $this->assertEquals("RelativeDiscount", $sveaRequest->relativeDiscountRows[0]->description);
- //test type
- $this->assertInternalType("float", $sveaRequest->relativeDiscountRows[0]->discountPercent);
- }
-
- public function testBuildOrderWithCustomer()
- {
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest = WebPay::createOrder($config)
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setNationalIdNumber(194605092222)
- ->setInitials("SB")
- ->setBirthDate(1923, 12, 12)
- ->setName("Tess", "Testson")
- ->setEmail("test@svea.com")
- ->setPhoneNumber(999999)
- ->setIpAddress("123.123.123")
- ->setStreetAddress("Gatan", 23)
- ->setCoAddress("c/o Eriksson")
- ->setZipCode(9999)
- ->setLocality("Stan")
- );
-
- $this->assertEquals(194605092222, $sveaRequest->customerIdentity->ssn);
- $this->assertEquals("SB", $sveaRequest->customerIdentity->initials);
- $this->assertEquals(19231212, $sveaRequest->customerIdentity->birthDate);
- $this->assertEquals("Tess", $sveaRequest->customerIdentity->firstname);
- $this->assertEquals("Testson", $sveaRequest->customerIdentity->lastname);
- $this->assertEquals("test@svea.com", $sveaRequest->customerIdentity->email);
- $this->assertEquals(999999, $sveaRequest->customerIdentity->phonenumber);
- $this->assertEquals("123.123.123", $sveaRequest->customerIdentity->ipAddress);
- $this->assertEquals("Gatan", $sveaRequest->customerIdentity->street);
- $this->assertEquals(23, $sveaRequest->customerIdentity->housenumber);
- $this->assertEquals("c/o Eriksson", $sveaRequest->customerIdentity->coAddress);
- $this->assertEquals(9999, $sveaRequest->customerIdentity->zipCode);
- $this->assertEquals("Stan", $sveaRequest->customerIdentity->locality);
- }
-
- public function testBuildOrderWithAllCustomerTypes()
- {
- $config = ConfigurationService::getDefaultConfig();
- $company = TRUE;
- $sveaRequest = WebPay::createOrder($config);
- if ($company == TRUE) {
- $item = WebPayItem::companyCustomer();
- $item = $item->setNationalIdNumber(194605092222)
- ->setEmail("test@svea.com")
- ->setCompanyName("TestCompagniet")
- ->setZipCode(9999)
- ->setLocality("Stan")
- ->setIpAddress("123.123.123")
- ->setPhoneNumber(999999);
-
- if ("DE" == "DE") {
- $item = $item
- ->setVatNumber("NL2345234")
- ->setStreetAddress("Gatan", 23);
- }
- }
- $sveaRequest = $sveaRequest->addCustomerDetails($item);
-
- $this->assertEquals(194605092222, $sveaRequest->customerIdentity->orgNumber);
- $this->assertEquals("NL2345234", $sveaRequest->customerIdentity->companyVatNumber);
- $this->assertEquals("test@svea.com", $sveaRequest->customerIdentity->email);
- $this->assertEquals(999999, $sveaRequest->customerIdentity->phonenumber);
- $this->assertEquals("123.123.123", $sveaRequest->customerIdentity->ipAddress);
- $this->assertEquals("Gatan", $sveaRequest->customerIdentity->street);
- $this->assertEquals(23, $sveaRequest->customerIdentity->housenumber);
- $this->assertEquals(9999, $sveaRequest->customerIdentity->zipCode);
- $this->assertEquals("Stan", $sveaRequest->customerIdentity->locality);
- }
-
- public function testBuildOrderWithCompanyDetails()
- {
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest = WebPay::createOrder($config)
- ->addCustomerDetails(WebPayItem::companyCustomer()
- ->setNationalIdNumber("2345234")
- ->setCompanyName("TestCompagniet")
- );
-
- $this->assertEquals("2345234", $sveaRequest->customerIdentity->orgNumber);
- $this->assertEquals("TestCompagniet", $sveaRequest->customerIdentity->companyName);
- }
-
- public function testBuildOrderWithShortOrderDate()
- {
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest = WebPay::createOrder($config)
- ->setOrderDate("2012-12-12");
-
- $this->assertEquals("2012-12-12", $sveaRequest->orderDate);
- }
-
- public function testBuildOrderWithFullISO8601OrderDate()
- {
- $iso8601date = date('c');
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest = WebPay::createOrder($config)
- ->setOrderDate($iso8601date);
-
- $this->assertEquals($iso8601date, $sveaRequest->orderDate);
- }
-
- public function testBuildOrderWithCountryCode()
- {
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest = WebPay::createOrder($config)
- ->setCountryCode("SE");
-
- $this->assertEquals("SE", $sveaRequest->countryCode);
- }
-
- public function testBuildOrderWithCurrency()
- {
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest = WebPay::createOrder($config)
- ->setCurrency("SEK");
-
- $this->assertEquals("SEK", $sveaRequest->currency);
- }
-
- public function testBuildOrderWithCustomerRefNumber()
- {
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest = WebPay::createOrder($config)
- ->setCustomerReference("33");
-
- $this->assertEquals("33", $sveaRequest->customerReference);
- }
-
- public function testBuildOrderWithClientOrderNumber()
- {
- $config = ConfigurationService::getDefaultConfig();
- $sveaRequest = WebPay::createOrder($config)
- ->setClientOrderNumber("33");
-
- $this->assertEquals("33", $sveaRequest->clientOrderNumber);
- }
-
- /**
- * function testThatValidatorIsCalledOnBuild() {
- * $this->orderBuilder->build();
- * $this->assertEquals(1, $this->orderBuilder->validator->nrOfCalls);
- * }
- */
+ //Set up orderobject
+
+ protected function setUp()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $this->orderBuilder = WebPay::createOrder($config);
+// $this->orderBuilder->validator = new Svea\WebPay\Test\UnitTest\BuildOrder\Validator\VoidValidator();
+ }
+
+ public function testBuildOrderWithOrderRow()
+ {
+ $sveaRequest = WebPay::createOrder(ConfigurationService::getProdConfig())
+ ->addOrderRow(TestUtil::createOrderRow());
+
+ $this->assertEquals(1, $sveaRequest->orderRows[0]->articleNumber);
+ $this->assertEquals(2, $sveaRequest->orderRows[0]->quantity);
+ $this->assertEquals(100.00, $sveaRequest->orderRows[0]->amountExVat);
+ $this->assertEquals("Specification", $sveaRequest->orderRows[0]->description);
+ $this->assertEquals("st", $sveaRequest->orderRows[0]->unit);
+ $this->assertEquals(25, $sveaRequest->orderRows[0]->vatPercent);
+ $this->assertEquals(0, $sveaRequest->orderRows[0]->vatDiscount);
+ //test type
+ $this->assertInternalType("int", $sveaRequest->orderRows[0]->quantity);
+ $this->assertInternalType("int", $sveaRequest->orderRows[0]->vatPercent);
+ }
+
+ public function testBuildOrderWithShippingFee()
+ {
+ $rowFactory = new TestUtil();
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest =
+ WebPay::createOrder($config)
+ ->run($rowFactory->buildShippingFee());
+
+ $this->assertEquals("Specification", $sveaRequest->shippingFeeRows[0]->description);
+ $this->assertEquals(50, $sveaRequest->shippingFeeRows[0]->amountExVat);
+ $this->assertEquals(25, $sveaRequest->shippingFeeRows[0]->vatPercent);
+ }
+
+ public function testBuildOrderWithInvoicefee()
+ {
+ $rowFactory = new TestUtil();
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->run($rowFactory->buildInvoiceFee());
+
+ $this->assertEquals("Svea fee", $sveaRequest->invoiceFeeRows[0]->name);
+ $this->assertEquals("Fee for invoice", $sveaRequest->invoiceFeeRows[0]->description);
+ $this->assertEquals(50, $sveaRequest->invoiceFeeRows[0]->amountExVat);
+ $this->assertEquals("st", $sveaRequest->invoiceFeeRows[0]->unit);
+ $this->assertEquals(25, $sveaRequest->invoiceFeeRows[0]->vatPercent);
+ $this->assertEquals(0, $sveaRequest->invoiceFeeRows[0]->discountPercent);
+ }
+
+ public function testBuildOrderWithFixedDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest = WebPay::createOrder($config)
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("1")
+ ->setAmountIncVat(100.00)
+ ->setUnit("st")
+ ->setDescription("FixedDiscount")
+ ->setName("Fixed")
+ );
+
+ $this->assertEquals("1", $sveaRequest->fixedDiscountRows[0]->discountId);
+ $this->assertEquals(100.00, $sveaRequest->fixedDiscountRows[0]->amount);
+ $this->assertEquals("FixedDiscount", $sveaRequest->fixedDiscountRows[0]->description);
+ //test type
+ $this->assertInternalType("float", $sveaRequest->fixedDiscountRows[0]->amount);
+ }
+
+ public function testBuildOrderWithRelativeDiscountAsInt()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest =
+ WebPay::createOrder($config)
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(50)
+ ->setUnit("st")
+ ->setName('Relative')
+ ->setDescription("RelativeDiscount")
+ );
+
+ $this->assertEquals("1", $sveaRequest->relativeDiscountRows[0]->discountId);
+ $this->assertEquals(50, $sveaRequest->relativeDiscountRows[0]->discountPercent);
+ $this->assertEquals("RelativeDiscount", $sveaRequest->relativeDiscountRows[0]->description);
+ //test type
+ $this->assertInternalType("int", $sveaRequest->relativeDiscountRows[0]->discountPercent);
+ }
+
+ public function testBuildOrderWithRelativeDiscountAsFloat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest =
+ WebPay::createOrder($config)
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(12.75)
+ ->setUnit("st")
+ ->setName('Relative')
+ ->setDescription("RelativeDiscount")
+ );
+
+ $this->assertEquals("1", $sveaRequest->relativeDiscountRows[0]->discountId);
+ $this->assertEquals(12.75, $sveaRequest->relativeDiscountRows[0]->discountPercent);
+ $this->assertEquals("RelativeDiscount", $sveaRequest->relativeDiscountRows[0]->description);
+ //test type
+ $this->assertInternalType("float", $sveaRequest->relativeDiscountRows[0]->discountPercent);
+ }
+
+ public function testBuildOrderWithCustomer()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest = WebPay::createOrder($config)
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setNationalIdNumber(194605092222)
+ ->setInitials("SB")
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Tess", "Testson")
+ ->setEmail("test@svea.com")
+ ->setPhoneNumber(999999)
+ ->setIpAddress("123.123.123")
+ ->setStreetAddress("Gatan", 23)
+ ->setCoAddress("c/o Eriksson")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ );
+
+ $this->assertEquals(194605092222, $sveaRequest->customerIdentity->ssn);
+ $this->assertEquals("SB", $sveaRequest->customerIdentity->initials);
+ $this->assertEquals(19231212, $sveaRequest->customerIdentity->birthDate);
+ $this->assertEquals("Tess", $sveaRequest->customerIdentity->firstname);
+ $this->assertEquals("Testson", $sveaRequest->customerIdentity->lastname);
+ $this->assertEquals("test@svea.com", $sveaRequest->customerIdentity->email);
+ $this->assertEquals(999999, $sveaRequest->customerIdentity->phonenumber);
+ $this->assertEquals("123.123.123", $sveaRequest->customerIdentity->ipAddress);
+ $this->assertEquals("Gatan", $sveaRequest->customerIdentity->street);
+ $this->assertEquals(23, $sveaRequest->customerIdentity->housenumber);
+ $this->assertEquals("c/o Eriksson", $sveaRequest->customerIdentity->coAddress);
+ $this->assertEquals(9999, $sveaRequest->customerIdentity->zipCode);
+ $this->assertEquals("Stan", $sveaRequest->customerIdentity->locality);
+ }
+
+ public function testBuildOrderWithAllCustomerTypes()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $company = TRUE;
+ $sveaRequest = WebPay::createOrder($config);
+ if ($company == TRUE) {
+ $item = WebPayItem::companyCustomer();
+ $item = $item->setNationalIdNumber(194605092222)
+ ->setEmail("test@svea.com")
+ ->setCompanyName("TestCompagniet")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ ->setIpAddress("123.123.123")
+ ->setPhoneNumber(999999);
+
+ if ("DE" == "DE") {
+ $item = $item
+ ->setVatNumber("NL2345234")
+ ->setStreetAddress("Gatan", 23);
+ }
+ }
+ $sveaRequest = $sveaRequest->addCustomerDetails($item);
+
+ $this->assertEquals(194605092222, $sveaRequest->customerIdentity->orgNumber);
+ $this->assertEquals("NL2345234", $sveaRequest->customerIdentity->companyVatNumber);
+ $this->assertEquals("test@svea.com", $sveaRequest->customerIdentity->email);
+ $this->assertEquals(999999, $sveaRequest->customerIdentity->phonenumber);
+ $this->assertEquals("123.123.123", $sveaRequest->customerIdentity->ipAddress);
+ $this->assertEquals("Gatan", $sveaRequest->customerIdentity->street);
+ $this->assertEquals(23, $sveaRequest->customerIdentity->housenumber);
+ $this->assertEquals(9999, $sveaRequest->customerIdentity->zipCode);
+ $this->assertEquals("Stan", $sveaRequest->customerIdentity->locality);
+ }
+
+ public function testBuildOrderWithCompanyDetails()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest = WebPay::createOrder($config)
+ ->addCustomerDetails(WebPayItem::companyCustomer()
+ ->setNationalIdNumber("2345234")
+ ->setCompanyName("TestCompagniet")
+ );
+
+ $this->assertEquals("2345234", $sveaRequest->customerIdentity->orgNumber);
+ $this->assertEquals("TestCompagniet", $sveaRequest->customerIdentity->companyName);
+ }
+
+ public function testBuildOrderWithShortOrderDate()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest = WebPay::createOrder($config)
+ ->setOrderDate("2012-12-12");
+
+ $this->assertEquals("2012-12-12", $sveaRequest->orderDate);
+ }
+
+ public function testBuildOrderWithFullISO8601OrderDate()
+ {
+ $iso8601date = date('c');
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest = WebPay::createOrder($config)
+ ->setOrderDate($iso8601date);
+
+ $this->assertEquals($iso8601date, $sveaRequest->orderDate);
+ }
+
+ public function testBuildOrderWithCountryCode()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest = WebPay::createOrder($config)
+ ->setCountryCode("SE");
+
+ $this->assertEquals("SE", $sveaRequest->countryCode);
+ }
+
+ public function testBuildOrderWithCurrency()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest = WebPay::createOrder($config)
+ ->setCurrency("SEK");
+
+ $this->assertEquals("SEK", $sveaRequest->currency);
+ }
+
+ public function testBuildOrderWithCustomerRefNumber()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest = WebPay::createOrder($config)
+ ->setCustomerReference("33");
+
+ $this->assertEquals("33", $sveaRequest->customerReference);
+ }
+
+ public function testBuildOrderWithClientOrderNumber()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $sveaRequest = WebPay::createOrder($config)
+ ->setClientOrderNumber("33");
+
+ $this->assertEquals("33", $sveaRequest->clientOrderNumber);
+ }
+
+ /**
+ * function testThatValidatorIsCalledOnBuild() {
+ * $this->orderBuilder->build();
+ * $this->assertEquals(1, $this->orderBuilder->validator->nrOfCalls);
+ * }
+ */
}
diff --git a/test/UnitTest/BuildOrder/QueryOrderBuilderTest.php b/test/UnitTest/BuildOrder/QueryOrderBuilderTest.php
index 2bf19c6a..4b0110d1 100644
--- a/test/UnitTest/BuildOrder/QueryOrderBuilderTest.php
+++ b/test/UnitTest/BuildOrder/QueryOrderBuilderTest.php
@@ -12,81 +12,81 @@
class QueryOrderBuilderTest extends \PHPUnit\Framework\TestCase
{
- protected $queryOrderObject;
+ protected $queryOrderObject;
- function setUp()
- {
- $this->queryOrderObject = new QueryOrderBuilder(ConfigurationService::getDefaultConfig());
- }
+ function setUp()
+ {
+ $this->queryOrderObject = new QueryOrderBuilder(ConfigurationService::getDefaultConfig());
+ }
- public function test_queryOrderBuilder_class_exists()
- {
- $this->assertInstanceOf('Svea\WebPay\BuildOrder\QueryOrderBuilder', $this->queryOrderObject);
- }
+ public function test_queryOrderBuilder_class_exists()
+ {
+ $this->assertInstanceOf('Svea\WebPay\BuildOrder\QueryOrderBuilder', $this->queryOrderObject);
+ }
- public function test_queryOrderBuilder_setOrderId()
- {
- $orderId = "123456";
- $this->queryOrderObject->setOrderId($orderId);
- $this->assertEquals($orderId, $this->queryOrderObject->orderId);
- }
+ public function test_queryOrderBuilder_setOrderId()
+ {
+ $orderId = "123456";
+ $this->queryOrderObject->setOrderId($orderId);
+ $this->assertEquals($orderId, $this->queryOrderObject->orderId);
+ }
- public function test_queryOrderBuilder_setTransactionId()
- {
- $orderId = "123456";
- $this->queryOrderObject->setTransactionId($orderId);
- $this->assertEquals($orderId, $this->queryOrderObject->orderId);
- }
+ public function test_queryOrderBuilder_setTransactionId()
+ {
+ $orderId = "123456";
+ $this->queryOrderObject->setTransactionId($orderId);
+ $this->assertEquals($orderId, $this->queryOrderObject->orderId);
+ }
- public function test_queryOrderBuilder_setCountryCode()
- {
- $country = "SE";
- $this->queryOrderObject->setCountryCode($country);
- $this->assertEquals($country, $this->queryOrderObject->countryCode);
- }
+ public function test_queryOrderBuilder_setCountryCode()
+ {
+ $country = "SE";
+ $this->queryOrderObject->setCountryCode($country);
+ $this->assertEquals($country, $this->queryOrderObject->countryCode);
+ }
- public function test_queryOrderBuilder_queryInvoiceOrder_returns_GetOrdersRequest_with_correct_orderType()
- {
- $orderId = "123456";
- $paymentMethod = ConfigurationProvider::INVOICE_TYPE; // todo check these ws ConfigProvicer::INVOICE_TYPE et al...
+ public function test_queryOrderBuilder_queryInvoiceOrder_returns_GetOrdersRequest_with_correct_orderType()
+ {
+ $orderId = "123456";
+ $paymentMethod = ConfigurationProvider::INVOICE_TYPE; // todo check these ws ConfigProvicer::INVOICE_TYPE et al...
- $queryOrderObject = $this->queryOrderObject->setOrderId($orderId)->queryInvoiceOrder();
+ $queryOrderObject = $this->queryOrderObject->setOrderId($orderId)->queryInvoiceOrder();
- $this->assertInstanceOf("Svea\WebPay\AdminService\GetOrdersRequest", $queryOrderObject);
- $this->assertEquals($paymentMethod, $queryOrderObject->orderBuilder->orderType);
+ $this->assertInstanceOf("Svea\WebPay\AdminService\GetOrdersRequest", $queryOrderObject);
+ $this->assertEquals($paymentMethod, $queryOrderObject->orderBuilder->orderType);
- }
+ }
- public function test_queryOrderBuilder_queryPaymentPlanOrder_returns_GetOrdersRequest_with_correct_orderType()
- {
- $orderId = "123456";
- $paymentMethod = ConfigurationProvider::PAYMENTPLAN_TYPE; // todo check these ws ConfigProvicer::INVOICE_TYPE et al...
+ public function test_queryOrderBuilder_queryPaymentPlanOrder_returns_GetOrdersRequest_with_correct_orderType()
+ {
+ $orderId = "123456";
+ $paymentMethod = ConfigurationProvider::PAYMENTPLAN_TYPE; // todo check these ws ConfigProvicer::INVOICE_TYPE et al...
- $queryOrderObject = $this->queryOrderObject->setOrderId($orderId)->queryPaymentPlanOrder();
+ $queryOrderObject = $this->queryOrderObject->setOrderId($orderId)->queryPaymentPlanOrder();
- $this->assertInstanceOf("Svea\WebPay\AdminService\GetOrdersRequest", $queryOrderObject);
- $this->assertEquals($paymentMethod, $queryOrderObject->orderBuilder->orderType);
+ $this->assertInstanceOf("Svea\WebPay\AdminService\GetOrdersRequest", $queryOrderObject);
+ $this->assertEquals($paymentMethod, $queryOrderObject->orderBuilder->orderType);
- }
+ }
- public function test_queryOrderBuilder_queryAccountCreditOrder_returns_GetOrdersRequest_with_correct_orderType()
- {
- $orderId = "123456";
- $paymentMethod = ConfigurationProvider::ACCOUNTCREDIT_TYPE; // todo check these ws ConfigProvicer::ACCOUNTCREDIT_TYPE et al...
+ public function test_queryOrderBuilder_queryAccountCreditOrder_returns_GetOrdersRequest_with_correct_orderType()
+ {
+ $orderId = "123456";
+ $paymentMethod = ConfigurationProvider::ACCOUNTCREDIT_TYPE; // todo check these ws ConfigProvicer::ACCOUNTCREDIT_TYPE et al...
- $queryOrderObject = $this->queryOrderObject->setOrderId($orderId)->queryAccountCreditOrder();
+ $queryOrderObject = $this->queryOrderObject->setOrderId($orderId)->queryAccountCreditOrder();
- $this->assertInstanceOf("Svea\WebPay\AdminService\GetOrdersRequest", $queryOrderObject);
- $this->assertEquals($paymentMethod, $queryOrderObject->orderBuilder->orderType);
+ $this->assertInstanceOf("Svea\WebPay\AdminService\GetOrdersRequest", $queryOrderObject);
+ $this->assertEquals($paymentMethod, $queryOrderObject->orderBuilder->orderType);
- }
+ }
- public function test_queryOrderBuilder_queryCardOrder_returns_QueryTransaction()
- {
- $orderId = "123456";
+ public function test_queryOrderBuilder_queryCardOrder_returns_QueryTransaction()
+ {
+ $orderId = "123456";
- $queryOrderObject = $this->queryOrderObject->setOrderId($orderId)->queryCardOrder();
+ $queryOrderObject = $this->queryOrderObject->setOrderId($orderId)->queryCardOrder();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransaction", $queryOrderObject);
- }
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransaction", $queryOrderObject);
+ }
}
diff --git a/test/UnitTest/BuildOrder/UpdateOrderRowsBuilderTest.php b/test/UnitTest/BuildOrder/UpdateOrderRowsBuilderTest.php
index 811d417e..bd032d72 100644
--- a/test/UnitTest/BuildOrder/UpdateOrderRowsBuilderTest.php
+++ b/test/UnitTest/BuildOrder/UpdateOrderRowsBuilderTest.php
@@ -11,45 +11,45 @@
class UpdateOrderRowsBuilderTest extends \PHPUnit\Framework\TestCase
{
- protected $updateOrderRowsObject;
-
- function setUp()
- {
- $this->updateOrderRowsObject = new UpdateOrderRowsBuilder(ConfigurationService::getDefaultConfig());
- }
-
- public function test_updateOrderRowsBuilder_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\UpdateOrderRowsBuilder", $this->updateOrderRowsObject);
- }
-
- public function test_updateOrderRowsBuilder_setOrderId()
- {
- $orderId = "123456";
- $this->updateOrderRowsObject->setOrderId($orderId);
- $this->assertEquals($orderId, $this->updateOrderRowsObject->orderId);
- }
-
- public function test_updateOrderRowsBuilder_setCountryCode()
- {
- $country = "SE";
- $this->updateOrderRowsObject->setCountryCode($country);
- $this->assertEquals($country, $this->updateOrderRowsObject->countryCode);
- }
-
- public function test_updateOrderRowsBuilder_updateInvoiceOrderRowsBuilder_returns_UpdateOrderRowsRequest()
- {
- $orderId = "123456";
- $updateOrderRowsObject = $this->updateOrderRowsObject->setOrderId($orderId)->updateInvoiceOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\UpdateOrderRowsRequest", $updateOrderRowsObject);
- }
-
- public function test_updateOrderRowsBuilder_updatePaymentPlanOrderRowsBuilder_returns_UpdateOrderRowsRequest()
- {
- $orderId = "123456";
- $updateOrderRowsObject = $this->updateOrderRowsObject->setOrderId($orderId)->updatePaymentPlanOrderRows();
-
- $this->assertInstanceOf("Svea\WebPay\AdminService\UpdateOrderRowsRequest", $updateOrderRowsObject);
- }
+ protected $updateOrderRowsObject;
+
+ function setUp()
+ {
+ $this->updateOrderRowsObject = new UpdateOrderRowsBuilder(ConfigurationService::getDefaultConfig());
+ }
+
+ public function test_updateOrderRowsBuilder_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\UpdateOrderRowsBuilder", $this->updateOrderRowsObject);
+ }
+
+ public function test_updateOrderRowsBuilder_setOrderId()
+ {
+ $orderId = "123456";
+ $this->updateOrderRowsObject->setOrderId($orderId);
+ $this->assertEquals($orderId, $this->updateOrderRowsObject->orderId);
+ }
+
+ public function test_updateOrderRowsBuilder_setCountryCode()
+ {
+ $country = "SE";
+ $this->updateOrderRowsObject->setCountryCode($country);
+ $this->assertEquals($country, $this->updateOrderRowsObject->countryCode);
+ }
+
+ public function test_updateOrderRowsBuilder_updateInvoiceOrderRowsBuilder_returns_UpdateOrderRowsRequest()
+ {
+ $orderId = "123456";
+ $updateOrderRowsObject = $this->updateOrderRowsObject->setOrderId($orderId)->updateInvoiceOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\UpdateOrderRowsRequest", $updateOrderRowsObject);
+ }
+
+ public function test_updateOrderRowsBuilder_updatePaymentPlanOrderRowsBuilder_returns_UpdateOrderRowsRequest()
+ {
+ $orderId = "123456";
+ $updateOrderRowsObject = $this->updateOrderRowsObject->setOrderId($orderId)->updatePaymentPlanOrderRows();
+
+ $this->assertInstanceOf("Svea\WebPay\AdminService\UpdateOrderRowsRequest", $updateOrderRowsObject);
+ }
}
diff --git a/test/UnitTest/BuildOrder/Validator/HostedOrderValidatorTest.php b/test/UnitTest/BuildOrder/Validator/HostedOrderValidatorTest.php
index e9bbcffb..c67774ab 100644
--- a/test/UnitTest/BuildOrder/Validator/HostedOrderValidatorTest.php
+++ b/test/UnitTest/BuildOrder/Validator/HostedOrderValidatorTest.php
@@ -13,160 +13,160 @@
class HostedOrderValidatorTest extends \PHPUnit\Framework\TestCase
{
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : ClientOrderNumber is required. Use function setClientOrderNumber().
- */
- public function testFailOnNullCustomerRefNo()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->usePayPageCardOnly()
- ->setReturnUrl("myurl.se");
-
- $order->getPaymentForm();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : ClientOrderNumber is required. Use function setClientOrderNumber().
- */
- public function testFailOnEmptyCustomerRefNo()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setClientOrderNumber("")
- ->usePayPageCardOnly()
- ->setReturnUrl("myurl.se");
-
- $order->getPaymentForm();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage
- * -missing value : Initials is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setInitials().
- * -missing value : BirthDate is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setBirthDate().
- * -missing value : Name is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setName().
- * -missing value : StreetAddress is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setStreetAddress().
- * -missing value : Locality is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setLocality().
- * -missing value : ZipCode is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setZipCode().
- */
- public function testFailOnMissingCustomerForNL()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("NL")
- ->setCurrency("SEK")
- ->setClientOrderNumber("55")
- ->usePaymentMethod(PaymentMethod::INVOICE)
- ->setReturnUrl("myurl.se");
-
- $order->getPaymentForm();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage
- * -missing value : StreetAddress is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setStreetAddress().
- * -missing value : Locality is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setLocality().
- * -missing value : ZipCode is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setZipCode().
- * -missing value : VatNumber is required for INVOICE and PAYMENTPLAN payments for company customers when countrycode is NL. Use function setVatNumber().
- * -missing value : CompanyName is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setCompanyName().
- */
- public function testFailOnMissingCompanyCustomerForNL()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("NL")
- ->setCurrency("SEK")
- ->setClientOrderNumber("55")
- ->usePaymentMethod(PaymentMethod::INVOICE)
- ->setReturnUrl("myurl.se");
-
- $order->getPaymentForm();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : Currency is required. Use function setCurrency().
- */
- public function testFailOnMissingCurrency()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("SE")
- ->setClientOrderNumber("34")
- ->usePayPageCardOnly()
- ->setReturnUrl("myurl.se");
-
- $order->getPaymentForm();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : ReturnUrl is required. Use function setReturnUrl().
- */
- public function testFailOnMissingReturnUrl()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setClientOrderNumber("34")
- ->usePayPage();
- // ->setReturnUrl("myurl.se")
-
- $order->getPaymentForm();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -unsupported currency : Currency is not supported with this payment method.
- */
- public function testUnsupportedCardPayCurrency()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCurrency("XXX")
- ->setClientOrderNumber("34")
- ->usePaymentMethod("SVEACARDPAY");
-
- $order->getPaymentForm();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : CountryCode is required for SVEACARDPAY_PF. Use function setCountryCode().
- */
- public function testNullCountryCodeWithCardPayPF()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCurrency("SEK")
- ->setClientOrderNumber("34")
- ->usePaymentMethod("SVEACARDPAY_PF");
-
- $order->getPaymentForm();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : ClientOrderNumber is required. Use function setClientOrderNumber().
+ */
+ public function testFailOnNullCustomerRefNo()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->usePayPageCardOnly()
+ ->setReturnUrl("myurl.se");
+
+ $order->getPaymentForm();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : ClientOrderNumber is required. Use function setClientOrderNumber().
+ */
+ public function testFailOnEmptyCustomerRefNo()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setClientOrderNumber("")
+ ->usePayPageCardOnly()
+ ->setReturnUrl("myurl.se");
+
+ $order->getPaymentForm();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage
+ * -missing value : Initials is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setInitials().
+ * -missing value : BirthDate is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setBirthDate().
+ * -missing value : Name is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setName().
+ * -missing value : StreetAddress is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setStreetAddress().
+ * -missing value : Locality is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setLocality().
+ * -missing value : ZipCode is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setZipCode().
+ */
+ public function testFailOnMissingCustomerForNL()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("NL")
+ ->setCurrency("SEK")
+ ->setClientOrderNumber("55")
+ ->usePaymentMethod(PaymentMethod::INVOICE)
+ ->setReturnUrl("myurl.se");
+
+ $order->getPaymentForm();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage
+ * -missing value : StreetAddress is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setStreetAddress().
+ * -missing value : Locality is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setLocality().
+ * -missing value : ZipCode is required for INVOICE and PAYMENTPLAN payments for all customers when countrycode is NL. Use function setZipCode().
+ * -missing value : VatNumber is required for INVOICE and PAYMENTPLAN payments for company customers when countrycode is NL. Use function setVatNumber().
+ * -missing value : CompanyName is required for INVOICE and PAYMENTPLAN payments for individual customers when countrycode is NL. Use function setCompanyName().
+ */
+ public function testFailOnMissingCompanyCustomerForNL()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("NL")
+ ->setCurrency("SEK")
+ ->setClientOrderNumber("55")
+ ->usePaymentMethod(PaymentMethod::INVOICE)
+ ->setReturnUrl("myurl.se");
+
+ $order->getPaymentForm();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : Currency is required. Use function setCurrency().
+ */
+ public function testFailOnMissingCurrency()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("34")
+ ->usePayPageCardOnly()
+ ->setReturnUrl("myurl.se");
+
+ $order->getPaymentForm();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : ReturnUrl is required. Use function setReturnUrl().
+ */
+ public function testFailOnMissingReturnUrl()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setClientOrderNumber("34")
+ ->usePayPage();
+ // ->setReturnUrl("myurl.se")
+
+ $order->getPaymentForm();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -unsupported currency : Currency is not supported with this payment method.
+ */
+ public function testUnsupportedCardPayCurrency()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCurrency("XXX")
+ ->setClientOrderNumber("34")
+ ->usePaymentMethod("SVEACARDPAY");
+
+ $order->getPaymentForm();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : CountryCode is required for SVEACARDPAY_PF. Use function setCountryCode().
+ */
+ public function testNullCountryCodeWithCardPayPF()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCurrency("SEK")
+ ->setClientOrderNumber("34")
+ ->usePaymentMethod("SVEACARDPAY_PF");
+
+ $order->getPaymentForm();
+ }
}
diff --git a/test/UnitTest/BuildOrder/Validator/VoidValidator.php b/test/UnitTest/BuildOrder/Validator/VoidValidator.php
index 7f679889..f5331d92 100644
--- a/test/UnitTest/BuildOrder/Validator/VoidValidator.php
+++ b/test/UnitTest/BuildOrder/Validator/VoidValidator.php
@@ -10,10 +10,10 @@
class VoidValidator extends OrderValidator
{
- public $nrOfCalls = 0;
+ public $nrOfCalls = 0;
- public function validate($order)
- {
- $this->nrOfCalls++;
- }
+ public function validate($order)
+ {
+ $this->nrOfCalls++;
+ }
}
diff --git a/test/UnitTest/BuildOrder/Validator/WebServiceOrderValidatorTest.php b/test/UnitTest/BuildOrder/Validator/WebServiceOrderValidatorTest.php
index b057d1b7..cbb522bb 100644
--- a/test/UnitTest/BuildOrder/Validator/WebServiceOrderValidatorTest.php
+++ b/test/UnitTest/BuildOrder/Validator/WebServiceOrderValidatorTest.php
@@ -15,693 +15,693 @@
*/
class WebServiceOrderValidatorTest extends \PHPUnit\Framework\TestCase
{
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : Customer values are required for Invoice and PaymentPlan orders.
- *
- * function te_stFailOnMissingCustomerIdentity() {
- * $builder = \Svea\WebPay\WebPay::createOrder($config);
- * $order = $builder
- * ->beginOrderRow()
- * ->setAmountExVat(100)
- * ->setVatPercent(20)
- * ->setQuantity(1)
- * ->endOrderRow()
- * ->setCountryCode("SE")
- * ->useInvoicePayment();
- * $order->prepareRequest();
- *
- * }
- *
- */
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -duplicated value : Customer is either an individual or a company. You can not use function setNationalIdNumber() in combination with setNationalIdNumber() or setVatNumber().
- */
- public function t_estFailOnDoubleIdentity()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(4608142222))
- ->useInvoicePayment();
-
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -Wrong customer type : PaymentPlanPayment not allowed for Company customer.
- */
- public function testFailOnCompanyPaymentPlanPayment()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::CreateOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(4608142222))
- ->usePaymentPlanPayment('5454');
-
- $order = $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -not valid : Given countrycode does not exist in our system.
- */
- public function testFailOnBadCountryCode()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("ZZ")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(111111))
- ->useInvoicePayment();
-
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : CountryCode is required. Use function setCountryCode().
- */
- public function testFailOnMissingCountryCode()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(111111))
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->useInvoicePayment();
-
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
- */
- public function testFailOnMissingNationalIdNumberForSeOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setName("Tess", "Testson"))
- ->useInvoicePayment();
-
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
- */
- public function testFailOnNationalIdNumberIsEmptyString()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->setCountryCode("SE")
- ->setOrderDate(date('c'))
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(""))
- ->useInvoicePayment();
-
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : OrgNumber is required for company customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
- */
- public function testFailOnMissingOrgNumberForCompanyOrderSe()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::companyCustomer()->setCompanyName("Mycompany"))
- ->useInvoicePayment();
-
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage
- * -missing value : BirthDate is required for individual customers when countrycode is DE. Use function setBirthDate().
- * -missing value : Name is required for individual customers when countrycode is DE. Use function setName().
- * -missing value : StreetAddress is required for all customers when countrycode is DE. Use function setStreetAddress().
- * -missing value : Locality is required for all customers when countrycode is DE. Use function setLocality().
- * -missing value : ZipCode is required for all customers when countrycode is DE. Use function setZipCode().
- */
- public function testFailOnMissingIdentityValuesForDEPaymentPlanOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->setCountryCode("DE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->usePaymentPlanPayment(213060);
-
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : BirthDate is required for individual customers when countrycode is DE. Use function setBirthDate().
- */
- public function testFailOnMissingBirthDateForDeOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->setCountryCode("DE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()
- //->setBirthDate(1923, 12, 12)
- ->setName("Tess", "Testson")
- ->setStreetAddress("Gatan", 23)
- ->setZipCode(9999)
- ->setLocality("Stan")
- )
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage
- * -missing value : Initials is required for individual customers when countrycode is NL. Use function setInitials().
- * -missing value : BirthDate is required for individual customers when countrycode is NL. Use function setBirthDate().
- * -missing value : Name is required for individual customers when countrycode is NL. Use function setName().
- * -missing value : StreetAddress is required for all customers when countrycode is NL. Use function setStreetAddress().
- * -missing value : Locality is required for all customers when countrycode is NL. Use function setLocality().
- * -missing value : ZipCode is required for all customers when countrycode is NL. Use function setZipCode().
- */
- public function testFailOnMissingValuesForNlOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("NL")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->useInvoicePayment();
- //$errorArray = $order->validateOrder();
- ////print_r($errorArray);
- $order->prepareRequest(); //throws esception
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : Initials is required for individual customers when countrycode is NL. Use function setInitials().
- */
- public function testFailOnMissingInitialsForNlOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->setCountryCode("NL")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()
- //->setInitials("SB")
- ->setBirthDate(1923, 12, 12)
- ->setName("Tess", "Testson")
- ->setStreetAddress("Gatan", 23)
- ->setZipCode(9999)
- ->setLocality("Stan")
- )
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing values : OrderRows are required. Use function addOrderRow(Svea\WebPay\WebPayItem::orderRow) to get orderrow setters.
- */
- public function testFailOnMissingOrderRows()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
-// /**
-// * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
-// * @expectedExceptionMessage -missing values : At least two of the values must be set in object \Svea\WebPay\WebPayItem:: AmountExVat, AmountIncVat or VatPercent for Orderrow. Use functions setAmountExVat(), setAmountIncVat() or setVatPercent().
-// * -missing value : Quantity is required in object \Svea\WebPay\WebPayItem. Use function \Svea\WebPay\WebPayItem::setQuantity().
-// */
-// public function testFailOnMissingOrderRowValues() {
-// $builder = \Svea\WebPay\WebPay::createOrder($config);
-// $order = $builder
-// ->addOrderRow(\Svea\WebPay\WebPayItem::orderRow())
-// ->setCountryCode("SE")
-// ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
-// ->addCustomerDetails(\Svea\WebPay\WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
-// ->useInvoicePayment();
-// $order->prepareRequest();
-// }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing values : Precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow. Use functions setAmountExVat(), setAmountIncVat() or setVatPercent().
- */
- public function testFailOnOrderRowMissingAllOfAmountExVatAmountIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(1)
- )
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing values : Precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow. Use functions setAmountExVat(), setAmountIncVat() or setVatPercent().
- */
- public function testFailOnOrderRowIncludesAllOfAmountExVatAmountIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(100.00)
- ->setAmountExVat(125.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage
- * -missing values : OrderDate is Required. Use function setOrderDate().
- */
- public function testFailOnMissingOrderDate()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(TestUtil::createHostedOrderRow())
- ->setCountryCode("SE")
- // ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- // order row type validation
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect datatype : articleNumber is not of type string.
- */
- public function testFailOnArticleNumberNotString()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setArticleNumber(42)
- )
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect datatype : quantity is not numeric
- */
- public function testFailOnQuantityNotNumeric()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(20)
- ->setQuantity("1,25") // note that i.e. "1,25" is numeric 1, so exclude strings for safety
- )
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect datatype : unit is not of type string.
- */
- public function testFailOnUnitNotString()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setUnit(1)
- )
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect datatype : amountExVat is not of type float or int.
- */
- public function testFailOnAmountExVatNotFloat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat("100.00")
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect datatype : amountIncVat is not of type float or int.
- */
- public function testFailOnAmountIncVatNotFloat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat("100.00")
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect datatype : name is not of type string.
- */
- public function testFailOnNameNotString()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(20)
- ->setName(1701)
- ->setQuantity(1)
- )
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect datatype : description is not of type string.
- */
- public function testFailOnDescriptionNotString()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(20)
- ->setDescription(1701)
- ->setQuantity(1)
- )
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect datatype : vatPercent is not of type int.
- */
- public function testFailOnVatNotInt()
- {
- // Stop here and mark this test as incomplete.
- $this->markTestIncomplete(
- 'vatPercent can be int and float now'
- );
-
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::createOrder($config);
- $order = $builder
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(20.33)
- ->setQuantity(1)
- )
- ->setCountryCode("SE")
- ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
- ->useInvoicePayment();
- $order->prepareRequest();
- }
-
-
- // public function testFailOnVatDiscountNotInt() {} This attribute has no setter in OrderRow, so not tested
-
- /**
- * @expectedException Exception
- * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
- */
- public function testFailOnMissingConfigurationProviderCreateOrder()
- {
- $object = WebPay::createOrder();
- }
-
- /**
- * @expectedException Exception
- * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
- */
- public function testFailOnMissingConfigurationProviderGetPaymentPlanParams()
- {
- $object = WebPay::getPaymentPlanParams();
- }
-
- /**
- * @expectedException Exception
- * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
- */
- public function testFailOnMissingConfigurationProviderDeliverOrder()
- {
- $object = WebPay::deliverOrder();
- }
-
- /**
- * @expectedException Exception
- * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
- */
- public function testFailOnMissingConfigurationProviderCloseOrder()
- {
- $object = WebPay::closeOrder();
- }
-
- /**
- * @expectedException Exception
- * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
- */
- public function testFailOnMissingConfigurationProviderGetAddresses()
- {
- $object = WebPay::getAddresses();
- }
-
- /**
- * @expectedException Exception
- * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
- */
- public function testFailOnMissingConfigurationProviderGetPaymentMethods()
- {
- $object = WebPay::getPaymentMethods();
- }
-
- /**
- * @expectedException Exception
- * @expectedExceptionMessage -incorrect value : distributionType EInvoiceB2B is only allowed for Norway.
- */
- public function testFailOnIncorrectCountryCodeForInvoiceB2B()
- {
- $config = ConfigurationService::getDefaultConfig();
- $object = WebPay::deliverOrder($config)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType(DistributionType::EINVOICEB2B)
- ->setOrderId(1)
- ->deliverInvoiceOrder()
- ->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect value : The fifth character of PeppolId must be ":"
- */
- public function testFailOnIncorrectFormatPeppolIdFifthCharacter()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(
- WebPayItem::companyCustomer()
- ->setNationalIdNumber(194608142222)
- )
- ->setOrderDate("2019-04-01")
- ->setPeppolId("12345678")
- ->setCountryCode("SE")
- ->useInvoicePayment()
- ->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect value : First 4 characters of PeppolId must be numeric.
- */
- public function testFailOnIncorrectFormatPeppolIdFirstCharacters()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(
- WebPayItem::companyCustomer()
- ->setNationalIdNumber(194608142222))
- ->setOrderDate("2019-04-01")
- ->setPeppolId("12a4:1sdf")
- ->setCountryCode("SE")
- ->useInvoicePayment()
- ->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect value : All characters after the fifth character in PeppolId must be alphanumeric.
- */
- public function testFailOnIncorrectFormatPeppolIdLastCharacters()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(
- WebPayItem::companyCustomer()
- ->setNationalIdNumber(194608142222))
- ->setOrderDate("2019-04-01")
- ->setPeppolId("1234:....")
- ->setCountryCode("SE")
- ->useInvoicePayment()
- ->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect value : PeppolId is too short, must be 6 characters or longer.
- */
- public function testFailOnIncorrectFormatPeppolIdTooShort()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(
- WebPayItem::companyCustomer()
- ->setNationalIdNumber(194608142222))
- ->setOrderDate("2019-04-01")
- ->setPeppolId("1234")
- ->setCountryCode("SE")
- ->useInvoicePayment()
- ->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect value : PeppolId is too long, must be 55 characters or fewer.
- */
- public function testFailOnIncorrectFormatPeppolIdTooLong()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(
- WebPayItem::companyCustomer()
- ->setNationalIdNumber(194608142222))
- ->setOrderDate("2019-04-01")
- ->setPeppolId("1234:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
- ->setCountryCode("SE")
- ->useInvoicePayment()
- ->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect value : CustomerType must be a company when using PeppolId.
- */
- public function testFailOnIncorrectFormatPeppolIdWrongCustomerType()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber(194605092222))
- ->setOrderDate("2019-04-01")
- ->setPeppolId("1234:asdf")
- ->setCountryCode("SE")
- ->useInvoicePayment()
- ->prepareRequest();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : Customer values are required for Invoice and PaymentPlan orders.
+ *
+ * function te_stFailOnMissingCustomerIdentity() {
+ * $builder = \Svea\WebPay\WebPay::createOrder($config);
+ * $order = $builder
+ * ->beginOrderRow()
+ * ->setAmountExVat(100)
+ * ->setVatPercent(20)
+ * ->setQuantity(1)
+ * ->endOrderRow()
+ * ->setCountryCode("SE")
+ * ->useInvoicePayment();
+ * $order->prepareRequest();
+ *
+ * }
+ *
+ */
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -duplicated value : Customer is either an individual or a company. You can not use function setNationalIdNumber() in combination with setNationalIdNumber() or setVatNumber().
+ */
+ public function t_estFailOnDoubleIdentity()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(4608142222))
+ ->useInvoicePayment();
+
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -Wrong customer type : PaymentPlanPayment not allowed for Company customer.
+ */
+ public function testFailOnCompanyPaymentPlanPayment()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::CreateOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(4608142222))
+ ->usePaymentPlanPayment('5454');
+
+ $order = $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -not valid : Given countrycode does not exist in our system.
+ */
+ public function testFailOnBadCountryCode()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("ZZ")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(111111))
+ ->useInvoicePayment();
+
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : CountryCode is required. Use function setCountryCode().
+ */
+ public function testFailOnMissingCountryCode()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(111111))
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->useInvoicePayment();
+
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
+ */
+ public function testFailOnMissingNationalIdNumberForSeOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setName("Tess", "Testson"))
+ ->useInvoicePayment();
+
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
+ */
+ public function testFailOnNationalIdNumberIsEmptyString()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->setCountryCode("SE")
+ ->setOrderDate(date('c'))
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(""))
+ ->useInvoicePayment();
+
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : OrgNumber is required for company customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
+ */
+ public function testFailOnMissingOrgNumberForCompanyOrderSe()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setCompanyName("Mycompany"))
+ ->useInvoicePayment();
+
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage
+ * -missing value : BirthDate is required for individual customers when countrycode is DE. Use function setBirthDate().
+ * -missing value : Name is required for individual customers when countrycode is DE. Use function setName().
+ * -missing value : StreetAddress is required for all customers when countrycode is DE. Use function setStreetAddress().
+ * -missing value : Locality is required for all customers when countrycode is DE. Use function setLocality().
+ * -missing value : ZipCode is required for all customers when countrycode is DE. Use function setZipCode().
+ */
+ public function testFailOnMissingIdentityValuesForDEPaymentPlanOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->setCountryCode("DE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->usePaymentPlanPayment(213060);
+
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : BirthDate is required for individual customers when countrycode is DE. Use function setBirthDate().
+ */
+ public function testFailOnMissingBirthDateForDeOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->setCountryCode("DE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ //->setBirthDate(1923, 12, 12)
+ ->setName("Tess", "Testson")
+ ->setStreetAddress("Gatan", 23)
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ )
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage
+ * -missing value : Initials is required for individual customers when countrycode is NL. Use function setInitials().
+ * -missing value : BirthDate is required for individual customers when countrycode is NL. Use function setBirthDate().
+ * -missing value : Name is required for individual customers when countrycode is NL. Use function setName().
+ * -missing value : StreetAddress is required for all customers when countrycode is NL. Use function setStreetAddress().
+ * -missing value : Locality is required for all customers when countrycode is NL. Use function setLocality().
+ * -missing value : ZipCode is required for all customers when countrycode is NL. Use function setZipCode().
+ */
+ public function testFailOnMissingValuesForNlOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("NL")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->useInvoicePayment();
+ //$errorArray = $order->validateOrder();
+ ////print_r($errorArray);
+ $order->prepareRequest(); //throws esception
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : Initials is required for individual customers when countrycode is NL. Use function setInitials().
+ */
+ public function testFailOnMissingInitialsForNlOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->setCountryCode("NL")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ //->setInitials("SB")
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Tess", "Testson")
+ ->setStreetAddress("Gatan", 23)
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ )
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing values : OrderRows are required. Use function addOrderRow(Svea\WebPay\WebPayItem::orderRow) to get orderrow setters.
+ */
+ public function testFailOnMissingOrderRows()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+// /**
+// * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+// * @expectedExceptionMessage -missing values : At least two of the values must be set in object \Svea\WebPay\WebPayItem:: AmountExVat, AmountIncVat or VatPercent for Orderrow. Use functions setAmountExVat(), setAmountIncVat() or setVatPercent().
+// * -missing value : Quantity is required in object \Svea\WebPay\WebPayItem. Use function \Svea\WebPay\WebPayItem::setQuantity().
+// */
+// public function testFailOnMissingOrderRowValues() {
+// $builder = \Svea\WebPay\WebPay::createOrder($config);
+// $order = $builder
+// ->addOrderRow(\Svea\WebPay\WebPayItem::orderRow())
+// ->setCountryCode("SE")
+// ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+// ->addCustomerDetails(\Svea\WebPay\WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+// ->useInvoicePayment();
+// $order->prepareRequest();
+// }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing values : Precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow. Use functions setAmountExVat(), setAmountIncVat() or setVatPercent().
+ */
+ public function testFailOnOrderRowMissingAllOfAmountExVatAmountIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(1)
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing values : Precisely two of these values must be set in the Svea\WebPay\WebPayItem object: AmountExVat, AmountIncVat or VatPercent for Orderrow. Use functions setAmountExVat(), setAmountIncVat() or setVatPercent().
+ */
+ public function testFailOnOrderRowIncludesAllOfAmountExVatAmountIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(100.00)
+ ->setAmountExVat(125.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage
+ * -missing values : OrderDate is Required. Use function setOrderDate().
+ */
+ public function testFailOnMissingOrderDate()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(TestUtil::createHostedOrderRow())
+ ->setCountryCode("SE")
+ // ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ // order row type validation
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect datatype : articleNumber is not of type string.
+ */
+ public function testFailOnArticleNumberNotString()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setArticleNumber(42)
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect datatype : quantity is not numeric
+ */
+ public function testFailOnQuantityNotNumeric()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(20)
+ ->setQuantity("1,25") // note that i.e. "1,25" is numeric 1, so exclude strings for safety
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect datatype : unit is not of type string.
+ */
+ public function testFailOnUnitNotString()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setUnit(1)
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect datatype : amountExVat is not of type float or int.
+ */
+ public function testFailOnAmountExVatNotFloat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat("100.00")
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect datatype : amountIncVat is not of type float or int.
+ */
+ public function testFailOnAmountIncVatNotFloat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat("100.00")
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect datatype : name is not of type string.
+ */
+ public function testFailOnNameNotString()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(20)
+ ->setName(1701)
+ ->setQuantity(1)
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect datatype : description is not of type string.
+ */
+ public function testFailOnDescriptionNotString()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(20)
+ ->setDescription(1701)
+ ->setQuantity(1)
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect datatype : vatPercent is not of type int.
+ */
+ public function testFailOnVatNotInt()
+ {
+ // Stop here and mark this test as incomplete.
+ $this->markTestIncomplete(
+ 'vatPercent can be int and float now'
+ );
+
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::createOrder($config);
+ $order = $builder
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(20.33)
+ ->setQuantity(1)
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate("Mon, 15 Aug 05 15:52:01 +0000")
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(46111111))
+ ->useInvoicePayment();
+ $order->prepareRequest();
+ }
+
+
+ // public function testFailOnVatDiscountNotInt() {} This attribute has no setter in OrderRow, so not tested
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
+ */
+ public function testFailOnMissingConfigurationProviderCreateOrder()
+ {
+ $object = WebPay::createOrder();
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
+ */
+ public function testFailOnMissingConfigurationProviderGetPaymentPlanParams()
+ {
+ $object = WebPay::getPaymentPlanParams();
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
+ */
+ public function testFailOnMissingConfigurationProviderDeliverOrder()
+ {
+ $object = WebPay::deliverOrder();
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
+ */
+ public function testFailOnMissingConfigurationProviderCloseOrder()
+ {
+ $object = WebPay::closeOrder();
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
+ */
+ public function testFailOnMissingConfigurationProviderGetAddresses()
+ {
+ $object = WebPay::getAddresses();
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage -missing parameter: This method requires an Svea\WebPay\Config\ConfigurationProvider object as parameter. Create a class that implements class Svea\WebPay\Config\ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class ConfigurationService e.g. ConfigurationService::getDefaultConfig(). You can replace the default config values into config files to return your own config values.
+ */
+ public function testFailOnMissingConfigurationProviderGetPaymentMethods()
+ {
+ $object = WebPay::getPaymentMethods();
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage -incorrect value : distributionType EInvoiceB2B is only allowed for Norway.
+ */
+ public function testFailOnIncorrectCountryCodeForInvoiceB2B()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $object = WebPay::deliverOrder($config)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType(DistributionType::EINVOICEB2B)
+ ->setOrderId(1)
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect value : The fifth character of PeppolId must be ":"
+ */
+ public function testFailOnIncorrectFormatPeppolIdFifthCharacter()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(
+ WebPayItem::companyCustomer()
+ ->setNationalIdNumber(194608142222)
+ )
+ ->setOrderDate("2019-04-01")
+ ->setPeppolId("12345678")
+ ->setCountryCode("SE")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect value : First 4 characters of PeppolId must be numeric.
+ */
+ public function testFailOnIncorrectFormatPeppolIdFirstCharacters()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(
+ WebPayItem::companyCustomer()
+ ->setNationalIdNumber(194608142222))
+ ->setOrderDate("2019-04-01")
+ ->setPeppolId("12a4:1sdf")
+ ->setCountryCode("SE")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect value : All characters after the fifth character in PeppolId must be alphanumeric.
+ */
+ public function testFailOnIncorrectFormatPeppolIdLastCharacters()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(
+ WebPayItem::companyCustomer()
+ ->setNationalIdNumber(194608142222))
+ ->setOrderDate("2019-04-01")
+ ->setPeppolId("1234:....")
+ ->setCountryCode("SE")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect value : PeppolId is too short, must be 6 characters or longer.
+ */
+ public function testFailOnIncorrectFormatPeppolIdTooShort()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(
+ WebPayItem::companyCustomer()
+ ->setNationalIdNumber(194608142222))
+ ->setOrderDate("2019-04-01")
+ ->setPeppolId("1234")
+ ->setCountryCode("SE")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect value : PeppolId is too long, must be 55 characters or fewer.
+ */
+ public function testFailOnIncorrectFormatPeppolIdTooLong()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(
+ WebPayItem::companyCustomer()
+ ->setNationalIdNumber(194608142222))
+ ->setOrderDate("2019-04-01")
+ ->setPeppolId("1234:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
+ ->setCountryCode("SE")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect value : CustomerType must be a company when using PeppolId.
+ */
+ public function testFailOnIncorrectFormatPeppolIdWrongCustomerType()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber(194605092222))
+ ->setOrderDate("2019-04-01")
+ ->setPeppolId("1234:asdf")
+ ->setCountryCode("SE")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ }
}
diff --git a/test/UnitTest/Checkout/Helper/CheckoutOrderBuilderTest.php b/test/UnitTest/Checkout/Helper/CheckoutOrderBuilderTest.php
index 99a5abf0..36d55d66 100644
--- a/test/UnitTest/Checkout/Helper/CheckoutOrderBuilderTest.php
+++ b/test/UnitTest/Checkout/Helper/CheckoutOrderBuilderTest.php
@@ -12,97 +12,97 @@
*/
class CheckoutOrderBuilderTest extends TestCase
{
- /**
- * @var CheckoutOrderBuilder
- */
- protected $order;
-
- public function setUp()
- {
- $this->order = $this->returnCreatedOrder();
- }
-
- /**
- * @test
- */
- public function returnCheckoutOrderBuilderInstance()
- {
- $this->assertInstanceOf('Svea\WebPay\Checkout\Helper\CheckoutOrderBuilder', $this->order);
- }
-
- /**
- * @test
- */
- public function isInitializedMerchantSetting()
- {
- $this->assertInstanceOf('Svea\WebPay\Checkout\Model\MerchantSettings', $this->order->getMerchantSettings());
- }
-
- /**
- * @test
- */
- public function setCountryCode()
- {
- $this->order->setCountryCode('EN');
-
- $this->assertEquals($this->order->getCountryCode(), 'EN');
- }
-
- /**
- * @test
- */
- public function setDefaultCountryCode()
- {
- $this->assertEquals($this->order->getCountryCode(), 'SE');
- }
-
- /**
- * @test
- */
- public function setOrderId()
- {
- $this->order->setId(123);
-
- $this->assertEquals($this->order->getId(), 123);
- }
-
- /**
- * @test
- */
- public function setCurrency()
- {
- $this->order->setCurrency('SEK');
-
- $this->assertEquals($this->order->getCurrency(), 'SEK');
- }
-
- /**
- * @test
- */
- public function setSCOLocale()
- {
- $this->order->setLocale('sv-Se');
-
- $this->assertEquals($this->order->getLocale(), 'sv-Se');
- }
-
- /**
- * @test
- */
- public function setValidationCallbackUri()
- {
- $validationCallbackUri = 'http://localhost:51898/validation-callback';
- $this->order->setValidationCallbackUri($validationCallbackUri);
- $this->assertEquals($this->order->getMerchantSettings()->getValidationCallbackUri(), $validationCallbackUri);
- }
-
- /**
- * @test
- */
- public function setMerchantData()
- {
- $merchantData = 'Newsletter:true';
- $this->order->setMerchantData($merchantData);
- $this->assertEquals($this->order->getMerchantData(), $merchantData);
- }
+ /**
+ * @var CheckoutOrderBuilder
+ */
+ protected $order;
+
+ public function setUp()
+ {
+ $this->order = $this->returnCreatedOrder();
+ }
+
+ /**
+ * @test
+ */
+ public function returnCheckoutOrderBuilderInstance()
+ {
+ $this->assertInstanceOf('Svea\WebPay\Checkout\Helper\CheckoutOrderBuilder', $this->order);
+ }
+
+ /**
+ * @test
+ */
+ public function isInitializedMerchantSetting()
+ {
+ $this->assertInstanceOf('Svea\WebPay\Checkout\Model\MerchantSettings', $this->order->getMerchantSettings());
+ }
+
+ /**
+ * @test
+ */
+ public function setCountryCode()
+ {
+ $this->order->setCountryCode('EN');
+
+ $this->assertEquals($this->order->getCountryCode(), 'EN');
+ }
+
+ /**
+ * @test
+ */
+ public function setDefaultCountryCode()
+ {
+ $this->assertEquals($this->order->getCountryCode(), 'SE');
+ }
+
+ /**
+ * @test
+ */
+ public function setOrderId()
+ {
+ $this->order->setId(123);
+
+ $this->assertEquals($this->order->getId(), 123);
+ }
+
+ /**
+ * @test
+ */
+ public function setCurrency()
+ {
+ $this->order->setCurrency('SEK');
+
+ $this->assertEquals($this->order->getCurrency(), 'SEK');
+ }
+
+ /**
+ * @test
+ */
+ public function setSCOLocale()
+ {
+ $this->order->setLocale('sv-Se');
+
+ $this->assertEquals($this->order->getLocale(), 'sv-Se');
+ }
+
+ /**
+ * @test
+ */
+ public function setValidationCallbackUri()
+ {
+ $validationCallbackUri = 'http://localhost:51898/validation-callback';
+ $this->order->setValidationCallbackUri($validationCallbackUri);
+ $this->assertEquals($this->order->getMerchantSettings()->getValidationCallbackUri(), $validationCallbackUri);
+ }
+
+ /**
+ * @test
+ */
+ public function setMerchantData()
+ {
+ $merchantData = 'Newsletter:true';
+ $this->order->setMerchantData($merchantData);
+ $this->assertEquals($this->order->getMerchantData(), $merchantData);
+ }
}
diff --git a/test/UnitTest/Checkout/Helper/CheckoutRowFormatterTest.php b/test/UnitTest/Checkout/Helper/CheckoutRowFormatterTest.php
index 7d4285db..1b3e66ce 100644
--- a/test/UnitTest/Checkout/Helper/CheckoutRowFormatterTest.php
+++ b/test/UnitTest/Checkout/Helper/CheckoutRowFormatterTest.php
@@ -11,29 +11,29 @@
*/
class CheckoutRowFormatterTest extends TestCase
{
- /**
- * @var CheckoutRowFormatter
- */
- protected $formatter;
+ /**
+ * @var CheckoutRowFormatter
+ */
+ protected $formatter;
- public function setUp()
- {
- parent::setUp();
+ public function setUp()
+ {
+ parent::setUp();
- $this->formatter = new CheckoutRowFormatter($this->order, true);
- }
+ $this->formatter = new CheckoutRowFormatter($this->order, true);
+ }
- /**
- * @test
- */
- public function ifRowsAreFormatted()
- {
- $row = $this->returnOrderRow();
+ /**
+ * @test
+ */
+ public function ifRowsAreFormatted()
+ {
+ $row = $this->returnOrderRow();
- $this->invokeMethod($this->formatter, 'formatOrderRows', array($row));
+ $this->invokeMethod($this->formatter, 'formatOrderRows', [$row]);
- $newRows = $this->getPrivateProperty($this->formatter, 'newRows');
+ $newRows = $this->getPrivateProperty($this->formatter, 'newRows');
- $this->assertInstanceOf('Svea\WebPay\WebService\SveaSoap\SveaOrderRow', $newRows[0]);
- }
+ $this->assertInstanceOf('Svea\WebPay\WebService\SveaSoap\SveaOrderRow', $newRows[0]);
+ }
}
diff --git a/test/UnitTest/Checkout/Model/CheckoutIdentityFlagsTest.php b/test/UnitTest/Checkout/Model/CheckoutIdentityFlagsTest.php
index 369121e4..1bb905f8 100644
--- a/test/UnitTest/Checkout/Model/CheckoutIdentityFlagsTest.php
+++ b/test/UnitTest/Checkout/Model/CheckoutIdentityFlagsTest.php
@@ -13,43 +13,43 @@
class CheckoutIdentityFlagsTest extends TestCase
{
- public function setUp()
- {
- parent::setUp();
- }
-
- /**
- * @test
- *
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public function setNonExistingIdentityFlag()
- {
- $this->setUp();
-
- // Set some valid flags and one invalid flag
- $this->order->addIdentityFlag(IdentityFlags::HIDEANONYMOUS);
- $this->order->addIdentityFlag("NonExistingFlag");
- $this->order->addIdentityFlag(IdentityFlags::HIDECHANGEADDRESS);
-
- $this->order->createOrder();
- }
-
- /**
- * @test
- */
- public function setValidIdentityFlag()
- {
- $this->setUp();
- $this->order->addIdentityFlag(IdentityFlags::HIDEANONYMOUS);
- $this->order->addIdentityFlag(IdentityFlags::HIDECHANGEADDRESS);
- $this->order->addIdentityFlag(IdentityFlags::HIDENOTYOU);
-
- $arr = $this->order->getIdentityFlags();
-
- $this->assertEquals("HideAnonymous", $arr[0]);
- $this->assertEquals("HideChangeAddress", $arr[1]);
- $this->assertEquals("HideNotYou", $arr[2]);
-
- }
+ public function setUp()
+ {
+ parent::setUp();
+ }
+
+ /**
+ * @test
+ *
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public function setNonExistingIdentityFlag()
+ {
+ $this->setUp();
+
+ // Set some valid flags and one invalid flag
+ $this->order->addIdentityFlag(IdentityFlags::HIDEANONYMOUS);
+ $this->order->addIdentityFlag("NonExistingFlag");
+ $this->order->addIdentityFlag(IdentityFlags::HIDECHANGEADDRESS);
+
+ $this->order->createOrder();
+ }
+
+ /**
+ * @test
+ */
+ public function setValidIdentityFlag()
+ {
+ $this->setUp();
+ $this->order->addIdentityFlag(IdentityFlags::HIDEANONYMOUS);
+ $this->order->addIdentityFlag(IdentityFlags::HIDECHANGEADDRESS);
+ $this->order->addIdentityFlag(IdentityFlags::HIDENOTYOU);
+
+ $arr = $this->order->getIdentityFlags();
+
+ $this->assertEquals("HideAnonymous", $arr[0]);
+ $this->assertEquals("HideChangeAddress", $arr[1]);
+ $this->assertEquals("HideNotYou", $arr[2]);
+
+ }
}
diff --git a/test/UnitTest/Checkout/Model/CheckoutOrderRowTest.php b/test/UnitTest/Checkout/Model/CheckoutOrderRowTest.php
index fef3bbba..639ae239 100644
--- a/test/UnitTest/Checkout/Model/CheckoutOrderRowTest.php
+++ b/test/UnitTest/Checkout/Model/CheckoutOrderRowTest.php
@@ -8,24 +8,24 @@
class CheckoutOrderRowTest extends TestCase
{
- public function setUp()
- {
- parent::setUp();
- }
+ public function setUp()
+ {
+ parent::setUp();
+ }
- public function testSetMerchantData()
- {
- $order = $this->order->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(rand(1, 1000) + rand(1, 99) / 100)// - required
- ->setVatPercent($this->getRandVatPercent())// - required
- ->setQuantity($this->getRandQuantity())
- ->setDiscountPercent($this->getRandDiscountPercent())
- ->setArticleNumber("123456")
- ->setName('Fork')
- ->setMerchantData('test string'));
+ public function testSetMerchantData()
+ {
+ $order = $this->order->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(rand(1, 1000) + rand(1, 99) / 100)// - required
+ ->setVatPercent($this->getRandVatPercent())// - required
+ ->setQuantity($this->getRandQuantity())
+ ->setDiscountPercent($this->getRandDiscountPercent())
+ ->setArticleNumber("123456")
+ ->setName('Fork')
+ ->setMerchantData('test string'));
- $this->assertEquals($order->orderRows[0]->merchantData, "test string");
- }
+ $this->assertEquals($order->orderRows[0]->merchantData, "test string");
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/Checkout/Model/CheckoutPresetValueTest.php b/test/UnitTest/Checkout/Model/CheckoutPresetValueTest.php
index e52e0e49..3d6f3364 100644
--- a/test/UnitTest/Checkout/Model/CheckoutPresetValueTest.php
+++ b/test/UnitTest/Checkout/Model/CheckoutPresetValueTest.php
@@ -12,53 +12,53 @@
class CheckoutPresetValueTest extends TestCase
{
- public function setUp()
- {
- parent::setUp();
- }
+ public function setUp()
+ {
+ parent::setUp();
+ }
- /**
- * @test
- *
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public function setTypeMethodReceiveBadParam()
- {
- $pv = new PresetValue();
+ /**
+ * @test
+ *
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public function setTypeMethodReceiveBadParam()
+ {
+ $pv = new PresetValue();
- $pv->setTypeName('NonExistingName');
- }
+ $pv->setTypeName('NonExistingName');
+ }
- /**
- * @doesNotPerformAssertions
- */
- public function setTypeMethodReceiveGoodParams()
- {
- $pv = new PresetValue();
- $typeList = $this->invokeMethod($pv, 'getConstantListValues');
+ /**
+ * @doesNotPerformAssertions
+ */
+ public function setTypeMethodReceiveGoodParams()
+ {
+ $pv = new PresetValue();
+ $typeList = $this->invokeMethod($pv, 'getConstantListValues');
- foreach ($typeList as $type) {
- $pv->setTypeName($type);
- }
- }
+ foreach ($typeList as $type) {
+ $pv->setTypeName($type);
+ }
+ }
- /**
- * @test
- */
- public function printArray()
- {
- $postalCode = '11123';
- $readonly = true;
+ /**
+ * @test
+ */
+ public function printArray()
+ {
+ $postalCode = '11123';
+ $readonly = true;
- $pv = new PresetValue();
- $pv->setTypeName($pv::POSTAL_CODE)
- ->setValue($postalCode)
- ->setIsReadonly($readonly);
+ $pv = new PresetValue();
+ $pv->setTypeName($pv::POSTAL_CODE)
+ ->setValue($postalCode)
+ ->setIsReadonly($readonly);
- $array = $pv->returnPresetArray();
-
- $this->assertEquals($array['typeName'], $pv::POSTAL_CODE);
- $this->assertEquals($array['value'], $postalCode);
- $this->assertEquals($array['isReadonly'], $readonly);
- }
+ $array = $pv->returnPresetArray();
+
+ $this->assertEquals($array['typeName'], $pv::POSTAL_CODE);
+ $this->assertEquals($array['value'], $postalCode);
+ $this->assertEquals($array['isReadonly'], $readonly);
+ }
}
diff --git a/test/UnitTest/Checkout/Service/Admin/AddOrderRowServiceTest.php b/test/UnitTest/Checkout/Service/Admin/AddOrderRowServiceTest.php
index d85aaa7d..71c15976 100644
--- a/test/UnitTest/Checkout/Service/Admin/AddOrderRowServiceTest.php
+++ b/test/UnitTest/Checkout/Service/Admin/AddOrderRowServiceTest.php
@@ -9,66 +9,66 @@
class AddOrderRowServiceTest extends TestCase
{
- public function testPrepareDataWithValidData()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
+ public function testPrepareDataWithValidData()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
- $orderRow = WebPayItem::orderRow()
- ->setArticleNumber('prod-01')
- ->setName('someProd1')
- ->setVatPercent(0)// required - 0, 6, 12, 25.
- ->setAmountIncVat(50.00)
- ->setQuantity(1)
- ->setUnit('pc');
+ $orderRow = WebPayItem::orderRow()
+ ->setArticleNumber('prod-01')
+ ->setName('someProd1')
+ ->setVatPercent(0)// required - 0, 6, 12, 25.
+ ->setAmountIncVat(50.00)
+ ->setQuantity(1)
+ ->setUnit('pc');
- $orderService = WebPayAdmin::addOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->addOrderRow($orderRow)
- ->addCheckoutOrderRows();
+ $orderService = WebPayAdmin::addOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->addOrderRow($orderRow)
+ ->addCheckoutOrderRows();
- $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
+ $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
- $this->assertEquals(7383, $preparedData['orderId']);
- $this->assertArrayHasKey('articleNumber', $preparedData['orderRow']);
- $this->assertArrayHasKey('name', $preparedData['orderRow']);
- $this->assertArrayHasKey('quantity', $preparedData['orderRow']);
- $this->assertArrayHasKey('vatPercent', $preparedData['orderRow']);
- $this->assertArrayHasKey('unitPrice', $preparedData['orderRow']);
- $this->assertArrayHasKey('unit', $preparedData['orderRow']);
- }
+ $this->assertEquals(7383, $preparedData['orderId']);
+ $this->assertArrayHasKey('articleNumber', $preparedData['orderRow']);
+ $this->assertArrayHasKey('name', $preparedData['orderRow']);
+ $this->assertArrayHasKey('quantity', $preparedData['orderRow']);
+ $this->assertArrayHasKey('vatPercent', $preparedData['orderRow']);
+ $this->assertArrayHasKey('unitPrice', $preparedData['orderRow']);
+ $this->assertArrayHasKey('unit', $preparedData['orderRow']);
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderIdAsString()
- {
- $sveaCheckoutOrderId = '7383';
- $testConfig = ConfigurationService::getTestConfig();
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderIdAsString()
+ {
+ $sveaCheckoutOrderId = '7383';
+ $testConfig = ConfigurationService::getTestConfig();
- $orderService = WebPayAdmin::addOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->addCheckoutOrderRows();
+ $orderService = WebPayAdmin::addOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->addCheckoutOrderRows();
- $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
+ $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
- $this->assertEquals(7383, $preparedData['orderId']);
- }
+ $this->assertEquals(7383, $preparedData['orderId']);
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- */
- public function testPrepareDataWithoutOrderRow()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ */
+ public function testPrepareDataWithoutOrderRow()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
- $orderService = WebPayAdmin::addOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->addCheckoutOrderRows();
+ $orderService = WebPayAdmin::addOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->addCheckoutOrderRows();
- $this->invokeMethod($orderService, 'prepareRequest');
- }
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
}
diff --git a/test/UnitTest/Checkout/Service/Admin/CancelOrderRowServiceTest.php b/test/UnitTest/Checkout/Service/Admin/CancelOrderRowServiceTest.php
index 21ee8735..ae6cf392 100644
--- a/test/UnitTest/Checkout/Service/Admin/CancelOrderRowServiceTest.php
+++ b/test/UnitTest/Checkout/Service/Admin/CancelOrderRowServiceTest.php
@@ -8,56 +8,56 @@
class CancelOrderRowServiceTest extends TestCase
{
- public function testPrepareDataWithValidData()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::cancelOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setRowToCancel(1)
- ->cancelCheckoutOrderRows();
-
- $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
-
- $this->assertArrayHasKey('orderId', $preparedData);
- $this->assertEquals(7383, $preparedData['orderId']);
- $this->assertArrayHasKey('orderRowId', $preparedData);
- $this->assertEquals(1, $preparedData['orderRowId']);
- }
-
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderIdAsString()
- {
- $sveaCheckoutOrderId = '7383';
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::cancelOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setRowToCancel(1)
- ->cancelCheckoutOrderRows();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Row Id : Order Row Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderRowIdAsString()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::cancelOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setRowToCancel('1')
- ->cancelCheckoutOrderRows();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
+ public function testPrepareDataWithValidData()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::cancelOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setRowToCancel(1)
+ ->cancelCheckoutOrderRows();
+
+ $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
+
+ $this->assertArrayHasKey('orderId', $preparedData);
+ $this->assertEquals(7383, $preparedData['orderId']);
+ $this->assertArrayHasKey('orderRowId', $preparedData);
+ $this->assertEquals(1, $preparedData['orderRowId']);
+ }
+
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderIdAsString()
+ {
+ $sveaCheckoutOrderId = '7383';
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::cancelOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setRowToCancel(1)
+ ->cancelCheckoutOrderRows();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Row Id : Order Row Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderRowIdAsString()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::cancelOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setRowToCancel('1')
+ ->cancelCheckoutOrderRows();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
}
diff --git a/test/UnitTest/Checkout/Service/Admin/CancelOrderServiceTest.php b/test/UnitTest/Checkout/Service/Admin/CancelOrderServiceTest.php
index 39960489..87c2fca2 100644
--- a/test/UnitTest/Checkout/Service/Admin/CancelOrderServiceTest.php
+++ b/test/UnitTest/Checkout/Service/Admin/CancelOrderServiceTest.php
@@ -8,104 +8,104 @@
class CancelOrderServiceTest extends TestCase
{
- public function testPrepareDataWithValidData()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::cancelOrder($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->cancelCheckoutOrder();
-
- $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
-
- $this->assertArrayHasKey('orderId', $preparedData);
- $this->assertEquals(7383, $preparedData['orderId']);
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderIdAsString()
- {
- $sveaCheckoutOrderId = '7383';
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::cancelOrder($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->cancelCheckoutOrder();
-
- $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
-
- $this->assertArrayHasKey('orderId', $preparedData);
- $this->assertEquals(7383, $preparedData['orderId']);
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
- */
- public function testPrepareDataWithoutOrderId()
- {
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::cancelOrder($testConfig)
- ->cancelCheckoutOrder();
-
- $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
-
- $this->assertArrayHasKey('orderId', $preparedData);
- $this->assertEquals(7383, $preparedData['orderId']);
- }
-
- public function testPrepareDataWithCancelingAmount()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::cancelOrder($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setAmountIncVat(5.00)
- ->cancelCheckoutOrderAmount();
-
- $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
-
- $this->assertArrayHasKey('orderId', $preparedData);
- $this->assertEquals(7383, $preparedData['orderId']);
- $this->assertArrayHasKey('cancelledAmount', $preparedData);
- $this->assertEquals(500, $preparedData['cancelledAmount']);
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Amount for cancel order : Amount can't be empty and must be Integer
- */
- public function testPrepareDataWithCancelingAmountAsString()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::cancelOrder($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setAmountIncVat('5.00')
- ->cancelCheckoutOrderAmount();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Amount for cancel order : Amount can't be empty and must be Integer
- */
- public function testPrepareDataWithoutCancelingAmount()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::cancelOrder($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->cancelCheckoutOrderAmount();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
+ public function testPrepareDataWithValidData()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::cancelOrder($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->cancelCheckoutOrder();
+
+ $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
+
+ $this->assertArrayHasKey('orderId', $preparedData);
+ $this->assertEquals(7383, $preparedData['orderId']);
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderIdAsString()
+ {
+ $sveaCheckoutOrderId = '7383';
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::cancelOrder($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->cancelCheckoutOrder();
+
+ $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
+
+ $this->assertArrayHasKey('orderId', $preparedData);
+ $this->assertEquals(7383, $preparedData['orderId']);
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithoutOrderId()
+ {
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::cancelOrder($testConfig)
+ ->cancelCheckoutOrder();
+
+ $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
+
+ $this->assertArrayHasKey('orderId', $preparedData);
+ $this->assertEquals(7383, $preparedData['orderId']);
+ }
+
+ public function testPrepareDataWithCancelingAmount()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::cancelOrder($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setAmountIncVat(5.00)
+ ->cancelCheckoutOrderAmount();
+
+ $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
+
+ $this->assertArrayHasKey('orderId', $preparedData);
+ $this->assertEquals(7383, $preparedData['orderId']);
+ $this->assertArrayHasKey('cancelledAmount', $preparedData);
+ $this->assertEquals(500, $preparedData['cancelledAmount']);
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Amount for cancel order : Amount can't be empty and must be Integer
+ */
+ public function testPrepareDataWithCancelingAmountAsString()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::cancelOrder($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setAmountIncVat('5.00')
+ ->cancelCheckoutOrderAmount();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Amount for cancel order : Amount can't be empty and must be Integer
+ */
+ public function testPrepareDataWithoutCancelingAmount()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::cancelOrder($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->cancelCheckoutOrderAmount();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
}
diff --git a/test/UnitTest/Checkout/Service/Admin/CreditOrderAmountServiceTest.php b/test/UnitTest/Checkout/Service/Admin/CreditOrderAmountServiceTest.php
index 0432e560..f9c83b54 100644
--- a/test/UnitTest/Checkout/Service/Admin/CreditOrderAmountServiceTest.php
+++ b/test/UnitTest/Checkout/Service/Admin/CreditOrderAmountServiceTest.php
@@ -8,94 +8,94 @@
class CreditOrderAmountServiceTest extends TestCase
{
- public function testPrepareDataWithValidData()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::creditAmount($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId(1)
- ->setAmountIncVat(20.00)
- ->creditCheckoutAmount();
-
- $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
-
- $this->assertEquals(7383, $preparedData['orderId']);
- $this->assertEquals(1, $preparedData['deliveryId']);
- $this->assertEquals(2000, $preparedData['creditedAmount']);
- $this->assertArrayHasKey('orderId', $preparedData);
- $this->assertArrayHasKey('deliveryId', $preparedData);
- $this->assertArrayHasKey('creditedAmount', $preparedData);
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderIdAsString()
- {
- $sveaCheckoutOrderId = '7383';
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::creditAmount($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId(1)
- ->setAmountIncVat(20.00)
- ->creditCheckoutAmount();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Delivery Id : Delivery Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderDeliveryIdAsString()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::creditAmount($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId('1')
- ->setAmountIncVat(20.00)
- ->creditCheckoutAmount();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Delivery Id : Delivery Id can't be empty and must be Integer
- */
- public function testPrepareDataWithoutOrderDeliveryId()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::creditAmount($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setAmountIncVat(20.00)
- ->creditCheckoutAmount();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Credit Amount : Credit amount can't be empty and must be number
- */
- public function testPrepareDataWithoutAmount()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::creditAmount($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId(1)
- ->creditCheckoutAmount();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
+ public function testPrepareDataWithValidData()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::creditAmount($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId(1)
+ ->setAmountIncVat(20.00)
+ ->creditCheckoutAmount();
+
+ $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
+
+ $this->assertEquals(7383, $preparedData['orderId']);
+ $this->assertEquals(1, $preparedData['deliveryId']);
+ $this->assertEquals(2000, $preparedData['creditedAmount']);
+ $this->assertArrayHasKey('orderId', $preparedData);
+ $this->assertArrayHasKey('deliveryId', $preparedData);
+ $this->assertArrayHasKey('creditedAmount', $preparedData);
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderIdAsString()
+ {
+ $sveaCheckoutOrderId = '7383';
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::creditAmount($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId(1)
+ ->setAmountIncVat(20.00)
+ ->creditCheckoutAmount();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Delivery Id : Delivery Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderDeliveryIdAsString()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::creditAmount($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId('1')
+ ->setAmountIncVat(20.00)
+ ->creditCheckoutAmount();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Delivery Id : Delivery Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithoutOrderDeliveryId()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::creditAmount($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setAmountIncVat(20.00)
+ ->creditCheckoutAmount();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Credit Amount : Credit amount can't be empty and must be number
+ */
+ public function testPrepareDataWithoutAmount()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::creditAmount($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId(1)
+ ->creditCheckoutAmount();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
}
diff --git a/test/UnitTest/Checkout/Service/Admin/CreditOrderRowsServiceTest.php b/test/UnitTest/Checkout/Service/Admin/CreditOrderRowsServiceTest.php
index 650bb156..7ed49c6e 100644
--- a/test/UnitTest/Checkout/Service/Admin/CreditOrderRowsServiceTest.php
+++ b/test/UnitTest/Checkout/Service/Admin/CreditOrderRowsServiceTest.php
@@ -9,103 +9,103 @@
class CreditOrderRowsServiceTest extends TestCase
{
- public function testPrepareDataWithValidData()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderRow = WebPayItem::orderRow()
- ->setAmountIncVat(300.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("Credited order with new Order row");
-
- $orderService = WebPayAdmin::creditOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId(1)
- ->addCreditOrderRow($orderRow)
- ->creditCheckoutOrderWithNewOrderRow();
-
- $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
-
- $this->assertArrayHasKey('orderId', $preparedData);
- $this->assertArrayHasKey('deliveryId', $preparedData);
- $this->assertArrayHasKey('newCreditRow', $preparedData);
- $this->assertEquals(7383, $preparedData['orderId']);
- $this->assertEquals(1, $preparedData['deliveryId']);
- $this->assertEquals(true, is_array($preparedData['newCreditRow']));
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderIdAsString()
- {
- $sveaCheckoutOrderId = '7383';
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::creditOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId(1)
- ->creditCheckoutOrderRows();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
- */
- public function testPrepareDataWithoutOrderId()
- {
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::creditOrderRows($testConfig)
- ->setDeliveryId(1)
- ->creditCheckoutOrderRows();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage missing order rows : must be at least one Order row set
- */
- public function testPrepareDataWithoutOrderRow()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::creditOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId(1)
- ->creditCheckoutOrderRows();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Delivery Id : Delivery Id can't be empty and must be Integer
- */
- public function testPrepareDataWithDeliveryIdAsString()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderRow = WebPayItem::orderRow()
- ->setAmountIncVat(300.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setDescription("Credited order with new Order row");
-
- $orderService = WebPayAdmin::creditOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setDeliveryId('1')
- ->addCreditOrderRow($orderRow)
- ->creditCheckoutOrderRows();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
+ public function testPrepareDataWithValidData()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderRow = WebPayItem::orderRow()
+ ->setAmountIncVat(300.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("Credited order with new Order row");
+
+ $orderService = WebPayAdmin::creditOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId(1)
+ ->addCreditOrderRow($orderRow)
+ ->creditCheckoutOrderWithNewOrderRow();
+
+ $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
+
+ $this->assertArrayHasKey('orderId', $preparedData);
+ $this->assertArrayHasKey('deliveryId', $preparedData);
+ $this->assertArrayHasKey('newCreditRow', $preparedData);
+ $this->assertEquals(7383, $preparedData['orderId']);
+ $this->assertEquals(1, $preparedData['deliveryId']);
+ $this->assertEquals(true, is_array($preparedData['newCreditRow']));
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderIdAsString()
+ {
+ $sveaCheckoutOrderId = '7383';
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::creditOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId(1)
+ ->creditCheckoutOrderRows();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithoutOrderId()
+ {
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::creditOrderRows($testConfig)
+ ->setDeliveryId(1)
+ ->creditCheckoutOrderRows();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage missing order rows : must be at least one Order row set
+ */
+ public function testPrepareDataWithoutOrderRow()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::creditOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId(1)
+ ->creditCheckoutOrderRows();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Delivery Id : Delivery Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithDeliveryIdAsString()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderRow = WebPayItem::orderRow()
+ ->setAmountIncVat(300.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setDescription("Credited order with new Order row");
+
+ $orderService = WebPayAdmin::creditOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setDeliveryId('1')
+ ->addCreditOrderRow($orderRow)
+ ->creditCheckoutOrderRows();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
}
diff --git a/test/UnitTest/Checkout/Service/Admin/DeliverOrderServiceTest.php b/test/UnitTest/Checkout/Service/Admin/DeliverOrderServiceTest.php
index bc788e3b..edebd337 100644
--- a/test/UnitTest/Checkout/Service/Admin/DeliverOrderServiceTest.php
+++ b/test/UnitTest/Checkout/Service/Admin/DeliverOrderServiceTest.php
@@ -8,73 +8,73 @@
class DeliverOrderServiceTest extends TestCase
{
- public function testPrepareDataWithOrderIdAsInteger()
- {
- $sveaCheckoutOrderId = 7383;
- $orderRowIds = array(1, 3);
- $testConfig = ConfigurationService::getTestConfig();
-
- $getOrderService = WebPayAdmin::deliverOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setRowsToDeliver($orderRowIds)
- ->deliverCheckoutOrderRows();
-
- $preparedData = $this->invokeMethod($getOrderService, 'prepareRequest');
-
- $this->assertEquals(7383, $preparedData['orderId']);
- $this->assertEquals(array(1, 3), $preparedData['orderRowIds']);
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderIdAsString()
- {
- $sveaCheckoutOrderId = '7383';
- $testConfig = ConfigurationService::getTestConfig();
-
- $getOrderService = WebPayAdmin::deliverOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->deliverCheckoutOrderRows();
-
- $this->invokeMethod($getOrderService, 'prepareRequest');
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Row Id : Order Row Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderIdAsIntegerAndOrderRowIdsAsString()
- {
- $sveaCheckoutOrderId = 7383;
- $orderRowIds = array('1', '3');
- $testConfig = ConfigurationService::getTestConfig();
-
- $getOrderService = WebPayAdmin::deliverOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setRowsToDeliver($orderRowIds)
- ->deliverCheckoutOrderRows();
-
- $this->invokeMethod($getOrderService, 'prepareRequest');
- }
-
- public function testPrepareDataWithOrderIdAsIntegerAndOrderRowIdsAsInteger()
- {
- $sveaCheckoutOrderId = 7383;
- $orderRowIds = array(1, 3);
- $testConfig = ConfigurationService::getTestConfig();
-
- $getOrderService = WebPayAdmin::deliverOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->setRowsToDeliver($orderRowIds)
- ->deliverCheckoutOrderRows();
-
- $preparedData = $this->invokeMethod($getOrderService, 'prepareRequest');
-
- $this->assertEquals(array(
- 'orderId' => 7383,
- 'orderRowIds' => array(1, 3)
- ), $preparedData);
- }
+ public function testPrepareDataWithOrderIdAsInteger()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $orderRowIds = [1, 3];
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $getOrderService = WebPayAdmin::deliverOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setRowsToDeliver($orderRowIds)
+ ->deliverCheckoutOrderRows();
+
+ $preparedData = $this->invokeMethod($getOrderService, 'prepareRequest');
+
+ $this->assertEquals(7383, $preparedData['orderId']);
+ $this->assertEquals([1, 3], $preparedData['orderRowIds']);
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderIdAsString()
+ {
+ $sveaCheckoutOrderId = '7383';
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $getOrderService = WebPayAdmin::deliverOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->deliverCheckoutOrderRows();
+
+ $this->invokeMethod($getOrderService, 'prepareRequest');
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Row Id : Order Row Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderIdAsIntegerAndOrderRowIdsAsString()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $orderRowIds = ['1', '3'];
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $getOrderService = WebPayAdmin::deliverOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setRowsToDeliver($orderRowIds)
+ ->deliverCheckoutOrderRows();
+
+ $this->invokeMethod($getOrderService, 'prepareRequest');
+ }
+
+ public function testPrepareDataWithOrderIdAsIntegerAndOrderRowIdsAsInteger()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $orderRowIds = [1, 3];
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $getOrderService = WebPayAdmin::deliverOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->setRowsToDeliver($orderRowIds)
+ ->deliverCheckoutOrderRows();
+
+ $preparedData = $this->invokeMethod($getOrderService, 'prepareRequest');
+
+ $this->assertEquals([
+ 'orderId' => 7383,
+ 'orderRowIds' => [1, 3]
+ ], $preparedData);
+ }
}
diff --git a/test/UnitTest/Checkout/Service/Admin/GetOrderServiceTest.php b/test/UnitTest/Checkout/Service/Admin/GetOrderServiceTest.php
index 91d3a120..9d3e2ed4 100644
--- a/test/UnitTest/Checkout/Service/Admin/GetOrderServiceTest.php
+++ b/test/UnitTest/Checkout/Service/Admin/GetOrderServiceTest.php
@@ -10,58 +10,58 @@
class GetOrderServiceTest extends TestCase
{
- public function testPrepareDataWithOrderIdAsInteger()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
+ public function testPrepareDataWithOrderIdAsInteger()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
- $getOrderService = WebPayAdmin::queryOrder($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->queryCheckoutOrder();
+ $getOrderService = WebPayAdmin::queryOrder($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->queryCheckoutOrder();
- $preparedData = $this->invokeMethod($getOrderService, 'prepareRequest');
+ $preparedData = $this->invokeMethod($getOrderService, 'prepareRequest');
- $this->assertEquals(7383, $preparedData['orderId']);
- }
+ $this->assertEquals(7383, $preparedData['orderId']);
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderIdAsString()
- {
- $sveaCheckoutOrderId = '7383';
- $testConfig = ConfigurationService::getTestConfig();
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderIdAsString()
+ {
+ $sveaCheckoutOrderId = '7383';
+ $testConfig = ConfigurationService::getTestConfig();
- $getOrderService = WebPayAdmin::queryOrder($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->queryCheckoutOrder();
+ $getOrderService = WebPayAdmin::queryOrder($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->queryCheckoutOrder();
- $this->invokeMethod($getOrderService, 'prepareRequest');
- }
+ $this->invokeMethod($getOrderService, 'prepareRequest');
+ }
- public function testDoRequest()
- {
- $this->markTestSkipped('Skip Do request test');
- $testConfig = ConfigurationService::getTestConfig();
+ public function testDoRequest()
+ {
+ $this->markTestSkipped('Skip Do request test');
+ $testConfig = ConfigurationService::getTestConfig();
- /**
- * @var QueryOrderBuilder|\PHPUnit_Framework_MockObject_MockObject $queryOrderBuilder
- */
- $queryOrderBuilder = $this->getMockBuilder('\Svea\WebPay\BuildOrder\QueryOrderBuilder')
- ->setConstructorArgs(array($testConfig))
- ->getMock();
+ /**
+ * @var QueryOrderBuilder|\PHPUnit_Framework_MockObject_MockObject $queryOrderBuilder
+ */
+ $queryOrderBuilder = $this->getMockBuilder('\Svea\WebPay\BuildOrder\QueryOrderBuilder')
+ ->setConstructorArgs([$testConfig])
+ ->getMock();
- /**
- * @var GetOrderService|\PHPUnit_Framework_MockObject_MockObject $getOrderServiceMock
- */
- $getOrderServiceMock = $this->getMockBuilder('\Svea\WebPay\Checkout\Service\Admin\GetOrderService')
- ->setConstructorArgs(array($queryOrderBuilder))
- ->setMethods(array('validate', 'prepareData', 'doRequest'))
- ->getMock();
+ /**
+ * @var GetOrderService|\PHPUnit_Framework_MockObject_MockObject $getOrderServiceMock
+ */
+ $getOrderServiceMock = $this->getMockBuilder('\Svea\WebPay\Checkout\Service\Admin\GetOrderService')
+ ->setConstructorArgs([$queryOrderBuilder])
+ ->setMethods(['validate', 'prepareData', 'doRequest'])
+ ->getMock();
- $getOrderServiceMock->expects($this->once())->method('prepareRequest');
+ $getOrderServiceMock->expects($this->once())->method('prepareRequest');
- $getOrderServiceMock->doRequest();
- }
+ $getOrderServiceMock->doRequest();
+ }
}
diff --git a/test/UnitTest/Checkout/Service/Admin/UpdateOrderRowsServiceTest.php b/test/UnitTest/Checkout/Service/Admin/UpdateOrderRowsServiceTest.php
index 78d76367..b7cbd85c 100644
--- a/test/UnitTest/Checkout/Service/Admin/UpdateOrderRowsServiceTest.php
+++ b/test/UnitTest/Checkout/Service/Admin/UpdateOrderRowsServiceTest.php
@@ -9,103 +9,103 @@
class UpdateOrderRowsServiceTest extends TestCase
{
- public function testPrepareDataWithValidData()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderRow = WebPayItem::numberedOrderRow()
- ->setRowId(4)
- ->setName('someProd')
- ->setVatPercent(6)
- ->setDiscountPercent(50)
- ->setAmountIncVat(123.9876)
- ->setQuantity(4)
- ->setUnit('pc');
-
- $orderService = WebPayAdmin::updateOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->updateOrderRow($orderRow)
- ->updateCheckoutOrderRows();
-
- $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
-
- $this->assertEquals(7383, $preparedData['orderId']);
- $this->assertEquals(4, $preparedData['orderRowId']);
- $this->assertArrayHasKey('articleNumber', $preparedData['orderRow']);
- $this->assertArrayHasKey('name', $preparedData['orderRow']);
- $this->assertArrayHasKey('quantity', $preparedData['orderRow']);
- $this->assertArrayHasKey('vatPercent', $preparedData['orderRow']);
- $this->assertArrayHasKey('unitPrice', $preparedData['orderRow']);
- $this->assertArrayHasKey('unit', $preparedData['orderRow']);
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
- */
- public function testPrepareDataWithOrderIdAsString()
- {
- $sveaCheckoutOrderId = '7383';
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderRow = WebPayItem::numberedOrderRow()
- ->setRowId(4)
- ->setName('someProd')
- ->setVatPercent(6)
- ->setDiscountPercent(50)
- ->setAmountIncVat(123.9876)
- ->setQuantity(4)
- ->setUnit('pc');
-
- $orderService = WebPayAdmin::updateOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->updateOrderRow($orderRow)
- ->updateCheckoutOrderRows();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Row data : You can Update just one Order Row
- */
- public function testPrepareDataWithMultipleOrderRows()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderRow = WebPayItem::numberedOrderRow()
- ->setRowId(4)
- ->setName('someProd')
- ->setVatPercent(6)
- ->setDiscountPercent(50)
- ->setAmountIncVat(123.9876)
- ->setQuantity(4)
- ->setUnit('pc');
-
- $orderService = WebPayAdmin::updateOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->updateOrderRow($orderRow)
- ->updateOrderRow($orderRow)
- ->updateCheckoutOrderRows();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
-
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage incorrect Order Row data : Order Row data can't be empty and must be Array
- */
- public function testPrepareDataWithoutOrderRow()
- {
- $sveaCheckoutOrderId = 7383;
- $testConfig = ConfigurationService::getTestConfig();
-
- $orderService = WebPayAdmin::updateOrderRows($testConfig)
- ->setCheckoutOrderId($sveaCheckoutOrderId)
- ->updateCheckoutOrderRows();
-
- $this->invokeMethod($orderService, 'prepareRequest');
- }
+ public function testPrepareDataWithValidData()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderRow = WebPayItem::numberedOrderRow()
+ ->setRowId(4)
+ ->setName('someProd')
+ ->setVatPercent(6)
+ ->setDiscountPercent(50)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(4)
+ ->setUnit('pc');
+
+ $orderService = WebPayAdmin::updateOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->updateOrderRow($orderRow)
+ ->updateCheckoutOrderRows();
+
+ $preparedData = $this->invokeMethod($orderService, 'prepareRequest');
+
+ $this->assertEquals(7383, $preparedData['orderId']);
+ $this->assertEquals(4, $preparedData['orderRowId']);
+ $this->assertArrayHasKey('articleNumber', $preparedData['orderRow']);
+ $this->assertArrayHasKey('name', $preparedData['orderRow']);
+ $this->assertArrayHasKey('quantity', $preparedData['orderRow']);
+ $this->assertArrayHasKey('vatPercent', $preparedData['orderRow']);
+ $this->assertArrayHasKey('unitPrice', $preparedData['orderRow']);
+ $this->assertArrayHasKey('unit', $preparedData['orderRow']);
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Id : Order Id can't be empty and must be Integer
+ */
+ public function testPrepareDataWithOrderIdAsString()
+ {
+ $sveaCheckoutOrderId = '7383';
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderRow = WebPayItem::numberedOrderRow()
+ ->setRowId(4)
+ ->setName('someProd')
+ ->setVatPercent(6)
+ ->setDiscountPercent(50)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(4)
+ ->setUnit('pc');
+
+ $orderService = WebPayAdmin::updateOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->updateOrderRow($orderRow)
+ ->updateCheckoutOrderRows();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Row data : You can Update just one Order Row
+ */
+ public function testPrepareDataWithMultipleOrderRows()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderRow = WebPayItem::numberedOrderRow()
+ ->setRowId(4)
+ ->setName('someProd')
+ ->setVatPercent(6)
+ ->setDiscountPercent(50)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(4)
+ ->setUnit('pc');
+
+ $orderService = WebPayAdmin::updateOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->updateOrderRow($orderRow)
+ ->updateOrderRow($orderRow)
+ ->updateCheckoutOrderRows();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
+
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage incorrect Order Row data : Order Row data can't be empty and must be Array
+ */
+ public function testPrepareDataWithoutOrderRow()
+ {
+ $sveaCheckoutOrderId = 7383;
+ $testConfig = ConfigurationService::getTestConfig();
+
+ $orderService = WebPayAdmin::updateOrderRows($testConfig)
+ ->setCheckoutOrderId($sveaCheckoutOrderId)
+ ->updateCheckoutOrderRows();
+
+ $this->invokeMethod($orderService, 'prepareRequest');
+ }
}
diff --git a/test/UnitTest/Checkout/Service/CreateCheckoutServiceTest.php b/test/UnitTest/Checkout/Service/CreateCheckoutServiceTest.php
index 103b7ea0..3cbe89af 100644
--- a/test/UnitTest/Checkout/Service/CreateCheckoutServiceTest.php
+++ b/test/UnitTest/Checkout/Service/CreateCheckoutServiceTest.php
@@ -12,84 +12,84 @@
*/
class CreateCheckoutServiceTest extends TestCase
{
- /**
- * @var CheckoutService
- */
- protected $service;
-
- public function setUp()
- {
- parent::setUp();
-
- $this->order->setCountryCode("SE")
- ->setCurrency('SEK')
- ->setCheckoutUri('http://localhost:51925/')
- ->setConfirmationUri('http://localhost:51925/checkout/confirm')
- ->setPushUri('https://svea.com/push.aspx?sid=123&svea_order=123')
- ->setTermsUri('http://localhost:51898/terms')
- ->setLocale('sv-Se')
- ->setMerchantData("Test string");
-
- $this->service = new CreateOrderService($this->order);
- }
-
- /**
- * @test
- */
- public function gettingFormattedRows()
- {
- $this->order
- ->addOrderRow($this->returnOrderRow())
- ->addOrderRow($this->returnOrderRow());
-
- $formattedOrderRows = $this->invokeMethod($this->service, 'formatOrderInformationWithOrderRows');
-
- $this->assertEquals(2, count($formattedOrderRows));
- }
-
- /**
- * @test
- */
- public function preparingData()
- {
- $this->order
- ->addPresetValue($this->returnPresetValue())
- ->addOrderRow($this->returnOrderRow())
- ->addOrderRow($this->returnOrderRow());
-
- $formattedOrderRows = $this->invokeMethod($this->service, 'mapCreateOrderData', array($this->order));
-
- $this->assertArrayHasKey('cart', $formattedOrderRows);
- $this->assertArrayHasKey('currency', $formattedOrderRows);
- $this->assertArrayHasKey('countryCode', $formattedOrderRows);
- $this->assertArrayHasKey('locale', $formattedOrderRows);
- $this->assertArrayHasKey('merchantSettings', $formattedOrderRows);
- $this->assertArrayHasKey('presetValues', $formattedOrderRows);
- $this->assertArrayHasKey('merchantData', $formattedOrderRows);
- }
-
- /**
- * @test
- */
- public function orderValidationWithBadOrder()
- {
- $errors = $this->invokeMethod($this->service, 'validateOrder');
-
- $this->assertGreaterThan(0, count($errors));
- }
-
- /**
- * @test
- */
- public function orderValidationWithGoodOrder()
- {
- $this->order
- ->addOrderRow($this->returnOrderRow())
- ->addOrderRow($this->returnOrderRow());
-
- $errors = $this->invokeMethod($this->service, 'validateOrder');
-
- $this->assertEquals(0, count($errors));
- }
+ /**
+ * @var CheckoutService
+ */
+ protected $service;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->order->setCountryCode("SE")
+ ->setCurrency('SEK')
+ ->setCheckoutUri('http://localhost:51925/')
+ ->setConfirmationUri('http://localhost:51925/checkout/confirm')
+ ->setPushUri('https://svea.com/push.aspx?sid=123&svea_order=123')
+ ->setTermsUri('http://localhost:51898/terms')
+ ->setLocale('sv-Se')
+ ->setMerchantData("Test string");
+
+ $this->service = new CreateOrderService($this->order);
+ }
+
+ /**
+ * @test
+ */
+ public function gettingFormattedRows()
+ {
+ $this->order
+ ->addOrderRow($this->returnOrderRow())
+ ->addOrderRow($this->returnOrderRow());
+
+ $formattedOrderRows = $this->invokeMethod($this->service, 'formatOrderInformationWithOrderRows');
+
+ $this->assertEquals(2, count($formattedOrderRows));
+ }
+
+ /**
+ * @test
+ */
+ public function preparingData()
+ {
+ $this->order
+ ->addPresetValue($this->returnPresetValue())
+ ->addOrderRow($this->returnOrderRow())
+ ->addOrderRow($this->returnOrderRow());
+
+ $formattedOrderRows = $this->invokeMethod($this->service, 'mapCreateOrderData', [$this->order]);
+
+ $this->assertArrayHasKey('cart', $formattedOrderRows);
+ $this->assertArrayHasKey('currency', $formattedOrderRows);
+ $this->assertArrayHasKey('countryCode', $formattedOrderRows);
+ $this->assertArrayHasKey('locale', $formattedOrderRows);
+ $this->assertArrayHasKey('merchantSettings', $formattedOrderRows);
+ $this->assertArrayHasKey('presetValues', $formattedOrderRows);
+ $this->assertArrayHasKey('merchantData', $formattedOrderRows);
+ }
+
+ /**
+ * @test
+ */
+ public function orderValidationWithBadOrder()
+ {
+ $errors = $this->invokeMethod($this->service, 'validateOrder');
+
+ $this->assertGreaterThan(0, count($errors));
+ }
+
+ /**
+ * @test
+ */
+ public function orderValidationWithGoodOrder()
+ {
+ $this->order
+ ->addOrderRow($this->returnOrderRow())
+ ->addOrderRow($this->returnOrderRow());
+
+ $errors = $this->invokeMethod($this->service, 'validateOrder');
+
+ $this->assertEquals(0, count($errors));
+ }
}
diff --git a/test/UnitTest/Checkout/Service/GetCheckoutServiceTest.php b/test/UnitTest/Checkout/Service/GetCheckoutServiceTest.php
index 87d7a8a8..e610b500 100644
--- a/test/UnitTest/Checkout/Service/GetCheckoutServiceTest.php
+++ b/test/UnitTest/Checkout/Service/GetCheckoutServiceTest.php
@@ -12,39 +12,39 @@
*/
class GetCheckoutServiceTest extends TestCase
{
- /**
- * @var CheckoutService
- */
- protected $service;
-
- public function setUp()
- {
- parent::setUp();
-
- $this->service = new GetOrderService($this->order);
- }
-
- /**
- * @test
- */
- public function orderValidationWithBadOrder()
- {
- $errors = $this->invokeMethod($this->service, 'validateOrder');
-
- $this->assertGreaterThan(0, count($errors));
- }
-
- /**
- * @test
- */
- public function orderValidationWithGoodOrder()
- {
- $this->order
- ->setId(123);
-
- $errors = $this->invokeMethod($this->service, 'validateOrder');
-
- $this->assertEquals(0, count($errors));
- }
+ /**
+ * @var CheckoutService
+ */
+ protected $service;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->service = new GetOrderService($this->order);
+ }
+
+ /**
+ * @test
+ */
+ public function orderValidationWithBadOrder()
+ {
+ $errors = $this->invokeMethod($this->service, 'validateOrder');
+
+ $this->assertGreaterThan(0, count($errors));
+ }
+
+ /**
+ * @test
+ */
+ public function orderValidationWithGoodOrder()
+ {
+ $this->order
+ ->setId(123);
+
+ $errors = $this->invokeMethod($this->service, 'validateOrder');
+
+ $this->assertEquals(0, count($errors));
+ }
}
diff --git a/test/UnitTest/Checkout/Service/UpdateCheckoutServiceTest.php b/test/UnitTest/Checkout/Service/UpdateCheckoutServiceTest.php
index 3005ba0f..05443035 100644
--- a/test/UnitTest/Checkout/Service/UpdateCheckoutServiceTest.php
+++ b/test/UnitTest/Checkout/Service/UpdateCheckoutServiceTest.php
@@ -12,73 +12,73 @@
*/
class UpdateCheckoutServiceTest extends TestCase
{
- /**
- * @var CheckoutService
- */
- protected $service;
-
- public function setUp()
- {
- parent::setUp();
-
- $this->order->setCountryCode("SE");
-
- $this->service = new UpdateOrderService($this->order);
- }
-
- /**
- * @test
- */
- public function gettingFormattedRows()
- {
- $this->order
- ->addOrderRow($this->returnOrderRow())
- ->addOrderRow($this->returnOrderRow());
-
- $formattedOrderRows = $this->invokeMethod($this->service, 'formatOrderInformationWithOrderRows');
-
- $this->assertEquals(2, count($formattedOrderRows));
- }
-
- /**
- * @test
- */
- public function preparingData()
- {
- $this->order
- ->addOrderRow($this->returnOrderRow())
- ->addOrderRow($this->returnOrderRow());
-
- $formattedOrderRows = $this->invokeMethod($this->service, 'mapCreateOrderData', array($this->order));
-
- $this->assertArrayHasKey('cart', $formattedOrderRows);
- $this->assertArrayHasKey('orderId', $formattedOrderRows);
- $this->assertArrayHasKey('merchantData', $formattedOrderRows);
- }
-
- /**
- * @test
- */
- public function orderValidationWithBadOrder()
- {
- $errors = $this->invokeMethod($this->service, 'validateOrder');
-
- $this->assertGreaterThan(0, count($errors));
- }
-
- /**
- * @test
- */
- public function orderValidationWithGoodOrder()
- {
- $this->order
- ->setId(123)
- ->addOrderRow($this->returnOrderRow())
- ->addOrderRow($this->returnOrderRow());
-
- $errors = $this->invokeMethod($this->service, 'validateOrder');
-
- $this->assertEquals(0, count($errors));
- }
+ /**
+ * @var CheckoutService
+ */
+ protected $service;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->order->setCountryCode("SE");
+
+ $this->service = new UpdateOrderService($this->order);
+ }
+
+ /**
+ * @test
+ */
+ public function gettingFormattedRows()
+ {
+ $this->order
+ ->addOrderRow($this->returnOrderRow())
+ ->addOrderRow($this->returnOrderRow());
+
+ $formattedOrderRows = $this->invokeMethod($this->service, 'formatOrderInformationWithOrderRows');
+
+ $this->assertEquals(2, count($formattedOrderRows));
+ }
+
+ /**
+ * @test
+ */
+ public function preparingData()
+ {
+ $this->order
+ ->addOrderRow($this->returnOrderRow())
+ ->addOrderRow($this->returnOrderRow());
+
+ $formattedOrderRows = $this->invokeMethod($this->service, 'mapCreateOrderData', [$this->order]);
+
+ $this->assertArrayHasKey('cart', $formattedOrderRows);
+ $this->assertArrayHasKey('orderId', $formattedOrderRows);
+ $this->assertArrayHasKey('merchantData', $formattedOrderRows);
+ }
+
+ /**
+ * @test
+ */
+ public function orderValidationWithBadOrder()
+ {
+ $errors = $this->invokeMethod($this->service, 'validateOrder');
+
+ $this->assertGreaterThan(0, count($errors));
+ }
+
+ /**
+ * @test
+ */
+ public function orderValidationWithGoodOrder()
+ {
+ $this->order
+ ->setId(123)
+ ->addOrderRow($this->returnOrderRow())
+ ->addOrderRow($this->returnOrderRow());
+
+ $errors = $this->invokeMethod($this->service, 'validateOrder');
+
+ $this->assertEquals(0, count($errors));
+ }
}
diff --git a/test/UnitTest/Checkout/TestCase.php b/test/UnitTest/Checkout/TestCase.php
index 65693d6d..f654b199 100644
--- a/test/UnitTest/Checkout/TestCase.php
+++ b/test/UnitTest/Checkout/TestCase.php
@@ -10,113 +10,113 @@
class TestCase extends \PHPUnit\Framework\TestCase
{
- /**
- * @var CheckoutOrderBuilder
- */
- protected $order;
-
- public function setUp()
- {
- $this->order = $this->returnCreatedOrder();
- }
-
- /**
- * @param $object
- * @param $methodName
- * @param array $parameters
- * @return mixed
- */
- public function invokeMethod(&$object, $methodName, array $parameters = array())
- {
- $reflection = new \ReflectionClass(get_class($object));
- $method = $reflection->getMethod($methodName);
- $method->setAccessible(true);
-
- return $method->invokeArgs($object, $parameters);
- }
-
- /**
- * @param $object
- * @param $propertyName
- * @return \ReflectionProperty
- */
- public function getPrivateProperty(&$object, $propertyName)
- {
- $reflector = new \ReflectionClass(get_class($object));
- $property = $reflector->getProperty($propertyName);
- $property->setAccessible(true);
-
- return $property->getValue($object);
- }
-
- /**
- * Creates a populated order object for use in tests
- *
- * @return CheckoutOrderBuilder
- */
- protected function returnCreatedOrder()
- {
- $config = ConfigurationService::getTestConfig();
-
- $orderObject = WebPay::Checkout($config);
-
- return $this->getPrivateProperty($orderObject, 'checkoutOrderBuilder');
- }
-
- /**
- * @return \Svea\WebPay\BuildOrder\RowBuilders\OrderRow
- */
- protected function returnOrderRow()
- {
- // create and add items to order
- $orderRow = WebPayItem::orderRow()
- ->setAmountIncVat(rand(1, 1000) + rand(1, 99) / 100)// - required
- ->setVatPercent($this->getRandVatPercent())// - required
- ->setQuantity($this->getRandQuantity())
- ->setDiscountPercent($this->getRandDiscountPercent())
- ->setArticleNumber("123456")
- ->setName('Fork');
-
- return $orderRow;
- }
-
- /**
- * @return PresetValue
- */
- protected function returnPresetValue()
- {
- $presetValue = new PresetValue();
- $presetValue->setTypeName(PresetValue::EMAIL_ADDRESS)
- ->setValue("email@mail.com")
- ->setIsReadonly(true);
-
- return $presetValue;
- }
-
- /**
- * Return random Vat Percent
- * @return mixed
- */
- protected function getRandVatPercent()
- {
- return array_rand(array(6, 12, 25));
- }
-
- /**
- * Return random Discount Percent
- * @return mixed
- */
- protected function getRandDiscountPercent()
- {
- return array_rand(array(6, 12, 20, 25));
- }
-
- /**
- * Return random Quantity
- * @return int
- */
- protected function getRandQuantity()
- {
- return rand(1, 100);
- }
+ /**
+ * @var CheckoutOrderBuilder
+ */
+ protected $order;
+
+ public function setUp()
+ {
+ $this->order = $this->returnCreatedOrder();
+ }
+
+ /**
+ * @param $object
+ * @param $methodName
+ * @param array $parameters
+ * @return mixed
+ */
+ public function invokeMethod(&$object, $methodName, array $parameters = [])
+ {
+ $reflection = new \ReflectionClass(get_class($object));
+ $method = $reflection->getMethod($methodName);
+ $method->setAccessible(true);
+
+ return $method->invokeArgs($object, $parameters);
+ }
+
+ /**
+ * @param $object
+ * @param $propertyName
+ * @return \ReflectionProperty
+ */
+ public function getPrivateProperty(&$object, $propertyName)
+ {
+ $reflector = new \ReflectionClass(get_class($object));
+ $property = $reflector->getProperty($propertyName);
+ $property->setAccessible(true);
+
+ return $property->getValue($object);
+ }
+
+ /**
+ * Creates a populated order object for use in tests
+ *
+ * @return CheckoutOrderBuilder
+ */
+ protected function returnCreatedOrder()
+ {
+ $config = ConfigurationService::getTestConfig();
+
+ $orderObject = WebPay::Checkout($config);
+
+ return $this->getPrivateProperty($orderObject, 'checkoutOrderBuilder');
+ }
+
+ /**
+ * @return \Svea\WebPay\BuildOrder\RowBuilders\OrderRow
+ */
+ protected function returnOrderRow()
+ {
+ // create and add items to order
+ $orderRow = WebPayItem::orderRow()
+ ->setAmountIncVat(rand(1, 1000) + rand(1, 99) / 100)// - required
+ ->setVatPercent($this->getRandVatPercent())// - required
+ ->setQuantity($this->getRandQuantity())
+ ->setDiscountPercent($this->getRandDiscountPercent())
+ ->setArticleNumber("123456")
+ ->setName('Fork');
+
+ return $orderRow;
+ }
+
+ /**
+ * @return PresetValue
+ */
+ protected function returnPresetValue()
+ {
+ $presetValue = new PresetValue();
+ $presetValue->setTypeName(PresetValue::EMAIL_ADDRESS)
+ ->setValue("email@mail.com")
+ ->setIsReadonly(true);
+
+ return $presetValue;
+ }
+
+ /**
+ * Return random Vat Percent
+ * @return mixed
+ */
+ protected function getRandVatPercent()
+ {
+ return array_rand([6, 12, 25]);
+ }
+
+ /**
+ * Return random Discount Percent
+ * @return mixed
+ */
+ protected function getRandDiscountPercent()
+ {
+ return array_rand([6, 12, 20, 25]);
+ }
+
+ /**
+ * Return random Quantity
+ * @return int
+ */
+ protected function getRandQuantity()
+ {
+ return rand(1, 100);
+ }
}
diff --git a/test/UnitTest/Checkout/Validation/CreateOrderValidationTest.php b/test/UnitTest/Checkout/Validation/CreateOrderValidationTest.php
index 84471c39..a54155f1 100644
--- a/test/UnitTest/Checkout/Validation/CreateOrderValidationTest.php
+++ b/test/UnitTest/Checkout/Validation/CreateOrderValidationTest.php
@@ -14,127 +14,127 @@
*/
class CreateOrderValidationTest extends TestCase
{
- /**
- * @var OrderValidator
- */
- protected $validator;
+ /**
+ * @var OrderValidator
+ */
+ protected $validator;
- public function setUp()
- {
- parent::setUp();
- $this->validator = new CreateOrderValidator();
- }
+ public function setUp()
+ {
+ parent::setUp();
+ $this->validator = new CreateOrderValidator();
+ }
- /**
- * @test
- */
- public function ifRequiredOrderFieldsArePassed()
- {
- $this->order->setCountryCode('SE')
- ->setCurrency('SEK')
- ->setLocale('sv-Se');
+ /**
+ * @test
+ */
+ public function ifRequiredOrderFieldsArePassed()
+ {
+ $this->order->setCountryCode('SE')
+ ->setCurrency('SEK')
+ ->setLocale('sv-Se');
- $errors = $this->invokeMethod($this->validator, 'validateRequiredOrderFields', array($this->order, array()));
+ $errors = $this->invokeMethod($this->validator, 'validateRequiredOrderFields', [$this->order, []]);
- $errorsNum = count($errors);
+ $errorsNum = count($errors);
- $this->assertEquals(0, $errorsNum);
- }
+ $this->assertEquals(0, $errorsNum);
+ }
- /**
- * @test
- */
- public function ifRequiredOrderFieldsAreNotPassed()
- {
- $errors = $this->invokeMethod($this->validator, 'validateRequiredOrderFields', array($this->order, array()));
+ /**
+ * @test
+ */
+ public function ifRequiredOrderFieldsAreNotPassed()
+ {
+ $errors = $this->invokeMethod($this->validator, 'validateRequiredOrderFields', [$this->order, []]);
- $errorsNum = count($errors);
+ $errorsNum = count($errors);
- $this->assertGreaterThan(0, $errorsNum);
- }
+ $this->assertGreaterThan(0, $errorsNum);
+ }
- /**
- * @test
- */
- public function ifOrderRowsAreNotPassed()
- {
- $errors = $this->invokeMethod($this->validator, 'validateRequiredFieldsForOrder', array($this->order, array()));
+ /**
+ * @test
+ */
+ public function ifOrderRowsAreNotPassed()
+ {
+ $errors = $this->invokeMethod($this->validator, 'validateRequiredFieldsForOrder', [$this->order, []]);
- $errorsNum = count($errors);
+ $errorsNum = count($errors);
- $this->assertGreaterThan(0, $errorsNum);
- }
+ $this->assertGreaterThan(0, $errorsNum);
+ }
- /**
- * @test
- */
- public function ifOrderRowsArePassed()
- {
- $this->order->addOrderRow($this->returnOrderRow());
+ /**
+ * @test
+ */
+ public function ifOrderRowsArePassed()
+ {
+ $this->order->addOrderRow($this->returnOrderRow());
- $errors = $this->invokeMethod($this->validator, 'validateRequiredFieldsForOrder', array($this->order, array()));
+ $errors = $this->invokeMethod($this->validator, 'validateRequiredFieldsForOrder', [$this->order, []]);
- $errorsNum = count($errors);
+ $errorsNum = count($errors);
- $this->assertEquals(0, $errorsNum);
- }
+ $this->assertEquals(0, $errorsNum);
+ }
- /**
- * @test
- */
- public function ifMerchantRowsAreNotPassed()
- {
- $this->order;
+ /**
+ * @test
+ */
+ public function ifMerchantRowsAreNotPassed()
+ {
+ $this->order;
- $errors = $this->invokeMethod($this->validator, 'validateMerchantSettings', array($this->order, array()));
+ $errors = $this->invokeMethod($this->validator, 'validateMerchantSettings', [$this->order, []]);
- $errorsNum = count($errors);
+ $errorsNum = count($errors);
- $this->assertGreaterThan(0, $errorsNum);
- }
+ $this->assertGreaterThan(0, $errorsNum);
+ }
- /**
- * @test
- */
- public function ifMerchantRowsArePassed()
- {
- $this->order->setCheckoutUri('http://localhost:51925/')
- ->setConfirmationUri('http://localhost:51925/checkout/confirm')
- ->setPushUri('https://svea.com/push.aspx?sid=123&svea_order=123')
- ->setTermsUri('http://localhost:51898/terms');
+ /**
+ * @test
+ */
+ public function ifMerchantRowsArePassed()
+ {
+ $this->order->setCheckoutUri('http://localhost:51925/')
+ ->setConfirmationUri('http://localhost:51925/checkout/confirm')
+ ->setPushUri('https://svea.com/push.aspx?sid=123&svea_order=123')
+ ->setTermsUri('http://localhost:51898/terms');
- $errors = $this->invokeMethod($this->validator, 'validateMerchantSettings', array($this->order, array()));
+ $errors = $this->invokeMethod($this->validator, 'validateMerchantSettings', [$this->order, []]);
- $errorsNum = count($errors);
+ $errorsNum = count($errors);
- $this->assertEquals(0, $errorsNum);
- }
+ $this->assertEquals(0, $errorsNum);
+ }
- /**
- * @test
- */
- public function ifPartnerKeyPassed()
- {
- $this->order->setPartnerKey("77FB33EC-505D-4CCF-AA21-D9DF50DC8344");
+ /**
+ * @test
+ */
+ public function ifPartnerKeyPassed()
+ {
+ $this->order->setPartnerKey("77FB33EC-505D-4CCF-AA21-D9DF50DC8344");
- $errors = $this->invokeMethod($this->validator, 'validatePartnerKey', array($this->order, array()));
+ $errors = $this->invokeMethod($this->validator, 'validatePartnerKey', [$this->order, []]);
- $errorsNum = count($errors);
+ $errorsNum = count($errors);
- $this->assertEquals(0, $errorsNum);
- }
+ $this->assertEquals(0, $errorsNum);
+ }
- /**
- * @test
- */
- public function requireElectronicIdAuthenticationWrongType()
- {
- $this->order->setRequireElectronicIdAuthentication(true);
+ /**
+ * @test
+ */
+ public function requireElectronicIdAuthenticationWrongType()
+ {
+ $this->order->setRequireElectronicIdAuthentication(true);
- $errors = $this->invokeMethod($this->validator, 'validateRequireElectronicIdAuthentication', array($this->order, array()));
+ $errors = $this->invokeMethod($this->validator, 'validateRequireElectronicIdAuthentication', [$this->order, []]);
- $errorsNum = count($errors);
+ $errorsNum = count($errors);
- $this->assertEquals(0, $errorsNum);
- }
+ $this->assertEquals(0, $errorsNum);
+ }
}
diff --git a/test/UnitTest/Checkout/Validation/GetAvailablePartPaymentCampaignsValidationTest.php b/test/UnitTest/Checkout/Validation/GetAvailablePartPaymentCampaignsValidationTest.php
index ef847f67..66d424b9 100644
--- a/test/UnitTest/Checkout/Validation/GetAvailablePartPaymentCampaignsValidationTest.php
+++ b/test/UnitTest/Checkout/Validation/GetAvailablePartPaymentCampaignsValidationTest.php
@@ -13,53 +13,53 @@
*/
class GetAvailablePartPaymentCampaignsValidationTest extends TestCase
{
- /**
- * @test
- */
- public function validatePresetValueIsCompanySuccess()
- {
- $presetValueIsCompany = \Svea\WebPay\WebPayItem::presetValue()
- ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::IS_COMPANY)
- ->setValue(false)
- ->setIsReadonly(true);
+ /**
+ * @test
+ */
+ public function validatePresetValueIsCompanySuccess()
+ {
+ $presetValueIsCompany = \Svea\WebPay\WebPayItem::presetValue()
+ ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::IS_COMPANY)
+ ->setValue(false)
+ ->setIsReadonly(true);
- $presetRequest = new CheckoutOrderBuilder(ConfigurationService::getTestConfig());
- $presetRequest->addPresetValue($presetValueIsCompany);
+ $presetRequest = new CheckoutOrderBuilder(ConfigurationService::getTestConfig());
+ $presetRequest->addPresetValue($presetValueIsCompany);
- $errors = new GetAvailablePartPaymentCampaignsValidator();
+ $errors = new GetAvailablePartPaymentCampaignsValidator();
- $this->assertEquals(0, count($errors->validate($presetRequest)));
- }
+ $this->assertEquals(0, count($errors->validate($presetRequest)));
+ }
- /**
- * @test
- */
- public function validatePresetValueIsCompanyValueWrongType()
- {
- $presetValueIsCompany = \Svea\WebPay\WebPayItem::presetValue()
- ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::IS_COMPANY)
- ->setValue("false")
- ->setIsReadonly(true);
+ /**
+ * @test
+ */
+ public function validatePresetValueIsCompanyValueWrongType()
+ {
+ $presetValueIsCompany = \Svea\WebPay\WebPayItem::presetValue()
+ ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::IS_COMPANY)
+ ->setValue("false")
+ ->setIsReadonly(true);
- $presetRequest = new CheckoutOrderBuilder(ConfigurationService::getTestConfig());
- $presetRequest->addPresetValue($presetValueIsCompany);
+ $presetRequest = new CheckoutOrderBuilder(ConfigurationService::getTestConfig());
+ $presetRequest->addPresetValue($presetValueIsCompany);
- $errors = new GetAvailablePartPaymentCampaignsValidator();
+ $errors = new GetAvailablePartPaymentCampaignsValidator();
- $this->assertGreaterThan(0, count($errors->validate($presetRequest)));
- }
+ $this->assertGreaterThan(0, count($errors->validate($presetRequest)));
+ }
- public function validatePresetValueIsCompanyValueNotSet()
- {
- $presetValueIsCompany = \Svea\WebPay\WebPayItem::presetValue()
- ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::IS_COMPANY)
- ->setIsReadonly(true);
+ public function validatePresetValueIsCompanyValueNotSet()
+ {
+ $presetValueIsCompany = \Svea\WebPay\WebPayItem::presetValue()
+ ->setTypeName(\Svea\WebPay\Checkout\Model\PresetValue::IS_COMPANY)
+ ->setIsReadonly(true);
- $presetRequest = new CheckoutOrderBuilder(ConfigurationService::getTestConfig());
- $presetRequest->addPresetValue($presetValueIsCompany);
+ $presetRequest = new CheckoutOrderBuilder(ConfigurationService::getTestConfig());
+ $presetRequest->addPresetValue($presetValueIsCompany);
- $errors = new GetAvailablePartPaymentCampaignsValidator();
+ $errors = new GetAvailablePartPaymentCampaignsValidator();
- $this->assertGreaterThan(0, count($errors->validate($presetRequest)));
- }
+ $this->assertGreaterThan(0, count($errors->validate($presetRequest)));
+ }
}
diff --git a/test/UnitTest/Checkout/Validation/GetOrderValidationTest.php b/test/UnitTest/Checkout/Validation/GetOrderValidationTest.php
index c85aa5f2..d386c63e 100644
--- a/test/UnitTest/Checkout/Validation/GetOrderValidationTest.php
+++ b/test/UnitTest/Checkout/Validation/GetOrderValidationTest.php
@@ -13,40 +13,40 @@
*/
class GetOrderValidationTest extends TestCase
{
- /**
- * @var \Svea\WebPay\BuildOrder\Validator\OrderValidator
- */
- protected $validator;
-
- public function setUp()
- {
- parent::setUp();
- $this->validator = new GetOrderValidator();
- }
-
- /**
- * @test
- */
- public function ifCheckoutOrderIdNotPassed()
- {
- $errors = $this->validator->validate($this->order);
-
- $errorsNum = count($errors);
-
- $this->assertGreaterThan(0, $errorsNum);
- }
-
- /**
- * @test
- */
- public function ifCheckoutOrderIdPassed()
- {
- $this->order->setId(123);
-
- $errors = $this->validator->validate($this->order);
-
- $errorsNum = count($errors);
-
- $this->assertEquals(0, $errorsNum);
- }
+ /**
+ * @var \Svea\WebPay\BuildOrder\Validator\OrderValidator
+ */
+ protected $validator;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->validator = new GetOrderValidator();
+ }
+
+ /**
+ * @test
+ */
+ public function ifCheckoutOrderIdNotPassed()
+ {
+ $errors = $this->validator->validate($this->order);
+
+ $errorsNum = count($errors);
+
+ $this->assertGreaterThan(0, $errorsNum);
+ }
+
+ /**
+ * @test
+ */
+ public function ifCheckoutOrderIdPassed()
+ {
+ $this->order->setId(123);
+
+ $errors = $this->validator->validate($this->order);
+
+ $errorsNum = count($errors);
+
+ $this->assertEquals(0, $errorsNum);
+ }
}
diff --git a/test/UnitTest/Checkout/Validation/UpdateOrderValidationTest.php b/test/UnitTest/Checkout/Validation/UpdateOrderValidationTest.php
index c3c1d0ee..ad014667 100644
--- a/test/UnitTest/Checkout/Validation/UpdateOrderValidationTest.php
+++ b/test/UnitTest/Checkout/Validation/UpdateOrderValidationTest.php
@@ -12,42 +12,42 @@
*/
class UpdateOrderValidationTest extends TestCase
{
- /**
- * @var OrderValidator
- */
- protected $validator;
+ /**
+ * @var OrderValidator
+ */
+ protected $validator;
- public function setUp()
- {
- parent::setUp();
- $this->validator = new UpdateOrderValidator();
- }
+ public function setUp()
+ {
+ parent::setUp();
+ $this->validator = new UpdateOrderValidator();
+ }
- /**
- * @test
- */
- public function ifBlankCheckoutOrderIsPassed()
- {
- $this->order->setId(123);
+ /**
+ * @test
+ */
+ public function ifBlankCheckoutOrderIsPassed()
+ {
+ $this->order->setId(123);
- $errors = $this->invokeMethod($this->validator, 'validate', array($this->order, array()));
+ $errors = $this->invokeMethod($this->validator, 'validate', [$this->order, []]);
- $errorsNum = count($errors);
+ $errorsNum = count($errors);
- $this->assertEquals(0, $errorsNum);
- }
+ $this->assertEquals(0, $errorsNum);
+ }
- /**
- * @test
- */
- public function ifCheckoutOrderIdNotPassed()
- {
- $this->order->addOrderRow($this->returnOrderRow());
+ /**
+ * @test
+ */
+ public function ifCheckoutOrderIdNotPassed()
+ {
+ $this->order->addOrderRow($this->returnOrderRow());
- $errors = $this->invokeMethod($this->validator, 'validateOrderRows', array($this->order, array()));
+ $errors = $this->invokeMethod($this->validator, 'validateOrderRows', [$this->order, []]);
- $errorsNum = count($errors);
+ $errorsNum = count($errors);
- $this->assertEquals(0, $errorsNum);
- }
+ $this->assertEquals(0, $errorsNum);
+ }
}
diff --git a/test/UnitTest/Config/ConfigurationProviderTest.php b/test/UnitTest/Config/ConfigurationProviderTest.php
index 18dc9c0e..669ff6a9 100644
--- a/test/UnitTest/Config/ConfigurationProviderTest.php
+++ b/test/UnitTest/Config/ConfigurationProviderTest.php
@@ -7,14 +7,14 @@
class ConfigurationProviderTest extends \PHPUnit\Framework\TestCase {
-
- public function testDefaultTestConfig() {
- $config = ConfigurationService::getDefaultConfig();
- $this->assertEquals("sverigetest", $config->getUsername("Invoice","SE"));
- $this->assertEquals("sverigetest", $config->getPassword("PaymentPlan","SE"));
- $this->assertEquals("16997", $config->getClientNumber("PaymentPlan","DE"));
- $this->assertEquals("1130", $config->getMerchantId("HOSTED", "NL"));
- $this->assertEquals("58702", $config->getClientNumber("AccountCredit", "SE"));
- $this->assertEquals("https://webpaywsstage.svea.com/SveaWebPay.asmx?WSDL", $config->getEndPoint("Invoice"));
- }
+
+ public function testDefaultTestConfig() {
+ $config = ConfigurationService::getDefaultConfig();
+ $this->assertEquals("sverigetest", $config->getUsername("Invoice","SE"));
+ $this->assertEquals("sverigetest", $config->getPassword("PaymentPlan","SE"));
+ $this->assertEquals("16997", $config->getClientNumber("PaymentPlan","DE"));
+ $this->assertEquals("1130", $config->getMerchantId("HOSTED", "NL"));
+ $this->assertEquals("58702", $config->getClientNumber("AccountCredit", "SE"));
+ $this->assertEquals("https://webpaywsstage.svea.com/SveaWebPay.asmx?WSDL", $config->getEndPoint("Invoice"));
+ }
}
diff --git a/test/UnitTest/Config/SveaConfigTest.php b/test/UnitTest/Config/SveaConfigTest.php
index d22c1cdd..4c510b3f 100644
--- a/test/UnitTest/Config/SveaConfigTest.php
+++ b/test/UnitTest/Config/SveaConfigTest.php
@@ -12,106 +12,106 @@
class SveaConfigTest extends \PHPUnit\Framework\TestCase {
- function testSveaConfigNotFound(){
- $config = ConfigurationService::getTestConfig();
- $foo = WebPay::createOrder($config);
-
- $this->assertEquals("sverigetest", $config->conf['credentials']['SE']['auth']['Invoice']['username']);
- }
-
- public function testOrderWithSEConfigFromFunction() {
- $request = WebPay::createOrder(ConfigurationService::getTestConfig())
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("sverigetest", $request->request->Auth->Username);
- $this->assertEquals("sverigetest", $request->request->Auth->Password);
- $this->assertEquals(79021, $request->request->Auth->ClientNumber);
- }
-
- public function test_getSveaSingleCountryConfig_defaults() {
- $secret = "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3";
-
- $config = ConfigurationService::getSingleCountryConfig(
- null, // SE
- null, null, null, //invoice 79021
- null, null, null, //partpayment 59999
- null, null, null, //accountCredit 58702
- null, null, // merchantid 1130
- null // test
- );
-
- $this->assertInstanceOf('Svea\WebPay\Config\ConfigurationProvider', $config );
-
- $this->assertEquals("sverigetest", $config->getUsername(ConfigurationProvider::INVOICE_TYPE, "SE") );
- $this->assertEquals("sverigetest", $config->getPassword(ConfigurationProvider::INVOICE_TYPE, "SE") );
- $this->assertEquals("79021", $config->getClientNumber(ConfigurationProvider::INVOICE_TYPE, "SE"));
- $this->assertEquals(ConfigurationService::SWP_TEST_WS_URL, $config->getEndPoint(ConfigurationProvider::INVOICE_TYPE));
-
- $this->assertEquals("sverigetest", $config->getUsername(ConfigurationProvider::PAYMENTPLAN_TYPE, "SE") );
- $this->assertEquals("sverigetest", $config->getPassword(ConfigurationProvider::PAYMENTPLAN_TYPE, "SE") );
- $this->assertEquals("59999", $config->getClientNumber(ConfigurationProvider::PAYMENTPLAN_TYPE, "SE"));
- $this->assertEquals(ConfigurationService::SWP_TEST_WS_URL, $config->getEndPoint(ConfigurationProvider::PAYMENTPLAN_TYPE));
-
- $this->assertEquals("sverigetest", $config->getUsername(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "SE") );
- $this->assertEquals("sverigetest", $config->getPassword(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "SE") );
- $this->assertEquals("58702", $config->getClientNumber(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "SE"));
- $this->assertEquals(ConfigurationService::SWP_TEST_WS_URL, $config->getEndPoint(ConfigurationProvider::ACCOUNTCREDIT_TYPE));
-
- $this->assertEquals("1130", $config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, "SE"));
- $this->assertEquals($secret, $config->getSecret(ConfigurationProvider::HOSTED_TYPE, "SE"));
- $this->assertEquals(ConfigurationService::SWP_TEST_URL, $config->getEndPoint(ConfigurationProvider::HOSTED_TYPE));
- }
-
- public function test_getSveaSingleCountryConfig_respects_passed_parameters() {
-
- $config = ConfigurationService::getSingleCountryConfig(
- "NO",
- "norgetest2", "norgetest2", "33308",
- "norgetest2", "norgetest2", "32503",
- "sverigetest", "sverigetest", "58702",
- "1701", "foo",
- true // $prod = true
- );
-
- $this->assertInstanceOf('Svea\WebPay\Config\ConfigurationProvider', $config );
- $this->assertEquals("norgetest2", $config->getUsername(ConfigurationProvider::INVOICE_TYPE, "NO") );
- $this->assertEquals("norgetest2", $config->getPassword(ConfigurationProvider::INVOICE_TYPE, "NO") );
- $this->assertEquals("33308", $config->getClientNumber(ConfigurationProvider::INVOICE_TYPE, "NO"));
- $this->assertEquals(ConfigurationService::SWP_PROD_WS_URL, $config->getEndPoint(ConfigurationProvider::INVOICE_TYPE));
- $this->assertEquals("norgetest2", $config->getUsername(ConfigurationProvider::PAYMENTPLAN_TYPE, "NO") );
- $this->assertEquals("norgetest2", $config->getPassword(ConfigurationProvider::PAYMENTPLAN_TYPE, "NO") );
- $this->assertEquals("32503", $config->getClientNumber(ConfigurationProvider::PAYMENTPLAN_TYPE, "NO"));
- $this->assertEquals(ConfigurationService::SWP_PROD_WS_URL, $config->getEndPoint(ConfigurationProvider::PAYMENTPLAN_TYPE));
- $this->assertEquals("sverigetest", $config->getUsername(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "NO") );
- $this->assertEquals("sverigetest", $config->getPassword(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "NO") );
- $this->assertEquals("58702", $config->getClientNumber(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "NO"));
- $this->assertEquals(ConfigurationService::SWP_PROD_WS_URL, $config->getEndPoint(ConfigurationProvider::ACCOUNTCREDIT_TYPE));
- $this->assertEquals("1701", $config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, "NO") );
- $this->assertEquals("foo", $config->getSecret(ConfigurationProvider::HOSTED_TYPE, "NO"));
- $this->assertEquals(ConfigurationService::SWP_PROD_URL, $config->getEndPoint(ConfigurationProvider::HOSTED_TYPE));
- }
-
- /**
- * @expectedException Svea\WebPay\HostedService\Helper\InvalidCountryException
- */
- public function test_getSveaSingleCountryConfig_throws_InvalidCountryException_for_invalid_country() {
- $config = ConfigurationService::getSingleCountryConfig(
- null, // SE
- null, null, null, //invoice 79021
- null, null, null, //partpayment 59999
- null, null, null, //accountcredit 58702
- null, null, // merchantid 1130
- null // test
- );
-
- $config->getUsername(ConfigurationProvider::INVOICE_TYPE, "NO");
- }
+ function testSveaConfigNotFound(){
+ $config = ConfigurationService::getTestConfig();
+ $foo = WebPay::createOrder($config);
+
+ $this->assertEquals("sverigetest", $config->conf['credentials']['SE']['auth']['Invoice']['username']);
+ }
+
+ public function testOrderWithSEConfigFromFunction() {
+ $request = WebPay::createOrder(ConfigurationService::getTestConfig())
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("sverigetest", $request->request->Auth->Username);
+ $this->assertEquals("sverigetest", $request->request->Auth->Password);
+ $this->assertEquals(79021, $request->request->Auth->ClientNumber);
+ }
+
+ public function test_getSveaSingleCountryConfig_defaults() {
+ $secret = "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3";
+
+ $config = ConfigurationService::getSingleCountryConfig(
+ null, // SE
+ null, null, null, //invoice 79021
+ null, null, null, //partpayment 59999
+ null, null, null, //accountCredit 58702
+ null, null, // merchantid 1130
+ null // test
+ );
+
+ $this->assertInstanceOf('Svea\WebPay\Config\ConfigurationProvider', $config );
+
+ $this->assertEquals("sverigetest", $config->getUsername(ConfigurationProvider::INVOICE_TYPE, "SE") );
+ $this->assertEquals("sverigetest", $config->getPassword(ConfigurationProvider::INVOICE_TYPE, "SE") );
+ $this->assertEquals("79021", $config->getClientNumber(ConfigurationProvider::INVOICE_TYPE, "SE"));
+ $this->assertEquals(ConfigurationService::SWP_TEST_WS_URL, $config->getEndPoint(ConfigurationProvider::INVOICE_TYPE));
+
+ $this->assertEquals("sverigetest", $config->getUsername(ConfigurationProvider::PAYMENTPLAN_TYPE, "SE") );
+ $this->assertEquals("sverigetest", $config->getPassword(ConfigurationProvider::PAYMENTPLAN_TYPE, "SE") );
+ $this->assertEquals("59999", $config->getClientNumber(ConfigurationProvider::PAYMENTPLAN_TYPE, "SE"));
+ $this->assertEquals(ConfigurationService::SWP_TEST_WS_URL, $config->getEndPoint(ConfigurationProvider::PAYMENTPLAN_TYPE));
+
+ $this->assertEquals("sverigetest", $config->getUsername(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "SE") );
+ $this->assertEquals("sverigetest", $config->getPassword(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "SE") );
+ $this->assertEquals("58702", $config->getClientNumber(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "SE"));
+ $this->assertEquals(ConfigurationService::SWP_TEST_WS_URL, $config->getEndPoint(ConfigurationProvider::ACCOUNTCREDIT_TYPE));
+
+ $this->assertEquals("1130", $config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, "SE"));
+ $this->assertEquals($secret, $config->getSecret(ConfigurationProvider::HOSTED_TYPE, "SE"));
+ $this->assertEquals(ConfigurationService::SWP_TEST_URL, $config->getEndPoint(ConfigurationProvider::HOSTED_TYPE));
+ }
+
+ public function test_getSveaSingleCountryConfig_respects_passed_parameters() {
+
+ $config = ConfigurationService::getSingleCountryConfig(
+ "NO",
+ "norgetest2", "norgetest2", "33308",
+ "norgetest2", "norgetest2", "32503",
+ "sverigetest", "sverigetest", "58702",
+ "1701", "foo",
+ true // $prod = true
+ );
+
+ $this->assertInstanceOf('Svea\WebPay\Config\ConfigurationProvider', $config );
+ $this->assertEquals("norgetest2", $config->getUsername(ConfigurationProvider::INVOICE_TYPE, "NO") );
+ $this->assertEquals("norgetest2", $config->getPassword(ConfigurationProvider::INVOICE_TYPE, "NO") );
+ $this->assertEquals("33308", $config->getClientNumber(ConfigurationProvider::INVOICE_TYPE, "NO"));
+ $this->assertEquals(ConfigurationService::SWP_PROD_WS_URL, $config->getEndPoint(ConfigurationProvider::INVOICE_TYPE));
+ $this->assertEquals("norgetest2", $config->getUsername(ConfigurationProvider::PAYMENTPLAN_TYPE, "NO") );
+ $this->assertEquals("norgetest2", $config->getPassword(ConfigurationProvider::PAYMENTPLAN_TYPE, "NO") );
+ $this->assertEquals("32503", $config->getClientNumber(ConfigurationProvider::PAYMENTPLAN_TYPE, "NO"));
+ $this->assertEquals(ConfigurationService::SWP_PROD_WS_URL, $config->getEndPoint(ConfigurationProvider::PAYMENTPLAN_TYPE));
+ $this->assertEquals("sverigetest", $config->getUsername(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "NO") );
+ $this->assertEquals("sverigetest", $config->getPassword(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "NO") );
+ $this->assertEquals("58702", $config->getClientNumber(ConfigurationProvider::ACCOUNTCREDIT_TYPE, "NO"));
+ $this->assertEquals(ConfigurationService::SWP_PROD_WS_URL, $config->getEndPoint(ConfigurationProvider::ACCOUNTCREDIT_TYPE));
+ $this->assertEquals("1701", $config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, "NO") );
+ $this->assertEquals("foo", $config->getSecret(ConfigurationProvider::HOSTED_TYPE, "NO"));
+ $this->assertEquals(ConfigurationService::SWP_PROD_URL, $config->getEndPoint(ConfigurationProvider::HOSTED_TYPE));
+ }
+
+ /**
+ * @expectedException Svea\WebPay\HostedService\Helper\InvalidCountryException
+ */
+ public function test_getSveaSingleCountryConfig_throws_InvalidCountryException_for_invalid_country() {
+ $config = ConfigurationService::getSingleCountryConfig(
+ null, // SE
+ null, null, null, //invoice 79021
+ null, null, null, //partpayment 59999
+ null, null, null, //accountcredit 58702
+ null, null, // merchantid 1130
+ null // test
+ );
+
+ $config->getUsername(ConfigurationProvider::INVOICE_TYPE, "NO");
+ }
}
diff --git a/test/UnitTest/Helper/HelperTest.php b/test/UnitTest/Helper/HelperTest.php
index 5d3fe9ea..86548da5 100644
--- a/test/UnitTest/Helper/HelperTest.php
+++ b/test/UnitTest/Helper/HelperTest.php
@@ -1,768 +1,180 @@
-assertEquals(1, Helper::bround(0.51));
- $this->assertEquals(1, Helper::bround(1.49));
- $this->assertEquals(2, Helper::bround(1.5));
-
- $this->assertEquals(1, Helper::bround(1.49999999999999)); //seems to work with up to 14 decimals, then float creep pushes us over 1.5
- $this->assertEquals(2, Helper::bround(1.500000000000000000000000000000000000000000));
- $this->assertEquals(1, Helper::bround(1.0));
- $this->assertEquals(1, Helper::bround(1));
- //$this->assert( 1, bround("1") ); raise illegalArgumentException??
-
- $this->assertEquals(4, Helper::bround(4.5));
- $this->assertEquals(6, Helper::bround(5.5));
-
- $this->assertEquals(-1, Helper::bround(-1.1));
- $this->assertEquals(-2, Helper::bround(-1.5));
-
- $this->assertEquals(0, Helper::bround(-0.5));
- $this->assertEquals(0, Helper::bround(0));
- $this->assertEquals(0, Helper::bround(0.5));
-
- $this->assertEquals(262462, Helper::bround(262462.5));
-
- $this->assertEquals(0.479, Helper::bround(0.4785375, 3)); // i.e. greater than 0.4585, so round up
- $this->assertEquals(0.478, Helper::bround(0.4780000, 3)); // i.e. exactly 0.4585, so round to even
- }
-
- //--------------------------------------------------------------------------
-
- function test_splitMeanToTwoTaxRates_returnType()
- {
-
- $discountAmountIncVat = 100;
- $discountVatAmount = 18.6667;
- $discountName = 'Coupon(1112)';
- $discountDescription = '-100kr';
- $allowedTaxRates = array(25, 6);
-
- $discountRows = Helper::splitMeanToTwoTaxRates($discountAmountIncVat, $discountVatAmount, $discountName, $discountDescription, $allowedTaxRates);
-
- $this->assertTrue(is_array($discountRows));
- $this->assertTrue(is_a($discountRows[0], 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount'));
- }
-
- function test_splitMeanToTwoTaxRates_splitTwoRates()
- {
-
- $discountAmountExVat = 100;
- $discountVatAmount = 18.6667;
- $discountName = 'Coupon(1112)';
- $discountDescription = '-100kr';
- $allowedTaxRates = array(25, 6);
-
- $discountRows = Helper::splitMeanToTwoTaxRates($discountAmountExVat, $discountVatAmount, $discountName, $discountDescription, $allowedTaxRates);
-
- // 200 + 50 (25%)
- // 100 + 6 (6%)
- // -100 => 200/300 @25%, 100/300 @6%
- // => 2/3 * -100 + 2/3 * -25 discount @25%, 1/3 * -100 + 1/3 * -6 discount @6% => -100 @ 18,6667%
-
- $this->assertEquals(66.67, $discountRows[0]->amountExVat);
- $this->assertEquals(25, $discountRows[0]->vatPercent);
- $this->assertEquals('Coupon(1112)', $discountRows[0]->name);
- $this->assertEquals('-100kr (25%)', $discountRows[0]->description);
-
- $this->assertEquals(33.33, $discountRows[1]->amountExVat);
- $this->assertEquals(6, $discountRows[1]->vatPercent);
- $this->assertEquals('Coupon(1112)', $discountRows[1]->name);
- $this->assertEquals('-100kr (6%)', $discountRows[1]->description);
- }
-
- function test_splitMeanToTwoTaxRates_splitTwoRates_2()
- {
-
- $discountAmountExVat = 100;
- $discountVatAmount = 15.5;
- $discountName = 'Coupon(1112)';
- $discountDescription = '-100kr';
- $allowedTaxRates = array(25, 6);
-
- $discountRows = Helper::splitMeanToTwoTaxRates($discountAmountExVat, $discountVatAmount, $discountName, $discountDescription, $allowedTaxRates);
-
- // 1000 + 250 (25%)
- // 1000 + 60 (6%)
- // -100 => 1000/2000 @25%, 1000/2000 @6%
- // => 0,5 * -100 + 0,5 * -25 discount @25%, 0,5 * -100 + 0,5 * -6 discount @6% => -100 @ 15,5%
-
- $this->assertEquals(50.0, $discountRows[0]->amountExVat);
- $this->assertEquals(25, $discountRows[0]->vatPercent);
- $this->assertEquals('Coupon(1112)', $discountRows[0]->name);
- $this->assertEquals('-100kr (25%)', $discountRows[0]->description);
-
- $this->assertEquals(50.0, $discountRows[1]->amountExVat);
- $this->assertEquals(6, $discountRows[1]->vatPercent);
- $this->assertEquals('Coupon(1112)', $discountRows[1]->name);
- $this->assertEquals('-100kr (6%)', $discountRows[1]->description);
- }
-
- // TODO move below from Svea\WebPay\Test\UnitTest\WebService\Helper\WebServiceRowFormatterTest (modified to use Helper::splitMeanToTwoTaxRates) to integrationtest for Helper
- //public function testFormatFixedDiscountRows_amountExVatAndVatPercent_WithDifferentVatRatesPresent2() {
-
- //--------------------------------------------------------------------------
-
- function test_getAllTaxRatesInOrder_returnType()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- );
-
- $taxRates = Helper::getTaxRatesInOrder($order);
-
- $this->assertTrue(is_array($taxRates));
- }
-
- function test_getAllTaxRatesInOrder_getOneRate()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- );
-
- $taxRates = Helper::getTaxRatesInOrder($order);
-
- $this->assertEquals(1, sizeof($taxRates));
- $this->assertEquals(25, $taxRates[0]);
- }
-
- function test_getAllTaxRatesInOrder_getTwoRates()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setAmountIncVat(125.00)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- );
-
- $taxRates = Helper::getTaxRatesInOrder($order);
-
- $this->assertEquals(2, sizeof($taxRates));
- $this->assertEquals(25, $taxRates[0]);
- $this->assertEquals(6, $taxRates[1]);
- }
-
- function test_getSveaLibraryProperties()
- {
- $libraryPropertiesArray = Helper::getSveaLibraryProperties();
- $this->assertTrue(array_key_exists("library_name", $libraryPropertiesArray));
- $this->assertTrue(array_key_exists("library_version", $libraryPropertiesArray));
- }
-
- /// new implementation of splitMeanAcrossTaxRates helper method
- // 1u. mean ex to single tax rate: 10e @20% -> 12i @25%
- // 2u. mean inc to single tax rate: 12i @20% -> 12i @25%
- // 3i. mean inc to single tax rate: 12i @20% -> 12i @25%, priceincvat = true => correct order total at Svea
- // 4i. mean inc to single tax rate: 12i @20% -> 12i @25%, priceincvat = false -> resent as 9.6e @25%, priceincvat = false => correct order total at Svea
- // 5u. mean ex to two tax rates: 8.62e @16% -> 5.67i @25%; 4.33i @6%
- // 6u. mean inc to two tax rate: 10i @16 % -> 5.67i @25%; 4.33i @6%
- // 7i. mean inc to two tax rates: 8.62e @16% -> 5.67i @25%; 4.33i @6%, priceincvat = true => correct order total at Svea
- // 8i. mean inc to two tax rates: 10i @16 % -> 5.67i @25%; 4.33i @6%, priceincvat = false -> resent w/priceincvat = false => correct order total at Svea
- // 9u. mean ex to single tax rate with mean vat rate zero: resend as single row
- // 10u. mean ex to two tax rates with mean vat rate zero: resend as single row
-
- // 1u. mean ex to single tax rate: 10e @20% -> 12i @25%
- function test_splitMeanAcrossTaxRates_1()
- {
- $discountAmount = 10.0;
- $discountGivenExVat = true;
- $discountMeanVatPercent = 20.0;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
- $this->assertEquals(12, $discountRows[0]->amountIncVat);
- $this->assertEquals(25, $discountRows[0]->vatPercent);
- $this->assertEquals('Name', $discountRows[0]->name);
- $this->assertEquals('Description', $discountRows[0]->description);
- $this->assertEquals(null, $discountRows[0]->amountExVat);
-
- $this->assertEquals(1, count($discountRows));
- }
-
- // 2u. mean inc to single tax rate: 12i @20% -> 12i @25%
- function test_splitMeanAcrossTaxRates_2()
- {
- $discountAmount = 12.0;
- $discountGivenExVat = false;
- $discountMeanVatPercent = 20.0;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
- $this->assertEquals(12, $discountRows[0]->amountIncVat);
- $this->assertEquals(25, $discountRows[0]->vatPercent);
- $this->assertEquals(null, $discountRows[0]->amountExVat);
- }
-
- // 5u. mean ex to two tax rates: 8.62e @16% -> 5.67i @25%; 4.33i @6%
- function test_splitMeanAcrossTaxRates_5()
- {
- $discountAmount = 8.62;
- $discountGivenExVat = true;
- $discountMeanVatPercent = 16.0;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25, 6);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
- $this->assertEquals(5.67, $discountRows[0]->amountIncVat);
- $this->assertEquals(25, $discountRows[0]->vatPercent);
- $this->assertEquals('Name', $discountRows[0]->name);
- $this->assertEquals('Description (25%)', $discountRows[0]->description);
- $this->assertEquals(null, $discountRows[0]->amountExVat);
-
- $this->assertEquals(4.33, $discountRows[1]->amountIncVat);
- $this->assertEquals(6, $discountRows[1]->vatPercent);
- $this->assertEquals('Name', $discountRows[1]->name);
- $this->assertEquals('Description (6%)', $discountRows[1]->description);
- $this->assertEquals(null, $discountRows[1]->amountExVat);
-
- $this->assertEquals(2, count($discountRows));
- }
-
- // 6u. mean inc to two tax rate: 10i @16 % -> 5.67i @25%; 4.33i @6%
- function test_splitMeanAcrossTaxRates_6()
- {
- $discountAmount = 10.0;
- $discountGivenExVat = false;
- $discountMeanVatPercent = 16.0;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25, 6);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
- $this->assertEquals(5.67, $discountRows[0]->amountIncVat);
- $this->assertEquals(25, $discountRows[0]->vatPercent);
- $this->assertEquals('Name', $discountRows[0]->name);
- $this->assertEquals('Description (25%)', $discountRows[0]->description);
- $this->assertEquals(null, $discountRows[0]->amountExVat);
-
- $this->assertEquals(4.33, $discountRows[1]->amountIncVat);
- $this->assertEquals(6, $discountRows[1]->vatPercent);
- $this->assertEquals('Name', $discountRows[1]->name);
- $this->assertEquals('Description (6%)', $discountRows[1]->description);
- $this->assertEquals(null, $discountRows[1]->amountExVat);
-
- $this->assertEquals(2, count($discountRows));
- }
-
- // 9u. mean ex to single tax rate with mean vat rate zero (exvat): resend as single row w/ zero vat
- function test_splitMeanAcrossTaxRates_9()
- {
- $discountAmount = 10.0;
- $discountGivenExVat = true;
- $discountMeanVatPercent = 0.0;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
- $this->assertEquals(10.0, $discountRows[0]->amountIncVat);
- $this->assertEquals(0, $discountRows[0]->vatPercent);
- $this->assertEquals('Name', $discountRows[0]->name);
- $this->assertEquals('Description', $discountRows[0]->description);
- $this->assertEquals(null, $discountRows[0]->amountExVat);
-
- $this->assertEquals(1, count($discountRows));
- }
-
- // 10u. mean ex to two tax rates with mean vat rate less than zero (incvat): resend as single row w/ zero vat
- function test_splitMeanAcrossTaxRates_10()
- {
- $discountAmount = 10.0;
- $discountGivenExVat = false;
- $discountMeanVatPercent = -1;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25, 6);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
- $this->assertEquals(10.0, $discountRows[0]->amountIncVat);
- $this->assertEquals(0, $discountRows[0]->vatPercent);
- $this->assertEquals('Name', $discountRows[0]->name);
- $this->assertEquals('Description', $discountRows[0]->description);
- $this->assertEquals(null, $discountRows[0]->amountExVat);
-
- $this->assertEquals(1, count($discountRows));
- }
-
-// function test_splitMeanToTwoTaxRates_splitTwoRates() {
-//
-// $discountAmountExVat = 100;
-// $discountVatAmount = 18.6667;
-// $discountName = 'Coupon(1112)';
-// $discountDescription = '-100kr';
-// $allowedTaxRates = array( 25,6 );
-//
-// $discountRows = Helper::splitMeanToTwoTaxRates( $discountAmountExVat,$discountVatAmount,$discountName,$discountDescription,$allowedTaxRates );
-//
-// // 200 + 50 (25%)
-// // 100 + 6 (6%)
-// // -100 => 200/300 @25%, 100/300 @6%
-// // => 2/3 * -100 + 2/3 * -25 discount @25%, 1/3 * -100 + 1/3 * -6 discount @6% => -100 @ 18,6667%
-//
-// $this->assertEquals( 66.67,$discountRows[0]->amountExVat );
-// $this->assertEquals( 25, $discountRows[0]->vatPercent );
-// $this->assertEquals( 'Coupon(1112)', $discountRows[0]->name );
-// $this->assertEquals( '-100kr (25%)', $discountRows[0]->description );
-//
-// $this->assertEquals( 33.33,$discountRows[1]->amountExVat );
-// $this->assertEquals( 6, $discountRows[1]->vatPercent );
-// $this->assertEquals( 'Coupon(1112)', $discountRows[1]->name );
-// $this->assertEquals( '-100kr (6%)', $discountRows[1]->description );
-// }
-
-
- // 11A. mean inc to two tax rates, 50+6/3 = 18,67% => 19%
- /**
- * @doesNotPerformAssertions
- */
- function test_splitMeanAcrossTaxRates_11a()
- {
- $discountAmount = 119.0;
- $discountGivenExVat = false;
- $discountMeanVatPercent = 19;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25, 6);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
-// print_r( $discountRows );
-
- }
-
- // 11B. mean inc to two tax rates, 50+6/3 = 18,67%
- /**
- * @doesNotPerformAssertions
- */
- function test_splitMeanAcrossTaxRates_11b()
- {
- $discountAmount = 118.67;
- $discountGivenExVat = false;
- $discountMeanVatPercent = 18.67;
- $discountName = 'Name';
- $discountDescription = 'Description';
- $allowedTaxRates = array(25, 6);
-
- $discountRows = Helper::splitMeanAcrossTaxRates(
- $discountAmount, $discountMeanVatPercent, $discountName, $discountDescription, $allowedTaxRates, $discountGivenExVat
- );
-
-// print_r( $discountRows );
-
- }
-
- function test_validCardPayCurrency()
- {
- $var = Helper::isCardPayCurrency("SEK");
- $this->assertEquals(true, $var);
- }
-
- function test_invalidCardPayCurrency()
- {
- $var = Helper::isCardPayCurrency("XXX");
- $this->assertEquals(false, $var);
- }
-
- function test_validPeppolId()
- {
- $var = Helper::isValidPeppolId("1234:abc12");
- $this->assertEquals(true, $var);
- }
-
- function test_invalidPeppolId()
- {
- $var = Helper::isValidPeppolId("abcd:1234"); // First 4 characters must be numeric
- $var1 = Helper::isValidPeppolId("1234abc12"); // Fifth character must be ':'.
- $var2 = Helper::isValidPeppolId("1234:ab.c12"); // Rest of the characters must be alphanumeric
- $var3 = Helper::isValidPeppolId("1234:abc12abc12abc12abc12abc12abc12abc12abc12abc12abc12abc12abc12abc12abc12abc12abc12abc12"); // String cannot be longer 55 characters
- $var4 = Helper::isValidPeppolId("1234:"); // String must be longer than 5 characters
-
- $this->assertEquals(false, $var);
- $this->assertEquals(false, $var1);
- $this->assertEquals(false, $var2);
- $this->assertEquals(false, $var3);
- $this->assertEquals(false, $var4);
- }
-
- function test_calculateCorrectPricePerMonth()
- {
- $price = 10000;
-
- $response = (object) array(
- "GetPaymentPlanParamsEuResult" => (object)array (
- "Accepted" => true,
- "ResultCode" => 0,
- "CampaignCodes" => (object)array(
- "CampaignCodeInfo" => array(
- 0 =>
- (object)array(
- "CampaignCode" => 213060,
- "Description" => "Dela upp betalningen på 60 månader",
- "PaymentPlanType" => "Standard",
- "ContractLengthInMonths" => 60,
- "MonthlyAnnuityFactor" => '0.02555',
- "InitialFee" => '100',
- "NotificationFee" => '29',
- "InterestRatePercent" => '16.75',
- "NumberOfInterestFreeMonths" => 3,
- "NumberOfPaymentFreeMonths" => 3,
- "FromAmount" => '1000',
- "ToAmount" => '50000',
- ),
- 1 =>
- (object)array(
- 'CampaignCode' => 222065,
- 'Description' => 'Vårkampanj',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 2 =>
- (object)array(
- 'CampaignCode' => 222066,
- 'Description' => 'Sommarkampanj',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 3 =>
- (object)array(
- 'CampaignCode' => 223060,
- 'Description' => 'Köp nu betala om 3 månader (räntefritt)',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '29',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '1000',
- 'ToAmount' => '50000',
- ),
- 4 =>
- (object)array(
- 'CampaignCode' => 223065,
- 'Description' => 'Black Friday - Cyber Monday',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 5 =>
- (object)array(
- 'CampaignCode' => 223066,
- 'Description' => 'Julkampanj',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 6 =>
- (object)array(
- 'CampaignCode' => 310012,
- 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
- 'PaymentPlanType' => 'InterestFree',
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => '0.08333',
- 'InitialFee' => '295',
- 'NotificationFee' => '35',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 12,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => '1000',
- 'ToAmount' => '30000',
- ),
- 7 =>
- (object)array(
- 'CampaignCode' => 410012,
- 'Description' => 'Dela upp betalningen på 12 månader',
- 'PaymentPlanType' => 'Standard',
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => '0.09259',
- 'InitialFee' => '0',
- 'NotificationFee' => '29',
- 'InterestRatePercent' => '19.9',
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => '100',
- 'ToAmount' => '30000',
- ),
- 8 =>
- (object)array(
- 'CampaignCode' => 410024,
- 'Description' => 'Dela upp betalningen på 24 månader',
- 'PaymentPlanType' => 'Standard',
- 'ContractLengthInMonths' => 24,
- 'MonthlyAnnuityFactor' => '0.04684',
- 'InitialFee' => '350',
- 'NotificationFee' => '35',
- 'InterestRatePercent' => '11.5',
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => '1000',
- 'ToAmount' => '150000',
- )
- )
- )
- )
- );
-
- $params = new PaymentPlanParamsResponse($response, false);
-
- $arr = Helper::paymentPlanPricePerMonth($price, $params, true);
-
- $this->assertEquals(287, $arr->values[0]['pricePerMonth']);
- $this->assertEquals(10000.0, $arr->values[1]['pricePerMonth']);
- $this->assertEquals(10000.0, $arr->values[2]['pricePerMonth']);
- $this->assertEquals(10029.0, $arr->values[3]['pricePerMonth']);
- $this->assertEquals(10000.0, $arr->values[4]['pricePerMonth']);
- $this->assertEquals(10000.0, $arr->values[5]['pricePerMonth']);
- $this->assertEquals(894, $arr->values[6]['pricePerMonth']);
- $this->assertEquals(955, $arr->values[7]['pricePerMonth']);
- $this->assertEquals(519, $arr->values[8]['pricePerMonth']);
- }
-
- function test_calculateCorrectPricePerMonthWithDecimals()
- {
- $price = 10000;
-
- $response = (object) array(
- "GetPaymentPlanParamsEuResult" => (object)array (
- "Accepted" => true,
- "ResultCode" => 0,
- "CampaignCodes" => (object)array(
- "CampaignCodeInfo" => array(
- 0 =>
- (object)array(
- "CampaignCode" => 213060,
- "Description" => "Dela upp betalningen på 60 månader",
- "PaymentPlanType" => "Standard",
- "ContractLengthInMonths" => 60,
- "MonthlyAnnuityFactor" => '0.02555',
- "InitialFee" => '100',
- "NotificationFee" => '29',
- "InterestRatePercent" => '16.75',
- "NumberOfInterestFreeMonths" => 3,
- "NumberOfPaymentFreeMonths" => 3,
- "FromAmount" => '1000',
- "ToAmount" => '50000',
- ),
- 1 =>
- (object)array(
- 'CampaignCode' => 222065,
- 'Description' => 'Vårkampanj',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 2 =>
- (object)array(
- 'CampaignCode' => 222066,
- 'Description' => 'Sommarkampanj',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 3 =>
- (object)array(
- 'CampaignCode' => 223060,
- 'Description' => 'Köp nu betala om 3 månader (räntefritt)',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '29',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '1000',
- 'ToAmount' => '50000',
- ),
- 4 =>
- (object)array(
- 'CampaignCode' => 223065,
- 'Description' => 'Black Friday - Cyber Monday',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 5 =>
- (object)array(
- 'CampaignCode' => 223066,
- 'Description' => 'Julkampanj',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 6 =>
- (object)array(
- 'CampaignCode' => 310012,
- 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
- 'PaymentPlanType' => 'InterestFree',
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => '0.08333',
- 'InitialFee' => '295',
- 'NotificationFee' => '35',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 12,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => '1000',
- 'ToAmount' => '30000',
- ),
- 7 =>
- (object)array(
- 'CampaignCode' => 410012,
- 'Description' => 'Dela upp betalningen på 12 månader',
- 'PaymentPlanType' => 'Standard',
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => '0.09259',
- 'InitialFee' => '0',
- 'NotificationFee' => '29',
- 'InterestRatePercent' => '19.9',
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => '100',
- 'ToAmount' => '30000',
- ),
- 8 =>
- (object)array(
- 'CampaignCode' => 410024,
- 'Description' => 'Dela upp betalningen på 24 månader',
- 'PaymentPlanType' => 'Standard',
- 'ContractLengthInMonths' => 24,
- 'MonthlyAnnuityFactor' => '0.04684',
- 'InitialFee' => '350',
- 'NotificationFee' => '35',
- 'InterestRatePercent' => '11.5',
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => '1000',
- 'ToAmount' => '150000',
- )
- )
- )
- )
- );
-
- $params = new PaymentPlanParamsResponse($response, false);
-
- $arr = Helper::paymentPlanPricePerMonth($price, $params, true, 2);
-
- $this->assertEquals(286.75, $arr->values[0]['pricePerMonth']);
- $this->assertEquals(10000.0, $arr->values[1]['pricePerMonth']);
- $this->assertEquals(10000.0, $arr->values[2]['pricePerMonth']);
- $this->assertEquals(10029.0, $arr->values[3]['pricePerMonth']);
- $this->assertEquals(10000.0, $arr->values[4]['pricePerMonth']);
- $this->assertEquals(10000.0, $arr->values[5]['pricePerMonth']);
- $this->assertEquals(893.58, $arr->values[6]['pricePerMonth']);
- $this->assertEquals(955, $arr->values[7]['pricePerMonth']);
- $this->assertEquals(518.58, $arr->values[8]['pricePerMonth']);
- }
-}
+assertEquals(1, Helper::bround(0.51));
+ $this->assertEquals(1, Helper::bround(1.49));
+ $this->assertEquals(2, Helper::bround(1.5));
+
+ $this->assertEquals(1, Helper::bround(1.49999999999999)); //seems to work with up to 14 decimals, then float creep pushes us over 1.5
+ $this->assertEquals(2, Helper::bround(1.500000000000000000000000000000000000000000));
+ $this->assertEquals(1, Helper::bround(1.0));
+ $this->assertEquals(1, Helper::bround(1));
+ //$this->assert( 1, bround("1") ); raise illegalArgumentException??
+
+ $this->assertEquals(4, Helper::bround(4.5));
+ $this->assertEquals(6, Helper::bround(5.5));
+
+ $this->assertEquals(-1, Helper::bround(-1.1));
+ $this->assertEquals(-2, Helper::bround(-1.5));
+
+ $this->assertEquals(0, Helper::bround(-0.5));
+ $this->assertEquals(0, Helper::bround(0));
+ $this->assertEquals(0, Helper::bround(0.5));
+
+ $this->assertEquals(262462, Helper::bround(262462.5));
+
+ $this->assertEquals(0.479, Helper::bround(0.4785375, 3)); // i.e. greater than 0.4585, so round up
+ $this->assertEquals(0.478, Helper::bround(0.4780000, 3)); // i.e. exactly 0.4585, so round to even
+ }
+
+ //--------------------------------------------------------------------------
+
+ function test_splitMeanToTwoTaxRates_returnType()
+ {
+
+ $discountAmountIncVat = 100;
+ $discountVatAmount = 18.6667;
+ $discountName = 'Coupon(1112)';
+ $discountDescription = '-100kr';
+ $allowedTaxRates = [25, 6];
+
+ $discountRows = Helper::splitMeanToTwoTaxRates($discountAmountIncVat, $discountVatAmount, $discountName, $discountDescription, $allowedTaxRates);
+
+ $this->assertTrue(is_array($discountRows));
+ $this->assertTrue(is_a($discountRows[0], 'Svea\WebPay\BuildOrder\RowBuilders\FixedDiscount'));
+ }
+
+ function test_splitMeanToTwoTaxRates_splitTwoRates()
+ {
+
+ $discountAmountExVat = 100;
+ $discountVatAmount = 18.6667;
+ $discountName = 'Coupon(1112)';
+ $discountDescription = '-100kr';
+ $allowedTaxRates = [25, 6];
+
+ $discountRows = Helper::splitMeanToTwoTaxRates($discountAmountExVat, $discountVatAmount, $discountName, $discountDescription, $allowedTaxRates);
+
+ // 200 + 50 (25%)
+ // 100 + 6 (6%)
+ // -100 => 200/300 @25%, 100/300 @6%
+ // => 2/3 * -100 + 2/3 * -25 discount @25%, 1/3 * -100 + 1/3 * -6 discount @6% => -100 @ 18,6667%
+
+ $this->assertEquals(66.67, $discountRows[0]->amountExVat);
+ $this->assertEquals(25, $discountRows[0]->vatPercent);
+ $this->assertEquals('Coupon(1112)', $discountRows[0]->name);
+ $this->assertEquals('-100kr (25%)', $discountRows[0]->description);
+
+ $this->assertEquals(33.33, $discountRows[1]->amountExVat);
+ $this->assertEquals(6, $discountRows[1]->vatPercent);
+ $this->assertEquals('Coupon(1112)', $discountRows[1]->name);
+ $this->assertEquals('-100kr (6%)', $discountRows[1]->description);
+ }
+
+ function test_splitMeanToTwoTaxRates_splitTwoRates_2()
+ {
+
+ $discountAmountExVat = 100;
+ $discountVatAmount = 15.5;
+ $discountName = 'Coupon(1112)';
+ $discountDescription = '-100kr';
+ $allowedTaxRates = [25, 6];
+
+ $discountRows = Helper::splitMeanToTwoTaxRates($discountAmountExVat, $discountVatAmount, $discountName, $discountDescription, $allowedTaxRates);
+
+ // 1000 + 250 (25%)
+ // 1000 + 60 (6%)
+ // -100 => 1000/2000 @25%, 1000/2000 @6%
+ // => 0,5 * -100 + 0,5 * -25 discount @25%, 0,5 * -100 + 0,5 * -6 discount @6% => -100 @ 15,5%
+
+ $this->assertEquals(50.0, $discountRows[0]->amountExVat);
+ $this->assertEquals(25, $discountRows[0]->vatPercent);
+ $this->assertEquals('Coupon(1112)', $discountRows[0]->name);
+ $this->assertEquals('-100kr (25%)', $discountRows[0]->description);
+
+ $this->assertEquals(50.0, $discountRows[1]->amountExVat);
+ $this->assertEquals(6, $discountRows[1]->vatPercent);
+ $this->assertEquals('Coupon(1112)', $discountRows[1]->name);
+ $this->assertEquals('-100kr (6%)', $discountRows[1]->description);
+ }
+
+ // TODO move below from Svea\WebPay\Test\UnitTest\WebService\Helper\WebServiceRowFormatterTest (modified to use Helper::splitMeanToTwoTaxRates) to integrationtest for Helper
+ //public function testFormatFixedDiscountRows_amountExVatAndVatPercent_WithDifferentVatRatesPresent2() {
+
+ //--------------------------------------------------------------------------
+
+ function test_getAllTaxRatesInOrder_returnType()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ );
+
+ $taxRates = Helper::getTaxRatesInOrder($order);
+
+ $this->assertTrue(is_array($taxRates));
+ }
+
+ function test_getAllTaxRatesInOrder_getOneRate()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ );
+
+ $taxRates = Helper::getTaxRatesInOrder($order);
+
+ $this->assertEquals(1, sizeof($taxRates));
+ $this->assertEquals(25, $taxRates[0]);
+ }
+
+ function test_getAllTaxRatesInOrder_getTwoRates()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setAmountIncVat(125.00)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ );
+
+ $taxRates = Helper::getTaxRatesInOrder($order);
+
+ $this->assertEquals(2, sizeof($taxRates));
+ $this->assertEquals(25, $taxRates[0]);
+ $this->assertEquals(6, $taxRates[1]);
+ }
+
+ function test_getSveaLibraryProperties()
+ {
+ $libraryPropertiesArray = Helper::getSveaLibraryProperties();
+ $this->assertTrue(array_key_exists("library_name", $libraryPropertiesArray));
+ $this->assertTrue(array_key_exists("library_version", $libraryPropertiesArray));
+ }
+
+ /// new implementation of splitMeanAcrossTaxRates helper method
+ // 1u. mean ex to single tax rate: 10e @20% -> 12i @25%
\ No newline at end of file
diff --git a/test/UnitTest/Helper/PaymentPlanHelper/PaymentPlanCalculatorTest.php b/test/UnitTest/Helper/PaymentPlanHelper/PaymentPlanCalculatorTest.php
index 4d2a0d5f..b85eb093 100644
--- a/test/UnitTest/Helper/PaymentPlanHelper/PaymentPlanCalculatorTest.php
+++ b/test/UnitTest/Helper/PaymentPlanHelper/PaymentPlanCalculatorTest.php
@@ -8,1205 +8,1205 @@
class PaymentPlanCalculatorTest extends TestCase
{
- protected $price;
-
- protected $paymentPlanParams;
-
- protected function setUp()
- {
- $this->price = 11200;
- }
-
- protected function getInterestAndAmortizationFreeCampaign()
- {
- $response = (object) array(
- "GetPaymentPlanParamsEuResult" => (object)array (
- "Accepted" => true,
- "ResultCode" => 0,
- "CampaignCodes" => (object)array(
- "CampaignCodeInfo" => array(
- 0 =>
- (object)array(
- 'CampaignCode' => 223060,
- 'Description' => 'Köp nu betala om 3 månader (räntefritt)',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '29',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '1000',
- 'ToAmount' => '50000',
- )
- )
- )
- )
- );
-
- $params = new PaymentPlanParamsResponse($response, false);
-
- return $params->campaignCodes;
- }
-
- protected function getInterestAndAmortizationFreeCampaignAsArray()
- {
- return array (
- 'CampaignCode' => 223060,
- 'Description' => 'Köp nu betala om 3 månader (räntefritt)',
- 'PaymentPlanType' => 2,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 1.0,
- 'InitialFee' => 0.0,
- 'NotificationFee' => 29.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 1000.0,
- 'ToAmount' => 50000.0,
- );
- }
-
- protected function getInterestFreeCampaign()
- {
- $response = (object) array(
- "GetPaymentPlanParamsEuResult" => (object)array (
- "Accepted" => true,
- "ResultCode" => 0,
- "CampaignCodes" => (object)array(
- "CampaignCodeInfo" => array(
- 0 =>
- (object)array(
- 'CampaignCode' => 310012,
- 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
- 'PaymentPlanType' => 'InterestFree',
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => '0.08333',
- 'InitialFee' => '295',
- 'NotificationFee' => '35',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 12,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => '1000',
- 'ToAmount' => '30000',
- )
- )
- )
- )
- );
-
- $params = new PaymentPlanParamsResponse($response, false);
-
- return $params->campaignCodes;
- }
-
- protected function getFinnishInterestAndAmortizationFreeCampaignAsArray()
- {
- return array (
- 'CampaignCode' => 220002,
- 'Description' => 'OSTA NYT, MAKSA 3 KK PÄÄSTÄ',
- 'PaymentPlanType' => 2,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 1,
- 'InitialFee' => 0,
- 'NotificationFee' => 3.95,
- 'InterestRatePercent' => 0,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 50.0,
- 'ToAmount' => 5000.0,
- );
- }
-
- protected function getInterestFreeCampaignAsArray()
- {
- return array (
- 'CampaignCode' => 310012,
- 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
- 'PaymentPlanType' => 1,
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => 0.08333,
- 'InitialFee' => 295.0,
- 'NotificationFee' => 35.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 12,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 1000.0,
- 'ToAmount' => 30000.0,
- );
- }
-
- protected function getFinnishInterestFreeCampaignAsArray()
- {
- return array (
- 'CampaignCode' => 220001,
- 'Description' => 'ERÄMAKSU 3 KK KOROTON',
- 'PaymentPlanType' => 1,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 0.33333,
- 'InitialFee' => 0.0,
- 'NotificationFee' => 0.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 50.0,
- 'ToAmount' => 1000.0,
- );
- }
-
- protected function getStandardCampaign()
- {
- $response = (object) array(
- "GetPaymentPlanParamsEuResult" => (object)array (
- "Accepted" => true,
- "ResultCode" => 0,
- "CampaignCodes" => (object)array(
- "CampaignCodeInfo" => array(
- 0 =>
- (object)array(
- "CampaignCode" => 213060,
- "Description" => "Dela upp betalningen på 60 månader",
- "PaymentPlanType" => "Standard",
- "ContractLengthInMonths" => 60,
- "MonthlyAnnuityFactor" => '0.02555',
- "InitialFee" => '100',
- "NotificationFee" => '29',
- "InterestRatePercent" => '16.75',
- "NumberOfInterestFreeMonths" => 3,
- "NumberOfPaymentFreeMonths" => 3,
- "FromAmount" => '1000',
- "ToAmount" => '50000',
- )
- )
- )
- )
- );
-
- $params = new PaymentPlanParamsResponse($response, false);
-
- return $params->campaignCodes;
- }
-
- protected function getStandardCampaignAsArray()
- {
- return array (
- 'CampaignCode' => 213060,
- 'Description' => 'Dela upp betalningen på 60 månader',
- 'PaymentPlanType' => 0,
- 'ContractLengthInMonths' => 60,
- 'MonthlyAnnuityFactor' => 0.02555,
- 'InitialFee' => 100.0,
- 'NotificationFee' => 29.0,
- 'InterestRatePercent' => 16.75,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 1000.0,
- 'ToAmount' => 50000.0,
- );
- }
-
- protected function getFinnishStandardCampaignAsArray()
- {
- return array (
- 'CampaignCode' => 220012,
- 'Description' => 'ERÄMAKSU 12 KK 9.8%',
- 'PaymentPlanType' => 0,
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => 0.08782,
- 'InitialFee' => 29.9,
- 'NotificationFee' => 8.9,
- 'InterestRatePercent' => 9.8,
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 50,
- 'ToAmount' => 1000,
- );
- }
-
- protected function getMixedCampaigns()
- {
- $response = (object) array(
- "GetPaymentPlanParamsEuResult" => (object)array (
- "Accepted" => true,
- "ResultCode" => 0,
- "CampaignCodes" => (object)array(
- "CampaignCodeInfo" => array(
- 0 =>
- (object)array(
- "CampaignCode" => 213060,
- "Description" => "Dela upp betalningen på 60 månader",
- "PaymentPlanType" => "Standard",
- "ContractLengthInMonths" => 60,
- "MonthlyAnnuityFactor" => '0.02555',
- "InitialFee" => '100',
- "NotificationFee" => '29',
- "InterestRatePercent" => '16.75',
- "NumberOfInterestFreeMonths" => 3,
- "NumberOfPaymentFreeMonths" => 3,
- "FromAmount" => '1000',
- "ToAmount" => '50000',
- ),
- 1 =>
- (object)array(
- 'CampaignCode' => 222065,
- 'Description' => 'Vårkampanj',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 2 =>
- (object)array(
- 'CampaignCode' => 222066,
- 'Description' => 'Sommarkampanj',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 3 =>
- (object)array(
- 'CampaignCode' => 223060,
- 'Description' => 'Köp nu betala om 3 månader (räntefritt)',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '29',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '1000',
- 'ToAmount' => '50000',
- ),
- 4 =>
- (object)array(
- 'CampaignCode' => 223065,
- 'Description' => 'Black Friday - Cyber Monday',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 5 =>
- (object)array(
- 'CampaignCode' => 223066,
- 'Description' => 'Julkampanj',
- 'PaymentPlanType' => 'InterestAndAmortizationFree',
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => '1',
- 'InitialFee' => '0',
- 'NotificationFee' => '0',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => '120',
- 'ToAmount' => '30000',
- ),
- 6 =>
- (object)array(
- 'CampaignCode' => 310012,
- 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
- 'PaymentPlanType' => 'InterestFree',
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => '0.08333',
- 'InitialFee' => '295',
- 'NotificationFee' => '35',
- 'InterestRatePercent' => '0',
- 'NumberOfInterestFreeMonths' => 12,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => '1000',
- 'ToAmount' => '30000',
- ),
- 7 =>
- (object)array(
- 'CampaignCode' => 410012,
- 'Description' => 'Dela upp betalningen på 12 månader',
- 'PaymentPlanType' => 'Standard',
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => '0.09259',
- 'InitialFee' => '0',
- 'NotificationFee' => '29',
- 'InterestRatePercent' => '19.9',
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => '100',
- 'ToAmount' => '30000',
- ),
- 8 =>
- (object)array(
- 'CampaignCode' => 410024,
- 'Description' => 'Dela upp betalningen på 24 månader',
- 'PaymentPlanType' => 'Standard',
- 'ContractLengthInMonths' => 24,
- 'MonthlyAnnuityFactor' => '0.04684',
- 'InitialFee' => '350',
- 'NotificationFee' => '35',
- 'InterestRatePercent' => '11.5',
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => '1000',
- 'ToAmount' => '150000',
- )
- )
- )
- )
- );
-
- $params = new PaymentPlanParamsResponse($response, false);
-
- return $params->campaignCodes;
- }
-
- protected function getMixedCampaignsAsArray()
- {
- return array (
- 0 =>
- array (
- 'CampaignCode' => 213060,
- 'Description' => 'Dela upp betalningen på 60 månader',
- 'PaymentPlanType' => 0,
- 'ContractLengthInMonths' => 60,
- 'MonthlyAnnuityFactor' => 0.02555,
- 'InitialFee' => 100.0,
- 'NotificationFee' => 29.0,
- 'InterestRatePercent' => 16.75,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 1000.0,
- 'ToAmount' => 50000.0,
- ),
- 1 =>
- array (
- 'CampaignCode' => 222065,
- 'Description' => 'Vårkampanj',
- 'PaymentPlanType' => 2,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 1.0,
- 'InitialFee' => 0.0,
- 'NotificationFee' => 0.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 120.0,
- 'ToAmount' => 30000.0,
- ),
- 2 =>
- array (
- 'CampaignCode' => 222066,
- 'Description' => 'Sommarkampanj',
- 'PaymentPlanType' => 2,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 1.0,
- 'InitialFee' => 0.0,
- 'NotificationFee' => 0.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 120.0,
- 'ToAmount' => 30000.0,
- ),
- 3 =>
- array (
- 'CampaignCode' => 223060,
- 'Description' => 'Köp nu betala om 3 månader (räntefritt)',
- 'PaymentPlanType' => 2,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 1.0,
- 'InitialFee' => 0.0,
- 'NotificationFee' => 29.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 1000.0,
- 'ToAmount' => 50000.0,
- ),
- 4 =>
- array (
- 'CampaignCode' => 223065,
- 'Description' => 'Black Friday - Cyber Monday',
- 'PaymentPlanType' => 2,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 1.0,
- 'InitialFee' => 0.0,
- 'NotificationFee' => 0.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 120.0,
- 'ToAmount' => 30000.0,
- ),
- 5 =>
- array (
- 'CampaignCode' => 223066,
- 'Description' => 'Julkampanj',
- 'PaymentPlanType' => 2,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 1.0,
- 'InitialFee' => 0.0,
- 'NotificationFee' => 0.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 120.0,
- 'ToAmount' => 30000.0,
- ),
- 6 =>
- array (
- 'CampaignCode' => 310012,
- 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
- 'PaymentPlanType' => 1,
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => 0.08333,
- 'InitialFee' => 295.0,
- 'NotificationFee' => 35.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 12,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 1000.0,
- 'ToAmount' => 30000.0,
- ),
- 7 =>
- array (
- 'CampaignCode' => 410012,
- 'Description' => 'Dela upp betalningen på 12 månader',
- 'PaymentPlanType' => 0,
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => 0.09259,
- 'InitialFee' => 0.0,
- 'NotificationFee' => 29.0,
- 'InterestRatePercent' => 19.9,
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 100.0,
- 'ToAmount' => 30000.0,
- ),
- 8 =>
- array (
- 'CampaignCode' => 410024,
- 'Description' => 'Dela upp betalningen på 24 månader',
- 'PaymentPlanType' => 0,
- 'ContractLengthInMonths' => 24,
- 'MonthlyAnnuityFactor' => 0.04684,
- 'InitialFee' => 350.0,
- 'NotificationFee' => 35.0,
- 'InterestRatePercent' => 11.5,
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 1000.0,
- 'ToAmount' => 150000.0,
- ),
- 9 =>
- array (
- 'CampaignCode' => 996699,
- 'Description' => 'Sommarkampanj',
- 'PaymentPlanType' => 1,
- 'ContractLengthInMonths' => 6,
- 'MonthlyAnnuityFactor' => 0.33333,
- 'InitialFee' => 95.0,
- 'NotificationFee' => 0.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 6,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 500.0,
- 'ToAmount' => 50000.0,
- ),
- );
- }
-
- protected function getFinnishMixedCampaignsAsArray()
- {
- return array (
- 0 =>
- array (
- 'CampaignCode' => 220001,
- 'Description' => 'ERÄMAKSU 3 KK KOROTON',
- 'PaymentPlanType' => 1,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 0.33333,
- 'InitialFee' => 0.0,
- 'NotificationFee' => 0.0,
- 'InterestRatePercent' => 0.0,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 50.0,
- 'ToAmount' => 1000.0,
- ),
- 1 =>
- array (
- 'CampaignCode' => 220003,
- 'Description' => 'ERÄMAKSU 3 KK, 9.8%',
- 'PaymentPlanType' => 0,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 0.33879,
- 'InitialFee' => 19.9,
- 'NotificationFee' => 8.9,
- 'InterestRatePercent' => 9.8,
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 50.0,
- 'ToAmount' => 1000.0,
- ),
- 2 =>
- array (
- 'CampaignCode' => 220006,
- 'Description' => 'ERÄMAKSU 6 KK, 9.8%',
- 'PaymentPlanType' => 0,
- 'ContractLengthInMonths' => 6,
- 'MonthlyAnnuityFactor' => 0.17146,
- 'InitialFee' => 19.9,
- 'NotificationFee' => 8.9,
- 'InterestRatePercent' => 9.8,
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 50.0,
- 'ToAmount' => 1000.0,
- ),
- 3 =>
- array (
- 'CampaignCode' => 220012,
- 'Description' => 'ERÄMAKSU 12 KK 9.8%',
- 'PaymentPlanType' => 0,
- 'ContractLengthInMonths' => 12,
- 'MonthlyAnnuityFactor' => 0.08782,
- 'InitialFee' => 29.9,
- 'NotificationFee' => 8.9,
- 'InterestRatePercent' => 9.8,
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 50.0,
- 'ToAmount' => 1000.0,
- ),
- 4 =>
- array (
- 'CampaignCode' => 220024,
- 'Description' => 'ERÄMAKSU 24 KK, 9.8',
- 'PaymentPlanType' => 0,
- 'ContractLengthInMonths' => 24,
- 'MonthlyAnnuityFactor' => 0.04605,
- 'InitialFee' => 29.9,
- 'NotificationFee' => 8.9,
- 'InterestRatePercent' => 9.8,
- 'NumberOfInterestFreeMonths' => 0,
- 'NumberOfPaymentFreeMonths' => 0,
- 'FromAmount' => 50.0,
- 'ToAmount' => 1000.0,
- ),
- 5 =>
- array (
- 'CampaignCode' => 220002,
- 'Description' => 'OSTA NYT, MAKSA 3 KK PÄÄSTÄ',
- 'PaymentPlanType' => 2,
- 'ContractLengthInMonths' => 3,
- 'MonthlyAnnuityFactor' => 1,
- 'InitialFee' => 0,
- 'NotificationFee' => 3.95,
- 'InterestRatePercent' => 0,
- 'NumberOfInterestFreeMonths' => 3,
- 'NumberOfPaymentFreeMonths' => 3,
- 'FromAmount' => 50.0,
- 'ToAmount' => 5000.0,
- ),
- );
- }
-
- function test_InterestAndAmortizationFreePaymentPlanCalculator_getTotalAmountToPay()
- {
- $campaign = $this->getInterestAndAmortizationFreeCampaign();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign[0]);
- $this->assertEquals(11229, $totalAmount);
- }
-
- function test_InterestAndAmortizationFreePaymentPlanCalculator_getTotalAmountToPayAsArray()
- {
- $campaign = $this->getInterestAndAmortizationFreeCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign);
- $this->assertEquals(11229, $totalAmount);
- }
-
- function test_InterestAndAmortizationFreePaymentPlanCalculator_getTotalAmountToPayWithFinnishCampaign()
- {
- $this->price = 100;
- $campaign = $this->getFinnishInterestAndAmortizationFreeCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign);
- $this->assertEquals(103.95, $totalAmount);
- }
-
- function test_InterestAndAmortizationFreePaymentPlanCalculator_getMonthlyAmountToPay()
- {
- $campaign = $this->getInterestAndAmortizationFreeCampaign();
- $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign[0]);
- $this->assertEquals(11229, $totalAmount);
- }
-
- function test_InterestAndAmortizationFreePaymentPlanCalculator_getMonthlyAmountToPayAsArray()
- {
- $campaign = $this->getInterestAndAmortizationFreeCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign);
- $this->assertEquals(11229, $totalAmount);
- }
-
- function test_InterestAndAmortizationFreePaymentPlanCalculator_getMonthlyAmountToPayWithFinnishCampaign()
- {
- $this->price = 100;
- $campaign = $this->getFinnishInterestAndAmortizationFreeCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign);
- $this->assertEquals(103.95, $totalAmount);
- }
-
- function test_InterestAndAmortizationFreePaymentPlanCalculator_getEffectiveInterestRate()
- {
- $campaign = $this->getInterestAndAmortizationFreeCampaign();
- $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign[0]);
- $this->assertEquals(1.04, $totalAmount);
- }
-
- function test_InterestAndAmortizationFreePaymentPlanCalculator_getEffectiveInterestRateAsArray()
- {
- $campaign = $this->getInterestAndAmortizationFreeCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign);
- $this->assertEquals(1.04, $totalAmount);
- }
-
- function test_InterestAndAmortizationFreePaymentPlanCalculator_getEffectiveInterestRateWithFinnishCampaign()
- {
- $this->price = 100;
- $campaign = $this->getFinnishInterestAndAmortizationFreeCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign, 2);
- $this->assertEquals(16.77, $totalAmount);
- }
-
- function test_InterestFreePaymentPlanCalculator_getTotalAmountToPay()
- {
- $campaign = $this->getInterestFreeCampaign();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign[0]);
- $this->assertEquals(11915, $totalAmount);
- }
-
- function test_InterestFreePaymentPlanCalculator_getTotalAmountToPayWithFinnishCampaign()
- {
- $this->price = 100;
- $campaign = $this->getFinnishInterestFreeCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign, 2);
- $this->assertEquals(100, $totalAmount);
- }
-
- function test_InterestFreePaymentPlanCalculator_getMonthlyAmountToPay()
- {
- $campaign = $this->getInterestFreeCampaign();
- $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign[0]);
- $this->assertEquals(993, $totalAmount);
- }
-
- function test_InterestFreePaymentPlanCalculator_getMonthlyAmountToPayWithFinnishCampaign()
- {
- $this->price = 100;
- $campaign = $this->getFinnishStandardCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign, 2);
- $this->assertEquals(20.17, $totalAmount);
- }
-
- function test_InterestFreePaymentPlanCalculator_getEffectiveInterestRate()
- {
- $campaign = $this->getInterestFreeCampaign();
- $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign[0]);
- $this->assertEquals(12.44, $totalAmount);
- }
-
- function test_InterestFreePaymentPlanCalculator_getEffectiveInterestRateWithFinnishCampaign()
- {
- $this->price = 100;
- $campaign = $this->getFinnishInterestFreeCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign, 2);
- $this->assertEquals(0, $totalAmount);
- }
-
- function test_StandardPaymentPlanCalculator_getTotalAmountToPay()
- {
- $campaign = $this->getStandardCampaign();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign[0]);
- $this->assertEquals(18067, $totalAmount);
- }
-
- function test_StandardPaymentPlanCalculator_getTotalAmountToPayWithFinnishCampaign()
- {
- $this->price = 100;
- $campaign = $this->getFinnishStandardCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign, 2);
- $this->assertEquals(242.09, $totalAmount);
- }
-
- function test_StandardPaymentPlanCalculator_getMonthlyAmountToPay()
- {
- $campaign = $this->getStandardCampaign();
- $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign[0]);
- $this->assertEquals(317, $totalAmount);
- }
-
- function test_StandardPaymentPlanCalculator_getMonthlyAmountToPayWithFinnishCampaign()
- {
- $this->price = 100;
- $campaign = $this->getFinnishStandardCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign, 2);
- $this->assertEquals(20.17, $totalAmount);
- }
-
- function test_StandardPaymentPlanCalculator_getEffectiveInterestRate()
- {
- $campaign = $this->getStandardCampaign();
- $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign[0]);
- $this->assertEquals(21.33, $totalAmount);
- }
-
- function test_StandardPaymentPlanCalculator_getEffectiveInterestRateWithFinnishCampaign()
- {
- $this->price = 100;
- $campaign = $this->getFinnishStandardCampaignAsArray();
- $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign, 2);
- $this->assertEquals(898.33, $totalAmount);
- }
-
- function test_PaymentPlanCalculator_getTotalAmountToPayFromCampaigns()
- {
- $campaigns = $this->getMixedCampaigns();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($this->price, $campaigns);
- $this->assertEquals(18067, $totalAmount[0]['totalAmountToPay']);
- $this->assertEquals(11200, $totalAmount[1]['totalAmountToPay']);
- $this->assertEquals(11200, $totalAmount[2]['totalAmountToPay']);
- $this->assertEquals(11229, $totalAmount[3]['totalAmountToPay']);
- $this->assertEquals(11200, $totalAmount[4]['totalAmountToPay']);
- $this->assertEquals(11200, $totalAmount[5]['totalAmountToPay']);
- $this->assertEquals(11915, $totalAmount[6]['totalAmountToPay']);
- $this->assertEquals(12792, $totalAmount[7]['totalAmountToPay']);
- $this->assertEquals(13781, $totalAmount[8]['totalAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getMonthlyAmountToPayFromCampaigns()
- {
- $campaigns = $this->getMixedCampaigns();
- $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($this->price, $campaigns);
- $this->assertEquals(317, $totalAmount[0]['monthlyAmountToPay']);
- $this->assertEquals(11200, $totalAmount[1]['monthlyAmountToPay']);
- $this->assertEquals(11200, $totalAmount[2]['monthlyAmountToPay']);
- $this->assertEquals(11229, $totalAmount[3]['monthlyAmountToPay']);
- $this->assertEquals(11200, $totalAmount[4]['monthlyAmountToPay']);
- $this->assertEquals(11200, $totalAmount[5]['monthlyAmountToPay']);
- $this->assertEquals(993, $totalAmount[6]['monthlyAmountToPay']);
- $this->assertEquals(1066, $totalAmount[7]['monthlyAmountToPay']);
- $this->assertEquals(574, $totalAmount[8]['monthlyAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getEffectiveInterestRateFromCampaigns()
- {
- $campaigns = $this->getMixedCampaigns();
- $totalAmount = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($this->price, $campaigns);
- $this->assertEquals(21.33, $totalAmount[0]['effectiveInterestRate']);
- $this->assertEquals(0, $totalAmount[1]['effectiveInterestRate']);
- $this->assertEquals(0, $totalAmount[2]['effectiveInterestRate']);
- $this->assertEquals(1.04, $totalAmount[3]['effectiveInterestRate']);
- $this->assertEquals(0, $totalAmount[4]['effectiveInterestRate']);
- $this->assertEquals(0, $totalAmount[5]['effectiveInterestRate']);
- $this->assertEquals(12.44, $totalAmount[6]['effectiveInterestRate']);
- $this->assertEquals(28.44, $totalAmount[7]['effectiveInterestRate']);
- $this->assertEquals(23.65, $totalAmount[8]['effectiveInterestRate']);
- }
-
- function test_PaymentPlanCalculator_getTotalAmountToPayFromCampaignsAsArray()
- {
- $campaigns = $this->getMixedCampaignsAsArray();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($this->price, $campaigns);
- $this->assertEquals(18067, $totalAmount[0]['TotalAmountToPay']);
- $this->assertEquals(11200, $totalAmount[1]['TotalAmountToPay']);
- $this->assertEquals(11200, $totalAmount[2]['TotalAmountToPay']);
- $this->assertEquals(11229, $totalAmount[3]['TotalAmountToPay']);
- $this->assertEquals(11200, $totalAmount[4]['TotalAmountToPay']);
- $this->assertEquals(11200, $totalAmount[5]['TotalAmountToPay']);
- $this->assertEquals(11915, $totalAmount[6]['TotalAmountToPay']);
- $this->assertEquals(12792, $totalAmount[7]['TotalAmountToPay']);
- $this->assertEquals(13781, $totalAmount[8]['TotalAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getTotalAmountToPayFromCampaignsAsArray_ReturnOnlyValidCampaigns()
- {
- $this->price = 100;
- $campaigns = $this->getMixedCampaignsAsArray();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($this->price, $campaigns);
- $this->assertEquals(1, count($totalAmount));
- }
-
- function test_PaymentPlanCalculator_getTotalAmountToPayFromCampaignsAsArray_ReturnZeroCampaigns()
- {
- $this->price = 1;
- $campaigns = $this->getMixedCampaignsAsArray();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($this->price, $campaigns);
- $this->assertEquals(0, count($totalAmount));
- }
-
- function test_PaymentPlanCalculator_getMonthlyAmountToPayFromCampaignsAsArray()
- {
- $campaigns = $this->getMixedCampaignsAsArray();
- $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($this->price, $campaigns);
- $this->assertEquals(317, $totalAmount[0]['MonthlyAmountToPay']);
- $this->assertEquals(11200, $totalAmount[1]['MonthlyAmountToPay']);
- $this->assertEquals(11200, $totalAmount[2]['MonthlyAmountToPay']);
- $this->assertEquals(11229, $totalAmount[3]['MonthlyAmountToPay']);
- $this->assertEquals(11200, $totalAmount[4]['MonthlyAmountToPay']);
- $this->assertEquals(11200, $totalAmount[5]['MonthlyAmountToPay']);
- $this->assertEquals(993, $totalAmount[6]['MonthlyAmountToPay']);
- $this->assertEquals(1066, $totalAmount[7]['MonthlyAmountToPay']);
- $this->assertEquals(574, $totalAmount[8]['MonthlyAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getMonthlyAmountToPayFromCampaignsAsArray_ReturnOnlyValidCampaigns()
- {
- $this->price = 100;
- $campaigns = $this->getMixedCampaignsAsArray();
- $monthlyAmount = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($this->price, $campaigns);
- $this->assertEquals(1, count($monthlyAmount));
- }
-
- function test_PaymentPlanCalculator_getMonthlyAmountToPayFromCampaignsAsArray_ReturnZeroCampaigns()
- {
- $this->price = 1;
- $campaigns = $this->getMixedCampaignsAsArray();
- $monthlyAmount = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($this->price, $campaigns);
- $this->assertEquals(0, count($monthlyAmount));
- }
-
- function test_PaymentPlanCalculator_getEffectiveInterestRateFromCampaignsAsArray()
- {
- $campaigns = $this->getMixedCampaignsAsArray();
- $totalAmount = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($this->price, $campaigns);
- $this->assertEquals(21.33, $totalAmount[0]['EffectiveInterestRate']);
- $this->assertEquals(0, $totalAmount[1]['EffectiveInterestRate']);
- $this->assertEquals(0, $totalAmount[2]['EffectiveInterestRate']);
- $this->assertEquals(1.04, $totalAmount[3]['EffectiveInterestRate']);
- $this->assertEquals(0, $totalAmount[4]['EffectiveInterestRate']);
- $this->assertEquals(0, $totalAmount[5]['EffectiveInterestRate']);
- $this->assertEquals(12.44, $totalAmount[6]['EffectiveInterestRate']);
- $this->assertEquals(28.44, $totalAmount[7]['EffectiveInterestRate']);
- $this->assertEquals(23.65, $totalAmount[8]['EffectiveInterestRate']);
- }
-
- function test_PaymentPlanCalculator_getEffectiveInterestRateFromCampaignsAsArray_ReturnOnlyValidCampaigns()
- {
- $this->price = 100;
- $campaigns = $this->getMixedCampaignsAsArray();
- $effectiveInterestRate = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($this->price, $campaigns);
- $this->assertEquals(1, count($effectiveInterestRate));
- }
-
- function test_PaymentPlanCalculator_getEffectiveInterestRateFromCampaignsAsArray_ReturnZeroCampaigns()
- {
- $this->price = 1;
- $campaigns = $this->getMixedCampaignsAsArray();
- $effectiveInterestRate = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($this->price, $campaigns);
- $this->assertEquals(0, count($effectiveInterestRate));
- }
-
- function test_PaymentPlanCalculator_getTotalAmountToPayFromCampaignsWithFinnishCampaign()
- {
- $this->price = 100;
- $campaigns = $this->getFinnishMixedCampaignsAsArray();
- $totalAmount = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($this->price, $campaigns, 2);
- $this->assertEquals(100, $totalAmount[0]['TotalAmountToPay']);
- $this->assertEquals(148.24, $totalAmount[1]['TotalAmountToPay']);
- $this->assertEquals(176.18, $totalAmount[2]['TotalAmountToPay']);
- $this->assertEquals(242.09, $totalAmount[3]['TotalAmountToPay']);
- $this->assertEquals(354.03, $totalAmount[4]['TotalAmountToPay']);
- $this->assertEquals(103.95, $totalAmount[5]['TotalAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getMonthlyAmountToPayFromCampaignsWithFinnishCampaign()
- {
- $this->price = 100;
- $campaigns = $this->getFinnishMixedCampaignsAsArray();
- $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($this->price, $campaigns, 2);
- $this->assertEquals(33.33, $totalAmount[0]['MonthlyAmountToPay']);
- $this->assertEquals(49.41, $totalAmount[1]['MonthlyAmountToPay']);
- $this->assertEquals(29.36, $totalAmount[2]['MonthlyAmountToPay']);
- $this->assertEquals(20.17, $totalAmount[3]['MonthlyAmountToPay']);
- $this->assertEquals(14.75, $totalAmount[4]['MonthlyAmountToPay']);
- $this->assertEquals(103.95, $totalAmount[5]['MonthlyAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getEffectiveInterestRateFromCampaignsWithFinnishCampaign()
- {
- $this->price = 100;
- $campaigns = $this->getFinnishMixedCampaignsAsArray();
- $totalAmount = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($this->price, $campaigns, 2);
- $this->assertEquals(0, $totalAmount[0]['EffectiveInterestRate']);
- $this->assertEquals(1300.39, $totalAmount[1]['EffectiveInterestRate']);
- $this->assertEquals(930.86, $totalAmount[2]['EffectiveInterestRate']);
- $this->assertEquals(898.33, $totalAmount[3]['EffectiveInterestRate']);
- $this->assertEquals(611.36, $totalAmount[4]['EffectiveInterestRate']);
- $this->assertEquals(16.77, $totalAmount[5]['EffectiveInterestRate']);
- }
-
- function test_PaymentPlanCalculator_getAllCalculations()
- {
- $campaign = $this->getStandardCampaign();
- $campaign = PaymentPlanCalculator::getAllCalculations($this->price, $campaign[0]);
- $this->assertEquals(21.33, $campaign['effectiveInterestRate']);
- $this->assertEquals(317, $campaign['monthlyAmountToPay']);
- $this->assertEquals(18067, $campaign['totalAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getAllCalculationsAsArray()
- {
- $campaign = $this->getStandardCampaignAsArray();
- $campaign = PaymentPlanCalculator::getAllCalculations($this->price, $campaign);
- $this->assertEquals(21.33, $campaign['EffectiveInterestRate']);
- $this->assertEquals(317, $campaign['MonthlyAmountToPay']);
- $this->assertEquals(18067, $campaign['TotalAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getAllCalculationsAsArrayWithFinnishCampaign()
- {
- $this->price = 100;
- $campaign = $this->getFinnishStandardCampaignAsArray();
- $campaign = PaymentPlanCalculator::getAllCalculations($this->price, $campaign, 2);
- $this->assertEquals(898.33, $campaign['EffectiveInterestRate']);
- $this->assertEquals(20.17, $campaign['MonthlyAmountToPay']);
- $this->assertEquals(242.09, $campaign['TotalAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getAllCalculationsFromCampaigns()
- {
- $campaigns = $this->getMixedCampaigns();
- $campaigns = PaymentPlanCalculator::getAllCalculationsFromCampaigns($this->price, $campaigns);
-
- // Campaign 0
- $this->assertEquals(21.33, $campaigns[0]['effectiveInterestRate']);
- $this->assertEquals(317, $campaigns[0]['monthlyAmountToPay']);
- $this->assertEquals(18067, $campaigns[0]['totalAmountToPay']);
-
- // Campaign 1
- $this->assertEquals(0, $campaigns[1]['effectiveInterestRate']);
- $this->assertEquals(11200, $campaigns[1]['monthlyAmountToPay']);
- $this->assertEquals(11200, $campaigns[1]['totalAmountToPay']);
-
- // Campaign 2
- $this->assertEquals(0, $campaigns[2]['effectiveInterestRate']);
- $this->assertEquals(11200, $campaigns[2]['monthlyAmountToPay']);
- $this->assertEquals(11200, $campaigns[2]['totalAmountToPay']);
-
- // Campaign 3
- $this->assertEquals(1.04, $campaigns[3]['effectiveInterestRate']);
- $this->assertEquals(11229, $campaigns[3]['monthlyAmountToPay']);
- $this->assertEquals(11229, $campaigns[3]['totalAmountToPay']);
-
- // Campaign 4
- $this->assertEquals(0, $campaigns[4]['effectiveInterestRate']);
- $this->assertEquals(11200, $campaigns[4]['monthlyAmountToPay']);
- $this->assertEquals(11200, $campaigns[4]['totalAmountToPay']);
-
- // Campaign 5
- $this->assertEquals(0, $campaigns[5]['effectiveInterestRate']);
- $this->assertEquals(11200, $campaigns[5]['monthlyAmountToPay']);
- $this->assertEquals(11200, $campaigns[5]['totalAmountToPay']);
-
- // Campaign 6
- $this->assertEquals(12.44, $campaigns[6]['effectiveInterestRate']);
- $this->assertEquals(993, $campaigns[6]['monthlyAmountToPay']);
- $this->assertEquals(11915, $campaigns[6]['totalAmountToPay']);
-
- // Campaign 7
- $this->assertEquals(28.44, $campaigns[7]['effectiveInterestRate']);
- $this->assertEquals(1066, $campaigns[7]['monthlyAmountToPay']);
- $this->assertEquals(12792, $campaigns[7]['totalAmountToPay']);
-
- // Campaign 8
- $this->assertEquals(23.65, $campaigns[8]['effectiveInterestRate']);
- $this->assertEquals(574, $campaigns[8]['monthlyAmountToPay']);
- $this->assertEquals(13781, $campaigns[8]['totalAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getAllCalculationsFromCampaignsAsArray()
- {
- $campaigns = $this->getMixedCampaignsAsArray();
- $campaigns = PaymentPlanCalculator::getAllCalculationsFromCampaigns($this->price, $campaigns);
-
- // Campaign 0
- $this->assertEquals(21.33, $campaigns[0]['EffectiveInterestRate']);
- $this->assertEquals(317, $campaigns[0]['MonthlyAmountToPay']);
- $this->assertEquals(18067, $campaigns[0]['TotalAmountToPay']);
-
- // Campaign 1
- $this->assertEquals(0, $campaigns[1]['EffectiveInterestRate']);
- $this->assertEquals(11200, $campaigns[1]['MonthlyAmountToPay']);
- $this->assertEquals(11200, $campaigns[1]['TotalAmountToPay']);
-
- // Campaign 2
- $this->assertEquals(0, $campaigns[2]['EffectiveInterestRate']);
- $this->assertEquals(11200, $campaigns[2]['MonthlyAmountToPay']);
- $this->assertEquals(11200, $campaigns[2]['TotalAmountToPay']);
-
- // Campaign 3
- $this->assertEquals(1.04, $campaigns[3]['EffectiveInterestRate']);
- $this->assertEquals(11229, $campaigns[3]['MonthlyAmountToPay']);
- $this->assertEquals(11229, $campaigns[3]['TotalAmountToPay']);
-
- // Campaign 4
- $this->assertEquals(0, $campaigns[4]['EffectiveInterestRate']);
- $this->assertEquals(11200, $campaigns[4]['MonthlyAmountToPay']);
- $this->assertEquals(11200, $campaigns[4]['TotalAmountToPay']);
-
- // Campaign 5
- $this->assertEquals(0, $campaigns[5]['EffectiveInterestRate']);
- $this->assertEquals(11200, $campaigns[5]['MonthlyAmountToPay']);
- $this->assertEquals(11200, $campaigns[5]['TotalAmountToPay']);
-
- // Campaign 6
- $this->assertEquals(12.44, $campaigns[6]['EffectiveInterestRate']);
- $this->assertEquals(993, $campaigns[6]['MonthlyAmountToPay']);
- $this->assertEquals(11915, $campaigns[6]['TotalAmountToPay']);
-
- // Campaign 7
- $this->assertEquals(28.44, $campaigns[7]['EffectiveInterestRate']);
- $this->assertEquals(1066, $campaigns[7]['MonthlyAmountToPay']);
- $this->assertEquals(12792, $campaigns[7]['TotalAmountToPay']);
-
- // Campaign 8
- $this->assertEquals(23.65, $campaigns[8]['EffectiveInterestRate']);
- $this->assertEquals(574, $campaigns[8]['MonthlyAmountToPay']);
- $this->assertEquals(13781, $campaigns[8]['TotalAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_getAllCalculationsFromCampaignsAsArray_ReturnOnlyValidCampaigns()
- {
- $this->price = 100;
- $campaigns = $this->getMixedCampaignsAsArray();
- $allCalculations = PaymentPlanCalculator::getAllCalculationsFromCampaigns($this->price, $campaigns);
- $this->assertEquals(1, count($allCalculations));
- }
-
- function test_PaymentPlanCalculator_getAllCalculationsFromCampaignsAsArray_ReturnZeroCampaigns()
- {
- $this->price = 1;
- $campaigns = $this->getMixedCampaignsAsArray();
- $allCalculations = PaymentPlanCalculator::getAllCalculationsFromCampaigns($this->price, $campaigns);
- $this->assertEquals(0, count($allCalculations));
- }
-
- function test_PaymentPlanCalculator_getAllCalculationsFromCampaignsAsArrayWithFinnishCampaign()
- {
- $this->price = 100;
- $campaigns = $this->getFinnishMixedCampaignsAsArray();
- $campaigns = PaymentPlanCalculator::getAllCalculationsFromCampaigns($this->price, $campaigns, 2);
-
- // Campaign 0
- $this->assertEquals(0, $campaigns[0]['EffectiveInterestRate']);
- $this->assertEquals(33.33, $campaigns[0]['MonthlyAmountToPay']);
- $this->assertEquals(100, $campaigns[0]['TotalAmountToPay']);
-
- // Campaign 1
- $this->assertEquals(1300.39, $campaigns[1]['EffectiveInterestRate']);
- $this->assertEquals(49.41, $campaigns[1]['MonthlyAmountToPay']);
- $this->assertEquals(148.24, $campaigns[1]['TotalAmountToPay']);
-
- // Campaign 2
- $this->assertEquals(930.86, $campaigns[2]['EffectiveInterestRate']);
- $this->assertEquals(29.36, $campaigns[2]['MonthlyAmountToPay']);
- $this->assertEquals(176.18, $campaigns[2]['TotalAmountToPay']);
-
- // Campaign 3
- $this->assertEquals(898.33, $campaigns[3]['EffectiveInterestRate']);
- $this->assertEquals(20.17, $campaigns[3]['MonthlyAmountToPay']);
- $this->assertEquals(242.09, $campaigns[3]['TotalAmountToPay']);
-
- // Campaign 4
- $this->assertEquals(611.36, $campaigns[4]['EffectiveInterestRate']);
- $this->assertEquals(14.75, $campaigns[4]['MonthlyAmountToPay']);
- $this->assertEquals(354.03, $campaigns[4]['TotalAmountToPay']);
-
- // Campaign 5
- $this->assertEquals(16.77, $campaigns[5]['EffectiveInterestRate']);
- $this->assertEquals(103.95, $campaigns[5]['MonthlyAmountToPay']);
- $this->assertEquals(103.95, $campaigns[5]['TotalAmountToPay']);
- }
-
- function test_PaymentPlanCalculator_convertFromCheckoutArray()
- {
- $arr = $this->getInterestAndAmortizationFreeCampaignAsArray();
- $class = new ReflectionClass('\Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator');
- $method = $class->getMethod('convertFromCheckoutArray');
- $method->setAccessible(true);
- $convertedArray = $method->invoke(null, $arr);
-
- $this->assertEquals(array_key_exists("campaignCode", $convertedArray), true);
- $this->assertEquals(array_key_exists("description", $convertedArray), true);
- $this->assertEquals(array_key_exists("toAmount", $convertedArray), true);
- $this->assertEquals($convertedArray['checkout'], true);
- $this->assertEquals($convertedArray['paymentPlanType'], "InterestAndAmortizationFree");
- }
-
- function test_PaymentPlanCalculator_convertToCheckoutArray()
- {
- $arr = $this->getInterestAndAmortizationFreeCampaignAsArray();
- $class = new ReflectionClass('\Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator');
- $methodConvertFrom = $class->getMethod('convertFromCheckoutArray');
- $methodConvertFrom->setAccessible(true);
- $convertedFromCheckoutArray = $methodConvertFrom->invoke(null, $arr);
-
- $methodConvertTo = $class->getMethod('convertToCheckoutArray');
- $methodConvertTo->setAccessible(true);
- $convertedToCheckoutArray = $methodConvertTo->invoke(null, $convertedFromCheckoutArray);
-
- $this->assertEquals(array_key_exists("CampaignCode", $convertedToCheckoutArray), true);
- $this->assertEquals($convertedToCheckoutArray['PaymentPlanType'], 2);
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage paymentPlanType not recognized
- */
- function test_InterestAndAmortizationFreePaymentPlanCalculator_getTotalAmountToPay_invalid_paymentPlanType()
- {
- $campaign = $this->getStandardCampaign();
- $campaign['paymentPlanType'] = "invalid";
- PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign);
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage Monthly payment can not be below 0
- */
- function test_EffectiveInterestRateCalculator_invalid_monthlyPayment()
- {
- $calculator = new EffectiveInterestRateCalculator(10000.00);
-
- $calculator->calculate(10000, 100, -1, 12, 0);
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage Contract length must be at least 1 month
- */
- function test_EffectiveInterestRateCalculator_invalid_contractLength()
- {
- $calculator = new EffectiveInterestRateCalculator(10000.00);
-
- $calculator->calculate(10000, 100, 100, 0, 0);
- }
+ protected $price;
+
+ protected $paymentPlanParams;
+
+ protected function setUp()
+ {
+ $this->price = 11200;
+ }
+
+ protected function getInterestAndAmortizationFreeCampaign()
+ {
+ $response = (object) [
+ "GetPaymentPlanParamsEuResult" => (object)[
+ "Accepted" => true,
+ "ResultCode" => 0,
+ "CampaignCodes" => (object)[
+ "CampaignCodeInfo" => [
+ 0 =>
+ (object)[
+ 'CampaignCode' => 223060,
+ 'Description' => 'Köp nu betala om 3 månader (räntefritt)',
+ 'PaymentPlanType' => 'InterestAndAmortizationFree',
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => '1',
+ 'InitialFee' => '0',
+ 'NotificationFee' => '29',
+ 'InterestRatePercent' => '0',
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => '1000',
+ 'ToAmount' => '50000',
+ ]
+ ]
+ ]
+ ]
+ ];
+
+ $params = new PaymentPlanParamsResponse($response, false);
+
+ return $params->campaignCodes;
+ }
+
+ protected function getInterestAndAmortizationFreeCampaignAsArray()
+ {
+ return [
+ 'CampaignCode' => 223060,
+ 'Description' => 'Köp nu betala om 3 månader (räntefritt)',
+ 'PaymentPlanType' => 2,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 1.0,
+ 'InitialFee' => 0.0,
+ 'NotificationFee' => 29.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 1000.0,
+ 'ToAmount' => 50000.0,
+ ];
+ }
+
+ protected function getInterestFreeCampaign()
+ {
+ $response = (object) [
+ "GetPaymentPlanParamsEuResult" => (object)[
+ "Accepted" => true,
+ "ResultCode" => 0,
+ "CampaignCodes" => (object)[
+ "CampaignCodeInfo" => [
+ 0 =>
+ (object)[
+ 'CampaignCode' => 310012,
+ 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
+ 'PaymentPlanType' => 'InterestFree',
+ 'ContractLengthInMonths' => 12,
+ 'MonthlyAnnuityFactor' => '0.08333',
+ 'InitialFee' => '295',
+ 'NotificationFee' => '35',
+ 'InterestRatePercent' => '0',
+ 'NumberOfInterestFreeMonths' => 12,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => '1000',
+ 'ToAmount' => '30000',
+ ]
+ ]
+ ]
+ ]
+ ];
+
+ $params = new PaymentPlanParamsResponse($response, false);
+
+ return $params->campaignCodes;
+ }
+
+ protected function getFinnishInterestAndAmortizationFreeCampaignAsArray()
+ {
+ return [
+ 'CampaignCode' => 220002,
+ 'Description' => 'OSTA NYT, MAKSA 3 KK PÄÄSTÄ',
+ 'PaymentPlanType' => 2,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 1,
+ 'InitialFee' => 0,
+ 'NotificationFee' => 3.95,
+ 'InterestRatePercent' => 0,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 50.0,
+ 'ToAmount' => 5000.0,
+ ];
+ }
+
+ protected function getInterestFreeCampaignAsArray()
+ {
+ return [
+ 'CampaignCode' => 310012,
+ 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
+ 'PaymentPlanType' => 1,
+ 'ContractLengthInMonths' => 12,
+ 'MonthlyAnnuityFactor' => 0.08333,
+ 'InitialFee' => 295.0,
+ 'NotificationFee' => 35.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 12,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 1000.0,
+ 'ToAmount' => 30000.0,
+ ];
+ }
+
+ protected function getFinnishInterestFreeCampaignAsArray()
+ {
+ return [
+ 'CampaignCode' => 220001,
+ 'Description' => 'ERÄMAKSU 3 KK KOROTON',
+ 'PaymentPlanType' => 1,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 0.33333,
+ 'InitialFee' => 0.0,
+ 'NotificationFee' => 0.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 50.0,
+ 'ToAmount' => 1000.0,
+ ];
+ }
+
+ protected function getStandardCampaign()
+ {
+ $response = (object) [
+ "GetPaymentPlanParamsEuResult" => (object)[
+ "Accepted" => true,
+ "ResultCode" => 0,
+ "CampaignCodes" => (object)[
+ "CampaignCodeInfo" => [
+ 0 =>
+ (object)[
+ "CampaignCode" => 213060,
+ "Description" => "Dela upp betalningen på 60 månader",
+ "PaymentPlanType" => "Standard",
+ "ContractLengthInMonths" => 60,
+ "MonthlyAnnuityFactor" => '0.02555',
+ "InitialFee" => '100',
+ "NotificationFee" => '29',
+ "InterestRatePercent" => '16.75',
+ "NumberOfInterestFreeMonths" => 3,
+ "NumberOfPaymentFreeMonths" => 3,
+ "FromAmount" => '1000',
+ "ToAmount" => '50000',
+ ]
+ ]
+ ]
+ ]
+ ];
+
+ $params = new PaymentPlanParamsResponse($response, false);
+
+ return $params->campaignCodes;
+ }
+
+ protected function getStandardCampaignAsArray()
+ {
+ return [
+ 'CampaignCode' => 213060,
+ 'Description' => 'Dela upp betalningen på 60 månader',
+ 'PaymentPlanType' => 0,
+ 'ContractLengthInMonths' => 60,
+ 'MonthlyAnnuityFactor' => 0.02555,
+ 'InitialFee' => 100.0,
+ 'NotificationFee' => 29.0,
+ 'InterestRatePercent' => 16.75,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 1000.0,
+ 'ToAmount' => 50000.0,
+ ];
+ }
+
+ protected function getFinnishStandardCampaignAsArray()
+ {
+ return [
+ 'CampaignCode' => 220012,
+ 'Description' => 'ERÄMAKSU 12 KK 9.8%',
+ 'PaymentPlanType' => 0,
+ 'ContractLengthInMonths' => 12,
+ 'MonthlyAnnuityFactor' => 0.08782,
+ 'InitialFee' => 29.9,
+ 'NotificationFee' => 8.9,
+ 'InterestRatePercent' => 9.8,
+ 'NumberOfInterestFreeMonths' => 0,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 50,
+ 'ToAmount' => 1000,
+ ];
+ }
+
+ protected function getMixedCampaigns()
+ {
+ $response = (object) [
+ "GetPaymentPlanParamsEuResult" => (object)[
+ "Accepted" => true,
+ "ResultCode" => 0,
+ "CampaignCodes" => (object)[
+ "CampaignCodeInfo" => [
+ 0 =>
+ (object)[
+ "CampaignCode" => 213060,
+ "Description" => "Dela upp betalningen på 60 månader",
+ "PaymentPlanType" => "Standard",
+ "ContractLengthInMonths" => 60,
+ "MonthlyAnnuityFactor" => '0.02555',
+ "InitialFee" => '100',
+ "NotificationFee" => '29',
+ "InterestRatePercent" => '16.75',
+ "NumberOfInterestFreeMonths" => 3,
+ "NumberOfPaymentFreeMonths" => 3,
+ "FromAmount" => '1000',
+ "ToAmount" => '50000',
+ ],
+ 1 =>
+ (object)[
+ 'CampaignCode' => 222065,
+ 'Description' => 'Vårkampanj',
+ 'PaymentPlanType' => 'InterestAndAmortizationFree',
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => '1',
+ 'InitialFee' => '0',
+ 'NotificationFee' => '0',
+ 'InterestRatePercent' => '0',
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => '120',
+ 'ToAmount' => '30000',
+ ],
+ 2 =>
+ (object)[
+ 'CampaignCode' => 222066,
+ 'Description' => 'Sommarkampanj',
+ 'PaymentPlanType' => 'InterestAndAmortizationFree',
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => '1',
+ 'InitialFee' => '0',
+ 'NotificationFee' => '0',
+ 'InterestRatePercent' => '0',
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => '120',
+ 'ToAmount' => '30000',
+ ],
+ 3 =>
+ (object)[
+ 'CampaignCode' => 223060,
+ 'Description' => 'Köp nu betala om 3 månader (räntefritt)',
+ 'PaymentPlanType' => 'InterestAndAmortizationFree',
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => '1',
+ 'InitialFee' => '0',
+ 'NotificationFee' => '29',
+ 'InterestRatePercent' => '0',
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => '1000',
+ 'ToAmount' => '50000',
+ ],
+ 4 =>
+ (object)[
+ 'CampaignCode' => 223065,
+ 'Description' => 'Black Friday - Cyber Monday',
+ 'PaymentPlanType' => 'InterestAndAmortizationFree',
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => '1',
+ 'InitialFee' => '0',
+ 'NotificationFee' => '0',
+ 'InterestRatePercent' => '0',
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => '120',
+ 'ToAmount' => '30000',
+ ],
+ 5 =>
+ (object)[
+ 'CampaignCode' => 223066,
+ 'Description' => 'Julkampanj',
+ 'PaymentPlanType' => 'InterestAndAmortizationFree',
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => '1',
+ 'InitialFee' => '0',
+ 'NotificationFee' => '0',
+ 'InterestRatePercent' => '0',
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => '120',
+ 'ToAmount' => '30000',
+ ],
+ 6 =>
+ (object)[
+ 'CampaignCode' => 310012,
+ 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
+ 'PaymentPlanType' => 'InterestFree',
+ 'ContractLengthInMonths' => 12,
+ 'MonthlyAnnuityFactor' => '0.08333',
+ 'InitialFee' => '295',
+ 'NotificationFee' => '35',
+ 'InterestRatePercent' => '0',
+ 'NumberOfInterestFreeMonths' => 12,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => '1000',
+ 'ToAmount' => '30000',
+ ],
+ 7 =>
+ (object)[
+ 'CampaignCode' => 410012,
+ 'Description' => 'Dela upp betalningen på 12 månader',
+ 'PaymentPlanType' => 'Standard',
+ 'ContractLengthInMonths' => 12,
+ 'MonthlyAnnuityFactor' => '0.09259',
+ 'InitialFee' => '0',
+ 'NotificationFee' => '29',
+ 'InterestRatePercent' => '19.9',
+ 'NumberOfInterestFreeMonths' => 0,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => '100',
+ 'ToAmount' => '30000',
+ ],
+ 8 =>
+ (object)[
+ 'CampaignCode' => 410024,
+ 'Description' => 'Dela upp betalningen på 24 månader',
+ 'PaymentPlanType' => 'Standard',
+ 'ContractLengthInMonths' => 24,
+ 'MonthlyAnnuityFactor' => '0.04684',
+ 'InitialFee' => '350',
+ 'NotificationFee' => '35',
+ 'InterestRatePercent' => '11.5',
+ 'NumberOfInterestFreeMonths' => 0,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => '1000',
+ 'ToAmount' => '150000',
+ ]
+ ]
+ ]
+ ]
+ ];
+
+ $params = new PaymentPlanParamsResponse($response, false);
+
+ return $params->campaignCodes;
+ }
+
+ protected function getMixedCampaignsAsArray()
+ {
+ return [
+ 0 =>
+ [
+ 'CampaignCode' => 213060,
+ 'Description' => 'Dela upp betalningen på 60 månader',
+ 'PaymentPlanType' => 0,
+ 'ContractLengthInMonths' => 60,
+ 'MonthlyAnnuityFactor' => 0.02555,
+ 'InitialFee' => 100.0,
+ 'NotificationFee' => 29.0,
+ 'InterestRatePercent' => 16.75,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 1000.0,
+ 'ToAmount' => 50000.0,
+ ],
+ 1 =>
+ [
+ 'CampaignCode' => 222065,
+ 'Description' => 'Vårkampanj',
+ 'PaymentPlanType' => 2,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 1.0,
+ 'InitialFee' => 0.0,
+ 'NotificationFee' => 0.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 120.0,
+ 'ToAmount' => 30000.0,
+ ],
+ 2 =>
+ [
+ 'CampaignCode' => 222066,
+ 'Description' => 'Sommarkampanj',
+ 'PaymentPlanType' => 2,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 1.0,
+ 'InitialFee' => 0.0,
+ 'NotificationFee' => 0.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 120.0,
+ 'ToAmount' => 30000.0,
+ ],
+ 3 =>
+ [
+ 'CampaignCode' => 223060,
+ 'Description' => 'Köp nu betala om 3 månader (räntefritt)',
+ 'PaymentPlanType' => 2,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 1.0,
+ 'InitialFee' => 0.0,
+ 'NotificationFee' => 29.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 1000.0,
+ 'ToAmount' => 50000.0,
+ ],
+ 4 =>
+ [
+ 'CampaignCode' => 223065,
+ 'Description' => 'Black Friday - Cyber Monday',
+ 'PaymentPlanType' => 2,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 1.0,
+ 'InitialFee' => 0.0,
+ 'NotificationFee' => 0.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 120.0,
+ 'ToAmount' => 30000.0,
+ ],
+ 5 =>
+ [
+ 'CampaignCode' => 223066,
+ 'Description' => 'Julkampanj',
+ 'PaymentPlanType' => 2,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 1.0,
+ 'InitialFee' => 0.0,
+ 'NotificationFee' => 0.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 120.0,
+ 'ToAmount' => 30000.0,
+ ],
+ 6 =>
+ [
+ 'CampaignCode' => 310012,
+ 'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
+ 'PaymentPlanType' => 1,
+ 'ContractLengthInMonths' => 12,
+ 'MonthlyAnnuityFactor' => 0.08333,
+ 'InitialFee' => 295.0,
+ 'NotificationFee' => 35.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 12,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 1000.0,
+ 'ToAmount' => 30000.0,
+ ],
+ 7 =>
+ [
+ 'CampaignCode' => 410012,
+ 'Description' => 'Dela upp betalningen på 12 månader',
+ 'PaymentPlanType' => 0,
+ 'ContractLengthInMonths' => 12,
+ 'MonthlyAnnuityFactor' => 0.09259,
+ 'InitialFee' => 0.0,
+ 'NotificationFee' => 29.0,
+ 'InterestRatePercent' => 19.9,
+ 'NumberOfInterestFreeMonths' => 0,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 100.0,
+ 'ToAmount' => 30000.0,
+ ],
+ 8 =>
+ [
+ 'CampaignCode' => 410024,
+ 'Description' => 'Dela upp betalningen på 24 månader',
+ 'PaymentPlanType' => 0,
+ 'ContractLengthInMonths' => 24,
+ 'MonthlyAnnuityFactor' => 0.04684,
+ 'InitialFee' => 350.0,
+ 'NotificationFee' => 35.0,
+ 'InterestRatePercent' => 11.5,
+ 'NumberOfInterestFreeMonths' => 0,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 1000.0,
+ 'ToAmount' => 150000.0,
+ ],
+ 9 =>
+ [
+ 'CampaignCode' => 996699,
+ 'Description' => 'Sommarkampanj',
+ 'PaymentPlanType' => 1,
+ 'ContractLengthInMonths' => 6,
+ 'MonthlyAnnuityFactor' => 0.33333,
+ 'InitialFee' => 95.0,
+ 'NotificationFee' => 0.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 6,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 500.0,
+ 'ToAmount' => 50000.0,
+ ],
+ ];
+ }
+
+ protected function getFinnishMixedCampaignsAsArray()
+ {
+ return [
+ 0 =>
+ [
+ 'CampaignCode' => 220001,
+ 'Description' => 'ERÄMAKSU 3 KK KOROTON',
+ 'PaymentPlanType' => 1,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 0.33333,
+ 'InitialFee' => 0.0,
+ 'NotificationFee' => 0.0,
+ 'InterestRatePercent' => 0.0,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 50.0,
+ 'ToAmount' => 1000.0,
+ ],
+ 1 =>
+ [
+ 'CampaignCode' => 220003,
+ 'Description' => 'ERÄMAKSU 3 KK, 9.8%',
+ 'PaymentPlanType' => 0,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 0.33879,
+ 'InitialFee' => 19.9,
+ 'NotificationFee' => 8.9,
+ 'InterestRatePercent' => 9.8,
+ 'NumberOfInterestFreeMonths' => 0,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 50.0,
+ 'ToAmount' => 1000.0,
+ ],
+ 2 =>
+ [
+ 'CampaignCode' => 220006,
+ 'Description' => 'ERÄMAKSU 6 KK, 9.8%',
+ 'PaymentPlanType' => 0,
+ 'ContractLengthInMonths' => 6,
+ 'MonthlyAnnuityFactor' => 0.17146,
+ 'InitialFee' => 19.9,
+ 'NotificationFee' => 8.9,
+ 'InterestRatePercent' => 9.8,
+ 'NumberOfInterestFreeMonths' => 0,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 50.0,
+ 'ToAmount' => 1000.0,
+ ],
+ 3 =>
+ [
+ 'CampaignCode' => 220012,
+ 'Description' => 'ERÄMAKSU 12 KK 9.8%',
+ 'PaymentPlanType' => 0,
+ 'ContractLengthInMonths' => 12,
+ 'MonthlyAnnuityFactor' => 0.08782,
+ 'InitialFee' => 29.9,
+ 'NotificationFee' => 8.9,
+ 'InterestRatePercent' => 9.8,
+ 'NumberOfInterestFreeMonths' => 0,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 50.0,
+ 'ToAmount' => 1000.0,
+ ],
+ 4 =>
+ [
+ 'CampaignCode' => 220024,
+ 'Description' => 'ERÄMAKSU 24 KK, 9.8',
+ 'PaymentPlanType' => 0,
+ 'ContractLengthInMonths' => 24,
+ 'MonthlyAnnuityFactor' => 0.04605,
+ 'InitialFee' => 29.9,
+ 'NotificationFee' => 8.9,
+ 'InterestRatePercent' => 9.8,
+ 'NumberOfInterestFreeMonths' => 0,
+ 'NumberOfPaymentFreeMonths' => 0,
+ 'FromAmount' => 50.0,
+ 'ToAmount' => 1000.0,
+ ],
+ 5 =>
+ [
+ 'CampaignCode' => 220002,
+ 'Description' => 'OSTA NYT, MAKSA 3 KK PÄÄSTÄ',
+ 'PaymentPlanType' => 2,
+ 'ContractLengthInMonths' => 3,
+ 'MonthlyAnnuityFactor' => 1,
+ 'InitialFee' => 0,
+ 'NotificationFee' => 3.95,
+ 'InterestRatePercent' => 0,
+ 'NumberOfInterestFreeMonths' => 3,
+ 'NumberOfPaymentFreeMonths' => 3,
+ 'FromAmount' => 50.0,
+ 'ToAmount' => 5000.0,
+ ],
+ ];
+ }
+
+ function test_InterestAndAmortizationFreePaymentPlanCalculator_getTotalAmountToPay()
+ {
+ $campaign = $this->getInterestAndAmortizationFreeCampaign();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign[0]);
+ $this->assertEquals(11229, $totalAmount);
+ }
+
+ function test_InterestAndAmortizationFreePaymentPlanCalculator_getTotalAmountToPayAsArray()
+ {
+ $campaign = $this->getInterestAndAmortizationFreeCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign);
+ $this->assertEquals(11229, $totalAmount);
+ }
+
+ function test_InterestAndAmortizationFreePaymentPlanCalculator_getTotalAmountToPayWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaign = $this->getFinnishInterestAndAmortizationFreeCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign);
+ $this->assertEquals(103.95, $totalAmount);
+ }
+
+ function test_InterestAndAmortizationFreePaymentPlanCalculator_getMonthlyAmountToPay()
+ {
+ $campaign = $this->getInterestAndAmortizationFreeCampaign();
+ $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign[0]);
+ $this->assertEquals(11229, $totalAmount);
+ }
+
+ function test_InterestAndAmortizationFreePaymentPlanCalculator_getMonthlyAmountToPayAsArray()
+ {
+ $campaign = $this->getInterestAndAmortizationFreeCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign);
+ $this->assertEquals(11229, $totalAmount);
+ }
+
+ function test_InterestAndAmortizationFreePaymentPlanCalculator_getMonthlyAmountToPayWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaign = $this->getFinnishInterestAndAmortizationFreeCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign);
+ $this->assertEquals(103.95, $totalAmount);
+ }
+
+ function test_InterestAndAmortizationFreePaymentPlanCalculator_getEffectiveInterestRate()
+ {
+ $campaign = $this->getInterestAndAmortizationFreeCampaign();
+ $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign[0]);
+ $this->assertEquals(1.04, $totalAmount);
+ }
+
+ function test_InterestAndAmortizationFreePaymentPlanCalculator_getEffectiveInterestRateAsArray()
+ {
+ $campaign = $this->getInterestAndAmortizationFreeCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign);
+ $this->assertEquals(1.04, $totalAmount);
+ }
+
+ function test_InterestAndAmortizationFreePaymentPlanCalculator_getEffectiveInterestRateWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaign = $this->getFinnishInterestAndAmortizationFreeCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign, 2);
+ $this->assertEquals(16.77, $totalAmount);
+ }
+
+ function test_InterestFreePaymentPlanCalculator_getTotalAmountToPay()
+ {
+ $campaign = $this->getInterestFreeCampaign();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign[0]);
+ $this->assertEquals(11915, $totalAmount);
+ }
+
+ function test_InterestFreePaymentPlanCalculator_getTotalAmountToPayWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaign = $this->getFinnishInterestFreeCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign, 2);
+ $this->assertEquals(100, $totalAmount);
+ }
+
+ function test_InterestFreePaymentPlanCalculator_getMonthlyAmountToPay()
+ {
+ $campaign = $this->getInterestFreeCampaign();
+ $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign[0]);
+ $this->assertEquals(993, $totalAmount);
+ }
+
+ function test_InterestFreePaymentPlanCalculator_getMonthlyAmountToPayWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaign = $this->getFinnishStandardCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign, 2);
+ $this->assertEquals(20.17, $totalAmount);
+ }
+
+ function test_InterestFreePaymentPlanCalculator_getEffectiveInterestRate()
+ {
+ $campaign = $this->getInterestFreeCampaign();
+ $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign[0]);
+ $this->assertEquals(12.44, $totalAmount);
+ }
+
+ function test_InterestFreePaymentPlanCalculator_getEffectiveInterestRateWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaign = $this->getFinnishInterestFreeCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign, 2);
+ $this->assertEquals(0, $totalAmount);
+ }
+
+ function test_StandardPaymentPlanCalculator_getTotalAmountToPay()
+ {
+ $campaign = $this->getStandardCampaign();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign[0]);
+ $this->assertEquals(18067, $totalAmount);
+ }
+
+ function test_StandardPaymentPlanCalculator_getTotalAmountToPayWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaign = $this->getFinnishStandardCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign, 2);
+ $this->assertEquals(242.09, $totalAmount);
+ }
+
+ function test_StandardPaymentPlanCalculator_getMonthlyAmountToPay()
+ {
+ $campaign = $this->getStandardCampaign();
+ $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign[0]);
+ $this->assertEquals(317, $totalAmount);
+ }
+
+ function test_StandardPaymentPlanCalculator_getMonthlyAmountToPayWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaign = $this->getFinnishStandardCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPay($this->price, $campaign, 2);
+ $this->assertEquals(20.17, $totalAmount);
+ }
+
+ function test_StandardPaymentPlanCalculator_getEffectiveInterestRate()
+ {
+ $campaign = $this->getStandardCampaign();
+ $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign[0]);
+ $this->assertEquals(21.33, $totalAmount);
+ }
+
+ function test_StandardPaymentPlanCalculator_getEffectiveInterestRateWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaign = $this->getFinnishStandardCampaignAsArray();
+ $totalAmount = PaymentPlanCalculator::getEffectiveInterestRate($this->price, $campaign, 2);
+ $this->assertEquals(898.33, $totalAmount);
+ }
+
+ function test_PaymentPlanCalculator_getTotalAmountToPayFromCampaigns()
+ {
+ $campaigns = $this->getMixedCampaigns();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(18067, $totalAmount[0]['totalAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[1]['totalAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[2]['totalAmountToPay']);
+ $this->assertEquals(11229, $totalAmount[3]['totalAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[4]['totalAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[5]['totalAmountToPay']);
+ $this->assertEquals(11915, $totalAmount[6]['totalAmountToPay']);
+ $this->assertEquals(12792, $totalAmount[7]['totalAmountToPay']);
+ $this->assertEquals(13781, $totalAmount[8]['totalAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getMonthlyAmountToPayFromCampaigns()
+ {
+ $campaigns = $this->getMixedCampaigns();
+ $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(317, $totalAmount[0]['monthlyAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[1]['monthlyAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[2]['monthlyAmountToPay']);
+ $this->assertEquals(11229, $totalAmount[3]['monthlyAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[4]['monthlyAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[5]['monthlyAmountToPay']);
+ $this->assertEquals(993, $totalAmount[6]['monthlyAmountToPay']);
+ $this->assertEquals(1066, $totalAmount[7]['monthlyAmountToPay']);
+ $this->assertEquals(574, $totalAmount[8]['monthlyAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getEffectiveInterestRateFromCampaigns()
+ {
+ $campaigns = $this->getMixedCampaigns();
+ $totalAmount = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(21.33, $totalAmount[0]['effectiveInterestRate']);
+ $this->assertEquals(0, $totalAmount[1]['effectiveInterestRate']);
+ $this->assertEquals(0, $totalAmount[2]['effectiveInterestRate']);
+ $this->assertEquals(1.04, $totalAmount[3]['effectiveInterestRate']);
+ $this->assertEquals(0, $totalAmount[4]['effectiveInterestRate']);
+ $this->assertEquals(0, $totalAmount[5]['effectiveInterestRate']);
+ $this->assertEquals(12.44, $totalAmount[6]['effectiveInterestRate']);
+ $this->assertEquals(28.44, $totalAmount[7]['effectiveInterestRate']);
+ $this->assertEquals(23.65, $totalAmount[8]['effectiveInterestRate']);
+ }
+
+ function test_PaymentPlanCalculator_getTotalAmountToPayFromCampaignsAsArray()
+ {
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(18067, $totalAmount[0]['TotalAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[1]['TotalAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[2]['TotalAmountToPay']);
+ $this->assertEquals(11229, $totalAmount[3]['TotalAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[4]['TotalAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[5]['TotalAmountToPay']);
+ $this->assertEquals(11915, $totalAmount[6]['TotalAmountToPay']);
+ $this->assertEquals(12792, $totalAmount[7]['TotalAmountToPay']);
+ $this->assertEquals(13781, $totalAmount[8]['TotalAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getTotalAmountToPayFromCampaignsAsArray_ReturnOnlyValidCampaigns()
+ {
+ $this->price = 100;
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(1, count($totalAmount));
+ }
+
+ function test_PaymentPlanCalculator_getTotalAmountToPayFromCampaignsAsArray_ReturnZeroCampaigns()
+ {
+ $this->price = 1;
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(0, count($totalAmount));
+ }
+
+ function test_PaymentPlanCalculator_getMonthlyAmountToPayFromCampaignsAsArray()
+ {
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(317, $totalAmount[0]['MonthlyAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[1]['MonthlyAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[2]['MonthlyAmountToPay']);
+ $this->assertEquals(11229, $totalAmount[3]['MonthlyAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[4]['MonthlyAmountToPay']);
+ $this->assertEquals(11200, $totalAmount[5]['MonthlyAmountToPay']);
+ $this->assertEquals(993, $totalAmount[6]['MonthlyAmountToPay']);
+ $this->assertEquals(1066, $totalAmount[7]['MonthlyAmountToPay']);
+ $this->assertEquals(574, $totalAmount[8]['MonthlyAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getMonthlyAmountToPayFromCampaignsAsArray_ReturnOnlyValidCampaigns()
+ {
+ $this->price = 100;
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $monthlyAmount = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(1, count($monthlyAmount));
+ }
+
+ function test_PaymentPlanCalculator_getMonthlyAmountToPayFromCampaignsAsArray_ReturnZeroCampaigns()
+ {
+ $this->price = 1;
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $monthlyAmount = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(0, count($monthlyAmount));
+ }
+
+ function test_PaymentPlanCalculator_getEffectiveInterestRateFromCampaignsAsArray()
+ {
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $totalAmount = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(21.33, $totalAmount[0]['EffectiveInterestRate']);
+ $this->assertEquals(0, $totalAmount[1]['EffectiveInterestRate']);
+ $this->assertEquals(0, $totalAmount[2]['EffectiveInterestRate']);
+ $this->assertEquals(1.04, $totalAmount[3]['EffectiveInterestRate']);
+ $this->assertEquals(0, $totalAmount[4]['EffectiveInterestRate']);
+ $this->assertEquals(0, $totalAmount[5]['EffectiveInterestRate']);
+ $this->assertEquals(12.44, $totalAmount[6]['EffectiveInterestRate']);
+ $this->assertEquals(28.44, $totalAmount[7]['EffectiveInterestRate']);
+ $this->assertEquals(23.65, $totalAmount[8]['EffectiveInterestRate']);
+ }
+
+ function test_PaymentPlanCalculator_getEffectiveInterestRateFromCampaignsAsArray_ReturnOnlyValidCampaigns()
+ {
+ $this->price = 100;
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $effectiveInterestRate = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(1, count($effectiveInterestRate));
+ }
+
+ function test_PaymentPlanCalculator_getEffectiveInterestRateFromCampaignsAsArray_ReturnZeroCampaigns()
+ {
+ $this->price = 1;
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $effectiveInterestRate = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(0, count($effectiveInterestRate));
+ }
+
+ function test_PaymentPlanCalculator_getTotalAmountToPayFromCampaignsWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaigns = $this->getFinnishMixedCampaignsAsArray();
+ $totalAmount = PaymentPlanCalculator::getTotalAmountToPayFromCampaigns($this->price, $campaigns, 2);
+ $this->assertEquals(100, $totalAmount[0]['TotalAmountToPay']);
+ $this->assertEquals(148.24, $totalAmount[1]['TotalAmountToPay']);
+ $this->assertEquals(176.18, $totalAmount[2]['TotalAmountToPay']);
+ $this->assertEquals(242.09, $totalAmount[3]['TotalAmountToPay']);
+ $this->assertEquals(354.03, $totalAmount[4]['TotalAmountToPay']);
+ $this->assertEquals(103.95, $totalAmount[5]['TotalAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getMonthlyAmountToPayFromCampaignsWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaigns = $this->getFinnishMixedCampaignsAsArray();
+ $totalAmount = PaymentPlanCalculator::getMonthlyAmountToPayFromCampaigns($this->price, $campaigns, 2);
+ $this->assertEquals(33.33, $totalAmount[0]['MonthlyAmountToPay']);
+ $this->assertEquals(49.41, $totalAmount[1]['MonthlyAmountToPay']);
+ $this->assertEquals(29.36, $totalAmount[2]['MonthlyAmountToPay']);
+ $this->assertEquals(20.17, $totalAmount[3]['MonthlyAmountToPay']);
+ $this->assertEquals(14.75, $totalAmount[4]['MonthlyAmountToPay']);
+ $this->assertEquals(103.95, $totalAmount[5]['MonthlyAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getEffectiveInterestRateFromCampaignsWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaigns = $this->getFinnishMixedCampaignsAsArray();
+ $totalAmount = PaymentPlanCalculator::getEffectiveInterestRateFromCampaigns($this->price, $campaigns, 2);
+ $this->assertEquals(0, $totalAmount[0]['EffectiveInterestRate']);
+ $this->assertEquals(1300.39, $totalAmount[1]['EffectiveInterestRate']);
+ $this->assertEquals(930.86, $totalAmount[2]['EffectiveInterestRate']);
+ $this->assertEquals(898.33, $totalAmount[3]['EffectiveInterestRate']);
+ $this->assertEquals(611.36, $totalAmount[4]['EffectiveInterestRate']);
+ $this->assertEquals(16.77, $totalAmount[5]['EffectiveInterestRate']);
+ }
+
+ function test_PaymentPlanCalculator_getAllCalculations()
+ {
+ $campaign = $this->getStandardCampaign();
+ $campaign = PaymentPlanCalculator::getAllCalculations($this->price, $campaign[0]);
+ $this->assertEquals(21.33, $campaign['effectiveInterestRate']);
+ $this->assertEquals(317, $campaign['monthlyAmountToPay']);
+ $this->assertEquals(18067, $campaign['totalAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getAllCalculationsAsArray()
+ {
+ $campaign = $this->getStandardCampaignAsArray();
+ $campaign = PaymentPlanCalculator::getAllCalculations($this->price, $campaign);
+ $this->assertEquals(21.33, $campaign['EffectiveInterestRate']);
+ $this->assertEquals(317, $campaign['MonthlyAmountToPay']);
+ $this->assertEquals(18067, $campaign['TotalAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getAllCalculationsAsArrayWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaign = $this->getFinnishStandardCampaignAsArray();
+ $campaign = PaymentPlanCalculator::getAllCalculations($this->price, $campaign, 2);
+ $this->assertEquals(898.33, $campaign['EffectiveInterestRate']);
+ $this->assertEquals(20.17, $campaign['MonthlyAmountToPay']);
+ $this->assertEquals(242.09, $campaign['TotalAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getAllCalculationsFromCampaigns()
+ {
+ $campaigns = $this->getMixedCampaigns();
+ $campaigns = PaymentPlanCalculator::getAllCalculationsFromCampaigns($this->price, $campaigns);
+
+ // Campaign 0
+ $this->assertEquals(21.33, $campaigns[0]['effectiveInterestRate']);
+ $this->assertEquals(317, $campaigns[0]['monthlyAmountToPay']);
+ $this->assertEquals(18067, $campaigns[0]['totalAmountToPay']);
+
+ // Campaign 1
+ $this->assertEquals(0, $campaigns[1]['effectiveInterestRate']);
+ $this->assertEquals(11200, $campaigns[1]['monthlyAmountToPay']);
+ $this->assertEquals(11200, $campaigns[1]['totalAmountToPay']);
+
+ // Campaign 2
+ $this->assertEquals(0, $campaigns[2]['effectiveInterestRate']);
+ $this->assertEquals(11200, $campaigns[2]['monthlyAmountToPay']);
+ $this->assertEquals(11200, $campaigns[2]['totalAmountToPay']);
+
+ // Campaign 3
+ $this->assertEquals(1.04, $campaigns[3]['effectiveInterestRate']);
+ $this->assertEquals(11229, $campaigns[3]['monthlyAmountToPay']);
+ $this->assertEquals(11229, $campaigns[3]['totalAmountToPay']);
+
+ // Campaign 4
+ $this->assertEquals(0, $campaigns[4]['effectiveInterestRate']);
+ $this->assertEquals(11200, $campaigns[4]['monthlyAmountToPay']);
+ $this->assertEquals(11200, $campaigns[4]['totalAmountToPay']);
+
+ // Campaign 5
+ $this->assertEquals(0, $campaigns[5]['effectiveInterestRate']);
+ $this->assertEquals(11200, $campaigns[5]['monthlyAmountToPay']);
+ $this->assertEquals(11200, $campaigns[5]['totalAmountToPay']);
+
+ // Campaign 6
+ $this->assertEquals(12.44, $campaigns[6]['effectiveInterestRate']);
+ $this->assertEquals(993, $campaigns[6]['monthlyAmountToPay']);
+ $this->assertEquals(11915, $campaigns[6]['totalAmountToPay']);
+
+ // Campaign 7
+ $this->assertEquals(28.44, $campaigns[7]['effectiveInterestRate']);
+ $this->assertEquals(1066, $campaigns[7]['monthlyAmountToPay']);
+ $this->assertEquals(12792, $campaigns[7]['totalAmountToPay']);
+
+ // Campaign 8
+ $this->assertEquals(23.65, $campaigns[8]['effectiveInterestRate']);
+ $this->assertEquals(574, $campaigns[8]['monthlyAmountToPay']);
+ $this->assertEquals(13781, $campaigns[8]['totalAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getAllCalculationsFromCampaignsAsArray()
+ {
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $campaigns = PaymentPlanCalculator::getAllCalculationsFromCampaigns($this->price, $campaigns);
+
+ // Campaign 0
+ $this->assertEquals(21.33, $campaigns[0]['EffectiveInterestRate']);
+ $this->assertEquals(317, $campaigns[0]['MonthlyAmountToPay']);
+ $this->assertEquals(18067, $campaigns[0]['TotalAmountToPay']);
+
+ // Campaign 1
+ $this->assertEquals(0, $campaigns[1]['EffectiveInterestRate']);
+ $this->assertEquals(11200, $campaigns[1]['MonthlyAmountToPay']);
+ $this->assertEquals(11200, $campaigns[1]['TotalAmountToPay']);
+
+ // Campaign 2
+ $this->assertEquals(0, $campaigns[2]['EffectiveInterestRate']);
+ $this->assertEquals(11200, $campaigns[2]['MonthlyAmountToPay']);
+ $this->assertEquals(11200, $campaigns[2]['TotalAmountToPay']);
+
+ // Campaign 3
+ $this->assertEquals(1.04, $campaigns[3]['EffectiveInterestRate']);
+ $this->assertEquals(11229, $campaigns[3]['MonthlyAmountToPay']);
+ $this->assertEquals(11229, $campaigns[3]['TotalAmountToPay']);
+
+ // Campaign 4
+ $this->assertEquals(0, $campaigns[4]['EffectiveInterestRate']);
+ $this->assertEquals(11200, $campaigns[4]['MonthlyAmountToPay']);
+ $this->assertEquals(11200, $campaigns[4]['TotalAmountToPay']);
+
+ // Campaign 5
+ $this->assertEquals(0, $campaigns[5]['EffectiveInterestRate']);
+ $this->assertEquals(11200, $campaigns[5]['MonthlyAmountToPay']);
+ $this->assertEquals(11200, $campaigns[5]['TotalAmountToPay']);
+
+ // Campaign 6
+ $this->assertEquals(12.44, $campaigns[6]['EffectiveInterestRate']);
+ $this->assertEquals(993, $campaigns[6]['MonthlyAmountToPay']);
+ $this->assertEquals(11915, $campaigns[6]['TotalAmountToPay']);
+
+ // Campaign 7
+ $this->assertEquals(28.44, $campaigns[7]['EffectiveInterestRate']);
+ $this->assertEquals(1066, $campaigns[7]['MonthlyAmountToPay']);
+ $this->assertEquals(12792, $campaigns[7]['TotalAmountToPay']);
+
+ // Campaign 8
+ $this->assertEquals(23.65, $campaigns[8]['EffectiveInterestRate']);
+ $this->assertEquals(574, $campaigns[8]['MonthlyAmountToPay']);
+ $this->assertEquals(13781, $campaigns[8]['TotalAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_getAllCalculationsFromCampaignsAsArray_ReturnOnlyValidCampaigns()
+ {
+ $this->price = 100;
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $allCalculations = PaymentPlanCalculator::getAllCalculationsFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(1, count($allCalculations));
+ }
+
+ function test_PaymentPlanCalculator_getAllCalculationsFromCampaignsAsArray_ReturnZeroCampaigns()
+ {
+ $this->price = 1;
+ $campaigns = $this->getMixedCampaignsAsArray();
+ $allCalculations = PaymentPlanCalculator::getAllCalculationsFromCampaigns($this->price, $campaigns);
+ $this->assertEquals(0, count($allCalculations));
+ }
+
+ function test_PaymentPlanCalculator_getAllCalculationsFromCampaignsAsArrayWithFinnishCampaign()
+ {
+ $this->price = 100;
+ $campaigns = $this->getFinnishMixedCampaignsAsArray();
+ $campaigns = PaymentPlanCalculator::getAllCalculationsFromCampaigns($this->price, $campaigns, 2);
+
+ // Campaign 0
+ $this->assertEquals(0, $campaigns[0]['EffectiveInterestRate']);
+ $this->assertEquals(33.33, $campaigns[0]['MonthlyAmountToPay']);
+ $this->assertEquals(100, $campaigns[0]['TotalAmountToPay']);
+
+ // Campaign 1
+ $this->assertEquals(1300.39, $campaigns[1]['EffectiveInterestRate']);
+ $this->assertEquals(49.41, $campaigns[1]['MonthlyAmountToPay']);
+ $this->assertEquals(148.24, $campaigns[1]['TotalAmountToPay']);
+
+ // Campaign 2
+ $this->assertEquals(930.86, $campaigns[2]['EffectiveInterestRate']);
+ $this->assertEquals(29.36, $campaigns[2]['MonthlyAmountToPay']);
+ $this->assertEquals(176.18, $campaigns[2]['TotalAmountToPay']);
+
+ // Campaign 3
+ $this->assertEquals(898.33, $campaigns[3]['EffectiveInterestRate']);
+ $this->assertEquals(20.17, $campaigns[3]['MonthlyAmountToPay']);
+ $this->assertEquals(242.09, $campaigns[3]['TotalAmountToPay']);
+
+ // Campaign 4
+ $this->assertEquals(611.36, $campaigns[4]['EffectiveInterestRate']);
+ $this->assertEquals(14.75, $campaigns[4]['MonthlyAmountToPay']);
+ $this->assertEquals(354.03, $campaigns[4]['TotalAmountToPay']);
+
+ // Campaign 5
+ $this->assertEquals(16.77, $campaigns[5]['EffectiveInterestRate']);
+ $this->assertEquals(103.95, $campaigns[5]['MonthlyAmountToPay']);
+ $this->assertEquals(103.95, $campaigns[5]['TotalAmountToPay']);
+ }
+
+ function test_PaymentPlanCalculator_convertFromCheckoutArray()
+ {
+ $arr = $this->getInterestAndAmortizationFreeCampaignAsArray();
+ $class = new ReflectionClass('\Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator');
+ $method = $class->getMethod('convertFromCheckoutArray');
+ $method->setAccessible(true);
+ $convertedArray = $method->invoke(null, $arr);
+
+ $this->assertEquals(array_key_exists("campaignCode", $convertedArray), true);
+ $this->assertEquals(array_key_exists("description", $convertedArray), true);
+ $this->assertEquals(array_key_exists("toAmount", $convertedArray), true);
+ $this->assertEquals($convertedArray['checkout'], true);
+ $this->assertEquals($convertedArray['paymentPlanType'], "InterestAndAmortizationFree");
+ }
+
+ function test_PaymentPlanCalculator_convertToCheckoutArray()
+ {
+ $arr = $this->getInterestAndAmortizationFreeCampaignAsArray();
+ $class = new ReflectionClass('\Svea\WebPay\Helper\PaymentPlanHelper\PaymentPlanCalculator');
+ $methodConvertFrom = $class->getMethod('convertFromCheckoutArray');
+ $methodConvertFrom->setAccessible(true);
+ $convertedFromCheckoutArray = $methodConvertFrom->invoke(null, $arr);
+
+ $methodConvertTo = $class->getMethod('convertToCheckoutArray');
+ $methodConvertTo->setAccessible(true);
+ $convertedToCheckoutArray = $methodConvertTo->invoke(null, $convertedFromCheckoutArray);
+
+ $this->assertEquals(array_key_exists("CampaignCode", $convertedToCheckoutArray), true);
+ $this->assertEquals($convertedToCheckoutArray['PaymentPlanType'], 2);
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage paymentPlanType not recognized
+ */
+ function test_InterestAndAmortizationFreePaymentPlanCalculator_getTotalAmountToPay_invalid_paymentPlanType()
+ {
+ $campaign = $this->getStandardCampaign();
+ $campaign['paymentPlanType'] = "invalid";
+ PaymentPlanCalculator::getTotalAmountToPay($this->price, $campaign);
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage Monthly payment can not be below 0
+ */
+ function test_EffectiveInterestRateCalculator_invalid_monthlyPayment()
+ {
+ $calculator = new EffectiveInterestRateCalculator(10000.00);
+
+ $calculator->calculate(10000, 100, -1, 12, 0);
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage Contract length must be at least 1 month
+ */
+ function test_EffectiveInterestRateCalculator_invalid_contractLength()
+ {
+ $calculator = new EffectiveInterestRateCalculator(10000.00);
+
+ $calculator->calculate(10000, 100, 100, 0, 0);
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/Helper/SplitAddressTest.php b/test/UnitTest/Helper/SplitAddressTest.php
index 67ec91b8..475e3be9 100644
--- a/test/UnitTest/Helper/SplitAddressTest.php
+++ b/test/UnitTest/Helper/SplitAddressTest.php
@@ -7,340 +7,340 @@
class SplitAddressTest extends \PHPUnit\Framework\TestCase
{
- function debugPrintSplitStreetAddressOutput($address)
- {
- $PRINT_TO_CONSOLE = false; // set to true to get debug output
+ function debugPrintSplitStreetAddressOutput($address)
+ {
+ $PRINT_TO_CONSOLE = false; // set to true to get debug output
- // you may force netbeans output window encoding to use utf-8 by adding
- // netbeans_default_options= "... -J-Dfile.encoding=UTF-8"
- // to /etc/netbeans.conf
- if ($PRINT_TO_CONSOLE) {
- print_r("\naddress[0]: " . (isset($address[0]) ? '"' . $address[0] . '"' : "not set") . "\n");
- print_r("address[1]: " . (isset($address[1]) ? '"' . $address[1] . '"' : "not set") . "\n");
- print_r("address[2]: " . (isset($address[2]) ? '"' . $address[2] . '"' : "not set") . "\n");
- }
- }
+ // you may force netbeans output window encoding to use utf-8 by adding
+ // netbeans_default_options= "... -J-Dfile.encoding=UTF-8"
+ // to /etc/netbeans.conf
+ if ($PRINT_TO_CONSOLE) {
+ print_r("\naddress[0]: " . (isset($address[0]) ? '"' . $address[0] . '"' : "not set") . "\n");
+ print_r("address[1]: " . (isset($address[1]) ? '"' . $address[1] . '"' : "not set") . "\n");
+ print_r("address[2]: " . (isset($address[2]) ? '"' . $address[2] . '"' : "not set") . "\n");
+ }
+ }
- // splitStreetAddress
- function testStreet()
- {
- $address = Helper::splitStreetAddress("Street");
+ // splitStreetAddress
+ function testStreet()
+ {
+ $address = Helper::splitStreetAddress("Street");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Street", $address[1]);
- $this->assertEquals("", $address[2]);
- }
+ $this->assertEquals("Street", $address[1]);
+ $this->assertEquals("", $address[2]);
+ }
- function testStreet_10()
- {
- $address = Helper::splitStreetAddress("Street 10");
+ function testStreet_10()
+ {
+ $address = Helper::splitStreetAddress("Street 10");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Street", $address[1]);
- $this->assertEquals("10", $address[2]);
- }
+ $this->assertEquals("Street", $address[1]);
+ $this->assertEquals("10", $address[2]);
+ }
- function testUnicodeTwoCodePointGraphemeFirstInStreetnameStreet_10()
- {
- $cc = $this->unicodeChar2string("\u006F\u0308"); // cc for combined codepoints
- $address = Helper::splitStreetAddress($cc . "Street 10");
+ function testUnicodeTwoCodePointGraphemeFirstInStreetnameStreet_10()
+ {
+ $cc = $this->unicodeChar2string("\u006F\u0308"); // cc for combined codepoints
+ $address = Helper::splitStreetAddress($cc . "Street 10");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals($cc . "Street", $address[1]);
- $this->assertEquals("10", $address[2]);
- }
+ $this->assertEquals($cc . "Street", $address[1]);
+ $this->assertEquals("10", $address[2]);
+ }
- function testUnicodeTwoCodePointGraphemeLastInStreetnameStreet_10()
- {
- $cc = $this->unicodeChar2string("\u006F\u0308"); // cc for combined codepoints
- $address = Helper::splitStreetAddress("Street" . $cc . " 10");
+ function testUnicodeTwoCodePointGraphemeLastInStreetnameStreet_10()
+ {
+ $cc = $this->unicodeChar2string("\u006F\u0308"); // cc for combined codepoints
+ $address = Helper::splitStreetAddress("Street" . $cc . " 10");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Street" . $cc, $address[1]);
- $this->assertEquals("10", $address[2]);
- }
+ $this->assertEquals("Street" . $cc, $address[1]);
+ $this->assertEquals("10", $address[2]);
+ }
- function testUnicodeTwoCodePointGraphemeInsideStreetnameStreet_10()
- {
- $cc = $this->unicodeChar2string("\u006F\u0308"); // cc for combined codepoints
- $address = Helper::splitStreetAddress("Str" . $cc . "eet" . " 10");
+ function testUnicodeTwoCodePointGraphemeInsideStreetnameStreet_10()
+ {
+ $cc = $this->unicodeChar2string("\u006F\u0308"); // cc for combined codepoints
+ $address = Helper::splitStreetAddress("Str" . $cc . "eet" . " 10");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Str" . $cc . "eet", $address[1]);
- $this->assertEquals("10", $address[2]);
- }
+ $this->assertEquals("Str" . $cc . "eet", $address[1]);
+ $this->assertEquals("10", $address[2]);
+ }
- function test_Street_10()
- {
- $address = Helper::splitStreetAddress(" Street 10 ");
+ function test_Street_10()
+ {
+ $address = Helper::splitStreetAddress(" Street 10 ");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Street", $address[1]);
- $this->assertEquals("10", $address[2]);
- }
+ $this->assertEquals("Street", $address[1]);
+ $this->assertEquals("10", $address[2]);
+ }
- function testStreet_10bis()
- {
- $address = Helper::splitStreetAddress("Street 10bis");
+ function testStreet_10bis()
+ {
+ $address = Helper::splitStreetAddress("Street 10bis");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Street", $address[1]);
- $this->assertEquals("10bis", $address[2]);
- }
+ $this->assertEquals("Street", $address[1]);
+ $this->assertEquals("10bis", $address[2]);
+ }
- function testStreet_10_bis()
- {
- $address = Helper::splitStreetAddress("Street 10 bis");
+ function testStreet_10_bis()
+ {
+ $address = Helper::splitStreetAddress("Street 10 bis");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Street", $address[1]);
- $this->assertEquals("10 bis", $address[2]);
- }
+ $this->assertEquals("Street", $address[1]);
+ $this->assertEquals("10 bis", $address[2]);
+ }
- function testStreet___10__bis()
- {
- $address = Helper::splitStreetAddress("Street 10 bis");
+ function testStreet___10__bis()
+ {
+ $address = Helper::splitStreetAddress("Street 10 bis");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Street", $address[1]);
- $this->assertEquals("10 bis", $address[2]);
- }
+ $this->assertEquals("Street", $address[1]);
+ $this->assertEquals("10 bis", $address[2]);
+ }
- function test3rd_street_11()
- {
- $address = Helper::splitStreetAddress("3rd street 11");
+ function test3rd_street_11()
+ {
+ $address = Helper::splitStreetAddress("3rd street 11");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("3rd street", $address[1]);
- $this->assertEquals("11", $address[2]);
- }
+ $this->assertEquals("3rd street", $address[1]);
+ $this->assertEquals("11", $address[2]);
+ }
- function test3rd_street_11bis()
- {
- $address = Helper::splitStreetAddress("3rd street 11bis");
+ function test3rd_street_11bis()
+ {
+ $address = Helper::splitStreetAddress("3rd street 11bis");
- $this->debugPrintSplitStreetAddressOutput($address);
+ $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("3rd street", $address[1]);
- $this->assertEquals("11bis", $address[2]);
- }
+ $this->assertEquals("3rd street", $address[1]);
+ $this->assertEquals("11bis", $address[2]);
+ }
- function test3rd_street_11_bis()
- {
- $address = Helper::splitStreetAddress("3rd street 11 bis");
-
- $this->debugPrintSplitStreetAddressOutput($address);
-
- $this->assertEquals("3rd street", $address[1]);
- $this->assertEquals("11 bis", $address[2]);
- }
-
- function test_3rd___street___11___bis()
- {
- $address = Helper::splitStreetAddress(" 3rd street 11 bis ");
-
- $this->debugPrintSplitStreetAddressOutput($address);
-
- $this->assertEquals("3rd street", $address[1]);
- $this->assertEquals("11 bis", $address[2]);
- }
-
- function testSankt_Larsgatan_1_Lgh_1003()
- {
- $address = Helper::splitStreetAddress("Sankt Larsgatan 1 Lgh 1003");
-
- $this->debugPrintSplitStreetAddressOutput($address);
-
- $this->assertEquals("Sankt Larsgatan", $address[1]);
- $this->assertEquals("1 Lgh 1003", $address[2]);
- }
-
- //Svea testperson DK
- function testGate_42_23()
- {
- $address = Helper::splitStreetAddress("Gate 42 23");
-
- $this->debugPrintSplitStreetAddressOutput($address);
-
- $this->assertEquals("Gate", $address[1]);
- $this->assertEquals("42 23", $address[2]); // ok, see testInvoiceRequestNLAcceptedWithDoubleHousenumber
- }
-
- // decided not to implement this case, as it looks like a corner case w/"street 42" and housenumber 23 after
-// //Svea testperson DK
-// function testGate_42_23(){
-// $address = Helper::splitStreetAddress("Gate 42 23");
-// $this->assertEquals( "Gate 42", $address[1]);
-// $this->assertEquals( "23", $address[2]);
-// }
-
- //Interpuncation in streetaddress
- function testStreetcomma_10()
- {
- $address = Helper::splitStreetAddress("Street, 10");
-
- $this->debugPrintSplitStreetAddressOutput($address);
-
- $this->assertEquals("Street", $address[1]);
- $this->assertEquals("10", $address[2]);
- }
- // decided not to implement this case, as it looks like a corner case
-// function testGate_42comma_23(){
-// $address = Helper::splitStreetAddress("Gate 4, 23");
-// $this->assertEquals( "Gate 42", $address[1]);
-// $this->assertEquals( "23", $address[2]);
-// }
-// function testSankt_Larsgatan_1comma_Lgh_1003(){
-// $address = Helper::splitStreetAddress("Sankt Larsgatan 1, Lgh 1003");
-// $this->assertEquals( "Sankt Larsgatan", $address[1]);
-// $this->assertEquals( "1 Lgh 1003", $address[2]);
-// }
-
- //Examples given by getzenned.nl
- function testSingelstraat_10()
- {
- $address = Helper::splitStreetAddress("Singelstraat 10");
-
- $this->debugPrintSplitStreetAddressOutput($address);
-
- $this->assertEquals("Singelstraat", $address[1]);
- $this->assertEquals("10", $address[2]);
- }
-
- function test3e_laan_12()
- {
- $address = Helper::splitStreetAddress("3e laan 12");
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("3e laan", $address[1]);
- $this->assertEquals("12", $address[2]);
- }
-
- function testHeeregracht_12bis()
- {
- $address = Helper::splitStreetAddress("Heeregracht 12bis");
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Heeregracht", $address[1]);
- $this->assertEquals("12bis", $address[2]);
- }
-
- //International characters
- function testÖnskevägen_10()
- {
- $address = Helper::splitStreetAddress("Önskevägen 10");
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Önskevägen", $address[1]);
- $this->assertEquals("10", $address[2]);
- }
-
- function testÅlandshav_10å()
- {
- $address = Helper::splitStreetAddress("Ålandshav 10å");
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Ålandshav", $address[1]);
- $this->assertEquals("10å", $address[2]);
- }
-
- function testÅväg_änna_10()
- {
- $address = Helper::splitStreetAddress("Åväg änna 10");
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("Åväg änna", $address[1]);
- $this->assertEquals("10", $address[2]);
- }
-
- function testÄÅÖåäöÜü()
- {
- $address = Helper::splitStreetAddress("ÄÅÖåäöÜü");
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("ÄÅÖåäöÜü", $address[1]);
- }
-
- function testÄÅÆÖØÜßäåæöøü_10()
- {
- $address = Helper::splitStreetAddress("ÄÅÆÖØÜßäåæöøü 10");
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals("ÄÅÆÖØÜßäåæöøü", $address[1]);
- $this->assertEquals("10", $address[2]);
- }
-
- function unicodeChar2string($unicode_char)
- {
- return json_decode('"' . $unicode_char . '"');
- }
-
- function testBaselineCharacterMatches()
- {
- $charstring = "ö";
-
- $prefix = "abc";
- $suffix = "xyz";
- $number = "10";
- $addressString = $prefix . $charstring . $suffix . " " . $number;
-
- $this->assertEquals("ö", $charstring);
- $this->assertEquals(2, strlen($charstring));
-
- $address = Helper::splitStreetAddress($addressString);
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals($prefix . $charstring . $suffix, $address[1]);
- $this->assertEquals($number, $address[2]);
- }
-
- // test unicode combined characters (i.e. U+00F6 (ö) as two code points -- U+006F (o) + U+0308 (¨), combining diaeresis)
- function testNoCombinedCharacterMatches()
- {
-
- $charstring = $this->unicodeChar2string("\u00F6");
-
- $prefix = "abc";
- $suffix = "xyz";
- $number = "10";
- $addressString = $prefix . $charstring . $suffix . " " . $number;
-
- $this->assertEquals("ö", $charstring);
- $this->assertEquals(2, strlen($charstring));
-
- $address = Helper::splitStreetAddress($addressString);
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals($prefix . $charstring . $suffix, $address[1]);
- $this->assertEquals($number, $address[2]);
- }
-
- // test unicode combined characters (i.e. U+00F6 (ö) as two code points -- U+006F (o) + U+0308 (¨), combining diaeresis)
- function testCombinedCharacterMatches()
- {
-
- $charstring = $this->unicodeChar2string("\u006F\u0308");
-
- $prefix = "abc";
- $suffix = "xyz";
- $number = "10";
- $addressString = $prefix . $charstring . $suffix . " " . $number;
-
- $this->assertNotEquals("ö", $charstring); // Not same as "ö", but prints the same to console using utf-8 output
- $this->assertEquals(3, strlen($charstring)); // Grapheme "ö" is represented by two code points => string w/length 3
-
- $address = Helper::splitStreetAddress($addressString);
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals($prefix . $charstring . $suffix, $address[1]);
- $this->assertEquals($number, $address[2]);
- }
-
- function testUnicodeRegExExample()
- {
- $match = preg_match("/([\x{06F0}-\x{06F9}]+)/u", '۱۲۳۴۵۶۷۸۹۰', $address);
- $this->debugPrintSplitStreetAddressOutput($address);
- $this->assertEquals(1, $match);
- }
+ function test3rd_street_11_bis()
+ {
+ $address = Helper::splitStreetAddress("3rd street 11 bis");
+
+ $this->debugPrintSplitStreetAddressOutput($address);
+
+ $this->assertEquals("3rd street", $address[1]);
+ $this->assertEquals("11 bis", $address[2]);
+ }
+
+ function test_3rd___street___11___bis()
+ {
+ $address = Helper::splitStreetAddress(" 3rd street 11 bis ");
+
+ $this->debugPrintSplitStreetAddressOutput($address);
+
+ $this->assertEquals("3rd street", $address[1]);
+ $this->assertEquals("11 bis", $address[2]);
+ }
+
+ function testSankt_Larsgatan_1_Lgh_1003()
+ {
+ $address = Helper::splitStreetAddress("Sankt Larsgatan 1 Lgh 1003");
+
+ $this->debugPrintSplitStreetAddressOutput($address);
+
+ $this->assertEquals("Sankt Larsgatan", $address[1]);
+ $this->assertEquals("1 Lgh 1003", $address[2]);
+ }
+
+ //Svea testperson DK
+ function testGate_42_23()
+ {
+ $address = Helper::splitStreetAddress("Gate 42 23");
+
+ $this->debugPrintSplitStreetAddressOutput($address);
+
+ $this->assertEquals("Gate", $address[1]);
+ $this->assertEquals("42 23", $address[2]); // ok, see testInvoiceRequestNLAcceptedWithDoubleHousenumber
+ }
+
+ // decided not to implement this case, as it looks like a corner case w/"street 42" and housenumber 23 after
+// //Svea testperson DK
+// function testGate_42_23(){
+// $address = Helper::splitStreetAddress("Gate 42 23");
+// $this->assertEquals( "Gate 42", $address[1]);
+// $this->assertEquals( "23", $address[2]);
+// }
+
+ //Interpuncation in streetaddress
+ function testStreetcomma_10()
+ {
+ $address = Helper::splitStreetAddress("Street, 10");
+
+ $this->debugPrintSplitStreetAddressOutput($address);
+
+ $this->assertEquals("Street", $address[1]);
+ $this->assertEquals("10", $address[2]);
+ }
+ // decided not to implement this case, as it looks like a corner case
+// function testGate_42comma_23(){
+// $address = Helper::splitStreetAddress("Gate 4, 23");
+// $this->assertEquals( "Gate 42", $address[1]);
+// $this->assertEquals( "23", $address[2]);
+// }
+// function testSankt_Larsgatan_1comma_Lgh_1003(){
+// $address = Helper::splitStreetAddress("Sankt Larsgatan 1, Lgh 1003");
+// $this->assertEquals( "Sankt Larsgatan", $address[1]);
+// $this->assertEquals( "1 Lgh 1003", $address[2]);
+// }
+
+ //Examples given by getzenned.nl
+ function testSingelstraat_10()
+ {
+ $address = Helper::splitStreetAddress("Singelstraat 10");
+
+ $this->debugPrintSplitStreetAddressOutput($address);
+
+ $this->assertEquals("Singelstraat", $address[1]);
+ $this->assertEquals("10", $address[2]);
+ }
+
+ function test3e_laan_12()
+ {
+ $address = Helper::splitStreetAddress("3e laan 12");
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals("3e laan", $address[1]);
+ $this->assertEquals("12", $address[2]);
+ }
+
+ function testHeeregracht_12bis()
+ {
+ $address = Helper::splitStreetAddress("Heeregracht 12bis");
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals("Heeregracht", $address[1]);
+ $this->assertEquals("12bis", $address[2]);
+ }
+
+ //International characters
+ function testÖnskevägen_10()
+ {
+ $address = Helper::splitStreetAddress("Önskevägen 10");
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals("Önskevägen", $address[1]);
+ $this->assertEquals("10", $address[2]);
+ }
+
+ function testÅlandshav_10å()
+ {
+ $address = Helper::splitStreetAddress("Ålandshav 10å");
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals("Ålandshav", $address[1]);
+ $this->assertEquals("10å", $address[2]);
+ }
+
+ function testÅväg_änna_10()
+ {
+ $address = Helper::splitStreetAddress("Åväg änna 10");
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals("Åväg änna", $address[1]);
+ $this->assertEquals("10", $address[2]);
+ }
+
+ function testÄÅÖåäöÜü()
+ {
+ $address = Helper::splitStreetAddress("ÄÅÖåäöÜü");
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals("ÄÅÖåäöÜü", $address[1]);
+ }
+
+ function testÄÅÆÖØÜßäåæöøü_10()
+ {
+ $address = Helper::splitStreetAddress("ÄÅÆÖØÜßäåæöøü 10");
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals("ÄÅÆÖØÜßäåæöøü", $address[1]);
+ $this->assertEquals("10", $address[2]);
+ }
+
+ function unicodeChar2string($unicode_char)
+ {
+ return json_decode('"' . $unicode_char . '"');
+ }
+
+ function testBaselineCharacterMatches()
+ {
+ $charstring = "ö";
+
+ $prefix = "abc";
+ $suffix = "xyz";
+ $number = "10";
+ $addressString = $prefix . $charstring . $suffix . " " . $number;
+
+ $this->assertEquals("ö", $charstring);
+ $this->assertEquals(2, strlen($charstring));
+
+ $address = Helper::splitStreetAddress($addressString);
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals($prefix . $charstring . $suffix, $address[1]);
+ $this->assertEquals($number, $address[2]);
+ }
+
+ // test unicode combined characters (i.e. U+00F6 (ö) as two code points -- U+006F (o) + U+0308 (¨), combining diaeresis)
+ function testNoCombinedCharacterMatches()
+ {
+
+ $charstring = $this->unicodeChar2string("\u00F6");
+
+ $prefix = "abc";
+ $suffix = "xyz";
+ $number = "10";
+ $addressString = $prefix . $charstring . $suffix . " " . $number;
+
+ $this->assertEquals("ö", $charstring);
+ $this->assertEquals(2, strlen($charstring));
+
+ $address = Helper::splitStreetAddress($addressString);
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals($prefix . $charstring . $suffix, $address[1]);
+ $this->assertEquals($number, $address[2]);
+ }
+
+ // test unicode combined characters (i.e. U+00F6 (ö) as two code points -- U+006F (o) + U+0308 (¨), combining diaeresis)
+ function testCombinedCharacterMatches()
+ {
+
+ $charstring = $this->unicodeChar2string("\u006F\u0308");
+
+ $prefix = "abc";
+ $suffix = "xyz";
+ $number = "10";
+ $addressString = $prefix . $charstring . $suffix . " " . $number;
+
+ $this->assertNotEquals("ö", $charstring); // Not same as "ö", but prints the same to console using utf-8 output
+ $this->assertEquals(3, strlen($charstring)); // Grapheme "ö" is represented by two code points => string w/length 3
+
+ $address = Helper::splitStreetAddress($addressString);
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals($prefix . $charstring . $suffix, $address[1]);
+ $this->assertEquals($number, $address[2]);
+ }
+
+ function testUnicodeRegExExample()
+ {
+ $match = preg_match("/([\x{06F0}-\x{06F9}]+)/u", '۱۲۳۴۵۶۷۸۹۰', $address);
+ $this->debugPrintSplitStreetAddressOutput($address);
+ $this->assertEquals(1, $match);
+ }
}
diff --git a/test/UnitTest/HostedService/HandleOrder/AnnulTransactionTest.php b/test/UnitTest/HostedService/HandleOrder/AnnulTransactionTest.php
index a676ce28..61954c65 100644
--- a/test/UnitTest/HostedService/HandleOrder/AnnulTransactionTest.php
+++ b/test/UnitTest/HostedService/HandleOrder/AnnulTransactionTest.php
@@ -15,82 +15,80 @@
class AnnulTransactionTest extends \PHPUnit\Framework\TestCase
{
- protected $configObject;
- protected $annulObject;
+ protected $configObject;
+ protected $annulObject;
- // fixture, run once before each test method
- protected function setUp()
- {
- $this->configObject = ConfigurationService::getDefaultConfig();
- $this->annulObject = new AnnulTransaction($this->configObject);
- }
+ // fixture, run once before each test method
+ protected function setUp()
+ {
+ $this->configObject = ConfigurationService::getDefaultConfig();
+ $this->annulObject = new AnnulTransaction($this->configObject);
+ }
- // test methods
- function test_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\AnnulTransaction", $this->annulObject);
- $this->assertEquals("annul", \PHPUnit\Framework\Assert::readAttribute($this->annulObject, 'method'));
- }
+ // test methods
+ function test_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\AnnulTransaction", $this->annulObject);
+ $this->assertEquals("annul", \PHPUnit\Framework\Assert::readAttribute($this->annulObject, 'method'));
+ }
- function test_prepareRequest_array_contains_mac_merchantid_message()
- {
+ function test_prepareRequest_array_contains_mac_merchantid_message()
+ {
- // set up annulTransaction object & get request form
- $transactionId = 987654;
- $this->annulObject->transactionId = $transactionId;
+ // set up annulTransaction object & get request form
+ $transactionId = 987654;
+ $this->annulObject->transactionId = $transactionId;
- $countryCode = "SE";
- $this->annulObject->countryCode = $countryCode;
+ $countryCode = "SE";
+ $this->annulObject->countryCode = $countryCode;
- $form = $this->annulObject->prepareRequest();
+ $form = $this->annulObject->prepareRequest();
- // prepared request is message (base64 encoded), merchantid, mac
- $this->assertTrue(isset($form['merchantid']));
- $this->assertTrue(isset($form['mac']));
- $this->assertTrue(isset($form['message']));
- }
+ // prepared request is message (base64 encoded), merchantid, mac
+ $this->assertTrue(isset($form['merchantid']));
+ $this->assertTrue(isset($form['mac']));
+ $this->assertTrue(isset($form['message']));
+ }
- function test_prepareRequest_request_has_correct_merchantid_mac_and_annulTransaction_request_message_contents()
- {
+ function test_prepareRequest_request_has_correct_merchantid_mac_and_annulTransaction_request_message_contents()
+ {
- // set up creditTransaction object & get request form
- $transactionId = 987654;
- $this->annulObject->transactionId = $transactionId;
+ // set up creditTransaction object & get request form
+ $transactionId = 987654;
+ $this->annulObject->transactionId = $transactionId;
- $countryCode = "SE";
- $this->annulObject->countryCode = $countryCode;
+ $countryCode = "SE";
+ $this->annulObject->countryCode = $countryCode;
- $form = $this->annulObject->prepareRequest();
+ $form = $this->annulObject->prepareRequest();
- // get our merchantid & secret
- $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ // get our merchantid & secret
+ $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- // check mechantid
- $this->assertEquals($merchantid, urldecode($form['merchantid']));
+ // check mechantid
+ $this->assertEquals($merchantid, urldecode($form['merchantid']));
- // check valid mac
- $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
+ // check valid mac
+ $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
- // check annul request message contents
- $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
+ // check annul request message contents
+ $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
- $this->assertEquals("annul", $xmlMessage->getName()); // root node
- $this->assertEquals((string)$transactionId, $xmlMessage->transactionid);
- }
+ $this->assertEquals("annul", $xmlMessage->getName()); // root node
+ $this->assertEquals((string)$transactionId, $xmlMessage->transactionid);
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.
- */
- function test_prepareRequest_missing_transactionId_throws_exception()
- {
- $countryCode = "SE";
- $this->annulObject->countryCode = $countryCode;
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.
+ */
+ function test_prepareRequest_missing_transactionId_throws_exception()
+ {
+ $countryCode = "SE";
+ $this->annulObject->countryCode = $countryCode;
- $form = $this->annulObject->prepareRequest();
- }
+ $form = $this->annulObject->prepareRequest();
+ }
}
-
-?>
diff --git a/test/UnitTest/HostedService/HandleOrder/CancelRecurSubscriptionTest.php b/test/UnitTest/HostedService/HandleOrder/CancelRecurSubscriptionTest.php
index 6c40878d..ee07dae4 100644
--- a/test/UnitTest/HostedService/HandleOrder/CancelRecurSubscriptionTest.php
+++ b/test/UnitTest/HostedService/HandleOrder/CancelRecurSubscriptionTest.php
@@ -16,86 +16,86 @@
class CancelRecurSubscriptionTest extends \PHPUnit\Framework\TestCase
{
- protected $configObject;
- protected $cancelRecurSubscriptionObject;
-
- // fixture, run once before each test method
- protected function setUp()
- {
- $this->configObject = ConfigurationService::getDefaultConfig();
- $this->cancelRecurSubscriptionObject = new CancelRecurSubscription($this->configObject);
- }
-
- // test methods
- function test_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CancelRecurSubscription", $this->cancelRecurSubscriptionObject);
- $this->assertEquals("cancelrecursubscription", \PHPUnit\Framework\Assert::readAttribute($this->cancelRecurSubscriptionObject, 'method'));
- }
-
- function test_setCountryCode()
- {
- $countryCode = "SE";
- $this->cancelRecurSubscriptionObject->countryCode = $countryCode;
- $this->assertEquals($countryCode, \PHPUnit\Framework\Assert::readAttribute($this->cancelRecurSubscriptionObject, 'countryCode'));
- }
-
- function test_prepareRequest_array_contains_mac_merchantid_message()
- {
-
- // set up annulTransaction object & get request form
- $subscriptionId = 334455;
- $this->cancelRecurSubscriptionObject->subscriptionId = $subscriptionId;
-
- $countryCode = "SE";
- $this->cancelRecurSubscriptionObject->countryCode = $countryCode;
-
- $form = $this->cancelRecurSubscriptionObject->prepareRequest();
-
- // prepared request is message (base64 encoded), merchantid, mac
- $this->assertTrue(isset($form['merchantid']));
- $this->assertTrue(isset($form['mac']));
- $this->assertTrue(isset($form['message']));
- }
-
- function test_prepareRequest_request_has_correct_merchantid_mac_and_querytransactionid_request_message_contents()
- {
-
- // set up creditTransaction object & get request form
- $subscriptionId = "334455";
- $this->cancelRecurSubscriptionObject->subscriptionId = $subscriptionId;
-
- $countryCode = "SE";
- $this->cancelRecurSubscriptionObject->countryCode = $countryCode;
-
- $form = $this->cancelRecurSubscriptionObject->prepareRequest();
-
- // get our merchantid & secret
- $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
-
- // check mechantid
- $this->assertEquals($merchantid, urldecode($form['merchantid']));
-
- // check valid mac
- $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
-
- // check annul request message contents
- $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
-
- $this->assertEquals("cancelrecursubscription", $xmlMessage->getName()); // root node
- $this->assertEquals((string)$subscriptionId, $xmlMessage->subscriptionid);
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : subscriptionId is required. Use function setSubscriptionId() with the subscriptionId from the createOrder response.
- */
- function test_prepareRequest_missing_transactionId_throws_exception()
- {
- $countryCode = "SE";
- $this->cancelRecurSubscriptionObject->countryCode = $countryCode;
-
- $form = $this->cancelRecurSubscriptionObject->prepareRequest();
- }
+ protected $configObject;
+ protected $cancelRecurSubscriptionObject;
+
+ // fixture, run once before each test method
+ protected function setUp()
+ {
+ $this->configObject = ConfigurationService::getDefaultConfig();
+ $this->cancelRecurSubscriptionObject = new CancelRecurSubscription($this->configObject);
+ }
+
+ // test methods
+ function test_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CancelRecurSubscription", $this->cancelRecurSubscriptionObject);
+ $this->assertEquals("cancelrecursubscription", \PHPUnit\Framework\Assert::readAttribute($this->cancelRecurSubscriptionObject, 'method'));
+ }
+
+ function test_setCountryCode()
+ {
+ $countryCode = "SE";
+ $this->cancelRecurSubscriptionObject->countryCode = $countryCode;
+ $this->assertEquals($countryCode, \PHPUnit\Framework\Assert::readAttribute($this->cancelRecurSubscriptionObject, 'countryCode'));
+ }
+
+ function test_prepareRequest_array_contains_mac_merchantid_message()
+ {
+
+ // set up annulTransaction object & get request form
+ $subscriptionId = 334455;
+ $this->cancelRecurSubscriptionObject->subscriptionId = $subscriptionId;
+
+ $countryCode = "SE";
+ $this->cancelRecurSubscriptionObject->countryCode = $countryCode;
+
+ $form = $this->cancelRecurSubscriptionObject->prepareRequest();
+
+ // prepared request is message (base64 encoded), merchantid, mac
+ $this->assertTrue(isset($form['merchantid']));
+ $this->assertTrue(isset($form['mac']));
+ $this->assertTrue(isset($form['message']));
+ }
+
+ function test_prepareRequest_request_has_correct_merchantid_mac_and_querytransactionid_request_message_contents()
+ {
+
+ // set up creditTransaction object & get request form
+ $subscriptionId = "334455";
+ $this->cancelRecurSubscriptionObject->subscriptionId = $subscriptionId;
+
+ $countryCode = "SE";
+ $this->cancelRecurSubscriptionObject->countryCode = $countryCode;
+
+ $form = $this->cancelRecurSubscriptionObject->prepareRequest();
+
+ // get our merchantid & secret
+ $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+
+ // check mechantid
+ $this->assertEquals($merchantid, urldecode($form['merchantid']));
+
+ // check valid mac
+ $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
+
+ // check annul request message contents
+ $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
+
+ $this->assertEquals("cancelrecursubscription", $xmlMessage->getName()); // root node
+ $this->assertEquals((string)$subscriptionId, $xmlMessage->subscriptionid);
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : subscriptionId is required. Use function setSubscriptionId() with the subscriptionId from the createOrder response.
+ */
+ function test_prepareRequest_missing_transactionId_throws_exception()
+ {
+ $countryCode = "SE";
+ $this->cancelRecurSubscriptionObject->countryCode = $countryCode;
+
+ $form = $this->cancelRecurSubscriptionObject->prepareRequest();
+ }
}
diff --git a/test/UnitTest/HostedService/HandleOrder/ConfirmTransactionTest.php b/test/UnitTest/HostedService/HandleOrder/ConfirmTransactionTest.php
index 7222c0f9..b4d5ee23 100644
--- a/test/UnitTest/HostedService/HandleOrder/ConfirmTransactionTest.php
+++ b/test/UnitTest/HostedService/HandleOrder/ConfirmTransactionTest.php
@@ -15,122 +15,120 @@
class ConfirmTransactionTest extends \PHPUnit\Framework\TestCase
{
- protected $configObject;
- protected $confirmObject;
+ protected $configObject;
+ protected $confirmObject;
- // fixture, run once before each test method
- protected function setUp()
- {
- $this->configObject = ConfigurationService::getDefaultConfig();
- $this->confirmObject = new ConfirmTransaction($this->configObject);
- }
-
- // test methods
- function test_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\ConfirmTransaction", $this->confirmObject);
- $this->assertEquals("confirm", \PHPUnit\Framework\Assert::readAttribute($this->confirmObject, 'method'));
- }
-
- function test_prepareRequest_array_contains_mac_merchantid_message()
- {
-
- // set up confirmTransaction object & get request form
- $transactionId = 987654;
- $this->confirmObject->transactionId = $transactionId;
-
- $captureDate = "2014-03-21";
- $this->confirmObject->captureDate = $captureDate;
-
- $countryCode = "SE";
- $this->confirmObject->countryCode = $countryCode;
-
- $form = $this->confirmObject->prepareRequest();
-
- // prepared request is message (base64 encoded), merchantid, mac
- $this->assertTrue(isset($form['merchantid']));
- $this->assertTrue(isset($form['mac']));
- $this->assertTrue(isset($form['message']));
- }
-
- function test_prepareRequest_has_correct_merchantid_mac_and_confirmTransaction_request_message_contents()
- {
-
- // set up confirmTransaction object & get request form
- $transactionId = 987654;
- $this->confirmObject->transactionId = $transactionId;
-
- $captureDate = "2014-03-21";
- $this->confirmObject->captureDate = $captureDate;
-
- $countryCode = "SE";
- $this->confirmObject->countryCode = $countryCode;
-
- $form = $this->confirmObject->prepareRequest();
-
- // get our merchantid & secret
- $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
-
- // check mechantid
- $this->assertEquals($merchantid, urldecode($form['merchantid']));
-
- // check valid mac
- $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
-
- // check confirm request message contents
- $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
-
- $this->assertEquals("confirm", $xmlMessage->getName()); // root node
- $this->assertEquals((string)$transactionId, $xmlMessage->transactionid);
- $this->assertEquals((string)$captureDate, $xmlMessage->capturedate);
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.
- */
- function test_prepareRequest_missing_transactionId_throws_exception()
- {
- $captureDate = "2014-03-21";
- $this->confirmObject->captureDate = $captureDate;
-
- $countryCode = "SE";
- $this->confirmObject->countryCode = $countryCode;
-
- $form = $this->confirmObject->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : captureDate is required. Use function setCaptureDate().
- */
- function test_prepareRequest_missing_captureDate_throws_exception()
- {
- $transactionId = 987654;
- $this->confirmObject->transactionId = $transactionId;
-
- $countryCode = "SE";
- $this->confirmObject->countryCode = $countryCode;
-
- $form = $this->confirmObject->prepareRequest();
- }
-
- // really a test of parent class HostedRequest countryCode requirement...
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : CountryCode is required. Use function setCountryCode().
- */
- function test_prepareRequest_missing_countryCode_throws_exception()
- {
- $transactionId = 987654;
- $this->confirmObject->transactionId = $transactionId;
-
- $captureDate = "2014-03-21";
- $this->confirmObject->captureDate = $captureDate;
+ // fixture, run once before each test method
+ protected function setUp()
+ {
+ $this->configObject = ConfigurationService::getDefaultConfig();
+ $this->confirmObject = new ConfirmTransaction($this->configObject);
+ }
+
+ // test methods
+ function test_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\ConfirmTransaction", $this->confirmObject);
+ $this->assertEquals("confirm", \PHPUnit\Framework\Assert::readAttribute($this->confirmObject, 'method'));
+ }
+
+ function test_prepareRequest_array_contains_mac_merchantid_message()
+ {
+
+ // set up confirmTransaction object & get request form
+ $transactionId = 987654;
+ $this->confirmObject->transactionId = $transactionId;
+
+ $captureDate = "2014-03-21";
+ $this->confirmObject->captureDate = $captureDate;
+
+ $countryCode = "SE";
+ $this->confirmObject->countryCode = $countryCode;
+
+ $form = $this->confirmObject->prepareRequest();
+
+ // prepared request is message (base64 encoded), merchantid, mac
+ $this->assertTrue(isset($form['merchantid']));
+ $this->assertTrue(isset($form['mac']));
+ $this->assertTrue(isset($form['message']));
+ }
+
+ function test_prepareRequest_has_correct_merchantid_mac_and_confirmTransaction_request_message_contents()
+ {
+
+ // set up confirmTransaction object & get request form
+ $transactionId = 987654;
+ $this->confirmObject->transactionId = $transactionId;
+
+ $captureDate = "2014-03-21";
+ $this->confirmObject->captureDate = $captureDate;
+
+ $countryCode = "SE";
+ $this->confirmObject->countryCode = $countryCode;
+
+ $form = $this->confirmObject->prepareRequest();
+
+ // get our merchantid & secret
+ $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+
+ // check mechantid
+ $this->assertEquals($merchantid, urldecode($form['merchantid']));
+
+ // check valid mac
+ $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
+
+ // check confirm request message contents
+ $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
+
+ $this->assertEquals("confirm", $xmlMessage->getName()); // root node
+ $this->assertEquals((string)$transactionId, $xmlMessage->transactionid);
+ $this->assertEquals((string)$captureDate, $xmlMessage->capturedate);
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.
+ */
+ function test_prepareRequest_missing_transactionId_throws_exception()
+ {
+ $captureDate = "2014-03-21";
+ $this->confirmObject->captureDate = $captureDate;
+
+ $countryCode = "SE";
+ $this->confirmObject->countryCode = $countryCode;
+
+ $form = $this->confirmObject->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : captureDate is required. Use function setCaptureDate().
+ */
+ function test_prepareRequest_missing_captureDate_throws_exception()
+ {
+ $transactionId = 987654;
+ $this->confirmObject->transactionId = $transactionId;
+
+ $countryCode = "SE";
+ $this->confirmObject->countryCode = $countryCode;
+
+ $form = $this->confirmObject->prepareRequest();
+ }
+
+ // really a test of parent class HostedRequest countryCode requirement...
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : CountryCode is required. Use function setCountryCode().
+ */
+ function test_prepareRequest_missing_countryCode_throws_exception()
+ {
+ $transactionId = 987654;
+ $this->confirmObject->transactionId = $transactionId;
+
+ $captureDate = "2014-03-21";
+ $this->confirmObject->captureDate = $captureDate;
- $form = $this->confirmObject->prepareRequest();
- }
+ $form = $this->confirmObject->prepareRequest();
+ }
}
-
-?>
diff --git a/test/UnitTest/HostedService/HandleOrder/CreditTransactionTest.php b/test/UnitTest/HostedService/HandleOrder/CreditTransactionTest.php
index 5a163f0e..d13d05c1 100644
--- a/test/UnitTest/HostedService/HandleOrder/CreditTransactionTest.php
+++ b/test/UnitTest/HostedService/HandleOrder/CreditTransactionTest.php
@@ -16,107 +16,105 @@
class CreditTransactionTest extends \PHPUnit\Framework\TestCase
{
- protected $configObject;
- protected $creditObject;
+ protected $configObject;
+ protected $creditObject;
- // fixture, run once before each test method
- protected function setUp()
- {
- $this->configObject = ConfigurationService::getDefaultConfig();
- $this->creditObject = new CreditTransaction($this->configObject);
- }
+ // fixture, run once before each test method
+ protected function setUp()
+ {
+ $this->configObject = ConfigurationService::getDefaultConfig();
+ $this->creditObject = new CreditTransaction($this->configObject);
+ }
- // test methods
- function test_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CreditTransaction", $this->creditObject);
- $this->assertEquals("credit", \PHPUnit\Framework\Assert::readAttribute($this->creditObject, 'method'));
- }
+ // test methods
+ function test_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\CreditTransaction", $this->creditObject);
+ $this->assertEquals("credit", \PHPUnit\Framework\Assert::readAttribute($this->creditObject, 'method'));
+ }
- function test_prepareRequest_array_contains_mac_merchantid_message()
- {
+ function test_prepareRequest_array_contains_mac_merchantid_message()
+ {
- // set up creditTransaction object & get request form
- $transactionId = 987654;
- $this->creditObject->transactionId = $transactionId;
+ // set up creditTransaction object & get request form
+ $transactionId = 987654;
+ $this->creditObject->transactionId = $transactionId;
- $creditAmount = 100;
- $this->creditObject->creditAmount = $creditAmount;
+ $creditAmount = 100;
+ $this->creditObject->creditAmount = $creditAmount;
- $countryCode = "SE";
- $this->creditObject->countryCode = $countryCode;
+ $countryCode = "SE";
+ $this->creditObject->countryCode = $countryCode;
- $form = $this->creditObject->prepareRequest();
+ $form = $this->creditObject->prepareRequest();
- // prepared request is message (base64 encoded), merchantid, mac
- $this->assertTrue(isset($form['merchantid']));
- $this->assertTrue(isset($form['mac']));
- $this->assertTrue(isset($form['message']));
- }
+ // prepared request is message (base64 encoded), merchantid, mac
+ $this->assertTrue(isset($form['merchantid']));
+ $this->assertTrue(isset($form['mac']));
+ $this->assertTrue(isset($form['message']));
+ }
- function test_prepareRequest_has_correct_merchantid_mac_and_creditTransaction_request_message_contents()
- {
+ function test_prepareRequest_has_correct_merchantid_mac_and_creditTransaction_request_message_contents()
+ {
- // set up creditTransaction object & get request form
- $transactionId = 987654;
- $this->creditObject->transactionId = $transactionId;
+ // set up creditTransaction object & get request form
+ $transactionId = 987654;
+ $this->creditObject->transactionId = $transactionId;
- $creditAmount = 100;
- $this->creditObject->creditAmount = $creditAmount;
+ $creditAmount = 100;
+ $this->creditObject->creditAmount = $creditAmount;
- $countryCode = "SE";
- $this->creditObject->countryCode = $countryCode;
+ $countryCode = "SE";
+ $this->creditObject->countryCode = $countryCode;
- $form = $this->creditObject->prepareRequest();
+ $form = $this->creditObject->prepareRequest();
- // get our merchantid & secret
- $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ // get our merchantid & secret
+ $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- // check mechantid
- $this->assertEquals($merchantid, urldecode($form['merchantid']));
+ // check mechantid
+ $this->assertEquals($merchantid, urldecode($form['merchantid']));
- // check valid mac
- $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
+ // check valid mac
+ $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
- // check credit request message contents
- $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
+ // check credit request message contents
+ $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
- $this->assertEquals("credit", $xmlMessage->getName()); // root node
- $this->assertEquals((string)$transactionId, $xmlMessage->transactionid);
- $this->assertEquals((string)$creditAmount, $xmlMessage->amounttocredit);
+ $this->assertEquals("credit", $xmlMessage->getName()); // root node
+ $this->assertEquals((string)$transactionId, $xmlMessage->transactionid);
+ $this->assertEquals((string)$creditAmount, $xmlMessage->amounttocredit);
- }
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.
- */
- function test_prepareRequest_missing_transactionId_throws_exception()
- {
- $creditAmount = 100;
- $this->creditObject->creditAmount = $creditAmount;
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.
+ */
+ function test_prepareRequest_missing_transactionId_throws_exception()
+ {
+ $creditAmount = 100;
+ $this->creditObject->creditAmount = $creditAmount;
- $countryCode = "SE";
- $this->creditObject->countryCode = $countryCode;
+ $countryCode = "SE";
+ $this->creditObject->countryCode = $countryCode;
- $form = $this->creditObject->prepareRequest();
- }
+ $form = $this->creditObject->prepareRequest();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : creditAmount is required. Use function setCreditAmount().
- */
- function test_prepareRequest_missing_creditAmount_throws_exception()
- {
- $transactionId = 987654;
- $this->creditObject->transactionId = $transactionId;
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : creditAmount is required. Use function setCreditAmount().
+ */
+ function test_prepareRequest_missing_creditAmount_throws_exception()
+ {
+ $transactionId = 987654;
+ $this->creditObject->transactionId = $transactionId;
- $countryCode = "SE";
- $this->creditObject->countryCode = $countryCode;
+ $countryCode = "SE";
+ $this->creditObject->countryCode = $countryCode;
- $form = $this->creditObject->prepareRequest();
- }
+ $form = $this->creditObject->prepareRequest();
+ }
}
-
-?>
diff --git a/test/UnitTest/HostedService/HandleOrder/ListPaymentMethodsTest.php b/test/UnitTest/HostedService/HandleOrder/ListPaymentMethodsTest.php
index 4f517093..a2b52674 100644
--- a/test/UnitTest/HostedService/HandleOrder/ListPaymentMethodsTest.php
+++ b/test/UnitTest/HostedService/HandleOrder/ListPaymentMethodsTest.php
@@ -16,62 +16,60 @@
class ListPaymentMethodsTest extends \PHPUnit\Framework\TestCase
{
- protected $configObject;
- protected $listpaymentmethodsObject;
+ protected $configObject;
+ protected $listpaymentmethodsObject;
- // fixture, run once before each test method
- protected function setUp()
- {
- $this->configObject = ConfigurationService::getDefaultConfig();
- $this->listpaymentmethodObject = new ListPaymentMethods($this->configObject);
- }
+ // fixture, run once before each test method
+ protected function setUp()
+ {
+ $this->configObject = ConfigurationService::getDefaultConfig();
+ $this->listpaymentmethodObject = new ListPaymentMethods($this->configObject);
+ }
- // test methods
- function test_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\ListPaymentMethods", $this->listpaymentmethodObject);
- $this->assertEquals("getpaymentmethods", \PHPUnit\Framework\Assert::readAttribute($this->listpaymentmethodObject, 'method'));
- }
+ // test methods
+ function test_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\ListPaymentMethods", $this->listpaymentmethodObject);
+ $this->assertEquals("getpaymentmethods", \PHPUnit\Framework\Assert::readAttribute($this->listpaymentmethodObject, 'method'));
+ }
- function test_prepareRequest_array_contains_mac_merchantid_message()
- {
+ function test_prepareRequest_array_contains_mac_merchantid_message()
+ {
- // set up ListPaymentMethods object & get request form
- $countryCode = "SE";
- $this->listpaymentmethodObject->countryCode = $countryCode;
+ // set up ListPaymentMethods object & get request form
+ $countryCode = "SE";
+ $this->listpaymentmethodObject->countryCode = $countryCode;
- $form = $this->listpaymentmethodObject->prepareRequest();
+ $form = $this->listpaymentmethodObject->prepareRequest();
- // prepared request is message (base64 encoded), merchantid, mac
- $this->assertTrue(isset($form['merchantid']));
- $this->assertTrue(isset($form['mac']));
- $this->assertTrue(isset($form['message']));
- }
+ // prepared request is message (base64 encoded), merchantid, mac
+ $this->assertTrue(isset($form['merchantid']));
+ $this->assertTrue(isset($form['mac']));
+ $this->assertTrue(isset($form['message']));
+ }
- function test_prepareRequest_request_has_correct_merchantid_mac_and_ListPaymentMethods_request_message_contents()
- {
+ function test_prepareRequest_request_has_correct_merchantid_mac_and_ListPaymentMethods_request_message_contents()
+ {
- $countryCode = "SE";
- $this->listpaymentmethodObject->countryCode = $countryCode;
+ $countryCode = "SE";
+ $this->listpaymentmethodObject->countryCode = $countryCode;
- $form = $this->listpaymentmethodObject->prepareRequest();
+ $form = $this->listpaymentmethodObject->prepareRequest();
- // get our merchantid & secret
- $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ // get our merchantid & secret
+ $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- // check mechantid
- $this->assertEquals($merchantid, urldecode($form['merchantid']));
+ // check mechantid
+ $this->assertEquals($merchantid, urldecode($form['merchantid']));
- // check valid mac
- $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
+ // check valid mac
+ $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
- // check request message contents
- $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
+ // check request message contents
+ $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
- $this->assertEquals("getpaymentmethods", $xmlMessage->getName()); // root node
- $this->assertEquals((string)$merchantid, $xmlMessage->merchantid);
- }
+ $this->assertEquals("getpaymentmethods", $xmlMessage->getName()); // root node
+ $this->assertEquals((string)$merchantid, $xmlMessage->merchantid);
+ }
}
-
-?>
diff --git a/test/UnitTest/HostedService/HandleOrder/LowerTransactionTest.php b/test/UnitTest/HostedService/HandleOrder/LowerTransactionTest.php
index 68e5309d..7d966a07 100644
--- a/test/UnitTest/HostedService/HandleOrder/LowerTransactionTest.php
+++ b/test/UnitTest/HostedService/HandleOrder/LowerTransactionTest.php
@@ -16,114 +16,112 @@
class LowerTransactionTest extends \PHPUnit\Framework\TestCase
{
- protected $configObject;
- protected $lowerTransactionObject;
-
- // fixture, run once before each test method
- protected function setUp()
- {
- $this->configObject = ConfigurationService::getDefaultConfig();
- $this->lowerTransactionObject = new LowerTransaction($this->configObject);
- }
-
- // test methods
- function test_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\LowerTransaction", $this->lowerTransactionObject);
- $this->assertEquals("loweramount", \PHPUnit\Framework\Assert::readAttribute($this->lowerTransactionObject, 'method'));
- }
-
- function test_setCountryCode()
- {
- $countryCode = "SE";
- $this->lowerTransactionObject->countryCode = $countryCode;
- $this->assertEquals($countryCode, \PHPUnit\Framework\Assert::readAttribute($this->lowerTransactionObject, 'countryCode'));
- }
-
- function test_prepareRequest_array_contains_mac_merchantid_message()
- {
-
- // set up lowerTransaction object & get request form
- $transactionId = 987654;
- $this->lowerTransactionObject->transactionId = $transactionId;
-
- $amountToLower = 100;
- $this->lowerTransactionObject->amountToLower = $amountToLower;
-
- $countryCode = "SE";
- $this->lowerTransactionObject->countryCode = $countryCode;
-
- $form = $this->lowerTransactionObject->prepareRequest();
-
- // prepared request is message (base64 encoded), merchantid, mac
- $this->assertTrue(isset($form['merchantid']));
- $this->assertTrue(isset($form['mac']));
- $this->assertTrue(isset($form['message']));
- }
-
- function test_prepareRequest_has_correct_merchantid_mac_and_lowerTransaction_request_message_contents()
- {
-
- // set up lowerTransaction object & get request form
- $transactionId = 987654;
- $this->lowerTransactionObject->transactionId = $transactionId;
-
- $amountToLower = 100;
- $this->lowerTransactionObject->amountToLower = $amountToLower;
-
- $countryCode = "SE";
- $this->lowerTransactionObject->countryCode = $countryCode;
-
- $form = $this->lowerTransactionObject->prepareRequest();
-
- // get our merchantid & secret
- $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
-
- // check mechantid
- $this->assertEquals($merchantid, urldecode($form['merchantid']));
-
- // check valid mac
- $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
-
- // check credit request message contents
- $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
-
- $this->assertEquals("loweramount", $xmlMessage->getName()); // root node
- $this->assertEquals((string)$transactionId, $xmlMessage->transactionid);
- $this->assertEquals((string)$amountToLower, $xmlMessage->amounttolower);
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.
- */
- function test_prepareRequest_missing_transactionId_throws_exception()
- {
- $amountToLower = 100;
- $this->lowerTransactionObject->amountToLower = $amountToLower;
-
- $countryCode = "SE";
- $this->lowerTransactionObject->countryCode = $countryCode;
-
- $form = $this->lowerTransactionObject->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : amountToLower is required. Use function setAmountToLower().
- */
- function test_prepareRequest_missing_amountToLower_throws_exception()
- {
- $transactionId = 987654;
- $this->lowerTransactionObject->transactionId = $transactionId;
+ protected $configObject;
+ protected $lowerTransactionObject;
+
+ // fixture, run once before each test method
+ protected function setUp()
+ {
+ $this->configObject = ConfigurationService::getDefaultConfig();
+ $this->lowerTransactionObject = new LowerTransaction($this->configObject);
+ }
+
+ // test methods
+ function test_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\LowerTransaction", $this->lowerTransactionObject);
+ $this->assertEquals("loweramount", \PHPUnit\Framework\Assert::readAttribute($this->lowerTransactionObject, 'method'));
+ }
+
+ function test_setCountryCode()
+ {
+ $countryCode = "SE";
+ $this->lowerTransactionObject->countryCode = $countryCode;
+ $this->assertEquals($countryCode, \PHPUnit\Framework\Assert::readAttribute($this->lowerTransactionObject, 'countryCode'));
+ }
+
+ function test_prepareRequest_array_contains_mac_merchantid_message()
+ {
+
+ // set up lowerTransaction object & get request form
+ $transactionId = 987654;
+ $this->lowerTransactionObject->transactionId = $transactionId;
+
+ $amountToLower = 100;
+ $this->lowerTransactionObject->amountToLower = $amountToLower;
+
+ $countryCode = "SE";
+ $this->lowerTransactionObject->countryCode = $countryCode;
+
+ $form = $this->lowerTransactionObject->prepareRequest();
+
+ // prepared request is message (base64 encoded), merchantid, mac
+ $this->assertTrue(isset($form['merchantid']));
+ $this->assertTrue(isset($form['mac']));
+ $this->assertTrue(isset($form['message']));
+ }
+
+ function test_prepareRequest_has_correct_merchantid_mac_and_lowerTransaction_request_message_contents()
+ {
+
+ // set up lowerTransaction object & get request form
+ $transactionId = 987654;
+ $this->lowerTransactionObject->transactionId = $transactionId;
+
+ $amountToLower = 100;
+ $this->lowerTransactionObject->amountToLower = $amountToLower;
+
+ $countryCode = "SE";
+ $this->lowerTransactionObject->countryCode = $countryCode;
+
+ $form = $this->lowerTransactionObject->prepareRequest();
+
+ // get our merchantid & secret
+ $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+
+ // check mechantid
+ $this->assertEquals($merchantid, urldecode($form['merchantid']));
+
+ // check valid mac
+ $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
+
+ // check credit request message contents
+ $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
+
+ $this->assertEquals("loweramount", $xmlMessage->getName()); // root node
+ $this->assertEquals((string)$transactionId, $xmlMessage->transactionid);
+ $this->assertEquals((string)$amountToLower, $xmlMessage->amounttolower);
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.
+ */
+ function test_prepareRequest_missing_transactionId_throws_exception()
+ {
+ $amountToLower = 100;
+ $this->lowerTransactionObject->amountToLower = $amountToLower;
+
+ $countryCode = "SE";
+ $this->lowerTransactionObject->countryCode = $countryCode;
+
+ $form = $this->lowerTransactionObject->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : amountToLower is required. Use function setAmountToLower().
+ */
+ function test_prepareRequest_missing_amountToLower_throws_exception()
+ {
+ $transactionId = 987654;
+ $this->lowerTransactionObject->transactionId = $transactionId;
- $countryCode = "SE";
- $this->lowerTransactionObject->countryCode = $countryCode;
-
- $form = $this->lowerTransactionObject->prepareRequest();
- }
+ $countryCode = "SE";
+ $this->lowerTransactionObject->countryCode = $countryCode;
+
+ $form = $this->lowerTransactionObject->prepareRequest();
+ }
}
-
-?>
diff --git a/test/UnitTest/HostedService/HandleOrder/QueryTransactionResponseTest.php b/test/UnitTest/HostedService/HandleOrder/QueryTransactionResponseTest.php
index 43cb1688..98914dd1 100644
--- a/test/UnitTest/HostedService/HandleOrder/QueryTransactionResponseTest.php
+++ b/test/UnitTest/HostedService/HandleOrder/QueryTransactionResponseTest.php
@@ -11,47 +11,47 @@
class QueryTransactionResponseTest extends \PHPUnit\Framework\TestCase
{
- function test_calculateVatPercentFromVatAndAmount_returns_correct_vatpercent_if_transactions_contains_negative_row()
- {
- $queryTransactionResponse = new QueryTransactionResponse("", "", "");
+ function test_calculateVatPercentFromVatAndAmount_returns_correct_vatpercent_if_transactions_contains_negative_row()
+ {
+ $queryTransactionResponse = new QueryTransactionResponse("", "", "");
- $test = $queryTransactionResponse->calculateVatPercentFromVatAndAmount("-1252", "-6262");
+ $test = $queryTransactionResponse->calculateVatPercentFromVatAndAmount("-1252", "-6262");
- $this->assertEquals("25.00", $test);
- }
+ $this->assertEquals("25.00", $test);
+ }
- function test_calculateVatPercentFromVatAndAmount_returns_correct_vatpercent_if_transactions_contains_positive_row()
- {
- $queryTransactionResponse = new QueryTransactionResponse("", "", "");
+ function test_calculateVatPercentFromVatAndAmount_returns_correct_vatpercent_if_transactions_contains_positive_row()
+ {
+ $queryTransactionResponse = new QueryTransactionResponse("", "", "");
- $test = $queryTransactionResponse->calculateVatPercentFromVatAndAmount("1252", "6262");
+ $test = $queryTransactionResponse->calculateVatPercentFromVatAndAmount("1252", "6262");
- $this->assertEquals("25.00", $test);
- }
+ $this->assertEquals("25.00", $test);
+ }
- function test_calculateVatPercentFromVatAndAmount_returns_correct_vatpercent_if_transactions_contains_zero_amount_row()
- {
- $queryTransactionResponse = new QueryTransactionResponse("", "", "");
+ function test_calculateVatPercentFromVatAndAmount_returns_correct_vatpercent_if_transactions_contains_zero_amount_row()
+ {
+ $queryTransactionResponse = new QueryTransactionResponse("", "", "");
- $test = $queryTransactionResponse->calculateVatPercentFromVatAndAmount("0", "0");
+ $test = $queryTransactionResponse->calculateVatPercentFromVatAndAmount("0", "0");
- $this->assertEquals("0.00", $test);
- }
+ $this->assertEquals("0.00", $test);
+ }
- function test_QueryTransactionResponse_contains_amountincvat_and_amountexvat()
- {
- $message = new \SimpleXMLElement("PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz48cmVzcG9uc2U+PHRyYW5zYWN0aW9uIGlkPSI3MTU2NDgiPjxjdXN0b21lcnJlZm5vPjQ5MzcyMDU8L2N1c3RvbWVycmVmbm8+PG1lcmNoYW50aWQ+MTEzMDwvbWVyY2hhbnRpZD48c3RhdHVzPlNVQ0NFU1M8L3N0YXR1cz48YW1vdW50PjU2MzYzPC9hbW91bnQ+PGN1cnJlbmN5PlNFSzwvY3VycmVuY3k+PHZhdD4xMTI3MzwvdmF0PjxjYXB0dXJlZGFtb3VudD41NjM2MzwvY2FwdHVyZWRhbW91bnQ+PGF1dGhvcml6ZWRhbW91bnQ+NTYzNjM8L2F1dGhvcml6ZWRhbW91bnQ+PGNyZWF0ZWQ+MjAxOS0wOS0wOSAxNzowOToyOS43NTc8L2NyZWF0ZWQ+PGNyZWRpdHN0YXR1cz5DUkVERkFJTDwvY3JlZGl0c3RhdHVzPjxjcmVkaXRlZGFtb3VudD41NjM2MjwvY3JlZGl0ZWRhbW91bnQ+PG1lcmNoYW50cmVzcG9uc2Vjb2RlPjA8L21lcmNoYW50cmVzcG9uc2Vjb2RlPjxwYXltZW50bWV0aG9kPlNWRUFDQVJEUEFZPC9wYXltZW50bWV0aG9kPjxjYWxsYmFja3VybD5odHRwOi8vbG9jYWxob3N0OjgwL2RldmVsb3Avb3BlbmNhcnQtMy4wLjMuMS9pbmRleC5waHA/cm91dGU9ZXh0ZW5zaW9uL3BheW1lbnQvc3ZlYV9jYXJkL2NhbGxiYWNrU3ZlYTwvY2FsbGJhY2t1cmw+PGNhcHR1cmVkYXRlPjIwMTktMDktMTAgMDA6MDU6MTkuNzQzPC9jYXB0dXJlZGF0ZT48c3Vic2NyaXB0aW9uaWQvPjxzdWJzY3JpcHRpb250eXBlLz48Y3VzdG9tZXIgaWQ9IjExODYyNiI+PGZpcnN0bmFtZS8+PGxhc3RuYW1lLz48aW5pdGlhbHMvPjxlbWFpbC8+PHNzbi8+PGFkZHJlc3MvPjxhZGRyZXNzMi8+PGNpdHkvPjxjb3VudHJ5PlNFPC9jb3VudHJ5Pjx6aXAvPjxwaG9uZS8+PHZhdG51bWJlci8+PGhvdXNlbnVtYmVyLz48Y29tcGFueW5hbWUvPjxmdWxsbmFtZS8+PGluZHVzdHJ5Y29kZS8+PGlzY29tcGFueT5mYWxzZTwvaXNjb21wYW55Pjx1bmtub3duY3VzdG9tZXI+ZmFsc2U8L3Vua25vd25jdXN0b21lcj48L2N1c3RvbWVyPjxtYXNrZWRjYXJkbm8+NDkxNjQyKioqKioqODEwMjwvbWFza2VkY2FyZG5vPjxjYXJkdHlwZT5WSVNBPC9jYXJkdHlwZT48ZWNpLz48bWRzdGF0dXMvPjxleHBpcnl5ZWFyPjIwPC9leHBpcnl5ZWFyPjxleHBpcnltb250aD41PC9leHBpcnltb250aD48Y2huYW1lPi08L2NobmFtZT48YXV0aGNvZGU+MTEzMDQ0PC9hdXRoY29kZT48b3JkZXJyb3dzPjxyb3c+PGlkPjI1NTUwMDwvaWQ+PG5hbWU+aVBob25lPC9uYW1lPjxhbW91bnQ+NjI2MjU8L2Ftb3VudD48dmF0PjEyNTI1PC92YXQ+PGRlc2NyaXB0aW9uPjwvZGVzY3JpcHRpb24+PHF1YW50aXR5PjEuMDwvcXVhbnRpdHk+PHNrdT5wcm9kdWN0IDExPC9za3U+PHVuaXQvPjwvcm93Pjxyb3c+PGlkPjI1NTUwMTwvaWQ+PG5hbWU+RnJlZSBTaGlwcGluZzwvbmFtZT48YW1vdW50PjA8L2Ftb3VudD48dmF0PjA8L3ZhdD48ZGVzY3JpcHRpb24+PC9kZXNjcmlwdGlvbj48cXVhbnRpdHk+MS4wPC9xdWFudGl0eT48c2t1PnNoaXBwaW5nPC9za3U+PHVuaXQvPjwvcm93Pjxyb3c+PGlkPjI1NTUwMjwvaWQ+PG5hbWU+Q291cG9uICgyMjIyKSBNb21za2xhc3M6MjUlPC9uYW1lPjxhbW91bnQ+LTYyNjI8L2Ftb3VudD48dmF0Pi0xMjUyPC92YXQ+PGRlc2NyaXB0aW9uPjwvZGVzY3JpcHRpb24+PHF1YW50aXR5PjEuMDwvcXVhbnRpdHk+PHNrdT48L3NrdT48dW5pdC8+PC9yb3c+PC9vcmRlcnJvd3M+PC90cmFuc2FjdGlvbj48c3RhdHVzY29kZT4wPC9zdGF0dXNjb2RlPjwvcmVzcG9uc2U+ 1130 c973795d51add05a20f82fe030a34866edf0ce2abfbb41b829e0f161f53291f95cc74fdb50e1d86e2ab0d2eee8a53cd3f3418ff6266fc6af987b83fbfaccfd82 ");
- $countryCode = "SE";
- $config = ConfigurationService::getTestConfig();
+ function test_QueryTransactionResponse_contains_amountincvat_and_amountexvat()
+ {
+ $message = new \SimpleXMLElement("PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz48cmVzcG9uc2U+PHRyYW5zYWN0aW9uIGlkPSI3MTU2NDgiPjxjdXN0b21lcnJlZm5vPjQ5MzcyMDU8L2N1c3RvbWVycmVmbm8+PG1lcmNoYW50aWQ+MTEzMDwvbWVyY2hhbnRpZD48c3RhdHVzPlNVQ0NFU1M8L3N0YXR1cz48YW1vdW50PjU2MzYzPC9hbW91bnQ+PGN1cnJlbmN5PlNFSzwvY3VycmVuY3k+PHZhdD4xMTI3MzwvdmF0PjxjYXB0dXJlZGFtb3VudD41NjM2MzwvY2FwdHVyZWRhbW91bnQ+PGF1dGhvcml6ZWRhbW91bnQ+NTYzNjM8L2F1dGhvcml6ZWRhbW91bnQ+PGNyZWF0ZWQ+MjAxOS0wOS0wOSAxNzowOToyOS43NTc8L2NyZWF0ZWQ+PGNyZWRpdHN0YXR1cz5DUkVERkFJTDwvY3JlZGl0c3RhdHVzPjxjcmVkaXRlZGFtb3VudD41NjM2MjwvY3JlZGl0ZWRhbW91bnQ+PG1lcmNoYW50cmVzcG9uc2Vjb2RlPjA8L21lcmNoYW50cmVzcG9uc2Vjb2RlPjxwYXltZW50bWV0aG9kPlNWRUFDQVJEUEFZPC9wYXltZW50bWV0aG9kPjxjYWxsYmFja3VybD5odHRwOi8vbG9jYWxob3N0OjgwL2RldmVsb3Avb3BlbmNhcnQtMy4wLjMuMS9pbmRleC5waHA/cm91dGU9ZXh0ZW5zaW9uL3BheW1lbnQvc3ZlYV9jYXJkL2NhbGxiYWNrU3ZlYTwvY2FsbGJhY2t1cmw+PGNhcHR1cmVkYXRlPjIwMTktMDktMTAgMDA6MDU6MTkuNzQzPC9jYXB0dXJlZGF0ZT48c3Vic2NyaXB0aW9uaWQvPjxzdWJzY3JpcHRpb250eXBlLz48Y3VzdG9tZXIgaWQ9IjExODYyNiI+PGZpcnN0bmFtZS8+PGxhc3RuYW1lLz48aW5pdGlhbHMvPjxlbWFpbC8+PHNzbi8+PGFkZHJlc3MvPjxhZGRyZXNzMi8+PGNpdHkvPjxjb3VudHJ5PlNFPC9jb3VudHJ5Pjx6aXAvPjxwaG9uZS8+PHZhdG51bWJlci8+PGhvdXNlbnVtYmVyLz48Y29tcGFueW5hbWUvPjxmdWxsbmFtZS8+PGluZHVzdHJ5Y29kZS8+PGlzY29tcGFueT5mYWxzZTwvaXNjb21wYW55Pjx1bmtub3duY3VzdG9tZXI+ZmFsc2U8L3Vua25vd25jdXN0b21lcj48L2N1c3RvbWVyPjxtYXNrZWRjYXJkbm8+NDkxNjQyKioqKioqODEwMjwvbWFza2VkY2FyZG5vPjxjYXJkdHlwZT5WSVNBPC9jYXJkdHlwZT48ZWNpLz48bWRzdGF0dXMvPjxleHBpcnl5ZWFyPjIwPC9leHBpcnl5ZWFyPjxleHBpcnltb250aD41PC9leHBpcnltb250aD48Y2huYW1lPi08L2NobmFtZT48YXV0aGNvZGU+MTEzMDQ0PC9hdXRoY29kZT48b3JkZXJyb3dzPjxyb3c+PGlkPjI1NTUwMDwvaWQ+PG5hbWU+aVBob25lPC9uYW1lPjxhbW91bnQ+NjI2MjU8L2Ftb3VudD48dmF0PjEyNTI1PC92YXQ+PGRlc2NyaXB0aW9uPjwvZGVzY3JpcHRpb24+PHF1YW50aXR5PjEuMDwvcXVhbnRpdHk+PHNrdT5wcm9kdWN0IDExPC9za3U+PHVuaXQvPjwvcm93Pjxyb3c+PGlkPjI1NTUwMTwvaWQ+PG5hbWU+RnJlZSBTaGlwcGluZzwvbmFtZT48YW1vdW50PjA8L2Ftb3VudD48dmF0PjA8L3ZhdD48ZGVzY3JpcHRpb24+PC9kZXNjcmlwdGlvbj48cXVhbnRpdHk+MS4wPC9xdWFudGl0eT48c2t1PnNoaXBwaW5nPC9za3U+PHVuaXQvPjwvcm93Pjxyb3c+PGlkPjI1NTUwMjwvaWQ+PG5hbWU+Q291cG9uICgyMjIyKSBNb21za2xhc3M6MjUlPC9uYW1lPjxhbW91bnQ+LTYyNjI8L2Ftb3VudD48dmF0Pi0xMjUyPC92YXQ+PGRlc2NyaXB0aW9uPjwvZGVzY3JpcHRpb24+PHF1YW50aXR5PjEuMDwvcXVhbnRpdHk+PHNrdT48L3NrdT48dW5pdC8+PC9yb3c+PC9vcmRlcnJvd3M+PC90cmFuc2FjdGlvbj48c3RhdHVzY29kZT4wPC9zdGF0dXNjb2RlPjwvcmVzcG9uc2U+ 1130 c973795d51add05a20f82fe030a34866edf0ce2abfbb41b829e0f161f53291f95cc74fdb50e1d86e2ab0d2eee8a53cd3f3418ff6266fc6af987b83fbfaccfd82 ");
+ $countryCode = "SE";
+ $config = ConfigurationService::getTestConfig();
- $queryTransactionResponse = new QueryTransactionResponse($message, $countryCode, $config);
+ $queryTransactionResponse = new QueryTransactionResponse($message, $countryCode, $config);
- $this->assertEquals("501.0",$queryTransactionResponse->numberedOrderRows[0]->amountExVat);
- $this->assertEquals("626.25",$queryTransactionResponse->numberedOrderRows[0]->amountIncVat);
- $this->assertEquals("0",$queryTransactionResponse->numberedOrderRows[1]->amountExVat);
- $this->assertEquals("0",$queryTransactionResponse->numberedOrderRows[1]->amountIncVat);
- $this->assertEquals("-50.1",$queryTransactionResponse->numberedOrderRows[2]->amountExVat);
- $this->assertEquals("-62.62",$queryTransactionResponse->numberedOrderRows[2]->amountIncVat);
+ $this->assertEquals("501.0",$queryTransactionResponse->numberedOrderRows[0]->amountExVat);
+ $this->assertEquals("626.25",$queryTransactionResponse->numberedOrderRows[0]->amountIncVat);
+ $this->assertEquals("0",$queryTransactionResponse->numberedOrderRows[1]->amountExVat);
+ $this->assertEquals("0",$queryTransactionResponse->numberedOrderRows[1]->amountIncVat);
+ $this->assertEquals("-50.1",$queryTransactionResponse->numberedOrderRows[2]->amountExVat);
+ $this->assertEquals("-62.62",$queryTransactionResponse->numberedOrderRows[2]->amountIncVat);
- }
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/HostedService/HandleOrder/QueryTransactionTest.php b/test/UnitTest/HostedService/HandleOrder/QueryTransactionTest.php
index 336b36d4..f584d376 100644
--- a/test/UnitTest/HostedService/HandleOrder/QueryTransactionTest.php
+++ b/test/UnitTest/HostedService/HandleOrder/QueryTransactionTest.php
@@ -16,88 +16,86 @@
class QueryTransactionTest extends \PHPUnit\Framework\TestCase
{
- protected $configObject;
- protected $queryObject;
-
- // fixture, run once before each test method
- protected function setUp()
- {
- $this->configObject = ConfigurationService::getDefaultConfig();
- $this->queryObject = new QueryTransaction($this->configObject);
- }
-
- // test methods
- function test_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransaction", $this->queryObject);
- $this->assertEquals("querytransactionid", \PHPUnit\Framework\Assert::readAttribute($this->queryObject, 'method'));
- }
-
- function test_setCountryCode()
- {
- $countryCode = "SE";
- $this->queryObject->countryCode = $countryCode;
- $this->assertEquals($countryCode, \PHPUnit\Framework\Assert::readAttribute($this->queryObject, 'countryCode'));
- }
-
- function test_prepareRequest_array_contains_mac_merchantid_message()
- {
-
- // set up annulTransaction object & get request form
- $transactionId = 987654;
- $this->queryObject->transactionId = $transactionId;
-
- $countryCode = "SE";
- $this->queryObject->countryCode = $countryCode;
-
- $form = $this->queryObject->prepareRequest();
-
- // prepared request is message (base64 encoded), merchantid, mac
- $this->assertTrue(isset($form['merchantid']));
- $this->assertTrue(isset($form['mac']));
- $this->assertTrue(isset($form['message']));
- }
-
- function test_prepareRequest_request_has_correct_merchantid_mac_and_querytransactionid_request_message_contents()
- {
-
- // set up creditTransaction object & get request form
- $transactionId = 987654;
- $this->queryObject->transactionId = $transactionId;
-
- $countryCode = "SE";
- $this->queryObject->countryCode = $countryCode;
-
- $form = $this->queryObject->prepareRequest();
-
- // get our merchantid & secret
- $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
-
- // check mechantid
- $this->assertEquals($merchantid, urldecode($form['merchantid']));
-
- // check valid mac
- $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
-
- // check annul request message contents
- $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
-
- $this->assertEquals("query", $xmlMessage->getName()); // root node
- $this->assertEquals((string)$transactionId, $xmlMessage->transactionid);
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.
- */
- function test_prepareRequest_missing_transactionId_throws_exception()
- {
- $countryCode = "SE";
- $this->queryObject->countryCode = $countryCode;
-
- $form = $this->queryObject->prepareRequest();
- }
+ protected $configObject;
+ protected $queryObject;
+
+ // fixture, run once before each test method
+ protected function setUp()
+ {
+ $this->configObject = ConfigurationService::getDefaultConfig();
+ $this->queryObject = new QueryTransaction($this->configObject);
+ }
+
+ // test methods
+ function test_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransaction", $this->queryObject);
+ $this->assertEquals("querytransactionid", \PHPUnit\Framework\Assert::readAttribute($this->queryObject, 'method'));
+ }
+
+ function test_setCountryCode()
+ {
+ $countryCode = "SE";
+ $this->queryObject->countryCode = $countryCode;
+ $this->assertEquals($countryCode, \PHPUnit\Framework\Assert::readAttribute($this->queryObject, 'countryCode'));
+ }
+
+ function test_prepareRequest_array_contains_mac_merchantid_message()
+ {
+
+ // set up annulTransaction object & get request form
+ $transactionId = 987654;
+ $this->queryObject->transactionId = $transactionId;
+
+ $countryCode = "SE";
+ $this->queryObject->countryCode = $countryCode;
+
+ $form = $this->queryObject->prepareRequest();
+
+ // prepared request is message (base64 encoded), merchantid, mac
+ $this->assertTrue(isset($form['merchantid']));
+ $this->assertTrue(isset($form['mac']));
+ $this->assertTrue(isset($form['message']));
+ }
+
+ function test_prepareRequest_request_has_correct_merchantid_mac_and_querytransactionid_request_message_contents()
+ {
+
+ // set up creditTransaction object & get request form
+ $transactionId = 987654;
+ $this->queryObject->transactionId = $transactionId;
+
+ $countryCode = "SE";
+ $this->queryObject->countryCode = $countryCode;
+
+ $form = $this->queryObject->prepareRequest();
+
+ // get our merchantid & secret
+ $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+
+ // check mechantid
+ $this->assertEquals($merchantid, urldecode($form['merchantid']));
+
+ // check valid mac
+ $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
+
+ // check annul request message contents
+ $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
+
+ $this->assertEquals("query", $xmlMessage->getName()); // root node
+ $this->assertEquals((string)$transactionId, $xmlMessage->transactionid);
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response.
+ */
+ function test_prepareRequest_missing_transactionId_throws_exception()
+ {
+ $countryCode = "SE";
+ $this->queryObject->countryCode = $countryCode;
+
+ $form = $this->queryObject->prepareRequest();
+ }
}
-
-?>
diff --git a/test/UnitTest/HostedService/HandleOrder/RecurTransactionTest.php b/test/UnitTest/HostedService/HandleOrder/RecurTransactionTest.php
index ec7a0aab..e519bd19 100644
--- a/test/UnitTest/HostedService/HandleOrder/RecurTransactionTest.php
+++ b/test/UnitTest/HostedService/HandleOrder/RecurTransactionTest.php
@@ -16,197 +16,195 @@
class RecurTransactionTest extends \PHPUnit\Framework\TestCase
{
- protected $configObject;
- protected $recurTransactionObject;
-
- // fixture, run once before each test method
- protected function setUp()
- {
- $this->configObject = ConfigurationService::getDefaultConfig();
- $this->recurTransactionObject = new RecurTransaction($this->configObject);
- }
-
- // test methods
- function test_class_exists()
- {
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\RecurTransaction", $this->recurTransactionObject);
- $this->assertEquals("recur", \PHPUnit\Framework\Assert::readAttribute($this->recurTransactionObject, 'method'));
- }
-
-// function test_setCurrency() {
-// $currency = "SEK";
-// $this->recurTransactionObject->setCurrency( $currency );
-// $this->assertEquals( $currency, PHPUnit_Framework_Assert::readAttribute($this->recurTransactionObject, 'currency') );
-// }
-//
-// function test_setAmount() {
-// $amount = 100;
-// $this->recurTransactionObject->setAmount( $amount );
-// $this->assertEquals( $amount, PHPUnit_Framework_Assert::readAttribute($this->recurTransactionObject, 'amount') );
-// }
+ protected $configObject;
+ protected $recurTransactionObject;
+
+ // fixture, run once before each test method
+ protected function setUp()
+ {
+ $this->configObject = ConfigurationService::getDefaultConfig();
+ $this->recurTransactionObject = new RecurTransaction($this->configObject);
+ }
+
+ // test methods
+ function test_class_exists()
+ {
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\RecurTransaction", $this->recurTransactionObject);
+ $this->assertEquals("recur", \PHPUnit\Framework\Assert::readAttribute($this->recurTransactionObject, 'method'));
+ }
+
+// function test_setCurrency() {
+// $currency = "SEK";
+// $this->recurTransactionObject->setCurrency( $currency );
+// $this->assertEquals( $currency, PHPUnit_Framework_Assert::readAttribute($this->recurTransactionObject, 'currency') );
+// }
//
-// function test_setCustomerRefNo( ){
-// $customerRefNo = "myCustomerRefNo";
-// $this->recurTransactionObject->setCustomerRefNo( $customerRefNo );
-// $this->assertEquals( $customerRefNo, PHPUnit_Framework_Assert::readAttribute($this->recurTransactionObject, 'customerRefNo') );
-// }
-//
-// function test_setSubscriptionId( ){
-// $subscriptionId = 987654;
-// $this->recurTransactionObject->setSubscriptionId( $subscriptionId );
-// $this->assertEquals( $subscriptionId, PHPUnit_Framework_Assert::readAttribute($this->recurTransactionObject, 'subscriptionId') );
-// }
-
- function test_prepareRequest_array_contains_mac_merchantid_message()
- {
+// function test_setAmount() {
+// $amount = 100;
+// $this->recurTransactionObject->setAmount( $amount );
+// $this->assertEquals( $amount, PHPUnit_Framework_Assert::readAttribute($this->recurTransactionObject, 'amount') );
+// }
+//
+// function test_setCustomerRefNo( ){
+// $customerRefNo = "myCustomerRefNo";
+// $this->recurTransactionObject->setCustomerRefNo( $customerRefNo );
+// $this->assertEquals( $customerRefNo, PHPUnit_Framework_Assert::readAttribute($this->recurTransactionObject, 'customerRefNo') );
+// }
+//
+// function test_setSubscriptionId( ){
+// $subscriptionId = 987654;
+// $this->recurTransactionObject->setSubscriptionId( $subscriptionId );
+// $this->assertEquals( $subscriptionId, PHPUnit_Framework_Assert::readAttribute($this->recurTransactionObject, 'subscriptionId') );
+// }
- // set up recurTransaction object & get request form
- $customerRefNo = "myCustomerRefNo";
- $this->recurTransactionObject->customerRefNo = $customerRefNo;
+ function test_prepareRequest_array_contains_mac_merchantid_message()
+ {
- $subscriptionId = 987654;
- $this->recurTransactionObject->subscriptionId = $subscriptionId;
+ // set up recurTransaction object & get request form
+ $customerRefNo = "myCustomerRefNo";
+ $this->recurTransactionObject->customerRefNo = $customerRefNo;
- $currency = "SEK";
- $this->recurTransactionObject->currency = $currency;
+ $subscriptionId = 987654;
+ $this->recurTransactionObject->subscriptionId = $subscriptionId;
- $amount = 100;
- $this->recurTransactionObject->amount = $amount;
-
- $countryCode = "SE";
- $this->recurTransactionObject->countryCode = $countryCode;
+ $currency = "SEK";
+ $this->recurTransactionObject->currency = $currency;
- $form = $this->recurTransactionObject->prepareRequest();
-
- // prepared request is message (base64 encoded), merchantid, mac
- $this->assertTrue(isset($form['merchantid']));
- $this->assertTrue(isset($form['mac']));
- $this->assertTrue(isset($form['message']));
- }
+ $amount = 100;
+ $this->recurTransactionObject->amount = $amount;
- function test_prepareRequest_has_correct_merchantid_mac_and_lowerTransaction_request_message_contents()
- {
+ $countryCode = "SE";
+ $this->recurTransactionObject->countryCode = $countryCode;
- // set up recurTransaction object & get request form
- $customerRefNo = "myCustomerRefNo";
- $this->recurTransactionObject->customerRefNo = $customerRefNo;
-
- $subscriptionId = 987654;
- $this->recurTransactionObject->subscriptionId = $subscriptionId;
-
- $currency = "SEK";
- $this->recurTransactionObject->currency = $currency;
-
- $amount = 100;
- $this->recurTransactionObject->amount = $amount;
+ $form = $this->recurTransactionObject->prepareRequest();
- $countryCode = "SE";
- $this->recurTransactionObject->countryCode = $countryCode;
+ // prepared request is message (base64 encoded), merchantid, mac
+ $this->assertTrue(isset($form['merchantid']));
+ $this->assertTrue(isset($form['mac']));
+ $this->assertTrue(isset($form['message']));
+ }
- $form = $this->recurTransactionObject->prepareRequest();
+ function test_prepareRequest_has_correct_merchantid_mac_and_lowerTransaction_request_message_contents()
+ {
- // get our merchantid & secret
- $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ // set up recurTransaction object & get request form
+ $customerRefNo = "myCustomerRefNo";
+ $this->recurTransactionObject->customerRefNo = $customerRefNo;
- // check mechantid
- $this->assertEquals($merchantid, urldecode($form['merchantid']));
+ $subscriptionId = 987654;
+ $this->recurTransactionObject->subscriptionId = $subscriptionId;
- // check valid mac
- $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
+ $currency = "SEK";
+ $this->recurTransactionObject->currency = $currency;
- // check credit request message contents
- $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
+ $amount = 100;
+ $this->recurTransactionObject->amount = $amount;
- $this->assertEquals("recur", $xmlMessage->getName()); // root node
- $this->assertEquals((string)$customerRefNo, $xmlMessage->customerrefno);
- $this->assertEquals((string)$subscriptionId, $xmlMessage->subscriptionid);
- $this->assertEquals((string)$currency, $xmlMessage->currency);
- $this->assertEquals((string)$amount, $xmlMessage->amount);
- }
+ $countryCode = "SE";
+ $this->recurTransactionObject->countryCode = $countryCode;
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : customerRefNo is required. Use function setCustomerRefNo (also check setClientOrderNumber in order builder).
- */
- function test_prepareRequest_missing_customerRefNo_throws_exception()
- {
- $subscriptionId = 987654;
- $this->recurTransactionObject->subscriptionId = $subscriptionId;
+ $form = $this->recurTransactionObject->prepareRequest();
- $currency = "SEK";
- $this->recurTransactionObject->currency = $currency;
+ // get our merchantid & secret
+ $merchantid = $this->configObject->getMerchantId(ConfigurationProvider::HOSTED_TYPE, $countryCode);
+ $secret = $this->configObject->getSecret(ConfigurationProvider::HOSTED_TYPE, $countryCode);
- $amount = 100;
- $this->recurTransactionObject->amount = $amount;
+ // check mechantid
+ $this->assertEquals($merchantid, urldecode($form['merchantid']));
- $countryCode = "SE";
- $this->recurTransactionObject->countryCode = $countryCode;
+ // check valid mac
+ $this->assertEquals(hash("sha512", urldecode($form['message']) . $secret), urldecode($form['mac']));
- $form = $this->recurTransactionObject->prepareRequest();
- }
+ // check credit request message contents
+ $xmlMessage = new SimpleXMLElement(base64_decode(urldecode($form['message'])));
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : subscriptionId is required. Use function setSubscriptionId() with the subscriptionId from the createOrder response.
- */
- function test_prepareRequest_missing_subscriptionId_throws_exception()
- {
- $customerRefNo = "myCustomerRefNo";
- $this->recurTransactionObject->customerRefNo = $customerRefNo;
+ $this->assertEquals("recur", $xmlMessage->getName()); // root node
+ $this->assertEquals((string)$customerRefNo, $xmlMessage->customerrefno);
+ $this->assertEquals((string)$subscriptionId, $xmlMessage->subscriptionid);
+ $this->assertEquals((string)$currency, $xmlMessage->currency);
+ $this->assertEquals((string)$amount, $xmlMessage->amount);
+ }
- $currency = "SEK";
- $this->recurTransactionObject->currency = $currency;
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : customerRefNo is required. Use function setCustomerRefNo (also check setClientOrderNumber in order builder).
+ */
+ function test_prepareRequest_missing_customerRefNo_throws_exception()
+ {
+ $subscriptionId = 987654;
+ $this->recurTransactionObject->subscriptionId = $subscriptionId;
- $amount = 100;
- $this->recurTransactionObject->amount = $amount;
+ $currency = "SEK";
+ $this->recurTransactionObject->currency = $currency;
- $countryCode = "SE";
- $this->recurTransactionObject->countryCode = $countryCode;
+ $amount = 100;
+ $this->recurTransactionObject->amount = $amount;
- $form = $this->recurTransactionObject->prepareRequest();
- }
+ $countryCode = "SE";
+ $this->recurTransactionObject->countryCode = $countryCode;
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : amount is required. Use function setAmount().
- */
- function test_prepareRequest_missing_amount_throws_exception()
- {
- $customerRefNo = "myCustomerRefNo";
- $this->recurTransactionObject->customerRefNo = $customerRefNo;
+ $form = $this->recurTransactionObject->prepareRequest();
+ }
- $subscriptionId = 987654;
- $this->recurTransactionObject->subscriptionId = $subscriptionId;
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : subscriptionId is required. Use function setSubscriptionId() with the subscriptionId from the createOrder response.
+ */
+ function test_prepareRequest_missing_subscriptionId_throws_exception()
+ {
+ $customerRefNo = "myCustomerRefNo";
+ $this->recurTransactionObject->customerRefNo = $customerRefNo;
- $currency = "SEK";
- $this->recurTransactionObject->currency = $currency;
+ $currency = "SEK";
+ $this->recurTransactionObject->currency = $currency;
- $countryCode = "SE";
- $this->recurTransactionObject->countryCode = $countryCode;
+ $amount = 100;
+ $this->recurTransactionObject->amount = $amount;
- $form = $this->recurTransactionObject->prepareRequest();
- }
- /**
- * @doesNotPerformAssertions
- */
- function test_prepareRequest_missing_currency_does_not_throw_an_exception()
- {
+ $countryCode = "SE";
+ $this->recurTransactionObject->countryCode = $countryCode;
- $customerRefNo = "myCustomerRefNo";
- $this->recurTransactionObject->customerRefNo = $customerRefNo;
+ $form = $this->recurTransactionObject->prepareRequest();
+ }
- $subscriptionId = 987654;
- $this->recurTransactionObject->subscriptionId = $subscriptionId;
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : amount is required. Use function setAmount().
+ */
+ function test_prepareRequest_missing_amount_throws_exception()
+ {
+ $customerRefNo = "myCustomerRefNo";
+ $this->recurTransactionObject->customerRefNo = $customerRefNo;
- $amount = 100;
- $this->recurTransactionObject->amount = $amount;
+ $subscriptionId = 987654;
+ $this->recurTransactionObject->subscriptionId = $subscriptionId;
- $countryCode = "SE";
- $this->recurTransactionObject->countryCode = $countryCode;
+ $currency = "SEK";
+ $this->recurTransactionObject->currency = $currency;
- $form = $this->recurTransactionObject->prepareRequest();
- }
-}
+ $countryCode = "SE";
+ $this->recurTransactionObject->countryCode = $countryCode;
+
+ $form = $this->recurTransactionObject->prepareRequest();
+ }
+ /**
+ * @doesNotPerformAssertions
+ */
+ function test_prepareRequest_missing_currency_does_not_throw_an_exception()
+ {
+
+ $customerRefNo = "myCustomerRefNo";
+ $this->recurTransactionObject->customerRefNo = $customerRefNo;
-?>
+ $subscriptionId = 987654;
+ $this->recurTransactionObject->subscriptionId = $subscriptionId;
+
+ $amount = 100;
+ $this->recurTransactionObject->amount = $amount;
+
+ $countryCode = "SE";
+ $this->recurTransactionObject->countryCode = $countryCode;
+
+ $form = $this->recurTransactionObject->prepareRequest();
+ }
+}
diff --git a/test/UnitTest/HostedService/Helper/ExcludePaymentsTest.php b/test/UnitTest/HostedService/Helper/ExcludePaymentsTest.php
index 85a92a24..5b332b3e 100644
--- a/test/UnitTest/HostedService/Helper/ExcludePaymentsTest.php
+++ b/test/UnitTest/HostedService/Helper/ExcludePaymentsTest.php
@@ -12,32 +12,32 @@
class ExcludePaymentsTest extends \PHPUnit\Framework\TestCase
{
- public function test_excludeInvoicesAndPaymentPlan_SE()
- {
+ public function test_excludeInvoicesAndPaymentPlan_SE()
+ {
- $exclude = new ExcludePayments();
- $excludedPaymentMethods = $exclude->excludeInvoicesAndPaymentPlan("SE");
+ $exclude = new ExcludePayments();
+ $excludedPaymentMethods = $exclude->excludeInvoicesAndPaymentPlan("SE");
- $this->assertEquals(14, count((array)$excludedPaymentMethods));
+ $this->assertEquals(14, count((array)$excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::INVOICESE, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLANSE, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_SE, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_SE, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::INVOICESE, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLANSE, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_SE, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_SE, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_DE, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_DE, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_DE, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_DE, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_DK, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_DK, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_DK, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_DK, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_FI, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_FI, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_FI, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_FI, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_NL, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_NL, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_NL, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_NL, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_NO, $excludedPaymentMethods));
- $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_NO, $excludedPaymentMethods));
- }
+ $this->assertTrue(in_array(SystemPaymentMethod::INVOICE_NO, $excludedPaymentMethods));
+ $this->assertTrue(in_array(SystemPaymentMethod::PAYMENTPLAN_NO, $excludedPaymentMethods));
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/HostedService/Helper/HostedRowFormatterTest.php b/test/UnitTest/HostedService/Helper/HostedRowFormatterTest.php
index a8b2821b..1c4693cf 100644
--- a/test/UnitTest/HostedService/Helper/HostedRowFormatterTest.php
+++ b/test/UnitTest/HostedService/Helper/HostedRowFormatterTest.php
@@ -15,1354 +15,1354 @@
class HostedRowFormatterTest extends \PHPUnit\Framework\TestCase
{
- private $order;
-
- protected function SetUp()
- {
- $this->order = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- }
-
- //
- // VAT calculations
-
- // we calculate vat in three different ways requiring two out of three of amount inc vat, ex vat, vatpercent
- // case 1 ex vat, vat percent given
- public function testFormatOrderRows_VatCalculationFromAmountExVatAndVatPercentEquals25()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(69.99)
- ->setVatPercent(25)
- ->setQuantity(4)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(8749, $newRow->amount);
- $this->assertEquals(1750, $newRow->vat);
- $this->assertEquals(4, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- public function testFormatOrderRows_VatCalculationFromAmountExVatAndVatPercentEquals6()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(69.99)
- ->setVatPercent(6)
- ->setQuantity(1)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(7419, $newRow->amount);
- $this->assertEquals(420, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- // case 2 inc vat, vat percent given
- public function testFormatOrderRows_VatCalculationFromAmountIncVatAndVatPercent()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountIncVat(87.49)
- ->setVatPercent(25)
- ->setQuantity(4)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(8749, $newRow->amount);
- $this->assertEquals(1750, $newRow->vat);
- $this->assertEquals(4, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- // case 3 ex vat, inc vat
- public function testFormatOrderRows_VatCalculationFromAmountExVatAndAmountIncVatAndVatPercent()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(69.99)
- ->setAmountIncVat(87.49)
- ->setQuantity(4)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(8749, $newRow->amount);
- $this->assertEquals(1750, $newRow->vat);
- $this->assertEquals(4, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- // case 4 all three given
- public function testFormatOrderRows_VatCalculationFromAllThreeOfAmountExVatAndAmountIncVatAndVatPercent()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(69.99)
- ->setAmountIncVat(87.49)
- ->setVatPercent(25)
- ->setQuantity(4)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(8749, $newRow->amount);
- $this->assertEquals(1750, $newRow->vat);
- $this->assertEquals(4, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- //
- // order row and item composition
- public function testFormatOrderRows_SingleRowWithSingleItem()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(4)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(500, $newRow->amount);
- $this->assertEquals(100, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- public function testFormatOrderRows_SingleRowWithMultipleItems()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(4)
- ->setVatPercent(25)
- ->setQuantity(4)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(500, $newRow->amount);
- $this->assertEquals(100, $newRow->vat);
- $this->assertEquals(4, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- // 69,99 kr excl. 25% moms => 87,4875 kr including 17,4975 kr moms, expressed as öre
- public function testFormatOrderRows_SingleRowSingleItemWithFractionalPrice()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(69.99)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(8749, $newRow->amount);
- $this->assertEquals(1750, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- public function testFormatOrderRows_SingleRowMultipleItemsWithFractionalPrice()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(69.99)
- ->setVatPercent(25)
- ->setQuantity(4)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(8749, $newRow->amount);
- $this->assertEquals(1750, $newRow->vat);
- $this->assertEquals(4, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- public function testFormatOrderRows_SingleRowSingleItemWithNoVat()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(4)
- ->setVatPercent(0)
- ->setQuantity(1)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(400, $newRow->amount);
- $this->assertEquals(0, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- // MultipleOrderRows
- public function testFormatOrderRows_MultipleRowsOfMultipleItemsWithSameVatRate()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(69.99)
- ->setVatPercent(25)
- ->setQuantity(4)
- ->setUnit("st")
- )
- ->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(4)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setUnit("st")
- );
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(8749, $newRow->amount);
- $this->assertEquals(1750, $newRow->vat);
- $this->assertEquals(4, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
-
- $newRow = $newRows[1];
- $this->assertEquals("1", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(500, $newRow->amount);
- $this->assertEquals(100, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- public function testFormatOrderRows_MultipleRowsOfMultipleItemsWithDifferentVatRate()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(69.99)
- ->setVatPercent(25)
- ->setQuantity(4)
- ->setUnit("st")
- )
- ->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(10)
- ->setVatPercent(6)
- ->setQuantity(1)
- ->setUnit("st")
- );
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(8749, $newRow->amount);
- $this->assertEquals(1750, $newRow->vat);
- $this->assertEquals(4, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
-
- $newRow = $newRows[1];
- $this->assertEquals("1", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(1060, $newRow->amount);
- $this->assertEquals(60, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- public function testFormatShippingFeeRows()
- {
- $this->order
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(4)
- ->setVatPercent(25)
- ->setUnit("st")
- );
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[0];
-
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(500, $newRow->amount);
- $this->assertEquals(100, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
- }
-
- public function testFormatFixedDiscountRows()
- {
- $this->order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountIncVat(1)
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[1];
-
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(-100, $newRow->amount);
- $this->assertEquals(-20, $newRow->vat);
- }
-
- public function testFormatRelativeDiscountRows()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setDiscountPercent(10)
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[1];
-
- $this->assertEquals("0", $newRow->sku);
- $this->assertEquals("Tess", $newRow->name);
- $this->assertEquals("Tester", $newRow->description);
- $this->assertEquals(-50, $newRow->amount);
- $this->assertEquals(-10, $newRow->vat);
- }
-
- public function testFormatTotalAmount()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100)
- ->setVatPercent(0)
- ->setQuantity(2)
- );
-
- $formatter = new HostedRowFormatter();
- $rows = $formatter->formatRows($this->order);
- $this->assertEquals(20000, $formatter->formatTotalAmount($rows));
- }
-
- public function testFormatTotalAmountNegative()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(-100)
- ->setVatPercent(0)
- ->setQuantity(2)
- );
- $formatter = new HostedRowFormatter();
- $rows = $formatter->formatRows($this->order);
- $this->assertEquals(-20000, $formatter->formatTotalAmount($rows));
- }
-
- public function testFormatTotalVat()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100)
- ->setVatPercent(100)
- ->setQuantity(2)
- );
-
- $formatter = new HostedRowFormatter();
- $rows = $formatter->formatRows($this->order);
- $this->assertEquals(20000, $formatter->formatTotalVat($rows));
- }
-
- public function testFormatTotalVatNegative()
- {
- $this->order->
- addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(-100)
- ->setVatPercent(100)
- ->setQuantity(2)
- );
-
- $formatter = new HostedRowFormatter();
- $rows = $formatter->formatRows($this->order);
- $this->assertEquals(-20000, $formatter->formatTotalVat($rows));
- }
+ private $order;
+
+ protected function SetUp()
+ {
+ $this->order = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ }
+
+ //
+ // VAT calculations
+
+ // we calculate vat in three different ways requiring two out of three of amount inc vat, ex vat, vatpercent
+ // case 1 ex vat, vat percent given
+ public function testFormatOrderRows_VatCalculationFromAmountExVatAndVatPercentEquals25()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(69.99)
+ ->setVatPercent(25)
+ ->setQuantity(4)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(8749, $newRow->amount);
+ $this->assertEquals(1750, $newRow->vat);
+ $this->assertEquals(4, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ public function testFormatOrderRows_VatCalculationFromAmountExVatAndVatPercentEquals6()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(69.99)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(7419, $newRow->amount);
+ $this->assertEquals(420, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ // case 2 inc vat, vat percent given
+ public function testFormatOrderRows_VatCalculationFromAmountIncVatAndVatPercent()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountIncVat(87.49)
+ ->setVatPercent(25)
+ ->setQuantity(4)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(8749, $newRow->amount);
+ $this->assertEquals(1750, $newRow->vat);
+ $this->assertEquals(4, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ // case 3 ex vat, inc vat
+ public function testFormatOrderRows_VatCalculationFromAmountExVatAndAmountIncVatAndVatPercent()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(69.99)
+ ->setAmountIncVat(87.49)
+ ->setQuantity(4)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(8749, $newRow->amount);
+ $this->assertEquals(1750, $newRow->vat);
+ $this->assertEquals(4, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ // case 4 all three given
+ public function testFormatOrderRows_VatCalculationFromAllThreeOfAmountExVatAndAmountIncVatAndVatPercent()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(69.99)
+ ->setAmountIncVat(87.49)
+ ->setVatPercent(25)
+ ->setQuantity(4)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(8749, $newRow->amount);
+ $this->assertEquals(1750, $newRow->vat);
+ $this->assertEquals(4, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ //
+ // order row and item composition
+ public function testFormatOrderRows_SingleRowWithSingleItem()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(4)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(500, $newRow->amount);
+ $this->assertEquals(100, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ public function testFormatOrderRows_SingleRowWithMultipleItems()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(4)
+ ->setVatPercent(25)
+ ->setQuantity(4)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(500, $newRow->amount);
+ $this->assertEquals(100, $newRow->vat);
+ $this->assertEquals(4, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ // 69,99 kr excl. 25% moms => 87,4875 kr including 17,4975 kr moms, expressed as öre
+ public function testFormatOrderRows_SingleRowSingleItemWithFractionalPrice()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(69.99)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(8749, $newRow->amount);
+ $this->assertEquals(1750, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ public function testFormatOrderRows_SingleRowMultipleItemsWithFractionalPrice()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(69.99)
+ ->setVatPercent(25)
+ ->setQuantity(4)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(8749, $newRow->amount);
+ $this->assertEquals(1750, $newRow->vat);
+ $this->assertEquals(4, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ public function testFormatOrderRows_SingleRowSingleItemWithNoVat()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(4)
+ ->setVatPercent(0)
+ ->setQuantity(1)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(400, $newRow->amount);
+ $this->assertEquals(0, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ // MultipleOrderRows
+ public function testFormatOrderRows_MultipleRowsOfMultipleItemsWithSameVatRate()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(69.99)
+ ->setVatPercent(25)
+ ->setQuantity(4)
+ ->setUnit("st")
+ )
+ ->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(4)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setUnit("st")
+ );
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(8749, $newRow->amount);
+ $this->assertEquals(1750, $newRow->vat);
+ $this->assertEquals(4, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+
+ $newRow = $newRows[1];
+ $this->assertEquals("1", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(500, $newRow->amount);
+ $this->assertEquals(100, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ public function testFormatOrderRows_MultipleRowsOfMultipleItemsWithDifferentVatRate()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(69.99)
+ ->setVatPercent(25)
+ ->setQuantity(4)
+ ->setUnit("st")
+ )
+ ->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(10)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ ->setUnit("st")
+ );
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(8749, $newRow->amount);
+ $this->assertEquals(1750, $newRow->vat);
+ $this->assertEquals(4, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+
+ $newRow = $newRows[1];
+ $this->assertEquals("1", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(1060, $newRow->amount);
+ $this->assertEquals(60, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ public function testFormatShippingFeeRows()
+ {
+ $this->order
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(4)
+ ->setVatPercent(25)
+ ->setUnit("st")
+ );
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[0];
+
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(500, $newRow->amount);
+ $this->assertEquals(100, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+ }
+
+ public function testFormatFixedDiscountRows()
+ {
+ $this->order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountIncVat(1)
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[1];
+
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(-100, $newRow->amount);
+ $this->assertEquals(-20, $newRow->vat);
+ }
+
+ public function testFormatRelativeDiscountRows()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setDiscountPercent(10)
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[1];
+
+ $this->assertEquals("0", $newRow->sku);
+ $this->assertEquals("Tess", $newRow->name);
+ $this->assertEquals("Tester", $newRow->description);
+ $this->assertEquals(-50, $newRow->amount);
+ $this->assertEquals(-10, $newRow->vat);
+ }
+
+ public function testFormatTotalAmount()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100)
+ ->setVatPercent(0)
+ ->setQuantity(2)
+ );
+
+ $formatter = new HostedRowFormatter();
+ $rows = $formatter->formatRows($this->order);
+ $this->assertEquals(20000, $formatter->formatTotalAmount($rows));
+ }
+
+ public function testFormatTotalAmountNegative()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(-100)
+ ->setVatPercent(0)
+ ->setQuantity(2)
+ );
+ $formatter = new HostedRowFormatter();
+ $rows = $formatter->formatRows($this->order);
+ $this->assertEquals(-20000, $formatter->formatTotalAmount($rows));
+ }
+
+ public function testFormatTotalVat()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100)
+ ->setVatPercent(100)
+ ->setQuantity(2)
+ );
+
+ $formatter = new HostedRowFormatter();
+ $rows = $formatter->formatRows($this->order);
+ $this->assertEquals(20000, $formatter->formatTotalVat($rows));
+ }
+
+ public function testFormatTotalVatNegative()
+ {
+ $this->order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(-100)
+ ->setVatPercent(100)
+ ->setQuantity(2)
+ );
+
+ $formatter = new HostedRowFormatter();
+ $rows = $formatter->formatRows($this->order);
+ $this->assertEquals(-20000, $formatter->formatTotalVat($rows));
+ }
// ------------------------
- // TODO! move these to Svea\WebPay\Test\UnitTest\WebService\Helper\WebServiceRowFormatterTest as well (as in java package
- // ported over tests of discounts from WebserviceRowFormatterTest
-
- /// fixed discount
- // iff no specified vatPercent => split discount excl. vat over the diffrent tax rates present in order
- public function test_FixedDiscount_specified_using_amountExVat_in_order_with_single_vat_rate()
- {
- $this->order->addOrderRow(WebPayItem::orderRow()
- // cover all three ways to specify items here: iv+vp, ev+vp, iv+ev
- ->setAmountExVat(4.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f1e")
- ->setName("couponName")
- ->setDescription("couponName")
- ->setAmountExVat(1.0)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter($this->order);
- $newRows = $formatter->formatRows($this->order);
- $newRow = $newRows[1];
-
- // 1.0 kr @25% => -125 öre discount, of which -25 öre is vat
- $this->assertEquals("f1e", $newRow->sku);
- $this->assertEquals("couponName", $newRow->name);
- $this->assertEquals("couponName", $newRow->description);
- $this->assertEquals(-125, $newRow->amount);
- $this->assertEquals(-25, $newRow->vat);
-
- $paymentForm = $this->order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // 5.00 (1.00) - 1.25 (.25) = 3.75 (.75)
- $this->assertRegexp('/375<\/amount>/', $paymentXml);
- $this->assertRegexp('/75<\/vat>/', $paymentXml);
- }
-
- public function test_FixedDiscount_specified_using_amountExVat_in_order_with_multiple_vat_rates()
- {
- $this->order->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @25% = 125")
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @6% = 106")
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100e")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountExVat(100.00)
- );
-
- $formatter = new HostedRowFormatter($this->order);
- $newRows = $formatter->formatRows($this->order);
- $testedRow = $newRows[2];
-
- // 100*200/300 = 66.67 ex. 25% vat => 83.34 vat as amount of which 16.67 is vat
- // 100*100/300 = 33.33 ex. 6% vat => 35.33 vat as amount 2.00 is vat
- // In one discount row -11867 öre, of which 1867 is vat
- $this->assertEquals("f100e", $testedRow->sku);
- $this->assertEquals("couponName", $testedRow->name);
- $this->assertEquals("couponDesc", $testedRow->description);
- $this->assertEquals(-11867, $testedRow->amount);
- $this->assertEquals(-1867, $testedRow->vat);
-
- $paymentForm = $this->order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // newRows.get(0).PricePerUnit * newRows.get(0).NumberOfUnits + // 250.00
- // newRows.get(1).PricePerUnit * newRows.get(1).NumberOfUnits + // 106.00
- // newRows.get(2).PricePerUnit * newRows.get(2).NumberOfUnits + // -83.34
- // newRows.get(3).PricePerUnit * newRows.get(3).NumberOfUnits // -35.33
- //assertEquals( 237.33, Double.valueOf(String.format(Locale.ENGLISH,"%.2f",total)), 0.001 );
- $this->assertRegexp('/23733<\/amount>/', $paymentXml);
- $this->assertRegexp('/3733<\/vat>/', $paymentXml);
- }
-
- // iff no specified vatPercent => split discount incl. vat over the diffrent tax rates present in order
- // public void test_FixedDiscount_specified_using_amountIncVat_in_order_with_single_vat_rate() {
- public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_single_vat_rate()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4.00)
- ->setVatPercent(25)
- ->setQuantity(1.0)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f1e")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountIncVat(1.00)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // validate HostedOrderRowBuilder row contents
- $newRow = $newRows[1];
- $this->assertEquals("f1e", $newRow->sku);
- $this->assertEquals("couponName", $newRow->name);
- $this->assertEquals("couponDesc", $newRow->description);
- $this->assertEquals(-100, $newRow->amount);
- $this->assertEquals(-20, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // 5.00 (1.00) - 1.00 (.20) = 4.00 (1.00)
- $this->assertRegexp('/400<\/amount>/', $paymentXml);
- $this->assertRegexp('/100<\/vat>/', $paymentXml);
- }
-
- public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_multiple_vat_rates()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @25% = 125")
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @6% = 106")
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1.0)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100e")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountIncVat(100.00)
- ->setUnit("st")
- );
-
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
- // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
- // => total discount is 100.00 (incl 15.73 vat)
- $newRow = $newRows[2];
- $this->assertEquals("f100e", $newRow->sku);
- $this->assertEquals("couponName", $newRow->name);
- $this->assertEquals("couponDesc", $newRow->description);
- $this->assertEquals(-10000, $newRow->amount);
- $this->assertEquals(-1573, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // newRows.get(0).PricePerUnit * newRows.get(0).NumberOfUnits + // 250.00
- // newRows.get(1).PricePerUnit * newRows.get(1).NumberOfUnits + // 106.00
- // newRows.get(2).PricePerUnit * newRows.get(2).NumberOfUnits + // -70.22 (14.04) + 29.78 (1.69) = -100.00 (-15.73)
- $this->assertRegexp('/25600<\/amount>/', $paymentXml);
- $this->assertRegexp('/4027<\/vat>/', $paymentXml);
- }
-
- // iff specified vatPercent => add as single row with specified vat rate only honouring specified amount and vatPercent
- public function test_FixedDiscount_specified_using_IncVat_and_vatPercent_is_added_as_single_discount_row()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1.0)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(111.00)
- ->setVatPercent(25)
- );
-
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // -111.00 (-22.20)
- $newRow = $newRows[2];
- $this->assertEquals(-11100, $newRow->amount);
- $this->assertEquals(-2220, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // newRows.get(0).PricePerUnit * newRows.get(0).NumberOfUnits + // 250.00
- // newRows.get(1).PricePerUnit * newRows.get(1).NumberOfUnits + // 106.00
- // newRows.get(2).PricePerUnit * newRows.get(2).NumberOfUnits + // -111.00 (-22.20)
- $this->assertRegexp('/24500<\/amount>/', $paymentXml);
- $this->assertRegexp('/3380<\/vat>/', $paymentXml);
- }
-
- public function test_FixedDiscount_specified_using_ExVat_and_vatPercent_is_added_as_single_discount_row()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1.0)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(88.80)
- ->setVatPercent(25)
- );
-
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // 88.80ex @25% => -111.00 (-22.20)
- $newRow = $newRows[2];
- $this->assertEquals(-11100, $newRow->amount);
- $this->assertEquals(-2220, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // newRows.get(0).PricePerUnit * newRows.get(0).NumberOfUnits + // 250.00
- // newRows.get(1).PricePerUnit * newRows.get(1).NumberOfUnits + // 106.00
- // newRows.get(2).PricePerUnit * newRows.get(2).NumberOfUnits + // -111.00 (-22.20)
- $this->assertRegexp('/24500<\/amount>/', $paymentXml);
- $this->assertRegexp('/3380<\/vat>/', $paymentXml);
- }
-
- public function test_FixedDiscount_specified_using_ExVat_and_IncVat_is_added_as_single_discount_row()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1.0)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(111.00)
- ->setAmountExVat(88.80)
- );
-
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // 111.00inc and 88.80ex => @25% => -111.00 (-22.20)
- $newRow = $newRows[2];
- $this->assertEquals(-11100, $newRow->amount);
- $this->assertEquals(-2220, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // newRows.get(0).PricePerUnit * newRows.get(0).NumberOfUnits + // 250.00
- // newRows.get(1).PricePerUnit * newRows.get(1).NumberOfUnits + // 106.00
- // newRows.get(2).PricePerUnit * newRows.get(2).NumberOfUnits + // -111.00 (-22.20)
- $this->assertRegexp('/24500<\/amount>/', $paymentXml);
- $this->assertRegexp('/3380<\/vat>/', $paymentXml);
- }
-
- // check that fixed discount split over vat rates ratios are present based on order item rows only, not shipping or invoice fees
- public function test_FixedDiscount_specified_using_amountExVat_is_calculated_from_order_item_rows_only()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @25% = 125")
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @6% = 106")
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1.0)
- )
- ->addFee(WebPayItem::shippingFee()// fee row should be ignored by discount calculation
- ->setName("shipping with price 50 @6% = 53")
- ->setAmountExVat(50.00)
- ->setVatPercent(6)
- )
- ->addFee(WebPayItem::invoiceFee()// fee row should be ignored by discount calculation
- ->setAmountExVat(23.20)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100e")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountExVat(100.00)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // 100*200/300 = 66.67 ex. 25% vat => discount 83.34 (incl. 16.67 vat @25%)
- // 100*100/300 = 33.33 ex. 6% vat => discount 35.33 (incl 2.00 vat @6%)
- // => total discount is 118.67 (incl 18.67 vat @18.67%)
-
- $newRow = $newRows[4];
- $this->assertEquals("f100e", $newRow->sku);
- $this->assertEquals("couponName", $newRow->name);
- $this->assertEquals("couponDesc", $newRow->description);
- $this->assertEquals(-11867, $newRow->amount);
- $this->assertEquals(-1867, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // 250.00 (50.00)
- // 106.00 (6.00)
- // 53.00 (3.00)
- // 29.00 (5.80)
- // -118.67 (-18.67)
- // => 319.33 (46.13)
- $this->assertRegexp('/31933<\/amount>/', $paymentXml);
- $this->assertRegexp('/4613<\/vat>/', $paymentXml);
- }
-
- // check that fixed discount split over vat rates ratios are present based on order item rows only, not shipping or invoice fees
- public function test_FixedDiscount_specified_using_amountIncVat_is_calculated_from_order_item_rows_only()
- {
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @25% = 125")
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @6% = 106")
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1.0)
- )
- ->addFee(WebPayItem::shippingFee()// fee row should be ignored by discount calculation
- ->setName("shipping with price 50 @6% = 53")
- ->setAmountExVat(50.00)
- ->setVatPercent(6)
- )
- ->addFee(WebPayItem::invoiceFee()// fee row should be ignored by discount calculation
- ->setAmountExVat(23.20)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100i")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountIncVat(100.00)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
- // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
- // => total discount is 100.00 (incl 15.73 vat)
-
- // validate HostedOrderRowBuilder row contents
- $newRow = $newRows[4];
- $this->assertEquals("f100i", $newRow->sku);
- $this->assertEquals("couponName", $newRow->name);
- $this->assertEquals("couponDesc", $newRow->description);
- $this->assertEquals(-10000, $newRow->amount);
- $this->assertEquals(-1573, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // 250.00 (50.00)
- // 106.00 (6.00)
- // 53.00 (3.00)
- // 29.00 (5.80)
- // -70.22 (14.04) + 29.78 (1.69) = -100.00 (-15.73)
- // => 338.00 (49.07)
- $this->assertRegexp('/33800<\/amount>/', $paymentXml);
- $this->assertRegexp('/4907<\/vat>/', $paymentXml);
- }
-
- /// relative discount
- // iff no specified discount vat rate, check that calculated vat rate is split correctly across vat rates
- public function test_RelativeDiscount_in_order_with_single_vat_rate()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(40.00)
- ->setVatPercent(25)
- ->setQuantity(2.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(50.00)
- ->setVatPercent(25)
- ->setQuantity(1.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(40.00)
- ->setAmountIncVat(50.00)
- ->setQuantity(1.0)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("r10%i")
- ->setDiscountPercent(10.00)
- ->setUnit("kr"));
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // 10% of (80ex + 40ex + 40ex =) 160ex @25% => -16ex @25% => -20 (-4)
- $newRow = $newRows[3];
- $this->assertEquals("r10%i", $newRow->sku);
- $this->assertEquals(-2000, $newRow->amount);
- $this->assertEquals(-400, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("kr", $newRow->unit);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // 100 (20) + 50 (10) + 50 (10) -20 (-4) => 180 (36)
- $this->assertRegexp('/18000<\/amount>/', $paymentXml);
- $this->assertRegexp('/3600<\/vat>/', $paymentXml);
- }
-
- public function test_RelativeDiscount_in_order_with_multiple_vat_rates()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(40.00)
- ->setVatPercent(25)
- ->setQuantity(2.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(50.00)
- ->setVatPercent(25)
- ->setQuantity(1.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(40.00)
- ->setAmountIncVat(50.00)
- ->setQuantity(1.0)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("r10%i")
- ->setDiscountPercent(10.00)
- ->setUnit("kr"));
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // 10% of (80ex + 40ex + 40ex =) 160ex @25% => -16ex @25% => -20 (-4)
- $newRow = $newRows[3];
- $this->assertEquals("r10%i", $newRow->sku);
- $this->assertEquals(-2000, $newRow->amount);
- $this->assertEquals(-400, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("kr", $newRow->unit);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // 100 (20) + 50 (10) + 50 (10) -20 (-4) => 180 (36)
- $this->assertRegexp('/18000<\/amount>/', $paymentXml);
- $this->assertRegexp('/3600<\/vat>/', $paymentXml);
- }
-
- // check that relative discount split over vat rates ratios are present based on order item rows only, not shipping or invoice fees
- public function test_RelativeDiscount_is_calculated_from_order_item_rows_only()
- {
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1.0)
- )
- ->addFee(WebPayItem::shippingFee()// fee row should be ignored by discount calculation
- ->setAmountIncVat(53.00)
- ->setVatPercent(6)
- )
- ->addFee(WebPayItem::invoiceFee()// fee row should be ignored by discount calculation
- ->setAmountIncVat(29.00)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10.00)
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // 10% of (250 (50) + 106 (6)) = 356 (56) => -35.6 (5.6)
- $newRow = $newRows[4];
- $this->assertEquals(-3560, $newRow->amount);
- $this->assertEquals(-560, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // 250 (50) + 106 (6) +53 (3) + 29 (5.8) -35.6 (-5.6) => 402.4 (59.2)
- $this->assertRegexp('/40240<\/amount>/', $paymentXml);
- $this->assertRegexp('/5920<\/vat>/', $paymentXml);
- }
+ // TODO! move these to Svea\WebPay\Test\UnitTest\WebService\Helper\WebServiceRowFormatterTest as well (as in java package
+ // ported over tests of discounts from WebserviceRowFormatterTest
+
+ /// fixed discount
+ // iff no specified vatPercent => split discount excl. vat over the diffrent tax rates present in order
+ public function test_FixedDiscount_specified_using_amountExVat_in_order_with_single_vat_rate()
+ {
+ $this->order->addOrderRow(WebPayItem::orderRow()
+ // cover all three ways to specify items here: iv+vp, ev+vp, iv+ev
+ ->setAmountExVat(4.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f1e")
+ ->setName("couponName")
+ ->setDescription("couponName")
+ ->setAmountExVat(1.0)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter($this->order);
+ $newRows = $formatter->formatRows($this->order);
+ $newRow = $newRows[1];
+
+ // 1.0 kr @25% => -125 öre discount, of which -25 öre is vat
+ $this->assertEquals("f1e", $newRow->sku);
+ $this->assertEquals("couponName", $newRow->name);
+ $this->assertEquals("couponName", $newRow->description);
+ $this->assertEquals(-125, $newRow->amount);
+ $this->assertEquals(-25, $newRow->vat);
+
+ $paymentForm = $this->order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // 5.00 (1.00) - 1.25 (.25) = 3.75 (.75)
+ $this->assertRegexp('/375<\/amount>/', $paymentXml);
+ $this->assertRegexp('/75<\/vat>/', $paymentXml);
+ }
+
+ public function test_FixedDiscount_specified_using_amountExVat_in_order_with_multiple_vat_rates()
+ {
+ $this->order->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @25% = 125")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @6% = 106")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100e")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountExVat(100.00)
+ );
+
+ $formatter = new HostedRowFormatter($this->order);
+ $newRows = $formatter->formatRows($this->order);
+ $testedRow = $newRows[2];
+
+ // 100*200/300 = 66.67 ex. 25% vat => 83.34 vat as amount of which 16.67 is vat
+ // 100*100/300 = 33.33 ex. 6% vat => 35.33 vat as amount 2.00 is vat
+ // In one discount row -11867 öre, of which 1867 is vat
+ $this->assertEquals("f100e", $testedRow->sku);
+ $this->assertEquals("couponName", $testedRow->name);
+ $this->assertEquals("couponDesc", $testedRow->description);
+ $this->assertEquals(-11867, $testedRow->amount);
+ $this->assertEquals(-1867, $testedRow->vat);
+
+ $paymentForm = $this->order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // newRows.get(0).PricePerUnit * newRows.get(0).NumberOfUnits + // 250.00
+ // newRows.get(1).PricePerUnit * newRows.get(1).NumberOfUnits + // 106.00
+ // newRows.get(2).PricePerUnit * newRows.get(2).NumberOfUnits + // -83.34
+ // newRows.get(3).PricePerUnit * newRows.get(3).NumberOfUnits // -35.33
+ //assertEquals( 237.33, Double.valueOf(String.format(Locale.ENGLISH,"%.2f",total)), 0.001 );
+ $this->assertRegexp('/23733<\/amount>/', $paymentXml);
+ $this->assertRegexp('/3733<\/vat>/', $paymentXml);
+ }
+
+ // iff no specified vatPercent => split discount incl. vat over the diffrent tax rates present in order
+ // public void test_FixedDiscount_specified_using_amountIncVat_in_order_with_single_vat_rate() {
+ public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_single_vat_rate()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4.00)
+ ->setVatPercent(25)
+ ->setQuantity(1.0)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f1e")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountIncVat(1.00)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // validate HostedOrderRowBuilder row contents
+ $newRow = $newRows[1];
+ $this->assertEquals("f1e", $newRow->sku);
+ $this->assertEquals("couponName", $newRow->name);
+ $this->assertEquals("couponDesc", $newRow->description);
+ $this->assertEquals(-100, $newRow->amount);
+ $this->assertEquals(-20, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // 5.00 (1.00) - 1.00 (.20) = 4.00 (1.00)
+ $this->assertRegexp('/400<\/amount>/', $paymentXml);
+ $this->assertRegexp('/100<\/vat>/', $paymentXml);
+ }
+
+ public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_multiple_vat_rates()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @25% = 125")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @6% = 106")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1.0)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100e")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountIncVat(100.00)
+ ->setUnit("st")
+ );
+
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
+ // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
+ // => total discount is 100.00 (incl 15.73 vat)
+ $newRow = $newRows[2];
+ $this->assertEquals("f100e", $newRow->sku);
+ $this->assertEquals("couponName", $newRow->name);
+ $this->assertEquals("couponDesc", $newRow->description);
+ $this->assertEquals(-10000, $newRow->amount);
+ $this->assertEquals(-1573, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // newRows.get(0).PricePerUnit * newRows.get(0).NumberOfUnits + // 250.00
+ // newRows.get(1).PricePerUnit * newRows.get(1).NumberOfUnits + // 106.00
+ // newRows.get(2).PricePerUnit * newRows.get(2).NumberOfUnits + // -70.22 (14.04) + 29.78 (1.69) = -100.00 (-15.73)
+ $this->assertRegexp('/25600<\/amount>/', $paymentXml);
+ $this->assertRegexp('/4027<\/vat>/', $paymentXml);
+ }
+
+ // iff specified vatPercent => add as single row with specified vat rate only honouring specified amount and vatPercent
+ public function test_FixedDiscount_specified_using_IncVat_and_vatPercent_is_added_as_single_discount_row()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1.0)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(111.00)
+ ->setVatPercent(25)
+ );
+
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // -111.00 (-22.20)
+ $newRow = $newRows[2];
+ $this->assertEquals(-11100, $newRow->amount);
+ $this->assertEquals(-2220, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // newRows.get(0).PricePerUnit * newRows.get(0).NumberOfUnits + // 250.00
+ // newRows.get(1).PricePerUnit * newRows.get(1).NumberOfUnits + // 106.00
+ // newRows.get(2).PricePerUnit * newRows.get(2).NumberOfUnits + // -111.00 (-22.20)
+ $this->assertRegexp('/24500<\/amount>/', $paymentXml);
+ $this->assertRegexp('/3380<\/vat>/', $paymentXml);
+ }
+
+ public function test_FixedDiscount_specified_using_ExVat_and_vatPercent_is_added_as_single_discount_row()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1.0)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(88.80)
+ ->setVatPercent(25)
+ );
+
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // 88.80ex @25% => -111.00 (-22.20)
+ $newRow = $newRows[2];
+ $this->assertEquals(-11100, $newRow->amount);
+ $this->assertEquals(-2220, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // newRows.get(0).PricePerUnit * newRows.get(0).NumberOfUnits + // 250.00
+ // newRows.get(1).PricePerUnit * newRows.get(1).NumberOfUnits + // 106.00
+ // newRows.get(2).PricePerUnit * newRows.get(2).NumberOfUnits + // -111.00 (-22.20)
+ $this->assertRegexp('/24500<\/amount>/', $paymentXml);
+ $this->assertRegexp('/3380<\/vat>/', $paymentXml);
+ }
+
+ public function test_FixedDiscount_specified_using_ExVat_and_IncVat_is_added_as_single_discount_row()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1.0)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(111.00)
+ ->setAmountExVat(88.80)
+ );
+
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // 111.00inc and 88.80ex => @25% => -111.00 (-22.20)
+ $newRow = $newRows[2];
+ $this->assertEquals(-11100, $newRow->amount);
+ $this->assertEquals(-2220, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // newRows.get(0).PricePerUnit * newRows.get(0).NumberOfUnits + // 250.00
+ // newRows.get(1).PricePerUnit * newRows.get(1).NumberOfUnits + // 106.00
+ // newRows.get(2).PricePerUnit * newRows.get(2).NumberOfUnits + // -111.00 (-22.20)
+ $this->assertRegexp('/24500<\/amount>/', $paymentXml);
+ $this->assertRegexp('/3380<\/vat>/', $paymentXml);
+ }
+
+ // check that fixed discount split over vat rates ratios are present based on order item rows only, not shipping or invoice fees
+ public function test_FixedDiscount_specified_using_amountExVat_is_calculated_from_order_item_rows_only()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @25% = 125")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @6% = 106")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1.0)
+ )
+ ->addFee(WebPayItem::shippingFee()// fee row should be ignored by discount calculation
+ ->setName("shipping with price 50 @6% = 53")
+ ->setAmountExVat(50.00)
+ ->setVatPercent(6)
+ )
+ ->addFee(WebPayItem::invoiceFee()// fee row should be ignored by discount calculation
+ ->setAmountExVat(23.20)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100e")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountExVat(100.00)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // 100*200/300 = 66.67 ex. 25% vat => discount 83.34 (incl. 16.67 vat @25%)
+ // 100*100/300 = 33.33 ex. 6% vat => discount 35.33 (incl 2.00 vat @6%)
+ // => total discount is 118.67 (incl 18.67 vat @18.67%)
+
+ $newRow = $newRows[4];
+ $this->assertEquals("f100e", $newRow->sku);
+ $this->assertEquals("couponName", $newRow->name);
+ $this->assertEquals("couponDesc", $newRow->description);
+ $this->assertEquals(-11867, $newRow->amount);
+ $this->assertEquals(-1867, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // 250.00 (50.00)
+ // 106.00 (6.00)
+ // 53.00 (3.00)
+ // 29.00 (5.80)
+ // -118.67 (-18.67)
+ // => 319.33 (46.13)
+ $this->assertRegexp('/31933<\/amount>/', $paymentXml);
+ $this->assertRegexp('/4613<\/vat>/', $paymentXml);
+ }
+
+ // check that fixed discount split over vat rates ratios are present based on order item rows only, not shipping or invoice fees
+ public function test_FixedDiscount_specified_using_amountIncVat_is_calculated_from_order_item_rows_only()
+ {
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @25% = 125")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @6% = 106")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1.0)
+ )
+ ->addFee(WebPayItem::shippingFee()// fee row should be ignored by discount calculation
+ ->setName("shipping with price 50 @6% = 53")
+ ->setAmountExVat(50.00)
+ ->setVatPercent(6)
+ )
+ ->addFee(WebPayItem::invoiceFee()// fee row should be ignored by discount calculation
+ ->setAmountExVat(23.20)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100i")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountIncVat(100.00)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
+ // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
+ // => total discount is 100.00 (incl 15.73 vat)
+
+ // validate HostedOrderRowBuilder row contents
+ $newRow = $newRows[4];
+ $this->assertEquals("f100i", $newRow->sku);
+ $this->assertEquals("couponName", $newRow->name);
+ $this->assertEquals("couponDesc", $newRow->description);
+ $this->assertEquals(-10000, $newRow->amount);
+ $this->assertEquals(-1573, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // 250.00 (50.00)
+ // 106.00 (6.00)
+ // 53.00 (3.00)
+ // 29.00 (5.80)
+ // -70.22 (14.04) + 29.78 (1.69) = -100.00 (-15.73)
+ // => 338.00 (49.07)
+ $this->assertRegexp('/33800<\/amount>/', $paymentXml);
+ $this->assertRegexp('/4907<\/vat>/', $paymentXml);
+ }
+
+ /// relative discount
+ // iff no specified discount vat rate, check that calculated vat rate is split correctly across vat rates
+ public function test_RelativeDiscount_in_order_with_single_vat_rate()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(40.00)
+ ->setVatPercent(25)
+ ->setQuantity(2.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(50.00)
+ ->setVatPercent(25)
+ ->setQuantity(1.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(40.00)
+ ->setAmountIncVat(50.00)
+ ->setQuantity(1.0)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("r10%i")
+ ->setDiscountPercent(10.00)
+ ->setUnit("kr"));
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // 10% of (80ex + 40ex + 40ex =) 160ex @25% => -16ex @25% => -20 (-4)
+ $newRow = $newRows[3];
+ $this->assertEquals("r10%i", $newRow->sku);
+ $this->assertEquals(-2000, $newRow->amount);
+ $this->assertEquals(-400, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("kr", $newRow->unit);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // 100 (20) + 50 (10) + 50 (10) -20 (-4) => 180 (36)
+ $this->assertRegexp('/18000<\/amount>/', $paymentXml);
+ $this->assertRegexp('/3600<\/vat>/', $paymentXml);
+ }
+
+ public function test_RelativeDiscount_in_order_with_multiple_vat_rates()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(40.00)
+ ->setVatPercent(25)
+ ->setQuantity(2.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(50.00)
+ ->setVatPercent(25)
+ ->setQuantity(1.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(40.00)
+ ->setAmountIncVat(50.00)
+ ->setQuantity(1.0)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("r10%i")
+ ->setDiscountPercent(10.00)
+ ->setUnit("kr"));
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // 10% of (80ex + 40ex + 40ex =) 160ex @25% => -16ex @25% => -20 (-4)
+ $newRow = $newRows[3];
+ $this->assertEquals("r10%i", $newRow->sku);
+ $this->assertEquals(-2000, $newRow->amount);
+ $this->assertEquals(-400, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("kr", $newRow->unit);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // 100 (20) + 50 (10) + 50 (10) -20 (-4) => 180 (36)
+ $this->assertRegexp('/18000<\/amount>/', $paymentXml);
+ $this->assertRegexp('/3600<\/vat>/', $paymentXml);
+ }
+
+ // check that relative discount split over vat rates ratios are present based on order item rows only, not shipping or invoice fees
+ public function test_RelativeDiscount_is_calculated_from_order_item_rows_only()
+ {
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1.0)
+ )
+ ->addFee(WebPayItem::shippingFee()// fee row should be ignored by discount calculation
+ ->setAmountIncVat(53.00)
+ ->setVatPercent(6)
+ )
+ ->addFee(WebPayItem::invoiceFee()// fee row should be ignored by discount calculation
+ ->setAmountIncVat(29.00)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10.00)
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // 10% of (250 (50) + 106 (6)) = 356 (56) => -35.6 (5.6)
+ $newRow = $newRows[4];
+ $this->assertEquals(-3560, $newRow->amount);
+ $this->assertEquals(-560, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // 250 (50) + 106 (6) +53 (3) + 29 (5.8) -35.6 (-5.6) => 402.4 (59.2)
+ $this->assertRegexp('/40240<\/amount>/', $paymentXml);
+ $this->assertRegexp('/5920<\/vat>/', $paymentXml);
+ }
// ----------------------------------------------------
- // FixedDiscountRow specified using only amountIncVat => split discount incl. vat over the diffrent tax rates present in order
- public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_single_vat_rate_php_original_version()
- {
- $this->order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(5.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f1i")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountIncVat(1.0)
- ->setUnit("kr")
- );
- $formatter = new HostedRowFormatter($this->order);
- $resultRows = $formatter->formatRows($this->order);
-
- // 1.0 kr @25% => -100 öre discount, of which -20 öre is vat
- $testedRow = $resultRows[3];
- $this->assertEquals("f1i", $testedRow->sku);
- $this->assertEquals("couponName", $testedRow->name);
- $this->assertEquals("couponDesc", $testedRow->description);
- $this->assertEquals(-100, $testedRow->amount);
- $this->assertEquals(-20, $testedRow->vat);
- }
-
- // FixedDiscountRow specified using only amountIncVat => split discount incl. vat over the diffrent tax rates present in order
- // if we have two orders items with different vat rate, we need to create
- // two discount order rows, one for each vat rate
- // funcation testFormatFixedDiscountRows_amountIncVat_WithDifferentVatRatesPresent() { // don't remove until java/dotnet packages are updated.
- public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_multiple_vat_rates_php_original_version()
- {
- $this->order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100i")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountIncVat(100)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter($this->order);
- $resultRows = $formatter->formatRows($this->order);
-
- // 100*250/356 = -7022 öre discount, of which -1404 öre is vat
- // 100*106/356 = -2978 öre discount, of which -169 öre is vat
- // HostedRowBuilder only creates a single discount row
- $testedRow = $resultRows[2];
- $this->assertEquals("f100i", $testedRow->sku);
- $this->assertEquals("couponName", $testedRow->name);
- $this->assertEquals("couponDesc", $testedRow->description);
- $this->assertEquals(-10000, $testedRow->amount);
- $this->assertEquals(-1573, $testedRow->vat);
-
- }
-
- // FixedDiscount should only look at vat rates from order item rows, not shipping or invoice fees
- public function test_FixedDiscount_specified_using_amountIncVat_is_calculated_from_order_item_rows_only_php_original_version()
- {
- $this->order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(50.00)
- ->setVatPercent(6)
- )
-// ->addFee(\Svea\WebPay\WebPayItem::invoiceFee() // Invoice fees are not processed by HostedRowFormatter
-// ->setAmountExVat(23.20)
-// ->setVatPercent(25)
-// )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100i")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountIncVat(100)
- ->setUnit("kr")
- );
-
- $formatter = new HostedRowFormatter($this->order);
- $resultRows = $formatter->formatRows($this->order);
-
- // 100*250/250 = 100 discount incl. 25% vat => 20 discount vat as amount
- $testedRow = $resultRows[2];
- $this->assertEquals("f100i", $testedRow->sku);
- $this->assertEquals("couponName", $testedRow->name);
- $this->assertEquals("couponDesc", $testedRow->description);
- $this->assertEquals(-10000, $testedRow->amount);
- $this->assertEquals(-2000, $testedRow->vat);
-
- // order total should be 250-100+53+29 = 232 kr
-// $total = HostedRowFormatter::convertExVatToIncVat( $resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent ) * $resultRows[0]->NumberOfUnits +
-// HostedRowFormatter::convertExVatToIncVat( $resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent ) * $resultRows[1]->NumberOfUnits +
-// HostedRowFormatter::convertExVatToIncVat( $resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent ) * $resultRows[2]->NumberOfUnits +
-// HostedRowFormatter::convertExVatToIncVat( $resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent ) * $resultRows[3]->NumberOfUnits;
-// $this->assertEquals(232.00, $total);
+ // FixedDiscountRow specified using only amountIncVat => split discount incl. vat over the diffrent tax rates present in order
+ public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_single_vat_rate_php_original_version()
+ {
+ $this->order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(5.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f1i")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountIncVat(1.0)
+ ->setUnit("kr")
+ );
+ $formatter = new HostedRowFormatter($this->order);
+ $resultRows = $formatter->formatRows($this->order);
+
+ // 1.0 kr @25% => -100 öre discount, of which -20 öre is vat
+ $testedRow = $resultRows[3];
+ $this->assertEquals("f1i", $testedRow->sku);
+ $this->assertEquals("couponName", $testedRow->name);
+ $this->assertEquals("couponDesc", $testedRow->description);
+ $this->assertEquals(-100, $testedRow->amount);
+ $this->assertEquals(-20, $testedRow->vat);
+ }
+
+ // FixedDiscountRow specified using only amountIncVat => split discount incl. vat over the diffrent tax rates present in order
+ // if we have two orders items with different vat rate, we need to create
+ // two discount order rows, one for each vat rate
+ // funcation testFormatFixedDiscountRows_amountIncVat_WithDifferentVatRatesPresent() { // don't remove until java/dotnet packages are updated.
+ public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_multiple_vat_rates_php_original_version()
+ {
+ $this->order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100i")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountIncVat(100)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter($this->order);
+ $resultRows = $formatter->formatRows($this->order);
+
+ // 100*250/356 = -7022 öre discount, of which -1404 öre is vat
+ // 100*106/356 = -2978 öre discount, of which -169 öre is vat
+ // HostedRowBuilder only creates a single discount row
+ $testedRow = $resultRows[2];
+ $this->assertEquals("f100i", $testedRow->sku);
+ $this->assertEquals("couponName", $testedRow->name);
+ $this->assertEquals("couponDesc", $testedRow->description);
+ $this->assertEquals(-10000, $testedRow->amount);
+ $this->assertEquals(-1573, $testedRow->vat);
+
+ }
+
+ // FixedDiscount should only look at vat rates from order item rows, not shipping or invoice fees
+ public function test_FixedDiscount_specified_using_amountIncVat_is_calculated_from_order_item_rows_only_php_original_version()
+ {
+ $this->order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(50.00)
+ ->setVatPercent(6)
+ )
+// ->addFee(\Svea\WebPay\WebPayItem::invoiceFee() // Invoice fees are not processed by HostedRowFormatter
+// ->setAmountExVat(23.20)
+// ->setVatPercent(25)
+// )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100i")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountIncVat(100)
+ ->setUnit("kr")
+ );
+
+ $formatter = new HostedRowFormatter($this->order);
+ $resultRows = $formatter->formatRows($this->order);
+
+ // 100*250/250 = 100 discount incl. 25% vat => 20 discount vat as amount
+ $testedRow = $resultRows[2];
+ $this->assertEquals("f100i", $testedRow->sku);
+ $this->assertEquals("couponName", $testedRow->name);
+ $this->assertEquals("couponDesc", $testedRow->description);
+ $this->assertEquals(-10000, $testedRow->amount);
+ $this->assertEquals(-2000, $testedRow->vat);
+
+ // order total should be 250-100+53+29 = 232 kr
+// $total = HostedRowFormatter::convertExVatToIncVat( $resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent ) * $resultRows[0]->NumberOfUnits +
+// HostedRowFormatter::convertExVatToIncVat( $resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent ) * $resultRows[1]->NumberOfUnits +
+// HostedRowFormatter::convertExVatToIncVat( $resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent ) * $resultRows[2]->NumberOfUnits +
+// HostedRowFormatter::convertExVatToIncVat( $resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent ) * $resultRows[3]->NumberOfUnits;
+// $this->assertEquals(232.00, $total);
//
- }
-
- // check that fixed discount split over vat rates ratios are present based on order item rows only, not shipping or invoice fees
- public function test_FixedDiscount_specified_using_amountExVat_is_calculated_from_order_item_rows_only_php_original_version()
- {
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @25% = 125")
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2.0)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @6% = 106")
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1.0)
- )
- ->addFee(WebPayItem::shippingFee()// fee row should be ignored by discount calculation
- ->setName("shipping with price 50 @6% = 53")
- ->setAmountExVat(50.00)
- ->setVatPercent(6)
- )
- ->addFee(WebPayItem::invoiceFee()// fee row should be ignored by discount calculation
- ->setAmountExVat(23.20)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100e")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountExVat(100.00)
- ->setUnit("st")
- );
-
- $formatter = new HostedRowFormatter();
- $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
-
- // 100*200/300 = 66.67 ex. 25% vat => discount 83.34 (incl. 16.67 vat @25%)
- // 100*100/300 = 33.33 ex. 6% vat => discount 35.33 (incl 2.00 vat @6%)
- // => total discount is 118.67 (incl 18.67 vat @18.67%)
-
- // validate HostedOrderRowBuilder row contents
- $newRow = $newRows[4];
- $this->assertEquals("f100e", $newRow->sku);
- $this->assertEquals("couponName", $newRow->name);
- $this->assertEquals("couponDesc", $newRow->description);
- $this->assertEquals(-11867, $newRow->amount);
- $this->assertEquals(-1867, $newRow->vat);
- $this->assertEquals(1, $newRow->quantity);
- $this->assertEquals("st", $newRow->unit);
-
- $paymentForm = $order
- ->setCountryCode("SE")
- ->setOrderDate("2015-02-23")
- ->setClientOrderNumber("unique")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.com")
- ->getPaymentForm();
- $paymentXml = $paymentForm->xmlMessage;
-
- // // 250.00 (50.00)
- // // 106.00 (6.00)
- // // 53.00 (3.00)
- // // 29.00 (5.80)
- // // -118.67 (-18.67)
- // // => 319.33 (46.13)
- $this->assertRegexp('/31933<\/amount>/', $paymentXml);
- $this->assertRegexp('/4613<\/vat>/', $paymentXml);
- }
-
-
-// ---------------------------------
-
- public function test_RelativeDiscount_in_order_with_single_vat_rate_php_original_version()
- {
- $this->order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(5.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("r10")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setDiscountPercent(10)
- ->setUnit("kr")
- );
-
- $formatter = new HostedRowFormatter();
- $resultRows = $formatter->formatRows($this->order);
- $testedRow = $resultRows[3];
-
- $this->assertEquals("r10", $testedRow->sku);
- $this->assertEquals("couponName", $testedRow->name);
- $this->assertEquals("couponDesc", $testedRow->description);
- $this->assertEquals(-150, $testedRow->amount);
- $this->assertEquals(-30, $testedRow->vat);
- }
+ }
+
+ // check that fixed discount split over vat rates ratios are present based on order item rows only, not shipping or invoice fees
+ public function test_FixedDiscount_specified_using_amountExVat_is_calculated_from_order_item_rows_only_php_original_version()
+ {
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @25% = 125")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2.0)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @6% = 106")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1.0)
+ )
+ ->addFee(WebPayItem::shippingFee()// fee row should be ignored by discount calculation
+ ->setName("shipping with price 50 @6% = 53")
+ ->setAmountExVat(50.00)
+ ->setVatPercent(6)
+ )
+ ->addFee(WebPayItem::invoiceFee()// fee row should be ignored by discount calculation
+ ->setAmountExVat(23.20)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100e")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountExVat(100.00)
+ ->setUnit("st")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $newRows = $formatter->formatRows($order); // of type HostedOrderRowBuilder
+
+ // 100*200/300 = 66.67 ex. 25% vat => discount 83.34 (incl. 16.67 vat @25%)
+ // 100*100/300 = 33.33 ex. 6% vat => discount 35.33 (incl 2.00 vat @6%)
+ // => total discount is 118.67 (incl 18.67 vat @18.67%)
+
+ // validate HostedOrderRowBuilder row contents
+ $newRow = $newRows[4];
+ $this->assertEquals("f100e", $newRow->sku);
+ $this->assertEquals("couponName", $newRow->name);
+ $this->assertEquals("couponDesc", $newRow->description);
+ $this->assertEquals(-11867, $newRow->amount);
+ $this->assertEquals(-1867, $newRow->vat);
+ $this->assertEquals(1, $newRow->quantity);
+ $this->assertEquals("st", $newRow->unit);
+
+ $paymentForm = $order
+ ->setCountryCode("SE")
+ ->setOrderDate("2015-02-23")
+ ->setClientOrderNumber("unique")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.com")
+ ->getPaymentForm();
+ $paymentXml = $paymentForm->xmlMessage;
+
+ // // 250.00 (50.00)
+ // // 106.00 (6.00)
+ // // 53.00 (3.00)
+ // // 29.00 (5.80)
+ // // -118.67 (-18.67)
+ // // => 319.33 (46.13)
+ $this->assertRegexp('/31933<\/amount>/', $paymentXml);
+ $this->assertRegexp('/4613<\/vat>/', $paymentXml);
+ }
+
+
+// ---------------------------------
+
+ public function test_RelativeDiscount_in_order_with_single_vat_rate_php_original_version()
+ {
+ $this->order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(5.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("r10")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setDiscountPercent(10)
+ ->setUnit("kr")
+ );
+
+ $formatter = new HostedRowFormatter();
+ $resultRows = $formatter->formatRows($this->order);
+ $testedRow = $resultRows[3];
+
+ $this->assertEquals("r10", $testedRow->sku);
+ $this->assertEquals("couponName", $testedRow->name);
+ $this->assertEquals("couponDesc", $testedRow->description);
+ $this->assertEquals(-150, $testedRow->amount);
+ $this->assertEquals(-30, $testedRow->vat);
+ }
}
diff --git a/test/UnitTest/HostedService/Helper/HostedXmlBuilderTest.php b/test/UnitTest/HostedService/Helper/HostedXmlBuilderTest.php
index ee726cfb..b7cea291 100644
--- a/test/UnitTest/HostedService/Helper/HostedXmlBuilderTest.php
+++ b/test/UnitTest/HostedService/Helper/HostedXmlBuilderTest.php
@@ -15,175 +15,175 @@
class HostedXmlBuilderTest extends \PHPUnit\Framework\TestCase
{
- private $order;
-
- protected function setUp()
- {
- $this->order = WebPay::createOrder(ConfigurationService::getDefaultConfig());
-
- $this->individualCustomer = new IndividualCustomer();
- $this->individualCustomer->setNationalIdNumber("123456");
-
- $this->orderRow = new OrderRow();
- $this->orderRow->setAmountExVat(100.00);
- $this->orderRow->setVatPercent(25);
- $this->orderRow->setQuantity(2);
- }
-
- public function testBasicXml()
- {
- $this->order->setClientOrderNumber("1234")
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->addCustomerDetails($this->individualCustomer)
- ->addOrderRow($this->orderRow);
-
- $payment = new FakeHostedPayment($this->order);
- $payment->order = $this->order;
- $payment->setReturnUrl("http://myurl.se");
-
- $xmlBuilder = new HostedXmlBuilder();
- $xml = $xmlBuilder->getOrderXML($payment->calculateRequestValues(), $this->order);
-
- $this->assertEquals(1, substr_count($xml, ""));
- $this->assertEquals(1, substr_count($xml, "1234 "));
- $this->assertEquals(1, substr_count($xml, "SEK "));
- $this->assertEquals(1, substr_count($xml, "25000 "));
- $this->assertEquals(1, substr_count($xml, "5000 "));
- $this->assertEquals(1, substr_count($xml, "FALSE "));
- $this->assertEquals(1, substr_count($xml, "en "));
- $this->assertEquals(1, substr_count($xml, 'http://myurl.se '));
- $this->assertEquals(1, substr_count($xml, " "));
- $this->assertEquals(1, substr_count($xml, ""));
- $this->assertEquals(1, substr_count($xml, "123456 "));
- $this->assertEquals(1, substr_count($xml, "SE "));
- $this->assertEquals(1, substr_count($xml, " "));
- $this->assertEquals(1, substr_count($xml, "FALSE "));
- $this->assertEquals(1, substr_count($xml, ""));
- $this->assertEquals(1, substr_count($xml, ""));
- $this->assertEquals(1, substr_count($xml, " "));
- $this->assertEquals(1, substr_count($xml, " "));
- $this->assertEquals(1, substr_count($xml, " "));
- $this->assertEquals(1, substr_count($xml, "12500 "));
- $this->assertEquals(1, substr_count($xml, "2500 "));
- $this->assertEquals(1, substr_count($xml, "2 "));
- $this->assertEquals(1, substr_count($xml, "
"));
- $this->assertEquals(1, substr_count($xml, " "));
- $this->assertEquals(1, substr_count($xml, " "));
- }
-
- public function testXmlWithIndividualCustomer()
- {
- $customer = $this->individualCustomer;
- $customer->setName("Julius", "Caesar");
- $customer->setInitials("JS");
- $customer->setPhoneNumber("999999");
- $customer->setEmail("test@svea.com");
- $customer->setIpAddress("123.123.123.123");
- $customer->setStreetAddress("Gatan", "23");
- $customer->setCoAddress("c/o Eriksson");
- $customer->setZipCode("9999");
- $customer->setLocality("Stan");
-
- $this->order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
- $this->order->setClientOrderNumber("1234")
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->addCustomerDetails($customer)
- ->addOrderRow($this->orderRow);
-
- $payment = new FakeHostedPayment($this->order);
- $payment->order = $this->order;
- $payment->setReturnUrl("http://myurl.se");
-
- $xmlBuilder = new HostedXmlBuilder();
- $xml = $xmlBuilder->getOrderXML($payment->calculateRequestValues(), $this->order);
-
- $this->assertEquals(1, substr_count($xml, "123456 "));
- $this->assertEquals(1, substr_count($xml, "Julius "));
- $this->assertEquals(1, substr_count($xml, "Caesar "));
- $this->assertEquals(1, substr_count($xml, "JS "));
- $this->assertEquals(1, substr_count($xml, "999999 "));
- $this->assertEquals(1, substr_count($xml, "test@svea.com "));
- $this->assertEquals(1, substr_count($xml, "Gatan"));
- $this->assertEquals(1, substr_count($xml, "23 "));
- $this->assertEquals(1, substr_count($xml, "c/o Eriksson "));
- $this->assertEquals(1, substr_count($xml, "9999 "));
- $this->assertEquals(1, substr_count($xml, "Stan "));
- $this->assertEquals(1, substr_count($xml, "SE "));
- }
-
- public function testXmlWithOrderRow()
- {
- $row = $this->orderRow;
- $row->setArticleNumber("1");
- $row->setName("Product");
- $row->setDescription("Good product");
- $row->setUnit("kg");
-
- $this->order->setClientOrderNumber("1234")
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->addCustomerDetails($this->individualCustomer)
- ->addOrderRow($row);
-
- $payment = new FakeHostedPayment($this->order);
- $payment->order = $this->order;
- $payment->setReturnUrl("http://myurl.se");
-
- $xmlBuilder = new HostedXmlBuilder();
- $xml = $xmlBuilder->getOrderXML($payment->calculateRequestValues(), $this->order);
-
- $this->assertEquals(1, substr_count($xml, "1 "));
- $this->assertEquals(1, substr_count($xml, "Product "));
- $this->assertEquals(1, substr_count($xml, "Good product "));
- $this->assertEquals(1, substr_count($xml, "kg "));
- }
-
- public function testXmlWithCancelUrl()
- {
- $payment = new FakeHostedPayment($this->order);
- $payment->setCancelUrl("http://www.cancel.com");
-
- $xmlBuilder = new HostedXmlBuilder();
- $xml = $xmlBuilder->getOrderXML($payment->calculateRequestValues(), $this->order);
-
- $this->assertEquals(1, substr_count($xml, "http://www.cancel.com"));
- }
-
-// public function test_getCreditTransactionXML() {
-//
-// // example from webservice api docs
-// $elements = array(
-// "transactionid" => 521527,
-// "amounttocredit" => 100
-// );
-//
-// // generate the request XML
-// $xmlBuilder = new HostedXmlBuilder();
-// $requestXML = $xmlBuilder->getCreditTransactionXML( $elements );
+ private $order;
+
+ protected function setUp()
+ {
+ $this->order = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+
+ $this->individualCustomer = new IndividualCustomer();
+ $this->individualCustomer->setNationalIdNumber("123456");
+
+ $this->orderRow = new OrderRow();
+ $this->orderRow->setAmountExVat(100.00);
+ $this->orderRow->setVatPercent(25);
+ $this->orderRow->setQuantity(2);
+ }
+
+ public function testBasicXml()
+ {
+ $this->order->setClientOrderNumber("1234")
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->addCustomerDetails($this->individualCustomer)
+ ->addOrderRow($this->orderRow);
+
+ $payment = new FakeHostedPayment($this->order);
+ $payment->order = $this->order;
+ $payment->setReturnUrl("http://myurl.se");
+
+ $xmlBuilder = new HostedXmlBuilder();
+ $xml = $xmlBuilder->getOrderXML($payment->calculateRequestValues(), $this->order);
+
+ $this->assertEquals(1, substr_count($xml, ""));
+ $this->assertEquals(1, substr_count($xml, "1234 "));
+ $this->assertEquals(1, substr_count($xml, "SEK "));
+ $this->assertEquals(1, substr_count($xml, "25000 "));
+ $this->assertEquals(1, substr_count($xml, "5000 "));
+ $this->assertEquals(1, substr_count($xml, "FALSE "));
+ $this->assertEquals(1, substr_count($xml, "en "));
+ $this->assertEquals(1, substr_count($xml, 'http://myurl.se '));
+ $this->assertEquals(1, substr_count($xml, " "));
+ $this->assertEquals(1, substr_count($xml, ""));
+ $this->assertEquals(1, substr_count($xml, "123456 "));
+ $this->assertEquals(1, substr_count($xml, "SE "));
+ $this->assertEquals(1, substr_count($xml, " "));
+ $this->assertEquals(1, substr_count($xml, "FALSE "));
+ $this->assertEquals(1, substr_count($xml, ""));
+ $this->assertEquals(1, substr_count($xml, ""));
+ $this->assertEquals(1, substr_count($xml, " "));
+ $this->assertEquals(1, substr_count($xml, " "));
+ $this->assertEquals(1, substr_count($xml, " "));
+ $this->assertEquals(1, substr_count($xml, "12500 "));
+ $this->assertEquals(1, substr_count($xml, "2500 "));
+ $this->assertEquals(1, substr_count($xml, "2 "));
+ $this->assertEquals(1, substr_count($xml, "
"));
+ $this->assertEquals(1, substr_count($xml, " "));
+ $this->assertEquals(1, substr_count($xml, " "));
+ }
+
+ public function testXmlWithIndividualCustomer()
+ {
+ $customer = $this->individualCustomer;
+ $customer->setName("Julius", "Caesar");
+ $customer->setInitials("JS");
+ $customer->setPhoneNumber("999999");
+ $customer->setEmail("test@svea.com");
+ $customer->setIpAddress("123.123.123.123");
+ $customer->setStreetAddress("Gatan", "23");
+ $customer->setCoAddress("c/o Eriksson");
+ $customer->setZipCode("9999");
+ $customer->setLocality("Stan");
+
+ $this->order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
+ $this->order->setClientOrderNumber("1234")
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->addCustomerDetails($customer)
+ ->addOrderRow($this->orderRow);
+
+ $payment = new FakeHostedPayment($this->order);
+ $payment->order = $this->order;
+ $payment->setReturnUrl("http://myurl.se");
+
+ $xmlBuilder = new HostedXmlBuilder();
+ $xml = $xmlBuilder->getOrderXML($payment->calculateRequestValues(), $this->order);
+
+ $this->assertEquals(1, substr_count($xml, "123456 "));
+ $this->assertEquals(1, substr_count($xml, "Julius "));
+ $this->assertEquals(1, substr_count($xml, "Caesar "));
+ $this->assertEquals(1, substr_count($xml, "JS "));
+ $this->assertEquals(1, substr_count($xml, "999999 "));
+ $this->assertEquals(1, substr_count($xml, "test@svea.com "));
+ $this->assertEquals(1, substr_count($xml, "Gatan"));
+ $this->assertEquals(1, substr_count($xml, "23 "));
+ $this->assertEquals(1, substr_count($xml, "c/o Eriksson "));
+ $this->assertEquals(1, substr_count($xml, "9999 "));
+ $this->assertEquals(1, substr_count($xml, "Stan "));
+ $this->assertEquals(1, substr_count($xml, "SE "));
+ }
+
+ public function testXmlWithOrderRow()
+ {
+ $row = $this->orderRow;
+ $row->setArticleNumber("1");
+ $row->setName("Product");
+ $row->setDescription("Good product");
+ $row->setUnit("kg");
+
+ $this->order->setClientOrderNumber("1234")
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->addCustomerDetails($this->individualCustomer)
+ ->addOrderRow($row);
+
+ $payment = new FakeHostedPayment($this->order);
+ $payment->order = $this->order;
+ $payment->setReturnUrl("http://myurl.se");
+
+ $xmlBuilder = new HostedXmlBuilder();
+ $xml = $xmlBuilder->getOrderXML($payment->calculateRequestValues(), $this->order);
+
+ $this->assertEquals(1, substr_count($xml, "1 "));
+ $this->assertEquals(1, substr_count($xml, "Product "));
+ $this->assertEquals(1, substr_count($xml, "Good product "));
+ $this->assertEquals(1, substr_count($xml, "kg "));
+ }
+
+ public function testXmlWithCancelUrl()
+ {
+ $payment = new FakeHostedPayment($this->order);
+ $payment->setCancelUrl("http://www.cancel.com");
+
+ $xmlBuilder = new HostedXmlBuilder();
+ $xml = $xmlBuilder->getOrderXML($payment->calculateRequestValues(), $this->order);
+
+ $this->assertEquals(1, substr_count($xml, "http://www.cancel.com"));
+ }
+
+// public function test_getCreditTransactionXML() {
//
-// // parse the generated request XML
-// $xmlMessage = new \SimpleXMLElement($requestXML);
-//
-// $this->assertEquals((string)$elements["transactionid"], $xmlMessage->transactionid);
-// $this->assertEquals((string)$elements["amounttocredit"], $xmlMessage->amounttocredit);
-// }
-
-// public function test_getQueryTransactionXML() {
-//
-// // example from webservice api docs
-// $elements = array(
-// "transactionid" => 521527,
-// );
-//
-// // generate the request XML
-// $xmlBuilder = new HostedXmlBuilder();
-// $requestXML = $xmlBuilder->getQueryTransactionXML( $elements );
+// // example from webservice api docs
+// $elements = array(
+// "transactionid" => 521527,
+// "amounttocredit" => 100
+// );
//
-// // parse the generated request XML
-// $xmlMessage = new \SimpleXMLElement($requestXML);
-//
-// $this->assertEquals((string)$elements["transactionid"], $xmlMessage->transactionid);
-// }
+// // generate the request XML
+// $xmlBuilder = new HostedXmlBuilder();
+// $requestXML = $xmlBuilder->getCreditTransactionXML( $elements );
+//
+// // parse the generated request XML
+// $xmlMessage = new \SimpleXMLElement($requestXML);
+//
+// $this->assertEquals((string)$elements["transactionid"], $xmlMessage->transactionid);
+// $this->assertEquals((string)$elements["amounttocredit"], $xmlMessage->amounttocredit);
+// }
+
+// public function test_getQueryTransactionXML() {
+//
+// // example from webservice api docs
+// $elements = array(
+// "transactionid" => 521527,
+// );
+//
+// // generate the request XML
+// $xmlBuilder = new HostedXmlBuilder();
+// $requestXML = $xmlBuilder->getQueryTransactionXML( $elements );
+//
+// // parse the generated request XML
+// $xmlMessage = new \SimpleXMLElement($requestXML);
+//
+// $this->assertEquals((string)$elements["transactionid"], $xmlMessage->transactionid);
+// }
}
diff --git a/test/UnitTest/HostedService/Payment/CardPaymentTest.php b/test/UnitTest/HostedService/Payment/CardPaymentTest.php
index b0eb437a..67eef468 100644
--- a/test/UnitTest/HostedService/Payment/CardPaymentTest.php
+++ b/test/UnitTest/HostedService/Payment/CardPaymentTest.php
@@ -13,453 +13,453 @@
*/
class CardPaymentTest extends \PHPUnit\Framework\TestCase {
- public function testSetAuthorization() {
- $form = WebPay::createOrder(new TestConf())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222)->setIpAddress("123.123.123"))
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPageCardOnly() // PayPageObject
- ->setPayPageLanguage("sv")
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $this->assertEquals("1130", $form->merchantid);
- $this->assertEquals('8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3', $form->secretWord);
- }
-
- public function testBuildCardPayment() {
- $rowFactory = new TestUtil();
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->run($rowFactory->buildShippingFee())
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(50)
- ->setUnit("st")
- ->setName('Relative')
- ->setDescription("RelativeDiscount")
- )
- ->addCustomerDetails(WebPayItem::companyCustomer()
- ->setNationalIdNumber("2345234")
- )
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPageCardOnly() // PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $payment = base64_decode($form->xmlMessageBase64);
- $payment_decoded = new \SimpleXMLElement($payment);
-
- //test values are as expected avter transforming xml to php object
- $this->assertEquals('SEK', $xmlMessage->currency);
- $this->assertEquals('18750', $xmlMessage->amount);
- $this->assertEquals('3750', $xmlMessage->vat);
- $this->assertEquals('12500', $xmlMessage->orderrows->row[0]->amount);
- $this->assertEquals('6250', $xmlMessage->orderrows->row[1]->amount);
- $this->assertEquals('-12500', $xmlMessage->orderrows->row[2]->amount);
- }
-
- public function testCardPaymentForEngCustomer() {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("GBP")
- ->usePayPageCardOnly() // PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $payment = base64_decode($form->xmlMessageBase64);
- $payment_decoded = new \SimpleXMLElement($payment);
-
- //test values are as expected avter transforming xml to php object
- $this->assertEquals('GBP', $xmlMessage->currency);
- }
-
- public function testBuildCardPaymentWithDiffrentProductVatAndDiscount() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(188.68)
- ->setDescription("Bok")
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("1")
- ->setAmountIncVat(100.00)
- ->setUnit("st")
- ->setDescription("testBuildCardPaymentWithDiffrentProductVatAndDiscount")
- ->setName("Fixed")
- )
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPageCardOnly() // PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->setPayPageLanguage("sv")
- ->getPaymentForm();
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
-
- $this->assertEquals('40000', $xmlMessage->amount);
- $this->assertEquals('5706', $xmlMessage->vat);
- }
-
- public function testBuildCardPaymentWithAmountIncVatWithVatPercent() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountIncVat(300.00)
- //->setAmountExVat(240.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountIncVat(200.00)
- ->setDescription("Bok")
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("1")
- ->setAmountIncVat(100.00)
- ->setUnit("st")
- ->setDescription("testBuildCardPaymentWithAmountIncVatWithVatPercent")
- ->setName("Fixed")
- )
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId('33')
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountIncVat(62.50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPageCardOnly() // PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
-
- $this->assertEquals('46250', $xmlMessage->amount);
- $this->assertEquals('6956', $xmlMessage->vat);
- }
-
- public function testBuildCardPaymentWithAmountExVatWithAmountIncVat() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- ->setAmountIncVat(300.00)
- ->setDescription("CD")
- //->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(188.68)
- ->setAmountIncVat(200.00)
- ->setDescription("Bok")
- //->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("1")
- ->setAmountIncVat(100.00)
- ->setUnit("st")
- ->setDescription("testBuildCardPaymentWithAmountExVatWithAmountIncVat")
- ->setName("Fixed")
- )
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPageCardOnly() // PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
-
- $this->assertEquals('40000', $xmlMessage->amount);
- $this->assertEquals('5706', $xmlMessage->vat);
- $this->assertEquals('30000', $xmlMessage->orderrows->row[0]->amount);
- $this->assertEquals('20000', $xmlMessage->orderrows->row[1]->amount);
- $this->assertEquals('-10000', $xmlMessage->orderrows->row[2]->amount);
- }
-
- public function testBuildCardPaymentWithCurrency() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- ->setAmountIncVat(300.00)
- ->setDescription("CD")
- )
- ->setClientOrderNumber("33")
- ->setCurrency(" sek")
- ->setCountryCode("SE")
- ->usePayPageCardOnly() // PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
-
- $this->assertEquals('SEK', $xmlMessage->currency);
- }
-
- public function testBuildCardPaymentWithShippingFee() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- ->setAmountIncVat(300.00)
- ->setDescription("CD")
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(80)
- ->setAmountIncVat(100)
- )
- ->setClientOrderNumber("33")
- ->setCurrency("sek")
- ->setCountryCode("SE")
- ->usePayPageCardOnly() // PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
-
- $this->assertEquals("8000", $xmlMessage->vat);
- $this->assertEquals("40000", $xmlMessage->amount);
- }
-
- public function testBuildCardPaymentWithDecimalLongPrice() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.303030)
- ->setAmountIncVat(300.00)
- ->setDescription("CD")
- )
- ->setClientOrderNumber("33")
- ->setCurrency("sek")
- ->setCountryCode("SE")
- ->usePayPageCardOnly() // PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals("5970", $xmlMessage->vat);
- $this->assertEquals("30000", $xmlMessage->amount);
- }
-
- public function testBuildCardPaymentNLCustomer() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.303030)
- ->setAmountIncVat(300.00)
- ->setDescription("CD")
- )
- ->setClientOrderNumber("33")
- ->setCurrency("sek")
- ->setCountryCode("NL")
- ->usePayPageCardOnly() // PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals("5970", $xmlMessage->vat);
- $this->assertEquals("30000", $xmlMessage->amount);
- }
-
- public function testBuildCardPaymentWithAmountAndVatCero() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(0.00)
- ->setAmountIncVat(0.00)
- ->setDescription("Free shipping")
- )
- ->setClientOrderNumber("33")
- ->setCurrency("sek")
- ->setCountryCode("NL")
- ->usePaymentMethod("KORTCERT")
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals("0", $xmlMessage->orderrows->row->vat);
- $this->assertEquals("0", $xmlMessage->orderrows->row->amount);
- }
-
- /*
- * new feature 2013-10-08
- */
- public function testSetCardPageLanguage() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->setAmountIncVat(125.00)
- ->setDescription("Free shipping")
- )
- ->setClientOrderNumber("33")
- ->setCurrency("sek")
- ->setCountryCode("SE")
- ->usePaymentMethod("KORTCERT")
- ->setCardPageLanguage("sv")
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals("sv", $xmlMessage->lang);
- }
- public function testCallbackUrl() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(100.00)
- ->setAmountIncVat(125.00)
- ->setDescription("Free shipping")
- )
- ->setClientOrderNumber("33")
- ->setCurrency("sek")
- ->setCountryCode("SE")
- ->usePaymentMethod("KORTCERT")
- ->setCallbackUrl("http://myurl.se")
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals("http://myurl.se", $xmlMessage->callbackurl);
-
- }
- public function testNegativeOrderrow() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(-100.00)
- ->setVatPercent(25)
- ->setDescription("Free shipping")
- )
- ->setClientOrderNumber("33")
- ->setCurrency("sek")
- ->setCountryCode("SE")
- ->usePaymentMethod("KORTCERT")
- ->setCallbackUrl("http://myurl.se")
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals("-12500", $xmlMessage->amount);
- $this->assertEquals("-2500", $xmlMessage->vat);
- }
-
- public function test_BuildCardPayment_With_InvoiceFee_ExVat_IncVat() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- ->setAmountIncVat(300.00)
- ->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() // PayPageObject
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
-
- $this->assertEquals("8000", $xmlMessage->vat);
- $this->assertEquals("40000", $xmlMessage->amount);
- }
-
-
- /**
- * test that we can set the subscriptiontype using setSubscriptionType()
- */
- public function test_cardPayment_setSubscriptionType() {
- $cardPayment = new CardPayment(TestUtil::createOrder());
- $cardPayment->setSubscriptionType(CardPayment::RECURRINGCAPTURE);
-
- $this->assertEquals( CardPayment::RECURRINGCAPTURE, $cardPayment->subscriptionType );
- }
-
- /**
- * test that is included in payment request xml
- */
- public function test_cardPayment_request_xml_includes_subscriptiontype() {
- $cardPayment = new CardPayment(TestUtil::createOrder()->setClientOrderNumber("33"));
- $cardPayment
- ->setSubscriptionType(CardPayment::RECURRINGCAPTURE)
- ->setCallbackUrl("http://myurl.se")
- ->setReturnUrl("http://myurl.se")
- ;
- $paymentForm = $cardPayment->getPaymentForm();
-
- $subscriptiontype = "RECURRINGCAPTURE<\/subscriptiontype>"; // remember to escape <_/_subscriptiontype>
- //$this->assertRegExp("/[a-zA-Z0-9<>]*".$subscriptiontype."[a-zA-Z0-9<>]*/","fooRECURRINGCAPTURE bar");
-
- ////print_r($paymentForm->xmlMessage);
- $this->assertRegExp("/[a-zA-Z0-9<>]*".$subscriptiontype."[a-zA-Z0-9<>]*/", $paymentForm->xmlMessage );
- }
+ public function testSetAuthorization() {
+ $form = WebPay::createOrder(new TestConf())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222)->setIpAddress("123.123.123"))
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPageCardOnly() // PayPageObject
+ ->setPayPageLanguage("sv")
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $this->assertEquals("1130", $form->merchantid);
+ $this->assertEquals('8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3', $form->secretWord);
+ }
+
+ public function testBuildCardPayment() {
+ $rowFactory = new TestUtil();
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->run($rowFactory->buildShippingFee())
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(50)
+ ->setUnit("st")
+ ->setName('Relative')
+ ->setDescription("RelativeDiscount")
+ )
+ ->addCustomerDetails(WebPayItem::companyCustomer()
+ ->setNationalIdNumber("2345234")
+ )
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPageCardOnly() // PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $payment = base64_decode($form->xmlMessageBase64);
+ $payment_decoded = new \SimpleXMLElement($payment);
+
+ //test values are as expected avter transforming xml to php object
+ $this->assertEquals('SEK', $xmlMessage->currency);
+ $this->assertEquals('18750', $xmlMessage->amount);
+ $this->assertEquals('3750', $xmlMessage->vat);
+ $this->assertEquals('12500', $xmlMessage->orderrows->row[0]->amount);
+ $this->assertEquals('6250', $xmlMessage->orderrows->row[1]->amount);
+ $this->assertEquals('-12500', $xmlMessage->orderrows->row[2]->amount);
+ }
+
+ public function testCardPaymentForEngCustomer() {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("GBP")
+ ->usePayPageCardOnly() // PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $payment = base64_decode($form->xmlMessageBase64);
+ $payment_decoded = new \SimpleXMLElement($payment);
+
+ //test values are as expected avter transforming xml to php object
+ $this->assertEquals('GBP', $xmlMessage->currency);
+ }
+
+ public function testBuildCardPaymentWithDiffrentProductVatAndDiscount() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(188.68)
+ ->setDescription("Bok")
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("1")
+ ->setAmountIncVat(100.00)
+ ->setUnit("st")
+ ->setDescription("testBuildCardPaymentWithDiffrentProductVatAndDiscount")
+ ->setName("Fixed")
+ )
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPageCardOnly() // PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->setPayPageLanguage("sv")
+ ->getPaymentForm();
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+
+ $this->assertEquals('40000', $xmlMessage->amount);
+ $this->assertEquals('5706', $xmlMessage->vat);
+ }
+
+ public function testBuildCardPaymentWithAmountIncVatWithVatPercent() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountIncVat(300.00)
+ //->setAmountExVat(240.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountIncVat(200.00)
+ ->setDescription("Bok")
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("1")
+ ->setAmountIncVat(100.00)
+ ->setUnit("st")
+ ->setDescription("testBuildCardPaymentWithAmountIncVatWithVatPercent")
+ ->setName("Fixed")
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId('33')
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountIncVat(62.50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPageCardOnly() // PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+
+ $this->assertEquals('46250', $xmlMessage->amount);
+ $this->assertEquals('6956', $xmlMessage->vat);
+ }
+
+ public function testBuildCardPaymentWithAmountExVatWithAmountIncVat() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ ->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ //->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(188.68)
+ ->setAmountIncVat(200.00)
+ ->setDescription("Bok")
+ //->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("1")
+ ->setAmountIncVat(100.00)
+ ->setUnit("st")
+ ->setDescription("testBuildCardPaymentWithAmountExVatWithAmountIncVat")
+ ->setName("Fixed")
+ )
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPageCardOnly() // PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+
+ $this->assertEquals('40000', $xmlMessage->amount);
+ $this->assertEquals('5706', $xmlMessage->vat);
+ $this->assertEquals('30000', $xmlMessage->orderrows->row[0]->amount);
+ $this->assertEquals('20000', $xmlMessage->orderrows->row[1]->amount);
+ $this->assertEquals('-10000', $xmlMessage->orderrows->row[2]->amount);
+ }
+
+ public function testBuildCardPaymentWithCurrency() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ ->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ )
+ ->setClientOrderNumber("33")
+ ->setCurrency(" sek")
+ ->setCountryCode("SE")
+ ->usePayPageCardOnly() // PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+
+ $this->assertEquals('SEK', $xmlMessage->currency);
+ }
+
+ public function testBuildCardPaymentWithShippingFee() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ ->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(80)
+ ->setAmountIncVat(100)
+ )
+ ->setClientOrderNumber("33")
+ ->setCurrency("sek")
+ ->setCountryCode("SE")
+ ->usePayPageCardOnly() // PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+
+ $this->assertEquals("8000", $xmlMessage->vat);
+ $this->assertEquals("40000", $xmlMessage->amount);
+ }
+
+ public function testBuildCardPaymentWithDecimalLongPrice() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.303030)
+ ->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ )
+ ->setClientOrderNumber("33")
+ ->setCurrency("sek")
+ ->setCountryCode("SE")
+ ->usePayPageCardOnly() // PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals("5970", $xmlMessage->vat);
+ $this->assertEquals("30000", $xmlMessage->amount);
+ }
+
+ public function testBuildCardPaymentNLCustomer() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.303030)
+ ->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ )
+ ->setClientOrderNumber("33")
+ ->setCurrency("sek")
+ ->setCountryCode("NL")
+ ->usePayPageCardOnly() // PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals("5970", $xmlMessage->vat);
+ $this->assertEquals("30000", $xmlMessage->amount);
+ }
+
+ public function testBuildCardPaymentWithAmountAndVatCero() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(0.00)
+ ->setAmountIncVat(0.00)
+ ->setDescription("Free shipping")
+ )
+ ->setClientOrderNumber("33")
+ ->setCurrency("sek")
+ ->setCountryCode("NL")
+ ->usePaymentMethod("KORTCERT")
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals("0", $xmlMessage->orderrows->row->vat);
+ $this->assertEquals("0", $xmlMessage->orderrows->row->amount);
+ }
+
+ /*
+ * new feature 2013-10-08
+ */
+ public function testSetCardPageLanguage() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->setAmountIncVat(125.00)
+ ->setDescription("Free shipping")
+ )
+ ->setClientOrderNumber("33")
+ ->setCurrency("sek")
+ ->setCountryCode("SE")
+ ->usePaymentMethod("KORTCERT")
+ ->setCardPageLanguage("sv")
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals("sv", $xmlMessage->lang);
+ }
+ public function testCallbackUrl() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(100.00)
+ ->setAmountIncVat(125.00)
+ ->setDescription("Free shipping")
+ )
+ ->setClientOrderNumber("33")
+ ->setCurrency("sek")
+ ->setCountryCode("SE")
+ ->usePaymentMethod("KORTCERT")
+ ->setCallbackUrl("http://myurl.se")
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals("http://myurl.se", $xmlMessage->callbackurl);
+
+ }
+ public function testNegativeOrderrow() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(-100.00)
+ ->setVatPercent(25)
+ ->setDescription("Free shipping")
+ )
+ ->setClientOrderNumber("33")
+ ->setCurrency("sek")
+ ->setCountryCode("SE")
+ ->usePaymentMethod("KORTCERT")
+ ->setCallbackUrl("http://myurl.se")
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals("-12500", $xmlMessage->amount);
+ $this->assertEquals("-2500", $xmlMessage->vat);
+ }
+
+ public function test_BuildCardPayment_With_InvoiceFee_ExVat_IncVat() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ ->setAmountIncVat(300.00)
+ ->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() // PayPageObject
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+
+ $this->assertEquals("8000", $xmlMessage->vat);
+ $this->assertEquals("40000", $xmlMessage->amount);
+ }
+
+
+ /**
+ * test that we can set the subscriptiontype using setSubscriptionType()
+ */
+ public function test_cardPayment_setSubscriptionType() {
+ $cardPayment = new CardPayment(TestUtil::createOrder());
+ $cardPayment->setSubscriptionType(CardPayment::RECURRINGCAPTURE);
+
+ $this->assertEquals( CardPayment::RECURRINGCAPTURE, $cardPayment->subscriptionType );
+ }
+
+ /**
+ * test that is included in payment request xml
+ */
+ public function test_cardPayment_request_xml_includes_subscriptiontype() {
+ $cardPayment = new CardPayment(TestUtil::createOrder()->setClientOrderNumber("33"));
+ $cardPayment
+ ->setSubscriptionType(CardPayment::RECURRINGCAPTURE)
+ ->setCallbackUrl("http://myurl.se")
+ ->setReturnUrl("http://myurl.se")
+ ;
+ $paymentForm = $cardPayment->getPaymentForm();
+
+ $subscriptiontype = "RECURRINGCAPTURE<\/subscriptiontype>"; // remember to escape <_/_subscriptiontype>
+ //$this->assertRegExp("/[a-zA-Z0-9<>]*".$subscriptiontype."[a-zA-Z0-9<>]*/","fooRECURRINGCAPTURE bar");
+
+ ////print_r($paymentForm->xmlMessage);
+ $this->assertRegExp("/[a-zA-Z0-9<>]*".$subscriptiontype."[a-zA-Z0-9<>]*/", $paymentForm->xmlMessage );
+ }
}
diff --git a/test/UnitTest/HostedService/Payment/DirectPaymentTest.php b/test/UnitTest/HostedService/Payment/DirectPaymentTest.php
index 7d350c1b..b0388ee2 100644
--- a/test/UnitTest/HostedService/Payment/DirectPaymentTest.php
+++ b/test/UnitTest/HostedService/Payment/DirectPaymentTest.php
@@ -15,92 +15,92 @@
*/
class DirectPaymentTest extends \PHPUnit\Framework\TestCase {
- public function testConfigureExcludedPaymentMethods() {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->run($rowFactory->buildShippingFee())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setNationalIdNumber(194605092222)
- )
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPageDirectBankOnly()
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
+ public function testConfigureExcludedPaymentMethods() {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->run($rowFactory->buildShippingFee())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setNationalIdNumber(194605092222)
+ )
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPageDirectBankOnly()
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
-
-// $excluded = (array)$xmlMessage->excludepaymentmethods->exclude; // only works with php 5.5
-// $this->assertTrue( in_array( SystemPaymentMethod::KORTCERT, $excluded ) );
-// $this->assertTrue( in_array( SystemPaymentMethod::SKRILL, $excluded ) );
-// $this->assertTrue( in_array( SystemPaymentMethod::PAYPAL, $excluded ) );
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals( SystemPaymentMethod::KORTCERT, $xmlMessage->excludepaymentmethods->exclude[14] );
- $this->assertEquals( SystemPaymentMethod::SKRILL, $xmlMessage->excludepaymentmethods->exclude[15] );
- $this->assertEquals( SystemPaymentMethod::PAYPAL, $xmlMessage->excludepaymentmethods->exclude[17] );
- }
+// $excluded = (array)$xmlMessage->excludepaymentmethods->exclude; // only works with php 5.5
+// $this->assertTrue( in_array( SystemPaymentMethod::KORTCERT, $excluded ) );
+// $this->assertTrue( in_array( SystemPaymentMethod::SKRILL, $excluded ) );
+// $this->assertTrue( in_array( SystemPaymentMethod::PAYPAL, $excluded ) );
- public function testBuildDirectBankPayment() {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId('33')
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountExVat(50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(50)
- ->setUnit("st")
- ->setName('Relative')
- ->setDescription("RelativeDiscount")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPageDirectBankOnly()
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
+ $this->assertEquals( SystemPaymentMethod::KORTCERT, $xmlMessage->excludepaymentmethods->exclude[14] );
+ $this->assertEquals( SystemPaymentMethod::SKRILL, $xmlMessage->excludepaymentmethods->exclude[15] );
+ $this->assertEquals( SystemPaymentMethod::PAYPAL, $xmlMessage->excludepaymentmethods->exclude[17] );
+ }
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- //test values are as expected avter transforming xml to php object
- $this->assertEquals('SEK', $xmlMessage->currency);
- $this->assertEquals('18750', $xmlMessage->amount);
- $this->assertEquals('3750', $xmlMessage->vat); //may change when we recaltulate in Cartpymentclass
- $this->assertEquals('12500', $xmlMessage->orderrows->row[0]->amount);
- $this->assertEquals('6250', $xmlMessage->orderrows->row[1]->amount);
- $this->assertEquals('-12500', $xmlMessage->orderrows->row[2]->amount);
- }
- public function testBuildDirectBankPaymentCallBackUrl() {
- $config = ConfigurationService::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();
+ public function testBuildDirectBankPayment() {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId('33')
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountExVat(50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(50)
+ ->setUnit("st")
+ ->setName('Relative')
+ ->setDescription("RelativeDiscount")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPageDirectBankOnly()
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals("http://myurl.se", $xmlMessage->callbackurl);
- }
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ //test values are as expected avter transforming xml to php object
+ $this->assertEquals('SEK', $xmlMessage->currency);
+ $this->assertEquals('18750', $xmlMessage->amount);
+ $this->assertEquals('3750', $xmlMessage->vat); //may change when we recaltulate in Cartpymentclass
+ $this->assertEquals('12500', $xmlMessage->orderrows->row[0]->amount);
+ $this->assertEquals('6250', $xmlMessage->orderrows->row[1]->amount);
+ $this->assertEquals('-12500', $xmlMessage->orderrows->row[2]->amount);
+ }
+ public function testBuildDirectBankPaymentCallBackUrl() {
+ $config = ConfigurationService::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);
+ }
}
diff --git a/test/UnitTest/HostedService/Payment/FakeHostedPayment.php b/test/UnitTest/HostedService/Payment/FakeHostedPayment.php
index 3674417a..1e45edbe 100644
--- a/test/UnitTest/HostedService/Payment/FakeHostedPayment.php
+++ b/test/UnitTest/HostedService/Payment/FakeHostedPayment.php
@@ -8,42 +8,42 @@
class FakeHostedPayment extends HostedPayment
{
- /**
- * Creates a new Svea\WebPay\Test\UnitTest\HostedService\Payment\FakeHostedPayment
- * @param FakeHostedPayment $order
- */
- public function __construct($order)
- {
- parent::__construct($order);
- }
-
-
- protected function configureExcludedPaymentMethods()
- {
- $methods = ExcludePayments::excludeInvoicesAndPaymentPlan();
-
- return $methods;
- }
-
- /**
- * @param string $returnUrlAsString
- * @return HostedPayment
- */
- public function setReturnUrl($returnUrlAsString)
- {
- $this->returnUrl = $returnUrlAsString;
-
- return $this;
- }
-
- /**
- * @param string $cancelUrlAsString
- * @return HostedPayment
- */
- public function setCancelUrl($cancelUrlAsString)
- {
- $this->cancelUrl = $cancelUrlAsString;
-
- return $this;
- }
+ /**
+ * Creates a new Svea\WebPay\Test\UnitTest\HostedService\Payment\FakeHostedPayment
+ * @param FakeHostedPayment $order
+ */
+ public function __construct($order)
+ {
+ parent::__construct($order);
+ }
+
+
+ protected function configureExcludedPaymentMethods()
+ {
+ $methods = ExcludePayments::excludeInvoicesAndPaymentPlan();
+
+ return $methods;
+ }
+
+ /**
+ * @param string $returnUrlAsString
+ * @return HostedPayment
+ */
+ public function setReturnUrl($returnUrlAsString)
+ {
+ $this->returnUrl = $returnUrlAsString;
+
+ return $this;
+ }
+
+ /**
+ * @param string $cancelUrlAsString
+ * @return HostedPayment
+ */
+ public function setCancelUrl($cancelUrlAsString)
+ {
+ $this->cancelUrl = $cancelUrlAsString;
+
+ return $this;
+ }
}
diff --git a/test/UnitTest/HostedService/Payment/FixedDiscountVatCalculationTest.php b/test/UnitTest/HostedService/Payment/FixedDiscountVatCalculationTest.php
index c3da09c7..ed1e04fb 100644
--- a/test/UnitTest/HostedService/Payment/FixedDiscountVatCalculationTest.php
+++ b/test/UnitTest/HostedService/Payment/FixedDiscountVatCalculationTest.php
@@ -11,204 +11,204 @@
* @author Kristian Grossman-Madsen
*/
class BvDiscountTest extends \PHPUnit\Framework\TestCase {
-
- public function test_bv_order_sent_incvat_two_decimals_with_both_discounts() {
-// print_r("\n\n-----test_bv_order_sent_incvat_two_decimals_with_both_discounts()\n");
-
- $order = WebPay::createOrder(\Svea\WebPay\Config\ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("1337")
- ->setOrderDate("2015-05-20")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1.00)
- ->setVatPercent(6)
- ->setQuantity(800)
- ->setName("3.00i@6%*800")
- )
- ->setClientOrderNumber(date('c'))
- ;
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(240)
- ->setVatPercent(6)
- ->setDiscountId("fixedDiscount")
- ->setName("-240i@6%*1")
- )
- ;
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(20)
- ->setVatPercent(6)
- ->setDiscountId("fixedDiscount2")
- ->setName("-20i@6%*1")
- )
- ; $request = $order->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml")
- ->getPaymentForm();
-
-// print_r( $request->xmlMessage );
-
- // 240i@6% => 240 (13,58491) => 24000 (1358)
- $expectedDiscountRow =
- " \n".
- " fixedDiscount \n".
- " -240i@6%*1 \n".
- " \n".
- " -24000 \n".
- " -1358 \n";
- " 1 \n".
- "
\n";
- $this->assertEquals(1, substr_count($request->xmlMessage, $expectedDiscountRow));
-
- // 20i@6% => 2000 (1,132076) => 2000 (113)
- $expectedDiscountRow2 =
- " \n".
- " fixedDiscount2 \n".
- " -20i@6%*1 \n".
- " \n".
- " -2000 \n".
- " -113 \n";
- " 1 \n".
- "
\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:
-
- //
- //
- // KORTCERT
- // 1130
- // 2015-05-20T17:10:39 02:00
- // 54000
- // SEK
- // VISA
- // 444433xxxxxx1100
- // 01
- // 16
- // 304397
- //
- //
- //
- //
- //
- // 194605092222
- //
- //
- //
- // SE
- //
- //
- //
- //
- //
- //
- //
- //
- // 0
- //
- }
-
- 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\WebPay\Config\ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("1337")
- ->setOrderDate("2015-05-20")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1.00)
- ->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://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml");
- $request = $request->getPaymentForm();
-
-// print_r( $request->xmlMessage );
-
- // 240i@6% => 240 (13,58491) => 24000 (1358)
- $expectedDiscountRow =
- " \n".
- " fixedDiscount \n".
- " -240i*1 \n".
- " \n".
- " -24000 \n".
- " -1358 \n";
- " 1 \n".
- "
\n";
- $this->assertEquals(1, substr_count($request->xmlMessage, $expectedDiscountRow));
-
- // 20i@6% => 2000 (1,132076) => 2000 (113)
- $expectedDiscountRow2 =
- " \n".
- " fixedDiscount2 \n".
- " -20i*1 \n".
- " \n".
- " -2000 \n".
- " -113 \n";
- " 1 \n".
- "
\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:
-
- //
- //
- // KORTCERT
- // 1130
- // 2015-05-22T13:00:54 02:00
- // 54000
- // SEK
- // VISA
- // 444433xxxxxx1100
- // 02
- // 17
- // 594378
- //
- //
- //
- //
- //
- // 194605092222
- //
- //
- //
- // SE
- //
- //
- //
- //
- //
- //
- //
- //
- // 0
- //
- }
+
+ public function test_bv_order_sent_incvat_two_decimals_with_both_discounts() {
+// print_r("\n\n-----test_bv_order_sent_incvat_two_decimals_with_both_discounts()\n");
+
+ $order = WebPay::createOrder(\Svea\WebPay\Config\ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("1337")
+ ->setOrderDate("2015-05-20")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1.00)
+ ->setVatPercent(6)
+ ->setQuantity(800)
+ ->setName("3.00i@6%*800")
+ )
+ ->setClientOrderNumber(date('c'))
+ ;
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(240)
+ ->setVatPercent(6)
+ ->setDiscountId("fixedDiscount")
+ ->setName("-240i@6%*1")
+ )
+ ;
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(20)
+ ->setVatPercent(6)
+ ->setDiscountId("fixedDiscount2")
+ ->setName("-20i@6%*1")
+ )
+ ; $request = $order->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml")
+ ->getPaymentForm();
+
+// print_r( $request->xmlMessage );
+
+ // 240i@6% => 240 (13,58491) => 24000 (1358)
+ $expectedDiscountRow =
+ " \n".
+ " fixedDiscount \n".
+ " -240i@6%*1 \n".
+ " \n".
+ " -24000 \n".
+ " -1358 \n";
+ " 1 \n".
+ "
\n";
+ $this->assertEquals(1, substr_count($request->xmlMessage, $expectedDiscountRow));
+
+ // 20i@6% => 2000 (1,132076) => 2000 (113)
+ $expectedDiscountRow2 =
+ " \n".
+ " fixedDiscount2 \n".
+ " -20i@6%*1 \n".
+ " \n".
+ " -2000 \n".
+ " -113 \n";
+ " 1 \n".
+ "
\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:
+
+ //
+ //
+ // KORTCERT
+ // 1130
+ // 2015-05-20T17:10:39 02:00
+ // 54000
+ // SEK
+ // VISA
+ // 444433xxxxxx1100
+ // 01
+ // 16
+ // 304397
+ //
+ //
+ //
+ //
+ //
+ // 194605092222
+ //
+ //
+ //
+ // SE
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // 0
+ //
+ }
+
+ 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\WebPay\Config\ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("1337")
+ ->setOrderDate("2015-05-20")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1.00)
+ ->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://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml");
+ $request = $request->getPaymentForm();
+
+// print_r( $request->xmlMessage );
+
+ // 240i@6% => 240 (13,58491) => 24000 (1358)
+ $expectedDiscountRow =
+ " \n".
+ " fixedDiscount \n".
+ " -240i*1 \n".
+ " \n".
+ " -24000 \n".
+ " -1358 \n";
+ " 1 \n".
+ "
\n";
+ $this->assertEquals(1, substr_count($request->xmlMessage, $expectedDiscountRow));
+
+ // 20i@6% => 2000 (1,132076) => 2000 (113)
+ $expectedDiscountRow2 =
+ " \n".
+ " fixedDiscount2 \n".
+ " -20i*1 \n".
+ " \n".
+ " -2000 \n".
+ " -113 \n";
+ " 1 \n".
+ "
\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:
+
+ //
+ //
+ // KORTCERT
+ // 1130
+ // 2015-05-22T13:00:54 02:00
+ // 54000
+ // SEK
+ // VISA
+ // 444433xxxxxx1100
+ // 02
+ // 17
+ // 594378
+ //
+ //
+ //
+ //
+ //
+ // 194605092222
+ //
+ //
+ //
+ // SE
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // 0
+ //
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/HostedService/Payment/FixedDiscountVatCalculationVat.php b/test/UnitTest/HostedService/Payment/FixedDiscountVatCalculationVat.php
index e807b9bb..e6fba62c 100644
--- a/test/UnitTest/HostedService/Payment/FixedDiscountVatCalculationVat.php
+++ b/test/UnitTest/HostedService/Payment/FixedDiscountVatCalculationVat.php
@@ -14,200 +14,200 @@
class FixedDiscountVatCalculationTest extends \PHPUnit\Framework\TestCase
{
- public function test_bv_order_sent_incvat_two_decimals_with_both_discounts()
- {
-// print_r("\n\n-----test_bv_order_sent_incvat_two_decimals_with_both_discounts()\n");
-
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("1337")
- ->setOrderDate("2015-05-20")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1.00)
- ->setVatPercent(6)
- ->setQuantity(800)
- ->setName("3.00i@6%*800")
- )
- ->setClientOrderNumber(date('c'));
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(240)
- ->setVatPercent(6)
- ->setDiscountId("fixedDiscount")
- ->setName("-240i@6%*1")
- );
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(20)
- ->setVatPercent(6)
- ->setDiscountId("fixedDiscount2")
- ->setName("-20i@6%*1")
- );
- $request = $order->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml")
- ->getPaymentForm();
-
-// print_r( $request->xmlMessage );
-
- // 240i@6% => 240 (13,58491) => 24000 (1358)
- $expectedDiscountRow =
- " \n" .
- " fixedDiscount \n" .
- " -240i@6%*1 \n" .
- " \n" .
- " -24000 \n" .
- " -1358 \n";
- " 1 \n" .
- "
\n";
- $this->assertEquals(1, substr_count($request->xmlMessage, $expectedDiscountRow));
-
- // 20i@6% => 2000 (1,132076) => 2000 (113)
- $expectedDiscountRow2 =
- " \n" .
- " fixedDiscount2 \n" .
- " -20i@6%*1 \n" .
- " \n" .
- " -2000 \n" .
- " -113 \n";
- " 1 \n" .
- "
\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:
-
- //
- //
- // KORTCERT
- // 1130
- // 2015-05-20T17:10:39 02:00
- // 54000
- // SEK
- // VISA
- // 444433xxxxxx1100
- // 01
- // 16
- // 304397
- //
- //
- //
- //
- //
- // 194605092222
- //
- //
- //
- // SE
- //
- //
- //
- //
- //
- //
- //
- //
- // 0
- //
- }
-
- 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(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("1337")
- ->setOrderDate("2015-05-20")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1.00)
- ->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://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml");
- $request = $request->getPaymentForm();
-
-// print_r( $request->xmlMessage );
-
- // 240i@6% => 240 (13,58491) => 24000 (1358)
- $expectedDiscountRow =
- " \n" .
- " fixedDiscount \n" .
- " -240i*1 \n" .
- " \n" .
- " -24000 \n" .
- " -1358 \n";
- " 1 \n" .
- "
\n";
- $this->assertEquals(1, substr_count($request->xmlMessage, $expectedDiscountRow));
-
- // 20i@6% => 2000 (1,132076) => 2000 (113)
- $expectedDiscountRow2 =
- " \n" .
- " fixedDiscount2 \n" .
- " -20i*1 \n" .
- " \n" .
- " -2000 \n" .
- " -113 \n";
- " 1 \n" .
- "
\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:
-
- //
- //
- // KORTCERT
- // 1130
- // 2015-05-22T13:00:54 02:00
- // 54000
- // SEK
- // VISA
- // 444433xxxxxx1100
- // 02
- // 17
- // 594378
- //
- //
- //
- //
- //
- // 194605092222
- //
- //
- //
- // SE
- //
- //
- //
- //
- //
- //
- //
- //
- // 0
- //
- }
+ public function test_bv_order_sent_incvat_two_decimals_with_both_discounts()
+ {
+// print_r("\n\n-----test_bv_order_sent_incvat_two_decimals_with_both_discounts()\n");
+
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("1337")
+ ->setOrderDate("2015-05-20")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1.00)
+ ->setVatPercent(6)
+ ->setQuantity(800)
+ ->setName("3.00i@6%*800")
+ )
+ ->setClientOrderNumber(date('c'));
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(240)
+ ->setVatPercent(6)
+ ->setDiscountId("fixedDiscount")
+ ->setName("-240i@6%*1")
+ );
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(20)
+ ->setVatPercent(6)
+ ->setDiscountId("fixedDiscount2")
+ ->setName("-20i@6%*1")
+ );
+ $request = $order->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("https://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml")
+ ->getPaymentForm();
+
+// print_r( $request->xmlMessage );
+
+ // 240i@6% => 240 (13,58491) => 24000 (1358)
+ $expectedDiscountRow =
+ " \n" .
+ " fixedDiscount \n" .
+ " -240i@6%*1 \n" .
+ " \n" .
+ " -24000 \n" .
+ " -1358 \n";
+ " 1 \n" .
+ "
\n";
+ $this->assertEquals(1, substr_count($request->xmlMessage, $expectedDiscountRow));
+
+ // 20i@6% => 2000 (1,132076) => 2000 (113)
+ $expectedDiscountRow2 =
+ " \n" .
+ " fixedDiscount2 \n" .
+ " -20i@6%*1 \n" .
+ " \n" .
+ " -2000 \n" .
+ " -113 \n";
+ " 1 \n" .
+ "
\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:
+
+ //
+ //
+ // KORTCERT
+ // 1130
+ // 2015-05-20T17:10:39 02:00
+ // 54000
+ // SEK
+ // VISA
+ // 444433xxxxxx1100
+ // 01
+ // 16
+ // 304397
+ //
+ //
+ //
+ //
+ //
+ // 194605092222
+ //
+ //
+ //
+ // SE
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // 0
+ //
+ }
+
+ 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(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("1337")
+ ->setOrderDate("2015-05-20")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1.00)
+ ->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://webpaypaymentgatewaystage.svea.com/webpay-admin/admin/merchantresponsetest.xhtml");
+ $request = $request->getPaymentForm();
+
+// print_r( $request->xmlMessage );
+
+ // 240i@6% => 240 (13,58491) => 24000 (1358)
+ $expectedDiscountRow =
+ " \n" .
+ " fixedDiscount \n" .
+ " -240i*1 \n" .
+ " \n" .
+ " -24000 \n" .
+ " -1358 \n";
+ " 1 \n" .
+ "
\n";
+ $this->assertEquals(1, substr_count($request->xmlMessage, $expectedDiscountRow));
+
+ // 20i@6% => 2000 (1,132076) => 2000 (113)
+ $expectedDiscountRow2 =
+ " \n" .
+ " fixedDiscount2 \n" .
+ " -20i*1 \n" .
+ " \n" .
+ " -2000 \n" .
+ " -113 \n";
+ " 1 \n" .
+ "
\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:
+
+ //
+ //
+ // KORTCERT
+ // 1130
+ // 2015-05-22T13:00:54 02:00
+ // 54000
+ // SEK
+ // VISA
+ // 444433xxxxxx1100
+ // 02
+ // 17
+ // 594378
+ //
+ //
+ //
+ //
+ //
+ // 194605092222
+ //
+ //
+ //
+ // SE
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // 0
+ //
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/HostedService/Payment/HostedPaymentTest.php b/test/UnitTest/HostedService/Payment/HostedPaymentTest.php
index 12393fe3..d4da450b 100644
--- a/test/UnitTest/HostedService/Payment/HostedPaymentTest.php
+++ b/test/UnitTest/HostedService/Payment/HostedPaymentTest.php
@@ -14,422 +14,422 @@
class HostedPaymentTest extends \PHPUnit\Framework\TestCase {
- // TODO move tests of setXXX from subclasses of HostedPayment here
-
- public function test_setXXXUrl() {
-
- $returnUrlAsString = "http://foo.bar.com/1";
- $cancelUrlAsString = "http://foo.bar.com/2";
- $callbackUrlAsString = "http://foo.bar.com/3";
-
- $order = TestUtil::createOrder();
- $payment = $order->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl($returnUrlAsString)
- ->setCancelUrl($cancelUrlAsString)
- ->setCallbackUrl($callbackUrlAsString);
-
- $this->assertEquals($returnUrlAsString, $payment->returnUrl );
- $this->assertEquals($cancelUrlAsString, $payment->cancelUrl );
- $this->assertEquals($callbackUrlAsString, $payment->callbackUrl );
- }
-
- public function test_payPageLanguage_defaults_to_english() {
- $defaultLanguage = "en";
-
- $order = TestUtil::createOrder();
- $payment = $order->usePaymentMethod(PaymentMethod::KORTCERT);
-
- $this->assertEquals($defaultLanguage, $payment->langCode );
- }
-
- public function test_setPayPageLanguage_with_unrecognised_language() {
- $newLanguage = "unrecognised_language";
-
- $order = TestUtil::createOrder();
- $payment = $order->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setPayPageLanguage( $newLanguage );
-
- $this->assertEquals("en", $payment->langCode );
- }
-
- public function test_setPayPageLanguage_with_recognised_language() {
- $orderLanguage = "sv";
-
- $order = TestUtil::createOrder();
- $payment = $order->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setPayPageLanguage( $orderLanguage );
-
- $this->assertEquals($orderLanguage, $payment->langCode );
- }
-
- // TODO tests for getPaymentForm and validatè order
-
- // TODO move the below to Svea\WebPay\Test\UnitTest\HostedService\Helper\HostedRowFormatterTest???
-
- /**
- * 30*69.99*1.25 = 2624.625 => 2624.62 w/Bankers rounding (half-to-even)
- *
- * problem, sums to 2624.7, in xml request, i.e. calculates 30* round( (69.99*1.25), 2) :(
- *
- */
- public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_ItemsDefinedWithExVatAndVatPercent() {
- $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
- $order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
- ->setDescription("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
- ->setAmountExVat(69.99)
- ->setVatPercent(25)
- ->setQuantity(30)
- ->setUnit("st")
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- $this->assertEquals(262462, $request['amount']); // 262462,5 rounded half-to-even
- $this->assertEquals(52492, $request['totalVat']); // 52492,5 rounded half-to-even
- }
-
- public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_ItemsDefinedWithIncVatAndVatPercent() {
- $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
- $order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
- ->setDescription("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
- ->setAmountIncVat(87.4875) // if low precision here, i.e. 87.49, we'll get a cumulative rounding error
- ->setVatPercent(25)
- ->setQuantity(30)
- ->setUnit("st")
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- $this->assertEquals(262462, $request['amount']); // 262462,5 rounded half-to-even
- $this->assertEquals(52492, $request['totalVat']); // 52492,5 rounded half-to-even
- }
-
- public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_ItemsDefinedWithExVatAndIncVat() {
- $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
- $order->
- addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
- ->setDescription("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
- ->setAmountExVat(69.99)
- ->setAmountIncVat(87.4875) // if low precision here, i.e. 87.49, we'll get a cumulative rounding error
- ->setQuantity(30)
- ->setUnit("st")
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- $this->assertEquals(262462, $request['amount']); // 262462,5 rounded half-to-even
- $this->assertEquals(52492, $request['totalVat']); // 52492,5 rounded half-to-even
- }
-
-
-// public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_ItemsDefinedWithIncVatAndExVat() {}
-
- // calculated fixed discount vat rate, single vat rate in order
- public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_WithFixedDiscountIncVatOnly() {
- $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(69.99)
- ->setVatPercent(25)
- ->setQuantity(30)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(10.00)
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- $this->assertEquals(261462, $request['amount']); // 262462,5 rounded half-to-even - 1000 discount
- $this->assertEquals(52292, $request['totalVat']); // 52492,5 rounded half-to-even - 200 discount (= 10/2624,62*524,92)
- }
-
- // explicit fixed discount vat rate, , single vat rate in order
- public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_WithFixedDiscountIncVatAndVatPercent() {
- $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(69.99)
- ->setVatPercent(25)
- ->setQuantity(30)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(12.50)
- ->setVatPercent(25)
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- $this->assertEquals(261212, $request['amount']); // 262462,5 rounded half-to-even - 1250 discount
- $this->assertEquals(52242, $request['totalVat']); // 52492,5 rounded half-to-even - 250 discount
- }
-
- // calculated fixed discount vat rate, multiple vat rate in order
- public function testCalculateRequestValues_CorrectTotalAmount_WithFixedDiscountIncVatOnly_WithDifferentVatRatesPresent() {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(100.00)
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
- // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
- // matches 15,73 discount (= 100/356 *56) discount
- $this->assertEquals(25600, $request['amount']); // 35600 - 10000 discount
- $this->assertEquals(4027, $request['totalVat']); // 5600 - 1573 discount (= 10000/35600 *5600) discount
- }
-
- // explicit fixed discount vat rate, multiple vat rate in order
- public function testCalculateRequestValues_CorrectTotalAmount_WithFixedDiscountIncVatAndVatPercent_WithDifferentVatRatesPresent() {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(125.00)
- ->setVatPercent(25)
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- $this->assertEquals(23100, $request['amount']); // 35600 - 12500 discount
- $this->assertEquals(3100, $request['totalVat']); // 5600 - 2500 discount
- }
-
- public function testCalculateRequestValues_CorrectTotalAmount_WithFixedDiscountExVatAndVatPercent_WithDifferentVatRatesPresent() {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(100.00)
- ->setVatPercent(0)
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- $this->assertEquals(25600, $request['amount']); // 35600 - 10000 discount
- $this->assertEquals(5600, $request['totalVat']); // 5600 - 0 discount
- }
-
- public function testCalculateRequestValues_CorrectTotalAmount_WithFixedDiscountExVatAndIncVat_WithDifferentVatRatesPresent() {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(80.00)
- ->setAmountIncVat(100.00)
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- $this->assertEquals(25600, $request['amount']); // 35600 - 10000 discount
- $this->assertEquals(3600, $request['totalVat']); // 5600 - 2000 discount
- }
-
- // calculated relative discount vat rate, single vat rate in order
- public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_WithRelativeDiscount_WithDifferentVatRatesPresent() {
- $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(69.99)
- ->setVatPercent(25)
- ->setQuantity(30)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(25.00)
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- $this->assertEquals(196846, $request['amount']); // 262462,5 rounded half-to-even - 65615,625 discount (25%) unrounded
- $this->assertEquals(39369, $request['totalVat']); // 52492,5 rounded half-to-even - 13123,125 discount (25%) unrounded
- }
-
- // calculated relative discount vat rate, single vat rate in order
- public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_WithRelativeDiscount_WithDifferentVatRatesPresent2() {
- $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(69.99)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(25.00)
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- $this->assertEquals(6562, $request['amount']); // 8748,75 rounded half-to-even - 2187,18 discount
- $this->assertEquals(1312, $request['totalVat']); // 1749,75 rounded half-to-even - 437,5 discount (1750*.25)
- }
-
- // calculated relative discount vat rate, multiple vat rate in order
- public function testCalculateRequestValues_CorrectTotalAmount_WithRelativeDiscount_WithDifferentVatRatesPresent() {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(25)
- );
-
- // follows HostedPayment calculateRequestValues() outline:
- $formatter = new HostedRowFormatter();
- $request = array();
-
- $request['rows'] = $formatter->formatRows($order);
- $request['amount'] = $formatter->formatTotalAmount($request['rows']);
- $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
-
- // 5000*.25 = 1250
- // 600*.25 = 150
- // matches 1400 discount
- $this->assertEquals(26700, $request['amount']); // 35600 - 8900 discount
- $this->assertEquals(4200, $request['totalVat']); // 5600 - 1400 discount (= 10000/35600 *5600) discount
- }
-
- /**
- * Test to make countrycode optional if you use your own Svea\WebPay\Config\ConfigurationProvider implementation,
- * because it is not required in the request.
- */
- function test_usepaymentmethodpayment_without_countrycode_required_success_when_using_configurationprovider () {
- $order = WebPay::createOrder(new TestConf());
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2))
- ->setCurrency('SEK')
- ->setClientOrderNumber('1010101')
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl('testurl.com')
- ->getPaymentForm();
-
- $this->assertEquals (null, $order->countryCode);
- }
+ // TODO move tests of setXXX from subclasses of HostedPayment here
+
+ public function test_setXXXUrl() {
+
+ $returnUrlAsString = "http://foo.bar.com/1";
+ $cancelUrlAsString = "http://foo.bar.com/2";
+ $callbackUrlAsString = "http://foo.bar.com/3";
+
+ $order = TestUtil::createOrder();
+ $payment = $order->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl($returnUrlAsString)
+ ->setCancelUrl($cancelUrlAsString)
+ ->setCallbackUrl($callbackUrlAsString);
+
+ $this->assertEquals($returnUrlAsString, $payment->returnUrl );
+ $this->assertEquals($cancelUrlAsString, $payment->cancelUrl );
+ $this->assertEquals($callbackUrlAsString, $payment->callbackUrl );
+ }
+
+ public function test_payPageLanguage_defaults_to_english() {
+ $defaultLanguage = "en";
+
+ $order = TestUtil::createOrder();
+ $payment = $order->usePaymentMethod(PaymentMethod::KORTCERT);
+
+ $this->assertEquals($defaultLanguage, $payment->langCode );
+ }
+
+ public function test_setPayPageLanguage_with_unrecognised_language() {
+ $newLanguage = "unrecognised_language";
+
+ $order = TestUtil::createOrder();
+ $payment = $order->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setPayPageLanguage( $newLanguage );
+
+ $this->assertEquals("en", $payment->langCode );
+ }
+
+ public function test_setPayPageLanguage_with_recognised_language() {
+ $orderLanguage = "sv";
+
+ $order = TestUtil::createOrder();
+ $payment = $order->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setPayPageLanguage( $orderLanguage );
+
+ $this->assertEquals($orderLanguage, $payment->langCode );
+ }
+
+ // TODO tests for getPaymentForm and validatè order
+
+ // TODO move the below to Svea\WebPay\Test\UnitTest\HostedService\Helper\HostedRowFormatterTest???
+
+ /**
+ * 30*69.99*1.25 = 2624.625 => 2624.62 w/Bankers rounding (half-to-even)
+ *
+ * problem, sums to 2624.7, in xml request, i.e. calculates 30* round( (69.99*1.25), 2) :(
+ *
+ */
+ public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_ItemsDefinedWithExVatAndVatPercent() {
+ $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
+ $order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
+ ->setDescription("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
+ ->setAmountExVat(69.99)
+ ->setVatPercent(25)
+ ->setQuantity(30)
+ ->setUnit("st")
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ $this->assertEquals(262462, $request['amount']); // 262462,5 rounded half-to-even
+ $this->assertEquals(52492, $request['totalVat']); // 52492,5 rounded half-to-even
+ }
+
+ public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_ItemsDefinedWithIncVatAndVatPercent() {
+ $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
+ $order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
+ ->setDescription("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
+ ->setAmountIncVat(87.4875) // if low precision here, i.e. 87.49, we'll get a cumulative rounding error
+ ->setVatPercent(25)
+ ->setQuantity(30)
+ ->setUnit("st")
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ $this->assertEquals(262462, $request['amount']); // 262462,5 rounded half-to-even
+ $this->assertEquals(52492, $request['totalVat']); // 52492,5 rounded half-to-even
+ }
+
+ public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_ItemsDefinedWithExVatAndIncVat() {
+ $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
+ $order->
+ addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
+ ->setDescription("testCalculateRequestValues_CorrectTotalAmountFromMultipleItems")
+ ->setAmountExVat(69.99)
+ ->setAmountIncVat(87.4875) // if low precision here, i.e. 87.49, we'll get a cumulative rounding error
+ ->setQuantity(30)
+ ->setUnit("st")
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ $this->assertEquals(262462, $request['amount']); // 262462,5 rounded half-to-even
+ $this->assertEquals(52492, $request['totalVat']); // 52492,5 rounded half-to-even
+ }
+
+
+// public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_ItemsDefinedWithIncVatAndExVat() {}
+
+ // calculated fixed discount vat rate, single vat rate in order
+ public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_WithFixedDiscountIncVatOnly() {
+ $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(69.99)
+ ->setVatPercent(25)
+ ->setQuantity(30)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10.00)
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ $this->assertEquals(261462, $request['amount']); // 262462,5 rounded half-to-even - 1000 discount
+ $this->assertEquals(52292, $request['totalVat']); // 52492,5 rounded half-to-even - 200 discount (= 10/2624,62*524,92)
+ }
+
+ // explicit fixed discount vat rate, , single vat rate in order
+ public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_WithFixedDiscountIncVatAndVatPercent() {
+ $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(69.99)
+ ->setVatPercent(25)
+ ->setQuantity(30)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(12.50)
+ ->setVatPercent(25)
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ $this->assertEquals(261212, $request['amount']); // 262462,5 rounded half-to-even - 1250 discount
+ $this->assertEquals(52242, $request['totalVat']); // 52492,5 rounded half-to-even - 250 discount
+ }
+
+ // calculated fixed discount vat rate, multiple vat rate in order
+ public function testCalculateRequestValues_CorrectTotalAmount_WithFixedDiscountIncVatOnly_WithDifferentVatRatesPresent() {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(100.00)
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
+ // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
+ // matches 15,73 discount (= 100/356 *56) discount
+ $this->assertEquals(25600, $request['amount']); // 35600 - 10000 discount
+ $this->assertEquals(4027, $request['totalVat']); // 5600 - 1573 discount (= 10000/35600 *5600) discount
+ }
+
+ // explicit fixed discount vat rate, multiple vat rate in order
+ public function testCalculateRequestValues_CorrectTotalAmount_WithFixedDiscountIncVatAndVatPercent_WithDifferentVatRatesPresent() {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(125.00)
+ ->setVatPercent(25)
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ $this->assertEquals(23100, $request['amount']); // 35600 - 12500 discount
+ $this->assertEquals(3100, $request['totalVat']); // 5600 - 2500 discount
+ }
+
+ public function testCalculateRequestValues_CorrectTotalAmount_WithFixedDiscountExVatAndVatPercent_WithDifferentVatRatesPresent() {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(0)
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ $this->assertEquals(25600, $request['amount']); // 35600 - 10000 discount
+ $this->assertEquals(5600, $request['totalVat']); // 5600 - 0 discount
+ }
+
+ public function testCalculateRequestValues_CorrectTotalAmount_WithFixedDiscountExVatAndIncVat_WithDifferentVatRatesPresent() {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(80.00)
+ ->setAmountIncVat(100.00)
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ $this->assertEquals(25600, $request['amount']); // 35600 - 10000 discount
+ $this->assertEquals(3600, $request['totalVat']); // 5600 - 2000 discount
+ }
+
+ // calculated relative discount vat rate, single vat rate in order
+ public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_WithRelativeDiscount_WithDifferentVatRatesPresent() {
+ $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(69.99)
+ ->setVatPercent(25)
+ ->setQuantity(30)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(25.00)
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ $this->assertEquals(196846, $request['amount']); // 262462,5 rounded half-to-even - 65615,625 discount (25%) unrounded
+ $this->assertEquals(39369, $request['totalVat']); // 52492,5 rounded half-to-even - 13123,125 discount (25%) unrounded
+ }
+
+ // calculated relative discount vat rate, single vat rate in order
+ public function testCalculateRequestValues_CorrectTotalAmountFromMultipleItems_WithRelativeDiscount_WithDifferentVatRatesPresent2() {
+ $order = new CreateOrderBuilder(new SveaConfigurationProvider(ConfigurationService::getDefaultConfig()));
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(69.99)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(25.00)
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ $this->assertEquals(6562, $request['amount']); // 8748,75 rounded half-to-even - 2187,18 discount
+ $this->assertEquals(1312, $request['totalVat']); // 1749,75 rounded half-to-even - 437,5 discount (1750*.25)
+ }
+
+ // calculated relative discount vat rate, multiple vat rate in order
+ public function testCalculateRequestValues_CorrectTotalAmount_WithRelativeDiscount_WithDifferentVatRatesPresent() {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(25)
+ );
+
+ // follows HostedPayment calculateRequestValues() outline:
+ $formatter = new HostedRowFormatter();
+ $request = [];
+
+ $request['rows'] = $formatter->formatRows($order);
+ $request['amount'] = $formatter->formatTotalAmount($request['rows']);
+ $request['totalVat'] = $formatter->formatTotalVat( $request['rows']);
+
+ // 5000*.25 = 1250
+ // 600*.25 = 150
+ // matches 1400 discount
+ $this->assertEquals(26700, $request['amount']); // 35600 - 8900 discount
+ $this->assertEquals(4200, $request['totalVat']); // 5600 - 1400 discount (= 10000/35600 *5600) discount
+ }
+
+ /**
+ * Test to make countrycode optional if you use your own Svea\WebPay\Config\ConfigurationProvider implementation,
+ * because it is not required in the request.
+ */
+ function test_usepaymentmethodpayment_without_countrycode_required_success_when_using_configurationprovider () {
+ $order = WebPay::createOrder(new TestConf());
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2))
+ ->setCurrency('SEK')
+ ->setClientOrderNumber('1010101')
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl('testurl.com')
+ ->getPaymentForm();
+
+ $this->assertEquals (null, $order->countryCode);
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/HostedService/Payment/PayPagePaymentTest.php b/test/UnitTest/HostedService/Payment/PayPagePaymentTest.php
index 73efda60..52f33aaa 100644
--- a/test/UnitTest/HostedService/Payment/PayPagePaymentTest.php
+++ b/test/UnitTest/HostedService/Payment/PayPagePaymentTest.php
@@ -15,165 +15,165 @@
*/
class PayPagePaymentTest extends \PHPUnit\Framework\TestCase {
- public function testBuildPayPagePaymentWithExcludepaymentMethods() {
- $config = ConfigurationService::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")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPage()
- ->setReturnUrl("http://myurl.se")
- ->excludePaymentMethods(PaymentMethod::INVOICE, PaymentMethod::KORTCERT)
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- //test values are as expected avter transforming xml to php object
- $this->assertEquals('SEK', $xmlMessage->currency);
- $this->assertEquals('18750', $xmlMessage->amount);
- $this->assertEquals('3750', $xmlMessage->vat); //may change when we recaltulate in Cartpymentclass
- $this->assertEquals('12500', $xmlMessage->orderrows->row[0]->amount);
- $this->assertEquals('6250', $xmlMessage->orderrows->row[1]->amount);
- $this->assertEquals('-12500', $xmlMessage->orderrows->row[2]->amount);
- // $this->assertEquals(\Svea\WebPay\Constant\PaymentMethod::KORTCERT,$xmlMessage->paymentMethod);
- $this->assertEquals(SystemPaymentMethod::INVOICE_SE, $xmlMessage->excludepaymentmethods->exclude[0]);
- }
-
- public function testpayPagePaymentExcludeCardPayments() {
- $config = ConfigurationService::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")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPage()
- ->setReturnUrl("http://myurl.se")
- ->excludeCardPaymentMethods()
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals(PaymentMethod::KORTCERT, $xmlMessage->excludepaymentmethods->exclude[0]);
- }
-
- public function testExcludeDirectPaymentMethods() {
- $config = ConfigurationService::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")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPage()
- ->setReturnUrl("http://myurl.se")
- ->excludeDirectPaymentMethods()
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals(PaymentMethod::BANKAXESS, $xmlMessage->excludepaymentmethods->exclude[0]);
- }
-
- public function testpayPagePaymentIncludePaymentMethods() {
- $config = ConfigurationService::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")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePayPage()
- ->setReturnUrl("http://myurl.se")
- ->includePaymentMethods(PaymentMethod::KORTCERT, PaymentMethod::SKRILL)
- ->getPaymentForm();
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- //check to see if the first value is one of the excluded ones
- $this->assertEquals(SystemPaymentMethod::BANKAXESS, $xmlMessage->excludepaymentmethods->exclude[0]);
- }
-
- public function testBuildPayPagePaymentVatIsCero() {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(2)
- ->setAmountExVat(100.00)
- ->setName('Prod')
- ->setVatPercent(0)
- )
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setCurrency("SEK")
- ->usePayPage()
- ->setReturnUrl("myurl")
- ->getPaymentForm();
-
-
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- //test values are as expected avter transforming xml to php object
- $this->assertEquals('SEK', $xmlMessage->currency);
- }
-
- public function testBuildPayPagePaymentCallBackUrl() {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $form = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setQuantity(2)
- ->setAmountExVat(100.00)
- ->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);
- }
+ public function testBuildPayPagePaymentWithExcludepaymentMethods() {
+ $config = ConfigurationService::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")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPage()
+ ->setReturnUrl("http://myurl.se")
+ ->excludePaymentMethods(PaymentMethod::INVOICE, PaymentMethod::KORTCERT)
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ //test values are as expected avter transforming xml to php object
+ $this->assertEquals('SEK', $xmlMessage->currency);
+ $this->assertEquals('18750', $xmlMessage->amount);
+ $this->assertEquals('3750', $xmlMessage->vat); //may change when we recaltulate in Cartpymentclass
+ $this->assertEquals('12500', $xmlMessage->orderrows->row[0]->amount);
+ $this->assertEquals('6250', $xmlMessage->orderrows->row[1]->amount);
+ $this->assertEquals('-12500', $xmlMessage->orderrows->row[2]->amount);
+ // $this->assertEquals(\Svea\WebPay\Constant\PaymentMethod::KORTCERT,$xmlMessage->paymentMethod);
+ $this->assertEquals(SystemPaymentMethod::INVOICE_SE, $xmlMessage->excludepaymentmethods->exclude[0]);
+ }
+
+ public function testpayPagePaymentExcludeCardPayments() {
+ $config = ConfigurationService::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")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPage()
+ ->setReturnUrl("http://myurl.se")
+ ->excludeCardPaymentMethods()
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals(PaymentMethod::KORTCERT, $xmlMessage->excludepaymentmethods->exclude[0]);
+ }
+
+ public function testExcludeDirectPaymentMethods() {
+ $config = ConfigurationService::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")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPage()
+ ->setReturnUrl("http://myurl.se")
+ ->excludeDirectPaymentMethods()
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals(PaymentMethod::BANKAXESS, $xmlMessage->excludepaymentmethods->exclude[0]);
+ }
+
+ public function testpayPagePaymentIncludePaymentMethods() {
+ $config = ConfigurationService::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")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePayPage()
+ ->setReturnUrl("http://myurl.se")
+ ->includePaymentMethods(PaymentMethod::KORTCERT, PaymentMethod::SKRILL)
+ ->getPaymentForm();
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ //check to see if the first value is one of the excluded ones
+ $this->assertEquals(SystemPaymentMethod::BANKAXESS, $xmlMessage->excludepaymentmethods->exclude[0]);
+ }
+
+ public function testBuildPayPagePaymentVatIsCero() {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(2)
+ ->setAmountExVat(100.00)
+ ->setName('Prod')
+ ->setVatPercent(0)
+ )
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setCurrency("SEK")
+ ->usePayPage()
+ ->setReturnUrl("myurl")
+ ->getPaymentForm();
+
+
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ //test values are as expected avter transforming xml to php object
+ $this->assertEquals('SEK', $xmlMessage->currency);
+ }
+
+ public function testBuildPayPagePaymentCallBackUrl() {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setQuantity(2)
+ ->setAmountExVat(100.00)
+ ->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);
+ }
}
diff --git a/test/UnitTest/HostedService/Payment/PaymentMethodTest.php b/test/UnitTest/HostedService/Payment/PaymentMethodTest.php
index 8668f762..c4103ccb 100644
--- a/test/UnitTest/HostedService/Payment/PaymentMethodTest.php
+++ b/test/UnitTest/HostedService/Payment/PaymentMethodTest.php
@@ -15,114 +15,114 @@
*/
class PaymentMethodTest extends \PHPUnit\Framework\TestCase{
- public function testPayPagePaymentWithSetPaymentMethod() {
- $config = ConfigurationService::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")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::KORTCERT)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
+ public function testPayPagePaymentWithSetPaymentMethod() {
+ $config = ConfigurationService::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")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::KORTCERT)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals(PaymentMethod::KORTCERT, $xmlMessage->paymentmethod[0]);
- }
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals(PaymentMethod::KORTCERT, $xmlMessage->paymentmethod[0]);
+ }
- public function testPayPagePaymentWithSetPaymentMethodInvoice() {
- $config = ConfigurationService::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")
- )
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(4608142222))
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::INVOICE)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
+ public function testPayPagePaymentWithSetPaymentMethodInvoice() {
+ $config = ConfigurationService::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")
+ )
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(4608142222))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::INVOICE)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals(SystemPaymentMethod::INVOICE_SE, $xmlMessage->paymentmethod[0]);
- $this->assertEquals("TRUE", $xmlMessage->iscompany);
- $this->assertEquals("4608142222", $xmlMessage->customer->ssn);
- }
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals(SystemPaymentMethod::INVOICE_SE, $xmlMessage->paymentmethod[0]);
+ $this->assertEquals("TRUE", $xmlMessage->iscompany);
+ $this->assertEquals("4608142222", $xmlMessage->customer->ssn);
+ }
- public function testPaymentMethodInvoiceNL() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setInitials("SB")
- ->setBirthDate(1923, 12, 12)
- ->setName("Sneider", "Boasman")
- ->setEmail("test@svea.com")
- ->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")
- ->getPaymentForm();
+ public function testPaymentMethodInvoiceNL() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setInitials("SB")
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Sneider", "Boasman")
+ ->setEmail("test@svea.com")
+ ->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")
+ ->getPaymentForm();
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals("FALSE", $xmlMessage->iscompany);
- $this->assertEquals("Sneider", $xmlMessage->customer->firstname);
- }
- public function testPaymentMethodInvoiceNLCallbackUrl() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setInitials("SB")
- ->setBirthDate(1923, 12, 12)
- ->setName("Sneider", "Boasman")
- ->setEmail("test@svea.com")
- ->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("FALSE", $xmlMessage->iscompany);
+ $this->assertEquals("Sneider", $xmlMessage->customer->firstname);
+ }
+ public function testPaymentMethodInvoiceNLCallbackUrl() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setInitials("SB")
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Sneider", "Boasman")
+ ->setEmail("test@svea.com")
+ ->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);
- }
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $this->assertEquals("http://myurl.se", $xmlMessage->callbackurl);
+ }
}
diff --git a/test/UnitTest/HostedService/Payment/SwishPaymentTest.php b/test/UnitTest/HostedService/Payment/SwishPaymentTest.php
index 32a1bb36..67e2d9c5 100644
--- a/test/UnitTest/HostedService/Payment/SwishPaymentTest.php
+++ b/test/UnitTest/HostedService/Payment/SwishPaymentTest.php
@@ -11,127 +11,127 @@
class SwishPaymentTest extends \PHPUnit\Framework\TestCase
{
- public function testSwishBuildPayment() {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setCurrency("SEK")
- ->setPayerAlias("46701234567")
- ->usePaymentMethod(PaymentMethod::SWISH)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
+ public function testSwishBuildPayment() {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setCurrency("SEK")
+ ->setPayerAlias("46701234567")
+ ->usePaymentMethod(PaymentMethod::SWISH)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
- $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
+ $xmlMessage = new \SimpleXMLElement($form->xmlMessage);
- $this->assertEquals('46701234567', $xmlMessage->payeralias);
- $this->assertEquals('SWISH', $xmlMessage->paymentmethod);
- }
+ $this->assertEquals('46701234567', $xmlMessage->payeralias);
+ $this->assertEquals('SWISH', $xmlMessage->paymentmethod);
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect type : payerAlias must be numeric and can not contain any non-numeric characters
- */
- public function testSwishValidationPayerAliasContainsNonNumericCharacters()
- {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setCurrency("SEK")
- ->setPayerAlias("4670123456a")
- ->usePaymentMethod(PaymentMethod::SWISH)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect type : payerAlias must be numeric and can not contain any non-numeric characters
+ */
+ public function testSwishValidationPayerAliasContainsNonNumericCharacters()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setCurrency("SEK")
+ ->setPayerAlias("4670123456a")
+ ->usePaymentMethod(PaymentMethod::SWISH)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect length : payerAlias must be 11 digits
- */
- public function testSwishValidationPayerAliasTooShort()
- {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setCurrency("SEK")
- ->setPayerAlias("4670123456")
- ->usePaymentMethod(PaymentMethod::SWISH)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect length : payerAlias must be 11 digits
+ */
+ public function testSwishValidationPayerAliasTooShort()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setCurrency("SEK")
+ ->setPayerAlias("4670123456")
+ ->usePaymentMethod(PaymentMethod::SWISH)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect length : payerAlias must be 11 digits
- */
- public function testSwishValidationPayerAliasTooLong()
- {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setCurrency("SEK")
- ->setPayerAlias("4670123456789")
- ->usePaymentMethod(PaymentMethod::SWISH)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect length : payerAlias must be 11 digits
+ */
+ public function testSwishValidationPayerAliasTooLong()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setCurrency("SEK")
+ ->setPayerAlias("4670123456789")
+ ->usePaymentMethod(PaymentMethod::SWISH)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect value : countryCode must be set to "SE" if payment method is SWISH
- */
- public function testSwishValidationWrongCountryCode()
- {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("NO")
- ->setClientOrderNumber("33")
- ->setCurrency("SEK")
- ->setPayerAlias("4670123456789")
- ->usePaymentMethod(PaymentMethod::SWISH)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect value : countryCode must be set to "SE" if payment method is SWISH
+ */
+ public function testSwishValidationWrongCountryCode()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("NO")
+ ->setClientOrderNumber("33")
+ ->setCurrency("SEK")
+ ->setPayerAlias("4670123456789")
+ ->usePaymentMethod(PaymentMethod::SWISH)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : payerAlias must be set if using payment method SWISH. Use function setPayerAlias()
- */
- public function testSwishValidationPayerAliasMissing()
- {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setClientOrderNumber("33")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::SWISH)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
- }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : payerAlias must be set if using payment method SWISH. Use function setPayerAlias()
+ */
+ public function testSwishValidationPayerAliasMissing()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("33")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::SWISH)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+ }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -incorrect length : ClientOrderNumber cannot be longer than 35 characters for Swish payments
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -incorrect length : ClientOrderNumber cannot be longer than 35 characters for Swish payments
- public function testSwishValidationClientOrderNumberTooLong()
- {
- $config = ConfigurationService::getDefaultConfig();
- $form = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setClientOrderNumber("3311111111111111111111111")
- ->setCurrency("SEK")
- ->usePaymentMethod(PaymentMethod::SWISH)
- ->setReturnUrl("http://myurl.se")
- ->getPaymentForm();
- }*/
+ public function testSwishValidationClientOrderNumberTooLong()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $form = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("3311111111111111111111111")
+ ->setCurrency("SEK")
+ ->usePaymentMethod(PaymentMethod::SWISH)
+ ->setReturnUrl("http://myurl.se")
+ ->getPaymentForm();
+ }*/
}
\ No newline at end of file
diff --git a/test/UnitTest/HostedService/Payment/TestConf.php b/test/UnitTest/HostedService/Payment/TestConf.php
index 74a568ac..dab1d981 100644
--- a/test/UnitTest/HostedService/Payment/TestConf.php
+++ b/test/UnitTest/HostedService/Payment/TestConf.php
@@ -11,69 +11,69 @@
class TestConf implements ConfigurationProvider
{
- public function getClientNumber($type, $country)
- {
- return 79021;
- }
+ public function getClientNumber($type, $country)
+ {
+ return 79021;
+ }
- public function getEndPoint($type)
- {
- $type = strtoupper($type);
- if ($type == "HOSTED") {
- return ConfigurationService::SWP_PROD_URL;;
- } elseif ($type == "INVOICE" || $type == "PAYMENTPLAN") {
- return ConfigurationService::SWP_PROD_WS_URL;
- } elseif ($type == "HOSTED_ADMIN") {
- return ConfigurationService::SWP_PROD_HOSTED_ADMIN_URL;
- } elseif ($type == "ADMIN") {
- return ConfigurationService::SWP_PROD_ADMIN_URL;
- } else {
- throw new Exception('Invalid type. Accepted values: INVOICE, PAYMENTPLAN, HOSTED_ADMIN or HOSTED');
- }
- }
+ public function getEndPoint($type)
+ {
+ $type = strtoupper($type);
+ if ($type == "HOSTED") {
+ return ConfigurationService::SWP_PROD_URL;;
+ } elseif ($type == "INVOICE" || $type == "PAYMENTPLAN") {
+ return ConfigurationService::SWP_PROD_WS_URL;
+ } elseif ($type == "HOSTED_ADMIN") {
+ return ConfigurationService::SWP_PROD_HOSTED_ADMIN_URL;
+ } elseif ($type == "ADMIN") {
+ return ConfigurationService::SWP_PROD_ADMIN_URL;
+ } else {
+ throw new Exception('Invalid type. Accepted values: INVOICE, PAYMENTPLAN, HOSTED_ADMIN or HOSTED');
+ }
+ }
- public function getMerchantId($type, $country)
- {
- return 1130;
- }
+ public function getMerchantId($type, $country)
+ {
+ return 1130;
+ }
- public function getPassword($type, $country)
- {
- return "sverigetest";
- }
+ public function getPassword($type, $country)
+ {
+ return "sverigetest";
+ }
- public function getSecret($type, $country)
- {
- return "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3";
- }
+ public function getSecret($type, $country)
+ {
+ return "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3";
+ }
- public function getUsername($type, $country)
- {
- return "sverigetest";
- }
+ public function getUsername($type, $country)
+ {
+ return "sverigetest";
+ }
- public function getIntegrationPlatform()
- {
- return "integration_name";
- }
+ public function getIntegrationPlatform()
+ {
+ return "integration_name";
+ }
- public function getIntegrationCompany()
- {
- return "Svea Svea\WebPay\WebPay";
- }
+ public function getIntegrationCompany()
+ {
+ return "Svea Svea\WebPay\WebPay";
+ }
- public function getIntegrationVersion()
- {
- return 'integration_version';
- }
+ public function getIntegrationVersion()
+ {
+ return 'integration_version';
+ }
- public function getCheckoutMerchantId($country = NULL)
- {
- return 1130;
- }
+ public function getCheckoutMerchantId($country = NULL)
+ {
+ return 1130;
+ }
- public function getCheckoutSecret($country = NULL)
- {
- return "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3";
- }
+ public function getCheckoutSecret($country = NULL)
+ {
+ return "8a9cece566e808da63c6f07ff415ff9e127909d000d259aba24daa2fed6d9e3f8b0b62e8ad1fa91c7d7cd6fc3352deaae66cdb533123edf127ad7d1f4c77e7a3";
+ }
}
diff --git a/test/UnitTest/Response/SveaResponseTest.php b/test/UnitTest/Response/SveaResponseTest.php
index 5a36ccd0..7df5e45a 100644
--- a/test/UnitTest/Response/SveaResponseTest.php
+++ b/test/UnitTest/Response/SveaResponseTest.php
@@ -13,86 +13,86 @@
class SveaResponseTest extends \PHPUnit\Framework\TestCase
{
- public function test_handles_response_which_is_null()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $response = new SveaResponse(NULL, "SE", $config);
- $this->assertInternalType('string', $response->getResponse());
- $this->assertEquals('Response is not recognized.', $response->getResponse());
- }
-
- public function test_handles_response_which_is_xml()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $message = "string_that_pretends_to_be_an_encoded_xml_response";
-
- $response = new SveaResponse($message, "SE", $config);
- $this->assertInstanceOf('Svea\WebPay\HostedService\HostedResponse\HostedPaymentResponse', $response->getResponse());
-
- }
-
- public function test_handles_response_is_SimpleXMLElement_object()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $message = (object)array("CloseOrderEuResult" => (object)array("Accepted" => "1", "ResultCode" => "0"));
-
- $this->assertTrue(\is_object($message));
-
- $response = new SveaResponse($message, "SE", $config);
- $this->assertInstanceOf('Svea\WebPay\WebService\WebServiceResponse\CloseOrderResult', $response->getResponse());
- }
-
- /**
- * Investigation of github php-integration issue #39.
- *
- * Also, an example of how to parse a HostedPaymentRequest response, i.e. at
- * the Svea\WebPay\WebPay::createOrder()->..->useCardPayment->getPaymentForm() returnurl
- * by passing the response post data through Svea\WebPay\Response\SveaResponse() to get a response
- * object matching the original payment request.
- */
- public function test_successful_test_card_order_has_accepted_non_zero()
- {
-
- // getSingleCountryConfig fetches a SveaConfigurationProvider object that implements Svea\WebPay\Config\ConfigurationProvider
- // as we don't set any parameters, the object contains only default values, i.e. the merchantid used is 1130
- $config = ConfigurationService::getSingleCountryConfig(
- null, //SE
- null, null, null,
- null, null, null,
- null, null, null,
- null, null,
- false // $prod = false
- );
-
- // $message, $mac and $merchantid below was taken from server logs for a test card transaction to the merchant 1130
- $message = "PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz48cmVzcG9uc2U+PHRyYW5zYWN0aW9uIGlkPSI1ODEzODAiPjxwYXltZW50bWV0aG9kPktPUlRDRVJUPC9wYXltZW50bWV0aG9kPjxtZXJjaGFudGlkPjExMzA8L21lcmNoYW50aWQ+PGN1c3RvbWVycmVmbm8+MzY8L2N1c3RvbWVycmVmbm8+PGFtb3VudD4xODU3ODwvYW1vdW50PjxjdXJyZW5jeT5TRUs8L2N1cnJlbmN5PjxjYXJkdHlwZT5WSVNBPC9jYXJkdHlwZT48bWFza2VkY2FyZG5vPjQ0NDQzM3h4eHh4eDExMDA8L21hc2tlZGNhcmRubz48ZXhwaXJ5bW9udGg+MDE8L2V4cGlyeW1vbnRoPjxleHBpcnl5ZWFyPjE1PC9leHBpcnl5ZWFyPjxhdXRoY29kZT40NTM2MjY8L2F1dGhjb2RlPjxjdXN0b21lcj48Zmlyc3RuYW1lLz48bGFzdG5hbWUvPjxpbml0aWFscy8+PGVtYWlsPnRlc3RAdGltLWludGVybmF0aW9uYWwubmV0PC9lbWFpbD48c3NuPjwvc3NuPjxhZGRyZXNzPktsb2NrYXJnYXRhbiA1QzwvYWRkcmVzcz48YWRkcmVzczIvPjxjaXR5PlbDpHN0ZXLDpXM8L2NpdHk+PGNvdW50cnk+U0U8L2NvdW50cnk+PHppcD43MjM0NDwvemlwPjxwaG9uZT40NjcwNDE2MDA5MDwvcGhvbmU+PHZhdG51bWJlci8+PGhvdXNlbnVtYmVyPjU8L2hvdXNlbnVtYmVyPjxjb21wYW55bmFtZS8+PGZ1bGxuYW1lLz48L2N1c3RvbWVyPjwvdHJhbnNhY3Rpb24+PHN0YXR1c2NvZGU+MDwvc3RhdHVzY29kZT48L3Jlc3BvbnNlPg==";
- $mac = "0411ed66739c251308b70c642fc5f7282f89050421408b74bdd909fb0c13c37c4c2efd6da3593dc388dd28952478aeb1ce5259caf33fd68d364fc4f82914e055";
-
- $merchantId = $config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, "SE");
-
- // the $rawresponse is similar to what we get posted back to our return url following a CardPayment post to i.e. the certitrade payment page
- $rawresponse = array();
- $rawresponse['response'] = $message;
- $rawresponse['mac'] = $mac;
- $rawresponse['merchantId'] = $merchantId;
-
- // $rawresponse is then put into the Svea\WebPay\Response\SveaResponse constructor along with the country and config object
- $sveaResponse = new SveaResponse($rawresponse, "SE", $config);
- // the resulting $response HostedPaymentResponse object contains all relevant information about the payment
- $response = $sveaResponse->getResponse();
-
- // uncomment the following to see the resulting response
-// //print_r( $response ); // accepted is show as having value of 1
-// var_dump( $response ); // note that var_dump lists accepted as 'int(1)' meaning an int with value 1 (in contrast to 'string(3) "SEK"')
+ public function test_handles_response_which_is_null()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $response = new SveaResponse(NULL, "SE", $config);
+ $this->assertInternalType('string', $response->getResponse());
+ $this->assertEquals('Response is not recognized.', $response->getResponse());
+ }
+
+ public function test_handles_response_which_is_xml()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $message = "string_that_pretends_to_be_an_encoded_xml_response";
+
+ $response = new SveaResponse($message, "SE", $config);
+ $this->assertInstanceOf('Svea\WebPay\HostedService\HostedResponse\HostedPaymentResponse', $response->getResponse());
+
+ }
+
+ public function test_handles_response_is_SimpleXMLElement_object()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $message = (object)["CloseOrderEuResult" => (object)["Accepted" => "1", "ResultCode" => "0"]];
+
+ $this->assertTrue(\is_object($message));
+
+ $response = new SveaResponse($message, "SE", $config);
+ $this->assertInstanceOf('Svea\WebPay\WebService\WebServiceResponse\CloseOrderResult', $response->getResponse());
+ }
+
+ /**
+ * Investigation of github php-integration issue #39.
+ *
+ * Also, an example of how to parse a HostedPaymentRequest response, i.e. at
+ * the Svea\WebPay\WebPay::createOrder()->..->useCardPayment->getPaymentForm() returnurl
+ * by passing the response post data through Svea\WebPay\Response\SveaResponse() to get a response
+ * object matching the original payment request.
+ */
+ public function test_successful_test_card_order_has_accepted_non_zero()
+ {
+
+ // getSingleCountryConfig fetches a SveaConfigurationProvider object that implements Svea\WebPay\Config\ConfigurationProvider
+ // as we don't set any parameters, the object contains only default values, i.e. the merchantid used is 1130
+ $config = ConfigurationService::getSingleCountryConfig(
+ null, //SE
+ null, null, null,
+ null, null, null,
+ null, null, null,
+ null, null,
+ false // $prod = false
+ );
+
+ // $message, $mac and $merchantid below was taken from server logs for a test card transaction to the merchant 1130
+ $message = "PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz48cmVzcG9uc2U+PHRyYW5zYWN0aW9uIGlkPSI1ODEzODAiPjxwYXltZW50bWV0aG9kPktPUlRDRVJUPC9wYXltZW50bWV0aG9kPjxtZXJjaGFudGlkPjExMzA8L21lcmNoYW50aWQ+PGN1c3RvbWVycmVmbm8+MzY8L2N1c3RvbWVycmVmbm8+PGFtb3VudD4xODU3ODwvYW1vdW50PjxjdXJyZW5jeT5TRUs8L2N1cnJlbmN5PjxjYXJkdHlwZT5WSVNBPC9jYXJkdHlwZT48bWFza2VkY2FyZG5vPjQ0NDQzM3h4eHh4eDExMDA8L21hc2tlZGNhcmRubz48ZXhwaXJ5bW9udGg+MDE8L2V4cGlyeW1vbnRoPjxleHBpcnl5ZWFyPjE1PC9leHBpcnl5ZWFyPjxhdXRoY29kZT40NTM2MjY8L2F1dGhjb2RlPjxjdXN0b21lcj48Zmlyc3RuYW1lLz48bGFzdG5hbWUvPjxpbml0aWFscy8+PGVtYWlsPnRlc3RAdGltLWludGVybmF0aW9uYWwubmV0PC9lbWFpbD48c3NuPjwvc3NuPjxhZGRyZXNzPktsb2NrYXJnYXRhbiA1QzwvYWRkcmVzcz48YWRkcmVzczIvPjxjaXR5PlbDpHN0ZXLDpXM8L2NpdHk+PGNvdW50cnk+U0U8L2NvdW50cnk+PHppcD43MjM0NDwvemlwPjxwaG9uZT40NjcwNDE2MDA5MDwvcGhvbmU+PHZhdG51bWJlci8+PGhvdXNlbnVtYmVyPjU8L2hvdXNlbnVtYmVyPjxjb21wYW55bmFtZS8+PGZ1bGxuYW1lLz48L2N1c3RvbWVyPjwvdHJhbnNhY3Rpb24+PHN0YXR1c2NvZGU+MDwvc3RhdHVzY29kZT48L3Jlc3BvbnNlPg==";
+ $mac = "0411ed66739c251308b70c642fc5f7282f89050421408b74bdd909fb0c13c37c4c2efd6da3593dc388dd28952478aeb1ce5259caf33fd68d364fc4f82914e055";
+
+ $merchantId = $config->getMerchantId(ConfigurationProvider::HOSTED_TYPE, "SE");
+
+ // the $rawresponse is similar to what we get posted back to our return url following a CardPayment post to i.e. the certitrade payment page
+ $rawresponse = [];
+ $rawresponse['response'] = $message;
+ $rawresponse['mac'] = $mac;
+ $rawresponse['merchantId'] = $merchantId;
+
+ // $rawresponse is then put into the Svea\WebPay\Response\SveaResponse constructor along with the country and config object
+ $sveaResponse = new SveaResponse($rawresponse, "SE", $config);
+ // the resulting $response HostedPaymentResponse object contains all relevant information about the payment
+ $response = $sveaResponse->getResponse();
+
+ // uncomment the following to see the resulting response
+// //print_r( $response ); // accepted is show as having value of 1
+// var_dump( $response ); // note that var_dump lists accepted as 'int(1)' meaning an int with value 1 (in contrast to 'string(3) "SEK"')
//
-// if( empty($response->accepted) ) { //print_r( "test accepted is empty" ); }
-// if( !empty($response->accepted) ) { //print_r( "test accepted not empty" ); }
+// if( empty($response->accepted) ) { //print_r( "test accepted is empty" ); }
+// if( !empty($response->accepted) ) { //print_r( "test accepted not empty" ); }
- $this->assertInstanceOf('Svea\WebPay\HostedService\HostedResponse\HostedPaymentResponse', $response);
- $this->assertEquals(1, $response->accepted);
+ $this->assertInstanceOf('Svea\WebPay\HostedService\HostedResponse\HostedPaymentResponse', $response);
+ $this->assertEquals(1, $response->accepted);
- }
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/WebPayAdminUnitTest.php b/test/UnitTest/WebPayAdminUnitTest.php
index 9a2bbe1f..c81faed9 100644
--- a/test/UnitTest/WebPayAdminUnitTest.php
+++ b/test/UnitTest/WebPayAdminUnitTest.php
@@ -17,551 +17,551 @@
class WebPayAdminUnitTest extends \PHPUnit\Framework\TestCase
{
- public function test_WebPayAdmin_class_exists()
- {
- $adminObject = new WebPayAdmin();
- $this->assertInstanceOf("Svea\WebPay\WebPayAdmin", $adminObject);
- }
-
- // Svea\WebPay\WebPayAdmin::cancelOrder() ----------------------------------------------
- public function test_cancelOrder_returns_CancelOrderBuilder()
- {
- $builderObject = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig());
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\CancelOrderBuilder", $builderObject);
- }
- // TODO add validation unit tests
-
-
- // Svea\WebPay\WebPayAdmin::cancelOrder() -------------------------------------------------------------------------------------
- // returned request class
- public function test_cancelOrder_cancelInvoiceOrder_returns_CloseOrder()
- {
- $cancelOrder = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig());
- $request = $cancelOrder->cancelInvoiceOrder();
- $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\CloseOrder", $request);
- $this->assertEquals(ConfigurationProvider::INVOICE_TYPE, $request->orderBuilder->orderType);
- }
-
- public function test_cancelOrder_cancelPaymentPlanOrder_returns_CloseOrder()
- {
- $cancelOrder = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig());
- $request = $cancelOrder->cancelPaymentPlanOrder();
- $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\CloseOrder", $request);
- $this->assertEquals(ConfigurationProvider::PAYMENTPLAN_TYPE, $request->orderBuilder->orderType);
- }
-
- public function test_cancelOrder_cancelCardOrder_returns_AnnulTransaction()
- {
- $cancelOrder = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig());
- $request = $cancelOrder->cancelCardOrder();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\AnnulTransaction", $request);
- }
- /// validators
- // invoice
-// public void test_validates_all_required_methods_for_cancelOrder_cancelInvoiceOrder() {
-// public void test_missing_required_method_for_cancelOrder_cancelInvoiceOrder_setOrderId() {
-// public void test_missing_required_method_for_cancelOrder_cancelInvoiceOrder_setCountryCode() {
-// public void test_validates_all_required_methods_for_cancelOrder_cancelPaymentPlanOrder() {
-// public void test_missing_required_method_for_cancelOrder_cancelPaymentPlanOrder_setOrderId() {
-// public void test_missing_required_method_for_cancelOrder_cancelPaymentPlanOrder_setCountryCode() {
- // card
- function test_validates_all_required_methods_for_cancelOrder_cancelCardOrder()
- {
- $request = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId("123456789")
- ->setCountryCode("SE");
- try {
- $request->cancelCardOrder()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response
- */
- function test_missing_required_method_for_cancelOrder_cancelCardOrder_setOrderId()
- {
- $request = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
- //->setOrderId("123456789")
- ->setCountryCode("SE");
- $request->cancelCardOrder()->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : CountryCode is required. Use function setCountryCode().
- */
- function test_missing_required_method_for_cancelOrder_cancelCardOrder_setCountryCode()
- {
- $request = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId("123456789")//->setCountryCode("SE")
- ;
- $request->cancelCardOrder()->prepareRequest();
- }
-
- // direct bank
- public function test_queryOrder_queryInvoiceOrder_returns_GetOrdersRequest()
- {
- $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
- $request = $queryOrder->queryInvoiceOrder();
- $this->assertInstanceOf("Svea\WebPay\AdminService\GetOrdersRequest", $request);
- $this->assertEquals(ConfigurationProvider::INVOICE_TYPE, $request->orderBuilder->orderType);
- }
-
- public function test_queryOrder_queryPaymentPlanOrder_returns_GetOrdersRequest()
- {
- $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
- $request = $queryOrder->queryPaymentPlanOrder();
- $this->assertInstanceOf("Svea\WebPay\AdminService\GetOrdersRequest", $request);
- $this->assertEquals(ConfigurationProvider::PAYMENTPLAN_TYPE, $request->orderBuilder->orderType);
- }
-
- public function test_queryOrder_queryCardOrder_returns_QueryTransaction()
- {
- $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
- $request = $queryOrder->queryCardOrder();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransaction", $request);
- }
-
- public function test_queryOrder_queryCardOrder_returns_QueryTransactionByCustomerRefNo()
- {
- $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setClientOrderNumber("123");
- $request = $queryOrder->queryCardOrder();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransactionByCustomerRefNo", $request);
- }
-
- public function test_queryOrder_queryDirectBankOrder_returns_QueryTransaction()
- {
- $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
- $request = $queryOrder->queryDirectBankOrder();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransaction", $request);
- }
-
- public function test_queryOrder_queryDirectBankOrder_returns_QueryTransactionByCustomerRefNo()
- {
- $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
- ->setClientOrderNumber("123");
- $request = $queryOrder->queryDirectBankOrder();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransactionByCustomerRefNo", $request);
- }
+ public function test_WebPayAdmin_class_exists()
+ {
+ $adminObject = new WebPayAdmin();
+ $this->assertInstanceOf("Svea\WebPay\WebPayAdmin", $adminObject);
+ }
+
+ // Svea\WebPay\WebPayAdmin::cancelOrder() ----------------------------------------------
+ public function test_cancelOrder_returns_CancelOrderBuilder()
+ {
+ $builderObject = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig());
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\CancelOrderBuilder", $builderObject);
+ }
+ // TODO add validation unit tests
+
+
+ // Svea\WebPay\WebPayAdmin::cancelOrder() -------------------------------------------------------------------------------------
+ // returned request class
+ public function test_cancelOrder_cancelInvoiceOrder_returns_CloseOrder()
+ {
+ $cancelOrder = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig());
+ $request = $cancelOrder->cancelInvoiceOrder();
+ $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\CloseOrder", $request);
+ $this->assertEquals(ConfigurationProvider::INVOICE_TYPE, $request->orderBuilder->orderType);
+ }
+
+ public function test_cancelOrder_cancelPaymentPlanOrder_returns_CloseOrder()
+ {
+ $cancelOrder = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig());
+ $request = $cancelOrder->cancelPaymentPlanOrder();
+ $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\CloseOrder", $request);
+ $this->assertEquals(ConfigurationProvider::PAYMENTPLAN_TYPE, $request->orderBuilder->orderType);
+ }
+
+ public function test_cancelOrder_cancelCardOrder_returns_AnnulTransaction()
+ {
+ $cancelOrder = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig());
+ $request = $cancelOrder->cancelCardOrder();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\AnnulTransaction", $request);
+ }
+ /// validators
+ // invoice
+// public void test_validates_all_required_methods_for_cancelOrder_cancelInvoiceOrder() {
+// public void test_missing_required_method_for_cancelOrder_cancelInvoiceOrder_setOrderId() {
+// public void test_missing_required_method_for_cancelOrder_cancelInvoiceOrder_setCountryCode() {
+// public void test_validates_all_required_methods_for_cancelOrder_cancelPaymentPlanOrder() {
+// public void test_missing_required_method_for_cancelOrder_cancelPaymentPlanOrder_setOrderId() {
+// public void test_missing_required_method_for_cancelOrder_cancelPaymentPlanOrder_setCountryCode() {
+ // card
+ function test_validates_all_required_methods_for_cancelOrder_cancelCardOrder()
+ {
+ $request = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId("123456789")
+ ->setCountryCode("SE");
+ try {
+ $request->cancelCardOrder()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : transactionId is required. Use function setTransactionId() with the SveaOrderId from the createOrder response
+ */
+ function test_missing_required_method_for_cancelOrder_cancelCardOrder_setOrderId()
+ {
+ $request = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
+ //->setOrderId("123456789")
+ ->setCountryCode("SE");
+ $request->cancelCardOrder()->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : CountryCode is required. Use function setCountryCode().
+ */
+ function test_missing_required_method_for_cancelOrder_cancelCardOrder_setCountryCode()
+ {
+ $request = WebPayAdmin::cancelOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId("123456789")//->setCountryCode("SE")
+ ;
+ $request->cancelCardOrder()->prepareRequest();
+ }
+
+ // direct bank
+ public function test_queryOrder_queryInvoiceOrder_returns_GetOrdersRequest()
+ {
+ $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
+ $request = $queryOrder->queryInvoiceOrder();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\GetOrdersRequest", $request);
+ $this->assertEquals(ConfigurationProvider::INVOICE_TYPE, $request->orderBuilder->orderType);
+ }
+
+ public function test_queryOrder_queryPaymentPlanOrder_returns_GetOrdersRequest()
+ {
+ $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
+ $request = $queryOrder->queryPaymentPlanOrder();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\GetOrdersRequest", $request);
+ $this->assertEquals(ConfigurationProvider::PAYMENTPLAN_TYPE, $request->orderBuilder->orderType);
+ }
+
+ public function test_queryOrder_queryCardOrder_returns_QueryTransaction()
+ {
+ $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
+ $request = $queryOrder->queryCardOrder();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransaction", $request);
+ }
+
+ public function test_queryOrder_queryCardOrder_returns_QueryTransactionByCustomerRefNo()
+ {
+ $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setClientOrderNumber("123");
+ $request = $queryOrder->queryCardOrder();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransactionByCustomerRefNo", $request);
+ }
+
+ public function test_queryOrder_queryDirectBankOrder_returns_QueryTransaction()
+ {
+ $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig());
+ $request = $queryOrder->queryDirectBankOrder();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransaction", $request);
+ }
+
+ public function test_queryOrder_queryDirectBankOrder_returns_QueryTransactionByCustomerRefNo()
+ {
+ $queryOrder = WebPayAdmin::queryOrder(ConfigurationService::getDefaultConfig())
+ ->setClientOrderNumber("123");
+ $request = $queryOrder->queryDirectBankOrder();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\QueryTransactionByCustomerRefNo", $request);
+ }
// TODO add validation unit tests
- // Svea\WebPay\WebPayAdmin::cancelOrderRows() ------------------------------------------
- public function test_cancelOrderRows_returns_AddOrderRowsBuilder()
- {
- $builderObject = WebPayAdmin::cancelOrderRows(ConfigurationService::getDefaultConfig());
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\CancelOrderRowsBuilder", $builderObject);
- }
-
- // invoice
- public function test_cancelOrderRows_cancelInvoiceOrderRows_returns_CancelOrderRowsRequest()
- {
- $cancelOrderRowsBuilder = WebPayAdmin::cancelOrderRows(ConfigurationService::getDefaultConfig());
- $request = $cancelOrderRowsBuilder->cancelInvoiceOrderRows();
- $this->assertInstanceOf("Svea\WebPay\AdminService\CancelOrderRowsRequest", $request);
- }
-
- // partpayment
- public function test_cancelOrderRows_cancelPaymentPlanOrderRows_returns_CancelOrderRowsRequest()
- {
- $cancelOrderRowsBuilder = WebPayAdmin::cancelOrderRows(ConfigurationService::getDefaultConfig());
- $request = $cancelOrderRowsBuilder->cancelPaymentPlanOrderRows();
- $this->assertInstanceOf("Svea\WebPay\AdminService\CancelOrderRowsRequest", $request);
- }
-
- // card
- public function test_cancelOrderRows_cancelCardOrderRows_returns_LowerTransaction()
- {
- $cancelOrderRowsBuilder = WebPayAdmin::cancelOrderRows(ConfigurationService::getDefaultConfig())
- ->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.00, 1, 1))
- ->setRowToCancel(1);
- $request = $cancelOrderRowsBuilder->cancelCardOrderRows();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\LowerTransaction", $request);
- }
- // TODO add validation tests here
-
- // Svea\WebPay\WebPayAdmin::creditOrderRows --------------------------------------------
- public function test_creditOrderRows_returns_CreditOrderRowsBuilder()
- {
- $builderObject = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig());
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\CreditOrderRowsBuilder", $builderObject);
- }
-
- // creditInvoiceOrderRows
- function test_validates_all_required_methods_for_creditOrderRows_creditInvoiceRows()
- {
- // needs either setRow(s)ToCredit or addCreditOrderRow(s)
- $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setInvoiceId("123456789")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode("SE")
- //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
- //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
- ->setRowToCredit(1)//->setRowsToCredit(array(1,2))
- ;
- try {
- $request->creditInvoiceOrderRows()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : no rows to credit, use setRow(s)ToCredit() or addCreditOrderRow(s)().
- */
- function test_validates_missing_required_method_for_creditOrderRows_creditInvoiceOrderRows_missing_rows()
- {
- $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setInvoiceId("123456789")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode("SE")
- //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
- //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
- //->setRowToCredit(1)
- //->setRowsToCredit(array(1,2))
- ;
- $request->creditInvoiceOrderRows()->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : countryCode is required, use setCountryCode().
- */
- function test_validates_missing_required_method_for_creditOrderRows_creditInvoiceOrderRows_missing_setCountryCode()
- {
- $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setInvoiceId("123456789")
- ->setInvoiceDistributionType(DistributionType::POST)
- //->setCountryCode("SE")
- //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
- //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
- ->setRowToCredit(1)//->setRowsToCredit(array(1,2))
- ;
- $request->creditInvoiceOrderRows()->prepareRequest();
- }
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : distributionType is required, use setInvoiceDistributionType().
- */
- function test_validates_missing_required_method_for_creditOrderRows_creditInvoiceOrderRows_missing_setInvoiceDistributionType()
- {
- $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setInvoiceId("123456789")
- //->setInvoiceDistributionType(Svea\WebPay\Constant\DistributionType::POST)
- ->setCountryCode("SE")
- //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
- //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
- ->setRowToCredit(1)//->setRowsToCredit(array(1,2))
- ;
- $request->creditInvoiceOrderRows()->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : invoiceId is required, use setInvoiceId().
- */
- function test_validates_missing_required_method_for_creditOrderRows_creditInvoiceOrderRows_missing_setInvoiceId()
- {
- $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- //->setInvoiceId("123456789")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode("SE")
- //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
- //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
- ->setRowToCredit(1)//->setRowsToCredit(array(1,2))
- ;
- $request->creditInvoiceOrderRows()->prepareRequest();
- }
-
- // creditCardOrderRows
- function test_validates_all_required_methods_for_creditOrderRows_creditCardOrderRows()
- {
- $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId("123456")
- ->setCountryCode("SE")
- ->addCreditOrderRow(TestUtil::createOrderRow())
- ->addCreditOrderRows(array(TestUtil::createOrderRow(), TestUtil::createOrderRow()))
- ->setRowToCredit(1)
- ->setRowsToCredit(array(2, 3))
- ->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.00, 1, 1))
- ->addNumberedOrderRows(array(TestUtil::createNumberedOrderRow(100.00, 1, 2), TestUtil::createNumberedOrderRow(100.00, 1, 3)));
- try {
- $request->creditCardOrderRows()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage orderId is required for creditCardOrderRows(). Use method setOrderId()
- */
- function test_validates_missing_required_method_for_creditOrderRows_creditCardOrderRows_missing_setOrderId()
- {
- $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- //->setOrderId("123456")
- //->setCountryCode("SE")
- //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
- //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
- //->setRowToCredit(1)
- //->setRowsToCredit(array(2,3))
- //->addNumberedOrderRow( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 1 ) )
- //->addNumberedOrderRows( array( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 2),Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 3 ) ) )
- ;
- $request->creditCardOrderRows()->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage countryCode is required for creditCardOrderRows(). Use method setCountryCode().
- */
- function test_validates_missing_required_method_for_creditOrderRows_creditCardOrderRows_missing_setCountryCode()
- {
- $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId("123456")
- //->setCountryCode("SE")
- //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
- //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
- //->setRowToCredit(1)
- //->setRowsToCredit(array(2,3))
- //->addNumberedOrderRow( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 1 ) )
- //->addNumberedOrderRows( array( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 2),Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 3 ) ) )
- ;
- $request->creditCardOrderRows()->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage at least one of rowsToCredit or creditOrderRows must be set. Use setRowToCredit() or addCreditOrderRow().
- */
- function test_validates_missing_required_method_for_creditOrderRows_creditCardOrderRows_missing_rows_to_credit()
- {
- $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId("123456")
- ->setCountryCode("SE")
- //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
- //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
- //->setRowToCredit(1)
- //->setRowsToCredit(array(2,3))
- //->addNumberedOrderRow( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 1 ) )
- //->addNumberedOrderRows( array( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 2),Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 3 ) ) )
- ;
- $request->creditCardOrderRows()->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage every entry in rowsToCredit must have a corresponding numberedOrderRows. Use setRowsToCredit() and addNumberedOrderRow().
- */
- function test_validates_missing_required_method_for_creditOrderRows_creditCardOrderRows_missing_numberedOrderRows()
- {
- $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId("123456")
- ->setCountryCode("SE")
- //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
- //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
- ->setRowToCredit(1)
- //->setRowsToCredit(array(2,3))
- //->addNumberedOrderRow( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 1 ) )
- //->addNumberedOrderRows( array( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 2),Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 3 ) ) )
- ;
- $request->creditCardOrderRows()->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage every entry in rowsToCredit must match a numberedOrderRows. Use setRowsToCredit() and addNumberedOrderRow().
- */
- function test_validates_missing_required_method_for_creditOrderRows_creditCardOrderRows__mismatched_numberedOrderRows()
- {
- $creditOrderRowsObject = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId("123456")
- ->setCountryCode("SE")
- ->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.00, 1, 1))
- ->setRowToCredit(9);
- $request = $creditOrderRowsObject->creditCardOrderRows(); // exception thrown in builder when selecting request class
- }
-
- // creditDirectBankOrderRows
- /**
- * @doesNotPerformAssertions
- */
- function test_no_separate_validation_tests_for_creditOrderRows_creditDirectBankOrderRows()
- {
- // creditDirectBankOrderRows is an alias of creditCardOrderRows, so no separate tests are needed
- }
-
- // end creditOrderRows tests -----------------------------------------------
-
- // Svea\WebPay\WebPayAdmin::addOrderRows() ---------------------------------------------
- public function test_addOrderRows_returns_AddOrderRowsBuilder()
- {
- $builderObject = WebPayAdmin::addOrderRows(ConfigurationService::getDefaultConfig());
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\AddOrderRowsBuilder", $builderObject);
- }
- // TODO add validation unit tests
- // end addOrderRows tests --------------------------------------------------
-
- // Svea\WebPay\WebPayAdmin::updateOrderRows() ------------------------------------------
- public function test_updateOrderRows_returns_AddOrderRowsBuilder()
- {
- $builderObject = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig());
- $this->assertInstanceOf("Svea\WebPay\BuildOrder\UpdateOrderRowsBuilder", $builderObject);
- }
- // TODO add validation unit tests
- // end updateOrderRows tests -----------------------------------------------
-
- // Svea\WebPay\WebPayAdmin::deliverOrderRows() -----------------------------------------
- // TODO add validation unit tests
- // end deliverOrderRows tests ----------------------------------------------
-
-
- // Verify that new orderRows may be specified with zero amount (INT-581) with WPA::addOrderRows
- public function test_addOrderRows_addInvoiceOrderRows_allows_orderRow_with_zero_amount()
- {
- $dummyorderid = 123456;
- $orderBuilder = WebPayAdmin::addOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId($dummyorderid)
- ->setCountryCode("SE")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(0)
- ->setVatPercent(0)
- ->setQuantity(0)
- );
-
- try {
- $request = $orderBuilder->addInvoiceOrderRows()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- public function test_addOrderRows_addPaymentPlanOrderRows_allows_orderRow_with_zero_amount()
- {
- $dummyorderid = 123456;
- $orderBuilder = WebPayAdmin::addOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId($dummyorderid)
- ->setCountryCode("SE")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(0.0)
- ->setVatPercent(0)
- ->setQuantity(0)
- );
-
- try {
- $request = $orderBuilder->addPaymentPlanOrderRows()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- // Verify that new orderRows may be specified with zero amount (INT-581) with WPA::updateOrderRows
- public function test_updateOrderRows_updateInvoiceOrderRows_allows_orderRow_with_zero_amount()
- {
- $dummyorderid = 123456;
- $orderBuilder = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId($dummyorderid)
- ->setCountryCode("SE")
- ->updateOrderRow(
- WebPayItem::numberedOrderRow()
- ->setAmountExVat(0.0)
- ->setVatPercent(0)
- ->setQuantity(0)
- ->setRowNumber(1)
- );
-
- try {
- $request = $orderBuilder->updateInvoiceOrderRows()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- public function test_updateOrderRows_updatePaymentPlanOrderRows_allows_orderRow_with_zero_amount()
- {
- $dummyorderid = 123456;
- $orderBuilder = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId($dummyorderid)
- ->setCountryCode("SE")
- ->updateOrderRow(
- WebPayItem::numberedOrderRow()
- ->setAmountExVat(0.0)
- ->setVatPercent(0)
- ->setQuantity(0)
- ->setRowNumber(1)
- );
-
- try {
- $request = $orderBuilder->updatePaymentPlanOrderRows()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- // Verify that new orderRows may be specified with zero amount (INT-581) with WPA::creditOrderRows
- public function test_creditOrderRows_creditInvoiceOrderRows_allows_orderRow_with_zero_amount()
- {
- $dummyorderid = 123456;
- $orderBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setInvoiceId($dummyorderid)
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCountryCode("SE")
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(0.0)
- ->setVatPercent(0)
- ->setQuantity(0)
- );
-
- try {
- $request = $orderBuilder->creditInvoiceOrderRows()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- public function test_creditOrderRows_creditCardOrderRows_allows_orderRow_with_zero_amount()
- {
- $dummyorderid = 123456;
- $orderBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
- ->setOrderId($dummyorderid)
- ->setCountryCode("SE")
- ->addCreditOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(0.0)
- ->setVatPercent(0)
- ->setQuantity(0)
- );
-
- try {
- $request = $orderBuilder->creditCardOrderRows()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
+ // Svea\WebPay\WebPayAdmin::cancelOrderRows() ------------------------------------------
+ public function test_cancelOrderRows_returns_AddOrderRowsBuilder()
+ {
+ $builderObject = WebPayAdmin::cancelOrderRows(ConfigurationService::getDefaultConfig());
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\CancelOrderRowsBuilder", $builderObject);
+ }
+
+ // invoice
+ public function test_cancelOrderRows_cancelInvoiceOrderRows_returns_CancelOrderRowsRequest()
+ {
+ $cancelOrderRowsBuilder = WebPayAdmin::cancelOrderRows(ConfigurationService::getDefaultConfig());
+ $request = $cancelOrderRowsBuilder->cancelInvoiceOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\CancelOrderRowsRequest", $request);
+ }
+
+ // partpayment
+ public function test_cancelOrderRows_cancelPaymentPlanOrderRows_returns_CancelOrderRowsRequest()
+ {
+ $cancelOrderRowsBuilder = WebPayAdmin::cancelOrderRows(ConfigurationService::getDefaultConfig());
+ $request = $cancelOrderRowsBuilder->cancelPaymentPlanOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\CancelOrderRowsRequest", $request);
+ }
+
+ // card
+ public function test_cancelOrderRows_cancelCardOrderRows_returns_LowerTransaction()
+ {
+ $cancelOrderRowsBuilder = WebPayAdmin::cancelOrderRows(ConfigurationService::getDefaultConfig())
+ ->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.00, 1, 1))
+ ->setRowToCancel(1);
+ $request = $cancelOrderRowsBuilder->cancelCardOrderRows();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\LowerTransaction", $request);
+ }
+ // TODO add validation tests here
+
+ // Svea\WebPay\WebPayAdmin::creditOrderRows --------------------------------------------
+ public function test_creditOrderRows_returns_CreditOrderRowsBuilder()
+ {
+ $builderObject = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig());
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\CreditOrderRowsBuilder", $builderObject);
+ }
+
+ // creditInvoiceOrderRows
+ function test_validates_all_required_methods_for_creditOrderRows_creditInvoiceRows()
+ {
+ // needs either setRow(s)ToCredit or addCreditOrderRow(s)
+ $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setInvoiceId("123456789")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode("SE")
+ //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
+ //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
+ ->setRowToCredit(1)//->setRowsToCredit(array(1,2))
+ ;
+ try {
+ $request->creditInvoiceOrderRows()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : no rows to credit, use setRow(s)ToCredit() or addCreditOrderRow(s)().
+ */
+ function test_validates_missing_required_method_for_creditOrderRows_creditInvoiceOrderRows_missing_rows()
+ {
+ $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setInvoiceId("123456789")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode("SE")
+ //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
+ //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
+ //->setRowToCredit(1)
+ //->setRowsToCredit(array(1,2))
+ ;
+ $request->creditInvoiceOrderRows()->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : countryCode is required, use setCountryCode().
+ */
+ function test_validates_missing_required_method_for_creditOrderRows_creditInvoiceOrderRows_missing_setCountryCode()
+ {
+ $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setInvoiceId("123456789")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ //->setCountryCode("SE")
+ //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
+ //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
+ ->setRowToCredit(1)//->setRowsToCredit(array(1,2))
+ ;
+ $request->creditInvoiceOrderRows()->prepareRequest();
+ }
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : distributionType is required, use setInvoiceDistributionType().
+ */
+ function test_validates_missing_required_method_for_creditOrderRows_creditInvoiceOrderRows_missing_setInvoiceDistributionType()
+ {
+ $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setInvoiceId("123456789")
+ //->setInvoiceDistributionType(Svea\WebPay\Constant\DistributionType::POST)
+ ->setCountryCode("SE")
+ //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
+ //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
+ ->setRowToCredit(1)//->setRowsToCredit(array(1,2))
+ ;
+ $request->creditInvoiceOrderRows()->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : invoiceId is required, use setInvoiceId().
+ */
+ function test_validates_missing_required_method_for_creditOrderRows_creditInvoiceOrderRows_missing_setInvoiceId()
+ {
+ $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ //->setInvoiceId("123456789")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode("SE")
+ //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
+ //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
+ ->setRowToCredit(1)//->setRowsToCredit(array(1,2))
+ ;
+ $request->creditInvoiceOrderRows()->prepareRequest();
+ }
+
+ // creditCardOrderRows
+ function test_validates_all_required_methods_for_creditOrderRows_creditCardOrderRows()
+ {
+ $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId("123456")
+ ->setCountryCode("SE")
+ ->addCreditOrderRow(TestUtil::createOrderRow())
+ ->addCreditOrderRows([TestUtil::createOrderRow(), TestUtil::createOrderRow()])
+ ->setRowToCredit(1)
+ ->setRowsToCredit([2, 3])
+ ->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.00, 1, 1))
+ ->addNumberedOrderRows([TestUtil::createNumberedOrderRow(100.00, 1, 2), TestUtil::createNumberedOrderRow(100.00, 1, 3)]);
+ try {
+ $request->creditCardOrderRows()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage orderId is required for creditCardOrderRows(). Use method setOrderId()
+ */
+ function test_validates_missing_required_method_for_creditOrderRows_creditCardOrderRows_missing_setOrderId()
+ {
+ $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ //->setOrderId("123456")
+ //->setCountryCode("SE")
+ //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
+ //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
+ //->setRowToCredit(1)
+ //->setRowsToCredit(array(2,3))
+ //->addNumberedOrderRow( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 1 ) )
+ //->addNumberedOrderRows( array( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 2),Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 3 ) ) )
+ ;
+ $request->creditCardOrderRows()->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage countryCode is required for creditCardOrderRows(). Use method setCountryCode().
+ */
+ function test_validates_missing_required_method_for_creditOrderRows_creditCardOrderRows_missing_setCountryCode()
+ {
+ $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId("123456")
+ //->setCountryCode("SE")
+ //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
+ //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
+ //->setRowToCredit(1)
+ //->setRowsToCredit(array(2,3))
+ //->addNumberedOrderRow( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 1 ) )
+ //->addNumberedOrderRows( array( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 2),Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 3 ) ) )
+ ;
+ $request->creditCardOrderRows()->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage at least one of rowsToCredit or creditOrderRows must be set. Use setRowToCredit() or addCreditOrderRow().
+ */
+ function test_validates_missing_required_method_for_creditOrderRows_creditCardOrderRows_missing_rows_to_credit()
+ {
+ $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId("123456")
+ ->setCountryCode("SE")
+ //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
+ //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
+ //->setRowToCredit(1)
+ //->setRowsToCredit(array(2,3))
+ //->addNumberedOrderRow( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 1 ) )
+ //->addNumberedOrderRows( array( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 2),Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 3 ) ) )
+ ;
+ $request->creditCardOrderRows()->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage every entry in rowsToCredit must have a corresponding numberedOrderRows. Use setRowsToCredit() and addNumberedOrderRow().
+ */
+ function test_validates_missing_required_method_for_creditOrderRows_creditCardOrderRows_missing_numberedOrderRows()
+ {
+ $request = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId("123456")
+ ->setCountryCode("SE")
+ //->addCreditOrderRow( Svea\WebPay\Test\TestUtil::createOrderRow() )
+ //->addCreditOrderRows( array( Svea\WebPay\Test\TestUtil::createOrderRow(), Svea\WebPay\Test\TestUtil::createOrderRow() ) )
+ ->setRowToCredit(1)
+ //->setRowsToCredit(array(2,3))
+ //->addNumberedOrderRow( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 1 ) )
+ //->addNumberedOrderRows( array( Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 2),Svea\WebPay\Test\TestUtil::createNumberedOrderRow( 100.00, 1, 3 ) ) )
+ ;
+ $request->creditCardOrderRows()->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage every entry in rowsToCredit must match a numberedOrderRows. Use setRowsToCredit() and addNumberedOrderRow().
+ */
+ function test_validates_missing_required_method_for_creditOrderRows_creditCardOrderRows__mismatched_numberedOrderRows()
+ {
+ $creditOrderRowsObject = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId("123456")
+ ->setCountryCode("SE")
+ ->addNumberedOrderRow(TestUtil::createNumberedOrderRow(100.00, 1, 1))
+ ->setRowToCredit(9);
+ $request = $creditOrderRowsObject->creditCardOrderRows(); // exception thrown in builder when selecting request class
+ }
+
+ // creditDirectBankOrderRows
+ /**
+ * @doesNotPerformAssertions
+ */
+ function test_no_separate_validation_tests_for_creditOrderRows_creditDirectBankOrderRows()
+ {
+ // creditDirectBankOrderRows is an alias of creditCardOrderRows, so no separate tests are needed
+ }
+
+ // end creditOrderRows tests -----------------------------------------------
+
+ // Svea\WebPay\WebPayAdmin::addOrderRows() ---------------------------------------------
+ public function test_addOrderRows_returns_AddOrderRowsBuilder()
+ {
+ $builderObject = WebPayAdmin::addOrderRows(ConfigurationService::getDefaultConfig());
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\AddOrderRowsBuilder", $builderObject);
+ }
+ // TODO add validation unit tests
+ // end addOrderRows tests --------------------------------------------------
+
+ // Svea\WebPay\WebPayAdmin::updateOrderRows() ------------------------------------------
+ public function test_updateOrderRows_returns_AddOrderRowsBuilder()
+ {
+ $builderObject = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig());
+ $this->assertInstanceOf("Svea\WebPay\BuildOrder\UpdateOrderRowsBuilder", $builderObject);
+ }
+ // TODO add validation unit tests
+ // end updateOrderRows tests -----------------------------------------------
+
+ // Svea\WebPay\WebPayAdmin::deliverOrderRows() -----------------------------------------
+ // TODO add validation unit tests
+ // end deliverOrderRows tests ----------------------------------------------
+
+
+ // Verify that new orderRows may be specified with zero amount (INT-581) with WPA::addOrderRows
+ public function test_addOrderRows_addInvoiceOrderRows_allows_orderRow_with_zero_amount()
+ {
+ $dummyorderid = 123456;
+ $orderBuilder = WebPayAdmin::addOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId($dummyorderid)
+ ->setCountryCode("SE")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(0)
+ ->setVatPercent(0)
+ ->setQuantity(0)
+ );
+
+ try {
+ $request = $orderBuilder->addInvoiceOrderRows()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ public function test_addOrderRows_addPaymentPlanOrderRows_allows_orderRow_with_zero_amount()
+ {
+ $dummyorderid = 123456;
+ $orderBuilder = WebPayAdmin::addOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId($dummyorderid)
+ ->setCountryCode("SE")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(0.0)
+ ->setVatPercent(0)
+ ->setQuantity(0)
+ );
+
+ try {
+ $request = $orderBuilder->addPaymentPlanOrderRows()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ // Verify that new orderRows may be specified with zero amount (INT-581) with WPA::updateOrderRows
+ public function test_updateOrderRows_updateInvoiceOrderRows_allows_orderRow_with_zero_amount()
+ {
+ $dummyorderid = 123456;
+ $orderBuilder = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId($dummyorderid)
+ ->setCountryCode("SE")
+ ->updateOrderRow(
+ WebPayItem::numberedOrderRow()
+ ->setAmountExVat(0.0)
+ ->setVatPercent(0)
+ ->setQuantity(0)
+ ->setRowNumber(1)
+ );
+
+ try {
+ $request = $orderBuilder->updateInvoiceOrderRows()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ public function test_updateOrderRows_updatePaymentPlanOrderRows_allows_orderRow_with_zero_amount()
+ {
+ $dummyorderid = 123456;
+ $orderBuilder = WebPayAdmin::updateOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId($dummyorderid)
+ ->setCountryCode("SE")
+ ->updateOrderRow(
+ WebPayItem::numberedOrderRow()
+ ->setAmountExVat(0.0)
+ ->setVatPercent(0)
+ ->setQuantity(0)
+ ->setRowNumber(1)
+ );
+
+ try {
+ $request = $orderBuilder->updatePaymentPlanOrderRows()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ // Verify that new orderRows may be specified with zero amount (INT-581) with WPA::creditOrderRows
+ public function test_creditOrderRows_creditInvoiceOrderRows_allows_orderRow_with_zero_amount()
+ {
+ $dummyorderid = 123456;
+ $orderBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setInvoiceId($dummyorderid)
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCountryCode("SE")
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(0.0)
+ ->setVatPercent(0)
+ ->setQuantity(0)
+ );
+
+ try {
+ $request = $orderBuilder->creditInvoiceOrderRows()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ public function test_creditOrderRows_creditCardOrderRows_allows_orderRow_with_zero_amount()
+ {
+ $dummyorderid = 123456;
+ $orderBuilder = WebPayAdmin::creditOrderRows(ConfigurationService::getDefaultConfig())
+ ->setOrderId($dummyorderid)
+ ->setCountryCode("SE")
+ ->addCreditOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(0.0)
+ ->setVatPercent(0)
+ ->setQuantity(0)
+ );
+
+ try {
+ $request = $orderBuilder->creditCardOrderRows()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
}
diff --git a/test/UnitTest/WebPayUnitTest.php b/test/UnitTest/WebPayUnitTest.php
index 1f158798..de7535b6 100644
--- a/test/UnitTest/WebPayUnitTest.php
+++ b/test/UnitTest/WebPayUnitTest.php
@@ -20,749 +20,749 @@ class WebPayUnitTest extends \PHPUnit\Framework\TestCase
{
- /// createOrder
- // useInvoicePayment return type
- // web service eu: invoice
- // web service eu: paymentplan
- // bypass paypage: usepaymentmethod
- // paypage: cardonly
- // paypage: directbankonly
- // paypage
- public function test_createOrder_useInvoicePayment_returns_InvoicePayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- // we should set attributes here if real request
- $request = $createOrder->useInvoicePayment();
- $this->assertInstanceOf("Svea\WebPay\WebService\Payment\InvoicePayment", $request);
- }
-
- public function test_createOrder_usePaymentPlanPayment_returns_PaymentPlanPayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- $request = $createOrder->usePaymentPlanPayment('111111');
- $this->assertInstanceOf("Svea\WebPay\WebService\Payment\PaymentPlanPayment", $request);
- }
-
- public function test_createOrder_usePayPageCardOnly_returns_CardPayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- $request = $createOrder->usePayPageCardOnly();
- $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\CardPayment", $request);
- }
-
- public function test_createOrder_usePayPageDirectBankOnly_returns_DirectPayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- $request = $createOrder->usePayPageDirectBankOnly();
- $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\DirectPayment", $request);
- }
-
- public function test_createOrder_usePaymentMethod_returns_PaymentMethodPayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- $request = $createOrder->usePaymentMethod("mocked_paymentMethod");
- $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\PaymentMethodPayment", $request);
- }
-
- public function test_createOrder_usePayPage_returns_PayPagePayment()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
- $request = $createOrder->usePayPage();
- $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\PayPagePayment", $request);
- }
-
- // individualCustomer validation - common
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing values : OrderRows are required. Use function addOrderRow(Svea\WebPay\WebPayItem::orderRow) to get orderrow setters.
- */
- function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_SE_addOrderRow()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- //->addOrderRow(
- // Svea\WebPay\WebPayItem::orderRow()
- // ->setQuantity(1.0)
- // ->setAmountExVat(4.0)
- // ->setAmountIncVat(5.0)
- //)
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("4605092222")
- )
- ->setCountryCode("SE")
- ->setOrderDate(date('c'));
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- $order->useInvoicePayment()->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing customerIdentity : customerIdentity is required. Use function addCustomerDetails().
- */
- function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_SE_addCustomerDetails()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- //->addCustomerDetails(
- // Svea\WebPay\WebPayItem::individualCustomer()
- // ->setNationalIdNumber("4605092222")
- //)
- ->setCountryCode("SE")
- ->setOrderDate(date('c'));
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- $order->useInvoicePayment()->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : CountryCode is required. Use function setCountryCode().
- */
- function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_SE_setCountryCode()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("4605092222")
- )
- //->setCountryCode("SE")
- ->setOrderDate(date('c'));
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- $order->useInvoicePayment()->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : OrderDate is Required. Use function setOrderDate().
- */
- function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_SE_setOrderDate()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("4605092222")
- )
- ->setCountryCode("SE")//->setOrderDate(date('c'))
- ;
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- $order->useInvoicePayment()->prepareRequest();
- }
-
- // SE
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_SE()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("4605092222")
- )
- ->setCountryCode("SE")
- ->setOrderDate(date('c'));
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- try {
- $order->useInvoicePayment()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
- */
- function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_SE()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- //missing ->setNationalIdNumber("4605092222")
- //or if we use ->setNationalIdNumber("")
- //or if we use ->setNationalIdNumber(null)
- )
- ->setCountryCode("SE")
- ->setOrderDate(date('c'));
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- $order->useInvoicePayment()->prepareRequest();
- }
- // CompanyCustomer
- // TODO
-
- // NO
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_NO()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("17054512066")
- )
- ->setCountryCode("NO")
- ->setOrderDate(date('c'));
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- try {
- $order->useInvoicePayment()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
- */
- function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_NO()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- //->setNationalIdNumber("17054512066")
- )
- ->setCountryCode("NO")
- ->setOrderDate(date('c'));
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- $order->useInvoicePayment()->prepareRequest();
- }
- // CompanyCustomer
- // TODO
-
- // DK
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_DK()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("2603692503")
- )
- ->setCountryCode("DK")
- ->setOrderDate(date('c'));
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- try {
- $order->useInvoicePayment()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
- */
- function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_DK()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- //->setNationalIdNumber("2603692503")
- )
- ->setCountryCode("DK")
- ->setOrderDate(date('c'));
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- $order->useInvoicePayment()->prepareRequest();
- }
- // CompanyCustomer
- // TODO
-
- // FI
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_FI()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("160264-999N")
- )
- ->setCountryCode("FI")
- ->setOrderDate(date('c'));
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- try {
- $order->useInvoicePayment()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
- */
- function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_FI()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- //->setNationalIdNumber("160264-999N")
- )
- ->setCountryCode("FI")
- ->setOrderDate(date('c'));
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- $order->useInvoicePayment()->prepareRequest();
- }
- // CompanyCustomer
- // TODO
-
- // DE
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_DE()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setBirthDate("19680403")
- ->setName("Theo", "Giebel")
- ->setStreetAddress("Zörgiebelweg", 21)
- ->setZipCode("13591")
- ->setLocality("BERLIN")
- )
- ->setCountryCode("DE")
- ->setOrderDate(date('c'));
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- try {
- $order->useInvoicePayment()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- //-missing value : BirthDate is required for individual customers when countrycode is DE. Use function setBirthDate().
- //-missing value : Name is required for individual customers when countrycode is DE. Use function setName().
- //-missing value : StreetAddress is required for all customers when countrycode is DE. Use function setStreetAddress().
- //-missing value : ZipCode is required for all customers when countrycode is DE. Use function setZipCode().
- //-missing value : Locality is required for all customers when countrycode is DE. Use function setLocality()
- }
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : ZipCode is required for all customers when countrycode is DE. Use function setZipCode().
- */
- function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_DE()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- //->setBirthDate("19680403")
- //->setName("Theo", "Giebel")
- //->setStreetAddress("Zörgiebelweg", 21)
- //->setZipCode("13591")
- //->setLocality("BERLIN")
- )
- ->setCountryCode("DE")
- ->setOrderDate(date('c'));
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- $order->useInvoicePayment()->prepareRequest();
- }
- // CompanyCustomer
- // TODO
-
- // NL
- // IndividualCustomer validation
- function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_NL()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setBirthDate("19550307")
- ->setInitials("SB")
- ->setName("Sneider", "Boasman")
- ->setStreetAddress("Gate 42", 23)
- ->setZipCode("1102 HG")
- ->setLocality("BARENDRECHT")
- )
- ->setCountryCode("NL")
- ->setOrderDate(date('c'));
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- try {
- $order->useInvoicePayment()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error:
- //-missing value : BirthDate is required for individual customers when countrycode is NL. Use function setBirthDate().
- //-missing value : Initials is required for individual customers when countrycode is NL. Use function setInitials().
- //-missing value : Name is required for individual customers when countrycode is NL. Use function setName()
- //-missing value : StreetAddress is required for all customers when countrycode is NL. Use function setStreetAddress().
- //-missing value : ZipCode is required for all customers when countrycode is NL. Use function setZipCode().
- //-missing value : Locality is required for all customers when countrycode is NL. Use function setLocality().
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : ZipCode is required for all customers when countrycode is NL. Use function setZipCode()
- */
- function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_NL()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(1.0)
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- //->setBirthDate("19550307")
- //->setInitials("SB")
- //->setName("Sneider", "Boasman")
- //->setStreetAddress("Gate 42", 23)
- //->setZipCode("1102 HG")
- //->setLocality("BARENDRECHT")
- )
- ->setCountryCode("NL")
- ->setOrderDate(date('c'));
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- $order->useInvoicePayment()->prepareRequest();
- }
-// $this->setExpectedException(
-// 'Svea\WebPay\BuildOrder\Validator\ValidationException',
-// '-missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().'
-// );
-
- /// Svea\WebPay\WebPay::deliverOrder()
- // deliverInvoiceOrder
- public function test_deliverOrder_deliverInvoiceOrder_without_order_rows_goes_against_adminservice_DeliverOrders()
- {
- $deliverOrder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig());
- $request = $deliverOrder->deliverInvoiceOrder();
- $this->assertInstanceOf("Svea\WebPay\AdminService\DeliverOrdersRequest", $request);
- $this->assertEquals("Invoice", $request->orderBuilder->orderType);
- }
-
- public function test_deliverOrder_deliverInvoiceOrder_with_order_rows_goes_against_DeliverOrderEU()
- {
- $deliverOrder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig());
- $deliverOrder->addOrderRow(WebPayItem::orderRow());
- $request = $deliverOrder->deliverInvoiceOrder();
- $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\DeliverInvoice", $request); // WebService\DeliverInvoice => soap call DeliverOrderEU
- }
-
- // deliverPaymentPlanOrder
- public function test_deliverOrder_deliverPaymentPlanOrder_without_order_rows_goes_against_DeliverOrderEU()
- {
- $deliverOrder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig());
- $request = $deliverOrder->deliverPaymentPlanOrder();
- $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\DeliverPaymentPlan", $request);
- $this->assertEquals("PaymentPlan", $request->orderBuilder->orderType);
- }
-
- public function test_deliverOrder_deliverPaymentPlanOrder_with_order_rows_goes_against_DeliverOrderEU()
- {
- $deliverOrder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig());
- $deliverOrder->addOrderRow(WebPayItem::orderRow()); // order rows are ignored by DeliverOrderEU, can't partially deliver PaymentPlan
- $request = $deliverOrder->deliverPaymentPlanOrder();
- $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\DeliverPaymentPlan", $request);
- }
-
- // card
- public function test_deliverOrder_deliverCardOrder_returns_ConfirmTransaction()
- {
- $deliverOrder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig());
- $deliverOrder->addOrderRow(WebPayItem::orderRow());
- $request = $deliverOrder->deliverCardOrder();
- $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\ConfirmTransaction", $request);
- }
-
-
- /// TODO getAddresses
- // setCountryCode
- // setIdentifier
-
- /// TODO getPaymentPlanParams
- // setCountryCode
- // setIdentifier
-
- /// listPaymentMethods
- function test_validates_all_required_methods_for_listPaymentMethods()
- {
- $order = WebPay::listPaymentMethods(ConfigurationService::getDefaultConfig())
- ->setCountryCode("SE");
- try {
- $order->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : CountryCode is required. Use function setCountryCode().
- */
- function test_validates_missing_required_method_for_listPaymentMethods_setCountryCode()
- {
- $order = WebPay::listPaymentMethods(ConfigurationService::getDefaultConfig())//->setCountryCode("SE")
- ;
- $order->prepareRequest();
- }
-
- /// Svea\WebPay\WebPay::getAddresses()
- public function test_getAddresses_returns_GetAddresses()
- {
- $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig());
- $this->assertInstanceOf("Svea\WebPay\WebService\GetAddress\GetAddresses", $request);
- }
-
- /// Svea\WebPay\WebPay::getPaymentPlanParams()
- public function test_getPaymentPlanParams_returns_GetPaymentPlanParams()
- {
- $request = WebPay::getPaymentPlanParams(ConfigurationService::getDefaultConfig());
- $this->assertInstanceOf("Svea\WebPay\WebService\GetPaymentPlanParams\GetPaymentPlanParams", $request);
- }
-
-
- // Verify that orderRows may be specified with zero amount (INT-581) when creating an order
- public function test_createOrder_useInvoicePayment_allows_orderRow_with_zero_amount()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(0.0)
- ->setAmountIncVat(0.0)
- ->setVatPercent(0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("4605092222")
- )
- ->setCountryCode("SE")
- ->setOrderDate(date('c'));
-
- $request = $createOrder->useInvoicePayment();
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- try {
- $request->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- public function test_createOrder_usePaymentPlanPayment_allows_orderRow_with_zero_amount()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(0.0)
- ->setAmountIncVat(0.0)
- ->setVatPercent(0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("4605092222")
- )
- ->setCountryCode("SE")
- ->setOrderDate(date('c'));
-
- $request = $createOrder->usePaymentPlanPayment('111111');
-
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- try {
- $request->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- public function test_createOrder_usePaymentMethod_KORTCERT_allows_orderRow_with_zero_amount()
- {
- $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setQuantity(0.0)
- ->setAmountIncVat(0.0)
- ->setVatPercent(0)
- )
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setNationalIdNumber("4605092222")
- )
- ->setCountryCode("SE")
- ->setOrderDate(date('c'))
- ->setCurrency("SEK")
- ->setClientOrderNumber(date('c'));
- // prepareRequest() validates the order and throws SveaWebPayException on validation failure
- try {
- $request = $createOrder->usePaymentMethod(PaymentMethod::KORTCERT)->setReturnUrl("http://myurl.se")->getPaymentForm();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- // Verify that orderRows may be specified with zero amount (INT-581) when delivering an order
- public function test_deliverOrder_deliverInvoiceOrder_allows_orderRow_with_zero_amount()
- {
- $dummyorderid = 123456;
- $deliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($dummyorderid)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(0.0)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(0)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(0) // required
- );
-
- try {
- $request = $deliverOrderBuilder->deliverInvoiceOrder()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- public function test_deliverOrder_deliverPaymentPlanOrder_allows_orderRow_with_zero_amount()
- {
- $dummyorderid = 123456;
- $deliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($dummyorderid)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(0.0)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(0)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(0) // required
- );
-
- try {
- $request = $deliverOrderBuilder->deliverPaymentPlanOrder()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- public function test_deliverOrder_deliverCardOrder_allows_orderRow_with_zero_amount()
- {
- $dummyorderid = 123456;
- $deliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
- ->setOrderId($dummyorderid)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(0.0)// recommended to specify price using AmountExVat & VatPercent
- ->setVatPercent(0)// recommended to specify price using AmountExVat & VatPercent
- ->setQuantity(0) // required
- );
-
- try {
- $request = $deliverOrderBuilder->deliverCardOrder()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
+ /// createOrder
+ // useInvoicePayment return type
+ // web service eu: invoice
+ // web service eu: paymentplan
+ // bypass paypage: usepaymentmethod
+ // paypage: cardonly
+ // paypage: directbankonly
+ // paypage
+ public function test_createOrder_useInvoicePayment_returns_InvoicePayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ // we should set attributes here if real request
+ $request = $createOrder->useInvoicePayment();
+ $this->assertInstanceOf("Svea\WebPay\WebService\Payment\InvoicePayment", $request);
+ }
+
+ public function test_createOrder_usePaymentPlanPayment_returns_PaymentPlanPayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ $request = $createOrder->usePaymentPlanPayment('111111');
+ $this->assertInstanceOf("Svea\WebPay\WebService\Payment\PaymentPlanPayment", $request);
+ }
+
+ public function test_createOrder_usePayPageCardOnly_returns_CardPayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ $request = $createOrder->usePayPageCardOnly();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\CardPayment", $request);
+ }
+
+ public function test_createOrder_usePayPageDirectBankOnly_returns_DirectPayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ $request = $createOrder->usePayPageDirectBankOnly();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\DirectPayment", $request);
+ }
+
+ public function test_createOrder_usePaymentMethod_returns_PaymentMethodPayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ $request = $createOrder->usePaymentMethod("mocked_paymentMethod");
+ $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\PaymentMethodPayment", $request);
+ }
+
+ public function test_createOrder_usePayPage_returns_PayPagePayment()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig());
+ $request = $createOrder->usePayPage();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\Payment\PayPagePayment", $request);
+ }
+
+ // individualCustomer validation - common
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing values : OrderRows are required. Use function addOrderRow(Svea\WebPay\WebPayItem::orderRow) to get orderrow setters.
+ */
+ function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_SE_addOrderRow()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ //->addOrderRow(
+ // Svea\WebPay\WebPayItem::orderRow()
+ // ->setQuantity(1.0)
+ // ->setAmountExVat(4.0)
+ // ->setAmountIncVat(5.0)
+ //)
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("4605092222")
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate(date('c'));
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ $order->useInvoicePayment()->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing customerIdentity : customerIdentity is required. Use function addCustomerDetails().
+ */
+ function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_SE_addCustomerDetails()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ //->addCustomerDetails(
+ // Svea\WebPay\WebPayItem::individualCustomer()
+ // ->setNationalIdNumber("4605092222")
+ //)
+ ->setCountryCode("SE")
+ ->setOrderDate(date('c'));
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ $order->useInvoicePayment()->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : CountryCode is required. Use function setCountryCode().
+ */
+ function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_SE_setCountryCode()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("4605092222")
+ )
+ //->setCountryCode("SE")
+ ->setOrderDate(date('c'));
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ $order->useInvoicePayment()->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : OrderDate is Required. Use function setOrderDate().
+ */
+ function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_SE_setOrderDate()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("4605092222")
+ )
+ ->setCountryCode("SE")//->setOrderDate(date('c'))
+ ;
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ $order->useInvoicePayment()->prepareRequest();
+ }
+
+ // SE
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_SE()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("4605092222")
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate(date('c'));
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ try {
+ $order->useInvoicePayment()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
+ */
+ function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_SE()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ //missing ->setNationalIdNumber("4605092222")
+ //or if we use ->setNationalIdNumber("")
+ //or if we use ->setNationalIdNumber(null)
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate(date('c'));
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ $order->useInvoicePayment()->prepareRequest();
+ }
+ // CompanyCustomer
+ // TODO
+
+ // NO
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_NO()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("17054512066")
+ )
+ ->setCountryCode("NO")
+ ->setOrderDate(date('c'));
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ try {
+ $order->useInvoicePayment()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
+ */
+ function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_NO()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ //->setNationalIdNumber("17054512066")
+ )
+ ->setCountryCode("NO")
+ ->setOrderDate(date('c'));
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ $order->useInvoicePayment()->prepareRequest();
+ }
+ // CompanyCustomer
+ // TODO
+
+ // DK
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_DK()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("2603692503")
+ )
+ ->setCountryCode("DK")
+ ->setOrderDate(date('c'));
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ try {
+ $order->useInvoicePayment()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
+ */
+ function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_DK()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ //->setNationalIdNumber("2603692503")
+ )
+ ->setCountryCode("DK")
+ ->setOrderDate(date('c'));
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ $order->useInvoicePayment()->prepareRequest();
+ }
+ // CompanyCustomer
+ // TODO
+
+ // FI
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_FI()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("160264-999N")
+ )
+ ->setCountryCode("FI")
+ ->setOrderDate(date('c'));
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ try {
+ $order->useInvoicePayment()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().
+ */
+ function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_FI()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ //->setNationalIdNumber("160264-999N")
+ )
+ ->setCountryCode("FI")
+ ->setOrderDate(date('c'));
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ $order->useInvoicePayment()->prepareRequest();
+ }
+ // CompanyCustomer
+ // TODO
+
+ // DE
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_DE()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setBirthDate("19680403")
+ ->setName("Theo", "Giebel")
+ ->setStreetAddress("Zörgiebelweg", 21)
+ ->setZipCode("13591")
+ ->setLocality("BERLIN")
+ )
+ ->setCountryCode("DE")
+ ->setOrderDate(date('c'));
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ try {
+ $order->useInvoicePayment()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ //-missing value : BirthDate is required for individual customers when countrycode is DE. Use function setBirthDate().
+ //-missing value : Name is required for individual customers when countrycode is DE. Use function setName().
+ //-missing value : StreetAddress is required for all customers when countrycode is DE. Use function setStreetAddress().
+ //-missing value : ZipCode is required for all customers when countrycode is DE. Use function setZipCode().
+ //-missing value : Locality is required for all customers when countrycode is DE. Use function setLocality()
+ }
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : ZipCode is required for all customers when countrycode is DE. Use function setZipCode().
+ */
+ function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_DE()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ //->setBirthDate("19680403")
+ //->setName("Theo", "Giebel")
+ //->setStreetAddress("Zörgiebelweg", 21)
+ //->setZipCode("13591")
+ //->setLocality("BERLIN")
+ )
+ ->setCountryCode("DE")
+ ->setOrderDate(date('c'));
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ $order->useInvoicePayment()->prepareRequest();
+ }
+ // CompanyCustomer
+ // TODO
+
+ // NL
+ // IndividualCustomer validation
+ function test_validates_all_required_methods_for_createOrder_useInvoicePayment_IndividualCustomer_NL()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setBirthDate("19550307")
+ ->setInitials("SB")
+ ->setName("Sneider", "Boasman")
+ ->setStreetAddress("Gate 42", 23)
+ ->setZipCode("1102 HG")
+ ->setLocality("BARENDRECHT")
+ )
+ ->setCountryCode("NL")
+ ->setOrderDate(date('c'));
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ try {
+ $order->useInvoicePayment()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error:
+ //-missing value : BirthDate is required for individual customers when countrycode is NL. Use function setBirthDate().
+ //-missing value : Initials is required for individual customers when countrycode is NL. Use function setInitials().
+ //-missing value : Name is required for individual customers when countrycode is NL. Use function setName()
+ //-missing value : StreetAddress is required for all customers when countrycode is NL. Use function setStreetAddress().
+ //-missing value : ZipCode is required for all customers when countrycode is NL. Use function setZipCode().
+ //-missing value : Locality is required for all customers when countrycode is NL. Use function setLocality().
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : ZipCode is required for all customers when countrycode is NL. Use function setZipCode()
+ */
+ function test_validates_missing_required_method_for_useInvoicePayment_IndividualCustomer_missing_credentials_NL()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(1.0)
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ //->setBirthDate("19550307")
+ //->setInitials("SB")
+ //->setName("Sneider", "Boasman")
+ //->setStreetAddress("Gate 42", 23)
+ //->setZipCode("1102 HG")
+ //->setLocality("BARENDRECHT")
+ )
+ ->setCountryCode("NL")
+ ->setOrderDate(date('c'));
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ $order->useInvoicePayment()->prepareRequest();
+ }
+// $this->setExpectedException(
+// 'Svea\WebPay\BuildOrder\Validator\ValidationException',
+// '-missing value : NationalIdNumber is required for individual customers when countrycode is SE, NO, DK or FI. Use function setNationalIdNumber().'
+// );
+
+ /// Svea\WebPay\WebPay::deliverOrder()
+ // deliverInvoiceOrder
+ public function test_deliverOrder_deliverInvoiceOrder_without_order_rows_goes_against_adminservice_DeliverOrders()
+ {
+ $deliverOrder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig());
+ $request = $deliverOrder->deliverInvoiceOrder();
+ $this->assertInstanceOf("Svea\WebPay\AdminService\DeliverOrdersRequest", $request);
+ $this->assertEquals("Invoice", $request->orderBuilder->orderType);
+ }
+
+ public function test_deliverOrder_deliverInvoiceOrder_with_order_rows_goes_against_DeliverOrderEU()
+ {
+ $deliverOrder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig());
+ $deliverOrder->addOrderRow(WebPayItem::orderRow());
+ $request = $deliverOrder->deliverInvoiceOrder();
+ $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\DeliverInvoice", $request); // WebService\DeliverInvoice => soap call DeliverOrderEU
+ }
+
+ // deliverPaymentPlanOrder
+ public function test_deliverOrder_deliverPaymentPlanOrder_without_order_rows_goes_against_DeliverOrderEU()
+ {
+ $deliverOrder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig());
+ $request = $deliverOrder->deliverPaymentPlanOrder();
+ $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\DeliverPaymentPlan", $request);
+ $this->assertEquals("PaymentPlan", $request->orderBuilder->orderType);
+ }
+
+ public function test_deliverOrder_deliverPaymentPlanOrder_with_order_rows_goes_against_DeliverOrderEU()
+ {
+ $deliverOrder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig());
+ $deliverOrder->addOrderRow(WebPayItem::orderRow()); // order rows are ignored by DeliverOrderEU, can't partially deliver PaymentPlan
+ $request = $deliverOrder->deliverPaymentPlanOrder();
+ $this->assertInstanceOf("Svea\WebPay\WebService\HandleOrder\DeliverPaymentPlan", $request);
+ }
+
+ // card
+ public function test_deliverOrder_deliverCardOrder_returns_ConfirmTransaction()
+ {
+ $deliverOrder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig());
+ $deliverOrder->addOrderRow(WebPayItem::orderRow());
+ $request = $deliverOrder->deliverCardOrder();
+ $this->assertInstanceOf("Svea\WebPay\HostedService\HostedAdminRequest\ConfirmTransaction", $request);
+ }
+
+
+ /// TODO getAddresses
+ // setCountryCode
+ // setIdentifier
+
+ /// TODO getPaymentPlanParams
+ // setCountryCode
+ // setIdentifier
+
+ /// listPaymentMethods
+ function test_validates_all_required_methods_for_listPaymentMethods()
+ {
+ $order = WebPay::listPaymentMethods(ConfigurationService::getDefaultConfig())
+ ->setCountryCode("SE");
+ try {
+ $order->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : CountryCode is required. Use function setCountryCode().
+ */
+ function test_validates_missing_required_method_for_listPaymentMethods_setCountryCode()
+ {
+ $order = WebPay::listPaymentMethods(ConfigurationService::getDefaultConfig())//->setCountryCode("SE")
+ ;
+ $order->prepareRequest();
+ }
+
+ /// Svea\WebPay\WebPay::getAddresses()
+ public function test_getAddresses_returns_GetAddresses()
+ {
+ $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig());
+ $this->assertInstanceOf("Svea\WebPay\WebService\GetAddress\GetAddresses", $request);
+ }
+
+ /// Svea\WebPay\WebPay::getPaymentPlanParams()
+ public function test_getPaymentPlanParams_returns_GetPaymentPlanParams()
+ {
+ $request = WebPay::getPaymentPlanParams(ConfigurationService::getDefaultConfig());
+ $this->assertInstanceOf("Svea\WebPay\WebService\GetPaymentPlanParams\GetPaymentPlanParams", $request);
+ }
+
+
+ // Verify that orderRows may be specified with zero amount (INT-581) when creating an order
+ public function test_createOrder_useInvoicePayment_allows_orderRow_with_zero_amount()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(0.0)
+ ->setAmountIncVat(0.0)
+ ->setVatPercent(0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("4605092222")
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate(date('c'));
+
+ $request = $createOrder->useInvoicePayment();
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ try {
+ $request->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ public function test_createOrder_usePaymentPlanPayment_allows_orderRow_with_zero_amount()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(0.0)
+ ->setAmountIncVat(0.0)
+ ->setVatPercent(0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("4605092222")
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate(date('c'));
+
+ $request = $createOrder->usePaymentPlanPayment('111111');
+
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ try {
+ $request->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ public function test_createOrder_usePaymentMethod_KORTCERT_allows_orderRow_with_zero_amount()
+ {
+ $createOrder = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setQuantity(0.0)
+ ->setAmountIncVat(0.0)
+ ->setVatPercent(0)
+ )
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setNationalIdNumber("4605092222")
+ )
+ ->setCountryCode("SE")
+ ->setOrderDate(date('c'))
+ ->setCurrency("SEK")
+ ->setClientOrderNumber(date('c'));
+ // prepareRequest() validates the order and throws SveaWebPayException on validation failure
+ try {
+ $request = $createOrder->usePaymentMethod(PaymentMethod::KORTCERT)->setReturnUrl("http://myurl.se")->getPaymentForm();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ // Verify that orderRows may be specified with zero amount (INT-581) when delivering an order
+ public function test_deliverOrder_deliverInvoiceOrder_allows_orderRow_with_zero_amount()
+ {
+ $dummyorderid = 123456;
+ $deliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($dummyorderid)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(0.0)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(0)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(0) // required
+ );
+
+ try {
+ $request = $deliverOrderBuilder->deliverInvoiceOrder()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ public function test_deliverOrder_deliverPaymentPlanOrder_allows_orderRow_with_zero_amount()
+ {
+ $dummyorderid = 123456;
+ $deliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($dummyorderid)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(0.0)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(0)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(0) // required
+ );
+
+ try {
+ $request = $deliverOrderBuilder->deliverPaymentPlanOrder()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ public function test_deliverOrder_deliverCardOrder_allows_orderRow_with_zero_amount()
+ {
+ $dummyorderid = 123456;
+ $deliverOrderBuilder = WebPay::deliverOrder(ConfigurationService::getDefaultConfig())
+ ->setOrderId($dummyorderid)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(0.0)// recommended to specify price using AmountExVat & VatPercent
+ ->setVatPercent(0)// recommended to specify price using AmountExVat & VatPercent
+ ->setQuantity(0) // required
+ );
+
+ try {
+ $request = $deliverOrderBuilder->deliverCardOrder()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
}
diff --git a/test/UnitTest/WebService/GetAddress/GetAddressesTest.php b/test/UnitTest/WebService/GetAddress/GetAddressesTest.php
index 00d30141..a61d1583 100644
--- a/test/UnitTest/WebService/GetAddress/GetAddressesTest.php
+++ b/test/UnitTest/WebService/GetAddress/GetAddressesTest.php
@@ -14,196 +14,196 @@
class GetAddressesTest extends \PHPUnit\Framework\TestCase
{
- public function testBuildRequest()
- {
- $config = ConfigurationService::getDefaultConfig();
- $addressRequest = WebPay::getAddresses($config);
- $addressRequest
- ->setCountryCode("SE")
- ->setCustomerIdentifier("SE460509")
- ->getCompanyAddresses();
- $this->assertEquals("SE", $addressRequest->countryCode);
- $this->assertEquals("SE460509", $addressRequest->companyId);
- }
-
- public function testPrepareRequestPrivate()
- {
- $config = ConfigurationService::getDefaultConfig();
- $addressRequest = WebPay::getAddresses($config);
- $request = $addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier(194605092222)
- ->getIndividualAddresses()
- ->prepareRequest();
-
- $this->assertEquals(79021, $request->request->Auth->ClientNumber); //Check all in identity
- $this->assertEquals("sverigetest", $request->request->Auth->Username); //Check all in identity
- $this->assertEquals("sverigetest", $request->request->Auth->Password); //Check all in identity
- $this->assertEquals(FALSE, $request->request->IsCompany);
- $this->assertEquals("SE", $request->request->CountryCode);
- $this->assertEquals(194605092222, $request->request->SecurityNumber);
- }
-
- public function testPrepareRequestCompany()
- {
- $config = ConfigurationService::getDefaultConfig();
- $addressRequest = WebPay::getAddresses($config);
- $request = $addressRequest
- ->setOrderTypeInvoice()
- ->setCountryCode("SE")
- ->setCustomerIdentifier(4608142222)
- ->getCompanyAddresses()
- ->prepareRequest();
-
- $this->assertEquals(79021, $request->request->Auth->ClientNumber); //Check all in identity
- $this->assertEquals("sverigetest", $request->request->Auth->Username); //Check all in identity
- $this->assertEquals("sverigetest", $request->request->Auth->Password); //Check all in identity
- $this->assertEquals(true, $request->request->IsCompany);
- $this->assertEquals("SE", $request->request->CountryCode);
- $this->assertEquals(4608142222, $request->request->SecurityNumber);
- }
-
- /// validations
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage countryCode is required. Use function setCountryCode().
- */
- public function test_missing_countryCode_throws_exception()
- {
- $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig())
- //->setCountryCode( "SE" )
- ->setCustomerIdentifier("4605092222")
- ->getIndividualAddresses()
- ->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage customerIdentifier is required. Use function setCustomerIdentifer().
- */
- public function test_getIndividualAddresses_with_missing_customerIdentifier_throws_exception()
- {
- $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig())
- ->setCountryCode("SE")
- //->setCustomerIdentifier("4605092222")
- ->getIndividualAddresses()
- ->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage customerIdentifier is required. Use function setCustomerIdentifer().
- */
- public function test_getCompanyAddresses_with_missing_customerIdentifier_throws_exception()
- {
- $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig())
- ->setCountryCode("SE")
- //->setCustomerIdentifier("4605092222")
- ->getCompanyAddresses()
- ->prepareRequest();
- }
-
- /**
- * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage missing authentication credentials. Check configuration.
- */
- public function test_missing_Configuration_for_CountryCode_throws_exception()
- {
- $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig());
-
- // clear both payment method credentials for SE
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['username'] = null;
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['password'] = null;
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['clientNumber'] = null;
- $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['username'] = null;
- $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['password'] = null;
- $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['clientNumber'] = null;
- $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['username'] = null;
- $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['password'] = null;
- $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['clientNumber'] = null;
-
- $request
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4605092222")
- ->getIndividualAddresses()
- ->prepareRequest();
- }
-
- public function test_checkAndSetConfiguredPaymentMethod_finds_invoice_configuration()
- {
-
- $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig());
-
- // clear both payment method credentials for SE
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['username'] = "sverigetest";
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['password'] = "sverigetest";
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['clientNumber'] = 79021;
-// $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['username'] = null;
-// $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['password'] = null;
-// $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['clientNumber'] = null;
-// $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['username'] = null;
-// $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['password'] = null;
-// $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['clientNumber'] = null;
-
- $request
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4605092222")
- ->getIndividualAddresses()
- ->prepareRequest();
-
- $this->assertEquals(ConfigurationProvider::INVOICE_TYPE, $request->orderType);
- }
-
- public function test_checkAndSetConfiguredPaymentMethod_finds_paymentplan_configuration()
- {
-
- $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig());
-
- // clear both payment method credentials for SE
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['username'] = null;
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['password'] = null;
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['clientNumber'] = null;
- $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['username'] = "sverigetest";
- $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['password'] = "sverigetest";
- $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['clientNumber'] = 59999;
- $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['username'] = null;
- $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['password'] = null;
- $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['clientNumber'] = null;
-
- $request
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4605092222")
- ->getIndividualAddresses()
- ->prepareRequest();
-
- $this->assertEquals(ConfigurationProvider::PAYMENTPLAN_TYPE, $request->orderType);
- }
-
-
- public function test_checkAndSetConfiguredPaymentMethod_finds_accountcredit_configuration()
- {
-
- $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig());
-
- // clear both payment method credentials for SE
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['username'] = null;
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['password'] = null;
- $request->conf->conf['credentials']['SE']['auth']['Invoice']['clientNumber'] = null;
- $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['username'] = null;
- $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['password'] = null;
- $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['clientNumber'] = null;
- $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['username'] = "sverigetest";
- $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['password'] = "sverigetest";
- $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['clientNumber'] = 58702;
-
- $request
- ->setCountryCode("SE")
- ->setCustomerIdentifier("4605092222")
- ->getIndividualAddresses()
- ->prepareRequest();
-
- $this->assertEquals(ConfigurationProvider::ACCOUNTCREDIT_TYPE, $request->orderType);
- }
+ public function testBuildRequest()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $addressRequest = WebPay::getAddresses($config);
+ $addressRequest
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("SE460509")
+ ->getCompanyAddresses();
+ $this->assertEquals("SE", $addressRequest->countryCode);
+ $this->assertEquals("SE460509", $addressRequest->companyId);
+ }
+
+ public function testPrepareRequestPrivate()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $addressRequest = WebPay::getAddresses($config);
+ $request = $addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier(194605092222)
+ ->getIndividualAddresses()
+ ->prepareRequest();
+
+ $this->assertEquals(79021, $request->request->Auth->ClientNumber); //Check all in identity
+ $this->assertEquals("sverigetest", $request->request->Auth->Username); //Check all in identity
+ $this->assertEquals("sverigetest", $request->request->Auth->Password); //Check all in identity
+ $this->assertEquals(FALSE, $request->request->IsCompany);
+ $this->assertEquals("SE", $request->request->CountryCode);
+ $this->assertEquals(194605092222, $request->request->SecurityNumber);
+ }
+
+ public function testPrepareRequestCompany()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $addressRequest = WebPay::getAddresses($config);
+ $request = $addressRequest
+ ->setOrderTypeInvoice()
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier(4608142222)
+ ->getCompanyAddresses()
+ ->prepareRequest();
+
+ $this->assertEquals(79021, $request->request->Auth->ClientNumber); //Check all in identity
+ $this->assertEquals("sverigetest", $request->request->Auth->Username); //Check all in identity
+ $this->assertEquals("sverigetest", $request->request->Auth->Password); //Check all in identity
+ $this->assertEquals(true, $request->request->IsCompany);
+ $this->assertEquals("SE", $request->request->CountryCode);
+ $this->assertEquals(4608142222, $request->request->SecurityNumber);
+ }
+
+ /// validations
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage countryCode is required. Use function setCountryCode().
+ */
+ public function test_missing_countryCode_throws_exception()
+ {
+ $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig())
+ //->setCountryCode( "SE" )
+ ->setCustomerIdentifier("4605092222")
+ ->getIndividualAddresses()
+ ->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage customerIdentifier is required. Use function setCustomerIdentifer().
+ */
+ public function test_getIndividualAddresses_with_missing_customerIdentifier_throws_exception()
+ {
+ $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig())
+ ->setCountryCode("SE")
+ //->setCustomerIdentifier("4605092222")
+ ->getIndividualAddresses()
+ ->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage customerIdentifier is required. Use function setCustomerIdentifer().
+ */
+ public function test_getCompanyAddresses_with_missing_customerIdentifier_throws_exception()
+ {
+ $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig())
+ ->setCountryCode("SE")
+ //->setCustomerIdentifier("4605092222")
+ ->getCompanyAddresses()
+ ->prepareRequest();
+ }
+
+ /**
+ * @expectedException Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage missing authentication credentials. Check configuration.
+ */
+ public function test_missing_Configuration_for_CountryCode_throws_exception()
+ {
+ $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig());
+
+ // clear both payment method credentials for SE
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['username'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['password'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['clientNumber'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['username'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['password'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['clientNumber'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['username'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['password'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['clientNumber'] = null;
+
+ $request
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4605092222")
+ ->getIndividualAddresses()
+ ->prepareRequest();
+ }
+
+ public function test_checkAndSetConfiguredPaymentMethod_finds_invoice_configuration()
+ {
+
+ $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig());
+
+ // clear both payment method credentials for SE
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['username'] = "sverigetest";
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['password'] = "sverigetest";
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['clientNumber'] = 79021;
+// $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['username'] = null;
+// $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['password'] = null;
+// $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['clientNumber'] = null;
+// $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['username'] = null;
+// $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['password'] = null;
+// $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['clientNumber'] = null;
+
+ $request
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4605092222")
+ ->getIndividualAddresses()
+ ->prepareRequest();
+
+ $this->assertEquals(ConfigurationProvider::INVOICE_TYPE, $request->orderType);
+ }
+
+ public function test_checkAndSetConfiguredPaymentMethod_finds_paymentplan_configuration()
+ {
+
+ $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig());
+
+ // clear both payment method credentials for SE
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['username'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['password'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['clientNumber'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['username'] = "sverigetest";
+ $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['password'] = "sverigetest";
+ $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['clientNumber'] = 59999;
+ $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['username'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['password'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['clientNumber'] = null;
+
+ $request
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4605092222")
+ ->getIndividualAddresses()
+ ->prepareRequest();
+
+ $this->assertEquals(ConfigurationProvider::PAYMENTPLAN_TYPE, $request->orderType);
+ }
+
+
+ public function test_checkAndSetConfiguredPaymentMethod_finds_accountcredit_configuration()
+ {
+
+ $request = WebPay::getAddresses(ConfigurationService::getDefaultConfig());
+
+ // clear both payment method credentials for SE
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['username'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['password'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['Invoice']['clientNumber'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['username'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['password'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['PaymentPlan']['clientNumber'] = null;
+ $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['username'] = "sverigetest";
+ $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['password'] = "sverigetest";
+ $request->conf->conf['credentials']['SE']['auth']['AccountCredit']['clientNumber'] = 58702;
+
+ $request
+ ->setCountryCode("SE")
+ ->setCustomerIdentifier("4605092222")
+ ->getIndividualAddresses()
+ ->prepareRequest();
+
+ $this->assertEquals(ConfigurationProvider::ACCOUNTCREDIT_TYPE, $request->orderType);
+ }
}
diff --git a/test/UnitTest/WebService/GetPaymentPlanParams/PaymentPlanParamsTest.php b/test/UnitTest/WebService/GetPaymentPlanParams/PaymentPlanParamsTest.php
index 92525a47..fd870c0f 100644
--- a/test/UnitTest/WebService/GetPaymentPlanParams/PaymentPlanParamsTest.php
+++ b/test/UnitTest/WebService/GetPaymentPlanParams/PaymentPlanParamsTest.php
@@ -13,16 +13,16 @@
class PaymentPlanParamsTest extends \PHPUnit\Framework\TestCase
{
- public function testBuildRequest()
- {
- $config = ConfigurationService::getDefaultConfig();
- $addressRequest = WebPay::getPaymentPlanParams($config);
- $request = $addressRequest
- ->setCountryCode("SE")
- ->prepareRequest();
+ public function testBuildRequest()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $addressRequest = WebPay::getPaymentPlanParams($config);
+ $request = $addressRequest
+ ->setCountryCode("SE")
+ ->prepareRequest();
- $this->assertEquals(59999, $request->request->Auth->ClientNumber); //Check all in identity
- $this->assertEquals("sverigetest", $request->request->Auth->Username); //Check all in identity
- $this->assertEquals("sverigetest", $request->request->Auth->Password); //Check all in identity
- }
+ $this->assertEquals(59999, $request->request->Auth->ClientNumber); //Check all in identity
+ $this->assertEquals("sverigetest", $request->request->Auth->Username); //Check all in identity
+ $this->assertEquals("sverigetest", $request->request->Auth->Password); //Check all in identity
+ }
}
diff --git a/test/UnitTest/WebService/HandleOrder/CloseOrderTest.php b/test/UnitTest/WebService/HandleOrder/CloseOrderTest.php
index 3cd081cb..cbe25294 100644
--- a/test/UnitTest/WebService/HandleOrder/CloseOrderTest.php
+++ b/test/UnitTest/WebService/HandleOrder/CloseOrderTest.php
@@ -13,29 +13,29 @@
class CloseOrderTest extends \PHPUnit\Framework\TestCase
{
- public function testCloseInvoiceOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderBuilder = WebPay::closeOrder($config);
- $request = $orderBuilder
- ->setOrderId("id")
- ->setCountryCode("SE")
- ->closeInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals("id", $request->request->CloseOrderInformation->SveaOrderId);
- }
-
- public function testClosePaymentPlanOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderBuilder = WebPay::closeOrder($config);
- $request = $orderBuilder
- ->setCountryCode("SE")
- ->setOrderId("id")
- ->closePaymentPlanOrder()
- ->prepareRequest();
-
- $this->assertEquals("id", $request->request->CloseOrderInformation->SveaOrderId);
- }
+ public function testCloseInvoiceOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderBuilder = WebPay::closeOrder($config);
+ $request = $orderBuilder
+ ->setOrderId("id")
+ ->setCountryCode("SE")
+ ->closeInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals("id", $request->request->CloseOrderInformation->SveaOrderId);
+ }
+
+ public function testClosePaymentPlanOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderBuilder = WebPay::closeOrder($config);
+ $request = $orderBuilder
+ ->setCountryCode("SE")
+ ->setOrderId("id")
+ ->closePaymentPlanOrder()
+ ->prepareRequest();
+
+ $this->assertEquals("id", $request->request->CloseOrderInformation->SveaOrderId);
+ }
}
diff --git a/test/UnitTest/WebService/HandleOrder/DeliverOrderTest.php b/test/UnitTest/WebService/HandleOrder/DeliverOrderTest.php
index 0479d3fb..0574a26b 100644
--- a/test/UnitTest/WebService/HandleOrder/DeliverOrderTest.php
+++ b/test/UnitTest/WebService/HandleOrder/DeliverOrderTest.php
@@ -16,974 +16,974 @@
class DeliverOrderTest extends \PHPUnit\Framework\TestCase
{
- public function testBuildRequest()
- {
- $config = ConfigurationService::getDefaultConfig();
- $handler = WebPay::deliverOrder($config);
- $request = $handler
- ->setOrderId("id");
-
- $this->assertEquals("id", $request->orderId);
- }
-
- public function testDeliverInvoiceDistributionType()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderBuilder = WebPay::deliverOrder($config);
- $request = $orderBuilder
- ->addOrderRow(TestUtil::createOrderRow())
- ->setOrderId("id")
- ->setNumberOfCreditDays(1)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals('Post', $request->request->DeliverOrderInformation->DeliverInvoiceDetails->InvoiceDistributionType);
- }
-
- public function testDeliverInvoiceDistributionTypeEInvoiceB2B()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderBuilder = WebPay::deliverOrder($config);
- $request = $orderBuilder
- ->addOrderRow(TestUtil::createOrderRow())
- ->setOrderId("id")
- ->setNumberOfCreditDays(1)
- ->setCountryCode("NO")
- ->setInvoiceDistributionType(DistributionType::EINVOICEB2B)
- ->setCreditInvoice("id")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals('EInvoiceB2B', $request->request->DeliverOrderInformation->DeliverInvoiceDetails->InvoiceDistributionType);
- }
-
- public function testDeliverInvoiceOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderBuilder = WebPay::deliverOrder($config);
- $request = $orderBuilder
- ->addOrderRow(TestUtil::createOrderRow())
- ->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10))
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId('33')
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountExVat(50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->setOrderId("id")
- ->setNumberOfCreditDays(1)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType(DistributionType::POST)
- ->setCreditInvoice("id")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals("Product: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals(100.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->DiscountPercent);
- //discount
- $this->assertEquals(-8.0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- //shippingfee
- $this->assertEquals("33", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals("shipping: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals(50, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->DiscountPercent);
-
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->NumberOfCreditDays);
- $this->assertEquals("Post", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->InvoiceDistributionType);
- $this->assertEquals(true, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->IsCreditInvoice);
- $this->assertEquals("id", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->InvoiceIdToCredit);
- $this->assertEquals("id", $request->request->DeliverOrderInformation->SveaOrderId);
- $this->assertEquals("Invoice", $request->request->DeliverOrderInformation->OrderType);
- }
-
- public function testDeliverPaymentPlanOrder()
- {
- $config = ConfigurationService::getDefaultConfig();
- $orderBuilder = WebPay::deliverOrder($config);
-
- $request = $orderBuilder
- ->addOrderRow(TestUtil::createOrderRow())
- ->setCountryCode("SE")
- ->setOrderId("id")
- ->deliverPaymentPlanOrder()
- ->prepareRequest();
- $this->assertEquals("id", $request->request->DeliverOrderInformation->SveaOrderId);
- $this->assertEquals("PaymentPlan", $request->request->DeliverOrderInformation->OrderType);
- }
-
- public function testNewDeliverInvoiceOrderRow()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow());
- $request = $request->setOrderId("id")
- ->setNumberOfCreditDays(1)
- ->setCountryCode("SE")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals("Product: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals(100.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->DiscountPercent);
- }
-
- public function testDeliverOrderWithInvoiceFeeAndFixedDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addFee(WebPayItem::invoiceFee()
- ->setName('Svea fee')
- ->setDescription("Fee for invoice")
- ->setAmountExVat(50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("1")
- ->setAmountIncVat(100.00)
- ->setUnit("st")
- ->setDescription("FixedDiscount")
- ->setName("Fixed")
- );
- $request = $request->setOrderId("id")
- ->setNumberOfCreditDays(1)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals("Product: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals(100.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->DiscountPercent);
- //invoicefee
- $this->assertEquals("", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals(50.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals("Svea fee: Fee for invoice", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->DiscountPercent);
- //fixeddiscount
- $this->assertEquals("1", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals(-80.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals("Fixed: FixedDiscount", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->DiscountPercent);
- }
-
- public function testDeliverOrderWithShippingFeeAndRelativeDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(TestUtil::createOrderRow())
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId(1)
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountExVat(50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(50)
- ->setUnit("st")
- ->setName('Relative')
- ->setDescription("RelativeDiscount")
- );
- $request = $request->setOrderId("id")
- ->setNumberOfCreditDays(1)
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals("Product: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals(100.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->DiscountPercent);
- //shipping
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals(50.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals("shipping: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->DiscountPercent);
- //relative discount
- $this->assertEquals("1", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals(-100.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals("Relative: RelativeDiscount", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->DiscountPercent);
- }
-
- /**
- * Tests for rounding**
- */
-
- public function testDeliverOrderWithAmountExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(80.00, $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(80.00, $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);
-
- }
-
- public function testDeliverFeeSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(80.00, $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(80.00, $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(80.00, $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);
-
- }
-
- public function testDeliverDiscountSetAsExVatWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(8)
- ->setVatPercent(24)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(80.00, $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(-8, $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);
-
- }
-
- public function testDeliverDiscountSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(8)
- ->setVatPercent(0))
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(80.00, $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(-8, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testDeliverDiscountPercentAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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(-9.999, $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);
-
- }
-
- public function testDeliverOrderRowPriceSetAsInkVatAndVatPercentSetAmountAsIncVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testDeliverFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(100.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(100.00)
- ->setVatPercent(24)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(100, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(100, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testDeliverDiscountSetAsIncVatWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(10)
- ->setVatPercent(0))
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-10, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testDiscountPercentAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-12.39876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testDeliverOrderSetAsIncVatAndExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testOrderAndFeesSetAsIncVatAndExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1230.9876)
- ->setAmountExVat(990.99)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testDeliverOrderAndFixedDiscountSetAsIncVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(12.39876)
- ->setVatPercent(24)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-12.39876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testDeliverOrderSetAsIncVatAndExVatAndRelativeDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-12.39876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testDeliverOrderSetWithMixedMethods1()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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.99, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $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);
-
- }
-
- public function testDeliverOrderSetWithMixedMethods2()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setName('incvat')
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setName('exvat')
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setName('exvat')
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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.99, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $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);
-
- }
-
- public function testDeliverOrderSetWithMixedOrderRowAndFee()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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.99, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $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);
-
- }
-
- public function testDeliverOrderSetWithMixedOrderRowAndFeeAndVatPercentSet()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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.99, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $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);
-
- }
-
- public function testDeliverOrderAndFixedDiscountSetWithMixedVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(9.999)
- ->setVatPercent(24)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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(-9.999, $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);
-
- }
-
- public function testDeliverOrderAndFixedDiscountSetWithMixedVat2()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(12.39876)
- ->setVatPercent(24)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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(-9.999, $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);
-
- }
-
- public function testDeliverOrderAndFixedDiscountSetWithMixedVat3()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(9.999)
- ->setVatPercent(24)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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(-9.999, $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);
-
- }
-
- public function testDeliverOrderSetAsMixedVatAndRelativeDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::deliverOrder($config);
- $request = $request
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(5)
- )
- ->setOrderId("id")
- ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
- ->setCreditInvoice("id")
- ->setCountryCode("SE")
- ->deliverInvoiceOrder()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $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.99, $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.999, $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);
-
- }
+ public function testBuildRequest()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $handler = WebPay::deliverOrder($config);
+ $request = $handler
+ ->setOrderId("id");
+
+ $this->assertEquals("id", $request->orderId);
+ }
+
+ public function testDeliverInvoiceDistributionType()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderBuilder = WebPay::deliverOrder($config);
+ $request = $orderBuilder
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setOrderId("id")
+ ->setNumberOfCreditDays(1)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals('Post', $request->request->DeliverOrderInformation->DeliverInvoiceDetails->InvoiceDistributionType);
+ }
+
+ public function testDeliverInvoiceDistributionTypeEInvoiceB2B()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderBuilder = WebPay::deliverOrder($config);
+ $request = $orderBuilder
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setOrderId("id")
+ ->setNumberOfCreditDays(1)
+ ->setCountryCode("NO")
+ ->setInvoiceDistributionType(DistributionType::EINVOICEB2B)
+ ->setCreditInvoice("id")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals('EInvoiceB2B', $request->request->DeliverOrderInformation->DeliverInvoiceDetails->InvoiceDistributionType);
+ }
+
+ public function testDeliverInvoiceOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderBuilder = WebPay::deliverOrder($config);
+ $request = $orderBuilder
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10))
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId('33')
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountExVat(50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->setOrderId("id")
+ ->setNumberOfCreditDays(1)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType(DistributionType::POST)
+ ->setCreditInvoice("id")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals("Product: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals(100.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->DiscountPercent);
+ //discount
+ $this->assertEquals(-8.0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ //shippingfee
+ $this->assertEquals("33", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals("shipping: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals(50, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->DiscountPercent);
+
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->NumberOfCreditDays);
+ $this->assertEquals("Post", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->InvoiceDistributionType);
+ $this->assertEquals(true, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->IsCreditInvoice);
+ $this->assertEquals("id", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->InvoiceIdToCredit);
+ $this->assertEquals("id", $request->request->DeliverOrderInformation->SveaOrderId);
+ $this->assertEquals("Invoice", $request->request->DeliverOrderInformation->OrderType);
+ }
+
+ public function testDeliverPaymentPlanOrder()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $orderBuilder = WebPay::deliverOrder($config);
+
+ $request = $orderBuilder
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->setCountryCode("SE")
+ ->setOrderId("id")
+ ->deliverPaymentPlanOrder()
+ ->prepareRequest();
+ $this->assertEquals("id", $request->request->DeliverOrderInformation->SveaOrderId);
+ $this->assertEquals("PaymentPlan", $request->request->DeliverOrderInformation->OrderType);
+ }
+
+ public function testNewDeliverInvoiceOrderRow()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow());
+ $request = $request->setOrderId("id")
+ ->setNumberOfCreditDays(1)
+ ->setCountryCode("SE")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals("Product: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals(100.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->DiscountPercent);
+ }
+
+ public function testDeliverOrderWithInvoiceFeeAndFixedDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addFee(WebPayItem::invoiceFee()
+ ->setName('Svea fee')
+ ->setDescription("Fee for invoice")
+ ->setAmountExVat(50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("1")
+ ->setAmountIncVat(100.00)
+ ->setUnit("st")
+ ->setDescription("FixedDiscount")
+ ->setName("Fixed")
+ );
+ $request = $request->setOrderId("id")
+ ->setNumberOfCreditDays(1)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals("Product: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals(100.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->DiscountPercent);
+ //invoicefee
+ $this->assertEquals("", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals(50.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals("Svea fee: Fee for invoice", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->DiscountPercent);
+ //fixeddiscount
+ $this->assertEquals("1", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals(-80.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals("Fixed: FixedDiscount", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->DiscountPercent);
+ }
+
+ public function testDeliverOrderWithShippingFeeAndRelativeDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId(1)
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountExVat(50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(50)
+ ->setUnit("st")
+ ->setName('Relative')
+ ->setDescription("RelativeDiscount")
+ );
+ $request = $request->setOrderId("id")
+ ->setNumberOfCreditDays(1)
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals("Product: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals(100.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->DiscountPercent);
+ //shipping
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals(50.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals("shipping: Specification", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->DiscountPercent);
+ //relative discount
+ $this->assertEquals("1", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals(1, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals(-100.00, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals("Relative: RelativeDiscount", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals("st", $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->DiscountPercent);
+ }
+
+ /**
+ * Tests for rounding**
+ */
+
+ public function testDeliverOrderWithAmountExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(80.00, $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(80.00, $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);
+
+ }
+
+ public function testDeliverFeeSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(80.00, $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(80.00, $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(80.00, $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);
+
+ }
+
+ public function testDeliverDiscountSetAsExVatWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(8)
+ ->setVatPercent(24)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(80.00, $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(-8, $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);
+
+ }
+
+ public function testDeliverDiscountSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(8)
+ ->setVatPercent(0))
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(80.00, $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(-8, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testDeliverDiscountPercentAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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(-9.999, $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);
+
+ }
+
+ public function testDeliverOrderRowPriceSetAsInkVatAndVatPercentSetAmountAsIncVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testDeliverFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(24)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(100, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(100, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testDeliverDiscountSetAsIncVatWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10)
+ ->setVatPercent(0))
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-10, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(0, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testDiscountPercentAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-12.39876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testDeliverOrderSetAsIncVatAndExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testOrderAndFeesSetAsIncVatAndExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1230.9876)
+ ->setAmountExVat(990.99)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testDeliverOrderAndFixedDiscountSetAsIncVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(12.39876)
+ ->setVatPercent(24)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-12.39876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testDeliverOrderSetAsIncVatAndExVatAndRelativeDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-12.39876, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testDeliverOrderSetWithMixedMethods1()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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.99, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $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);
+
+ }
+
+ public function testDeliverOrderSetWithMixedMethods2()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setName('incvat')
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setName('exvat')
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setName('exvat')
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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.99, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $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);
+
+ }
+
+ public function testDeliverOrderSetWithMixedOrderRowAndFee()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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.99, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $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);
+
+ }
+
+ public function testDeliverOrderSetWithMixedOrderRowAndFeeAndVatPercentSet()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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.99, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->DeliverOrderInformation->DeliverInvoiceDetails->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $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);
+
+ }
+
+ public function testDeliverOrderAndFixedDiscountSetWithMixedVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(9.999)
+ ->setVatPercent(24)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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(-9.999, $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);
+
+ }
+
+ public function testDeliverOrderAndFixedDiscountSetWithMixedVat2()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(12.39876)
+ ->setVatPercent(24)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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(-9.999, $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);
+
+ }
+
+ public function testDeliverOrderAndFixedDiscountSetWithMixedVat3()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(9.999)
+ ->setVatPercent(24)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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(-9.999, $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);
+
+ }
+
+ public function testDeliverOrderSetAsMixedVatAndRelativeDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::deliverOrder($config);
+ $request = $request
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(5)
+ )
+ ->setOrderId("id")
+ ->setInvoiceDistributionType(DistributionType::POST)//Post or Email
+ ->setCreditInvoice("id")
+ ->setCountryCode("SE")
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $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.99, $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.999, $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);
+
+ }
}
diff --git a/test/UnitTest/WebService/HandleOrder/OrderHandlerValidatorTest.php b/test/UnitTest/WebService/HandleOrder/OrderHandlerValidatorTest.php
index 34bceae9..ea4a00f8 100644
--- a/test/UnitTest/WebService/HandleOrder/OrderHandlerValidatorTest.php
+++ b/test/UnitTest/WebService/HandleOrder/OrderHandlerValidatorTest.php
@@ -17,93 +17,93 @@
class OrderHandlerValidatorTest extends \PHPUnit\Framework\TestCase
{
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : OrderId is required. Use function setOrderId() with the SveaOrderId from the createOrder response.
- */
- public function test_deliverPaymentPlanOrder_with_missing_OrderId_raises_exception()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::deliverOrder($config);
- $object = $builder;
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : OrderId is required. Use function setOrderId() with the SveaOrderId from the createOrder response.
+ */
+ public function test_deliverPaymentPlanOrder_with_missing_OrderId_raises_exception()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::deliverOrder($config);
+ $object = $builder;
- $object->deliverPaymentPlanOrder()
- ->prepareRequest();
- }
+ $object->deliverPaymentPlanOrder()
+ ->prepareRequest();
+ }
- public function test_deliverPaymentPlanOrder_with_missing_invoiceDistributionType_validates_OK()
- {
- try {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::deliverOrder($config);
- $request = $builder
- ->setOrderId(123456)
- ->setCountryCode("SE")
- ->addOrderRow(TestUtil::createOrderRow())
- ->deliverPaymentPlanOrder()
- ->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
+ public function test_deliverPaymentPlanOrder_with_missing_invoiceDistributionType_validates_OK()
+ {
+ try {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::deliverOrder($config);
+ $request = $builder
+ ->setOrderId(123456)
+ ->setCountryCode("SE")
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->deliverPaymentPlanOrder()
+ ->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
- }
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : InvoiceDistributionType is required for deliverInvoiceOrder. Use function setInvoiceDistributionType().
- */
- public function test_deliverInvoiceOrder_with_missing_invoiceDistributionType_raises_exception()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = WebPay::deliverOrder($config);
- $request = $builder
- ->setOrderId(123456)
- ->setCountryCode("SE")
- ->addOrderRow(TestUtil::createOrderRow())
- ->deliverInvoiceOrder()
- ->prepareRequest();
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : InvoiceDistributionType is required for deliverInvoiceOrder. Use function setInvoiceDistributionType().
+ */
+ public function test_deliverInvoiceOrder_with_missing_invoiceDistributionType_raises_exception()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = WebPay::deliverOrder($config);
+ $request = $builder
+ ->setOrderId(123456)
+ ->setCountryCode("SE")
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->deliverInvoiceOrder()
+ ->prepareRequest();
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage -missing value : InvoiceDistributionType is required for deliverInvoiceOrder. Use function setInvoiceDistributionType().
- */
- public function testFailOnMissingInvoiceDetailsOnInvoiceDeliver()
- {
- $config = ConfigurationService::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();
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage -missing value : InvoiceDistributionType is required for deliverInvoiceOrder. Use function setInvoiceDistributionType().
+ */
+ public function testFailOnMissingInvoiceDetailsOnInvoiceDeliver()
+ {
+ $config = ConfigurationService::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();
+ }
- /**
- * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
- * @expectedExceptionMessage No rows has been included. Use function beginOrderRow(), beginShippingfee() or beginInvoiceFee().
- *
- * 2.0 goes directly to DeliverInvoice
- */
- public function testFailOnMissingOrderRowsOnInvoiceDeliver()
- {
- $config = ConfigurationService::getDefaultConfig();
- $builder = new DeliverOrderBuilder($config);
- $builder
- ->setOrderId('id')
- ->setInvoiceDistributionType('Post');
- $object = new DeliverInvoice($builder);
- $object->prepareRequest();
- }
+ /**
+ * @expectedException \Svea\WebPay\BuildOrder\Validator\ValidationException
+ * @expectedExceptionMessage No rows has been included. Use function beginOrderRow(), beginShippingfee() or beginInvoiceFee().
+ *
+ * 2.0 goes directly to DeliverInvoice
+ */
+ public function testFailOnMissingOrderRowsOnInvoiceDeliver()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $builder = new DeliverOrderBuilder($config);
+ $builder
+ ->setOrderId('id')
+ ->setInvoiceDistributionType('Post');
+ $object = new DeliverInvoice($builder);
+ $object->prepareRequest();
+ }
}
diff --git a/test/UnitTest/WebService/Helper/WebServiceRowFormatterTest.php b/test/UnitTest/WebService/Helper/WebServiceRowFormatterTest.php
index a8928146..0058fdcb 100644
--- a/test/UnitTest/WebService/Helper/WebServiceRowFormatterTest.php
+++ b/test/UnitTest/WebService/Helper/WebServiceRowFormatterTest.php
@@ -13,764 +13,764 @@
class WebServiceRowFormatterTest extends \PHPUnit\Framework\TestCase
{
- public function test_convertIncVatToExVat()
- {
-
- $this->assertEquals(8.00, WebServiceRowFormatter::convertIncVatToExVat(10.00, 25));
- $this->assertEquals(69.99, WebServiceRowFormatter::convertIncVatToExVat(69.99 * 1.25, 25));
-
- $this->assertEquals(0, WebServiceRowFormatter::convertIncVatToExVat(0, 0));
- $this->assertEquals(1, WebServiceRowFormatter::convertIncVatToExVat(1, 0));
- $this->assertEquals(0, WebServiceRowFormatter::convertIncVatToExVat(0 * 1.25, 25));
-
- $this->assertEquals(100.00, WebServiceRowFormatter::convertIncVatToExVat(100.00 * 1.06, 6));
- $this->assertEquals(100.00, WebServiceRowFormatter::convertIncVatToExVat(100.00 * 1.0825, 8.25));
- }
-
- public function test_convertExVatToIncVat()
- {
-
- $this->assertEquals(10.00, WebServiceRowFormatter::convertExVatToIncVat(8.00, 25));
- $this->assertEquals(69.99 * 1.25, WebServiceRowFormatter::convertExVatToIncVat(69.99, 25));
-
- $this->assertEquals(0, WebServiceRowFormatter::convertExVatToIncVat(0, 0));
- $this->assertEquals(1, WebServiceRowFormatter::convertExVatToIncVat(1, 0));
- $this->assertEquals(0, WebServiceRowFormatter::convertExVatToIncVat(0, 25));
-
- $this->assertEquals(100.00 * 1.06, WebServiceRowFormatter::convertExVatToIncVat(100.00, 6));
- $this->assertEquals(Helper::bround(100.00 * 1.0825, 2), WebServiceRowFormatter::convertExVatToIncVat(100.00, 8.25));
- }
-
- public function test_FormatOrderRows_includes_all_attributes_in_formatted_rows()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(4)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setUnit("st")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
- $testedRow = $resultRows[0];
-
- $this->assertEquals("0", $testedRow->ArticleNumber);
- $this->assertEquals("Tess: Tester", $testedRow->Description);
- $this->assertEquals(4.0, $testedRow->PricePerUnit);
- $this->assertEquals(25.0, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent);
- $this->assertEquals(1, $testedRow->NumberOfUnits);
- $this->assertEquals("st", $testedRow->Unit);
- }
-
- // TODO write tests for the three different ways we can specify an order here (ex+vat, inc+vat, ex+inc)
-
- public function test_FormatShippingFeeRows_includes_all_attributes_in_formatted_rows()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addFee(WebPayItem::shippingFee()
- ->setShippingId("0")
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(4)
- ->setVatPercent(25)
- ->setUnit("st")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
- $testedRow = $resultRows[0];
-
- $this->assertEquals("0", $testedRow->ArticleNumber);
- $this->assertEquals("Tess: Tester", $testedRow->Description);
- $this->assertEquals(4.0, $testedRow->PricePerUnit);
- $this->assertEquals(25.0, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent);
- $this->assertEquals(1, $testedRow->NumberOfUnits);
- $this->assertEquals("st", $testedRow->Unit);
- }
-
- // TODO write tests for the three different ways we can specify a shipping fee here (ex+vat, inc+vat, ex+inc?)
-
- public function test_FormatInvoiceFeeRows_includes_all_attributes_in_formatted_rows()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addFee(WebPayItem::invoiceFee()
- ->setName("Tess")
- ->setDescription("Tester")
- ->setAmountExVat(4)
- ->setVatPercent(25)
- ->setUnit("st")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
- $testedRow = $resultRows[0];
-
- $this->assertEquals("", $testedRow->ArticleNumber);
- $this->assertEquals("Tess: Tester", $testedRow->Description);
- $this->assertEquals(4.0, $testedRow->PricePerUnit);
- $this->assertEquals(25.0, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent);
- $this->assertEquals(1, $testedRow->NumberOfUnits);
- $this->assertEquals("st", $testedRow->Unit);
- }
-
- // TODO write tests for the three different ways we can specify an invoice fee here (ex+vat, inc+vat, ex+inc?)
-
- // FixedDiscountRow specified using only amountExVat
- public function test_FixedDiscount_specified_using_amountExVat_in_order_with_single_vat_rate()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- // cover all three ways to specify items here: iv+vp, ev+vp, iv+ev
- ->setAmountExVat(4.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(5.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f1e")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountExVat(1.0)
- ->setUnit("st")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
- $testedRow = $resultRows[3];
-
- $this->assertEquals("f1e", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc", $testedRow->Description);
- $this->assertEquals(-1.0, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent);
- $this->assertEquals(1, $testedRow->NumberOfUnits);
- $this->assertEquals("st", $testedRow->Unit);
- }
-
- // FixedDiscountRow specified using only amountExVat => split discount excl. vat over the diffrent tax rates present in order
- public function test_FixedDiscount_specified_using_amountExVat_in_order_with_multiple_vat_rates()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @25% = 125")
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @6% = 106")
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100e")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountExVat(100.00)
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
- // 100*200/300 = 66.66 ex. 25% vat => discount 83.33 (incl. 16.67 vat @25%)
- $testedRow = $resultRows[2];
- $this->assertEquals("f100e", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
- $this->assertEquals(-(200 / 300) * 100, $testedRow->PricePerUnit); //-66.67
- //$this->assertEquals(-66.67, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
-
- // 100*100/300 = 33.33 ex. 6% vat => discount 35.33 (incl 2.00 vat @6%)
- $testedRow = $resultRows[3];
- $this->assertEquals("f100e", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
- $this->assertEquals(-(100 / 300) * 100, $testedRow->PricePerUnit); //-33.33
- //$this->assertEquals(-33.33, $testedRow->PricePerUnit);
- $this->assertEquals(6, $testedRow->VatPercent);
-
- // order total should be 166.66 (incl. 33.33 vat @25%) + 70.67 (incl. 4.00 vat @6%) = 237.33 (incl 37.33 vat @18.665%)
- $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits;
- $this->assertEquals(237.33333333333, $total);
- }
-
- // FixedDiscountRow specified using only amountIncVat => split discount incl. vat over the diffrent tax rates present in order
- public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_single_vat_rate()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(5.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f1i")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountIncVat(1.0)
- ->setUnit("kr")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
- $testedRow = $resultRows[3];
- $this->assertEquals("f1i", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc", $testedRow->Description);
- $this->assertEquals(-0.8, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent);
- $this->assertEquals(1, $testedRow->NumberOfUnits);
- $this->assertEquals("kr", $testedRow->Unit);
- }
-
- // FixedDiscountRow specified using only amountIncVat => split discount incl. vat over the diffrent tax rates present in order
- // if we have two orders items with different vat rate, we need to create
- // two discount order rows, one for each vat rate
- public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_multiple_vat_rates()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100i")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountIncVat(100)
- ->setUnit("st")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
-
- // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
- $testedRow = $resultRows[2];
- $this->assertEquals("f100i", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
- $this->assertEquals(-56.179775280899, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
-
- // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
- $testedRow = $resultRows[3];
- $this->assertEquals("f100i", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
- $this->assertEquals(-28.089887640449, $testedRow->PricePerUnit);
- $this->assertEquals(6, $testedRow->VatPercent);
-
- // order total should be 250 + 106 - 100 = 256 (incl. 40.27 vat)
- $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits;
- $this->assertEquals(256.00, $total);
- }
-
- // FixedDiscount should only look at vat rates from order item rows, not shipping or invoice fees
- public function test_FixedDiscount_specified_using_amountIncVat_are_calculated_from_order_item_rows_only()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(50.00)
- ->setVatPercent(6)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(23.20)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100i")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountIncVat(100)
- ->setUnit("kr")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
-
- // 100*250/250 = 100 discount incl. 25% vat => 20 discount vat as amount
- $testedRow = $resultRows[3];
- $this->assertEquals("f100i", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc", $testedRow->Description);
- $this->assertEquals(-80.00, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
-
- // order total should be 250-100+53+29 = 232 kr
- $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits;
- $this->assertEquals(232.00, $total);
-
- }
-
- // FixedDiscount should only look at vat rates from order item rows, not shipping or invoice fees
- public function test_FixedDiscount_specified_using_amountExVat_are_calculated_from_order_item_rows_only()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(50.00)
- ->setVatPercent(6)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(23.20)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100e")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountExVat(100)
- ->setUnit("kr")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
-
- // 100*200/200 = 100 discount excl.% vat => 20 discount vat as amount
- $testedRow = $resultRows[3];
- $this->assertEquals("f100e", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc", $testedRow->Description);
- $this->assertEquals(-100.00, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
-
- // order total should be 250-125+53+29 = 207 kr
- $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits;
- $this->assertEquals(207.00, $total);
- }
-
- public function test_FixedDiscount_specified_using_amountExVat_are_calculated_from_order_item_rows_only_multiple_vat_rates()
- {
- // FixedDiscountRow specified using only amountExVat => split discount excl. vat over the diffrent tax rates present in order
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @25% = 125")
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setName("product with price 100 @6% = 106")
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setName("shipping with price 50 @6% = 106")
- ->setAmountExVat(50.00)
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100e")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountExVat(100.00)
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
-
- // 100*200/300 = 66.66 ex. 25% vat => 83.33 vat as amount
- $testedRow = $resultRows[3];
- $this->assertEquals("f100e", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
- $this->assertEquals(-66.666666666667, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
-
- // 100*100/300 = 33.33 ex. 6% vat => 35.33 vat as amount
- $testedRow = $resultRows[4];
- $this->assertEquals("f100e", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
- $this->assertEquals(-(100 / 300) * 100, $testedRow->PricePerUnit);
- $this->assertEquals(6, $testedRow->VatPercent);
-
- // order total should be 166.67+70.67 +53 = 237.34 +53
- $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[4]->PricePerUnit, $resultRows[4]->VatPercent) * $resultRows[4]->NumberOfUnits;
- $this->assertEquals(237.33333333333 + 53, $total);
- }
-
- public function test_FixedDiscount_specified_using_amountIncVat_are_calculated_from_order_item_rows_only_multiple_vat_rates()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setName("shipping with price 50 @6% = 106")
- ->setAmountExVat(50.00)
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("f100i")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setAmountIncVat(100)
- ->setUnit("st")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
-
- // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
- $testedRow = $resultRows[3];
- $this->assertEquals("f100i", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
- $this->assertEquals(-56.179775280899, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
-
- // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
- $testedRow = $resultRows[4];
- $this->assertEquals("f100i", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
- $this->assertEquals(-28.089887640449, $testedRow->PricePerUnit);
- $this->assertEquals(6, $testedRow->VatPercent);
-
- // order total should be 250 + 106 - 100 +53= 256+53
- $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits +
- WebServiceRowFormatter::convertExVatToIncVat($resultRows[4]->PricePerUnit, $resultRows[4]->VatPercent) * $resultRows[4]->NumberOfUnits;
- $this->assertEquals(256.00 + 53, $total);
- }
-
-
- // amountIncVat and vatPercent => add as single row with specified vat rate only
- public function test_FixedDiscount_specified_using_amountIncVat_and_vatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setDiscountId("42")
- ->setName("->setAmountIncVat(111), ->vatPercent(25)")
- ->setDescription("testFormatFixedDiscountRows_amountIncVatAndVatPercent_WithDifferentVatRatesPresent")
- ->setAmountIncVat(111)
- ->setVatPercent(25)
- ->setUnit("st")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
-
- // 100 @25% vat = -80 excl. vat
- $testedRow = $resultRows[2];
- $this->assertEquals("42", $testedRow->ArticleNumber);
- $this->assertEquals("->setAmountIncVat(111), ->vatPercent(25): testFormatFixedDiscountRows_amountIncVatAndVatPercent_WithDifferentVatRatesPresent", $testedRow->Description);
- $this->assertEquals(-88.80, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent);
- $this->assertEquals(1, $testedRow->NumberOfUnits);
- $this->assertEquals("st", $testedRow->Unit);
-
- $this->assertEquals(false, isset($resultRows[3])); // no more rows
- }
-
- // amountExVat and vatPercent => add as single row with specified vat rate only
- public function test_FixedDiscount_specified_using_amountExVat_and_vatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setName("->setAmountExVat(100)")
- ->setDescription("testFormatFixedDiscountRowsWithDifferentVatRatesPresent2 (25%)")
- ->setAmountExVat(66.67)
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setName("->setAmountExVat(100)")
- ->setDescription("testFormatFixedDiscountRowsWithDifferentVatRatesPresent2 (6%)")
- ->setAmountExVat(33.33)
- ->setVatPercent(6)
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
-
- $testedRow = $resultRows[2];
- $this->assertEquals("->setAmountExVat(100): testFormatFixedDiscountRowsWithDifferentVatRatesPresent2 (25%)", $testedRow->Description);
- $this->assertEquals(-66.67, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
-
- $testedRow = $resultRows[3];
- $this->assertEquals("->setAmountExVat(100): testFormatFixedDiscountRowsWithDifferentVatRatesPresent2 (6%)", $testedRow->Description);
- $this->assertEquals(-33.33, $testedRow->PricePerUnit);
- $this->assertEquals(6, $testedRow->VatPercent);
-
- $this->assertEquals(false, isset($resultRows[4])); // no more rows
- }
-
- // specifying discounts with incVat+exVat is not supported -- public function test_FixedDiscount_specified_using_amountIncVat_and_amountExVat() {
-
- public function test_RelativeDiscount_in_order_with_single_vat_rate()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(5.0)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(4.0)
- ->setAmountIncVat(5.0)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("r10")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setDiscountPercent(10)
- ->setUnit("kr")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
- $testedRow = $resultRows[3];
-
- $this->assertEquals("r10", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc", $testedRow->Description);
- $this->assertEquals(-1.2, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as DiscountPercent in our Svea\WebPay\WebPayItem...
- $this->assertEquals(1, $testedRow->NumberOfUnits);
- $this->assertEquals("kr", $testedRow->Unit);
- }
-
- public function test_RelativeDiscount_in_order_with_multiple_vat_rates()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(12)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("r20")
- ->setName("couponName")
- ->setDescription("couponDesc")
- ->setDiscountPercent(25)
- ->setUnit("kr")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
-
- $testedRow = $resultRows[3];
- $this->assertEquals("r20", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
- $this->assertEquals(-25.00, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as DiscountPercent in our Svea\WebPay\WebPayItem...
- $this->assertEquals(1, $testedRow->NumberOfUnits);
- $this->assertEquals("kr", $testedRow->Unit);
-
- $testedRow = $resultRows[4];
- $this->assertEquals("r20", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (12%)", $testedRow->Description);
- $this->assertEquals(-25.00, $testedRow->PricePerUnit);
- $this->assertEquals(12, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as DiscountPercent in our Svea\WebPay\WebPayItem...
- $this->assertEquals(1, $testedRow->NumberOfUnits);
- $this->assertEquals("kr", $testedRow->Unit);
-
- $testedRow = $resultRows[5];
- $this->assertEquals("r20", $testedRow->ArticleNumber);
- $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
- $this->assertEquals(-25.00, $testedRow->PricePerUnit);
- $this->assertEquals(6, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as DiscountPercent in our Svea\WebPay\WebPayItem...
- $this->assertEquals(1, $testedRow->NumberOfUnits);
- $this->assertEquals("kr", $testedRow->Unit);
- }
-
- // if we have two orders items with different vat rate, we need to create
- // two discount order rows, one for each vat rate
- public function testFormatRelativeDiscountRows_WithDifferentVatRatesPresent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(2)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("42")
- ->setName("->setDiscountPercent(10)")
- ->setDescription("testFormatRelativeDiscountRows_WithDifferentVatRatesPresent")
- ->setDiscountPercent(10)
- ->setUnit("st")
- );
-
- $formatter = new WebServiceRowFormatter($order);
- $resultRows = $formatter->formatRows();
-
- $testedRow = $resultRows[2];
- $this->assertEquals("42", $testedRow->ArticleNumber);
- $this->assertEquals("->setDiscountPercent(10): testFormatRelativeDiscountRows_WithDifferentVatRatesPresent (25%)", $testedRow->Description);
- $this->assertEquals(-20.00, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as in our Svea\WebPay\WebPayItem...
- $this->assertEquals(1, $testedRow->NumberOfUnits); // 1 "discount unit"
- $this->assertEquals("st", $testedRow->Unit);
-
- $testedRow = $resultRows[3];
- $this->assertEquals("42", $testedRow->ArticleNumber);
- $this->assertEquals("->setDiscountPercent(10): testFormatRelativeDiscountRows_WithDifferentVatRatesPresent (6%)", $testedRow->Description);
- $this->assertEquals(-10.00, $testedRow->PricePerUnit);
- $this->assertEquals(6, $testedRow->VatPercent);
- $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as DiscountPercent in our Svea\WebPay\WebPayItem...
- $this->assertEquals(1, $testedRow->NumberOfUnits); // 1 "discount unit"
- $this->assertEquals("st", $testedRow->Unit);
- }
-
- /**
- * 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 Svea\WebPay\Test\IntegrationTest\WebService\Payment\InvoicePaymentIntegrationTest, Jira issue WEB-193
- */
- public function test_regressiontest_for_float_to_int_conversion_errorS()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config);
- $order->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(0.00)
- ->setVatPercent(0)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(23.20)
- ->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.20, $testedRow->PricePerUnit);
- $this->assertEquals(25, $testedRow->VatPercent);
- }
+ public function test_convertIncVatToExVat()
+ {
+
+ $this->assertEquals(8.00, WebServiceRowFormatter::convertIncVatToExVat(10.00, 25));
+ $this->assertEquals(69.99, WebServiceRowFormatter::convertIncVatToExVat(69.99 * 1.25, 25));
+
+ $this->assertEquals(0, WebServiceRowFormatter::convertIncVatToExVat(0, 0));
+ $this->assertEquals(1, WebServiceRowFormatter::convertIncVatToExVat(1, 0));
+ $this->assertEquals(0, WebServiceRowFormatter::convertIncVatToExVat(0 * 1.25, 25));
+
+ $this->assertEquals(100.00, WebServiceRowFormatter::convertIncVatToExVat(100.00 * 1.06, 6));
+ $this->assertEquals(100.00, WebServiceRowFormatter::convertIncVatToExVat(100.00 * 1.0825, 8.25));
+ }
+
+ public function test_convertExVatToIncVat()
+ {
+
+ $this->assertEquals(10.00, WebServiceRowFormatter::convertExVatToIncVat(8.00, 25));
+ $this->assertEquals(69.99 * 1.25, WebServiceRowFormatter::convertExVatToIncVat(69.99, 25));
+
+ $this->assertEquals(0, WebServiceRowFormatter::convertExVatToIncVat(0, 0));
+ $this->assertEquals(1, WebServiceRowFormatter::convertExVatToIncVat(1, 0));
+ $this->assertEquals(0, WebServiceRowFormatter::convertExVatToIncVat(0, 25));
+
+ $this->assertEquals(100.00 * 1.06, WebServiceRowFormatter::convertExVatToIncVat(100.00, 6));
+ $this->assertEquals(Helper::bround(100.00 * 1.0825, 2), WebServiceRowFormatter::convertExVatToIncVat(100.00, 8.25));
+ }
+
+ public function test_FormatOrderRows_includes_all_attributes_in_formatted_rows()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(4)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setUnit("st")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+ $testedRow = $resultRows[0];
+
+ $this->assertEquals("0", $testedRow->ArticleNumber);
+ $this->assertEquals("Tess: Tester", $testedRow->Description);
+ $this->assertEquals(4.0, $testedRow->PricePerUnit);
+ $this->assertEquals(25.0, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent);
+ $this->assertEquals(1, $testedRow->NumberOfUnits);
+ $this->assertEquals("st", $testedRow->Unit);
+ }
+
+ // TODO write tests for the three different ways we can specify an order here (ex+vat, inc+vat, ex+inc)
+
+ public function test_FormatShippingFeeRows_includes_all_attributes_in_formatted_rows()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addFee(WebPayItem::shippingFee()
+ ->setShippingId("0")
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(4)
+ ->setVatPercent(25)
+ ->setUnit("st")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+ $testedRow = $resultRows[0];
+
+ $this->assertEquals("0", $testedRow->ArticleNumber);
+ $this->assertEquals("Tess: Tester", $testedRow->Description);
+ $this->assertEquals(4.0, $testedRow->PricePerUnit);
+ $this->assertEquals(25.0, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent);
+ $this->assertEquals(1, $testedRow->NumberOfUnits);
+ $this->assertEquals("st", $testedRow->Unit);
+ }
+
+ // TODO write tests for the three different ways we can specify a shipping fee here (ex+vat, inc+vat, ex+inc?)
+
+ public function test_FormatInvoiceFeeRows_includes_all_attributes_in_formatted_rows()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addFee(WebPayItem::invoiceFee()
+ ->setName("Tess")
+ ->setDescription("Tester")
+ ->setAmountExVat(4)
+ ->setVatPercent(25)
+ ->setUnit("st")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+ $testedRow = $resultRows[0];
+
+ $this->assertEquals("", $testedRow->ArticleNumber);
+ $this->assertEquals("Tess: Tester", $testedRow->Description);
+ $this->assertEquals(4.0, $testedRow->PricePerUnit);
+ $this->assertEquals(25.0, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent);
+ $this->assertEquals(1, $testedRow->NumberOfUnits);
+ $this->assertEquals("st", $testedRow->Unit);
+ }
+
+ // TODO write tests for the three different ways we can specify an invoice fee here (ex+vat, inc+vat, ex+inc?)
+
+ // FixedDiscountRow specified using only amountExVat
+ public function test_FixedDiscount_specified_using_amountExVat_in_order_with_single_vat_rate()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ // cover all three ways to specify items here: iv+vp, ev+vp, iv+ev
+ ->setAmountExVat(4.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(5.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f1e")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountExVat(1.0)
+ ->setUnit("st")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+ $testedRow = $resultRows[3];
+
+ $this->assertEquals("f1e", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc", $testedRow->Description);
+ $this->assertEquals(-1.0, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent);
+ $this->assertEquals(1, $testedRow->NumberOfUnits);
+ $this->assertEquals("st", $testedRow->Unit);
+ }
+
+ // FixedDiscountRow specified using only amountExVat => split discount excl. vat over the diffrent tax rates present in order
+ public function test_FixedDiscount_specified_using_amountExVat_in_order_with_multiple_vat_rates()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @25% = 125")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @6% = 106")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100e")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountExVat(100.00)
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+ // 100*200/300 = 66.66 ex. 25% vat => discount 83.33 (incl. 16.67 vat @25%)
+ $testedRow = $resultRows[2];
+ $this->assertEquals("f100e", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
+ $this->assertEquals(-(200 / 300) * 100, $testedRow->PricePerUnit); //-66.67
+ //$this->assertEquals(-66.67, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+
+ // 100*100/300 = 33.33 ex. 6% vat => discount 35.33 (incl 2.00 vat @6%)
+ $testedRow = $resultRows[3];
+ $this->assertEquals("f100e", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
+ $this->assertEquals(-(100 / 300) * 100, $testedRow->PricePerUnit); //-33.33
+ //$this->assertEquals(-33.33, $testedRow->PricePerUnit);
+ $this->assertEquals(6, $testedRow->VatPercent);
+
+ // order total should be 166.66 (incl. 33.33 vat @25%) + 70.67 (incl. 4.00 vat @6%) = 237.33 (incl 37.33 vat @18.665%)
+ $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits;
+ $this->assertEquals(237.33333333333, $total);
+ }
+
+ // FixedDiscountRow specified using only amountIncVat => split discount incl. vat over the diffrent tax rates present in order
+ public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_single_vat_rate()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(5.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f1i")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountIncVat(1.0)
+ ->setUnit("kr")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+ $testedRow = $resultRows[3];
+ $this->assertEquals("f1i", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc", $testedRow->Description);
+ $this->assertEquals(-0.8, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent);
+ $this->assertEquals(1, $testedRow->NumberOfUnits);
+ $this->assertEquals("kr", $testedRow->Unit);
+ }
+
+ // FixedDiscountRow specified using only amountIncVat => split discount incl. vat over the diffrent tax rates present in order
+ // if we have two orders items with different vat rate, we need to create
+ // two discount order rows, one for each vat rate
+ public function test_FixedDiscount_specified_using_amountIncVat_in_order_with_multiple_vat_rates()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100i")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountIncVat(100)
+ ->setUnit("st")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+
+ // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
+ $testedRow = $resultRows[2];
+ $this->assertEquals("f100i", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
+ $this->assertEquals(-56.179775280899, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+
+ // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
+ $testedRow = $resultRows[3];
+ $this->assertEquals("f100i", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
+ $this->assertEquals(-28.089887640449, $testedRow->PricePerUnit);
+ $this->assertEquals(6, $testedRow->VatPercent);
+
+ // order total should be 250 + 106 - 100 = 256 (incl. 40.27 vat)
+ $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits;
+ $this->assertEquals(256.00, $total);
+ }
+
+ // FixedDiscount should only look at vat rates from order item rows, not shipping or invoice fees
+ public function test_FixedDiscount_specified_using_amountIncVat_are_calculated_from_order_item_rows_only()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(50.00)
+ ->setVatPercent(6)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(23.20)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100i")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountIncVat(100)
+ ->setUnit("kr")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+
+ // 100*250/250 = 100 discount incl. 25% vat => 20 discount vat as amount
+ $testedRow = $resultRows[3];
+ $this->assertEquals("f100i", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc", $testedRow->Description);
+ $this->assertEquals(-80.00, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+
+ // order total should be 250-100+53+29 = 232 kr
+ $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits;
+ $this->assertEquals(232.00, $total);
+
+ }
+
+ // FixedDiscount should only look at vat rates from order item rows, not shipping or invoice fees
+ public function test_FixedDiscount_specified_using_amountExVat_are_calculated_from_order_item_rows_only()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(50.00)
+ ->setVatPercent(6)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(23.20)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100e")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountExVat(100)
+ ->setUnit("kr")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+
+ // 100*200/200 = 100 discount excl.% vat => 20 discount vat as amount
+ $testedRow = $resultRows[3];
+ $this->assertEquals("f100e", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc", $testedRow->Description);
+ $this->assertEquals(-100.00, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+
+ // order total should be 250-125+53+29 = 207 kr
+ $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits;
+ $this->assertEquals(207.00, $total);
+ }
+
+ public function test_FixedDiscount_specified_using_amountExVat_are_calculated_from_order_item_rows_only_multiple_vat_rates()
+ {
+ // FixedDiscountRow specified using only amountExVat => split discount excl. vat over the diffrent tax rates present in order
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @25% = 125")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setName("product with price 100 @6% = 106")
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setName("shipping with price 50 @6% = 106")
+ ->setAmountExVat(50.00)
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100e")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountExVat(100.00)
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+
+ // 100*200/300 = 66.66 ex. 25% vat => 83.33 vat as amount
+ $testedRow = $resultRows[3];
+ $this->assertEquals("f100e", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
+ $this->assertEquals(-66.666666666667, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+
+ // 100*100/300 = 33.33 ex. 6% vat => 35.33 vat as amount
+ $testedRow = $resultRows[4];
+ $this->assertEquals("f100e", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
+ $this->assertEquals(-(100 / 300) * 100, $testedRow->PricePerUnit);
+ $this->assertEquals(6, $testedRow->VatPercent);
+
+ // order total should be 166.67+70.67 +53 = 237.34 +53
+ $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[4]->PricePerUnit, $resultRows[4]->VatPercent) * $resultRows[4]->NumberOfUnits;
+ $this->assertEquals(237.33333333333 + 53, $total);
+ }
+
+ public function test_FixedDiscount_specified_using_amountIncVat_are_calculated_from_order_item_rows_only_multiple_vat_rates()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setName("shipping with price 50 @6% = 106")
+ ->setAmountExVat(50.00)
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("f100i")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setAmountIncVat(100)
+ ->setUnit("st")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+
+ // 100*250/356 = 70.22 incl. 25% vat => 14.04 vat as amount
+ $testedRow = $resultRows[3];
+ $this->assertEquals("f100i", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
+ $this->assertEquals(-56.179775280899, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+
+ // 100*106/356 = 29.78 incl. 6% vat => 1.69 vat as amount
+ $testedRow = $resultRows[4];
+ $this->assertEquals("f100i", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
+ $this->assertEquals(-28.089887640449, $testedRow->PricePerUnit);
+ $this->assertEquals(6, $testedRow->VatPercent);
+
+ // order total should be 250 + 106 - 100 +53= 256+53
+ $total = WebServiceRowFormatter::convertExVatToIncVat($resultRows[0]->PricePerUnit, $resultRows[0]->VatPercent) * $resultRows[0]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[1]->PricePerUnit, $resultRows[1]->VatPercent) * $resultRows[1]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[2]->PricePerUnit, $resultRows[2]->VatPercent) * $resultRows[2]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[3]->PricePerUnit, $resultRows[3]->VatPercent) * $resultRows[3]->NumberOfUnits +
+ WebServiceRowFormatter::convertExVatToIncVat($resultRows[4]->PricePerUnit, $resultRows[4]->VatPercent) * $resultRows[4]->NumberOfUnits;
+ $this->assertEquals(256.00 + 53, $total);
+ }
+
+
+ // amountIncVat and vatPercent => add as single row with specified vat rate only
+ public function test_FixedDiscount_specified_using_amountIncVat_and_vatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setDiscountId("42")
+ ->setName("->setAmountIncVat(111), ->vatPercent(25)")
+ ->setDescription("testFormatFixedDiscountRows_amountIncVatAndVatPercent_WithDifferentVatRatesPresent")
+ ->setAmountIncVat(111)
+ ->setVatPercent(25)
+ ->setUnit("st")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+
+ // 100 @25% vat = -80 excl. vat
+ $testedRow = $resultRows[2];
+ $this->assertEquals("42", $testedRow->ArticleNumber);
+ $this->assertEquals("->setAmountIncVat(111), ->vatPercent(25): testFormatFixedDiscountRows_amountIncVatAndVatPercent_WithDifferentVatRatesPresent", $testedRow->Description);
+ $this->assertEquals(-88.80, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent);
+ $this->assertEquals(1, $testedRow->NumberOfUnits);
+ $this->assertEquals("st", $testedRow->Unit);
+
+ $this->assertEquals(false, isset($resultRows[3])); // no more rows
+ }
+
+ // amountExVat and vatPercent => add as single row with specified vat rate only
+ public function test_FixedDiscount_specified_using_amountExVat_and_vatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setName("->setAmountExVat(100)")
+ ->setDescription("testFormatFixedDiscountRowsWithDifferentVatRatesPresent2 (25%)")
+ ->setAmountExVat(66.67)
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setName("->setAmountExVat(100)")
+ ->setDescription("testFormatFixedDiscountRowsWithDifferentVatRatesPresent2 (6%)")
+ ->setAmountExVat(33.33)
+ ->setVatPercent(6)
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+
+ $testedRow = $resultRows[2];
+ $this->assertEquals("->setAmountExVat(100): testFormatFixedDiscountRowsWithDifferentVatRatesPresent2 (25%)", $testedRow->Description);
+ $this->assertEquals(-66.67, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+
+ $testedRow = $resultRows[3];
+ $this->assertEquals("->setAmountExVat(100): testFormatFixedDiscountRowsWithDifferentVatRatesPresent2 (6%)", $testedRow->Description);
+ $this->assertEquals(-33.33, $testedRow->PricePerUnit);
+ $this->assertEquals(6, $testedRow->VatPercent);
+
+ $this->assertEquals(false, isset($resultRows[4])); // no more rows
+ }
+
+ // specifying discounts with incVat+exVat is not supported -- public function test_FixedDiscount_specified_using_amountIncVat_and_amountExVat() {
+
+ public function test_RelativeDiscount_in_order_with_single_vat_rate()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(5.0)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(4.0)
+ ->setAmountIncVat(5.0)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("r10")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setDiscountPercent(10)
+ ->setUnit("kr")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+ $testedRow = $resultRows[3];
+
+ $this->assertEquals("r10", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc", $testedRow->Description);
+ $this->assertEquals(-1.2, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as DiscountPercent in our Svea\WebPay\WebPayItem...
+ $this->assertEquals(1, $testedRow->NumberOfUnits);
+ $this->assertEquals("kr", $testedRow->Unit);
+ }
+
+ public function test_RelativeDiscount_in_order_with_multiple_vat_rates()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(12)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("r20")
+ ->setName("couponName")
+ ->setDescription("couponDesc")
+ ->setDiscountPercent(25)
+ ->setUnit("kr")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+
+ $testedRow = $resultRows[3];
+ $this->assertEquals("r20", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (25%)", $testedRow->Description);
+ $this->assertEquals(-25.00, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as DiscountPercent in our Svea\WebPay\WebPayItem...
+ $this->assertEquals(1, $testedRow->NumberOfUnits);
+ $this->assertEquals("kr", $testedRow->Unit);
+
+ $testedRow = $resultRows[4];
+ $this->assertEquals("r20", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (12%)", $testedRow->Description);
+ $this->assertEquals(-25.00, $testedRow->PricePerUnit);
+ $this->assertEquals(12, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as DiscountPercent in our Svea\WebPay\WebPayItem...
+ $this->assertEquals(1, $testedRow->NumberOfUnits);
+ $this->assertEquals("kr", $testedRow->Unit);
+
+ $testedRow = $resultRows[5];
+ $this->assertEquals("r20", $testedRow->ArticleNumber);
+ $this->assertEquals("couponName: couponDesc (6%)", $testedRow->Description);
+ $this->assertEquals(-25.00, $testedRow->PricePerUnit);
+ $this->assertEquals(6, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as DiscountPercent in our Svea\WebPay\WebPayItem...
+ $this->assertEquals(1, $testedRow->NumberOfUnits);
+ $this->assertEquals("kr", $testedRow->Unit);
+ }
+
+ // if we have two orders items with different vat rate, we need to create
+ // two discount order rows, one for each vat rate
+ public function testFormatRelativeDiscountRows_WithDifferentVatRatesPresent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(2)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("42")
+ ->setName("->setDiscountPercent(10)")
+ ->setDescription("testFormatRelativeDiscountRows_WithDifferentVatRatesPresent")
+ ->setDiscountPercent(10)
+ ->setUnit("st")
+ );
+
+ $formatter = new WebServiceRowFormatter($order);
+ $resultRows = $formatter->formatRows();
+
+ $testedRow = $resultRows[2];
+ $this->assertEquals("42", $testedRow->ArticleNumber);
+ $this->assertEquals("->setDiscountPercent(10): testFormatRelativeDiscountRows_WithDifferentVatRatesPresent (25%)", $testedRow->Description);
+ $this->assertEquals(-20.00, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as in our Svea\WebPay\WebPayItem...
+ $this->assertEquals(1, $testedRow->NumberOfUnits); // 1 "discount unit"
+ $this->assertEquals("st", $testedRow->Unit);
+
+ $testedRow = $resultRows[3];
+ $this->assertEquals("42", $testedRow->ArticleNumber);
+ $this->assertEquals("->setDiscountPercent(10): testFormatRelativeDiscountRows_WithDifferentVatRatesPresent (6%)", $testedRow->Description);
+ $this->assertEquals(-10.00, $testedRow->PricePerUnit);
+ $this->assertEquals(6, $testedRow->VatPercent);
+ $this->assertEquals(0, $testedRow->DiscountPercent); // not the same thing as DiscountPercent in our Svea\WebPay\WebPayItem...
+ $this->assertEquals(1, $testedRow->NumberOfUnits); // 1 "discount unit"
+ $this->assertEquals("st", $testedRow->Unit);
+ }
+
+ /**
+ * 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 Svea\WebPay\Test\IntegrationTest\WebService\Payment\InvoicePaymentIntegrationTest, Jira issue WEB-193
+ */
+ public function test_regressiontest_for_float_to_int_conversion_errorS()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config);
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(0.00)
+ ->setVatPercent(0)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(23.20)
+ ->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.20, $testedRow->PricePerUnit);
+ $this->assertEquals(25, $testedRow->VatPercent);
+ }
}
diff --git a/test/UnitTest/WebService/Payment/AccountCreditPaymentTest.php b/test/UnitTest/WebService/Payment/AccountCreditPaymentTest.php
index 10a002f5..f95dd064 100644
--- a/test/UnitTest/WebService/Payment/AccountCreditPaymentTest.php
+++ b/test/UnitTest/WebService/Payment/AccountCreditPaymentTest.php
@@ -16,1863 +16,1863 @@ class AccountCreditPaymentTest extends \PHPUnit\Framework\TestCase
- public function __setUp()
- {
-
- }
-
-
- public function getCustomerRow()
- {
- return WebPayItem::individualCustomer()
- ->setNationalIdNumber("194605092222")
- ->setBirthDate(1946, 05, 9)
- ->setName("Tess T", "Persson")
- ->setStreetAddress("Testgatan", 1)
- ->setCoAddress("c/o Eriksson, Erik")
- ->setLocality("Stan")
- ->setEmail('testt@svea.com')->
- setZipCode("99999");
- }
-
- public function testInvoiceRequestObjectForCustomerIdentityIndividualFromSE()
- {
- $config = ConfigurationService::getDefaultConfig();
-
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails($this->getCustomerRow())
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate(date('c'))
- ->useAccountCredit("111111")
- ->prepareRequest();
-
- $this->assertEquals(194605092222, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
- $this->assertEquals("SE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
- $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
- }
-
- public function testInvoiceRequestOnProductVatCero()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow($this->getOrderRow())
- ->addCustomerDetails($this->getCustomerRow())
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate(date('c'))
- ->useAccountCredit("111111")
- ->prepareRequest();
-
- $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit); //Check all in identity
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent); //Check all in identity
- }
-
- public function getOrderRow()
- {
- return WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountExVat(100.00)
- ->setDescription("Specification")
- ->setName('Prod')
- ->setUnit("st")
- ->setVatPercent(0)
- ->setDiscountPercent(0);
- }
-
- public function testSetAuth()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails($this->getCustomerRow())
- ->setCountryCode("SE")
- ->setCurrency("SEK")
- ->setOrderDate(date('c'))
- ->useAccountCredit("111111")// return object
- ->prepareRequest();
-
- $this->assertEquals(58702, $request->request->Auth->ClientNumber); //Check all in identity
- $this->assertEquals("sverigetest", $request->request->Auth->Username); //Check all in identity
- $this->assertEquals("sverigetest", $request->request->Auth->Password); //Check all in identity
- }
-
- public function testInvoiceRequestObjectForCustomerIdentityIndividualFromNL()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setInitials("SB")
- ->setBirthDate(1923, 12, 12)
- ->setName("Tess", "Testson")
- ->setEmail("test@svea.com")
- ->setPhoneNumber(999999)
- ->setIpAddress("123.123.123")
- ->setStreetAddress("Gatan", 23)
- ->setCoAddress("c/o Eriksson")
- ->setZipCode(9999)
- ->setLocality("Stan")
- )
- ->setCountryCode("NL")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
- $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
- $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
- $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
- $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
- $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
- $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
- $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
- $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
- $this->assertEquals("NL", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
- $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
- $this->assertEquals("Tess", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->FirstName); //Check all in identity
- $this->assertEquals("Testson", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->LastName); //Check all in identity
- $this->assertEquals("SB", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->Initials); //Check all in identity
- $this->assertEquals(19231212, $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->BirthDate); //Check all in identity
- }
-
- public function testInvoiceRequestObjectForCustomerIdentityIndividualFromDE()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setBirthDate(1923, 12, 12)
- ->setName("Tess", "Testson")
- ->setEmail("test@svea.com")
- ->setPhoneNumber(999999)
- ->setIpAddress("123.123.123")
- ->setStreetAddress("Gatan", 23)
- ->setCoAddress("c/o Eriksson")
- ->setZipCode(9999)
- ->setLocality("Stan")
- )
- ->setCountryCode("DE")
- ->setOrderDate("2012-12-12")
- ->setCurrency("EUR")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
- $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
- $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
- $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
- $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
- $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
- $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
- $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
- $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
- $this->assertEquals("DE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
- $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
- $this->assertEquals("Tess", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->FirstName); //Check all in identity
- $this->assertEquals("Testson", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->LastName); //Check all in identity
- $this->assertEquals(19231212, $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->BirthDate); //Check all in identity
- }
-
- public function testInvoiceRequestObjectForCustomerIdentityCompanyFromNL()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setInitials("SB")
- ->setBirthDate(1923, 12, 12)
- ->setName("Tess", "Testson")
- ->setEmail("test@svea.com")
- ->setPhoneNumber(999999)
- ->setIpAddress("123.123.123")
- ->setStreetAddress("Gatan", 23)
- ->setCoAddress("c/o Eriksson")
- ->setZipCode(9999)
- ->setLocality("Stan")
- )
- ->setCountryCode("NL")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
- $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
- $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
- $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
- $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
- $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
- $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
- $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
- $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
- $this->assertEquals("NL", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
- $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
- }
-
- public function testInvoiceRequestObjectForCustomerIdentityCompanyFromSE()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber("vat234"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals("vat234", $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
- $this->assertEquals("SE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
- $this->assertEquals("Company", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
- }
-
- public function testInvoiceRequestObjectForSEorderOnOneProductRow()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->run($rowFactory->buildShippingFee())
- ->run($rowFactory->buildInvoiceFee())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- //First orderrow is a product
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals(100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
- //Second orderrow is shipment
- $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals(50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- //Third orderrow is invoicefee
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals(50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
- }
-
- public function testInvoiceRequestUsingAmountIncVatWithVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountIncVat(125.00)
- ->setDescription("Specification")
- ->setName('Product')
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId('33')
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountIncVat(62.50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setName('Svea fee')
- ->setDescription("Fee for invoice")
- ->setAmountIncVat(62.50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- //First orderrow is a product
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals(125.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
- //Second orderrow is shipment
- $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- //Third orderrow is invoicefee
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
- }
-
- public function testInvoiceRequestUsingAmountIncVatWithAmountExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountIncVat(125.00)
- ->setAmountExVat(100.00)
- ->setDescription("Specification")
- ->setName('Product')
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId('33')
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountIncVat(62.50)
- ->setAmountExVat(50.00)
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setName('Svea fee')
- ->setDescription("Fee for invoice")
- ->setAmountIncVat(62.50)
- ->setAmountExVat(50.00)
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- //First orderrow is a product
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals(125.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
- //Second orderrow is shipment
- $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- //Third orderrow is invoicefee
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
- }
-
- public function testInvoiceRequestObjectWithRelativeDiscountOnDifferentProductVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- //->setAmountIncVat(300.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(188.68)
- //->setAmountIncVat(200.00)
- ->setDescription("Bok")
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(20)
- ->setDescription("RelativeDiscount")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- //couponrows
-
- $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals('RelativeDiscount (25%)', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals(-48.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
-
- $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->ArticleNumber);
- $this->assertEquals('RelativeDiscount (6%)', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Description);
- $this->assertEquals(-37.736, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->NumberOfUnits);
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Unit);
- $this->assertEquals(6, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->DiscountPercent);
- }
-
- public function test_RelativeDiscountAsInt()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- //->setAmountIncVat(300.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(188.68)
- //->setAmountIncVat(200.00)
- ->setDescription("Bok")
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(21)
- ->setDescription("RelativeDiscount")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- //couponrows
- $this->assertEquals(-50.40, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(-39.6228, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
-
- }
-
- public function test_RelativeDiscountAsFloat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- //->setAmountIncVat(300.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(188.68)
- //->setAmountIncVat(200.00)
- ->setDescription("Bok")
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(20.5)//
- ->setDescription("RelativeDiscount")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- //couponrows
- $this->assertEquals(-49.20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(-38.6794, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- }
-
-
- public function testInvoiceWithFixedDiscountWithUneavenAmount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(101.50)
- ->setDescription('FixedDiscount')
- ->setDiscountId('1')
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
- //couponrow
- $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals('FixedDiscount', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals(-81.2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- }
-
- public function testInvoiceRequestObjectWithCreateOrderInformation()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->run($rowFactory->buildShippingFee())
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(194605092222)->setAddressSelector("ad33"))
- ->setCountryCode("SE")
- ->setClientOrderNumber("nr26")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
- /**
- * Test that all data is in the right place for SoapRequest
- */
- //First orderrow is a product
- $this->assertEquals("2012-12-12", $request->request->CreateOrderInformation->OrderDate);
- $this->assertEquals('AccountCredit', $request->request->CreateOrderInformation->OrderType);
- $this->assertEquals('nr26', $request->request->CreateOrderInformation->ClientOrderNumber); //check in identity
- $this->assertEquals('ad33', $request->request->CreateOrderInformation->AddressSelector); //check in identity
- }
-
- public function testInvoiceRequestObjectWithAuth()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->run($rowFactory->buildShippingFee())
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(194605092222)->setAddressSelector("ad33"))
- ->setCountryCode("SE")
- ->setClientOrderNumber("nr26")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals('sverigetest', $request->request->Auth->Username);
- $this->assertEquals('sverigetest', $request->request->Auth->Password);
- $this->assertEquals(58702, $request->request->Auth->ClientNumber);
- }
-
- /**
- * Tests for rounding**
- */
- public function testOrderSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testDiscountSetAsExVatWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()->setAmountExVat(8))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(8)
- ->setVatPercent(0))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testDiscountPercentAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testFeeSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testOrderRowPriceSetAsInkVatAndVatPercentSetAmountAsIncVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(100.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(100.00)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testDiscountSetAsIncVatWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(10)
- ->setVatPercent(0))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
-
- public function testDiscountPercentAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testOrderSetAsIncVatAndExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testOrderAndFeesSetAsIncVatAndExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1230.9876)
- ->setAmountExVat(990.99)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testOrderAndFixedDiscountSetAsIncVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1230.9876)
- ->setAmountExVat(990.99)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(12.39876)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals(1230.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testOrderSetAsIncVatAndExVatAndRelativeDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testOrderSetWithMixedMethods1()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testOrderSetWithMixedMethods2()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setName('incvat')
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setName('exvat')
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setName('exvat')
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testOrderSetWithMixedOrderRowAndFee()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testOrderSetWithMixedOrderRowAndFeeAndVatPercentSet()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testOrderAndFixedDiscountSetWithMixedVat2()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(12.39876)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testOrderSetAsMixedVatAndRelativeDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(5)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useAccountCredit('111111')
- ->prepareRequest();
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
-
- /// relative discount examples:
- // single order rows vat rate
- public function test_relativeDiscount_amount()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(25)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(25)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::relativeDiscount()
- ->setDiscountPercent(10.0)
- ->setDiscountId("TenPercentOff")
- ->setName("relativeDiscount")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: 10% off orderRow rows: 2x 80.00 @25% => -16.00 @25% discount
- $this->assertEquals(-16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- }
-
- // relative discount on multiple order row defined exvat/vatpercent vat rates
- public function test_relativeDiscount_amount_multiple_vat_rates_defined_exvat_creates_discount_rows_using_exvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::relativeDiscount()
- ->setDiscountPercent(10.0)
- ->setDiscountId("TenPercentOff")
- ->setName("relativeDiscount")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: 10% off orderRow rows: 1x60.00 @20%, 1x30@10% => split proportionally across order row (only) vat rate: -6.0 @20%, -3.0 @10%
- $this->assertEquals(-6.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
-
- }
-
- // relative discount -- created discount rows should use incvat + vatpercent
- // relative discount on multiple order row defined exvat/vatpercent vat rates
- public function test_relativeDiscount_amount_multiple_vat_rates_defined_incvat_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- ->setName("incvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::relativeDiscount()
- ->setDiscountPercent(10.0)
- ->setDiscountId("TenPercentOff")
- ->setName("relativeDiscount")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10% off orderRow rows: 1x60.00 @20%, 1x30@10% => split proportionally across order row (only) vat rate: -6.0 @20%, -3.0 @10%
- $this->assertEquals(-7.20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.30, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- }
-
-
-
- /// fixed discount examples:
- // single order rows vat rate
- public function test_fixedDiscount_amount_with_set_exvat_vat_rate()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- }
-
- public function test_fixedDiscount_amount_with_set_incvat_vat_rate()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(11.0)
- ->setVatPercent(10)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- }
-
- public function test_fixedDiscount_amount_with_calculated_vat_rate_exvat()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setDiscountId("TenCrownsOff")
- ->setName("fixedDiscount: 10 off exvat")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: fixedDiscount: 10 off exvat, order row amount are 66% at 20% vat, 33% at 10% vat => 6.67 @20% and 3.33 @10%
- $this->assertEquals(-6.6666666666667, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(-3.3333333333333, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- }
-
- public function test_fixedDiscount_amount_with_calculated_vat_rate_incvat()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(10.0)
- ->setDiscountId("TenCrownsOff")
- ->setName("fixedDiscount: 10 off incvat")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $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_fixedDiscount_amount_with_set_incvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails($this->getCustomerRow())
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(11.0)
- ->setVatPercent(10)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- }
-
- public function test_fixedDiscount_amount_with_calculated_vat_rate_exvat_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setDiscountId("TenCrownsOff")
- ->setName("fixedDiscount: 10 off exvat")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: fixedDiscount: 10 off exvat, order row amount are 66% at 20% vat, 33% at 10% vat => 6.67 @20% and 3.33 @10%
- $this->assertEquals(-6.6666666666667, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(-3.3333333333333, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- }
-
- public function test_fixedDiscount_amount_with_calculated_vat_rate_incvat_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(10.0)
- ->setDiscountId("TenCrownsOff")
- ->setName("fixedDiscount: 10 off incvat")
- );
- $request = $order->useAccountCredit('111111')->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $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);
- }
-
- // See file Svea\WebPay\Test\UnitTest\WebService\Payment\FixedDiscountRowsTest for specification of FixedDiscount row behaviour.
+ public function __setUp()
+ {
+
+ }
+
+
+ public function getCustomerRow()
+ {
+ return WebPayItem::individualCustomer()
+ ->setNationalIdNumber("194605092222")
+ ->setBirthDate(1946, 05, 9)
+ ->setName("Tess T", "Persson")
+ ->setStreetAddress("Testgatan", 1)
+ ->setCoAddress("c/o Eriksson, Erik")
+ ->setLocality("Stan")
+ ->setEmail('testt@svea.com')->
+ setZipCode("99999");
+ }
+
+ public function testInvoiceRequestObjectForCustomerIdentityIndividualFromSE()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails($this->getCustomerRow())
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate(date('c'))
+ ->useAccountCredit("111111")
+ ->prepareRequest();
+
+ $this->assertEquals(194605092222, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
+ $this->assertEquals("SE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
+ $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
+ }
+
+ public function testInvoiceRequestOnProductVatCero()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow($this->getOrderRow())
+ ->addCustomerDetails($this->getCustomerRow())
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate(date('c'))
+ ->useAccountCredit("111111")
+ ->prepareRequest();
+
+ $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit); //Check all in identity
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent); //Check all in identity
+ }
+
+ public function getOrderRow()
+ {
+ return WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountExVat(100.00)
+ ->setDescription("Specification")
+ ->setName('Prod')
+ ->setUnit("st")
+ ->setVatPercent(0)
+ ->setDiscountPercent(0);
+ }
+
+ public function testSetAuth()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails($this->getCustomerRow())
+ ->setCountryCode("SE")
+ ->setCurrency("SEK")
+ ->setOrderDate(date('c'))
+ ->useAccountCredit("111111")// return object
+ ->prepareRequest();
+
+ $this->assertEquals(58702, $request->request->Auth->ClientNumber); //Check all in identity
+ $this->assertEquals("sverigetest", $request->request->Auth->Username); //Check all in identity
+ $this->assertEquals("sverigetest", $request->request->Auth->Password); //Check all in identity
+ }
+
+ public function testInvoiceRequestObjectForCustomerIdentityIndividualFromNL()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setInitials("SB")
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Tess", "Testson")
+ ->setEmail("test@svea.com")
+ ->setPhoneNumber(999999)
+ ->setIpAddress("123.123.123")
+ ->setStreetAddress("Gatan", 23)
+ ->setCoAddress("c/o Eriksson")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ )
+ ->setCountryCode("NL")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
+ $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
+ $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
+ $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
+ $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
+ $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
+ $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
+ $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
+ $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
+ $this->assertEquals("NL", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
+ $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
+ $this->assertEquals("Tess", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->FirstName); //Check all in identity
+ $this->assertEquals("Testson", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->LastName); //Check all in identity
+ $this->assertEquals("SB", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->Initials); //Check all in identity
+ $this->assertEquals(19231212, $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->BirthDate); //Check all in identity
+ }
+
+ public function testInvoiceRequestObjectForCustomerIdentityIndividualFromDE()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Tess", "Testson")
+ ->setEmail("test@svea.com")
+ ->setPhoneNumber(999999)
+ ->setIpAddress("123.123.123")
+ ->setStreetAddress("Gatan", 23)
+ ->setCoAddress("c/o Eriksson")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ )
+ ->setCountryCode("DE")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("EUR")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
+ $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
+ $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
+ $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
+ $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
+ $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
+ $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
+ $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
+ $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
+ $this->assertEquals("DE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
+ $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
+ $this->assertEquals("Tess", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->FirstName); //Check all in identity
+ $this->assertEquals("Testson", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->LastName); //Check all in identity
+ $this->assertEquals(19231212, $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->BirthDate); //Check all in identity
+ }
+
+ public function testInvoiceRequestObjectForCustomerIdentityCompanyFromNL()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setInitials("SB")
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Tess", "Testson")
+ ->setEmail("test@svea.com")
+ ->setPhoneNumber(999999)
+ ->setIpAddress("123.123.123")
+ ->setStreetAddress("Gatan", 23)
+ ->setCoAddress("c/o Eriksson")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ )
+ ->setCountryCode("NL")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
+ $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
+ $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
+ $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
+ $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
+ $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
+ $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
+ $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
+ $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
+ $this->assertEquals("NL", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
+ $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
+ }
+
+ public function testInvoiceRequestObjectForCustomerIdentityCompanyFromSE()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber("vat234"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals("vat234", $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
+ $this->assertEquals("SE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
+ $this->assertEquals("Company", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
+ }
+
+ public function testInvoiceRequestObjectForSEorderOnOneProductRow()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->run($rowFactory->buildShippingFee())
+ ->run($rowFactory->buildInvoiceFee())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ //First orderrow is a product
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals(100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
+ //Second orderrow is shipment
+ $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals(50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ //Third orderrow is invoicefee
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals(50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
+ }
+
+ public function testInvoiceRequestUsingAmountIncVatWithVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountIncVat(125.00)
+ ->setDescription("Specification")
+ ->setName('Product')
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId('33')
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountIncVat(62.50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setName('Svea fee')
+ ->setDescription("Fee for invoice")
+ ->setAmountIncVat(62.50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ //First orderrow is a product
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals(125.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
+ //Second orderrow is shipment
+ $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ //Third orderrow is invoicefee
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
+ }
+
+ public function testInvoiceRequestUsingAmountIncVatWithAmountExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountIncVat(125.00)
+ ->setAmountExVat(100.00)
+ ->setDescription("Specification")
+ ->setName('Product')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId('33')
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountIncVat(62.50)
+ ->setAmountExVat(50.00)
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setName('Svea fee')
+ ->setDescription("Fee for invoice")
+ ->setAmountIncVat(62.50)
+ ->setAmountExVat(50.00)
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ //First orderrow is a product
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals(125.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
+ //Second orderrow is shipment
+ $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ //Third orderrow is invoicefee
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
+ }
+
+ public function testInvoiceRequestObjectWithRelativeDiscountOnDifferentProductVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ //->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(188.68)
+ //->setAmountIncVat(200.00)
+ ->setDescription("Bok")
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(20)
+ ->setDescription("RelativeDiscount")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ //couponrows
+
+ $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals('RelativeDiscount (25%)', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals(-48.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
+
+ $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->ArticleNumber);
+ $this->assertEquals('RelativeDiscount (6%)', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Description);
+ $this->assertEquals(-37.736, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->NumberOfUnits);
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Unit);
+ $this->assertEquals(6, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->DiscountPercent);
+ }
+
+ public function test_RelativeDiscountAsInt()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ //->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(188.68)
+ //->setAmountIncVat(200.00)
+ ->setDescription("Bok")
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(21)
+ ->setDescription("RelativeDiscount")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ //couponrows
+ $this->assertEquals(-50.40, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(-39.6228, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+
+ }
+
+ public function test_RelativeDiscountAsFloat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ //->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(188.68)
+ //->setAmountIncVat(200.00)
+ ->setDescription("Bok")
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(20.5)//
+ ->setDescription("RelativeDiscount")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ //couponrows
+ $this->assertEquals(-49.20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(-38.6794, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ }
+
+
+ public function testInvoiceWithFixedDiscountWithUneavenAmount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(101.50)
+ ->setDescription('FixedDiscount')
+ ->setDiscountId('1')
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ //couponrow
+ $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals('FixedDiscount', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals(-81.2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ }
+
+ public function testInvoiceRequestObjectWithCreateOrderInformation()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->run($rowFactory->buildShippingFee())
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(194605092222)->setAddressSelector("ad33"))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("nr26")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ /**
+ * Test that all data is in the right place for SoapRequest
+ */
+ //First orderrow is a product
+ $this->assertEquals("2012-12-12", $request->request->CreateOrderInformation->OrderDate);
+ $this->assertEquals('AccountCredit', $request->request->CreateOrderInformation->OrderType);
+ $this->assertEquals('nr26', $request->request->CreateOrderInformation->ClientOrderNumber); //check in identity
+ $this->assertEquals('ad33', $request->request->CreateOrderInformation->AddressSelector); //check in identity
+ }
+
+ public function testInvoiceRequestObjectWithAuth()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->run($rowFactory->buildShippingFee())
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(194605092222)->setAddressSelector("ad33"))
+ ->setCountryCode("SE")
+ ->setClientOrderNumber("nr26")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals('sverigetest', $request->request->Auth->Username);
+ $this->assertEquals('sverigetest', $request->request->Auth->Password);
+ $this->assertEquals(58702, $request->request->Auth->ClientNumber);
+ }
+
+ /**
+ * Tests for rounding**
+ */
+ public function testOrderSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testDiscountSetAsExVatWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()->setAmountExVat(8))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(8)
+ ->setVatPercent(0))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testDiscountPercentAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testFeeSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testOrderRowPriceSetAsInkVatAndVatPercentSetAmountAsIncVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testDiscountSetAsIncVatWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10)
+ ->setVatPercent(0))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+
+ public function testDiscountPercentAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetAsIncVatAndExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testOrderAndFeesSetAsIncVatAndExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1230.9876)
+ ->setAmountExVat(990.99)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testOrderAndFixedDiscountSetAsIncVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1230.9876)
+ ->setAmountExVat(990.99)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(12.39876)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(1230.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetAsIncVatAndExVatAndRelativeDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetWithMixedMethods1()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetWithMixedMethods2()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setName('incvat')
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setName('exvat')
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setName('exvat')
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetWithMixedOrderRowAndFee()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetWithMixedOrderRowAndFeeAndVatPercentSet()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testOrderAndFixedDiscountSetWithMixedVat2()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(12.39876)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetAsMixedVatAndRelativeDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(5)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useAccountCredit('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+
+ /// relative discount examples:
+ // single order rows vat rate
+ public function test_relativeDiscount_amount()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(25)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(25)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10.0)
+ ->setDiscountId("TenPercentOff")
+ ->setName("relativeDiscount")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: 10% off orderRow rows: 2x 80.00 @25% => -16.00 @25% discount
+ $this->assertEquals(-16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ }
+
+ // relative discount on multiple order row defined exvat/vatpercent vat rates
+ public function test_relativeDiscount_amount_multiple_vat_rates_defined_exvat_creates_discount_rows_using_exvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10.0)
+ ->setDiscountId("TenPercentOff")
+ ->setName("relativeDiscount")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: 10% off orderRow rows: 1x60.00 @20%, 1x30@10% => split proportionally across order row (only) vat rate: -6.0 @20%, -3.0 @10%
+ $this->assertEquals(-6.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+
+ }
+
+ // relative discount -- created discount rows should use incvat + vatpercent
+ // relative discount on multiple order row defined exvat/vatpercent vat rates
+ public function test_relativeDiscount_amount_multiple_vat_rates_defined_incvat_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ ->setName("incvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10.0)
+ ->setDiscountId("TenPercentOff")
+ ->setName("relativeDiscount")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10% off orderRow rows: 1x60.00 @20%, 1x30@10% => split proportionally across order row (only) vat rate: -6.0 @20%, -3.0 @10%
+ $this->assertEquals(-7.20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.30, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ }
+
+
+
+ /// fixed discount examples:
+ // single order rows vat rate
+ public function test_fixedDiscount_amount_with_set_exvat_vat_rate()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ }
+
+ public function test_fixedDiscount_amount_with_set_incvat_vat_rate()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(11.0)
+ ->setVatPercent(10)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ }
+
+ public function test_fixedDiscount_amount_with_calculated_vat_rate_exvat()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setDiscountId("TenCrownsOff")
+ ->setName("fixedDiscount: 10 off exvat")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: fixedDiscount: 10 off exvat, order row amount are 66% at 20% vat, 33% at 10% vat => 6.67 @20% and 3.33 @10%
+ $this->assertEquals(-6.6666666666667, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(-3.3333333333333, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ }
+
+ public function test_fixedDiscount_amount_with_calculated_vat_rate_incvat()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10.0)
+ ->setDiscountId("TenCrownsOff")
+ ->setName("fixedDiscount: 10 off incvat")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $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_fixedDiscount_amount_with_set_incvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails($this->getCustomerRow())
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(11.0)
+ ->setVatPercent(10)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ }
+
+ public function test_fixedDiscount_amount_with_calculated_vat_rate_exvat_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setDiscountId("TenCrownsOff")
+ ->setName("fixedDiscount: 10 off exvat")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: fixedDiscount: 10 off exvat, order row amount are 66% at 20% vat, 33% at 10% vat => 6.67 @20% and 3.33 @10%
+ $this->assertEquals(-6.6666666666667, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(-3.3333333333333, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ }
+
+ public function test_fixedDiscount_amount_with_calculated_vat_rate_incvat_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10.0)
+ ->setDiscountId("TenCrownsOff")
+ ->setName("fixedDiscount: 10 off incvat")
+ );
+ $request = $order->useAccountCredit('111111')->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $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);
+ }
+
+ // See file Svea\WebPay\Test\UnitTest\WebService\Payment\FixedDiscountRowsTest for specification of FixedDiscount row behaviour.
}
\ No newline at end of file
diff --git a/test/UnitTest/WebService/Payment/CreateInvoiceOrderUnitTest.php b/test/UnitTest/WebService/Payment/CreateInvoiceOrderUnitTest.php
index 294c3c5e..82c10c5f 100644
--- a/test/UnitTest/WebService/Payment/CreateInvoiceOrderUnitTest.php
+++ b/test/UnitTest/WebService/Payment/CreateInvoiceOrderUnitTest.php
@@ -15,932 +15,932 @@
*/
class CreateInvoiceOrderUnitTest extends \PHPUnit\Framework\TestCase
{
- var $order;
- var $exvatRow;
- var $exvatRow2;
- var $exvatInvoiceFee;
- var $exvatShippingFee;
- var $incvatRow;
- var $incvatRow2;
- var $incvatInvoiceFee;
- var $incvatShippingFee;
-
- public function setUp()
- { // run before each test, in effect resetting the default order
-
- $this->order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setOrderDate(date('c'));
-
- $this->exvatRow = WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setName("exvatRow");
- $this->exvatRow2 = WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setName("exvatRow2");
-
- $this->exvatInvoiceFee = WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(25)
- ->setName("exvatInvoiceFee");
-
- $this->exvatShippingFee = WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(25)
- ->setName("exvatShippingFee");
- $this->incvatRow = WebPayItem::orderRow()
- ->setAmountIncvat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setName("incvatRow");
- $this->incvatRow2 = WebPayItem::orderRow()
- ->setAmountIncvat(100.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setName("incvatRow2");
-
- $this->incvatInvoiceFee = WebPayItem::invoiceFee()
- ->setAmountIncvat(10.00)
- ->setVatPercent(25)
- ->setName("incvatInvoiceFee");
-
- $this->incvatShippingFee = WebPayItem::shippingFee()
- ->setAmountIncvat(20.00)
- ->setVatPercent(25)
- ->setName("incvatShippingFee");
- }
-
- /// tests preparing order rows price specification
- // invoice request
- public function test_orderRows_and_Fees_specified_exvat_and_vat_using_useInvoicePayment_are_prepared_as_exvat_and_vat()
- {
- $order = $this->order;
-
- $order->addOrderRow($this->exvatRow);
- $order->addOrderRow($this->exvatRow2);
- $order->addFee($this->exvatInvoiceFee);
- $order->addFee($this->exvatShippingFee);
-
- // all order rows
- // all shipping fee rows
- // all invoice fee rows
- $request = $order->useInvoicePayment()->prepareRequest();
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
-
-
- }
-
- public function test_orderRows_and_Fees_specified_incvat_and_vat_using_useInvoicePayment_are_prepared_as_incvat_and_vat()
- {
- $order = $this->order;
-
- $order->addOrderRow($this->incvatRow);
- $order->addOrderRow($this->incvatRow2);
- $order->addFee($this->incvatInvoiceFee);
- $order->addFee($this->incvatShippingFee);
-
- // all order rows
- // all shipping fee rows
- // all invoice fee rows
- $request = $order->useInvoicePayment()->prepareRequest();
- $this->assertEquals(100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- $this->assertEquals(20.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
-
- }
-
- //validation of same order row price/vat specification in same order
- public function test_that_createOrder_with_uniform_orderRow_and_Fee_price_specifications_does_not_throw_validation_error()
- {
- $order = $this->order;
-
- $order->addOrderRow($this->exvatRow);
- $order->addOrderRow($this->exvatRow);
- $order->addFee($this->exvatInvoiceFee);
- $order->addFee($this->exvatShippingFee);
-
- try {
- $request = $order->useInvoicePayment()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- public function test_that_createOrder_with_mixed_orderRow_and_Fee_price_specifications_does_not_throw_validation_error()
- {
- $order = $this->order;
-
- $order->addOrderRow($this->exvatRow);
- $order->addOrderRow($this->incvatRow);
- $order->addFee($this->exvatInvoiceFee);
- $order->addFee($this->exvatShippingFee);
-
- try {
- $request = $order->useInvoicePayment()->prepareRequest();
- $this->assertTrue(true);
- } catch (Exception $e) {
- // fail on validation error
- $this->fail("Unexpected validation exception: " . $e->getMessage());
- }
- }
-
- //if no mixed specification types, default to sending order as incvat
- public function test_that_createOrder_request_is_sent_as_incvat_iff_no_exvat_specified_anywhere_in_order()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setAmountExVat(30.00)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(10.0)
- ->setDiscountId("TenCrownsOff")
- ->setName("fixedDiscount: 10 off incvat")
- );
-
- $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.8, $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: 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.7143ex @20% and 2.8571ex @10% => 6.86inc @20%, 3.14inc @10%
- // NOTE that php package does not round the request amounts to two decimals, as the java integration package, hence the call to bround below
- $this->assertEquals(-6.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.14, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // order total should be (72+33+17.6+8.8)-10 = 121.40, see integration test
- }
-
- //if mixed specification types, send order as exvat if at least one exvat + vat found
- public function test_that_createOrder_request_is_sent_as_exvat_if_exvat_specified_anywhere_in_order()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setAmountExVat(30.00)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- )
- ->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(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // 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);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // 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);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 off incvat, order row amount are 66% at 20% vat, 33% at 10% vat
- // 1.2*0.66x + 1.1*0.33x = 10 => x = 8.6580 => 5.7143ex @20% and 2.8571ex @10% =
- // NOTE that php package does not round the request amounts to two decimals, as the java integration package, hence the call to bround below
- $this->assertEquals(-5.71, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-2.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // order total should be (72+33+17.6+8.8)-10 = 121.40, see integration test
- }
-
-
- /// relative discount examples:
- public function test_exvat_only_order_with_relativeDiscount_with_single_vat_rates_order_sent_with_PriceIncludingVat_false()
- {
- $order = $this->order;
-
- $order->addOrderRow($this->exvatRow);
- $order->addOrderRow($this->exvatRow2);
- $order->addFee($this->exvatInvoiceFee);
- $order->addFee($this->exvatShippingFee);
-
- $order->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10.0)
- ->setDiscountId("TenPercentOff")
- ->setName("relativeDiscount")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: 10% off orderRow rows: 2x 80.00 @25% => -16.00 @25% discount
- $this->assertEquals(-16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- }
-
- public function test_exvat_only_order_with_relativeDiscount_with_multiple_vat_rates_order_sent_with_PriceIncludingVat_false()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- );
- $order->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- ->setDiscountId("TenPercentOff")
- ->setName("relativeDiscount")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: 10% off orderRow rows: 1x60.00 @20%, 1x30@10% => split proportionally across order row (only) vat rate: -6.0 @20%, -3.0 @10%
- $this->assertEquals(-6.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- }
-
- public function test_incvat_only_order_with_relativeDiscount_with_multiple_vat_rates_order_sent_with_PriceIncludingVat_true()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- );
- $order->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- ->setDiscountId("TenPercentOff")
- ->setName("relativeDiscount")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10% off orderRow rows: 60.0 @20%, 30.0 @10% => split across order row (only) vat rate: 6.0ex @20% = 7.2inc, 3.0ex @10% = 3.3inc
- $this->assertEquals(-7.20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.30, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- }
-
- // fixed discount examples:
- public function test_exvat_only_order_with_fixedDiscount_with_amount_specified_as_exvat_and_given_vat_rate_order_sent_with_PriceIncludingVat_false()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- );
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10.0)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- }
-
- public function test_incvat_only_order_with__fixedDiscount_with_amount_specified_as_exvat_and_given_vat_rate_order_sent_with_PriceIncludingVat_false()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- );
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10.0)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- }
-
- public function test_exvat_only_order_fixedDiscount_with_amount_specified_as_incvat_and_given_vat_rate_order_sent_with_PriceIncludingVat_false()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- );
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(11.0)
- ->setVatPercent(10.0)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 11i @10% => 11kr")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- }
-
- public function test_incvat_only_order_fixedDiscount_with_amount_specified_as_incvat_and_given_vat_rate_order_sent_with_PriceIncludingVat_true()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- );
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(11.0)
- ->setVatPercent(10.0)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 11i @10% => 11kr")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10 @10% => 11kr, expressed as incvat + vat in request
- $this->assertEquals(-11.00, $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);
- }
-
- public function test_exvat_only_order_with_fixedDiscount_amount_specified_as_exvat_and_calculated_vat_rate_order_sent_with_PriceIncludingVat_false()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(600.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(300.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(160.00)
- ->setVatPercent(10)
- );
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setDiscountId("TenCrownsOff")
- ->setName("fixedDiscount: 10 off exvat")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(600.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(300.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(160.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 off exvat, order row amount are 66% at 20% vat, 33% at 10% vat => 6.67 @20% and 3.33 @10%
- $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- }
-
- public function test_incvat_only_order_with_fixedDiscount_amount_specified_as_exvat_and_calculated_vat_rate_order_sent_with_PriceIncludingVat_false()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(720.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(330.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(88.00)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(172.00)
- ->setVatPercent(10)
- );
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setDiscountId("TenCrownsOffExVat")
- ->setName("fixedDiscount: 10 off exvat")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(600.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(300.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(156.36, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit, 2));
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 off exvat, order row amount are 66% @20% vat, 33% @10% vat => 6.67ex @20% = 8.00 inc and 3.33ex @10% = 3.67inc
- $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- }
-
- public function test_exvat_only_order_with_fixedDiscount_amount_specified_as_incvat_and_calculated_vat_rate_order_sent_with_PriceIncludingVat_false()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(600.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountExVat(300.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(160.00)
- ->setVatPercent(10)
- );
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(10.0)
- ->setDiscountId("TenCrownsOff")
- ->setName("fixedDiscount: 10 off incvat")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(600.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(300.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(160.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 off incvat, order row amount are 66% at 20% vat, 33% at 10% vat
- // 1.2*0.66x + 1.1*0.33x = 10 => x = 8.6580 => 5.7143 @20% and 2.8571 @10% = 10kr
- $this->assertEquals(-5.71, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-2.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- }
-
- public function test_incvat_only_order_with_fixedDiscount_amount_specified_as_incvat_and_calculated_vat_rate_order_sent_with_PriceIncludingVat_true()
- {
- $order = $this->order;
- $order
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(720.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(330.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(88.00)
- ->setVatPercent(10)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(172.00)
- ->setVatPercent(10)
- );
- $order->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(10.0)
- ->setDiscountId("TenCrownsOff")
- ->setName("fixedDiscount: 10 off incvat")
- );
-
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(720.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(330.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(88.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(172.00, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit, 2));
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 off incvat, order row amount are 66% at 20% vat, 33% at 10% vat
- // 1.2*0.66x + 1.1*0.33x = 10 => x = 8.6580 => 5.7143 @20% and 2.8571 @10% = 10kr
- $this->assertEquals(-6.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.14, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- }
-
- public function test_add_publickey_for_company_customer()
- {
- $config = ConfigurationService::getTestConfig();
- $order = WebPay::createOrder($config)
- ->addCustomerDetails(
- WebPayItem::companyCustomer()
- ->setPublicKey('ac0f2573b58ff523')//String ex. ac0f2573b58ff523
- );
- $this->assertEquals('ac0f2573b58ff523', $order->customerIdentity->publicKey);
-
-
- }
-
- public function test_add_publickey_for_private_customer()
- {
- $config = ConfigurationService::getTestConfig();
- $order = WebPay::createOrder($config)
- ->addCustomerDetails(
- WebPayItem::individualCustomer()
- ->setPublicKey('ac0f2573b58ff523')//String ex. ac0f2573b58ff523
- );
-
- $this->assertEquals('ac0f2573b58ff523', $order->customerIdentity->publicKey);
-
- }
-
- public function test_add_publickey_for_company_customer_full_request()
- {
- $config = ConfigurationService::getTestConfig();
- $order = WebPay::createOrder($config)
- ->addCustomerDetails(
- WebPayItem::companyCustomer()
- ->setCompanyName('mycomp')
- ->setNationalIdNumber('164701161111')
- ->setPublicKey('ac0f2573b58ff523')//String ac0f2573b58ff523
- )
- ->setCountryCode('SE')
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(125.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->setOrderDate(date('c'))
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals('ac0f2573b58ff523', $order->request->CreateOrderInformation->CustomerIdentity->PublicKey);
-
- }
-
- public function test_add_publickey_for_private_customer_full_request()
- {
- $config = ConfigurationService::getTestConfig();
- $order = WebPay::createOrder($config)
- ->addCustomerDetails(
- WebPayItem::companyCustomer()
- ->setCompanyName('mycomp')
- ->setNationalIdNumber('164701161111')
- ->setPublicKey('ac0f2573b58ff523')//String ac0f2573b58ff523
- )
- ->setCountryCode('SE')
- ->addOrderRow(WebPayItem::orderRow()
- ->setAmountIncVat(125.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- )
- ->setOrderDate(date('c'))
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals('ac0f2573b58ff523', $order->request->CreateOrderInformation->CustomerIdentity->PublicKey);
-
- }
+ var $order;
+ var $exvatRow;
+ var $exvatRow2;
+ var $exvatInvoiceFee;
+ var $exvatShippingFee;
+ var $incvatRow;
+ var $incvatRow2;
+ var $incvatInvoiceFee;
+ var $incvatShippingFee;
+
+ public function setUp()
+ { // run before each test, in effect resetting the default order
+
+ $this->order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setOrderDate(date('c'));
+
+ $this->exvatRow = WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setName("exvatRow");
+ $this->exvatRow2 = WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setName("exvatRow2");
+
+ $this->exvatInvoiceFee = WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(25)
+ ->setName("exvatInvoiceFee");
+
+ $this->exvatShippingFee = WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(25)
+ ->setName("exvatShippingFee");
+ $this->incvatRow = WebPayItem::orderRow()
+ ->setAmountIncvat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setName("incvatRow");
+ $this->incvatRow2 = WebPayItem::orderRow()
+ ->setAmountIncvat(100.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setName("incvatRow2");
+
+ $this->incvatInvoiceFee = WebPayItem::invoiceFee()
+ ->setAmountIncvat(10.00)
+ ->setVatPercent(25)
+ ->setName("incvatInvoiceFee");
+
+ $this->incvatShippingFee = WebPayItem::shippingFee()
+ ->setAmountIncvat(20.00)
+ ->setVatPercent(25)
+ ->setName("incvatShippingFee");
+ }
+
+ /// tests preparing order rows price specification
+ // invoice request
+ public function test_orderRows_and_Fees_specified_exvat_and_vat_using_useInvoicePayment_are_prepared_as_exvat_and_vat()
+ {
+ $order = $this->order;
+
+ $order->addOrderRow($this->exvatRow);
+ $order->addOrderRow($this->exvatRow2);
+ $order->addFee($this->exvatInvoiceFee);
+ $order->addFee($this->exvatShippingFee);
+
+ // all order rows
+ // all shipping fee rows
+ // all invoice fee rows
+ $request = $order->useInvoicePayment()->prepareRequest();
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+
+
+ }
+
+ public function test_orderRows_and_Fees_specified_incvat_and_vat_using_useInvoicePayment_are_prepared_as_incvat_and_vat()
+ {
+ $order = $this->order;
+
+ $order->addOrderRow($this->incvatRow);
+ $order->addOrderRow($this->incvatRow2);
+ $order->addFee($this->incvatInvoiceFee);
+ $order->addFee($this->incvatShippingFee);
+
+ // all order rows
+ // all shipping fee rows
+ // all invoice fee rows
+ $request = $order->useInvoicePayment()->prepareRequest();
+ $this->assertEquals(100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ $this->assertEquals(20.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+
+ }
+
+ //validation of same order row price/vat specification in same order
+ public function test_that_createOrder_with_uniform_orderRow_and_Fee_price_specifications_does_not_throw_validation_error()
+ {
+ $order = $this->order;
+
+ $order->addOrderRow($this->exvatRow);
+ $order->addOrderRow($this->exvatRow);
+ $order->addFee($this->exvatInvoiceFee);
+ $order->addFee($this->exvatShippingFee);
+
+ try {
+ $request = $order->useInvoicePayment()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ public function test_that_createOrder_with_mixed_orderRow_and_Fee_price_specifications_does_not_throw_validation_error()
+ {
+ $order = $this->order;
+
+ $order->addOrderRow($this->exvatRow);
+ $order->addOrderRow($this->incvatRow);
+ $order->addFee($this->exvatInvoiceFee);
+ $order->addFee($this->exvatShippingFee);
+
+ try {
+ $request = $order->useInvoicePayment()->prepareRequest();
+ $this->assertTrue(true);
+ } catch (Exception $e) {
+ // fail on validation error
+ $this->fail("Unexpected validation exception: " . $e->getMessage());
+ }
+ }
+
+ //if no mixed specification types, default to sending order as incvat
+ public function test_that_createOrder_request_is_sent_as_incvat_iff_no_exvat_specified_anywhere_in_order()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setAmountExVat(30.00)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10.0)
+ ->setDiscountId("TenCrownsOff")
+ ->setName("fixedDiscount: 10 off incvat")
+ );
+
+ $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.8, $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: 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.7143ex @20% and 2.8571ex @10% => 6.86inc @20%, 3.14inc @10%
+ // NOTE that php package does not round the request amounts to two decimals, as the java integration package, hence the call to bround below
+ $this->assertEquals(-6.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.14, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ // order total should be (72+33+17.6+8.8)-10 = 121.40, see integration test
+ }
+
+ //if mixed specification types, send order as exvat if at least one exvat + vat found
+ public function test_that_createOrder_request_is_sent_as_exvat_if_exvat_specified_anywhere_in_order()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setAmountExVat(30.00)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ )
+ ->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(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // 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);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // 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);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 off incvat, order row amount are 66% at 20% vat, 33% at 10% vat
+ // 1.2*0.66x + 1.1*0.33x = 10 => x = 8.6580 => 5.7143ex @20% and 2.8571ex @10% =
+ // NOTE that php package does not round the request amounts to two decimals, as the java integration package, hence the call to bround below
+ $this->assertEquals(-5.71, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-2.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ // order total should be (72+33+17.6+8.8)-10 = 121.40, see integration test
+ }
+
+
+ /// relative discount examples:
+ public function test_exvat_only_order_with_relativeDiscount_with_single_vat_rates_order_sent_with_PriceIncludingVat_false()
+ {
+ $order = $this->order;
+
+ $order->addOrderRow($this->exvatRow);
+ $order->addOrderRow($this->exvatRow2);
+ $order->addFee($this->exvatInvoiceFee);
+ $order->addFee($this->exvatShippingFee);
+
+ $order->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10.0)
+ ->setDiscountId("TenPercentOff")
+ ->setName("relativeDiscount")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: 10% off orderRow rows: 2x 80.00 @25% => -16.00 @25% discount
+ $this->assertEquals(-16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ }
+
+ public function test_exvat_only_order_with_relativeDiscount_with_multiple_vat_rates_order_sent_with_PriceIncludingVat_false()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ );
+ $order->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ ->setDiscountId("TenPercentOff")
+ ->setName("relativeDiscount")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: 10% off orderRow rows: 1x60.00 @20%, 1x30@10% => split proportionally across order row (only) vat rate: -6.0 @20%, -3.0 @10%
+ $this->assertEquals(-6.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ }
+
+ public function test_incvat_only_order_with_relativeDiscount_with_multiple_vat_rates_order_sent_with_PriceIncludingVat_true()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ );
+ $order->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ ->setDiscountId("TenPercentOff")
+ ->setName("relativeDiscount")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10% off orderRow rows: 60.0 @20%, 30.0 @10% => split across order row (only) vat rate: 6.0ex @20% = 7.2inc, 3.0ex @10% = 3.3inc
+ $this->assertEquals(-7.20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.30, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ }
+
+ // fixed discount examples:
+ public function test_exvat_only_order_with_fixedDiscount_with_amount_specified_as_exvat_and_given_vat_rate_order_sent_with_PriceIncludingVat_false()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ );
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10.0)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ }
+
+ public function test_incvat_only_order_with__fixedDiscount_with_amount_specified_as_exvat_and_given_vat_rate_order_sent_with_PriceIncludingVat_false()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ );
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10.0)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ }
+
+ public function test_exvat_only_order_fixedDiscount_with_amount_specified_as_incvat_and_given_vat_rate_order_sent_with_PriceIncludingVat_false()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ );
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(11.0)
+ ->setVatPercent(10.0)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 11i @10% => 11kr")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ }
+
+ public function test_incvat_only_order_fixedDiscount_with_amount_specified_as_incvat_and_given_vat_rate_order_sent_with_PriceIncludingVat_true()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ );
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(11.0)
+ ->setVatPercent(10.0)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 11i @10% => 11kr")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10 @10% => 11kr, expressed as incvat + vat in request
+ $this->assertEquals(-11.00, $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);
+ }
+
+ public function test_exvat_only_order_with_fixedDiscount_amount_specified_as_exvat_and_calculated_vat_rate_order_sent_with_PriceIncludingVat_false()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(600.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(300.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(160.00)
+ ->setVatPercent(10)
+ );
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setDiscountId("TenCrownsOff")
+ ->setName("fixedDiscount: 10 off exvat")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(600.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(300.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(160.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 off exvat, order row amount are 66% at 20% vat, 33% at 10% vat => 6.67 @20% and 3.33 @10%
+ $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ }
+
+ public function test_incvat_only_order_with_fixedDiscount_amount_specified_as_exvat_and_calculated_vat_rate_order_sent_with_PriceIncludingVat_false()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(720.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(330.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(88.00)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(172.00)
+ ->setVatPercent(10)
+ );
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setDiscountId("TenCrownsOffExVat")
+ ->setName("fixedDiscount: 10 off exvat")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(600.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(300.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(156.36, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit, 2));
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 off exvat, order row amount are 66% @20% vat, 33% @10% vat => 6.67ex @20% = 8.00 inc and 3.33ex @10% = 3.67inc
+ $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ }
+
+ public function test_exvat_only_order_with_fixedDiscount_amount_specified_as_incvat_and_calculated_vat_rate_order_sent_with_PriceIncludingVat_false()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(600.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountExVat(300.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(160.00)
+ ->setVatPercent(10)
+ );
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10.0)
+ ->setDiscountId("TenCrownsOff")
+ ->setName("fixedDiscount: 10 off incvat")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(600.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(300.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(160.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 off incvat, order row amount are 66% at 20% vat, 33% at 10% vat
+ // 1.2*0.66x + 1.1*0.33x = 10 => x = 8.6580 => 5.7143 @20% and 2.8571 @10% = 10kr
+ $this->assertEquals(-5.71, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-2.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ }
+
+ public function test_incvat_only_order_with_fixedDiscount_amount_specified_as_incvat_and_calculated_vat_rate_order_sent_with_PriceIncludingVat_true()
+ {
+ $order = $this->order;
+ $order
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(720.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(330.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(88.00)
+ ->setVatPercent(10)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(172.00)
+ ->setVatPercent(10)
+ );
+ $order->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10.0)
+ ->setDiscountId("TenCrownsOff")
+ ->setName("fixedDiscount: 10 off incvat")
+ );
+
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(720.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(330.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(88.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(172.00, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit, 2));
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 off incvat, order row amount are 66% at 20% vat, 33% at 10% vat
+ // 1.2*0.66x + 1.1*0.33x = 10 => x = 8.6580 => 5.7143 @20% and 2.8571 @10% = 10kr
+ $this->assertEquals(-6.86, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit, 2));
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.14, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit, 2));
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ }
+
+ public function test_add_publickey_for_company_customer()
+ {
+ $config = ConfigurationService::getTestConfig();
+ $order = WebPay::createOrder($config)
+ ->addCustomerDetails(
+ WebPayItem::companyCustomer()
+ ->setPublicKey('ac0f2573b58ff523')//String ex. ac0f2573b58ff523
+ );
+ $this->assertEquals('ac0f2573b58ff523', $order->customerIdentity->publicKey);
+
+
+ }
+
+ public function test_add_publickey_for_private_customer()
+ {
+ $config = ConfigurationService::getTestConfig();
+ $order = WebPay::createOrder($config)
+ ->addCustomerDetails(
+ WebPayItem::individualCustomer()
+ ->setPublicKey('ac0f2573b58ff523')//String ex. ac0f2573b58ff523
+ );
+
+ $this->assertEquals('ac0f2573b58ff523', $order->customerIdentity->publicKey);
+
+ }
+
+ public function test_add_publickey_for_company_customer_full_request()
+ {
+ $config = ConfigurationService::getTestConfig();
+ $order = WebPay::createOrder($config)
+ ->addCustomerDetails(
+ WebPayItem::companyCustomer()
+ ->setCompanyName('mycomp')
+ ->setNationalIdNumber('164701161111')
+ ->setPublicKey('ac0f2573b58ff523')//String ac0f2573b58ff523
+ )
+ ->setCountryCode('SE')
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(125.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->setOrderDate(date('c'))
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals('ac0f2573b58ff523', $order->request->CreateOrderInformation->CustomerIdentity->PublicKey);
+
+ }
+
+ public function test_add_publickey_for_private_customer_full_request()
+ {
+ $config = ConfigurationService::getTestConfig();
+ $order = WebPay::createOrder($config)
+ ->addCustomerDetails(
+ WebPayItem::companyCustomer()
+ ->setCompanyName('mycomp')
+ ->setNationalIdNumber('164701161111')
+ ->setPublicKey('ac0f2573b58ff523')//String ac0f2573b58ff523
+ )
+ ->setCountryCode('SE')
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setAmountIncVat(125.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ )
+ ->setOrderDate(date('c'))
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals('ac0f2573b58ff523', $order->request->CreateOrderInformation->CustomerIdentity->PublicKey);
+
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/WebService/Payment/FixedDiscountRowsTest.php b/test/UnitTest/WebService/Payment/FixedDiscountRowsTest.php
index 4028110d..a0d2f051 100644
--- a/test/UnitTest/WebService/Payment/FixedDiscountRowsTest.php
+++ b/test/UnitTest/WebService/Payment/FixedDiscountRowsTest.php
@@ -14,425 +14,425 @@
class FixedDiscountRowsTest extends \PHPUnit\Framework\TestCase
{
- /**
- * Tests that orders created with a mix of order and fee rows specified as exvat/incvat and vatpercent
- * are sent to the webservice using the correct PriceIncludingVat flag.
- *
- * Also tests that fixed discount rows specified as amount inc/exvat only are split correctly across
- * all the order vat rates, and that the split discount rows are sent to the service using the correct
- * PriceIncludingVat flag.
- */
- private static function create_mixed_exvat_and_incvat_order_and_fee_rows_order()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("incvatRow")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- );
+ /**
+ * Tests that orders created with a mix of order and fee rows specified as exvat/incvat and vatpercent
+ * are sent to the webservice using the correct PriceIncludingVat flag.
+ *
+ * Also tests that fixed discount rows specified as amount inc/exvat only are split correctly across
+ * all the order vat rates, and that the split discount rows are sent to the service using the correct
+ * PriceIncludingVat flag.
+ */
+ private static function create_mixed_exvat_and_incvat_order_and_fee_rows_order()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("incvatRow")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ );
- return $order;
- }
+ return $order;
+ }
- // same order with discount exvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts ex vat
- public function test_mixed_order_with_fixedDiscount_as_exvat_only_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- //->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10e")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.67e @20% + 3.33e @10%
- $this->assertEquals(-6.67, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.33, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP); //=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ // same order with discount exvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts ex vat
+ public function test_mixed_order_with_fixedDiscount_as_exvat_only_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ //->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10e")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.67e @20% + 3.33e @10%
+ $this->assertEquals(-6.67, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.33, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP); //=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
- }
+ // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
+ }
- // same order with discount incvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts inc vat
- public function test_mixed_order_with_fixedDiscount_as_incvat_only_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(10.0)
- //->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10i")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 incvat => split across 10i *(72/72+33) @20% + 10i *(33/72+33) @10% => 6.8571i @20% + 3.1428i @10% =>5.71 + 2.86
- $this->assertEquals(-5.71, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-2.86, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ // same order with discount incvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts inc vat
+ public function test_mixed_order_with_fixedDiscount_as_incvat_only_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10.0)
+ //->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10i")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 incvat => split across 10i *(72/72+33) @20% + 10i *(33/72+33) @10% => 6.8571i @20% + 3.1428i @10% =>5.71 + 2.86
+ $this->assertEquals(-5.71, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-2.86, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
- }
+ // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
+ }
- // same order with discount exvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given exvat + vat
- public function test_mixed_order_with_fixedDiscount_as_exvat_and_vatpercent_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10e@10%")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 11 incvat @10% => -10e @10%
- $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
+ // same order with discount exvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given exvat + vat
+ public function test_mixed_order_with_fixedDiscount_as_exvat_and_vatpercent_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsTest::create_mixed_exvat_and_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10e@10%")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 11 incvat @10% => -10e @10%
+ $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
- // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
- }
+ // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
+ }
- // same order with discount incvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given incvat + vat
- public function test_mixed_order_with_fixedDiscount_as_incvat_and_vatpercent_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsTest::create_mixed_exvat_and_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(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 11 incvat @10% => -10e @10%
- $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
+ // same order with discount incvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given incvat + vat
+ public function test_mixed_order_with_fixedDiscount_as_incvat_and_vatpercent_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsTest::create_mixed_exvat_and_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(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 11 incvat @10% => -10e @10%
+ $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
- // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
- }
+ // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
+ }
- private static function create_only_incvat_order_and_fee_rows_order()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("incvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("incvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- ->setName("incvatShippingFee")
- );
+ private static function create_only_incvat_order_and_fee_rows_order()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("incvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("incvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ ->setName("incvatShippingFee")
+ );
- return $order;
- }
+ return $order;
+ }
- // order with order/fee rows all having incvat should be sent with PriceIncludingVat = true
- public function test_incvat_order_row_and_shipping_fees_only_has_priceIncludingVat_true()
- {
- $order = FixedDiscountRowsTest::create_only_incvat_order_and_fee_rows_order();
+ // order with order/fee rows all having incvat should be sent with PriceIncludingVat = true
+ public function test_incvat_order_row_and_shipping_fees_only_has_priceIncludingVat_true()
+ {
+ $order = FixedDiscountRowsTest::create_only_incvat_order_and_fee_rows_order();
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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);
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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);
- // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
- }
+ // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
+ }
- // same order with discount exvat should be sent with PriceIncludingVat = false with split discount rows based on order amounts ex
- public function test_incvat_order_with_fixedDiscount_as_exvat_only_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsTest::create_only_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- //->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10e")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
- $this->assertEquals(-6.67, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.33, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ // same order with discount exvat should be sent with PriceIncludingVat = false with split discount rows based on order amounts ex
+ public function test_incvat_order_with_fixedDiscount_as_exvat_only_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsTest::create_only_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ //->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10e")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
+ $this->assertEquals(-6.67, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.33, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
- }
+ // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
+ }
- // same order with discount incvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts inc vat
- public function test_incvat_order_with_fixedDiscount_as_incvat_only_has_priceIncludingVat_true()
- {
- $order = FixedDiscountRowsTest::create_only_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(10.0)
- //->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10i")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10 incvat => split across 10i *(72/72+33) @20% + 10i *(33/72+33) @10% => 6.8571i @20% + 3.1428i @10% =>5.71 + 2.86
- $this->assertEquals(-6.86, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.14, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ // same order with discount incvat should be sent with PriceIncludingVat = false but with split discount rows based on order amounts inc vat
+ public function test_incvat_order_with_fixedDiscount_as_incvat_only_has_priceIncludingVat_true()
+ {
+ $order = FixedDiscountRowsTest::create_only_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10.0)
+ //->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10i")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10 incvat => split across 10i *(72/72+33) @20% + 10i *(33/72+33) @10% => 6.8571i @20% + 3.1428i @10% =>5.71 + 2.86
+ $this->assertEquals(-6.86, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.14, round($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
- }
+ // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
+ }
- // same order with discount exvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given exvat + vat
- public function test_incvat_order_with_fixedDiscount_as_exvat_and_vatpercent_has_priceIncludingVat_false()
- {
- $order = FixedDiscountRowsTest::create_only_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10e@10%")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10exvat @10% = -11.00
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
+ // same order with discount exvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given exvat + vat
+ public function test_incvat_order_with_fixedDiscount_as_exvat_and_vatpercent_has_priceIncludingVat_false()
+ {
+ $order = FixedDiscountRowsTest::create_only_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10e@10%")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10exvat @10% = -11.00
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertFalse(isset($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]));
- // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
- }
+ // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
+ }
- // same order with discount incvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given incvat + vat
- 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.00, $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.00, $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.80, $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.60, $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.00, $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]));
+ // same order with discount incvat+vat should be sent with PriceIncludingVat = false with one discount row amount based on given incvat + vat
+ 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.00, $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.00, $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.80, $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.60, $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.00, $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/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
- }
+ // See file IntegrationTest/WebService/Payment/Svea\WebPay\Test\IntegrationTest\WebService\Payment\FixedDiscountRowsIntegrationTest for service response tests.
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/WebService/Payment/GetRequestTotalsTest.php b/test/UnitTest/WebService/Payment/GetRequestTotalsTest.php
index b48e9524..9ccd622b 100644
--- a/test/UnitTest/WebService/Payment/GetRequestTotalsTest.php
+++ b/test/UnitTest/WebService/Payment/GetRequestTotalsTest.php
@@ -12,273 +12,273 @@
class GetRequestTotalsTest extends \PHPUnit\Framework\TestCase
{
- function test_get_invoice_total_amount_before_createorder()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK");
- $order->addOrderRow(WebPayItem::orderRow()
- ->setName('Universal Camera Charger')
- ->setAmountIncVat(19.60)
- ->setVatPercent(25)
- ->setQuantity(100)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(29.00)
- ->setVatPercent(25)
- ->setName('Svea Invoice Fee')
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(294.00)
- ->setName('Discount')
- );
- $total = $order->useInvoicePayment()->getRequestTotals();
+ function test_get_invoice_total_amount_before_createorder()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK");
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setName('Universal Camera Charger')
+ ->setAmountIncVat(19.60)
+ ->setVatPercent(25)
+ ->setQuantity(100)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(29.00)
+ ->setVatPercent(25)
+ ->setName('Svea Invoice Fee')
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(294.00)
+ ->setName('Discount')
+ );
+ $total = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals(1695.0, $total['total_incvat']);
- $this->assertEquals(1356.0, $total['total_exvat']);
- $this->assertEquals(339.0, $total['total_vat']);
- }
+ $this->assertEquals(1695.0, $total['total_incvat']);
+ $this->assertEquals(1356.0, $total['total_exvat']);
+ $this->assertEquals(339.0, $total['total_vat']);
+ }
- function test_get_invoice_total_amount_before_createorder_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK");
- $order->addOrderRow(WebPayItem::orderRow()
- ->setName('Universal Camera Charger')
- ->setAmountIncVat(19.60)
- ->setVatPercent(25)
- ->setQuantity(100)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(29.00)
- ->setVatPercent(25)
- ->setName('Svea Invoice Fee')
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(294.00)
- ->setName('Discount')
- );
- $total = $order->useInvoicePayment()->getRequestTotals();
+ function test_get_invoice_total_amount_before_createorder_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK");
+ $order->addOrderRow(WebPayItem::orderRow()
+ ->setName('Universal Camera Charger')
+ ->setAmountIncVat(19.60)
+ ->setVatPercent(25)
+ ->setQuantity(100)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(29.00)
+ ->setVatPercent(25)
+ ->setName('Svea Invoice Fee')
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(294.00)
+ ->setName('Discount')
+ );
+ $total = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals(1695.0, $total['total_incvat']);
- $this->assertEquals(1356.0, $total['total_exvat']);
- $this->assertEquals(339.0, $total['total_vat']);
- }
+ $this->assertEquals(1695.0, $total['total_incvat']);
+ $this->assertEquals(1356.0, $total['total_exvat']);
+ $this->assertEquals(339.0, $total['total_vat']);
+ }
- /// example of order differing when sent incvat and exvat ----------------------------------------------------------------------
+ /// example of order differing when sent incvat and exvat ----------------------------------------------------------------------
- private static function create_only_incvat_order_and_fee_rows_order()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("incvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("incvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- ->setName("incvatShippingFee")
- );
+ private static function create_only_incvat_order_and_fee_rows_order()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("incvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("incvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ ->setName("incvatShippingFee")
+ );
- return $order;
- }
+ return $order;
+ }
- public function test_getOrderTotals_has_same_amounts_as_service_when_order_sent_priceIncludingVat_false()
- {
- $order = GetRequestTotalsTest::create_only_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- //->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 10e")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
- $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ public function test_getOrderTotals_has_same_amounts_as_service_when_order_sent_priceIncludingVat_false()
+ {
+ $order = GetRequestTotalsTest::create_only_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ //->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 10e")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
+ $this->assertEquals(-6.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.33, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- //// 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.00*1) + r(33.00*1) + r(17.60*1) + r(8.80*1) + r(-8.00*1) + r(-3.66*1) => 72.00+33.00+17.60+8.80-8.00-3.67 => 119.73
- ////$this->assertEquals( "119.73", $response->amount ); // TODO check that this is the amount in S1 invoice, vs 119.74 w/PriceIncludingVat = false
- //$this->assertEquals( "119.74", $response->amount ); // jfr vs 119.73 w/PriceIncludingVat = true
+ //// 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.00*1) + r(33.00*1) + r(17.60*1) + r(8.80*1) + r(-8.00*1) + r(-3.66*1) => 72.00+33.00+17.60+8.80-8.00-3.67 => 119.73
+ ////$this->assertEquals( "119.73", $response->amount ); // TODO check that this is the amount in S1 invoice, vs 119.74 w/PriceIncludingVat = false
+ //$this->assertEquals( "119.74", $response->amount ); // jfr vs 119.73 w/PriceIncludingVat = true
- // verify that getRequestTotals() got the same amount as the service
- $preview = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals("119.74", $preview['total_incvat']);
- //$this->assertEquals( $preview['total_incvat'], $response->amount );
- }
+ // verify that getRequestTotals() got the same amount as the service
+ $preview = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals("119.74", $preview['total_incvat']);
+ //$this->assertEquals( $preview['total_incvat'], $response->amount );
+ }
- public function test_getOrderTotals_has_same_amounts_as_service_when_order_sent_priceIncludingVat_true()
- {
- $order = GetRequestTotalsTest::create_only_incvat_order_and_fee_rows_order();
- $order->
- addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(8.00)
- ->setVatPercent(20)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 8.00i@20%")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(3.67)
- ->setVatPercent(10)
- ->setDiscountId("fixedDiscount")
- ->setName("fixedDiscount: 3.67ie@10%")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
- $this->assertEquals(-8.00, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ public function test_getOrderTotals_has_same_amounts_as_service_when_order_sent_priceIncludingVat_true()
+ {
+ $order = GetRequestTotalsTest::create_only_incvat_order_and_fee_rows_order();
+ $order->
+ addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(8.00)
+ ->setVatPercent(20)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 8.00i@20%")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(3.67)
+ ->setVatPercent(10)
+ ->setDiscountId("fixedDiscount")
+ ->setName("fixedDiscount: 3.67ie@10%")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10 exvat => split across 10e *(60/60+30) @20% + 10e *(30/60+30) @10% => 6.6666e @20% + 3.3333e @10% => 8.00i + 3.67i
+ $this->assertEquals(-8.00, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.67, Helper::bround($request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit), 2, PHP_ROUND_HALF_UP);//=WS
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- // 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.00*1) + r(33.00*1) + r(17.60*1) + r(8.80*1) + r(-8.00*1) + r(-3.66*1) => 72.00+33.00+17.60+8.80-8.00-3.67 => 119.73
- ////$this->assertEquals( "119.73", $response->amount ); // TODO check that this is the amount in S1 invoice, vs 119.74 w/PriceIncludingVat = false
- //$this->assertEquals( "119.73", $response->amount ); // jfr vs 119.73 w/PriceIncludingVat = true
+ // 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.00*1) + r(33.00*1) + r(17.60*1) + r(8.80*1) + r(-8.00*1) + r(-3.66*1) => 72.00+33.00+17.60+8.80-8.00-3.67 => 119.73
+ ////$this->assertEquals( "119.73", $response->amount ); // TODO check that this is the amount in S1 invoice, vs 119.74 w/PriceIncludingVat = false
+ //$this->assertEquals( "119.73", $response->amount ); // jfr vs 119.73 w/PriceIncludingVat = true
- // verify that getRequestTotals() got the same amount as the service
- $preview = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals("119.73", $preview['total_incvat']);
- //$this->assertEquals( $preview['total_incvat'], $response->amount );
- }
+ // verify that getRequestTotals() got the same amount as the service
+ $preview = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals("119.73", $preview['total_incvat']);
+ //$this->assertEquals( $preview['total_incvat'], $response->amount );
+ }
- public function test_getRequestTotals_reference_1400_00_inc_behaviour()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1400.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2016-04-14");
+ public function test_getRequestTotals_reference_1400_00_inc_behaviour()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1400.00)
+ ->setVatPercent(6)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2016-04-14");
- $preview_total = $order->useInvoicePayment()->getRequestTotals();
- $this->assertEquals(1400.00, $preview_total['total_incvat']);
- $this->assertEquals(1320.75, $preview_total['total_exvat']);
- $this->assertEquals(79.25, $preview_total['total_vat']);
- }
+ $preview_total = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals(1400.00, $preview_total['total_incvat']);
+ $this->assertEquals(1320.75, $preview_total['total_exvat']);
+ $this->assertEquals(79.25, $preview_total['total_vat']);
+ }
- public function test_getRequestTotals_reference_1400_26_inc_behaviour()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1400.26)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2016-04-14");
+ public function test_getRequestTotals_reference_1400_26_inc_behaviour()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1400.26)
+ ->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.00, $preview_total['total_exvat']);
- $this->assertEquals(79.26, $preview_total['total_vat']);
- }
+ $preview_total = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals(1400.26, $preview_total['total_incvat']);
+ $this->assertEquals(1321.00, $preview_total['total_exvat']);
+ $this->assertEquals(79.26, $preview_total['total_vat']);
+ }
- public function test_getRequestTotals_reference_1321_00_ex_behaviour()
- {
- $config = ConfigurationService::getDefaultConfig();
- $order = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(1321.00)
- ->setVatPercent(6)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2016-04-14");
+ public function test_getRequestTotals_reference_1321_00_ex_behaviour()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $order = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(1321.00)
+ ->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.00, $preview_total['total_exvat']);
- $this->assertEquals(79.26, $preview_total['total_vat']);
- }
+ $preview_total = $order->useInvoicePayment()->getRequestTotals();
+ $this->assertEquals(1400.26, $preview_total['total_incvat']);
+ $this->assertEquals(1321.00, $preview_total['total_exvat']);
+ $this->assertEquals(79.26, $preview_total['total_vat']);
+ }
}
\ No newline at end of file
diff --git a/test/UnitTest/WebService/Payment/InvoicePaymentTest.php b/test/UnitTest/WebService/Payment/InvoicePaymentTest.php
index b6dde2eb..bc5fd6e4 100644
--- a/test/UnitTest/WebService/Payment/InvoicePaymentTest.php
+++ b/test/UnitTest/WebService/Payment/InvoicePaymentTest.php
@@ -14,1912 +14,1912 @@
class InvoicePaymentTest extends \PHPUnit\Framework\TestCase
{
- public function testInvoiceRequestwithPeppolId()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(
- WebPayItem::companyCustomer()
- ->setNationalIdNumber(194608142222))
- ->setOrderDate("2019-04-01")
- ->setPeppolId("1234:asdf")
- ->setCountryCode("SE")
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals("1234:asdf", $request->request->CreateOrderInformation->PeppolId);
- }
-
- public function testInvoiceRequestObjectForCustomerIdentityIndividualFromSE()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals(194605092222, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
- $this->assertEquals("SE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
- $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
- }
-
- public function testInvoiceRequestOnProductVatCero()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountExVat(100.00)
- ->setDescription("Specification")
- ->setName('Prod')
- ->setUnit("st")
- ->setVatPercent(0)
- ->setDiscountPercent(0)
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit); //Check all in identity
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent); //Check all in identity
- }
-
- public function testSetAuth()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- //->setPasswordBasedAuthorization("sverigetest", "sverigetest", 79021)
- ->prepareRequest();
-
- $this->assertEquals(79021, $request->request->Auth->ClientNumber); //Check all in identity
- $this->assertEquals("sverigetest", $request->request->Auth->Username); //Check all in identity
- $this->assertEquals("sverigetest", $request->request->Auth->Password); //Check all in identity
- }
-
- public function testInvoiceRequestObjectForCustomerIdentityIndividualFromNL()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setInitials("SB")
- ->setBirthDate(1923, 12, 12)
- ->setName("Tess", "Testson")
- ->setEmail("test@svea.com")
- ->setPhoneNumber(999999)
- ->setIpAddress("123.123.123")
- ->setStreetAddress("Gatan", 23)
- ->setCoAddress("c/o Eriksson")
- ->setZipCode(9999)
- ->setLocality("Stan")
- )
- ->setCountryCode("NL")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
- $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
- $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
- $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
- $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
- $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
- $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
- $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
- $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
- $this->assertEquals("NL", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
- $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
- $this->assertEquals("Tess", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->FirstName); //Check all in identity
- $this->assertEquals("Testson", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->LastName); //Check all in identity
- $this->assertEquals("SB", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->Initials); //Check all in identity
- $this->assertEquals(19231212, $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->BirthDate); //Check all in identity
- }
-
- public function testInvoiceRequestObjectForCustomerIdentityIndividualFromDE()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setBirthDate(1923, 12, 12)
- ->setName("Tess", "Testson")
- ->setEmail("test@svea.com")
- ->setPhoneNumber(999999)
- ->setIpAddress("123.123.123")
- ->setStreetAddress("Gatan", 23)
- ->setCoAddress("c/o Eriksson")
- ->setZipCode(9999)
- ->setLocality("Stan")
- )
- ->setCountryCode("DE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("EUR")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
- $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
- $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
- $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
- $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
- $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
- $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
- $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
- $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
- $this->assertEquals("DE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
- $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
- $this->assertEquals("Tess", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->FirstName); //Check all in identity
- $this->assertEquals("Testson", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->LastName); //Check all in identity
- $this->assertEquals(19231212, $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->BirthDate); //Check all in identity
- }
-
- public function testInvoiceRequestObjectForCustomerIdentityCompanyFromNL()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::individualCustomer()
- ->setInitials("SB")
- ->setBirthDate(1923, 12, 12)
- ->setName("Tess", "Testson")
- ->setEmail("test@svea.com")
- ->setPhoneNumber(999999)
- ->setIpAddress("123.123.123")
- ->setStreetAddress("Gatan", 23)
- ->setCoAddress("c/o Eriksson")
- ->setZipCode(9999)
- ->setLocality("Stan")
- )
- ->setCountryCode("NL")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
- $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
- $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
- $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
- $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
- $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
- $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
- $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
- $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
- $this->assertEquals("NL", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
- $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
- }
-
- public function testInvoiceRequestObjectForCustomerIdentityCompanyFromSE()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber("vat234"))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals("vat234", $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
- $this->assertEquals("SE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
- $this->assertEquals("Company", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
- }
-
- public function testInvoiceRequestObjectForSEorderOnOneProductRow()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->run($rowFactory->buildShippingFee())
- ->run($rowFactory->buildInvoiceFee())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- //First orderrow is a product
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals(100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
- //Second orderrow is shipment
- $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals(50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- //Third orderrow is invoicefee
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals(50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
- }
-
- public function testInvoiceRequestUsingAmountIncVatWithVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountIncVat(125.00)
- ->setDescription("Specification")
- ->setName('Product')
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId('33')
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountIncVat(62.50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setName('Svea fee')
- ->setDescription("Fee for invoice")
- ->setAmountIncVat(62.50)
- ->setUnit("st")
- ->setVatPercent(25)
- ->setDiscountPercent(0)
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- //First orderrow is a product
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals(125.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
- //Second orderrow is shipment
- $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- //Third orderrow is invoicefee
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
- }
-
- public function testInvoiceRequestUsingAmountIncVatWithAmountExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountIncVat(125.00)
- ->setAmountExVat(100.00)
- ->setDescription("Specification")
- ->setName('Product')
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setShippingId('33')
- ->setName('shipping')
- ->setDescription("Specification")
- ->setAmountIncVat(62.50)
- ->setAmountExVat(50.00)
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setName('Svea fee')
- ->setDescription("Fee for invoice")
- ->setAmountIncVat(62.50)
- ->setAmountExVat(50.00)
- ->setUnit("st")
- ->setDiscountPercent(0)
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- //First orderrow is a product
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
- $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
- $this->assertEquals(125.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
- //Second orderrow is shipment
- $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- //Third orderrow is invoicefee
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
- }
-
- public function testInvoiceRequestObjectWithRelativeDiscountOnDifferentProductVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- //->setAmountIncVat(300.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(188.68)
- //->setAmountIncVat(200.00)
- ->setDescription("Bok")
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(20)
- ->setDescription("RelativeDiscount")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->prepareRequest();
-
- //couponrows
-
- $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals('RelativeDiscount (25%)', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals(-48.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
-
- $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->ArticleNumber);
- $this->assertEquals('RelativeDiscount (6%)', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Description);
- $this->assertEquals(-37.736, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->NumberOfUnits);
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Unit);
- $this->assertEquals(6, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->DiscountPercent);
- }
-
- public function test_RelativeDiscountAsInt()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- //->setAmountIncVat(300.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(188.68)
- //->setAmountIncVat(200.00)
- ->setDescription("Bok")
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(21)
- ->setDescription("RelativeDiscount")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->prepareRequest();
-
- //couponrows
- $this->assertEquals(-50.40, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(-39.6228, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
-
- }
-
- public function test_RelativeDiscountAsFloat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- //->setAmountIncVat(300.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(188.68)
- //->setAmountIncVat(200.00)
- ->setDescription("Bok")
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(20.5)//
- ->setDescription("RelativeDiscount")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->prepareRequest();
-
- //couponrows
- $this->assertEquals(-49.20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(-38.6794, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- }
-
- public function t_estInvoiceRequestObjectWithFixedDiscountOnDifferentProductVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(188.68)
- ->setDescription("Bok")
- ->setVatPercent(6)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(100.00)
- ->setDescription('FixedDiscount')
- ->setDiscountId('1')
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->prepareRequest();
-
- //couponrow
- $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
- $this->assertEquals('FixedDiscount (25%)', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
- $this->assertEquals(-85.74, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
- $this->assertEquals(17, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
- }
-
- public function testInvoiceWithFixedDiscountWithUneavenAmount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(1)
- ->setAmountExVat(240.00)
- ->setDescription("CD")
- ->setVatPercent(25)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(101.50)
- ->setDescription('FixedDiscount')
- ->setDiscountId('1')
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->prepareRequest();
- //couponrow
- $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals('FixedDiscount', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals(-81.2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- }
-
- public function testInvoiceRequestObjectWithCreateOrderInformation()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->run($rowFactory->buildShippingFee())
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(194605092222)->setAddressSelector("ad33"))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setClientOrderNumber("nr26")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
- /**
- * Test that all data is in the right place for SoapRequest
- */
- //First orderrow is a product
- $this->assertEquals("2012-12-12", $request->request->CreateOrderInformation->OrderDate);
- $this->assertEquals('33', $request->request->CreateOrderInformation->CustomerReference);
- $this->assertEquals('Invoice', $request->request->CreateOrderInformation->OrderType);
- $this->assertEquals('nr26', $request->request->CreateOrderInformation->ClientOrderNumber); //check in identity
- $this->assertEquals('ad33', $request->request->CreateOrderInformation->AddressSelector); //check in identity
- }
-
- public function testInvoiceRequestObjectWithAuth()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->run($rowFactory->buildShippingFee())
- ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(194605092222)->setAddressSelector("ad33"))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setClientOrderNumber("nr26")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals('sverigetest', $request->request->Auth->Username);
- $this->assertEquals('sverigetest', $request->request->Auth->Password);
- $this->assertEquals(79021, $request->request->Auth->ClientNumber);
- }
-
- /**
- * Tests for rounding**
- */
- public function testOrderSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testDiscountSetAsExVatWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()->setAmountExVat(8))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(8)
- ->setVatPercent(0))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testDiscountPercentAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testFeeSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testOrderRowPriceSetAsInkVatAndVatPercentSetAmountAsIncVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(100.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(100.00)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testDiscountSetAsIncVatWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(10)
- ->setVatPercent(0))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
-
- public function testDiscountPercentAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testOrderSetAsIncVatAndExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testOrderAndFeesSetAsIncVatAndExVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1230.9876)
- ->setAmountExVat(990.99)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testOrderAndFixedDiscountSetAsIncVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(1230.9876)
- ->setAmountExVat(990.99)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(12.39876)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals(1230.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testOrderSetAsIncVatAndExVatAndRelativeDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setAmountExVat(99.99)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testOrderSetWithMixedMethods1()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setAmountIncVat(123.9876)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testOrderSetWithMixedMethods2()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setName('incvat')
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setName('exvat')
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setName('exvat')
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testOrderSetWithMixedOrderRowAndFee()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testOrderSetWithMixedOrderRowAndFeeAndVatPercentSet()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
- public function testOrderAndFixedDiscountSetWithMixedVat2()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(12.39876)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- }
-
- public function testOrderSetAsMixedVatAndRelativeDiscount()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(99.99)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(5)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
-
- $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
-
- }
-
-
- /// relative discount examples:
- // single order rows vat rate
- public function test_relativeDiscount_amount()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(25)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(25)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(25)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::relativeDiscount()
- ->setDiscountPercent(10.0)
- ->setDiscountId("TenPercentOff")
- ->setName("relativeDiscount")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: 10% off orderRow rows: 2x 80.00 @25% => -16.00 @25% discount
- $this->assertEquals(-16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- }
-
- // relative discount on multiple order row defined exvat/vatpercent vat rates
- public function test_relativeDiscount_amount_multiple_vat_rates_defined_exvat_creates_discount_rows_using_exvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::relativeDiscount()
- ->setDiscountPercent(10.0)
- ->setDiscountId("TenPercentOff")
- ->setName("relativeDiscount")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: 10% off orderRow rows: 1x60.00 @20%, 1x30@10% => split proportionally across order row (only) vat rate: -6.0 @20%, -3.0 @10%
- $this->assertEquals(-6.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
-
- }
-
- // relative discount -- created discount rows should use incvat + vatpercent
- // relative discount on multiple order row defined exvat/vatpercent vat rates
- public function test_relativeDiscount_amount_multiple_vat_rates_defined_incvat_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(72.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(33.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountIncVat(8.80)
- ->setVatPercent(10)
- ->setName("incvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountIncVat(17.60)
- ->setVatPercent(10)
- ->setName("incvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::relativeDiscount()
- ->setDiscountPercent(10.0)
- ->setDiscountId("TenPercentOff")
- ->setName("relativeDiscount")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10% off orderRow rows: 1x60.00 @20%, 1x30@10% => split proportionally across order row (only) vat rate: -6.0 @20%, -3.0 @10%
- $this->assertEquals(-7.20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- $this->assertEquals(-3.30, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
- }
-
- /// fixed discount examples:
- // single order rows vat rate
- public function test_fixedDiscount_amount_with_set_exvat_vat_rate()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setVatPercent(10)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
- }
-
- public function test_fixedDiscount_amount_with_set_incvat_vat_rate()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(11.0)
- ->setVatPercent(10)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- }
-
- public function test_fixedDiscount_amount_with_calculated_vat_rate_exvat()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setDiscountId("TenCrownsOff")
- ->setName("fixedDiscount: 10 off exvat")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: fixedDiscount: 10 off exvat, order row amount are 66% at 20% vat, 33% at 10% vat => 6.67 @20% and 3.33 @10%
- $this->assertEquals(-6.6666666666667, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(-3.3333333333333, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- }
-
- public function test_fixedDiscount_amount_with_calculated_vat_rate_incvat()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->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.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $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_fixedDiscount_amount_with_set_incvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountIncVat(11.0)
- ->setVatPercent(10)
- ->setDiscountId("ElevenCrownsOff")
- ->setName("fixedDiscount: 10 @10% => 11kr")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
- $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- }
-
- public function test_fixedDiscount_amount_with_calculated_vat_rate_exvat_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->setVatPercent(10)
- ->setName("exvatShippingFee")
- )
- ->addDiscount(
- WebPayItem::fixedDiscount()
- ->setAmountExVat(10.0)
- ->setDiscountId("TenCrownsOff")
- ->setName("fixedDiscount: 10 off exvat")
- );
- $request = $order->useInvoicePayment()->prepareRequest();
- // all order rows
- $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
- // all discount rows
- // expected: fixedDiscount: 10 off exvat, order row amount are 66% at 20% vat, 33% at 10% vat => 6.67 @20% and 3.33 @10%
- $this->assertEquals(-6.6666666666667, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
- $this->assertEquals(-3.3333333333333, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
- }
-
- public function test_fixedDiscount_amount_with_calculated_vat_rate_incvat_creates_discount_rows_using_incvat_and_vatpercent()
- {
- $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(60.00)
- ->setVatPercent(20)
- ->setQuantity(1)
- ->setName("exvatRow")
- )
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(30.00)
- ->setVatPercent(10)
- ->setQuantity(1)
- ->setName("exvatRow2")
- )
- ->addFee(
- WebPayItem::invoiceFee()
- ->setAmountExVat(8.00)
- ->setVatPercent(10)
- ->setName("exvatInvoiceFee")
- )
- ->addFee(
- WebPayItem::shippingFee()
- ->setAmountExVat(16.00)
- ->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.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- // all invoice fee rows
- $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
- // all shipping fee rows
- $this->assertEquals(16.00, $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);
- }
-
- // See file Svea\WebPay\Test\UnitTest\WebService\Payment\FixedDiscountRowsTest for specification of FixedDiscount row behaviour.
+ public function testInvoiceRequestwithPeppolId()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(
+ WebPayItem::companyCustomer()
+ ->setNationalIdNumber(194608142222))
+ ->setOrderDate("2019-04-01")
+ ->setPeppolId("1234:asdf")
+ ->setCountryCode("SE")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals("1234:asdf", $request->request->CreateOrderInformation->PeppolId);
+ }
+
+ public function testInvoiceRequestObjectForCustomerIdentityIndividualFromSE()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals(194605092222, $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
+ $this->assertEquals("SE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
+ $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
+ }
+
+ public function testInvoiceRequestOnProductVatCero()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountExVat(100.00)
+ ->setDescription("Specification")
+ ->setName('Prod')
+ ->setUnit("st")
+ ->setVatPercent(0)
+ ->setDiscountPercent(0)
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit); //Check all in identity
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent); //Check all in identity
+ }
+
+ public function testSetAuth()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ //->setPasswordBasedAuthorization("sverigetest", "sverigetest", 79021)
+ ->prepareRequest();
+
+ $this->assertEquals(79021, $request->request->Auth->ClientNumber); //Check all in identity
+ $this->assertEquals("sverigetest", $request->request->Auth->Username); //Check all in identity
+ $this->assertEquals("sverigetest", $request->request->Auth->Password); //Check all in identity
+ }
+
+ public function testInvoiceRequestObjectForCustomerIdentityIndividualFromNL()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setInitials("SB")
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Tess", "Testson")
+ ->setEmail("test@svea.com")
+ ->setPhoneNumber(999999)
+ ->setIpAddress("123.123.123")
+ ->setStreetAddress("Gatan", 23)
+ ->setCoAddress("c/o Eriksson")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ )
+ ->setCountryCode("NL")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
+ $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
+ $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
+ $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
+ $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
+ $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
+ $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
+ $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
+ $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
+ $this->assertEquals("NL", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
+ $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
+ $this->assertEquals("Tess", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->FirstName); //Check all in identity
+ $this->assertEquals("Testson", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->LastName); //Check all in identity
+ $this->assertEquals("SB", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->Initials); //Check all in identity
+ $this->assertEquals(19231212, $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->BirthDate); //Check all in identity
+ }
+
+ public function testInvoiceRequestObjectForCustomerIdentityIndividualFromDE()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Tess", "Testson")
+ ->setEmail("test@svea.com")
+ ->setPhoneNumber(999999)
+ ->setIpAddress("123.123.123")
+ ->setStreetAddress("Gatan", 23)
+ ->setCoAddress("c/o Eriksson")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ )
+ ->setCountryCode("DE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("EUR")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
+ $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
+ $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
+ $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
+ $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
+ $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
+ $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
+ $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
+ $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
+ $this->assertEquals("DE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
+ $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
+ $this->assertEquals("Tess", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->FirstName); //Check all in identity
+ $this->assertEquals("Testson", $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->LastName); //Check all in identity
+ $this->assertEquals(19231212, $request->request->CreateOrderInformation->CustomerIdentity->IndividualIdentity->BirthDate); //Check all in identity
+ }
+
+ public function testInvoiceRequestObjectForCustomerIdentityCompanyFromNL()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::individualCustomer()
+ ->setInitials("SB")
+ ->setBirthDate(1923, 12, 12)
+ ->setName("Tess", "Testson")
+ ->setEmail("test@svea.com")
+ ->setPhoneNumber(999999)
+ ->setIpAddress("123.123.123")
+ ->setStreetAddress("Gatan", 23)
+ ->setCoAddress("c/o Eriksson")
+ ->setZipCode(9999)
+ ->setLocality("Stan")
+ )
+ ->setCountryCode("NL")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("test@svea.com", $request->request->CreateOrderInformation->CustomerIdentity->Email); //Check all in identity
+ $this->assertEquals(999999, $request->request->CreateOrderInformation->CustomerIdentity->PhoneNumber); //Check all in identity
+ $this->assertEquals("123.123.123", $request->request->CreateOrderInformation->CustomerIdentity->IpAddress); //Check all in identity
+ $this->assertEquals("Tess Testson", $request->request->CreateOrderInformation->CustomerIdentity->FullName); //Check all in identity
+ $this->assertEquals("Gatan", $request->request->CreateOrderInformation->CustomerIdentity->Street); //Check all in identity
+ $this->assertEquals("c/o Eriksson", $request->request->CreateOrderInformation->CustomerIdentity->CoAddress); //Check all in identity
+ $this->assertEquals(9999, $request->request->CreateOrderInformation->CustomerIdentity->ZipCode); //Check all in identity
+ $this->assertEquals(23, $request->request->CreateOrderInformation->CustomerIdentity->HouseNumber); //Check all in identity
+ $this->assertEquals("Stan", $request->request->CreateOrderInformation->CustomerIdentity->Locality); //Check all in identity
+ $this->assertEquals("NL", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
+ $this->assertEquals("Individual", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
+ }
+
+ public function testInvoiceRequestObjectForCustomerIdentityCompanyFromSE()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber("vat234"))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals("vat234", $request->request->CreateOrderInformation->CustomerIdentity->NationalIdNumber); //Check all in identity
+ $this->assertEquals("SE", $request->request->CreateOrderInformation->CustomerIdentity->CountryCode); //Check all in identity
+ $this->assertEquals("Company", $request->request->CreateOrderInformation->CustomerIdentity->CustomerType); //Check all in identity
+ }
+
+ public function testInvoiceRequestObjectForSEorderOnOneProductRow()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->run($rowFactory->buildShippingFee())
+ ->run($rowFactory->buildInvoiceFee())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ //First orderrow is a product
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals(100.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
+ //Second orderrow is shipment
+ $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals(50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ //Third orderrow is invoicefee
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals(50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
+ }
+
+ public function testInvoiceRequestUsingAmountIncVatWithVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountIncVat(125.00)
+ ->setDescription("Specification")
+ ->setName('Product')
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId('33')
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountIncVat(62.50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setName('Svea fee')
+ ->setDescription("Fee for invoice")
+ ->setAmountIncVat(62.50)
+ ->setUnit("st")
+ ->setVatPercent(25)
+ ->setDiscountPercent(0)
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ //First orderrow is a product
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals(125.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
+ //Second orderrow is shipment
+ $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ //Third orderrow is invoicefee
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
+ }
+
+ public function testInvoiceRequestUsingAmountIncVatWithAmountExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountIncVat(125.00)
+ ->setAmountExVat(100.00)
+ ->setDescription("Specification")
+ ->setName('Product')
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setShippingId('33')
+ ->setName('shipping')
+ ->setDescription("Specification")
+ ->setAmountIncVat(62.50)
+ ->setAmountExVat(50.00)
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setName('Svea fee')
+ ->setDescription("Fee for invoice")
+ ->setAmountIncVat(62.50)
+ ->setAmountExVat(50.00)
+ ->setUnit("st")
+ ->setDiscountPercent(0)
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ //First orderrow is a product
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->ArticleNumber);
+ $this->assertEquals('Product: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Description);
+ $this->assertEquals(125.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->DiscountPercent);
+ //Second orderrow is shipment
+ $this->assertEquals('33', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals('shipping: Specification', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ //Third orderrow is invoicefee
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals('Svea fee: Fee for invoice', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals(62.50, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals('st', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
+ }
+
+ public function testInvoiceRequestObjectWithRelativeDiscountOnDifferentProductVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ //->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(188.68)
+ //->setAmountIncVat(200.00)
+ ->setDescription("Bok")
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(20)
+ ->setDescription("RelativeDiscount")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ //couponrows
+
+ $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals('RelativeDiscount (25%)', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals(-48.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
+
+ $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->ArticleNumber);
+ $this->assertEquals('RelativeDiscount (6%)', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Description);
+ $this->assertEquals(-37.736, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->NumberOfUnits);
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->Unit);
+ $this->assertEquals(6, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->DiscountPercent);
+ }
+
+ public function test_RelativeDiscountAsInt()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ //->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(188.68)
+ //->setAmountIncVat(200.00)
+ ->setDescription("Bok")
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(21)
+ ->setDescription("RelativeDiscount")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ //couponrows
+ $this->assertEquals(-50.40, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(-39.6228, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+
+ }
+
+ public function test_RelativeDiscountAsFloat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ //->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(188.68)
+ //->setAmountIncVat(200.00)
+ ->setDescription("Bok")
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(20.5)//
+ ->setDescription("RelativeDiscount")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ //couponrows
+ $this->assertEquals(-49.20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(-38.6794, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ }
+
+ public function t_estInvoiceRequestObjectWithFixedDiscountOnDifferentProductVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(188.68)
+ ->setDescription("Bok")
+ ->setVatPercent(6)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(100.00)
+ ->setDescription('FixedDiscount')
+ ->setDiscountId('1')
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ //couponrow
+ $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->ArticleNumber);
+ $this->assertEquals('FixedDiscount (25%)', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Description);
+ $this->assertEquals(-85.74, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->NumberOfUnits);
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->Unit);
+ $this->assertEquals(17, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->DiscountPercent);
+ }
+
+ public function testInvoiceWithFixedDiscountWithUneavenAmount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(1)
+ ->setAmountExVat(240.00)
+ ->setDescription("CD")
+ ->setVatPercent(25)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(101.50)
+ ->setDescription('FixedDiscount')
+ ->setDiscountId('1')
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ //couponrow
+ $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals('FixedDiscount', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals(-81.2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ }
+
+ public function testInvoiceRequestObjectWithCreateOrderInformation()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->run($rowFactory->buildShippingFee())
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(194605092222)->setAddressSelector("ad33"))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setClientOrderNumber("nr26")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+ /**
+ * Test that all data is in the right place for SoapRequest
+ */
+ //First orderrow is a product
+ $this->assertEquals("2012-12-12", $request->request->CreateOrderInformation->OrderDate);
+ $this->assertEquals('33', $request->request->CreateOrderInformation->CustomerReference);
+ $this->assertEquals('Invoice', $request->request->CreateOrderInformation->OrderType);
+ $this->assertEquals('nr26', $request->request->CreateOrderInformation->ClientOrderNumber); //check in identity
+ $this->assertEquals('ad33', $request->request->CreateOrderInformation->AddressSelector); //check in identity
+ }
+
+ public function testInvoiceRequestObjectWithAuth()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->run($rowFactory->buildShippingFee())
+ ->addCustomerDetails(WebPayItem::companyCustomer()->setNationalIdNumber(194605092222)->setAddressSelector("ad33"))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setClientOrderNumber("nr26")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals('sverigetest', $request->request->Auth->Username);
+ $this->assertEquals('sverigetest', $request->request->Auth->Password);
+ $this->assertEquals(79021, $request->request->Auth->ClientNumber);
+ }
+
+ /**
+ * Tests for rounding**
+ */
+ public function testOrderSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testDiscountSetAsExVatWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()->setAmountExVat(8))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(8)
+ ->setVatPercent(0))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testDiscountPercentAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testFeeSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testOrderRowPriceSetAsInkVatAndVatPercentSetAmountAsIncVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testDiscountSetAsIncVatWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10)
+ ->setVatPercent(0))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+
+ public function testDiscountPercentAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetAsIncVatAndExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testOrderAndFeesSetAsIncVatAndExVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1230.9876)
+ ->setAmountExVat(990.99)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(123.9876)->setAmountExVat(99.99)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testOrderAndFixedDiscountSetAsIncVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(1230.9876)
+ ->setAmountExVat(990.99)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(12.39876)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals(1230.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetAsIncVatAndExVatAndRelativeDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setAmountExVat(99.99)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetWithMixedMethods1()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setAmountIncVat(123.9876)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetWithMixedMethods2()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setName('incvat')
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setName('exvat')
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setName('exvat')
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetWithMixedOrderRowAndFee()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetWithMixedOrderRowAndFeeAndVatPercentSet()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+ public function testOrderAndFixedDiscountSetWithMixedVat2()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(12.39876)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ }
+
+ public function testOrderSetAsMixedVatAndRelativeDiscount()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(99.99)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(5)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(99.99, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+
+ $this->assertEquals(-9.999, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertFalse($request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+
+ }
+
+
+ /// relative discount examples:
+ // single order rows vat rate
+ public function test_relativeDiscount_amount()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(25)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(25)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(25)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10.0)
+ ->setDiscountId("TenPercentOff")
+ ->setName("relativeDiscount")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(80.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: 10% off orderRow rows: 2x 80.00 @25% => -16.00 @25% discount
+ $this->assertEquals(-16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ }
+
+ // relative discount on multiple order row defined exvat/vatpercent vat rates
+ public function test_relativeDiscount_amount_multiple_vat_rates_defined_exvat_creates_discount_rows_using_exvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10.0)
+ ->setDiscountId("TenPercentOff")
+ ->setName("relativeDiscount")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: 10% off orderRow rows: 1x60.00 @20%, 1x30@10% => split proportionally across order row (only) vat rate: -6.0 @20%, -3.0 @10%
+ $this->assertEquals(-6.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+
+ }
+
+ // relative discount -- created discount rows should use incvat + vatpercent
+ // relative discount on multiple order row defined exvat/vatpercent vat rates
+ public function test_relativeDiscount_amount_multiple_vat_rates_defined_incvat_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(72.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(33.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountIncVat(8.80)
+ ->setVatPercent(10)
+ ->setName("incvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountIncVat(17.60)
+ ->setVatPercent(10)
+ ->setName("incvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10.0)
+ ->setDiscountId("TenPercentOff")
+ ->setName("relativeDiscount")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(72.00, $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.00, $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.80, $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.60, $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: 10% off orderRow rows: 1x60.00 @20%, 1x30@10% => split proportionally across order row (only) vat rate: -6.0 @20%, -3.0 @10%
+ $this->assertEquals(-7.20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ $this->assertEquals(-3.30, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ $this->assertEquals(true, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PriceIncludingVat);
+ }
+
+ /// fixed discount examples:
+ // single order rows vat rate
+ public function test_fixedDiscount_amount_with_set_exvat_vat_rate()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setVatPercent(10)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PriceIncludingVat);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PriceIncludingVat);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PriceIncludingVat);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(false, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PriceIncludingVat);
+ }
+
+ public function test_fixedDiscount_amount_with_set_incvat_vat_rate()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(11.0)
+ ->setVatPercent(10)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ }
+
+ public function test_fixedDiscount_amount_with_calculated_vat_rate_exvat()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setDiscountId("TenCrownsOff")
+ ->setName("fixedDiscount: 10 off exvat")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: fixedDiscount: 10 off exvat, order row amount are 66% at 20% vat, 33% at 10% vat => 6.67 @20% and 3.33 @10%
+ $this->assertEquals(-6.6666666666667, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(-3.3333333333333, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ }
+
+ public function test_fixedDiscount_amount_with_calculated_vat_rate_incvat()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->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.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $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_fixedDiscount_amount_with_set_incvat_vat_rate_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountIncVat(11.0)
+ ->setVatPercent(10)
+ ->setDiscountId("ElevenCrownsOff")
+ ->setName("fixedDiscount: 10 @10% => 11kr")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: fixedDiscount: 10 @10% => 11kr, expressed as exvat + vat in request
+ $this->assertEquals(-10.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ }
+
+ public function test_fixedDiscount_amount_with_calculated_vat_rate_exvat_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->setVatPercent(10)
+ ->setName("exvatShippingFee")
+ )
+ ->addDiscount(
+ WebPayItem::fixedDiscount()
+ ->setAmountExVat(10.0)
+ ->setDiscountId("TenCrownsOff")
+ ->setName("fixedDiscount: 10 off exvat")
+ );
+ $request = $order->useInvoicePayment()->prepareRequest();
+ // all order rows
+ $this->assertEquals(60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][3]->VatPercent);
+ // all discount rows
+ // expected: fixedDiscount: 10 off exvat, order row amount are 66% at 20% vat, 33% at 10% vat => 6.67 @20% and 3.33 @10%
+ $this->assertEquals(-6.6666666666667, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][4]->VatPercent);
+ $this->assertEquals(-3.3333333333333, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][5]->VatPercent);
+ }
+
+ public function test_fixedDiscount_amount_with_calculated_vat_rate_incvat_creates_discount_rows_using_incvat_and_vatpercent()
+ {
+ $order = WebPay::createOrder(ConfigurationService::getDefaultConfig())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(60.00)
+ ->setVatPercent(20)
+ ->setQuantity(1)
+ ->setName("exvatRow")
+ )
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(30.00)
+ ->setVatPercent(10)
+ ->setQuantity(1)
+ ->setName("exvatRow2")
+ )
+ ->addFee(
+ WebPayItem::invoiceFee()
+ ->setAmountExVat(8.00)
+ ->setVatPercent(10)
+ ->setName("exvatInvoiceFee")
+ )
+ ->addFee(
+ WebPayItem::shippingFee()
+ ->setAmountExVat(16.00)
+ ->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.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(20, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertEquals(30.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ // all invoice fee rows
+ $this->assertEquals(8.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+ // all shipping fee rows
+ $this->assertEquals(16.00, $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);
+ }
+
+ // See file Svea\WebPay\Test\UnitTest\WebService\Payment\FixedDiscountRowsTest for specification of FixedDiscount row behaviour.
}
\ No newline at end of file
diff --git a/test/UnitTest/WebService/Payment/PaymentPlanTest.php b/test/UnitTest/WebService/Payment/PaymentPlanTest.php
index bd99bc09..512e09fe 100644
--- a/test/UnitTest/WebService/Payment/PaymentPlanTest.php
+++ b/test/UnitTest/WebService/Payment/PaymentPlanTest.php
@@ -15,347 +15,347 @@
class PaymentPlanTest extends \PHPUnit\Framework\TestCase
{
- /**
- * Use to get paymentPlanParams to be able to test PaymentPlanRequest
- * @return type
- */
- public function getGetPaymentPlanParamsForTesting()
- {
- $config = ConfigurationService::getDefaultConfig();
- $addressRequest = WebPay::getPaymentPlanParams($config);
- $response = $addressRequest
- ->setCountryCode("SE")
- ->doRequest();
-
- return $response->campaignCodes[0]->campaignCode;
- }
-
- public function testPaymentPlanRequestObjectSpecifics()
- {
- $config = ConfigurationService::getDefaultConfig();
- $rowFactory = new TestUtil();
- $request = WebPay::createOrder($config)
- ->addOrderRow(TestUtil::createOrderRow())
- ->run($rowFactory->buildShippingFee())
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setClientOrderNumber("nr26")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePaymentPlanPayment("camp1")// returnerar InvoiceOrder object
- ->prepareRequest();
-
- $this->assertEquals('camp1', $request->request->CreateOrderInformation->CreatePaymentPlanDetails['CampaignCode']);
- $this->assertEquals(0, $request->request->CreateOrderInformation->CreatePaymentPlanDetails['SendAutomaticGiroPaymentForm']);
- }
-
- public function testInvoiceRequestObjectWithRelativeDiscountOnTwoProducts()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountExVat(240.00)
- ->setAmountIncVat(300.00)
- ->setDescription("CD")
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountId("1")
- ->setDiscountPercent(10)
- ->setDescription("RelativeDiscount")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->useInvoicePayment()
- ->prepareRequest();
- //couponrow
- $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
- $this->assertEquals('RelativeDiscount', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
- $this->assertEquals(-60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
- $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
- }
-
- public function testPaymentPlanWithPriceAsDecimal()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(WebPayItem::orderRow()
- ->setArticleNumber("1")
- ->setQuantity(2)
- ->setAmountExVat(240.00)
- ->setAmountIncVat(300.00)
- ->setDescription("CD")
- )
- ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
- ->setCountryCode("SE")
- ->setCustomerReference("33")
- ->setOrderDate("2012-12-12")
- ->setCurrency("SEK")
- ->usePaymentPlanPayment('111111')
- ->prepareRequest();
- //couponrow
-
- $this->assertEquals(300.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
- $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- }
-
-
- /**
- * Tests for rounding**
- */
-
- public function testDiscountSetAsExVatWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()->setAmountExVat(8))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment('111111')
- ->prepareRequest();
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
-
- $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
-
- }
-
- public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountExVat(8)
- ->setVatPercent(0))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment('111111')
- ->prepareRequest();
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
-
- $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
-
- }
-
- public function testDiscountPercentAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment('111111')
- ->prepareRequest();
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
-
- $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
-
- }
-
- public function testFeeSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountExVat(80.00)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment('111111')
- ->prepareRequest();
-
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
-
- $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
-
- }
-
- public function testOrderRowPriceSetAsInkVatAndVatPercentSetAmountAsIncVat()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment('111111')
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
- public function testFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addFee(WebPayItem::shippingFee()
- ->setAmountIncVat(100.00)
- ->setVatPercent(24)
- )
- ->addFee(WebPayItem::invoiceFee()
- ->setAmountIncVat(100.00)
- ->setVatPercent(24)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment('111111')
- ->prepareRequest();
-
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
-
- $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
-
- $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
-
- }
-
- public function testDiscountSetAsIncVatWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment('111111')
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
-
- }
-
- public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::fixedDiscount()
- ->setAmountIncVat(10)
- ->setVatPercent(0))
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->usePaymentPlanPayment('111111')
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
-
-
- public function testDiscountPercentAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
- {
- $config = ConfigurationService::getDefaultConfig();
- $request = WebPay::createOrder($config)
- ->addOrderRow(
- WebPayItem::orderRow()
- ->setAmountIncVat(123.9876)
- ->setVatPercent(24)
- ->setQuantity(1)
- )
- ->addDiscount(WebPayItem::relativeDiscount()
- ->setDiscountPercent(10)
- )
- ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
- ->setCountryCode("SE")
- ->setOrderDate("2012-12-12")
- ->useInvoicePayment()
- ->prepareRequest();
- $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
- $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
- $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
-
- }
+ /**
+ * Use to get paymentPlanParams to be able to test PaymentPlanRequest
+ * @return type
+ */
+ public function getGetPaymentPlanParamsForTesting()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $addressRequest = WebPay::getPaymentPlanParams($config);
+ $response = $addressRequest
+ ->setCountryCode("SE")
+ ->doRequest();
+
+ return $response->campaignCodes[0]->campaignCode;
+ }
+
+ public function testPaymentPlanRequestObjectSpecifics()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $rowFactory = new TestUtil();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(TestUtil::createOrderRow())
+ ->run($rowFactory->buildShippingFee())
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setClientOrderNumber("nr26")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePaymentPlanPayment("camp1")// returnerar InvoiceOrder object
+ ->prepareRequest();
+
+ $this->assertEquals('camp1', $request->request->CreateOrderInformation->CreatePaymentPlanDetails['CampaignCode']);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->CreatePaymentPlanDetails['SendAutomaticGiroPaymentForm']);
+ }
+
+ public function testInvoiceRequestObjectWithRelativeDiscountOnTwoProducts()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountExVat(240.00)
+ ->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountId("1")
+ ->setDiscountPercent(10)
+ ->setDescription("RelativeDiscount")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ //couponrow
+ $this->assertEquals('1', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->ArticleNumber);
+ $this->assertEquals('RelativeDiscount', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Description);
+ $this->assertEquals(-60.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(1, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->NumberOfUnits);
+ $this->assertEquals('', $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->Unit);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->DiscountPercent);
+ }
+
+ public function testPaymentPlanWithPriceAsDecimal()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(WebPayItem::orderRow()
+ ->setArticleNumber("1")
+ ->setQuantity(2)
+ ->setAmountExVat(240.00)
+ ->setAmountIncVat(300.00)
+ ->setDescription("CD")
+ )
+ ->addCustomerDetails(WebPayItem::individualCustomer()->setNationalIdNumber(194605092222))
+ ->setCountryCode("SE")
+ ->setCustomerReference("33")
+ ->setOrderDate("2012-12-12")
+ ->setCurrency("SEK")
+ ->usePaymentPlanPayment('111111')
+ ->prepareRequest();
+ //couponrow
+
+ $this->assertEquals(300.00, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(2, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->NumberOfUnits);
+ $this->assertEquals(25, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ }
+
+
+ /**
+ * Tests for rounding**
+ */
+
+ public function testDiscountSetAsExVatWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()->setAmountExVat(8))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment('111111')
+ ->prepareRequest();
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+
+ $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+
+ }
+
+ public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountExVat(8)
+ ->setVatPercent(0))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment('111111')
+ ->prepareRequest();
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+
+ $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+
+ }
+
+ public function testDiscountPercentAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment('111111')
+ ->prepareRequest();
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+
+ $this->assertEquals(-8, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+
+ }
+
+ public function testFeeSetAsExVatAndVatPercentWhenPriceSetAsExVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountExVat(80.00)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+
+ $this->assertEquals(80, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+
+ }
+
+ public function testOrderRowPriceSetAsInkVatAndVatPercentSetAmountAsIncVat()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+ public function testFeeSetAsIncVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addFee(WebPayItem::shippingFee()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(24)
+ )
+ ->addFee(WebPayItem::invoiceFee()
+ ->setAmountIncVat(100.00)
+ ->setVatPercent(24)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment('111111')
+ ->prepareRequest();
+
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+
+ $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+
+ $this->assertEquals(100, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][2]->VatPercent);
+
+ }
+
+ public function testDiscountSetAsIncVatWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()->setAmountIncVat(10))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment('111111')
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+
+ }
+
+ public function testDiscountSetAsExVatAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::fixedDiscount()
+ ->setAmountIncVat(10)
+ ->setVatPercent(0))
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->usePaymentPlanPayment('111111')
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-10, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(0, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
+
+
+ public function testDiscountPercentAndVatPercentWhenPriceSetAsIncVatAndVatPercent()
+ {
+ $config = ConfigurationService::getDefaultConfig();
+ $request = WebPay::createOrder($config)
+ ->addOrderRow(
+ WebPayItem::orderRow()
+ ->setAmountIncVat(123.9876)
+ ->setVatPercent(24)
+ ->setQuantity(1)
+ )
+ ->addDiscount(WebPayItem::relativeDiscount()
+ ->setDiscountPercent(10)
+ )
+ ->addCustomerDetails(TestUtil::createIndividualCustomer("SE"))
+ ->setCountryCode("SE")
+ ->setOrderDate("2012-12-12")
+ ->useInvoicePayment()
+ ->prepareRequest();
+ $this->assertEquals(123.9876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ $this->assertEquals(-12.39876, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->PricePerUnit);
+ $this->assertEquals(24, $request->request->CreateOrderInformation->OrderRows['OrderRow'][1]->VatPercent);
+ $this->assertTrue($request->request->CreateOrderInformation->OrderRows['OrderRow'][0]->PriceIncludingVat);
+
+ }
}