#samiya_code
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/1430859912124174336
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
๐ Are you getting an error message? Can you share the request ID (req_xxx)? https://support.stripe.com/questions/finding-the-id-for-an-api-request
Preauthorization code
case 'customer.subscription.created':
$subscription = $event->data->object;
if (!empty($subscription->items->data) &&
isset($subscription->items->data[0]->price->id) &&
$subscription->items->data[0]->price->id === 'price_1RVbnpED5xkfDv2cFGpuEsb7' &&
isset($subscription->metadata['preauthorized_subscriptions']) &&
$subscription->metadata['preauthorized_subscriptions'] === 'true'
) {
$customer_id = $subscription->customer;
$payment_method_id = $subscription->default_payment_method ?? $subscription->payment_settings->default_payment_method;
if ($payment_method_id) {
// Attempt to create PaymentIntent, with error logging
try {
$paymentIntent = $stripe->paymentIntents->create([
'amount' => 1999,
'currency' => 'gbp',
'customer' => $customer_id,
'payment_method' => $payment_method_id,
'capture_method' => 'manual',
'confirm' => true,
'off_session' => true,
'metadata' => [
'subscription_id' => $subscription->id,
'purpose' => 'preauthorization_day4',
],
]);
} catch (\Exception $e) {
error_log('PaymentIntent creation error: ' . $e->getMessage());
echo('PaymentIntent creation error: ' . $e->getMessage());
}
error: {"error":"PaymentIntent creation failed"}PaymentIntent creation error: Your card was declined
Can you give me more details on what you're trying to do, in particualar with regard to this "preauthorizing" Generally, if you're not intending on charging straight away, Setup Intents are used. Some info on the differences here: https://docs.stripe.com/payments/paymentintents/lifecycle
Yes I am using setup intents. Basically what I am doing is I have a 7 day free trial based subscription that I am creating usng setup intent and then creating a suscription using a webhook event setup.intent.succeeded. Now what I want to do is create a preauthorization on the 4th day of trial using event trial.will.end, but in order to test it, I am adding the trigger on customer.subscription.created so that I can test it immediately rather than waiting for 4 days
Can you find me the request ID (req_xxx) for the failed attempt?
evt_1SLKjWED5xkfDv2cVY5JlKGI
Will this work for you?
Let me take a look..
sure thanks
Looks like you have a Radar rule that's blocking non-GB cards - this seems to have been triggered by your requests
So that means the preauthorization code is correct but its failing due to the radar rule?
It's creating the request fine anyway, but we won't attempt to perform any authorization with the bank at all in this instance due to the Radar rule
Can you please help like how do we check that which radar rule is affecting it?
Do we see that in the event itself?
If you fetch the charge object from the payment intent, there's an outcome hash which will indicate this: https://docs.stripe.com/api/charges/object#charge_object-outcome
Specfically, outcome.rule
How to fetch charge object from the payment intent?
The most recent charge ID for a PaymentIntent can be found under latest_charge: https://docs.stripe.com/api/payment_intents/object#payment_intent_object-latest_charge
I mean is there a way to check it in stripe. E.g how can I confirm that the the non-GB cards radar rule is triggering my webhook event
Which webhook event are you referring to here?
From the Dashboard you can see which payments matched a block rule
And from payment_intent.payment_failed events you can see the specific Radar rule, e.g. https://dashboard.stripe.com/acct_1GdvzJED5xkfDv2c/workbench/events/evt_3SJEL0ED5xkfDv2c1SksiB4g