diff --git a/CRM/Core/Payment/StripeIPN.php b/CRM/Core/Payment/StripeIPN.php index 6b47499ed579ed4441589f4b13565ca11638338c..9af00c09bb0f62963821e650c74a6a2ffae851b0 100644 --- a/CRM/Core/Payment/StripeIPN.php +++ b/CRM/Core/Payment/StripeIPN.php @@ -20,6 +20,13 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN { // testing, we can properly test a failed recurring contribution. protected $verify_event = TRUE; + /** + * Do we send an email receipt for each contribution? + * + * @var int + */ + protected $is_email_receipt = NULL; + // Properties of the event. protected $event_type = NULL; protected $subscription_id = NULL; @@ -57,6 +64,47 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN { parent::__construct(); } + /** + * Set the value of is_email_receipt to use when a new contribution is received for a recurring contribution + * This is used for the API Stripe.Ipn function. If not set, we respect the value set on the ContributionRecur entity. + * + * @param int $sendReceipt The value of is_email_receipt + */ + public function setSendEmailReceipt($sendReceipt) { + switch ($sendReceipt) { + case 0: + $this->is_email_receipt = 0; + break; + + case 1: + $this->is_email_receipt = 1; + break; + + default: + $this->is_email_receipt = 0; + } + } + + /** + * Get the value of is_email_receipt to use when a new contribution is received for a recurring contribution + * This is used for the API Stripe.Ipn function. If not set, we respect the value set on the ContributionRecur entity. + * + * @return int + * @throws \CiviCRM_API3_Exception + */ + public function getSendEmailReceipt() { + if (isset($this->is_email_receipt)) { + return (int) $this->is_email_receipt; + } + if (!empty($this->contribution_recur_id)) { + $this->is_email_receipt = civicrm_api3('ContributionRecur', 'getvalue', [ + 'return' => ["is_email_receipt"], + 'id' => $this->contribution_recur_id, + ]); + } + return (int) $this->is_email_receipt; + } + /** * Store input array on the class. * We override base because our input parameter is an object @@ -236,7 +284,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN { 'trxn_id' => $this->charge_id, 'total_amount' => $this->amount, 'fee_amount' => $this->fee, - 'is_email_receipt' => 0, + 'is_email_receipt' => $this->getSendEmailReceipt(), )); } @@ -391,7 +439,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN { 'net_amount' => $this->net_amount, 'fee_amount' => $this->fee, 'payment_processor_id' => $this->_paymentProcessor['id'], - 'is_email_receipt' => 0, + 'is_email_receipt' => $this->getSendEmailReceipt(), )); } diff --git a/api/v3/Stripe/Ipn.php b/api/v3/Stripe/Ipn.php index 2515e9f1a2bfa329934caad82ea7d5688219c672..07cde844b0b9b456b0803c04c4f750a21fd315c3 100644 --- a/api/v3/Stripe/Ipn.php +++ b/api/v3/Stripe/Ipn.php @@ -23,6 +23,8 @@ function _civicrm_api3_stripe_Ipn_spec(&$spec) { $spec['id']['title'] = ts("CiviCRM System Log id to replay from system log."); $spec['evtid']['title'] = ts("An event id as generated by Stripe."); $spec['ppid']['title'] = ts("The payment processor to use (required if using evtid)"); + $spec['noreceipt']['title'] = ts("Set to 1 to override contribution page settings and do not send a receipt (default is off or 0). )"); + $spec['noreceipt']['api.default'] = 0; } /** @@ -77,6 +79,9 @@ function civicrm_api3_stripe_Ipn($params) { $_GET['processor_id'] = $ppid; $ipnClass = new CRM_Core_Payment_StripeIPN($object); $ipnClass->main(); + if ($params['noreceipt'] == 1) { + $ipnClass->setSendEmailReceipt(0); + } } else { trigger_error("The api depends on CRM_Core_Payment_StripeIPN");