Javascript 贝宝:如何获取订单id并传递到交易详细信息页面

Javascript 贝宝:如何获取订单id并传递到交易详细信息页面,javascript,paypal-sandbox,Javascript,Paypal Sandbox,我是贝宝整合的新手。我需要获取订单Id以获取交易的详细信息,并希望在另一个页面上向客户显示交易的详细信息 下面是javascript代码。以下代码显示OrderId=0 贝宝,按钮({ createOrder:函数(数据、操作){ //此功能设置交易的详细信息,包括金额和行项目详细信息。 return actions.order.create({ 应用程序上下文:{ 返回url:'https://example.com', 取消url:'https://example.com' }, 购买单位

我是贝宝整合的新手。我需要获取订单Id以获取交易的详细信息,并希望在另一个页面上向客户显示交易的详细信息

下面是javascript代码。以下代码显示OrderId=0


贝宝,按钮({
createOrder:函数(数据、操作){
//此功能设置交易的详细信息,包括金额和行项目详细信息。
return actions.order.create({
应用程序上下文:{
返回url:'https://example.com',
取消url:'https://example.com'
},
购买单位:[{
金额:{
货币代码:“美元”,
值:“”
}
}]
});
},
onApprove:功能(数据、操作){
//捕获交易资金
返回actions.order.capture().then(函数(){
//向买方出示确认书
警报('Transaction complete!'&data.orderID);
});
}
}).render(“#贝宝按钮容器”)//此功能在网页上显示智能支付按钮。

问题:上述代码不符合要求。如何解决此问题?

使用以下代码行,我能够检索事务的详细信息。-

“返回操作.order.capture().then(函数(详细信息)”

以下是完整的运行代码-

paypal.Buttons({
    createOrder: function (data, actions) {
        // This function sets up the details of the transaction, including the amount and line item details.
        return actions.order.create({
            purchase_units: [{
                amount: {
                    currency_code: 'USD',
                    value: '<%=bookingAmount%>'
                }
            }]
        });
    },
    onApprove: function (data, actions) {
        // Capture the transaction funds
        return actions.order.capture().then(function (details) {
            console.log(JSON.stringify(details));
        });
    }
}).render('#paypal-button-container');
paypal.Buttons({
createOrder:函数(数据、操作){
//此功能设置交易的详细信息,包括金额和行项目详细信息。
return actions.order.create({
购买单位:[{
金额:{
货币代码:“美元”,
值:“”
}
}]
});
},
onApprove:功能(数据、操作){
//捕获交易资金
返回actions.order.capture().then(函数(详细信息){
log(JSON.stringify(details));
});
}
}).render(“#贝宝按钮容器”);

控制台日志(数据);
pleaase我正在使用angular,并且我已经将此脚本与component.ts集成。我想保留此返回的订单ID,但我无法访问Approve函数中的service.ts变量。我正在.NET应用程序中使用上述代码。对于angular应用程序,请尝试从service.ts“导入”变量。诀窍是像这样使用ngZone这很有帮助
paypal.Buttons({
    createOrder: function (data, actions) {
        // This function sets up the details of the transaction, including the amount and line item details.
        return actions.order.create({
            purchase_units: [{
                amount: {
                    currency_code: 'USD',
                    value: '<%=bookingAmount%>'
                }
            }]
        });
    },
    onApprove: function (data, actions) {
        // Capture the transaction funds
        return actions.order.capture().then(function (details) {
            console.log(JSON.stringify(details));
        });
    }
}).render('#paypal-button-container');