Prepare database to store payment modes of customers
This commit is contained in:
parent
7a277a8d2b
commit
489dde4db4
@ -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;
|
||||
|
||||
|
||||
|
||||
@ -17,15 +17,19 @@
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- 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;
|
||||
|
||||
@ -185,7 +185,7 @@ for ($i=1; $i<=4; $i++) {
|
||||
<td><?php echo $langs->trans('RIB'); ?></td>
|
||||
<td align="right">
|
||||
<?php if ($user->rights->societe->creer) { ?>
|
||||
<a href="<?php echo DOL_URL_ROOT.'/societe/rib.php?socid='.$this->control->tpl['id']; ?>"><?php echo $this->control->tpl['image_edit']; ?></a>
|
||||
<a href="<?php echo DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->control->tpl['id']; ?>"><?php echo $this->control->tpl['image_edit']; ?></a>
|
||||
<?php } else { ?>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
@ -144,7 +144,7 @@ dol_fiche_head($head, 'card', $langs->trans("ThirdParty"),0,'company');
|
||||
<td><?php echo $langs->trans('RIB'); ?></td>
|
||||
<td align="right">
|
||||
<?php if ($user->rights->societe->creer) { ?>
|
||||
<a href="<?php echo DOL_URL_ROOT.'/societe/rib.php?socid='.$this->control->tpl['id']; ?>"><?php echo $this->control->tpl['image_edit']; ?></a>
|
||||
<a href="<?php echo DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->control->tpl['id']; ?>"><?php echo $this->control->tpl['image_edit']; ?></a>
|
||||
<?php } else { ?>
|
||||
|
||||
<?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.= '<u>' . $langs->trans("ShowBan") . '</u>';
|
||||
$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/rib.php?socid='.$this->id;
|
||||
$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->id;
|
||||
}
|
||||
|
||||
// By default
|
||||
|
||||
@ -23,9 +23,9 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/societe/rib.php
|
||||
* \file htdocs/societe/paymentmodes.php
|
||||
* \ingroup societe
|
||||
* \brief BAN tab for companies
|
||||
* \brief Tab of payment modes for the customer
|
||||
*/
|
||||
|
||||
require '../main.inc.php';
|
||||
@ -162,7 +162,7 @@ if (empty($reshook))
|
||||
$account->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 '<form action="rib.php?socid='.$object->id.'" method="post">';
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="update">';
|
||||
print '<input type="hidden" name="id" value="'.GETPOST("id","int").'">';
|
||||
}
|
||||
if ($socid && $action == 'create' && $user->rights->societe->creer)
|
||||
{
|
||||
print '<form action="rib.php?socid='.$object->id.'" method="post">';
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
}
|
||||
@ -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='<a href="rib.php?socid='.$object->id.'&action=create">'.$langs->trans("Add").'</a>';
|
||||
$morehtmlright='<a href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=create">'.$langs->trans("Add").'</a>';
|
||||
|
||||
print load_fiche_titre($langs->trans("AllRIB"), $morehtmlright, '');
|
||||
|
||||
@ -636,7 +643,7 @@ if ($socid && $action != 'edit' && $action != "create")
|
||||
// Default
|
||||
print '<td align="center" width="70">';
|
||||
if (!$rib->default_rib) {
|
||||
print '<a href="'.DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id.'&ribid='.$rib->id.'&action=setasbankdefault">';
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&ribid='.$rib->id.'&action=setasbankdefault">';
|
||||
print img_picto($langs->trans("Disabled"),'off');
|
||||
print '</a>';
|
||||
} else {
|
||||
@ -704,13 +711,13 @@ if ($socid && $action != 'edit' && $action != "create")
|
||||
print '<td align="right">';
|
||||
if ($user->rights->societe->creer)
|
||||
{
|
||||
print '<a href="'.DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id.'&id='.$rib->id.'&action=edit">';
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=edit">';
|
||||
print img_picto($langs->trans("Modify"),'edit');
|
||||
print '</a>';
|
||||
|
||||
print ' ';
|
||||
|
||||
print '<a href="'.DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id.'&id='.$rib->id.'&action=delete">';
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&id='.$rib->id.'&action=delete">';
|
||||
print img_picto($langs->trans("Delete"),'delete');
|
||||
print '</a>';
|
||||
}
|
||||
@ -741,7 +748,7 @@ if ($socid && $action != 'edit' && $action != "create")
|
||||
|
||||
if ($user->rights->societe->creer)
|
||||
{
|
||||
print '<a class="butAction" href="rib.php?socid='.$object->id.'&action=create">'.$langs->trans("Add").'</a>';
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=create">'.$langs->trans("Add").'</a>';
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
@ -879,7 +886,7 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
|
||||
|
||||
print '<tr><td>'.$langs->trans("WithdrawMode").'</td><td>';
|
||||
$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 '</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user