1

我们正在使用带有一些扩展的 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>

感谢您的关注。

4

1 回答 1

1

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

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

于 2017-04-21T09:31:22.520 回答