Accepting Credit Cards on your Website
If you're running a business and have been wondering "Can I accept credit cards on my site?" the answer is yes!
It's easier than ever to set up e-commerce for your website. All you need is something that can process payments, like Stripe or PayPal, and then a way to sell your product/service in exchange for those payments.
While there are many payment gateways and processors out there, the two most popular are Stripe and PayPal. That said, the pricing model for processing payments varies greatly; Stripe's pricing is very inexpensive for small transactions while PayPal's is more expensive. In this article I'll illustrate how to accept credit cards on your site with both.
I'll demonstrate how to accept payments on your own website with Stripe as your payment processor then show how to use this same method to accept payments through PayPal as well, along with some other tips and tricks. Let's get started!
Stripe vs. PayPal Payments
Stripe Stripe is a newer startup and one of the biggest names in the e-commerce game right now. They've become an extremely popular payment processor for smaller businesses and individuals as it's an easy way to start accepting payments online without much legwork.
Stripe offers three tiers of pricing depending on your sales volume, which is a really attractive thing: charge less for small transactions and more for larger ones with no setup fees or expensive extras at any tier. They have a full-featured API that allows you to do things like get information about your customers through their Dashboard or even create custom forms for your site that ease the process on mobile devices.
Paypal With PayPal, a merchant can accept payment by credit cards, debit cards or bank account balances. It's perhaps the most ubiquitous way for people to send and receive payments over the internet and while it's not a product that I would recommend for selling products at your site, I do want to illustrate how to use PayPal along with Stripe so you have both options.
PayPal offers two pricing models: one fee-based pricing plan and one fee-free plan with higher transaction fees. PayPal charges 2.9% plus a $0.30 per transaction fee with a minimum fee of $0.30 per ACH transaction. There is also an annual fee of $30 for basic accounts (these fees and services are subject to change). PayPal has two great features: the ability to accept payments with credit cards online and the ability to receive payments directly into your bank account.
PayPal's implementation is a lot more involved than working with Stripe, but it can be done and I'll show you how. Let's look at setting up Stripe first though.
Stripe Setup: A Simple Example
If you haven't worked with Stripe before, it's really easy to set up on your website; just generate an API key on their settings page, then create an account and enter your banking information. (Note: If you're using this to sell products, like a product for sale on your site, make sure you select the "Deposit" payment option in the credit card section of Stripe's settings instead of "Pay now" – this will give you a full description and total costs of each item when the sale is complete.)
Once you've set up Stripe, there are just a few small steps to that process. First is creating a stripe.js file on your website. This will be something like this:
function stripe_init () { stripe . setPublishableKey ( 'pk_test_YYYY-MM-DD' ); /* Publishable Key can be found on the settings page at stripe.com/account/#publishablekey */ stripe . setAccount ( 'pk_test_YYYY-MM-DD' ); /* Account ID can be found on the settings page at stripe.com/account */ } ( function (){ var element = document . createElement ( 'script' ); element . src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js' ; var f = document . getElementsByTagName ( 'script' ) [ 0 ]; f . parentNode . insertBefore ( element , f ); })();
Next, add an HTML form within the body of your site with a hidden field input that retrieves the results of the Stripe function you just created. This will look like this:
<form action="/test" method="post"> <input type= "hidden" name="stripeToken" value=" {{ form_token }} "> <!-- Put your products here --> </form>
Finally, you'll need to make sure that Stripe is included on your website and connected to your form using jQuery like so:
$( "#stripe-container" ). append ( '<script> $(document).ready(function() { var stripe = Stripe(); $.stripe( "test" , stripe); }); </script>' );
With all of that setup complete, your code will now be working with Stripe!
If you're looking for a way to accept payments on your own website with Stripe without having to set up an account or pay fees, check out this tutorial by Wix.com: How To Use Shopify Payments With Stripe Payment Gateway .
Getting Started With PayPal: A Simple Example
All you'll need for PayPal is a basic PayPal merchant account and a few simple steps to get started. Once you've confirmed your account, you'll be able to create a test file that can then be used to test out different e-commerce options.
First, install the PayPal Merchant SDK for JavaScript in your project then run the following code:
<script src="http://js.paypal.com/v2/ authorized=false"></script>
Next, include this script and some basic CSS on your page:
<style> </style> <script> $(document).ready(function () { const stripe = Stripe(); $.extend( 'paypal' , { stripe: stripe }).load( 'paypal.js' ); }); </script>
Finally, create a simple HTML form with a hidden field that retrieves the results of the PayPal function we just created. To do this, let's update our code from above to look like this:
<form action="/test" method="post"> <input type= "hidden" value=" {{ form_token }} " name="stripeToken" id="stripeToken"> <!-- Put your products here --> </form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1 /jquery.min.
Conclusion
Both Stripe and PayPal are good choices for accepting online payments, but I think that Stripe will be most appealing to the end user. As a developer, I've found PayPal to be more convoluted: it required me to create an account and use an API key (using Stripe was much easier). Also, they only offered one pricing model at the time of writing this article, whereas there are three different pricing models available with Stripe.
Pricing: Price is based on transaction volume, which is determined by the number of active customers per month; $0.15 per million transactions, $0.25 per million transactions and $0.50 per million transactions respectively.