Commit 1212b577 authored by mattwire's avatar mattwire

Update stripe API compatibility, cleanup some code

parent ee4bfa86
...@@ -9,12 +9,10 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -9,12 +9,10 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
use CRM_Core_Payment_StripeTrait; use CRM_Core_Payment_StripeTrait;
/** /**
* We only need one instance of this object. So we use the singleton
* pattern and cache the instance in this variable
* *
* @var object * @var string
*/ */
private static $_singleton = NULL; protected $_stripeAPIVersion = '2019-02-19';
/** /**
* Mode of operation: live or test. * Mode of operation: live or test.
...@@ -23,13 +21,6 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -23,13 +21,6 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
*/ */
protected $_mode = NULL; protected $_mode = NULL;
/**
* TRUE if we are dealing with a live transaction
*
* @var boolean
*/
private $_islive = FALSE;
/** /**
* Constructor * Constructor
* *
...@@ -40,7 +31,6 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -40,7 +31,6 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
*/ */
public function __construct($mode, &$paymentProcessor) { public function __construct($mode, &$paymentProcessor) {
$this->_mode = $mode; $this->_mode = $mode;
$this->_islive = ($mode == 'live' ? 1 : 0);
$this->_paymentProcessor = $paymentProcessor; $this->_paymentProcessor = $paymentProcessor;
$this->_processorName = ts('Stripe'); $this->_processorName = ts('Stripe');
} }
...@@ -178,7 +168,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -178,7 +168,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$planId = $params['membership_type_tag'] . $planId; $planId = $params['membership_type_tag'] . $planId;
} }
if (!$this->_islive) { if ($this->_paymentProcessor['is_test']) {
$planId .= '-test'; $planId .= '-test';
} }
...@@ -192,7 +182,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -192,7 +182,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
if ($err['code'] == 'resource_missing') { if ($err['code'] == 'resource_missing') {
$formatted_amount = number_format(($amount / 100), 2); $formatted_amount = number_format(($amount / 100), 2);
$productName = "CiviCRM " . (isset($params['membership_name']) ? $params['membership_name'] . ' ' : '') . "every {$params['frequency_interval']} {$params['frequency_unit']}(s) {$formatted_amount}{$currency}"; $productName = "CiviCRM " . (isset($params['membership_name']) ? $params['membership_name'] . ' ' : '') . "every {$params['frequency_interval']} {$params['frequency_unit']}(s) {$formatted_amount}{$currency}";
if (!$this->_islive) { if ($this->_paymentProcessor['is_test']) {
$productName .= '-test'; $productName .= '-test';
} }
$product = \Stripe\Product::create(array( $product = \Stripe\Product::create(array(
...@@ -452,7 +442,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -452,7 +442,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$customerParams = [ $customerParams = [
'contact_id' => $contactId, 'contact_id' => $contactId,
'card_token' => $card_token, 'card_token' => $card_token,
'is_live' => $this->_islive, 'is_live' => !$this->_paymentProcessor['is_test'],
'processor_id' => $this->_paymentProcessor['id'], 'processor_id' => $this->_paymentProcessor['id'],
'email' => $email, 'email' => $email,
]; ];
...@@ -858,7 +848,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { ...@@ -858,7 +848,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
} }
/** /**
* Process incoming notification. * Process incoming payment notification (IPN).
* *
* @throws \CRM_Core_Exception * @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
......
...@@ -20,7 +20,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN { ...@@ -20,7 +20,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
* *
* @var int * @var int
*/ */
protected $is_email_receipt = 1; public $is_email_receipt = 1;
// By default, always retrieve the event from stripe to ensure we are // By default, always retrieve the event from stripe to ensure we are
// not being fed garbage. However, allow an override so when we are // not being fed garbage. However, allow an override so when we are
...@@ -53,14 +53,14 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN { ...@@ -53,14 +53,14 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
/** /**
* CRM_Core_Payment_StripeIPN constructor. * CRM_Core_Payment_StripeIPN constructor.
* *
* @param $inputData * @param $ipnData
* @param bool $verify * @param bool $verify
* *
* @throws \CRM_Core_Exception * @throws \CRM_Core_Exception
*/ */
public function __construct($inputData, $verify = TRUE) { public function __construct($ipnData, $verify = TRUE) {
$this->verify_event = $verify; $this->verify_event = $verify;
$this->setInputParameters($inputData); $this->setInputParameters($ipnData);
parent::__construct(); parent::__construct();
} }
......
...@@ -8,11 +8,11 @@ Latest releases can be found here: https://civicrm.org/extensions/stripe-payment ...@@ -8,11 +8,11 @@ Latest releases can be found here: https://civicrm.org/extensions/stripe-payment
View this extension in the [Extension Directory](https://civicrm.org/extensions/stripe-payment-processor). View this extension in the [Extension Directory](https://civicrm.org/extensions/stripe-payment-processor).
## Compatibility / Requirements ## Compatibility / Requirements
* CiviCRM 5.3+ * CiviCRM 5.10+
* PHP 5.6+ * PHP 7.0+
* Jquery 1.10 (Use jquery_update module on Drupal). * Jquery 1.10 (Use jquery_update module on Drupal).
* Drupal 7 / Joomla / Wordpress (latest supported release). *Not currently tested with other CMS but it may work.* * Drupal 7 / Joomla / Wordpress (latest supported release). *Not currently tested with other CMS but it may work.*
* Stripe API version: 2018-11-08 * Stripe API version: 2019-02-19
* Drupal webform_civicrm 7.x-4.22+ (if using webform integration) * Drupal webform_civicrm 7.x-4.22+ (if using webform integration)
## Credits ## Credits
......
## Release 5.3
There are no database changes in this release but you should update your Stripe webhook API version to 2019-02-19.
## Release 5.2 ## Release 5.2
*This release introduces a number of new features, standardises the behaviour of recurring contributions/memberships to match standard CiviCRM functionality and does a major cleanup of the backend code to improve stability and allow for new features.* *This release introduces a number of new features, standardises the behaviour of recurring contributions/memberships to match standard CiviCRM functionality and does a major cleanup of the backend code to improve stability and allow for new features.*
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<version>5.2</version> <version>5.2</version>
<develStage>stable</develStage> <develStage>stable</develStage>
<compatibility> <compatibility>
<ver>5.3</ver> <ver>5.10.3</ver>
</compatibility> </compatibility>
<comments>Original Author: Joshua Walker (drastik) - Drastik by Design. <comments>Original Author: Joshua Walker (drastik) - Drastik by Design.
Jamie Mcclelland (ProgressiveTech) did a lot of the 5.x compatibility work. Jamie Mcclelland (ProgressiveTech) did a lot of the 5.x compatibility work.
......
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