Version Notes
PayPal order in selected currency
Download this release
Release Info
| Developer | Magento Core Team |
| Extension | PayPal_order_in_selected_currency |
| Version | 1.0 |
| Comparing to | |
| See all releases | |
Version 1.0
- app/code/local/Mage/Paypal/Block/Standard/Redirect.php +29 -0
- app/code/local/Mage/Paypal/Model/Standard.php +216 -0
- app/code/local/MagentoCenter/Pp/Helper/Data.php +8 -0
- app/code/local/MagentoCenter/Pp/etc/config.xml +24 -0
- app/code/local/MagentoCenter/Pp/etc/system.xml +28 -0
- app/etc/modules/MagentoCenter_Pp.xml +12 -0
- package.xml +18 -0
app/code/local/Mage/Paypal/Block/Standard/Redirect.php
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Mage_Paypal_Block_Standard_Redirect extends Mage_Core_Block_Abstract
|
| 4 |
+
{
|
| 5 |
+
protected function _toHtml()
|
| 6 |
+
{
|
| 7 |
+
$standard = Mage::getModel('paypal/standard');
|
| 8 |
+
|
| 9 |
+
$form = new Varien_Data_Form();
|
| 10 |
+
$form->setAction($standard->getConfig()->getPaypalUrl())
|
| 11 |
+
->setId('paypal_standard_checkout')
|
| 12 |
+
->setName('paypal_standard_checkout')
|
| 13 |
+
->setMethod('POST')
|
| 14 |
+
->setUseContainer(true);
|
| 15 |
+
|
| 16 |
+
foreach ($standard->getStandardCheckoutFormFields() as $field=>$value) {
|
| 17 |
+
$form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value));
|
| 18 |
+
// echo $field.' - '.$value.'</br>';
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
$html = '<html><body>';
|
| 22 |
+
$html.= $this->__('You will be redirected to the PayPal website in a few seconds.');
|
| 23 |
+
$html.= $form->toHtml();
|
| 24 |
+
$html.= '<script type="text/javascript">document.getElementById("paypal_standard_checkout").submit();</script>';
|
| 25 |
+
$html.= '</body></html>';
|
| 26 |
+
|
| 27 |
+
return $html;
|
| 28 |
+
}
|
| 29 |
+
}
|
app/code/local/Mage/Paypal/Model/Standard.php
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Mage_Paypal_Model_Standard extends Mage_Payment_Model_Method_Abstract
|
| 4 |
+
{
|
| 5 |
+
protected $_code = Mage_Paypal_Model_Config::METHOD_WPS;
|
| 6 |
+
protected $_formBlockType = 'paypal/standard_form';
|
| 7 |
+
protected $_infoBlockType = 'paypal/payment_info';
|
| 8 |
+
protected $_isInitializeNeeded = true;
|
| 9 |
+
protected $_canUseInternal = false;
|
| 10 |
+
protected $_canUseForMultishipping = false;
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Config instance
|
| 14 |
+
* @var Mage_Paypal_Model_Config
|
| 15 |
+
*/
|
| 16 |
+
protected $_config = null;
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Whether method is available for specified currency
|
| 20 |
+
*
|
| 21 |
+
* @param string $currencyCode
|
| 22 |
+
* @return bool
|
| 23 |
+
*/
|
| 24 |
+
public function canUseForCurrency($currencyCode)
|
| 25 |
+
{
|
| 26 |
+
return $this->getConfig()->isCurrencyCodeSupported($currencyCode);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* Get paypal session namespace
|
| 31 |
+
*
|
| 32 |
+
* @return Mage_Paypal_Model_Session
|
| 33 |
+
*/
|
| 34 |
+
public function getSession()
|
| 35 |
+
{
|
| 36 |
+
return Mage::getSingleton('paypal/session');
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Get checkout session namespace
|
| 41 |
+
*
|
| 42 |
+
* @return Mage_Checkout_Model_Session
|
| 43 |
+
*/
|
| 44 |
+
public function getCheckout()
|
| 45 |
+
{
|
| 46 |
+
return Mage::getSingleton('checkout/session');
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Get current quote
|
| 51 |
+
*
|
| 52 |
+
* @return Mage_Sales_Model_Quote
|
| 53 |
+
*/
|
| 54 |
+
public function getQuote()
|
| 55 |
+
{
|
| 56 |
+
return $this->getCheckout()->getQuote();
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* Create main block for standard form
|
| 61 |
+
*
|
| 62 |
+
*/
|
| 63 |
+
public function createFormBlock($name)
|
| 64 |
+
{
|
| 65 |
+
$block = $this->getLayout()->createBlock('paypal/standard_form', $name)
|
| 66 |
+
->setMethod('paypal_standard')
|
| 67 |
+
->setPayment($this->getPayment())
|
| 68 |
+
->setTemplate('paypal/standard/form.phtml');
|
| 69 |
+
|
| 70 |
+
return $block;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* Return Order place redirect url
|
| 75 |
+
*
|
| 76 |
+
* @return string
|
| 77 |
+
*/
|
| 78 |
+
public function getOrderPlaceRedirectUrl()
|
| 79 |
+
{
|
| 80 |
+
return Mage::getUrl('paypal/standard/redirect', array('_secure' => true));
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* Return form field array
|
| 85 |
+
*
|
| 86 |
+
* @return array
|
| 87 |
+
*/
|
| 88 |
+
public function getStandardCheckoutFormFields()
|
| 89 |
+
{
|
| 90 |
+
$orderIncrementId = $this->getCheckout()->getLastRealOrderId();
|
| 91 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
|
| 92 |
+
$api = Mage::getModel('paypal/api_standard')->setConfigObject($this->getConfig());
|
| 93 |
+
$fixactive = Mage::getStoreConfig('payment/pp/active');
|
| 94 |
+
if ($fixactive) {
|
| 95 |
+
$api->setOrderId($orderIncrementId)
|
| 96 |
+
->setCurrencyCode($order->getOrderCurrencyCode())
|
| 97 |
+
->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
|
| 98 |
+
->setReturnUrl(Mage::getUrl('paypal/standard/success'))
|
| 99 |
+
->setCancelUrl(Mage::getUrl('paypal/standard/cancel'));
|
| 100 |
+
} else {
|
| 101 |
+
$api->setOrderId($orderIncrementId)
|
| 102 |
+
->setCurrencyCode($order->getBaseCurrencyCode())
|
| 103 |
+
->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
|
| 104 |
+
->setReturnUrl(Mage::getUrl('paypal/standard/success'))
|
| 105 |
+
->setCancelUrl(Mage::getUrl('paypal/standard/cancel'));
|
| 106 |
+
}
|
| 107 |
+
// export address
|
| 108 |
+
$isOrderVirtual = $order->getIsVirtual();
|
| 109 |
+
$address = $isOrderVirtual ? $order->getBillingAddress() : $order->getShippingAddress();
|
| 110 |
+
if ($isOrderVirtual) {
|
| 111 |
+
$api->setNoShipping(true);
|
| 112 |
+
}
|
| 113 |
+
elseif ($address->getEmail()) {
|
| 114 |
+
$api->setAddress($address);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
list($items, $totals, $discountAmount, $shippingAmount) = Mage::helper('paypal')->prepareLineItems($order, false, true);
|
| 118 |
+
// prepare line items if required in config
|
| 119 |
+
if ($this->_config->lineItemsEnabled) {
|
| 120 |
+
$api->setLineItems($items)->setLineItemTotals($totals)->setDiscountAmount($discountAmount);
|
| 121 |
+
}
|
| 122 |
+
// or values specific for aggregated order
|
| 123 |
+
else {
|
| 124 |
+
$grandTotal = $order->getBaseGrandTotal();
|
| 125 |
+
|
| 126 |
+
if (!$isOrderVirtual) {
|
| 127 |
+
$api->setShippingAmount($shippingAmount);
|
| 128 |
+
$grandTotal -= $shippingAmount;
|
| 129 |
+
}
|
| 130 |
+
$api->setAmount($grandTotal)->setCartSummary($this->_getAggregatedCartSummary());
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
$result = $api->getStandardCheckoutRequest();
|
| 134 |
+
if ($fixactive) {
|
| 135 |
+
$storeCurrency= Mage::getModel('directory/currency')->load($order->getBaseCurrencyCode());
|
| 136 |
+
$currency=$order->getOrderCurrencyCode();
|
| 137 |
+
$i = 0;
|
| 138 |
+
do {
|
| 139 |
+
$i++;
|
| 140 |
+
$key='amount_'.$i;
|
| 141 |
+
//$result[$key] = $storeCurrency->convert($result[$key], $currency);
|
| 142 |
+
if (array_key_exists($key, $result)) $result[$key] = trim(round( $storeCurrency->convert($result[$key], $currency), 2));
|
| 143 |
+
} while (array_key_exists($key, $result));
|
| 144 |
+
$result['tax_cart'] = trim(round( $storeCurrency->convert($result['tax_cart'], $currency), 2));
|
| 145 |
+
$result['discount_amount_cart'] = trim(round( $storeCurrency->convert($result['discount_amount_cart'], $currency), 2));
|
| 146 |
+
}
|
| 147 |
+
return $result;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
/**
|
| 151 |
+
* Instantiate state and set it to state object
|
| 152 |
+
* @param string $paymentAction
|
| 153 |
+
* @param Varien_Object
|
| 154 |
+
*/
|
| 155 |
+
public function initialize($paymentAction, $stateObject)
|
| 156 |
+
{
|
| 157 |
+
$state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
|
| 158 |
+
$stateObject->setState($state);
|
| 159 |
+
$stateObject->setStatus('pending_payment');
|
| 160 |
+
$stateObject->setIsNotified(false);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/**
|
| 164 |
+
* Config instance getter
|
| 165 |
+
* @return Mage_Paypal_Model_Config
|
| 166 |
+
*/
|
| 167 |
+
public function getConfig()
|
| 168 |
+
{
|
| 169 |
+
if (null === $this->_config) {
|
| 170 |
+
$params = array($this->_code);
|
| 171 |
+
if ($store = $this->getStore()) {
|
| 172 |
+
$params[] = is_object($store) ? $store->getId() : $store;
|
| 173 |
+
}
|
| 174 |
+
$this->_config = Mage::getModel('paypal/config', $params);
|
| 175 |
+
}
|
| 176 |
+
return $this->_config;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* Check whether payment method can be used
|
| 181 |
+
* @param Mage_Sales_Model_Quote
|
| 182 |
+
* @return bool
|
| 183 |
+
*/
|
| 184 |
+
public function isAvailable($quote = null)
|
| 185 |
+
{
|
| 186 |
+
if ($this->getConfig()->isMethodAvailable() && parent::isAvailable($quote)) {
|
| 187 |
+
return true;
|
| 188 |
+
}
|
| 189 |
+
return false;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/**
|
| 193 |
+
* Custom getter for payment configuration
|
| 194 |
+
*
|
| 195 |
+
* @param string $field
|
| 196 |
+
* @param int $storeId
|
| 197 |
+
* @return mixed
|
| 198 |
+
*/
|
| 199 |
+
public function getConfigData($field, $storeId = null)
|
| 200 |
+
{
|
| 201 |
+
return $this->getConfig()->$field;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
/**
|
| 205 |
+
* Aggregated cart summary label getter
|
| 206 |
+
*
|
| 207 |
+
* @return string
|
| 208 |
+
*/
|
| 209 |
+
private function _getAggregatedCartSummary()
|
| 210 |
+
{
|
| 211 |
+
if ($this->_config->lineItemsSummary) {
|
| 212 |
+
return $this->_config->lineItemsSummary;
|
| 213 |
+
}
|
| 214 |
+
return Mage::app()->getStore($this->getStore())->getFrontendName();
|
| 215 |
+
}
|
| 216 |
+
}
|
app/code/local/MagentoCenter/Pp/Helper/Data.php
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class MagentoCenter_Pp_Helper_Data extends Mage_Core_Helper_Abstract
|
| 5 |
+
{
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
}
|
app/code/local/MagentoCenter/Pp/etc/config.xml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<MagentoCenter_Pp>
|
| 5 |
+
<version>1.0</version>
|
| 6 |
+
</MagentoCenter_Pp>
|
| 7 |
+
</modules>
|
| 8 |
+
|
| 9 |
+
<global>
|
| 10 |
+
<helpers>
|
| 11 |
+
<pp>
|
| 12 |
+
<class>MagentoCenter_Pp_Helper</class>
|
| 13 |
+
</pp>
|
| 14 |
+
</helpers>
|
| 15 |
+
</global>
|
| 16 |
+
|
| 17 |
+
<default>
|
| 18 |
+
<payment>
|
| 19 |
+
<pp>
|
| 20 |
+
<active>1</active>
|
| 21 |
+
</pp>
|
| 22 |
+
</payment>
|
| 23 |
+
</default>
|
| 24 |
+
</config>
|
app/code/local/MagentoCenter/Pp/etc/system.xml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<sections>
|
| 4 |
+
<payment>
|
| 5 |
+
<groups>
|
| 6 |
+
<pp translate="label" module="pp">
|
| 7 |
+
<label>PayPal order in selected currency</label>
|
| 8 |
+
<frontend_type>text</frontend_type>
|
| 9 |
+
<sort_order>103</sort_order>
|
| 10 |
+
<show_in_default>1</show_in_default>
|
| 11 |
+
<show_in_website>1</show_in_website>
|
| 12 |
+
<show_in_store>0</show_in_store>
|
| 13 |
+
<fields>
|
| 14 |
+
<active translate="label">
|
| 15 |
+
<label>Enabled</label>
|
| 16 |
+
<frontend_type>select</frontend_type>
|
| 17 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 18 |
+
<sort_order>1</sort_order>
|
| 19 |
+
<show_in_default>1</show_in_default>
|
| 20 |
+
<show_in_website>1</show_in_website>
|
| 21 |
+
<show_in_store>0</show_in_store>
|
| 22 |
+
</active>
|
| 23 |
+
</fields>
|
| 24 |
+
</pp>
|
| 25 |
+
</groups>
|
| 26 |
+
</payment>
|
| 27 |
+
</sections>
|
| 28 |
+
</config>
|
app/etc/modules/MagentoCenter_Pp.xml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<MagentoCenter_Pp>
|
| 5 |
+
<active>true</active>
|
| 6 |
+
<codePool>local</codePool>
|
| 7 |
+
<depends>
|
| 8 |
+
<Mage_Payment />
|
| 9 |
+
</depends>
|
| 10 |
+
</MagentoCenter_Pp>
|
| 11 |
+
</modules>
|
| 12 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>PayPal_order_in_selected_currency</name>
|
| 4 |
+
<version>1.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license>Open Software License (OSL 3.0)</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>PayPal order in selected currency</summary>
|
| 10 |
+
<description>PayPal order in selected currency</description>
|
| 11 |
+
<notes>PayPal order in selected currency</notes>
|
| 12 |
+
<authors><author><name>MagentoCenter</name><user>auto-converted</user><email>volgodark@gmail.com</email></author></authors>
|
| 13 |
+
<date>2010-09-22</date>
|
| 14 |
+
<time>13:28:58</time>
|
| 15 |
+
<contents><target name="magelocal"><dir name="Mage"><dir name="Paypal"><dir name="Block"><dir name="Standard"><file name="Redirect.php" hash="a5bc8523aad1f7a9309768bf3ea58ed5"/></dir></dir><dir name="Model"><file name="Standard.php" hash="9b5ab0252ec738bf341dca5a3d4c5693"/></dir></dir></dir><dir name="MagentoCenter"><dir name="Pp"><dir name="etc"><file name="config.xml" hash="f0a5f96c359933cc842341e1ed845ac0"/><file name="system.xml" hash="c84a9e93e250a94f0213aecb3919368f"/></dir><dir name="Helper"><file name="Data.php" hash="b9e414e2659cf8d43ab835d8f8de316c"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="MagentoCenter_Pp.xml" hash="860041dfee30e2e91f42ea704700575d"/></dir></target></contents>
|
| 16 |
+
<compatible/>
|
| 17 |
+
<dependencies/>
|
| 18 |
+
</package>
|
