10 Social Media Branding Strategies Every Business Should Follow

Social media can be used for a variety of purposes. Whether it’s social selling, content marketing or customer support, social media gives you the perfect opportunity to reach your target audience…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Basic guide to accepting payments with stripe

A year ago i worked on a project where i had to do payment integration, it was first time, and looking back to how i handled it, i realize i made a few mistakes on the project. This post can serve as a guide to any beginner looking to integrate payments in their application.

I’ll be using using php/Laravel and the Stripe api in this post. Even though i call this a beginner tutorial, a basic understanding of Laravel is required. The knowledge shared in this post should be transferable to other languages and frameworks too.

We are gonna create an application called grape-shop, users will be able to subscribe to our services on it. This post will cover the moment a user lands our product page to when he/she gets to the success page due to successful charge or redirect back to product page due to an unsuccessful charge.

Get full code here:

Create a new laravel 5.4 project: grape-shop and configure your database in .env file

We are gonna use a Laravel cashier to work with Stripe.

Register laravel cashier service provider. Paste line below in config/app.php

We are going to add some more columns to your users table

and also create a subscriptions table to keep all of our users subscriptions.

then … remember to have set your database in .env file

Update your user model to use the Billable trait provided by Laravel cashier

Update your .env file to contain two new configuration values needed to work with Stripe. To get this values, create or login to your stripe account, go to account settings panel, api keys tab.

Create authentication because we require users to have an account before they can subscribe to our grape-shop.

Add a new menu to app.blade.php

Update web.php to contain the 3 routes below. The first route will display the payment page, the second route will process the payment and the third route links to the success page.

Also create a dedicated controller for handling the subscriptions

Add the code below to the SubscriptionsController.php file just created. It’s an index method that returns a page where the user will make payment to subscribe.

Next, create index.blade.php file at resources/subscriptions and paste the code below into it. The code below contains two inputs (but it can contain as many as you require), phone number input and card input.

This is the recommended way to go about it, it is not advisable to post sensitive user information to Stripe from your server.

payment page

We need to create the layout file our pages are extending from. Make a new file app.blade.php in resources/subscriptions/layouts

Create stripe.css file and paste the code below in it:

In the stripe-config.js code below, when the user fills in the info requested, we collect the card data and send it to Stripe, Stripe returns a token to us, we then submit this token along with the other inputs we collected in the payment page to our server to charge the user. You’ll need to put your api key in the code for this to work.

Update SubscriptionsController.php to contain the two methods below.

In the first method, create, we are subscribing the authenticated user using the newSubscription method provided by the billable trait we added earlier to the user model. The first argument passed is the plan name, the second argument is the specific plan identifier of the plan. The create method chained will initiate the transaction and also update the database with the billing information.

If the charge is successful we are redirected to the success page, if not, we flash the message gotten from Stripe to session and return back to the payment page.

The second method, success, returns the success page for our subscription.

Finally, the success page, make a file named success.blade.php in resources/subscriptions

success page

If we choose to only charge users in our grape-shop and not subscribe them to any plan. We will import the Stripe and Charge classes.

Done!

If you have any questions or corrections, please leave a comment for me.

Gracias.

Add a comment

Related posts:

3D Logo Designing

Within this article explains about 3D logo designing techniques. I used illustrator for create the Lion face in vector in 3D Max, used dot pattern as a material for chamfer box, and V-Ray materials…

The Harvester OSINT Reconnaissance

Reconnaissance tool the harvester for OSINT gathering

Drone 17

This is a transcript of my weekly radio show, The Drone, which airs Saturdays at 7 EST on http://twitch.tv/elah806. This episode aired March 16, 2019. Good evening. I’m Alma Ramsey, something of a…