Airwallex Payment Gateway Setup and Integration with Laravel Application

Airwallex Payment Gateway Setup and Integration with Laravel Application

Airwallex Payment Gateway: A Powerful Solution for Laravel Applications

Airwallex is a leading global financial technology platform that offers a robust payment gateway solution. Integrating Airwallex with your Laravel application can provide your users a seamless and efficient payment experience.

Benefits of Airwallex Integration:

  • Global Reach: Accept payments from customers worldwide with support for multiple currencies and payment methods.
  • Competitive Pricing: Benefit from transparent pricing and competitive fees.
  • Easy Integration: Integrate Airwallex into your Laravel application using its well-documented API and SDK.
  • Enhanced Security: Protect your customers’ data with Airwallex’s advanced security measures and compliance with industry standards.
  • Scalability: Handle growing transaction volumes and accommodate future business expansion.


To integrate Airwallex as a payment gateway into a Laravel application, follow these steps:

Install Airwallex PHP SDK

  1. Create an Airwallex Account: Sign up for an Airwallex account and obtain your API credentials.
  2. Use Composer to install the official Airwallex SDK for Laravel:

composer require airwallex/airwallex-php        

Get API Credentials

Sign up for an Airwallex account and retrieve your API Key and Client Secret from the dashboard.

Configure the SDK: Set your API credentials in your Laravel configuration file.

AIRWALLEX_API_KEY=your_api_key
AIRWALLEX_SECRET_KEY=your_secret_key
AIRWALLEX_ENV=sandbox_or_production        

Create Payment Requests: Use the Airwallex SDK to create payment requests with the necessary details (e.g., amount, currency, customer information).

Handle Payment Responses: Implement logic to handle successful and failed payment responses, update your database accordingly, and provide appropriate feedback to the user.

Create a Service Provider(Optional): You can create a Laravel service provider to handle the initialization of the Airwallex SDK.

php artisan make:provider AirwallexServiceProvider        

In the AirwallexServiceProvider.php:

<?php

namespace App\Providers;

use Airwallex\Airwallex;
use Illuminate\Support\ServiceProvider;

class AirwallexServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton(Airwallex::class, function ($app) {
            return new Airwallex([
                'api_key' => env('AIRWALLEX_API_KEY'),
                'secret_key' => env('AIRWALLEX_SECRET_KEY'),
                'environment' => env('AIRWALLEX_ENV', 'sandbox')
            ]);
        });
    }
}        

Now, you can create controllers and routes to handle payment processing.

Create a Controller:

php artisan make:controller PaymentController        

Inside PaymentController.php

<?php

namespace App\Http\Controllers;

use Airwallex\Airwallex;
use Illuminate\Http\Request;

class PaymentController extends Controller
{
    protected $airwallex;

    public function __construct(Airwallex $airwallex)
    {
        $this->airwallex = $airwallex;
    }

    public function createPaymentIntent(Request $request)
    {
        try {
            $paymentIntent = $this->airwallex->payment_intents->create([
                'amount' => $request->amount,
                'currency' => $request->currency,
                'merchant_order_id' => uniqid(),
                'return_url' => url('/payment/callback'),
            ]);
            
            return response()->json($paymentIntent);
        } catch (\Exception $e) {
            return response()->json(['error' => $e->getMessage()]);
        }
    }

    public function paymentCallback(Request $request)
    {
        // Handle callback after payment
    }
}        

Define Routes

In routes/web.php

use App\Http\Controllers\PaymentController;

Route::post('/payment/create', [PaymentController::class, 'createPaymentIntent']);
Route::get('/payment/callback', [PaymentController::class, 'paymentCallback']);        

Example Code Snippet:

use Airwallex\Client;

// Create an Airwallex client instance
$client = new Client('YOUR_API_KEY', 'YOUR_API_SECRET');

// Create a payment request
$request = [
    'amount' => 100,
    'currency' => 'USD',
    'customer' => [
        'name' => 'John Doe',
        'email' => '[email protected]',
    ],
    // ... other payment details
];

// Make the payment request
$response = $client->request('payments', 'create', $request);

// Handle the response
if ($response->isSuccess()) {
    // Payment was successful
} else {
    // Handle payment failure
}        

Test the Integration:

  • Ensure your environment variables are correctly set for sandbox mode.
  • Use tools like Postman or cURL to test the payment creation process.
  • Monitor responses and logs to debug any issues.

Move to Production:

Once testing is successful, switch to production by updating the .env with production credentials and changing the AIRWALLEX_ENV to production.


By following these steps and considering the additional factors, you can successfully integrate Airwallex into your Laravel application and provide a seamless payment experience for your users.

Hiring an RND Experts Team for Complex Integrations:

For complex integrations or organizations with limited in-house expertise, consider hiring an RND Experts team specializing in payment gateway integrations. They can provide:

  • Deep Expertise: Leverage their experience and knowledge to streamline the integration process and address potential challenges.
  • Customized Solutions: Tailor the integration to your specific requirements and business goals.
  • Ongoing Support: Receive ongoing support and maintenance for the integrated solution.

要查看或添加评论,请登录