FIX Creation of Stripe card from backoffice must return a clean message
This commit is contained in:
parent
97d726733c
commit
7b661e707e
@ -68,3 +68,4 @@ ToOfferALinkForTestWebhook=Link to setup Stripe WebHook to call the IPN (test mo
|
|||||||
ToOfferALinkForLiveWebhook=Link to setup Stripe WebHook to call the IPN (live mode)
|
ToOfferALinkForLiveWebhook=Link to setup Stripe WebHook to call the IPN (live mode)
|
||||||
PaymentWillBeRecordedForNextPeriod=Payment will be recorded for the next period.
|
PaymentWillBeRecordedForNextPeriod=Payment will be recorded for the next period.
|
||||||
ClickHereToTryAgain=<a href="%s">Click here to try again...</a>
|
ClickHereToTryAgain=<a href="%s">Click here to try again...</a>
|
||||||
|
CreationOfPaymentModeMustBeDoneFromStripeInterface=Due to Strong Customer Authenticatin rules, creation of a card must be done from Stripe backoffice. You can click here to switch on Stripe customer record: %s
|
||||||
@ -554,16 +554,14 @@ if (empty($reshook))
|
|||||||
if (!$error)
|
if (!$error)
|
||||||
{
|
{
|
||||||
// Creation of Stripe card + update of societe_account
|
// Creation of Stripe card + update of societe_account
|
||||||
|
// Note that with the new Stripe API, option to create a card is no more available, instead an error message will be returned to
|
||||||
|
// ask to create the crdit card from Stripe backoffice.
|
||||||
$card = $stripe->cardStripe($cu, $companypaymentmode, $stripeacc, $servicestatus, 1);
|
$card = $stripe->cardStripe($cu, $companypaymentmode, $stripeacc, $servicestatus, 1);
|
||||||
if (!$card)
|
if (!$card)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
setEventMessages($stripe->error, $stripe->errors, 'errors');
|
setEventMessages($stripe->error, $stripe->errors, 'errors');
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$stripecard = $card->id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -682,18 +682,18 @@ class Stripe extends CommonObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Stripe card of a company payment mode (with option to create it on Stripe if not linked yet)
|
* Get the Stripe card of a company payment mode (option to create it on Stripe if not linked yet is no more available on new Stripe API)
|
||||||
*
|
*
|
||||||
* @param \Stripe\StripeCustomer $cu Object stripe customer
|
* @param \Stripe\StripeCustomer $cu Object stripe customer
|
||||||
* @param CompanyPaymentMode $object Object companypaymentmode to check, or create on stripe (create on stripe also update the societe_rib table for current entity)
|
* @param CompanyPaymentMode $object Object companypaymentmode to check, or create on stripe (create on stripe also update the societe_rib table for current entity)
|
||||||
* @param string $stripeacc ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect
|
* @param string $stripeacc ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect
|
||||||
* @param int $status Status (0=test, 1=live)
|
* @param int $status Status (0=test, 1=live)
|
||||||
* @param int $createifnotlinkedtostripe 1=Create the stripe card and the link if the card is not yet linked to a stripe card
|
* @param int $createifnotlinkedtostripe 1=Create the stripe card and the link if the card is not yet linked to a stripe card. Deprecated with new Stripe API and SCA.
|
||||||
* @return \Stripe\StripeCard|\Stripe\PaymentMethod|null Stripe Card or null if not found
|
* @return \Stripe\StripeCard|\Stripe\PaymentMethod|null Stripe Card or null if not found
|
||||||
*/
|
*/
|
||||||
public function cardStripe($cu, CompanyPaymentMode $object, $stripeacc = '', $status = 0, $createifnotlinkedtostripe = 0)
|
public function cardStripe($cu, CompanyPaymentMode $object, $stripeacc = '', $status = 0, $createifnotlinkedtostripe = 0)
|
||||||
{
|
{
|
||||||
global $conf, $user;
|
global $conf, $user, $langs;
|
||||||
|
|
||||||
$card = null;
|
$card = null;
|
||||||
|
|
||||||
@ -756,27 +756,54 @@ class Stripe extends CommonObject
|
|||||||
|
|
||||||
//$a = \Stripe\Stripe::getApiKey();
|
//$a = \Stripe\Stripe::getApiKey();
|
||||||
//var_dump($a);var_dump($stripeacc);exit;
|
//var_dump($a);var_dump($stripeacc);exit;
|
||||||
dol_syslog("Try to create card with dataforcard = ".json_encode($dataforcard));
|
|
||||||
try {
|
try {
|
||||||
if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
|
if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
|
||||||
if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION))
|
if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION))
|
||||||
{
|
{
|
||||||
|
dol_syslog("Try to create card with dataforcard = ".json_encode($dataforcard));
|
||||||
$card = $cu->sources->create($dataforcard);
|
$card = $cu->sources->create($dataforcard);
|
||||||
|
if (! $card)
|
||||||
|
{
|
||||||
|
$this->error = 'Creation of card on Stripe has failed';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO
|
$connect = '';
|
||||||
dol_syslog("Error: This case is not supported", LOG_ERR);
|
if (!empty($stripeacc)) $connect = $stripeacc.'/';
|
||||||
|
$url = 'https://dashboard.stripe.com/'.$connect.'test/customers/'.$cu->id;
|
||||||
|
if ($status)
|
||||||
|
{
|
||||||
|
$url = 'https://dashboard.stripe.com/'.$connect.'customers/'.$cu->id;
|
||||||
|
}
|
||||||
|
$urtoswitchonstripe = ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe'), 'globe').'</a>';
|
||||||
|
|
||||||
|
//dol_syslog("Error: This case is not supported", LOG_ERR);
|
||||||
|
$this->error = $langs->trans('CreationOfPaymentModeMustBeDoneFromStripeInterface', $urtoswitchonstripe);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION))
|
if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION))
|
||||||
{
|
{
|
||||||
|
dol_syslog("Try to create card with dataforcard = ".json_encode($dataforcard));
|
||||||
$card = $cu->sources->create($dataforcard, array("stripe_account" => $stripeacc));
|
$card = $cu->sources->create($dataforcard, array("stripe_account" => $stripeacc));
|
||||||
|
if (! $card)
|
||||||
|
{
|
||||||
|
$this->error = 'Creation of card on Stripe has failed';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO
|
$connect = '';
|
||||||
dol_syslog("Error: This case is not supported", LOG_ERR);
|
if (!empty($stripeacc)) $connect = $stripeacc.'/';
|
||||||
|
$url = 'https://dashboard.stripe.com/'.$connect.'test/customers/'.$cu->id;
|
||||||
|
if ($status)
|
||||||
|
{
|
||||||
|
$url = 'https://dashboard.stripe.com/'.$connect.'customers/'.$cu->id;
|
||||||
|
}
|
||||||
|
$urtoswitchonstripe = ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe'), 'globe').'</a>';
|
||||||
|
|
||||||
|
//dol_syslog("Error: This case is not supported", LOG_ERR);
|
||||||
|
$this->error = $langs->trans('CreationOfPaymentModeMustBeDoneFromStripeInterface', $urtoswitchonstripe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -794,10 +821,6 @@ class Stripe extends CommonObject
|
|||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->error = 'Call to cu->source->create return empty card';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user