From 52767c4324351d5b89c77ff21055d2face34fe5c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Jan 2020 15:45:25 +0100 Subject: [PATCH 1/4] NEW Can enter and edit stripe credit card using the Stripe card ID --- .../class/companypaymentmode.class.php | 1 + htdocs/societe/paymentmodes.php | 38 +++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index 781a25ac8c0..441dac5bd37 100644 --- a/htdocs/societe/class/companypaymentmode.class.php +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -162,6 +162,7 @@ class CompanyPaymentMode extends CommonObject public $preapproval_key; public $total_amount_of_all_payments; public $stripe_card_ref; + public $stripe_account; /** * @var int Status diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 52af815827f..08165909bea 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -194,13 +194,13 @@ if (empty($reshook)) if ($action == 'updatecard') { // Modification - if (!GETPOST('label', 'alpha') || !GETPOST('proprio', 'alpha') || !GETPOST('cardnumber', 'alpha') || !GETPOST('exp_date_month', 'alpha') || !GETPOST('exp_date_year', 'alpha') || !GETPOST('cvn', 'alpha')) + if (!GETPOST('label', 'alpha') || !GETPOST('proprio', 'alpha') || !GETPOST('exp_date_month', 'alpha') || !GETPOST('exp_date_year', 'alpha')) { if (!GETPOST('label', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); if (!GETPOST('proprio', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors'); - if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors'); + //if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors'); if (!(GETPOST('exp_date_month', 'alpha') > 0) || !(GETPOST('exp_date_year', 'alpha') > 0)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors'); - if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors'); + //if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors'); $action = 'createcard'; $error++; } @@ -220,6 +220,10 @@ if (empty($reshook)) $companypaymentmode->cvn = GETPOST('cvn', 'alpha'); $companypaymentmode->country_code = $object->country_code; + if (GETPOST('stripe_card_ref', 'alpha') && GETPOST('stripe_card_ref', 'alpha') != $companypaymentmode->stripe_card_ref) { + // If we set a stripe value that is different than previous one, we also set the stripe account + $companypaymentmode->stripe_account = $site_account; + } $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha'); $result = $companypaymentmode->update($user); @@ -346,13 +350,13 @@ if (empty($reshook)) { $error = 0; - if (!GETPOST('label', 'alpha') || !GETPOST('proprio', 'alpha') || !GETPOST('cardnumber', 'alpha') || !GETPOST('exp_date_month', 'alpha') || !GETPOST('exp_date_year', 'alpha') || !GETPOST('cvn', 'alpha')) + if (!GETPOST('label', 'alpha') || !GETPOST('proprio', 'alpha') || !GETPOST('exp_date_month', 'alpha') || !GETPOST('exp_date_year', 'alpha')) { if (!GETPOST('label', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); if (!GETPOST('proprio', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NameOnCard")), null, 'errors'); - if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors'); + //if (!GETPOST('cardnumber', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardNumber")), null, 'errors'); if (!(GETPOST('exp_date_month', 'alpha') > 0) || !(GETPOST('exp_date_year', 'alpha') > 0)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpiryDate")), null, 'errors'); - if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors'); + //if (!GETPOST('cvn', 'alpha')) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CVN")), null, 'errors'); $action = 'createcard'; $error++; } @@ -377,6 +381,10 @@ if (empty($reshook)) $companypaymentmode->country_code = $object->country_code; $companypaymentmode->status = $servicestatus; + if (GETPOST('stripe_card_ref', 'alpha')) { + // If we set a stripe value, we also set the stripe account + $companypaymentmode->stripe_account = $site_account; + } $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref', 'alpha'); $db->begin(); @@ -1615,7 +1623,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' // Edit BAN if ($socid && $action == 'edit' && $user->rights->societe->creer) { - dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company'); + dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company'); $linkback = ''.$langs->trans("BackToList").''; @@ -1721,7 +1729,7 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) // Edit Card if ($socid && $action == 'editcard' && $user->rights->societe->creer) { - dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company'); + dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company'); $linkback = ''.$langs->trans("BackToList").''; @@ -1738,7 +1746,7 @@ if ($socid && $action == 'editcard' && $user->rights->societe->creer) print ''.$langs->trans("NameOnCard").''; print ''; - print ''.$langs->trans("CardNumber").''; + print ''.$langs->trans("CardNumber").''; print ''; print ''.$langs->trans("ExpiryDate").''; @@ -1747,7 +1755,7 @@ if ($socid && $action == 'editcard' && $user->rights->societe->creer) print $formother->select_year($companypaymentmode->exp_date_year, 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly'); print ''; - print ''.$langs->trans("CVN").''; + print ''.$langs->trans("CVN").''; print ''; print ''.$langs->trans("StripeID")." ('card_....')"; @@ -1769,7 +1777,7 @@ if ($socid && $action == 'editcard' && $user->rights->societe->creer) // Create BAN if ($socid && $action == 'create' && $user->rights->societe->creer) { - dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company'); + dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company'); $linkback = ''.$langs->trans("BackToList").''; @@ -1869,7 +1877,7 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) // Create Card if ($socid && $action == 'createcard' && $user->rights->societe->creer) { - dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), -1, 'company'); + dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"), 0, 'company'); $linkback = ''.$langs->trans("BackToList").''; @@ -1886,7 +1894,7 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer) print ''.$langs->trans("NameOnCard").''; print ''; - print ''.$langs->trans("CardNumber").''; + print ''.$langs->trans("CardNumber").''; print ''; print ''.$langs->trans("ExpiryDate").''; @@ -1895,8 +1903,8 @@ if ($socid && $action == 'createcard' && $user->rights->societe->creer) print $formother->select_year(GETPOST('exp_date_year', 'int'), 'exp_date_year', 1, 5, 10, 0, 0, '', 'marginleftonly'); print ''; - print ''.$langs->trans("CVN").''; - print ''; + print ''.$langs->trans("CVN").''; + print ''; print ''.$langs->trans("StripeID")." ('card_....')"; print ''; From b7bf12819ab243ea6617619997810e79b0b07da7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Jan 2020 17:19:42 +0100 Subject: [PATCH 2/4] Add label in list of Stripe payments --- htdocs/societe/paymentmodes.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 08165909bea..c70150f8bc0 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -1010,6 +1010,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' { print ''.$langs->trans('LocalID').''; } + print ''.$langs->trans('Label').''; print ''.$langs->trans('StripeID').''; print ''.$langs->trans('Type').''; print ''.$langs->trans('Informations').''; @@ -1063,6 +1064,9 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print $companypaymentmodetemp->id; print ''; print ''; + print $companypaymentmodetemp->label; + print ''; + print ''; print $companypaymentmodetemp->stripe_card_ref; if ($companypaymentmodetemp->stripe_card_ref) { From dbb65d864ede580cc4dc102b34cb709aac887095 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Jan 2020 19:05:03 +0100 Subject: [PATCH 3/4] fix missing column --- htdocs/societe/paymentmodes.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index c70150f8bc0..7e940583824 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -1160,6 +1160,8 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' print ''; print ''; } + print ''; + print ''; // Src ID print ''; $connect = ''; From 5cb8cceb8202f58752d5ae5b47b464e822c78a3e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Jan 2020 20:29:19 +0100 Subject: [PATCH 4/4] FIX Do not update timestamp when we set the "default" to another record --- htdocs/societe/class/companypaymentmode.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index 441dac5bd37..55b5b865dee 100644 --- a/htdocs/societe/class/companypaymentmode.class.php +++ b/htdocs/societe/class/companypaymentmode.class.php @@ -444,7 +444,7 @@ class CompanyPaymentMode extends CommonObject $this->db->begin(); - $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0"; + $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0, tms = tms"; $sql2.= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc; if ($type) $sql2.= " AND type = '".$this->db->escape($type)."'"; dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);