Paypal Express-Service Side Integration

24nitya
New Community Member

Hi Team,

I am trying to integrate paypal express with my server side application. I have included the javascript checkout.js and have modified the payment() method to call my server side mapping i.e. th ejava controller but wit does not work giving different exceptions as follows:

Approach 1:

Client side:

var url1 = "paypalexpress/starttransactiontest?productCode=123&qty=1&bundleNo=0&bundleTemplateId=null";

payment: function () {

var client = new XMLHttpRequest();
client.open("POST", url1, false);
console.log("URL is");
client.setRequestHeader("Content-Type", "application/json");
console.log(url1);
client.send(null);
if (client.status == 202) {
var params = client.responseText.split('&');
document.querySelector('#finalizeTransactionId').innerText = params[1];
return params[0];
}

return "error";
},

 

Backend:

@RequestMapping(value="/starttransactiontest", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity initiatePaypalTransactionExpress(final HttpServletRequest request,
final String productCode,final long qty,final Integer bundleNo,final String bundleTemplateId,
final Model model) {

// perform logic 

final String response = String.format("%s&%d&%d&%d", paypalCheckoutData.getPaypalPaymentRef(), paypalCheckoutData.getFinalizeTransactionId());

return new ResponseEntity<>(response, HttpStatus.ACCEPTED);

}

On click of the paypal express button:

Error: INVALID_RESOURCE_ID at https://www.payp…://www.paypalobjects.com/api/checkout.js:1825:14)", errtype: "[object Error]", timestamp: 1582662569198, windowID: "a24ecf7490", pageID: "cb8839f346", …}

 

Approach 2:

Js code:

payment: function() {
// 2. Make a request to your server
var CREATE_URL = 'paypalexpress/starttransaction?productCode=123&qty=1&bundleNo=0&bundleTemplateId=null';
return paypal.request.post(CREATE_URL)
.then(function(res) {
alert(res.paymentID);
// 3. Return res.id from the response
return res.paymentID;
});
},

Backend(server side):

@RequestMapping(value="/starttransaction", method = RequestMethod.POST)
@ResponseBody
public PaypalCheckoutData initiatePaypalTransaction(final HttpServletRequest request,
final String productCode,final long qty,final Integer bundleNo,final String bundleTemplateId,
final Model model) {

//logic which gets the paypal id as an attribute in paypalCheckoutData

return paypalCheckoutData;
}

Error: No value passed to payment at https://w…s://www.paypalobjects.com/api/checkout.js:8156:3

 

In none of the cases I am getting the response and the paypal window doe snot open.Really appreciate your inputs here if something needs to be modified as do not get response form the paypal. I have been following this link for the server side integration : https://developer.paypal.com/docs/archive/checkout/how-to/server-integration/

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.