Skip to content

Commit

Permalink
Fix metadata for charge.php
Browse files Browse the repository at this point in the history
Fix for dol_id, dol_type
  • Loading branch information
ptibogxiv committed Oct 4, 2018
1 parent e83149a commit d36dda3
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions htdocs/public/payment/newpayment.php
Expand Up @@ -410,7 +410,9 @@
$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');
Expand All @@ -425,8 +427,7 @@
'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)
Expand Down Expand Up @@ -461,14 +462,18 @@
$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
Expand All @@ -494,6 +499,10 @@
'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.
Expand All @@ -504,7 +513,7 @@
'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'=>...)
Expand Down Expand Up @@ -820,6 +829,7 @@
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)
{
Expand Down Expand Up @@ -939,6 +949,7 @@
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)
{
Expand Down Expand Up @@ -1137,6 +1148,7 @@
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)
{
Expand Down Expand Up @@ -1531,6 +1543,7 @@ class="stripe-button"
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">
Expand All @@ -1543,7 +1556,7 @@ class="stripe-button"
<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>
Expand All @@ -1554,8 +1567,6 @@ class="stripe-button"
</form>
<script src="https://js.stripe.com/v2/"></script>
<script src="https://js.stripe.com/v3/"></script>
<script type="text/javascript" language="javascript">';
Expand Down Expand Up @@ -1691,4 +1702,3 @@ function stripeSourceHandler(source) {
llxFooter('', 'public');

$db->close();

0 comments on commit d36dda3

Please sign in to comment.