Showing results for 
Search instead for 
Did you mean: 

Smart Payment Buttons custom integration problem


Smart Payment Buttons custom integration problem

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


But when I try to define a server method call to achieve what I need I got an error:



				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




public HttpResponse<Order> createOrder(boolean debug) throws IOException {
	    OrdersCreateRequest request = new OrdersCreateRequest();
	    //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:

Object { err: "JSON.parse: unexpected character at line 26 column 1 of the JSON data\ncreateOrder@http://localhost:8081/ROOT/:437:8\nhr/</</</<@", timestamp: "1571062868630", referer: "", 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.

New Community Member

Re: Smart Payment Buttons custom integration problem

I have pretty much exactly the same issue using the python sdk. It works fine for me with the JS smart buttons but when following the documentation on to replace it with server-side calls I get:


SyntaxError: Unexpected token < in JSON at position 0Error: Unexpected token < in JSON at position 0 at jr.error (  at Object.<anonymous> (