FIX compatibility with intent payment_modes

This commit is contained in:
Laurent Destailleur 2019-05-17 00:10:44 +02:00
parent 52c1f42734
commit ae3a20d6ff
3 changed files with 77 additions and 4 deletions

View File

@ -2025,7 +2025,7 @@ if (preg_match('/^dopayment/', $action))
postal_code: '<?php echo $object->thirdparty->zip; ?>'}<?php } ?> postal_code: '<?php echo $object->thirdparty->zip; ?>'}<?php } ?>
} /* TODO Add all other known data like emails, ... to be SCA compliant */ } /* TODO Add all other known data like emails, ... to be SCA compliant */
}, },
save_payment_method: false save_payment_method: true /* the card will be saved */
} }
).then(function(result) { ).then(function(result) {
console.log(result); console.log(result);

View File

@ -810,8 +810,42 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
try { try {
$customerstripe=$stripe->customerStripe($object, $stripeacc, $servicestatus); $customerstripe=$stripe->customerStripe($object, $stripeacc, $servicestatus);
if ($customerstripe->id) { if ($customerstripe->id) {
// When using the Charge API architecture
if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION))
{
$listofsources=$customerstripe->sources->data; $listofsources=$customerstripe->sources->data;
} }
else
{
$service = 'StripeTest';
$servicestatus = 0;
if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox', 'alpha'))
{
$service = 'StripeLive';
$servicestatus = 1;
}
// Force to use the correct API key
global $stripearrayofkeysbyenv;
\Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']);
try {
if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
$paymentmethodobjs = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "card"));
} else {
$paymentmethodobjs = \Stripe\PaymentMethod::all(array("customer" => $customerstripe->id, "type" => "card"), array("stripe_account" => $stripeacc));
}
$listofsources = $paymentmethodobjs->data;
}
catch(Exception $e)
{
$error++;
setEventMessages($e->getMessage(), null, 'errors');
}
}
}
} }
catch(Exception $e) catch(Exception $e)
{ {
@ -1001,6 +1035,14 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
{ {
print '<span class="fa fa-university fa-2x fa-fw"></span>'; print '<span class="fa fa-university fa-2x fa-fw"></span>';
} }
elseif ($src->object=='payment_method' && $src->type=='card')
{
print img_credit_card($src->card->brand);
}
elseif ($src->object=='payment_method' && $src->type=='sepa_debit')
{
print '<span class="fa fa-university fa-2x fa-fw"></span>';
}
print'</td>'; print'</td>';
print '<td valign="middle">'; print '<td valign="middle">';
if ($src->object=='card') if ($src->object=='card')
@ -1040,6 +1082,34 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
} }
else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>'; else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
} }
elseif ($src->object=='payment_method' && $src->type=='card')
{
print $src->billing_details->name.'<br>....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.'';
print '</td><td>';
if ($src->card->country)
{
$img=picto_from_langcode($src->card->country);
print $img?$img.' ':'';
print getCountry($src->card->country, 1);
}
else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
}
elseif ($src->object=='payment_method' && $src->type=='sepa_debit')
{
print 'info sepa';
print '</td><td>';
if ($src->sepa_debit->country)
{
$img=picto_from_langcode($src->sepa_debit->country);
print $img?$img.' ':'';
print getCountry($src->sepa_debit->country, 1);
}
else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
}
else {
print '</td><td>';
}
print '</td>'; print '</td>';
// Default // Default
print '<td class="center" width="50">'; print '<td class="center" width="50">';
@ -1080,7 +1150,9 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard'
if ($nbremote == 0 && $nblocal == 0) if ($nbremote == 0 && $nblocal == 0)
{ {
print '<tr><td class="opacitymedium" colspan="7">'.$langs->trans("None").'</td></tr>'; $colspan=8;
if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) $colspan++;
print '<tr><td class="opacitymedium" colspan="'.$colspan.'">'.$langs->trans("None").'</td></tr>';
} }
print "</table>"; print "</table>";
print "</div>"; print "</div>";

View File

@ -344,11 +344,12 @@ class Stripe extends CommonObject
"payment_method_types" => ["card"], "payment_method_types" => ["card"],
"description" => $description, "description" => $description,
"statement_descriptor" => dol_trunc($tag, 10, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt (company + description) "statement_descriptor" => dol_trunc($tag, 10, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt (company + description)
//"save_payment_method" => true,
"metadata" => $metadata "metadata" => $metadata
); );
if (! is_null($customer)) $dataforintent["customer"]=$customer; if (! is_null($customer)) $dataforintent["customer"]=$customer;
// save_payment_method = true,
// payment_method = // payment_method =
// payment_method_types = array('card')
//var_dump($dataforintent); //var_dump($dataforintent);
if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0) if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)