I am trying to integrate https://www.checkout.com/ in my app.
I tried there sample code to get token.
Frames.addEventHandler(
Frames.Events.CARD_TOKENIZED,
function (data) {
Frames.addCardToken(form, data.token);
if (data.token) {
confirmPayment(data.token);
} else {
console.log(data);
}
}
);
I tried https://api.sandbox.checkout.com/payments/ api to do the payments,
payment successfully captures, but I am unable to read its response to or redirect user on successfully attempt.
async function confirmPayment(token) {
// Storing response
const response = await fetch('https://api.sandbox.checkout.com/payments/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk_sbox_..abc'
},
body: JSON.stringify({
"source": {
"type": "token",
"token": token
},
"Capture": true,
"processing_channel_id": "pc_..abc",
'amount': 1000,
'currency': 'USD',
"3ds": {
"enabled": false
},
"customer": {
"email": "test.testUI#example.com",
"name": "John Test"
},
'reference': 'ORD-175-759',
"metadata": {
"udf1": "UI-CALL-TEST",
"coupon_code": "NY2018",
"partner_id": 123989
},
"success_url": "http://example.com/payments/success",
"failure_url": "http://example.com/payments/fail"
})
});
// Storing data in form of JSON
var data = await response.json();
console.log(data);
if (response) {
}
show(data);
}
I want to get a payment response like errors "card invalid" etc
Also redirect to Url if successful.
Please let me know if this is a correct way to do the payment or If there any JavaScript library that I can use?
I want to do payment on client side and use webhook later.
Thank you
Related
I am posting data to a web API. The response is a 401 error. I don't know what is wrong with my code.
This is the code:
var form = document.getElementById("form");
form.addEventListener("submit", function (e) {
e.preventDefault();
var edition= document.getElementById("edition").value;
var competition= document.getElementById("competition").value;
var price= document.getElementById("price").value;
var firstname= document.getElementById("firstname").value;
var lastname= document.getElementById("lastname").value;
var email= document.getElementById("email").value;
fetch("https://front-api.njuko.com/partner/registration", {
method: "POST",
body: JSON.stringify({
edition: edition,
competition: competition,
price: price,
firstname: firstname,
lastname: lastname,
email: email,
}),
headers: {
"Content-Type": "application/json",
},
})
.then(function (response) {
return response.json();
})
.then(function (data) {
console.log(data);
});
});
As i am new to the programming i don't how i can send the data into the website. This are the request sample of the website.
{
"edition": "5d888c93df85b80006f54265",
"competition": "5d888c93df85b80006f54265",
"price": "5d888c93df85b80006f54265",
"firstname": "John",
"lastname": "Doe",
"email": "john.doe#acme.com",
"methodName": "Partner payment (VISA)",
"datas": [
{
"value": "Detroit, Michigan",
"field": "5d888c93df85b80006f54255"
}
],
"metaData": [
{
"key": "stravaActivityId",
"label": "strava-activity-id",
"value": "329859FNENF29492Ifnjnfe93"
}
]
}
This are the Actual Picture
401 Error Code means Unauthorized.
I don't see any authentication in your code.
The HyperText Transfer Protocol (HTTP) 401 Unauthorized response status code indicates that the client request has not been completed because it lacks valid authentication credentials for the requested resource.
I dont know the implementation of the exact API,
but mostly used is this :
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer <API_TOKEN>"
}
I am trying to create a fetch call to servicedesk plus system but I keep getting 400 error, I understand that the request I made is not what the server wanted but in postman, I do manage to send that same query successfully. I can't understand what is the problem
In the dev tools network tab I see this data after dending the Json:
response_status: {status_code: 4000,…}
messages: [{status_code: 4001, field: "input_data", type: "failed", message: "JSON cant be analyzed"}]
0: {status_code: 4001, field: "input_data", type: "failed", message: "JSON cant be analyzed"}
field: "input_data"
message: "JSON cant be analyzed"
status_code: 4001
type: "failed"
status: "failed"
status_code: 4000
From what I read in the API documentation I saw that the 4001 error means that the ID or the name are not as they are in the service desk system.
here is a link to the API docs
this is my code:
const jss = {
"request": {
"subject": "test 29072020",
"description": "TEST REQUEST BY DAVID",
"requester": {
"id": "1231",
"name": "david"
},
"resolution": {
"content": "Mail Fetching Server problem has been fixed"
},
"status": {
"name": "פתוחה"
},
"template": {
"name": "Test for API",
"id": "123123"
},
}
}
const sendToSd = document.getElementById('send');
sendToSd.addEventListener('click', submitData);
var mydata = JSON.parse(jss);
var stringify = JSON.stringify(mydata);
async function submitData(){
const url = 'http://MYURL.COM/api/v3/requests?TECHNICIAN_KEY=SOME-STRING&input_data='+stringify+'&FORMAT=json';
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
console.log('response',response)
}
This fetch works and manages to retrieve the data from the service desk using the same URL and TECHNICIAN_KEY.
// fetch('http://MYURL.COM/api/v3/requests/61627?TECHNICIAN_KEY=SOME-STRING', {
// method: 'GET'
// })
// .then(response => {
// console.log(response);
// return response;
// });
I am making an application that sends emails from a User as described by this article.
Everything is working as expected, except for when I try to include an attachment. The email sends, but without the attachment. I'm not sure what the problem is as I've tried pretty much everything I could find online. I have made sure the file I am sending is properly encoded in base64.
var message = {
"subject": subject,
"hasAttachments":true,
"body": {
"contentType": "Text",
"content": emailBody
},
"toRecipients": toRecipients,
ccRecipients,
bccRecipients
};
function sendMailRequest(access_token, message, uriSend, file, base64, callback){
const attachments = [{
'#odata.type': '#microsoft.graph.fileAttachment',
"contentBytes": base64
"name": "example.jpg"
}];
// Configure the request
var options2 = {
"url": uriSend,
"method": 'POST',
"headers": {
'Authorization': access_token,
'Content-Type': 'application/json'
},
"body": JSON.stringify({
"message": message,
"SaveToSentItems": "true",
"Attachments": attachments
})
}
Attachments go inside the message JSON, not outside of it. This should work:
function sendMailRequest(access_token, message, uriSend, file, base64, callback) {
const attachments = [
{
"#odata.type": "#microsoft.graph.fileAttachment",
"contentBytes": base64
"name": "example.jpg"
}
];
message["attachments"] = attachments;
// Configure the request
var options2 = {
"url": uriSend,
"method": "POST",
"headers": {
"Authorization": access_token,
"Content-Type": "application/json"
},
"body": JSON.stringify({
"message": message,
"SaveToSentItems": "true"
})
}
...
}
I am developing multi-language website using Angularjs and a Web api as backend. I am trying to send RequestedPlatform and RequestedLanguage in the header whenever I make an API call.
Below is my Ajax request call.
$http.post(url,RegistrationData).then(function (response) {
var pageList = response.data.ID;
toastr.success('', 'Registered Succesfully');
$state.go('Registration.OTPVerification', { pageList });
}, function (error) {
toastr.error('', 'Error Occured');
});
updated code
var RegistrationData = {
FirstName: $scope.user.Fname,
LastName: $scope.user.Lname,
Password: $scope.user.password,
Gender: "Male",
DateOfBirth: "2017-04-04",
Nationality: $scope.user.selectedGlobe,
Mobile_CountryCod: "91",
MobileNumber: $scope.user.mobilenumber,
EmailId: $scope.user.email,
Home_Location: $scope.user.homeLocation,
Home_City: $scope.user.homeCity,
Home_Neighbourhood: $scope.user.homeNeighbourhood,
Home_HouseNumber: $scope.user.housenumber,
Home_MainStreet: $scope.user.homemainstreet,
Home_SubStreet: $scope.user.homesubstreet,
Work_Location: $scope.user.worklocation,
Work_City: $scope.user.workcity,
Work_Neighbourhood: $scope.user.workNeighbourhood,
Work_HouseNumber: $scope.user.workhousenumber,
Work_MainStreet: $scope.user.workmainstreet,
Work_SubStreet: $scope.user.worksubstreet
};
var req = {
method: 'POST',
url: url,
data: { RegistrationData: RegistrationData },
headers: {
RequestedPlatform: "Web",
RequestedLanguage: "English"
}
}
$http(req).then(function (response) {
var pageList = response.data.ID;
toastr.success('', 'Registered Succesfully');
$state.go('Registration.OTPVerification', { pageList });
}, function () {
toastr.error('', 'Error Occured');
});
May I get some help to set headers in Ajax. Any help would be appreciated.
you can send headers with headers property of $http
var req = {
method: 'POST',
url: 'http://example.com',
headers: {
'Content-Type': undefined
},
data: { test: 'test' }
}
$http(req).then(function(){...}, function(){...});
and if you want headers for all the requests that can be fully configured by accessing the $httpProvider.defaults.headers configuration object,
Reference
There are few ways and I have posted one which I have been using it for a while. I hope you are looking for the below
$http.post('test', data, {
withCredentials : false,
transformRequest : angular.identity,
headers : {
'Content-Type' : undefined
}
})
I'm building a mobile client to talk to a bot built with microsoft botbuilder through botconnector directline. I want to send things like the unique id of the user speaking with the bot, so my bot can operate on this user. Currently I'm just POSTing to directline, but when I add additional things in the body, my bot can't retrieve it. I'm probably doing something really simple wrong. Would love to get your help on this!
POST code from client:
sendToBot: function(setUpObj, message, returnCallback){
var postURL=baseURL+"/"+setUpObj.conversationId+"/messages"
var postOptions ={
method: 'POST',
headers: {
"Authorization": setUpObj.conversationToken,
"content-type": "application/json"
},
body: JSON.stringify({
"text": message,
"from": {
'address': setUpObj.currentUserUid
}
})
}
fetch(postURL, postOptions)
.then(
(response)=>response.text()
)
.then(
(responseText)=>{
this.getResponse(setUpObj, returnCallback)
}
)
}
and I'm accessing the the currentUserUid on the server by
session.message.from.address
Thanks for you patience.
Have you tried setting the channelData in the json? It's described as "data sent unmodified between client and bot" and can look like:
{
"id": "CuvLPID4kDb|000000000000000004",
"conversationId": "CuvLPID4kDb",
"created": "2017-02-22T21:19:51.0357965Z",
"from": "examplebot",
"text": "Hello!",
"channelData": {
"examplefield": "abc123"
}
}
https://docs.botframework.com/en-us/core-concepts/channeldata/
So in your code it could look like:
var postOptions ={
method: 'POST',
headers: {
"Authorization": setUpObj.conversationToken,
"content-type": "application/json"
},
body: JSON.stringify({
"text": message,
"channelData": {
"from": {
"address": setUpObj.currentUserUid
}
}
})
}