diff --git a/README.md b/README.md index 48d767f9..c346c42a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # OpenCart - Svea payment module -##Version 2.7.0 +##Version 2.7.1 * Supports OpenCart 1.4.9 or higher * Requires PHP 5.3 or higher (namespace support) * Feature _Product Price Widget_ and admin functions requires [vQmod](https://code.google.com/p/vqmod/) to be installed in your Opencart installation diff --git a/docs/info.json b/docs/info.json index a283b9ba..c4c24b89 100644 --- a/docs/info.json +++ b/docs/info.json @@ -1,6 +1,6 @@ { "module_name": "Opencart", - "module_version": "2.7.0", + "module_version": "2.7.1", "module_shop_version_support": [ "1.4.9", " - ", diff --git a/src/admin/controller/payment/svea_card.php b/src/admin/controller/payment/svea_card.php index 3d8d3852..064f4aae 100644 --- a/src/admin/controller/payment/svea_card.php +++ b/src/admin/controller/payment/svea_card.php @@ -1,7 +1,7 @@ load->language('payment/svea_card'); @@ -46,7 +46,8 @@ public function index() { $this->data['button_cancel'] = $this->language->get('button_cancel'); $this->data['tab_general'] = $this->language->get('tab_general'); - $this->data['svea_version'] = $this->getSveaVersion(); + $this->data['svea_version_text'] = $this->getSveaVersion(); + $this->data['svea_version'] = $this->svea_version; //Credentials $this->data['entry_test'] = $this->language->get('entry_test'); $this->data['entry_prod'] = $this->language->get('entry_prod'); diff --git a/src/admin/controller/payment/svea_directbank.php b/src/admin/controller/payment/svea_directbank.php index 867c7f20..0f413b4b 100644 --- a/src/admin/controller/payment/svea_directbank.php +++ b/src/admin/controller/payment/svea_directbank.php @@ -1,7 +1,7 @@ load->language('payment/svea_directbank'); @@ -31,7 +31,8 @@ public function index() { $this->data['text_enabled'] = $this->language->get('text_enabled'); $this->data['text_disabled'] = $this->language->get('text_disabled'); $this->data['text_all_zones'] = $this->language->get('text_all_zones'); - $this->data['svea_version'] = $this->getSveaVersion(); + $this->data['svea_version_text'] = $this->getSveaVersion(); + $this->data['svea_version'] = $this->svea_version; $this->data['entry_order_status'] = $this->language->get('entry_order_status'); diff --git a/src/admin/controller/payment/svea_invoice.php b/src/admin/controller/payment/svea_invoice.php index 8fe354b9..f633d37f 100644 --- a/src/admin/controller/payment/svea_invoice.php +++ b/src/admin/controller/payment/svea_invoice.php @@ -2,7 +2,7 @@ class ControllerPaymentsveainvoice extends Controller { private $error = array(); - protected $svea_version = '2.7.0'; + protected $svea_version = '2.7.1'; public function index() { $this->load->language('payment/svea_invoice'); @@ -20,7 +20,8 @@ public function index() { } $this->data['heading_title'] = $this->language->get('heading_title'); - $this->data['svea_version'] = $this->getSveaVersion(); + $this->data['svea_version_text'] = $this->getSveaVersion(); + $this->data['svea_version'] = $this->svea_version; $this->data['text_enabled'] = $this->language->get('text_enabled'); $this->data['text_disabled'] = $this->language->get('text_disabled'); diff --git a/src/admin/controller/payment/svea_partpayment.php b/src/admin/controller/payment/svea_partpayment.php index 857a7c0e..fadaaea4 100644 --- a/src/admin/controller/payment/svea_partpayment.php +++ b/src/admin/controller/payment/svea_partpayment.php @@ -1,7 +1,7 @@ load->language('payment/svea_partpayment'); @@ -19,7 +19,8 @@ public function index() { $this->session->data['success'] = $this->language->get('text_success'); $this->redirect(HTTPS_SERVER . 'index.php?route=extension/payment&token=' . $this->session->data['token']); } - $this->data['svea_version'] = $this->getSveaVersion(); + $this->data['svea_version_text'] = $this->getSveaVersion(); + $this->data['svea_version'] = $this->svea_version; $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['text_enabled'] = $this->language->get('text_enabled'); @@ -215,23 +216,23 @@ private function loadPaymentPlanParams(){ // we need to use the database config settings directly, as $this->config may contain old data that we just edited $settings = $this->model_setting_setting->getSetting('svea_partpayment'); - $username = $settings['svea_partpayment_username_' . $countryCode[$i]]; - $password = $settings['svea_partpayment_password_' . $countryCode[$i]]; + $username = $settings['svea_partpayment_username_' . $countryCode[$i]]; + $password = $settings['svea_partpayment_password_' . $countryCode[$i]]; $client_id = $settings['svea_partpayment_clientno_' . $countryCode[$i]]; $testmode = $settings['svea_partpayment_testmode_' . $countryCode[$i]]; - + //get params if config is set - if($username != "" && $password != "" && $client_id != ""){ - - if ( $testmode !== NULL){ + if($username != "" && $password != "" && $client_id != ""){ + + if ( $testmode !== NULL){ $conf = ($testmode == "1") ? new OpencartSveaConfigTest($this->config) : new OpencartSveaConfig($this->config); - + // need to update $this->config with username et al from $settings $conf->config->set('svea_partpayment_username_' . $countryCode[$i], $username); $conf->config->set('svea_partpayment_password_' . $countryCode[$i], $password); - $conf->config->set('svea_partpayment_clientno_' . $countryCode[$i], $client_id); - - $svea_params = WebPay::getPaymentPlanParams($conf); + $conf->config->set('svea_partpayment_clientno_' . $countryCode[$i], $client_id); + + $svea_params = WebPay::getPaymentPlanParams($conf); try { $svea_params = $svea_params->setCountryCode($countryCode[$i]) diff --git a/src/admin/view/template/payment/svea_card.tpl b/src/admin/view/template/payment/svea_card.tpl index afdf62c8..a0a518e1 100644 --- a/src/admin/view/template/payment/svea_card.tpl +++ b/src/admin/view/template/payment/svea_card.tpl @@ -16,7 +16,8 @@ Version - +
+ : diff --git a/src/admin/view/template/payment/svea_directbank.tpl b/src/admin/view/template/payment/svea_directbank.tpl index 46a6abc8..b2b0c3d3 100644 --- a/src/admin/view/template/payment/svea_directbank.tpl +++ b/src/admin/view/template/payment/svea_directbank.tpl @@ -15,7 +15,8 @@ Version - +
+ diff --git a/src/admin/view/template/payment/svea_invoice.tpl b/src/admin/view/template/payment/svea_invoice.tpl index 46fce7a8..93abf745 100644 --- a/src/admin/view/template/payment/svea_invoice.tpl +++ b/src/admin/view/template/payment/svea_invoice.tpl @@ -17,7 +17,8 @@ Version - + + diff --git a/src/admin/view/template/payment/svea_partpayment.tpl b/src/admin/view/template/payment/svea_partpayment.tpl index d738ff75..af280277 100644 --- a/src/admin/view/template/payment/svea_partpayment.tpl +++ b/src/admin/view/template/payment/svea_partpayment.tpl @@ -15,7 +15,8 @@ Version - + + diff --git a/src/admin/view/template/total/svea_fee.tpl b/src/admin/view/template/total/svea_fee.tpl index 238053aa..7c292f37 100644 --- a/src/admin/view/template/total/svea_fee.tpl +++ b/src/admin/view/template/total/svea_fee.tpl @@ -22,7 +22,7 @@ - +
Version2.7.02.7.1
diff --git a/src/catalog/controller/payment/svea_card.php b/src/catalog/controller/payment/svea_card.php index 18e47a82..405dff2d 100644 --- a/src/catalog/controller/payment/svea_card.php +++ b/src/catalog/controller/payment/svea_card.php @@ -39,7 +39,7 @@ public function index() { $this->load->language('payment/svea_card'); include(DIR_APPLICATION.'../svea/Includes.php'); - $conf = ($this->config->get('svea_card_testmode') == 1) ? (new OpencartSveaConfigTest($this->config)) : new OpencartSveaConfig($this->config); + $conf = ($this->config->get('svea_card_testmode') == 1) ? (new OpencartSveaConfigTest($this->config, 'svea_card')) : new OpencartSveaConfig($this->config, 'svea_card'); $svea = WebPay::createOrder($conf); @@ -110,7 +110,7 @@ public function responseSvea(){ $countryCode = $order_info['payment_iso_code_2']; //Testmode - $conf = ($this->config->get('svea_card_testmode') == 1) ? (new OpencartSveaConfigTest($this->config)) : new OpencartSveaConfig($this->config); + $conf = ($this->config->get('svea_card_testmode') == 1) ? (new OpencartSveaConfigTest($this->config, 'svea_card')) : new OpencartSveaConfig($this->config, 'svea_card'); $resp = new SveaResponse($_REQUEST, $countryCode, $conf); //HostedPaymentResponse $response = $resp->getResponse(); $clean_clientOrderNumber = str_replace('.err', '', $response->clientOrderNumber);//bugfix for gateway concatinating ".err" on number @@ -138,7 +138,7 @@ public function callbackSvea(){ $this->load->language('payment/svea_card'); include(DIR_APPLICATION.'../svea/Includes.php'); - $conf = ($this->config->get('svea_card_testmode') == 1) ? (new OpencartSveaConfigTest($this->config)) : new OpencartSveaConfig($this->config); + $conf = ($this->config->get('svea_card_testmode') == 1) ? (new OpencartSveaConfigTest($this->config, 'svea_card')) : new OpencartSveaConfig($this->config, 'svea_card'); $resp = new SveaResponse($_REQUEST, 'SE', $conf); //HostedPaymentResponse. Countrycode not important on hosted payments. $response = $resp->getResponse(); $clean_clientOrderNumber = str_replace('.err', '', $response->clientOrderNumber);//bugfix for gateway concatinating ".err" on number diff --git a/src/catalog/controller/payment/svea_directbank.php b/src/catalog/controller/payment/svea_directbank.php index b59f1c26..03a10892 100644 --- a/src/catalog/controller/payment/svea_directbank.php +++ b/src/catalog/controller/payment/svea_directbank.php @@ -33,7 +33,7 @@ public function index() { include(DIR_APPLICATION.'../svea/Includes.php'); //Testmode - $conf = ($this->config->get('svea_directbank_testmode') == 1) ? (new OpencartSveaConfigTest($this->config)) : new OpencartSveaConfig($this->config); + $conf = ($this->config->get('svea_directbank_testmode') == 1) ? (new OpencartSveaConfigTest($this->config, 'svea_directbank')) : new OpencartSveaConfig($this->config, 'svea_directbank'); try { $svea = WebPay::getPaymentMethods($conf); $this->data['sveaMethods'] = $svea @@ -62,13 +62,13 @@ public function redirectSvea(){ $this->load->language('payment/svea_directbank'); include(DIR_APPLICATION.'../svea/Includes.php'); - $conf = ($this->config->get('svea_directbank_testmode') == 1) ? (new OpencartSveaConfigTest($this->config)) : new OpencartSveaConfig($this->config); + $conf = ($this->config->get('svea_directbank_testmode') == 1) ? (new OpencartSveaConfigTest($this->config, 'svea_directbank')) : new OpencartSveaConfig($this->config, 'svea_directbank'); $svea = WebPay::createOrder($conf); //Get order information - $order = $this->model_checkout_order->getOrder($this->session->data['order_id']); + $order = $this->model_checkout_order->getOrder($this->session->data['order_id']); $currencyValue = (floatval(VERSION) >= 1.5) ? $order['currency_value'] : $order['value']; - + //Product rows $products = $this->cart->getProducts(); $svea = $this->addOrderRowsToHostedServiceOrder($svea, $products, $currencyValue); @@ -119,13 +119,13 @@ public function redirectSvea(){ ->setCardPageLanguage($payPageLanguage) ->getPaymentForm() ; - } + } catch (Exception $e) { $this->log->write($e->getMessage()); echo '
Logged Svea Error
'; exit(); } - + // 2.x below //Save order but Void it while order status is unsure //$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], 0,'Sent to Svea gateway.'); // 2.x @@ -170,7 +170,7 @@ public function responseSvea(){ $countryCode = $order_info['payment_iso_code_2']; //Testmode - $conf = ($this->config->get('svea_directbank_testmode') == 1) ? (new OpencartSveaConfigTest($this->config)) : new OpencartSveaConfig($this->config); + $conf = ($this->config->get('svea_directbank_testmode') == 1) ? (new OpencartSveaConfigTest($this->config, 'svea_directbank')) : new OpencartSveaConfig($this->config, 'svea_directbank'); $resp = new SveaResponse($_REQUEST, $countryCode, $conf); $response = $resp->getResponse(); $clean_clientOrderNumber = str_replace('.err', '', $response->clientOrderNumber);//bugfix for gateway concatinating ".err" on number @@ -197,7 +197,7 @@ public function callbackSvea(){ $this->load->language('payment/svea_directbank'); include(DIR_APPLICATION.'../svea/Includes.php'); - $conf = ($this->config->get('svea_directbank_testmode') == 1) ? (new OpencartSveaConfigTest($this->config)) : new OpencartSveaConfig($this->config); + $conf = ($this->config->get('svea_directbank_testmode') == 1) ? (new OpencartSveaConfigTest($this->config, 'svea_directbank')) : new OpencartSveaConfig($this->config, 'svea_directbank'); $resp = new SveaResponse($_REQUEST, 'SE', $conf); //HostedPaymentResponse. Countrycode not important on hosted payments. $response = $resp->getResponse(); $clean_clientOrderNumber = str_replace('.err', '', $response->clientOrderNumber);//bugfix for gateway concatinating ".err" on number diff --git a/src/catalog/controller/payment/svea_invoice.php b/src/catalog/controller/payment/svea_invoice.php index ee6f781e..0f642a14 100644 --- a/src/catalog/controller/payment/svea_invoice.php +++ b/src/catalog/controller/payment/svea_invoice.php @@ -86,7 +86,7 @@ public function confirm() { //Testmode if($this->config->get('svea_invoice_testmode_'.$countryCode) !== NULL){ $conf = ( $this->config->get('svea_invoice_testmode_'.$countryCode) == "1" ) - ? new OpencartSveaConfigTest($this->config) : new OpencartSveaConfig($this->config); + ? new OpencartSveaConfigTest($this->config,'svea_invoice') : new OpencartSveaConfig($this->config,'svea_invoice'); } else { $response = array("error" => $this->responseCodes(40001,"The country is not supported for this paymentmethod")); @@ -309,7 +309,7 @@ public function getAddress() { $countryCode = $order['payment_iso_code_2']; //Testmode $conf = ( $this->config->get('svea_invoice_testmode_'.$countryCode) == '1' ) - ? new OpencartSveaConfigTest($this->config) : new OpencartSveaConfig($this->config); + ? new OpencartSveaConfigTest($this->config,'svea_invoice') : new OpencartSveaConfig($this->config,'svea_invoice'); $svea = WebPay::getAddresses($conf) ->setOrderTypeInvoice() diff --git a/src/catalog/controller/payment/svea_partpayment.php b/src/catalog/controller/payment/svea_partpayment.php index ec2194f8..6ee02431 100644 --- a/src/catalog/controller/payment/svea_partpayment.php +++ b/src/catalog/controller/payment/svea_partpayment.php @@ -88,7 +88,7 @@ public function confirm() { $countryCode = $order['payment_iso_code_2']; //Testmode if ($this->config->get('svea_partpayment_testmode_' . $countryCode) !== NULL) { - $conf = $this->config->get('svea_partpayment_testmode_' . $countryCode) == "1" ? new OpencartSveaConfigTest($this->config) : new OpencartSveaConfig($this->config); + $conf = $this->config->get('svea_partpayment_testmode_' . $countryCode) == "1" ? new OpencartSveaConfigTest($this->config,'svea_partpayment') : new OpencartSveaConfig($this->config,'svea_partpayment'); } else { $response = array("error" => $this->responseCodes(40001, "The country is not supported for this paymentmethod")); echo json_encode($response); @@ -106,10 +106,10 @@ public function confirm() { $currencyValue = $currency_info['value']; //Products - $this->load->language('payment/svea_partpayment'); + $this->load->language('payment/svea_partpayment'); $svea = $this->addOrderRowsToWebServiceOrder($svea, $products, $currencyValue); - //extra charge addons like shipping and invoice fee + //extra charge addons like shipping and invoice fee $addons = $this->addTaxRateToAddons(); $svea = $this->addAddonRowsToSveaOrder($svea, $addons, $currencyValue); @@ -121,7 +121,7 @@ public function confirm() { $addressArr[1] = $order['payment_address_1']; $addressArr[2] = ""; } - + $ssn = (isset($_GET['ssn'])) ? $_GET['ssn'] : 0; $item = Item::individualCustomer(); @@ -135,13 +135,13 @@ public function confirm() { ->setPhoneNumber($order['telephone']); if ($order["payment_iso_code_2"] == "DE" || $order["payment_iso_code_2"] == "NL") { - - $item = $item->setInitials($_GET['initials']) - ->setBirthDate($_GET['birthYear'], $_GET['birthMonth'], $_GET['birthDay']); + if($order["payment_iso_code_2"] == "NL") { + $item = $item->setInitials($_GET['initials']); + } + $item = $item->setBirthDate($_GET['birthYear'], $_GET['birthMonth'], $_GET['birthDay']); } - $svea = $svea->addCustomerDetails($item); - + try { $svea = $svea ->setCountryCode($countryCode) @@ -220,7 +220,7 @@ private function getAddress($ssn) { $order = $this->model_checkout_order->getOrder($this->session->data['order_id']); $countryCode = $order['payment_iso_code_2']; //Testmode - $conf = $this->config->get('svea_partpayment_testmode_' . $countryCode) == "1" ? new OpencartSveaConfigTest($this->config) : new OpencartSveaConfig($this->config); + $conf = $this->config->get('svea_partpayment_testmode_' . $countryCode) == "1" ? new OpencartSveaConfigTest($this->config,'svea_partpayment') : new OpencartSveaConfig($this->config,'svea_partpayment'); $svea = WebPay::getAddresses($conf) ->setOrderTypePaymentPlan() diff --git a/src/svea/AdminService/AdminServiceRequest.php b/src/svea/AdminService/AdminServiceRequest.php index 6299d38e..0771994e 100644 --- a/src/svea/AdminService/AdminServiceRequest.php +++ b/src/svea/AdminService/AdminServiceRequest.php @@ -23,7 +23,7 @@ abstract class AdminServiceRequest { /** * Set up the soap client and perform the soap call, with the soap action and prepared request from the relevant subclass. - * Returns the apropriate request response class, as determined by SveaResponse matching on request action. + * Returns the appropriate request response class, as determined by SveaResponse matching on request action. */ public function doRequest( $resendOrderWithFlippedPriceIncludingVat = false ) { @@ -80,8 +80,8 @@ abstract function prepareRequest(); // prepare the soap request data abstract function validate(); // validate is defined by subclasses, should validate all elements required for call is present /** - * the integration package ConfigurationProvider::INVOICE_TYPE and ::PAYMENTPLAN_TYPE constanst are all caps, whereas the admin service - * enumeration used in the calls are CamelCase. This function converts the package constants so they work with the admin service. + * the integration package 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. */ public static function CamelCaseOrderType( $orderTypeAsConst ) { switch( $orderTypeAsConst ) { @@ -138,7 +138,7 @@ protected function getAdminSoapOrderRowsFromBuilderOrderRowsUsingVatFlag($builde $amount, $orderRow->unit, $orderRow->vatPercent, - $priceIncludingVat + $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" ); } @@ -181,7 +181,7 @@ protected function getAdminSoapNumberedOrderRowsFromBuilderOrderRowsUsingVatFlag $orderRow->creditInvoiceId, $orderRow->invoiceId, $orderRow->rowNumber, - $priceIncludingVat + $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" ); diff --git a/src/svea/AdminService/AdminServiceResponse/GetOrdersResponse.php b/src/svea/AdminService/AdminServiceResponse/GetOrdersResponse.php index c4a0ad45..05b6a466 100644 --- a/src/svea/AdminService/AdminServiceResponse/GetOrdersResponse.php +++ b/src/svea/AdminService/AdminServiceResponse/GetOrdersResponse.php @@ -13,7 +13,7 @@ class GetOrdersResponse extends AdminServiceResponse { public $changedDate; /** @var string $clientId -- Id that identifies a client in sveawebpay system */ public $clientId; - /** @var string $clientOrderId -- Order number from client's ordersystem */ + /** @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; @@ -92,10 +92,10 @@ protected function formatObject($message) { //individual customer? if( $order->Customer->CustomerType === "Individual" ) { - + //stdClass Object //( - // [ChangedDate] => + // [ChangedDate] => // [ClientId] => 79021 // [ClientOrderId] => 449 // [CreatedDate] => 2014-05-19T16:04:54.787 @@ -109,34 +109,34 @@ protected function formatObject($message) { // [Customer] => stdClass Object // ( // [CoAddress] => c/o Eriksson, Erik - // [CompanyIdentity] => + // [CompanyIdentity] => // [CountryCode] => SE // [CustomerType] => Individual - // [Email] => + // [Email] => // [FullName] => Persson, Tess T - // [HouseNumber] => + // [HouseNumber] => // [IndividualIdentity] => stdClass Object // ( - // [BirthDate] => - // [FirstName] => - // [Initials] => - // [LastName] => + // [BirthDate] => + // [FirstName] => + // [Initials] => + // [LastName] => // ) // // [Locality] => Stan // [NationalIdNumber] => 194605092222 - // [PhoneNumber] => - // [PublicKey] => + // [PhoneNumber] => + // [PublicKey] => // [Street] => Testgatan 1 // [ZipCode] => 99999 // ) // // [CustomerId] => 1000117 - // [CustomerReference] => - // [DeliveryAddress] => + // [CustomerReference] => + // [DeliveryAddress] => // [IsPossibleToAdminister] => false // [IsPossibleToCancel] => true - // [Notes] => + // [Notes] => // [OrderDeliveryStatus] => Created // [OrderRows] => stdClass Object // ( @@ -144,64 +144,64 @@ protected function formatObject($message) { // ( // [0] => stdClass Object // ( - // [ArticleNumber] => + // [ArticleNumber] => // [Description] => Dyr produkt 25% // [DiscountPercent] => 0.00 // [NumberOfUnits] => 2.00 // [PriceIncludingVat] => false // [PricePerUnit] => 2000.00 - // [Unit] => + // [Unit] => // [VatPercent] => 25.00 - // [CreditInvoiceId] => - // [InvoiceId] => + // [CreditInvoiceId] => + // [InvoiceId] => // [RowNumber] => 1 // [Status] => NotDelivered // ) // // [1] => stdClass Object // ( - // [ArticleNumber] => + // [ArticleNumber] => // [Description] => Testprodukt 1kr 25% // [DiscountPercent] => 0.00 // [NumberOfUnits] => 1.00 // [PriceIncludingVat] => false // [PricePerUnit] => 1.00 - // [Unit] => + // [Unit] => // [VatPercent] => 25.00 - // [CreditInvoiceId] => - // [InvoiceId] => + // [CreditInvoiceId] => + // [InvoiceId] => // [RowNumber] => 2 // [Status] => NotDelivered // ) // // [2] => stdClass Object // ( - // [ArticleNumber] => + // [ArticleNumber] => // [Description] => Fastpris (Fast fraktpris) // [DiscountPercent] => 0.00 // [NumberOfUnits] => 1.00 // [PriceIncludingVat] => false // [PricePerUnit] => 4.00 - // [Unit] => + // [Unit] => // [VatPercent] => 25.00 - // [CreditInvoiceId] => - // [InvoiceId] => + // [CreditInvoiceId] => + // [InvoiceId] => // [RowNumber] => 3 // [Status] => NotDelivered // ) // // [3] => stdClass Object // ( - // [ArticleNumber] => + // [ArticleNumber] => // [Description] => Svea Fakturaavgift:: 20.00kr (SE) // [DiscountPercent] => 0.00 // [NumberOfUnits] => 1.00 // [PriceIncludingVat] => false // [PricePerUnit] => 20.00 - // [Unit] => + // [Unit] => // [VatPercent] => 0.00 - // [CreditInvoiceId] => - // [InvoiceId] => + // [CreditInvoiceId] => + // [InvoiceId] => // [RowNumber] => 4 // [Status] => NotDelivered // ) @@ -212,12 +212,12 @@ protected function formatObject($message) { // // [OrderStatus] => Active // [OrderType] => Invoice - // [PaymentPlanDetails] => - // [PendingReasons] => + // [PaymentPlanDetails] => + // [PendingReasons] => // [SveaOrderId] => 348629 // [SveaWillBuy] => true //) - + $this->customer = new \Svea\IndividualCustomer; $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber); @@ -237,12 +237,12 @@ protected function formatObject($message) { } if( $order->Customer->CustomerType === "Company" ) { - + //stdClass Object //( - // [ChangedDate] => + // [ChangedDate] => // [ClientId] => 79021 - // [ClientOrderId] => + // [ClientOrderId] => // [CreatedDate] => 2014-12-29T16:41:58.897 // [CreditReportStatus] => stdClass Object // ( @@ -256,30 +256,30 @@ protected function formatObject($message) { // [CoAddress] => c/o Eriksson, Erik // [CompanyIdentity] => stdClass Object // ( - // [CompanyIdentification] => - // [CompanyVatNumber] => + // [CompanyIdentification] => + // [CompanyVatNumber] => // ) // // [CountryCode] => SE // [CustomerType] => Company - // [Email] => + // [Email] => // [FullName] => Persson, Tess T - // [HouseNumber] => - // [IndividualIdentity] => + // [HouseNumber] => + // [IndividualIdentity] => // [Locality] => Stan // [NationalIdNumber] => 164608142222 - // [PhoneNumber] => - // [PublicKey] => + // [PhoneNumber] => + // [PublicKey] => // [Street] => Testgatan 1 // [ZipCode] => 99999 // ) // // [CustomerId] => 1000119 - // [CustomerReference] => - // [DeliveryAddress] => + // [CustomerReference] => + // [DeliveryAddress] => // [IsPossibleToAdminister] => false // [IsPossibleToCancel] => true - // [Notes] => + // [Notes] => // [OrderDeliveryStatus] => Created // [OrderRows] => stdClass Object // ( @@ -295,8 +295,8 @@ protected function formatObject($message) { // [PricePerUnit] => 100.00 // [Unit] => st // [VatPercent] => 25.00 - // [CreditInvoiceId] => - // [InvoiceId] => + // [CreditInvoiceId] => + // [InvoiceId] => // [RowNumber] => 1 // [Status] => NotDelivered // ) @@ -311,8 +311,8 @@ protected function formatObject($message) { // [PricePerUnit] => 1000.00 // [Unit] => st // [VatPercent] => 25.00 - // [CreditInvoiceId] => - // [InvoiceId] => + // [CreditInvoiceId] => + // [InvoiceId] => // [RowNumber] => 2 // [Status] => NotDelivered // ) @@ -323,11 +323,11 @@ protected function formatObject($message) { // // [OrderStatus] => Active // [OrderType] => Invoice - // [PaymentPlanDetails] => - // [PendingReasons] => + // [PaymentPlanDetails] => + // [PendingReasons] => // [SveaOrderId] => 499329 // [SveaWillBuy] => true - //) + //) $this->customer = new \Svea\CompanyCustomer; $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber); diff --git a/src/svea/AdminService/AdminServiceResponse/UpdateOrderResponse.php b/src/svea/AdminService/AdminServiceResponse/UpdateOrderResponse.php new file mode 100644 index 00000000..19c6016e --- /dev/null +++ b/src/svea/AdminService/AdminServiceResponse/UpdateOrderResponse.php @@ -0,0 +1,25 @@ +formatObject($message); + } + + /** + * Parses response and sets attributes. + */ + protected function formatObject($message) { + parent::formatObject($message); + + if ($this->accepted == 1) { + // nothing to do for updateOrderRequest response + } + } +} diff --git a/src/svea/AdminService/CreditOrderRowsRequest.php b/src/svea/AdminService/CreditOrderRowsRequest.php index 2d346b3c..092b4bdf 100644 --- a/src/svea/AdminService/CreditOrderRowsRequest.php +++ b/src/svea/AdminService/CreditOrderRowsRequest.php @@ -52,8 +52,7 @@ public function prepareRequest( $resendOrderWithFlippedPriceIncludingVat = false ), $this->orderBuilder->conf->getClientNumber( ($this->orderBuilder->orderType), $this->orderBuilder->countryCode ), $this->orderBuilder->distributionType, - $this->orderBuilder->invoiceId, - + $this->orderBuilder->invoiceId, $this->orderRows, $this->rowNumbers ); diff --git a/src/svea/AdminService/DeliverOrderRowsRequest.php b/src/svea/AdminService/DeliverOrderRowsRequest.php index a2e2e4d5..fb5c85a6 100644 --- a/src/svea/AdminService/DeliverOrderRowsRequest.php +++ b/src/svea/AdminService/DeliverOrderRowsRequest.php @@ -13,12 +13,6 @@ class DeliverOrderRowsRequest extends AdminServiceRequest { /** @var DeliverOrderRowBuilder $orderBuilder */ public $orderBuilder; - -// /** @var SoapVar[] $rowNumbers initally empty, contains the indexes of all order rows that will be delivered */ -// public $rowNumbers; -// -// /** @var SoapVar[] $orderRows initially empty, specifies any additional deliver order rows to deliver */ -// public $orderRows; /** * @param deliverOrderRowsBuilder $orderBuilder @@ -26,8 +20,6 @@ class DeliverOrderRowsRequest extends AdminServiceRequest { public function __construct($deliverOrderRowsBuilder) { $this->action = "DeliverPartial"; $this->orderBuilder = $deliverOrderRowsBuilder; -// $this->rowNumbers = array(); -// $this->orderRows = array(); } /** @@ -39,33 +31,6 @@ public function prepareRequest() { $this->validateRequest(); -// foreach( $this->orderBuilder->deliverOrderRows as $orderRow ) { -// -// // handle different ways to spec an orderrow -// // inc + ex -// if( !isset($orderRow->vatPercent) && (isset($orderRow->amountExVat) && isset($orderRow->amountIncVat)) ) { -// $orderRow->vatPercent = \Svea\WebService\WebServiceRowFormatter::calculateVatPercentFromPriceExVatAndPriceIncVat($orderRow->amountIncVat, $orderRow->amountExVat ); -// } -// // % + inc -// elseif( (isset($orderRow->vatPercent) && isset($orderRow->amountIncVat)) && !isset($orderRow->amountExVat) ) { -// $orderRow->amountExVat = \Svea\WebService\WebServiceRowFormatter::convertIncVatToExVat($orderRow->amountIncVat, $orderRow->vatPercent); -// } -// // % + ex, no need to do anything -// -// $this->orderRows[] = new \SoapVar( -// new AdminSoap\OrderRow( -// $orderRow->articleNumber, -// $orderRow->name.": ".$orderRow->description, -// $orderRow->discountPercent, -// $orderRow->quantity, -// $orderRow->amountExVat, -// $orderRow->unit, -// $orderRow->vatPercent -// ), -// SOAP_ENC_OBJECT, null, null, 'OrderRow', "http://schemas.datacontract.org/2004/07/DataObjects.Webservice" -// ); -// } - foreach( $this->orderBuilder->rowsToDeliver as $rowToDeliver ) { $this->rowNumbers[] = new \SoapVar($rowToDeliver, XSD_LONG, null,null, 'long', "http://schemas.microsoft.com/2003/10/Serialization/Arrays"); } diff --git a/src/svea/AdminService/UpdateOrderRequest.php b/src/svea/AdminService/UpdateOrderRequest.php new file mode 100644 index 00000000..66689872 --- /dev/null +++ b/src/svea/AdminService/UpdateOrderRequest.php @@ -0,0 +1,83 @@ +action = "UpdateOrder"; + $this->orderBuilder = $updateOrderBuilder; + } + + /** + * populate and return soap request contents using AdminSoap helper classes to get the correct data format + * @return Svea\AdminSoap\UpdateOrderRequest + * @throws Svea\ValidationException + */ + public function prepareRequest() { + $this->validateRequest(); + $soapRequest = new AdminSoap\UpdateOrderRequest( + new AdminSoap\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; + } + +} diff --git a/src/svea/AdminService/admin_soap/AddOrderRowsRequest.php b/src/svea/AdminService/admin_soap/AddOrderRowsRequest.php index cb3d179a..b0cd876f 100644 --- a/src/svea/AdminService/admin_soap/AddOrderRowsRequest.php +++ b/src/svea/AdminService/admin_soap/AddOrderRowsRequest.php @@ -23,6 +23,7 @@ function __construct( $authentication, $clientId, $orderRows, $orderType, $sveaO $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, diff --git a/src/svea/AdminService/admin_soap/CancelOrderRequest.php b/src/svea/AdminService/admin_soap/CancelOrderRequest.php index 39fa9faa..6122807c 100644 --- a/src/svea/AdminService/admin_soap/CancelOrderRequest.php +++ b/src/svea/AdminService/admin_soap/CancelOrderRequest.php @@ -18,6 +18,7 @@ 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, diff --git a/src/svea/AdminService/admin_soap/CancelOrderRowsRequest.php b/src/svea/AdminService/admin_soap/CancelOrderRowsRequest.php index fad53f4c..f715917f 100644 --- a/src/svea/AdminService/admin_soap/CancelOrderRowsRequest.php +++ b/src/svea/AdminService/admin_soap/CancelOrderRowsRequest.php @@ -17,6 +17,7 @@ function __construct( $authentication, $clientId, $orderRowNumbers, $orderType, $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, diff --git a/src/svea/AdminService/admin_soap/CreditInvoiceRequest.php b/src/svea/AdminService/admin_soap/CreditInvoiceRequest.php index 8d876459..cac32829 100644 --- a/src/svea/AdminService/admin_soap/CreditInvoiceRequest.php +++ b/src/svea/AdminService/admin_soap/CreditInvoiceRequest.php @@ -23,6 +23,7 @@ function __construct( $authentication, $clientId, $invoiceDistributionType, $inv $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, diff --git a/src/svea/AdminService/admin_soap/DeliverOrdersRequest.php b/src/svea/AdminService/admin_soap/DeliverOrdersRequest.php index b4f0893e..976bbed8 100644 --- a/src/svea/AdminService/admin_soap/DeliverOrdersRequest.php +++ b/src/svea/AdminService/admin_soap/DeliverOrdersRequest.php @@ -16,6 +16,7 @@ function __construct( $authentication, $invoiceDistributionType, $ordersToDelive $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, diff --git a/src/svea/AdminService/admin_soap/DeliverPartialRequest.php b/src/svea/AdminService/admin_soap/DeliverPartialRequest.php index d382083e..4395d06e 100644 --- a/src/svea/AdminService/admin_soap/DeliverPartialRequest.php +++ b/src/svea/AdminService/admin_soap/DeliverPartialRequest.php @@ -19,6 +19,7 @@ function __construct( $authentication, $invoiceDistributionType, $orderToDeliver $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, diff --git a/src/svea/AdminService/admin_soap/GetOrderInformation.php b/src/svea/AdminService/admin_soap/GetOrderInformation.php index 76fff7f2..7846462d 100644 --- a/src/svea/AdminService/admin_soap/GetOrderInformation.php +++ b/src/svea/AdminService/admin_soap/GetOrderInformation.php @@ -14,6 +14,7 @@ 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/svea/AdminService/admin_soap/GetOrdersRequest.php b/src/svea/AdminService/admin_soap/GetOrdersRequest.php index 9ec591fc..a8afc306 100644 --- a/src/svea/AdminService/admin_soap/GetOrdersRequest.php +++ b/src/svea/AdminService/admin_soap/GetOrdersRequest.php @@ -14,6 +14,7 @@ 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/svea/AdminService/admin_soap/NumberedOrderRow.php b/src/svea/AdminService/admin_soap/NumberedOrderRow.php index 3269eadc..b6d52762 100644 --- a/src/svea/AdminService/admin_soap/NumberedOrderRow.php +++ b/src/svea/AdminService/admin_soap/NumberedOrderRow.php @@ -26,23 +26,22 @@ function __construct( $articleNumber, $description, $discountPercent, $quantity, //Webservice $this->ArticleNumber = new \SoapVar( $articleNumber, XSD_STRING, "-","--","ArticleNumber","http://schemas.datacontract.org/2004/07/DataObjects.Webservice"); - $this->Description = new \SoapVar( $description, XSD_STRING, + $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, + $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, + $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 } @@ -61,4 +60,5 @@ function __construct( $articleNumber, $description, $discountPercent, $quantity, "-","--","RowNumber","http://schemas.datacontract.org/2004/07/DataObjects.Admin.Service"); } + // Status -- optional, not sent by package } \ No newline at end of file diff --git a/src/svea/AdminService/admin_soap/UpdateOrderRequest.php b/src/svea/AdminService/admin_soap/UpdateOrderRequest.php new file mode 100644 index 00000000..cb6bb4a6 --- /dev/null +++ b/src/svea/AdminService/admin_soap/UpdateOrderRequest.php @@ -0,0 +1,34 @@ +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"); + } +} \ No newline at end of file diff --git a/src/svea/AdminService/admin_soap/UpdateOrderRowsRequest.php b/src/svea/AdminService/admin_soap/UpdateOrderRowsRequest.php index dcb77570..960e5752 100644 --- a/src/svea/AdminService/admin_soap/UpdateOrderRowsRequest.php +++ b/src/svea/AdminService/admin_soap/UpdateOrderRowsRequest.php @@ -19,6 +19,7 @@ function __construct( $authentication, $clientId, $orderType, $sveaOrderId, $upd $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, diff --git a/src/svea/BuildOrder/OrderBuilder.php b/src/svea/BuildOrder/OrderBuilder.php index 568f3cde..cbcea628 100644 --- a/src/svea/BuildOrder/OrderBuilder.php +++ b/src/svea/BuildOrder/OrderBuilder.php @@ -6,38 +6,41 @@ /** * OrderBuilder collects and prepares order data to be sent to Svea. It is the * parent of CreateOrderBuilder and DeliverOrderBuilder. - * + * * @author Kristian Grossman-Madsen, Anneli Halld'n, Daniel Brolund for Svea WebPay */ class OrderBuilder { /** @var boolean true indicates test mode, false indicates production mode */ public $testmode = false; - + /** @var \ConfigurationProvider $conf */ public $conf; - + /** @var \Svea\IndividualCustomer|\Svea\CompanyCustomer */ public $customerIdentity; - + /** @var \Svea\OrderRow [] array of OrderRow */ public $orderRows = array(); - + /** @var \Svea\ShippingFee [] array of ShippingFee */ public $shippingFeeRows = array(); - + /** @var \Svea\InvoiceFee [] array of InvoiceFee */ public $invoiceFeeRows = array(); - + /** @var \Svea\FixedDiscount [] array of FixedDiscount*/ public $fixedDiscountRows = array(); /** @var \Svea\RelativeDiscount [] array of RelativeDiscount */ - public $relativeDiscountRows = array(); - + public $relativeDiscountRows = array(); + + /** @var type array 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; @@ -46,27 +49,27 @@ class OrderBuilder { /** @var string your customer Reference number */ public $customerReference; - + /** @var string order number given by client side, should uniquely identify order at client */ public $clientOrderNumber; - - /** + + /** * @param \ConfigurationProvider $config */ public function __construct($config) { $this->conf = $config; } - + /** - * Required for invoice and payment plan orders - add customer information to the order + * 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\IndividualCustomer - * @see \Svea\CompanyCustomer \Svea\CompanyCustomer - * + * + * @see \Svea\IndividualCustomer \Svea\IndividualCustomer + * @see \Svea\CompanyCustomer \Svea\CompanyCustomer + * * @param \Svea\IndividualCustomer|\Svea\CompanyCustomer $itemCustomerObject * @return $this */ @@ -76,8 +79,8 @@ public function addCustomerDetails($itemCustomerObject) { } /** - * Required - you need to add at least one order row to the order - * + * Required - you need to add at least one order row to the order + * * @param \Svea\OrderRow $itemOrderRowObject * @return $this */ @@ -85,30 +88,34 @@ 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\InvoiceFee|\Svea\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\ShippingFee") { - array_push($this->shippingFeeRows, $row); + array_push($this->shippingFeeRows, $row); } if (get_class($row) == "Svea\InvoiceFee") { - array_push($this->invoiceFeeRows, $row); + array_push($this->invoiceFeeRows, $row); } } } else { + array_push($this->rows, $itemFeeObject); if (get_class($itemFeeObject) == "Svea\ShippingFee") { array_push($this->shippingFeeRows, $itemFeeObject); } @@ -121,18 +128,19 @@ public function addFee($itemFeeObject) { /** * 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\FixedDiscount - * @see \Svea\RelativeDiscount \Svea\RelativeDiscount - * + * + * @see \Svea\FixedDiscount \Svea\FixedDiscount + * @see \Svea\RelativeDiscount \Svea\RelativeDiscount + * * @param \Svea\FixedDiscount|\Svea\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\FixedDiscount") { array_push($this->fixedDiscountRows, $row); } @@ -142,6 +150,7 @@ public function addDiscount($itemDiscountObject) { } } else { + array_push($this->rows, $itemDiscountObject); if (get_class($itemDiscountObject) == "Svea\FixedDiscount") { array_push($this->fixedDiscountRows, $itemDiscountObject); } @@ -151,18 +160,18 @@ public function addDiscount($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 + * + * 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; @@ -172,7 +181,7 @@ public function setCountryCode($countryCodeAsString) { * 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 ConfigurationProvider and setCountryCode. - * + * * @param string $currencyAsString in ISO 4217 three-letter format, ex. "SEK", "EUR" * @return $this */ @@ -185,7 +194,7 @@ public function setCurrency($currencyAsString) { /** * 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 */ @@ -197,9 +206,9 @@ public function setCustomerReference($customerReferenceAsString) { /** * Required for Card, Direct Bank and 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. - * + * + * 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 */ @@ -208,9 +217,9 @@ public function setClientOrderNumber($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 */ diff --git a/src/svea/BuildOrder/RowBuilders/CompanyCustomer.php b/src/svea/BuildOrder/RowBuilders/CompanyCustomer.php index 9a07b5c7..cd126f98 100644 --- a/src/svea/BuildOrder/RowBuilders/CompanyCustomer.php +++ b/src/svea/BuildOrder/RowBuilders/CompanyCustomer.php @@ -3,64 +3,44 @@ /** * Class CompanyCustomer, a customer information container for legal entities. - * - * Note that "required" below as a requirement only when the IndividualCustomer is used - * to identify the customer when using the invoice or payment plan payment methods. - * - * (For card and direct bank orders, adding customer information to the order is optional.) - * - * $order->addCustomerDetails( - * 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 WebPay::getAddress() request - * ) - * ; - * * @author anne-hal, Kristian Grossman-Madsen */ class CompanyCustomer { - + /** @var string $orgNumber */ public $orgNumber; /** @var string $companyVatNumber */ - public $companyVatNumber; + public $companyVatNumber; /** @var string $email */ public $email; /** @var int $phonenumber */ public $phonenumber; /** @var string $ipAddress */ - public $ipAddress; + public $ipAddress; /** @var string $firstname */ public $firstname; - /** @var string $lastname */ + /** @var string $lastname */ public $lastname; /** @var string $street */ - public $street; + public $street; /** @var int $housenumber */ public $housenumber; /** @var string $coAddress */ - public $coAddress; + public $coAddress; /** @var string $zipCode */ - public $zipCode; + public $zipCode; /** @var string $locality */ public $locality; /** @var string $companyName */ - public $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 @@ -75,7 +55,7 @@ public function setNationalIdNumber($companyIdNumberAsString) { $this->orgNumber = $companyIdNumberAsString; return $this; } - + /** * Example: NL123456789A12 * @param string $vatNumber @@ -85,7 +65,7 @@ public function setNationalIdNumber($companyIdNumberAsString) { public function setVatNumber($vatNumberAsString) { $this->companyVatNumber = $vatNumberAsString; return $this; - } + } /** * Optional but desirable @@ -96,7 +76,7 @@ public function setEmail($emailAsString) { $this->email = $emailAsString; return $this; } - + /** * Optional * @param int $phoneNumberAsInt @@ -106,7 +86,7 @@ public function setPhoneNumber($phoneNumberAsInt) { $this->phonenumber = $phoneNumberAsInt; return $this; } - + /** * Optinal but desirable * @param type $ipAddressAsString @@ -115,8 +95,8 @@ public function setPhoneNumber($phoneNumberAsInt) { 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 @@ -135,7 +115,7 @@ public function setStreetAddress($streetAsString, $houseNumberAsInt = null) { // $this->housenumber = $houseNumberAsInt; } return $this; - } + } /** * Optional in NL and DE * @param type $coAddressAsString @@ -144,8 +124,8 @@ public function setStreetAddress($streetAsString, $houseNumberAsInt = null) { // public function setCoAddress($coAddressAsString) { $this->coAddress = $coAddressAsString; return $this; - } - + } + /** * Requuired in NL and DE * @param type $zipCodeAsString @@ -154,8 +134,8 @@ public function setCoAddress($coAddressAsString) { public function setZipCode($zipCodeAsString) { $this->zipCode = $zipCodeAsString; return $this; - } - + } + /** * Required in NL and DE * @param type $cityAsString @@ -164,8 +144,8 @@ public function setZipCode($zipCodeAsString) { public function setLocality($cityAsString) { $this->locality = $cityAsString; return $this; - } - + } + /** * Required for Eu countries like NL and DE * @param string $nameAsString @@ -174,7 +154,7 @@ public function setLocality($cityAsString) { 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. @@ -186,4 +166,13 @@ 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/svea/BuildOrder/RowBuilders/IndividualCustomer.php b/src/svea/BuildOrder/RowBuilders/IndividualCustomer.php index 21789ece..de23e41f 100644 --- a/src/svea/BuildOrder/RowBuilders/IndividualCustomer.php +++ b/src/svea/BuildOrder/RowBuilders/IndividualCustomer.php @@ -3,28 +3,6 @@ /** * Class IndividualCustomer, a customer information container for private individuals. - * - * The IndividualCustomer attributes are used by the invoice and payment plan payment methods - * to identify the customer. Which attributes are required varies according to country. - * - * (For card and direct bank orders, adding customer information to the order is optional.) - * - * $order->addCustomerDetails( - * 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 - * ) - * ; - * * @author anne-hal, Kristian Grossman-Madsen */ class IndividualCustomer { @@ -43,7 +21,7 @@ class IndividualCustomer { public $ipAddress; /** @var string $firstname */ public $firstname; - /** @var string $lastname */ + /** @var string $lastname */ public $lastname; /** @var string $street */ public $street; @@ -55,11 +33,13 @@ class IndividualCustomer { 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 $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 @@ -86,12 +66,13 @@ public function setInitials($initialsAsString) { * @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; + throw new \InvalidArgumentException( 'setBirthDate expects arguments on format $yyyy, $mm, $dd or $yyyymmdd' ); } else { $yyyy = substr($yyyymmdd,0,4); @@ -149,13 +130,13 @@ public function setName($firstnameAsString, $lastnameAsString = null) { // = nul $this->name = $fullNameAsString; } // two names given, assume firstName and lastName - else { + 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 @@ -205,4 +186,14 @@ 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/svea/BuildOrder/UpdateOrderBuilder.php b/src/svea/BuildOrder/UpdateOrderBuilder.php new file mode 100644 index 00000000..2a9f5f17 --- /dev/null +++ b/src/svea/BuildOrder/UpdateOrderBuilder.php @@ -0,0 +1,84 @@ +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 UpdateOrderRowsRequest + */ + public function updateInvoiceOrder() { + $this->orderType = \ConfigurationProvider::INVOICE_TYPE; + return new AdminService\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 AdminService\UpdateOrderRequest($this); + } +} \ No newline at end of file diff --git a/src/svea/BuildOrder/Validator/HostedOrderValidator.php b/src/svea/BuildOrder/Validator/HostedOrderValidator.php index f76f4a1c..d5fd60b5 100644 --- a/src/svea/BuildOrder/Validator/HostedOrderValidator.php +++ b/src/svea/BuildOrder/Validator/HostedOrderValidator.php @@ -20,10 +20,10 @@ public function validate($order) { if (isset($order->orgNumber) || isset($order->companyVatNumber) || isset($order->companyName)) { $this->isCompany = TRUE; } - + $this->errors = $this->validateClientOrderNumber($order,$this->errors); $this->errors = $this->validateCurrency($order,$this->errors); - $this->errors = $this->validateCountryCode($order, $this->errors); +// $this->errors = $this->validateCountryCode($order, $this->errors); //should be optional for hosted payment because not used $this->errors = $this->validateRequiredFieldsForOrder($order,$this->errors); $this->errors = $this->validateOrderRows($order,$this->errors); @@ -40,7 +40,7 @@ private function validateClientOrderNumber($order,$errors) { } return $errors; } - + /** * @param type $order * @param type $errors @@ -51,7 +51,7 @@ private function validateCurrency($order,$errors) { } return $errors; } - + /** * @param type $order * @param type $errors diff --git a/src/svea/Config/ConfigurationProvider.php b/src/svea/Config/ConfigurationProvider.php index af5c981a..b699da68 100644 --- a/src/svea/Config/ConfigurationProvider.php +++ b/src/svea/Config/ConfigurationProvider.php @@ -35,6 +35,7 @@ interface ConfigurationProvider { const PAYMENTPLAN_TYPE = 'PaymentPlan'; const HOSTED_ADMIN_TYPE = 'HOSTED_ADMIN'; const ADMIN_TYPE = 'ADMIN'; + const PREPARED_URL = 'PREPARED'; /** * fetch username, used with invoice or payment plan (i.e. Svea WebService Europe API) @@ -94,30 +95,30 @@ public function getSecret($type, $country); * @param string $type one of ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_ADMIN_TYPE, ::ADMIN_TYPE */ public function getEndPoint($type); - + /** * 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 ConfigurationProvider implementation. - */ - // public function getIntegrationPlatform(); - + */ + 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 + * 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 ConfigurationProvider implementation. - */ - // public function getIntegrationCompany(); + */ + 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 ConfigurationProvider implementation. - */ - // public function getIntegrationVersion(); + */ + public function getIntegrationVersion(); } diff --git a/src/svea/Config/OpencartSveaConfig.php b/src/svea/Config/OpencartSveaConfig.php index 92a7173b..978b4d19 100644 --- a/src/svea/Config/OpencartSveaConfig.php +++ b/src/svea/Config/OpencartSveaConfig.php @@ -80,6 +80,18 @@ public function getclientNumber($type, $country) { } return $this->config->get('svea_'.$lowertype.'_clientno_' . $country); } + + public function getIntegrationCompany() { + + } + + public function getIntegrationPlatform() { + + } + + public function getIntegrationVersion() { + + } } ?> diff --git a/src/svea/Config/OpencartSveaConfigTest.php b/src/svea/Config/OpencartSveaConfigTest.php index 8aaf3544..799727a5 100644 --- a/src/svea/Config/OpencartSveaConfigTest.php +++ b/src/svea/Config/OpencartSveaConfigTest.php @@ -15,9 +15,11 @@ class OpencartSveaConfigTest implements ConfigurationProvider{ public $config; + public $payment_method; - public function __construct($config) { + public function __construct($config, $payment_method = NULL) { $this->config = $config; + $this->payment_method = $payment_method; } public function getEndPoint($type) { @@ -81,6 +83,18 @@ public function getclientNumber($type, $country) { } return $this->config->get('svea_'.$lowertype.'_clientno_' . $country); } + + public function getIntegrationCompany() { + return "Svea Ekonomi : Opencart 1.x module"; + } + + public function getIntegrationPlatform() { + return 'Opencart '. VERSION; + } + + public function getIntegrationVersion() { + return $this->config->get($this->payment_method . '_version'); + } } ?> diff --git a/src/svea/Config/SveaConfig.php b/src/svea/Config/SveaConfig.php index edbd26fa..3cb99f27 100644 --- a/src/svea/Config/SveaConfig.php +++ b/src/svea/Config/SveaConfig.php @@ -20,6 +20,9 @@ class SveaConfig { const SWP_TEST_ADMIN_URL = "https://partnerweb.sveaekonomi.se/WebPayAdminService_test/AdminService.svc/backward"; // /backward => SOAP 1.1 const SWP_PROD_ADMIN_URL = "https://partnerweb.sveaekonomi.se/WebPayAdminService/AdminService.svc/backward"; // /backward => SOAP 1.1 + const SWP_TEST_PREPARED_URL = "https://test.sveaekonomi.se/webpay/preparedpayment/"; + const SWP_PROD_PREPARED_URL = "https://webpay.sveaekonomi.se/webpay/preparedpayment/"; + /** * Replace the provided Svea test account credentials with your own to use * the package with your own account. @@ -104,7 +107,8 @@ public static function getTestConfig() { \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 + \ConfigurationProvider::ADMIN_TYPE => self::SWP_TEST_ADMIN_URL, + \ConfigurationProvider::PREPARED_URL => self::SWP_TEST_PREPARED_URL ); $integrationproperties = array( @@ -113,7 +117,7 @@ public static function getTestConfig() { 'integrationplatform' => "myintegrationplatform" ) ; - + return new SveaConfigurationProvider(array("url" => $url, "credentials" => $testConfig, "integrationproperties" => $integrationproperties)); } @@ -167,7 +171,8 @@ public static function getProdConfig() { \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 + \ConfigurationProvider::ADMIN_TYPE => self::SWP_PROD_ADMIN_URL, + \ConfigurationProvider::PREPARED_URL => self::SWP_PROD_PREPARED_URL ) ; @@ -177,7 +182,7 @@ public static function getProdConfig() { 'integrationplatform' => "myintegrationplatform" ) ; - + return new SveaConfigurationProvider(array("url" => $url, "credentials" => $prodConfig, "integrationproperties" => $integrationproperties)); } @@ -246,6 +251,7 @@ public static function getSingleCountryConfig( \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, + \ConfigurationProvider::PREPARED_URL => self::SWP_TEST_PREPARED_URL ); $produrl = array( @@ -253,9 +259,10 @@ public static function getSingleCountryConfig( \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 + \ConfigurationProvider::ADMIN_TYPE => self::SWP_PROD_ADMIN_URL, + \ConfigurationProvider::PREPARED_URL => self::SWP_PROD_PREPARED_URL ); - + $integrationproperties = array( 'integrationcompany' => "myintegrationcompany", 'integrationversion' => "myintegrationversion", diff --git a/src/svea/Constant/PaymentMethod.php b/src/svea/Constant/PaymentMethod.php index efd25d05..818a0a47 100644 --- a/src/svea/Constant/PaymentMethod.php +++ b/src/svea/Constant/PaymentMethod.php @@ -3,10 +3,10 @@ /** * PaymentMethod is a container for the various payment method constant strings - * + * */ abstract class PaymentMethod { - + const INVOICE = 'INVOICE'; const PAYMENTPLAN = 'PAYMENTPLAN'; //DIRECT @@ -28,6 +28,7 @@ abstract class PaymentMethod { const TAPIOLA_FI = 'DBTAPIOLAFI'; //PaymentMethodType::CARD const KORTCERT = 'KORTCERT'; + const SVEACARDPAY = 'SVEACARDPAY'; const SKRILL = 'SKRILL'; const KORTWN = 'KORTWN'; //PREPAID diff --git a/src/svea/Constant/SystemPaymentMethod.php b/src/svea/Constant/SystemPaymentMethod.php index fd3beedd..f352674f 100644 --- a/src/svea/Constant/SystemPaymentMethod.php +++ b/src/svea/Constant/SystemPaymentMethod.php @@ -25,6 +25,7 @@ abstract class SystemPaymentMethod { const DBTAPIOLAFI = 'DBTAPIOLAFI'; //PaymentMethodType::CARD const KORTCERT = 'KORTCERT'; + const SVEACARDPAY = 'SVEACARDPAY'; const SKRILL = 'SKRILL'; const KORTWN = 'KORTWN'; diff --git a/src/svea/Helper/Helper.php b/src/svea/Helper/Helper.php index bb1384b6..0ae99897 100644 --- a/src/svea/Helper/Helper.php +++ b/src/svea/Helper/Helper.php @@ -264,6 +264,30 @@ static function splitMeanAcrossTaxRates( $discountAmount, $discountMeanVat, $dis } 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. + * + * @param float $price + * @param object $paymentPlanParamsResonseObject + * @param boolean $ignoreMaxAndMinFlag; optional, defaults to false + * @return Svea\WebService\PaymentPlanPricePerMonth + * + */ + public static function paymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag = false) { + return new WebService\PaymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag); + } } \ No newline at end of file diff --git a/src/svea/HostedService/Helper/HostedRowFormatter.php b/src/svea/HostedService/Helper/HostedRowFormatter.php index ed7f570c..f91c4894 100644 --- a/src/svea/HostedService/Helper/HostedRowFormatter.php +++ b/src/svea/HostedService/Helper/HostedRowFormatter.php @@ -5,16 +5,16 @@ 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; // all order rows, as above + 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 $invoiceAmount; private $invoiceVat; - + private $discountAmount; private $discountVat; /** @@ -27,21 +27,36 @@ public function __construct() { } /** - * Format rows and calculate vat. + * Format rows and calculate vat. * Includes order InvoiceFee rows, as InvoiceFee may be used for i.e. generic handling fee etc. - * + * * @param type $rows * @return int */ public function formatRows($order) { - - $this->formatOrderRows($order); - $this->formatShippingFeeRows($order); - $this->formatInvoiceFeeRows($order); // invoice fee stands in for all kinds of handling fees - $this->formatFixedDiscountRows($order); - $this->formatRelativeDiscountRows($order); - - return $this->newRows; + foreach ($order->rows as $row ) { + switch (get_class($row)) { + case 'Svea\OrderRow': + $this->formatOrderRows($row); + break; + case 'Svea\ShippingFee': + $this->formatShippingFeeRows($row); + break; + case 'Svea\InvoiceFee': + $this->formatInvoiceFeeRows($row); // invoice fee stands in for all kinds of handling fees + break; + case 'Svea\FixedDiscount': + $this->formatFixedDiscountRows($row); + break; + case 'Svea\RelativeDiscount': + $this->formatRelativeDiscountRows($row); + break; + default: + break; + } + } + + return $this->newRows; } /** @@ -56,8 +71,7 @@ public function formatRows($order) { * rounding errors. (See HostedPaymentTest for an example.) * */ - private function formatOrderRows($order) { - foreach ($order->orderRows as $row ) { + private function formatOrderRows($row) { $tempRow = new HostedOrderRowBuilder(); // new empty object if (isset($row->name)) { @@ -108,15 +122,9 @@ private function formatOrderRows($order) { $this->totalVat += ($tempRow->vat * $row->quantity); $this->rawAmount += \Svea\Helper::bround( ($rawAmount * $row->quantity) ,2) *100; $this->rawVat += \Svea\Helper::bround( ($rawVat * $row->quantity) ,2) *100; - } } - private function formatShippingFeeRows($order) { - if (!isset($order->shippingFeeRows)) { - return; - } - - foreach ($order->shippingFeeRows as $row) { + private function formatShippingFeeRows($row) { $tempRow = new HostedOrderRowBuilder(); if (isset($row->articleNumber)) { @@ -166,15 +174,9 @@ private function formatShippingFeeRows($order) { $this->shippingAmount += ($tempRow->amount ); $this->shippingVat += ($tempRow->vat ); - } } - public function formatInvoiceFeeRows($order) { - if (!isset($order->invoiceFeeRows)) { - return; - } - - foreach ($order->invoiceFeeRows as $row) { + public function formatInvoiceFeeRows($row) { $tempRow = new HostedOrderRowBuilder(); if (isset($row->name)) { @@ -215,15 +217,9 @@ public function formatInvoiceFeeRows($order) { $this->newRows[] = $tempRow; $this->invoiceAmount += ($tempRow->amount ); $this->invoiceVat += ($tempRow->vat ); - } } - - public function formatFixedDiscountRows($order) { - if (!isset($order->fixedDiscountRows)) { - return; - } - foreach ($order->fixedDiscountRows as $row) { + public function formatFixedDiscountRows($row) { $tempRow = new HostedOrderRowBuilder(); if (isset($row->name)) { @@ -294,15 +290,9 @@ public function formatFixedDiscountRows($order) { $this->discountAmount += $tempRow->amount; $this->discountVat += $tempRow->vat; - } } - public function formatRelativeDiscountRows($order) { - if (!isset($order->relativeDiscountRows)) { - return; - } - - foreach ($order->relativeDiscountRows as $row) { + public function formatRelativeDiscountRows($row) { $tempRow = new HostedOrderRowBuilder(); if (isset($row->name)) { @@ -335,7 +325,6 @@ public function formatRelativeDiscountRows($order) { $this->discountAmount += $tempRow->amount; $this->discountVat += $tempRow->vat; - } } /** diff --git a/src/svea/HostedService/Helper/PaymentForm.php b/src/svea/HostedService/Helper/PaymentForm.php index c4086e45..c9f6186a 100644 --- a/src/svea/HostedService/Helper/PaymentForm.php +++ b/src/svea/HostedService/Helper/PaymentForm.php @@ -26,26 +26,26 @@ class PaymentForm { 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 ) { + 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->setRawFields(); + $this->setSubmitMessage(); } @@ -81,7 +81,7 @@ public function setForm() { $formString .= ""; $formString .= ""; $formString .= ""; - + $this->completeHtmlFormWithSubmitButton = $formString; } diff --git a/src/svea/HostedService/HostedRequest.php b/src/svea/HostedService/HostedRequest.php index 89bd7df6..3b237658 100644 --- a/src/svea/HostedService/HostedRequest.php +++ b/src/svea/HostedService/HostedRequest.php @@ -31,7 +31,7 @@ function __construct($config) { * are present. If not, throws an exception. Actual validation is delegated * to subclass validateAttributes() implementations. * - * @throws ValidationException + * @throws \Svea\ValidationException */ public function validateRequest() { diff --git a/src/svea/HostedService/HostedResponse/HostedAdminResponse/HostedAdminResponse.php b/src/svea/HostedService/HostedResponse/HostedAdminResponse/HostedAdminResponse.php index 76e23d8c..fc393b59 100644 --- a/src/svea/HostedService/HostedResponse/HostedAdminResponse/HostedAdminResponse.php +++ b/src/svea/HostedService/HostedResponse/HostedAdminResponse/HostedAdminResponse.php @@ -6,22 +6,25 @@ /** * Handles diverse administrative function responses from the webservice and * wrapped legacy services through the webservice. - * + * * @author anne-hal, Kristian Grossman-Madsen for Svea WebPay */ class HostedAdminResponse extends HostedResponse{ + 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; if (is_object($message)) { @@ -48,28 +51,28 @@ function __construct($message,$countryCode,$config) { /** * 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 ); + $this->setErrorParams( (string)$hostedAdminResponse->statuscode ); } - + // getPaymentUrl/preparepayment request if( property_exists($hostedAdminResponse,"preparedpayment")) { - $url = "https://webpay.sveaekonomi.se/webpay/preparedpayment/"; - $testurl = "https://test.sveaekonomi.se/webpay/preparedpayment/"; - + $url = $this->config->getEndpoint( \Svea\SveaConfigurationProvider::PREPARED_URL); + $testurl = \Svea\SveaConfig::SWP_TEST_PREPARED_URL; + $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 } diff --git a/src/svea/HostedService/HostedResponse/HostedAdminResponse/ListPaymentMethodsResponse.php b/src/svea/HostedService/HostedResponse/HostedAdminResponse/ListPaymentMethodsResponse.php index 31d52790..2e8ddf61 100644 --- a/src/svea/HostedService/HostedResponse/HostedAdminResponse/ListPaymentMethodsResponse.php +++ b/src/svea/HostedService/HostedResponse/HostedAdminResponse/ListPaymentMethodsResponse.php @@ -6,19 +6,19 @@ /** * ListPaymentMethodsResponse handles the getpaymentmethods transaction response - * consistent with other HostedAdmin responses (i.e. returns an HostedResponse object) - * + * consistent with other HostedAdmin responses (i.e. returns an HostedResponse object) + * * @author Kristian Grossman-Madsen for Svea WebPay */ class ListPaymentMethodsResponse extends HostedAdminResponse{ /** 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 $config; +// private $config; private $countryCode; - + function __construct($message,$countryCode,$config) { $this->config = $config; $this->countryCode = $countryCode; @@ -28,30 +28,30 @@ function __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); - + if ((string)$hostedAdminResponse->statuscode == '0') { $this->accepted = 1; $this->resultcode = '0'; } else { $this->accepted = 0; - $this->setErrorParams( (string)$hostedAdminResponse->statuscode ); + $this->setErrorParams( (string)$hostedAdminResponse->statuscode ); } - //$this->paymentMethods = (array)$hostedAdminResponse->paymentmethods->paymentmethod; // seems to break under php 5.3 + //$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); - + if(is_numeric($clientIdInvoice) && strlen($clientIdInvoice) > 0 ){ $this->paymentmethods[] = \PaymentMethod::INVOICE; } @@ -59,10 +59,10 @@ protected function formatXml($hostedAdminResponseXML) { 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); - + if(is_numeric($clientIdPaymentPlan) && strlen($clientIdPaymentPlan) > 0 ){ $this->paymentmethods[] = \PaymentMethod::PAYMENTPLAN; } @@ -70,9 +70,9 @@ protected function formatXml($hostedAdminResponseXML) { 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); + unset( $this->countryCode); } } diff --git a/src/svea/HostedService/Payment/HostedPayment.php b/src/svea/HostedService/Payment/HostedPayment.php index f8bb9d3b..29633528 100644 --- a/src/svea/HostedService/Payment/HostedPayment.php +++ b/src/svea/HostedService/Payment/HostedPayment.php @@ -5,28 +5,28 @@ /** * HostedPayment and its descendants sets up the various hosted payment methods. - * - * Set all required attributes in the hosted payment class instance using the - * setAttribute() methods. Instance methods can be chained together, as they + * + * Set all required attributes in the hosted payment class instance using the + * setAttribute() methods. Instance methods can be chained together, as they * return the instance itself in a fluent fashion. - * + * * Finish by using the getPaymentForm() method which returns an HTML form with * the POST request to Svea prepared. After the customer has completed the * hosted payment request, a response xml message is returned to the specified * return url, where it can be parsed using i.e. the SveaResponse class. - * + * * Alternatively, you can use the getPaymentUrl() to get a response with * an URL that the customer can visit later to complete the payment at a later * time. - * + * * For recurring payments, first send a payment request, using setSubscriptionType(). - * Use the initial request response subscriptionId attribute as input to subsequent + * Use the initial request response subscriptionId attribute as input to subsequent * recur orders, using setSubscriptionId() and sending the recur request with doRecur(). - * + * * @author Anneli Halld'n, Daniel Brolund, Kristian Grossman-Madsen for Svea Webpay */ class HostedPayment { - + const RECURRINGCAPTURE = "RECURRINGCAPTURE"; const ONECLICKCAPTURE = "ONECLICKCAPTURE"; const RECURRING = "RECURRING"; @@ -34,22 +34,22 @@ class HostedPayment { /** @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 */ + + /** @var string $returnUrl holds the return URL used in request */ public $returnUrl; - - /** @var string $callbackUrl holds the callback URL used in request */ + + /** @var string $callbackUrl holds the callback URL used in request */ public $callbackUrl; - - /** @var string $cancelUrl holds the cancel URL used in request */ + + /** @var string $cancelUrl holds the cancel URL used in request */ public $cancelUrl; - + /** @var string $langCode holds the language code used in request */ public $langCode; @@ -63,16 +63,16 @@ class HostedPayment { public function __construct($order) { $this->langCode = "en"; $this->order = $order; - $this->request = array(); + $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 Certitrade card payment page. - * + * + * 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 */ @@ -80,44 +80,44 @@ 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 + * + * 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 + * 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. + * + * 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. - * + } + + /* 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 */ @@ -141,10 +141,10 @@ public function setPayPageLanguage($languageCodeAsISO639){ } return $this; } - + /** * getPaymentForm returns a form object containing a webservice payment request - * + * * @return PaymentForm * @throws ValidationException */ @@ -167,37 +167,44 @@ public function getPaymentForm() { $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; } - + /** * 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()."; - * + * + * Use function setIpAddress() on the order customer."; + * Use function setPayPageLanguage()."; + * * @return HostedPaymentResponse + * [accepted] => 1 + * [resultcode] => 0 + * [errormessage] => + * [id] => //the order id + * [created] + * [url] => https://webpay.sveaekonomi.se/webpay/preparedpayment/xxxxx Will return test or prod url depending on where the order was created + * [testurl] => https://test.sveaekonomi.se/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 - // + + // 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."; + $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()."; + $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) { @@ -210,31 +217,31 @@ public function getPaymentUrl() { throw new \Svea\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->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( + $fields = array( 'merchantid' => urlencode($merchantId), 'message' => urlencode(base64_encode($message)), 'mac' => urlencode($mac) - ); + ); // below taken from HostedRequest doRequest $fieldsString = ""; @@ -253,14 +260,14 @@ public function getPaymentUrl() { //returns a html page with redirecting to bank... $responseXML = curl_exec($ch); curl_close($ch); - + // create SveaResponse to handle response - $responseObj = new \SimpleXMLElement($responseXML); + $responseObj = new \SimpleXMLElement($responseXML); $sveaResponse = new \SveaResponse($responseObj, $this->countryCode, $this->config); - return $sveaResponse->response; + return $sveaResponse->response; } - + /** * @return string[] $errors an array containing the validation errors found */ @@ -268,32 +275,32 @@ public function validateOrder() { $validator = new \Svea\HostedOrderValidator(); $errors = $validator->validate($this->order); if (($this->order->countryCode == "NL" || $this->order->countryCode == "DE") && isset($this->paymentMethod)) { - if( 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 + + /** + * 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['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; @@ -302,90 +309,90 @@ public function calculateRequestValues() { if (isset($this->subscriptionType)) { $this->request['subscriptionType'] = $this->subscriptionType; - } + } if (isset($this->subscriptionId)) { $this->request['subscriptionId'] = $this->subscriptionId; - } - + } + return $this->request; } - + /** - * 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 + * 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 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 - * + * 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 + + // 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']); - + $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->amount = $this->request['amount']; $request->customerRefNo = $this->order->clientOrderNumber; $request->countryCode = $this->order->countryCode; $request->subscriptionId = $this->subscriptionId; - $response = $request->doRequest(); - + $response = $request->doRequest(); + return $response; } } diff --git a/src/svea/Response/SveaResponse.php b/src/svea/Response/SveaResponse.php index 97006684..59756bc8 100644 --- a/src/svea/Response/SveaResponse.php +++ b/src/svea/Response/SveaResponse.php @@ -3,19 +3,19 @@ /** * SveaResponse creates a uniform response object from a call to Svea services. - * - * SveaResponse returns an instance of the response class corresponding to - * the request sent to Svea, i.e. instances of subclasses to HostedResponse + * + * SveaResponse returns an instance of the response class corresponding to + * the request sent to Svea, i.e. instances of subclasses to HostedResponse * and WebServiceResponse, respectively. - * - * For asynchronous services, create an instance of SveaResponse, pass it the - * resulting xml response as part of the $_REQUEST response along with - * countryCode and config, then receive your HostedResponse instance by calling - * the getResponse() method. - * - * For synchronous services, the appropriate WebServiceResponse instance is + * + * For asynchronous services, create an instance of SveaResponse, pass it the + * resulting xml response as part of the $_REQUEST response along with + * countryCode and config, then receive your HostedResponse instance by calling + * the getResponse() method. + * + * For synchronous services, the appropriate WebServiceResponse instance is * returned by calling ->doRequest() on the order object. - * + * * @author Anneli Halld'n, Daniel Brolund, Kristian Grossman-Madsen for Svea WebPay */ class SveaResponse { @@ -29,53 +29,53 @@ class SveaResponse { /** * 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 + * 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 + * 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 string $method set for i.e. HostedAdmin, AdminService requests * @return mixed one of the various service request response classes */ public function __construct($message, $countryCode, $config = NULL, $method = NULL) { - + // 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 Svea\WebService\CreateOrderResponse($message); - } + } elseif (property_exists($message, "GetAddressesResult")) { // also legacy getAddresses result $this->response = new Svea\WebService\GetAddressesResponse($message); - } + } elseif (property_exists($message, "GetPaymentPlanParamsEuResult")) { $this->response = new Svea\WebService\PaymentPlanParamsResponse($message); - } + } elseif (property_exists($message, "DeliverOrderEuResult")) { $this->response = new Svea\WebService\DeliverOrderResult($message); - } + } elseif (property_exists($message, "CloseOrderEuResult")) { $this->response = new Svea\WebService\CloseOrderResult($message); } - - // $method is set for i.e. AdminService requests - elseif( isset($method) ) { + + // $method is set for i.e. AdminService requests + elseif( isset($method) ) { switch( $method ) { case "CancelOrder": $this->response = new Svea\AdminService\CancelOrderResponse( $message ); - break; + break; case "DeliverOrders": $this->response = new Svea\AdminService\DeliverOrdersResponse( $message ); break; @@ -84,45 +84,48 @@ public function __construct($message, $countryCode, $config = NULL, $method = NU break; case "CancelOrderRows": $this->response = new Svea\AdminService\CancelOrderRowsResponse( $message ); - break; + break; case "AddOrderRows": $this->response = new Svea\AdminService\AddOrderRowsResponse( $message ); break; case "UpdateOrderRows": $this->response = new Svea\AdminService\UpdateOrderRowsResponse( $message ); break; + case "UpdateOrder": + $this->response = new Svea\AdminService\UpdateOrderResponse( $message ); + break; case "CreditInvoiceRows": $this->response = new Svea\AdminService\CreditInvoiceRowsResponse( $message ); break; case "DeliverPartial": $this->response = new Svea\AdminService\DeliverPartialResponse( $message ); break; - + default: throw new Exception("unknown method: $method"); break; } } - + // legacy fallback -- webservice from hosted_admin -- used by preparedpayment - elseif (property_exists($message, "message")) { + elseif (property_exists($message, "message")) { $this->response = new Svea\HostedService\HostedAdminResponse($message,$countryCode,$config); } - } - + } + // webservice hosted payment elseif ($message != NULL) { $this->response = new Svea\HostedService\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 + * @return mixed */ public function getResponse() { return $this->response; diff --git a/src/svea/WebPay.php b/src/svea/WebPay.php index aab963c6..9f40829c 100644 --- a/src/svea/WebPay.php +++ b/src/svea/WebPay.php @@ -72,12 +72,11 @@ class WebPay { * @see \Svea\CompanyCustomer \Svea\CompanyCustomer * @return \Svea\CreateOrderBuilder * @param ConfigurationProvider $config instance implementing ConfigurationProvider Interface - * @throws Exception + * @throws Svea\ValidationException * */ public static function createOrder($config = NULL) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } - return new Svea\CreateOrderBuilder($config); } @@ -126,11 +125,10 @@ public static function createOrder($config = NULL) { * * @param ConfigurationProvider $config instance implementing ConfigurationProvider Interface * @return Svea\DeliverOrderBuilder - * @throws ValidationException + * @throws Svea\ValidationException */ public static function deliverOrder($config = NULL) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } - return new Svea\DeliverOrderBuilder($config); } @@ -183,7 +181,6 @@ public static function deliverOrder($config = NULL) { */ public static function getAddresses($config = NULL) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } - return new Svea\WebService\GetAddresses($config); } @@ -195,10 +192,10 @@ public static function getAddresses($config = NULL) { * * @return Svea\WebService\GetPaymentPlanParams * @param ConfigurationProvider $config instance implementing ConfigurationProvider + * @throws \Svea\ValidationException */ public static function getPaymentPlanParams($config = NULL) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } - return new Svea\WebService\GetPaymentPlanParams($config); } @@ -213,32 +210,16 @@ public static function getPaymentPlanParams($config = NULL) { * * @param ConfigurationProvider $config instance implementing ConfigurationProvider * @return string[] array of available paymentmethods for this ConfigurationProvider + * @throws \Svea\ValidationException */ public static function getPaymentMethods($config = NULL) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } return new Svea\HostedService\GetPaymentMethods($config); } - /** - * 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. - * - * The returned instance contains an array value, where each element in turn - * contains a pair of campaign code and price per month: - * $paymentPlanParamsResonseObject->value[0..n] (for n campaignCodes), where - * value['campaignCode' => campaignCode, 'pricePerMonth' => pricePerMonth] - * - * @param float $price - * @param object $paymentPlanParamsResonseObject - * @return Svea\WebService\PaymentPlanPricePerMonth - * - */ - public static function paymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject) { - return new Svea\WebService\PaymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject); + /** @deprecated -- use Helper::paymentPlanPricePerMonth() instead*/ + public static function paymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag = false) { + return new Svea\WebService\PaymentPlanPricePerMonth($price, $paymentPlanParamsResponseObject, $ignoreMaxAndMinFlag); } /** @@ -246,10 +227,10 @@ public static function paymentPlanPricePerMonth($price, $paymentPlanParamsRespon * @deprecated 2.0.0 -- use WebPayAdmin::cancelOrder instead, which supports both synchronous and asynchronous orders * @param ConfigurationProvider $config instance implementing ConfigurationProvider * @return Svea\CloseOrderBuilder + * @throws \Svea\ValidationException */ public static function closeOrder($config = NULL) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } - return new Svea\CloseOrderBuilder($config); } @@ -271,13 +252,15 @@ public static function closeOrder($config = NULL) { * * @param ConfigurationProvider $config * @return Svea\HostedService\ListPaymentMethods + * @throws \Svea\ValidationException */ static function listPaymentMethods($config) { + if( $config == NULL ) { WebPay::throwMissingConfigException(); } return new Svea\HostedService\ListPaymentMethods($config); } /** helper function, throws exception if no config is given */ private static function throwMissingConfigException() { - throw new Exception('-missing parameter: This method requires an ConfigurationProvider object as parameter. Create a class that implements class ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class SveaConfig e.g. SveaConfig::getDefaultConfig(). You can replace the default config values to return your own config values.'); + throw new \Svea\ValidationException('-missing parameter: This method requires an ConfigurationProvider object as parameter. Create a class that implements class ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class SveaConfig e.g. SveaConfig::getDefaultConfig(). You can replace the default config values to return your own config values.'); } } diff --git a/src/svea/WebPayAdmin.php b/src/svea/WebPayAdmin.php index 1859d60d..8110e51b 100644 --- a/src/svea/WebPayAdmin.php +++ b/src/svea/WebPayAdmin.php @@ -41,31 +41,31 @@ class WebPayAdmin { /** * The 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 WebPayAdmin::creditOrderRows() instead. - * - * Get an instance using the WebPayAdmin::cancelOrder entrypoint, then provide more information about the order and send + * + * Get an instance using the WebPayAdmin::cancelOrder entrypoint, then provide more information about the order and send * the request using the CancelOrderBuilder methods: - * + * * ... * $request = 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 + * ->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\CancelOrderBuilder * @see \Svea\WebService\CloseOrderResult Svea\WebService\CloseOrderResult * @see \Svea\HostedService\AnnulTransactionResponse \Svea\HostedService\AnnulTransactionResponse * * @param ConfigurationProvider $config instance implementing ConfigurationProvider * @return Svea\CancelOrderBuilder - * @throws Exception + * @throws Svea\ValidationException */ public static function cancelOrder($config = NULL) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } @@ -77,75 +77,75 @@ public static function cancelOrder($config = NULL) { * * 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 WebPayAdmin::queryOrder entrypoint, then provide more information - * about the order and send the request using the QueryOrderBuilder methods: - * + * + * Get an instance using the WebPayAdmin::queryOrder entrypoint, then provide more information + * about the order and send the request using the QueryOrderBuilder methods: + * * ... * $request = 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 + * ->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 + * $response = $request->queryDirectBankOrder()->doRequest(); // returns QueryTransactionResponse * ... - * + * * @see \Svea\QueryOrderBuilder \Svea\QueryOrderBuilder * @see \Svea\AdminService\GetOrdersResponse \Svea\AdminService\GetOrdersResponse * @see \Svea\HostedService\QueryTransactionResponse \Svea\HostedService\QueryTransactionResponse * * @param ConfigurationProvider $config instance implementing ConfigurationProvider * @return Svea\QueryOrderBuilder - * @throws Exception + * @throws Svea\ValidationException */ public static function queryOrder( $config = NULL ) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } return new Svea\QueryOrderBuilder($config); } - + /** * The WebPayAdmin::cancelOrderRows entrypoint method is used to cancel rows in an order before it has been delivered. * Supports Invoice, Payment Plan and Card orders. (Direct Bank orders are not supported, see CreditOrderRows instead.) - * + * * For Invoice 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 WebPayAdmin::queryOrder entrypoint, then provide more information about the order and + * + * Get an instance using the 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 + * + * Use setRowToCancel() or setRowsToCancel() to specify the order row(s) to cancel. The order row indexes should correspond to those returned by * i.e. 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 WebPayAdmin::queryOrder(); the numberedOrderRows attribute contains the serverside order rows w/indexes. Note that if a card + * + * 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 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 = 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 + * ->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\CancelOrderRowsBuilder * @see \Svea\AdminService\CancelOrderRowsResponse \Svea\AdminService\CancelOrderRowsResponse * @see \Svea\HostedService\LowerTransactionResponse \Svea\HostedService\LowerTransactionResponse * * @param ConfigurationProvider $config instance implementing ConfigurationProvider * @return Svea\CancelOrderRowsBuilder - * @throws ValidationException + * @throws Svea\ValidationException */ public static function cancelOrderRows( $config = NULL ) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } @@ -155,23 +155,23 @@ public static function cancelOrderRows( $config = NULL ) { /** * The WebPayAdmin::creditOrderRows entrypoint method is used to credit rows in an order after it has been delivered. * Supports invoice, card and direct bank orders. (To credit a payment plan order, please contact Svea customer service.) - * - * If you wish to credit an amount not present in the original order, use addCreditOrderRow() or addCreditOrderRows() + * + * 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 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 + * + * If you wish to credit an invoice 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(), + * + * 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. - * + * will be credited to the customer. + * * Note: when using addCreditOrderRows, you may only use WebPayItem::orderRow with price specified as amountExVat and vatPercent. - * - * Get an order builder instance using the WebPayAdmin::creditOrderRows entrypoint, then provide more information about the + * + * Get an order builder instance using the WebPayAdmin::creditOrderRows entrypoint, then provide more information about the * transaction and send the request using the creditOrderRowsBuilder methods: - * + * * ... * $request = WebPay::creditOrder($config) * ->setInvoiceId() // invoice only, required @@ -190,10 +190,10 @@ public static function cancelOrderRows( $config = NULL ) { * $response = $request->creditCardOrderRows()->doRequest(); // returns CreditTransactionResponse * $response = $request->creditDirectBankOrderRows()->doRequest(); // returns CreditTransactionResponse * ... - * + * * @param ConfigurationProvider $config * @return Svea\CreditOrderRowsBuilder - * @throws ValidationException + * @throws Svea\ValidationException * * @see \Svea\CreditOrderRowsBuilder \Svea\CreditOrderRowsBuilder * @see \Svea\AdminService\CreditInvoiceRowsResponse \Svea\AdminService\CreditInvoiceRowsResponse @@ -207,7 +207,7 @@ public static function creditOrderRows( $config = NULL ) { } /** - * Add order rows to an order. + * Add order rows to an order. * * Provide information about the new order rows and send the request using * addOrderRowsBuilder methods: @@ -228,7 +228,7 @@ public static function creditOrderRows( $config = NULL ) { * * @param ConfigurationProvider $config instance implementing ConfigurationProvider * @return Svea\AddOrderRowsBuilder - * @throws ValidationException + * @throws Svea\ValidationException */ public static function addOrderRows( $config = NULL ) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } @@ -236,26 +236,26 @@ public static function addOrderRows( $config = NULL ) { } /** - * The WebPayAdmin::updateOrderRows() method is used to update individual order rows in non-delivered invoice and + * The 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' + * 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 WebPayAdmin::updateOrderRows() entrypoint, then provide more information - * about the transaction and send the request using the UpdateOrderRowsBuilder methods: - * + * + * Get an order builder instance using the 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 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 + * 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 = WebPayAdmin.updateOrderRows($config) * ->setOrderId() // required @@ -266,7 +266,7 @@ public static function addOrderRows( $config = NULL ) { * $response = $request->updateInvoiceOrderRows()->doRequest(); // returns UpdateOrderRowsResponse * $response = $request->updatePaymentPlanOrderRows()->doRequest(); // returns UpdateOrderRowsResponse * ... - * + * * @author Kristian Grossman-Madsen * * @see \Svea\UpdateOrderRowsBuilder \Svea\UpdateOrderRowsBuilder @@ -274,63 +274,103 @@ public static function addOrderRows( $config = NULL ) { * * @param ConfigurationProvider $config instance implementing ConfigurationProvider * @return Svea\UpdateOrderRowsBuilder - * @throws ValidationException + * @throws Svea\ValidationException */ public static function updateOrderRows( $config = NULL ) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } return new Svea\UpdateOrderRowsBuilder($config); } + /** + * The 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 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 = 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\UpdateOrderBuilder + * @see \Svea\AdminService\UpdateOrderResponse \Svea\AdminService\UpdateOrderResponse + * + * @param ConfigurationProvider $config instance implementing ConfigurationProvider + * @return Svea\UpdateOrderBuilder + * @throws Svea\ValidationException + */ + public static function updateOrder( $config = NULL ) { + if( $config == NULL ) { WebPay::throwMissingConfigException(); } + return new Svea\UpdateOrderBuilder($config); + } + /** - * The WebPayAdmin::deliverOrderRows entrypoint method is used to deliver individual order rows. Supports invoice and card orders. + * The 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 + * + * 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 WebPayAdmin::deliverOrderRows() entrypoint, then provide more information about the + * + * Get an order builder instance using the 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 + * + * Use setRowToDeliver() or setRowsToDeliver() to specify the order row(s) to deliver. The order row indexes should correspond to * those returned by i.e. 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 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 + * + * 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 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 = WebPayAdmin::deliverOrderRows($config) * ->setOrderId() // required - * ->setTransactionId() // optional, card only, alias for setOrderId - * ->setCountryCode() // 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 + * ->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\DeliverOrderRowsBuilder * @see \Svea\AdminService\DeliverOrderRowsResponse \Svea\AdminService\DeliverOrderRowsResponse * @see \Svea\HostedService\ConfirmTransactionResponse \Svea\HostedService\ConfirmTransactionResponse * * @param ConfigurationProvider $config instance implementing ConfigurationProvider * @return Svea\DeliverOrderRowsBuilder - * @throws ValidationException + * @throws Svea\ValidationException */ public static function deliverOrderRows( $config = NULL ) { if( $config == NULL ) { WebPay::throwMissingConfigException(); } return new Svea\DeliverOrderRowsBuilder($config); - } - + } + /** helper function, throws exception if no config is given */ private static function throwMissingConfigException() { - throw new Exception('-missing parameter: This method requires an ConfigurationProvider object as parameter. Create a class that implements class ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class SveaConfig e.g. SveaConfig::getDefaultConfig(). You can replace the default config values to return your own config values in the method.'); + throw new \Svea\ValidationException('-missing parameter: This method requires an ConfigurationProvider object as parameter. Create a class that implements class ConfigurationProvider. Set returnvalues to configuration values. Create an object from that class. Alternative use static function from class SveaConfig e.g. SveaConfig::getDefaultConfig(). You can replace the default config values to return your own config values in the method.'); } } diff --git a/src/svea/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonth.php b/src/svea/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonth.php index d2681887..eccdc498 100644 --- a/src/svea/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonth.php +++ b/src/svea/WebService/GetPaymentPlanParams/PaymentPlanPricePerMonth.php @@ -12,25 +12,27 @@ * 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. * - * The returned instance of PaymentPlanPricePerMonth contains an array "values", where each element in turn contains an array of campaign code, * description and price per month: + * The returned instance of PaymentPlanPricePerMonth contains an array "values", + * where each element in turn contains an array of campaign code, description & + * price per month: * * $paymentPlanParamsResonseObject->values[0..n] (for n campaignCodes), where * values['campaignCode' => campaignCode, 'pricePerMonth' => pricePerMonth, 'description' => description] * - * @author Anneli Halld'n, Daniel Brolund for Svea Webpay + * @author Anneli Halld'n, Daniel Brolund, Kristian Grossman-Madsen for Svea Webpay */ class PaymentPlanPricePerMonth { public $values = array(); - function __construct($price,$params) { - $this->calculate($price,$params); + function __construct($price, $params, $ignoreMaxAndMinFlag = false) { + $this->calculate($price, $params, $ignoreMaxAndMinFlag); } - private function calculate($price, $params) { + private function calculate($price, $params, $ignoreMaxAndMinFlag) { if (!empty($params)) { foreach ($params->campaignCodes as $key => $value) { - if ($price >= $value->fromAmount && $price <= $value->toAmount) { + if( $ignoreMaxAndMinFlag || ($price >= $value->fromAmount && $price <= $value->toAmount) ) { $pair = array(); $pair['pricePerMonth'] = $price * $value->monthlyAnnuityFactor + $value->notificationFee; foreach ($value as $key => $val) { diff --git a/src/svea/WebService/Helper/WebServiceRowFormatter.php b/src/svea/WebService/Helper/WebServiceRowFormatter.php index f47c8f92..93327aff 100644 --- a/src/svea/WebService/Helper/WebServiceRowFormatter.php +++ b/src/svea/WebService/Helper/WebServiceRowFormatter.php @@ -77,11 +77,28 @@ public function formatRows() { $this->priceIncludingVat = $this->resendOrderVat ? FALSE : TRUE; } - $this->formatOrderRows(); - $this->formatShippingFeeRows(); - $this->formatInvoiceFeeRows(); - $this->formatFixedDiscountRows(); - $this->formatRelativeDiscountRows(); + foreach ($this->order->rows as $row) { + switch (get_class($row)) { + case 'Svea\OrderRow': + $this->formatOrderRows($row); + break; + case 'Svea\ShippingFee': + $this->formatShippingFeeRows($row); + break; + case 'Svea\InvoiceFee': + $this->formatInvoiceFeeRows($row); + break; + case 'Svea\FixedDiscount': + $this->formatFixedDiscountRows($row); + break; + case 'Svea\RelativeDiscount': + $this->formatRelativeDiscountRows($row); + break; + default: + break; + } + } + return $this->newRows; } @@ -142,8 +159,8 @@ private function calculateTotals() { } } - private function formatOrderRows() { - foreach ($this->order->orderRows as $row) { + private function formatOrderRows($row) { +// foreach ($this->order->orderRows as $row) { $orderRow = new WebServiceSoap\SveaOrderRow(); @@ -179,7 +196,7 @@ private function formatOrderRows() { } $this->newRows[] = $orderRow; - } +// } } /** @@ -209,12 +226,7 @@ public function formatRowNameAndDescription( $webPayItemRow ) { return $description; } - private function formatShippingFeeRows() { - if (!isset($this->order->shippingFeeRows)) { - return; - } - - foreach ($this->order->shippingFeeRows as $row) { + private function formatShippingFeeRows($row) { $orderRow = new WebServiceSoap\SveaOrderRow(); @@ -244,6 +256,12 @@ private function formatShippingFeeRows() { $orderRow->VatPercent = \Svea\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, \Svea\Helper::bround($row->vatPercent)); @@ -251,16 +269,9 @@ private function formatShippingFeeRows() { $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE; } $this->newRows[] = $orderRow; - } } - private function formatInvoiceFeeRows() { - if (!isset($this->order->invoiceFeeRows)) { - return; - } - - foreach ($this->order->invoiceFeeRows as $row) { - + private function formatInvoiceFeeRows($row) { $orderRow = new WebServiceSoap\SveaOrderRow(); $orderRow->ArticleNumber = ""; @@ -287,14 +298,18 @@ private function formatInvoiceFeeRows() { $orderRow->VatPercent = \Svea\Helper::bround($row->vatPercent); $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE; } - // no vatPercent given + // 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, \Svea\Helper::bround($row->vatPercent)); $orderRow->VatPercent = $this->calculateVatPercentFromPriceExVatAndPriceIncVat( $row->amountIncVat, $row->amountExVat ); $orderRow->PriceIncludingVat = $this->priceIncludingVat ? TRUE : FALSE; } $this->newRows[] = $orderRow; - } } /** @@ -344,13 +359,12 @@ private function formatFixedDiscountSpecifiedAsAmountIncVatOnly( $discountRow ) /** * Formats FixedDiscount rows specified with setAmountExVat() only. * Returns one or more discount rows, one for each vat rate present in the order. - * If the + * If the * * @param FixedDiscount $discountRow * @return \Svea\SveaOrderRow */ private 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 ) { @@ -386,19 +400,14 @@ private function formatFixedDiscountSpecifiedAsAmountExVatOnly( $discountRow ) { $orderRow->VatPercent = $vatRate; $orderRow->PriceIncludingVat = FALSE; } - + $splitRows[] = $orderRow; } return $splitRows; } - private function formatFixedDiscountRows() { - if (!isset($this->order->fixedDiscountRows)) { - return; - } - foreach ($this->order->fixedDiscountRows as $row) { - + private 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 ) ); @@ -466,16 +475,9 @@ private function formatFixedDiscountRows() { $this->newRows[] = $orderRow; } - } } - private function formatRelativeDiscountRows() { - if (!isset($this->order->relativeDiscountRows)) { - return; - } - - foreach ($this->order->relativeDiscountRows as $row) { - + private function formatRelativeDiscountRows($row) { foreach( $this->totalAmountPerVatRateIncVat as $vatRate => $amountAtThisVatRateIncVat ) { $orderRow = new WebServiceSoap\SveaOrderRow(); @@ -504,62 +506,45 @@ private function formatRelativeDiscountRows() { $this->newRows[] = $orderRow; } - } } private function determineVatFlag() { $exVat = 0; $incVat = 0; - - //check first if there is a mix of orderrows - foreach ($this->order->orderRows as $row) { - if(isset($row->amountExVat) && isset($row->amountIncVat)){ - $incVat++; - }elseif (isset($row->amountExVat) && isset ($row->vatPercent)) { - $exVat++; - }else { - $incVat++; - } - } - //invoicefees - foreach ($this->order->invoiceFeeRows as $row) { - if(isset($row->amountExVat) && isset($row->amountIncVat)){ - $incVat++; - }elseif (isset($row->amountExVat) && !isset($row->amountIncVat)) { - $exVat++; - }else { - $incVat++; - } - } - //shippingfees - foreach ($this->order->shippingFeeRows as $row) { - if(isset($row->amountExVat) && isset($row->amountIncVat)){ - $incVat++; - } if (isset($row->amountExVat) && !isset($row->amountIncVat)) { - $exVat++; - }else { - $incVat++; + 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\RelativeDiscount': + break; + case 'Svea\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; } + } - //fixed discount - foreach ($this->order->fixedDiscountRows as $row) { - if(isset($row->amountExVat) && isset($row->amountIncVat)){ - $incVat++; - } if (isset($row->amountExVat) && !isset($row->amountIncVat)) { - $exVat++; - }else { - $incVat++; - } - } - - //relative discount - // ignored, as relative discount doesn't use setAmountExVat/-IncVat at all - //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; } + } + } diff --git a/src/svea/WebService/Payment/WebServicePayment.php b/src/svea/WebService/Payment/WebServicePayment.php index 8e6c3a10..7e9ca0eb 100644 --- a/src/svea/WebService/Payment/WebServicePayment.php +++ b/src/svea/WebService/Payment/WebServicePayment.php @@ -51,14 +51,13 @@ public function prepareRequest() { } throw new \Svea\ValidationException($exceptionString); } - + // create soap order object, set authorization $sveaOrder = new WebServiceSoap\SveaOrder; $sveaOrder->Auth = $this->getPasswordBasedAuthorization(); - //make orderrows and put in CreateOrderInfromation $orderinformation = $this->formatOrderInformationWithOrderRows($this->order->orderRows); - + //parallel ways of creating customer if (isset($this->order->customerIdentity)) { $orderinformation->CustomerIdentity = $this->formatCustomerDetails(); @@ -110,7 +109,7 @@ protected function formatOrderInformationWithOrderRows($rows) { // rewrite order rows to soap_class order rows $formatter = new WebServiceRowFormatter($this->order); $formattedOrderRows = $formatter->formatRows(); - + foreach ($formattedOrderRows as $formattedOrderRow) { $orderInformation->addOrderRow($formattedOrderRow); } @@ -178,6 +177,7 @@ private function formatCustomerIdentity() { $individualCustomerIdentity->CountryCode = $this->order->countryCode; $individualCustomerIdentity->CustomerType = $isCompany ? "Company" : "Individual"; + $individualCustomerIdentity->PublicKey = isset($this->order->publicKey) ? $this->order->publicKey : ""; return $individualCustomerIdentity; } @@ -244,6 +244,7 @@ public function formatCustomerDetails() { $individualCustomerIdentity->CountryCode = $this->order->countryCode; $individualCustomerIdentity->CustomerType = $isCompany ? "Company" : "Individual"; + $individualCustomerIdentity->PublicKey = isset($this->order->customerIdentity->publicKey) ? $this->order->customerIdentity->publicKey : ""; return $individualCustomerIdentity; } @@ -267,8 +268,8 @@ public function getRequestTotals() { 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 ); @@ -282,13 +283,13 @@ private function calculateOrderRowExVat($row) { private function convertIncVatToExVat( $row, $rowsum_incvat ) { return \Svea\Helper::bround( ($rowsum_incvat / (1 + ($row->VatPercent / 100))),2); } - + private function getRowAmount( $row ) { return \Svea\Helper::bround($row->NumberOfUnits,2) * - \Svea\Helper::bround($row->PricePerUnit,2) * + \Svea\Helper::bround($row->PricePerUnit,2) * (1 - ($row->DiscountPercent / 100)); } - + private function calculateTotalVatSumOfRows($row) { //if amount inc vat $sum = 0; @@ -298,10 +299,10 @@ private function calculateTotalVatSumOfRows($row) { $exvat = $this->convertIncVatToExVat( $row, $rowsum_incvat ); $vat = \Svea\Helper::bround($rowsum_incvat,2) - \Svea\Helper::bround($exvat,2); - $sum += $vat; + $sum += $vat; } else { $exvat = $this->getRowAmount( $row ); - + $vat = \Svea\Helper::bround($exvat,2) * ($row->VatPercent / 100 ); $sum += \Svea\Helper::bround($vat,2); } diff --git a/src/svea/WebService/WebServiceResponse/CustomerIdentity/CustomerIdentityResponse.php b/src/svea/WebService/WebServiceResponse/CustomerIdentity/CustomerIdentityResponse.php index a6185840..096043f1 100644 --- a/src/svea/WebService/WebServiceResponse/CustomerIdentity/CustomerIdentityResponse.php +++ b/src/svea/WebService/WebServiceResponse/CustomerIdentity/CustomerIdentityResponse.php @@ -3,37 +3,40 @@ /** * CustomerIdentityResponse structure - * + * * @author Anneli Halld'n, Daniel Brolund, Kristian Grossman-Madsen for Svea Webpay - */ + */ class CustomerIdentityResponse { /** @var string $customerType one of { Person, Business } */ - public $customerType; + public $customerType; /** @var string $nationalIdNumber */ - public $nationalIdNumber; + public $nationalIdNumber; /** @var string $phoneNumber */ - public $phoneNumber; + public $phoneNumber; /** @var string $fullName */ - public $fullName; + public $fullName; /** @var string $street */ - public $street; + public $street; /** @var string $coAddress */ - public $coAddress; + public $coAddress; /** @var string $zipCode */ - public $zipCode; + public $zipCode; /** @var string $locality */ - public $locality; - + public $locality; + /** @var string $publicKey */ + public $publicKey; + + /** * populates the CustomerIdentityResponse object - * + * * @param object $customer -- response from either legacy GetAddresses or CreateOrderEU */ - function __construct( $customer ) { - + 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 : ""; @@ -53,7 +56,8 @@ function __construct( $customer ) { $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->locality = isset($customer->Locality) ? $customer->Locality : ""; + $this->publicKey = isset($customer->PublicKey) ? $customer->PublicKey : ""; } } } diff --git a/src/svea/WebService/svea_soap/SveaCustomerIdentity.php b/src/svea/WebService/svea_soap/SveaCustomerIdentity.php index 0037cc54..8265556e 100644 --- a/src/svea/WebService/svea_soap/SveaCustomerIdentity.php +++ b/src/svea/WebService/svea_soap/SveaCustomerIdentity.php @@ -21,6 +21,7 @@ class SveaCustomerIdentity { public $Locality; public $CountryCode; public $CustomerType; + public $PublicKey; /** * Dynamically crate an instancevariable depending on Company or Individual diff --git a/src/svea/docs/info.json b/src/svea/docs/info.json index d2c68a36..dccfac94 100644 --- a/src/svea/docs/info.json +++ b/src/svea/docs/info.json @@ -1,4 +1,4 @@ { "library_name": "PHP Integration Package", - "library_version": "2.2.21" + "library_version": "2.2.25" } \ No newline at end of file diff --git a/src/svea/version.txt b/src/svea/version.txt index e39b8e2f..5bba3e25 100644 --- a/src/svea/version.txt +++ b/src/svea/version.txt @@ -1,5 +1,7 @@ -Updated integrationLib 2015-06-05 to: +Updated integrationLib 2015-11-30 to: sveawebpay/php-integration -release/2.2.21 +release/2.2.25 + +Remember to activate integration functions in Config/ConfigurationProvider.php on update diff --git a/src/vqmod/xml/svea_product.xml b/src/vqmod/xml/svea_product.xml index 454e49fc..dca37542 100644 --- a/src/vqmod/xml/svea_product.xml +++ b/src/vqmod/xml/svea_product.xml @@ -1,7 +1,7 @@ SveaWebPay Product Price -2.7.0 +2.7.1 2.4.1 Anneli Halld'n, Kristian Grossman-Madsen / Svea Ekonomi AB, SveaWebPay diff --git a/src/vqmod/xml/svea_sale_order.xml b/src/vqmod/xml/svea_sale_order.xml index 9f10ba40..53041f55 100644 --- a/src/vqmod/xml/svea_sale_order.xml +++ b/src/vqmod/xml/svea_sale_order.xml @@ -1,7 +1,7 @@ SveaWebPay Product Price -2.7.0 +2.7.1 1.0.8 Anneli Halld'n, Kristian Grossman-Madsen / Svea Ekonomi AB, SveaWebPay