Tutorials

RSForm!Pro and Stripe - Automatically Adding the Fee

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

It's pretty effortless 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 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 this instance, setting up a complete e-commerce platform to collect payments would have been overkill, so we chose RSForm!Pro and Stripe.  However, they wanted to pass the Stripe service fee on to the customer (of course letting them know they would be paying it).  None of the plugins do this, so a little scripting was 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).

I've created a quick calculator so you can check stripe fee calculator badge

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).

I hope this helps.  The RSForm documentation isn’t all that clear with the new Stripe payment plugin.

If you need really awesome forms for your website - talk to us - we’re pretty good at it!

new-logo-medium.png
©2024 NavigateTomorrow, Inc. All rights reserved

Search