#papix_webhooks

1 messages · Page 1 of 1 (latest)

noble drumBOT
robust plumeBOT
#

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.

noble drumBOT
#

👋 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.

naive dove
#

You can stop close my tickets?

#

i request help, i'm stripe costumer

void lava
#

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

naive dove
#
$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

void lava
#

What does 'don't work' mean? Do you see an error? Are any of those logs printed in your console?

naive dove
#

i get 0 errors

#

or debug infos

#

but if put something before the switch work

#

i need inside the payment_intent.succeeded

void lava
#

So you don't see this log: log_debug('Event received: ' . $event->type);

#

Are you actually forwarding events from Stripe to the endpoint?

naive dove
#

sure

#

now work, the last question is:

#

how i can use variables with the data from stripe?

#

like email

void lava
naive dove
#

you show me 1 small example?

untold locust
#

which event are you listening to, and which field are you looking for?

naive dove
#

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);
}
untold locust
#

It's already in your code:

$paymentIntent = $event->data->object;
this gives you data from Stripe about the PaymentIntent

naive dove
#

sure but i need get the costum field i created

untold locust
#

PaymentIntent don't have custom fields. Do you mean on the Checkout Session object or something else?

naive dove
#

my gool it's give 1 discord msg with username (costum field) and amount when the costumer really pay

untold locust
#

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.

naive dove
#

yes

  'custom_fields' => [
    ['key' => 'username',
      'label' => [
        'type' => 'custom',
        'custom' => 'Username (Login)',
      ],

      'type' => 'text',
      'text' => ['default_value' => $username,],
    ],
  ],
untold locust
#

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:

naive dove
#

i use Checkout Session

untold locust
#

yep

naive dove
untold locust
#

correct

naive dove
#

now how i can manipulate the data?

untold locust
#

what does that mean?

naive dove
#

for example, get the "username" and "amount"

untold locust
#

username is in custom_fields. amount is in amount_total.

naive dove
#
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

untold locust
#

it's amount_total, not mount_total

naive dove
#

sorry kkkk

#

and now the special field?

#
$paymentIntent->custom_fields['username'];
untold locust
#

$paymentIntent->custom_fields[0]->text->value

naive dove
#

sure, but in api demo don't have the costum field, just in session

untold locust
#

also $paymentIntent = $event->data->object; should be $checkout_session = $event->data->object;

#

what is "api demo"?

naive dove
#

sorry, webhook demo *

untold locust
#

I don't understand sorry

naive dove
#

i use this for test mode

untold locust
#

and? what's the issue?

naive dove
#

i don't have here the "special field"

untold locust
#

what is "special field"?

naive dove
#

in main script i do this:

  'custom_fields' => [
    ['key' => 'username',
      'label' => [
        'type' => 'custom',
        'custom' => 'Username (Login)',
      ],

      'type' => 'text',
      'text' => ['default_value' => $username,],
    ],
  ],
untold locust
#

I already explained how to retrieve the customer field in your webhook code:

$checkout_session->custom_fields[0]->text->value

naive dove
#

yes in "main script" i need also in demo mode

untold locust
#

I don't understad what is "main script" and what is "demo mode". can you be more precise in your questions?

naive dove
#

Test Mode webhook

#

i need also the costum field...

untold locust
#

I'm sorry I don't understand. please explain in more details exactly what you are trying to do and what is the issue.

naive dove
#

i repeat 500000x .....

#

i need include in data the costum field!

#

the costumer pay and i get the username and amount from webhook

untold locust
#

exactly, so:

  1. create the Checkout Session
  2. redirect the user to the Checkout Sesison url
  3. once the user submits the form, you will get a checkout.session.completed event
  4. in that event you can find the custom fields
naive dove
#

it's possible put the session in demo mode?

untold locust
#

please use correct vocabulary, "demo mode" doesn't mean anything.

naive dove
#

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

south kestrel
#

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

naive dove
#

Right, tell me your name and I'll call human resources at stripe

#

Do you even know the law?

south kestrel
#

@naive dove please stop making empty threats. Let's focus on solving your issue

naive dove
#

yes mate, i want fix this i have costumers waiting...

south kestrel
#

if you're not willing to drop the tone and attitude here and now I will have to ban you

south kestrel
naive dove
#

Friend, I only expressed my dissatisfaction

south kestrel
#

not even that

#

just tell me what I can help you with and I will gladly answer your question

naive dove
#

is this how you treat your customers? i work with myolian companies and none of them care about “bro” or “mate”

south kestrel
#

we do here!

naive dove
#

i'm here for make money, you too don't do this dude

south kestrel
#

I'm giving you your last warning, please stop discussing this, and let's move on!

naive dove
#

i just need help for fix the problem

south kestrel
#

what's the issue?

#

how may I help?

naive dove
#

Question: How i can enable "test mode" in session script?

south kestrel
#

what do you mean by session script?

#

ok before you answer that

naive dove
#

i do this, work good

south kestrel
#

do you understand the difference between the different API keys for your account?

noble drumBOT
naive dove
#

but now i need do the webhook and i need enable test mode for can test the webhook

south kestrel
#

please delete the code you just shared

#

it has your live secret key

naive dove
#

don't worry about that

south kestrel
#

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

naive dove
#

sure

south kestrel
#

since you're also visiting that page

#

which explains the different API keys that you have for your account and which ones to use in which situation

naive dove
#
$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

south kestrel
#

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

naive dove
#

sure i go try again

south kestrel
#

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_xxx with the testmode secret key sk_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

naive dove
#

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

south kestrel
#

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!