/**
  * @param string $comments
  * @param string $invoiceNumber
  *
  * @dataProvider dataProvider
  */
 public function testXMLGeneration($comments, $invoiceNumber)
 {
     $ccData = new TransactionDetails($comments, $invoiceNumber);
     $document = new \DOMDocument('1.0', 'UTF-8');
     $xml = $ccData->getXML($document);
     $document->appendChild($xml);
     $elementPayment = $document->getElementsByTagName('ns2:TransactionDetails');
     $this->assertEquals(1, $elementPayment->length, 'Expected element TransactionDetails not found');
     $children = [];
     /** @var \DOMNode $child */
     foreach ($elementPayment->item(0)->childNodes as $child) {
         $children[$child->nodeName] = $child->nodeValue;
     }
     $this->assertArrayHasKey('ns1:Comments', $children, 'Expected element Comments not found');
     $this->assertEquals($comments, $children['ns1:Comments'], 'Comments data id did not match');
     if ($invoiceNumber !== null) {
         $this->assertArrayHasKey('ns1:InvoiceNumber', $children, 'Expected element InvoiceNumber not found');
         $this->assertEquals($invoiceNumber, $children['ns1:InvoiceNumber'], 'InvoiceNumber did not match');
     } else {
         $this->assertArrayNotHasKey('ns1:InvoiceNumber', $children, 'Unexpected element InvoiceNumber was found');
     }
 }
예제 #2
0
 public function __construct(CustomerOrder $order, Currency $currency)
 {
     parent::__construct();
     $this->order = $order;
     $order->loadAll();
     // billing address
     if ($address = $order->billingAddress->get()) {
         $fields = array('firstName', 'lastName', 'companyName', 'phone', 'city', 'postalCode', 'countryID' => 'country');
         foreach ($fields as $key => $field) {
             $addressField = is_numeric($key) ? $field : $key;
             $this->{$field}->set($address->{$addressField}->get());
         }
         $this->state->set($this->getStateValue($address));
         $this->address->set($address->address1->get() . ' ' . $address->address2->get());
     }
     // shipping address
     $address = $order->shippingAddress->get();
     if (!$address) {
         $address = $order->billingAddress->get();
     }
     if ($address) {
         foreach ($fields as $key => $field) {
             $addressField = is_numeric($key) ? $field : $key;
             $field = 'shipping' . ucfirst($field);
             $this->{$field}->set($address->{$addressField}->get());
         }
         $this->shippingState->set($this->getStateValue($address));
         $this->shippingAddress->set($address->address1->get() . ' ' . $address->address2->get());
     }
     // amount
     $order->currency->set($currency);
     $this->amount->set(round($order->getDueAmount(), 2));
     $this->currency->set($currency->getID());
     // transaction identification
     $this->invoiceID->set($order->getID());
     if (isset($_SERVER['REMOTE_ADDR'])) {
         $this->ipAddress->set($_SERVER['REMOTE_ADDR']);
     }
     // customer identification
     if ($order->user->get()) {
         $order->user->get()->load();
         $this->shippingEmail->set($order->user->get()->email->get());
         $this->email->set($order->user->get()->email->get());
         $this->clientID->set($order->user->get()->getID());
     }
     // order details
     // load variation data
     $variations = new ProductSet();
     foreach ($order->getShoppingCartItems() as $item) {
         if ($item->product->get() && $item->product->get()->parent->get()) {
             $variations->unshift($item->product->get());
         }
     }
     if ($variations->size()) {
         $variations->loadVariations();
     }
     foreach ($order->getShoppingCartItems() as $item) {
         $product = $item->getProduct();
         $variations = array();
         foreach ($product->getRegisteredVariations() as $variation) {
             $variations[] = $variation->getValueByLang('name');
         }
         $ri = RecurringItem::getInstanceByOrderedItem($item);
         if ($ri && $ri->isExistingRecord()) {
             $ri->load();
         } else {
             $ri = null;
         }
         $this->addLineItem($product->getName() . ($variations ? ' (' . implode(' / ', $variations) . ')' : ''), $item->getPrice(false), $item->count->get(), $product->sku->get(), $ri);
     }
     if ($discount = $order->getFixedDiscountAmount()) {
         $this->addLineItem(CustomerOrder::getApplication()->translate('_discount'), $discount * -1, 1, 'discount');
     }
     foreach ($order->getShipments() as $shipment) {
         if ($rate = $shipment->getSelectedRate()) {
             $rate = $rate->toArray();
             $name = empty($rate['ShippingService']['name_lang']) ? $rate['serviceName'] : $rate['ShippingService']['name_lang'];
             $this->addLineItem($name, $shipment->getShippingTotalBeforeTax(), 1, 'shipping');
         }
     }
     if ($taxes = $order->getTaxBreakdown()) {
         foreach ($taxes as $id => $amount) {
             $tax = Tax::getInstanceById($id, true);
             $this->addLineItem($tax->getValueByLang('name', null), $amount, 1, 'tax');
         }
     }
 }
예제 #3
0
 public function getPaymentHandler($className, LiveCartTransaction $details = null)
 {
     if (!class_exists($className, false)) {
         if ('OfflineTransactionHandler' == $className) {
             ClassLoader::import('application.model.order.OfflineTransactionHandler');
         } else {
             ClassLoader::importNow('library.payment.method.*');
             ClassLoader::importNow('library.payment.method.cc.*');
             ClassLoader::importNow('library.payment.method.express.*');
         }
     }
     if (is_null($details)) {
         $details = new TransactionDetails();
     }
     $inst = new $className($details);
     if ($details instanceof LiveCartTransaction) {
         $inst->setOrder($details->getOrder());
     }
     $c = $this->config->getSection('payment/' . $className);
     foreach ($c as $key => $value) {
         $value = $this->config->get($key);
         $key = substr($key, strlen($className) + 1);
         $inst->setConfigValue($key, $value);
     }
     // check if the currency is supported by the payment handler
     $currency = $inst->getValidCurrency($details->currency->get());
     if ($details->currency->get() != $currency && !is_null($details->currency->get())) {
         $newAmount = Currency::getInstanceById($currency, Currency::LOAD_DATA)->convertAmount(Currency::getInstanceById($details->currency->get(), Currency::LOAD_DATA), $details->amount->get());
         $details->currency->set($currency);
         $details->amount->set(round($newAmount, 2));
     }
     $inst->setApplication($this);
     return $inst;
 }