## Checkout integration SDK
Paysera PHP payments API integration SDK

## Code style
[PSR-12](https://www.php-fig.org/psr/psr-12)

## Used
<b>Built with</b>
- [PSR](https://www.php-fig.org/psr/)

## Requirements
- PHP 7.4 or higher
- ext-curl
- ext-json

## Installation

Install via Composer:

```bash
composer require paysera/lib-checkout-integration-sdk
```

## Features

- **JWT Token Validation**: Automatic validation of JWT tokens with project ID extraction
- **PSR-Compliant Caching**: Configurable cache pool for improved performance
- **Payment Processing**: Full payment order creation and link generation
- **Callback Processing**: Secure webhook verification and processing
- **Translations**: Namespace-based localization with SDK and plugin translation merging
- **Multiple Environments**: Support for both production and sandbox environments

## Quick Start

```php
<?php

use Paysera\CheckoutSdk\SdkFacadeBuilder;
use Paysera\CheckoutSdk\Entity\PaymentApiCredentials;

// Build SDK facade with minimal configuration
$sdkFacade = (new SdkFacadeBuilder())
    ->build()
;

// Authorize with your API credentials
$apiCredentials = new PaymentApiCredentials(
    'your-client-id',
    'your-client-secret'
);

$sdkFacade
    ->getAuthorizationFacade()
    ->authorize($apiCredentials)
;

// Now you're ready to process payments
```

## SDK Facade Configuration

The SDK facade can be customized with various options:

```php
<?php

use Paysera\CheckoutSdk\SdkFacadeBuilder;

$sdkFacade = (new SdkFacadeBuilder())
    // Optional: Set custom PSR-3 logger. NullLogger by default
    ->setLogger($logger)

    // Optional: Set custom PSR-18 HTTP client. CurlHttpClient by default
    ->setHttpClient($httpClient)

    // Optional: Set custom PSR-6 cache pool. InMemoryCache by default
    // Caches JWT tokens and other data for improved performance
    ->setCacheItemPool($cacheItemPool)

    // Optional: Set custom PSR-20 clock. System clock by default
    // Used for time-based operations like token expiration
    ->setClock($clock)

    // Optional: Set auth token repository. InMemoryRepository by default
    // Permanently stores payment API access tokens
    // Needed for using the same token between requests
    ->setPaymentApiAuthTokenRepository($paymentApiAuthTokenRepository)

    // Optional: Set credentials repository. InMemoryRepository by default
    // Permanently stores payment API credentials
    // Needed for automatically refreshing tokens
    ->setPaymentApiCredentialsRepository($paymentApiCredentialsRepository)

    // Optional: Set custom API client formatter. SecureApiClientFormatter by default
    // Controls how HTTP requests/responses are formatted in logs
    ->setApiClientFormatter($apiClientFormatter)

    ->build()
;
```

## Documentation

### Use Cases
- [Authorization](docs/AUTHORIZE.md) - Authenticate with the Payment API and decode JWT tokens
- [Payment Initiation](docs/INITIATE_PAYMENT.md) - Create payment orders and generate payment links
- [Callback Processing](docs/PROCESS_PAYMENT_CALLBACK.md) - Securely process payment webhooks
- [Translations](docs/TRANSLATIONS.md) - Localization with SDK and plugin namespace support
- [Local Development](docs/LOCAL_DEVELOPMENT.md) - Setup and testing in development environment

## Version History

See [CHANGELOG.md](CHANGELOG.md) for detailed version history and upgrade notes.

## License

LGPL-3.0-or-later
