I am using paypal REST API to test out express checkout on sandbox environment.
Everything works fine except one thing: order description area is rather empty: no summs, no individual item information, no total order sum amount - I can see only my dummy description" regardless that I do pass order summ amount.
I am passing payment information similar to one used in the example apps:
var ppPayment = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {},
"transactions": [{
"amount": {
"currency": "EUR",
"details": {
"subtotal": 0
}
}
}]
};
ppPayment.transactions[0].amount.total = params.req_order_amount;
ppPayment.redirect_urls.return_url = "http://xxxxxxxxx/confirm?order_id=" + order_id;
ppPayment.redirect_urls.cancel_url = "http://xxxxxxxxx/cancel?order_id" + order_id;
ppPayment.transactions[0].description = "Dummy description";
ppPayment.transactions[0].amount.details.subtotal = params.req_order_amount;
What lines should I add to the payment.create call to user to be able to see the description like displayed here ?
Follow the API
PayPal REST API Reference
You need to create transaction object inside which item_list object consisting of items. Lets name one item object or and go by your screenshot :
paypalItem.name
..until 6. : See API for item object. Some fields only exist in invoice_item object
..until 10. : See API for Invoice object
Good luck
So the explicit answer will be :
ppPayment.transactions[0].amount.total = params.req_order_amount;
ppPayment.redirect_urls.return_url = "http://xxxxxxxxx/confirm?order_id=" + order_id;
ppPayment.redirect_urls.cancel_url = "http://xxxxxxxxx/cancel?order_id" + order_id;
ppPayment.transactions[0].description = "Dummy description";
ppPayment.transactions[0].amount.details.subtotal = params.req_order_amount;
ppPayment.transactions[0].item_list =
{
items: [{quantity: 1, name: 'My stuff', price: params.req_order_amount, currency: "USD"}]
};
Related
On my current project in node.js (where I'm a beginner), there is a source of data that can be queried (WEB API) but is restricted to a certain amount of entries from a given position. It is not possible to request the full record set (eg. 1000 entries) you only can select a maximum of 50 Entries from an offset.
The function to get the data is as follow:
let myResponseData = await client.getData({userId: myId, first: 50, after: cursor});
where userId is an authentication, first is the number of records I want to request (0-50), and after is the cursor
the response looks like this:
{
"totalRecords": 1000,
"page_info": {
"has_next_page": true,
"end_cursor": "this is some random string"
},
"data": [
{
"id:" 1,
"name": "Name1"
},
{
"id:" 2,
"name": "Name2"
}
]
}
My current progress in fetching all data is, that i've already constructed a function that reads all pages from the data source like this:
let myResponseData = await client.getData({userId: myId});
let hasNextPage = myResponseData.page_info.next_page;
let cursor = myResponseData.page_info.cursor;
while(hasNextPage){
console.log('next...' + cursor);
myResponseData= await client.getData({ userId: myId, first: 50, after: cursor});
hasNextPage = myResponseData.page_info.next_page;
cursor = myResponseData.page_info.cursor;
myFunctionToJoinData(myResponseData); //Here i need help
}
This works so far since the console logs the next + random string.
My goal is to end up with a json data object like in the request, but having all the entries from all queries
How can this be achieved?
I'm using Node.js to make a Axios request to the Vimeo API.
I'm kind of a Noob with Json but I'd like to understand. I made a call to Vimeo with a filter of name, so I get an "array of objects" (I hope that name is correct ) it looks like this below:
[{ name: 'A Personalized Goal for Anthony' },
{ name: 'Flow access & overview' },
{ name: 'Welcome - 2018 Conference' },
{ name: 'Dropout Video' } ] }
This is simply the names of the videos, however I need to add two keys value pairs with the same value as the name value for a dropdown menu, so it looks like this below:
[{ name: 'A Personalized Goal for Anthony',
"text": "A Personalized Goal for Anthony",
"value": "A Personalized Goal for Anthony" },
{ name: 'Flow access & overview',
"text": "Flow access & overview"
"value": "Flow access & overview" },
{ name: 'Welcome - 2018 Conference',
"text": "Welcome - 2018 Conference"
"value": "Welcome - 2018 Conference" },
{ name: 'Dropout Video',
"text": "Welcome - 2018 Conference"
"value": "Welcome - 2018 Conference" }]
My app needs the keys "Text" and "Value" for a dropdown menu in order to process the response from the user.
I'm not sure why { name: 'Dropout Video'}, isn't formatted like this {"name":"Dropout Video"},
Is there a way in Node.js to add or duplicate an array using map or push using the same name value while also doing a foreach to this array which reflects the name but with two additional key value pairs with the same Value as the key Name?
This is a dynamic Object as well so when the request is called again it could have many more than just 4 video names returned.
My goal is to add numerous Videos to a Vimeo Album that I want to make the request to, then my app ( Slack chatbot ) then returns a list of options via a drop down menu for the users consideration so that I'm able to see which Name or title they selected and thus want more information on.
Thank you so much any help here. I wish Vimeo had a Text and Value field so I could just filter that instead but then it wouldn't be fun :)
You could map through your result, so, for example, after you get the result:
const movies = [{ name: 'A Personalized Goal for Anthony' },
{ name: 'Flow access & overview' },
{ name: 'Welcome - 2018 Conference' },
{ name: 'Dropout Video' }];
You could map it to add the other two properties to each one of your objects, the advantage is that you are not mutating your results.
const mappedMovies = movies.map(movie => {
return {
name: movie.name,
text: movie.name,
value: movie.name
}
);
In that way, you will have the list of objects with the format that you want, now if you need it in json format you could do:
const JSONString = JSON.stringify(mappedMovies);
Objects are references, so you could just loop through your objects and add the keys.
const videos = [
{ name: 'A Personalized Goal for Anthony' },
{ name: 'Flow access & overview' },
{ name: 'Welcome - 2018 Conference' },
{ name: 'Dropout Video' }
]
for (video of videos) {
video.text = video.name
video.value = video.name
}
console.log(videos)
Welcome to SO Kevin,
It looks like you almost provided the answer yourself already...
To get the resulting array you can map through the object and add keys as required:
const slackVideos = videos.map(function (item, label) {
return {
...item, //this ensures all original keys are available, using the ES6 destructuring
text: item.name,
value: item.value,
}
});
Assuming videos is the object received from vimeo, slackVideos will now contain your aditional text & value keys; both containing the name key from the original vimeo object.
I am trying to do a load test on a chat bot that I deployed on Microsoft Azure bot service, and I am following the blog post on here: https://blog.botframework.com/2017/06/19/load-testing-a-bot/,
I am able to finish the first step, I am able to get auth token and get Mock channel, but for the last step:
it states:
{
"type": "message",
"id": <GUID>,
"channelId" : "test",
"conversation": { "id": <CONVERSATION ID> },
"from": { "id": <USER ID> },
"recipient": { "id": <BOT HANDLE> },
"serviceUrl": <SEE BELOW>
}
I know service URL is the endpoint of the mock channel. but for all other Id, I don't know where can I get it?
Can anyone help me with this? give me some guidance on how to get all those ids?
Thanks a lot.
Node.js
You can get all these by inspecting an activity from your bot, then plugging in valid values in your mock channel for sending the activity. You can get these values by setting a breakpoint at any other point in your process that sends/receives or handles an activity. Just inspect the values and use them accordingly. Remember to do things like switch the from and recipient where needed.
I know you are asking for JavaScript but this is an example of how I am constructing and activity in my mock channel using c#:
Activity a = new Activity
{
Type = ActivityTypes.Message,
Id = "9dn3fa6lh4hd9dn3fa6lh4hd",
ChannelId = Microsoft.Bot.Builder.Dialogs.ChannelIds.Console,
Conversation = new ConversationAccount(id: "9dn3fa6lh4hd"),
From = new ChannelAccount(id: "user", name: "username"),
Recipient = new ChannelAccount(id: "bot", name: "botname"),
Text = "Mock Channel",
ServiceUrl = #"http://localhost:55086/api/values",
MembersAdded = new List<ChannelAccount>(),
MembersRemoved = new List<ChannelAccount>(),
Locale = "en-US",
Attachments = new List<Attachment>(),
ReplyToId = "nii4344blg42",
TextFormat = "plain",
Timestamp = DateTime.Now,
ChannelData = JsonConvert.SerializeObject(new { clientActivityId = "1506483656068.11949484894092266.2" })
};
I''m really new to Node but I currently have a NodeJS / Express open source CMS and would like to output some API data for an app that I am working. Forgive me if I'm not using the correct terminology or whatnot, this is new to me.
What I currently have are two collections, locations and tours. The CMS allows me to create a relationship between the two. This simply stores an array of ObjectID's in the locations record for each associated tour record.
What I want to do is take my API output code (below) and have it output the entire tours array, complete with all the fields (title, description, etc), in with each location record. Currently it only outputs an array of the ID's.
Here is my current code:
var async = require('async'),
landmark = require('keystone');
var Location = keystone.list('Location'),
Tour = keystone.list('Tour');
/**
* List Locations
*/
exports.list = function(req, res) {
Location.model.find(function(err, items) {
if (err) return res.apiError('database error', err);
res.apiResponse({
locations: items
});
});
}
/**
* Get Location by ID
*/
exports.get = function(req, res) {
Location.model.findById(req.params.id).exec(function(err, item) {
if (err) return res.apiError('database error', err);
if (!item) return res.apiError('not found');
res.apiResponse({
location: item
});
});
}
Current API output (truncated):
{
"locations": [
{
"_id": "53a47997ebe91d8a4a26d251",
"slug": "test-location",
"lastModified": "2014-06-20T20:19:14.484Z",
"commonName": "test location",
"__v": 3,
"url": "",
"tours": [
"53a47963ebe91d8a4a26d250"
],
"images": []
}
]
}
What I'm looking for:
{
"locations": [
{
"_id": "53a47997ebe91d8a4a26d251",
"slug": "test-location",
"lastModified": "2014-06-20T20:19:14.484Z",
"commonName": "test location",
"__v": 3,
"url": "",
"tours": [
{
"_id": "53a47963ebe91d8a4a26d250",
"title": "my test tour title",
"url": "url_to_audio_file"
}
],
"images": []
}
]
}
Anyone know if this is possible? Any help would be appreciated! Thanks!
It looks like you have setup your Location model to have a reference to the Tours, defined as an array of Tours. This means that when you store the Tour within your Location, you're not storing the data that represents that Tour, but instead an ID that references the Tour. When you perform the find operation, you're seeing that in the response that you send back to the client.
If this is the case, then you might want to take a look at Mongoose's populate function. This will take those references and populate them fully with the data that they contain.
So for instance, you can change your query to the following:
Location.model.find().populate('tours').exec(function(err, items) {
// items should now contain fully populated tours
}
Let me know if this isn't what you mean and I can try to help further.
The solution provided by #dylants is absolutely correct. However, for it to work you need to have tours declared as a Types.Relationship field in your Location list with the ref option set to Tour.
Check out the Keystone docs on Relationship Fields.
I included the many: true option in my example below, because I assumed this is a one-to-many relationship. If it isn't, you can discard it.
var keystone = require('keystone'),
Location = keystone.list('Location');
Location.add({
...
tours: { type: Types.Relationship, ref: 'Tour', many: true },
...
});
The List.relationship() method you mentioned is meant to be used only if you want a list of related documents to automatically appear in the Keystone Admin UI, and not to establish the actual relationship.
Hope this helps.
So I have the code below which is the front end on a node.js app which pulls Instagram posts with a certain hashtag. Right now it posts all over the world. Is there a way to limit the radius on the posts and if possible, limit to the window that is currently visible to the user? I'm using the Instagram Real Time tag subscription.
function initialize() {
var styles = [{
"featureType": "landscape",
"stylers": [{
"color": "#808080"
}, {
"visibility": "simplified"
}]
}, {
"featureType": "administrative",
"elementType": "labels.text.fill",
"stylers": [{
"weight": 0.1
}, {
"lightness": 100
}, {
"visibility": "off"
}]
}, {}];
var mapOptions = {
center: new google.maps.LatLng(32.71533, -117.15726),
zoom: 4,
scrollwheel: false,
scaleControl: true,
styles: styles
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
var socket = io.connect();
socket.on('photo', function (data) {
var icon = {
url: data.img, // url
size: new google.maps.Size(80, 80), // size
};
marker = new google.maps.Marker({
position: new google.maps.LatLng(data.lat, data.long),
draggable: true,
animation: google.maps.Animation.DROP,
icon: icon,
map: map,
title: data.caption
});
});
// Try HTML5 geolocation
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(pos);
}, function () {
handleNoGeolocation(true);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation(false);
}
}
function handleNoGeolocation(errorFlag) {
if (errorFlag) {
var content = 'Error: The Geolocation service failed.';
} else {
var content = 'Error: Your browser doesn\'t support geolocation.';
}
var options = {
map: map,
position: new google.maps.LatLng(60, 105),
content: content
};
var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}
// Finally, call map
google.maps.event.addDomListener(window, 'load', initialize);
As far as I'm aware, there is no way to combine endpoints, ie Geographies and Tags into one search. I would think you have 2 options and both will be fairly labour intensive on your end, depending on the popularity of the hashtag/s, and the radius of your geography. I'm interested to see more opinions on this.
Option 1
Keep your realtime Tag subscription
Process the results manually to filter by the location information provided with each photo
Example from doc:
...
"location": {
"latitude": 37.780885099999999,`
"id": "514276",
"longitude": -122.3948632,
"name": "Instagram"
}
...
Pros:
You've already got a tag subscription.
You are not restricted to any radius
Cons:
Figuring out what photos fall into your desired radius sounds pretty complicated.
Option 2
Create a realtime Geography subscription
Process the results manually to filter by the tag information provided with each photo
Example from doc:
...
"tags": ["expobar"],
...
Pros:
Manually filtering by tag is likely going to be much easier
Cons:
You're restricted to a max radius of 5000m in your geography subscription
UPDATED ANSWER:
I think you're confused between Locations and Geographies, what you describe in your last comment (thinking out loud) is exactly what I was trying to suggest in option 2. Locations are places where you can tag a photo when uploading, for instance 'Starbucks Downtown', and are not terribly useful IMO, whereas Geographies use latitude, longitude & a radius, and are perfect for what you want to achieve - finding and displaying photos taken in close proximity, no matter where the user is.
Check out the "Geography Subscriptions" section of http://instagram.com/developer/realtime/
Creating a Geography Subscription is very similar to a Tag subscription so it shouldn't take much to tinker with what you've already got. As you guessed, you will just need to use a javascript library to grab the users lat/longitude first
The Instagram real-time API has a Geography Subscription as per the documentation which allows you to specify a position and a radius.
To create a subscription to a geography, specify a center latitude and longitude and a radius of the area you'd like to capture around that point (maximum radius is 5000 meters).
We don't really know from your question where the issue is, so let's hope this helps.