I'm trying to construct, sign and broadcast a transaction on the tezos blockchain.
Here is my current code
const rpcUrl = "someTestnetRPC";
//generate private key
// get information about the most recent block
//reveal status
//reveal operation
//can't quite figure out how to make this reveal transaction, this is the data
data: {
branch: mostRecentBlock,
contents: [
{
kind: "reveal",
fee: "1",
public_key: TezBridgeCrypto.crypto
.getKeyFromSeed(random_seed)
.getPublicKey(),
gas_limit: "10500",
storage_limit: "0",
},
],
}
//I don't know the url to send this request to.
let binaryFromRpc = await axios({
method: "post",
url: `${rpcUrl}/chains/main/blocks/head/helpers/forge/operations`,
data: {
branch: mostRecentBlock,
contents: [
{
kind: "transaction",
source: sourceAddr,
fee: "1",
counter: (Number(counter.data) + 1).toString(),
gas_limit: "10500",
storage_limit: "0",
amount: "1",
destination: "tz1biFoRp3n9X2r4o3sgcqRLkXAXce7hpPLp",
},
],
},
headers: {
"Content-type": "application/json",
},
});
const signature = Buffer.from(
ed25519.Sign(
Buffer.from(await blake2b(`0x03${binaryFromRpc.data}`, 256), "utf-8"),
Buffer.from(random_seed, "utf-8")
)
).toString("hex");
const injectionData = `${binaryFromRpc.data}${signature}`;
await axios({
method: "post",
url: `${rpcUrl}/injection/operation?chain=test&async`,
data: injectionData,
headers: {
"Content-type": "application/json",
},
});
When I send this request the final injection goes through, no failure message, no content in the returned data and I can't quite figure out what I'm doing wrong.
Related
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
I am trying to implement Paytm integration in react native. but I am getting this error = "invalid : syntax of callback URL is incorrect. sample callback URL is as 'https://merchant.com/calback/". please tell me whats wrong with my code
here is my code
call_api = () => {
fetch("https://XXXXXXXXXXXXXXX", {
method: "POST",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
},
body: JSON.stringify([
{
mobile_no: "XXXXXx",
user_id: "XX",
patient_name: "XXXx",
},
]),
})
.then((returnValue) => returnValue.json())
.then((response) => {
console.log("this checksum api esponse" + JSON.stringify(response));
this.setState({ order_id: response[0].data.order_id });
this.setState({ checksum: response[0].data.checksumhash });
this.pay();
});
};
pay = () => {
const details = {
// mode: "Staging", // 'Staging' or 'Production'
mode: "Production",
MID: "XXXXXXXXXXXXXXX",
INDUSTRY_TYPE_ID: "Retail",
WEBSITE: "APPSTAGING",
CHANNEL_ID: "WAP",
TXN_AMOUNT: "1", // String
ORDER_ID: this.state.order_id, // String
// EMAIL: email, // String
// MOBILE_NO: mobile, // String
CUST_ID: "CUSTOMER_1", // String
CHECKSUMHASH: `${this.state.checksum}`, //From your server using PayTM Checksum Utility
// CALLBACK_URL:
// "https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=" +
// `${this.state.order_id}`,
CALLBACK_URL: `https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=<${this.state.order_id}>`,
};
Paytm.startPayment(details);
console.log(details);
};
In callbackUrl param, you need to pass your website URL where you want to get the response. If you don't have your own callback Url, you can use Paytm's static callback URL which is mentioned in the documentation of react native on Developer Portal. It should be same as you have sent in your const details
I have the following submit method:
submitForm(e) {
e.preventDefault();
var token = document.getElementsByTagName("meta")[0].getAttribute("content");
var form = document.querySelector('.form');
if(navigator.onLine && JSON.parse(localStorage.getItem('candidates'))) {
axios({
url: '/save-data',
method: 'POST',
contentType: 'application/json',
data: {
"candidates": localStorage.getItem('candidates')
},
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': token
}
}).then(function(response) {
console.log(response);
})
.catch(function(e){
console.log(e);
});
}
else {
var singleCandidate = serialize(form, { hash: true });
var fromStorage = localStorage.getItem("candidates");
if (fromStorage) {
var parsedFromStorage = JSON.parse(fromStorage)
parsedFromStorage.push(singleCandidate)
localStorage.setItem("candidates", JSON.stringify(parsedFromStorage));
}
else {
localStorage.setItem("candidates", JSON.stringify([singleCandidate]));
}
}
}
it loads data from local storage and submits it if there is data and connection at the same time.
However there is something that doesn't work with the following:
data: {
"candidates": localStorage.getItem('candidates')
},
if I do:
data: {
"candidates": [
{
"name": this.state.firstName,
"email": this.state.email,
"university": this.state.university,
"degree": this.state.degree
}
]
},
I get a positive response, form data gets submitted. However I have to submit this value (localStorage.getItem('candidates')) and when I do that I get the following:
Should "localStorage.getItem('candidates')" be changed to another format?
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 have written the following code to insert records in a list which is contained in the host site.
var projectItems = [
{ Title: "SharePoint", ProjectDescription: "SharePoint 2013", ProjectManager: "Test0" },
{ Title: "Lync", ProjectDescription: "Lync 2013", ProjectManager: "Test1" },
{ Title: "Exchange", ProjectDescription: "Exchange 2013", ProjectManager: "Test2" }
];
function insertListItems(items) {
for (var item in items) {
var inputData = new Object();
var type = new Object();
type.type = getListItemType(listName);
inputData.__metadata = type;
for (var prop in items[item]) {
inputData[prop] = items[item][prop];
}
console.log(JSON.stringify(inputData));
console.log(url);
var obj = {
url: url,
type: "POST",
contentType: "application/json; odata=verbose",
data: JSON.stringify(inputData),
headers: { "Accept": "application/json; odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() },
success: function (successData) { console.log("insert successful"); },
error: function (errorData) { console.log("insert failed") }
};
if (parent) {
var exec = new SP.RequestExecutor(appWebUrl);
exec.executeAsync(obj);
} else {
$.ajax(obj);
}
}
}
insertListItems(projectItems);
when I run it it prints
{"__metadata":{"type":"SP.Data.ProjectsListItem"},"Title":"SharePoint","ProjectDescription":"SharePoint 2013","ProjectManager":"Test0"}
http://app-e9f4c136adfd88.abhiapps.com/SPAppHelper/_api/SP.AppContextSite(#target)/web/lists/getbytitle('Projects')/items?#target='http://dev.abhi.com'
{"__metadata":{"type":"SP.Data.ProjectsListItem"},"Title":"Lync","ProjectDescription":"Lync 2013","ProjectManager":"Test1"}
http://app-e9f4c136adfd88.abhiapps.com/SPAppHelper/_api/SP.AppContextSite(#target)/web/lists/getbytitle('Projects')/items?#target='http://dev.abhi.com'
{"__metadata":{"type":"SP.Data.ProjectsListItem"},"Title":"Exchange","ProjectDescription":"Exchange 2013","ProjectManager":"Test2"}
http://app-e9f4c136adfd88.abhiapps.com/SPAppHelper/_api/SP.AppContextSite(#target)/web/lists/getbytitle('Projects')/items?#target='http://dev.abhi.com'
insert successful
insert successful
insert successful
I have multiple problems with this source code
No records actually get inserted. but no errors are thrown.
How do I ensure that in my main method... the code which comes after the insertListItems method is only executed when all the 3 records have been inserted successfully. currently because of the async nature of javascript the flow moves forward even before anything has been inserted.
I googled on option 2 and found that jquery has a promise and deffered object pattern but it seems SP.RequestExecutor.executeAsync does not follow that and throws an error on the "done" method saying no such method is supported.
This is how my lists looks
Replace your obj with this:
....
method: "POST",
body: JSON.stringify(inputData),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
}
....
....