Skip to content

Commit

Permalink
Merge pull request #9764 from ptibogxiv/patch-71
Browse files Browse the repository at this point in the history
FIX and dolibarize
  • Loading branch information
eldy committed Oct 16, 2018
2 parents 2c1e8d6 + dc0aaf4 commit a7c94ea
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions htdocs/stripe/class/stripe.class.php
Expand Up @@ -346,10 +346,10 @@ public function cardStripe($cu, CompanyPaymentMode $object, $stripeacc='', $stat
/**
* Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API
*
* @param int $amount Amount to pay
* @param int $stripeamount Amount to pay
* @param string $currency EUR, GPB...
* @param string $origin Object type to pay (order, invoice, contract...)
* @param int $item Object id to pay
* @param string $dol_type Object type to pay (order, invoice, contract...)
* @param int $dol_id 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()
Expand All @@ -358,7 +358,7 @@ public function cardStripe($cu, CompanyPaymentMode $object, $stripeacc='', $stat
* @param boolean $capture Set capture flag to true (take payment) or false (wait)
* @return Stripe
*/
public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0, $usethirdpartyemailforreceiptemail=0, $capture=true)
public function createPaymentStripe($stripeamount, $currency, $dol_type, $dol_id, $source, $customer, $account, $status=0, $usethirdpartyemailforreceiptemail=0, $capture=true)
{
global $conf;

Expand Down Expand Up @@ -387,29 +387,28 @@ public function createPaymentStripe($amount, $currency, $origin, $item, $source,
}

$arrayzerounitcurrency=array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
if (! in_array($currency, $arrayzerounitcurrency)) $stripeamount=$amount * 100;
else $stripeamount = $amount;
if (! in_array($currency, $arrayzerounitcurrency)) $stripeamount=$stripeamount * 100;

$societe = new Societe($this->db);
if ($key > 0) $societe->fetch($key);

$description = "";
$ref = "";
if ($origin == order) {
if ($dol_type == order) {
$order = new Commande($this->db);
$order->fetch($item);
$order->fetch($dol_id);
$ref = $order->ref;
$description = "ORD=" . $ref . ".CUS=" . $societe->id.".PM=stripe";
} elseif ($origin == invoice) {
} elseif ($dol_type == invoice) {
$invoice = new Facture($this->db);
$invoice->fetch($item);
$invoice->fetch($dol_id);
$ref = $invoice->ref;
$description = "INV=" . $ref . ".CUS=" . $societe->id.".PM=stripe";
}

$metadata = array(
"dol_id" => "" . $item . "",
"dol_type" => "" . $origin . "",
"dol_id" => "" . $dol_id . "",
"dol_type" => "" . $dol_type . "",
"dol_thirdparty_id" => "" . $societe->id . "",
'dol_thirdparty_name' => $societe->name,
'dol_version'=>DOL_VERSION,
Expand All @@ -427,7 +426,7 @@ public function createPaymentStripe($amount, $currency, $origin, $item, $source,
if (preg_match('/acct_/i', $source))
{
$charge = \Stripe\Charge::create(array(
"amount" => "$stripeamount",
"amount" => price2num($stripeamount, 'MU'),
"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,
Expand All @@ -437,7 +436,7 @@ public function createPaymentStripe($amount, $currency, $origin, $item, $source,
));
} else {
$paymentarray = array(
"amount" => "$stripeamount",
"amount" => price2num($stripeamount, 'MU'),
"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,
Expand All @@ -456,13 +455,13 @@ public function createPaymentStripe($amount, $currency, $origin, $item, $source,
}
} else {

$fee = round(($amount * ($conf->global->STRIPE_APPLICATION_FEE_PERCENT / 100) + $conf->global->STRIPE_APPLICATION_FEE) * 100);
$fee = round(($stripeamount * ($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" => "$stripeamount",
"amount" => price2num($stripeamount, 'MU'),
"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,
Expand Down

0 comments on commit a7c94ea

Please sign in to comment.