Hi all, I'm facing an integration with smart payment buttons with server-side setup because my data is filled dynamically and also I want to store the payment in my own database. If I try this code it works successfully: <script> paypal.Buttons({
createOrder: function(data, actions) {
// Set up the transaction
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
style: {
color: 'blue',
shape: 'rect',
label: 'paypal',
height: 40
}
}).render('#ppBtn');</script> But when I try to define a server method call to achieve what I need I got an error: client-side <script>
paypal.Buttons({
createOrder: function() {
return fetch('${pageContext.request.contextPath}/createOrder', {
method: 'post',
headers: {'content-type': 'application/json'}
}).then(function(res) {
return res.json();
}).then(function(data) {
return data.orderID; // Use the same key name for order ID on the client and server
});
},
style: {
color: 'blue',
shape: 'rect',
label: 'paypal',
height: 40
}
}).render('#ppBtn');
</script> server-side public HttpResponse<Order> createOrder(boolean debug) throws IOException {
OrdersCreateRequest request = new OrdersCreateRequest();
request.prefer("return=representation");
request.requestBody(buildRequestBody());
//3. Call PayPal to set up a transaction
HttpResponse<Order> response = client().execute(request);
if (debug) {
if (response.statusCode() == 201) {
System.out.println("Status Code: " + response.statusCode());
System.out.println("Status: " + response.result().status());
System.out.println("Order ID: " + response.result().id());
System.out.println("Intent: " + response.result().intent());
System.out.println("Links: ");
for (LinkDescription link : response.result().links()) {
System.out.println("\t" + link.rel() + ": " + link.href() + "\tCall Type: " + link.method());
}
System.out.println("Total Amount: " + response.result().purchaseUnits().get(0).amount().currencyCode()
+ " " + response.result().purchaseUnits().get(0).amount().value());
}
}
return response;
} And the error message is the following: unhandled_error Object { err: "JSON.parse: unexpected character at line 26 column 1 of the JSON data\ncreateOrder@http://localhost:8081/ROOT/:437:8\nhr/</</</<@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:55387\nw</n.dispatch@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:5429\nw</n.then@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:6172\nhr/</</<@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:55000\n@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:60279\nw</e.try@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:7915\n@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:59991\nNr@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:62261\n_r/</</<@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:66869\n_r/</<@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:66647\n\n\nor[er.ERROR]@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:50112\nCr/</<@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:56841\nCr/<@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:56695\nCr@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:56635\nNr/l<@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:61935\nNr@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:61889\n_r/</</<@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:66869\n_r/</<@https://www.paypal.com/sdk/js?client-id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx¤cy=EUR&disable-funding=sofort:1:66647\n", timestamp: "1571062868630", referer: "www.sandbox.paypal.com", uid: "19a7b17404_mti6mjg6mdu", env: "sandbox" } It does not make any sense for me and it never gets method in server side. Could you kindly help me with something that can be useful to solve this problem? Thank you to all.
... View more