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";
@ -292,13 +292,13 @@ class Stripe extends CommonObject
/** /**
* Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API * Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API
* *
* @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()
* @param int $status Status (0=test, 1=live) * @param int $status Status (0=test, 1=live)
* @return Stripe * @return Stripe
*/ */
@ -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,24 +348,28 @@ 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",
// "statement_descriptor" => " ", // "statement_descriptor" => " ",
"metadata" => $metadata, "metadata" => $metadata,
"source" => "$source" "source" => "$source"
)); ));
} else { } else {
$charge = \Stripe\Charge::create(array( $charge = \Stripe\Charge::create(array(
"amount" => "$stripeamount", "amount" => "$stripeamount",
"currency" => "$currency", "currency" => "$currency",
// "statement_descriptor" => " ", // "statement_descriptor" => " ",
@ -371,31 +378,32 @@ class Stripe extends CommonObject
"receipt_email" => $societe->email, "receipt_email" => $societe->email,
"source" => "$source", "source" => "$source",
"customer" => "$customer" "customer" => "$customer"
), array(
"idempotency_key" => "$ref"
));
}
} else {
$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);
}
$charge = \Stripe\Charge::create(array(
"amount" => "$stripeamount",
"currency" => "$currency",
// "statement_descriptor" => " ",
"description" => "$description",
"metadata" => $metadata,
"source" => "$source",
"customer" => "$customer",
"application_fee" => "$fee"
), array( ), array(
"idempotency_key" => "$ref", "idempotency_key" => "$ref"
"stripe_account" => "$account"
)); ));
} }
if (isset($charge->id)) {} } else {
$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);
}
$charge = \Stripe\Charge::create(array(
"amount" => "$stripeamount",
"currency" => "$currency",
// "statement_descriptor" => " ",
"description" => "$description",
"metadata" => $metadata,
"source" => "$source",
"customer" => "$customer",
"application_fee" => "$fee"
), array(
"idempotency_key" => "$ref",
"stripe_account" => "$account"
));
} }
if (isset($charge->id)) {}
$return->statut = 'success'; $return->statut = 'success';
$return->id = $charge->id; $return->id = $charge->id;