Fix metadata for charge.php

Fix for dol_id, dol_type
This commit is contained in:
ptibogxiv
2018-10-04 10:56:29 +02:00
committed by GitHub
parent e83149a344
commit d36dda37e6

View File

@@ -410,7 +410,9 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
$stripeToken = GETPOST("stripeToken",'alpha');
$email = GETPOST("email",'alpha');
$thirdparty_id=GETPOST('thirdparty_id', 'int'); // Note that for payment following online registration for members, this is empty because thirdparty is created once payment is confirmed by paymentok.php
$vatnumber = GETPOST('vatnumber','alpha');
$dol_type=GETPOST('s', 'int');
$dol_id=GETPOST('dol_id', 'int');
$vatnumber = GETPOST('vatnumber','alpha');
dol_syslog("stripeToken = ".$stripeToken, LOG_DEBUG, 0, '_stripe');
dol_syslog("email = ".$email, LOG_DEBUG, 0, '_stripe');
@@ -425,8 +427,7 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
'dol_entity'=>$conf->entity,
'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])
);
if (! empty($dol_id)) $metadata["dol_id"] = $dol_id;
if (! empty($dol_type)) $metadata["dol_type"] = $dol_type;
if (! empty($thirdparty_id)) $metadata["dol_thirdparty_id"] = $thirdparty_id;
if ($thirdparty_id > 0)
@@ -461,14 +462,18 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
$action='';
}
else
{
{
if (! empty($FULLTAG)) $metadata["FULLTAG"] = $FULLTAG;
if (! empty($dol_id)) $metadata["dol_id"] = $dol_id;
if (! empty($dol_type)) $metadata["dol_type"] = $dol_type;
dol_syslog("Create charge on card ".$card->id, LOG_DEBUG, 0, '_stripe');
$charge = \Stripe\Charge::create(array(
'amount' => price2num($amountstripe, 'MU'),
'currency' => $currency,
'capture' => true, // Charge immediatly
'description' => 'Stripe payment: '.$FULLTAG,
'metadata' => array("FULLTAG" => $FULLTAG, 'Recipient' => $mysoc->name, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])),
'metadata' => $metadata,
'customer' => $customer->id,
'source' => $card,
'statement_descriptor' => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 6, 'right', 'UTF-8', 1).' '.$FULLTAG, 22, 'right', 'UTF-8', 1) // 22 chars that appears on bank receipt
@@ -494,6 +499,10 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
'source' => $stripeToken // source can be a token OR array('object'=>'card', 'exp_month'=>xx, 'exp_year'=>xxxx, 'number'=>xxxxxxx, 'cvc'=>xxx, 'name'=>'Cardholder's full name', zip ?)
));
// Return $customer = array('id'=>'cus_XXXX', ...)
if (! empty($FULLTAG)) $metadata["FULLTAG"] = $FULLTAG;
if (! empty($dol_id)) $metadata["dol_id"] = $dol_id;
if (! empty($dol_type)) $metadata["dol_type"] = $dol_type;
// The customer was just created with a source, so we can make a charge
// with no card defined, the source just used for customer creation will be used.
@@ -504,7 +513,7 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
'currency' => $currency,
'capture' => true, // Charge immediatly
'description' => 'Stripe payment: '.$FULLTAG,
'metadata' => array("FULLTAG" => $FULLTAG, 'Recipient' => $mysoc->name, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])),
'metadata' => $metadata,
'statement_descriptor' => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 6, 'right', 'UTF-8', 1).' '.$FULLTAG, 22, 'right', 'UTF-8', 1) // 22 chars that appears on bank receipt
));
// Return $charge = array('id'=>'ch_XXXX', 'status'=>'succeeded|pending|failed', 'failure_code'=>, 'failure_message'=>...)
@@ -820,6 +829,7 @@ if ($source == 'order')
print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
print '<input type="hidden" name="s" value="'.dol_escape_htmltag($source).'">';
print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($order->ref).'">';
print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag($order->id).'">';
$directdownloadlink = $order->getLastMainDocLink('commande');
if ($directdownloadlink)
{
@@ -939,6 +949,7 @@ if ($source == 'invoice')
print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
print '<input type="hidden" name="s" value="'.dol_escape_htmltag($source).'">';
print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($invoice->ref).'">';
print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag($invoice->id).'">';
$directdownloadlink = $invoice->getLastMainDocLink('facture');
if ($directdownloadlink)
{
@@ -1137,6 +1148,7 @@ if ($source == 'contractline')
print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
print '<input type="hidden" name="source" value="'.dol_escape_htmltag($source).'">';
print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($contractline->ref).'">';
print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag($contractline->id).'">';
$directdownloadlink = $contract->getLastMainDocLink('contract');
if ($directdownloadlink)
{
@@ -1531,6 +1543,7 @@ if (preg_match('/^dopayment/',$action))
print '<input type="hidden" name="forcesandbox" value="'.GETPOST('forcesandbox','alpha').'" />';
print '<input type="hidden" name="email" value="'.GETPOST('email','alpha').'" />';
print '<input type="hidden" name="thirdparty_id" value="'.GETPOST('thirdparty_id','int').'" />';
print '<input type="hidden" name="thirdparty_id" value="'.GETPOST('thirdparty_id','int').'" />';
print '
<table id="dolpaymenttable" summary="Payment form" class="center">
@@ -1543,7 +1556,7 @@ if (preg_match('/^dopayment/',$action))
<div id="card-element">
<!-- a Stripe Element will be inserted here. -->
</div>
<input name="savesource" type="checkbox"> '.$langs->trans("SaveSource").'
<!-- Used to display form errors -->
<div id="card-errors" role="alert"></div>
</div>
@@ -1554,8 +1567,6 @@ if (preg_match('/^dopayment/',$action))
</form>
<script src="https://js.stripe.com/v2/"></script>
<script src="https://js.stripe.com/v3/"></script>
<script type="text/javascript" language="javascript">';
@@ -1691,4 +1702,3 @@ htmlPrintOnlinePaymentFooter($mysoc,$langs,1,$suffix,$object);
llxFooter('', 'public');
$db->close();