Download the PHP package esanj/discount-client without Composer
On this page you can find all versions of the php package esanj/discount-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download esanj/discount-client
More information about esanj/discount-client
Files in esanj/discount-client
Package discount-client
Short Description Laravel client package for the Esanj Discount Microservice (coupons & gift cards)
License MIT
Informations about the package discount-client
Esanj Discount Client
A Laravel client package for the Esanj Discount Microservice (coupons & gift cards). It authenticates with client credentials through the esanj/auth-bridge package, then lets you create and apply discount codes (coupons) and gift cards — with typed DTOs, typed responses and structured error handling.
Installation
The service provider and the Discount, Coupon and GiftCard facades are auto-discovered.
Configuration
Publish the config (optional — it is merged automatically):
Set the environment variables:
The access token is issued by the OAuth server configured for
esanj/auth-bridge(ACCOUNTING_BRIDGE_BASE_URL) using this service'sDISCOUNT_CLIENT_ID/DISCOUNT_CLIENT_SECRET, then sent as a short-livedBearertoken to the Discount service. Tokens are cached and refreshed automatically by auth-bridge.
Usage
Dependency injection (recommended)
You can also inject CouponClientInterface / GiftCardClientInterface directly.
Facades
Applying a coupon (validate → redeem → confirm / cancel)
Applying a gift card (validate → redeem)
Creating coupons and gift cards
Error Handling
Every failure throws a subclass of Esanj\DiscountClient\Exceptions\DiscountException:
| Exception | When |
|---|---|
DiscountAuthenticationException |
Client credentials missing/invalid; the OAuth server rejected the token request. |
DiscountApiException |
The Discount service returned an error response. Carries statusCode, responseBody, getErrorCode(), getErrors(). |
Server (5xx), connection and rejected-token (401/403) failures are retried automatically
according to the retry config; a rejected token is invalidated and re-fetched before the retry.
API surface
| Method | HTTP | Endpoint |
|---|---|---|
coupons()->create(CouponData) |
POST | /api/v1/service/coupons |
coupons()->show(string $code) |
GET | /api/v1/service/coupons/{code} |
coupons()->validate(string $code, CouponValidationData) |
POST | /api/v1/service/coupons/{code}/validate |
coupons()->redeem(string $code, string $usageId, CouponValidationData) |
POST | /api/v1/service/coupons/{code}/redeem |
coupons()->confirm(string $code, string $usageId) |
POST | /api/v1/service/coupons/{code}/confirm |
coupons()->cancel(string $code, string $usageId) |
POST | /api/v1/service/coupons/{code}/cancel |
giftCards()->create(GiftCardData) |
POST | /api/v1/service/gift-cards |
giftCards()->show(string $code) |
GET | /api/v1/service/gift-cards/{code} |
giftCards()->validate(string $code, int $userId) |
POST | /api/v1/service/gift-cards/{code}/validate |
giftCards()->redeem(string $code, string $usageId, int $userId) |
POST | /api/v1/service/gift-cards/{code}/redeem |
See docs/GUIDE.md for a full walkthrough.
License
MIT
All versions of discount-client with dependencies
ext-json Version *
esanj/auth-bridge Version >=0.2.0 <0.3.0
illuminate/support Version ^12.0|^13.0
illuminate/log Version ^12.0|^13.0
guzzlehttp/guzzle Version ^7.0