#papix_webhooks
1 messages · Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- papix_webhooks, 22 minutes ago, 32 messages
- papix_checkout-sessions, 1 hour ago, 78 messages
👋 Welcome to your new thread!
⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1247515822847692882
📝 Have more to share? Add details, code, screenshots, videos, etc. below.
No – we close them after a period of inactivity. If you need help please provide some actual context of what it is you're trying to do and the problems you're having. There's no detail in any of your asks
$payload = @file_get_contents('php://input');
$event = null;
// Função para registrar logs no arquivo debug.txt
function log_debug($message) {
$logFile = __DIR__ . '/debug.txt';
file_put_contents($logFile, $message . PHP_EOL, FILE_APPEND);
}
try {
$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);
} catch (\UnexpectedValueException $e) {
// Invalid payload
log_debug('⚠️ Webhook error while parsing basic request.');
http_response_code(400);
exit();
}
if ($endpoint_secret) {
// Only verify the event if there is an endpoint secret defined
// Otherwise use the basic decoded event
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch (\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
log_debug('⚠️ Webhook error while validating signature.');
http_response_code(400);
exit();
}
}
log_debug('Event received: ' . $event->type);
switch ($event->type) {
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
log_debug('Payment succeeded: ' . $paymentIntent->id);
break;
default:
// Unexpected event type
log_debug('Received unknown event type: ' . $event->type);
}
http_response_code(200);
?>
this:
switch ($event->type) {
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
log_debug('Payment succeeded: ' . $paymentIntent->id);
break;
default:
// Unexpected event type
log_debug('Received unknown event type: ' . $event->type);
}
don't work
What does 'don't work' mean? Do you see an error? Are any of those logs printed in your console?
i get 0 errors
or debug infos
but if put something before the switch work
i need inside the payment_intent.succeeded
So you don't see this log: log_debug('Event received: ' . $event->type);
Are you actually forwarding events from Stripe to the endpoint?
sure
now work, the last question is:
how i can use variables with the data from stripe?
like email
Your $event->data->object variable will contain the fields of the related object, so in the case of payment_intent.* events the Payment Intent: https://docs.stripe.com/api/payment_intents/object
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Email likely won't be available directly, as most the time it's set on the underlying Charge object created when the intent succeeds: https://docs.stripe.com/api/charges/object#charge_object-billing_details-email
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So you'll need to lookup the ch_xxx ID from the API using the latest_charge field from your event: https://docs.stripe.com/api/payment_intents/object#payment_intent_object-latest_charge
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
you show me 1 small example?
which event are you listening to, and which field are you looking for?
i want for example get variables with stripe data
switch ($event->type) {
case 'charge.succeeded':
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
log_debug('Payment succeeded: ' . $paymentIntent->id);
DiscordWebhook("${heree} @everyone", "coins");
break;
default:
// Unexpected event type
log_debug('Received unknown event type: ' . $event->type);
}
It's already in your code:
$paymentIntent = $event->data->object;
this gives you data from Stripe about the PaymentIntent
sure but i need get the costum field i created
PaymentIntent don't have custom fields. Do you mean on the Checkout Session object or something else?
my gool it's give 1 discord msg with username (costum field) and amount when the costumer really pay
but what is "custom field"? did you create a Checkout Session or Payment Link with a custom field? Or you are talking about metadata? Or something else?
Please be more precise in your questions if you want us to help you.
yes
'custom_fields' => [
['key' => 'username',
'label' => [
'type' => 'custom',
'custom' => 'Username (Login)',
],
'type' => 'text',
'text' => ['default_value' => $username,],
],
],
so you are using Checkout Session or Payment Links! this information won't be availeble in the PaymentIntent, but in the Checkout Session object.
so either:
- listen to
checkout.session.completed - or make an extra API call to retrieve the Checkout Session: https://docs.stripe.com/api/checkout/sessions/list
i use Checkout Session
yep
this?
correct
now how i can manipulate the data?
what does that mean?
for example, get the "username" and "amount"
username is in custom_fields. amount is in amount_total.
switch ($event->type) {
case 'checkout.session.completed':
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
$amount_total = $paymentIntent->mount_total;
log_debug('Payment succeeded: ' . $paymentIntent->id);
DiscordWebhook("${amount_total} @everyone", "coins");
break;
with id work but with mount_total dont work
it's amount_total, not mount_total
$paymentIntent->custom_fields[0]->text->value
sure, but in api demo don't have the costum field, just in session
also $paymentIntent = $event->data->object; should be $checkout_session = $event->data->object;
what is "api demo"?
sorry, webhook demo *
I don't understand sorry
and? what's the issue?
i don't have here the "special field"
what is "special field"?
in main script i do this:
'custom_fields' => [
['key' => 'username',
'label' => [
'type' => 'custom',
'custom' => 'Username (Login)',
],
'type' => 'text',
'text' => ['default_value' => $username,],
],
],
I already explained how to retrieve the customer field in your webhook code:
$checkout_session->custom_fields[0]->text->value
yes in "main script" i need also in demo mode
I don't understad what is "main script" and what is "demo mode". can you be more precise in your questions?
I'm sorry I don't understand. please explain in more details exactly what you are trying to do and what is the issue.
i repeat 500000x .....
i need include in data the costum field!
the costumer pay and i get the username and amount from webhook
exactly, so:
- create the Checkout Session
- redirect the user to the Checkout Sesison url
- once the user submits the form, you will get a
checkout.session.completedevent - in that event you can find the custom fields
it's possible put the session in demo mode?
please use correct vocabulary, "demo mode" doesn't mean anything.
TEST MODE
Are you still going to be rude?
I'm sure stripe's management doesn't tolerate that kind of behavior from employees to customers
Maintain respect and do your job
hi @naive dove, please refrain from being aggressive with my colleagues
otherwise we wouldn't have any other choice but to ban you from the server
Aggressive? Read the conversation again
Right, tell me your name and I'll call human resources at stripe
Do you even know the law?
@naive dove please stop making empty threats. Let's focus on solving your issue
yes mate, i want fix this i have costumers waiting...
if you're not willing to drop the tone and attitude here and now I will have to ban you
I told you earlier this morning to refrain from slang such as bro and mate
Friend, I only expressed my dissatisfaction
not even that
just tell me what I can help you with and I will gladly answer your question
is this how you treat your customers? i work with myolian companies and none of them care about “bro” or “mate”
we do here!
i'm here for make money, you too don't do this dude
I'm giving you your last warning, please stop discussing this, and let's move on!
i just need help for fix the problem
Question: How i can enable "test mode" in session script?
i do this, work good
do you understand the difference between the different API keys for your account?
but now i need do the webhook and i need enable test mode for can test the webhook
don't worry about that
please do delete it!
it's not something that you can share on a public thead
and while talking about that, now that you did, you need to roll your live secret key
sure
since you're also visiting that page
you can look at this section https://docs.stripe.com/keys#obtain-api-keys
which explains the different API keys that you have for your account and which ones to use in which situation
$YOUR_DOMAIN = $config['general']['base_url'];
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[
# Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
'price' => 'xxxxxx',
'quantity' => 1,
]],
'custom_fields' => [
['key' => 'username',
'label' => [
'type' => 'custom',
'custom' => 'Username (Login)',
],
'type' => 'text',
'text' => ['default_value' => $username,],
],
],
'customer_email' => $email,
'mode' => 'demo',
'success_url' => $YOUR_DOMAIN . '/coins?stripe_done',
'cancel_url' => $YOUR_DOMAIN . '/coins',
]);
die('<meta http-equiv="refresh" content="0;url='. $checkout_session->url .'">');
i needed "test mode" inside this
objects are created in test mode vs live mode based on which API key you use
that's why I suggested looking at the section I linked you to
sure i go try again
so please in the future when we advise you to read some docs, please do read the docs before jumping the gun
so as action items:
- replace the livemode secret key
sk_live_xxxwith the testmode secret keysk_test_yyy - roll your livemode secret key since it was exposed in a public space
I'm here @naive dove, if you still need any more help please let me know
sure, now it's all ok
i sincerely apologize if you and your team felt i was aggressive, keep up the good work and i'm sorry
no worries @naive dove, please in the future, if you feel a bit frustrated, take a step back, breathe for a moment and try to focus on how you can help us help you instead of escalating our conversation into a FUD
I appreciate your apology! and thank you for your patience while we provided you with the necessary answer
have a good day and I hope to see you soon here!