Merge pull request #10611 from frederic34/patch-21

Update stripe.class.php
This commit is contained in:
Laurent Destailleur 2019-02-15 15:15:29 +01:00 committed by GitHub
commit 8d699c2b49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -251,7 +251,7 @@ class Stripe extends CommonObject
*/ */
public function getPaymentIntent($object, $customer, $key = null, $status = 0, $usethirdpartyemailforreceiptemail = 0, $mode = 'automatic') public function getPaymentIntent($object, $customer, $key = null, $status = 0, $usethirdpartyemailforreceiptemail = 0, $mode = 'automatic')
{ {
global $conf, $user; global $conf, $user, $mysoc;
if (empty($object->id)) if (empty($object->id))
{ {
@ -302,34 +302,34 @@ class Stripe extends CommonObject
} }
else //if ($createifnotlinkedtostripe) else //if ($createifnotlinkedtostripe)
{ {
$arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'); $arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
if (! in_array($object->multicurrency_code, $arrayzerounitcurrency)) $stripeamount=$object->multicurrency_total_ttc * 100; if (! in_array($object->multicurrency_code, $arrayzerounitcurrency)) $stripeamount=$object->multicurrency_total_ttc * 100;
else $stripeamount = $object->multicurrency_total_ttc; else $stripeamount = $object->multicurrency_total_ttc;
$fee = round(($amount * ($conf->global->STRIPE_APPLICATION_FEE_PERCENT / 100) + $conf->global->STRIPE_APPLICATION_FEE) * 100); $fee = round(($amount * ($conf->global->STRIPE_APPLICATION_FEE_PERCENT / 100) + $conf->global->STRIPE_APPLICATION_FEE) * 100);
if ($fee < ($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100)) { if ($fee < ($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100)) {
$fee = round($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100); $fee = round($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100);
} }
$description=$object->element.$object->ref; $description=$object->element.$object->ref;
$dataforintent = array( $dataforintent = array(
"amount" => $stripeamount, "amount" => $stripeamount,
"currency" => $object->multicurrency_code, "currency" => $object->multicurrency_code,
"customer" => $customer, "customer" => $customer,
"allowed_source_types" => ["card"], "allowed_source_types" => ["card"],
"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt "statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt
"metadata" => array('dol_type'=>$object->element, 'dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])) "metadata" => array('dol_type'=>$object->element, 'dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))
); );
if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0) if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)
{ {
$dataforintent["application_fee"] = $fee; $dataforintent["application_fee"] = $fee;
} }
if ($societe->email && $usethirdpartyemailforreceiptemail) if ($societe->email && $usethirdpartyemailforreceiptemail)
{ {
$dataforintent["receipt_email"] = $societe->email; $dataforintent["receipt_email"] = $societe->email;
} }
try { try {
// Force to use the correct API key // Force to use the correct API key
@ -341,14 +341,14 @@ class Stripe extends CommonObject
} else { } else {
$paymentintent = \Stripe\PaymentIntent::create($dataforintent, array("idempotency_key" => "$description","stripe_account" => $key)); $paymentintent = \Stripe\PaymentIntent::create($dataforintent, array("idempotency_key" => "$description","stripe_account" => $key));
} }
$now=dol_now(); $now=dol_now();
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_facture_demande (fk_soc, date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site)"; $sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_facture_demande (fk_soc, date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site)";
$sql .= " VALUES ('".$object->socid."','".$this->db->idate($now)."', '0', '".$this->db->escape($paymentintent->id)."', ".$object->id.", '".$object->element."', " . $conf->entity . ", '" . $service . "')"; $sql .= " VALUES ('".$object->socid."','".$this->db->idate($now)."', '0', '".$this->db->escape($paymentintent->id)."', ".$object->id.", '".$object->element."', " . $conf->entity . ", '" . $service . "')";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) if (! $resql)
{ {
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
dol_syslog(get_class($this) . "::PaymentIntent not insert with id=".$paymentintent->id); dol_syslog(get_class($this) . "::PaymentIntent not insert with id=".$paymentintent->id);
} }
} }
catch(Exception $e) catch(Exception $e)
@ -395,7 +395,7 @@ class Stripe extends CommonObject
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$cardref = $obj->stripe_card_ref; $cardref = $obj->stripe_card_ref;
dol_syslog("************* cardref=".$cardref); dol_syslog(get_class($this) . "::cardStripe cardref=".$cardref);
if ($cardref) if ($cardref)
{ {
try { try {
@ -553,7 +553,7 @@ class Stripe extends CommonObject
{ {
if (preg_match('/acct_/i', $source)) if (preg_match('/acct_/i', $source))
{ {
$charge = \Stripe\Charge::create(array( $charge = \Stripe\Charge::create(array(
"amount" => "$stripeamount", "amount" => "$stripeamount",
"currency" => "$currency", "currency" => "$currency",
"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt "statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt
@ -589,25 +589,25 @@ class Stripe extends CommonObject
} }
$paymentarray = array( $paymentarray = array(
"amount" => "$stripeamount", "amount" => "$stripeamount",
"currency" => "$currency", "currency" => "$currency",
"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt "statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt
"description" => "Stripe payment: ".$description, "description" => "Stripe payment: ".$description,
"capture" => $capture, "capture" => $capture,
"metadata" => $metadata, "metadata" => $metadata,
"source" => "$source", "source" => "$source",
"customer" => "$customer" "customer" => "$customer"
); );
if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0) if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)
{ {
$paymentarray["application_fee"] = $fee; $paymentarray["application_fee"] = $fee;
} }
if ($societe->email && $usethirdpartyemailforreceiptemail) if ($societe->email && $usethirdpartyemailforreceiptemail)
{ {
$paymentarray["receipt_email"] = $societe->email; $paymentarray["receipt_email"] = $societe->email;
} }
$charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$ref","stripe_account" => "$account")); $charge = \Stripe\Charge::create($paymentarray, array("idempotency_key" => "$ref","stripe_account" => "$account"));
} }
if (isset($charge->id)) {} if (isset($charge->id)) {}