'Stripe PHP integration with URL query as price (site.com/?price=15)

I've recently purchased a simple PHP script to allow payments using Stripe. For legal purposes I cannot show much of the code here. I hope a solution can be found with the minimum of information I'll provide.

First of all, the script gets the price/amount to be paid from a constant added in the header

$itemPrice = 10;

It works perfectly fine with this and processes $10 payments as it should. However, I want to make it capture the price from the URL query, so I can use the same script to process other items as well. So I've added this instead of the above (top of the .php file):

if(isset($_GET['p'])) {
$itemPrice = intval($_GET['p']);
} else {  $itemPrice = 10; };

Now when I visit site.com/?p=15 I can see the 15 in the page, echoed.

echo $itemPrice;

But when I continue with the Stripe payment, in the Stripe logs there's no 15$ payment, but the same $10. Somehow it still uses $itemPrice = 10; even if it has a p query.

I've also tried to set $itemPrice = 0 in the else above, but when I do this the Stripe payment form doesn't even load.

Another strange behavior, looking at the Stripe logs, is that no matter what value the p query has, there is always a payment processed of $10, and 1-3 others failed. Reason is that 'the customer has not entered their payment method'. enter image description here

Anyone knows how to fix this, I appreciate any suggestion. And please, don't write a novel, such as the people on Quora :) The longer the solution, the harder to implement.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source