How to get a dynamic attribute value into the create payment intent amount field

I am with stripe and having issues getting a dynamic value into the “Amount” field within the Stripe Create Payment Intent. I am passing the data value from one page to another using a Session Variable called session_order_total. I can recall the variable at anytime on the client side to prove it has the correct value. On the server side I cannot retrieve the value of the session variable and place it into the Amount field with the Stripe Create Payment Intent area. I set a variable called order_total under Input, $_SESSION area and when applied to the Amount field there is no value. I also tried {{$_GET.session.order_total}} and the amount field it still has not value. Can someone help with the right solution?

I am working on Windows 10 with the latest release of Wappler 3.9.5.The code is in PHP.

One other problem, how to recall the the values from stripe to apply to my database table? I have followed the Stripe guides Teodor has made for Stripe checkout and webhooks. I have the Stripe_Webhooks window open on the bottom of the screen and can see that there are indications of payment_intent_create, payment_intent.suceeded and chrage.suceeded. My question is how do I get the data so the I can place it into my data tables.

Any help would be greatly appreciated. Thank you. Jim

The client session cannot be used on the server. You need to have a form with a hidden text field that carries the value of the session. On the server, you can then use the $_POST’ed value

Having said that, this method is open to tampering. When you open the Developer panel, under Session Storage (in the example: Local Storage), anybody can change the amount in the session.

The best way is to verify the amounts on the server.

1 Like

Ben;
Thanks for your suggestion. I tried that but still the value for the Amount field is missing. Take a look at the pictures on the client and server side. I called the field in the form order_total. Thanks Jim

Simple reasoning, something is not right between the form and what is expected by Stripe. Thinking aloud:

  1. Stripe expects a whole number, i.e. not text.
  2. It would be helpful if i saw the code for the form

I went back to be sure that the value for order_total is a number. What I did in the code was to declare a variable order_total, set as the following . Simply takes the sum of the quantity*product_price for all the items in the cart. The session variable then gets set with the value of the order_value
session_order_total.set(‘order_total’,order_total.value)
These values were declared on the cart page. Next page, the shipping and payment page, the order total was derived from the session variable.

It is then placed in the form with the following code:

                            <label for="inp_order_total">Order Total (Cents)</label>

                            <input type="number" class="form-control" id="inp_order_total" name="order_total" aria-describedby="input2_help" readonly="true" dmx-bind:value="session_variable.data.order_total">

                        </div>

This value then gets called on the server side and placed into the Amount field within the Stripe Payment Intent. Please let me know if there is anything else you need. Thanks - Jim

I have taken the values directly from the datastore as in

<input dmx-bind:value="dsCart.data.sum('product_price * quantity * 100')" name="totalAmount" id="totalAmount" type="hidden">

Suddenly realise, if you have 50 as the amount, this translates to 50 cents. Stripe accepts amounts of 100 cents and over. If you meant $50, then the amount needs to be 5000 cents.

You may have noticed that I multiplied my sum by 100 to compensate.

I too thought of the minimum value being over one dollar and have tried a much larger value as seen in the latest screenshot. I tried putting the exact same code in the total value field in form you see but that total was calculated on the previous page. That is the reason I set it to a session variable which can easily be recalled. You can see that the value of the new variable is set in the form. Any other ideas? Thanks - Jim

I am still having problems getting a dynamic value into the Payment Intent field using Stripe. I have set the order_total variable as seen in the Order Total box within the form it shows a large value of 1500. On the Server side in Stripe Create Payment Intent field the value entered is $_POST.order_total. On the client side order_total is set to the Session variable order_total from the previous page. If I place a number value into Payment Intent field the application works. I have included 4 snapshots to show the server side and the client side with the variable order_total being set and used.


shipping_payment
Please help. I need to get this corrected before it goes live. Thanks - Jim

Have you ever figure out your issue?
FYI, the dynamic value on the create payment intent component doe work when the dynamic data is fetched from a database (our case). Maybe Stripe won’t allow your type of dynamic data fetching because it is not secure? We’re total newbie here with Stripe so just thinking out loud…

I just noticed that there is something flagging as an error in your code. Maybe an unclosed tag or duplicated id. It would be worth checking that it isn’t causing the page structure to be incorrect:
image