diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index eb3c865c106..227562ea9bc 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -97,3 +97,23 @@ ALTER TABLE llx_c_payment_term CHANGE COLUMN rowid rowid INTEGER AUTO_INCREMENT ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term_code(entity, code); ALTER TABLE llx_oauth_token ADD COLUMN tokenstring text; + +-- Add field for payment modes +ALTER TABLE llx_societe_rib ADD COLUMN type varchar(32) DEFAULT 'ban' after rowid; +ALTER TABLE llx_societe_rib ADD COLUMN last_four varchar(4); +ALTER TABLE llx_societe_rib ADD COLUMN card_type varchar(255); +ALTER TABLE llx_societe_rib ADD COLUMN cvn varchar(255); +ALTER TABLE llx_societe_rib ADD COLUMN exp_date_month INTEGER; +ALTER TABLE llx_societe_rib ADD COLUMN exp_date_year INTEGER; +ALTER TABLE llx_societe_rib ADD COLUMN country_code varchar(10); +ALTER TABLE llx_societe_rib ADD COLUMN approved integer DEFAULT 0; +ALTER TABLE llx_societe_rib ADD COLUMN email varchar(255); +ALTER TABLE llx_societe_rib ADD COLUMN ending_date date; +ALTER TABLE llx_societe_rib ADD COLUMN max_total_amount_of_all_payments double(24,8); +ALTER TABLE llx_societe_rib ADD COLUMN preapproval_key varchar(255); +ALTER TABLE llx_societe_rib ADD COLUMN starting_date date; +ALTER TABLE llx_societe_rib ADD COLUMN total_amount_of_all_payments double(24,8); +ALTER TABLE llx_societe_rib ADD COLUMN stripe_card_ref varchar(128); +ALTER TABLE llx_societe_rib ADD COLUMN status integer NOT NULL DEFAULT 1; + + diff --git a/htdocs/install/mysql/tables/llx_societe_rib.sql b/htdocs/install/mysql/tables/llx_societe_rib.sql index 168a2803c9d..6157af37830 100644 --- a/htdocs/install/mysql/tables/llx_societe_rib.sql +++ b/htdocs/install/mysql/tables/llx_societe_rib.sql @@ -17,15 +17,19 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -- +-- Table with the payment modes of a thirdparty (BAN, Paypal, Card, ...) -- ============================================================================= create table llx_societe_rib ( rowid integer AUTO_INCREMENT PRIMARY KEY, + type varchar(32) DEFAULT 'ban', -- 'ban' or 'paypal' or 'card' or 'stripe' + label varchar(30), fk_soc integer NOT NULL, datec datetime, tms timestamp, - label varchar(30), + + -- For BAN bank varchar(255), -- bank name code_banque varchar(128), -- bank code code_guichet varchar(6), -- desk code @@ -37,10 +41,28 @@ create table llx_societe_rib proprio varchar(60), owner_address varchar(255), default_rib smallint NOT NULL DEFAULT 0, - + -- For BAN direct debit feature rum varchar(32), -- RUM value to use for SEPA generation date_rum date, -- Date of mandate frstrecur varchar(16) default 'FRST', -- 'FRST' or 'RECUR' - + --For credit card + last_four varchar(4), -- last 4 + card_type varchar(255), -- card type 'VISA', 'MC' , ... + cvn varchar(255), + exp_date_month INTEGER, + exp_date_year INTEGER, + country_code varchar(10), + --For Paypal + approved INTEGER DEFAULT 0, + email varchar(255), + ending_date date, + max_total_amount_of_all_payments double(24,8), + preapproval_key varchar(255), + starting_date date, + total_amount_of_all_payments double(24,8), + --For Stripe + stripe_card_ref varchar(128), -- 'card_...' + + status integer NOT NULL DEFAULT 1, -- 1=ACTIVE, 0=IN_TRASH import_key varchar(14) -- import key )ENGINE=innodb; diff --git a/htdocs/societe/canvas/company/tpl/card_view.tpl.php b/htdocs/societe/canvas/company/tpl/card_view.tpl.php index 3865e9b95a0..24ddfbaaaac 100644 --- a/htdocs/societe/canvas/company/tpl/card_view.tpl.php +++ b/htdocs/societe/canvas/company/tpl/card_view.tpl.php @@ -185,7 +185,7 @@ for ($i=1; $i<=4; $i++) { trans('RIB'); ?> rights->societe->creer) { ?> - control->tpl['image_edit']; ?> + control->tpl['image_edit']; ?>   diff --git a/htdocs/societe/canvas/individual/tpl/card_view.tpl.php b/htdocs/societe/canvas/individual/tpl/card_view.tpl.php index 359f4ec7b44..fd9b3487f50 100644 --- a/htdocs/societe/canvas/individual/tpl/card_view.tpl.php +++ b/htdocs/societe/canvas/individual/tpl/card_view.tpl.php @@ -144,7 +144,7 @@ dol_fiche_head($head, 'card', $langs->trans("ThirdParty"),0,'company'); trans('RIB'); ?> rights->societe->creer) { ?> - control->tpl['image_edit']; ?> + control->tpl['image_edit']; ?>   diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index b936a431080..f7098d88478 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1662,7 +1662,7 @@ class Societe extends CommonObject return 1; } } - + /** * Definit la societe comme un client * @@ -1674,7 +1674,7 @@ class Societe extends CommonObject function set_remise_supplier($remise, $note, User $user) { global $conf, $langs; - + // Nettoyage parametres $note=trim($note); if (! $note) @@ -1682,15 +1682,15 @@ class Societe extends CommonObject $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason")); return -2; } - + dol_syslog(get_class($this)."::set_remise_supplier ".$remise.", ".$note.", ".$user->id); - + if ($this->id) { $this->db->begin(); - + $now=dol_now(); - + // Positionne remise courante $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; $sql.= " SET remise_supplier = '".$this->db->escape($remise)."'"; @@ -1702,7 +1702,7 @@ class Societe extends CommonObject $this->error=$this->db->error(); return -1; } - + // Ecrit trace dans historique des remises $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_supplier"; $sql.= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author)"; @@ -1710,7 +1710,7 @@ class Societe extends CommonObject $sql.= " '".$this->db->escape($note)."',"; $sql.= " ".$user->id; $sql.= ")"; - + $resql=$this->db->query($sql); if (! $resql) { @@ -1718,7 +1718,7 @@ class Societe extends CommonObject $this->error=$this->db->lasterror(); return -1; } - + $this->db->commit(); return 1; } @@ -2037,7 +2037,7 @@ class Societe extends CommonObject else if ($option == 'ban') { $label.= '' . $langs->trans("ShowBan") . ''; - $linkstart = 'setAsDefault($id); // This will make sure there is only one default rib } - $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id; + $url=$_SERVER["PHP_SELF"].'?socid='.$object->id; header('Location: '.$url); exit; } @@ -261,7 +261,7 @@ if (empty($reshook)) { $db->commit(); - $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id; + $url=$_SERVER["PHP_SELF"].'?socid='.$object->id; header('Location: '.$url); exit; } @@ -332,19 +332,23 @@ if (empty($reshook)) $id = $savid; } -if (class_exists('Stripe')) +if (! empty($conf->stripe->enabled) && class_exists('Stripe')) { $stripe=new Stripe($db); - $customerstripe=$stripe->CustomerStripe($socid,$stripe->GetStripeAccount($conf->entity)); + + if (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest'; + else $service = 'StripeLive'; + + $customerstripe=$stripe->customerStripe($socid, $stripe->getStripeAccount($service)); if ($customerstripe->id) { - $cu = \Stripe\Customer::retrieve("".$customerstripe->id."");} + $cu = \Stripe\Customer::retrieve("".$customerstripe->id."");} $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id; if ($action == 'setassourcedefault') { $cu->default_source = "$source"; // obtained with Stripe.js $cu->save(); - + header('Location: '.$url); exit; } @@ -366,7 +370,7 @@ $form = new Form($db); $formfile = new FormFile($db); llxHeader(); - + $head=societe_prepare_head($object); if (! $id) @@ -381,14 +385,14 @@ if (empty($account->socid)) $account->socid=$object->id; if ($socid && $action == 'edit' && $user->rights->societe->creer) { - print '
'; + print ''; print ''; print ''; print ''; } if ($socid && $action == 'create' && $user->rights->societe->creer) { - print ''; + print ''; print ''; print ''; } @@ -414,9 +418,12 @@ if ($socid && $action != 'edit' && $action != "create") { print load_fiche_titre($langs->trans('StripeGateways'), '', ''); - if (is_object($stripe) && $stripe->GetStripeAccount($conf->entity)) + if (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest'; + else $service = 'StripeLive'; + + if (is_object($stripe) && $stripe->getStripeAccount($service)) { - $customerstripe=$stripe->CustomerStripe($object->id,$stripe->GetStripeAccount($conf->entity)); + $customerstripe=$stripe->customerStripe($object->id,$stripe->getStripeAccount($service)); } if ($customerstripe->id) { @@ -538,7 +545,7 @@ if ($socid && $action != 'edit' && $action != "create") // List of bank accounts - $morehtmlright=''.$langs->trans("Add").''; + $morehtmlright=''.$langs->trans("Add").''; print load_fiche_titre($langs->trans("AllRIB"), $morehtmlright, ''); @@ -636,7 +643,7 @@ if ($socid && $action != 'edit' && $action != "create") // Default print ''; if (!$rib->default_rib) { - print ''; + print ''; print img_picto($langs->trans("Disabled"),'off'); print ''; } else { @@ -704,13 +711,13 @@ if ($socid && $action != 'edit' && $action != "create") print ''; if ($user->rights->societe->creer) { - print ''; + print ''; print img_picto($langs->trans("Modify"),'edit'); print ''; print ' '; - print ''; + print ''; print img_picto($langs->trans("Delete"),'delete'); print ''; } @@ -741,7 +748,7 @@ if ($socid && $action != 'edit' && $action != "create") if ($user->rights->societe->creer) { - print ''.$langs->trans("Add").''; + print ''.$langs->trans("Add").''; } print ''; @@ -879,7 +886,7 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) print ''.$langs->trans("WithdrawMode").''; $tblArraychoice = array("FRST" => $langs->trans("FRST"), "RECUR" => $langs->trans("RECUR")); - print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur')?GETPOST('frstrecur'):$account->frstrecur), 0); + print $form->selectarray("frstrecur", $tblArraychoice, dol_escape_htmltag(GETPOST('frstrecur','alpha')?GETPOST('frstrecur','alpha'):$account->frstrecur), 0); print ''; print ''; diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index a9df01d6acb..4167c6a0d81 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -200,6 +200,7 @@ class Stripe extends CommonObject public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account) { global $conf; + if (empty($conf->global->STRIPECONNECT_LIVE)) { $mode = 0; } else { @@ -292,6 +293,9 @@ class Stripe extends CommonObject if (isset($charge->id)) {} } + if (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest'; + else $service = 'StripeLive'; + $return->statut = 'success'; $return->id = $charge->id; if ($charge->source->type == 'card') { @@ -299,7 +303,7 @@ class Stripe extends CommonObject } elseif ($charge->source->type == 'three_d_secure') { $stripe = new Stripe($this->db); $src = \Stripe\Source::retrieve("" . $charge->source->three_d_secure->card . "", array( - "stripe_account" => $stripe->getStripeAccount($conf->entity) + "stripe_account" => $stripe->getStripeAccount($service) )); $return->message = $src->card->brand . " ****" . $src->card->last4; } else {