From 6a363fd1ab2d17d96d8e2b008dcdcf26d05b5015 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Oct 2018 19:26:00 +0200 Subject: [PATCH 1/3] API Stripe 2018-09-24 --- .../core/triggers/interface_80_modStripe_Stripe.class.php | 8 ++++---- htdocs/public/payment/newpayment.php | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php index 43dc796bd5f..04326e7a3fe 100644 --- a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php +++ b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php @@ -17,7 +17,7 @@ */ /** - * \file htdocs/core/triggers/interface_50_modStripe_Stripe.class.php + * \file htdocs/core/triggers/interface_80_modStripe_Stripe.class.php * \ingroup core * \brief Fichier * \remarks Son propre fichier d'actions peut etre cree par recopie de celui-ci: @@ -148,9 +148,9 @@ class InterfaceStripe { $namecleaned = $object->name ? $object->name : null; $vatcleaned = array( - "tax_id" => $object->tva_intra ? $object->tva_intra : null, // We force data to "null" if empty as expected by Stripe - "type" => 'vat', - ); + "tax_id" => $object->tva_intra ? $object->tva_intra : null, // We force data to "null" if empty as expected by Stripe + "type" => 'vat', + ); // Detect if we change a Stripe info (email, description, vat id) $changerequested = 0; diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index a03c0a719c6..08e50e58be7 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -495,12 +495,17 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled)) } else { + $vatcleaned = array( + "tax_id" => $vatnumber ? $vatnumber : null, // We force data to "null" if empty as expected by Stripe + "type" => 'vat', + ); + dol_syslog("Create anonymous customer card profile", LOG_DEBUG, 0, '_stripe'); $customer = \Stripe\Customer::create(array( 'email' => $email, 'description' => ($email?'Anonymous customer for '.$email:'Anonymous customer'), 'metadata' => $metadata, - 'business_vat_id' => ($vatnumber?$vatnumber:null), + 'tax_info' => $vatcleaned, 'source' => $stripeToken // source can be a token OR array('object'=>'card', 'exp_month'=>xx, 'exp_year'=>xxxx, 'number'=>xxxxxxx, 'cvc'=>xxx, 'name'=>'Cardholder's full name', zip ?) )); // Return $customer = array('id'=>'cus_XXXX', ...) From 2bbf9a3429b9d46b37ef61250c35bb83d4bae226 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Oct 2018 20:37:59 +0200 Subject: [PATCH 2/3] Hide feature that need re-engeneering --- .../class/actions_datapolicies.class.php | 77 ++++++++++--------- htdocs/datapolicies/lib/datapolicies.lib.php | 11 ++- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/htdocs/datapolicies/class/actions_datapolicies.class.php b/htdocs/datapolicies/class/actions_datapolicies.class.php index d65de390b8c..45e443cb274 100644 --- a/htdocs/datapolicies/class/actions_datapolicies.class.php +++ b/htdocs/datapolicies/class/actions_datapolicies.class.php @@ -363,45 +363,48 @@ class ActionsDatapolicies global $conf, $user, $langs; $langs->load('datapolicies@datapolicies'); - $dialog = '"; - $dialog .= ''; - echo $dialog; - if ($parameters['currentcontext'] == 'thirdpartycard' && in_array($object->forme_juridique_code, array(11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005)) || $object->typent_id == 8) { - echo ''; - } elseif ($parameters['currentcontext'] == 'membercard') { - echo ''; - } elseif ($parameters['currentcontext'] == 'contactcard') { - echo ''; - } - if (!empty($object->mail) && empty($object->array_options['options_datapolicies_send']) && $parameters['currentcontext'] == 'thirdpartycard' && in_array($object->forme_juridique_code, array(11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005)) || $object->typent_id == 8) { - echo ''; - } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicies_send']) && $parameters['currentcontext'] == 'membercard') { - echo ''; - } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicies_send']) && $parameters['currentcontext'] == 'contactcard') { - echo ''; + return false; + }); + } ); + '; + echo $dialog; + if ($parameters['currentcontext'] == 'thirdpartycard' && in_array($object->forme_juridique_code, array(11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005)) || $object->typent_id == 8) { + echo ''; + } elseif ($parameters['currentcontext'] == 'membercard') { + echo ''; + } elseif ($parameters['currentcontext'] == 'contactcard') { + echo ''; + } + if (!empty($object->mail) && empty($object->array_options['options_datapolicies_send']) && $parameters['currentcontext'] == 'thirdpartycard' && in_array($object->forme_juridique_code, array(11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005)) || $object->typent_id == 8) { + echo ''; + } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicies_send']) && $parameters['currentcontext'] == 'membercard') { + echo ''; + } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicies_send']) && $parameters['currentcontext'] == 'contactcard') { + echo ''; + } } } diff --git a/htdocs/datapolicies/lib/datapolicies.lib.php b/htdocs/datapolicies/lib/datapolicies.lib.php index 59366d1f93d..cca255801a8 100644 --- a/htdocs/datapolicies/lib/datapolicies.lib.php +++ b/htdocs/datapolicies/lib/datapolicies.lib.php @@ -40,10 +40,13 @@ function datapoliciesAdminPrepareHead() $head[$h][2] = 'settings'; $h++; - $head[$h][0] = dol_buildpath("/datapolicies/admin/setupmail.php", 1); - $head[$h][1] = $langs->trans("DATAPOLICIESMail"); - $head[$h][2] = 'settings'; - $h++; + if (! empty($conf->global->DATAPOLICIES_ENABLE_EMAILS)) + { + $head[$h][0] = dol_buildpath("/datapolicies/admin/setupmail.php", 1); + $head[$h][1] = $langs->trans("DATAPOLICIESMail"); + $head[$h][2] = 'settings'; + $h++; + } complete_head_from_modules($conf, $langs, $object, $head, $h, 'datapolicies'); From 1e635cff1b3bf7d21cb78f2ed1c7669d23dafe43 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Oct 2018 21:00:33 +0200 Subject: [PATCH 3/3] Fix new stripe API --- .../interface_80_modStripe_Stripe.class.php | 23 +++++++--- htdocs/public/payment/newpayment.php | 46 +++++++++++-------- htdocs/stripe/class/stripe.class.php | 19 +++++--- 3 files changed, 55 insertions(+), 33 deletions(-) diff --git a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php index 04326e7a3fe..cb03315496a 100644 --- a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php +++ b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php @@ -147,22 +147,33 @@ class InterfaceStripe if ($customer) { $namecleaned = $object->name ? $object->name : null; - $vatcleaned = array( - "tax_id" => $object->tva_intra ? $object->tva_intra : null, // We force data to "null" if empty as expected by Stripe - "type" => 'vat', - ); + $vatcleaned = $object->tva_intra ? $object->tva_intra : null; + + $taxinfo = array('type'=>'vat'); + if ($vatcleaned) + { + $taxinfo["tax_id"] = $vatcleaned; + } + // We force data to "null" if not defined as expected by Stripe + if (empty($vatcleaned)) $taxinfo=null; // Detect if we change a Stripe info (email, description, vat id) $changerequested = 0; if (! empty($object->email) && $object->email != $customer->email) $changerequested++; if ($namecleaned != $customer->description) $changerequested++; - if ($vatcleaned != $customer->tax_info) $changerequested++; + if (! isset($customer->tax_info['tax_id']) && ! is_null($vatcleaned)) $changerequested++; + elseif (isset($customer->tax_info['tax_id']) && is_null($vatcleaned)) $changerequested++; + elseif (isset($customer->tax_info['tax_id']) && ! is_null($vatcleaned)) + { + if ($vatcleaned != $customer->tax_info['tax_id']) $changerequested++; + } if ($changerequested) { if (! empty($object->email)) $customer->email = $object->email; $customer->description = $namecleaned; - $customer->tax_info = $vatcleaned; + if (empty($taxinfo)) $customer->tax_info = array('type'=>'vat', 'tax_id'=>null); + else $customer->tax_info = $taxinfo; $customer->save(); } diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 08e50e58be7..e0234fcd1f9 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -413,12 +413,12 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled)) $dol_type=(GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha')); $dol_id=GETPOST('dol_id', 'int'); $vatnumber = GETPOST('vatnumber','alpha'); - $savesource=GETPOST('savesource', 'int'); + $savesource=GETPOSTISSET('savesource')?GETPOST('savesource', 'int'):1; - dol_syslog("stripeToken = ".$stripeToken, LOG_DEBUG, 0, '_stripe'); - dol_syslog("email = ".$email, LOG_DEBUG, 0, '_stripe'); - dol_syslog("thirdparty_id = ".$thirdparty_id, LOG_DEBUG, 0, '_stripe'); - dol_syslog("vatnumber = ".$vatnumber, LOG_DEBUG, 0, '_stripe'); + dol_syslog("POST stripeToken = ".$stripeToken, LOG_DEBUG, 0, '_stripe'); + dol_syslog("POST email = ".$email, LOG_DEBUG, 0, '_stripe'); + dol_syslog("POST thirdparty_id = ".$thirdparty_id, LOG_DEBUG, 0, '_stripe'); + dol_syslog("POST vatnumber = ".$vatnumber, LOG_DEBUG, 0, '_stripe'); $error = 0; @@ -444,7 +444,6 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled)) $servicestatus = 1; } - $thirdparty = new Societe($db); $thirdparty->fetch($thirdparty_id); @@ -455,9 +454,11 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled)) $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1); // Create Stripe card from Token - if (! empty($savesource)) { - $card = $customer->sources->create(array("source" => $stripeToken, "metadata" => $metadata)); - } else { $card = $stripeToken; } + if ($savesource) { + $card = $customer->sources->create(array("source" => $stripeToken, "metadata" => $metadata)); + } else { + $card = $stripeToken; + } if (empty($card)) { @@ -468,9 +469,9 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled)) } else { - if (! empty($FULLTAG)) $metadata["FULLTAG"] = $FULLTAG; - if (! empty($dol_id)) $metadata["dol_id"] = $dol_id; - if (! empty($dol_type)) $metadata["dol_type"] = $dol_type; + if (! empty($FULLTAG)) $metadata["FULLTAG"] = $FULLTAG; + if (! empty($dol_id)) $metadata["dol_id"] = $dol_id; + if (! empty($dol_type)) $metadata["dol_type"] = $dol_type; dol_syslog("Create charge on card ".$card->id, LOG_DEBUG, 0, '_stripe'); $charge = \Stripe\Charge::create(array( @@ -495,24 +496,29 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled)) } else { - $vatcleaned = array( - "tax_id" => $vatnumber ? $vatnumber : null, // We force data to "null" if empty as expected by Stripe - "type" => 'vat', - ); + $vatcleaned = $vatnumber ? $vatnumber : null; + + $taxinfo = array('type'=>'vat'); + if ($vatcleaned) + { + $taxinfo["tax_id"] = $vatcleaned; + } + // We force data to "null" if not defined as expected by Stripe + if (empty($vatcleaned)) $taxinfo=null; dol_syslog("Create anonymous customer card profile", LOG_DEBUG, 0, '_stripe'); $customer = \Stripe\Customer::create(array( 'email' => $email, 'description' => ($email?'Anonymous customer for '.$email:'Anonymous customer'), 'metadata' => $metadata, - 'tax_info' => $vatcleaned, + 'tax_info' => $taxinfo, 'source' => $stripeToken // source can be a token OR array('object'=>'card', 'exp_month'=>xx, 'exp_year'=>xxxx, 'number'=>xxxxxxx, 'cvc'=>xxx, 'name'=>'Cardholder's full name', zip ?) )); // Return $customer = array('id'=>'cus_XXXX', ...) - if (! empty($FULLTAG)) $metadata["FULLTAG"] = $FULLTAG; - if (! empty($dol_id)) $metadata["dol_id"] = $dol_id; - if (! empty($dol_type)) $metadata["dol_type"] = $dol_type; + if (! empty($FULLTAG)) $metadata["FULLTAG"] = $FULLTAG; + if (! empty($dol_id)) $metadata["dol_id"] = $dol_id; + if (! empty($dol_type)) $metadata["dol_type"] = $dol_type; // The customer was just created with a source, so we can make a charge // with no card defined, the source just used for customer creation will be used. diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 5aabb60f07c..db2553ee167 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -189,13 +189,18 @@ class Stripe extends CommonObject "description" => $object->name, "metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])) ); - - if ($object->tva_intra!=null) - { - $dataforcustomer["tax_info"] = array( - "tax_id" => $object->tva_intra, - "type" => 'vat'); - } + + $vatcleaned = $object->tva_intra ? $object->tva_intra : null; + + $taxinfo = array('type'=>'vat'); + if ($vatcleaned) + { + $taxinfo["tax_id"] = $vatcleaned; + } + // We force data to "null" if not defined as expected by Stripe + if (empty($vatcleaned)) $taxinfo=null; + + $dataforcustomer["tax_info"] = $taxinfo; //$a = \Stripe\Stripe::getApiKey(); //var_dump($a);var_dump($key);exit;