diff --git a/htdocs/societe/class/companypaymentmode.class.php b/htdocs/societe/class/companypaymentmode.class.php index 781a25ac8c0..55b5b865dee 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 @@ -443,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); diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 52af815827f..7e940583824 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(); @@ -1002,6 +1010,7 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' { print '