From 5f1b3fbc12aef681073a31f8653e37a033fdafbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 10 Sep 2018 20:18:16 +0200 Subject: [PATCH 1/5] add stripe user for actions --- htdocs/langs/en_US/stripe.lang | 5 ++-- htdocs/public/stripe/ipn.php | 42 +++++++++++++++++++++++++++------- htdocs/stripe/admin/stripe.php | 12 ++++++++-- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index ecd176a0ae7..5eb1c803829 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -22,7 +22,7 @@ ToOfferALinkForOnlinePaymentOnContractLine=URL to offer a %s online payment user ToOfferALinkForOnlinePaymentOnFreeAmount=URL to offer a %s online payment user interface for a free amount ToOfferALinkForOnlinePaymentOnMemberSubscription=URL to offer a %s online payment user interface for a member subscription YouCanAddTagOnUrl=You can also add url parameter &tag=value to any of those URL (required only for free payment) to add your own payment comment tag. -SetupStripeToHavePaymentCreatedAutomatically=Setup your Stripe with url %s to have payment created automatically when validated by Stripe. +SetupStripeToHavePaymentCreatedAutomatically=Setup your Stripe with url %s to have payment created automatically when validated by Stripe. AccountParameter=Account parameters UsageParameter=Usage parameters InformationToFindParameters=Help to find your %s account information @@ -60,4 +60,5 @@ DeleteACard=Delete Card ConfirmDeleteCard=Are you sure you want to delete this Credit or Debit card? CreateCustomerOnStripe=Create customer on Stripe CreateCardOnStripe=Create card on Stripe -ShowInStripe=Show in Stripe \ No newline at end of file +ShowInStripe=Show in Stripe +StripeUserAccountForActions=User account for Stripe actions diff --git a/htdocs/public/stripe/ipn.php b/htdocs/public/stripe/ipn.php index faca27f78c7..fd4049143ad 100644 --- a/htdocs/public/stripe/ipn.php +++ b/htdocs/public/stripe/ipn.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2018 Thibault FOUCART + * Copyright (C) 2018 Frédéric France * * 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 @@ -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/bank/class/account.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 if (isset($_GET['connect'])){ @@ -88,7 +90,7 @@ catch(\UnexpectedValueException $e) { http_response_code(200); // PHP 5.4 or greater $langs->load("main"); $user = new User($db); -$user->fetch(5); +$user->fetch($conf->global->STRIPE_USER_ACCOUNT_FOR_ACTIONS); $user->getrights(); if (! empty($conf->multicompany->enabled) && ! empty($conf->stripeconnect->enabled) && is_object($mc)) { @@ -126,12 +128,36 @@ if ($event->type == 'payout.created') { if ($result > 0) { - // TODO Use CMail and translation - $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); - $subject = '[NOTIFICATION] Virement programmée'; - $headers = 'From: "'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; // TODO convert in dolibarr standard - mail(''.$conf->global->MAIN_INFO_SOCIETE_MAIL.'', $subject, $body, $headers); - return 1; + $subject = '[NOTIFICATION] Virement programmée'; + if (!empty($user->email)) { + $sendto = dolGetFirstLastname($user->firstname, $user->lastname) . " <".$user->email.">"; + } else { + $sendto = $conf->global->MAIN_INFO_SOCIETE_MAIL.'" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; + } + $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 { diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 19d12a33005..8b5a92c0092 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -70,7 +70,11 @@ 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); 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); + $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) $error ++; $result = dolibarr_set_const($db, "STRIPE_MINIMAL_3DSECURE", GETPOST('STRIPE_MINIMAL_3DSECURE', 'int'), 'chaine', 0, '', $conf->entity); @@ -251,6 +255,11 @@ print 'name; print ''; +print ''; +print $langs->trans("StripeUserAccountForActions").''; +print $form->select_dolusers($conf->global->STRIPE_USER_ACCOUNT_FOR_ACTIONS, 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0); +print ''; + print ''; print $langs->trans("BankAccount").''; print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1); @@ -357,4 +366,3 @@ if (! empty($conf->use_javascript_ajax)) // End of page llxFooter(); $db->close(); - From afdf87603b8dcd06dcadec92512c21f4a1a4b04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 10 Sep 2018 20:50:10 +0200 Subject: [PATCH 2/5] add stripe user for actions --- htdocs/public/stripe/ipn.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/public/stripe/ipn.php b/htdocs/public/stripe/ipn.php index fd4049143ad..9c7941ff5e7 100644 --- a/htdocs/public/stripe/ipn.php +++ b/htdocs/public/stripe/ipn.php @@ -134,6 +134,7 @@ if ($event->type == 'payout.created') { } else { $sendto = $conf->global->MAIN_INFO_SOCIETE_MAIL.'" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; } + $replyto = $sendto; $sendtocc = ''; if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) { $sendtocc = $conf->global->ONLINE_PAYMENT_SENDEMAIL.'" <'.$conf->global->ONLINE_PAYMENT_SENDEMAIL.'>'; From a8cfc6be3f486e91225cf5bd20ee75fbd7fb1cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 10 Sep 2018 20:55:20 +0200 Subject: [PATCH 3/5] add stripe user for actions --- htdocs/stripe/admin/stripe.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 8b5a92c0092..6a4dd8713f7 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -3,6 +3,7 @@ * Copyright (C) 2017 Olivier Geffroy * Copyright (C) 2017 Saasprov * Copyright (C) 2018 ptibogxiv + * Copyright (C) 2018 Frédéric France * * 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 @@ -77,7 +78,7 @@ if ($action == 'setvalue' && $user->admin) $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 'int'), 'chaine', 0, '', $conf->entity); if (! $result > 0) $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) $error ++; $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity); @@ -120,10 +121,8 @@ if ($action == 'setvalue' && $user->admin) if ($action=="setlive") { $liveenable = GETPOST('value','int'); - $res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable,'yesno',0,'',$conf->entity); - if (! $res > 0) $error++; - if (! $error) - { + $res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable, 'yesno', 0, '', $conf->entity); + if ($res > 0) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else From e89ff94d74e42a2fe07273bcf446d3beecf9b224 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 12 Sep 2018 18:35:47 +0200 Subject: [PATCH 4/5] Update stripe.lang --- htdocs/langs/en_US/stripe.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index 5eb1c803829..ed3d24f4370 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -61,4 +61,4 @@ ConfirmDeleteCard=Are you sure you want to delete this Credit or Debit card? CreateCustomerOnStripe=Create customer on Stripe CreateCardOnStripe=Create card on Stripe ShowInStripe=Show in Stripe -StripeUserAccountForActions=User account for Stripe actions +StripeUserAccountForActions=User account to use for some emails notification of Stripe events (Stripe payouts) From fb71edd35a262490f951ed1143aa265582213142 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 12 Sep 2018 18:37:24 +0200 Subject: [PATCH 5/5] Update ipn.php --- htdocs/public/stripe/ipn.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/public/stripe/ipn.php b/htdocs/public/stripe/ipn.php index 9c7941ff5e7..12420c81add 100644 --- a/htdocs/public/stripe/ipn.php +++ b/htdocs/public/stripe/ipn.php @@ -88,7 +88,10 @@ catch(\UnexpectedValueException $e) { // Do something with $event http_response_code(200); // PHP 5.4 or greater + $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->fetch($conf->global->STRIPE_USER_ACCOUNT_FOR_ACTIONS); $user->getrights();