diff --git a/CRM/Stripe/AJAX.php b/CRM/Stripe/AJAX.php index 431d0722cddb792c284e051dda025f432e4884f8..96cb3439420e63a0a3909905795772300b6324b7 100644 --- a/CRM/Stripe/AJAX.php +++ b/CRM/Stripe/AJAX.php @@ -109,16 +109,25 @@ class CRM_Stripe_AJAX { \Civi\Firewall\Event\FraudEvent::trigger(\CRM_Utils_System::ipAddress(), 'CRM_Stripe_AJAX::confirmPayment'); } } + // Save the "error" in the paymentIntent table in in case investigation is required. + $intentParams = [ + 'paymentintent_id' => 'null', + 'payment_processor_id' => $processorID, + 'status' => 'failed', + 'description' => "{$e->getMessage()};{$title}", + 'referrer' => $_SERVER['HTTP_REFERER'], + ]; + CRM_Stripe_BAO_StripePaymentintent::create($intentParams); CRM_Utils_JSON::output(['error' => ['message' => $e->getMessage()]]); } } - // Save the generated paymentIntent in the CiviCRM database for later tracking $intentParams = [ 'paymentintent_id' => $intent->id, 'payment_processor_id' => $processorID, 'status' => $intent->status, - 'description' => $title, + 'description' => ";{$title}", + 'referrer' => $_SERVER['HTTP_REFERER'], ]; CRM_Stripe_BAO_StripePaymentintent::create($intentParams); diff --git a/CRM/Stripe/DAO/StripePaymentintent.php b/CRM/Stripe/DAO/StripePaymentintent.php index b59cbc42715263ac1854bb950b0b67dab94040ad..681afe246e6d0a5c32fda5780b39711bad6a1d01 100644 --- a/CRM/Stripe/DAO/StripePaymentintent.php +++ b/CRM/Stripe/DAO/StripePaymentintent.php @@ -2,17 +2,20 @@ /** * @package CRM - * @copyright CiviCRM LLC (c) 2004-2019 + * @copyright CiviCRM LLC https://civicrm.org/licensing * - * Generated from /home/dev/civicrm/civicrm-buildkit/build/dmaster/sites/default/files/civicrm/ext/civicrm-stripe/xml/schema/CRM/Stripe/StripePaymentintent.xml + * Generated from /home/matthew/buildkit/build/d7master/web/sites/default/files/civicrm/ext/civicrm-stripe/xml/schema/CRM/Stripe/StripePaymentintent.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:9eb72d282f516624404a0f9cf806f534) + * (GenCodeChecksum:7a92c93121b3c4206316369a15581b60) */ +use \CRM_Stripe_ExtensionUtil as E; /** * Database access object for the StripePaymentintent entity. */ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO { + const EXT = E::LONG_NAME; + const TABLE_ADDED = ''; /** * Static instance to hold the table name. @@ -98,6 +101,13 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO { */ public $flags; + /** + * HTTP referrer of this paymentIntent + * + * @var string + */ + public $referrer; + /** * Class constructor. */ @@ -106,6 +116,13 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO { parent::__construct(); } + /** + * Returns localized title of this entity. + */ + public static function getEntityTitle() { + return E::ts('Stripe Paymentintents'); + } + /** * Returns foreign keys and entity references. * @@ -133,19 +150,20 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO { 'id' => [ 'name' => 'id', 'type' => CRM_Utils_Type::T_INT, - 'description' => CRM_Stripe_ExtensionUtil::ts('Unique ID'), + 'description' => E::ts('Unique ID'), 'required' => TRUE, 'where' => 'civicrm_stripe_paymentintent.id', 'table_name' => 'civicrm_stripe_paymentintent', 'entity' => 'StripePaymentintent', 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', 'localizable' => 0, + 'add' => NULL, ], 'paymentintent_id' => [ 'name' => 'paymentintent_id', 'type' => CRM_Utils_Type::T_STRING, - 'title' => CRM_Stripe_ExtensionUtil::ts('PaymentIntent ID'), - 'description' => CRM_Stripe_ExtensionUtil::ts('The PaymentIntent ID'), + 'title' => E::ts('PaymentIntent ID'), + 'description' => E::ts('The PaymentIntent ID'), 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, 'where' => 'civicrm_stripe_paymentintent.paymentintent_id', @@ -153,39 +171,43 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO { 'entity' => 'StripePaymentintent', 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', 'localizable' => 0, + 'add' => NULL, ], 'contribution_id' => [ 'name' => 'contribution_id', 'type' => CRM_Utils_Type::T_INT, - 'title' => CRM_Stripe_ExtensionUtil::ts('Contribution ID'), - 'description' => CRM_Stripe_ExtensionUtil::ts('FK ID from civicrm_contribution'), + 'title' => E::ts('Contribution ID'), + 'description' => E::ts('FK ID from civicrm_contribution'), 'where' => 'civicrm_stripe_paymentintent.contribution_id', 'table_name' => 'civicrm_stripe_paymentintent', 'entity' => 'StripePaymentintent', 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', 'localizable' => 0, + 'add' => NULL, ], 'payment_processor_id' => [ 'name' => 'payment_processor_id', 'type' => CRM_Utils_Type::T_INT, - 'title' => CRM_Stripe_ExtensionUtil::ts('Payment Processor'), - 'description' => CRM_Stripe_ExtensionUtil::ts('Foreign key to civicrm_payment_processor.id'), + 'title' => E::ts('Payment Processor'), + 'description' => E::ts('Foreign key to civicrm_payment_processor.id'), 'where' => 'civicrm_stripe_paymentintent.payment_processor_id', 'table_name' => 'civicrm_stripe_paymentintent', 'entity' => 'StripePaymentintent', 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', 'localizable' => 0, + 'FKClassName' => 'CRM_Financial_DAO_PaymentProcessor', 'pseudoconstant' => [ 'table' => 'civicrm_payment_processor', 'keyColumn' => 'id', 'labelColumn' => 'name', ], + 'add' => NULL, ], 'description' => [ 'name' => 'description', 'type' => CRM_Utils_Type::T_STRING, - 'title' => CRM_Stripe_ExtensionUtil::ts('Description'), - 'description' => CRM_Stripe_ExtensionUtil::ts('Description of this paymentIntent'), + 'title' => E::ts('Description'), + 'description' => E::ts('Description of this paymentIntent'), 'required' => FALSE, 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, @@ -194,12 +216,13 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO { 'entity' => 'StripePaymentintent', 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', 'localizable' => 0, + 'add' => NULL, ], 'status' => [ 'name' => 'status', 'type' => CRM_Utils_Type::T_STRING, - 'title' => CRM_Stripe_ExtensionUtil::ts('Status'), - 'description' => CRM_Stripe_ExtensionUtil::ts('The status of the paymentIntent'), + 'title' => E::ts('Status'), + 'description' => E::ts('The status of the paymentIntent'), 'required' => FALSE, 'maxlength' => 25, 'size' => CRM_Utils_Type::MEDIUM, @@ -208,12 +231,13 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO { 'entity' => 'StripePaymentintent', 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', 'localizable' => 0, + 'add' => NULL, ], 'identifier' => [ 'name' => 'identifier', 'type' => CRM_Utils_Type::T_STRING, - 'title' => CRM_Stripe_ExtensionUtil::ts('Identifier'), - 'description' => CRM_Stripe_ExtensionUtil::ts('An identifier that we can use in CiviCRM to find the paymentIntent if we do not have the ID (eg. session key)'), + 'title' => E::ts('Identifier'), + 'description' => E::ts('An identifier that we can use in CiviCRM to find the paymentIntent if we do not have the ID (eg. session key)'), 'required' => FALSE, 'maxlength' => 255, 'size' => CRM_Utils_Type::HUGE, @@ -222,34 +246,38 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO { 'entity' => 'StripePaymentintent', 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', 'localizable' => 0, + 'add' => NULL, ], 'contact_id' => [ 'name' => 'contact_id', 'type' => CRM_Utils_Type::T_INT, - 'description' => CRM_Stripe_ExtensionUtil::ts('FK to Contact'), + 'description' => E::ts('FK to Contact'), 'where' => 'civicrm_stripe_paymentintent.contact_id', 'table_name' => 'civicrm_stripe_paymentintent', 'entity' => 'StripePaymentintent', 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', 'localizable' => 0, + 'FKClassName' => 'CRM_Contact_DAO_Contact', + 'add' => NULL, ], 'created_date' => [ 'name' => 'created_date', 'type' => CRM_Utils_Type::T_TIMESTAMP, - 'title' => CRM_Stripe_ExtensionUtil::ts('Created Date'), - 'description' => CRM_Stripe_ExtensionUtil::ts('When was paymentIntent created'), + 'title' => E::ts('Created Date'), + 'description' => E::ts('When was paymentIntent created'), 'where' => 'civicrm_stripe_paymentintent.created_date', 'default' => 'CURRENT_TIMESTAMP', 'table_name' => 'civicrm_stripe_paymentintent', 'entity' => 'StripePaymentintent', 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', 'localizable' => 0, + 'add' => NULL, ], 'flags' => [ 'name' => 'flags', 'type' => CRM_Utils_Type::T_STRING, - 'title' => CRM_Stripe_ExtensionUtil::ts('Flags'), - 'description' => CRM_Stripe_ExtensionUtil::ts('Flags associated with this PaymentIntent (NC=no contributionID when doPayment called)'), + 'title' => E::ts('Flags'), + 'description' => E::ts('Flags associated with this PaymentIntent (NC=no contributionID when doPayment called)'), 'required' => FALSE, 'maxlength' => 100, 'size' => CRM_Utils_Type::HUGE, @@ -258,6 +286,22 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO { 'entity' => 'StripePaymentintent', 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', 'localizable' => 0, + 'add' => NULL, + ], + 'referrer' => [ + 'name' => 'referrer', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => E::ts('Referrer'), + 'description' => E::ts('HTTP referrer of this paymentIntent'), + 'required' => FALSE, + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'where' => 'civicrm_stripe_paymentintent.referrer', + 'table_name' => 'civicrm_stripe_paymentintent', + 'entity' => 'StripePaymentintent', + 'bao' => 'CRM_Stripe_DAO_StripePaymentintent', + 'localizable' => 0, + 'add' => NULL, ], ]; CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); diff --git a/CRM/Stripe/Upgrader.php b/CRM/Stripe/Upgrader.php index b6137effae89037c53f311cd28c1830b9cadeb18..3cbf53f9cc6da06b4bc9889dd7fc1bbcff7a3e67 100644 --- a/CRM/Stripe/Upgrader.php +++ b/CRM/Stripe/Upgrader.php @@ -379,4 +379,13 @@ class CRM_Stripe_Upgrader extends CRM_Stripe_Upgrader_Base { return TRUE; } + public function upgrade_5025() { + $this->ctx->log->info('Applying Stripe update 5025. Add referrer column to civicrm_stripe_paymentintent database table'); + if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_stripe_paymentintent', 'referrer', FALSE)) { + CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_stripe_paymentintent` + ADD COLUMN `referrer` varchar(255) NULL COMMENT 'HTTP referrer of this paymentIntent'"); + } + return TRUE; + } + } diff --git a/api/v3/Job/ProcessStripe.php b/api/v3/Job/ProcessStripe.php index 021857fd24d944603bd4805c646f34f3c4399239..13b58a2e6392a10d7380b9d41defe4061ebf360f 100644 --- a/api/v3/Job/ProcessStripe.php +++ b/api/v3/Job/ProcessStripe.php @@ -24,7 +24,7 @@ function civicrm_api3_job_process_stripe($params) { if ($params['delete_old'] !== 0 && !empty($params['delete_old'])) { // Delete all locally recorded paymentIntents that are older than 3 months $oldPaymentIntents = civicrm_api3('StripePaymentintent', 'get', [ - 'status' => ['IN' => ["succeeded", "cancelled"]], + 'status' => ['IN' => ["succeeded", "cancelled", "failed"]], 'created_date' => ['<' => $params['delete_old']], ]); foreach ($oldPaymentIntents['values'] as $id => $detail) { diff --git a/sql/auto_uninstall.sql b/sql/auto_uninstall.sql index 275f79f4ce72a2cccb513dbb9c7092aa565ad92f..80360acf0ac66388bc71c36ea78742725cb594b2 100644 --- a/sql/auto_uninstall.sql +++ b/sql/auto_uninstall.sql @@ -1,25 +1,9 @@ -- +--------------------------------------------------------------------+ --- | CiviCRM version 5 | --- +--------------------------------------------------------------------+ --- | Copyright CiviCRM LLC (c) 2004-2019 | --- +--------------------------------------------------------------------+ --- | This file is a part of CiviCRM. | --- | | --- | CiviCRM is free software; you can copy, modify, and distribute it | --- | under the terms of the GNU Affero General Public License | --- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | --- | | --- | CiviCRM is distributed in the hope that it will be useful, but | --- | WITHOUT ANY WARRANTY; without even the implied warranty of | --- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | --- | See the GNU Affero General Public License for more details. | +-- | Copyright CiviCRM LLC. All rights reserved. | -- | | --- | You should have received a copy of the GNU Affero General Public | --- | License and the CiviCRM Licensing Exception along | --- | with this program; if not, contact CiviCRM LLC | --- | at info[AT]civicrm[DOT]org. If you have questions about the | --- | GNU Affero General Public License or the licensing of CiviCRM, | --- | see the CiviCRM license FAQ at http://civicrm.org/licensing | +-- | This work is published under the GNU AGPLv3 license with some | +-- | permitted exceptions and without any warranty. For full license | +-- | and copyright information, see https://civicrm.org/licensing | -- +--------------------------------------------------------------------+ -- -- Generated from drop.tpl @@ -35,4 +19,4 @@ SET FOREIGN_KEY_CHECKS=0; DROP TABLE IF EXISTS `civicrm_stripe_paymentintent`; -SET FOREIGN_KEY_CHECKS=1; +SET FOREIGN_KEY_CHECKS=1; \ No newline at end of file diff --git a/sql/paymentintent_install.sql b/sql/paymentintent_install.sql index 7891337c126177602be7149fb45d7fe17c1eda1b..0ff2dac6b1f3d14e439853d388e1307bfedfb205 100644 --- a/sql/paymentintent_install.sql +++ b/sql/paymentintent_install.sql @@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_stripe_paymentintent` ( `contact_id` int unsigned COMMENT 'FK to Contact', `created_date` timestamp DEFAULT CURRENT_TIMESTAMP COMMENT 'When was paymentIntent created', `flags` varchar(100) NULL COMMENT 'Flags associated with this PaymentIntent (NC=no contributionID when doPayment called)', + `referrer` varchar(255) NULL COMMENT 'HTTP referrer of this paymentIntent' PRIMARY KEY (`id`), UNIQUE INDEX `UI_paymentintent_id` ( paymentintent_id diff --git a/xml/schema/CRM/Stripe/StripePaymentintent.xml b/xml/schema/CRM/Stripe/StripePaymentintent.xml index cbfdf4842991abd766debb843cf832c876204797..9581033515edcd06e063dec9990e65f570249321 100644 --- a/xml/schema/CRM/Stripe/StripePaymentintent.xml +++ b/xml/schema/CRM/Stripe/StripePaymentintent.xml @@ -109,4 +109,13 @@ <comment>Flags associated with this PaymentIntent (NC=no contributionID when doPayment called)</comment> </field> + <field> + <name>referrer</name> + <title>Referrer</title> + <type>varchar</type> + <required>false</required> + <length>255</length> + <comment>HTTP referrer of this paymentIntent</comment> + </field> + </table>