diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index e0928b91376..db2553ee167 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -346,10 +346,10 @@ class Stripe extends CommonObject /** * Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API * - * @param int $stripeamount Amount to pay + * @param int $amount Amount to pay * @param string $currency EUR, GPB... - * @param string $dol_type Object type to pay (order, invoice, contract...) - * @param int $dol_id Object id to pay + * @param string $origin Object type to pay (order, invoice, contract...) + * @param int $item Object id to pay * @param string $source src_xxxxx or card_xxxxx * @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() * @param string $account Stripe account ref 'acc_xxxxxxxxxxxxx' via getStripeAccount() @@ -358,7 +358,7 @@ class Stripe extends CommonObject * @param boolean $capture Set capture flag to true (take payment) or false (wait) * @return Stripe */ - public function createPaymentStripe($stripeamount, $currency, $dol_type, $dol_id, $source, $customer, $account, $status=0, $usethirdpartyemailforreceiptemail=0, $capture=true) + public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0, $usethirdpartyemailforreceiptemail=0, $capture=true) { global $conf; @@ -387,28 +387,29 @@ class Stripe extends CommonObject } $arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'); - if (! in_array($currency, $arrayzerounitcurrency)) $stripeamount=$stripeamount * 100; + if (! in_array($currency, $arrayzerounitcurrency)) $stripeamount=$amount * 100; + else $stripeamount = $amount; $societe = new Societe($this->db); if ($key > 0) $societe->fetch($key); $description = ""; $ref = ""; - if ($dol_type == order) { + if ($origin == order) { $order = new Commande($this->db); - $order->fetch($dol_id); + $order->fetch($item); $ref = $order->ref; $description = "ORD=" . $ref . ".CUS=" . $societe->id.".PM=stripe"; - } elseif ($dol_type == invoice) { + } elseif ($origin == invoice) { $invoice = new Facture($this->db); - $invoice->fetch($dol_id); + $invoice->fetch($item); $ref = $invoice->ref; $description = "INV=" . $ref . ".CUS=" . $societe->id.".PM=stripe"; } $metadata = array( - "dol_id" => "" . $dol_id . "", - "dol_type" => "" . $dol_type . "", + "dol_id" => "" . $item . "", + "dol_type" => "" . $origin . "", "dol_thirdparty_id" => "" . $societe->id . "", 'dol_thirdparty_name' => $societe->name, 'dol_version'=>DOL_VERSION, @@ -426,7 +427,7 @@ class Stripe extends CommonObject if (preg_match('/acct_/i', $source)) { $charge = \Stripe\Charge::create(array( - "amount" => price2num($stripeamount, 'MU'), + "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, @@ -436,7 +437,7 @@ class Stripe extends CommonObject )); } else { $paymentarray = array( - "amount" => price2num($stripeamount, 'MU'), + "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, @@ -455,13 +456,13 @@ class Stripe extends CommonObject } } else { - $fee = round(($stripeamount * ($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)) { $fee = round($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100); } $paymentarray = array( - "amount" => price2num($stripeamount, 'MU'), + "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,