无法读取未定义的 属性 'http'

Cannot read property 'http' of undefined

您好,我需要在执行 ngx-paypal 付款后将交易日期发送到服务器。但是我得到了这个错误: Cannot read property 'http' of undefined

这是我的代码:

 payPalConfig = {
  env: 'sandbox',
    client: {
                sandbox:    '########################',
                production: '#######################'
            },
    commit: true,

            // payment() is called when the button is clicked
            payment: function(data, actions) {
              // Make a call to the REST api to create the payment
                let prezzo = cookieService.get('importo');
                return actions.payment.create({
              payment: {
                        transactions: [
                            {
              amount: { total: prezzo, currency: 'EUR' }
                            }
                        ]

            }
                })
            },
    // onAuthorize() is called when the buyer approves the payment
            onAuthorize: function(data, actions) {

                // Make a call to the REST api to execute the payment
                return actions.payment.execute().then(function(response) {
                  this.http.post('https://dev.miosit.it/aggiorna-abbonamento', response).subscribe(data=> {});

                });
            }
    };

在这种情况下如何让 http 正常工作?

这很可能是由于 this 的使用范围。尝试使用箭头函数,通常更推荐。您的代码将如下所示。

return actions.payment.execute().then( (response) => { ...} );