diff --git a/.docs/README.md b/.docs/README.md index 931c548..04cb946 100644 --- a/.docs/README.md +++ b/.docs/README.md @@ -1,86 +1,11 @@ -# Contributte Comgate +# Comgate reference -## Content - -- [Setup](#usage) -- [Configuration](#configuration) - -## Setup - -```bash -composer require contributte/comgate -``` - -```neon -extensions: - comgate: Contributte\Comgate\DI\ComgateExtension -``` - -## Configuration - -```neon -comgate: - merchant: "12345678" - secret: foobar - test: true/false -``` - -## Usage - -### Create payment - -```php -use Brick\Money\Money; -use Contributte\Comgate\Entity\Codes\PaymentMethodCode; -use Contributte\Comgate\Entity\Payment; -use Contributte\Comgate\Gateway\PaymentService; - -final class Payments -{ - - /** @var PaymentService */ - private $paymentService; - - public function createPayment(array $data): array - { - $payment = Payment::of( - Money::of($data['price'] ?? 50, $data['currency'] ?? 'CZK'), - $data['label'] ?? 'Test item', - $data['refId'] ?? 'order101', - $data['email'] ?? 'dev@contributte.org', - $data['fullName'] ?? 'John Doe', - PaymentMethodCode::ALL, - ); - - $res = $this->paymentService->create($payment); - - // $res->isOk(); - return $res->getData(); - } - -} -``` - -### Status +The root README contains the first test-payment flow. Check a transaction with the existing status API: ```php -use Contributte\Comgate\Entity\Codes\PaymentMethodCode; -use Contributte\Comgate\Entity\PaymentStatus; -use Contributte\Comgate\Gateway\PaymentService; - -final class Payments -{ - - /** @var PaymentService */ - private $paymentService; - - public function getStatus(string $transaction): array - { - $res = $this->paymentService->status(PaymentStatus::of($transaction)); - - // $res->isOk(); - return $res->getData(); - } +$response = $payments->status(PaymentStatus::of($transaction)); +if ($response->isOk()) { + $data = $response->getData(); } ``` diff --git a/README.md b/README.md index fd2016b..650055f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,17 @@ Website 🚀 contributte.org | Contact 👨🏻‍💻 f3l1x.io | Twitter 🐦 @contributte

-## Usage +Comgate payment gateway integration for Nette applications. + +## Versions + +| State | Version | Branch | Nette | PHP | +|--------|---------|----------|--------|---------| +| dev | `^0.6` | `master` | `3.2+` | `>=8.2` | +| stable | `^0.5` | `master` | `3.2+` | `>=8.1` | +| stable | `^0.4` | `master` | `3.2+` | `>=8.1` | + +## Installation To install latest version of `contributte/comgate` use [Composer](https://getcomposer.org). @@ -26,17 +36,57 @@ To install latest version of `contributte/comgate` use [Composer](https://getcom composer require contributte/comgate ``` -## Documentation +Register the extension in your NEON configuration. -For details on how to use this package, check out our [documentation](.docs). +```neon +extensions: + comgate: Contributte\Comgate\DI\ComgateExtension +``` -## Versions +## Quick start -| State | Version | Branch | Nette | PHP | -|--------|---------|----------|--------|---------| -| dev | `^0.6` | `master` | `3.2+` | `>=8.2` | -| stable | `^0.5` | `master` | `3.2+` | `>=8.1` | -| stable | `^0.4` | `master` | `3.2+` | `>=8.1` | +Configure **test-only development credentials** and inject `PaymentService` into an application service: + +```neon +comgate: + merchant: 'test-merchant' + secret: test-secret + test: true +``` + +```php +use Brick\Money\Money; +use Contributte\Comgate\Entity\Codes\PaymentMethodCode; +use Contributte\Comgate\Entity\Payment; +use Contributte\Comgate\Gateway\PaymentService; + +final class Payments +{ + public function __construct(private PaymentService $payments) + { + } + + public function create(): string + { + $response = $this->payments->create(Payment::of( + Money::of(50, 'CZK'), 'Test item', 'test-001', 'dev@example.test', 'John Doe', PaymentMethodCode::ALL, + )); + + return $response->getRedirect() ?? ''; + } +} +``` + +A successful response provides a transaction ID and may provide the payment redirect URL through `getRedirect()`. Use real credentials only outside development; see [the detailed usage reference](.docs/README.md) for status lookups. + +## Configuration + +```neon +comgate: + merchant: "12345678" + secret: foobar + test: true/false +``` ## Development