Fix action after payment on member registration
This commit is contained in:
parent
dc9ac9d298
commit
c112c807ac
@ -1660,19 +1660,19 @@ if ($action != 'dopayment')
|
||||
$reshook = $hookmanager->executeHooks('doCheckStatus', $parameters, $object, $action);
|
||||
if ($source == 'order' && $object->billed)
|
||||
{
|
||||
print '<br><br><span class="amountpaymentcomplete">'.$langs->trans("OrderBilled").'</span>';
|
||||
print '<br><br><span class="amountpaymentcomplete size15x">'.$langs->trans("OrderBilled").'</span>';
|
||||
} elseif ($source == 'invoice' && $object->paye)
|
||||
{
|
||||
print '<br><br><span class="amountpaymentcomplete">'.$langs->trans("InvoicePaid").'</span>';
|
||||
print '<br><br><span class="amountpaymentcomplete size15x">'.$langs->trans("InvoicePaid").'</span>';
|
||||
} elseif ($source == 'donation' && $object->paid)
|
||||
{
|
||||
print '<br><br><span class="amountpaymentcomplete">'.$langs->trans("DonationPaid").'</span>';
|
||||
print '<br><br><span class="amountpaymentcomplete size15x">'.$langs->trans("DonationPaid").'</span>';
|
||||
} else {
|
||||
// Membership can be paid and we still allow to make renewal
|
||||
if ($source == 'membersubscription' && $object->datefin > dol_now())
|
||||
{
|
||||
$langs->load("members");
|
||||
print '<br><span class="amountpaymentcomplete">'.$langs->trans("MembershipPaid", dol_print_date($object->datefin, 'day')).'</span><br>';
|
||||
print '<br><span class="amountpaymentcomplete size15x">'.$langs->trans("MembershipPaid", dol_print_date($object->datefin, 'day')).'</span><br>';
|
||||
print '<div class="opacitymedium margintoponly">'.$langs->trans("PaymentWillBeRecordedForNextPeriod").'</div>';
|
||||
}
|
||||
|
||||
|
||||
@ -471,8 +471,10 @@ if ($ispaymentok)
|
||||
$thirdparty = new Societe($db);
|
||||
$thirdparty->fetch($thirdparty_id);
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; // This also set $stripearrayofkeysbyenv
|
||||
$stripe = new Stripe($db);
|
||||
//$stripeacc = $stripe->getStripeAccount($service); Already defined previously
|
||||
|
||||
$customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
|
||||
|
||||
if (!$customer && $TRANSACTIONID) // Not linked to a stripe customer, we make the link
|
||||
@ -480,21 +482,48 @@ if ($ispaymentok)
|
||||
dol_syslog("No stripe profile found, so we add it for TRANSACTIONID = ".$TRANSACTIONID, LOG_DEBUG, 0, '_payment');
|
||||
|
||||
try {
|
||||
$ch = \Stripe\Charge::retrieve($TRANSACTIONID); // contains the charge id
|
||||
$stripecu = $ch->customer; // value 'cus_....'
|
||||
global $stripearrayofkeysbyenv;
|
||||
\Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']);
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_account (fk_soc, login, key_account, site, status, entity, date_creation, fk_user_creat)";
|
||||
$sql .= " VALUES (".$object->fk_soc.", '', '".$db->escape($stripecu)."', 'stripe', ".$servicestatus.", ".$conf->entity.", '".$db->idate(dol_now())."', 0)";
|
||||
$resql = $db->query($sql);
|
||||
if (!$resql)
|
||||
{
|
||||
if (preg_match('/^pi_/', $TRANSACTIONID)) {
|
||||
// This may throw an error if not found.
|
||||
$chpi = \Stripe\PaymentIntent::retrieve($TRANSACTIONID); // payment_intent (pi_...)
|
||||
} else {
|
||||
// This throw an error if not found
|
||||
$chpi = \Stripe\Charge::retrieve($TRANSACTIONID); // old method, contains the charge id (ch_...)
|
||||
}
|
||||
|
||||
if ($chpi) {
|
||||
$stripecu = $chpi->customer; // value 'cus_....'. WARNING: This property may be empty if first payment was recorded before the stripe customer was created.
|
||||
|
||||
if (empty($stripecu)) {
|
||||
// This include the INSERT
|
||||
$customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
|
||||
|
||||
// Link this customer to the payment intent
|
||||
if (preg_match('/^pi_/', $TRANSACTIONID) && $customer) {
|
||||
\Stripe\PaymentIntent::update($chpi->id, array('customer' => $customer->id));
|
||||
}
|
||||
} else {
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
|
||||
$sql .= " VALUES (".$object->fk_soc.", '', '".$db->escape($stripecu)."', 'stripe', '".$db->escape($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])."', ".$servicestatus.", ".$conf->entity.", '".$db->idate(dol_now())."', 0)";
|
||||
$resql = $db->query($sql);
|
||||
if (!$resql) { // should not happen
|
||||
$error++;
|
||||
$errmsg = 'Failed to insert customer stripe id in database : '.$db->lasterror();
|
||||
dol_syslog($errmsg, LOG_ERR, 0, '_payment');
|
||||
$postactionmessages[] = $errmsg;
|
||||
$ispostactionok = -1;
|
||||
}
|
||||
}
|
||||
} else { // should not happen
|
||||
$error++;
|
||||
$errmsg = 'Failed to insert customer stripe id in database : '.$db->lasterror();
|
||||
$errmsg = 'Failed to retreive paymentintent or charge from id';
|
||||
dol_syslog($errmsg, LOG_ERR, 0, '_payment');
|
||||
$postactionmessages[] = $errmsg;
|
||||
$ispostactionok = -1;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
} catch (Exception $e) { // should not happen
|
||||
$error++;
|
||||
$errmsg = 'Failed to get or save customer stripe id in database : '.$e->getMessage();
|
||||
dol_syslog($errmsg, LOG_ERR, 0, '_payment');
|
||||
@ -505,8 +534,7 @@ if ($ispaymentok)
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
} else {
|
||||
$db->rollback();
|
||||
|
||||
@ -142,7 +142,7 @@ class Stripe extends CommonObject
|
||||
|
||||
|
||||
/**
|
||||
* Get the Stripe customer of a thirdparty (with option to create it if not linked yet).
|
||||
* Get the Stripe customer of a thirdparty (with option to create it in Stripe if not linked yet).
|
||||
* Search on site_account = 0 or = $stripearrayofkeysbyenv[$status]['publishable_key']
|
||||
*
|
||||
* @param Societe $object Object thirdparty to check, or create on stripe (create on stripe also update the stripe_account table for current entity)
|
||||
@ -179,8 +179,7 @@ class Stripe extends CommonObject
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num)
|
||||
{
|
||||
if ($num) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$tiers = $obj->key_account;
|
||||
|
||||
@ -199,8 +198,7 @@ class Stripe extends CommonObject
|
||||
// For exemple, we may have error: 'No such customer: cus_XXXXX; a similar object exists in live mode, but a test mode key was used to make this request.'
|
||||
$this->error = $e->getMessage();
|
||||
}
|
||||
} elseif ($createifnotlinkedtostripe)
|
||||
{
|
||||
} elseif ($createifnotlinkedtostripe) {
|
||||
$ipaddress = getUserRemoteIP();
|
||||
|
||||
$dataforcustomer = array(
|
||||
|
||||
@ -769,7 +769,7 @@ span.fa.fa-plus-circle.paddingleft {
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
|
||||
.size15x { font-size: 1.5em; }
|
||||
.size15x { font-size: 1.5em !important; }
|
||||
.fa-toggle-on, .fa-toggle-off, .size2x { font-size: 2em; }
|
||||
.websiteselectionsection .fa-toggle-on, .websiteselectionsection .fa-toggle-off,
|
||||
.asetresetmodule .fa-toggle-on, .asetresetmodule .fa-toggle-off,
|
||||
|
||||
@ -840,7 +840,7 @@ body[class*="colorblind-"] .text-success{
|
||||
color: rgb(<?php echo $colortexttitle; ?>) !important;
|
||||
}
|
||||
|
||||
.size15x { font-size: 1.5em; }
|
||||
.size15x { font-size: 1.5em !important; }
|
||||
.fa-toggle-on, .fa-toggle-off, .size2x { font-size: 2em; }
|
||||
.websiteselectionsection .fa-toggle-on, .websiteselectionsection .fa-toggle-off,
|
||||
.asetresetmodule .fa-toggle-on, .asetresetmodule .fa-toggle-off {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user