Debug payment with stripe Intent

This commit is contained in:
Laurent Destailleur 2019-05-16 23:11:49 +02:00
parent fa5c5a3336
commit 52c1f42734
2 changed files with 33 additions and 8 deletions

View File

@ -396,8 +396,9 @@ if ($action == 'dopayment')
}
// Called when choosing Stripe mode, after clicking the 'dopayment' with the Charge API architecture.
// When using the PaymentItent architecture, we dont need this, the Stripe customer is created when creating PaymentItent when showing payment page.
// Called when choosing Stripe mode.
// When using the Charge API architecture, this code is called after clicking the 'dopayment' with the Charge API architecture.
// When using the PaymentIntent API architecture, the Stripe customer is already created when creating PaymentItent when showing payment page and the payment is already ok.
if ($action == 'charge' && ! empty($conf->stripe->enabled))
{
$amountstripe = $amount;
@ -426,6 +427,7 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
$error = 0;
$errormessage = '';
// When using the Charge API architecture
if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION))
{
try {
@ -611,6 +613,7 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
}
}
// When using the PaymentIntent API architecture
if (! empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION))
{
$service = 'StripeTest';
@ -656,6 +659,12 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
setEventMessages($e->getMessage(), null, 'errors');
$action='';
}
else
{
// TODO We can alse record the payment mode into llx_societe_rib with stripe $paymentintent->payment_method
// Note that with other Stripe architecture (using Charge API), the payment mode was not recorded, so it is not mandatory to do it here.
//dol_syslog("Create payment_method for ".$paymentintent->payment_method, LOG_DEBUG, 0, '_stripe');
}
}
@ -2008,7 +2017,7 @@ if (preg_match('/^dopayment/', $action))
billing_details: {
name: cardholderName.value
<?php if (GETPOST('email', 'alpha')) { ?>, email: '<?php echo GETPOST('email', 'alpha'); ?>'<?php } ?>
<?php if (is_object($object) && is_object($object->thirdparty)) { ?>, phone: '<?php echo $object->thirdparty->phone; ?>'<?php } ?>
<?php if (is_object($object) && is_object($object->thirdparty) && is_object($object->thirdparty->phone)) { ?>, phone: '<?php echo $object->thirdparty->phone; ?>'<?php } ?>
<?php if (is_object($object) && is_object($object->thirdparty)) { ?>, address: {
city: '<?php echo $object->thirdparty->town; ?>',
country: '<?php echo $object->thirdparty->country_code; ?>',

View File

@ -239,6 +239,10 @@ class Stripe extends CommonObject
/**
* Get the Stripe payment intent. Create it with confirm=false
* Warning. If a payment was tried and failed, a payment intent was created.
* But if we change someting on object to pay (amount or other), reusing same payment intent is not allowed.
* Recommanded solution is to recreate a new payment intent each time we need one (old one will be automatically closed after a delay),
* that's why i comment the part of code to retreive a payment intent with object id (never mind if we cumulate payment intent with old that will not be used)
*
* @param double $amount Amount
* @param string $currency_code Currency code
@ -279,7 +283,12 @@ class Stripe extends CommonObject
if (is_object($object))
{
$sql = "SELECT pi.ext_payment_id, pi.entity, pi.fk_facture, pi.sourcetype, pi.ext_payment_site";
// Warning. If a payment was tried and failed, a payment intent was created.
// But if we change someting on object to pay (amount or other), reusing same payment intent is not allowed.
// Recommanded solution is to recreate a new payment intent each time we need one (old one will be automatically closed after a delay),
// that's why i comment the part of code to retreive a payment intent with object id (never mind if we cumulate payment intent with old that will not be used)
/*
$sql = "SELECT pi.ext_payment_id, pi.entity, pi.fk_facture, pi.sourcetype, pi.ext_payment_site";
$sql.= " FROM " . MAIN_DB_PREFIX . "prelevement_facture_demande as pi";
$sql.= " WHERE pi.fk_facture = " . $object->id;
$sql.= " AND pi.sourcetype = '" . $object->element . "'";
@ -314,7 +323,7 @@ class Stripe extends CommonObject
$this->error = $e->getMessage();
}
}
}
}*/
}
if (empty($paymentintent))
@ -369,8 +378,8 @@ class Stripe extends CommonObject
if (is_object($object))
{
$now=dol_now();
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_facture_demande (fk_soc, date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site)";
$sql .= " VALUES ('".$object->socid."','".$this->db->idate($now)."', '0', '".$this->db->escape($paymentintent->id)."', ".$object->id.", '".$this->db->escape($object->element)."', " . $conf->entity . ", '" . $service . "')";
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_facture_demande (date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site)";
$sql .= " VALUES ('".$this->db->idate($now)."', '0', '".$this->db->escape($paymentintent->id)."', ".$object->id.", '".$this->db->escape($object->element)."', " . $conf->entity . ", '" . $service . "')";
$resql = $this->db->query($sql);
if (! $resql)
{
@ -398,7 +407,14 @@ class Stripe extends CommonObject
dol_syslog("getPaymentIntent return error=".$error);
return $paymentintent;
if (! $error)
{
return $paymentintent;
}
else
{
return null;
}
}
/**