diff --git a/htdocs/core/class/events.class.php b/htdocs/core/class/events.class.php index 57a076963fd..160e22f4c50 100644 --- a/htdocs/core/class/events.class.php +++ b/htdocs/core/class/events.class.php @@ -87,33 +87,9 @@ class Events // extends CommonObject array('id'=>'USER_NEW_PASSWORD', 'test'=>1), array('id'=>'USER_ENABLEDISABLE', 'test'=>1), array('id'=>'USER_DELETE', 'test'=>1), - /* array('id'=>'USER_SETINGROUP', 'test'=>1), deprecated. Replace with USER_MODIFY - array('id'=>'USER_REMOVEFROMGROUP', 'test'=>1), deprecated. Replace with USER_MODIFY */ array('id'=>'GROUP_CREATE', 'test'=>1), array('id'=>'GROUP_MODIFY', 'test'=>1), array('id'=>'GROUP_DELETE', 'test'=>1), - /* array('id'=>'ACTION_CREATE', 'test'=>$conf->societe->enabled), - array('id'=>'COMPANY_CREATE', 'test'=>$conf->societe->enabled), - array('id'=>'CONTRACT_VALIDATE', 'test'=>$conf->contrat->enabled), - array('id'=>'PROPAL_VALIDATE', 'test'=>$conf->propal->enabled), - array('id'=>'PROPAL_CLOSE_SIGNED', 'test'=>$conf->propal->enabled), - array('id'=>'PROPAL_CLOSE_REFUSED', 'test'=>$conf->propal->enabled), - array('id'=>'PROPAL_SENTBYMAIL', 'test'=>$conf->propal->enabled), - array('id'=>'ORDER_VALIDATE', 'test'=>$conf->commande->enabled), - array('id'=>'ORDER_SENTBYMAIL', 'test'=>$conf->commande->enabled), - array('id'=>'BILL_VALIDATE', 'test'=>$conf->facture->enabled), - array('id'=>'BILL_PAYED', 'test'=>$conf->facture->enabled), - array('id'=>'BILL_CANCEL', 'test'=>$conf->facture->enabled), - array('id'=>'BILL_SENTBYMAIL', 'test'=>$conf->facture->enabled), - array('id'=>'PAYMENT_CUSTOMER_CREATE','test'=>$conf->facture->enabled), - array('id'=>'PAYMENT_SUPPLIER_CREATE','test'=>$conf->fournisseur->enabled), - array('id'=>'MEMBER_CREATE', 'test'=>$conf->adherent->enabled), - array('id'=>'MEMBER_VALIDATE', 'test'=>$conf->adherent->enabled), - array('id'=>'MEMBER_SUBSCRIPTION', 'test'=>$conf->adherent->enabled), - array('id'=>'MEMBER_MODIFY', 'test'=>$conf->adherent->enabled), - array('id'=>'MEMBER_RESILIATE', 'test'=>$conf->adherent->enabled), - array('id'=>'MEMBER_DELETE', 'test'=>$conf->adherent->enabled), - */ ); diff --git a/htdocs/install/mysql/data/llx_c_action_trigger.sql b/htdocs/install/mysql/data/llx_c_action_trigger.sql index aaa96e3136a..0e2a1875e21 100644 --- a/htdocs/install/mysql/data/llx_c_action_trigger.sql +++ b/htdocs/install/mysql/data/llx_c_action_trigger.sql @@ -113,12 +113,13 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TICKET_CLOSE','Ticket closed','Executed when a ticket is closed','ticket',165); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TICKET_SENTBYMAIL','Ticket message sent by email','Executed when a message is sent from the ticket record','ticket',166); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TICKET_DELETE','Ticket deleted','Executed when a ticket is deleted','ticket',167); --- actions not enabled by default (no constant created for that) when we enable module agenda +insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('USER_SENTBYMAIL','Email sent','Executed when an email is sent from user card','user',300); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_MODIFY','Product or service modified','Executed when a product or sevice is modified','product',41); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_MODIFY','Member modified','Executed when a member is modified','member',23); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_MODIFY','Intervention modified','Executed when a intervention is modified','ficheinter',19); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROJECT_CREATE','Project creation','Executed when a project is created','project',140); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROJECT_MODIFY','Project modified','Executed when a project is modified','project',142); +-- actions not enabled by default : they are excluded when we enable the module Agenda (except TASK_...) insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_CREATE','Task created','Executed when a project task is created','project',150); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_MODIFY','Task modified','Executed when a project task is modified','project',151); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('TASK_DELETE','Task deleted','Executed when a project task is deleted','project',152); diff --git a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql index 92dcdce1128..890411109f9 100644 --- a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql +++ b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql @@ -33,6 +33,11 @@ ALTER TABLE llx_account_bookkeeping ADD COLUMN date_export datetime DEFAULT NULL ALTER TABLE llx_expensereport ADD COLUMN paid smallint default 0 NOT NULL; UPDATE llx_expensereport set paid = 1 WHERE fk_statut = 6 and paid = 0; + +-- For v11 + +insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('USER_SENTBYMAIL','Email sent','Executed when an email is sent from user card','user',300); + create table llx_entrepot_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 9c0bc9ebae3..c8a9c69a5ae 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -305,16 +305,18 @@ class Stripe extends CommonObject * @param string $currency_code Currency code * @param string $tag Tag * @param string $description Description - * @param Societe $object Object to pay with Stripe + * @param mixed $object Object to pay with Stripe * @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect * @param int $status Status (0=test, 1=live) * @param int $usethirdpartyemailforreceiptemail 1=use thirdparty email for receipt * @param int $mode automatic=automatic confirmation/payment when conditions are ok, manual=need to call confirm() on intent * @param boolean $confirmnow false=default, true=try to confirm immediatly after create (if conditions are ok) + * @param string $payment_method 'pm_....' (if known) + * @param string $off_session If we use an already known payment method to pay off line. * @return \Stripe\PaymentIntent|null Stripe PaymentIntent or null if not found and failed to create */ - public function getPaymentIntent($amount, $currency_code, $tag, $description = '', $object = null, $customer = null, $key = null, $status = 0, $usethirdpartyemailforreceiptemail = 0, $mode = 'automatic', $confirmnow = false) + public function getPaymentIntent($amount, $currency_code, $tag, $description = '', $object = null, $customer = null, $key = null, $status = 0, $usethirdpartyemailforreceiptemail = 0, $mode = 'automatic', $confirmnow = false, $payment_method = null, $off_session = 0) { global $conf; @@ -335,7 +337,7 @@ class Stripe extends CommonObject } elseif ($fee < $conf->global->STRIPE_APPLICATION_FEE_MINIMAL) { $fee = $conf->global->STRIPE_APPLICATION_FEE_MINIMAL; } - if (! in_array($currency, $arrayzerounitcurrency)) $stripefee = round($fee * 100); + if (! in_array($currency_code, $arrayzerounitcurrency)) $stripefee = round($fee * 100); else $stripefee = round($fee); $paymentintent = null; @@ -411,6 +413,12 @@ class Stripe extends CommonObject // payment_method = // payment_method_types = array('card') //var_dump($dataforintent); + if ($off_session) + { + unset($dataforintent['setup_future_usage']); + $dataforintent["off_session"] = true; + } + if (! is_null($payment_method)) $dataforintent["payment_method"] = $payment_method; if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $stripefee > 0) { @@ -491,7 +499,7 @@ class Stripe extends CommonObject } } - dol_syslog("getPaymentIntent return error=".$error, LOG_INFO, -1); + dol_syslog("getPaymentIntent return error=".$error." this->error=".$this->error, LOG_INFO, -1); if (! $error) { @@ -654,7 +662,7 @@ class Stripe extends CommonObject * @param string $stripeacc ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect * @param int $status Status (0=test, 1=live) * @param int $createifnotlinkedtostripe 1=Create the stripe card and the link if the card is not yet linked to a stripe card - * @return \Stripe\StripeCard|null Stripe Card or null if not found + * @return \Stripe\StripeCard|\Stripe\PaymentMethod|null Stripe Card or null if not found */ public function cardStripe($cu, CompanyPaymentMode $object, $stripeacc = '', $status = 0, $createifnotlinkedtostripe = 0) { @@ -680,10 +688,24 @@ class Stripe extends CommonObject { try { if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage - $card = $cu->sources->retrieve($cardref); + if (! preg_match('/^pm_/', $cardref)) + { + $card = $cu->sources->retrieve($cardref); + } + else + { + $card = \Stripe\PaymentMethod::retrieve($cardref); + } } else { - //$card = $cu->sources->retrieve($cardref, array("stripe_account" => $stripeacc)); // this API fails when array stripe_account is provided - $card = $cu->sources->retrieve($cardref); + if (! preg_match('/^pm_/', $cardref)) + { + //$card = $cu->sources->retrieve($cardref, array("stripe_account" => $stripeacc)); // this API fails when array stripe_account is provided + $card = $cu->sources->retrieve($cardref); + } + else { + //$card = \Stripe\PaymentMethod::retrieve($cardref, array("stripe_account" => $stripeacc)); // Don't know if this works + $card = \Stripe\PaymentMethod::retrieve($cardref); + } } } catch(Exception $e) @@ -707,12 +729,28 @@ class Stripe extends CommonObject //$a = \Stripe\Stripe::getApiKey(); //var_dump($a);var_dump($stripeacc);exit; - dol_syslog("Try to create card dataforcard = ".json_encode($dataforcard)); + dol_syslog("Try to create card with dataforcard = ".json_encode($dataforcard)); try { if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage - $card = $cu->sources->create($dataforcard); + if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) + { + $card = $cu->sources->create($dataforcard); + } + else + { + // TODO + dol_syslog("Error: This case is not supported", LOG_ERR); + } } else { - $card = $cu->sources->create($dataforcard, array("stripe_account" => $stripeacc)); + if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) + { + $card = $cu->sources->create($dataforcard, array("stripe_account" => $stripeacc)); + } + else + { + // TODO + dol_syslog("Error: This case is not supported", LOG_ERR); + } } if ($card)