Merge pull request #9456 from frederic34/stripeuser

add stripe user for actions
This commit is contained in:
Laurent Destailleur 2018-09-12 18:37:31 +02:00 committed by GitHub
commit 88192d1bae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 17 deletions

View File

@ -61,3 +61,4 @@ ConfirmDeleteCard=Are you sure you want to delete this Credit or Debit card?
CreateCustomerOnStripe=Create customer on Stripe CreateCustomerOnStripe=Create customer on Stripe
CreateCardOnStripe=Create card on Stripe CreateCardOnStripe=Create card on Stripe
ShowInStripe=Show in Stripe ShowInStripe=Show in Stripe
StripeUserAccountForActions=User account to use for some emails notification of Stripe events (Stripe payouts)

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2018 Thibault FOUCART <support@ptibogxiv.net> /* Copyright (C) 2018 Thibault FOUCART <support@ptibogxiv.net>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -34,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php';
// You can find your endpoint's secret in your webhook settings // You can find your endpoint's secret in your webhook settings
if (isset($_GET['connect'])){ if (isset($_GET['connect'])){
@ -86,9 +88,12 @@ catch(\UnexpectedValueException $e) {
// Do something with $event // Do something with $event
http_response_code(200); // PHP 5.4 or greater http_response_code(200); // PHP 5.4 or greater
$langs->load("main"); $langs->load("main");
// TODO Do we really need a user in setup just to have an name to fill an email topic when it is a technical system notification email
$user = new User($db); $user = new User($db);
$user->fetch(5); $user->fetch($conf->global->STRIPE_USER_ACCOUNT_FOR_ACTIONS);
$user->getrights(); $user->getrights();
if (! empty($conf->multicompany->enabled) && ! empty($conf->stripeconnect->enabled) && is_object($mc)) { if (! empty($conf->multicompany->enabled) && ! empty($conf->stripeconnect->enabled) && is_object($mc)) {
@ -126,12 +131,37 @@ if ($event->type == 'payout.created') {
if ($result > 0) if ($result > 0)
{ {
// TODO Use CMail and translation $subject = '[NOTIFICATION] Virement programmée';
$body = "Un virement de ".price2num($event->data->object->amount/100)." ".$event->data->object->currency." est attendu sur votre compte le ".date('d-m-Y H:i:s',$event->data->object->arrival_date); if (!empty($user->email)) {
$subject = '[NOTIFICATION] Virement programmée'; $sendto = dolGetFirstLastname($user->firstname, $user->lastname) . " <".$user->email.">";
$headers = 'From: "'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; // TODO convert in dolibarr standard } else {
mail(''.$conf->global->MAIN_INFO_SOCIETE_MAIL.'', $subject, $body, $headers); $sendto = $conf->global->MAIN_INFO_SOCIETE_MAIL.'" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
return 1; }
$replyto = $sendto;
$sendtocc = '';
if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
$sendtocc = $conf->global->ONLINE_PAYMENT_SENDEMAIL.'" <'.$conf->global->ONLINE_PAYMENT_SENDEMAIL.'>';
}
$message = "Un virement de ".price2num($event->data->object->amount/100)." ".$event->data->object->currency." est attendu sur votre compte le ".date('d-m-Y H:i:s',$event->data->object->arrival_date);
$mailfile = new CMailFile(
$subject,
$sendto,
$replyto,
$message,
array(),
array(),
array(),
$sendtocc,
'',
0,
-1
);
$ret = $mailfile->sendfile())
return 1;
} }
else else
{ {

View File

@ -3,6 +3,7 @@
* Copyright (C) 2017 Olivier Geffroy <jeff@jeffinfo.com> * Copyright (C) 2017 Olivier Geffroy <jeff@jeffinfo.com>
* Copyright (C) 2017 Saasprov <saasprov@gmail.com> * Copyright (C) 2017 Saasprov <saasprov@gmail.com>
* Copyright (C) 2018 ptibogxiv <support@ptibogxiv.net> * Copyright (C) 2018 ptibogxiv <support@ptibogxiv.net>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -70,10 +71,14 @@ if ($action == 'setvalue' && $user->admin)
$result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity); $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
if (! $result > 0) if (! $result > 0)
$error ++; $error ++;
$result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 'int'), 'chaine', 0, '', $conf->entity); $result = dolibarr_set_const($db, "STRIPE_USER_ACCOUNT_FOR_ACTIONS", GETPOST('STRIPE_USER_ACCOUNT_FOR_ACTIONS', 'int'), 'chaine', 0, '', $conf->entity);
if (! $result > 0) {
$error ++;
}
$result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 'int'), 'chaine', 0, '', $conf->entity);
if (! $result > 0) if (! $result > 0)
$error ++; $error ++;
$result = dolibarr_set_const($db, "STRIPE_MINIMAL_3DSECURE", GETPOST('STRIPE_MINIMAL_3DSECURE', 'int'), 'chaine', 0, '', $conf->entity); $result = dolibarr_set_const($db, "STRIPE_MINIMAL_3DSECURE", GETPOST('STRIPE_MINIMAL_3DSECURE', 'int'), 'chaine', 0, '', $conf->entity);
if (! $result > 0) if (! $result > 0)
$error ++; $error ++;
$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity); $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
@ -116,10 +121,8 @@ if ($action == 'setvalue' && $user->admin)
if ($action=="setlive") if ($action=="setlive")
{ {
$liveenable = GETPOST('value','int'); $liveenable = GETPOST('value','int');
$res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable,'yesno',0,'',$conf->entity); $res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable, 'yesno', 0, '', $conf->entity);
if (! $res > 0) $error++; if ($res > 0) {
if (! $error)
{
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} }
else else
@ -251,6 +254,11 @@ print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.$con
print ' &nbsp; '.$langs->trans("Example").': '.$mysoc->name; print ' &nbsp; '.$langs->trans("Example").': '.$mysoc->name;
print '</td></tr>'; print '</td></tr>';
print '<tr class="oddeven"><td>';
print $langs->trans("StripeUserAccountForActions").'</td><td>';
print $form->select_dolusers($conf->global->STRIPE_USER_ACCOUNT_FOR_ACTIONS, 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0);
print '</td></tr>';
print '<tr class="oddeven"><td>'; print '<tr class="oddeven"><td>';
print $langs->trans("BankAccount").'</td><td>'; print $langs->trans("BankAccount").'</td><td>';
print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1); print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
@ -357,4 +365,3 @@ if (! empty($conf->use_javascript_ajax))
// End of page // End of page
llxFooter(); llxFooter();
$db->close(); $db->close();