payum/core
Payum Core is a PHP payments library providing a flexible foundation for integrating multiple payment gateways and handling payment workflows from simple to advanced use cases. Includes docs, community support, and is MIT licensed.
Installation
composer require payum/core
payum/core appears in composer.json under require.Basic Setup
config/app.php:
'providers' => [
// ...
Payum\Core\Payum::class,
],
php artisan vendor:publish --provider="Payum\Core\Payum" --tag="config"
First Use Case: Payment Gateway Integration
config/payum.php:
'gateways' => [
'stripe' => [
'factory' => 'stripe',
'username' => env('STRIPE_API_KEY'),
'password' => env('STRIPE_SECRET_KEY'),
],
],
use Payum\Core\Payum;
public function capture(Payum $payum)
{
$gateway = $payum->getGateway('stripe');
$capture = $gateway->capture([
'amount' => 1000, // $10.00
'currency' => 'USD',
'details' => [
'number' => 'tok_visa',
],
]);
return $capture->isSuccess() ? 'Success!' : 'Failed.';
}
Gateway Initialization
public function __construct(private Payum $payum) {}
$gateway = $this->payum->getGateway('stripe');
'gateways' => [
'paypal' => [
'factory' => 'paypal_express_checkout',
'username' => env('PAYPAL_USER'),
'password' => env('PAYPAL_PASSWORD'),
'signature' => env('PAYPAL_SIGNATURE'),
],
],
Payment Capture/Authorization
$capture = $gateway->capture([
'amount' => 5000,
'currency' => 'EUR',
'details' => ['number' => 'tok_mastercard'],
]);
$authorize = $gateway->authorize([
'amount' => 3000,
'currency' => 'USD',
'details' => ['number' => 'tok_amex'],
]);
$refund = $gateway->refund([
'amount' => 2000,
'currency' => 'USD',
'details' => ['original_id' => 'txn_123'],
]);
Webhook Handling
Payum\Core\Request\Notify to process async events:
public function handleWebhook(Request $request, Payum $payum)
{
$notify = new Notify();
$notify->setModel($request->input('model'));
$notify->setRequestData($request->all());
$gateway = $payum->getGateway('stripe');
$gateway->execute($notify);
return response()->json(['status' => 'processed']);
}
Storage Integration
payments table):
use Payum\Core\Model\Payment;
$payment = new Payment();
$payment->setNumber(uniqid());
$payment->setCurrencyCode('USD');
$payment->setTotalAmount(1000);
$payment->setDescription('Order #12345');
$gateway->execute($payment->getToken());
Tokenization
$token = $gateway->getTokenFactory()->createToken(
Payment::class,
$payment,
'stripe'
);
$token->setGatewayName('stripe');
$token->setDetails(['number' => 'tok_visa']);
Route::post('/pay', [PaymentController::class, 'capture'])
->name('payum.capture');
Route::middleware(['auth'])->group(function () {
Route::post('/pay', [PaymentController::class, 'capture']);
});
config/payum.php:
'logging' => [
'enabled' => env('PAYUM_LOGGING', true),
'level' => 'debug',
],
$payum = new Payum();
$payum->addGateway('test', [
'factory' => 'test',
'username' => 'test',
'password' => 'test',
]);
Gateway Configuration Errors
Payum\PayumException with "Unknown gateway".config/payum.php matches the factory and DI container.php artisan payum:list-gateways to check registered gateways.Currency/Amount Mismatch
INVALID_AMOUNT.amount is in the smallest currency unit (e.g., cents for USD).Money objects for clarity:
use Payum\Core\Money\Money;
$money = new Money(1000, 'USD'); // $10.00
$gateway->capture(['amount' => $money]);
Token Expiry
TokenNotFoundException or TokenExpiredException.'gateways' => [
'stripe' => [
'factory' => 'stripe',
'token_expiry' => 3600, // 1 hour
],
],
Webhook Signature Validation
InvalidSignature.'gateways' => [
'stripe' => [
'factory' => 'stripe',
'webhook_signature' => env('STRIPE_WEBHOOK_SIGNING_SECRET'),
],
],
Database Storage Quirks
'storage' => [
'adapter' => 'array', // or 'doctrine', 'redis', etc.
'options' => [],
],
Payum\Core\Storage\ArrayStorage for testing, but switch to a persistent storage (e.g., Doctrine) in production.php artisan payum:log --level=debug
$request = new Capture();
$request->setModel($payment);
$request->setGatewayName('stripe');
dump($request->getParameters()); // Debug payload
$gateway->execute($request);
php artisan payum
Common commands:
payum:list-gateways – List configured gateways.payum:list-storage – Inspect stored tokens/payments.Payum\Core\Gateway or use the GatewayFactory:
class CustomGatewayFactory extends GatewayFactory
{
protected function populateConfig(array $config)
{
$config['payum.factory_name'] = 'custom';
$config['payum.factory_path'] = __DIR__.'/CustomGatewayFactory.php';
return $config;
}
}
config/payum.php:
'gateways' => [
'custom' => [
'factory' => 'custom',
'api_key' => env('CUSTOM_API_KEY'),
],
How can I help you explore Laravel packages today?