diff --git a/htdocs/admin/oauth.php b/htdocs/admin/oauth.php index 3e6f165161c..99ade75fdfe 100644 --- a/htdocs/admin/oauth.php +++ b/htdocs/admin/oauth.php @@ -95,6 +95,7 @@ print '
| '.$langs->trans($key[0]).' | '; print ''; @@ -222,7 +235,6 @@ if ($mode == 'setup' && $user->admin) print ''; print ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ';
//var_dump($key);
@@ -237,19 +249,21 @@ if ($mode == 'setup' && $user->admin)
if (is_object($tokenobj))
{
//test on $storage->hasAccessToken($OAUTH_SERVICENAME) ?
- print ''.$langs->trans('DeleteAccess').' '; + print ''.$langs->trans('DeleteAccess').' '; } // Request remote token - print ''.$langs->trans('RequestAccess').' '; + if ($urltorenew) + { + print ''.$langs->trans('RequestAccess').' '; + } // Check remote access if ($urltocheckperms) { - print $langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).': '.$urltocheckperms.''; + print ' '.$langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME).': '.$urltocheckperms.''; } print ' | ';
print '|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '; //var_dump($key); @@ -272,7 +286,6 @@ if ($mode == 'setup' && $user->admin) if (is_object($tokenobj)) { // Token refresh - $var = ! $var; print ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '; //var_dump($key); @@ -283,7 +296,6 @@ if ($mode == 'setup' && $user->admin) print ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '; //var_dump($key); @@ -294,7 +306,6 @@ if ($mode == 'setup' && $user->admin) print ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ';
//var_dump($key);
@@ -354,7 +365,6 @@ if ($mode == 'userconf' && $user->admin)
print $langs->trans('PrintUserConfDesc'.$driver)." \n"; print '
';
- print $langs->trans("ONLINE_PAYMENT_WAREHOUSE").' | ';
- print $formproduct->selectWarehouses($conf->global->ONLINE_PAYMENT_WAREHOUSE,'ONLINE_PAYMENT_WAREHOUSE','',1,$disabled);
- print ' | ';
+print $langs->trans("BankAccount").' | ';
+print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
+print ' | ';
- print $langs->trans("BankAccountForBankTransfer").' | ';
- print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS, 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
- print ' | ';
+ print $langs->trans("BankAccountForBankTransfer").' | ';
+ print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS, 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
+ print ' | ';
print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").' | ';
print '';
print ' '.$langs->trans("Example").': myemail@myserver.com';
-print ' | ';
diff --git a/htdocs/stripe/charge.php b/htdocs/stripe/charge.php
index aaa0b0475f8..d13235c4f01 100644
--- a/htdocs/stripe/charge.php
+++ b/htdocs/stripe/charge.php
@@ -46,20 +46,36 @@ $offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
+
+
/*
-* View
-*/
+ * View
+ */
+
llxHeader('', $langs->trans("StripeChargeList"));
+
$form = new Form($db);
$societestatic = new societe($db);
$acc = new Account($db);
$stripe=new Stripe($db);
if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')))
{
+ $service = 'StripeTest';
dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning');
}
-if (!$rowid){
+else
+{
+ $service = 'StripeLive';
+}
+$stripeaccount = $stripe->GetStripeAccount($service);
+if (empty($stripeaccount))
+{
+ print $langs->trans('ErrorStripeAccountNotDefined');
+}
+
+if (!$rowid && $stripeaccount)
+{
print ' | ".$charge->id." | \n";
// Employee
print "".$societestatic->getNomUrl(1)." | \n";
- // Origine
+ // Origine
print "";
-if ($charge->metadata->source=="order"){
-$object = new Commande($db);
-$object->fetch($charge->metadata->idsource);
- print "".img_picto('', 'object_order')." ".$object->ref."";
-} elseif ($charge->metadata->source=="invoice"){
-$object = new Facture($db);
-$object->fetch($charge->metadata->idsource);
- print "".img_picto('', 'object_invoice')." ".$object->ref."";
-}
- print " | \n";
- // Date payment
- print ''.dol_print_date($charge->created,'%d/%m/%Y %H:%M')." | \n";
- // Label payment
- print "";
-if ($charge->refunded=='1'){
- print $langs->trans("refunded");
-} elseif ($charge->paid=='1'){
- print $langs->trans("".$charge->status."");
-} else {
-$label="Message: ".$charge->failure_message." | \n";
- // Type
- print '"; -$label.="Réseau: ".$charge->outcome->network_status." "; -$label.="Statut: ".$langs->trans("".$charge->outcome->seller_message.""); - print $form->textwithpicto($langs->trans("".$charge->status.""),$label,1); -} - print " ';
-if ($charge->source->object=='card'){
- print $langs->trans("card");
-}
-elseif ($charge->source->type=='card'){
- print $langs->trans("card");
-} elseif ($charge->source->type=='three_d_secure'){
- print $langs->trans("card3DS");
-}
- print ' | ';
- // Amount
- print "".price(($charge->amount-$charge->amount_refunded)/100)." | ";
- print "'.dol_print_date($charge->created,'%d/%m/%Y %H:%M')." | \n";
+ // Label payment
+ print "";
+ if ($charge->refunded=='1'){
+ print $langs->trans("refunded");
+ } elseif ($charge->paid=='1'){
+ print $langs->trans("".$charge->status."");
+ } else {
+ $label="Message: ".$charge->failure_message." | \n";
+ // Type
+ print '"; + $label.="Réseau: ".$charge->outcome->network_status." "; + $label.="Statut: ".$langs->trans("".$charge->outcome->seller_message.""); + print $form->textwithpicto($langs->trans("".$charge->status.""),$label,1); + } + print " ';
+ if ($charge->source->object=='card')
+ {
+ print $langs->trans("card");
+ }
+ elseif ($charge->source->type=='card'){
+ print $langs->trans("card");
+ } elseif ($charge->source->type=='three_d_secure'){
+ print $langs->trans("card3DS");
+ }
+ print ' | ';
+ // Amount
+ print "".price(($charge->amount-$charge->amount_refunded)/100)." | ";
+ print "\n";
+ }
} else {
-}
+}
llxFooter();
$db->close();
diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php
index a1eefd6ecb7..4ea45b7a4b3 100644
--- a/htdocs/stripe/class/stripe.class.php
+++ b/htdocs/stripe/class/stripe.class.php
@@ -21,23 +21,24 @@ require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/stripe/config.php';
-/**
- * \class Rewards
- * \brief Class for Rewards
+
+
+/**
+ * Stripe class
*/
class Stripe extends CommonObject
{
public $rowid;
- public $fk_soc;
- public $fk_key;
- public $id;
- public $mode;
- public $entity;
- public $statut;
- public $type;
- public $code;
- public $message;
-
+ public $fk_soc;
+ public $fk_key;
+ public $id;
+ public $mode;
+ public $entity;
+ public $statut;
+ public $type;
+ public $code;
+ public $message;
+
/**
* Constructor
*
@@ -48,273 +49,306 @@ class Stripe extends CommonObject
$this->db = $db;
}
-
-public function GetStripeAccount($id) // TODO: move /transforme optimize function/data
+
+ /**
+ * GetStripeAccount
+ *
+ * @param string $mode 'StripeTest' or 'StripeLive'
+ * @return int ???
+ */
+ public function GetStripeAccount($mode='StripeTest')
{
global $conf;
- $sql = "SELECT key_account";
- $sql.= " FROM ".MAIN_DB_PREFIX."stripe_entity";
- $sql.= " WHERE entity = ".$id."";
+ $sql = "SELECT tokenstring";
+ $sql.= " FROM ".MAIN_DB_PREFIX."oauth_token";
+ $sql.= " WHERE entity = ".$conf->entity;
+ $sql.= " AND service = '".$mode."'";
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result)
+ if ($result)
{
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result);
- $key=$obj->key_account;
- }
- else {$key=0;}
- }
- else {$key=0;}
-
-return $key;
- }
-
-public function GetStripeCustomerAccount($id)
+ $tokenstring=$obj->tokenstring;
+
+ $tmparray = dol_json_decode($tokenstring);
+ $key = $tmparray->stripe_user_id;
+ }
+ else {
+ $tokenstring='';
+ }
+ }
+ else {
+ dol_print_error($this->db);
+ }
+
+ return $key;
+ }
+
+ /**
+ * GetStripeCustomerAccount
+ *
+ * @param int $id ???
+ * @return int ???
+ */
+ public function GetStripeCustomerAccount($id)
{
global $conf;
$sql = "SELECT s.key_account as key_account, s.entity, e.fk_object";
- $sql.= " FROM ".MAIN_DB_PREFIX."stripe_entity as s";
- $sql.= " JOIN ".MAIN_DB_PREFIX."entity_extrafields as e ON s.entity=e.fk_object";
- $sql.= " WHERE e.fk_soc=".$id." ";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "stripe_entity as s";
+ $sql .= " JOIN " . MAIN_DB_PREFIX . "entity_extrafields as e ON s.entity=e.fk_object";
+ $sql .= " WHERE e.fk_soc=" . $id . " ";
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result)
- {
- if ($this->db->num_rows($result))
- {
+ if ($result) {
+ if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
- $key=$obj->key_account;
- }
- else {$key=NULL;}
- }
- else {$key=NULL;}
-
-return $key;
- }
-
-public function CustomerStripe($id,$key)
+ $key = $obj->key_account;
+ } else {
+ $key = NULL;
+ }
+ } else {
+ $key = NULL;
+ }
+
+ return $key;
+ }
+
+
+ /**
+ * CustomerStripe
+ *
+ * @param int $id ???
+ * @param string $key ???
+ * @return \Stripe\StripeObject|\Stripe\ApiResource
+ */
+ public function CustomerStripe($id,$key)
{
-global $conf;
-if (empty($conf->global->STRIPECONNECT_LIVE))
-{
-$mode=0;
-}
-else
-{
-if (empty($conf->global->STRIPE_LIVE))
-{
-$mode=0;
-}
-else
-{
-$mode=$conf->global->STRIPE_LIVE;
-}
-}
+ global $conf;
+ if (empty($conf->global->STRIPECONNECT_LIVE)) {
+ $mode = 0;
+ } else {
+ if (empty($conf->global->STRIPE_LIVE)) {
+ $mode = 0;
+ } else {
+ $mode = $conf->global->STRIPE_LIVE;
+ }
+ }
$sql = "SELECT rowid,fk_soc,fk_key,mode,entity";
- $sql.= " FROM ".MAIN_DB_PREFIX."societe_stripe";
- $sql.= " WHERE fk_soc = ".$id." ";
- $sql.= " AND mode=".$mode." AND entity IN (" . getEntity('stripe') . ")";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "societe_stripe";
+ $sql .= " WHERE fk_soc = " . $id . " ";
+ $sql .= " AND mode=" . $mode . " AND entity IN (" . getEntity('stripe') . ")";
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
- $soc = new Societe($this->db);
- $soc->fetch($id);
- $num=$this->db->num_rows($resql);
+ $soc = new Societe($this->db);
+ $soc->fetch($id);
+ $num = $this->db->num_rows($resql);
if ($num) {
- $obj = $this->db->fetch_object($resql);
- $tiers = $obj->fk_key;
- if ($conf->entity==1){
- $customer = \Stripe\Customer::retrieve("$tiers");
- }else{
- $customer = \Stripe\Customer::retrieve("$tiers",array("stripe_account" => $key));
- }}
- else {
- if ($conf->entity==1){
- $customer = \Stripe\Customer::create(array(
- "email" => $soc->email,
- "description" => $soc->name
- ));
- }else{
- $customer = \Stripe\Customer::create(array(
- "email" => $soc->email,
- "description" => $soc->name
- ), array("stripe_account" => $key));
- }
- $customer_id = "".$customer->id."";
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_stripe (fk_soc,fk_key,mode,entity)";
- $sql .= " VALUES ($id,'$customer_id',".$mode.",".$conf->entity.")";
- dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
- $resql = $this->db->query($sql);
- }}
-return $customer;
+ $obj = $this->db->fetch_object($resql);
+ $tiers = $obj->fk_key;
+ if ($conf->entity == 1) {
+ $customer = \Stripe\Customer::retrieve("$tiers");
+ } else {
+ $customer = \Stripe\Customer::retrieve("$tiers", array(
+ "stripe_account" => $key
+ ));
+ }
+ } else {
+ if ($conf->entity == 1) {
+ $customer = \Stripe\Customer::create(array(
+ "email" => $soc->email,
+ "description" => $soc->name
+ ));
+ } else {
+ $customer = \Stripe\Customer::create(array(
+ "email" => $soc->email,
+ "description" => $soc->name
+ ), array(
+ "stripe_account" => $key
+ ));
+ }
+ $customer_id = "" . $customer->id . "";
+ $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_stripe (fk_soc,fk_key,mode,entity)";
+ $sql .= " VALUES ($id,'$customer_id'," . $mode . "," . $conf->entity . ")";
+ dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ }
+ }
+ return $customer;
}
-
-public function CreatePaymentStripe($amount,$currency,$origin,$item,$source,$customer,$account)
-{
-global $conf;
-if (empty($conf->global->STRIPECONNECT_LIVE))
-{
-$mode=0;
-}
-else
-{
-if (empty($conf->global->STRIPE_LIVE))
-{
-$mode=0;
-}
-else
-{
-$mode=$conf->global->STRIPE_LIVE;
-}
-}
+
+ /**
+ * CreatePaymentStripe
+ *
+ * @param unknown $amount ???
+ * @param unknown $currency ???
+ * @param unknown $origin ???
+ * @param unknown $item ???
+ * @param unknown $source ???
+ * @param unknown $customer ???
+ * @param unknown $account ???
+ * @return Stripe
+ */
+ public function CreatePaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account)
+ {
+ global $conf;
+ if (empty($conf->global->STRIPECONNECT_LIVE)) {
+ $mode = 0;
+ } else {
+ if (empty($conf->global->STRIPE_LIVE)) {
+ $mode = 0;
+ } else {
+ $mode = $conf->global->STRIPE_LIVE;
+ }
+ }
$sql = "SELECT fk_soc,fk_key,mode,entity";
- $sql.= " FROM ".MAIN_DB_PREFIX."societe_stripe";
- $sql.= " WHERE fk_key = '$customer' ";
- $sql.= " AND mode=".$mode." ";
+ $sql .= " FROM " . MAIN_DB_PREFIX . "societe_stripe";
+ $sql .= " WHERE fk_key = '$customer' ";
+ $sql .= " AND mode=" . $mode . " ";
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result)
- {
- if ($this->db->num_rows($result))
- {
+ if ($result) {
+ if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
- $entite=$obj->entity;
- $fksoc=$obj->fk_soc;
- }
- }
-$stripeamount=round($amount*100);
-$societe = new Societe($this->db);
-$societe->fetch($fksoc);
+ $entite = $obj->entity;
+ $fksoc = $obj->fk_soc;
+ }
+ }
+ $stripeamount = round($amount * 100);
+ $societe = new Societe($this->db);
+ $societe->fetch($fksoc);
-if ($origin==order){
-$order=new Commande($this->db);
-$order->fetch($item);
-$ref=$order->ref;
-$description="ORD=".$ref.".CUS=".$societe->code_client;
-}
-elseif ($origin==invoice) {
-$invoice=new Facture($this->db);
-$invoice->fetch($item);
-$ref=$invoice->ref;
-$description="INV=".$ref.".CUS=".$societe->code_client;
-}
+ if ($origin == order) {
+ $order = new Commande($this->db);
+ $order->fetch($item);
+ $ref = $order->ref;
+ $description = "ORD=" . $ref . ".CUS=" . $societe->code_client;
+ } elseif ($origin == invoice) {
+ $invoice = new Facture($this->db);
+ $invoice->fetch($item);
+ $ref = $invoice->ref;
+ $description = "INV=" . $ref . ".CUS=" . $societe->code_client;
+ }
-$metadata = array(
- "source" => "".$origin."",
- "idsource" => "".$item."",
- "idcustomer" => "".$societe->id.""
- );
-$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(
- "amount" => "$stripeamount",
- "currency" => "$currency",
-// "statement_descriptor" => " ",
- "metadata" => $metadata,
- "source" => "$source"
-)
-);
-} else {
-$charge = \Stripe\Charge::create(array(
- "amount" => "$stripeamount",
- "currency" => "$currency",
-// "statement_descriptor" => " ",
- "description" => "$description",
- "metadata" => $metadata,
- "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"));
-}
-if (isset($charge->id)){
+ $metadata = array(
+ "source" => "" . $origin . "",
+ "idsource" => "" . $item . "",
+ "idcustomer" => "" . $societe->id . ""
+ );
+ $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(
+ "amount" => "$stripeamount",
+ "currency" => "$currency",
+ // "statement_descriptor" => " ",
+ "metadata" => $metadata,
+ "source" => "$source"
+ ));
+ } else {
+ $charge = \Stripe\Charge::create(array(
+ "amount" => "$stripeamount",
+ "currency" => "$currency",
+ // "statement_descriptor" => " ",
+ "description" => "$description",
+ "metadata" => $metadata,
+ "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"
+ ));
+ }
+ if (isset($charge->id)) {}
+ }
+
+ $return->statut = 'success';
+ $return->id = $charge->id;
+ if ($charge->source->type == 'card') {
+ $return->message = $charge->source->card->brand . " ****" . $charge->source->card->last4;
+ } elseif ($charge->source->type == 'three_d_secure') {
+ $stripe = new Stripe($this->db);
+ $src = \Stripe\Source::retrieve("" . $charge->source->three_d_secure->card . "", array(
+ "stripe_account" => $stripe->GetStripeAccount($conf->entity)
+ ));
+ $return->message = $src->card->brand . " ****" . $src->card->last4;
+ } else {
+ $return->message = $charge->id;
+ }
+ } catch (\Stripe\Error\Card $e) {
+ // Since it's a decline, \Stripe\Error\Card will be caught
+ $body = $e->getJsonBody();
+ $err = $body['error'];
+
+ $return->statut = 'error';
+ $return->id = $err['charge'];
+ $return->type = $err['type'];
+ $return->code = $err['code'];
+ $return->message = $err['message'];
+ $body = "Une erreur de paiement est survenue. Voici le code d'erreur: " . $return->id . " " . $return->message . " "; + $subject = '[NOTIFICATION] Erreur de paiement'; + $headers = 'From: "ptibogxiv.net" <' . $conf->global->MAIN_INFO_SOCIETE_MAIL . '>'; + mail('' . $conf->global->MAIN_INFO_SOCIETE_MAIL . '', $subject, $body, $headers); + $error ++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (\Stripe\Error\RateLimit $e) { + // Too many requests made to the API too quickly + $error ++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (\Stripe\Error\InvalidRequest $e) { + // Invalid parameters were supplied to Stripe's API + $error ++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (\Stripe\Error\Authentication $e) { + // Authentication with Stripe's API failed + // (maybe you changed API keys recently) + $error ++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (\Stripe\Error\ApiConnection $e) { + // Network communication with Stripe failed + $error ++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (\Stripe\Error\Base $e) { + // Display a very generic error to the user, and maybe send + // yourself an email + $error ++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } catch (Exception $e) { + // Something else happened, completely unrelated to Stripe + $error ++; + dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); + } + return $return; + } } -} - -$return->statut = 'success'; -$return->id = $charge->id; -if ($charge->source->type=='card'){ -$return->message = $charge->source->card->brand." ****".$charge->source->card->last4; -}elseif ($charge->source->type=='three_d_secure'){ -$stripe=new Stripe($this->db); -$src = \Stripe\Source::retrieve("".$charge->source->three_d_secure->card."",array("stripe_account" => $stripe->GetStripeAccount($conf->entity))); -$return->message = $src->card->brand." ****".$src->card->last4; -}else { -$return->message = $charge->id; -} - -} catch(\Stripe\Error\Card $e) { - // Since it's a decline, \Stripe\Error\Card will be caught - $body = $e->getJsonBody(); - $err = $body['error']; - -$return->statut = 'error'; -$return->id = $err['charge']; -$return->type = $err['type']; -$return->code = $err['code']; -$return->message = $err['message']; -$body = "Une erreur de paiement est survenue. Voici le code d'erreur: ".$return->id." ".$return->message." "; -$subject = '[NOTIFICATION] Erreur de paiement'; -$headers = 'From: "ptibogxiv.net" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; -mail(''.$conf->global->MAIN_INFO_SOCIETE_MAIL.'', $subject, $body, $headers); - $error++; - dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); - } catch (\Stripe\Error\RateLimit $e) { - // Too many requests made to the API too quickly - $error++; - dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); - } catch (\Stripe\Error\InvalidRequest $e) { - // Invalid parameters were supplied to Stripe's API - $error++; - dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); - } catch (\Stripe\Error\Authentication $e) { - // Authentication with Stripe's API failed - // (maybe you changed API keys recently) - $error++; - dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); - } catch (\Stripe\Error\ApiConnection $e) { - // Network communication with Stripe failed - $error++; - dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); - } catch (\Stripe\Error\Base $e) { - // Display a very generic error to the user, and maybe send - // yourself an email - $error++; - dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); - } catch (Exception $e) { - // Something else happened, completely unrelated to Stripe - $error++; - dol_syslog($e->getMessage(), LOG_WARNING, 0, '_stripe'); - } - return $return; -} - -} diff --git a/htdocs/stripe/transaction.php b/htdocs/stripe/transaction.php index 2a37b5a55a5..143c34f7530 100644 --- a/htdocs/stripe/transaction.php +++ b/htdocs/stripe/transaction.php @@ -46,94 +46,109 @@ $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -/* -* View -*/ + /* + * View + */ llxHeader('', $langs->trans("StripeTransactionList")); $form = new Form($db); $societestatic = new societe($db); $acc = new Account($db); -$stripe=new Stripe($db); -if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha'))) +$stripe = new Stripe($db); + +if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox', 'alpha'))) { - dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode','Stripe'),'','warning'); + $service = 'StripeTest'; + dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning'); +} +else +{ + $servie = 'StripeLive'; } -if (!$rowid){ - print ''; +} else {} llxFooter(); $db->close(); |