Airwallex Payment Gateway Setup and Integration with Laravel Application
Rajeev Kumar
CEO & Founder at RND Experts | LMS/CRM Development | eCommerce store | Custom Application using Laravel, NodeJs
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:
To integrate Airwallex as a payment gateway into a Laravel application, follow these steps:
Install Airwallex PHP SDK
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:
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: