首页 > 解决方案 > Django Paypal 集成 - 更改语言时渲染按钮不起作用

问题描述

我已将 Paypal 集成到我的网站,一切都按预期工作。但是,当我添加一种新语言(希腊语)时,我在使用 paypal 按钮按下付款时遇到了问题。当改回英文时,一切正常,按钮渲染没有问题。

我从贝宝得到的错误是:

在此处输入图像描述

我正在使用的代码:

<div id="paypal-button-container">
                        <!--Paypal button will load-->
                </div>

    // Render the PayPal button into #paypal-button-container
    paypal.Buttons({
    
        style: {
            color: 'blue',
            shape: 'rect',
            label: 'pay',
            height: 40
        },
    
        // Set up the transaction
        createOrder: function(data, actions) {
            console.log('kostas');
            console.log(actions);
            return actions.order.create({
                purchase_units: [{
                    amount: {
                        value: amount,
                    }
                }]
            });
        },
    
        // Finalize the transaction
        onApprove: function(data, actions) {
            return actions.order.capture().then(function(details) {
                // Show a success message to the buyer
                console.log(details);
                sendData();
                function sendData() {
                    fetch(url, {
                        method: "POST",
                        headers: {
                            "Content-type": "application/json",
                            "X-CSRFToken": csrftoken,
                        },
                        body: JSON.stringify ({
                            orderID: orderID,
                            transID: details.id,
                            payment_method: payment_method,
                            status: details.status,
                        }),
                    })
                .then((response) => response.json())
}).render('#paypal-button-container');

由于是第一次尝试使用贝宝,如果您能给我关于以下错误的任何提示或有关如何排除故障的任何想法,我将不胜感激。

非常感谢

标签: djangopaypal

解决方案


当我添加一种新语言(希腊语)时,我在使用 paypal 按钮按下付款时遇到了问题。

您没有显示要添加的代码,因此无法说出具体是什么触发了错误,但似乎它可能是订单创建调用中的某些内容,这不是更改按钮文本的正确位置。

要将按钮的语言更改为默认语言以外的语言(根据浏览器的语言自动检测),请使用localeSDKsrc行上的查询字符串参数。

这是文档:https ://developer.paypal.com/docs/checkout/reference/customize-sdk/#locale


推荐阅读