PayPal批准/完成交易后调用外部函数

问题描述 投票:0回答:1

我正在为我的Checkout流程集成PayPal智能按钮,下面是呈现按钮的代码

     LoadPaypalButton(orderid :string , link : string,token : string , applicationbaseurl:string)
  {
    this.addPaypalScript().then(()=>{paypal.Buttons({enableStandardCardFields: true,
      style: {
        shape: 'rect',
        color: 'blue',
        layout: 'vertical',
        label: 'paypal',
    },
      createOrder: function() {
        return orderid
       },
       onApprove : function(data , actions) {
        return fetch(link, {
          method: 'post',
          headers: {
            'Authorization': token,
            'content-type': 'application/json'
          },
          body: JSON.stringify({
            OrderID: data.orderID
          })
        }).then(function(res) {
          return res.json();
        }).then(function(details) {
          console.log( details);
          console.log(details);
          actions.redirect(applicationbaseurl+'OrderHistory/'+token);

        })
       }
     }
    ).render('#paypal-button-container')});


  }

一切正常,我想在事务完成后调用外部函数来处理我的UI,而无需将用户带到任何其他页面。如何在脚本内调用如下函数:>

callsuccess()
 {
   // Some Other work....
   console.log("Something ..!");

 }

我正在使用Angular 8.0作为前端。这是我到目前为止在OnApprove中尝试的方法:

   onApprove : function(data , actions) {
    return fetch(link, {
      method: 'post',
      headers: {
        'Authorization': token,
        'content-type': 'application/json'
      },
      body: JSON.stringify({
        OrderID: data.orderID
      })
    }).then(function(res) {
      return res.json();
    }).then(function(details) {

      this.callsuccess(); //  This does not work
      actions.redirect(applicationbaseurl+'OrderHistory/'+token);

    })
   }

给我下面的错误

zone-evergreen.js:172 Uncaught TypeError: Cannot read property 'callsuccess' of undefined
at http://localhost:4200/main.js:1430:30
at ZoneDelegate.invoke (http://localhost:4200/polyfills.js:3365:26)
at Zone.run (http://localhost:4200/polyfills.js:3130:43)
at http://localhost:4200/polyfills.js:3861:36
at ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:3397:31)
at Zone.runTask (http://localhost:4200/polyfills.js:3174:47)
at drainMicroTaskQueue (http://localhost:4200/polyfills.js:3565:35)

是否有人建议实现这一目标..?

我正在为我的Checkout流程集成PayPal智能按钮下面是呈现按钮LoadPaypalButton(orderid:string,link:string,token:string,applicationbaseurl:string)的代码{...

node.js angular paypal
1个回答
0
投票
尝试使用箭头功能:
© www.soinside.com 2019 - 2024. All rights reserved.