SWAuk / website

Student Windsurfing Association website
www.swa.co.uk
5 stars 3 forks source link

Creating a ticket with no add-ons causes error message at payment #216

Closed arneyjfs closed 3 years ago

arneyjfs commented 4 years ago

It seems a ticket with no add-ons is now throwing the infamous 'We have sent the wrong details to our payment provider, contact webaster@swa......' message.

If anyone has any idea what changes might have caused this please let me know.

I'm guessing it's been a little while since we've not had any merch for an event so it could date back to quite an old change.

For now i'm putting in a dietry requirement 'add-on' but not the best solution long term.

Thanks!

addshore commented 4 years ago

Hmmmm

Triggered at https://github.com/SWAuk/com_swa/blob/6c2dfab60f86190e575909a007cfc9f91143838c/src/site/controllers/ticketpurchase.php#L144-L152

I don't see anything to do with addons being added to the charge though..

https://github.com/SWAuk/com_swa/blob/6c2dfab60f86190e575909a007cfc9f91143838c/src/site/controllers/ticketpurchase.php#L112-L129

It looks like this is also logged, and there may be more info there.

https://github.com/SWAuk/com_swa/blob/6c2dfab60f86190e575909a007cfc9f91143838c/src/site/controllers/ticketpurchase.php#L147

Most of the errors in the logs around the time you filed this tiket just seem to be:

ERROR No such token: NULL Also 1 INFO Unable to find ticket with id "" - redirecting to ticketpurchase page

Do you have an exact time this happened?

oshotton commented 4 years ago

I don't see anything to do with addons being added to the charge though..

The $totalCost is the price of the ticket plus the addons.

See further up, the $totalCost is calculated from the ticket price and any addons.


I think the bug is in com_swa/src/site/views/ticketpurchase/tmpl/summary.php.

The frontend JS makes a call to Stripe with the amount to charge. It gets the amount to charge from the data-amount attribute of #stripe-button as you can see here: https://github.com/SWAuk/com_swa/blob/6c2dfab60f86190e575909a007cfc9f91143838c/src/site/views/ticketpurchase/tmpl/summary.php#L226-L228

The issue is that data-amount isn't set initially [see here] and is only set in the $totalTicketPrice function which is only called when one of the addon qtySelectors is changed [see here and here].

So, if there are no addons, there are no qtySelectors; which means they are never changed; which means $qtyChanged() and in turn $totalTicketPrice() are never called; and so the data-amount attribute is never set on #stripe-button. I imagine that the front end JS is saying to Stripe the cost is £0 and the backend PHP is saying the cost is more than that (the price of the ticket) causing Stripe to give the error that we sent the wrong information.


Setting an initial value of data-amount to $ticket->price for the #stripe-button might fix this but I haven't tested that this is all that's needed yet.

<button class="btn btn-primary btn-lg" id="stripe-button" data-amount="<?php echo $ticket->price; ?>">
    <span class="glyphicon glyphicon-shopping-cart">
        <?php echo "Pay £{$ticket->price} now!" ?>
    </span>
</button>