From 2f6e1fa7ab290a61a6619a6e56ab036cdef4fd09 Mon Sep 17 00:00:00 2001 From: Matthew Wire <mjw@mjwconsult.co.uk> Date: Sun, 26 Apr 2020 22:04:29 +0100 Subject: [PATCH] Fix #191 - Add all possible Stripe subscription statuses --- CRM/Stripe/Api.php | 14 +++++++++++--- docs/recur.md | 12 ++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CRM/Stripe/Api.php b/CRM/Stripe/Api.php index bc572dd7..c0a1a96f 100644 --- a/CRM/Stripe/Api.php +++ b/CRM/Stripe/Api.php @@ -130,14 +130,22 @@ class CRM_Stripe_Api { case 'status_id': switch ($stripeObject->status) { + case \Stripe\Subscription::STATUS_INCOMPLETE: + return CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'); + case \Stripe\Subscription::STATUS_ACTIVE: + case \Stripe\Subscription::STATUS_TRIALING: return CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'In Progress'); - case \Stripe\Subscription::STATUS_CANCELED: - return CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'); + case \Stripe\Subscription::STATUS_PAST_DUE: return CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Overdue'); + + case \Stripe\Subscription::STATUS_CANCELED: + case \Stripe\Subscription::STATUS_UNPAID: + case \Stripe\Subscription::STATUS_INCOMPLETE_EXPIRED: default: - return NULL; + return CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'); + } case 'customer_id': diff --git a/docs/recur.md b/docs/recur.md index 051d457a..d6734775 100644 --- a/docs/recur.md +++ b/docs/recur.md @@ -27,3 +27,15 @@ You can cancel a recurring contribution from the Stripe Dashboard or from within 1. Stripe.com will cancel the subscription, send a webhook to your site and the recurring contribution will be marked as "Cancelled" in CiviCRM.  + +## Recurring statuses + +Recurring contributions start in the status "Pending". + +The Stripe subscription status is mapped to the recurring contribution status as follows: + +STATUS_INCOMPLETE => Pending +STATUS_ACTIVE => In Progress +STATUS_TRIALING => In Progress +STATUS_PAST_DUE => Overdue +STATUS_CANCELED / STATUS_UNPAID / STATUS_INCOMPLETE_EXPIRED => Cancelled -- GitLab