#wagamumma_webhooks
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1364909836340564039
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
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.
- wagamumma_best-practices, 1 hour ago, 13 messages
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
// Optional: retrieve the customer details
if (!empty($paymentIntent->customer)) {
$customer = \Stripe\Customer::retrieve($paymentIntent->customer);
is always returning empty I am not sure what I am doing wrong?
is $paymentIntent->customer not a thing?
hi there!
hi ๐ just to explain this is from a google pay express checkout I am trying to return the customer details so we can create the order details in the clients database
you can retrive the associated payment_method, which should have the information you are loowing for in billing_details: https://docs.stripe.com/api/payment_methods/object#payment_method_object-billing_details
how do I get this payment_method then sorry I am not totally understanding
$paymentIntent = $event->data->object;
is it $paymentIntent->payment_method?
is it $paymentIntent->payment_method?
yes ๐
then $paymentIntent->payment_method->billing_details->address ?
is there a php example of this anywhere?
as its google/apple express i dont know if a customer is being created on stripe I thought I could just get the details directly from their apple/google details somehow?
like I am not sure what 'cus_9s6XKzkNRiz8i3' would be ?
sorry, I linked to the wrong endpoint. it should be https://docs.stripe.com/api/payment_methods/retrieve where no customer is needed
ok thanks I think I see, would it be
$paymentMethod = $stripe->paymentMethods->retrieve(
$paymentMethod->id,
[]
);
yep
wait no
to get the paymentmethod ID, its directly $paymentIntent->payment_method. there's no ->id.
ah ok great I will try this thanks
Stripe Notice: Undefined property of Stripe\PaymentIntent instance: paymentMethods; PHP message: PHP Fatal error: Uncaught Error: Call to a member function retrieve() on null
can you add some logs to your code to understand what is happening?
I am not sure what to do with these
\Stripe\Stripe::setApiKey('*');
$stripe = new \Stripe\StripeClient('');
whjich is the right way, or does it need both one for payment intent and another for payment method?
i seem to have 2 different test keys is the api test key meant to be different, and much shorter in length?
I'm not sure I understand your question, sorry. when you make API calls to Stripe, you need to set your API key, either your test key (sk_test_xxx) or live key (sk_live_xxx)
can I send the full code on here?
yes, but don't include your secret key.
in PHP you need to do something like this:
$stripe = new \Stripe\StripeClient('sk_test_xxx');
// and then make your API calls
its just in one example it gives an api test key and in the payment method example its a much longer test key completely different
\Stripe\Stripe::setApiKey('sk_test_26PHem9AhJZvU623Dxxxxx'); // Replace with your secret key
$stripe = new \Stripe\StripeClient('sk_test_51QhtgiIDAO7vvncvKCJZqEqyEmjSgWGZA4c7RStDqQJbVop6fvJI6Y1mPLCOpMR9svQ5BGoknfTbpxkauGRWs63D00dxxxxx');
I don't understand your question. you need to use your own API key, that you can find in your Stripe dashboard.
ok i think maybe the webhook doc just isn't putting in the right test key in the code example I don't know
how do I paste code here?
ok i think maybe the webhook doc just isn't putting in the right test key in the code example I don't know
don't use the documentation for this. just check your dashboard and use the keys listed here
ok it is still giving the same error though ๐ฆ
\Stripe\Stripe::setApiKey('sk_test_****');
// Retrieve the request's body and parse it as JSON
$payload = @file_get_contents("php://input");
$sig_header = $SERVER['HTTP_STRIPE_SIGNATURE'];
$endpoint_secret = 'whsec****'; // Set your webhook secret here
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
echo json_encode(['Error parsing payload: ' => $e->getMessage()]);
exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code(400);
echo json_encode(['Error verifying webhook signature: ' => $e->getMessage()]);
exit();
}
// Handle the event
switch ($event->type) {
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
// Optional: retrieve the customer details
$paymentMethod = $paymentIntent->paymentMethods->retrieve(
$paymentIntent->payment_method,
[]
);
$name = $paymentMethod->billing_details->name;
$email = $paymentMethod->billing_details->email;
$address = $paymentMethod->billing_details->address;
// Example: write to log
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/stripe-components/public/stripe_log.txt', "Payment succeeded for $name ($email)\nAddress: $addresss\n\n", FILE_APPEND);
break;
Stripe Notice: Undefined property of Stripe\PaymentIntent instance: paymentMethods; PHP message: PHP Fatal error: Uncaught Error: Call to a member function retrieve() on null
ok it is still giving the same error though ๐ฆ
have you tried my suggestion from earlier?
which is:
can you add some logs to your code to understand what is happening?
yeah I am logging to file but it just isn't logging any more because this bit must be wrong does it look right to you?
$paymentMethod = $paymentIntent->paymentMethods->retrieve(
$paymentIntent->payment_method,
[]
);
can you log $paymentIntent and $paymentIntent->payment_method and $paymentMethod?
ok I will try
Hey, taking over here. Let me know if there's any follow-up Qs I can answer!
Payment intent:
Stripe\PaymentIntent JSON: {
"id": "pi_3RHNd0IDAO7vvncv1nrWcfoe",
"object": "payment_intent",
"amount": 2400,
"amount_capturable": 0,
"amount_details": {
"tip": []
},
"amount_received": 2400,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": {
"allow_redirects": "always",
"enabled": true
},
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic_async",
"client_secret": "pi_3RHNd0IDAO7vvncv1nrWcfoe_secret_gg30BkOe1BvpKxX6CPgTPrZHe",
"confirmation_method": "automatic",
"created": 1745492858,
"currency": "gbp",
"customer": null,
"description": "Purchase of Item XYZ",
"invoice": null,
"last_payment_error": null,
"latest_charge": "ch_3RHNd0IDAO7vvncv1LHEdLSo",
"livemode": false,
"metadata": {
"order_id": "123456789"
},
"next_action": null,
"on_behalf_of": null,
"payment_method": "pm_1RHNd0IDAO7vvncvCEuUnGWD",
"payment_method_configuration_details": {
"id": "pmc_1QhthDIDAO7vvncvXGHVCxbG",
"parent": null
},
"payment_method_options": {
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
},
"klarna": {
"preferred_locale": null
},
"paypal": {
"preferred_locale": null,
"reference": null
}
},
"payment_method_types": [
"card",
"klarna",
"paypal"
],
"processing": null,
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
Payment method:
pm_1RHNd0IDAO7vvncvCEuUnGWD
hi sorry to paste so much this is the logs of payment intent and payment_method
Feel free just to share the object Id next time, it should be enough (aka pi_... or pm_...)
But no worries yeap!
What issue you are facing with this PaymentIntent ?
I am trying to get the customer name, email, address
$paymentMethod = $paymentIntent->paymentMethods->retrieve(
$paymentIntent->payment_method,
[]
);
$name = $paymentMethod->billing_details->name;
this is causing a php error though but not sure what I've done wrong
There is no Customer attached to that PaymentIntent
First, how are you collecting the customer name, email, address?
I was told that above would work , this is google/apple express checkout
so I need to get the details from that payment method somehow
What is the issue/error you are getting ?
Stripe Notice: Undefined property of Stripe\PaymentIntent instance: paymentMethods; PHP message: PHP Fatal error: Uncaught Error: Call to a member function retrieve() on null
But the PaymentMethod has indeed customer details
$paymentMethod = $paymentIntent->paymentMethods->retrieve( so this is wrong somehow?
You should follow this guide in order to retrieve a PaymentMethod by Id
$paymentMethod = $stripe->paymentMethods->retrieve(
$paymentIntent->payment_method,
[]
);
yeah I did copy that from that page but I am not making $stripe in that way it is like this:
\Stripe\Stripe::setApiKey('sktest_xxxxxxxxxxxxxxxxxxxxxxxxxxxx');
is there a way I can do it like this like:
$paymentMethod = \Stripe::paymentMethods->retrieve(
You can yes
How are you making your calls usually ?
\Stripe\Stripe::setApiKey('sktest_xxxxxxxxxxxxxxxxxxxxxxxxxxxx');
The recommended flow is to create a Client and not setting it as global var
ok so I will try it that way instead but what would this become?
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
$event=$stripe->Webhook::constrectEvent ?
no i mean $stripe->Webhook->constrectEvent
except spelled correctly ๐
Yeah that should be like that ๐
sorry really new at this stuff... so what would these become?
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
echo json_encode(['Error parsing payload: ' => $e->getMessage()]);
exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
These are just classes, so no changes
so I can keep \Stripe in there even if I am not setting stripe globally anymore and using $stripe = new \Stripe\StripeClient('sk_test_
but this will work? $event = $stripe->Webhook->constructEvent(
ok it definitely doesn't like that hmm
so I can keep \Stripe in there even if I am not setting stripe globally anymore and using $stripe = new \Stripe\StripeClient('sktest
You can use both approaches
You can keep the first/existing approach with the webhooks
and use the Client instance (following the API doc for the other calls)
it works ๐
only thing is the name didn't come through for some reason
$name = $paymentMethod->billing_details->name;
$email = $paymentMethod->billing_details->email;
$address = $paymentMethod->billing_details->address;
the email and address were fine but there's no name from billing details?
actually I think I'm being dumb because it's test account details the name is returned and just called "Card Holder Name"
thanks so much for your help with this
one last question sorry, if I want the shipping name/address if they're different from google/apple pay how would I get these is there a $paymentMethod->shipping_details type ?
Nice!
Sorry I don't understand this follow up question...
if you are buying a gift and the shipping address and name is to another person not the cardholder, because the website owner will need to know the address to ship to, it won't always be the billing name/address?
so instead of ->billing_details is there a ->shipping_details?
tbh I dont even know if you can choose a different address when using apple/google pay express checkout
Ah I see
you can collect Shipping details using Express Checkout Element
following this guide
(You won't have it in the PaymentMethod however, not like billing)
I see where would the customer enter this then does it make new form fields if I set shippingAddressRequired: true, ?
In the wallet, yes.
ok thanks, adding that seems to make it hang for a very long time for some reason and in log it says
Uncaught (in promise) SyntaxError: Unexpected token '<', " <!DOCTYPE "... is not valid JSON
const optionsExpress = {
shippingAddressRequired: true,
emailRequired: true,
phoneNumberRequired: true,
};
// Set up Stripe.js and Elements to use in checkout form.
const elements = stripe.elements(options);
// Create and mount the Express Checkout Element
const expressCheckoutElement = elements.create('expressCheckout',optionsExpress);
if I take shippingAddressRequired: true, out its instant again but with it in it just hangs with a loading icon for a long time
it loads eventually but says
Hi. I'm taking over from my colleague. Please, give me a moment to catch up.