【问题标题】:Magento Paypalplus - Deactivate Payment-Methods via PHPMagento Paypalplus - 通过 PHP 停用付款方式
【发布时间】:2017-09-18 04:05:09
【问题描述】:

我们正在使用带有一些扩展的 Magento,其中之一是 Paypalplus,它是必不可少的。

现在我们要销售礼券,这是 Paypal 明确禁止的。所以我们需要停用 Paypayplus,或者至少停用它的一些付款方式。

我们首先尝试完全停用它,这导致 Javascript 损坏,并且 Magento 拒绝了订单。似乎如果激活了 PPP,则当购物车中存在礼券时,其他内置方法不会加载其 Js,而是尝试使用未加载的 PPP-Js。

然后我尝试使用自己的 Js 停用被禁止的付款方式,它会自行呈现所有方式。

window.ppp = PAYPAL.apps.PPP({ ... })

这应该设置 PPP Js。但我不知道是否有可能或在对象中传递哪个参数来部分或完全停用 它自己的付款方式。谁能告诉我。我现在搜索了一段时间,但找不到有关此 API 的文档。

这是应该呈现 PPP 的完整代码,包含在 Magento PPP-Extension 中:

<div id="ppplus"></div>
<script type="text/javascript">
    if(typeof payment == 'undefined') {
        var payment = {};
    }
    function selectMethod(code) {
        try {
            if(typeof awOSCPayment != "undefined") {
                awOSCPayment.currentMethod = code;
            }
        } catch (e) {

        }
        document.getElementById('p_method_' + code).click();
    }
    window.externMethodEnabled = false;
    window.startPPP = function () {
        if(typeof window.thirdPartyObject == 'undefined') {
            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(); ?>';
        selectMethod('<?php echo Iways_PayPalPlus_Model_Payment::METHOD_CODE; ?>');
        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; ?>
                <?php if($this->showLoadingIndicator()) : ?>
                showLoadingIndicator: true,
                <?php endif; ?>
                country:"<?php echo $this->getCountryId(); ?>",
                language:"<?php echo $this->getLanguage(); ?>",
                onContinue: function () {
                    payment.save()
                },
                onThirdPartyPaymentMethodSelected:function (data) {
                    this.lastCall = 'onThirdPartyPaymentMethodSelected';
                    selectMethod(window.thirdPartyObject[data.thirdPartyPaymentMethod]);
                },
                enableContinue: function (data) {
                    if(this.lastCall != 'onThirdPartyPaymentMethodSelected') {
                        selectMethod('<?php echo Iways_PayPalPlus_Model_Payment::METHOD_CODE; ?>');
                    }
                    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();
                        }
                        if($$('#aw-onestepcheckout-place-order-button').length > 0) {
                            $$('#aw-onestepcheckout-place-order-button')[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();
                            }
                            if($$('#aw-onestepcheckout-place-order-button').length > 0) {
                                $$('#aw-onestepcheckout-place-order-button')[0].disable();
                            }
                        }catch (e) {
                            console.log(e);
                        }
                    }
                },
                <?php echo $this->getThirdPartyMethods(); ?>
            });
    }
    window.startPPP();
    function checkStep() {
        try {
            if(typeof window.checkout != 'undefined' && typeof window.lastStep == 'undefined') {
                window.lastStep = window.checkout.accordion.currentSection;
            }
            if (typeof window.lastStep != 'undefined' && window.lastStep != window.checkout.accordion.currentSection) {
                window.lastStep = checkout.accordion.currentSection;
                if (checkout.accordion.currentSection == "opc-payment") {
                    window.startPPP();
                }
            }
        } catch(e) {
        }
    }
    window.setInterval(checkStep, 1000);

</script>

感谢您的关注。

【问题讨论】:

    标签: javascript php magento paypal paypal-plus


    【解决方案1】:

    好的,我们发现,没有参数可以传递来部分禁用支付方式。我找到了另一种方法来消除困难。参数 onLoad 采用一个函数,该函数在 iframe 准备好时调用。每当购物车中有礼券时,我们都会通过将其从 iframe DOM 中删除来手动删除付款方式。这不是最佳解决方案,但它确实有效。

    希望看到,Paypal 扩展了他们的 API,给开发者更多的控制权。

    【讨论】:

    • 你能分享一下你的代码吗?我也在寻找这样的解决方案,但遇到了 CORS 问题。
    猜你喜欢
    • 1970-01-01
    • 2012-03-01
    • 2014-08-04
    • 2016-07-05
    • 2013-02-15
    • 2013-02-21
    • 2013-05-25
    • 2015-09-13
    • 2015-02-27
    相关资源
    最近更新 更多