javascript - 如何在 paypal 快速结帐中显示产品详细信息

标签 javascript php paypal express-checkout

我已经实现了这样的快速结账

//渲染 PayPal 按钮

paypal.Button.render({

// Set your environment

env: 'sandbox', // sandbox | production

// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create

client: {
    sandbox:    'AZDxjDScFpQtjWTOUtWKbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6liB2CUXlkA59kJXE7M6R',
    production: 'Aco85QiB9jk8Q3GdsidqKVCXuPAAVbnqm0agscHCL2-K2Lu2L6MxDU2AwTZa-ALMn_N0z-s2MXKJBxqJ'
},

// Set to 'Pay Now'

commit: true,

// Wait for the PayPal button to be clicked

payment: function() {

    // Make a client-side call to the REST api to create the payment

    return paypal.rest.payment.create(this.props.env, this.props.client, {
        transactions: [
            {
                amount: { total: '<?php echo $cart->total(); ?>', currency: 'USD' }
            }
        ]
    });
},

// Wait for the payment to be authorized by the customer

onAuthorize: function(data, actions) {

    // Execute the payment

    return actions.payment.execute().then(function() {
        document.querySelector('#paypal-button-container').innerText = 'Payment Complete!';
        window.location.href = 'cartaction.php?action=place0rder';
    });
}

}, '#paypal-button-container');

其中 $cart->total() 是所有产品的总应付金额。它工作得很好。

但我想显示所有产品名称价格和描述,如下图所示。

When we click Amount it shows item details

但在我的例子中,它只显示如下所示的金额。

enter image description here

我应该在代码中添加什么来实现这一点。请问有什么帮助吗?

最佳答案

就像 REST API 集成一样,您实际上可以使用相同的参数。下面是我的该部分的示例代码:

transactions: [
	{
		amount: { total: '1.00', currency: 'USD' },
		item_list: {
			items: [
				{
				name: 'hat',
				description: 'Brown hat.',
				quantity: '1',
				price: '1.00',
				currency: 'USD'
				}
			]
		}
	}
]

关于javascript - 如何在 paypal 快速结帐中显示产品详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43655228/

相关文章:

javascript - 语法错误: Unexpected end of input at Module._compile

javascript - 如何在 iPad 上自动打开 HTML 选择菜单

php - Azure 函数应用程序 - PHP $_GET/$_POST/$_REQUEST

javascript - 如何在有关 td 旁边显示响应

wordpress - WooCommerce:使用 PayPal 和 notify_URL

javascript - 不区分大小写的 javascript 替换考虑单词边界的正则表达式

javascript - JS错误: play is not a function

php - $next_avail ID - 我的网站需要的一种 auto_increment - 查询速度

PHP 文件不会从 HTML PayPal 表单中提取 'AMOUNT'

php - 支付成功后paypal,如何将用户重定向到新页面