Skip to content

Commit 79125fa

Browse files
committed
Use abstract PayPalIPNGatewayBase class insted of trait.
1 parent 3fc64be commit 79125fa

File tree

4 files changed

+68
-37
lines changed

4 files changed

+68
-37
lines changed

src/Plugin/Commerce/PaymentGateway/ExpressCheckout.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Drupal\commerce_payment\Exception\PaymentGatewayException;
99
use Drupal\commerce_payment\PaymentMethodTypeManager;
1010
use Drupal\commerce_payment\PaymentTypeManager;
11-
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayBase;
1211
use Drupal\commerce_price\Price;
1312
use Drupal\commerce_price\RounderInterface;
1413
use Drupal\Core\Entity\EntityTypeManagerInterface;
@@ -33,9 +32,7 @@
3332
* },
3433
* )
3534
*/
36-
class ExpressCheckout extends OffsitePaymentGatewayBase implements ExpressCheckoutInterface {
37-
38-
use PaypalPaymentGatewayTrait;
35+
class ExpressCheckout extends PayPalIPNGatewayBase implements ExpressCheckoutInterface {
3936

4037
/**
4138
* The HTTP client.

src/Plugin/Commerce/PaymentGateway/ExpressCheckoutInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Provides the interface for the Express Checkout payment gateway.
1313
*/
14-
interface ExpressCheckoutInterface extends OffsitePaymentGatewayInterface, SupportsAuthorizationsInterface, SupportsRefundsInterface {
14+
interface ExpressCheckoutInterface extends PayPalIPNGatewayBaseInterface, SupportsAuthorizationsInterface, SupportsRefundsInterface {
1515

1616
/**
1717
* Gets the API URL.

src/Plugin/Commerce/PaymentGateway/PaypalPaymentGatewayTrait.php renamed to src/Plugin/Commerce/PaymentGateway/PayPalIPNGatewayBase.php

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@
22

33
namespace Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway;
44

5+
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayBase;
56
use Symfony\Component\HttpFoundation\Request;
67

78
/**
89
* Provides common methods to be used by PayPal payment gateways.
910
*/
10-
trait PaypalPaymentGatewayTrait {
11+
abstract class PayPalIPNGatewayBase extends OffsitePaymentGatewayBase implements PayPalIPNGatewayBaseInterface {
1112

1213
/**
13-
* Loads the payment for a given remote id.
14-
*
15-
* @param string $remote_id
16-
* The remote id property for a payment.
17-
*
18-
* @return \Drupal\commerce_payment\Entity\PaymentInterface
19-
* Payment object.
20-
*
21-
* @todo: to be replaced by Commerce core payment storage method
22-
* @see https://www.drupal.org/node/2856209
14+
* {@inheritdoc}
2315
*/
2416
public function loadPaymentByRemoteId($remote_id) {
2517
/** @var \Drupal\commerce_payment\PaymentStorage $storage */
@@ -29,13 +21,7 @@ public function loadPaymentByRemoteId($remote_id) {
2921
}
3022

3123
/**
32-
* Processes an incoming IPN request.
33-
*
34-
* @param \Symfony\Component\HttpFoundation\Request $request
35-
* The request.
36-
*
37-
* @return mixed
38-
* The request data array or FALSE.
24+
* {@inheritdoc}
3925
*/
4026
public function processIpnRequest(Request $request) {
4127
// Get IPN request data.
@@ -66,27 +52,15 @@ public function processIpnRequest(Request $request) {
6652
}
6753

6854
/**
69-
* Get data array from a request content.
70-
*
71-
* @param string $request_content
72-
* The Request content.
73-
*
74-
* @return array
75-
* The request data array.
55+
* {@inheritdoc}
7656
*/
7757
public function getRequestDataArray($request_content) {
7858
parse_str(html_entity_decode($request_content), $ipn_data);
7959
return $ipn_data;
8060
}
8161

8262
/**
83-
* Gets the IPN URL to be used for validation for IPN data.
84-
*
85-
* @param array $ipn_data
86-
* The IPN request data from PayPal.
87-
*
88-
* @return string
89-
* The IPN validation URL.
63+
* {@inheritdoc}
9064
*/
9165
public function getIpnValidationUrl(array $ipn_data) {
9266
if (!empty($ipn_data['test_ipn']) && $ipn_data['test_ipn'] == 1) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway;
4+
5+
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayInterface;
6+
use Symfony\Component\HttpFoundation\Request;
7+
8+
/**
9+
* Provides the interface for the Express Checkout payment gateway.
10+
*/
11+
interface PayPalIPNGatewayBaseInterface extends OffsitePaymentGatewayInterface {
12+
13+
/**
14+
* Loads the payment for a given remote id.
15+
*
16+
* @param string $remote_id
17+
* The remote id property for a payment.
18+
*
19+
* @return \Drupal\commerce_payment\Entity\PaymentInterface
20+
* Payment object.
21+
*
22+
* @todo: to be replaced by Commerce core payment storage method
23+
* @see https://www.drupal.org/node/2856209
24+
*/
25+
public function loadPaymentByRemoteId($remote_id);
26+
27+
/**
28+
* Processes an incoming IPN request.
29+
*
30+
* @param \Symfony\Component\HttpFoundation\Request $request
31+
* The request.
32+
*
33+
* @return mixed
34+
* The request data array or FALSE.
35+
*/
36+
public function processIpnRequest(Request $request);
37+
38+
/**
39+
* Get data array from a request content.
40+
*
41+
* @param string $request_content
42+
* The Request content.
43+
*
44+
* @return array
45+
* The request data array.
46+
*/
47+
public function getRequestDataArray($request_content);
48+
49+
/**
50+
* Gets the IPN URL to be used for validation for IPN data.
51+
*
52+
* @param array $ipn_data
53+
* The IPN request data from PayPal.
54+
*
55+
* @return string
56+
* The IPN validation URL.
57+
*/
58+
public function getIpnValidationUrl(array $ipn_data);
59+
60+
}

0 commit comments

Comments
 (0)