Trying to test sandbox createOrder Capture Order with angular Receiving "Payer has not yet approved the Order for payment" Order is created correctly.
Angular code
try {
this.paypal = await loadScript({ clientId : clientId });
} catch (error) {
console.error("failed to load the PayPal JS SDK script", error,HttpStatusCode);
}
if (this.paypal) {
try {
await this.paypal.Buttons({
style: {
layout: 'vertical',
color: 'gold',
},
createOrder : this.createOrderPaypal(),// this returns orderData.id from backend
onApprove : (data: any, actions: any) => {
//actions.order.capture().then(this.approveOrderPaypal())
this.approveOrderPaypal(data.orderID)
},
}).render("#buttonPaypal");
} catch (error) {
console.error("failed to render the PayPal Buttons", error);
}
}
backend dotnet code:
private async Task<dynamic> _CreateOrder(PayPalOrder newOrder,string _paypalClientId, string _paypalClientSecret, string _base)
{
var accessToken = await GenerateAccessToken(_paypalClientId,_paypalClientSecret,_base);
var url = $"{_base}/v2/checkout/orders";
var payload = new
{
intent = "CAPTURE",
purchase_units = new[]
{
new
{
description = newOrder.Description,
amount = new
{
currency_code = newOrder.CurrencyCode,
value = newOrder.Value
}
}
}
};
.....
var response = await client.SendAsync(request);
return await HandleResponse(response);
}
private async Task<dynamic> _CaptureOrder(string orderID, string _paypalClientId, string _paypalClientSecret, string _base)
{
var accessToken = await GenerateAccessToken(_paypalClientId,_paypalClientSecret,_base);
var url = $"{_base}/v2/checkout/orders/{orderID}/capture";
.....
var response = await client.SendAsync(request);
return await HandleResponse(response);
}
Receiving "Payer has not yet approved the Order for payment" Order is created correctly.
createOrder : this.createOrderPaypal(),
createOrder should be set to a function (that returns), which normally would not itself be function evaluation/return. Instead try:
createOrder : this.createOrderPaypal,
It also appears wrong that this.approveOrderPayPal is not taking the id
to capture as a parameter.
Both these functions should be included in the question for if anything else is wrong within them.