-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from shopware5/pt-13151/capture-timeout
PT-13151 - Handle session timeout while capture payment
- Loading branch information
Showing
27 changed files
with
833 additions
and
17 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,43 @@ | ||
name: PHP | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
call-legacy-analyse-workflow: | ||
name: PHP legacy code analysis | ||
runs-on: ubuntu-latest | ||
container: | ||
image: ghcr.io/shopware5/docker-images-testing/install:shopware_5.2_5.7_5.6_5.2.11-5.2.27 | ||
credentials: | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.github_token }} | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
|
||
steps: | ||
- run: /usr/bin/supervisord -c /etc/supervisord.conf & | ||
|
||
- name: Checkout SwagPaymentPayPalUnified | ||
uses: actions/checkout@v3 | ||
with: | ||
path: plugin | ||
|
||
- name: Move plugin | ||
run: mv "$(pwd)/plugin" /shopware/custom/plugins/SwagPaymentPayPalUnified | ||
|
||
- name: Setup SwagPaymentPayPalUnified | ||
run: | | ||
cd /shopware/custom/plugins/SwagPaymentPayPalUnified | ||
make init-legacy | ||
- name: Setup legacy tests | ||
run: | | ||
cd /shopware/custom/plugins/SwagPaymentPayPalUnified | ||
composer require --dev phpcompatibility/php-compatibility | ||
- name: Run legacy tests | ||
run: | | ||
cd /shopware/custom/plugins/SwagPaymentPayPalUnified | ||
./vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility | ||
./vendor/bin/phpcs -p --ignore="./vendor/,./PhpStan/" --standard="PHPCompatibility" --runtime-set testVersion 5.6 ./ |
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
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
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,24 @@ | ||
<?php | ||
/** | ||
* (c) shopware AG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SwagPaymentPayPalUnified\Components\Exception; | ||
|
||
use Exception; | ||
|
||
class InvalidOrderException extends Exception | ||
{ | ||
/** | ||
* @param string $paypalOrderId | ||
*/ | ||
public function __construct($paypalOrderId) | ||
{ | ||
$message = \sprintf('No capture found in order with ID: %s', $paypalOrderId); | ||
|
||
parent::__construct($message); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
/** | ||
* (c) shopware AG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SwagPaymentPayPalUnified\Components\Exception; | ||
|
||
use Exception; | ||
|
||
class TimeoutInfoException extends Exception | ||
{ | ||
/** | ||
* @param string $paypalOrderId | ||
*/ | ||
public function __construct($paypalOrderId) | ||
{ | ||
$message = \sprintf('Timeout information not found for PayPal order with ID: %s', $paypalOrderId); | ||
|
||
parent::__construct($message); | ||
} | ||
} |
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,120 @@ | ||
<?php | ||
/** | ||
* (c) shopware AG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SwagPaymentPayPalUnified\Components\Services; | ||
|
||
use DateTime; | ||
use Doctrine\DBAL\Connection; | ||
use PDO; | ||
use Shopware\Bundle\StoreFrontBundle\Service\Core\ContextService; | ||
use SwagPaymentPayPalUnified\Components\Exception\TimeoutInfoException; | ||
use SwagPaymentPayPalUnified\PayPalBundle\V2\Api\Order\PurchaseUnit\Payments\Refund; | ||
use SwagPaymentPayPalUnified\PayPalBundle\V2\Api\Order\PurchaseUnit\Payments\Refund\Amount; | ||
use SwagPaymentPayPalUnified\PayPalBundle\V2\Resource\CaptureResource; | ||
|
||
class TimeoutRefundService | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* @var ContextService | ||
*/ | ||
private $contextService; | ||
|
||
/** | ||
* @var CaptureResource | ||
*/ | ||
private $captureResource; | ||
|
||
public function __construct( | ||
Connection $connection, | ||
ContextService $contextService, | ||
CaptureResource $captureResource | ||
) { | ||
$this->connection = $connection; | ||
$this->contextService = $contextService; | ||
$this->captureResource = $captureResource; | ||
} | ||
|
||
/** | ||
* @param string $payPalOrderId | ||
* @param float $orderAmount | ||
* | ||
* @return void | ||
*/ | ||
public function saveInfo($payPalOrderId, $orderAmount) | ||
{ | ||
$this->connection->insert('swag_payment_paypal_unified_order_refund_info', [ | ||
'paypal_order_id' => (string) $payPalOrderId, | ||
'order_amount' => (string) $orderAmount, | ||
'currency' => $this->contextService->getShopContext()->getCurrency()->getCurrency(), | ||
'created_at' => (string) (new DateTime())->getTimestamp(), | ||
]); | ||
} | ||
|
||
/** | ||
* @param string $payPalOrderId | ||
* | ||
* @return void | ||
*/ | ||
public function deleteInfo($payPalOrderId) | ||
{ | ||
$this->connection->delete('swag_payment_paypal_unified_order_refund_info', [ | ||
'paypal_order_id' => $payPalOrderId, | ||
]); | ||
} | ||
|
||
/** | ||
* @param string $payPalOrderId | ||
* @param string $captureId | ||
* | ||
* @return void | ||
*/ | ||
public function refund($payPalOrderId, $captureId) | ||
{ | ||
$info = $this->getInfo($payPalOrderId); | ||
if (!\is_array($info)) { | ||
throw new TimeoutInfoException($payPalOrderId); | ||
} | ||
|
||
$amount = new Amount(); | ||
$amount->setCurrencyCode($info['currency']); | ||
$amount->setValue($info['order_amount']); | ||
|
||
$refund = new Refund(); | ||
$refund->setAmount($amount); | ||
$refund->setNoteToPayer('User timeout'); | ||
|
||
$this->captureResource->refund($captureId, $refund); | ||
} | ||
|
||
/** | ||
* @param string $payPalOrderId | ||
* | ||
* @return array<string, string>|null | ||
*/ | ||
private function getInfo($payPalOrderId) | ||
{ | ||
$result = $this->connection->createQueryBuilder() | ||
->select(['*']) | ||
->from('swag_payment_paypal_unified_order_refund_info') | ||
->where('paypal_order_id = :paypalOrderId') | ||
->setParameter('paypalOrderId', $payPalOrderId) | ||
->execute() | ||
->fetch(PDO::FETCH_ASSOC); | ||
|
||
if (!\is_array($result)) { | ||
return null; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.