#Tony4455-payment-amount
1 messages ยท Page 1 of 1 (latest)
okay sending it to you now
these are the 3 files
checkout.js is the file which is sending the amount on click button to create.php
My guess is it's always $45.00?
yes
always 45$
transaction is working
but I want the custom amount to go there
I hope you understand what I mean
if(isset($_POST['amount'])){
$amount=$_POST['amount'];
}
else{
$amount=4500;
}
Your POST request to your PHP function to create the PI doesn't have an amount parameter, so it's setting the variable to 4500 ($45.00)
Looking at your JS file, there's both an ajax and fetch call to the same function. is this intentional?
I guess this is the one that's actually used:
const { clientSecret } = await fetch("https://leadclearcle.com/create.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items }),
}).then((r) => r.json());
So yeah, you need to pass an amount parameter in the body:
body: JSON.stringify({ amount }),
this is the default code I got it from stripe flow
const { clientSecret } = await fetch("https://leadclearcle.com/create.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items }),
}).then((r) => r.json());
so it is there
I am using this code to send the amount variable
$("#nxtbtn2").click(function(){
var amountval=$('#amount').val();
alert(amountval);
$.ajax(
{
type: "POST",
url: "https://leadclearcle.com/create.php",
data:{"amount":amountval},
cache: false,
success: function(data)
{
alert(data);
alert('sending amount');
initialize();
}
});
in js file top you will find this function
I can see that. But I don't think that ajax call is ever fired
Why is there both ajax and fetch? There's no need for both
so can you tell me how can I send the amount
can you tell me
in fetch function how to send the amount
pls help me on that
var amountval=$('#amount').val();
this is the variable
which has amount
is this the right way to send it
const items = [{ id: "xl-tshirt", amount:amountval }];
I guess:
body: JSON.stringify({ amount: ${'amount').val() }),
Your integration is really confusing as there's a mix of JS and jQuery, multiple server-side calls
i just added the ajax call rest is same as it is provided on your site
I am using this custom payment flow
provided on your site
I can see that, but both the fetch and ajax call are calling the same PHP function which is likely just confusing you
fetch is a much more versatile and modern web API, I'd stick to that
Did you try it?
yes still getting 45
not the custom amount
var amountval=$('#amount').val();
const { clientSecret } = await fetch("https://leadclearcle.com/create.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
//body: JSON.stringify({ items }),
body: JSON.stringify({ amount: amountval }),
}).then((r) => r.json());
elements = stripe.elements({ clientSecret });
const paymentElement = elements.create("payment");
paymentElement.mount("#payment-element");
}
this is the new code now
but I think I should do something on create.php also to get the value
Probably need to do something like:
$jsonStr = file_get_contents('php://input');
$jsonObj = json_decode($jsonStr);
And then in your PaymentIntent::create call:
'amount' => $jsonObj->amount
(I'm just following this: https://stripe.com/docs/payments/quickstart)
yes it worked thanks ynnoj
you are genius
I chat with other support staff also but they were not able to help me on this
but you helped me and sorted the issue right aways
thanks a lot
Sure, np!