#ade-pi-statementdescriptor

1 messages · Page 1 of 1 (latest)

novel crow
junior trail
#

it seems not to work

novel crow
#

hello, catching up one sec

junior trail
#

sure, thank you!

novel crow
#

so updating Statement Descriptor (SD for short) isn't updateable after the PaymentIntent is confirmed and is successful, by that point the Charge has been created and a SD sent to the bank so it isn't mutable

metadata on the other hand is something that can be mutated at that point so I'm curious if you have a request only updating the metadata and that should work, if not pls share the request ID for that

junior trail
#

I see. Well the metadata one appears to fail too. However are these synchronous requests? i.e. can I do something this in a single pass of my script?

`$intent = \Stripe\PaymentIntent::retrieve($input->payment_intent_id);
$intent->confirm();

$invoice_id = '123';
\Stripe\PaymentIntent::update(
  $input->payment_intent_id,
  ['metadata' => ['invoice_number' => 'INVOICE '.$invoice_id]]
);
`
#

I wondered if my problem was that both the confirm() and update() are here being run in the same process

#

I am not sure how to get my request ID, unless you mean the payment_intent_id ?

#

I just made a payment with this exact code: pi_3JaMoX2RYOwcUf4c1e501cXs

#

the dashboard shows No metadata

novel crow
#

your update request isn't being run

#

I'm only seeing that PaymentIntent being created

#

no further updates to it, no requests beyond the first one

#

so I don't think any of the above code is running? I'm not seeing a retrieve of confirm of the PaymentIntent

junior trail
#

not seeing confirm?

#

but the payment is completed in Stripe

#

is this perhaps because i have 'confirm' => true in the \Stripe\PaymentIntent::create block? so it is already confirmed?

i did wonder about that but i get an error if i set that to false

#

it has been working like this, in a production system for many years

novel crow
#

is this perhaps because i have 'confirm' => true in the \Stripe\PaymentIntent::create block? so it is already confirmed?
yes, that is why the payment is successful

but none of the above code is being run

#

there is to PI.update() request that I'm seeing on that PaymentIntent

junior trail
#

perhaps the first pass is returning response.requires_action as false.

novel crow
#

yes it is going directly into status: succeeded

junior trail
#

ok, that explains it then.

so it's not wrong as such but there is no separate confirm step

#

setting 'confirm'=>false in create method is causing an error but i don't know if it's an error from Stripe or from my application

#

i will debug that now

#

ok so i am getting the else case (error 500) here:

`private function _generatePaymentResponse($orderNumber, $orderData, $approval_user_id, $intent){

if ($intent->status === 'requires_action' &&
$intent->next_action->type === 'use_stripe_sdk') {
  // Tell the client to handle the action
  $this->success((object)[
    'requires_action' => true,
    'payment_intent_client_secret' => $intent->client_secret
  ]);

} else if ($intent->status === 'succeeded') {
  // The payment didn’t need any additional actions and completed!
  // Handle post-payment fulfillment
  $this->_do_card_payment_success($orderNumber, $orderData, $approval_user_id, $intent);
  $this->session->set_flashdata('last_action', 'payment_complete');
  $this->success();

} else {

  // payment intent failed
  return $this->fail((object)['error' => 'Invalid PaymentIntent status'], 500);
}

}

`

#

i will look what the status is here

#

perhaps i need to find documentation for integrating it this way

novel crow
#

so let's take a step back, let me highlight it for you

junior trail
#

aha.. so the status is requires_confirmation

#

ok

novel crow
#

right now your code was
1/ creating a PaymentIntent but also passing confirm: true

it looked like if the PaymentIntent succeeded immediately in step 1, your code was not updating the PaymentIntent with metadata

so that is the first thing you need to debug first, is your code ever creating (plus confirming) a PaymentIntent in one API call (which can return status: succeeded ) , if so, is it immediately updating metadata on the PI? or is it only doing it in a different scenario like when the PI is requires_action ?

you can update metadata on a PI after it is succeeded, just that your code isn't doing that

junior trail
#

yep. i see that now. the status: succeeded was never passed back to my backend, so that code never ran (i can now see)

#

is your code ever creating (plus confirming) a PaymentIntent in one API call
yes it's doing exactly this, we have been taking payments this way for many years

#

requires_action does get used to pass the client the client_secret

novel crow
#

not sure I understand the last thing, can you re-phrase that?

junior trail
#

sure...

#

so i guess stripe.js is triggering all these requests to my API using stripe.handleCardAction

and i can see that it makes two... the first one passes the payment_method_id and this causes $intent = \Stripe\PaymentIntent::create to be run (with confirm: true, currently)...

then my method _generatePaymentResponse is called, which essentially looks at the $intent->status and then responds to the frontend.

so the response for the first request basically returns:

[ 'requires_action' => true, 'payment_intent_client_secret' => $intent->client_secret ]

#

then it makes a second request containing the payment_intent_id and this creates AND confirms in one step

#

it looks as though i need to set confirm to false when i create the intent, then it will presumably make a third request which confirms the intent ... and here i can also update metadata.

#

essentially: i have set up both the front and backend to expect and handle requires_action but i have nothing that expects or handles requires_confirmation so i will need new front and backend code for that.

#

^^ ignore that, i found a way

#

this works, using confirm: true

#

`
$intent = \Stripe\PaymentIntent::create([
'payment_method' => $input->payment_method_id,
'amount' => $orderData['grand_total'] * 100, // amount in pence as a whole number (prevent floating point errors with rounding)
'currency' => 'gbp',
'confirmation_method' => 'manual',
'confirm' => true, //Set to true to attempt to confirm this PaymentIntent immediately
'statement_descriptor' => $statementDescriptor // add order number (need to get next order # first)
]);

    if($intent->status === 'succeeded'){
      \Stripe\PaymentIntent::update(
        $intent->id,
        ['metadata' => ['invoice_number' => 'INVOICE 1234']]
      );
    }

`

#

i hadn't realised i can just get $intent->id so this is a huge shortcut 🙂

#

pm_1JaNZf2RYOwcUf4cavVtsaPf has the correct metadata

#

thank you so much for the help!

novel crow
#

np! yeah there might be little changes or more depending on what your integration is doing but it looks like it would be a small-ish refactor to make sure your PaymentIntents are updated with metadata, after they have succeeded