|
| 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) |
0 commit comments