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

Remove is_live parameter from civicrm_stripe_customers. We can derive from payment processor id

parent 116560e7
Branches
Tags
1 merge request!29Remove is_live parameter from civicrm_stripe_customers
......@@ -443,7 +443,6 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$customerParams = [
'contact_id' => $contactId,
'card_token' => $card_token,
'is_live' => !$this->_paymentProcessor['is_test'],
'processor_id' => $this->_paymentProcessor['id'],
'email' => $email,
];
......
......@@ -11,7 +11,7 @@ class CRM_Stripe_Customer {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public static function find($params) {
$requiredParams = ['is_live', 'processor_id'];
$requiredParams = ['processor_id'];
foreach ($requiredParams as $required) {
if (empty($params[$required])) {
throw new \Civi\Payment\Exception\PaymentProcessorException('Stripe Customer (find): Missing required parameter: ' . $required);
......@@ -22,18 +22,17 @@ class CRM_Stripe_Customer {
}
$queryParams = [
1 => [$params['contact_id'], 'String'],
2 => [$params['is_live'] ? 1 : 0, 'Boolean'],
3 => [$params['processor_id'], 'Positive'],
2 => [$params['processor_id'], 'Positive'],
];
return CRM_Core_DAO::singleValueQuery("SELECT id
FROM civicrm_stripe_customers
WHERE contact_id = %1 AND is_live = %2 AND processor_id = %3", $queryParams);
WHERE contact_id = %1 AND processor_id = %3", $queryParams);
}
/**
* Find the details (contact_id, is_live, processor_id) for an existing Stripe customer in the CiviCRM database
* Find the details (contact_id, processor_id) for an existing Stripe customer in the CiviCRM database
*
* @param string $stripeCustomerId
*
......@@ -44,28 +43,26 @@ class CRM_Stripe_Customer {
1 => [$stripeCustomerId, 'String'],
];
$dao = CRM_Core_DAO::executeQuery("SELECT contact_id, is_live, processor_id
$dao = CRM_Core_DAO::executeQuery("SELECT contact_id, processor_id
FROM civicrm_stripe_customers
WHERE id = %1", $queryParams);
$dao->fetch();
return [
'contact_id' => $dao->contact_id,
'is_live' => $dao->is_live,
'processor_id' => $dao->processor_id,
];
}
/**
* Find the details (contact_id, is_live, processor_id) for an existing Stripe customer in the CiviCRM database
* Find the details (contact_id, processor_id) for an existing Stripe customer in the CiviCRM database
*
* @param string $stripeCustomerId
*
* @return array|null
*/
public static function getAll($isLive, $processorId, $options = []) {
public static function getAll($processorId, $options = []) {
$queryParams = [
1 => [$isLive ? 1 : 0, 'Boolean'],
2 => [$processorId, 'Integer'],
1 => [$processorId, 'Integer'],
];
$limitClause = '';
......@@ -79,7 +76,7 @@ class CRM_Stripe_Customer {
$customerIds = [];
$dao = CRM_Core_DAO::executeQuery("SELECT id
FROM civicrm_stripe_customers
WHERE is_live = %1 AND processor_id = %2 {$limitClause}", $queryParams);
WHERE processor_id = %2 {$limitClause}", $queryParams);
while ($dao->fetch()) {
$customerIds[] = $dao->id;
}
......@@ -94,7 +91,7 @@ class CRM_Stripe_Customer {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public static function add($params) {
$requiredParams = ['contact_id', 'customer_id', 'is_live', 'processor_id'];
$requiredParams = ['contact_id', 'customer_id', 'processor_id'];
foreach ($requiredParams as $required) {
if (empty($params[$required])) {
throw new \Civi\Payment\Exception\PaymentProcessorException('Stripe Customer (add): Missing required parameter: ' . $required);
......@@ -104,11 +101,10 @@ class CRM_Stripe_Customer {
$queryParams = [
1 => [$params['contact_id'], 'String'],
2 => [$params['customer_id'], 'String'],
3 => [$params['is_live'] ? 1 : 0, 'Boolean'],
4 => [$params['processor_id'], 'Integer'],
3 => [$params['processor_id'], 'Integer'],
];
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_stripe_customers
(contact_id, id, is_live, processor_id) VALUES (%1, %2, %3, %4)", $queryParams);
(contact_id, id, processor_id) VALUES (%1, %2, %3)", $queryParams);
}
/**
......@@ -120,7 +116,7 @@ class CRM_Stripe_Customer {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public static function create($params, $paymentProcessor) {
$requiredParams = ['contact_id', 'card_token', 'is_live', 'processor_id'];
$requiredParams = ['contact_id', 'card_token', 'processor_id'];
// $optionalParams = ['email'];
foreach ($requiredParams as $required) {
if (empty($params[$required])) {
......@@ -153,7 +149,6 @@ class CRM_Stripe_Customer {
$params = [
'contact_id' => $params['contact_id'],
'customer_id' => $stripeCustomer->id,
'is_live' => $params['is_live'],
'processor_id' => $params['processor_id'],
];
self::add($params);
......@@ -169,7 +164,7 @@ class CRM_Stripe_Customer {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public static function delete($params) {
$requiredParams = ['is_live', 'processor_id'];
$requiredParams = ['processor_id'];
foreach ($requiredParams as $required) {
if (empty($params[$required])) {
throw new \Civi\Payment\Exception\PaymentProcessorException('Stripe Customer (delete): Missing required parameter: ' . $required);
......@@ -182,20 +177,18 @@ class CRM_Stripe_Customer {
if (!empty($params['id'])) {
$queryParams = [
1 => [$params['id'], 'String'],
2 => [$params['is_live'] ? 1 : 0, 'Boolean'],
3 => [$params['processor_id'], 'Integer'],
2 => [$params['processor_id'], 'Integer'],
];
$sql = "DELETE FROM civicrm_stripe_customers
WHERE id = %1 AND is_live = %2 AND processor_id = %3";
WHERE id = %1 AND processor_id = %3";
}
else {
$queryParams = [
1 => [$params['contact_id'], 'String'],
2 => [$params['is_live'] ? 1 : 0, 'Boolean'],
3 => [$params['processor_id'], 'Integer'],
2 => [$params['processor_id'], 'Integer'],
];
$sql = "DELETE FROM civicrm_stripe_customers
WHERE contact_id = %1 AND is_live = %2 AND processor_id = %3";
WHERE contact_id = %1 AND processor_id = %3";
}
CRM_Core_DAO::executeQuery($sql, $queryParams);
}
......
......@@ -19,8 +19,6 @@ function _civicrm_api3_stripe_customer_get_spec(&$spec) {
$spec['id']['type'] = CRM_Utils_Type::T_STRING;
$spec['contact_id']['title'] = ts("CiviCRM Contact ID");
$spec['contact_id']['type'] = CRM_Utils_Type::T_INT;
$spec['is_live']['title'] = ts("Is live processor");
$spec['is_live']['type'] = CRM_Utils_Type::T_BOOLEAN;
$spec['processor_id']['title'] = ts("Payment Processor ID");
$spec['processor_id']['type'] = CRM_Utils_Type::T_INT;
}
......@@ -51,11 +49,6 @@ function civicrm_api3_stripe_customer_get($params) {
$index++;
break;
case 'is_live':
$where[$index] = "{$key}=%{$index}";
$whereParam[$index] = [$value, 'Boolean'];
$index++;
break;
}
}
......@@ -70,7 +63,6 @@ function civicrm_api3_stripe_customer_get($params) {
$result = [
'id' => $dao->id,
'contact_id' => $dao->contact_id,
'is_live' => $dao->is_live,
'processor_id' => $dao->processor_id,
];
if ($dao->email) {
......@@ -93,9 +85,6 @@ function _civicrm_api3_stripe_customer_delete_spec(&$spec) {
$spec['id']['type'] = CRM_Utils_Type::T_STRING;
$spec['contact_id']['title'] = ts("CiviCRM Contact ID");
$spec['contact_id']['type'] = CRM_Utils_Type::T_INT;
$spec['is_live']['title'] = ts("Is live processor");
$spec['is_live']['type'] = CRM_Utils_Type::T_BOOLEAN;
$spec['is_live']['api.required'] = TRUE;
$spec['processor_id']['title'] = ts("Payment Processor ID");
$spec['processor_id']['type'] = CRM_Utils_Type::T_INT;
$spec['processor_id']['api.required'] = TRUE;
......@@ -198,8 +187,6 @@ function _civicrm_api3_stripe_customer_updatestripemetadata_spec(&$spec) {
$spec['id']['api.required'] = FALSE;
$spec['dryrun']['api.required'] = TRUE;
$spec['dryrun']['type'] = CRM_Utils_Type::T_BOOLEAN;
$spec['is_live']['api.required'] = FALSE;
$spec['is_live']['type'] = CRM_Utils_Type::T_BOOLEAN;
$spec['processor_id']['api.required'] = FALSE;
$spec['processor_id']['type'] = CRM_Utils_Type::T_INT;
}
......@@ -222,10 +209,10 @@ function civicrm_api3_stripe_customer_updatestripemetadata($params) {
// Check params
if (empty($params['id'])) {
// We're doing an update on all stripe customers
if (!isset($params['is_live']) || !isset($params['processor_id'])) {
throw new CiviCRM_API3_Exception('Missing required parameters is_live and/or processor_id when using without a customer id');
if (!isset($params['processor_id'])) {
throw new CiviCRM_API3_Exception('Missing required parameters processor_id when using without a customer id');
}
$customerIds = CRM_Stripe_Customer::getAll($params['is_live'], $params['processor_id'], $params['options']);
$customerIds = CRM_Stripe_Customer::getAll($params['processor_id'], $params['options']);
}
else {
$customerIds = [$params['id']];
......
......@@ -19,8 +19,6 @@ function _civicrm_api3_stripe_subscription_get_spec(&$spec) {
$spec['customer_id']['type'] = CRM_Utils_Type::T_STRING;
$spec['contribution_recur_id']['title'] = ts("Contribution Recur ID");
$spec['contribution_recur_id']['type'] = CRM_Utils_Type::T_INT;
$spec['is_live']['title'] = ts("Is live processor");
$spec['is_live']['type'] = CRM_Utils_Type::T_BOOLEAN;
$spec['processor_id']['title'] = ts("Payment Processor ID");
$spec['processor_id']['type'] = CRM_Utils_Type::T_INT;
$spec['end_time_id']['title'] = ts("End Time");
......@@ -57,11 +55,6 @@ function civicrm_api3_stripe_subscription_get($params) {
$index++;
break;
case 'is_live':
$where[$index] = "{$key}=%{$index}";
$whereParam[$index] = [$value, 'Boolean'];
$index++;
break;
}
}
......@@ -78,7 +71,6 @@ function civicrm_api3_stripe_subscription_get($params) {
'subscription_id' => $dao->subscription_id,
'customer_id' => $dao->customer_id,
'contribution_recur_id' => $dao->contribution_recur_id,
'is_live' => $dao->is_live,
'processor_id' => $dao->processor_id,
'end_time' => $dao->end_time,
];
......
......@@ -2,7 +2,6 @@
CREATE TABLE IF NOT EXISTS `civicrm_stripe_customers` (
`id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`contact_id` int(10) UNSIGNED DEFAULT NULL COMMENT 'FK ID from civicrm_contact',
`is_live` tinyint(4) NOT NULL COMMENT 'Whether this is a live or test transaction',
`processor_id` int(10) DEFAULT NULL COMMENT 'ID from civicrm_payment_processor',
UNIQUE KEY `id` (`id`),
CONSTRAINT `FK_civicrm_stripe_customers_contact_id` FOREIGN KEY (`contact_id`)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment