public function test_cancelOrderRowsBuilder_cancelCardOrderRowsBuilder_returns_LowerTransaction()
 {
     $orderId = "123456";
     $mockedNumberedOrderRow = new \Svea\NumberedOrderRow();
     $mockedNumberedOrderRow->setAmountExVat(100.0)->setVatPercent(25)->setQuantity(1)->setRowNumber(1);
     $cancelOrderRowsObject = $this->cancelOrderRowsObject->setOrderId($orderId)->addNumberedOrderRow($mockedNumberedOrderRow)->setRowToCancel(1);
     $request = $cancelOrderRowsObject->cancelCardOrderRows();
     $this->assertInstanceOf("Svea\\HostedService\\LowerTransaction", $request);
 }
예제 #2
0
 protected function formatObject($message)
 {
     // was request accepted?
     parent::formatObject($message);
     // if successful, set deliverOrderResult, using the same attributes as for DeliverOrderEU?
     if ($this->accepted == 1) {
         // populate GetOrdersResponse select attributes from the raw GetOrders response
         $order = $message->Orders->Order;
         $this->changedDate = $order->ChangedDate;
         $this->clientId = $order->ClientId;
         $this->clientOrderId = $order->ClientOrderId;
         $this->createdDate = $order->CreatedDate;
         $this->creditReportStatusAccepted = $order->CreditReportStatus->Accepted === "true" ? true : false;
         $this->creditReportStatusCreationDate = $order->CreditReportStatus->CreationDate;
         $this->currency = $order->Currency;
         //individual customer?
         if ($order->Customer->CustomerType === "Individual") {
             //stdClass Object
             //(
             //    [ChangedDate] =>
             //    [ClientId] => 79021
             //    [ClientOrderId] => 449
             //    [CreatedDate] => 2014-05-19T16:04:54.787
             //    [CreditReportStatus] => stdClass Object
             //        (
             //            [Accepted] => true
             //            [CreationDate] => 2014-05-19T16:04:54.893
             //        )
             //
             //    [Currency] => SEK
             //    [Customer] => stdClass Object
             //        (
             //            [CoAddress] => c/o Eriksson, Erik
             //            [CompanyIdentity] =>
             //            [CountryCode] => SE
             //            [CustomerType] => Individual
             //            [Email] =>
             //            [FullName] => Persson, Tess T
             //            [HouseNumber] =>
             //            [IndividualIdentity] => stdClass Object
             //                (
             //                    [BirthDate] =>
             //                    [FirstName] =>
             //                    [Initials] =>
             //                    [LastName] =>
             //                )
             //
             //            [Locality] => Stan
             //            [NationalIdNumber] => 194605092222
             //            [PhoneNumber] =>
             //            [PublicKey] =>
             //            [Street] => Testgatan 1
             //            [ZipCode] => 99999
             //        )
             //
             //    [CustomerId] => 1000117
             //    [CustomerReference] =>
             //    [DeliveryAddress] =>
             //    [IsPossibleToAdminister] => false
             //    [IsPossibleToCancel] => true
             //    [Notes] =>
             //    [OrderDeliveryStatus] => Created
             //    [OrderRows] => stdClass Object
             //        (
             //            [NumberedOrderRow] => Array
             //                (
             //                    [0] => stdClass Object
             //                        (
             //                            [ArticleNumber] =>
             //                            [Description] => Dyr produkt 25%
             //                            [DiscountPercent] => 0.00
             //                            [NumberOfUnits] => 2.00
             //                            [PriceIncludingVat] => false
             //                            [PricePerUnit] => 2000.00
             //                            [Unit] =>
             //                            [VatPercent] => 25.00
             //                            [CreditInvoiceId] =>
             //                            [InvoiceId] =>
             //                            [RowNumber] => 1
             //                            [Status] => NotDelivered
             //                        )
             //
             //                    [1] => stdClass Object
             //                        (
             //                            [ArticleNumber] =>
             //                            [Description] => Testprodukt 1kr 25%
             //                            [DiscountPercent] => 0.00
             //                            [NumberOfUnits] => 1.00
             //                            [PriceIncludingVat] => false
             //                            [PricePerUnit] => 1.00
             //                            [Unit] =>
             //                            [VatPercent] => 25.00
             //                            [CreditInvoiceId] =>
             //                            [InvoiceId] =>
             //                            [RowNumber] => 2
             //                            [Status] => NotDelivered
             //                        )
             //
             //                    [2] => stdClass Object
             //                        (
             //                            [ArticleNumber] =>
             //                            [Description] => Fastpris (Fast fraktpris)
             //                            [DiscountPercent] => 0.00
             //                            [NumberOfUnits] => 1.00
             //                            [PriceIncludingVat] => false
             //                            [PricePerUnit] => 4.00
             //                            [Unit] =>
             //                            [VatPercent] => 25.00
             //                            [CreditInvoiceId] =>
             //                            [InvoiceId] =>
             //                            [RowNumber] => 3
             //                            [Status] => NotDelivered
             //                        )
             //
             //                    [3] => stdClass Object
             //                        (
             //                            [ArticleNumber] =>
             //                            [Description] => Svea Fakturaavgift:: 20.00kr (SE)
             //                            [DiscountPercent] => 0.00
             //                            [NumberOfUnits] => 1.00
             //                            [PriceIncludingVat] => false
             //                            [PricePerUnit] => 20.00
             //                            [Unit] =>
             //                            [VatPercent] => 0.00
             //                            [CreditInvoiceId] =>
             //                            [InvoiceId] =>
             //                            [RowNumber] => 4
             //                            [Status] => NotDelivered
             //                        )
             //
             //                )
             //
             //        )
             //
             //    [OrderStatus] => Active
             //    [OrderType] => Invoice
             //    [PaymentPlanDetails] =>
             //    [PendingReasons] =>
             //    [SveaOrderId] => 348629
             //    [SveaWillBuy] => true
             //)
             $this->customer = new \Svea\IndividualCustomer();
             $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber);
             $this->customer->setInitials($order->Customer->IndividualIdentity->Initials);
             if (isset($order->Customer->IndividualIdentity->BirthDate)) {
                 // setBirthDate is picky about the argument format
                 $this->customer->setBirthDate($order->Customer->IndividualIdentity->BirthDate);
             }
             $this->customer->setName($order->Customer->IndividualIdentity->FirstName, $order->Customer->IndividualIdentity->LastName);
             // sets firstName, lastName if present
             $this->customer->setName($order->Customer->FullName);
             // sets compounded fullName if present
             $this->customer->setEmail($order->Customer->Email);
             $this->customer->setPhoneNumber($order->Customer->PhoneNumber);
             $this->customer->setStreetAddress($order->Customer->Street);
             // sets compounded streetAddress if present, as well as street
             $this->customer->setStreetAddress($order->Customer->Street, $order->Customer->HouseNumber);
             // sets Individual street, houseNumber if present
             $this->customer->setCoAddress($order->Customer->CoAddress);
             $this->customer->setZipCode($order->Customer->ZipCode);
             $this->customer->setLocality($order->Customer->Locality);
         }
         if ($order->Customer->CustomerType === "Company") {
             //stdClass Object
             //(
             //    [ChangedDate] =>
             //    [ClientId] => 79021
             //    [ClientOrderId] =>
             //    [CreatedDate] => 2014-12-29T16:41:58.897
             //    [CreditReportStatus] => stdClass Object
             //        (
             //            [Accepted] => true
             //            [CreationDate] => 2014-12-29T16:41:58.96
             //        )
             //
             //    [Currency] => SEK
             //    [Customer] => stdClass Object
             //        (
             //            [CoAddress] => c/o Eriksson, Erik
             //            [CompanyIdentity] => stdClass Object
             //                (
             //                    [CompanyIdentification] =>
             //                    [CompanyVatNumber] =>
             //                )
             //
             //            [CountryCode] => SE
             //            [CustomerType] => Company
             //            [Email] =>
             //            [FullName] => Persson, Tess T
             //            [HouseNumber] =>
             //            [IndividualIdentity] =>
             //            [Locality] => Stan
             //            [NationalIdNumber] => 164608142222
             //            [PhoneNumber] =>
             //            [PublicKey] =>
             //            [Street] => Testgatan 1
             //            [ZipCode] => 99999
             //        )
             //
             //    [CustomerId] => 1000119
             //    [CustomerReference] =>
             //    [DeliveryAddress] =>
             //    [IsPossibleToAdminister] => false
             //    [IsPossibleToCancel] => true
             //    [Notes] =>
             //    [OrderDeliveryStatus] => Created
             //    [OrderRows] => stdClass Object
             //        (
             //            [NumberedOrderRow] => Array
             //                (
             //                    [0] => stdClass Object
             //                        (
             //                            [ArticleNumber] => 1
             //                            [Description] => Product: Specification
             //                            [DiscountPercent] => 0.00
             //                            [NumberOfUnits] => 2.00
             //                            [PriceIncludingVat] => false
             //                            [PricePerUnit] => 100.00
             //                            [Unit] => st
             //                            [VatPercent] => 25.00
             //                            [CreditInvoiceId] =>
             //                            [InvoiceId] =>
             //                            [RowNumber] => 1
             //                            [Status] => NotDelivered
             //                        )
             //
             //                    [1] => stdClass Object
             //                        (
             //                            [ArticleNumber] => 1
             //                            [Description] => Product: Specification
             //                            [DiscountPercent] => 0.00
             //                            [NumberOfUnits] => 2.00
             //                            [PriceIncludingVat] => false
             //                            [PricePerUnit] => 1000.00
             //                            [Unit] => st
             //                            [VatPercent] => 25.00
             //                            [CreditInvoiceId] =>
             //                            [InvoiceId] =>
             //                            [RowNumber] => 2
             //                            [Status] => NotDelivered
             //                        )
             //
             //                )
             //
             //        )
             //
             //    [OrderStatus] => Active
             //    [OrderType] => Invoice
             //    [PaymentPlanDetails] =>
             //    [PendingReasons] =>
             //    [SveaOrderId] => 499329
             //    [SveaWillBuy] => true
             //)
             $this->customer = new \Svea\CompanyCustomer();
             $this->customer->setNationalIdNumber($order->Customer->NationalIdNumber);
             $this->customer->setVatNumber($order->Customer->CompanyIdentity->CompanyVatNumber);
             $this->customer->setCompanyName($order->Customer->FullName);
             $this->customer->setEmail($order->Customer->Email);
             $this->customer->setPhoneNumber($order->Customer->PhoneNumber);
             $this->customer->setStreetAddress($order->Customer->Street);
             // sets compounded streetAddress if present, as well as street
             $this->customer->setStreetAddress($order->Customer->Street, $order->Customer->HouseNumber);
             $this->customer->setCoAddress($order->Customer->CoAddress);
             $this->customer->setZipCode($order->Customer->ZipCode);
             $this->customer->setLocality($order->Customer->Locality);
         }
         $this->customerId = $order->CustomerId;
         $this->customerReference = $order->CustomerReference;
         //$this->deliveryAddress = $order->DeliveryAddress; // not supported
         $this->isPossibleToAdminister = $order->IsPossibleToAdminister === "true" ? true : false;
         $this->isPossibleToCancel = $order->IsPossibleToCancel === 'true' ? true : false;
         $this->notes = $order->Notes;
         $this->orderDeliveryStatus = $order->OrderDeliveryStatus;
         // a single order row is returned as type stdClass
         if (is_a($order->OrderRows->NumberedOrderRow, "stdClass")) {
             $row = $order->OrderRows->NumberedOrderRow;
             $newrow = new \Svea\NumberedOrderRow();
             // webpay orderrow
             $newrow->setDescription($row->Description)->setQuantity($row->NumberOfUnits)->setArticleNumber($row->ArticleNumber)->setUnit($row->Unit)->setVatPercent((int) $row->VatPercent)->setDiscountPercent($row->DiscountPercent);
             if ($row->PriceIncludingVat === 'true') {
                 $newrow->setAmountIncVat($row->PricePerUnit);
             } else {
                 $newrow->setAmountExVat($row->PricePerUnit);
             }
             $newrow->creditInvoiceId = $row->CreditInvoiceId;
             $newrow->invoiceId = $row->InvoiceId;
             $newrow->rowNumber = $row->RowNumber;
             $newrow->status = $row->Status;
             $this->numberedOrderRows[] = $newrow;
         } elseif (is_array($order->OrderRows->NumberedOrderRow)) {
             // for each numbered orderrow, add it to the numberedOrderRow array
             foreach ($order->OrderRows->NumberedOrderRow as $row) {
                 //GetOrders NumberedOrderRow:
                 // [ArticleNumber]
                 // [Description]
                 // [DiscountPercent]
                 // [NumberOfUnits]
                 // [PricePerUnit]
                 // [Unit]
                 // [VatPercent]
                 // [CreditInvoiceId]
                 // [InvoiceId]
                 // [RowNumber]
                 // [Status]
                 $newrow = new \Svea\NumberedOrderRow();
                 // webpay orderrow
                 //WebPayItem OrderRow:
                 // $articleNumber   *
                 // $quantity        *
                 // $unit            *
                 // $amountExVat     * depends on bool priceincludingvat
                 // $amountIncVat    * depends on bool priceincludingvat
                 // $vatPercent      *
                 // $name            not used
                 // $description     *
                 // $discountPercent *
                 // $vatDiscount     not used
                 $newrow->setDescription($row->Description)->setQuantity($row->NumberOfUnits)->setArticleNumber($row->ArticleNumber)->setUnit($row->Unit)->setVatPercent((int) $row->VatPercent)->setDiscountPercent($row->DiscountPercent);
                 if ($row->PriceIncludingVat === 'true') {
                     $newrow->setAmountIncVat($row->PricePerUnit);
                 } else {
                     $newrow->setAmountExVat($row->PricePerUnit);
                 }
                 $newrow->creditInvoiceId = $row->CreditInvoiceId;
                 $newrow->invoiceId = $row->InvoiceId;
                 $newrow->rowNumber = $row->RowNumber;
                 $newrow->status = $row->Status;
                 $this->numberedOrderRows[] = $newrow;
             }
         }
         $this->orderStatus = $order->OrderStatus;
         $this->orderType = $order->OrderType;
         if (is_a($order->PaymentPlanDetails, "stdClass") && property_exists($order->PaymentPlanDetails, "ContractLengthMonths")) {
             $this->paymentPlanDetailsContractLengthMonths = $order->PaymentPlanDetails->ContractLengthMonths;
         }
         if (is_a($order->PaymentPlanDetails, "stdClass") && property_exists($order->PaymentPlanDetails, "ContractNumber")) {
             $this->paymentPlanDetailsContractNumber = $order->PaymentPlanDetails->ContractNumber;
         }
         $this->pendingReasons = $order->PendingReasons;
         if (is_a($order->PendingReasons, "stdClass") && property_exists($order->PendingReasons, "PendingType")) {
             $this->pendingReasonsPendingType = $order->PendingReasons->PendingType;
         }
         if (is_a($order->PendingReasons, "stdClass") && property_exists($order->PendingReasons, "CreatedDate")) {
             $this->PendingReasonsCreatedDate = $order->PendingReasons->CreatedDate;
         }
         $this->orderId = $order->SveaOrderId;
         $this->sveaWillBuy = $order->SveaWillBuy === 'true' ? true : false;
     }
 }
 /**
  * formatXml() parses the query transaction response xml and sets the
  * response attributes accordingly.
  * 
  * @param string $hostedAdminResponseXML  hostedAdminResponse as xml
  */
 protected function formatXml($hostedAdminResponseXML)
 {
     $hostedAdminResponse = new \SimpleXMLElement($hostedAdminResponseXML);
     if ((string) $hostedAdminResponse->statuscode == '0') {
         $this->accepted = 1;
         $this->resultcode = '0';
     } else {
         $this->accepted = 0;
         $this->setErrorParams((string) $hostedAdminResponse->statuscode);
     }
     //print_r( $hostedAdminResponse ); // uncomment to dump raw request response
     // queryTransaction
     if (property_exists($hostedAdminResponse->transaction, "customerrefno") && property_exists($hostedAdminResponse->transaction, "merchantid")) {
         $this->transactionId = (string) $hostedAdminResponse->transaction['id'];
         $this->clientOrderNumber = (string) $hostedAdminResponse->transaction->customerrefno;
         // to confirm with HostedPaymentResponse
         $this->merchantId = (string) $hostedAdminResponse->transaction->merchantid;
         $this->status = (string) $hostedAdminResponse->transaction->status;
         $this->amount = (string) $hostedAdminResponse->transaction->amount;
         $this->currency = (string) $hostedAdminResponse->transaction->currency;
         $this->vat = (string) $hostedAdminResponse->transaction->vat;
         $this->capturedamount = (string) $hostedAdminResponse->transaction->capturedamount;
         $this->authorizedamount = (string) $hostedAdminResponse->transaction->authorizedamount;
         $this->created = (string) $hostedAdminResponse->transaction->created;
         $this->creditstatus = (string) $hostedAdminResponse->transaction->creditstatus;
         $this->creditedamount = (string) $hostedAdminResponse->transaction->creditedamount;
         $this->merchantresponsecode = (string) $hostedAdminResponse->transaction->merchantresponsecode;
         $this->paymentMethod = (string) $hostedAdminResponse->transaction->paymentmethod;
         $this->callbackurl = (string) $hostedAdminResponse->transaction->callbackurl;
         $this->capturedate = (string) $hostedAdminResponse->transaction->capturedate;
         $this->subscriptionId = (string) $hostedAdminResponse->transaction->subscriptionid;
         $this->subscriptiontype = (string) $hostedAdminResponse->transaction->subscriptiontype;
         $this->cardType = (string) $hostedAdminResponse->transaction->cardtype;
         $this->maskedCardNumber = (string) $hostedAdminResponse->transaction->maskedcardno;
         $this->eci = (string) $hostedAdminResponse->transaction->eci;
         $this->mdstatus = (string) $hostedAdminResponse->transaction->mdstatus;
         $this->expiryYear = (string) $hostedAdminResponse->transaction->expiryyear;
         $this->expiryMonth = (string) $hostedAdminResponse->transaction->expirymonth;
         $this->chname = (string) $hostedAdminResponse->transaction->chname;
         $this->authCode = (string) $hostedAdminResponse->transaction->authcode;
         //SimpleXMLElement Object
         //(
         //    [transaction] => SimpleXMLElement Object
         //        (
         //            [@attributes] => Array
         //                (
         //                    [id] => 581497
         //                )
         //
         //            [customerrefno] => test_recur_1
         //            [merchantid] => 1130
         //            [status] => SUCCESS
         //            [amount] => 500
         //            [currency] => SEK
         //            [vat] => 100
         //            [capturedamount] => 500
         //            [authorizedamount] => 500
         //            [created] => 2014-04-16 14:51:34.917
         //            [creditstatus] => CREDNONE
         //            [creditedamount] => 0
         //            [merchantresponsecode] => 0
         //            [paymentmethod] => KORTCERT
         //            [callbackurl] => SimpleXMLElement Object
         //                (
         //                )
         //
         //            [capturedate] => 2014-04-18 00:15:12.287
         //            [subscriptionid] => 2922
         //            [subscriptiontype] => RECURRINGCAPTURE
         //        )
         //
         //    [statuscode] => 0
         //)
         if (property_exists($hostedAdminResponse->transaction, "orderrows")) {
             $rownumber = 1;
             foreach ($hostedAdminResponse->transaction->orderrows->row as $orderrow) {
                 $orderrow = (array) $orderrow;
                 //queried orderrow:
                 // [name]
                 // [amount]
                 // [vat]
                 // [description]
                 // [quantity]
                 // [sku]
                 // [unit]
                 $newrow = new \Svea\NumberedOrderRow();
                 // webpay orderrow
                 //WebPayItem OrderRow:
                 // $articleNumber
                 // $quantity
                 // $unit
                 // $amountExVat
                 // $amountIncVat
                 // $vatPercent
                 // $name
                 // $description
                 // $discountPercent
                 // $vatDiscount
                 $newrow->setName((string) $orderrow['name'])->setAmountExVat(floatval($orderrow['amount'] - $orderrow['vat']) / 100)->setDescription((string) $orderrow['description'])->setQuantity(floatval((string) $orderrow['quantity']))->setArticleNumber((string) $orderrow['sku'])->setUnit((string) $orderrow['unit'])->setVatPercent($this->calculateVatPercentFromVatAndAmount($orderrow['vat'], $orderrow['amount']));
                 $newrow->creditInvoiceId = null;
                 $newrow->invoiceId = null;
                 $newrow->rowNumber = $rownumber;
                 $newrow->status = null;
                 $rownumber += 1;
                 $this->numberedOrderRows[] = $newrow;
             }
         }
     }
 }