Skip to content
Snippets Groups Projects
Commit f1da0fd6 authored by mattwire's avatar mattwire
Browse files

Don't initialise paymentprocessor twice for IPN. Change...

Don't initialise paymentprocessor twice for IPN. Change stripe_webhook_processing_limit so that 0=never process immediately
parent 830aecd6
Branches
Tags
1 merge request!176Release 6.7
......@@ -13,6 +13,7 @@ use Civi\Api4\PaymentprocessorWebhook;
use CRM_Stripe_ExtensionUtil as E;
use Civi\Payment\PropertyBag;
use Stripe\Stripe;
use Civi\Payment\Exception\PaymentProcessorException;
/**
* Class CRM_Core_Payment_Stripe
......@@ -1185,7 +1186,6 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
return;
}
$ipnClass->setVerifyData(TRUE);
$ipnClass->setPaymentProcessor(CRM_Utils_Request::retrieveValue('processor_id', 'Positive', NULL, FALSE, 'GET'));
$ipnClass->onReceiveWebhook();
}
......@@ -1209,7 +1209,11 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
http_response_code(200);
$event = json_decode($rawData);
$ipnClass = new CRM_Core_Payment_StripeIPN();
$paymentProcessorObject = \Civi\Payment\System::singleton()->getById($paymentProcessorID);
if (!($paymentProcessorObject instanceof CRM_Core_Payment_Stripe)) {
throw new PaymentProcessorException('Failed to get payment processor');
}
$ipnClass = new CRM_Core_Payment_StripeIPN($paymentProcessorObject);
$ipnClass->setEventID($event->id);
if (!$ipnClass->setEventType($event->type)) {
// We don't handle this event
......@@ -1219,7 +1223,6 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
if (!$verifyRequest) {
$ipnClass->setData($event->data);
}
$ipnClass->setPaymentProcessor($paymentProcessorID);
$ipnClass->setExceptionMode(FALSE);
if (isset($emailReceipt)) {
$ipnClass->setSendEmailReceipt($emailReceipt);
......
......@@ -232,7 +232,7 @@ class CRM_Core_Payment_StripeIPN {
// We have not received this webhook before.
// Some webhooks we always add to the queue and do not process immediately (eg. invoice.finalized)
if (in_array($this->eventType, CRM_Stripe_Webhook::getDelayProcessingEvents())) {
// Process the webhook immediately. @todo is this comment correct? surely it means do NOT process webhook immediately?
// Never process the webhook immediately.
$processWebhook = FALSE;
}
}
......@@ -271,10 +271,9 @@ class CRM_Core_Payment_StripeIPN {
->addWhere('processed_date', 'IS NULL')
->execute();
// Limit on webhooks that will be processed immediately. Otherwise we delay execution. 0=unlimited.
// Limit on webhooks that will be processed immediately. Otherwise we delay execution.
$webhookProcessingLimit = (int)\Civi::settings()->get('stripe_webhook_processing_limit');
if (!$processWebhook
|| (($toBeProcessedWebhook->rowCount > $webhookProcessingLimit) && ($webhookProcessingLimit > 0))) {
if (!$processWebhook || ($toBeProcessedWebhook->rowCount > $webhookProcessingLimit)) {
return TRUE;
}
......
......@@ -9,6 +9,7 @@
+--------------------------------------------------------------------+
*/
use Civi\Payment\Exception\PaymentProcessorException;
use CRM_Stripe_ExtensionUtil as E;
/**
......@@ -31,8 +32,11 @@ function _civicrm_api3_stripe_invoice_process_spec(&$spec) {
}
function civicrm_api3_stripe_invoice_process($params) {
$ipnClass = new CRM_Core_Payment_StripeIPN();
$ipnClass->setPaymentProcessor($params['payment_processor_id']);
$paymentProcessorObject = \Civi\Payment\System::singleton()->getById($params['payment_processor_id']);
if (!($paymentProcessorObject instanceof CRM_Core_Payment_Stripe)) {
throw new PaymentProcessorException('Failed to get payment processor');
}
$ipnClass = new CRM_Core_Payment_StripeIPN($paymentProcessorObject);
$stripeInvoiceObject = $ipnClass->getPaymentProcessor()->stripeClient->invoices->retrieve($params['invoice_id']);
if ($stripeInvoiceObject->paid === TRUE) {
......
......@@ -178,7 +178,7 @@ Required by the paymentRequest button. 2-character code (eg. "US") that can be f
'is_domain' => 1,
'is_contact' => 0,
'title' => E::ts('Maximum number of webhooks to process simultaneously.'),
'description' => E::ts('Default 50. 0=Unlimited. This helps prevents webhooks from Stripe failing if a large number are triggered at the same time by delaying processing of any over this limit.'),
'description' => E::ts('Default 50. This helps prevents webhooks from Stripe failing if a large number are triggered at the same time by delaying processing of any over this limit.'),
'html_attributes' => [
'size' => 10,
'maxlength' => 3,
......
......@@ -627,7 +627,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
* want stripe to resend something again later)
*/
public function ipn($event, $verifyRequest = TRUE, $exceptionOnFailure=FALSE) {
$ipnClass = new CRM_Core_Payment_StripeIPN();
$ipnClass = new CRM_Core_Payment_StripeIPN($this->paymentObject);
if ($exceptionOnFailure) {
// We don’t' expect failure, so ensure exceptions are not caught.
......@@ -642,7 +642,6 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
if (!$verifyRequest) {
$ipnClass->setData($event->data);
}
$ipnClass->setPaymentProcessor($this->paymentProcessorID);
$ipnClass->setExceptionMode(FALSE);
// This code commented as $emailReceipt is never passed in/set.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment