I'm following PayPal's server integration demo: https://developer.paypal.com/demo/checkout/#/pattern/server
The following code does not appear to be passing data via the "body" parameter:
createOrder: function(data, actions) {
return fetch('/paypal_api', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({name:"sammy"}),
}).then(function(res) {
return res.json();
}).then(function(orderData) {
return orderData.id;
});
},
I am, however, able to pass parameters within the URL. For example:
return fetch('/paypal_api/<some_variable>/', {
So I can get this working but am bugged that the POST method does not appear to be working as expected. Here's a snippet from my python server code:
class createOrder(webapp2.RequestHandler): def get(self):
print self.request.params
... and the print statement returns nothing (UnicodeMultiDict([])).
I'm 99% certain that I'm missing something obvious since google is not helping me! :)
CodePudding user response:
Parse the request body as JSON
import json
jsonstring = self.request.body
jsonobject = json.loads(jsonstring)