protected function _exportAddressses($data) { $version = Mage::getVersionInfo(); if ($version['major'] >= 1 && $version['minor'] >= 7) { parent::_exportAddressses($data); } else { $address = new Varien_Object(); Varien_Object_Mapper::accumulateByMap($data, $address, $this->_billingAddressMap); $address->setExportedKeys(array_values($this->_billingAddressMap)); $this->_applyStreetAndRegionWorkarounds($address); $this->setExportedBillingAddress($address); // assume there is shipping address if there is at least one field specific to shipping if (isset($data['SHIPTONAME'])) { $shippingAddress = clone $address; Varien_Object_Mapper::accumulateByMap($data, $shippingAddress, $this->_shippingAddressMap); $this->_applyStreetAndRegionWorkarounds($shippingAddress); // PayPal doesn't provide detailed shipping name fields, so the name will be overwritten $firstName = $data['SHIPTONAME']; $lastName = null; if (isset($data['FIRSTNAME']) && $data['LASTNAME']) { $firstName = $data['FIRSTNAME']; $lastName = $data['LASTNAME']; } $shippingAddress->addData(array('prefix' => null, 'firstname' => $firstName, 'middlename' => null, 'lastname' => $lastName, 'suffix' => null)); $this->setExportedShippingAddress($shippingAddress); } } }
/** * Export cmpi lookups and authentication information stored in session into array * * @param mixed $to * @param array $map * @return mixed $to */ public function exportCmpiData($to, $map = false) { if (!$map) { $map = $this->_cmpiMap; } if ($validationState = $this->_getValidationState()) { $to = Varien_Object_Mapper::accumulateByMap($validationState, $to, $map); } return $to; }
/** * Import address object, if set, to the request * * @param array $request */ protected function _importAddress(&$request) { $address = $this->getAddress(); if (!$address) { if ($this->getNoShipping()) { $request['no_shipping'] = 1; } return; } $request = Varien_Object_Mapper::accumulateByMap($address, $request, array_flip($this->_addressMap)); // Address may come without email info (user is not always required to enter it), so add email from order if (!$request['email']) { $order = $this->getOrder(); if ($order) { $request['email'] = $order->getCustomerEmail(); } } $regionCode = $this->_lookupRegionCodeFromAddress($address); if ($regionCode) { $request['state'] = $regionCode; } $this->_importStreetFromAddress($address, $request, 'address1', 'address2'); $this->_applyCountryWorkarounds($request); $request['address_override'] = 1; }
/** * Submit RP to the gateway * * @param Mage_Payment_Model_Recurring_Profile $profile * @param Mage_Payment_Model_Info $paymentInfo * @throws Mage_Core_Exception */ public function submitRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile, Mage_Payment_Model_Info $paymentInfo) { $api = $this->getApi(); Varien_Object_Mapper::accumulateByMap($profile, $api, array('token', 'subscriber_name', 'start_datetime', 'internal_reference_id', 'schedule_description', 'suspension_threshold', 'bill_failed_later', 'period_unit', 'period_frequency', 'period_max_cycles', 'billing_amount' => 'amount', 'trial_period_unit', 'trial_period_frequency', 'trial_period_max_cycles', 'trial_billing_amount', 'currency_code', 'shipping_amount', 'tax_amount', 'init_amount', 'init_may_fail')); $api->callCreateRecurringPaymentsProfile(); $profile->setReferenceId($api->getRecurringProfileId()); if ($api->getIsProfileActive()) { $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE); } elseif ($api->getIsProfilePending()) { $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_PENDING); } }
/** * 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; }
/** * Import $this public data from a private response array * * @param array $privateResponseMap * @param array $response */ protected function _importFromResponse(array $privateResponseMap, array $response) { $map = array(); foreach ($privateResponseMap as $key) { if (isset($this->_globalMap[$key])) { $map[$key] = $this->_globalMap[$key]; } if (isset($response[$key]) && isset($this->_importFromRequestFilters[$key])) { $callback = $this->_importFromRequestFilters[$key]; $response[$key] = call_user_func(array($this, $callback), $response[$key], $key, $map[$key]); } } Varien_Object_Mapper::accumulateByMap($response, array($this, 'setDataUsingMethod'), $map); }
/** * Return request object with information for 'authorization' or 'sale' action * * @param Mage_Sales_Model_Order_Payment $payment * @param float $amount * @return Varien_Object */ protected function _buildPlaceRequest(Varien_Object $payment, $amount) { $request = $this->_buildBasicRequest($payment); $request->setAmt(round($amount, 2)); $request->setAcct($payment->getCcNumber()); $request->setExpdate(sprintf('%02d', $payment->getCcExpMonth()) . substr($payment->getCcExpYear(), -2, 2)); $request->setCvv2($payment->getCcCid()); if ($this->getIsCentinelValidationEnabled()) { $params = array(); $params = $this->getCentinelValidator()->exportCmpiData($params); $request = Varien_Object_Mapper::accumulateByMap($params, $request, $this->_centinelFieldMap); } $order = $payment->getOrder(); if (!empty($order)) { $request->setCurrency($order->getBaseCurrencyCode()); $orderIncrementId = $order->getIncrementId(); $request->setCustref($orderIncrementId)->setComment1($orderIncrementId); $billing = $order->getBillingAddress(); if (!empty($billing)) { $request->setFirstname($billing->getFirstname())->setLastname($billing->getLastname())->setStreet(implode(' ', $billing->getStreet()))->setCity($billing->getCity())->setState($billing->getRegionCode())->setZip($billing->getPostcode())->setCountry($billing->getCountry())->setEmail($payment->getOrder()->getCustomerEmail()); } $shipping = $order->getShippingAddress(); if (!empty($shipping)) { $this->_applyCountryWorkarounds($shipping); $request->setShiptofirstname($shipping->getFirstname())->setShiptolastname($shipping->getLastname())->setShiptostreet(implode(' ', $shipping->getStreet()))->setShiptocity($shipping->getCity())->setShiptostate($shipping->getRegionCode())->setShiptozip($shipping->getPostcode())->setShiptocountry($shipping->getCountry()); } } return $request; }
/** * Prepare request data basing on provided addresses * * @param array $to * @return array */ protected function _importAddresses(array $to) { $billingAddress = $this->getBillingAddress() ? $this->getBillingAddress() : $this->getAddress(); $shippingAddress = $this->getAddress(); $to = Varien_Object_Mapper::accumulateByMap($billingAddress, $to, array_merge(array_flip($this->_billingAddressMap), $this->_billingAddressMapRequest)); if ($regionCode = $this->_lookupRegionCodeFromAddress($billingAddress)) { $to['STATE'] = $regionCode; } if (!$this->getSuppressShipping()) { $to = Varien_Object_Mapper::accumulateByMap($shippingAddress, $to, array_flip($this->_shippingAddressMap)); if ($regionCode = $this->_lookupRegionCodeFromAddress($shippingAddress)) { $to['SHIPTOSTATE'] = $regionCode; } $this->_importStreetFromAddress($shippingAddress, $to, 'SHIPTOSTREET', 'SHIPTOSTREET2'); $this->_importStreetFromAddress($billingAddress, $to, 'STREET', 'STREET2'); $to['SHIPTONAME'] = $shippingAddress->getName(); } $this->_applyCountryWorkarounds($to); return $to; }
/** * 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; }
/** * Prepare line items request * * @param array &$request * @param int $i */ protected function _exportLineItems(array &$request, $i = 0) { $items = $this->getLineItems(); if (empty($items)) { return; } // line items foreach ($items as $item) { foreach ($this->_lineItemExportItemsFormat as $publicKey => $privateFormat) { $value = $item->getDataUsingMethod($publicKey); if (is_float($value)) { $value = $this->_filterAmount($value); } $request[sprintf($privateFormat, $i)] = $value; } $i++; } // line item totals $lineItemTotals = $this->getLineItemTotals(); if ($lineItemTotals) { $request = Varien_Object_Mapper::accumulateByMap($lineItemTotals, $request, $this->_lineItemExportTotals); foreach ($this->_lineItemExportTotals as $privateKey) { if (isset($request[$privateKey])) { $request[$privateKey] = $this->_filterAmount($request[$privateKey]); } else { Mage::logException(new Exception(sprintf('Missing index "%s" for line item totals.', $privateKey))); Mage::throwException(Mage::helper('paypal')->__('Unable to calculate cart line item totals.')); } } } }
/** * Grab data from payment and map it into target * * @param Mage_Payment_Model_Info $payment * @param array|Varien_Object|callback $to * @param array $map * @return array|Varien_Object */ public function &exportFromPayment(Mage_Payment_Model_Info $payment, $to, array $map = null) { $fullMap = array_merge($this->_paymentMap, $this->_systemMap); Varien_Object_Mapper::accumulateByMap(array($payment, 'getAdditionalInformation'), $to, $map ? $map : array_flip($fullMap)); return $to; }
/** * Grab data from source and map it into payment * * @param array|Varien_Object|callback $from * @param Mage_Payment_Model_Info $payment */ public function importToPayment($from, Mage_Payment_Model_Info $payment) { $fullMap = array_merge($this->_paymentMap, $this->_systemMap); if (is_object($from)) { $from = array($from, 'getDataUsingMethod'); } Varien_Object_Mapper::accumulateByMap($from, array($payment, 'setAdditionalInformation'), $fullMap); }
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; }
/** * Import address object, if set, to the request * * @param array $request */ protected function _importAddress(&$request) { $address = $this->getAddress(); if (!$address) { if ($this->getNoShipping()) { $request['no_shipping'] = 1; } return; } $request = Varien_Object_Mapper::accumulateByMap($address, $request, array_flip($this->_addressMap)); if ($regionCode = $this->_lookupRegionCodeFromAddress($address)) { $request['state'] = $regionCode; } $this->_importStreetFromAddress($address, $request, 'address1', 'address2'); $request['address_override'] = 1; }
/** * Prepare request data basing on provided address * * @param Varien_Object $address * @param array $to * @return array */ protected function _importAddress(Varien_Object $address, array $to) { $to = Varien_Object_Mapper::accumulateByMap($address, $to, array_flip($this->_billingAddressMap)); if ($regionCode = $this->_lookupRegionCodeFromAddress($address)) { $to['STATE'] = $regionCode; } if (!$this->getSuppressShipping()) { $to = Varien_Object_Mapper::accumulateByMap($address, $to, array_flip($this->_shippingAddressMap)); if ($regionCode = $this->_lookupRegionCodeFromAddress($address)) { $to['SHIPTOSTATE'] = $regionCode; } $this->_importStreetFromAddress($address, $to, 'SHIPTOSTREET', 'SHIPTOSTREET2'); $this->_importStreetFromAddress($address, $to, 'STREET', 'STREET2'); $to['SHIPTONAME'] = $address->getName(); } return $to; }