How to update Stripe plugin with value (WORKAROUND)

ontarget

Active Member
Hi
On the stripe plugin is there any way of getting Price tab >Cost to change value via ajax?
I have a "booking id" field element which creates an amount via a calc element - i need the stripe popup to take the value of the calc element
I tried setting
Eval to Element > Yes > Selected my Calc Element but this has no effect.
If i set Eval to Yes and enter the php below the stripe value only updates on submit ( which is too late !)


PHP:
$bookingid = '{aaa_deposits___enter_booking_id}';

// Get the db object
$db =JFactory::getDbo();
// Quote the values for security reasons:
$bookingid = $db->quote($bookingid);
// Build the query
$query = $db->getQuery(true);

$query->select('deposit_amount')
->from('aaa_bookings')
->where('booking_id = ' . $bookingid);
$db->setQuery($query);
// Run the query
$found = $db->loadResult();

return $found;

UPDATE MY WORK AROUND!
To get this working I created a calc element which generated a URL containing my values

PHP:
$fullUrl = 'http://xxxx.com/index.php?option=com_fabrik&view=form&formid=2' .
'&aaa_deposits___enter_booking_id='. urlencode('{aaa_bookings___unique_id}') .
'&aaa_deposits___deposit_amount=' . urlencode('{aaa_bookings___deposit_amount}');
return $fullUrl;
I could then return the url as a bitly link

In the stripe plugin i set Cost >Eval = Yes then
PHP:
return '{aaa_deposits___deposit_amount}';

The stripe plugin is now prepopulated with my value

When a successful payment was made i have a php onformsubmit which updates the booking table with a paid value
PHP:
$uniqueid = '{aaa_deposits___enter_booking_id}';
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
    ->update($myDb->quoteName('aaa_bookings'))
    ->set('deposit_paid =' . 1)
    ->where('unique_id = ' . $myDb->quote($uniqueid));

$myDb->setQuery($myQuery);

try {
  $result = $myDb->execute();

}
catch (Exception $e) {

}
 
Last edited:
AAARGGH it was working so well
I'm trying to pre-populate The stripe Pop upWith a prefilled valueUsing a URL

If you hit this link
http://finelines.pro/index.php?opti...2f62ae00326&aaa_deposits___deposit_amount=377
It should have prepopulated the stripe popup Box.However now it is returning The following error
Some parts of your form have not been correctly filled in
There was an internal error reported by the Stripe payment processing servers, please try again later.

It seems The "purchase for" field was not populated quickly enough for stripe to take account of it.
If I refresh the page It seems to pre-populate the purchase for fieldWith my valuesAnd then pop-up works againIt's very frustrating
Can anyone suggest any solution?
 
Have you tried using the 'product table' feature?

I'm not entirely clear on what you are doing, but it looks like you are using an element on the form to specify a booking ID (FK to a booking table), and getting an amount from a field on that table. Which is what the "product table" does. It'll watch whatever you designate as the "Product Element", and when it changes, it fires off an AJAX call to look up a value in the table you designate, using the Product Element's value as the row to load the Product Cost from. It updates the cost information at the bottom of the form, the amount specified in the Stripe popup, etc.

If your copy of the plugin doesn't have the Product Table section in the settings, update from github. I added it a month or two ago.

-- hugh
 
Cool thanks For the fast reply,
There is an enquiry form which creates a deposit amount aaa_bookings___deposit_amount and unique id aaa_bookings___unique_id.
The site owner that accepts the enquiry or rejects it.
If the enquiry is accepted the following url is generated $fullUrl='http://xxxx.com/index.php?option=com_fabrik&view=form&formid=2'.
'&aaa_deposits___enter_booking_id='.urlencode('{aaa_bookings___unique_id}').
'&aaa_deposits___deposit_amount='.urlencode('{aaa_bookings___deposit_amount}');
return$fullUrl;

When the user goes to the form Via the URL Then the values are pre-populated For the stripe plugin
In the stripe plugin i set Cost >Eval = Yes then
PHP:
return '{aaa_deposits___deposit_amount}';
(except it dont work no more!!)
I will explore your product table option
 
Ok thanks Hugh
I'm getting placesI updated the product tab in stripe plugin With the values that match.
If you enter The following deposit ID 5b2f62ae00326 Into the deposit ID fieldThenThe correct value is populatedHowever i am still getting stripe error on save

Here is a link to test the form
http://finelines.pro/index.php/book/test-deposit
 
Sorry I eat my hat - that is now working perfectly it seems! Thanks again Hugh for pointing me in the right direction
 
Having eaten my hat unfortunately it is a little temperamental.
It will show the error on first submission then on the second time you hit submit the stripe popup triggers correctly
Can you please test too ? Thanks
Screen_Shot_2018-07-05_at_22.17.23.png


If you enter The following deposit ID 5b2f62ae00326 Into the deposit ID field
http://finelines.pro/index.php/book/test-deposit
 
Two things ...

1) I can't enter anything into the Deposit ID, it's a read only field.

2) I really can't do hands-on support for the Stripe plugin in Community. I've got about 200 hours work in that plugin so far, and really need people to subscribe if they want support on it.

-- hugh
 
OK, yeah, that's a timing issue with loading the Stripe JS. They don't let you host it locally, it has to be loaded from their site, which makes it problematic to load with our requirejs module dependency handling. So we have to load it explicitly, and there's a chance the form init code will try and use it, before it's ready. I occasionally see this issue on my own sites, but very rare. Not sure why your site is getting it every first page load (after that it's cached in the browser for a while).

If you open dev tools in your browser, you'll see an error about StripeCheckout being null. So when you submit the form, the Stripe token hasn't been loaded, so the submission fails when it tries to talk to Stripe.

I can probably work round it, but it will take some effort. I just spent half an hour trying to figure out how to convince the requirejs module loader to load it, but so far no luck.

-- hugh
 
ok cool i thought it was something like that.
I tried a js to reload the page after load in a hope it would trigger the stripe stuff -but that didnt seem to work
<script>window.onload = function() {
if(!window.location.hash) {
window.location = window.location + '#loaded';
window.location.reload();
}
}
</script>
 
OK, I think I'm close to a fix. So if you want to take out a sub, we can test some new code on your site.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top