I'm integrating PayPal Smart Button for My CheckOut Process Below is the Code to Render the Button
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')});
}
Everything Working fine and i want to call external function to handle my UI after transaction finish without taking user to any other page.How can call function like below within the script
callsuccess()
{
// Some Other work....
console.log("Something ..!");
}
I'm Using Angular 8.0 as my front end.this is what i tried so far in 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);
})
}
giving me below error
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)
Does anyone have any suggestion to make this happen ..?