| Joomla

How to Automatically Add Stripe's Fee Using RSForm!Pro

It's fairly easy to create a simple payment system using RSForm!Pro in Joomla!.  When you combine it with Stripe as the payment processor, you get a really great way to collect payments on your website.  In this tutorial, I'm going to demonstrate how to automatically add the Stripe payment fee (currently 2.9% + $0.30 per transaction) into the amount that is sent to Stripe and passed on to the consumer.

Sometimes a client wants something that isn't "out-of-the-box".  In one instance, setting up a complete e-commerce platform to collect payments would have been overkill, so another optionis RSForm!Pro and Stripe.  However, if they want to pass the Stripe service fee on to the customer (of course letting them know they would be paying it) there's a bit of a trick.  None of the plugins can do this by default, so a little scripting is in order.

The trick here is you can't just add 2.9% + $0.30 cents to the total.  Stripe actually works backward!  Their rule is: "We're going to take 2.9% + $0.30 away from whatever you send us." If you want $100 from Stripe, the total isn't $103.20.  

The correct calculation is (100 + .3) / (1-(0.029)) - this adds the $0.30 then adds the 2.9% that will be taken away from the total to give you $100.00.  The total to charge is actually $103.30.

There are now THREE different configuration options for the Stripe Plugin.

The old way of updating the array that’s sent to Stripe DOESN’T work with the new API.

Old Way

In the "Script called on Form Process" box - we USED to enter the following:

$stripe = RSFormProStripe::getInstance();
$stripe->args['amount'] = $amount;

When the payment is sent - this last line replaces the amount with your newly calculated total.

The above script WILL NOT WORK if you’re using one of the new API methods with Stripe.  You can’t actually update the amount field - only some of the comments, etc: (https://www.rsjoomla.com/support/documentation/rsform-pro/plugins-and-modules/plugin-stripe-create-custom-order-forms.html).

Better Way

So the code is basically the same, but you have to update the Total field before it’s sent to Stripe. (This works with all three Stripe configurations - so it is the preferred method).

$payment = $_POST['form']['total'];
$total = ($payment + 0.30) / (1 - 0.029);
$total = round($total,2);
$_POST['form']['rsfp_Total'] = $total;

Since you’re updating a field that will get processed before it’s sent to Stripe, you no longer have to multiply by 100 to move the decimal over for Stripe to use it.

The documentation for this field is https://www.rsjoomla.com/blog/view/196-updated-payment-package-for-rsformpro.html (at the bottom).

 

Learn more about RSForm!Pro in our online course!

 


About the author

Rod holds two masters degrees and has been training people how to do "things" for over 25 years. Originally from Australia, he grew up in Canada and now resides just outside Cincinnati, Ohio.