Paypal und Onestepcheckout

The problem: We use Magestore's one-step checkout and have repurposed the Gift Wrap functionality (gift wrapping) as shipping insurance, which customers can optionally add to any order.

However, the shipping insurance costs are not transmitted via the "PayPal" payment method by default - with the result that Magento cannot process the order correctly and classifies it as "Suspected Fraud", i.e. as an attempted fraud.
This can be solved by transmitting the shipping insurance amount to PayPal as an additional item:

First, we need to temporarily store the session values from the checkout process so that we can access them when transmitting the data to PayPal. We achieve this by modifying the file

\app\code\local\Magestore\Onestepcheckout\Model\Observer.php

In the function "orderPlaceAfter($observers)", we add the following code after the line

if($giftwrap || $giftwrapAmount){

this code:

$session->setData('onestepcheckout_giftwrap_helper_temp', 1);
$session->setData('onestepcheckout_giftwrap_amount_helper_temp', $giftwrapAmount*100);

Now that we have temporarily stored the amounts, we create an override using the file

\app\code\local\Mage\Paypal\Model\Cart.php

Here we look for the "_render()" function and add the following code after the statement

if ($this->_isShippingAsItem && (float)$this->_totals[self::TOTAL_SHIPPING]) {
$this->addItem(Mage::helper('paypal')->__('Shipping'), 1, (float)$this->_totals[self::TOTAL_SHIPPING],
$shippingItemId
);
}

to add the item:

$session = Mage::getSingleton('checkout/session');
if($session->getData('onestepcheckout_giftwrap_helper_temp') === 1) {
$giftwrapAmount = $session->getData('onestepcheckout_giftwrap_amount_helper_temp');
$session->unsetData('onestepcheckout_giftwrap_helper_temp');
$session->unsetData('onestepcheckout_giftwrap_amount_helper_temp');
$giftwrapAmount_net = round($giftwrapAmount/100,2);
$this->addItem(Mage::helper('paypal')->__('Transportversicherung'), 1, $giftwrapAmount_net,'transport_insurance');
}

In a similar way, amounts generated by price rules can also be added, such as a small-order surcharge that is applied to low-value shopping carts. Tested with Magento 1.7.0.2.

... back to the blog