Download the PHP package sudiptpa/khalti-sdk-php without Composer
On this page you can find all versions of the php package sudiptpa/khalti-sdk-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package khalti-sdk-php
Khalti PHP SDK
Framework-agnostic Khalti SDK for modern ePayment integrations in PHP.
If this package has been useful to you, GitHub Sponsors is a simple way to support ongoing maintenance, improvements, and future releases.
Highlights
- Modern resource API:
payments(),verification(),legacyPayments(),transactions() - ePayment KPG-2 create/status flow with strict backend verification
- First-class payload models (
CustomerInfo,AmountBreakdownItem,ProductDetail) - Typed models and value objects (
MoneyPaisa,OrderVerificationResult) - Polling helper:
waitForCompletion() - Idempotency-friendly verification model for safe order fulfillment
- Retry policy for transient failures (
429,5xx, transport) - Framework agnostic core with pluggable
TransportInterface
Requirements
- PHP
8.2+ext-curlis optional. It is only required when using the built-inCurlTransport.
Installation
Basic Usage (default CurlTransport)
If ext-curl is not installed, default transport throws a clear exception telling you to install ext-curl or pass your own transport.
Transport Examples
1) Custom Transport (framework-agnostic)
2) PSR-18 / Guzzle adapter example
Note: This PSR-18 example requires user-land packages (for example guzzlehttp/guzzle, php-http/guzzle7-adapter, and PSR-17 factories). They are optional and not required by this SDK.
3) Built-in CurlTransport
4) Custom Laravel Transport
ePayment Flow
Important: Khalti ePayment Has No Checkout Webhook
Khalti ePayment does not provide a dedicated payment webhook for this checkout flow.
You must manually verify payment on your backend before order fulfillment.
Never trust return query params alone.
Return Verification (Backend)
Idempotency (Processed-once Pattern)
Use IdempotencyStoreInterface in your app:
If the same payment return is received again, status becomes duplicate and fulfillment is blocked.
Polling Helper
Retry Policy
Transaction APIs
Legacy APIs
Optional Extension Points
RequestNormalizerInterfaceResponseNormalizerInterfaceIdempotencyStoreInterfaceMismatchCounterInterfaceClockInterface
These are optional and do not add runtime dependencies.
Troubleshooting
Common auth errors
AuthenticationException(401/403): wrong secret key or wrong environment key.- Check sandbox vs production key mismatch.
Amount mismatch causes
- Stored order amount in paisa differs from Khalti lookup amount.
- Tax/fee math done at UI but not stored in backend order snapshot.
- Verifying wrong order against wrong
pidx.
Return verification checklist
- Parse query with
parseReturnQuery(). - Verify with
VerificationContext(orderId,pidx,expectedAmount). - Enforce idempotency before fulfillment.
- Fulfill only when
OrderVerificationResult::isPaid()andfulfillable === true.
Testing & Quality
Architecture
See ARCHITECTURE.md.
License
MIT