Skip to content

Commit

Permalink
Debug stripe payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 15, 2018
1 parent 5a397ff commit 84e1aff
Showing 1 changed file with 50 additions and 42 deletions.
92 changes: 50 additions & 42 deletions htdocs/stripe/class/stripe.class.php
Expand Up @@ -203,7 +203,7 @@ public function cardStripe($cu, CompanyPaymentMode $object, $key='', $status=0,
{
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.= " FROM " . MAIN_DB_PREFIX . "societe_rib as sa";
Expand Down Expand Up @@ -292,13 +292,13 @@ public function cardStripe($cu, CompanyPaymentMode $object, $key='', $status=0,
/**
* Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API
*
* @param int $amount Amount to pay
* @param string $currency EUR, GPB...
* @param string $origin order, invoice, contract...
* @param int $item if of element 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()
* @param int $amount 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 $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()
* @param int $status Status (0=test, 1=live)
* @return Stripe
*/
Expand All @@ -309,7 +309,7 @@ public function createPaymentStripe($amount, $currency, $origin, $item, $source,
if (empty($status)) $service = 'StripeTest';
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.= " WHERE sa.key_account = '" . $this->db->escape($customer) . "'";
//$sql.= " AND sa.entity IN (".getEntity('societe').")";
Expand All @@ -328,9 +328,12 @@ public function createPaymentStripe($amount, $currency, $origin, $item, $source,
$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->fetch($fksoc);
if ($key > 0) $societe->fetch($key);

if ($origin == order) {
$order = new Commande($this->db);
Expand All @@ -345,24 +348,28 @@ public function createPaymentStripe($amount, $currency, $origin, $item, $source,
}

$metadata = array(
"source" => "" . $origin . "",
"idsource" => "" . $item . "",
"idcustomer" => "" . $societe->id . ""
"dol_id" => "" . $item . "",
"dol_type" => "" . $origin . "",
"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);
try {
if ($stripeamount >= 100) {
if ($entite == '1' or empty($conf->stripeconnect->enabled)) {
if (preg_match('/acct_/i', $source)) {
$charge = \Stripe\Charge::create(array(
if (empty($conf->stripeconnect->enabled))
{
if (preg_match('/acct_/i', $source))
{
$charge = \Stripe\Charge::create(array(
"amount" => "$stripeamount",
"currency" => "$currency",
// "statement_descriptor" => " ",
"metadata" => $metadata,
"source" => "$source"
));
} else {
$charge = \Stripe\Charge::create(array(
));
} else {
$charge = \Stripe\Charge::create(array(
"amount" => "$stripeamount",
"currency" => "$currency",
// "statement_descriptor" => " ",
Expand All @@ -371,31 +378,32 @@ public function createPaymentStripe($amount, $currency, $origin, $item, $source,
"receipt_email" => $societe->email,
"source" => "$source",
"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(
"idempotency_key" => "$ref",
"stripe_account" => "$account"
"idempotency_key" => "$ref"
));
}
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->id = $charge->id;
Expand Down

0 comments on commit 84e1aff

Please sign in to comment.