my cloud function
Parse.Cloud.define(“paymentRequest”, async (request) => {
const {token, amount, number} = request.params;
const autToken = `Token ${token}`;
const headers = {
'Authorization': autToken,
'Content-Type': 'application/json'
};
const url = `https://demo.campay.net/api/collect/`;
const body = JSON.stringify({
"amount": amount,
"from": number,
"description": "Testing Flipay withdrawal",
"external_reference": ""
});
try {
const response = await Parse.Cloud.httpRequest({
method: 'POST',
url: url,
headers: headers,
body: body,
});
if (response.statusCode == 200) {
console.log(response.text);
const jbody = JSON.stringify(response.body);
const data = JSON.parse(jbody);
const ref = data.reference;
console.log(`Reference ${ref}`);
console.log('paid');
return ref;
} else {
console.error('Request failed with response code:', response.status);
console.log('not paid');
}
} catch (error) {
console.error('Request failed with error:', error);
console.log('not paid');
throw new Error('Failed to send payment request');
}
});
the output after been called with the necessary parameters
flutter: ╭– Parse Request
flutter: curl -X POST -H ‘content-type: text/plain; charset=utf-8’ -H ‘user-agent: Flutter Parse SDK 5.1.3’ -H ‘X-Parse-Application-Id: VSywmg8EtB4bhzJzRXuxsjxzLiWBJlEEshZB578K’ -H ‘X-Parse-Client-Key: qJvcumQMZposWCGayVWfC6GyYSkljB5MijIJ8ALS’ -d ‘{“token”:”eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsInVpZCI6MzM5NH0.eyJpYXQiOjE3MTYxNTQ5OTAsIm5iZiI6MTcxNjE1NDk5MCwiZXhwIjoxNzE2MTU4NTkwfQ.xrxoGtwsfYR1bktP0EnUOU-6DS3OPQ8SE7X312QHAOU”,”amount”:”100″,”number”:”237678447430″}’ https://parseapi.back4app.com/functions/paymentRequest
https://parseapi.back4app.com/functions/paymentRequest
flutter: ╰–
flutter: ╭– Parse Response
Class: paymentRequest
Function: ParseApiRQ.execute
Status Code: 200
Payload: {}
╰–
i have tried everything i could.
the expected results has to be uuid4 for example: “bcedde9b-62a7-4421-96ac-2e6179552a1a”
che carlson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.