Skip to content

Commit 4e7284e

Browse files
committed
Refactor: Update Environment enum casing, adjust method references, and update docs/tests accordingly
1 parent 3c876d5 commit 4e7284e

4 files changed

Lines changed: 220 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ use Lloricode\Paymaya\Requests\Customization\RetrieveCustomizationRequest;
165165
use Lloricode\Paymaya\Requests\Customization\SetCustomizationRequest;
166166

167167
$api = new PaymayaConnector(
168-
environment: Environment::sandbox,
168+
environment: Environment::Sandbox,
169169
secretKey: 'sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl',
170170
publicKey: 'pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah',
171171
);
@@ -206,7 +206,7 @@ use Lloricode\Paymaya\Requests\Webhook\GetAllWebhookRequest;
206206
use Lloricode\Paymaya\Requests\Webhook\UpdateWebhookRequest;
207207

208208
$api = new PaymayaConnector(
209-
environment: Environment::sandbox,
209+
environment: Environment::Sandbox,
210210
secretKey: 'sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl',
211211
publicKey: 'pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah',
212212
);

UPGRADE.md

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
# Upgrade Guide
2+
3+
This document contains upgrade instructions for breaking changes in each major release.
4+
5+
---
6+
7+
## TL;DR – Breaking Changes in v3
8+
9+
- **PHP 8.3+ required** (previously 8.2)
10+
- **Uses [Saloon](https://docs.saloon.dev/) instead of direct Guzzle usage**
11+
- **Removed multiple clients (`CheckoutClient`, `WebhookClient`, etc.)**
12+
- Use **`PaymayaConnector`** + **Request classes**
13+
- **Introduced Enums** (`Environment::Sandbox` instead of string constants)
14+
- **Introduced DTOs** for request payloads (instead of raw arrays)
15+
- **Internal structure reorganized**:
16+
- `Enums/`, `DataTransferObjects/`, `Requests/`
17+
- **Error handling via Saloon exceptions**
18+
- **Laravel users should install [`lloricode/laravel-paymaya-sdk`](https://github.com/lloricode/laravel-paymaya-sdk)**
19+
20+
---
21+
22+
## v3.x (from v2.x)
23+
24+
Version 3 introduces **breaking changes** to improve code structure, type safety, and developer experience.
25+
26+
### Why v3?
27+
28+
- **Simplified API calls** using a single `PaymayaConnector` instead of multiple clients.
29+
- **DTO-based requests** for better type safety and maintainability.
30+
- **Enum support** for standardized values (like environment, status, etc.).
31+
- **Modern PHP features** (typed properties, readonly, enums).
32+
- **Adopts [Saloon](https://docs.saloon.dev/)** for HTTP requests (Saloon is built on top of Guzzle).
33+
- **Reorganized internal structure** for better maintainability:
34+
- `Enums` for constants
35+
- `DataTransferObjects` for typed payloads
36+
- `Requests` for Saloon-powered requests
37+
38+
---
39+
40+
### Minimum Requirements
41+
42+
| Requirement | v2 | v3 |
43+
|---------------|-----------|-----------|
44+
| PHP Version | ^8.2 | ^8.3 |
45+
| HTTP Layer | `guzzlehttp/guzzle` | `saloonphp/saloon` (uses Guzzle under the hood) |
46+
47+
---
48+
49+
### Why PHP 8.3?
50+
51+
- **Active Support** – PHP 8.3 is still under **active support**, not just security fixes.
52+
- **Reduced Maintenance Complexity** – Dropping older PHP versions simplifies the codebase, avoiding polyfills or backward compatibility hacks.
53+
- **Modern Features** – We take advantage of the latest language features such as:
54+
- **Readonly properties**
55+
- **Enums**
56+
- **Improved type safety**
57+
- **Future-Proof** – Encourages developers to adopt the latest technologies for long-term sustainability.
58+
59+
---
60+
61+
### Major Changes
62+
63+
#### Initialization
64+
65+
**Before (v2):**
66+
```php
67+
$checkoutClient = new CheckoutClient('public-key', 'secret-key', Environment::SANDBOX);
68+
$response = $checkoutClient->createCheckout($payload);
69+
```
70+
71+
**Now (v3):**
72+
```php
73+
use Lloricode\Paymaya\PaymayaConnector;
74+
use Lloricode\Paymaya\Requests\CreateCheckoutRequest;
75+
use Lloricode\Paymaya\DataTransferObjects\CheckoutDto;
76+
77+
$connector = new PaymayaConnector(apiKey: 'your-api-key', secret: 'your-secret');
78+
79+
$response = $connector->send(
80+
new CreateCheckoutRequest(
81+
new CheckoutDto(
82+
amount: 100.00,
83+
currency: 'PHP',
84+
redirectUrl: 'https://your-site.com/success'
85+
)
86+
)
87+
);
88+
```
89+
90+
---
91+
92+
#### Removed Multiple Clients
93+
- **Removed:** `CheckoutClient`, `PaymentsClient`, `WebhookClient`, etc.
94+
- **Use instead:** `PaymayaConnector` + specific Request classes like:
95+
- `CreateCheckoutRequest`
96+
- `GetCheckoutRequest`
97+
- `CreateWebhookRequest`
98+
99+
---
100+
101+
#### Request & Response Handling
102+
- v2 used **arrays** for payloads.
103+
- v3 uses **DTO objects** for better structure and type safety.
104+
105+
**Old (v2):**
106+
```php
107+
$checkoutClient->createCheckout([
108+
'amount' => [
109+
'value' => 100,
110+
'currency' => 'PHP'
111+
]
112+
]);
113+
```
114+
115+
**New (v3):**
116+
```php
117+
new CheckoutDto(amount: 100, currency: 'PHP');
118+
```
119+
120+
---
121+
122+
#### Environment & Config
123+
- **Old:**
124+
```php
125+
Environment::SANDBOX;
126+
```
127+
- **New:**
128+
```php
129+
Environment::Sandbox; // Enum case
130+
```
131+
132+
---
133+
134+
### Error Handling
135+
136+
**Before:**
137+
- Errors returned as arrays or Guzzle exceptions.
138+
139+
**Now:**
140+
- Errors throw `RequestException` from Saloon.
141+
- Use `try...catch`:
142+
143+
```php
144+
try {
145+
$response = $connector->send($request);
146+
} catch (\Saloon\Exceptions\Request\RequestException $e) {
147+
// Handle API error
148+
}
149+
```
150+
151+
---
152+
153+
### Laravel Users
154+
155+
If you are building a Laravel application, install the Laravel integration package:
156+
157+
```bash
158+
composer require lloricode/laravel-paymaya-sdk
159+
```
160+
161+
This package provides:
162+
- Auto configuration through Laravel service provider
163+
- Facades for quick access
164+
- Config file publishing
165+
166+
See [Laravel PayMaya SDK](https://github.com/lloricode/laravel-paymaya-sdk) for usage.
167+
168+
---
169+
170+
### Old → New Class & Method Mapping
171+
172+
| v2 Class / Method | v3 Replacement |
173+
|--------------------------------|---------------------------------------------|
174+
| `CheckoutClient::createCheckout()` | `PaymayaConnector + CreateCheckoutRequest` |
175+
| `CheckoutClient::retrieve()` | `PaymayaConnector + GetCheckoutRequest` |
176+
| `WebhookClient::register()` | `PaymayaConnector + CreateWebhookRequest` |
177+
| `WebhookClient::list()` | `PaymayaConnector + ListWebhookRequest` |
178+
| `Environment::SANDBOX` | `Environment::Sandbox` (Enum) |
179+
| `Environment::PRODUCTION` | `Environment::Production` (Enum) |
180+
181+
---
182+
183+
## Future Upgrade Policy
184+
185+
We aim to **always support the latest PHP versions** to:
186+
- Reduce technical debt
187+
- Take advantage of new language features
188+
- Encourage modern development practices
189+
- Ensure long-term compatibility and maintainability
190+
191+
If you plan to contribute, please make sure to:
192+
- Follow the current PHP minimum version requirement
193+
- Prefer modern syntax and features whenever possible
194+
195+
### Check PHP Active Support
196+
197+
- [PHP Supported Versions](https://www.php.net/supported-versions.php)
198+
- [PHP Version Changes & Features](https://php.watch/versions)
199+
200+
---
201+
202+
## v4.x (TBD)
203+
204+
*Details will be added here when v4 is released.*
205+
206+
---
207+
208+
## References
209+
- [Full Documentation](https://github.com/lloricode/paymaya-sdk-php)
210+
- [Saloon Documentation](https://docs.saloon.dev/)
211+
- [Laravel Integration](https://github.com/lloricode/laravel-paymaya-sdk)

src/Enums/Environment.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
enum Environment: string
88
{
9-
case production = 'production';
10-
case sandbox = 'sandbox';
11-
case testing = 'testing';
9+
case Production = 'Production';
10+
case Sandbox = 'Sandbox';
11+
case Testing = 'Testing';
1212

1313
public function url(): string
1414
{
1515
return match ($this) {
16-
self::production => 'https://pg.paymaya.com',
17-
self::sandbox => 'https://pg-sandbox.paymaya.com',
18-
self::testing => 'http://test.local',
16+
self::Production => 'https://pg.paymaya.com',
17+
self::Sandbox => 'https://pg-sandbox.paymaya.com',
18+
self::Testing => 'http://test.local',
1919
};
2020
}
2121
}

tests/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
function paymayaConnectorSend(Request $request): Response
1212
{
1313
return (new PaymayaConnector(
14-
environment: Environment::testing,
14+
environment: Environment::Testing,
1515
secretKey: 'fake-secretKey',
1616
publicKey: 'fake-publicKey',
1717
))->send($request);

0 commit comments

Comments
 (0)