-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3c75f59
Showing
45 changed files
with
2,238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ps_root_dir/ | ||
vendor/ | ||
|
||
composer.lock | ||
.php-cs-fixer.php | ||
.php-cs-fixer.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in([ | ||
__DIR__, | ||
]) | ||
->exclude([ | ||
'vendor', | ||
'ps_root_dir', | ||
]); | ||
|
||
$config = new PhpCsFixer\Config(); | ||
|
||
return $config | ||
->setRules([ | ||
'@PER-CS2.0' => true, | ||
'declare_strict_types' => true, | ||
'strict_param' => true, | ||
'concat_space' => ['spacing' => 'one'], | ||
'protected_to_private' => true, | ||
'nullable_type_declaration_for_default_null_value' => true, | ||
'final_class' => true, | ||
]) | ||
->setRiskyAllowed(true) | ||
->setFinder($finder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 SimPay.pl | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fixer: | ||
vendor/bin/php-cs-fixer fix | ||
|
||
phpstan: | ||
vendor/bin/phpstan analyse | ||
|
||
sa: fixer phpstan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Simpay Prestashop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"license": "MIT", | ||
"name": "simpaypl/prestashop", | ||
"type": "prestashop-module", | ||
"description": "Module for integration with SimPay payment gateway", | ||
"keywords": [ | ||
"simpay", | ||
"prestashop", | ||
"payment", | ||
"gateway" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "SimPay Core Team" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"SimPaypl\\PrestaShop\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php": "^8.1", | ||
"simpaypl/simpay": "^3.0" | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan": "^1.10", | ||
"prestashop/php-dev-tools": "^4.3" | ||
}, | ||
"config": { | ||
"preferred-install": "dist", | ||
"prepend-autoloader": false, | ||
"sort-packages": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<module> | ||
<name>simpay</name> | ||
<displayName><![CDATA[SimPay]]></displayName> | ||
<version><![CDATA[1.0.0]]></version> | ||
<description><![CDATA[Accept payments by SimPay payment gateway for easy and secure payments.]]></description> | ||
<author><![CDATA[Payments Solution Sp. z o.o.]]></author> | ||
<tab><![CDATA[payments_gateways]]></tab> | ||
<confirmUninstall><![CDATA[Are you sure you want to uninstall?]]></confirmUninstall> | ||
<is_configurable>1</is_configurable> | ||
<need_instance>1</need_instance> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); | ||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); | ||
header('Cache-Control: no-store, no-cache, must-revalidate'); | ||
header('Cache-Control: post-check=0, pre-check=0', false); | ||
header('Pragma: no-cache'); | ||
header('Location: ../'); | ||
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
services: | ||
_defaults: | ||
public: true | ||
|
||
SimPaypl\PrestaShop\Controller\SimpayConfigurationAdminController: | ||
arguments: | ||
- '@prestashop.module.simpay.admin.form.simpay_form_data_handler' | ||
tags: | ||
- { name: 'controller.service_arguments' } | ||
|
||
# Demo configuration text form | ||
prestashop.module.simpay.admin.form.simpay_form_type: | ||
class: 'SimPaypl\PrestaShop\Form\SimpayFormType' | ||
parent: 'form.type.translatable.aware' | ||
public: true | ||
tags: | ||
- { name: form.type } | ||
|
||
prestashop.module.simpay.admin.form.simpay_data_configuration: | ||
class: 'SimPaypl\PrestaShop\Form\SimpayDataConfiguration' | ||
arguments: | ||
- '@prestashop.adapter.legacy.configuration' | ||
|
||
prestashop.module.simpay.admin.form.simpay_form_data_provider: | ||
class: 'SimPaypl\PrestaShop\Form\SimpayFormDataProvider' | ||
arguments: | ||
- '@prestashop.module.simpay.admin.form.simpay_data_configuration' | ||
|
||
prestashop.module.simpay.admin.form.simpay_form_data_handler: | ||
class: 'PrestaShop\PrestaShop\Core\Form\Handler' | ||
arguments: | ||
- '@form.factory' | ||
- '@prestashop.core.hook.dispatcher' | ||
- '@prestashop.module.simpay.admin.form.simpay_form_data_provider' | ||
- 'SimPaypl\PrestaShop\Form\SimpayFormType' | ||
- 'SimpayConfiguration' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); | ||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); | ||
header('Cache-Control: no-store, no-cache, must-revalidate'); | ||
header('Cache-Control: post-check=0, pre-check=0', false); | ||
header('Pragma: no-cache'); | ||
header('Location: ../'); | ||
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
services: | ||
_defaults: | ||
public: true | ||
|
||
prestashop.module.simpay.front.payment_client_factory: | ||
class: 'SimPaypl\PrestaShop\PaymentClientFactory' | ||
arguments: | ||
- '@prestashop.adapter.legacy.configuration' | ||
|
||
prestashop.module.simpay.front.payment_client: | ||
class: 'Simpay\PaymentInterface' | ||
factory: '@prestashop.module.simpay.front.payment_client_factory' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); | ||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); | ||
header('Cache-Control: no-store, no-cache, must-revalidate'); | ||
header('Cache-Control: post-check=0, pre-check=0', false); | ||
header('Pragma: no-cache'); | ||
header('Location: ../'); | ||
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
simpay_configuration: | ||
path: /simpay/configuration | ||
methods: [GET, POST] | ||
defaults: | ||
_controller: SimPaypl\PrestaShop\Controller\SimpayConfigurationAdminController::configureAction | ||
# Needed to work with tab system | ||
_legacy_controller: 'SimpayConfigurationAdminController' | ||
_legacy_link: 'SimpayConfigurationAdminController' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
final class SimpayFailedModuleFrontController extends ModuleFrontController | ||
{ | ||
/** @var Simpay */ | ||
public $module; | ||
|
||
public function initContent(): void | ||
{ | ||
parent::initContent(); | ||
$this->setTemplate('module:simpay/views/templates/front/failed.tpl'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); | ||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); | ||
header('Cache-Control: no-store, no-cache, must-revalidate'); | ||
header('Cache-Control: post-check=0, pre-check=0', false); | ||
header('Pragma: no-cache'); | ||
header('Location: ../'); | ||
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Simpay\Model\Request\Amount; | ||
use Simpay\Model\Request\CallbackReturnUrl; | ||
use Simpay\Model\Request\CreatePayment; | ||
use Simpay\Model\Request\ServiceId; | ||
use Simpay\Model\Request\Currency; | ||
use Simpay\PaymentInterface; | ||
|
||
final class SimpayNotifyModuleFrontController extends ModuleFrontController | ||
{ | ||
/** @var Simpay */ | ||
public $module; | ||
|
||
public function init(): void | ||
{ | ||
parent::init(); | ||
// validate module is enabled and configured correctly | ||
} | ||
|
||
public function postProcess(): void | ||
{ | ||
$jsonPayload = Tools::file_get_contents('php://input'); | ||
|
||
if (!is_string($jsonPayload)) { | ||
http_response_code(400); | ||
header('Content-Type: application/json'); | ||
die(json_encode(['status' => 'error', 'message' => 'Invalid payload, expected JSON'])); | ||
} | ||
|
||
/** @var array{ | ||
* id: string, | ||
* service_id: string, | ||
* status: string, | ||
* amount: array{ | ||
* value: float, | ||
* currency: string, | ||
* commission: float, | ||
* }, | ||
* control: string, | ||
* channel: string, | ||
* environment: string, | ||
* signature: string | ||
* }|bool|null $payload | ||
*/ | ||
$payload = json_decode($jsonPayload, true); | ||
|
||
if (!is_array($payload)) { | ||
http_response_code(400); | ||
header('Content-Type: application/json'); | ||
die(json_encode(['status' => 'error', 'message' => 'Invalid payload, expected JSON'])); | ||
} | ||
|
||
$signatureValues = []; | ||
array_walk_recursive($payload, function (mixed $item, string $key) use (&$signatureValues) { | ||
if ($key === 'signature') { | ||
return; | ||
} | ||
|
||
$signatureValues[] = (string) $item; | ||
}); | ||
|
||
$signatureValues[] = Configuration::get('SIMPAY_SERVICE_IPN_SIGNATURE_KEY'); | ||
$signatureValues = implode('|', $signatureValues); | ||
$signatureHash = hash('sha256', $signatureValues); | ||
|
||
if ($payload['signature'] !== $signatureHash) { | ||
http_response_code(400); | ||
header('Content-Type: application/json'); | ||
die(json_encode(['status' => 'error', 'message' => 'Invalid signature'])); | ||
} | ||
|
||
$order = Order::getByCartId((int) $payload['control']); | ||
|
||
if (null === $order) { | ||
http_response_code(400); | ||
header('Content-Type: application/json'); | ||
die(json_encode(['status' => 'error', 'message' => 'Order not found'])); | ||
} | ||
|
||
if ((int) Configuration::get(Simpay::CONFIG_OS_AWAITING) === $order->getCurrentState()) { | ||
|
||
$orderStatusId = (int) match($payload['status']) { | ||
'transaction_paid' => Configuration::get('PS_OS_PAYMENT'), | ||
default => Configuration::get('PS_OS_ERROR'), | ||
}; | ||
|
||
$orderHistory = new OrderHistory(); | ||
$orderHistory->id_order = (int) $order->id; | ||
$orderHistory->changeIdOrderState($orderStatusId, (int) $order->id, true); | ||
$orderHistory->save(); | ||
} | ||
|
||
|
||
http_response_code(200); | ||
header('Content-Type: application/json'); | ||
die(json_encode(['status' => 'ok'])); | ||
} | ||
} |
Oops, something went wrong.