/** * Try to create a card record from legacy data. */ public function importLegacyData(Varien_Object $payment) { // Customer ID -- pull from customer if possible, otherwise go to Authorize.Net. if ($this->getCustomer()->getAuthnetcimProfileId() != '') { $this->setProfileId($this->getCustomer()->getAuthnetcimProfileId()); } else { $this->_createCustomerProfile(); } // Payment ID -- pull from order if possible. $this->setPaymentId($payment->getOrder()->getExtCustomerId()); if ($this->getProfileId() == '' || $this->getPaymentId() == '') { Mage::helper('tokenbase')->log($this->getMethod(), 'Authorize.Net CIM: Unable to covert legacy data for processing. Please seek support.'); Mage::throwException(Mage::helper('tokenbase')->__('Authorize.Net CIM: Unable to covert legacy data for processing. Please seek support.')); } if ($payment->getCcType() != '') { $this->setAdditional('cc_type', $payment->getCcType()); } if ($payment->getCcLast4() != '') { $this->setAdditional('cc_last4', $payment->getCcLast4()); } if ($payment->getCcExpYear() > date('Y') || $payment->getCcExpYear() == date('Y') && $payment->getCcExpMonth() >= date('n')) { $this->setAdditional('cc_exp_year', $payment->getCcExpYear())->setAdditional('cc_exp_month', $payment->getCcExpMonth())->setExpires(sprintf("%s-%s-%s 23:59:59", $payment->getCcExpYear(), $payment->getCcExpMonth(), date('t', strtotime($payment->getCcExpYear() . '-' . $payment->getCcExpMonth())))); } return $this; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } // salva a bandeira, o numero de parcelas e o token $info = $this->getInfoInstance(); $additionaldata = array('parcels_number' => $data->getParcelsNumber()); if ($data->getToken()) { $tokenData = $this->_getTokenById($data->getToken()); $additionaldata['token'] = $tokenData['token']; $data->setCcType($tokenData['ccType']); } $info->setCcType($data->getCcType())->setCcNumber(Mage::helper('core')->encrypt($data->getCcNumber()))->setCcOwner($data->getCcOwner())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcCid(Mage::helper('core')->encrypt($data->getCcCid()))->setAdditionalData(serialize($additionaldata)); // pega dados de juros $withoutInterest = intval($this->getConfigData('installment_without_interest', $this->getStoreId())); $interestValue = floatval($this->getConfigData('installment_interest_value', $this->getStoreId())); // verifica se há juros if ($data->getParcelsNumber() > $withoutInterest) { $installmentValue = Mage::helper('Query_Cielo')->calcInstallmentValue($info->getQuote()->getGrandTotal(), $interestValue / 100, $data->getParcelsNumber()); $installmentValue = round($installmentValue, 2); $interest = $installmentValue * $data->getParcelsNumber() - $info->getQuote()->getGrandTotal(); $info->getQuote()->setInterest($info->getQuote()->getStore()->convertPrice($interest, false)); $info->getQuote()->setBaseInterest($interest); $info->getQuote()->setTotalsCollectedFlag(false)->collectTotals(); $info->getQuote()->save(); } else { $info->getQuote()->setInterest(0.0); $info->getQuote()->setBaseInterest(0.0); $info->getQuote()->setTotalsCollectedFlag(false)->collectTotals(); $info->getQuote()->save(); } return $this; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear()); return $this; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $info->setCcOwner($data->getCcOwner())->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear()); return $this; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $additionaldata = array('Cc_parcelas' => $data->getCcParcelas(), 'cc_cid_enc' => $info->encrypt($data->getCcCid())); $info->setCcType($data->getCcType())->setAdditionalData(serialize($additionaldata))->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear())->setCcNumberEnc($info->encrypt($data->getCcNumber()))->setCcCidEnc($info->encrypt($data->getCcCid())); return $this; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $session = Mage::getSingleton('core/session'); $info = $this->getInfoInstance(); $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear()); $session->setVeritransQuoteId($this->_getOrderId()); $session->setTokenBrowser($data->getTokenId()); return $this; }
/** * Capture payment method * * @param Varien_Object $payment * @param float $amount * @return $this * @throws Mage_Core_Exception */ public function capture(Varien_Object $payment, $amount) { $order = $payment->getOrder(); $billingAddress = $order->getBillingAddress(); try { $api = Stripe\Charge::create(array('amount' => $amount * 100, 'currency' => strtolower($order->getBaseCurrencyCode()), 'card' => array('number' => $payment->getCcNumber(), 'exp_month' => sprintf('%02d', $payment->getCcExpMonth()), 'exp_year' => $payment->getCcExpYear(), 'cvc' => $payment->getCcCid(), 'name' => $billingAddress->getName(), 'address_line1' => $billingAddress->getStreet(1), 'address_line2' => $billingAddress->getStreet(2), 'address_zip' => $billingAddress->getPostcode(), 'address_state' => $billingAddress->getRegion(), 'address_country' => $billingAddress->getCountry()), 'description' => sprintf('#%s, %s', $order->getIncrementId(), $order->getCustomerEmail()))); } catch (Exception $e) { $this->debugData($e->getMessage()); Mage::throwException(Mage::helper('boolfly_stripe')->__('Payment capturing error.')); } $payment->setTransactionId($api->id)->setIsTransactionClosed(0); return $this; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } // salva a bandeira $info = $this->getInfoInstance(); // converte nomenclatura da bandeira if ($data->getCcType() == "visa-electron") { $cardType = "visa"; } else { $cardType = $data->getCcType(); } $info->setCcType($cardType)->setCcNumber(Mage::helper('core')->encrypt($data->getCcNumber()))->setCcOwner($data->getCcOwner())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcCid(Mage::helper('core')->encrypt($data->getCcCid())); return $this; }
/** * Assign data to info model instance * * @param mixed $data * * @return Mage_Payment_Model_Method_Abstract */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $quote = $info->getQuote(); if ($this->isSingleOrder($quote)) { $info->setAdditionalInformation('installments', $data->getCcInstallments()); } if ($data->getCcChoice() === 'saved') { $info->setAdditionalInformation('PaymentMethod', $this->_code)->setAdditionalInformation('use_saved_cc', true); return $this; } $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear())->setAdditionalInformation('PaymentMethod', $this->_code)->setAdditionalInformation('use_saved_cc', false); return $this; }
public function processPayment(Varien_Object $payment, $amount) { ini_set('soap.wsdl_cache_enabled', '0'); $braspag_url = $this->getConfigData('service'); $merchant_id = $this->getConfigData('merchant_id'); $order = $payment->getOrder(); $order_id = $order->getIncrementId(); $soapclient = new Zend_Soap_Client($braspag_url); $parametros = array(); $parametros['merchantId'] = (string) $merchant_id; $parametros['orderId'] = (string) $order_id; $parametros['customerName'] = (string) $payment->getCcOwner(); $parametros['amount'] = (string) number_format($amount, 2, ',', '.'); $parametros['paymentMethod'] = (string) $this->getMethodConfig($payment->getCcType()); $parametros['holder'] = (string) $payment->getCcOwner(); $parametros['cardNumber'] = (string) $payment->getCcNumber(); $parametros['expiration'] = (string) $payment->getCcExpMonth() . '/' . $payment->getCcExpYear(); $parametros['securityCode'] = (string) $payment->getCcCid(); if (!$this->getCheckout()->getCcParcelamento()) { $parametros['numberPayments'] = '1'; $parametros['typePayment'] = '0'; } else { $parametros['numberPayments'] = '3'; $parametros['typePayment'] = $this->getParcelamentoType(); } $authorize = $soapclient->Authorize($parametros); $resultado = $authorize->AuthorizeResult; $transacao = Mage::getModel('braspag/braspag'); $transacao->setOrderId($order_id); $transacao->setAuthorisation($resultado->authorisationNumber); $transacao->setAmount($amount); $transacao->setNumberPayments($parametros['numberPayments']); $transacao->setTypePayment($parametros['typePayment']); $transacao->setTransactionId($resultado->transactionId); $transacao->setMessage($resultado->message); $transacao->setReturnCode($resultado->returnCode); $transacao->setStatus($resultado->status); $transacao->save(); return $transacao; }
/** * 1) Called everytime the adyen_cc is called or used in checkout * @description Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); // set number of installements $info->setAdditionalInformation('number_of_installments', $data->getAdditionalData()); // save value remember details checkbox $info->setAdditionalInformation('store_cc', $data->getStoreCc()); if ($this->isCseEnabled()) { $info->setCcType($data->getCcType()); $info->setAdditionalInformation('encrypted_data', $data->getEncryptedData()); } else { $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcCid($data->getCcCid())->setPoNumber($data->getAdditionalData()); } if ($info->getAdditionalInformation('number_of_installments') != "") { // recalculate the totals so that extra fee is defined $quote = Mage::getModel('checkout/type_onepage') !== false ? Mage::getModel('checkout/type_onepage')->getQuote() : Mage::getModel('checkout/session')->getQuote(); $quote->setTotalsCollectedFlag(false); $quote->collectTotals(); } return $this; }
public function callApi(Varien_Object $payment, $amount, $type) { $order = $payment->getOrder(); $invoiceNumber = $order->getIncrementId(); if ($type != 'authorizeandcaptureAIM') { /** * This will build the profile for the customer */ $customerID = $order->getCustomerId(); $customerEmail = $order->getCustomerEmail(); if (!$customerID) { /** * This will build the guest customer ID since they do not exist in the database yet */ $this->_guest = 1; //$customerEmail = 'guest-'. $customerEmail = $order->getCustomerEmail(); $guestCheck = Mage::getModel('authorizenetcim/guests')->load($customerEmail, 'email'); if (!$guestCheck->getData()) { $guest = Mage::getModel('authorizenetcim/guests'); $guest->setEmail($customerEmail); $guest->save(); $customerID = $guest->getGuestId(); } else { $customerID = $guestCheck->getGuestId(); } } $billingInfo = $order->getBillingAddress(); $shippingInfo = $order->getShippingAddress(); $ccType = $payment->getCcType(); $ccNumber = $payment->getCcNumber(); $ccExpDate = $payment->getCcExpYear() . '-' . str_pad($payment->getCcExpMonth(), 2, '0', STR_PAD_LEFT); $ccCCV = $payment->getCcCid(); /** * Checks to see if there is a token for profile and payment already associated with the customer * If it is a guest, there will not be one * I believe this may be extra unncessary code */ $tokenProfileId = $payment->getTokenProfileId(); $tokenPaymentProfileId = $payment->getTokenPaymentProfileId(); $postData = Mage::app()->getRequest()->getPost('payment', array()); if (isset($postData['ccsave_id'])) { $ccSaveId = $postData['ccsave_id']; } if ($customerID == $order->getIncrementId()) { /** * Can combine it with the below code to make * it an || statement instead of having the extra * lines of code */ $profileData = Mage::getModel('authorizenetcim/authorizenetcim')->load($customerID, 'customer_id')->getData(); $tokenProfileId = $profileData['token_profile_id']; $tokenPaymentProfileId = $profileData['token_payment_profile_id']; } elseif (isset($ccSaveId)) { $profileData = Mage::getModel('authorizenetcim/authorizenetcim')->load($ccSaveId)->getData(); $tokenProfileId = $profileData['token_profile_id']; $tokenPaymentProfileId = $profileData['token_payment_profile_id']; } if ($tokenProfileId == 0 && $tokenPaymentProfileId == 0 && ($type == 'authorize' || $type == 'capture' || $type == 'authorizeandcapture')) { /** * If token doesn't exist and type is = authorize, capture or authorizeandcapture * then it will create the token for you through authorize.net * and save it to the database */ if (isset($ccSaveId)) { /** * Can most likely be removed since it was done above already * Ambiguous call to the database */ $profileData = Mage::getModel('authorizenetcim/authorizenetcim')->load($ccSaveId)->getData(); $tokenProfileId = $profileData['token_profile_id']; $tokenPaymentProfileId = $profileData['token_payment_profile_id']; } else { $profile = Mage::getModel('authorizenetcim/authorizenetcim'); $profileCollection = $profile->getCollection()->addFieldToFilter('customer_id', $customerID)->addFieldToFilter('store_id', Mage::app()->getStore()->getStoreId()); if (count($profileCollection) == 0) { /** * If customer doesn't already exist in our database, it will try * to create it through the authorize.net section. It will also create the first initial * payment profile id */ $responseXML = $this->createCustomerProfileRequest($customerID, $customerEmail, $billingInfo, $shippingInfo, $ccNumber, $ccExpDate, $ccCCV, $ccType, $this->_guest); $tokenProfileId = $responseXML->customerProfileId; $tokenPaymentProfileId = $responseXML->customerPaymentProfileIdList->numericString; } else { /** * If customer already exists, it will get the profileID and then create the new * customer payment profile ID */ $tokenProfileId = $profileCollection->getFirstItem()->getTokenProfileId(); /** * Before we create a new payment profile id, we need to check * and see if it already exists */ // gets the last 4 of the cc $ccLast4 = substr($ccNumber, -4, 4); $tokenCheck = Mage::getModel('authorizenetcim/authorizenetcim')->getCollection()->addFieldToFilter('token_profile_id', $tokenProfileId)->addFieldToFilter('cc_last4', $ccLast4)->addFieldToSelect('token_payment_profile_id')->addFieldToSelect('token_profile_id'); $token = $tokenCheck->getFirstItem()->getData(); if (empty($token)) { $tokenPaymentProfileId = $this->createCustomerPaymentProfileRequest($customerID, $tokenProfileId, $billingInfo, $ccNumber, $ccExpDate, $ccCCV, $ccType); } else { $tokenProfileId = $token['token_profile_id']; $tokenPaymentProfileId = $token['token_payment_profile_id']; } } } } } //call xml creation functions switch ($type) { case 'authorize': $response = $this->runAuthorize($payment, $customerID, $amount, (string) $tokenProfileId, (string) $tokenPaymentProfileId, $invoiceNumber, $ccCCV); break; case 'capture': $response = $this->runCapture($payment, $invoiceNumber, $amount, $tokenProfileId, $tokenPaymentProfileId); break; case 'authorizeandcapture': $response = $this->runAuthorizeAndCapture($payment, $amount, $tokenProfileId, $tokenPaymentProfileId, $invoiceNumber, $ccCCV); break; case 'void': $response = $this->runVoid($payment, $tokenProfileId, $tokenPaymentProfileId, $refundTransactionId); break; case 'refund': $response = $this->runRefund($payment, $invoiceNumber, $amount, $tokenProfileId, $tokenPaymentProfileId); break; case 'authorizeandcaptureAIM': $response = $this->createAuthorizeCaptureAIM($amount, $payment, $order); break; case 'captureAIM': $response = $this->captureAIM($tokenProfileId); break; case 'createauthorizeaim': $response = $this->createAuthorizeAim($amount, $payment, $order); break; case 'refundAIM': $response = $this->createRefundAIM($amount, $payment, $order); break; } return $response; }
/** * Authorize or Capture payment * * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment * @param float $amount * @param bool $capture * @return $this */ private function _authorize(Varien_Object $payment, $amount, $capture) { $order = $payment->getOrder(); /* @var $order Mage_Sales_Model_Order */ $multiToken = false; $cardData = null; $additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null); $secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null; $saveCreditCard = !!(bool) $additionalData->getCcSaveFuture(); $customerId = $additionalData->getCustomerId(); if ($saveCreditCard) { $multiToken = true; $cardData = new HpsCreditCard(); $cardData->number = $payment->getCcLast4(); $cardData->expYear = $payment->getCcExpYear(); $cardData->expMonth = $payment->getCcExpMonth(); } $chargeService = $this->_getChargeService(); $cardHolder = $this->_getCardHolderData($order); $details = $this->_getTxnDetailsData($order); $cardOrToken = new HpsTokenData(); $cardOrToken->tokenValue = $secureToken; try { if ($capture) { if ($payment->getCcTransId()) { $response = $chargeService->capture($payment->getCcTransId(), $amount); } else { $response = $chargeService->charge($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details); } } else { $response = $chargeService->authorize($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details); } $this->_debugChargeService($chargeService); $payment->setStatus(self::STATUS_APPROVED); $payment->setAmount($amount); $payment->setLastTransId($response->transactionId); $payment->setCcTransId($response->transactionId); $payment->setTransactionId($response->transactionId); $payment->setIsTransactionClosed(0); if ($multiToken) { $tokenData = $response->tokenData; /* @var $tokenData HpsTokenData */ if ($tokenData->responseCode == '0') { if ($customerId > 0) { Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType, $customerId); } else { Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType); } } else { Mage::log('Requested multi token has not been generated for the transaction # ' . $response->transactionId, Zend_Log::WARN); } } } catch (HpsCreditException $e) { Mage::logException($e); $this->_debugChargeService($chargeService, $e); $payment->setStatus(self::STATUS_DECLINED); $this->throwUserError($e->getMessage(), $e->resultText, TRUE); } catch (HpsException $e) { $this->_debugChargeService($chargeService, $e); $payment->setStatus(self::STATUS_ERROR); $this->throwUserError($e->getMessage(), NULL, TRUE); } catch (Exception $e) { $this->_debugChargeService($chargeService, $e); Mage::logException($e); $payment->setStatus(self::STATUS_ERROR); $this->throwUserError($e->getMessage()); } return $this; }
/** * 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; }
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; }
/** * Return commno data for *all* transactions. * @return array Data */ public function _getGeneralTrnData(Varien_Object $payment, $adminParams = array()) { $order = $payment->getOrder(); $quoteObj = $this->_getQuote(); $vendorTxCode = $this->_getTrnVendorTxCode(); if ($payment->getCcNumber()) { $vendorTxCode .= $this->_cleanString(substr($payment->getCcOwner(), 0, 10)); } $payment->setVendorTxCode($vendorTxCode); $request = new Varien_Object(); $request->setVPSProtocol((string) $this->getVpsProtocolVersion($this->getConfigData('mode')))->setReferrerID($this->getConfigData('referrer_id'))->setVendor($this->getConfigData('vendor'))->setVendorTxCode($vendorTxCode); $request->setClientIPAddress($this->getClientIp()); if ($payment->getIntegra()) { //Server if (is_array($adminParams) && !empty($adminParams)) { $confParam = isset($adminParams['order']['send_confirmation']) ? '&e=' . (int) $adminParams['order']['send_confirmation'] : ''; if (isset($adminParams['order']['account']['email'])) { $confParam .= '&l=' . urlencode($adminParams['order']['account']['email']); } if (isset($adminParams['order']['account']['group_id'])) { $confParam .= '&g=' . $adminParams['order']['account']['group_id']; } } else { $confParam = ''; } $this->getSageSuiteSession()->setLastVendorTxCode($vendorTxCode); $request->setIntegration($payment->getIntegra()); $request->setData('notification_URL', $this->getNotificationUrl() . '&vtxc=' . $vendorTxCode . $confParam); $request->setData('success_URL', $this->getSuccessUrl()); $request->setData('redirect_URL', $this->getRedirectUrl()); $request->setData('failure_URL', $this->getFailureUrl()); } if ($this->_getIsAdminOrder()) { $request->setAccountType('M'); } if ($payment->getAmountOrdered()) { $this->_setRequestCurrencyAmount($request, $quoteObj); } if (!empty($order)) { $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setBillingAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setBillingSurname($this->ss($billing->getLastname(), 20))->setBillingFirstnames($this->ss($billing->getFirstname(), 20))->setBillingPostCode($this->sanitizePostcode($this->ss($billing->getPostcode(), 10)))->setBillingAddress1($this->ss($billing->getStreet(1), 100))->setBillingAddress2($this->ss($billing->getStreet(2), 100))->setBillingCity($this->ss($billing->getCity(), 40))->setBillingCountry($billing->getCountry())->setContactNumber(substr($this->_cphone($billing->getTelephone()), 0, 20)); if ($billing->getCountry() == 'US') { $request->setBillingState($billing->getRegionCode()); } $request->setCustomerEMail($billing->getEmail()); } if (!$request->getDescription()) { $request->setDescription('.'); } $shipping = $order->getShippingAddress(); if (!$quoteObj->isVirtual()) { $request->setDeliveryAddress($shipping->getStreet(1) . ' ' . $shipping->getCity() . ' ' . $shipping->getRegion() . ' ' . $shipping->getCountry())->setDeliverySurname($this->ss($shipping->getLastname(), 20))->setDeliveryFirstnames($this->ss($shipping->getFirstname(), 20))->setDeliveryPostCode($this->sanitizePostcode($this->ss($shipping->getPostcode(), 10)))->setDeliveryAddress1($this->ss($shipping->getStreet(1), 100))->setDeliveryAddress2($this->ss($shipping->getStreet(2), 100))->setDeliveryCity($this->ss($shipping->getCity(), 40))->setDeliveryCountry($shipping->getCountry())->setDeliveryPhone($this->ss(urlencode($this->_cphone($shipping->getTelephone())), 20)); if ($shipping->getCountry() == 'US') { $request->setDeliveryState($shipping->getRegionCode()); } } else { #If the cart only has virtual products, I need to put an shipping address to Sage Pay. #Then the billing address will be the shipping address to $request->setDeliveryAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setDeliverySurname($this->ss($billing->getLastname(), 20))->setDeliveryFirstnames($this->ss($billing->getFirstname(), 20))->setDeliveryPostCode($this->sanitizePostcode($this->ss($billing->getPostcode(), 10)))->setDeliveryAddress1($this->ss($billing->getStreet(1), 100))->setDeliveryAddress2($this->ss($billing->getStreet(2), 100))->setDeliveryCity($this->ss($billing->getCity(), 40))->setDeliveryCountry($billing->getCountry())->setDeliveryPhone($this->ss(urlencode($this->_cphone($billing->getTelephone())), 20)); if ($billing->getCountry() == 'US') { $request->setDeliveryState($billing->getRegionCode()); } } } if ($payment->getCcNumber()) { $request->setCardNumber($payment->getCcNumber())->setExpiryDate(sprintf('%02d%02d', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), strlen($payment->getCcExpYear()) - 2)))->setCardType($payment->getCcType())->setCV2($payment->getCcCid())->setCardHolder($payment->getCcOwner()); if ($payment->getCcIssue()) { $request->setIssueNumber($payment->getCcIssue()); } if ($payment->getCcStartMonth() && $payment->getCcStartYear()) { $request->setStartDate(sprintf('%02d%02d', $payment->getCcStartMonth(), substr($payment->getCcStartYear(), strlen($payment->getCcStartYear()) - 2))); } } $basket = Mage::helper('sagepaysuite')->getSagePayBasket($quoteObj, false); if (!empty($basket)) { if ($basket[0] == "<") { $request->setBasketXML($basket); } else { $request->setBasket($basket); } } if (!$request->getDeliveryPostCode()) { $request->setDeliveryPostCode('000'); } if (!$request->getBillingPostCode()) { $request->setBillingPostCode('000'); } return $request; }
/** * 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; }
/** * Note to self: * Custom fields are stored using the addData */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $info->setAdditionalData(serialize(array('cc_token' => $data['cc_token']))); if ($data['cc_token'] == 'manual') { $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear()); } else { $customer_tokens = $this->_getPaytraceTokens($info); $paytrace = null; foreach ($customer_tokens as $tk => $tv) { if ($tv->token_id == $data['cc_token']) { $paytrace = $tv; } } $last4 = empty($paytrace->token_id) ? '' : $paytrace->last4; $info->setCcType('')->setCcOwner('')->setCcLast4($last4)->setCcNumber('999999999999' . $last4)->setCcCid('')->setCcExpMonth('')->setCcExpYear('')->setCcSsIssue('')->setCcSsStartMonth('')->setCcSsStartYear(''); } return $this; }
/** * Fill out the request payload with payment data and update the API request * body with the complete request. * @param Api\IBidirectionalApi $api * @param Varien_Object $payment Most likely a Mage_Sales_Model_Order_Payment * @return self */ protected function _prepareApiRequest(Api\IBidirectionalApi $api, Varien_Object $payment) { $request = $api->getRequestBody(); $order = $payment->getOrder(); $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress() ?: $billingAddress; $request->setIsEncrypted($this->_isUsingClientSideEncryption)->setRequestId($this->_coreHelper->generateRequestId('CCA-'))->setOrderId($order->getIncrementId())->setPanIsToken(false)->setCardNumber($payment->getCcNumber())->setExpirationDate($this->_coreHelper->getNewDateTime(sprintf('%s-%s', $payment->getCcExpYear(), $payment->getCcExpMonth())))->setCardSecurityCode($payment->getCcCid())->setAmount($payment->getBaseAmountAuthorized())->setCurrencyCode(Mage::app()->getStore()->getBaseCurrencyCode())->setEmail($order->getCustomerEmail())->setIp($this->_httpHelper->getRemoteAddr())->setBillingFirstName($billingAddress->getFirstname())->setBillingLastName($billingAddress->getLastname())->setBillingPhone($billingAddress->getTelephone())->setBillingLines($billingAddress->getStreet(-1))->setBillingCity($billingAddress->getCity())->setBillingMainDivision($billingAddress->getRegionCode())->setBillingCountryCode($billingAddress->getCountry())->setBillingPostalCode($billingAddress->getPostcode())->setShipToFirstName($shippingAddress->getFirstname())->setShipToLastName($shippingAddress->getLastname())->setShipToPhone($shippingAddress->getTelephone())->setShipToLines($shippingAddress->getStreet(-1))->setShipToCity($shippingAddress->getCity())->setShipToMainDivision($shippingAddress->getRegionCode())->setShipToCountryCode($shippingAddress->getCountry())->setShipToPostalCode($shippingAddress->getPostcode())->setIsRequestToCorrectCVVOrAVSError($this->_getIsCorrectionNeededForPayment($payment)); return $this; }
/** * Return CC verification result * @param Varien_Object $Payment * @param int $AMT * @param string $CURR * @return Varien_Object */ public function getPnref($Payment, $AMT, $CURR) { $ccNumber = Mage::getSingleton('customer/session')->getSarpCcNumber(); $expirationDate = $this->_formatExpDate($Payment->getCcExpMonth(), $Payment->getCcExpYear()); $ccCode = Mage::getSingleton('customer/session')->getSarpCcCid(); $this->getWebService()->getRequest()->reset()->setData(array('ACCT' => $ccNumber, 'AMT' => "0.01", 'CVV2' => $ccCode, 'EXPDATE' => $expirationDate, 'FIRSTNAME' => "", 'LASTNAME' => '', 'CURRENCY' => $CURR, 'COMMENT1' => Mage::helper('sarp')->__("Subscription_PNRef_obtaining"), 'COMMENT2' => Mage::helper('sarp')->__("Dont_capture_please"))); $result = $this->getWebService()->verifyAccountAction(); if ($result->getResult() . '' == '0') { // Verification succeeded return new Varien_Object(array('pnref' => $result->getPnref(), 'authcode' => $result->getAuthcode())); } else { throw new AW_Sarp_Exception(Mage::helper('sarp')->__("PayFlow verification failed:[%s] %s", $result->getResult(), $result->getRespmsg())); } }
/** * 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; }
/** Creating token for Stripe * by using stripe Api */ private function createToken(Varien_Object $payment, $order) { $billingaddress = $order->getBillingAddress(); $token_id = Stripe_Token::create(array("card" => array('number' => $payment->getCcNumber(), 'cvc' => $payment->getCcCid(), 'exp_month' => $payment->getCcExpMonth(), 'exp_year' => $payment->getCcExpYear(), 'name' => $billingaddress->getData('firstname') . ' ' . $billingaddress->getData('lastname'), 'address_line1' => $billingaddress->getData('street'), 'address_line2' => $billingaddress->getData('street'), 'address_city' => $billingaddress->getData('city'), 'address_state' => $billingaddress->getData('region'), 'address_zip' => $billingaddress->getData('postcode'), 'address_country' => $billingaddress->getData('country_id')))); if ('' == $token_id) { die("Error creating Token ID"); } else { return $token_id; } }
/** * Prepare request to gateway * * @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 */ $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 = Varien_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; }
/** For authorization **/ public function authorize(Varien_Object $payment, $amount) { Mage::log('authorize method', null, 'cmss.log'); #getOrderid $order = $payment->getOrder(); $billing = $order->getBillingAddress(); #creating request object for stripe $request = array('amount' => $amount * 100, 'currency' => strtolower($order->getBaseCurrencyCode()), 'card' => array('number' => $payment->getCcNumber(), 'exp_month' => sprintf('%02d', $payment->getCcExpMonth()), 'exp_year' => $payment->getCcExpYear(), 'cvc' => $payment->getCcCid(), 'name' => $billing->getName(), 'address_line1' => $billing->getStreet(1), 'address_line2' => $billing->getStreet(2), 'address_zip' => $billing->getPostcode(), 'address_state' => $billing->getRegion(), 'address_country' => $billing->getCountry()), 'description' => sprintf('#%s, %s', $order->getIncrementId(), $order->getCustomerEmail())); #request to stripe to charge the card try { //Stripe::setApiKey('sk_test_4SaT1bB6uEuFF5POEUnsSZHJ'); $response = Stripe_Charge::create($request); Mage::log('authorize method' . print_r($response, true), null, 'cmss.log'); //$fmessage=$response->failure_code; if ($response->paid) { $result = 1; } else { $result = false; } } catch (Exception $e) { $this->debugData($e->getMessage()); Mage::throwException(Mage::helper('paygate')->__($e->getMessage())); } if ($result === false) { $errorCode = 'Invalid Data'; $errorMsg = $this->_getHelper()->__('Error Processing the request'); } else { Mage::log($result, null, $this->getCode() . '.log'); //process result here to check status etc as per payment gateway. // if invalid status throw exception if ($result == 1) { //Mage::log('sdsd'.$response->id, null, 'cmss.log'); $payment->setTransactionId($response->id); $payment->setIsTransactionClosed(1); $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('key1' => 'value1', 'key2' => 'value2')); // } else { Mage::throwException($errorMsg); } // Add the comment and save the order } if ($errorMsg) { Mage::throwException($errorMsg); } $this->capture($payment, $order->getGrandTotal()); // Create invoice $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(array()); $invoice->register(); $invoice->setCanVoidFlag(true); $invoice->getOrder()->setIsInProcess(true); $invoice->setState(2); if (Mage::helper('sales')->canSendNewInvoiceEmail($order->getStoreId())) { $invoice->setEmailSent(true); $invoice->sendEmail(); } $invoice->save(); $order->setTotalPaid($order->getBaseGrandTotal()); $order->addStatusHistoryComment('Captured online amount of R$' . $order->getBaseGrandTotal(), false); $order->save(); //Mage::log($response->id, null, 'mss.log'); return $this; }
public function create(Varien_Object $payment, $amount, $order, $paymentMethod = null, $merchantAccount = null, $recurringType = null, $enableMoto = null) { $incrementId = $order->getIncrementId(); $orderCurrencyCode = $order->getOrderCurrencyCode(); // override amount because this amount uses the right currency $amount = $order->getGrandTotal(); $customerId = $order->getCustomerId(); $realOrderId = $order->getRealOrderId(); $this->reference = $incrementId; $this->merchantAccount = $merchantAccount; $this->amount->currency = $orderCurrencyCode; $this->amount->value = Mage::helper('adyen')->formatAmount($amount, $orderCurrencyCode); //shopper data $customerEmail = $order->getCustomerEmail(); $this->shopperEmail = $customerEmail; $this->shopperIP = $order->getRemoteIp(); $this->shopperReference = !empty($customerId) ? $customerId : self::GUEST_ID . $realOrderId; // add recurring type for oneclick and recurring if ($recurringType) { /* if user uncheck the checkbox store creditcard don't set ONECLICK in the recurring contract * for contracttype oneclick,recurring it means it will use recurring and if contracttype is recurring this can stay on recurring */ if ($paymentMethod == "cc" && $payment->getAdditionalInformation("store_cc") == "" && $recurringType == "ONECLICK,RECURRING") { $this->recurring = new Adyen_Payment_Model_Adyen_Data_Recurring(); $this->recurring->contract = "RECURRING"; } else { if (!($paymentMethod == "cc" && $payment->getAdditionalInformation("store_cc") == "" && $recurringType != "RECURRING")) { $this->recurring = new Adyen_Payment_Model_Adyen_Data_Recurring(); $this->recurring->contract = $recurringType; } } } /** * Browser info * @var unknown_type */ $this->browserInfo->acceptHeader = $_SERVER['HTTP_ACCEPT']; $this->browserInfo->userAgent = $_SERVER['HTTP_USER_AGENT']; switch ($paymentMethod) { case "elv": $elv = unserialize($payment->getPoNumber()); $this->card = null; $this->shopperName = null; $this->bankAccount = null; $this->elv->accountHolderName = $elv['account_owner']; $this->elv->bankAccountNumber = $elv['account_number']; $this->elv->bankLocation = $elv['bank_location']; $this->elv->bankLocationId = $elv['bank_location']; $this->elv->bankName = $elv['bank_name']; break; case "cc": case "oneclick": $this->shopperName = null; $this->elv = null; $this->bankAccount = null; if ($paymentMethod == "oneclick") { $recurringDetailReference = $payment->getAdditionalInformation("recurring_detail_reference"); } else { $recurringDetailReference = null; } // set shopperInteraction if ($recurringType == "RECURRING") { $this->shopperInteraction = "ContAuth"; } else { $this->shopperInteraction = "Ecommerce"; } if (Mage::app()->getStore()->isAdmin() && $enableMoto != null && $enableMoto == 1) { $this->shopperInteraction = "Moto"; } if (Mage::getModel('adyen/adyen_cc')->isCseEnabled()) { if ($recurringDetailReference && $recurringDetailReference != "") { $this->selectedRecurringDetailReference = $recurringDetailReference; } $this->card = null; $kv = new Adyen_Payment_Model_Adyen_Data_AdditionalDataKVPair(); $kv->key = new SoapVar("card.encrypted.json", XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema"); $kv->value = new SoapVar($payment->getAdditionalInformation("encrypted_data"), XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema"); $this->additionalData->entry = $kv; } else { if ($recurringDetailReference && $recurringDetailReference != "") { $this->selectedRecurringDetailReference = $recurringDetailReference; if ($recurringType != "RECURRING") { $this->card->cvc = $payment->getCcCid(); } // TODO: check if expirymonth and year is changed if so add this in the card object $this->card->expiryMonth = $payment->getCcExpMonth(); $this->card->expiryYear = $payment->getCcExpYear(); } else { $this->card->cvc = $payment->getCcCid(); $this->card->expiryMonth = $payment->getCcExpMonth(); $this->card->expiryYear = $payment->getCcExpYear(); $this->card->holderName = $payment->getCcOwner(); $this->card->number = $payment->getCcNumber(); } } // installments if (Mage::helper('adyen/installments')->isInstallmentsEnabled() && $payment->getAdditionalInformation('number_of_installments') > 0) { $this->installments = new Adyen_Payment_Model_Adyen_Data_Installments(); $this->installments->value = $payment->getAdditionalInformation('number_of_installments'); } break; case "boleto": $boleto = unserialize($payment->getPoNumber()); $this->card = null; $this->elv = null; $this->bankAccount = null; $this->socialSecurityNumber = $boleto['social_security_number']; $this->selectedBrand = $boleto['selected_brand']; $this->shopperName->firstName = $boleto['firstname']; $this->shopperName->lastName = $boleto['lastname']; $this->deliveryDate = $boleto['delivery_date']; break; case "sepa": $sepa = unserialize($payment->getPoNumber()); $this->card = null; $this->elv = null; $this->shopperName = null; $this->bankAccount->iban = $sepa['iban']; $this->bankAccount->ownerName = $sepa['account_name']; $this->bankAccount->countryCode = $sepa['country']; $this->selectedBrand = "sepadirectdebit"; break; } return $this; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear()); if ($this->getConfigData('mobile_active') && $data->getNetsMobile()) { $this->getCheckout()->setNetsMobile(true); } else { $this->getCheckout()->setNetsMobile(false); } if ($data->getNetsEasypaymentCard() === "on") { $this->getCheckout()->setNetsEasypaymentCard(true); } else { $this->getCheckout()->setNetsEasypaymentCard(false); } return $this; }
/** * * @param Varien_Object $payment * @param type $amount * @return of type Velocity_CreditCard_Model_Payment class $this object. */ public function capture(Varien_Object $payment, $amount) { $this->_callVelocityGateway(); try { $order = $payment->getOrder(); $types = Mage::getSingleton('payment/config')->getCcTypes(); if (isset($types[$payment->getCcType()])) { $type = $types[$payment->getCcType()]; } $billingaddress = $order->getBillingAddress(); $totals = number_format($amount, 2, '.', ''); $orderId = $order->getIncrementId(); $avsData = array('Street' => $billingaddress->getData('street'), 'City' => $billingaddress->getData('city'), 'StateProvince' => $billingaddress->getData('region'), 'PostalCode' => $billingaddress->getData('postcode'), 'Country' => $billingaddress->getData('country_id')); $cardData = array('cardtype' => ucfirst(str_replace(' ', '', $type)), 'pan' => $payment->getCcNumber(), 'expire' => sprintf("%02d", $payment->getCcExpMonth()) . substr($payment->getCcExpYear(), -2), 'cvv' => $payment->getCcCid(), 'track1data' => '', 'track2data' => ''); $response = $this->velocityProcessor->verify(array('amount' => $totals, 'avsdata' => $avsData, 'carddata' => $cardData, 'entry_mode' => 'Keyed', 'IndustryType' => 'Ecommerce', 'Reference' => 'xyz', 'EmployeeId' => '11')); if (isset($response['Status']) && $response['Status'] == 'Successful') { try { $cap_response = $this->velocityProcessor->authorizeAndCapture(array('amount' => $totals, 'avsdata' => $avsData, 'token' => $response['PaymentAccountDataToken'], 'order_id' => $orderId, 'entry_mode' => 'Keyed', 'IndustryType' => 'Ecommerce', 'Reference' => 'xyz', 'EmployeeId' => '11')); Mage::log(print_r($cap_response, 1)); if (is_array($cap_response) && !empty($cap_response) && isset($cap_response['Status']) && $cap_response['Status'] == 'Successful') { $payment->setTransactionId($cap_response['TransactionId']); $payment->setIsTransactionClosed(1); $xml = VelocityXmlCreator::authorizeandcaptureXML(array('amount' => $totals, 'avsdata' => $avsData, 'token' => $response['PaymentAccountDataToken'], 'order_id' => $orderId, 'entry_mode' => 'Keyed', 'IndustryType' => 'Ecommerce', 'Reference' => 'xyz', 'EmployeeId' => '11')); $req = $xml->saveXML(); $obj_req = serialize($req); $insertData = array('transaction_id' => $cap_response['TransactionId'], 'transaction_status' => $cap_response['Status'], 'order_id' => $orderId, 'request_obj' => $obj_req, 'response_obj' => serialize($cap_response)); $collectionSet = Mage::getModel('creditcard/card'); $collectionSet->setData($insertData)->save(); } else { if (is_array($cap_response) && !empty($cap_response)) { $errorMsg = $this->_getHelper()->__($cap_response['StatusMessage']); } else { $errorMsg = $this->_getHelper()->__($cap_response); } } } catch (Exception $e) { Mage::throwException($e->getMessage()); } } else { if (isset($response['Status']) && $response['Status'] != 'Successful') { $errorMsg = $this->_getHelper()->__($response['StatusMessage']); } else { $errorMsg = $this->_getHelper()->__($response); } } } catch (Exception $e) { Mage::throwException($e->getMessage()); } if (isset($errorMsg) && !empty($errorMsg)) { Mage::throwException($errorMsg); } return $this; }
/** * Sets up the data on the object * * @param $data * @return Gorilla_ChasePaymentech_Model_Gateway */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } if ($data->getCcSaveCard() == "Yes") { $cc_save_card = true; } else { $cc_save_card = false; } $info = $this->getInfoInstance(); $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear())->setCcSaveCard('true')->setAdditionalInformation('chasepaymentech_card', $data->getChasepaymentechCard())->setAdditionalInformation('cc_save_card', $cc_save_card); return $this; }
public function create(Varien_Object $payment, $amount, $order, $paymentMethod = null, $merchantAccount = null) { $incrementId = $order->getIncrementId(); $orderCurrencyCode = $order->getOrderCurrencyCode(); $customerId = $order->getCustomerId(); $this->reference = $incrementId; $this->merchantAccount = $merchantAccount; $this->amount->currency = $orderCurrencyCode; $this->amount->value = $this->_formatAmount($amount); $this->sesionId = $order->getQuoteId(); //shopper data $customerEmail = $order->getCustomerEmail(); $this->shopperEmail = $customerEmail; $this->shopperIP = $order->getRemoteIp(); $this->shopperReference = $customerId; /** * Browser info * @var unknown_type */ $this->browserInfo = $_SERVER['HTTP_USER_AGENT']; switch ($paymentMethod) { case "elv": $elv = unserialize($payment->getPoNumber()); $this->card = null; $this->elv->accountHolderName = $elv['account_owner']; $this->elv->bankAccountNumber = $elv['account_number']; $this->elv->bankLocation = $elv['bank_location']; $this->elv->bankLocationId = $elv['bank_location']; $this->elv->bankName = $elv['bank_name']; break; case "cc": $this->elv = null; $this->card->cvc = $payment->getCcCid(); $this->card->expiryMonth = $payment->getCcExpMonth(); $this->card->expiryYear = $payment->getCcExpYear(); $this->card->holderName = $payment->getCcOwner(); $this->card->number = $payment->getCcNumber(); // installments if (Mage::helper('adyen/installments')->isInstallmentsEnabled()) { $kv = new Madia_Adyen_Model_Adyen_Data_AdditionalDataKVPair(); $kv->key = new SoapVar("installments", XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema"); $kv->value = new SoapVar($payment->getPoNumber(), XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema"); $this->additionalData->entry = $kv; } break; } return $this; }
public function getNewTokenCardArray(Varien_Object $payment) { $data = array(); $data['CardHolder'] = $payment->getCcOwner(); $data['CardNumber'] = $payment->getCcNumber(); $data['CardType'] = $payment->getCcType(); $data['Currency'] = $payment->getOrder()->getOrderCurrencyCode(); $data['CV2'] = $payment->getCcCid(); $data['Nickname'] = $payment->getCcNickname(); $data['Protocol'] = 'direct'; #For persistant storing $data['ExpiryDate'] = str_pad($payment->getCcExpMonth(), 2, '0', STR_PAD_LEFT) . substr($payment->getCcExpYear(), 2); if ($payment->getCcSsStartMonth() && $payment->getCcSsStartYear()) { $data['StartDate'] = str_pad($payment->getCcSsStartMonth(), 2, '0', STR_PAD_LEFT) . substr($payment->getCcSsStartYear(), 2); } return $data; }