Exemplo n.º 1
0
 /**
  * Method is invoked before save
  *
  * @param \Magento\Framework\Object $object
  * @return $this
  */
 public function beforeSave($object)
 {
     if ($object->getOrder()) {
         $object->setOrderId($object->getOrder()->getId());
         $object->setBillingAddressId($object->getOrder()->getBillingAddress()->getId());
     }
     return parent::beforeSave($object);
 }
Exemplo n.º 2
0
 /**
  * Perform operation before save
  *
  * @param \Magento\Framework\Object $object
  * @return $this
  */
 public function beforeSave($object)
 {
     if ($object->getOrder()) {
         $object->setParentId($object->getOrder()->getId());
     }
     parent::beforeSave($object);
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Get "double" prices html (block with base and place currency)
  *
  * @param   \Magento\Framework\Object $dataObject
  * @param   float $basePrice
  * @param   float $price
  * @param   bool $strong
  * @param   string $separator
  * @return  string
  */
 public function displayPrices($dataObject, $basePrice, $price, $strong = false, $separator = '<br/>')
 {
     $order = false;
     if ($dataObject instanceof \Magento\Sales\Model\Order) {
         $order = $dataObject;
     } else {
         $order = $dataObject->getOrder();
     }
     if ($order && $order->isCurrencyDifferent()) {
         $res = '<strong>';
         $res .= $order->formatBasePrice($basePrice);
         $res .= '</strong>' . $separator;
         $res .= '[' . $order->formatPrice($price) . ']';
     } elseif ($order) {
         $res = $order->formatPrice($price);
         if ($strong) {
             $res = '<strong>' . $res . '</strong>';
         }
     } else {
         $res = $this->priceCurrency->format($price);
         if ($strong) {
             $res = '<strong>' . $res . '</strong>';
         }
     }
     return $res;
 }
Exemplo n.º 4
0
 /**
  * Prepare request to gateway
  *
  * @param \Magento\Framework\Object|\Magento\Payment\Model\Info $payment
  * @return \Magento\Authorizenet\Model\Authorizenet\Request
  * @link http://www.authorize.net/support/AIM_guide.pdf
  */
 protected function _buildRequest(\Magento\Framework\Object $payment)
 {
     $order = $payment->getOrder();
     $this->setStore($order->getStoreId());
     $request = $this->_getRequest()->setXType($payment->getAnetTransType())->setXMethod(self::REQUEST_METHOD_CC);
     if ($order && $order->getIncrementId()) {
         $request->setXInvoiceNum($order->getIncrementId());
     }
     if ($payment->getAmount()) {
         $request->setXAmount($payment->getAmount(), 2);
         $request->setXCurrencyCode($order->getBaseCurrencyCode());
     }
     switch ($payment->getAnetTransType()) {
         case self::REQUEST_TYPE_AUTH_CAPTURE:
             $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False');
             if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) {
                 $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey));
             }
             break;
         case self::REQUEST_TYPE_AUTH_ONLY:
             $request->setXAllowPartialAuth($this->getConfigData('allow_partial_authorization') ? 'True' : 'False');
             if ($payment->getAdditionalInformation($this->_splitTenderIdKey)) {
                 $request->setXSplitTenderId($payment->getAdditionalInformation($this->_splitTenderIdKey));
             }
             break;
         case self::REQUEST_TYPE_CREDIT:
             /**
              * Send last 4 digits of credit card number to authorize.net
              * otherwise it will give an error
              */
             $request->setXCardNum($payment->getCcLast4());
             $request->setXTransId($payment->getXTransId());
             break;
         case self::REQUEST_TYPE_VOID:
             $request->setXTransId($payment->getXTransId());
             break;
         case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE:
             $request->setXTransId($payment->getXTransId());
             break;
         case self::REQUEST_TYPE_CAPTURE_ONLY:
             $request->setXAuthCode($payment->getCcAuthCode());
             break;
     }
     if ($this->getIsCentinelValidationEnabled()) {
         $params = $this->getCentinelValidator()->exportCmpiData(array());
         $request = \Magento\Framework\Object\Mapper::accumulateByMap($params, $request, $this->_centinelFieldMap);
     }
     if (!empty($order)) {
         $billing = $order->getBillingAddress();
         if (!empty($billing)) {
             $request->setXFirstName($billing->getFirstname())->setXLastName($billing->getLastname())->setXCompany($billing->getCompany())->setXAddress($billing->getStreet(1))->setXCity($billing->getCity())->setXState($billing->getRegion())->setXZip($billing->getPostcode())->setXCountry($billing->getCountry())->setXPhone($billing->getTelephone())->setXFax($billing->getFax())->setXCustId($order->getCustomerId())->setXCustomerIp($order->getRemoteIp())->setXCustomerTaxId($billing->getTaxId())->setXEmail($order->getCustomerEmail())->setXEmailCustomer($this->getConfigData('email_customer'))->setXMerchantEmail($this->getConfigData('merchant_email'));
         }
         $shipping = $order->getShippingAddress();
         if (!empty($shipping)) {
             $request->setXShipToFirstName($shipping->getFirstname())->setXShipToLastName($shipping->getLastname())->setXShipToCompany($shipping->getCompany())->setXShipToAddress($shipping->getStreet(1))->setXShipToCity($shipping->getCity())->setXShipToState($shipping->getRegion())->setXShipToZip($shipping->getPostcode())->setXShipToCountry($shipping->getCountry());
         }
         $request->setXPoNum($payment->getPoNumber())->setXTax($order->getBaseTaxAmount())->setXFreight($order->getBaseShippingAmount());
     }
     if ($payment->getCcNumber()) {
         $request->setXCardNum($payment->getCcNumber())->setXExpDate(sprintf('%02d-%04d', $payment->getCcExpMonth(), $payment->getCcExpYear()))->setXCardCode($payment->getCcCid());
     }
     return $request;
 }
Exemplo n.º 5
0
 /**
  * Cancel payment
  *
  * @param \Magento\Framework\Object $payment
  * @return void
  */
 public function cancel(\Magento\Framework\Object $payment)
 {
     if (!$payment->getOrder()->getInvoiceCollection()->count()) {
         $this->void($payment);
     }
 }
Exemplo n.º 6
0
 /**
  * Call DoAuthorize
  *
  * @param int $amount
  * @param \Magento\Framework\Object $payment
  * @param string $parentTransactionId
  * @return \Magento\Paypal\Model\Api\AbstractApi
  */
 protected function _callDoAuthorize($amount, $payment, $parentTransactionId)
 {
     $apiData = $this->_pro->getApi()->getData();
     foreach ($apiData as $k => $v) {
         if (is_object($v)) {
             unset($apiData[$k]);
         }
     }
     $this->_checkoutSession->setPaypalTransactionData($apiData);
     $this->_pro->resetApi();
     $api = $this->_setApiProcessableErrors()->setAmount($amount)->setCurrencyCode($payment->getOrder()->getBaseCurrencyCode())->setTransactionId($parentTransactionId)->callDoAuthorization();
     $payment->setAdditionalInformation($this->_authorizationCountKey, $payment->getAdditionalInformation($this->_authorizationCountKey) + 1);
     return $api;
 }
Exemplo n.º 7
0
 /**
  * Return request object with information for 'authorization' or 'sale' action
  *
  * @param Object|Payment $payment
  * @param float $amount
  * @return Object
  */
 protected function _buildPlaceRequest(Object $payment, $amount)
 {
     $request = $this->buildBasicRequest();
     $request->setAmt(round($amount, 2));
     $request->setAcct($payment->getCcNumber());
     $request->setExpdate(sprintf('%02d', $payment->getCcExpMonth()) . substr($payment->getCcExpYear(), -2, 2));
     $request->setCvv2($payment->getCcCid());
     $order = $payment->getOrder();
     if (!empty($order)) {
         $request->setCurrency($order->getBaseCurrencyCode());
         $orderIncrementId = $order->getIncrementId();
         $request->setCurrency($order->getBaseCurrencyCode())->setInvnum($orderIncrementId)->setPonum($order->getId())->setComment1($orderIncrementId);
         $request = $this->fillCustomerContacts($order, $request);
     }
     return $request;
 }