Skip to content

Commit bdd20ea

Browse files
Canceling request at this time is the awkwardest possible way to do that.
1 parent 64f65a3 commit bdd20ea

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

Diff for: src/base/Gateway.php

+2-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use craft\commerce\base\Purchasable;
88
use craft\commerce\base\RequestResponseInterface;
99
use craft\commerce\elements\Order;
10-
use craft\commerce\errors\GatewayRequestCancelledException;
1110
use craft\commerce\errors\PaymentException;
1211
use craft\commerce\helpers\Currency;
1312
use craft\commerce\models\LineItem;
@@ -65,9 +64,7 @@ abstract class Gateway extends BaseGateway
6564
/**
6665
* @event GatewayRequestEvent The event that is triggered before a gateway request is sent.
6766
*
68-
* You may set [[GatewayRequestEvent::isValid]] to `false` to prevent the request from being sent.
69-
*
70-
* This event gives you a chance to do something before a request is being sent to the gateway. If you set the `isValid` property of the event to `true`, the request will be cancelled.
67+
* This event gives you a chance to do something before a request is being sent to the gateway.
7168
*
7269
* ```php
7370
* use craft\commerce\omnipay\events\GatewayRequestEvent
@@ -76,8 +73,7 @@ abstract class Gateway extends BaseGateway
7673
*
7774
* Event::on(Gateway::class, Gateway::EVENT_BEFORE_GATEWAY_REQUEST_SEND, function(GatewayRequestEvent $e) {
7875
* if ($e->request['someKey'] === 'someValue') {
79-
* // Prevent the request from going through
80-
* $e->isValid = false;
76+
* // do something
8177
* }
8278
* });
8379
* ```
@@ -739,10 +735,6 @@ protected function performRequest($request, $transaction): RequestResponseInterf
739735
// Raise 'beforeGatewayRequestSend' event
740736
$this->trigger(self::EVENT_BEFORE_GATEWAY_REQUEST_SEND, $event);
741737

742-
if (!$event->isValid) {
743-
throw new GatewayRequestCancelledException(Craft::t('commerce', 'The gateway request was cancelled!'));
744-
}
745-
746738
$response = $this->sendRequest($request);
747739

748740
return $this->prepareResponse($response, $transaction);

Diff for: src/events/GatewayRequestEvent.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
namespace craft\commerce\omnipay\events;
44

55
use craft\commerce\models\Transaction;
6-
use craft\events\CancelableEvent;
6+
use yii\base\Event;
77

88
/**
99
* Class GatewayRequestEvent
1010
*
1111
* @author Pixel & Tonic, Inc. <[email protected]>
1212
* @since 2.0
1313
*/
14-
class GatewayRequestEvent extends CancelableEvent
14+
class GatewayRequestEvent extends Event
1515
{
1616
// Properties
1717
// =========================================================================

0 commit comments

Comments
 (0)