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')
{
global $conf, $user;
global $conf, $user, $mysoc;
if (empty($object->id))
{
@ -302,34 +302,34 @@ class Stripe extends CommonObject
}
else //if ($createifnotlinkedtostripe)
{
$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;
else $stripeamount = $object->multicurrency_total_ttc;
$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;
else $stripeamount = $object->multicurrency_total_ttc;
$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)) {
$fee = round($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100);
}
$description=$object->element.$object->ref;
$description=$object->element.$object->ref;
$dataforintent = array(
"amount" => $stripeamount,
"currency" => $object->multicurrency_code,
"customer" => $customer,
"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
"customer" => $customer,
"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
"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)
{
$dataforintent["application_fee"] = $fee;
}
if ($societe->email && $usethirdpartyemailforreceiptemail)
{
$dataforintent["receipt_email"] = $societe->email;
}
if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)
{
$dataforintent["application_fee"] = $fee;
}
if ($societe->email && $usethirdpartyemailforreceiptemail)
{
$dataforintent["receipt_email"] = $societe->email;
}
try {
// Force to use the correct API key
@ -341,14 +341,14 @@ class Stripe extends CommonObject
} else {
$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 .= " 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);
if (! $resql)
{
$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)
@ -395,7 +395,7 @@ class Stripe extends CommonObject
{
$obj = $this->db->fetch_object($resql);
$cardref = $obj->stripe_card_ref;
dol_syslog("************* cardref=".$cardref);
dol_syslog(get_class($this) . "::cardStripe cardref=".$cardref);
if ($cardref)
{
try {
@ -553,7 +553,7 @@ class Stripe extends CommonObject
{
if (preg_match('/acct_/i', $source))
{
$charge = \Stripe\Charge::create(array(
$charge = \Stripe\Charge::create(array(
"amount" => "$stripeamount",
"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
@ -589,25 +589,25 @@ class Stripe extends CommonObject
}
$paymentarray = array(
"amount" => "$stripeamount",
"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
"description" => "Stripe payment: ".$description,
"capture" => $capture,
"metadata" => $metadata,
"source" => "$source",
"customer" => "$customer"
);
if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)
{
$paymentarray["application_fee"] = $fee;
}
if ($societe->email && $usethirdpartyemailforreceiptemail)
{
$paymentarray["receipt_email"] = $societe->email;
}
"amount" => "$stripeamount",
"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
"description" => "Stripe payment: ".$description,
"capture" => $capture,
"metadata" => $metadata,
"source" => "$source",
"customer" => "$customer"
);
if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)
{
$paymentarray["application_fee"] = $fee;
}
if ($societe->email && $usethirdpartyemailforreceiptemail)
{
$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)) {}