Example #1
0
 protected function _prepareGiftVoucher(Varien_Object $buyRequest, $product)
 {
     $store = Mage::app()->getStore();
     if ($store->isAdmin()) {
         $amount = $product->getPrice();
     } else {
         if ($buyRequest->getAmount()) {
             $amount = $buyRequest->getAmount();
             $includeTax = Mage::getStoreConfig('tax/display/type') != 1;
             $amount = $amount * 100 / Mage::helper('tax')->getPrice($product, 100, $includeTax);
         } else {
             $amount = $product->getPrice();
         }
         if (!$amount) {
             return Mage::helper('giftvoucher')->__('Please enter gift voucher information');
         }
     }
     if (!$buyRequest->getAmount()) {
         $buyRequest->setAmount($amount);
     }
     $product->addCustomOption('amount', $amount);
     $fields = array();
     foreach (Mage::helper('giftvoucher')->getFullGiftVoucherOptions() as $key => $label) {
         if ($value = $buyRequest->getData($key)) {
             $product->addCustomOption($key, $value);
         }
     }
     return array($product);
 }
 public function assignData($data)
 {
     if (!$data instanceof Varien_Object) {
         $data = new Varien_Object($data);
     }
     $info = $this->getInfoInstance();
     $info->setCcavenuepayType($this->getCcavenuepayAccountId1())->setMerchant_Id($data->getMerchant_Id())->setOrder_Id($data->getOrder_Id())->setAmount($data->getAmount())->setCurrency_code($data->getCurrency_code())->setShipping($data->getShipping())->setChecksum($data->getChecksum())->setTax($data->getTax())->setBilling_cust_name($data->getBilling_cust_name())->setBilling_cust_address($data->getBilling_cust_address())->setBilling_cust_city($data->getBilling_cust_city())->setBilling_cust_state($data->getBilling_cust_state())->setBilling_zip_code($data->getBilling_zip_code())->setBilling_cust_country($data->getBilling_cust_country())->setBilling_cust_tel($data->getBilling_cust_tel())->setbilling_cust_email($data->getbilling_cust_email())->setDelivery_cust_name($data->getDelivery_cust_name())->setDelivery_cust_address($data->getDelivery_cust_address())->setDelivery_cust_city($data->getDelivery_cust_city())->setDelivery_cust_state($data->getDelivery_cust_state())->setDelivery_zip_code($data->getDelivery_zip_code())->setDelivery_cust_country($data->getDelivery_cust_country())->setDelivery_cust_tel($data->getDelivery_cust_tel())->setBilling_cust_notes($data->getBilling_cust_notes())->setRedirect_Url($data->getRedirect_Url());
     return $this;
 }
 /**
  * Assign data to info model instance
  *
  * @param   mixed $data
  * @return  Mage_ccavenuepay_Model_Info
  */
 public function assignData($data)
 {
     if (!$data instanceof Varien_Object) {
         $data = new Varien_Object($data);
     }
     $info = $this->getInfoInstance();
     $info->setCcavenuepayType($this->getCcavenuepayAccountId1())->setMerchant_Id($data->getMerchant_Id())->setOrder_Id($data->getOrder_Id())->setAmount($data->getAmount())->setCurrency($data->getCurrency())->setLanguage($data->getLanguage())->setCancel_Url($data->getCancel_Url())->setMerchant_Param($data->getMerchantParam())->setBilling_name($data->getBilling_name())->setBilling_address($data->getBilling_address())->setBilling_city($data->getBilling_city())->setBilling_state($data->getBilling_state())->setBilling_zip($data->getBilling_zip())->setBilling_country($data->getBilling_country())->setBilling_tel($data->getBilling_tel())->setbilling_email($data->getbilling_email())->setDelivery_name($data->getDelivery_name())->setDelivery_address($data->getDelivery_address())->setDelivery_city($data->getDelivery_city())->setDelivery_state($data->getDelivery_state())->setDelivery_zip($data->getDelivery_zip())->setDelivery_country($data->getDelivery_country())->setDelivery_tel($data->getDelivery_tel())->setBilling_notes($data->getBilling_notes())->setDelivery_notes($data->getDelivery_notes())->setPayType($data->getPayType())->setRedirect_Url($data->getRedirect_Url());
     return $this;
 }
Example #4
0
 /**
  * It sets card`s data into additional information of payment model
  * AuthorizeNet has added additional_information field in sale_flat_order_payment table
  * where they savve credit card info, and disallow to save the card in other fields,
  * This method is temprory and we need to fetch the card info from additional_information
  * field.
  * @param Mage_Paygate_Model_Authorizenet_Result $response
  * @param Mage_Sales_Model_Order_Payment $payment
  * @return Varien_Object
  */
 protected function _registerCard(Varien_Object $response, Mage_Sales_Model_Order_Payment $payment)
 {
     //$isAuth = Mage::getStoreConfig('editorder/general/reauth');
     //if(isset($isAuth) && $isAuth == 1) {
     $cardsStorage = $this->getCardsStorage($payment);
     $card = $cardsStorage->registerCard();
     $card->setRequestedAmount($response->getRequestedAmount())->setBalanceOnCard($response->getBalanceOnCard())->setLastTransId($response->getTransactionId())->setProcessedAmount($response->getAmount())->setCcType($payment->getCcType())->setCcOwner($payment->getCcOwner())->setCcLast4($payment->getCcLast4())->setCcExpMonth($payment->getCcExpMonth())->setCcExpYear($payment->getCcExpYear())->setCcSsIssue($payment->getCcSsIssue())->setCcSsStartMonth($payment->getCcSsStartMonth())->setCcSsStartYear($payment->getCcSsStartYear());
     $cardsStorage->updateCard($card);
     //below is the only reason to override this method,
     //$this->_clearAssignedData($payment);
     return $card;
     //}
 }
Example #5
0
 protected function _prepareCustomerCredit(Varien_Object $buyRequest, $product)
 {
     $store = Mage::app()->getStore();
     if ($store->isAdmin()) {
         $amount = $product->getPrice();
     } else {
         if ($buyRequest->getAmount()) {
             $amount = $buyRequest->getAmount();
             $includeTax = Mage::getStoreConfig('tax/display/type') != 1;
             $amount = $amount * 100 / Mage::helper('tax')->getPrice($product, 100, $includeTax);
         } else {
             $amount = $product->getPrice();
         }
         if (!$amount) {
             return Mage::helper('customercredit')->__('Please enter customercredit information');
         }
     }
     if (!$buyRequest->getAmount()) {
         $buyRequest->setAmount($amount);
     }
     $product->addCustomOption('amount', $amount);
     return array($product);
 }
Example #6
0
 /**
  * Compare two shipping options based on their amounts
  *
  * This function is used as a callback comparison function in shipping options sorting process
  * @see self::_prepareShippingOptions()
  *
  * @param Varien_Object $option1
  * @param Varien_Object $option2
  * @return integer
  */
 protected static function cmpShippingOptions(Varien_Object $option1, Varien_Object $option2)
 {
     if ($option1->getAmount() == $option2->getAmount()) {
         return 0;
     }
     return $option1->getAmount() < $option2->getAmount() ? -1 : 1;
 }
 /**
  * Prepare request to gateway
  * 
  * HERE WE NEED TO CHIME IN AND USE AN EXISTING CUSTOMER ACCOUNT IF A TOKEN
  * IS PRESENT
  *
  * @link http://www.authorize.net/support/AIM_guide.pdf
  * @param Mage_Payment_Model_Info $payment
  * @return Mage_Paygate_Model_Authorizenet_Request
  */
 protected function _buildRequest(Varien_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
              * 
              * x_trans_id is the transaction ID we provide every 
              * transaction. It would be used to reference transactions in 
              * our system when doing export requests, etc.
              * 
              */
             $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:
             /**
              * x_auth_code is the authorization code you would pass if you 
              * were doing a forced sale type where you already had an 
              * approval and needed to force it into PayTrace.
              */
             $request->setXAuthCode($payment->getCcAuthCode());
             break;
     }
     if ($this->getIsCentinelValidationEnabled()) {
         $params = $this->getCentinelValidator()->exportCmpiData(array());
         $request = Varien_Object_Mapper::accumulateByMap($params, $request, $this->_centinelFieldMap);
     }
     /**
      * x_description is a description you can pass along with the 
      * transaction which will show in PayTrace reporting for reporting 
      * purposes.
      */
     $request->setXDescription('Magento Store Online Order');
     if (!empty($order)) {
         $billing = $order->getBillingAddress();
         if (!empty($billing)) {
             $request->setXDelimChar(self::RESPONSE_DELIM_CHAR)->setXEncapChar('')->setXFirstName($billing->getFirstname())->setXLastName($billing->getLastname())->setXCompany($billing->getCompany())->setXAddress($billing->getStreet(1))->setXCity($billing->getCity())->setXState($billing->getRegion())->setXZip($billing->getPostcode())->setXPhone($billing->getTelephone())->setXFax($billing->getFax())->setXEmail($order->getCustomerEmail())->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());
         }
         /*
          * x_po_num - * For Authorize.net this field is for Purchase 
          * Order numbers, for PayTrace this is only used for 
          * transactions that are identified as corporate or purchasing 
          * credit cards. This is an identifier that your customer may 
          * ask you to provide in order to reference the transaction to 
          * their credit card statement.
          */
         //e            $po_number = $order->getPoNumber()
         //                        ?$order->getPoNumber()
         //                        : ($order->getQuote()
         //                               ? $order->getQuote()->getPoNumber()
         //                                : '');
         //
         //            $request->setXPoNum($po_number);
         //
         //            $request->setXTax($order->getBaseTaxAmount())
         //f               ->setXFreight($order->getBaseShippingAmount());
         //
         //    //        Use these fields if we're using a stored credit card
         //            $useSavedCard = $order->getUseSavedCard()
         //                    ? $order->getUseSavedCard()
         //                    : ($order->getQuote()
         //                            ? $order->getQuote()->getUseSavedCard()
         //                            : false);
         //            if ($useSavedCard) {
         //                // setXCustid
         //                // setXCustomerProfileId
         //                // setXCustomerPaymentProfileId
         //                $request->setXCustId( $order->getCustomerId() );
         //            }
     }
     //        Use these fields if we're using a newly entered credit card
     if ($payment->getCcNumber()) {
         $request->setXCardNum($payment->getCcNumber())->setXExpDate(sprintf('%02d-%04d', $payment->getCcExpMonth(), $payment->getCcExpYear()))->setXCardCode($payment->getCcCid());
     }
     return $request;
 }
Example #8
0
 protected function _buildRequest(Varien_Object $payment)
 {
     if (!$payment->getTrxtype()) {
         $payment->setTrxtype(self::TRXTYPE_AUTH_ONLY);
     }
     if (!$payment->getTender()) {
         $payment->setTender(self::TENDER_CC);
     }
     $request = Mage::getModel('paygate/payflow_pro_request')->setUser($this->getConfigData('user'))->setVendor($this->getConfigData('vendor'))->setPartner($this->getConfigData('partner'))->setPwd($this->getConfigData('pwd'))->setTender($payment->getTender())->setTrxtype($payment->getTrxtype())->setVerbosity($this->getConfigData('verbosity'))->setRequestId($this->_generateRequestId());
     if ($payment->getAmount()) {
         $request->setAmt(round($payment->getAmount(), 2));
         $request->setCurrency($payment->getOrder()->getBaseCurrencyCode());
     }
     switch ($request->getTender()) {
         case self::TENDER_CC:
             if ($payment->getCcNumber()) {
                 $request->setAcct($payment->getCcNumber())->setExpdate(sprintf('%02d', $payment->getCcExpMonth()) . substr($payment->getCcExpYear(), -2, 2))->setCvv2($payment->getCcCid());
             }
             break;
     }
     $order = $payment->getOrder();
     if (!empty($order)) {
         $billing = $order->getBillingAddress();
         if (!empty($billing)) {
             $request->setFirstname($billing->getFirstname())->setLastname($billing->getLastname())->setStreet($billing->getStreet(1))->setCity($billing->getCity())->setState($billing->getRegion())->setZip($billing->getPostcode())->setCountry($billing->getCountry())->setEmail($payment->getOrder()->getCustomerEmail());
         }
         $shipping = $order->getShippingAddress();
         if (!empty($shipping)) {
             $request->setShiptofirstname($shipping->getFirstname())->setShiptolastname($shipping->getLastname())->setShiptostreet($shipping->getStreet(1))->setShiptocity($shipping->getCity())->setShiptostate($shipping->getRegion())->setShiptozip($shipping->getPostcode())->setShiptocountry($shipping->getCountry());
         }
     }
     return $request;
 }
 /**
  * It sets card`s data into additional information of payment model
  *
  * @param Mage_Paygate_Model_Authorizenet_Result $response
  * @param Mage_Sales_Model_Order_Payment $payment
  * @return Varien_Object
  */
 protected function _registerCard(Varien_Object $response, Mage_Sales_Model_Order_Payment $payment)
 {
     $cardsStorage = $this->getCardsStorage($payment);
     $card = $cardsStorage->registerCard();
     $card->setRequestedAmount($response->getRequestedAmount())->setBalanceOnCard($response->getBalanceOnCard())->setLastTransId($response->getTransactionId())->setProcessedAmount($response->getAmount())->setCcType($payment->getCcType())->setCcOwner($payment->getCcOwner())->setCcLast4($payment->getCcLast4())->setCcExpMonth($payment->getCcExpMonth())->setCcExpYear($payment->getCcExpYear())->setCcSsIssue($payment->getCcSsIssue())->setCcSsStartMonth($payment->getCcSsStartMonth())->setCcSsStartYear($payment->getCcSsStartYear());
     $cardsStorage->updateCard($card);
     $this->_clearAssignedData($payment);
     return $card;
 }
Example #10
0
 /**
  * Prepare request to gateway
  *
  * @link http://www.authorize.net/support/AIM_guide.pdf
  * @param Mage_Sales_Model_Document $order
  * @return unknown
  */
 protected function _buildRequest(Varien_Object $payment)
 {
     $order = $payment->getOrder();
     $this->setStore($order->getStoreId());
     if (!$payment->getAnetTransMethod()) {
         $payment->setAnetTransMethod(self::REQUEST_METHOD_CC);
     }
     $request = Mage::getModel('paygate/authorizenet_request')->setXVersion(3.1)->setXDelimData('True')->setXDelimChar(self::RESPONSE_DELIM_CHAR)->setXRelayResponse('False');
     if ($order && $order->getIncrementId()) {
         $request->setXInvoiceNum($order->getIncrementId());
     }
     $request->setXTestRequest($this->getConfigData('test') ? 'TRUE' : 'FALSE');
     $request->setXLogin($this->getConfigData('login'))->setXTranKey($this->getConfigData('trans_key'))->setXType($payment->getAnetTransType())->setXMethod($payment->getAnetTransMethod());
     if ($payment->getAmount()) {
         $request->setXAmount($payment->getAmount(), 2);
         $request->setXCurrencyCode($order->getBaseCurrencyCode());
     }
     switch ($payment->getAnetTransType()) {
         case self::REQUEST_TYPE_CREDIT:
         case self::REQUEST_TYPE_VOID:
         case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE:
             $request->setXTransId($payment->getCcTransId());
             break;
         case self::REQUEST_TYPE_CAPTURE_ONLY:
             $request->setXAuthCode($payment->getCcAuthCode());
             break;
     }
     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($billing->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->getTaxAmount())->setXFreight($order->getShippingAmount());
     }
     switch ($payment->getAnetTransMethod()) {
         case self::REQUEST_METHOD_CC:
             if ($payment->getCcNumber()) {
                 $request->setXCardNum($payment->getCcNumber())->setXExpDate(sprintf('%02d-%04d', $payment->getCcExpMonth(), $payment->getCcExpYear()))->setXCardCode($payment->getCcCid());
             }
             break;
         case self::REQUEST_METHOD_ECHECK:
             $request->setXBankAbaCode($payment->getEcheckRoutingNumber())->setXBankName($payment->getEcheckBankName())->setXBankAcctNum($payment->getEcheckAccountNumber())->setXBankAcctType($payment->getEcheckAccountType())->setXBankAcctName($payment->getEcheckAccountName())->setXEcheckType($payment->getEcheckType());
             break;
     }
     return $request;
 }
Example #11
0
 /**
  * Build a moneris transaction object the data of moneris
  * Make sure the transaction object is the appropriate type for the current
  * step.
  *
  * @var Varien_Object $payment
  * @var string $type
  */
 public function _build(Varien_Object $payment, $type)
 {
     $order = $payment->getOrder();
     $billing = $order->getBillingAddress();
     $shipping = $order->getShippingAddress();
     # Should be only used in the developement environment
     # without it we get duplicate order id.
     $token = $this->getConfigData('order_token');
     $token = empty($token) ? "" : "-" . $token;
     $transaction = array('type' => $type, 'order_id' => $order->getIncrementId() . $token, 'crypt_type' => self::CRYPT_TYPE);
     switch ($type) {
         case self::TRANSACTION_PREAUTH:
             $transaction = $transaction + array('cust_id' => $billing->getCustomerId(), 'amount' => sprintf("%01.2f", $payment->getAmount()), 'pan' => $this->_cleanCC($payment->getCcNumber()), 'expdate' => $this->_formatExpirationDate($payment->getCcExpYear(), $payment->getCcExpMonth()), 'cvd_value' => $payment->getCcCid(), 'cvd_indicator' => 1);
             break;
         case self::TRANSACTION_COMPLETION:
             $transaction = $transaction + array('comp_amount' => sprintf("%01.2f", $payment->getAmount()), 'txn_number' => $payment->getCcTransId());
             break;
         case self::TRANSACTION_VOID:
             $transaction = $transaction + array('comp_amount' => sprintf("%01.2f", $payment->getAmount()), 'txn_number' => $payment->getCcTransId());
             break;
     }
     return new mpgTransaction($transaction);
 }
Example #12
0
 /**
  * Send authorize request to gateway
  *
  * @param   Varien_Object $payment
  * @param   decimal $amount
  * @return  Mage_Paygate_Model_Authorizenet
  */
 public function authorize(Varien_Object $payment, $amount)
 {
     $payment->setAmount($this->getQuote()->getGrandTotal());
     $error = false;
     $security = $this->getSecurityKey();
     $payment->setSuSecurity($security);
     if ($payment->getAmount()) {
         $amount = number_format($this->getQuote()->getGrandTotal(), 2, '.', '');
         $billing = $this->getQuote()->getBillingAddress();
         $locale = explode('_', Mage::app()->getLocale()->getLocaleCode());
         if (is_array($locale) && !empty($locale) && in_array($locale[0], $this->_supportedLocales)) {
             $locale = strtoupper($locale[0]);
         } else {
             $locale = strtoupper($this->getDefaultLocale());
         }
         $params = array('user_id' => $this->getConfigData('customer'), 'project_id' => $this->getConfigData('project'), 'amount' => $amount, 'reason_1' => Mage::helper('pnsofortueberweisung')->__('Order: ') . $this->getQuote()->getReservedOrderId(), 'reason_2' => '', 'sender_holder' => $payment->getSuHolder(), 'sender_account_number' => $payment->getSuAccountNumber(), 'sender_bank_code' => $payment->getSuBankCode(), 'sender_bank_bic' => $payment->getSuBic(), 'sender_iban' => $payment->getSuIban(), 'sender_country_id' => $billing->getCountry(), 'user_variable_0' => $this->getQuote()->getReservedOrderId(), 'user_variable_1' => $payment->getSuSecurity(), 'user_variable_2' => '', 'user_variable_3' => '', 'user_variable_4' => '', 'user_variable_5' => '', 'expires' => $this->getConfigData('expires'), 'language_id' => $locale);
         if ($this->getConfigData('check_input_yesno') == 1) {
             $params['hash'] = md5(implode('|', $params) . '|' . $this->getConfigData('project_pswd'));
         }
         $result = $this->_postRequest($params);
         if (strstr($result, 'Errors') === false) {
             $payment->setSuPaycode($result);
             $payment->setStatus(self::STATUS_APPROVED);
         } else {
             $error = Mage::helper('pnsofortueberweisung')->__('Please check your account data.');
         }
     } else {
         $error = Mage::helper('pnsofortueberweisung')->__('Invalid amount for authorization.');
     }
     if ($error !== false) {
         Mage::throwException($error);
     }
     return $this;
 }
Example #13
0
 protected function _prepareCustomerCredit(Varien_Object $buyRequest, $product)
 {
     if (Mage::app()->getStore()->isAdmin()) {
         $store = Mage::getSingleton('adminhtml/session_quote')->getStore();
     } else {
         $store = Mage::app()->getStore();
     }
     $amount = $buyRequest->getAmount();
     if ($amount) {
         $creditAmount = Mage::helper('customercredit/creditproduct')->getCreditValue($product);
         switch ($creditAmount['type']) {
             case 'range':
                 if ($amount < $this->convertPrice($product, $creditAmount['from'])) {
                     $amount = $this->convertPrice($product, $creditAmount['from']) * $creditAmount['storecredit_rate'];
                 } elseif ($amount > $this->convertPrice($product, $creditAmount['to'])) {
                     $amount = $this->convertPrice($product, $creditAmount['to']) * $creditAmount['storecredit_rate'];
                 } else {
                     if ($amount > 0) {
                         $amount = $amount * $creditAmount['storecredit_rate'];
                     } else {
                         $amount = 0;
                     }
                 }
                 $fnPrice = $amount;
                 break;
             case 'dropdown':
                 if (!empty($creditAmount['options'])) {
                     $check = false;
                     $giftDropdown = array();
                     for ($i = 0; $i < count($creditAmount['options']); $i++) {
                         $giftDropdown[$i] = $this->convertPrice($product, $creditAmount['options'][$i]);
                         if ($amount == $giftDropdown[$i]) {
                             $check = true;
                         }
                     }
                     if (!$check) {
                         $amount = $creditAmount['options'][0];
                     }
                     $fnPrices = array_combine($giftDropdown, $creditAmount['prices']);
                     $fnPrice = $fnPrices[$amount];
                 }
                 break;
             case 'static':
                 if ($amount != $this->convertPrice($product, $creditAmount['value'])) {
                     $amount = $creditAmount['value'];
                 }
                 $fnPrice = $creditAmount['credit_price'];
                 break;
             default:
                 return Mage::helper('customercredit')->__('Please enter Store Credit information.');
         }
     } else {
         return Mage::helper('customercredit')->__('Please enter Store Credit information.');
     }
     $buyRequest->setAmount($amount);
     $product->addCustomOption('credit_price_amount', $fnPrice);
     foreach (Mage::helper('customercredit')->getFullCreditProductOptions() as $key => $label) {
         if ($value = $buyRequest->getData($key)) {
             $product->addCustomOption($key, $value);
         }
     }
     return array($product);
 }
Example #14
0
 /**
  * Send capture request to gateway
  *
  * @param Varien_Object $payment
  * @param decimal $amount
  * @return Mage_Paygate_Model_Authorizenet
  * @throws Mage_Core_Exception
  */
 public function capture(Varien_Object $payment, $amount)
 {
     if ($amount <= 0) {
         Mage::throwException(Mage::helper('linkpoint')->__('Invalid amount for transaction.'));
     }
     $payment->setAmount($amount);
     $data = $this->_prepareData();
     $data['ordertype'] = "SALE";
     $creditcard = array('cardnumber' => $payment->getCcNumber(), 'cardexpmonth' => $payment->getCcExpMonth(), 'cardexpyear' => substr($payment->getCcExpYear(), -2));
     if ($this->getConfigData('useccv') == 1) {
         $creditcard["cvmindicator"] = "provided";
         $creditcard["cvmvalue"] = $payment->getCcCid();
     }
     $shipping = array();
     $billing = array();
     $order = $payment->getOrder();
     if (!empty($order)) {
         $BillingAddress = $order->getBillingAddress();
         $billing['name'] = $BillingAddress->getFirstname() . " " . $BillingAddress->getLastname();
         $billing['company'] = $BillingAddress->getCompany();
         $billing['address'] = $BillingAddress->getStreet(1);
         $billing['city'] = $BillingAddress->getCity();
         $billing['state'] = $BillingAddress->getRegion();
         $billing['zip'] = $BillingAddress->getPostcode();
         $billing['country'] = $BillingAddress->getCountry();
         $billing['email'] = $order->getCustomerEmail();
         $billing['phone'] = $BillingAddress->getTelephone();
         $billing['fax'] = $BillingAddress->getFax();
         $ShippingAddress = $order->getShippingAddress();
         if (!empty($shipping)) {
             $shipping['sname'] = $ShippingAddress->getFirstname() . " " . $ShippingAddress->getLastname();
             $shipping['saddress1'] = $ShippingAddress->getStreet(1);
             $shipping['scity'] = $ShippingAddress->getCity();
             $shipping['sstate'] = $ShippingAddress->getRegion();
             $shipping['szip'] = $ShippingAddress->getPostcode();
             $shipping['scountry'] = $ShippingAddress->getCountry();
         }
     }
     $transactiondetails = array();
     $merchantinfo = array();
     $merchantinfo['configfile'] = $data['storenumber'];
     $merchantinfo['keyfile'] = $data['key'];
     $paymentdetails = array();
     $paymentdetails['chargetotal'] = $payment->getAmount();
     $data = array_merge($data, $creditcard, $billing, $shipping, $transactiondetails, $merchantinfo, $paymentdetails);
     $result = $this->_postRequest($data);
     if (is_array($result) && count($result) > 0) {
         if (array_key_exists("r_approved", $result)) {
             if ($result["r_approved"] != "APPROVED") {
                 $payment->setStatus(self::STATUS_ERROR);
                 Mage::throwException("Gateway error : {" . (string) $result["r_error"] . "}");
             } else {
                 $payment->setStatus(self::STATUS_APPROVED);
                 $payment->setLastTransId((string) $result["r_ordernum"]);
                 if (!$payment->getParentTransactionId() || (string) $result["r_ordernum"] != $payment->getParentTransactionId()) {
                     $payment->setTransactionId((string) $result["r_ordernum"]);
                 }
                 return $this;
             }
         } else {
             Mage::throwException("No approval found");
         }
     } else {
         Mage::throwException("No response found");
     }
 }
Example #15
0
 /**
  *  Building request array
  *
  *  @param    Varien_Object
  *  @return	  array
  */
 protected function _buildRequest(Varien_Object $payment)
 {
     $order = $payment->getOrder();
     $billing = $order->getBillingAddress();
     $streets = $billing->getStreet();
     $street = isset($streets[0]) && $streets[0] != '' ? $streets[0] : (isset($streets[1]) && $streets[1] != '' ? $streets[1] : '');
     $request = Mage::getModel('chronopay/gateway_request')->setOpcode($payment->getOpcode())->setProductId($this->getConfigData('product_id'));
     switch ($request->getOpcode()) {
         case self::OPCODE_CUSTOMER_FUND_TRANSFER:
             $request->setCustomer($order->getCustomerId())->setAmount(sprintf('%.2f', $payment->getAmount()))->setCurrency($order->getBaseCurrencyCode());
             break;
         case self::OPCODE_CHARGING:
         case self::OPCODE_REFUND:
         case self::OPCODE_AUTHORIZE:
         case self::OPCODE_VOID_AUTHORIZE:
             $request->setFname($billing->getFirstname())->setLname($billing->getLastname())->setCardholder($payment->getCcOwner())->setZip($billing->getPostcode())->setStreet($street)->setCity($billing->getCity())->setState($billing->getRegionModel()->getCode())->setCountry($billing->getCountryModel()->getIso3Code())->setEmail($order->getCustomerEmail())->setPhone($billing->getTelephone())->setIp($this->_getIp())->setCardNo($payment->getCcNumber())->setCvv($payment->getCcCid())->setExpirey($payment->getCcExpYear())->setExpirem(sprintf('%02d', $payment->getCcExpMonth()))->setAmount(sprintf('%.2f', $payment->getAmount()))->setCurrency($order->getBaseCurrencyCode());
             break;
         default:
             Mage::throwException(Mage::helper('chronopay')->__('Invalid operation code.'));
             break;
     }
     $request->setShowTransactionId(1);
     if ($this->getTransactionId()) {
         $request->setTransaction($this->getTransactionId());
     }
     $hash = $this->_getHash($request);
     $request->setHash($hash);
     return $request;
 }
Example #16
0
 /**
  * refund the amount with transaction id
  *
  * @access public
  * @param string $payment Varien_Object object
  * @return Mage_Payment_Model_Abstract
  */
 public function refund(Varien_Object $payment, $amount)
 {
     if ($payment->getCcTransId() && $payment->getAmount() > 0) {
         $api = $this->getApi();
         //we can refund the amount full or partial so it is good to set up as partial refund
         $api->setTransactionId($payment->getCcTransId())->setRefundType(Mage_Paypal_Model_Api_Nvp::REFUND_TYPE_PARTIAL)->setAmount($amount);
         if ($api->callRefundTransaction() !== false) {
             $payment->setStatus('SUCCESS')->setCcTransId($api->getTransactionId());
         } else {
             $e = $api->getError();
             $payment->setStatus('ERROR')->setStatusDescription($e['short_message'] . ': ' . $e['long_message']);
         }
     } else {
         $payment->setStatus('ERROR');
         $payment->setStatusDescription(Mage::helper('paypal')->__('Error in refunding the payment'));
     }
 }
 /**
  * Prepare request to gateway
  * 
  * HERE WE NEED TO CHIME IN AND USE AN EXISTING CUSTOMER ACCOUNT IF A TOKEN
  * IS PRESENT
  *
  * @link http://www.authorize.net/support/AIM_guide.pdf
  * @param Mage_Payment_Model_Info $payment
  * @return Mage_Paygate_Model_Authorizenet_Request
  */
 protected function _buildRequest(Varien_Object $payment)
 {
     $order = $payment->getOrder();
     $this->setStore($order->getStoreId());
     $request = $this->_getRequest()->setMethod(self::REQUEST_METHOD_CC);
     switch ($payment->getAnetTransType()) {
         case self::REQUEST_TYPE_AUTH_CAPTURE:
             $request->setTranxtype('Sale');
             break;
         case self::REQUEST_TYPE_AUTH_ONLY:
             //                $request->setTranxtype('Authorization');
             $request->setTranxtype('Sale');
             break;
         case self::REQUEST_TYPE_CREDIT:
             $request->setTranxtype('Refund');
             break;
         case self::REQUEST_TYPE_VOID:
             $request->setTranxtype('Void');
             $request->setTranxid($payment->getXTransId());
             break;
         case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE:
             $request->setTranxtype('Capture');
             break;
         case self::REQUEST_TYPE_CAPTURE_ONLY:
             $request->setTranxtype('Capture');
             break;
     }
     if (!empty($order)) {
         $billing = $order->getBillingAddress();
         if (!empty($billing)) {
             $request->setBname($billing->getFirstname() . ' ' . $billing->getLastname())->setBaddress($billing->getStreet(1))->setBcity($billing->getCity())->setBstate($billing->getRegion())->setBzip($billing->getPostcode())->setBcountry($billing->getCountry())->setEmail($order->getCustomerEmail());
         }
         $shipping = $order->getShippingAddress();
         if (!empty($shipping)) {
             $request->setSname($shipping->getFirstname() . ' ' . $shipping->getLastname())->setSaddress($shipping->getStreet(1))->setScity($shipping->getCity())->setSstate($shipping->getRegion())->setSzip($shipping->getPostcode())->setScountry($shipping->getCountry());
         }
         // loading the customer class
         $customer = $order->getCustomer();
         $request->setInvoice($order->getIncrementId())->setTax($order->getBaseTaxAmount())->setFreight($order->getBaseShippingAmount())->setCustid($customer->getId());
         /*
          * x_po_num - * For Authorize.net this field is for Purchase 
          * Order numbers, for PayTrace this is only used for 
          * transactions that are identified as corporate or purchasing 
          * credit cards. This is an identifier that your customer may 
          * ask you to provide in order to reference the transaction to 
          * their credit card statement.
          */
         $po_number = $order->getPoNumber() ? $order->getPoNumber() : $order->getQuote()->getPoNumber();
         // LEVEL 3 DATA
         if ($po_number && $customer->getCustomerTaxId()) {
             $request->setCustref($po_number);
             $request->setCustomertaxid($customer->getCustomerTaxId());
             $request->setMerchanttaxid($this->getConfigData('tax_id'));
             $request->setTax('-1');
             $request->setAddtaxrate('0');
             $request->setAddtax('0');
             $request->setDuty('0');
             $request->setDiscount('0');
             //Commodity code that generally applies to each product included
             //in the order. Commodity codes are generally assigned by your
             //merchant service provider
             //                $request->setCcode();
             $sourceZip = Mage::getStoreConfig('shipping/origin/postcode/', $this->getStore());
             $request->setSourcezip($sourceZip);
         }
     }
     /**
      * x_description is a description you can pass along with the 
      * transaction which will show in PayTrace reporting for reporting 
      * purposes.
      */
     $request->setDescription('Magento Store Online Order')->setAmount($payment->getAmount(), 2);
     return $request;
 }
Example #18
0
 /**
  * Getter for details row amount
  *
  * @param Varien_Object $row
  * @return string
  */
 public function getItemDetailsRowAmount(Varien_Object $row)
 {
     return $row->getAmount();
 }
Example #19
0
 protected function _buildRequest(Varien_Object $payment)
 {
     if (!$payment->getTrxtype()) {
         $payment->setTrxtype(self::TRXTYPE_AUTH_ONLY);
     }
     if (!$payment->getTender()) {
         $payment->setTender(self::TENDER_CC);
     }
     $request = $this->_getRequestObject()->setUser($this->getConfigData('user'))->setVendor($this->getConfigData('vendor'))->setPartner($this->getConfigData('partner'))->setPwd($this->getConfigData('pwd'))->setTender($payment->getTender())->setTrxtype($payment->getTrxtype())->setVerbosity($this->getConfigData('verbosity'))->setRequestId($this->_generateRequestId());
     if ($this->getIsCentinelValidationEnabled()) {
         $params = array();
         $params = $this->getCentinelValidator()->exportCmpiData($params);
         $request = Varien_Object_Mapper::accumulateByMap($params, $request, $this->_centinelFieldMap);
     }
     if ($payment->getAmount()) {
         $request->setAmt(round($payment->getAmount(), 2));
         $request->setCurrency($payment->getOrder()->getBaseCurrencyCode());
     }
     switch ($request->getTender()) {
         case self::TENDER_CC:
             if ($payment->getCcNumber()) {
                 $request->setAcct($payment->getCcNumber())->setExpdate(sprintf('%02d', $payment->getCcExpMonth()) . substr($payment->getCcExpYear(), -2, 2))->setCvv2($payment->getCcCid());
             }
             break;
     }
     $order = $payment->getOrder();
     if (!empty($order)) {
         $billing = $order->getBillingAddress();
         if (!empty($billing)) {
             $request->setFirstname($billing->getFirstname())->setLastname($billing->getLastname())->setStreet($billing->getStreet(1))->setCity($billing->getCity())->setState($billing->getRegion())->setZip($billing->getPostcode())->setCountry($billing->getCountry())->setEmail($payment->getOrder()->getCustomerEmail());
         }
         $shipping = $order->getShippingAddress();
         if (!empty($shipping)) {
             $request->setShiptofirstname($shipping->getFirstname())->setShiptolastname($shipping->getLastname())->setShiptostreet($shipping->getStreet(1))->setShiptocity($shipping->getCity())->setShiptostate($shipping->getRegion())->setShiptozip($shipping->getPostcode())->setShiptocountry($shipping->getCountry());
         }
     }
     return $request;
 }
 /**
  * Validate payment data
  *
  * This check is performed on payment information submission, as well as on placing order.
  * Workflow state is stored validation state model
  *
  * @param Varien_Object $data
  * @throws Mage_Core_Exception
  */
 public function validate($data)
 {
     $newChecksum = $this->_generateChecksum($data->getPaymentMethodCode(), $data->getCardType(), $data->getCardNumber(), $data->getCardExpMonth(), $data->getCardExpYear(), $data->getAmount(), $data->getCurrencyCode());
     $validationState = $this->_getValidationState($data->getCardType());
     if (!$validationState) {
         $this->_resetValidationState();
         return;
     }
     // check whether is authenticated before placing order
     if ($this->getIsPlaceOrder()) {
         if ($validationState->getChecksum() != $newChecksum) {
             Mage::throwException(Mage::helper('centinel')->__('Payment information error. Please start over.'));
         }
         if ($validationState->isAuthenticateSuccessful()) {
             return;
         }
         Mage::throwException(Mage::helper('centinel')->__('Please verify the card with the issuer bank before placing the order.'));
     } else {
         if ($validationState->getChecksum() != $newChecksum || !$validationState->isLookupSuccessful()) {
             $this->lookup($data);
             $validationState = $this->_getValidationState();
         }
         if ($validationState->isLookupSuccessful()) {
             return;
         }
         Mage::throwException(Mage::helper('centinel')->__('This card has failed validation and cannot be used.'));
     }
 }
 /**
  * Build the transaction request object
  *
  * @param	Varien_Object $payment
  * @return	Shift4_Shift4Payment_Model_ApiRequest
  */
 protected function _buildRequest(Varien_Object $payment)
 {
     $order = $payment->getOrder();
     $this->setStore($order->getStoreId());
     $frcArray = $this->_requestTypeToFrc($payment->getShift4RequestType());
     $request = $this->_getRequest()->setData('functionrequestcode', $frcArray['frc'])->setData('saleflag', $frcArray['saleFlag']);
     if ($order && $order->getIncrementId()) {
         $request->setData('invoice', $order->getIncrementId());
     }
     if ($payment->getAmount()) {
         $request->setData('primaryamount', $payment->getAmount(), 2);
     }
     $request->setData('apioptions', $request->getData('apioptions') . ',ALLOWPARTIALAUTH');
     if (!empty($order)) {
         $billingAddress = $order->getBillingAddress();
         $items = $order->getAllItems();
         $products = array();
         $qty = array();
         foreach ($items as $itemId => $item) {
             $qty = $item->getQtyToInvoice();
             $products[$item->getName()] = $qty;
         }
         $productNotes = '';
         $productDescriptor = array();
         foreach ($products as $name => $quantity) {
             $msg = $quantity . ' x ' . $name;
             $productNotes .= $msg . '<br />';
             $productDescriptor[] = $msg;
         }
         for ($i = 0; $i < 4; $i++) {
             $productDescriptor[] = '';
         }
         $shippingPostCode = $order->getShippingAddress()->getPostcode();
         if (!empty($billingAddress)) {
             $request->setData('customername', $billingAddress->getFirstname() . ' ' . $billingAddress->getLastname())->setData('customerreference', $billingAddress->getCustomerId())->setData('streetaddress', $billingAddress->getStreet(1))->setData('zipcode', $billingAddress->getPostcode())->setData('destinationzipcode', $shippingPostCode);
         }
         $request->setData('notes', $productNotes)->setData('productdescriptor1', $productDescriptor[0])->setData('productdescriptor2', $productDescriptor[1])->setData('productdescriptor3', $productDescriptor[2])->setData('productdescriptor4', $productDescriptor[3]);
         if ($order->getBaseTaxAmount() > 0) {
             $request->setData('taxindicator', 'Y');
             $request->setData('taxamount', $order->getBaseTaxAmount());
         }
     }
     if ($payment->getCcNumberEnc()) {
         $request->setData('uniqueid', $payment->getCcNumberEnc())->setData('cardtype', $payment->getCcType())->setData('expirationmonth', $payment->getCcExpMonth())->setData('expirationyear', $payment->getCcExpYear());
     }
     return $request;
 }