PHP code example of lahiru / laravel-solidgate
1. Go to this page and download the library: Download lahiru/laravel-solidgate library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lahiru / laravel-solidgate example snippets
use Lahiru\LaravelSolidGate\Facades\SolidGate;
$response = SolidGate::charge([...]);
use Lahiru\LaravelSolidGate\Contracts\SolidGateClientInterface;
public function __construct(
protected SolidGateClientInterface $solidgate
) {}
$this->solidgate->charge([...]);
$signature = SolidGate::generateSignature($jsonPayload);
use Lahiru\LaravelSolidGate\Facades\SolidGate;
use Lahiru\LaravelSolidGate\Support\Platform;
$response = SolidGate::charge([
'amount' => 10000, // $100.00 in cents
'currency' => 'USD',
'order_id' => (string) Str::uuid(),
'order_description' => 'Premium package',
'customer_email' => '[email protected] ',
'ip_address' => $request->ip(),
'platform' => Platform::WEB, // WEB | MOB | APP
'card_number' => '4111111111111111',
'card_holder' => 'John Doe',
'card_exp_month' => '12',
'card_exp_year' => 2030,
'card_cvv' => '123',
]);
if ($response->isSuccessful()) {
$status = $response->get('order.status'); // e.g. "processing", "settle_ok"
} else {
$error = $response->getErrorMessage();
}
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Lahiru\LaravelSolidGate\Contracts\SolidGateClientInterface;
use Lahiru\LaravelSolidGate\Support\Platform;
class PaymentController extends Controller
{
public function __construct(
protected SolidGateClientInterface $solidgate
) {}
public function charge(Request $request): JsonResponse
{
$response = $this->solidgate->charge([
'amount' => $request->integer('amount'),
'currency' => $request->string('currency'),
'order_id' => (string) Str::uuid(),
'order_description' => $request->string('order_description'),
'customer_email' => $request->string('customer_email'),
'ip_address' => $request->ip(),
'platform' => Platform::WEB,
'card_number' => $request->string('card_number'),
'card_holder' => $request->string('card_holder'),
'card_exp_month' => $request->string('card_exp_month'),
'card_exp_year' => $request->integer('card_exp_year'),
'card_cvv' => $request->string('card_cvv'),
]);
if (! $response->isSuccessful()) {
return response()->json([
'error' => $response->getError(),
'message' => $response->getErrorMessage(),
], 422);
}
return response()->json([
'status' => $response->get('order.status'),
'order' => $response->get('order'),
]);
}
}
use Lahiru\LaravelSolidGate\Support\PaymentType;
$response = SolidGate::recurring([
'amount' => 10000,
'currency' => 'USD',
'order_id' => (string) Str::uuid(),
'customer_email' => '[email protected] ',
'ip_address' => $request->ip(),
'payment_type' => PaymentType::RECURRING,
'recurring_token' => 'token-from-previous-payment',
]);
use Illuminate\Support\Str;
use Lahiru\LaravelSolidGate\Facades\SolidGate;
use Lahiru\LaravelSolidGate\Support\Platform;
$response = SolidGate::createPaymentPage([
'order' => [
'order_id' => (string) Str::uuid(),
'amount' => 10000,
'currency' => 'USD',
'order_description' => 'Premium package',
'customer_email' => $request->user()->email,
'ip_address' => $request->ip(),
'platform' => Platform::WEB,
'success_url' => route('checkout.success'),
'fail_url' => route('checkout.fail'),
],
]);
if (! $response->isSuccessful()) {
return back()->withErrors(['payment' => $response->getErrorMessage()]);
}
return redirect()->away($response->get('url'));
// app/Http/Controllers/PaymentPageController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Lahiru\LaravelSolidGate\Facades\SolidGate;
use Lahiru\LaravelSolidGate\Support\Platform;
class PaymentPageController extends Controller
{
public function checkout(Request $request)
{
$response = SolidGate::createPaymentPage([
'order' => [
'order_id' => (string) Str::uuid(),
'amount' => $request->integer('amount'),
'currency' => $request->string('currency'),
'order_description' => $request->string('description'),
'customer_email' => $request->user()->email,
'ip_address' => $request->ip(),
'platform' => Platform::WEB,
'success_url' => route('checkout.success'),
'fail_url' => route('checkout.fail'),
],
]);
if (! $response->isSuccessful()) {
return back()->withErrors(['payment' => $response->getErrorMessage()]);
}
return redirect()->away($response->get('url'));
}
}
// routes/web.php
Route::get('/checkout', [PaymentPageController::class, 'checkout'])->name('checkout.start');
namespace App\Services;
use Lahiru\LaravelSolidGate\Facades\SolidGate;
class SolidgatePaymentForm
{
public function merchantData(array $paymentIntent): array
{
$json = json_encode($paymentIntent, JSON_UNESCAPED_SLASHES);
return [
'merchant' => config('solidgate.public_key'),
'signature' => SolidGate::generateSignature($json),
'paymentIntent' => $this->encrypt($paymentIntent, config('solidgate.secret_key')),
];
}
private function encrypt(array $paymentIntent, string $secretKey): string
{
$payload = json_encode($paymentIntent, JSON_UNESCAPED_SLASHES);
$key = substr($secretKey, 0, 32);
$ivLen = openssl_cipher_iv_length('aes-256-cbc');
$iv = openssl_random_pseudo_bytes($ivLen);
$encrypted = openssl_encrypt($payload, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
return str_replace(['+', '/'], ['-', '_'], base64_encode($iv.$encrypted));
}
}
namespace App\Http\Controllers;
use App\Services\SolidgatePaymentForm;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Lahiru\LaravelSolidGate\Support\Platform;
class PaymentFormController extends Controller
{
public function __construct(protected SolidgatePaymentForm $paymentForm) {}
public function checkout(Request $request)
{
$paymentIntent = [
'order_id' => (string) Str::uuid(),
'amount' => 10000,
'currency' => 'USD',
'order_description' => 'Premium package',
'customer_email' => $request->user()->email,
'ip_address' => $request->ip(),
'platform' => Platform::WEB,
'success_url' => route('checkout.success'),
'fail_url' => route('checkout.fail'),
];
return view('checkout.payment-form', [
'merchantData' => $this->paymentForm->merchantData($paymentIntent),
]);
}
}
// ── Process payments ──────────────────────────────────────
SolidGate::charge([...]); // Charge card
SolidGate::auth([...]); // Authorize only (no capture)
SolidGate::recurring([...]); // Token-based charge
SolidGate::resignTransaction([...]); // Re-sign expired token
SolidGate::chargeWithGooglePay([...]);
SolidGate::chargeWithApplePay([...]);
SolidGate::createIncrementalAuth([
'order_id' => 'order-123',
'amount' => 500,
]);
// ── Post-payment operations ───────────────────────────────
SolidGate::status(['order_id' => 'order-123']);
SolidGate::getOrderStatus('order-123');
SolidGate::refund(['order_id' => 'order-123', 'amount' => 5000]);
SolidGate::void(['order_id' => 'order-123']);
SolidGate::settle(['order_id' => 'order-123', 'amount' => 10000]);
SolidGate::getArnCodes(['order_id' => 'order-123']);
// ── Refunds with reason codes ─────────────────────────────
use Lahiru\LaravelSolidGate\Support\RefundReason;
SolidGate::processFullRefund('order-123', 5000, 'card', RefundReason::REQUEST_BY_USER);
SolidGate::processPartialRefund('order-123', 2500, 'card', RefundReason::REQUEST_BY_USER);
use Lahiru\LaravelSolidGate\Support\Platform;
// Start payment (PayPal, Pix, etc.)
$response = SolidGate::initializeAlternativePayment([
'payment_method' => 'paypal-vault',
'order_id' => 'order-123',
'amount' => 1020,
'currency' => 'USD',
'customer_email' => '[email protected] ',
'order_description' => 'Premium package',
'ip_address' => $request->ip(),
'platform' => Platform::WEB,
]);
// Token-based APM recurring
SolidGate::recurringAlternativePayment([
'order_id' => 'order-123',
'amount' => 1020,
'currency' => 'USD',
'payment_method' => 'paypal-vault',
'token' => 'token-from-previous-payment',
]);
// Status, revoke, refund
SolidGate::getAlternativePaymentOrderStatus('order-123');
SolidGate::revokeRecurringToken(['token' => 'token-value']);
SolidGate::processFullRefund('order-123', 1000, 'paypal');
use Lahiru\LaravelSolidGate\Support\CancelSubscriptionReason;
// Read & update
SolidGate::retrieveSubscription($subscriptionId);
SolidGate::getSubscriptionList($customerId);
SolidGate::updateSubscription($subscriptionId, ['product_id' => $newProductId]);
SolidGate::switchSubscriptionProduct($subscriptionId, $newProductId);
SolidGate::updatePaymentMethodToken($subscriptionId, $token);
// Cancel & restore
SolidGate::cancelSubscription($subscriptionId, CancelSubscriptionReason::CANCELLATION_BY_CUSTOMER);
SolidGate::cancelSubscriptionsByCustomer($customerId, CancelSubscriptionReason::CANCELLATION_BY_CUSTOMER);
SolidGate::restoreSubscription($subscriptionId, $expireDate);
// Pause schedule
SolidGate::createSubscriptionPause($subscriptionId, '2026-12-31', '2026-06-01');
SolidGate::updateSubscriptionPause($subscriptionId, [...]);
SolidGate::removeSubscriptionPause($subscriptionId);
// Invoices & orders
SolidGate::listInvoicesBySubscription($subscriptionId);
SolidGate::listOrdersByInvoice($invoiceId);
// Products & prices
SolidGate::createProduct([...]);
SolidGate::getProductList(['filter' => ['status' => 'active']]);
SolidGate::getProduct($productId);
SolidGate::updateProduct($productId, [...]);
SolidGate::archiveProduct($productId);
SolidGate::createProductPrice($productId, [...]);
SolidGate::getProductPrices($productId);
SolidGate::calculateProductPrice(['product_id' => $productId, 'currency' => 'USD']);
// Taxes (async: create report, then download by report_id)
$response = SolidGate::createTransactionalTax([
'date_from' => '2025-01-15 11:00:00',
'date_to' => '2025-06-20 13:00:00',
]);
SolidGate::downloadTransactionalTax('TAX_250702_140728_CHECKOUT');
// Reports (async: generate, then download)
SolidGate::getCardOrdersReport(['date_from' => '...', 'date_to' => '...']);
SolidGate::getApmOrdersReport([...]);
SolidGate::getSubscriptionsReport([...]);
SolidGate::getChargebacksReport([...]);
SolidGate::downloadFinancialEntries($reportId);
SolidGate::getRoutingEventsReport([...]);
SolidGate::downloadRoutingEvents($reportId);
// Payment links (shareable URL, separate from Payment Page)
SolidGate::createPaymentLink([...]);
SolidGate::deactivatePaymentLink($linkId);
// Hosted / embedded checkout: [Checkout integrations](#checkout-integrations)
// Risks & files
SolidGate::createFraudPreventionListItems(['items' => [...]]);
SolidGate::createDisputeRepresentment([...]);
SolidGate::createFile(['file_name' => 'document.pdf', 'file_type' => 'application/pdf', 'file_size' => 1024000]);
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
$middleware->validateCsrfTokens(except: [
'solidgate/webhook',
]);
})
use Lahiru\LaravelSolidGate\Events\SolidGateWebhookReceived;
// app/Providers/EventServiceProvider.php (or AppServiceProvider)
protected $listen = [
SolidGateWebhookReceived::class => [
ProcessSolidGateWebhook::class,
],
];
// app/Listeners/ProcessSolidGateWebhook.php
public function handle(SolidGateWebhookReceived $event): void
{
match ($event->eventType) {
'card_gate.order.updated' => $this->handleOrderUpdated($event->payload),
'card_gate.chargeback.received' => $this->handleChargeback($event->payload),
default => null,
};
}
use Lahiru\LaravelSolidGate\Support\SignatureValidator;
SignatureValidator::validate(
$publicKey,
$request->getContent(),
$secretKey,
$request->header('Signature')
);
use Lahiru\LaravelSolidGate\Exceptions\SolidGateApiException;
use Lahiru\LaravelSolidGate\Exceptions\SolidGateConfigurationException;
try {
$response = SolidGate::charge([...]);
if (! $response->isSuccessful()) {
// HTTP 200 but SolidGate returned an error object
return response()->json([
'error' => $response->getError(), // ['code' => '2.01', 'messages' => [...]]
'message' => $response->getErrorMessage(), // "platform: Platform is empty or invalid"
], 422);
}
// Success
$order = $response->get('order');
$status = $response->get('order.status');
} catch (SolidGateApiException $e) {
// HTTP 4xx/5xx or connection timeout
logger()->error('SolidGate API error', [
'message' => $e->getMessage(),
'response' => $e->getResponse(),
'code' => $e->getCode(),
]);
} catch (SolidGateConfigurationException $e) {
logger()->error('SolidGate not configured', ['message' => $e->getMessage()]);
}
$response->isSuccessful(); // true only when HTTP 2xx AND no error object
$response->hasError(); // true when error object is present
$response->getError(); // raw error array
$response->getErrorMessage(); // flattened human-readable string
$response->get('order.status'); // dot-notation access
$response->toArray();
$response->toJson();
$response->statusCode;
use Lahiru\LaravelSolidGate\Support\Platform;
Platform::WEB; // Desktop browser
Platform::MOB; // Mobile browser
Platform::APP; // Native app
use Lahiru\LaravelSolidGate\Support\PaymentType;
PaymentType::ONE_CLICK; // Customer-initiated (first payment)
PaymentType::RECURRING; // Subscription MIT
PaymentType::RETRY; // Reattempt MIT
PaymentType::INSTALLMENT; // Installment MIT
PaymentType::REBILL; // Unscheduled MIT
PaymentType::MOTO; // Mail/phone order (no card_cvv)
use Lahiru\LaravelSolidGate\Support\SolidGateConstants;
SolidGateConstants::isZeroDecimalCurrency('JPY'); // true
SolidGateConstants::formatAmount(99.99, 'USD'); // 9999 (cents)
SolidGateConstants::parseAmount(9999, 'USD'); // 99.99
'platform' => Platform::WEB, // or MOB, APP
'ip_address' => '8.8.8.8', // sandbox only — use real client IP in production
if (! $response->isSuccessful()) {
logger()->warning('SolidGate validation error', [
'code' => $response->get('error.code'),
'message' => $response->getErrorMessage(),
]);
}
// Direct access when no helper exists
SolidGate::send('charge', $attributes); // pay API
SolidGate::subscriptions('subscription/status', ['subscription_id' => $id]);
SolidGate::gate('v1/status', ['order_id' => $orderId]); // gate API
bash
php artisan vendor:publish --tag=solidgate-config