#sxe

1 messages · Page 1 of 1 (latest)

bitter flicker
#

starting a thread for you!

harsh python
#

If stripe cancels a bad payment, but I cancel it again, how can I not cancel the first payment because it was already cancelled?

bitter flicker
#

Can you be more specific? I'm afraid I don't understand exactly what you're talking about

harsh python
#

I tested this:

#

I placed in my basket one item = 10 RON.

#

I entered on the payment page, where $price = 1000

#

I opened a new page, and I added in my basket another object too. So, the price was now 20 RON.

#

And, I came back to my first opened tab, where $price was still 10 RON

#

And proceeded the payment.

#

But, stripe cancelled it.

#

Because, $price was 2000, and payment was only 1000

#

And, in my webhook, I cancel it again because $basketvalue != $price

#

Still vague, no?

bitter flicker
#

What do you mean by "stripe cancelled it" - do you have specific object IDs that I can look at?

harsh python
#

Not right now, but I can try it again in 30 minutes and create a new thread.

bitter flicker
#

If it'll just be 30 minutes then we can just leave this thread open

harsh python
#

Can you tell me,

#

what does this exactly do?

#
if ($event->type == 'payment_intent.amount_capturable_updated')
    {      
$stripe->paymentIntents->capture(
  $intent_id,
  []
);
}
bitter flicker
#

I assume this is in your webhook event handler - so when you receive a payment_intent.amount_capturable_updated event it'll capture the Payment Intent

harsh python
#

I kinda rewrote the entire code, made it cleaner. So, I have a question.

#

I'm trying to implement some security protocols.

#

Scenario:

#

User adds to his basket, one item valued 10$.
In global.php, with mysql queries,
$basketvalue = 10.

#

User now proceeds to payment page, where,

#
$paymentIntent = \Stripe\PaymentIntent::create([
          'amount' => $basketvalue*100,
#

He doesn't insert his bank card yet, he opens a new tab.

#

He adds a new item in his basket, where. $basketvalue = 20 now.

#

He goes back to first tab, where $basketvalue = 10

#

And proceeds the payment.

#

Me, in webhook.php, I'm trying to detect,

#

if, $basketvalue * 100 equals to amount_captured, then approve the payment.

#

if it doesn't, cancel it.

#

Am I doing something ok?

bitter flicker
#

Is there a reason you're doing this though? Why can't you refresh the UI in the first tab so that the basket is displayed correctly?

harsh python
#

Well, how can I refresh the UI?

#

Because the addment was done by a new tab in the browser.

#

How can the server detect that there is a new item in the basket,

#

Or there was a modify made.

#

Or, I could load the global.php with ajax query each 1 second?

bitter flicker
harsh python
#
<?php
    $intent = $stripe->paymentIntents->update(
      '{{PAYMENT_INTENT_ID}}',
      ['amount' => 1499]
    );
    echo json_encode(array('status' => $intent->status));
?>
#

Yes, but how can I update it

#

if the php page is still static

#

Or, you mean that, I can update it in my webhook.php ?

bitter flicker
#

No, let's back up - are you using Payment Element at all?

harsh python
#

No.

#

I'm using payment intent

bitter flicker
#

Payment Element is something you'd use in combination with Payment Intents - Payment Element is what you'd use in your UI to collect the payment details

zealous monolith
#

Stepping in for Karbi here.

Yes, but how can I update it if the php page is still static
That would be up to you and the way your site/application works. What exactly are you trying to update?

harsh python
#

either,

#

B) Constantly update the global.php (what includes the $basketvalue) in the payment page, so if the user adds a new item, or removes it, or price gets modified before the placement of the payment, the page gets modified live.

#

I'm thinking to go on B, so I was now trying to constantly setinterval with jquery.

zealous monolith
#

Whatever works for you application is probably fine! This is outside of the scope of your Stripe-specific integration.

harsh python
#

Is create.php loaded in checkout.js ?

zealous monolith
#

What do you mean, exactly? Can you share any relevant code snippet?

harsh python
#

index.php

  <script src="checkout.js" defer></script>
#

checkout.js

async function initialize() {
  const { clientSecret } = await fetch("create.php", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ items }),
  }).then((r) => r.json());

  elements = stripe.elements({ clientSecret });

  const paymentElement = elements.create("payment");
  paymentElement.mount("#payment-element");
}
#

create.php

<?php
require 'vendor/autoload.php';

// This is your test secret API key.
\Stripe\Stripe::setApiKey('x');

$Price = $Price*100;

header('Content-Type: application/json');

try {
    // retrieve JSON from POST body
    $jsonStr = file_get_contents('php://input');
    $jsonObj = json_decode($jsonStr);

$stripe = new \Stripe\StripeClient(
  'x'
);

    // Create a PaymentIntent with amount and currency
    $paymentIntent = \Stripe\PaymentIntent::create([
          'amount' => $Price,
          'currency' => 'ron',
          'payment_method_types' => ['card'],
          'capture_method' => 'manual',
          'metadata' => [
      'UserID' => $_SESSION['ID'],
      'IP' => $_SERVER['REMOTE_ADDR'],
   ]

    ]);
    
    $output = [
        'clientSecret' => $paymentIntent->client_secret,
        'id' => $paymentIntent->id,
    ];

    echo json_encode($output);
    

} catch (Error $e) {
    
    http_response_code(500);
    echo json_encode(['error' => $e->getMessage()]);


}
?>```
zealous monolith
#

OK thanks, but I'm afraid I don't understand your question

harsh python
#

I've managed to do this:

#

Currently, when the price is updated, the index.php updates the price also.

#

But, when I'm sending the payment process,

#

Stripe registers the old price,

#

instead the new price.

zealous monolith
#

Is create.php loaded in checkout.js
Your checkout.js code makes a request to your create.php endpoint

#

It sounds like you have some state you need to update in your app, but that's going to be something that depends entirely on your implemenetation

harsh python
#

Is there any way, where I can update the create.php ?

#

Currently, what am I doing is this:

#

index.php

 <form id="payment-form">
      <div id="payment-element">
        <!--Stripe.js injects the Payment Element-->
      </div>
      <button id="submit">
        <div class="spinner hidden" id="spinner"></div>
        <span id="button-text"></span>
      </button>
      <div id="payment-message" class="hidden"></div>

    </form>
  <script>
$(function(){
   function pingServer(){
   $('#button-text').load('test.php');
   }

   setInterval( pingServer, 1000 );
});
</script>
#

test.php

<?php
include_once(''.$_SERVER['DOCUMENT_ROOT'].'/global.php');
?>
Plătește (<?php echo number_format($Price,",",".")?> RON) ```
#

Which, is totally fine,

#

It updates the price on the index.php

#

But, create.php is not being updated, and I don't know how should I update it because it's being fetched on.. where?

#

I don't see any include for create.php on index.php

zealous monolith
#

That's code entirely in your control, you can change it however you like

harsh python
#

Yes, but I don't understand how does create.php is included in my index.php

zealous monolith
#

It's being called to get a payment intent as an async fetch call, right?

harsh python
#

Because of this

  const { clientSecret } = await fetch("create.php", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ items }),
  }).then((r) => r.json());
#

right?

zealous monolith
#

It's not "included" -- it's a separate file providing a separate endpoint

#

yes

harsh python
#

So, I should add checkout.js on setinterval, so I could load it again, and again?

#

so create.php should reload it with new price?

zealous monolith
#

If that does what you need, you could, but it might not be ideal

harsh python
#

From your POV, what could be ideal?

#

What if, I'd use paymentIntents->update(

inside test.php ?

#

updating each second the intent.

zealous monolith
#

It shouldnt be necessary to update repeatedly unless something has changed, you'd want to track state & changes somewhere

harsh python
#

Is there any way, to get the payment intent ID, in the index.php, even if I didn't send the payment yet?

zealous monolith
#

What do you mean?

#

The payment intent only exists after its created, you could create it in your index page build if you prefer to, then only using another endpoint to update

#

How do you normally manage your async state tracking? You can handle all your Stripe integration points similarly

harsh python
#

I entered on the payment page, without clicking "Pay" nor completing the card's infos.

#

And stripe created the intent.

#

"object": {
"id": "pi_3KxzqRLKPu9R0yzS0Ly2REpY",

#

inside my create.php, i have these lines.

    
    $output = [
        'clientSecret' => $paymentIntent->client_secret,
        'id' => $paymentIntent->id,
    ];
#

Would, inserting a new line inside create.php, as this

    
    $output = [
        'clientSecret' => $paymentIntent->client_secret,
        'id' => $paymentIntent->id,
    ];

$paymentid = $output['id'];
#

and inside the index.php

<?php echo  $paymentid ?> ``` work?
#

Or this is a bad approach

zealous monolith
#

That doesn't look like the way create.php works though, it responds with json data and already includes that id

harsh python
zealous monolith
#

So in your client js code you can get the id in the same spot you get the clientSecret if you want to track that

harsh python
#

Without having to press submit?

zealous monolith
#

If you wanted to create the payment earlier, you'd need to make an async request to do that

harsh python
zealous monolith
#

I'll be honest: it sounds like you're struggling with the overall architecture and async flow of the application here

harsh python
zealous monolith
#

Was this build by another developer and you're trying to modify it?

harsh python
#

I was using the create charge, before, two years ago maybe and had lesser js.

harsh python
zealous monolith
#

What do you mean official source code? One of our examples?

zealous monolith
#

OK, so that's an illustration of how you can do this

#

Are you writing something new or adapting that pre-existing code?

harsh python
zealous monolith
harsh python
#

I'll stick with the payment intent.

#

Because I'm not from US / Canada

zealous monolith
#

Which may make more sense for what you already have, but maybe not

#

Sure, that guide helps you move from charges to payment intents

harsh python
#

No.

#

I do have the payment intent right now.

#

I'll tell you what I want to do, what I did until this moment,

#

And maybe you can help me what should I do from this moment to the next one.

#

I've asked myself a question. What would happen, if the prices would change while user is on the payment page and did not submit the payment?

#

So, I've tried to make the page a live one, where the price would update.

#

How do I get the price? : I'm getting the prices from a global.php file, with some mysql queries.

#

How does my create.php page looks like?

<?php
include_once(''.$_SERVER['DOCUMENT_ROOT'].'/global.php');
require 'vendor/autoload.php';





// This is your test secret API key.
\Stripe\Stripe::setApiKey('x');

$Price = $Price*100;

header('Content-Type: application/json');

try {
    // retrieve JSON from POST body
    $jsonStr = file_get_contents('php://input');
    $jsonObj = json_decode($jsonStr);

$stripe = new \Stripe\StripeClient(
  'x'
);

    // Create a PaymentIntent with amount and currency
    $paymentIntent = \Stripe\PaymentIntent::create([
          'amount' => $Price,
          'currency' => 'ron',
          'payment_method_types' => ['card'],
          'capture_method' => 'manual',
          'metadata' => [
      'UserID' => $_SESSION['ID'],
      'IP' => $_SERVER['REMOTE_ADDR'],
      and a long list of metaatas...
      
   ]

    ]);
    

    
    $output = [
        'clientSecret' => $paymentIntent->client_secret,
        'id' => $paymentIntent->id,
    ];

    echo json_encode($output);
    

} catch (Error $e) {
    
    http_response_code(500);
    echo json_encode(['error' => $e->getMessage()]);


}
?>

#

as you can see, 'amount' equals to $Price.

#

When, the user, enters on the payment page, stripe creates this intent.

#

With amount equal to $Price.

#

Now, I just changed the price of a product, and my basket is now valued 22.61 RON

#

The price changed itself, due this:

  <script>
$(function(){
   function pingServer(){
   $('#button-text').load('test.php');
   }

   setInterval( pingServer, 1000 );
});
</script>
#

test.php

<?php
include_once(''.$_SERVER['DOCUMENT_ROOT'].'/global.php');
?>
Plătește (<?php echo number_format($Price,",",".")?> RON)```
#

But, there's the catch, even if the button has changed it's value,

#

create.php still has the old value (33.92)

#

and if I would complete my bank card, and place the payment, it would give me an error.

#

as it gave me here
"id": "evt_3KxzqRLKPu9R0yzS0w8h82AU",
"id": "pi_3KxzqRLKPu9R0yzS0Ly2REpY",

#

So, basically, what I'm trying to do is, to refresh / update the paymentintent (from create.php) with the new price, and new metadatas, as I am doing with the button.

zealous monolith
balmy wigeon
#

We got it, you can delurk

#

@harsh python taking over for synthrider who is done for the day

harsh python
#

Ok, t for your time @zealous monolith

#

Thank you **

balmy wigeon
#

if you're changing the underlying PaymentIntent you need to re-render the Payment Element, is that what you're trying to do?

harsh python
#

I think so, yes.
I'm trying to modify the values of paymentintent::create

balmy wigeon
#

Have you considered just rendering the UI only after the amount is stable instead?

harsh python
#

But, what if the price changes after the UI has been rendered?

#

Can't I update, the paymentintent in my webhook.php ?

#

When, the user will press the 'pay' button, I'd update the payment intent with new amount, new metadatas.

#

Would this be easier?

balmy wigeon
#

Just trying to get you on the right track you seem to be mixing up so many concepts

#

like a "webhook.php" would be code that handles webhook events. This is not the code that would change the PaymentIntent amount those should be entirely separate

harsh python
#

Oh, I thought that, I can use the paymentIntents->update( in the webhook.php.

#

Thank you for the clarification.

balmy wigeon
#

no it doesn't really make sense

#

your webhook.php code is what will receive say payment_intent.created

#

It's another part of your application that should be changing the PaymentIntent amount, for example if they add something else to their cart/order

#

that part of your integration should
1/ Call the Update PaymentIntent API https://stripe.com/docs/api/payment_intents/update
2/ Likely log/track in your database what is being ordered/paid for

The entire payment flow happens when your code client-side confirms the PaymentIntent itself, so there shouldn't be a world where the 2 are out of sync

#

Does that all make sense?

harsh python
#

Maybe there's a communication barrier between me and you because I don't speak English very well,

#

But,

#

I currently save all products in my database. Once saved, I calculate the price after taxes and discounts, if there is a promotion.

#

Once the user clicks on the "Redirect me to payment page" button, from what I noticed on my stripe account, an intent is created

#

Please note that the user has not yet entered their bank details or pressed payment, but the intent has been created.

#

I was thinking about a few security flaws as well.

  1. If a discount promotion expires while the user is on the payment page and failed to pay and the price changes until he makes the payment?
  2. If, the price of an object changes while the user enters their bank details?
    And more possible security flaws as out of stock items and so on.
#

So, I decided to make the payment page real-time. Using index.php, a javascript code, setinterval, I entered the payment text of the live one button, which changes every 1 second with the price calculated from the database, with mysql queries.

#

As you can see, the text in the blue button is a live text that is updated every second. Now, it doesn't change because there are no price updates, new items in the cart, expired discounts and so on.

#

However, if there is a price change, let's say that from 22.61 it would turn into 30.00, and I would enter my bank details, Stripe would cancel my payment because the intent was created at 22.61 ( because, with this price I entered the payment page, and the price changed while I was on the page and the intent already created.)

#

Although I managed to update the price from the payment button, I don't know how to update the price and metadata from the create.php page.

balmy wigeon
#

yeah I understand some bits of this but not most

#

why would you have a setInterval. Why would the price change server-side? What could cause this if not some actions client-side already?

#

Ultimately, your approach works, if you had something that every X seconds goes to your server and checks if the PaymentIntent has changed, it would work. Client-side you'll need to unmount the PaymentElement entirely and remount it

#

So what specific part is blocking you with your code right now?

harsh python
#
  1. Why would the price change server side?
#

The price would change on the server-side because, let's say that on TAB1 you entered the payment page with 5 objects, worth 50 RON. But, you open a TAB2, and insert another object in your basket, already your basket is worth 6 objects worth 60 RON. You go back to TAB1, where the intent has already been created with 50 RON, and you pay 50 RON for 6 objects. That's why I did SetInterval, because every second it updates, what price it should be, from the database.

balmy wigeon
#

I see, so you basically want some kind of complex JS that will detect other tabs (or devices) that would change the cart?

#

I don't think even Amazon bothers with this :p

harsh python
#

Because as I said, if you came in with 50 RON to pay, however, a discount promotion has expired, and you have to pay 60 RON, what happens? That, while typing in your card details.

harsh python
#

Currently, I don't know how to refresh the create.php page.

balmy wigeon
#

yeah that's not the right way to look at it unfortunately

#

You don't really "refresh create.php" that's not how PHP works

harsh python
#

Yes, the user entered the payment page, the intent was created with 50 RON. However, in the $Price database from 50 RON it turned into $Price = 60.
How do I update this, so that when he presses the pay button, he pays 60 RON, instead of the 50 that was created when he entered the page?

balmy wigeon
#

Your server-side code (PHP) should know about you and which PaymentIntent you are trying to pay. So what you can do is some JS code that hits the server say every 10 seconds and it says "I have pi_123 and I'm seeing amount is 123456, can you let me know if it changed?" and then your server-side code can retrieve the PaymentIntent (or better it caches it locally) and it re-calculates the amount that is owed and it tells the client if it changed

harsh python
#

My server currently calculates how much money to pay, as evidenced by the ongoing payment button.

#

My question is, can I use *paymentIntents->update( * on my index.php page?

#

Using the intent created by \ Stripe \ PaymentIntent :: create ([?

balmy wigeon
#

yes

#

that you can, and when you change the amount you need to also update the UI client-side to re-render the element

harsh python
#

Because, look, if I have this code, and stripe creates it for me even if I haven't pressed the payment button yet, am I thinking of using $output ['id'] in the code where I use SetInterval, and keep updating the price?

#
$stripe = new \Stripe\StripeClient(
  'x'
);

    // Create a PaymentIntent with amount and currency
    $paymentIntent = \Stripe\PaymentIntent::create([
          'amount' => $Price,
          'currency' => 'ron',
          'payment_method_types' => ['card'],
          'capture_method' => 'manual',
          'metadata' => [
      'UserID' => $_SESSION['ID'],
      'IP' => $_SERVER['REMOTE_ADDR']
   ]

    ]);
    
    
    $output = [
        'clientSecret' => $paymentIntent->client_secret,
        'id' => $paymentIntent->id,
    ];

$paymentid = $output['id'];
    echo json_encode($output);
    

#

$paymentid = $output['id'];

balmy wigeon
#

There's no "price" that $price is your own PHP code

harsh python
#

Yes, I agree that.

balmy wigeon
#

I hope it's okay to say this but you are missing some fundamentals on web developer I think

#

you want to have a database, that stores your PaymentIntent id pi_123 and all the relevant information

harsh python
balmy wigeon
#

you're not supposed to just output the id client-side, if you did, anyone could abuse your code to look at other PaymentIntents and that's not what you want

#

every request from your client goes to your PHP code and that PHP code should know exactly which PaymentIntent to look at. Usually you do this with a cookie / PHP session for example

harsh python
#

So you're saying I'd better save the intent id as a session?

balmy wigeon
#

yes absolutely

harsh python
#

Great idea!

balmy wigeon
#

it forces the refresh of the PaymentElement based on what changed on the PaymentIntent

#

seems like exactly what you needed

harsh python
#

Does an intent ID need to change continuously with each refresh?

#

Each page refresh *

#

I think I broke something?

#

Is it okay to generate a different intent with each page refresh?

balmy wigeon
#

no, you should re-use the existing one

#

your code is just creating a new one each time

harsh python
#

But why is this happening to me? I didn't add anything to the code other than that

#
$_SESSION['payintent'] = $output['id'];
#

inside the create.php

balmy wigeon
#

I mean I don't know, that's your PHP code, I assume it's always happened this way?

harsh python
#

Before I added this code, I would've get only one intent, even if I'd refresh 5000 times.

#

Could I do something else? To run a if(isset($_SESSION['payintent'],

#

and if is not set, allow the PaymentIntent::create

#

if is set, do nothing ?

balmy wigeon
#

yes that would work

harsh python
#

I think I'm the only user who wants planes, right? lol.

balmy wigeon
#

:p

harsh python
#

Please note that once I added the condition, the stripe UI was no longer loaded, and no php error was generated.

#

And also, $_SESSION['payintent'] shows an previous intent.

#

I'll remove that line so I can debug it.

balmy wigeon
#

sure, for now this seems purely in your code

harsh python
#

To make sure I understand, I need to get the ID from the intent and update?
And I write the update code in the test.php document which is with setinterval and is continuously updated?

balmy wigeon
#

we don't care about the id overall, just the client_secret, the id is irrelevant to the Payment Element

harsh python
#

Is there any way to not alllow stripe from trying to resubmit the event to the webhook? (From what I'm reading here, he'll try to resend in an hour)

#

it'll try*

balmy wigeon
#

events are retried automatically but you don't need events for any of this flow for now so ignore it

harsh python
#

I refreshed the page and checked the webhooks on Stripe. Indeed, another payment_intent.created has been generated

#

Should I worry that a payment_intent.created event is generated at each page refresh?

balmy wigeon
#

yes you should

#

this means you don't really understand your code unfortunately

#

you're supposed to put the existing PaymentIntent id in a session

#

and then on page load you need to look at that session and whether there's already a PaymentIntent instead of recreating a new one each time

harsh python
#

Now I'm trying to change the code, thanks.

balmy wigeon
#

sure!

harsh python
#

I just set that, if is set $_SESSION['paymentintent'] => then retrieve payment intent,

#

if !isset $_SESSION['paymentintent'] => then create intent & set session with that id.

#

That's right until now?

balmy wigeon
#

yes

harsh python
#

Also, can I remove all webhook events without having to delete the webhook itself and recreating?

balmy wigeon
#

no

#

you have to delete/re-add

harsh python
#

Okay, I refreshed again and looked over the Stripe panel. No more new intents are generated.

#

Thank you.

balmy wigeon
#

yay!

harsh python
#

This PaymentIntent's amount could not be updated because it has a status of succeeded. You may only update the amount of a PaymentIntent with one of the following statuses: requires_payment_method, requires_confirmation, requires_action.

regal path
#

Hi 👋 I'm stepping in for @balmy wigeon

harsh python
#

hi

regal path
#

I've been reading this thread and I think the reason for updating the Payment Intent is in response to a user adding another item to their cart, yes?

harsh python
#

While the user is on the payment page.

regal path
#

Okay so in that case you would not be making an update request on a Payment Intent that had already succeeded, correct?

harsh python
#

Which has 200 response code.

regal path
#

Okay let me zoom out and provide a summary of the intended flow as I read it and you can correct me if I'm wrong

#
  1. User selects a price/product and proceeds to the checkout form. <- Payment Intent created
  2. User makes some change that affects their total price for this checkout <- Payment Intent Updated on Server
  3. Payment Element calls fetch_updates() to update to amount shown to the user
  4. User provides payment method details and submits form <- Payment Intent confirmed
harsh python
#

I'm still at 2.

the no.3 I made it with an SetInterval jquery, which I'm constantly pinging the test.php to show me the current value of the basket.

#
  <button id="submit">
        <div class="spinner hidden" id="spinner"></div>
        <span id="button-text"></span>
      </button>
#
 <script>
$(function(){
   function pingServer(){
   $('#button-text').load('test.php');
   }

   setInterval( pingServer, 1000 );
});
</script>
regal path
#

I don't think you should need to use SetInterval. When the user makes a change in the front-end, I would send a request back to my server with the new total amount

#

Then the response back to the front-end would trigger Step 3

harsh python
#

testphp

<?php
include_once(''.$_SERVER['DOCUMENT_ROOT'].'/global.php');
require 'vendor/autoload.php';

if(isset($_SESSION['payintent'])) {
    $Price = $Price*100;

if($_SESSION['pretdeplata'] != $Price
OR 
$_SESSION['CateProduse'] != $ID) {
$stripe = new \Stripe\StripeClient(
  'x'
);
$stripe->paymentIntents->update(
  $_SESSION['payintent'],
  ['amount' => $Price]
);
$_SESSION['pretdeplata'] = $Price;
$_SESSION['CateProduse'] = $IDrow1010;
}
}
?>

Plătește (<?php echo number_format($Price,2,",",".")?> RON)``` 
#

This is the test.php

balmy wigeon
#

@regal path the changes can happen in another tab

#

they just want to ensure they have the right version always (still I would never build it this way either)

regal path
#

Copy that @balmy wigeon then setInterval makes sense

harsh python
#

I'm trying to do *

regal path
#

But I would still expect a customer action that changes the price on the client-side to generate a request back to the server to update the price.

harsh python
#

So,

#

I am on tab 1

#

tab 2

#

Prices match.

#

I increased the amount with +1 item

#

which, now price is 33.92

#

On tab 2, the price matches too, because of the set interval

#

But, there's a but,

#

pi_3Ky25gLKPu9R0yzS1arPxPFB

#

"amount": 2261,

#

is the old price.

#

So, I've added in to the test.php (the document which is being constantly updated in the setinterval code)

#

the following code :

#
$stripe = new \Stripe\StripeClient(
  'x'
);
$stripe->paymentIntents->update(
  $_SESSION['payintent'],
  ['amount' => $Price]
);
regal path
#

Where are you seeing the old amount?

harsh python
#

here

regal path
#

That is the created event

#

That was the state of the PI when it was created

harsh python
#

So my update works?

regal path
#

Where you updated the amount to 3392

harsh python
#

payment_intent.amount_capturable_updated

#

Yes, it works.

regal path
#

It looks like it to me. You can see in the response the Payment Intent amount matches what you are displaying on your site

harsh python
#

And, in the webhook api, should I check in the event payment_intent.succeeded, or in the payment_intent.amount_capturable_updated

#

If the payment was sucesfull?

#

succesfull *

regal path
#

payment_intent.succeeded tells you the payment was successful.

#

Occurs when a PaymentIntent has successfully completed payment.

harsh python
#

Thank you. I'll fix a bit in the code, make it cleaner and I'll try to debug the current errors.

regal path
#

Ok great, I'm glad we could get you further along in your integration

harsh python
#

@balmy wigeon thank you for your time and your clarifications
@regal path thanks that you pointed me some good infos.

balmy wigeon
#

happy to help 🙂

regal path
#

^ +1

harsh python
#

Is this a good approach?

$stripe->paymentIntents->update(
  $_SESSION['payintent'],
  ['amount' => $Price],
  ['metadata' => ['UserID' => $_SESSION['ID']]],
  ['metadata' => ['IP' => $_SERVER['REMOTE_ADDR']]]
  
);
#

The metadata area

regal path
#

I think you need to specify the metadata parameter only once and include both key=>value pairs.

harsh python
#

As this?

#
$stripe->paymentIntents->update(
  $_SESSION['payintent'],
  ['amount' => $Price],
  ['metadata' => [
                 'UserID' => $_SESSION['ID'],
                 'IP' => $_SERVER['REMOTE_ADDR']
                 ]
  ]
  
);
regal path
#

Yes I think that approach will work better for you.

harsh python
#

Thank you.

balmy wigeon
#

😹

#

"will work better for you" is a polite way to say "because the other way really wouldn't work" :p

regal path
#

Hey, I'm just happy @harsh python properly uses code formatting in here

#

You know how many times we have to ask

harsh python
#

xD

regal path
#

It really helps

harsh python
#

Guess what, trying to implement new things helps me to improve my coding skills too.

regal path
#

Writing more code and solving new problems tends to improve overall coding skills

harsh python
#

Specially that you guys give me good advices.

#

Got unexpected keys in options array: metadata in

#

Did I do something wrong?

#
['metadata' => [
                  'UserID' => $_SESSION['ID'],
                  'IP' => $_SERVER['REMOTE_ADDR'],
                  'DiscountAplicat' => $outputrow1007e,
                  'Transport' => $Transportrow1007,
                  'NumeTransport' => $NumeTransportrow1007,
                  'PrenumeTransport' => $PrenumeTransportrow1007,
                  'Localitatea' => $Localitatearow1007,
                  'Adresa' => $Adresarow1007,
                  'Email' => $Emailrow1007,
                  'Telefon' => $Telefonrow1007,
                  'AdresaTransport' => $AdresaTransportrow1007,
                  'SumaTransport' => $PretTransport,
                  'CateProduse' => $IDrow1010
                 ]
  ]
regal path
#

Oh, right, you will need to include the metadata key in the same array as your amount key

harsh python
#
 ['amount' => $Price,
  'metadata' => [
                  'UserID' => $_SESSION['ID']
                
                 ]
  ]
#

Like this?

regal path
#

Yes, please give that a try

harsh python
#

Fixed it, thank you.

regal path
#

🎉