/** * Config instance setter * * @param Mage_Paypal_Model_Config $instace * @param int $storeId */ public function setConfig(Ebcomm_PaypalMx_Model_Config $instace, $storeId = null) { $this->_config = $instace; if (null !== $storeId) { $this->_config->setStoreId($storeId); } return $this; }
/** * Set template and redirect message */ protected function _construct() { $this->_config = Mage::getModel('paypal/config')->setMethod($this->getMethodCode()); $locale = Mage::app()->getLocale(); $mark = Mage::getConfig()->getBlockClassName('core/template'); $mark = new $mark(); $mark->setTemplate('paypal/payment/mark.phtml')->setPaymentAcceptanceMarkHref($this->_config->getPaymentMarkWhatIsPaypalUrl($locale))->setPaymentAcceptanceMarkSrc($this->_config->getPaymentMarkImageUrl($locale->getLocaleCode())); // known issue: code above will render only static mark image $this->setTemplate('paypal/payment/redirect.phtml')->setRedirectMessage(Mage::helper('paypal')->__('You will be redirected to the PayPal website when you place an order.'))->setMethodTitle('')->setMethodLabelAfterHtml($mark->toHtml()); return parent::_construct(); }
/** * Set template and redirect message */ protected function _construct() { $this->_config = Mage::getModel('paypalmx/config')->setMethod($this->getMethodCode()); $locale = Mage::app()->getLocale(); $mark = Mage::getConfig()->getBlockClassName('core/template'); $mark = new $mark(); $mark->setTemplate('paypalmx/payment/mark.phtml')->setPaymentAcceptanceMarkHref($this->_config->getPaymentMarkWhatIsPaypalUrl($locale))->setPaymentAcceptanceMarkSrc($this->_config->getPaymentMarkImageUrl($locale->getLocaleCode()))->setNoPosAH($this->_config->getnoposah()); // known issue: code above will render only static mark image $this->setTemplate('paypalmx/payment/redirect.phtml')->setMethodTitle('')->setMethodLabelAfterHtml($mark->toHtml()); return parent::_construct(); }
/** * Check whether customer should be asked confirmation whether to sign a billing agreement * * @param Mage_Paypal_Model_Config $config * @param int $customerId * @return bool */ public function shouldAskToCreateBillingAgreement(Mage_Paypal_Model_Config $config, $customerId) { if (null === self::$_shouldAskToCreateBillingAgreement) { self::$_shouldAskToCreateBillingAgreement = false; if ($customerId && $config->shouldAskToCreateBillingAgreement()) { if (Mage::getModel('sales/billing_agreement')->needToCreateForCustomer($customerId)) { self::$_shouldAskToCreateBillingAgreement = true; } } } return self::$_shouldAskToCreateBillingAgreement; }
/** * Reserve order ID for specified quote and start checkout on PayPal * @return string */ public function start($returnUrl, $cancelUrl) { $this->_quote->reserveOrderId()->save(); // prepare API $this->_getApi(); $this->_api->setAmount($this->_quote->getBaseGrandTotal())->setCurrencyCode($this->_quote->getBaseCurrencyCode())->setInvNum($this->_quote->getReservedOrderId())->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl)->setSolutionType($this->_config->solutionType)->setPaymentAction($this->_config->paymentAction); // supress or export shipping address if ($this->_quote->getIsVirtual()) { $this->_api->setSuppressShipping(true); } else { $address = $this->_quote->getShippingAddress(); $isOverriden = 0; if (true === $address->validate()) { $isOverriden = 1; $this->_api->setAddress($address); } $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden); $this->_quote->getPayment()->save(); } // add line items if ($this->_config->lineItemsEnabled) { list($items, $totals) = Mage::helper('paypal')->prepareLineItems($this->_quote); $this->_api->setLineItems($items)->setLineItemTotals($totals); } $this->_config->exportExpressCheckoutStyleSettings($this->_api); // call API and redirect with token $this->_api->callSetExpressCheckout(); $token = $this->_api->getToken(); $this->_redirectUrl = $this->_config->getExpressCheckoutStartUrl($token); return $token; }
/** * Log debug data to file * * @param mixed $debugData */ protected function _debug() { if ($this->_config && $this->_config->debug) { $file = $this->_config->getMethodCode() ? "payment_{$this->_config->getMethodCode()}.log" : self::DEFAULT_LOG_FILE; Mage::getModel('Mage_Core_Model_Log_Adapter', array('fileName' => $file))->log($this->_debugData); } }
/** * Log debug data to file * * @param mixed $debugData */ protected function _debug() { if ($this->_config && $this->_config->debug) { $file = $this->_config->getMethodCode() ? "payment_{$this->_config->getMethodCode()}.log" : self::DEFAULT_LOG_FILE; Mage::getModel('core/log_adapter', $file)->log($this->_debugData); } }
public function __get($key) { if (strcmp($key, 'verifyPeer') == 0 || strcmp($key, 'verify_peer') == 0) { if ($this->_isStagingMode === null) { $this->_isStagingMode = 0; try { $curlResource = curl_init("https://www.paypal.com/"); curl_setopt($curlResource, CURLOPT_TIMEOUT, 3); curl_setopt($curlResource, CURLOPT_RETURNTRANSFER, false); curl_setopt($curlResource, CURLOPT_SSL_VERIFYPEER, true); curl_exec($curlResource); $curlError = curl_error($curlResource); curl_close($curlResource); if (!!$curlError) { $this->_isStagingMode = 1; } } catch (Exception $ex) { $this->_isStagingMode = 1; } } if ($this->_isStagingMode == 1) { return 0; } } return parent::__get($key); }
/** * Place the order when customer returned from paypal * Until this moment all quote data must be valid * * @param string $token * @param string $shippingMethodCode * @return Mage_Sales_Model_Order */ public function placeOrder($token, $shippingMethodCode = null) { if ($shippingMethodCode) { $this->updateShippingMethod($shippingMethodCode); } if (!$this->_quote->getCustomerId()) { $this->_quote->setCustomerIsGuest(true)->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->setCustomerEmail($this->_quote->getBillingAddress()->getEmail()); } $this->_ignoreAddressValidation(); $order = Mage::getModel('sales/service_quote', $this->_quote)->submit(); $this->_quote->save(); // commence redirecting to finish payment, if paypal requires it if ($order->getPayment()->getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT)) { $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token); } switch ($order->getState()) { // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT: // TODO break; // regular placement, when everything is ok // regular placement, when everything is ok case Mage_Sales_Model_Order::STATE_PROCESSING: case Mage_Sales_Model_Order::STATE_COMPLETE: $order->sendNewOrderEmail(); break; } return $order; }
/** * Dispatch customer back to PayPal for editing payment information */ public function editAction() { try { $this->getResponse()->setRedirect($this->_config->getExpressCheckoutEditUrl($this->_initToken())); } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); $this->_redirect('*/*/review'); } }
/** * BN code getter * * @param string $countryCode ISO 3166-1 */ public function getBuildNotationCode($countryCode = null) { parent::getBuildNotationCode($countryCode); if (Mage::helper('iwdall')->isEnterprise()) { return 'IWD_SI_MagentoEE_WPS'; // enterprise } else { return 'IWD_SI_MagentoCE_WPS'; // community } }
/** * Map any supported payment method into a config path by specified field name * * @param string $fieldName * @return string|null */ protected function _getSpecificConfigPath($fieldName) { $path = $this->_mapExpressFieldset($fieldName); if ($path === null) { $path = $this->_mapWppFieldset($fieldName); } if ($path === null) { $path = parent::_getSpecificConfigPath($fieldName); } return $path; }
/** * BN code getter * override method * * @param string $countryCode ISO 3166-1 */ public function getBuildNotationCode($countryCode = null) { if ($this->isMageEnterprise()) { $newBnCode = 'Magestore_SI_MagentoEE'; } else { $newBnCode = 'Magestore_SI_MagentoCE'; } $bnCode = parent::getBuildNotationCode($countryCode); if (class_exists("Magestore_Onestepcheckout_Helper_Data") && Mage::getStoreConfig('onestepcheckout/general/active')) { return $newBnCode; } else { return $bnCode; } }
/** * Set create billing agreement flag to api call * * @return Mage_Paypal_Model_Express_Checkout */ protected function _setBillingAgreementRequest() { if (!$this->_customerId || $this->_quote->hasNominalItems()) { return $this; } $isRequested = $this->_isBARequested || $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT); if (!($this->_config->allow_ba_signup == Mage_Paypal_Model_Config::EC_BA_SIGNUP_AUTO || $isRequested && $this->_config->shouldAskToCreateBillingAgreement())) { return $this; } if (!Mage::getModel('sales/billing_agreement')->needToCreateForCustomer($this->_customerId)) { return $this; } $this->_api->setBillingType($this->_api->getBillingAgreementType()); return $this; }
/** * Get ipn data, send verification to PayPal, run corresponding handler */ public function processIpnRequest() { if (!$this->_ipnFormData) { return; } // debug requested if ($this->_config->debugFlag) { Mage::getModel('paypal/api_debug')->setApiEndpoint($this->_config->getPaypalUrl())->setRequestBody(var_export($this->_ipnFormData, 1))->save(); } $sReq = ''; $sReqDebug = ''; foreach ($this->_ipnFormData as $k => $v) { $sReq .= '&' . $k . '=' . urlencode(stripslashes($v)); $sReqDebug .= '&' . $k . '='; } // append ipn command $sReq .= "&cmd=_notify-validate"; $sReq = substr($sReq, 1); $http = new Varien_Http_Adapter_Curl(); $http->write(Zend_Http_Client::POST, $this->_config->getPaypalUrl(), '1.1', array(), $sReq); $response = $http->read(); // debug postback request & response if ($this->_config->debugFlag) { Mage::getModel('paypal/api_debug')->setApiEndpoint($this->_config->getPaypalUrl())->setRequestBody($sReq)->setResponseBody($response)->save(); } if ($error = $http->getError()) { $this->_notifyAdmin(Mage::helper('paypal')->__('PayPal IPN postback HTTP error: %s', $error)); return; } $response = preg_split('/^\\r?$/m', $response, 2); $response = trim($response[1]); if ($response == 'VERIFIED') { $this->processIpnVerified(); } else { // TODO: possible PCI compliance issue - the $sReq may contain data that is supposed to be encrypted $this->_notifyAdmin(Mage::helper('paypal')->__('PayPal IPN postback Validation error: %s', $sReq)); } }
/** * BN code getter * * @param string $countryCode ISO 3166-1 */ public function getBuildNotationCode($countryCode = null) { parent::getBuildNotationCode($countryCode); return 'IWD_SI_MagentoCE_WPS'; // community }
/** * Log debug data to file * * @param mixed $debugData */ protected function _debug($debugData) { if ($this->getDebugFlag()) { Mage::getModel('core/log_adapter', 'payment_' . $this->_config->getMethodCode() . '.log')->setFilterDataKeys($this->_debugReplacePrivateDataKeys)->log($debugData); } }
/** * Don't show CC type for non-CC methods * * @return string|null */ public function getCcTypeName() { if (Mage_Paypal_Model_Config::getIsCreditCardMethod($this->getInfo()->getMethod())) { return parent::getCcTypeName(); } }
/** * Log debug data to file * * @param mixed $debugData */ protected function _debug($debugData) { if ($this->getDebugFlag()) { Mage::getModel('Mage_Core_Model_Log_Adapter', array('fileName' => 'payment_' . $this->_config->getMethodCode() . '.log'))->setFilterDataKeys($this->_debugReplacePrivateDataKeys)->log($debugData); } }
/** * BN code getter * * @param string $countryCode ISO 3166-1 */ public function getBuildNotationCode($countryCode = null) { parent::getBuildNotationCode($countryCode); return 'IWD_SI_Other_OnePage'; }
/** * Redirect customer back to PayPal with the same token */ protected function _redirectSameToken() { $token = $this->_initToken(); $this->getResponse()->setRedirect($this->_config->getExpressCheckoutStartUrl($token)); }
/** * BN code getter * * @return string */ public function getBuildNotationCode() { return $this->_config->getBuildNotationCode(); }
public function __construct($params = array()) { parent::__construct($params); $this->_supportedCurrencyCodes = array_merge($this->_supportedCurrencyCodes, Mage::helper('ppfix')->getCurrencyArray()); }
/** * Map PayPal Website Payments Pro common config fields * * @param string $fieldName * @return string|null */ protected function _mapWpukFieldset($fieldName) { $result = null; switch ($this->_methodCode) { case self::METHOD_PAYFLOW_BILLING_AGREEMENT: case self::METHOD_PAYFLOW_ORDERSTORED_AGREEMENT: $pathPrefix = 'paypal/wpuk'; // Use PUMP credentials from Verisign for EC when Direct Payments are unavailable if (!$this->isMethodAvailable(Mage_Paypal_Model_Config::METHOD_WPP_PE_DIRECT)) { $pathPrefix = 'payment/verisign'; } switch ($fieldName) { case 'partner': case 'user': case 'vendor': case 'pwd': case 'sandbox_flag': case 'use_proxy': case 'proxy_host': case 'proxy_port': $result = $pathPrefix . '/' . $fieldName; break; default: } break; default: $result = parent::_mapWpukFieldset($fieldName); } return $result; }