Commit bd5fb015 authored by mattwire's avatar mattwire
Browse files

Implement new method for retrying IPN notifications using Mjwpayment.notificationretry

parent 775abc1e
......@@ -14,7 +14,7 @@ use \JohnConde\Authnet\AuthnetWebhook as AuthnetWebhook;
use \JohnConde\Authnet\AuthnetApiFactory as AuthnetApiFactory;
use \JohnConde\Authnet\AuthnetWebhooksResponse as AuthnetWebhooksResponse;
class CRM_Core_Payment_AuthNetIPN extends CRM_Core_Payment_BaseIPN {
class CRM_Core_Payment_AuthNetIPN {
use CRM_Core_Payment_MJWIPNTrait;
......@@ -41,25 +41,24 @@ class CRM_Core_Payment_AuthNetIPN extends CRM_Core_Payment_BaseIPN {
/**
* CRM_Core_Payment_AuthNetIPN constructor.
*
* @param string $ipnData
* @param string $rawData
* json encoded string
* @param bool $verifyRequest
* Should we check the received event is valid/matches what the payment provider has?
*
* @throws \JohnConde\Authnet\AuthnetInvalidCredentialsException
* @throws \JohnConde\Authnet\AuthnetInvalidJsonException
*/
public function __construct($ipnData) {
$this->_params = $ipnData;
public function __construct($rawData, $verifyRequest = TRUE) {
$this->getPaymentProcessor();
$webhook = new AuthnetWebhook(CRM_Core_Payment_AuthorizeNetCommon::getSignature($this->_paymentProcessor->getPaymentProcessor()), $ipnData);
if ($webhook->isValid()) {
// Get the transaction ID
$this->eventType = $webhook->eventType;
$this->trxnId = $webhook->payload->id;
}
else {
$webhook = new AuthnetWebhook(CRM_Core_Payment_AuthorizeNetCommon::getSignature($this->_paymentProcessor->getPaymentProcessor()), $rawData);
if ($verifyRequest && !$webhook->isValid()) {
$this->exception('Webhook not valid');
}
parent::__construct();
$this->eventType = $webhook->eventType;
$this->trxnId = $webhook->payload->id;
}
/**
......
......@@ -780,4 +780,24 @@ abstract class CRM_Core_Payment_AuthorizeNetCommon extends CRM_Core_Payment {
}
}
/**
* @param int $paymentProcessorID
* The actual payment processor ID that should be used.
* @param $dataRaw
* The "raw" data, eg. a JSON string that is saved in the civicrm_system_log.context table
* @param bool $verifyRequest
* Should we verify the request data with the payment processor (eg. retrieve it again?).
*
* @return bool
* @throws \CiviCRM_API3_Exception
* @throws \ErrorException
* @throws \JohnConde\Authnet\AuthnetInvalidCredentialsException
* @throws \JohnConde\Authnet\AuthnetInvalidServerException
*/
public static function processPaymentNotification($paymentProcessorID, $dataRaw, $verifyRequest = TRUE) {
$_GET['processor_id'] = $paymentProcessorID;
$ipnClass = new CRM_Core_Payment_AuthNetIPN($dataRaw, $verifyRequest);
return $ipnClass->main();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment