12goyuriyr/symfony-mono-acquiring-bundle
Symfony bundle providing a typed HTTP client for Monobank Acquiring API.
composer require 12goyuriyr/symfony-mono-acquiring-bundle
Symfony Flex will automatically register the bundle in config/bundles.php. If it didn't, add it manually:
return [
// ...
MonobankAcquiring\MonobankAcquiringBundle::class => ['all' => true],
];
Add your Monobank merchant token to .env:
MONO_API_TOKEN=your_token_here
Create the bundle configuration file:
# config/packages/monobank_acquiring.yaml
monobank_acquiring:
api_token: '%env(MONO_API_TOKEN)%'
# api_url: 'https://api.monobank.ua' # optional, this is the default
That's it. MonoAcquiringClientInterface is now available for dependency injection.
Inject MonoAcquiringClientInterface into your service:
use MonobankAcquiring\Client\MonoAcquiringClientInterface;
class PaymentService
{
public function __construct(
private readonly MonoAcquiringClientInterface $monoClient,
) {}
public function createPayment(): string
{
$invoice = $this->monoClient->createInvoice([
'amount' => 10000, // amount in kopiykas (100.00 UAH)
'ccy' => 980, // ISO 4217 currency code (UAH)
'merchantPaymInfo' => [
'reference' => 'Order #123',
'destination' => 'Payment for order #123',
],
'redirectUrl' => 'https://example.com/payment/callback',
'webHookUrl' => 'https://example.com/payment/webhook',
'validity' => 3600,
]);
// Redirect user to $invoice->getPageUrl()
return $invoice->getInvoiceId();
}
public function checkStatus(string $invoiceId): bool
{
$status = $this->monoClient->getInvoiceStatus($invoiceId);
return $status->isSuccess();
}
}
createInvoice(array $payload): InvoiceResponseCreates a payment invoice. Returns InvoiceResponse with getInvoiceId() and getPageUrl().
See Monobank API docs for payload options.
getInvoiceStatus(string $invoiceId): InvoiceStatusReturns InvoiceStatus with:
getStatus() — raw status stringisCreated(), isProcessing(), isSuccess(), isFailure(), isExpired(), isReversed() — status checksgetAmount(), getFinalAmount(), getCcy() — payment amountsgetFee() — gateway feegetPaymentInfo() — raw payment info arraygetRates(): Rate[]Returns an array of Rate objects with:
getCurrencyCodeA(), getCurrencyCodeB() — ISO 4217 codesgetDate() — Unix timestampgetRateSell(), getRateBuy(), getRateCross() — exchange ratesAll API errors throw MonoApiException:
use MonobankAcquiring\Exception\MonoApiException;
try {
$invoice = $monoClient->createInvoice($payload);
} catch (MonoApiException $e) {
$e->getMessage(); // error description
$e->getHttpStatusCode(); // HTTP status code
$e->getResponseBody(); // raw response array
}
MIT
How can I help you explore Laravel packages today?