laraditz/xenopay
Laravel SDK for Xenopay payments. Authenticate via facade/container, create and view bills with access tokens, optional default credentials via .env, plus included migration. Returns XenopayResponse with helpers for status, message, data, and errors.
Installation
composer require laraditz/xenopay
(Auto-discovery works for Laravel 5.5+; otherwise, manually register Laraditz\Xenopay\XenopayServiceProvider in config/app.php.)
Environment Configuration
Add Xenopay credentials to .env:
XENOPAY_EMAIL=your_email@example.com
XENOPAY_PASSWORD=your_secure_password
Run Migrations
php artisan migrate
(Note: Verify if migrations are required for your use case—check the package’s database/migrations for dependencies.)
First API Call
// Facade (preferred for simplicity)
$response = \Xenopay::auth()->login();
// Or via container
$response = app('xenopay')->auth()->login();
(The facade abstracts the container call, reducing boilerplate.)
auth()->login() to authenticate and retrieve a session token.$response->success() or inspect $response->data for errors.session(['xenopay_token' => $response->data->token]);
login(['email' => ..., 'password' => ...]).auth()->logout() to end the session.$response = \Xenopay::withToken($storedToken)->api()->get('endpoint');
api() method with HTTP verbs:
$response = \Xenopay::api()->post('transactions', ['amount' => 100]);
$response = \Xenopay::api()->get('transactions', ['status' => 'pending']);
public function handle($request, Closure $next) {
$valid = \Xenopay::validateWebhook($request->getContent(), $request->header('X-Signature'));
if (!$valid) abort(403);
return $next($request);
}
Route::post('/xenopay/webhook', [XenopayWebhookController::class, 'handle']);
Laraditz\Xenopay\Exceptions\XenopayException in App\Exceptions\Handler:
public function render($request, Throwable $exception) {
if ($exception instanceof XenopayException) {
return response()->json(['error' => $exception->getMessage()], 400);
}
return parent::render($request, $exception);
}
$response->success() before processing:
if (!$response->success()) {
throw new \RuntimeException($response->message);
}
dispatch(new ProcessXenopayPayment($paymentId));
event(new XenopayTransactionCreated($transactionData));
Notification::send($user, new PaymentStatusUpdated($response->data));
Mockery to stub responses:
$mock = Mockery::mock('\Laraditz\Xenopay\Xenopay');
$mock->shouldReceive('api()->post')->andReturn((object) ['success' => true]);
$this->app->instance('xenopay', $mock);
laravel/env package to manage test credentials:
XENOPAY_EMAIL=test@example.com
XENOPAY_PASSWORD=test123
$response = \Xenopay::withCredentials(['email' => 'alt@example.com', 'password' => 'altpass'])
->auth()->login();
config/xenopay.php (if supported):
'api_url' => env('XENOPAY_API_URL', 'https://api.xenopay.example.com'),
README lacks details on required tables.vendor/laraditz/xenopay/database/migrations to understand schema dependencies. If unused, skip migrations or create your own tables.401 Unauthorized errors.try {
$response = \Xenopay::withToken($token)->api()->get('data');
} catch (\Laraditz\Xenopay\Exceptions\UnauthorizedException $e) {
$token = \Xenopay::auth()->refreshToken();
return $this->withToken($token)->api()->get('data');
}
public function __construct(private Xenopay $xenopay) {}
\Log::debug('Webhook payload:', $request->getContent());
\Log::debug('Signature header:', $request->header('X-Signature'));
use Symfony\Component\HttpClient\RetryStrategy;
$client = \Xenopay::getClient()->withOptions([
'timeout' => 30,
'retry' => RetryStrategy::create(3, 1000, true),
]);
XENOPAY_DEBUG=true in .env to log raw API responses:
XENOPAY_DEBUG=true
tap to debug the underlying HTTP client:
\Xenopay::getClient()->tap(function ($client) {
\Log::info('Client config:', $client->getConfig());
});
$validator = Validator::make($request->all(), [
'amount' => 'required|numeric|min:0.01',
'currency' => 'required|string|size:3',
]);
$this->app->bind('xenopay.http_client', function () {
return new \GuzzleHttp\Client([
'timeout' => 60,
'headers' => ['User-Agent' => 'MyApp/1.0'],
]);
});
\Xenopay::getClient()->getEmitter()->
How can I help you explore Laravel packages today?