generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename Request statuses to accommodate refunds and other transaction types * handle redsys responses for POST method * Fix styling * update phpunit config * add docs --------- Co-authored-by: dtorras <[email protected]>
- Loading branch information
Showing
11 changed files
with
170 additions
and
120 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.php_cs | ||
.php_cs.cache | ||
.phpunit.result.cache | ||
.phpunit.cache | ||
build | ||
composer.lock | ||
coverage | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
executionOrder="random" | ||
failOnWarning="true" | ||
failOnRisky="true" | ||
failOnEmptyTestSuite="true" | ||
beStrictAboutOutputDuringTests="true" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Creagia Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
<report> | ||
<html outputDirectory="build/coverage"/> | ||
<text outputFile="build/coverage.txt"/> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
</report> | ||
</coverage> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<php> | ||
<env name="DB_CONNECTION" value="sqlite"/> | ||
<env name="DB_DATABASE" value=":memory:"/> | ||
<env name="REDSYS_ENVIRONMENT" value="test" /> | ||
<env name="REDSYS_MERCHANT_NAME" value="Merchant Name" /> | ||
<env name="REDSYS_MERCHANT_CODE" value="999008881" /> | ||
<env name="REDSYS_KEY" value="sq7HjrUOBfKmC576ILgskD5srU870gJ7" /> | ||
<env name="REDSYS_SUCCESSFUL_ROUTE_NAME" value="okroute" /> | ||
<env name="REDSYS_UNSUCCESSFUL_ROUTE_NAME" value="koroute" /> | ||
</php> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false"> | ||
<testsuites> | ||
<testsuite name="Creagia Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<php> | ||
<env name="DB_CONNECTION" value="sqlite"/> | ||
<env name="DB_DATABASE" value=":memory:"/> | ||
<env name="REDSYS_ENVIRONMENT" value="test"/> | ||
<env name="REDSYS_MERCHANT_NAME" value="Merchant Name"/> | ||
<env name="REDSYS_MERCHANT_CODE" value="999008881"/> | ||
<env name="REDSYS_KEY" value="sq7HjrUOBfKmC576ILgskD5srU870gJ7"/> | ||
<env name="REDSYS_SUCCESSFUL_ROUTE_NAME" value="okroute"/> | ||
<env name="REDSYS_UNSUCCESSFUL_ROUTE_NAME" value="koroute"/> | ||
</php> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
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,91 @@ | ||
<?php | ||
|
||
namespace Creagia\LaravelRedsys\Actions; | ||
|
||
use Creagia\LaravelRedsys\Events\RedsysSuccessfulEvent; | ||
use Creagia\LaravelRedsys\Events\RedsysUnsuccessfulEvent; | ||
use Creagia\LaravelRedsys\Exceptions\RedsysRequestNotFound; | ||
use Creagia\LaravelRedsys\RedsysCard; | ||
use Creagia\LaravelRedsys\RedsysNotificationLog; | ||
use Creagia\LaravelRedsys\RedsysRequestStatus; | ||
use Creagia\LaravelRedsys\Request; | ||
use Creagia\Redsys\Exceptions\DeniedRedsysPaymentResponseException; | ||
use Creagia\Redsys\RedsysResponse; | ||
use Creagia\Redsys\Support\PostRequestError; | ||
use Illuminate\Support\Str; | ||
|
||
class HandleRedsysResponse | ||
{ | ||
public function __invoke( | ||
?Request $request, | ||
RedsysResponse|PostRequestError $response, | ||
) { | ||
$redsysNotificationLog = RedsysNotificationLog::create([ | ||
'merchant_parameters' => $response instanceof PostRequestError | ||
? $response->responseParameters | ||
: $response->merchantParametersArray, | ||
]); | ||
|
||
if (! $request) { | ||
throw new RedsysRequestNotFound('Redsys Request not found from bank response'); | ||
} | ||
|
||
$redsysNotificationLog->redsysRequest()->associate($request); | ||
$redsysNotificationLog->save(); | ||
|
||
if ($response instanceof PostRequestError) { | ||
/** | ||
* Error | ||
*/ | ||
$request->status = RedsysRequestStatus::Error; | ||
$request->response_message = $response->message; | ||
$request->response_code = $response->code; | ||
$request->save(); | ||
|
||
return; | ||
} | ||
|
||
$request->auth_code = (empty($authCode = trim($response->parameters->responseAuthorisationCode))) ? null : $authCode; | ||
$request->response_code = $response->parameters->responseCode ?? null; | ||
$request->response_message = $response->parameters->responseDescription; | ||
|
||
try { | ||
$notificationData = $response->checkResponse(); | ||
|
||
RedsysSuccessfulEvent::dispatch($request, $notificationData->toArray()); | ||
$request->status = RedsysRequestStatus::Success; | ||
$request->save(); | ||
|
||
if ($request->model) { | ||
$request->model->paidWithRedsys(); | ||
} | ||
|
||
if ( | ||
$request->save_card | ||
and filled($notificationData->merchantIdentifier) | ||
and filled($notificationData->cofTransactionId) | ||
) { | ||
$redsysCard = new RedsysCard(); | ||
$redsysCard->uuid = Str::uuid(); | ||
$redsysCard->number = $notificationData->cardNumber; | ||
$redsysCard->expiration_date = $notificationData->cardExpiryDate; | ||
$redsysCard->merchant_identifier = $notificationData->merchantIdentifier; | ||
$redsysCard->cof_transaction_id = $notificationData->cofTransactionId; | ||
|
||
if ($request->card_request_model_id) { | ||
$redsysCard->model_id = $request->card_request_model_id; | ||
$redsysCard->model_type = $request->card_request_model_type; | ||
} | ||
|
||
$redsysCard->save(); | ||
} | ||
} catch (DeniedRedsysPaymentResponseException $e) { | ||
$errorMessage = $e->getMessage(); | ||
RedsysUnsuccessfulEvent::dispatch($request, $errorMessage); | ||
|
||
$request->status = RedsysRequestStatus::Error; | ||
$request->response_message = $errorMessage; | ||
$request->save(); | ||
} | ||
} | ||
} |
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.