Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:

strategy:
matrix:
php-versions: [ "8.0" ]
php-versions: [ "8.4" ]
operating-system: [ "ubuntu-latest" ]
fail-fast: false

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Setup PHP cache environment"
id: "extcache"
Expand All @@ -40,7 +40,7 @@ jobs:
key: "${{ env.cacheVersion }}"

- name: "Cache PHP extensions"
uses: "actions/cache@v2"
uses: "actions/cache@v4"
with:
path: "${{ steps.extcache.outputs.dir }}"
key: "${{ steps.extcache.outputs.key }}"
Expand All @@ -58,10 +58,10 @@ jobs:

- name: "Get Composer cache directory"
id: "composercache"
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- name: "Cache PHP dependencies"
uses: "actions/cache@v2"
uses: "actions/cache@v4"
with:
path: "${{ steps.composercache.outputs.dir }}"
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
Expand All @@ -82,13 +82,13 @@ jobs:

strategy:
matrix:
php-versions: [ "8.0" ]
php-versions: [ "8.4" ]
operating-system: [ "ubuntu-latest" ]
fail-fast: false

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Setup PHP cache environment"
id: "extcache"
Expand All @@ -99,7 +99,7 @@ jobs:
key: "${{ env.cacheVersion }}"

- name: "Cache PHP extensions"
uses: "actions/cache@v2"
uses: "actions/cache@v4"
with:
path: "${{ steps.extcache.outputs.dir }}"
key: "${{ steps.extcache.outputs.key }}"
Expand All @@ -117,10 +117,10 @@ jobs:

- name: "Get Composer cache directory"
id: "composercache"
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- name: "Cache PHP dependencies"
uses: "actions/cache@v2"
uses: "actions/cache@v4"
with:
path: "${{ steps.composercache.outputs.dir }}"
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ https://examples.contributte.org/payments-skeleton/

To install latest version of `contributte/payments-skeleton` use [Composer](https://getcomposer.org).

### Requirements

- PHP 8.4+

```
composer create-project -s dev contributte/payments-skeleton acme
```
Expand Down
9 changes: 3 additions & 6 deletions app/Model/PaymentMethodDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
final class PaymentMethodDTO
{

/** @var string */
private $paymentMethodName;
private string $paymentMethodName;

/** @var string */
private $paymentIcon;
private string $paymentIcon;

/** @var bool */
private $isPaymentByCard;
private bool $isPaymentByCard;

public function __construct(
string $paymentMethodName,
Expand Down
75 changes: 32 additions & 43 deletions app/Presenters/HomepagePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,18 @@
use Contributte\ThePay\ReturnedPayment;
use Nette\Application\UI\Presenter;
use Tp\InvalidSignatureException;
use Tp\Payment;

class HomepagePresenter extends Presenter
{

/**
* @var DataApi
* @inject
*/
public $thePayDataApi;
/** @inject */
public DataApi $thePayDataApi;

/**
* @var IPayment
* @inject
*/
public $tpPayment;
/** @inject */
public IPayment $tpPayment;

/**
* @var IReturnedPayment
* @inject
*/
public $tpReturnedPayment;
/** @inject */
public IReturnedPayment $tpReturnedPayment;

public function actionPay(int $paymentMethodId): void
{
Expand All @@ -41,7 +31,6 @@ public function actionPay(int $paymentMethodId): void
$userId = 1;

$payment = $this->tpPayment->create();
assert($payment instanceof Payment);

$payment->setMethodId($paymentMethodId);
$payment->setValue(1000.0);
Expand Down Expand Up @@ -71,35 +60,35 @@ public function actionOnlineConfirmation(int $cartId): void
$returnedPayment = $this->tpReturnedPayment->create();

try {// TODO mark cart as payed, send email, ...
if ($returnedPayment->verifySignature() !== false) {
if (in_array($returnedPayment->getStatus(), [
ReturnedPayment::STATUS_OK, // we have money
ReturnedPayment::STATUS_WAITING, // some bank method are asynchronous, using this you believe nothing go wrong, see official docs
], true)) {
//Demo gate don't allow active check...
if ($this->thePayDataApi->getMerchantConfig()->isDemo()) {
//Do not load thePayDataApi->getPayment

if (bccomp(number_format((float) $returnedPayment->getValue(), 2, '.', ''), $cartTotalPrice, 2) === 0) {
// everything is ok
// TODO mark cart as payed, send email, ...

$this->flashMessage('Payment received using demo gateway', 'success');
}
} else {
$paymentId = $returnedPayment->getPaymentId();
$payment = $this->thePayDataApi->getPayment($paymentId);

if (bccomp(number_format((float) $payment->getPayment()?->getValue(), 2, '.', ''), $cartTotalPrice, 2) === 0) {
// everything is ok
// TODO mark cart as payed, send email, ...

$this->flashMessage('Payment received', 'success');
}
$returnedPayment->verifySignature();

if (in_array($returnedPayment->getStatus(), [
ReturnedPayment::STATUS_OK, // we have money
ReturnedPayment::STATUS_WAITING, // some bank method are asynchronous, using this you believe nothing go wrong, see official docs
], true)) {
//Demo gate don't allow active check...
if ($this->thePayDataApi->getMerchantConfig()->isDemo()) {
//Do not load thePayDataApi->getPayment

if (bccomp(number_format((float) $returnedPayment->getValue(), 2, '.', ''), $cartTotalPrice, 2) === 0) {
// everything is ok
// TODO mark cart as payed, send email, ...

$this->flashMessage('Payment received using demo gateway', 'success');
}
} else {
$this->flashMessage('Payment not received, status ' . $returnedPayment->getStatus() . '. See constants ReturnedPayment::STATUS_*', 'error');
$paymentId = $returnedPayment->getPaymentId();
$payment = $this->thePayDataApi->getPayment($paymentId);

if (bccomp(number_format((float) $payment->getPayment()?->getValue(), 2, '.', ''), $cartTotalPrice, 2) === 0) {
// everything is ok
// TODO mark cart as payed, send email, ...

$this->flashMessage('Payment received', 'success');
}
}
} else {
$this->flashMessage('Payment not received, status ' . $returnedPayment->getStatus() . '. See constants ReturnedPayment::STATUS_*', 'error');
}
} catch (InvalidSignatureException $e) {
// TODO handle invalid request signature
Expand Down
1 change: 1 addition & 0 deletions app/Router/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static function createRouter(): RouteList
{
$router = new RouteList();
$router->addRoute('<presenter>/<action>[/<id>]', 'Homepage:default');

return $router;
}

Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
"license": "MIT",
"type": "project",
"require": {
"php": ">= 8.0",
"php": ">=8.4",
"ext-bcmath": "*",
"contributte/bootstrap": "^0.6.0",
"contributte/latte": "^0.5.0",
"contributte/bootstrap": "^0.7.0",
"contributte/latte": "^0.7.0",
"contributte/thepay": "^4.0.2",
"contributte/tracy": "^0.6.0"
"contributte/tracy": "^0.7.0"
},
"require-dev": {
"ninjify/qa": "^0.13",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-nette": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0"
"contributte/qa": "^0.4",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-nette": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0"
},
"prefer-stable": true,
"minimum-stability": "dev",
Expand Down
Loading