Payment Gateway Integration With Laravel 5.8

I can teach you how you can integrate with Laravel 5.8In this tutorial i will use Authorize sandbox account.

So lets begin with a new installation of Laravel 5.8:

composer create-project --prefer-dist laravel/laravel authorize_payment_gateway "5.8.*"

Open your composer.json file and add the following codes in require:

  "require": {
  "php": ">=5.6",
  "authorizenet/authorizenet": "2.0.0"

Run the following command in your console terminal:

composer update


Now, you have to get your API Login ID and transaction key from . For this purpose, you have to first sign up at  Create  Sandbox Account Authorize site and then sign in. Then goto Account ->Security Settings -> API Credentials & Keys. You can see API Login ID there and for Transaction Key. Create New Key(s) then they will send pin code on your email, copy pin from email and paste pin there then you will get your transaction key.

Now back to your laravel project.

Now create a new controller with command:

php artisan make:controller AuthorizeCheckoutController

Your Authorize Checkout Controller will be as below:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
class AuthorizeCheckoutController extends Controller
    public function index()
        return view('authorize');
    public function chargeCreditCard(Request $request)

        // Common setup for API credentials
 $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();

        $refId = 'ref'.time();
// Create the payment data for a credit card
        $creditCard = new AnetAPI\CreditCardType();
//         $creditCard->setExpirationDate( "2038-12");
        $paymentOne = new AnetAPI\PaymentType();
// Create a transaction
        $transactionRequestType = new AnetAPI\TransactionRequestType();
//        $transactionRequestType->setAmount('60');
        $request = new AnetAPI\CreateTransactionRequest();
        $request->setRefId( $refId);
        $controller = new AnetController\CreateTransactionController($request);
        $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);

        if ($response != null)
            $tresponse = $response->getTransactionResponse();
            if (($tresponse != null) && ($tresponse->getResponseCode()=="1"))
                echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
                echo "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "\n";
              //here save data in your database


                echo "Charge Credit Card ERROR :  Invalid response\n";
            echo  "Charge Credit Card Null response returned";

        return redirect('/');

Now, open your routes/web.php file:

Route::get('/checkout', 'AuthorizeCheckoutController@index'); 
Route::post('/checkout', 'AuthorizeCheckoutController@chargeCreditCard'); 

Create a new view blade file in resources/views/authorize.blade.php. Your authorize.blade.php file will be like below:

<!DOCTYPE html>
<html lang="en">
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
<div class="container">
    <div class="row">
        <div class="content">
            <h1 >Laravel Authorize Payment Integration</h1><br>
            <form class="" action="{{ url('/checkout') }}" method="post">

                <h3>Credit Card Information</h3>
                <div class="form-group">
                    <label for="cnumber">Card Number</label>
                    <input type="number" class="form-control" id="cnumber" name="cnumber" placeholder="Enter Card Number eg.4111111111111111">
                <div class="form-group">
                    <label for="card-expiry-month-year">Expiration Month and Year</label>
                    <input type="month" name="card_expiry_month_year" class="form-control" required>
                <div class="form-group">
                    <label for="ccode">Card Code</label>
                    <input type="number" class="form-control" name="code" placeholder="Enter Card Code">
                <div class="form-group">
                    <label for="amount">Amount</label>
                    <input type="number" class="form-control"  name="amount" placeholder="Enter Amount" >
                {{ csrf_field() }}
                <button type="submit" class="btn btn-success">Confirm</button>


Leave a Reply

Your email address will not be published. Required fields are marked *