From 348fb8e9f23e1001cfa7afda0543b144827f9128 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 12 Jun 2022 21:34:35 +0200 Subject: [PATCH 1/6] Stripe Terminal --- htdocs/stripe/admin/stripe.php | 54 +++++++ htdocs/stripe/ajax/ajax.php | 124 +++++++++++++++ htdocs/stripe/class/stripe.class.php | 41 ++++- htdocs/takepos/admin/terminal.php | 43 +++++ htdocs/takepos/pay.php | 229 ++++++++++++++++++++++++++- 5 files changed, 486 insertions(+), 5 deletions(-) create mode 100644 htdocs/stripe/ajax/ajax.php diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 77c8d9a03b2..8240b21ff75 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -104,6 +104,10 @@ if ($action == 'setvalue' && $user->admin) { if (!$result > 0) { $error++; } + $result = dolibarr_set_const($db, "STRIPE_LOCATION", GETPOST('STRIPE_LOCATION', 'alpha'), '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); if (!$result > 0) { $error++; @@ -364,6 +368,56 @@ if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // What is this for ? print ''; } +// Card Present for Stripe Terminal +if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code + print ''; + print $langs->trans("STRIPE_CARD_PRESENT").''; + if ($conf->use_javascript_ajax) { + print ajax_constantonoff('STRIPE_CARD_PRESENT'); + } else { + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("STRIPE_CARD_PRESENT", $arrval, $conf->global->STRIPE_CARD_PRESENT); + } + print ''; +} + +// Locations for Stripe Terminal +if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code + print ''; + print $langs->trans("STRIPE_LOCATION").''; + $service = 'StripeTest'; + $servicestatus = 0; + if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) { + $service = 'StripeLive'; + $servicestatus = 1; + } + global $stripearrayofkeysbyenv; + $site_account = $stripearrayofkeysbyenv[$servicestatus]['secret_key']; + \Stripe\Stripe::setApiKey($site_account); + if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) { + $service = 'StripeTest'; + $servicestatus = '0'; + dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning'); + } else { + $service = 'StripeLive'; + $servicestatus = '1'; + } + $stripe = new Stripe($db); + $stripeacc = $stripe->getStripeAccount($service); + if ($stripeacc) { + $locations = \Stripe\Terminal\Location::all('', array("stripe_account" => $stripeacc)); + } else { + $locations = \Stripe\Terminal\Location::all(); + } + $location = array(); + $location[""] = $langs->trans("EmptyLocation"); + foreach ($locations as $locations) { + $location[$locations->id] = $locations->display_name; + } + print $form->selectarray("STRIPE_LOCATION", $location, $conf->global->STRIPE_LOCATION); + print ''; +} + // Activate Payment Request API if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code print ''; diff --git a/htdocs/stripe/ajax/ajax.php b/htdocs/stripe/ajax/ajax.php new file mode 100644 index 00000000000..e50b426ee87 --- /dev/null +++ b/htdocs/stripe/ajax/ajax.php @@ -0,0 +1,124 @@ + + * + * 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 . + */ + +/** + * \file htdocs/stripe/ajax/ajax.php + * \brief Ajax action for Stipe ie: Terminal + */ + +if (!defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +if (!defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOBROWSERNOTIF')) { + define('NOBROWSERNOTIF', '1'); +} + +require '../../main.inc.php'; // Load $user and permissions +require_once DOL_DOCUMENT_ROOT.'/includes/stripe/stripe-php/init.php'; +require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + +$action = GETPOST('action', 'aZ09'); +$location = GETPOST('location', 'alphanohtml'); +$stripeacc = GETPOST('stripeacc', 'alphanohtml'); +$servicestatus = GETPOST('servicestatus', 'int'); +$amount = GETPOST('amount', 'int'); + +if (empty($user->rights->takepos->run)) { + accessforbidden(); +} + + +/* + * View + */ + +if ($action == 'getConnexionToken') { + try { + // Be sure to authenticate the endpoint for creating connection tokens. + // Force to use the correct API key + global $stripearrayofkeysbyenv; + \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']); + // The ConnectionToken's secret lets you connect to any Stripe Terminal reader + // and take payments with your Stripe account. + $array = array(); + if (isset($location) && !empty($location)) $array['location'] = $location; + if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage + $connectionToken = \Stripe\Terminal\ConnectionToken::create($array); + } else { + $connectionToken = \Stripe\Terminal\ConnectionToken::create($array, array("stripe_account" => $stripeacc)); + } + echo json_encode(array('secret' => $connectionToken->secret)); + } catch (Error $e) { + http_response_code(500); + echo json_encode(['error' => $e->getMessage()]); + } +} elseif ($action == 'createPaymentIntent') { + try { + $json_str = file_get_contents('php://input'); + $json_obj = json_decode($json_str); + + // For Terminal payments, the 'payment_method_types' parameter must include + // 'card_present' and the 'capture_method' must be set to 'manual' + $object = new Facture($db); + $object->fetch($json_obj->invoiceid); + $object->fetch_thirdparty(); + + $fulltag='INV='.$object->id.'.CUS='.$object->thirdparty->id; + $tag=null; + $fulltag=dol_string_unaccent($fulltag); + + $stripe = new Stripe($db); + $customer = $stripe->customerStripe($object->thirdparty, $stripeacc, $servicestatus, 1); + + $intent = $stripe->getPaymentIntent($json_obj->amount, $object->multicurrency_code, null, 'Stripe payment: '.$fulltag.(is_object($object)?' ref='.$object->ref:''), $object, $customer, $stripeacc, $servicestatus, 1, 'terminal', false, null, 0, 1); + + echo json_encode(array('client_secret' => $intent->client_secret)); + } catch (Error $e) { + http_response_code(500); + echo json_encode(['error' => $e->getMessage()]); + } +} elseif ($action == 'capturePaymentIntent') { + try { + // retrieve JSON from POST body + $json_str = file_get_contents('php://input'); + $json_obj = json_decode($json_str); + if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage + $intent = \Stripe\PaymentIntent::retrieve($json_obj->id); + } else { + $intent = \Stripe\PaymentIntent::retrieve($json_obj->id, array("stripe_account" => $stripeacc)); + } + $intent = $intent->capture(); + + echo json_encode($intent); + } catch (Error $e) { + http_response_code(500); + echo json_encode(['error' => $e->getMessage()]); + } +} diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 36e67d2827c..b14ed0e8ca6 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -290,6 +290,34 @@ class Stripe extends CommonObject return $stripepaymentmethod; } + /** + * Get the Stripe reader Object from its ID + * + * @param string $reader Reader ID + * @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) + * @return \Stripe\Terminal\Reader|null Stripe Reader or null if not found + */ + public function getSelectedReader($reader, $key = '', $status = 0) + { + $selectedreader = null; + + try { + // Force to use the correct API key + global $stripearrayofkeysbyenv; + \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']); + if (empty($key)) { // If the Stripe connect account not set, we use common API usage + $selectedreader = \Stripe\Terminal\Reader::retrieve(''.$reader.''); + } else { + $stripepaymentmethod = \Stripe\Terminal\Reader::retrieve(''.$reader.'', array("stripe_account" => $key)); + } + } catch (Exception $e) { + $this->error = $e->getMessage(); + } + + return $selectedreader; + } + /** * Get the Stripe payment intent. Create it with confirmnow=false * Warning. If a payment was tried and failed, a payment intent was created. @@ -350,7 +378,7 @@ class Stripe extends CommonObject $paymentintent = null; - if (is_object($object) && !empty($conf->global->STRIPE_REUSE_EXISTING_INTENT_IF_FOUND)) { + if (is_object($object) && !empty($conf->global->STRIPE_REUSE_EXISTING_INTENT_IF_FOUND) && empty($conf->global->STRIPE_CARD_PRESENT)) { // Warning. If a payment was tried and failed, a payment intent was created. // But if we change something on object to pay (amount or other that does not change the idempotency key), reusing same payment intent is not allowed by Stripe. // Recommended solution is to recreate a new payment intent each time we need one (old one will be automatically closed by Stripe after a delay), Stripe will @@ -424,6 +452,9 @@ class Stripe extends CommonObject if (!empty($conf->global->STRIPE_SOFORT)) { $paymentmethodtypes[] = "sofort"; } + if (!empty($conf->global->STRIPE_CARD_PRESENT) && $mode == 'terminal') { + $paymentmethodtypes = array("card_present"); + } $dataforintent = array( "confirm" => $confirmnow, // Do not confirm immediatly during creation of intent @@ -456,6 +487,11 @@ class Stripe extends CommonObject if (!empty($conf->global->STRIPE_KLARNA)) { unset($dataforintent['setup_future_usage']); } + if (!empty($conf->global->STRIPE_CARD_PRESENT) && $mode == 'terminal') { + unset($dataforintent['setup_future_usage']); + $dataforintent["capture_method"] = "manual"; + $dataforintent["confirmation_method"] = "manual"; + } if (!is_null($payment_method)) { $dataforintent["payment_method"] = $payment_method; $description .= ' - '.$payment_method; @@ -607,6 +643,9 @@ class Stripe extends CommonObject if (!empty($conf->global->STRIPE_BANCONTACT)) { $paymentmethodtypes[] = "bancontact"; } + if (!empty($conf->global->STRIPE_KLARNA)) { + $paymentmethodtypes[] = "klarna"; + } if (!empty($conf->global->STRIPE_IDEAL)) { $paymentmethodtypes[] = "ideal"; } diff --git a/htdocs/takepos/admin/terminal.php b/htdocs/takepos/admin/terminal.php index f6562d81693..64ce74b6022 100644 --- a/htdocs/takepos/admin/terminal.php +++ b/htdocs/takepos/admin/terminal.php @@ -1,6 +1,7 @@ * Copyright (C) 2011-2017 Juanjo Menent + * Copyright (C) 2021 Thibault FOUCART * * 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 @@ -28,6 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT."/core/lib/takepos.lib.php"; +require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; $terminal = GETPOST('terminal', 'int'); // If socid provided by ajax company selector @@ -73,6 +75,9 @@ if (GETPOST('action', 'alpha') == 'set') { $res = dolibarr_set_const($db, "CASHDESK_ID_BANKACCOUNT_CASH".$terminaltouse, (GETPOST('CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse, 'alpha') > 0 ? GETPOST('CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse, 'alpha') : ''), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "CASHDESK_ID_BANKACCOUNT_CHEQUE".$terminaltouse, (GETPOST('CASHDESK_ID_BANKACCOUNT_CHEQUE'.$terminaltouse, 'alpha') > 0 ? GETPOST('CASHDESK_ID_BANKACCOUNT_CHEQUE'.$terminaltouse, 'alpha') : ''), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "CASHDESK_ID_BANKACCOUNT_CB".$terminaltouse, (GETPOST('CASHDESK_ID_BANKACCOUNT_CB'.$terminaltouse, 'alpha') > 0 ? GETPOST('CASHDESK_ID_BANKACCOUNT_CB'.$terminaltouse, 'alpha') : ''), 'chaine', 0, '', $conf->entity); + if (!empty($conf->stripe->enabled) && !empty($conf->global->STRIPE_CARD_PRESENT)) { + $res = dolibarr_set_const($db, "CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL".$terminaltouse, GETPOST('CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL'.$terminaltouse, 'alpha'), 'chaine', 0, '', $conf->entity); + } if (!empty($conf->global->TAKEPOS_ENABLE_SUMUP)) { $res = dolibarr_set_const($db, "CASHDESK_ID_BANKACCOUNT_SUMUP".$terminaltouse, (GETPOST('CASHDESK_ID_BANKACCOUNT_SUMUP'.$terminaltouse, 'alpha') > 0 ? GETPOST('CASHDESK_ID_BANKACCOUNT_SUMUP'.$terminaltouse, 'alpha') : ''), 'chaine', 0, '', $conf->entity); } @@ -174,6 +179,44 @@ if (!empty($conf->banque->enabled)) { $atleastonefound++; } print ''; + + if (!empty($conf->stripe->enabled) && !empty($conf->global->STRIPE_CARD_PRESENT)) { + print ''.$langs->trans("CashDeskBankAccountForStripeTerminal").''; // Force Stripe Terminal + print ''; + $service = 'StripeTest'; + $servicestatus = 0; + if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) { + $service = 'StripeLive'; + $servicestatus = 1; + } + global $stripearrayofkeysbyenv; + $site_account = $stripearrayofkeysbyenv[$servicestatus]['secret_key']; + \Stripe\Stripe::setApiKey($site_account); + if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) { + $service = 'StripeTest'; + $servicestatus = '0'; + dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning'); + } else { + $service = 'StripeLive'; + $servicestatus = '1'; + } + $stripe = new Stripe($db); + $stripeacc = $stripe->getStripeAccount($service); + if ($stripeacc) { + $readers = \Stripe\Terminal\Reader::all('', array("location" => $conf->global->STRIPE_LOCATION, "stripe_account" => $stripeacc)); + } else { + $readers = \Stripe\Terminal\Reader::all('', array("location" => $conf->global->STRIPE_LOCATION)); + } + + $reader = array(); + $reader[""] = $langs->trans("NoReader"); + foreach ($readers as $readers) { + $reader[$reader->id] = $readers->label.' ('.$readers->status.')'; + } + print $form->selectarray('CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL'.$terminaltouse, $reader, $conf->global->{'CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL'.$terminaltouse}); + print ''; + } + if ($conf->global->TAKEPOS_ENABLE_SUMUP) { print ''.$langs->trans("CashDeskBankAccountForSumup").''; print ''; diff --git a/htdocs/takepos/pay.php b/htdocs/takepos/pay.php index 40d873654c6..cc1d335272d 100644 --- a/htdocs/takepos/pay.php +++ b/htdocs/takepos/pay.php @@ -1,5 +1,6 @@ + * Copyright (C) 2021 Thibault FOUCART * * 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 @@ -40,6 +41,7 @@ if (!defined('NOREQUIREHTML')) { require '../main.inc.php'; // Load $user and permissions require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; $langs->loadLangs(array("main", "bills", "cashdesk", "banks")); @@ -51,11 +53,60 @@ if (empty($user->rights->takepos->run)) { accessforbidden(); } +if (!empty($conf->stripe->enabled)) { + $service = 'StripeTest'; + $servicestatus = 0; + if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) { + $service = 'StripeLive'; + $servicestatus = 1; + } + + // Force to use the correct API key + global $stripearrayofkeysbyenv; + $site_account = $stripearrayofkeysbyenv[$servicestatus]['publishable_key']; + + $stripe = new Stripe($db); + $stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account (no remote access to Stripe here) + $stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus, $site_account); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here) + $keyforstripeterminalbank = "CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL".$_SESSION["takeposterminal"]; + ?> + + +stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) { + dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning', 1); +} + $invoice = new Facture($db); if ($invoiceid > 0) { $invoice->fetch($invoiceid); @@ -73,6 +124,57 @@ if ($invoiceid > 0) { } } +?> + +global->TAKEPOS_NUMPAD == 0) { }); } + function fetchPaymentIntentClientSecret(amount, invoiceid) { + const bodyContent = JSON.stringify({ amount : amount, invoiceid : invoiceid }); + + return fetch('', { + method: "POST", + headers: { + 'Content-Type': 'application/json' + }, + body: bodyContent + }) + .then(function(response) { + return response.json(); + }) + .then(function(data) { + return data.client_secret; + }); + } + + + function capturePaymentIntent(paymentIntentId) { + const bodyContent = JSON.stringify({"id": paymentIntentId}) + + return fetch('', { + method: "POST", + headers: { + 'Content-Type': 'application/json' + }, + body: bodyContent + }) + .then(function(response) { + return response.json(); + }) + .then(function(data) { + return data.client_secret; + }); + } + + + function ValidateStripeTerminal() { + console.log("Launch ValidateStripeTerminal"); + var invoiceid = 0 ? $invoiceid : 0); ?>; + var accountid = $("#selectaccountid").val(); + var amountpayed = $("#change1").val(); + var excess = $("#change2").val(); + if (amountpayed > getRemainToPay(); ?>) { + amountpayed = getRemainToPay(); ?>; + } + if (amountpayed == 0) { + amountpayed = getRemainToPay(); ?>; + } + + console.log("Pay with terminal ", amountpayed); + + fetchPaymentIntentClientSecret(amountpayed, invoiceid).then(function(client_secret) { + global->STRIPE_TERMINAL_SIMULATED)) { ?> + terminal.setSimulatorConfiguration({testCardNumber: 'global->STRIPE_TERMINAL_SIMULATED; ?>'}); + + document.getElementById("card-present-alert").innerHTML = '
trans('PaymentSendToStripeTerminal'); ?>
'; + terminal.collectPaymentMethod(client_secret).then(function(result) { + if (result.error) { + // Placeholder for handling result.error + document.getElementById("card-present-alert").innerHTML = '
'+result.error.message+'
'; + } else { + document.getElementById("card-present-alert").innerHTML = '
trans('PaymentBeingProcessed'); ?>
'; + console.log('terminal.collectPaymentMethod', result.paymentIntent); + terminal.processPayment(result.paymentIntent).then(function(result) { + if (result.error) { + document.getElementById("card-present-alert").innerHTML = '
'+result.error.message+'
'; + console.log(result.error) + } else if (result.paymentIntent) { + paymentIntentId = result.paymentIntent.id; + console.log('terminal.processPayment', result.paymentIntent); + capturePaymentIntent(paymentIntentId).then(function(client_secret) { + if (result.error) { + // Placeholder for handling result.error + document.getElementById("card-present-alert").innerHTML = '
'+result.error.message+'
'; + console.log("error when capturing paymentIntent", result.error); + } else { + document.getElementById("card-present-alert").innerHTML = '
trans('PaymentValidated'); ?>
'; + console.log("Capture paymentIntent successfull "+paymentIntentId); + parent.$("#poslines").load("invoice.php?place=&action=valid&pay=CB&amount="+amountpayed+"&excess="+excess+"&invoiceid="+invoiceid+"&accountid="+accountid, function() { + if (amountpayed > || amountpayed == || amountpayed==0 ) { + console.log("Close popup"); + parent.$.colorbox.close(); + } + else { + console.log("Amount is not comple, so we do NOT close popup and reload it."); + location.reload(); + } + }); + + } + }); + } + }); + } + }); + }); + } + function ValidateSumup() { console.log("Launch ValidateSumup"); @@ -271,7 +479,7 @@ if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) { ?> -
+
trans('TotalTTC'); ?>: total_ttc, 1, '', 1, -1, -1, $invoice->multicurrency_code); ?>
@@ -299,7 +507,6 @@ if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) { } ?>
-
global->TAKEPOS_NUMPAD; - +if (!empty($conf->stripe->enabled) && !empty($conf->global->STRIPE_CARD_PRESENT)) { + print ''; + dol_htmloutput_mesg($langs->trans('ConnectingToStripeTerminal', 'Stripe'), '', 'warning', 1); + print ''; +} print ''; print ''; print ''; @@ -424,8 +635,18 @@ while ($i < count($arrayOfValidPaymentModes)) { $i = $i + 1; } -$keyforsumupbank = "CASHDESK_ID_BANKACCOUNT_SUMUP".$_SESSION["takeposterminal"]; +if (!empty($conf->stripe->enabled) && !empty($conf->global->STRIPE_CARD_PRESENT)) { + $keyforstripeterminalbank = "CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL".$_SESSION["takeposterminal"]; + print ''; + if (!empty($conf->global->$keyforstripeterminalbank)) { + } else { + $langs->loadLangs(array("errors", "admin")); + //print ''; + } +} + if ($conf->global->TAKEPOS_ENABLE_SUMUP) { + $keyforsumupbank = "CASHDESK_ID_BANKACCOUNT_SUMUP".$_SESSION["takeposterminal"]; if (!empty($conf->global->$keyforsumupbank)) { print ''; } else { From 627f3469336d636ea1f1a9d52c2a3231117c8463 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 12 Jun 2022 21:40:21 +0200 Subject: [PATCH 2/6] Update pay.php --- htdocs/takepos/pay.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/takepos/pay.php b/htdocs/takepos/pay.php index cc1d335272d..f4c1a0416b1 100644 --- a/htdocs/takepos/pay.php +++ b/htdocs/takepos/pay.php @@ -103,7 +103,7 @@ function fetchConnectionToken() { * View */ -if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) { +if (!empty($conf->stripe->enabled) && isset($keyforstripeterminalbank) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) { dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning', 1); } @@ -524,7 +524,7 @@ $action_buttons = array( ), ); $numpad = $conf->global->TAKEPOS_NUMPAD; -if (!empty($conf->stripe->enabled) && !empty($conf->global->STRIPE_CARD_PRESENT)) { +if (!empty($conf->stripe->enabled) && isset($keyforstripeterminalbank) && !empty($conf->global->STRIPE_CARD_PRESENT)) { print ''; dol_htmloutput_mesg($langs->trans('ConnectingToStripeTerminal', 'Stripe'), '', 'warning', 1); print ''; From 87f98b5bcbeea3778a45450dfe62293bef93f042 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 12 Jun 2022 21:44:17 +0200 Subject: [PATCH 3/6] Update pay.php --- htdocs/takepos/pay.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/takepos/pay.php b/htdocs/takepos/pay.php index f4c1a0416b1..f487862e895 100644 --- a/htdocs/takepos/pay.php +++ b/htdocs/takepos/pay.php @@ -635,7 +635,7 @@ while ($i < count($arrayOfValidPaymentModes)) { $i = $i + 1; } -if (!empty($conf->stripe->enabled) && !empty($conf->global->STRIPE_CARD_PRESENT)) { +if (!empty($conf->stripe->enabled) && isset($keyforstripeterminalbank) && !empty($conf->global->STRIPE_CARD_PRESENT)) { $keyforstripeterminalbank = "CASHDESK_ID_BANKACCOUNT_STRIPETERMINAL".$_SESSION["takeposterminal"]; print ''; if (!empty($conf->global->$keyforstripeterminalbank)) { From 616e6f5a8f833a27c46f5667c85f2c989fa2ed60 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 12 Jun 2022 19:46:22 +0000 Subject: [PATCH 4/6] Fixing style errors. --- htdocs/stripe/ajax/ajax.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/stripe/ajax/ajax.php b/htdocs/stripe/ajax/ajax.php index e50b426ee87..cf6ec53d580 100644 --- a/htdocs/stripe/ajax/ajax.php +++ b/htdocs/stripe/ajax/ajax.php @@ -92,13 +92,13 @@ if ($action == 'getConnexionToken') { $fulltag='INV='.$object->id.'.CUS='.$object->thirdparty->id; $tag=null; - $fulltag=dol_string_unaccent($fulltag); + $fulltag=dol_string_unaccent($fulltag); $stripe = new Stripe($db); $customer = $stripe->customerStripe($object->thirdparty, $stripeacc, $servicestatus, 1); $intent = $stripe->getPaymentIntent($json_obj->amount, $object->multicurrency_code, null, 'Stripe payment: '.$fulltag.(is_object($object)?' ref='.$object->ref:''), $object, $customer, $stripeacc, $servicestatus, 1, 'terminal', false, null, 0, 1); - + echo json_encode(array('client_secret' => $intent->client_secret)); } catch (Error $e) { http_response_code(500); From 1c61dda0ddd000d34fdc363a1a54f0c87120d228 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 10 Jul 2022 10:11:23 +0200 Subject: [PATCH 5/6] Update stripe.php --- htdocs/stripe/admin/stripe.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 8240b21ff75..bd86b31e0f2 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -2,7 +2,7 @@ /* Copyright (C) 2017 Alexandre Spangaro * Copyright (C) 2017 Olivier Geffroy * Copyright (C) 2017 Saasprov - * Copyright (C) 2018-2021 Thibault FOUCART + * Copyright (C) 2018-2022 Thibault FOUCART * Copyright (C) 2018 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -104,10 +104,12 @@ if ($action == 'setvalue' && $user->admin) { if (!$result > 0) { $error++; } + if (GETPOSTISSET('STRIPE_LOCATION')) { $result = dolibarr_set_const($db, "STRIPE_LOCATION", GETPOST('STRIPE_LOCATION', 'alpha'), '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); if (!$result > 0) { $error++; From 445add32e30a296ecb3e2e1917a7e2fd38c3c8e9 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 10 Jul 2022 08:16:04 +0000 Subject: [PATCH 6/6] Fixing style errors. --- htdocs/stripe/admin/stripe.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index bd86b31e0f2..0206de8cb43 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -105,10 +105,10 @@ if ($action == 'setvalue' && $user->admin) { $error++; } if (GETPOSTISSET('STRIPE_LOCATION')) { - $result = dolibarr_set_const($db, "STRIPE_LOCATION", GETPOST('STRIPE_LOCATION', 'alpha'), 'chaine', 0, '', $conf->entity); - if (!$result > 0) { - $error++; - } + $result = dolibarr_set_const($db, "STRIPE_LOCATION", GETPOST('STRIPE_LOCATION', 'alpha'), '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); if (!$result > 0) {