Download the PHP package sarkhanrasimoghlu/laravel-kapital-bank-payment without Composer
On this page you can find all versions of the php package sarkhanrasimoghlu/laravel-kapital-bank-payment. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sarkhanrasimoghlu/laravel-kapital-bank-payment
More information about sarkhanrasimoghlu/laravel-kapital-bank-payment
Files in sarkhanrasimoghlu/laravel-kapital-bank-payment
Package laravel-kapital-bank-payment
Short Description Laravel package for Kapital Bank Merchant API V1.3 payment integration
License MIT
Homepage https://github.com/Rasimoghlu/laravel-kapital-bank-payment
Informations about the package laravel-kapital-bank-payment
Laravel Kapital Bank Payment
A Laravel package for integrating with the Kapital Bank Checkout Merchant API V1.3. Handles payments, refunds, cancellations, OAuth2 authentication, and webhook verification out of the box.
Requirements
- PHP 8.3+
- Laravel 12.0+ or 13.0+
- Guzzle 7.8+ or 8.0+
Installation
The service provider is auto-discovered. Publish the config and migration:
Configuration
Add these to your .env file:
| Key | Required | Description |
|---|---|---|
MERCHANT_ID |
Yes | posDetail.merchantId |
TERMINAL_ID |
Yes | posDetail.terminalId |
CLIENT_ID |
Yes | OAuth2 client ID |
CLIENT_SECRET |
Yes | OAuth2 client secret |
SECRET_KEY |
No | Webhook HMAC secret (required only if using webhook verification) |
BASE_URL |
Yes | API base URL (must be HTTPS in production) |
Optional settings:
Usage
Create a Payment
Payment Method Types
Payment with Metadata
Get Payment Status
Cancel a Payment
Cancel depends on payment status. See the payment state flow in the official documentation.
Full Refund
Partial Refund
Payment can be refunded multiple times if refundable amount is not exceeded.
Get Refund Status
Webhooks
The package automatically registers a POST /kapital-bank/callback route protected by signature verification middleware.
Webhook Payload Format
Kapital Bank sends webhooks in this format:
Supported events: payment_succeeded, payment_canceled.
Signature Verification
The middleware verifies the X-Signature header using Base64-encoded HMAC-SHA256 of the raw request body:
Requests without a valid signature are rejected.
Listening to Events
The package dispatches Laravel events that you can listen to:
Example listener:
Authentication
The package uses OAuth2 client credentials flow (POST /api/oauth2/token). Tokens are automatically:
- Fetched on first API request with
grant_type=client_credentialsandscope=email - Cached in Laravel's cache store (default TTL: 3500 seconds)
- Refreshed automatically on 401 responses (exactly once per request)
- Protected against thundering herd with cache locks
You never need to manage tokens manually.
API Endpoints
| Method | Endpoint | Service Method |
|---|---|---|
POST |
/api/oauth2/token |
Automatic |
POST |
/v1/payments |
createPayment() |
GET |
/v1/payments/{id} |
getPaymentStatus() |
PUT |
/v1/payments/{id}/cancel |
cancelPayment() |
POST |
/v1/refunds |
refund() |
GET |
/v1/refunds/{id} |
getRefundStatus() |
POST |
/kapital-bank/callback |
Webhook (auto-handled) |
Transaction Statuses
| Enum Case | Value | Description |
|---|---|---|
Pending |
pending |
Payment created, awaiting customer action |
Succeeded |
succeeded |
Payment completed successfully |
Canceled |
canceled |
Payment was canceled |
WaitingForCapture |
waiting_for_capture |
Authorized, awaiting capture |
Refunded |
refunded |
Fully refunded |
PartiallyRefunded |
partially_refunded |
Partially refunded |
Error Handling
All exceptions extend KapitalBankException which carries a getContext() method with structured error details:
Security
- OAuth2 Bearer Token injected automatically on every API request
- Token caching with cache lock to prevent thundering herd
- 401 auto-retry with token refresh (exactly once)
- Base64 HMAC-SHA256 webhook signature verification on raw body
hash_equals()for timing-safe signature comparisonX-Idempotency-KeyUUID on every POST/PUT to prevent double charges- HTTPS enforcement on all configured URLs (HTTP allowed in local/testing)
client_secretnever logged in any context
Database
The package creates a kapital_bank_transactions table:
| Column | Type | Description |
|---|---|---|
id |
bigint | Primary key |
transaction_id |
string | Kapital Bank payment ID (unique) |
order_id |
string | Your application's order ID (indexed) |
amount |
decimal(10,2) | Payment amount |
currency |
string(3) | Currency code |
status |
string | Transaction status (indexed, default: pending) |
payment_method |
string | Payment method (nullable) |
idempotency_key |
string | Idempotency key (nullable) |
payment_url |
text | Redirect URL (nullable) |
raw_request |
json | Request payload (nullable) |
raw_response |
json | Response/callback payload (nullable) |
paid_at |
timestamp | When payment succeeded (nullable) |
created_at |
timestamp | Record creation time |
updated_at |
timestamp | Last update time |
Testing
The package includes 86 tests covering:
- Configuration validation
- DTO construction and serialization
- HMAC signature generation and verification (hex + Base64)
- Service layer (create, status, cancel, refund)
- Webhook controller (success, cancel, duplicate, validation)
- Middleware signature verification (raw body)
- OAuth token management (fetch, cache, refresh, errors)
Postman Collection
A ready-to-use Postman collection is included in postman/:
Kapital_Bank_API_V1.3.postman_collection.json— all endpoints with auto-testsKapital_Bank_API_V1.3.postman_environment.json— environment template
Features:
- Auto token refresh on expiry
- Auto-save
payment_idandrefund_idbetween requests - Auto-generate
X-Idempotency-KeyUUIDs - Auto-generate
X-Signaturefor webhook simulation - Test assertions on every request
License
MIT
All versions of laravel-kapital-bank-payment with dependencies
laravel/framework Version ^12.0 || ^13.0
guzzlehttp/guzzle Version ^7.8 || ^8.0