Debug stripe payment method

This commit is contained in:
Laurent Destailleur 2018-03-16 00:30:03 +01:00
parent 5a397fff72
commit 84e1affd5b

View File

@ -203,7 +203,7 @@ class Stripe extends CommonObject
{ {
global $conf, $user; global $conf, $user;
$customer = null; $card = null;
$sql = "SELECT sa.stripe_card_ref, sa.proprio, sa.exp_date_month, sa.exp_date_year, sa.number, sa.cvn"; // stripe_card_ref is card_.... $sql = "SELECT sa.stripe_card_ref, sa.proprio, sa.exp_date_month, sa.exp_date_year, sa.number, sa.cvn"; // stripe_card_ref is card_....
$sql.= " FROM " . MAIN_DB_PREFIX . "societe_rib as sa"; $sql.= " FROM " . MAIN_DB_PREFIX . "societe_rib as sa";
@ -294,8 +294,8 @@ class Stripe extends CommonObject
* *
* @param int $amount Amount to pay * @param int $amount Amount to pay
* @param string $currency EUR, GPB... * @param string $currency EUR, GPB...
* @param string $origin order, invoice, contract... * @param string $origin Object type to pay (order, invoice, contract...)
* @param int $item if of element to pay * @param int $item Object id to pay
* @param string $source src_xxxxx or card_xxxxx * @param string $source src_xxxxx or card_xxxxx
* @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() * @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe()
* @param string $account Stripe account ref 'acc_xxxxxxxxxxxxx' via getStripeAccount() * @param string $account Stripe account ref 'acc_xxxxxxxxxxxxx' via getStripeAccount()
@ -309,7 +309,7 @@ class Stripe extends CommonObject
if (empty($status)) $service = 'StripeTest'; if (empty($status)) $service = 'StripeTest';
else $service = 'StripeLive'; else $service = 'StripeLive';
$sql = "SELECT sa.key_account as key_account, sa.entity"; $sql = "SELECT sa.key_account as key_account, sa.fk_soc, sa.entity";
$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
$sql.= " WHERE sa.key_account = '" . $this->db->escape($customer) . "'"; $sql.= " WHERE sa.key_account = '" . $this->db->escape($customer) . "'";
//$sql.= " AND sa.entity IN (".getEntity('societe').")"; //$sql.= " AND sa.entity IN (".getEntity('societe').")";
@ -328,9 +328,12 @@ class Stripe extends CommonObject
$key = NULL; $key = NULL;
} }
$stripeamount = round($amount * 100); $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;
$societe = new Societe($this->db); $societe = new Societe($this->db);
$societe->fetch($fksoc); if ($key > 0) $societe->fetch($key);
if ($origin == order) { if ($origin == order) {
$order = new Commande($this->db); $order = new Commande($this->db);
@ -345,15 +348,19 @@ class Stripe extends CommonObject
} }
$metadata = array( $metadata = array(
"source" => "" . $origin . "", "dol_id" => "" . $item . "",
"idsource" => "" . $item . "", "dol_type" => "" . $origin . "",
"idcustomer" => "" . $societe->id . "" "dol_thirdparty_id" => "" . $societe->id . "",
'dol_version'=>DOL_VERSION,
'dol_entity'=>$conf->entity,
'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])
); );
$return = new Stripe($this->db); $return = new Stripe($this->db);
try { try {
if ($stripeamount >= 100) { if (empty($conf->stripeconnect->enabled))
if ($entite == '1' or empty($conf->stripeconnect->enabled)) { {
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",
@ -376,10 +383,12 @@ class Stripe extends CommonObject
)); ));
} }
} else { } else {
$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);
} }
$charge = \Stripe\Charge::create(array( $charge = \Stripe\Charge::create(array(
"amount" => "$stripeamount", "amount" => "$stripeamount",
"currency" => "$currency", "currency" => "$currency",
@ -395,7 +404,6 @@ class Stripe extends CommonObject
)); ));
} }
if (isset($charge->id)) {} if (isset($charge->id)) {}
}
$return->statut = 'success'; $return->statut = 'success';
$return->id = $charge->id; $return->id = $charge->id;