Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop
This commit is contained in:
commit
a658f7c455
@ -1330,7 +1330,7 @@ class pdf_einstein extends ModelePDFCommandes
|
||||
$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
|
||||
}
|
||||
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
// Show sender
|
||||
$posy=42+$top_shift;
|
||||
|
||||
@ -583,7 +583,7 @@ class pdf_strato extends ModelePDFContract
|
||||
$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
|
||||
}
|
||||
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
// Show sender
|
||||
$posy=42;
|
||||
|
||||
@ -542,7 +542,7 @@ class pdf_merou extends ModelePdfExpedition
|
||||
$pdf->SetTextColor(0,0,0);
|
||||
|
||||
// Sender properties
|
||||
$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
|
||||
$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
$pdf->SetFont('','', $default_font_size - 3);
|
||||
$pdf->SetXY($blSocX,$blSocY+4);
|
||||
|
||||
@ -935,7 +935,7 @@ class pdf_rouget extends ModelePdfExpedition
|
||||
$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
|
||||
}
|
||||
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
// Show sender
|
||||
$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
|
||||
|
||||
@ -1692,7 +1692,7 @@ class pdf_crabe extends ModelePDFFactures
|
||||
if ($showaddress)
|
||||
{
|
||||
// Sender properties
|
||||
$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
|
||||
$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
// Show sender
|
||||
$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
|
||||
|
||||
@ -584,7 +584,7 @@ class pdf_soleil extends ModelePDFFicheinter
|
||||
$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
|
||||
}
|
||||
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
// Show sender
|
||||
$posy=42;
|
||||
|
||||
@ -799,7 +799,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
|
||||
if ($showaddress)
|
||||
{
|
||||
// Sender properties
|
||||
$carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
|
||||
$carac_emetteur = pdf_build_address($outputlangs,$this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
// Show sender
|
||||
$posy=42;
|
||||
|
||||
@ -1515,7 +1515,7 @@ class pdf_azur extends ModelePDFPropales
|
||||
$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
|
||||
}
|
||||
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
// Show sender
|
||||
$posy=42+$top_shift;
|
||||
|
||||
@ -1086,7 +1086,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
|
||||
if ($showaddress)
|
||||
{
|
||||
// Sender properties
|
||||
$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
|
||||
$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
// Show sender
|
||||
$posy=42;
|
||||
|
||||
@ -1211,7 +1211,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
|
||||
if ($showaddress)
|
||||
{
|
||||
// Sender properties
|
||||
$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
|
||||
$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
// Show sender
|
||||
$posy=42;
|
||||
|
||||
@ -1306,7 +1306,7 @@ class pdf_aurore extends ModelePDFSupplierProposal
|
||||
$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
|
||||
}
|
||||
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
|
||||
$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
|
||||
|
||||
// Show sender
|
||||
$posy=42;
|
||||
|
||||
170
htdocs/core/triggers/interface_80_modStripe_Stripe.class.php
Normal file
170
htdocs/core/triggers/interface_80_modStripe_Stripe.class.php
Normal file
@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 ptibogxiv <support@ptibogxiv.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/triggers/interface_50_modStripe_Stripe.class.php
|
||||
* \ingroup core
|
||||
* \brief Fichier
|
||||
* \remarks Son propre fichier d'actions peut etre cree par recopie de celui-ci:
|
||||
* - Le nom du fichier doit etre: interface_99_modMymodule_Mytrigger.class.php
|
||||
* ou: interface_99_all_Mytrigger.class.php
|
||||
* - Le fichier doit rester stocke dans core/triggers
|
||||
* - Le nom de la classe doit etre InterfaceMytrigger
|
||||
* - Le nom de la propriete name doit etre Mytrigger
|
||||
*/
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
|
||||
dol_include_once('/stripe/class/stripe.class.php');
|
||||
$path=dirname(__FILE__).'/';
|
||||
/**
|
||||
* Class of triggers for stripe module
|
||||
*/
|
||||
class InterfaceStripe
|
||||
{
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
|
||||
$this->name = preg_replace('/^Interface/i', '', get_class($this));
|
||||
$this->family = 'Stripeconnect';
|
||||
$this->description = "Triggers of the module Stripeconnect";
|
||||
$this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version
|
||||
$this->picto = 'stripe@stripe';
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger name
|
||||
*
|
||||
* @return string Name of trigger file
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Trigger description
|
||||
*
|
||||
* @return string Description of trigger file
|
||||
*/
|
||||
public function getDesc()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger version
|
||||
*
|
||||
* @return string Version of trigger file
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
global $langs;
|
||||
$langs->load("admin");
|
||||
|
||||
if ($this->version == 'development') {
|
||||
return $langs->trans("Development");
|
||||
} elseif ($this->version == 'experimental') {
|
||||
return $langs->trans("Experimental");
|
||||
} elseif ($this->version == 'dolibarr') {
|
||||
return DOL_VERSION;
|
||||
} elseif ($this->version) {
|
||||
return $this->version;
|
||||
} else {
|
||||
return $langs->trans("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called when a Dolibarrr business event is done.
|
||||
* All functions "runTrigger" are triggered if file
|
||||
* is inside directory core/triggers
|
||||
*
|
||||
* @param string $action Event action code
|
||||
* @param CommonObject $object Object
|
||||
* @param User $user Object user
|
||||
* @param Translate $langs Object langs
|
||||
* @param Conf $conf Object conf
|
||||
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
|
||||
*/
|
||||
|
||||
public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
|
||||
{
|
||||
// Put here code you want to execute when a Dolibarr business events occurs.
|
||||
// Data and type of action are stored into $object and $action
|
||||
global $langs,$db,$conf;
|
||||
$langs->load("members");
|
||||
$langs->load("users");
|
||||
$langs->load("mails");
|
||||
$langs->load('other');
|
||||
/** Users */
|
||||
$ok=0;
|
||||
$stripe=new Stripe($db);
|
||||
if (empty($conf->stripe->enabled)) return 0;
|
||||
|
||||
if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')))
|
||||
{
|
||||
$service = 'StripeTest';
|
||||
}
|
||||
else
|
||||
{
|
||||
$service = 'StripeLive';
|
||||
}
|
||||
|
||||
if ($action == 'COMPANY_MODIFY') {
|
||||
dol_syslog(
|
||||
"Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
|
||||
);
|
||||
if ($stripe->getStripeAccount($service) && $object->client!=0) {
|
||||
$cu=$stripe->CustomerStripe($object->id,$stripe->getStripeAccount($service));
|
||||
if ($cu) {
|
||||
if ($conf->entity=='1'){
|
||||
$customer = \Stripe\Customer::retrieve("$cu->id");
|
||||
}else{
|
||||
$customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->getStripeAccount($service)));
|
||||
}
|
||||
if (!empty($object->email)) {$customer->email = "$object->email";}
|
||||
$customer->description = "$object->name";
|
||||
$customer->save();
|
||||
}}
|
||||
}
|
||||
elseif ($action == 'COMPANY_DELETE') {
|
||||
dol_syslog(
|
||||
"Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
|
||||
);
|
||||
$cu=$stripe->CustomerStripe($object->id,$stripe->getStripeAccount($service));
|
||||
if ($cu) {
|
||||
if ($conf->entity==1){
|
||||
$customer = \Stripe\Customer::retrieve("$cu->id");
|
||||
}else{
|
||||
$customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->getStripeAccount($service)));
|
||||
}
|
||||
$customer->delete();
|
||||
}
|
||||
}
|
||||
|
||||
return $ok;
|
||||
}
|
||||
}
|
||||
@ -126,8 +126,8 @@ class Stripe extends CommonObject
|
||||
/**
|
||||
* customerStripe
|
||||
*
|
||||
* @param int $id ???
|
||||
* @param string $key ???
|
||||
* @param int $id Id of third party
|
||||
* @return string Stripe account ref 'acc_xxxxxxxxxxxxx'
|
||||
* @return \Stripe\StripeObject|\Stripe\ApiResource
|
||||
*/
|
||||
public function customerStripe($id,$key)
|
||||
@ -142,10 +142,11 @@ class Stripe extends CommonObject
|
||||
$mode = $conf->global->STRIPE_LIVE;
|
||||
}
|
||||
}
|
||||
$sql = "SELECT rowid,fk_soc,fk_key,mode,entity";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "societe_stripe";
|
||||
$sql .= " WHERE fk_soc = " . $id . " ";
|
||||
$sql .= " AND mode=" . $mode . " AND entity IN (" . getEntity('stripe') . ")";
|
||||
$sql = "SELECT sa.key_account as key_account, sa.entity";
|
||||
$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
|
||||
$sql.= " WHERE sa.fk_soc = " . $id;
|
||||
$sql.= " AND sa.entity IN (".getEntity('societe').")";
|
||||
$sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
|
||||
|
||||
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
@ -155,7 +156,7 @@ class Stripe extends CommonObject
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$tiers = $obj->fk_key;
|
||||
$tiers = $obj->key_account;
|
||||
if ($conf->entity == 1) {
|
||||
$customer = \Stripe\Customer::retrieve("$tiers");
|
||||
} else {
|
||||
@ -178,8 +179,8 @@ class Stripe extends CommonObject
|
||||
));
|
||||
}
|
||||
$customer_id = "" . $customer->id . "";
|
||||
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_stripe (fk_soc,fk_key,mode,entity)";
|
||||
$sql .= " VALUES ($id,'$customer_id'," . $mode . "," . $conf->entity . ")";
|
||||
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc,key_account,site,status,entity)";
|
||||
$sql .= " VALUES ($id,'$customer_id','stripe'," . $mode . "," . $conf->entity . ")";
|
||||
dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
}
|
||||
@ -188,44 +189,41 @@ class Stripe extends CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* createPaymentStripe
|
||||
* createPaymentStripe Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API
|
||||
*
|
||||
* @param unknown $amount ???
|
||||
* @param unknown $currency ???
|
||||
* @param unknown $origin ???
|
||||
* @param unknown $item ???
|
||||
* @param unknown $source ???
|
||||
* @param unknown $customer ???
|
||||
* @param unknown $account ???
|
||||
* @param int $amount amount to pay
|
||||
* @param string $currency EUR, GPB...
|
||||
* @param string $origin order, invoice, contract...
|
||||
* @param int $item if of element to pay
|
||||
* @param string $source src_xxxxx or card_xxxxx or ac_xxxxx
|
||||
* @param string $customer Stripe account ref 'cu_xxxxxxxxxxxxx' via customerStripe()
|
||||
* @param string $account Stripe account ref 'acc_xxxxxxxxxxxxx' via getStripeAccount()
|
||||
* @param int $status Status
|
||||
* @return Stripe
|
||||
*/
|
||||
public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account)
|
||||
public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (empty($conf->global->STRIPECONNECT_LIVE)) {
|
||||
$mode = 0;
|
||||
} else {
|
||||
if (empty($conf->global->STRIPE_LIVE)) {
|
||||
$mode = 0;
|
||||
} else {
|
||||
$mode = $conf->global->STRIPE_LIVE;
|
||||
}
|
||||
}
|
||||
$sql = "SELECT fk_soc,fk_key,mode,entity";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "societe_stripe";
|
||||
$sql .= " WHERE fk_key = '$customer' ";
|
||||
$sql .= " AND mode=" . $mode . " ";
|
||||
$sql = "SELECT sa.key_account as key_account, sa.entity";
|
||||
$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
|
||||
$sql.= " WHERE sa.key_account = " . $customer;
|
||||
//$sql.= " AND sa.entity IN (".getEntity('societe').")";
|
||||
$sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
|
||||
|
||||
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
if ($this->db->num_rows($result)) {
|
||||
$obj = $this->db->fetch_object($result);
|
||||
$entite = $obj->entity;
|
||||
$fksoc = $obj->fk_soc;
|
||||
$key = $obj->fk_soc;
|
||||
} else {
|
||||
$key = NULL;
|
||||
}
|
||||
} else {
|
||||
$key = NULL;
|
||||
}
|
||||
|
||||
$stripeamount = round($amount * 100);
|
||||
$societe = new Societe($this->db);
|
||||
$societe->fetch($fksoc);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user