diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index c8135d8dc36..6bdaa92f508 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -2025,7 +2025,7 @@ if (preg_match('/^dopayment/', $action)) postal_code: 'thirdparty->zip; ?>'} } /* 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) { console.log(result); diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 24bdedc946f..e2175142dd4 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -810,7 +810,41 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' try { $customerstripe=$stripe->customerStripe($object, $stripeacc, $servicestatus); if ($customerstripe->id) { - $listofsources=$customerstripe->sources->data; + + // When using the Charge API architecture + if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) + { + $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) @@ -1001,6 +1035,14 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' { print ''; } + 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 ''; + } print''; print ''; if ($src->object=='card') @@ -1040,6 +1082,34 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' } else print img_warning().' '.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).''; } + elseif ($src->object=='payment_method' && $src->type=='card') + { + print $src->billing_details->name.'
....'.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.''; + print ''; + + if ($src->card->country) + { + $img=picto_from_langcode($src->card->country); + print $img?$img.' ':''; + print getCountry($src->card->country, 1); + } + else print img_warning().' '.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).''; + } + elseif ($src->object=='payment_method' && $src->type=='sepa_debit') + { + print 'info sepa'; + print ''; + 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().' '.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CompanyCountry")).''; + } + else { + print ''; + } print ''; // Default print ''; @@ -1080,7 +1150,9 @@ if ($socid && $action != 'edit' && $action != 'create' && $action != 'editcard' if ($nbremote == 0 && $nblocal == 0) { - print ''.$langs->trans("None").''; + $colspan=8; + if (! empty($conf->global->STRIPE_ALLOW_LOCAL_CARD)) $colspan++; + print ''.$langs->trans("None").''; } print ""; print ""; diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index adfac2cd620..f832e061efb 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -344,11 +344,12 @@ class Stripe extends CommonObject "payment_method_types" => ["card"], "description" => $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 ); if (! is_null($customer)) $dataforintent["customer"]=$customer; - // save_payment_method = true, // payment_method = + // payment_method_types = array('card') //var_dump($dataforintent); if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0)