Loading image

Blogs / Programming

A Step-by-Step Guide: How to Integrate CoinGate with Laravel 10

A Step-by-Step Guide: How to Integrate CoinGate with Laravel 10

  • showkat ali
  • 0 Comments
  • 2599 View

 

In this article, we will look at how integrating CoinGate into your Laravel 10 application can provide a smooth payment experience for users who prefer to pay with cryptocurrency. CoinGate lets you accept payments in Bitcoin, Ethereum, Litecoin, and other popular cryptocurrencies. In this article, we will walk you through the steps required to integrate CoinGate into your Laravel 10 app.

Prerequisites

Before we start, please ensure that you have the following conditions in place:

  1. Installed Laravel and installed coinigate.
  2. Account on CoinGate is free to use. If you do not already have one, create one. You may do so by going to the CoinGate website and signing up for an account.
  3. API Key: Once you have a CoinGate account, go to the API area in your CoinGate account dashboard to generate an API key (API Overview).

Step 1: Create a New Laravel Project

You can use Composer to create a Laravel project if you don't already have one. Run the following command in your terminal:

composer create-project --prefer-dist laravel/laravel coingate-laravel

This command will generate the coingate-laravel project.

Step 2: Install CoinGate PHP SDK

Now that you've set up your Laravel project, you need to install the CoinGate PHP SDK. You can do this using Composer. In your terminal, navigate to the root directory of your project and run:

composer require coingate/coingate-php

Composer will download and install the CoinGate PHP SDK and its dependencies.

Step 3: CoinGate configuration  (Optional)

Following that, you must configure CoinGate in your Laravel application. Open the .env  file in the root directory of your project and enter your CoinGate API credentials:

COINGATE_API_KEY=your_api_key
COINGATE_APP_ID=your_app_id
COINGATE_APP_SECRET=your_app_secret

Make sure to replace your_api_key, your_app_id, and your_app_secret with your actual CoinGate API credentials.

Step 4: Create a Controller

You may create a new Laravel controller to manage CoinGate transactions. To create a new controller, use the following command:

php artisan make:controller CoinGateController

This command will create a new file named CoinGateController.php in the app/Http/Controllers directory.

Step 5:Use CoinGate Payment Logic.

use CoinGate\CoinGate;

class CoinGateController extends Controller
{
    public function createPayment()
    {
        $order_id = uniqid();
        $description = "Payment for order #$order_id";
        $amount = 100.00; // Replace with your desired amount
        $currency = 'USD'; // Replace with your desired currency

        // if you can secure the api key then get from .env 
        $client = new Client('kUgJ_pWh5fpMDyzxCnvWZhxCDt2SriVw_zeGEtbY', true); 
        $token = hash('sha512', 'coingate' . rand());

        $params = array(
            'order_id'          =>  $order_id,
            'price_amount'      => $amount ,
            'price_currency'    =>$currency ,
            'receive_currency'  => 'EUR',
            'callback_url'      => 'http://localhost:8000/coin-gate/callback?token=' . $token,
            'cancel_url'        => 'http://localhost:8000/coin-gate/cancel',
            'success_url'       => 'http://localhost:8000/coin-gate/success',
            'title'             => 'Order #112',
            'description'       => $description ,
        );
        $order = $client->order->create($params);
        return redirect($order->payment_url);
    }

    public function handleCallback()
    {
        // Handle the CoinGate callback here
    }
}

In this example, the createPayment method initiates a payment request, and the handleCallback method handles the CoinGate callback.

Step 6: Define Routes

Finally, routes for your CoinGate payment and callback destinations must be defined. Add the following kinds of routes to the routes/web.php file:

Route::get('/singlePayment',[CoinGateController::class,'singlePayment'])->middleware(['auth']);
Route::get('/coin-gate/callback/{?token}',[CoinGateController::class,'callback'])->middleware(['auth']);
Route::get('/coin-gate/cancel',[CoinGateController::class,'cancel'])->middleware(['auth']);
Route::get('/coin-gate/success',[CoinGateController::class,'success'])->middleware(['auth']);
Route::get('/coin-gate/fail',[CoinGateController::class,'fail'])->middleware(['auth']);

Conclusion

Congratulations! You've successfully integrated CoinGate with your Laravel operationallowing you to accept cryptocurrency payments. With this integration, you can tap into the world of cryptocurrencies and offer your guests more payment options.

Flash back to test your integration completely and follow CoinGate's attestation for fresh features and customization optionsHappy coding!

 

 

How to Integrate paypal with Laravel 10: Click here 

  • Programming
showkat ali Author

showkat ali

Greetings, I'm a passionate full-stack developer and entrepreneur based in Pakistan. I specialize in PHP, Laravel, React.js, Node.js, JavaScript, and Python. I own interviewsolutionshub.com, where I share tech tutorials, tips, and interview questions. I'm a firm believer in hard work and consistency. Welcome to interviewsolutionshub.com, your source for tech insights and career guidance

0 Comments

Post Comment

Recent Blogs

Recent posts form our Blog

Understanding Recursive Functions in Python: A Deep Dive

Understanding Recursive Functions in Python: A Deep Dive

showkat ali
/
Programming

Read More
Using Multiple Select as Count in the Select2 Search Box

Using Multiple Select as Count in the Select2 Search Box

showkat ali
/
Programming

Read More
How to Create Structuring React Projects: From Beginner to Advanced

How to Create Structuring React Projects: From Beginner to Advanced

showkat ali
/

Read More
How to use Select2 Multi-Checkboxes using JavaScript

How to use Select2 Multi-Checkboxes using JavaScript

showkat ali
/
Programming

Read More
[FIXED]  target class [role] does not exist in  laravel 11

[FIXED] target class [role] does not exist in laravel 11

showkat ali
/
Programming

Read More
[SOLVED] CORS ISSUE WITH REACT AND LARAVEL 10 API

[SOLVED] CORS ISSUE WITH REACT AND LARAVEL 10 API

showkat ali
/
Programming

Read More