Exemplo n.º 1
0
 public static function crateFromOrder(Mage_Sales_Model_Order $order)
 {
     $aOrder = new self();
     $aOrder->id = $order->getIncrementId();
     $aOrder->currency = $order->getOrderCurrencyCode();
     $aOrder->total_amount = Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getTotalDue());
     $aOrder->articles = array_map(array('Aplazame_Aplazame_BusinessModel_Article', 'crateFromOrderItem'), $order->getAllVisibleItems());
     if (($discounts = $order->getDiscountAmount()) !== null) {
         $aOrder->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat(-$discounts);
     }
     return $aOrder;
 }
Exemplo n.º 2
0
 public static function crateFromOrderItem(Mage_Sales_Model_Order_Item $orderItem)
 {
     $productId = $orderItem->getProductId();
     /** @var Mage_Catalog_Model_Product $product */
     $product = Mage::getModel('catalog/product')->load($productId);
     $discounts = $product->getPrice() - $product->getFinalPrice();
     $aArticle = new self();
     $aArticle->id = $productId;
     $aArticle->name = $orderItem->getName();
     $aArticle->url = $product->getProductUrl();
     $aArticle->image_url = $product->getImageUrl();
     $aArticle->quantity = intval($orderItem->getQtyOrdered());
     $aArticle->price = Aplazame_Sdk_Serializer_Decimal::fromFloat($orderItem->getPrice() + $discounts);
     $aArticle->description = substr($product->getDescription(), 0, 255);
     $aArticle->tax_rate = Aplazame_Sdk_Serializer_Decimal::fromFloat(self::getProductTaxRate($product));
     $aArticle->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat($discounts);
     return $aArticle;
 }
Exemplo n.º 3
0
 public static function createFromOrder(Mage_Sales_Model_Order $order)
 {
     $address = $order->getShippingAddress();
     $shippingInfo = new self();
     $shippingInfo->first_name = $address->getFirstname();
     $shippingInfo->last_name = $address->getLastname();
     $shippingInfo->street = $address->getStreet(1);
     $shippingInfo->city = $address->getCity();
     $shippingInfo->state = $address->getRegion();
     $shippingInfo->country = $address->getCountryModel()->getIso2Code();
     $shippingInfo->postcode = $address->getPostcode();
     $shippingInfo->name = $order->getShippingMethod();
     $shippingInfo->price = Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getShippingAmount());
     $shippingInfo->phone = $address->getTelephone();
     $shippingInfo->alt_phone = $address->getAltTelephone();
     $shippingInfo->address_addition = $address->getStreet(2);
     if ($order->getShippingAmount() > 0) {
         $shippingInfo->tax_rate = Aplazame_Sdk_Serializer_Decimal::fromFloat(100 * $order->getShippingTaxAmount() / $order->getShippingAmount());
     }
     $shippingInfo->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getShippingDiscountAmount());
     return $shippingInfo;
 }
Exemplo n.º 4
0
 /**
  * @param Mage_Sales_Model_Order $order
  *
  * @return array
  */
 public static function createFromOrder(Mage_Sales_Model_Order $order)
 {
     $serialized = array('id' => $order->getIncrementId(), 'amount' => Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getGrandTotal()), 'due' => Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getTotalDue()), 'status' => $order->getStatus(), 'type' => $order->getPayment()->getMethodInstance()->getCode(), 'order_date' => date(DATE_ISO8601, strtotime($order->getCreatedAt())), 'currency' => $order->getOrderCurrencyCode(), 'billing' => Aplazame_Aplazame_BusinessModel_Address::createFromAddress($order->getBillingAddress()), 'shipping' => Aplazame_Aplazame_BusinessModel_ShippingInfo::createFromOrder($order));
     return $serialized;
 }
Exemplo n.º 5
0
 /**
  * @param Mage_Sales_Model_Order $order
  * @param float $amount
  * @return array
  */
 public function refundAmount($order, $amount)
 {
     $data = array('amount' => Aplazame_Sdk_Serializer_Decimal::fromFloat($amount)->jsonSerialize());
     return $this->apiClient->request(Varien_Http_Client::POST, $this->getEndpointForOrder($order) . "/refund", $data);
 }
Exemplo n.º 6
0
 public function authorize(Varien_Object $payment, $amount)
 {
     if ($amount <= 0) {
         Mage::throwException(Mage::helper('aplazame')->__('Invalid amount for authorization.'));
     }
     $token = $payment->getAdditionalInformation(self::CHECKOUT_TOKEN);
     /** @var Aplazame_Aplazame_Model_Api_Client $api */
     $api = Mage::getModel('aplazame/api_client');
     $result = $api->authorize($token);
     if (isset($result["id"])) {
         $this->getInfoInstance()->setAdditionalInformation("charge_id", $result["id"]);
     } else {
         Mage::throwException(Mage::helper('aplazame')->__('Aplazame charge id not returned from call.'));
     }
     $this->_validate_amount_result(Aplazame_Sdk_Serializer_Decimal::fromFloat($amount)->jsonSerialize(), $result);
     $payment->setTransactionId($this->getChargeId())->setIsTransactionClosed(0);
     return $this;
 }