// Don't touch the contributionRecur as it's updated automatically by Contribution.repeattransaction
}
}
returnTRUE;
returnTRUE;
}
}
...
@@ -217,7 +204,16 @@ class CRM_Core_Payment_StripeIPN {
...
@@ -217,7 +204,16 @@ class CRM_Core_Payment_StripeIPN {
case'invoice.payment_succeeded':
case'invoice.payment_succeeded':
// Successful recurring payment. Either we are completing an existing contribution or it's the next one in a subscription
// Successful recurring payment. Either we are completing an existing contribution or it's the next one in a subscription
if(!$this->setInfo()){
if(!$this->setInfo()){
returnTRUE;
if(!$this->contribution_recur_id){
returnTRUE;
}
else{
// We have a recurring contribution but have not yet received invoice.finalized so we don't have the next contribution yet.
// invoice.payment_succeeded sometimes comes before invoice.finalized so trigger the same behaviour here to create a new contribution
$this->createNextContributionForRecur();
// Now get the contribution we just created.
$this->getContribution();
}
}
}
if(civicrm_api3('Mjwpayment','get_payment',[
if(civicrm_api3('Mjwpayment','get_payment',[
'trxn_id'=>$this->charge_id,
'trxn_id'=>$this->charge_id,
...
@@ -392,6 +388,29 @@ class CRM_Core_Payment_StripeIPN {
...
@@ -392,6 +388,29 @@ class CRM_Core_Payment_StripeIPN {
returnTRUE;
returnTRUE;
}
}
/**
* Create the next contribution for a recurring contribution
* This happens when Stripe generates a new invoice and notifies us (normally by invoice.finalized but invoice.payment_succeeded sometimes arrives first).
*
* @throws \CiviCRM_API3_Exception
*/
publicfunctioncreateNextContributionForRecur(){
// We have a recurring contribution but no contribution so we'll repeattransaction
// Stripe has generated a new invoice (next payment in a subscription) so we