Skip to content

Instantly share code, notes, and snippets.

@madismanni
Last active May 5, 2018 20:22
Show Gist options
  • Save madismanni/1d7f861d77a8865e08a5877fad849ca3 to your computer and use it in GitHub Desktop.
Save madismanni/1d7f861d77a8865e08a5877fad849ca3 to your computer and use it in GitHub Desktop.
FIX FOR ISSUE : the following combination not working : pp+ 1.5.1 /// One Step Checkout 4.5.5 /// and patch for them
<?php $paymentExperience = $this->getPaymentEperience();?>
<?php if ($paymentExperience) :?>
<script type="text/javascript">
window.externMethodEnabled = false;
window.startPPP = function () {
if(typeof window.thirdPartyObject == 'undefined') {
//window.thirdPartyObject = <?php echo $this->getThirdPartyJsonObject(); ?>;
//window.thirdPartyMethodObject = <?php echo $this->getThirdPartyMethodJsonObject(); ?>;
window.thirdPartyObject = {<?php echo $this->getThirdPartyJsonObject(); ?>};
window.thirdPartyMethodObject = {<?php echo $this->getThirdPartyMethodJsonObject(); ?>};
}
document.cookie = 'paypalplus_session=; Path=/checkout/onepage; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
document.cookie = 'paypalplus_session=; Path=/checkout; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
document.cookie = 'paypalplus_session=; Path=/firecheckout; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
document.cookie = 'paypalplus_session=; Path=/onestepcheckout; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
window.pppId = '<?php echo $this->getPayPalPaymentId(); ?>';
window.ppp = PAYPAL.apps.PPP(
{
approvalUrl: "<?php echo $paymentExperience; ?>",
placeholder: "ppplus",
mode: "<?php echo Mage::getStoreConfig('iways_paypalplus/api/mode'); ?>",
useraction:"commit",
buttonLocation:"outside",
<?php if($this->isPuiSandboxMode()) : ?>
showPuiOnSandbox: true,
<?php endif; ?>
country:"<?php echo $this->getCountryId(); ?>",
language:"<?php echo $this->getLanguage(); ?>",
onContinue: function () {
payment.save()
},
enableContinue: function (data) {
this.lastCall = 'enableContinue';
try {
if($$('#payment-buttons-container > button').length > 0) {
$$('#payment-buttons-container > button')[0].enable();
}
if($('onestepcheckout-place-order') != null) {
$('onestepcheckout-place-order').enable();
}
if($$('#review-buttons-container > button').length > 0) {
$$('#review-buttons-container > button')[0].enable();
}
if($('onestepcheckout-button-place-order') != null) {
$('onestepcheckout-button-place-order').enable();
}
if($$('#checkout-review-submit > button.opc-btn-checkout').length > 0) {
$$('#checkout-review-submit > button.opc-btn-checkout')[0].enable();
}
}catch (e) {
console.log(e);
}
},
disableContinue: function (data) {
if(!window.externMethodEnabled) {
try {
if($$('#payment-buttons-container > button').length > 0) {
$$('#payment-buttons-container > button')[0].disable();
}
if($('onestepcheckout-place-order') != null) {
$('onestepcheckout-place-order').disable();
}
if($$('#review-buttons-container > button').length > 0) {
$$('#review-buttons-container > button')[0].disable();
}
if($('onestepcheckout-button-place-order') != null) {
$('onestepcheckout-button-place-order').disable();
}
if($$('#checkout-review-submit > button.opc-btn-checkout').length > 0) {
$$('#checkout-review-submit > button.opc-btn-checkout')[0].disable();
}
}catch (e) {
console.log(e);
}
}
},
onThirdPartyPaymentMethodSelected:function (data) {
this.lastCall = 'onThirdPartyPaymentMethodSelected';
selectMethod(window.thirdPartyObject[data.thirdPartyPaymentMethod]);
},
<?php echo $this->getThirdPartyMethods(); ?>
});
}
/**
* our goal here is to not edit any template and instead just inject our functionality on default events. Currently replacing OneStepCheckout submit event
*/
Event.observe(window, 'load', function() {
// check if we are dealing with OneStepCheckout
payment.isOneStepCheckout = $$('.onestepcheckout-place-order');
payment.formOneStepCheckout = $('onestepcheckout-form');
payment.iways = 'iways_paypalplus_payment';
payment.submitclicked = false;
Ajax.Responders.register({
onComplete : function(transport) {
if (transport.url.indexOf("onestepcheckout") > 0) {
if (payment.currentMethod == payment.iways) {
if ($('onestepcheckout-place-order') != null) {
$('onestepcheckout-place-order').disable();
}
window.startPPP();
}
}
}
});
payment.formOneStepCheckout.submit = payment.formOneStepCheckout.submit.wrap(function(originalSubmitMethod) {
if(payment.submitclicked){
return;
}
payment.toggleOneStepCheckout('payment');
payment.submitclicked = true;
if (payment.currentMethod == payment.iways) {
if ($('checkout-agreements') != null) {
if (checkout.loadWaiting != false){
return;
}
//checkout.setLoadWaiting('review');
payment.toggleOneStepCheckout('payment');
params = {};
var items = $$('.checkout-agreements input');
var names = items.pluck('name');
var values = items.pluck('checked');
for(var x=0; x < names.length; x++) {
if(values[x]) {
params[names[x]] = 1;
}
}
params.validate = true;
var request = new Ajax.Request(
'<?php echo Mage::helper('iways_paypalplus')->getUrl('paypalplus/index/validate'); ?>',
{
method: 'post',
parameters: params,
onSuccess: function (transport) {
try {
response = eval('(' + transport.responseText + ')');
}
catch (e) {
response = {};
}
if (response.redirect) {
review.isSuccess = true;
window.ppp.doCheckout();
return;
}
if (response.success) {
review.isSuccess = true;
window.ppp.doCheckout();
}
else {
var msg = response.error_messages;
if (typeof(msg) == 'object') {
msg = msg.join("\n");
}
if (msg) {
alert(msg);
}
payment.toggleOneStepCheckout('remove');
}
},
onFailure: function(transport){
payment.toggleOneStepCheckout('remove');
}
}
);
} else {
//review.isSuccess = true;
payment.submitclicked = false;
window.ppp.doCheckout();
}
} else {
originalSubmitMethod();
}
});
//add new method to restore the palce order state when failure
payment.toggleOneStepCheckout = function(action){
submitelement = $('onestepcheckout-place-order');
loaderelement = $$('.onestepcheckout-place-order-loading');
if(action === 'payment'){
window.already_placing_order = true;
/* Disable button to avoid multiple clicks */
submitelement.removeClassName('orange').addClassName('grey');
submitelement.disabled = true;
payment.holdOneStepCheckout = true;
}
if(action === 'remove'){
submitelement.removeClassName('grey').addClassName('orange');
submitelement.disabled = false;
if(loaderelement){
loaderelement = loaderelement[0];
if(loaderelement){
loaderelement.remove();
}
}
window.already_placing_order = false;
payment.holdOneStepCheckout = false;
}
return;
};
});
</script>
<?php endif;?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment