Level 11
You could do something like this.
export default {
data() {
return {
amount: 0,
user: "",
}
},
mounted() {
axios.get('/api')
.then(res => {
this.user = res.data.user;
this.amount = res.data.amount;
this.preparePaypalButtons();
})
.catch(err => console.log(err))
},
methods: {
preparePaypalButtons() {
paypal.Buttons({
style: {
layout: 'horizontal',
label: 'pay',
tagline: 'false'
},
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [{
amount: {
value: this.amount,
}
}]
});
},
onApprove: (data, actions) => {
return actions.order.capture().then(details => {
axios.post('/pay-now', {
payer_id: this.user,
amount: details.purchase_units[0].amount.value,
})
.then(res => {
window.location.replace("/finish-order");
})
.catch(err => console.log(err))
});
}
}).render('#btn');
}
}
}