Adyen, create token for credit card without making payment - payment

I know that a token can be created in Adyen for a credit card, when specifying shopperReference and storePaymentMethod to the payment request, together with the desired amount and currency. But I need to do that, without making an actual payment. So I need to save the card, get token for it and in the next step make the payment with that token.
Is that possible?

You can make a payment with the amount of 0. This will tokenize the card without actually charging the card. These zero dollar verifications flow is something established by visa/mc to make sure that card details can be verified vs tokenizing a fake or invalid card.
{
"amount": {
"currency": "USD",
"value": 0
},
"reference": "Your order number",
"paymentMethod": {
"type": "scheme",
"encryptedCardNumber": "test_4111111111111111",
"encryptedExpiryMonth": "test_03",
"encryptedExpiryYear": "test_2030",
"encryptedSecurityCode": "test_737"
},
"merchantAccount": "YOUR_MERCHANT_ACCOUNT"
}
That said, not all banks support zero dollar verification but the vast majority of banks do. For banks that don't support it, Adyen will automatically perform a 1 dollar auth followed by an immediate cancel of that auth.

Related

Github API: determine if user or org

Given the URL https://github.com/foo/bar, I want to be able to get all the repos for foo. If foo is a user, I need to call api.repos.getForUser({username: 'foo'}) and if an org, I'll need to call api.repos.getForOrg({org: 'foo'}).
My problem is: how can I tell if "foo" is an org or a user?
Right now, I "solve" it in the costly way of trying to get an org called "foo", if I got it, I try to get its repos; if I end up getting an exception (I use promises) and if the code of the exception is "404", I assume "foo" is a user, and try to get user repos.
This is obviously inefficient, and has the side effect of adding calls that may trigger rate limit.
Is there an easier way to know whether "foo" is a user or an org?
As we all know, handling exceptions is costly. So instead of trying to get an org and handling the 404, you could instead look at the type property of the response to https://api.github.com/users/<username> in order to determine if the "user" is a user or organization and then proceed accordingly.
For example a call to my GitHub user API https://api.github.com/users/raghav710 returns
{
"login": "raghav710",
...
"type": "User",
...
}
And a call to an organization like https://api.github.com/users/Microsoft returns
{
"login": "Microsoft",
...
"type": "Organization",
...
}
Update: Doing it in a single call
I understand that you are already trying to access a URL https://github.com/<user or organization>/<repo name> and therein trying to get all the repos of that user or organization.
A suggestion is, instead of trying to do a GET on the above link, you could do a GET on https://api.github.com/repos/<user or organization>/<repo name>
For example doing a GET on https://api.github.com/repos/Microsoft/vscode
Gives
{
"id": 41881900,
"name": "vscode",
"full_name": "Microsoft/vscode",
"owner": {
"login": "Microsoft",
"id": 6154722,
...
"type": "Organization",
},
"private": false,
"html_url": "https://github.com/Microsoft/vscode",
...
}
As you can see the familiar type field is available under the owner key. You can use this to decide your next call
So even if there's an API call to differentiate, you'll still need that call to determine whether it's a user or not.
Considering the fact that most repositories should belong to users, why don't you reverse the checks? Try to retrieve the user repository, if that fails get the organization repository.
In addition, I'd cache as much information as necessary. Don't retrieve everything in real time while users use your tool. Many things won't change that often, if they're even able to be changed.

LUIS - understand any person name

we are building a product on LUIS / Microsoft Bot framework and one of the doubt we have is Person Name understanding. The product is set to use by anyone by just signing up to our website. Which means any company who is signing up can have any number of employees with any name obviously.
What we understood is the user entity is not able to recognize all names. We have created a phrase list but as per we know there is a limit to phrase list (10K or even if its 100K) and names in the world can never have a limit. The other way we are thinking is to not train the entity with utterances. However if we have 100s of customers with 1000s of users each, the utterances will not be a good idea in that case.
I do not see any other way of handling this situation. Probably I am missing something here? Anyone faced similar problem and how it is handled?
The worst case would be to create a separate LUIS instance for each customer but that's really a big task to do only because we cant handle names.
As you might already know, a person's name could literally be anything: e.g. an animal, car, month, or color. So, there isn't any definitive way to identify something as a name. The closest you can come is via text analysis parts of speech and either taking a guess or comparing to an existing list. LUIS or any other NLP tool is unlikely to help with this. Here's one approach that might work out better. Try something like Microsoft's Text Analytics cognitive service, with a POST to the Key Phrases endpoint, like this:
https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/keyPhrases
and the body:
{
"documents": [
{
"language": "en-us",
"id": "myid",
"text": "Please book a flight for John Smith at 2:30pm on Wednesday."
}
]
}
That returns:
{
"languageDetection": {
"documents": [
{
"id": "e4263091-2d54-4ab7-b660-d2b393c4a889",
"detectedLanguages": [
{
"name": "English",
"iso6391Name": "en",
"score": 1.0
}
]
}
],
"errors": []
},
"keyPhrases": {
"documents": [
{
"id": "e4263091-2d54-4ab7-b660-d2b393c4a889",
"keyPhrases": [
"John Smith",
"flight"
]
}
],
"errors": []
},
"sentiment": {
"documents": [
{
"id": "e4263091-2d54-4ab7-b660-d2b393c4a889",
"score": 0.5
}
],
"errors": []
}
}
Notice that you get "John Smith" and "flight" back as key phrases. "flight" is definitely not a name, but "John Smith" might be, giving you a better idea of what the name is. Additionally, if you have a database of customer names, you can compare the value to a customer name, either exact or soundex, to increase your confidence in the name.
Sometimes, the services don't give you an 100% answer and you have to be creative with work-arounds. Please see the Text Analytics API docs for more info.
Have asked this question to few MS guys in my local region however it seems there is no way LUIS at moment can identify names.
Its not good as being NLP, it is not able to handle such things :(
I found wit.ai (best so far) in identifying names and IBM Watson is also good upto some level. Lets see how they turn out in future but for now I switched to https://wit.ai

RESTful API design - naming an "activity" resource

When designing the endpoints for an activity resource that provides information on the activity of other resources such as users and organisations we are struggling with naming conventions.
What would be more semantic:
/organisations/activity
/organisations/activity/${activityId}
/users/activity
/users/activity/${activityId}
OR
/activity/users/${activityId}
/activity/users
/activity/organisations/${activityId}
/activity/organisations
There's not a generic answer for this, especially since the mechanisms doing the lookup/retrieval at the other end, and associated back-ends vary so drastically, not to mention the use case purpose and intended application.
That said, assuming for all intents and purposes the "schema" (or ... endpoint convention from the point of view of the end user) was just going to be flat, I have seen many more of the latter activity convention, as that is the actual resource, which is what many applications and APIs are developed around.
I've come to expect the following style of representation from APIs today (how they achieve the referencings and mappings is a different story, but from the point of view of API reference)
-
{
"Activity": [
{
"date": "1970-01-01 08:00:00",
"some_other_resource_reference_uuid": "f1c4a41e-1639-4e35-ba98-e7b169d1c92d",
"user": "b3ababc4-461b-404a-a1a2-83b4ca8c097f",
"uuid": "0ccf1b41-aecf-45f9-a963-178128096c97"
}
],
"Users": [
{
"email": "johnanderson#mycompany.net",
"first": "John",
"last": "Anderson",
"user_preference_1": "somevalue",
"user_property_1": "somevalue",
"uuid": "b3ababc4-461b-404a-a1a2-83b4ca8c097f"
}
]
}
The StackExchange API allows retrieving objects through multiple methods also:
For example, the User type look like this:
-
{
"view_count": 1000,
"user_type": "registered",
"user_id": 9999,
"link": "http://example.stackexchange.com/users/1/example-user",
"profile_image": "https://www.gravatar.com/avatar/a007be5a61f6aa8f3e85ae2fc18dd66e?d=identicon&r=PG",
"display_name": "Example User"
}
And on the Question type, the same user is shown underneath the owner object :
-
{
"owner": {
"user_id": 9999,
"user_type": "registered",
"profile_image": "https://www.gravatar.com/avatar/a007be5a61f6aa8f3e85ae2fc18dd66e?d=identicon&r=PG",
"display_name": "Example User",
"link": "https://example.stackexchange.com/users/1/example-user"
},
"is_answered": false,
"view_count": 31415,
"favorite_count": 1,
"down_vote_count": 2,
"up_vote_count": 3,
"answer_count": 0,
"score": 1,
"last_activity_date": 1494871135,
"creation_date": 1494827935,
"last_edit_date": 1494896335,
"question_id": 1234,
"link": "https://example.stackexchange.com/questions/1234/an-example-post-title",
"title": "An example post title",
"body": "An example post body"
}
On the Posts Type reference (Using this as a separate example because there is only a handful of methods to reach this type), you'll see an example down the bottom :
Methods That Return This Type
  posts
  posts/{ids}
  users/{ids}/posts 2.2
  me/posts 2.2
So whilst you can access resources (or "types" as it is on StackExchange), through a number of ways including filters and complex queries, there still exists the ability to see the desired resource through a number of more direct transparent URI conventions.
Different applications will clearly have different requirements. For example, the Gmail API is user based all the way - this makes sense from a users point of view given that in the context of the authenticated credential, you're separating one users objects from another.
This doesn't mean google uses the same convention for all of their APIs, their Activities API resource is all about the activity
Even looking at the Twitter API, there is a Direct Messages endpoint resource that has sender and receiver objects within.
I've not seen many API's at all that are limited to accessing resources purely via a user endpoint, unless the situation obviously calls for it, i.e. the Gmail example above.
Regardless of how flexible a REST API can be, the minimum I have come to expect is that some kind of Activity, location, physical object, or other entity is usually it's own resource, and the user association is plugged in and referenced at various degrees of flexibility (at a minimum, the example given at the top of this post).
It should be pointed out that in a true REST api the uri holds no meaning. It's the link relationships from your organizations and users resources that matter.
Clients should just discover those urls, and should also adapt to the new situation if you decide that you want a different url structure after all.
That being said, it's nice to have a logical structure for this type of thing. However, either is fine. You're asking for an opinion, there is not really a standard or best practice. That said, I would choose option #1.

What are the possible kinds of webhooks Trello can send? What attributes come in each?

I'm developing an app that is tightly integrated with Trello and uses Trello webhooks for a lot of things. However, I can't find anywhere in Trello's developer documentation what are the "actions" that may trigger a webhook and what data will come in each of these.
In fact, in my experience, the data that comes with each webhook is kinda random. For example, while most webhooks contain the shortLink of the card which is being the target of some action, some do not, in a totally unpredictable way. Also, creating cards from checklists doesn't seem to trigger the same webhook that is triggered when a card is created normally, and so on.
So, is that documented somewhere?
After fighting against these issues and my raw memory of what data should come in each webhook, along with the name of each different action, I decided to document this myself and released it as a (constantly updating as I find new webhooks out there) set of JSON files showing samples of the data each webhook will send to your endpoint:
https://github.com/fiatjaf/trello-webhooks
For example, when a board is closed, a webhook will be sent with
{
"id": "55d7232fc3597726f3e13ddf",
"idMemberCreator": "50e853a3a98492ed05002257",
"data": {
"old": {
"closed": false
},
"board": {
"shortLink": "V50D5SXr",
"id": "55af0b659f5c12edf972ac2e",
"closed": true,
"name": "Communal Website"
}
},
"type": "updateBoard",
"date": "2015-08-21T13:10:07.216Z",
"memberCreator": {
"username": "fiatjaf",
"fullName": "fiatjaf",
"avatarHash": "d2f9f8c8995019e2d3fda00f45d939b8",
"id": "50e853a3a98492ed05002257",
"initials": "F"
}
}
In fact, what comes is a JSON object like {"model": ..., "action": ... the data you see up there...}, but I've removed these for the sake o brevity and I'm showing only what comes inside the "action" key.
based on #flatjaf's repo, I gathered and summarized all* the webhooks types.
addAttachmentToCard
addChecklistToCard
addLabelToCard
addMemberToBoard
addMemberToCard
commentCard
convertToCardFromCheckItem
copyCard
createCard
createCheckItem
createLabel
createList
deleteAttachmentFromCard
deleteCard
deleteCheckItem
deleteComment
deleteLabel
emailCard
moveCardFromBoard
moveCardToBoard
moveListFromBoard
moveListToBoard
removeChecklistFromCard
removeLabelFromCard
removeMemberFromBoard
removeMemberFromCard
updateBoard
updateCard
updateCheckItem
updateCheckItemStateOnCard
updateChecklist
updateComment
updateLabel
updateList
hope it helps!
*I don't know if that list includes all the available webhooks types because as i already said, it's based on flatjaf's repo created 2 years ago

How do I get the number of Followers gained and lost during a selected time range from Instagram API?

I need to get number of Followers gained and lost or just the total followers during a selected time range.
For example:
if I send a request to: https://api.instagram.com/v1/users/3/
I will get this Json:
{
"data":
{
"username": "kevin",
"bio": "CEO & Co-founder of Instagram",
"website": "",
"profile_picture": "https://instagramimages-a.akamaihd.net/profiles/profile_3_75sq_1325536697.jpg",
"full_name": "Kevin Systrom",
"counts": {
"media": 1419,
"followed_by": 1138347,
"follows": 643
},
"id": "3"
}
But I can't get the "followed_by" for a select time range
I read the Instagram api documentation and I can't find anywhere a Endpoint to do a request that I want.
in MEDIA I can pass MIN_TIMESTAMP and MAX_TIMESTAMP as parameters, but I am not looking for medias, I am looking for the number of followers.
I know It's possible because there is a website https://minter.io that gets every information since the beginning of the account.
PS: I already have the Authentication with OAuth 2.0
There is no API to do this, I think you have to keep a track of your follower count and update it every day. Setup a cron job to do this via API.
I just tried minter.io, I dont know how they show followers from day 1, I can definitely tell u it is fake and not accurate, I had about 1400 followers at some point and I removed them few months ago, so its back to 200 something, and minter.io does not show this at all. I think they just show a fake linear graph for historical data and going forward they keep a track of followers every day.
It is possible to use the field 'followers_count' on the User node to get a starting point. This gives the total number of followers at the time of the request. From there you could calculate a running total by subtracting the daily follower count from the Insights api that you mention.
Get current follower count:
curl -i -X GET "https://graph.facebook.com/v8/<user id>?fields=followers_count&access_token=EAACwX..."
https://developers.facebook.com/docs/instagram-api/reference/user
Get new followers for single day:
curl -i -X GET "https://graph.facebook.com/v8/<user id>/insights?metric=follower_count&period=day&since=2020-10-5T07:00:01&until=2020-10-06T07:00:00
https://developers.facebook.com/docs/instagram-api/reference/user/insights

Resources