How to handle dispute event in webhook? - javascript

I'm a amateur php developer. I accepts stripe payments in my php website as one-time payments. I've integrated it correctly according to stripe website docs. (https://stripe.com/docs/payments/checkout/one-time#create-checkout-session). I'm getting checkout.session.created event from stripe webhook and I store it in my database as a completed payment. ( Advise me if I'm doing wrong ). This is the sample event data that stripe triggers as checkout.session.completed event.
{
"id": "evt_123",
"object": "event",
"api_version": "2019-03-14",
"created": 1561420781,
"data": {
"object": {
"id": "cs_test_123",
"object": "checkout.session",
"billing_address_collection": null,
"cancel_url": "https://example.com/cancel",
"client_reference_id": null,
"customer": "cus_123",
"customer_email": null,
"display_items": [],
"mode": "setup",
"setup_intent": "seti_1123",
"submit_type": null,
"subscription": null,
"success_url": "https://example.com/success"
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}
But I need to handle webhook events for disputes. If a paid user opens dispute, I need to know it. How stripe notifies me it via webhook ? If stripe notifies me, How do I find parent payment ?. Sorry for my bad English.

webbhook is a url provided by you to stripe, on which stripe will be sending data, just like how you send data from a form to your site.
You should follow stripe docs for it, https://stripe.com/docs/payments/handling-payment-events and https://stripe.com/docs/webhooks

You should ideally edit your original post to include the 'answer' you added yesterday - and remove that answer - as Stackoverflow isn't the same as a forum
The Dispute object contains a Payment Intent ID and you can list / 'retrieve' the Checkout Session for that Payment Intent ID, so that's how you get it.

Related

how to get the users/me relation in strapi v4

i'va added a relation my user but when i try to query it i can see it even with the populate deep plug in
when i add a normal field, there is no problem but the relation is impossible to see.
here is the user table in the dashboard :
here is the query i'm doing:
http://localhost:1337/api/users/me?populate=deep
end the response i get :
{
"id": 1,
"username": "testAdmin",
"email": "testadmin#gmail.com",
"provider": "local",
"confirmed": true,
"blocked": false,
"createdAt": "2023-01-27T20:38:35.624Z",
"updatedAt": "2023-01-28T17:07:51.151Z",
"test": "test"
}
i've seen the same issue in a github repo but it's fair old and i've not seen any update
any idea ?

How to obtain a client-side token without using Stripe's UI layer?

I have the following php page that works fine:
<html>
<head>
<script src="https://checkout.stripe.com/checkout.js"></script>
<script>
var handler = StripeCheckout.configure({
key: '<?=$stripePublicKey?>',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
// You can access the token ID with `token.id`.
// Get the token ID to your server-side code for use.
console.log("token.id: " + token.id);
console.log("token: " + token);
}
});
function init(){
document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'TruckerCert',
description: 'Buy Certs',
amount: 2000
});
e.preventDefault();
});
// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});
}
</script>
</head>
<body onload="init()">
<h1>Stripe Token Test</h1>
<button id="customButton">Purchase</button>
</body>
</html>
It works and produces the following JSON:
{
"id": "tok_1E255j2*****wC135im",
"object": "token",
"card": {
"id": "card_1E255j2H1*****RGS4Kqc",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": null,
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 12,
"exp_year": 2021,
"fingerprint": "3nk5B*****29xV",
"funding": "unknown",
"last4": "1111",
"metadata": {
},
"name": "her*******#gmail.com",
"tokenization_method": null,
"type": "Visa"
},
"client_ip": "67.***.***.17",
"created": 1549754315,
"email": "her********#gmail.com",
"livemode": false,
"type": "card",
"used": false
}
So that is all as expected. The problem is, the only way I can find to submit my credit card # and exp date and receive back the JSON is by going through their UI. For example, when I click my customButton, this dialog appears:
I don't want to use their cc form. I have my own CC form. I want to use my own form, send an ajax request to Stripe's API endpoint, and receive back the JSON just as above. I have combed through Stripe's online docs for an hour and can't find any way to do this.
How is it done?
The product you mentioned is called Stripe Checkout and lets you collect card details securely without having to build your own payment form.
Since you mentioned having your payment form already though you should instead look into Stripe Elements. This lets you design and style your own payment form while still meeting the lowest level of PCI compliance, SAQ A, as documented here.
You can still multiple examples of payments form and the corresponding code here: https://stripe.github.io/elements-examples/
Stripe.js version 2 supported this. As of the time of writing this you can see the old documentation here. If I had to guess Stripe.js v2 will be depreciated fully and removed from use at some point. So although you can use it with some hassle, it is depreciated, and you have to ask yourself if it's worth the risk of having to rewrite in the future. Since you are building it currently, I would just use the latest technology.
Also, according to Stripe's page on PCI compliance:
If you continue to use Stripe.js v2, you’ll be required to upload your SAQ A-EP annually to prove your business is PCI compliant.
Overall using Stripe's Elements system is the way to go. There is no way you can touch the user's payment information, which makes it as secure as possible. Much less possibility of you messing up in your code vs an AJAX call. What if you accidentally send the AJAX call to your own server? You are in violation of PCI compliance then.
Stripe Elements also provides a LOT of customization in terms of styling. You should be able to design it in a way that integrates with your existing form pretty easily.

Vue dynamic form with dynamic feedback

I have a case where I want to create a form in Vue based on an external JSON response dictating the form fields and feedback based on the choices made in the form.
This is a snippet of the JSON question-format I had in mind:
{
"questionId": 23,
"questionText": "Do you need help completing this questionnaire?",
"questionName": "need-help",
"answerType": "radio",
"answers": [
{
"id": 1,
"answerText": "Yes",
"answerFeedbackType": "error",
"answerFeedback": "At the moment we cannot complete the intake procedure. Please contact us by sending an e-mail and we'll help you towards your subscription."
},
{
"id": 2,
"answerText": "No"
}
]
},
At the moment I pass this data to a Question component where I have props for each key of the data object. This is loaded from my Form component where I load in the JSON and loop though all questions. How should I go about determining whether to show a notification when the user clicks on an option where there is a feedbacktype of 'error' and also detect whether the user has actually filled in every field?

Facebook Graph API - get page feed + full event info?

Is it possible to, in 1 request, get the feed of a page but with the full event info?
As it is now, if a shared event is posted, you only get back the link to that event, no picture or title:
{
"id": "xxx",
"from": {
"category": "Community",
"name": "xxx",
"id": "xxx"
},
"story": "xxx shared xxx's event.",
"link": "https://www.facebook.com/events/xxx/",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/xxx/posts/xxx"
},
{
"name": "Like",
"link": "https://www.facebook.com/xxx/posts/xxx"
}
],
"privacy": {
"value": ""
},
"type": "link",
"status_type": "shared_story",
"application": {
"name": "Links",
"id": "xxx"
},
"created_time": "2013-06-19T10:05:50+0000",
"updated_time": "2013-06-19T10:05:50+0000",
"likes": {
"data": [
{
"name": "xxx",
"id": "xxx"
}
],
"count": 1
}
}
If I understand correctly, you need to retrieve the events but you want to do it all at once with the feed because you want to retrieve the information on the feed anyway.
Before doing that, you must know that the feed doesn't contain all the events.... Once created, a link to the event is automatically shared on the page feed. It is only a reference, which can then be hidden. The event won't be displayed on the feed anymore even if it still exists.
Requesting two different objects at the same time
So, the feed doesn't have the events information and the events and posts (feed) are stored on 2 different tables. Therefore, you need to get the events independently from the feed:
The feed /PAGE_ID/feed
The events /PAGE_ID/events
And, as you wanted, Graph API allows you to do this in only one request:
/PAGE_ID?fields=feed,events
Additional fields
Note that either feed or events accept the limit and fields parameters. For example, events can be specified by:
events.limit(100).fields(location,name,owner,description,updated_time,venue)
Possible fields are given in the doc.
There is no way to get the "full info" at once. You will have to specify each field in the request. So, don't get the "full info", but just the information you really need.
There is a post from Facebook addressing this scenario using multi-queries and FQL (Facebook Query Language). This will allow you to make multiple FQL calls in one request.
https://developers.facebook.com/docs/technical-guides/fql/#multi

get facebook users data of his reads in washington post or yahoo reader

Is there any way to get the reads of a user in washington post or yahoo reader?
I have checked http://developers.facebook.com/docs/reference/api/ where one gets access to news feed and profile feed, but they dont gives what the user has read in washington post / yahoo reader. Is there any way to get this information using javascript jdk?
What I have tried:
After login in thorugh the login in button. I query
FB.api('/me/washington_posts', function(response) {
var wash_post=JSON.stringify(response);
alert(wash_post);
});
graph.facebook.com/me/317071798339058?access_token=AAAAAAITEghM...
graph.facebook.com/me/...
I tried sevaral combinations of washington_posts, but always got error. I know this was not going to work but tried for some luck There is no documentaion of the same as mentioned here.
I believe its not possible to get it as of now as wpsocialreader is a diiferent fb app. apps.facebook.com/wpsocialreader/… I am only able to get the app info.
graph.facebook.com/267401179951379 :
{ "id": "267401179951379", "name": "Washington Post Social Reader", "link": "facebook.com/wpsocialreader";, "likes": 169544, "category": "App", "is_published": true, "website": "washingtonpost.com/socialreader";, "username": "wpsocialreader", "description": ".........", "about": "News. Better with friends. ", "release_date": "2011", "can_post": true, "talking_about_count": 19977 }
I think it is not possible to collect data from washington post reader app, so I am looking if somebody have already done it.
You can get the entries with the open graph action type news.read from yourself or a friend using the graph API:
graph.facebook.com/me/news.reads or graph.facebook.com/USER_ID/news.reads
Obviously, add in the access token and other graph parameters you need as well. This will return all reads from the applications that publish them. You could then pick out the social reader reads by app id.
Hope this helps.
-matt

Categories

Resources