For client side, I use Swift to make Post HTTP request as follows:
<code>static func postNonceToServer(paymentMethodNonce: BTPayPalAccountNonce, deviceData: String) {
let paymentURL = URL(string: "http://server.openxverse.com/shop/transac")!
var request = URLRequest(url: paymentURL)
request.httpBody = "payment_method_nonce=(paymentMethodNonce)&device_data=(deviceData)".data(using: .utf8)
request.httpMethod = "POST"
URLSession.shared.dataTask(with: request) { (data, response, error) -> Void in
if let data = data {
print("success data from postNonceToServer", data)
} else if let error = error {
print("error from postNonceToServer", error)
} else {
print("what happen from postNonceToServer")
}
}.resume()
}
</code>
<code>static func postNonceToServer(paymentMethodNonce: BTPayPalAccountNonce, deviceData: String) {
let paymentURL = URL(string: "http://server.openxverse.com/shop/transac")!
var request = URLRequest(url: paymentURL)
request.httpBody = "payment_method_nonce=(paymentMethodNonce)&device_data=(deviceData)".data(using: .utf8)
request.httpMethod = "POST"
URLSession.shared.dataTask(with: request) { (data, response, error) -> Void in
if let data = data {
print("success data from postNonceToServer", data)
} else if let error = error {
print("error from postNonceToServer", error)
} else {
print("what happen from postNonceToServer")
}
}.resume()
}
</code>
static func postNonceToServer(paymentMethodNonce: BTPayPalAccountNonce, deviceData: String) {
let paymentURL = URL(string: "http://server.openxverse.com/shop/transac")!
var request = URLRequest(url: paymentURL)
request.httpBody = "payment_method_nonce=(paymentMethodNonce)&device_data=(deviceData)".data(using: .utf8)
request.httpMethod = "POST"
URLSession.shared.dataTask(with: request) { (data, response, error) -> Void in
if let data = data {
print("success data from postNonceToServer", data)
} else if let error = error {
print("error from postNonceToServer", error)
} else {
print("what happen from postNonceToServer")
}
}.resume()
}
On the server side, I would like to use Python and Django for http POST requests.
<code> def post(self, request):
result = gateway.transaction.sale({
"amount": "10.00",
"payment_method_nonce": nonce_from_the_client,
"device_data": device_data_from_the_client,
"options": {
"submit_for_settlement": True
}
})
if result.is_success:
return Response(true, status = status.HTTP_201_CREATED)
else:
return Response(false, status = status.HTTP_400_BAD_REQUEST)
</code>
<code> def post(self, request):
result = gateway.transaction.sale({
"amount": "10.00",
"payment_method_nonce": nonce_from_the_client,
"device_data": device_data_from_the_client,
"options": {
"submit_for_settlement": True
}
})
if result.is_success:
return Response(true, status = status.HTTP_201_CREATED)
else:
return Response(false, status = status.HTTP_400_BAD_REQUEST)
</code>
def post(self, request):
result = gateway.transaction.sale({
"amount": "10.00",
"payment_method_nonce": nonce_from_the_client,
"device_data": device_data_from_the_client,
"options": {
"submit_for_settlement": True
}
})
if result.is_success:
return Response(true, status = status.HTTP_201_CREATED)
else:
return Response(false, status = status.HTTP_400_BAD_REQUEST)
but the question is, on the server side, how do I access the POST request body data “payment_method_nonce” and “device_data” in “def post”?
Note that I could not use Json to send the POST request since BTPayPalAccountNonce is not json encryptable.
Great appreciate your help!