plisio/plisio-sdk-laravel
Laravel SDK for Plisio crypto payments. Install via Composer, publish config, set your API key, then create invoices and query shop info, balances, and enabled cryptocurrencies with simple Payment gateway calls.
Installation
composer require plisio/plisio-sdk-laravel
Publish the config file:
php artisan vendor:publish --provider="Plisio\PlisioSdkLaravel\PlisioServiceProvider"
Configuration
Edit .env with your Plisio API credentials:
PLISIO_API_KEY=your_api_key_here
PLISIO_SECRET_KEY=your_secret_key_here
PLISIO_PROJECT_ID=your_project_id
First Use Case: Creating a Payment
use Plisio\PlisioSdkLaravel\Facades\Plisio;
$payment = Plisio::createPayment([
'amount' => 1000, // in minor units (e.g., cents)
'currency' => 'USD',
'description' => 'Order #12345',
'customer' => [
'email' => 'user@example.com',
'phone' => '+1234567890',
],
]);
Where to Look First
Plisio facade for quick access to all methods.PlisioService for direct instantiation.$payment = Plisio::createPayment($data);
$confirmed = Plisio::confirmPayment($payment->id);
route:web middleware and HasApiTokens for secure webhook endpoints:
Route::post('/plisio-webhook', [PaymentWebhookController::class, 'handle']);
// PaymentWebhookController.php
public function handle(Request $request)
{
$event = Plisio::parseWebhook($request->getContent());
// Process event (e.g., update order status)
}
$subscription = Plisio::createSubscription([
'amount' => 500,
'currency' => 'USD',
'interval' => 'month',
'customer' => [...],
]);
Plisio::pauseSubscription($subscription->id);
Plisio::resumeSubscription($subscription->id);
Plisio::createRefund($payment->id, [
'amount' => 500,
'reason' => 'Customer requested refund',
]);
$dispute = Plisio::createDispute($payment->id, [
'amount' => 1000,
'evidence' => ['document1.pdf', 'document2.pdf'],
]);
$customer = Plisio::getCustomer($customerId);
Plisio::updateCustomer($customerId, ['email' => 'new@example.com']);
event(new PaymentCreated($payment));
RefundJob::dispatch($payment->id, $amount);
Laravel Cashier Alternative: Use Plisio for non-Stripe regions or specific use cases (e.g., crypto payments):
// In a service class
public function subscribeUser(User $user)
{
$subscription = Plisio::createSubscription([
'customer' => ['email' => $user->email],
'amount' => $user->plan->price,
// ...
]);
$user->update(['plisio_subscription_id' => $subscription->id]);
}
Testing:
Use Plisio’s sandbox mode (configured in .env):
PLISIO_ENVIRONMENT=sandbox
Mock responses in PHPUnit:
$this->mock(Plisio::class)->shouldReceive('createPayment')->andReturn($mockPayment);
Logging:
Enable debug logging in config/plisio.php:
'debug' => env('PLISIO_DEBUG', false),
Log raw API responses for debugging:
Plisio::setLogger(new SingleHandleMonologLogger(Storage::path('logs/plisio.log')));
API Key Exposure:
.env to version control. Use Laravel’s .env.example for templates.trustedproxy middleware.Idempotency:
$payment = Plisio::createPayment($data, [
'idempotency_key' => 'unique_key_123',
]);
Webhook Verification:
$isValid = Plisio::verifyWebhook($request->header('X-Plisio-Signature'), $request->getContent());
Rate Limiting:
$customer = Cache::remember("plisio_customer_{$id}", now()->addHours(1), fn() =>
Plisio::getCustomer($id)
);
Currency and Amount Handling:
1000 for $10.00 USD). Validate inputs:
if (!is_numeric($request->amount) || $request->amount <= 0) {
throw new \InvalidArgumentException('Invalid amount');
}
Async Operations:
$payout = Plisio::createPayout($data);
while ($payout->status === 'pending') {
$payout = Plisio::getPayout($payout->id);
sleep(5);
}
Enable Debug Mode:
Set PLISIO_DEBUG=true in .env to log raw API requests/responses to storage/logs/plisio.log.
Inspect HTTP Clients: The SDK uses Guzzle under the hood. Override the client for debugging:
Plisio::setClient(new \GuzzleHttp\Client([
'debug' => fopen('debug.log', 'w'),
]));
Common Errors:
401 Unauthorized: Verify PLISIO_API_KEY and PLISIO_SECRET_KEY.400 Bad Request: Validate payload structure (e.g., required fields like amount or currency).429 Too Many Requests: Implement retries with exponential backoff:
use Plisio\PlisioSdkLaravel\Exceptions\RateLimitExceededException;
try {
$payment = Plisio::createPayment($data);
} catch (RateLimitExceededException $e) {
sleep(10); // Wait and retry
retry();
}
Custom API Endpoints:
Extend the SDK by adding methods to PlisioService:
// app/Providers/PlisioServiceProvider.php
public function boot()
{
Plisio::extend(function ($service) {
$service->addMethod('customEndpoint', function ($params) {
return $this->client->post('/custom-endpoint', $params);
});
});
}
Middleware for API Calls: Add headers or modify requests globally:
Plisio::setMiddleware(function ($request) {
$request->setHeader('X-Custom-Header', 'value');
return $request;
});
Event Dispatching: Hook into Plisio events to trigger Laravel events:
Plisio
How can I help you explore Laravel packages today?