Skip to content
Snippets Groups Projects
Commit 454c055c authored by Andie Hunt's avatar Andie Hunt
Browse files

Stripe customers per-account

parent 9d78a704
No related branches found
No related tags found
No related merge requests found
......@@ -310,11 +310,12 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
// Prepare escaped query params.
$query_params = array(
1 => array($email, 'String'),
2 => array($this->_paymentProcessor['id'], 'Integer'),
);
$customer_query = CRM_Core_DAO::singleValueQuery("SELECT id
FROM civicrm_stripe_customers
WHERE email = %1 AND is_live = '{$this->_islive}'", $query_params);
WHERE email = %1 AND is_live = '{$this->_islive}' AND processor_id = %2", $query_params);
/****
* If for some reason you cannot use Stripe.js and you are aware of PCI Compliance issues,
......@@ -368,10 +369,11 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$query_params = array(
1 => array($email, 'String'),
2 => array($stripe_customer->id, 'String'),
3 => array($this->_paymentProcessor['id'], 'Integer'),
);
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_stripe_customers
(email, id, is_live) VALUES (%1, %2, '{$this->_islive}')", $query_params);
(email, id, is_live, processor_id) VALUES (%1, %2, '{$this->_islive}', %3)", $query_params);
}
else {
CRM_Core_Error::fatal(ts('There was an error saving new customer within Stripe. Is Stripe down?'));
......@@ -421,17 +423,19 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
// Delete whatever we have for this customer.
$query_params = array(
1 => array($email, 'String'),
2 => array($this->_paymentProcessor['id'], 'Integer'),
);
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_stripe_customers
WHERE email = %1 AND is_live = '{$this->_islive}'", $query_params);
WHERE email = %1 AND is_live = '{$this->_islive}' AND processor_id = %2", $query_params);
// Create new record for this customer.
$query_params = array(
1 => array($email, 'String'),
2 => array($stripe_customer->id, 'String'),
3 => array($this->_paymentProcessor['id'], 'Integer'),
);
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_stripe_customers (email, id, is_live)
VALUES (%1, %2, '{$this->_islive}')", $query_params);
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_stripe_customers (email, id, is_live, processor_id)
VALUES (%1, %2, '{$this->_islive}, %3')", $query_params);
}
else {
// Customer was found in civicrm_stripe database, but unable to be
......@@ -576,7 +580,7 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
// subscription first.
$subscriptions = $stripe_customer->offsetGet('subscriptions');
$data = $subscriptions->offsetGet('data');
if(!empty($data)) {
$status = $data[0]->offsetGet('status');
......
......@@ -51,4 +51,23 @@ class CRM_Stripe_Upgrader extends CRM_Stripe_Upgrader_Base {
}
return TRUE;
}
/**
* Add processor_id column to civicrm_stripe_customers table.
*
* @return TRUE on success
* @throws Exception
*/
public function upgrade_4_6_01() {
$procIdCheck = mysql_query("SHOW COLUMNS FROM `civicrm_stripe_customers` LIKE 'processor_id'");
if (mysql_num_rows($procIdCheck)) {
$this->ctx->log->info('Skipped civicrm_stripe update 4601. Column processor_id already present on civicrm_stripe_customers table.');
}
else {
$this->ctx->log->info('Applying civicrm_stripe update 4601. Adding processor_id to civicrm_stripe_customers table.');
CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_stripe_customers ADD COLUMN `processor_id` int(10) DEFAULT NULL COMMENT "ID from civicrm_payment_processor"');
}
return TRUE;
}
}
......@@ -32,6 +32,7 @@ function stripe_civicrm_install() {
`email` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
`id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`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`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment