嗨,在执行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工作?
答案 0 :(得分:0)
这很可能是由于使用 this 的范围所致。尝试使用箭头功能,通常更推荐使用。您的代码将如下所示。
return actions.payment.execute().then( (response) => { ...} );