Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
AbstractIpn Class Reference
Inheritance diagram for AbstractIpn:
Ipn

Public Member Functions

 __construct (\Magento\Paypal\Model\ConfigFactory $configFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory, array $data=[])
 
 getRequestData ($key=null)
 

Protected Member Functions

 _postBack ()
 
 _filterPaymentStatus ($ipnPaymentStatus)
 
 _debug ()
 
 _addDebugData ($key, $value)
 

Protected Attributes

 $_config
 
 $_ipnRequest
 
 $_debugData = []
 
 $_configFactory
 
 $_curlFactory
 

Detailed Description

Definition at line 11 of file AbstractIpn.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Paypal\Model\ConfigFactory  $configFactory,
\Psr\Log\LoggerInterface  $logger,
\Magento\Framework\HTTP\Adapter\CurlFactory  $curlFactory,
array  $data = [] 
)
Parameters
\Magento\Paypal\Model\ConfigFactory$configFactory
\Psr\Log\LoggerInterface$logger
\Magento\Framework\HTTP\Adapter\CurlFactory$curlFactory
array$data

Definition at line 48 of file AbstractIpn.php.

53  {
54  $this->_configFactory = $configFactory;
55  $this->logger = $logger;
56  $this->_curlFactory = $curlFactory;
57  $this->_ipnRequest = $data;
58  }
$logger
$configFactory
Definition: config_data.php:43

Member Function Documentation

◆ _addDebugData()

_addDebugData (   $key,
  $value 
)
protected
Parameters
string$key
array | string$value
Returns
$this

Definition at line 178 of file AbstractIpn.php.

179  {
180  $this->_debugData[$key] = $value;
181  return $this;
182  }
$value
Definition: gender.phtml:16

◆ _debug()

_debug ( )
protected

Log debug data to file

Returns
void

Definition at line 166 of file AbstractIpn.php.

167  {
168  if ($this->_config && $this->_config->getValue('debug')) {
169  $this->logger->debug(var_export($this->_debugData, true));
170  }
171  }

◆ _filterPaymentStatus()

_filterPaymentStatus (   $ipnPaymentStatus)
protected

Filter payment status from NVP into paypal/info format

Parameters
string$ipnPaymentStatus
Returns
string @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 127 of file AbstractIpn.php.

128  {
129  switch ($ipnPaymentStatus) {
130  case 'Created':
131  // break is intentionally omitted
132  case 'Completed':
134  case 'Denied':
136  case 'Expired':
138  case 'Failed':
140  case 'Pending':
142  case 'Refunded':
144  case 'Reversed':
146  case 'Canceled_Reversal':
148  case 'Processed':
150  case 'Voided':
152  default:
153  return '';
154  }
155  // documented in NVP, but not documented in IPN:
156  //Info::PAYMENTSTATUS_NONE
157  //Info::PAYMENTSTATUS_INPROGRESS
158  //Info::PAYMENTSTATUS_REFUNDEDPART
159  }
const PAYMENTSTATUS_COMPLETED
Definition: Info.php:117
const PAYMENTSTATUS_PROCESSED
Definition: Info.php:137
const PAYMENTSTATUS_UNREVERSED
Definition: Info.php:135
const PAYMENTSTATUS_REFUNDED
Definition: Info.php:129
const PAYMENTSTATUS_REVERSED
Definition: Info.php:133

◆ _postBack()

_postBack ( )
protected

Post back to PayPal to check whether this request is a valid one

Returns
void
Exceptions
RemoteServiceUnavailableException

Definition at line 81 of file AbstractIpn.php.

82  {
83  $httpAdapter = $this->_curlFactory->create();
84  $postbackQuery = http_build_query($this->getRequestData()) . '&cmd=_notify-validate';
85  $postbackUrl = $this->_config->getPayPalIpnUrl();
86  $this->_addDebugData('postback_to', $postbackUrl);
87 
88  $httpAdapter->setConfig(['verifypeer' => $this->_config->getValue('verifyPeer')]);
89  $httpAdapter->write(\Zend_Http_Client::POST, $postbackUrl, '1.1', ['Connection: close'], $postbackQuery);
90  try {
91  $postbackResult = $httpAdapter->read();
92  } catch (\Exception $e) {
93  $this->_addDebugData('http_error', ['error' => $e->getMessage(), 'code' => $e->getCode()]);
94  throw $e;
95  }
96 
97  /*
98  * Handle errors on PayPal side.
99  */
100  $responseCode = \Zend_Http_Response::extractCode($postbackResult);
101  if (empty($postbackResult) || in_array($responseCode, ['500', '502', '503'])) {
102  if (empty($postbackResult)) {
103  $reason = 'Empty response.';
104  } else {
105  $reason = 'Response code: ' . $responseCode . '.';
106  }
107  $this->_debugData['exception'] = 'PayPal IPN postback failure. ' . $reason;
108  throw new RemoteServiceUnavailableException(__($reason));
109  }
110 
111  $response = preg_split('/^\r?$/m', $postbackResult, 2);
112  $response = trim($response[1]);
113  if ($response != 'VERIFIED') {
114  $this->_addDebugData('postback', $postbackQuery);
115  $this->_addDebugData('postback_result', $postbackResult);
116  throw new \Exception('PayPal IPN postback failure. See system.log for details.');
117  }
118  }
$response
Definition: 404.php:11
__()
Definition: __.php:13
static extractCode($response_str)
Definition: Response.php:449

◆ getRequestData()

getRequestData (   $key = null)

IPN request data getter

Parameters
string$key
Returns
array|string

Definition at line 66 of file AbstractIpn.php.

67  {
68  if (null === $key) {
69  return $this->_ipnRequest;
70  }
71  return isset($this->_ipnRequest[$key]) ? $this->_ipnRequest[$key] : null;
72  }

Field Documentation

◆ $_config

$_config
protected

Definition at line 16 of file AbstractIpn.php.

◆ $_configFactory

$_configFactory
protected

Definition at line 35 of file AbstractIpn.php.

◆ $_curlFactory

$_curlFactory
protected

Definition at line 40 of file AbstractIpn.php.

◆ $_debugData

$_debugData = []
protected

Definition at line 30 of file AbstractIpn.php.

◆ $_ipnRequest

$_ipnRequest
protected

Definition at line 23 of file AbstractIpn.php.


The documentation for this class was generated from the following file: