21require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
22require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
23require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
24require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
25require_once DOL_DOCUMENT_ROOT.
'/stripe/config.php';
108 $entity =
$conf->entity;
111 $sql =
"SELECT tokenstring";
112 $sql .=
" FROM ".MAIN_DB_PREFIX.
"oauth_token";
113 $sql .=
" WHERE service = '".$this->db->escape($mode).
"'";
114 $sql .=
" AND entity = ".((int) $entity);
116 $sql .=
" AND fk_soc = ".((int) $fk_soc);
118 $sql .=
" AND fk_soc IS NULL";
120 $sql .=
" AND fk_user IS NULL AND fk_adherent IS NULL";
122 dol_syslog(get_class($this).
"::getStripeAccount", LOG_DEBUG);
124 $result = $this->db->query($sql);
126 if ($this->db->num_rows($result)) {
127 $obj = $this->db->fetch_object($result);
128 $tokenstring = $obj->tokenstring;
131 $tmparray = json_decode($tokenstring);
132 $key = empty($tmparray->stripe_user_id) ?
'' : $tmparray->stripe_user_id;
141 dol_syslog(
"No dedicated Stripe Connect account available for entity ".
$conf->entity);
156 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societeaccount.class.php';
158 return $societeaccount->getCustomerAccount($id,
'stripe', $status, $site_account);
177 dol_syslog(
"customerStripe is called with the parameter object that is not loaded");
184 global $stripearrayofkeysbyenv;
185 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
187 $sql =
"SELECT sa.key_account as key_account, sa.entity";
188 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_account as sa";
189 $sql .=
" WHERE sa.fk_soc = ".((int)
$object->id);
190 $sql .=
" AND sa.entity IN (".getEntity(
'societe').
")";
191 $sql .=
" AND sa.site = 'stripe' AND sa.status = ".((int) $status);
192 $sql .=
" AND (sa.site_account IS NULL OR sa.site_account = '' OR sa.site_account = '".$this->db->escape($stripearrayofkeysbyenv[$status][
'publishable_key']).
"')";
193 $sql .=
" AND sa.key_account IS NOT NULL AND sa.key_account <> ''";
194 $sql .=
" ORDER BY sa.site_account DESC, sa.rowid DESC";
196 dol_syslog(get_class($this).
"::customerStripe search stripe customer id for thirdparty id=".
$object->id, LOG_DEBUG);
197 $resql = $this->db->query($sql);
199 $num = $this->db->num_rows($resql);
201 $obj = $this->db->fetch_object($resql);
202 $tiers = $obj->key_account;
204 dol_syslog(get_class($this).
"::customerStripe found stripe customer key_account = ".$tiers.
". We will try to read it on Stripe with publishable_key = ".$stripearrayofkeysbyenv[$status][
'publishable_key']);
209 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$tiers",
'expand[]' =>
'sources'));
212 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$tiers",
'expand[]' =>
'sources'), array(
"stripe_account" => $key));
216 $this->error = $e->getMessage();
218 } elseif ($createifnotlinkedtostripe) {
221 $dataforcustomer = array(
223 "description" =>
$object->name,
224 "metadata" => array(
'dol_id' =>
$object->id,
'dol_version' => DOL_VERSION,
'dol_entity' =>
$conf->entity,
'ipaddress' => $ipaddress)
244 global $stripearrayofkeysbyenv;
245 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
248 $customer = \Stripe\Customer::create($dataforcustomer);
250 $customer = \Stripe\Customer::create($dataforcustomer, array(
"stripe_account" => $key));
255 if (!empty($vatcleaned)) {
257 if (
$object->country_code && $isineec) {
259 $customer->createTaxId($customer->id, array(
'type' =>
'eu_vat',
'value' => $vatcleaned));
265 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
266 $sql .=
" VALUES (".((int)
$object->id).
", '', '".$this->db->escape($customer->id).
"', 'stripe', '".$this->db->escape($stripearrayofkeysbyenv[$status][
'publishable_key']).
"', ".((int) $status).
", ".((int)
$conf->entity).
", '".$this->db->idate(
dol_now()).
"', ".((
int) $user->id).
")";
267 $resql = $this->db->query($sql);
269 $this->error = $this->db->lasterror();
272 $this->error = $e->getMessage();
292 $stripepaymentmethod =
null;
296 global $stripearrayofkeysbyenv;
297 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
299 $stripepaymentmethod = \Stripe\PaymentMethod::retrieve((
string) $paymentmethod->id);
301 $stripepaymentmethod = \Stripe\PaymentMethod::retrieve((
string) $paymentmethod->id, array(
"stripe_account" => $key));
304 $this->error = $e->getMessage();
307 return $stripepaymentmethod;
320 $selectedreader =
null;
324 global $stripearrayofkeysbyenv;
325 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
327 $selectedreader = \Stripe\Terminal\Reader::retrieve((
string) $reader);
329 $stripepaymentmethod = \Stripe\Terminal\Reader::retrieve((
string) $reader, array(
"stripe_account" => $key));
332 $this->error = $e->getMessage();
335 return $selectedreader;
349 $arrayzerounitcurrency = array(
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF');
350 if (!in_array($currency_code, $arrayzerounitcurrency)) {
351 if (empty($direction)) {
352 $newamount = (int) round($amount * 100);
354 $newamount = (float) ($amount / 100);
357 $newamount = $amount;
390 public function getPaymentIntent($amount, $currency_code, $tag, $description =
'',
$object =
null, $customer =
null, $key =
null, $servicestatus = 0, $usethirdpartyemailforreceiptemail = 0, $mode =
'automatic', $confirmnow =
false, $payment_method =
null, $off_session = 0, $noidempotency_key = 1, $did = 0)
392 global
$conf, $user, $hookmanager;
394 dol_syslog(get_class($this).
"::getPaymentIntent description=".$description, LOG_INFO, 1);
398 if (empty($servicestatus)) {
399 $service =
'StripeTest';
401 $service =
'StripeLive';
404 $stripeamount = $this->
convertAmount($amount, $currency_code, 0);
415 $stripefee = round($this->
convertAmount($fee, $currency_code));
417 $paymentintent =
null;
427 $sql =
"SELECT pi.ext_payment_id, pi.entity, pi.fk_facture, pi.sourcetype, pi.ext_payment_site";
428 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pi";
429 $sql .=
" WHERE pi.fk_facture = ".((int)
$object->id);
430 $sql .=
" AND pi.sourcetype = '".$this->db->escape(
$object->element).
"'";
431 $sql .=
" AND pi.entity IN (".getEntity(
'societe').
")";
432 $sql .=
" AND pi.ext_payment_site = '".$this->db->escape($service).
"'";
433 $sql .=
" ORDER BY rowid DESC";
435 dol_syslog(get_class($this).
"::getPaymentIntent search stripe payment intent for object id = ".
$object->id, LOG_DEBUG);
437 $resql = $this->db->query($sql);
439 $num = $this->db->num_rows($resql);
441 $obj = $this->db->fetch_object($resql);
443 $ext_payment_intent = $obj->ext_payment_id;
444 $ext_payment_intent_array = preg_split(
'/[:@]/', $ext_payment_intent);
446 $intent = $ext_payment_intent_array[0];
447 $customerindb = (isset($ext_payment_intent_array[1]) ? $ext_payment_intent_array[1] :
'');
448 $pkeyindb = (isset($ext_payment_intent_array[2]) ? $ext_payment_intent_array[2] :
'');
451 dol_syslog(get_class($this).
"::getPaymentIntent found existing payment intent record with intent=".$intent);
454 global $stripearrayofkeysbyenv;
455 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
459 $paymentintent = \Stripe\PaymentIntent::retrieve($intent);
461 $paymentintent = \Stripe\PaymentIntent::retrieve($intent, array(
"stripe_account" => $key));
465 $this->error = $e->getMessage();
471 if (empty($paymentintent)) {
474 $metadata = array(
'dol_version' => DOL_VERSION,
'dol_entity' =>
$conf->entity,
'ipaddress' => $ipaddress,
'dol_noidempotency' => (
int) $noidempotency_key);
476 $metadata[
'dol_type'] =
$object->element;
477 $metadata[
'dol_id'] =
$object->id;
478 if (is_object(
$object->thirdparty) &&
$object->thirdparty->id > 0) {
479 $metadata[
'dol_thirdparty_id'] =
$object->thirdparty->id;
486 $paymentmethodtypes = array(
"card");
487 $descriptor =
dol_trunc($tag, 10,
'right',
'UTF-8', 1);
489 $paymentmethodtypes[] =
"sepa_debit";
492 $paymentmethodtypes[] =
"klarna";
495 $paymentmethodtypes[] =
"bancontact";
498 $paymentmethodtypes[] =
"ideal";
501 $paymentmethodtypes[] =
"giropay";
504 $paymentmethodtypes[] =
"sofort";
506 if ($mode ==
'terminal') {
508 $paymentmethodtypes = array(
"card_present");
510 $stripemode =
'manual';
513 $descriptioninpaymentintent = $description;
518 $useautomaticmethods = (
getDolGlobalInt(
'STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 2 && $mode !=
'terminal');
519 $dataforintent = array_merge(
521 "confirm" => $confirmnow,
522 "amount" => $stripeamount,
523 "currency" => $currency_code,
524 "description" => $descriptioninpaymentintent,
525 "metadata" => $metadata,
527 $useautomaticmethods ? array(
528 'automatic_payment_methods' => array(
532 'confirmation_method' => $stripemode,
533 'payment_method_types' => $paymentmethodtypes,
534 'setup_future_usage' =>
'on_session',
538 $dataforintent[
"statement_descriptor_suffix"] =
dol_trunc($tag, 12,
'right',
'UTF-8', 1);
539 $dataforintent[
"statement_descriptor"] =
dol_trunc($tag, 22,
'right',
'UTF-8', 1);
541 if (!is_null($customer)) {
542 $dataforintent[
"customer"] = $customer;
548 unset($dataforintent[
'setup_future_usage']);
552 $dataforintent[
"off_session"] =
true;
555 unset($dataforintent[
'setup_future_usage']);
558 unset($dataforintent[
'setup_future_usage']);
561 unset($dataforintent[
'setup_future_usage']);
562 $dataforintent[
"capture_method"] =
"manual";
563 $dataforintent[
"confirmation_method"] =
"manual";
565 if (!is_null($payment_method)) {
566 $dataforintent[
"payment_method"] = $payment_method;
567 $description .=
' - '.$payment_method;
571 $dataforintent[
"application_fee_amount"] = $stripefee;
573 if ($usethirdpartyemailforreceiptemail && is_object(
$object) &&
$object->thirdparty->email) {
574 $dataforintent[
"receipt_email"] =
$object->thirdparty->email;
579 global $stripearrayofkeysbyenv;
580 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
582 $arrayofoptions = array();
583 if (empty($noidempotency_key)) {
584 $arrayofoptions[
"idempotency_key"] = $descriptioninpaymentintent;
588 $arrayofoptions[
"stripe_account"] = $key;
596 'dataforintent' => $dataforintent,
600 'currency_code' => $currency_code,
601 'customer' => $customer,
602 'servicestatus' => $servicestatus,
604 $reshook = $hookmanager->executeHooks(
'beforeCreateStripePaymentIntent', $parameters, $this);
605 if (!empty($hookmanager->resArray[
'dataforintent'])) {
606 $dataforintent = $hookmanager->resArray[
'dataforintent'];
609 dol_syslog(get_class($this).
"::getPaymentIntent ".$stripearrayofkeysbyenv[$servicestatus][
'publishable_key'], LOG_DEBUG);
610 dol_syslog(get_class($this).
"::getPaymentIntent dataforintent to create paymentintent = ".
formatLogObject($dataforintent));
612 $paymentintent = \Stripe\PaymentIntent::create($dataforintent, $arrayofoptions);
614 if ($paymentintent instanceof \
Stripe\PaymentIntent) {
615 dol_syslog(get_class($this).
"::getPaymentIntent paymentintent is a defined object");
619 $paymentintentalreadyexists = 0;
622 $customerid = $paymentintent->customer;
624 if (isset($stripearrayofkeysbyenv[$servicestatus][
'publishable_key'])) {
625 $pkey = $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
628 $LONGTRANSACTIONID = $paymentintent->id.
':'.$customerid.
'@'.$pkey;
633 dol_syslog(get_class($this).
"::getPaymentIntent search if payment intent already in prelevement_demande", LOG_DEBUG);
635 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande SET";
636 $sql .=
" ext_payment_site = '".$this->db->escape($service).
"',";
637 $sql .=
" ext_payment_id = '".$this->db->escape($paymentintent->id).
"'";
638 $sql .=
" WHERE rowid = ".((int) $did);
640 $resql = $this->db->query($sql);
642 $paymentintentalreadyexists++;
649 dol_syslog(get_class($this).
"::getPaymentIntent search if payment intent already in prelevement_demande", LOG_DEBUG);
651 $sql =
"SELECT pi.rowid";
652 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pi";
653 $sql .=
" WHERE pi.entity IN (".getEntity(
'societe').
")";
654 $sql .=
" AND pi.ext_payment_site = '".$this->db->escape($service).
"'";
655 $sql .=
" AND (pi.ext_payment_id = '".$this->db->escape($paymentintent->id).
"' OR pi.ext_payment_id = '".$this->db->escape($LONGTRANSACTIONID).
"')";
657 $resql = $this->db->query($sql);
659 $num = $this->db->num_rows($resql);
661 $obj = $this->db->fetch_object($resql);
663 $paymentintentalreadyexists++;
673 if (!$error && !$paymentintentalreadyexists) {
675 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_demande (date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site, amount)";
677 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $user->id).
", '".$this->db->escape($paymentintent->id).
"', ".((int)
$object->id).
", '".$this->db->escape(
$object->element).
"', ".((int)
$conf->entity).
", '".$this->db->escape($service).
"', ".((float) $amount).
")";
678 $resql = $this->db->query($sql);
681 $this->error = $this->db->lasterror();
682 dol_syslog(get_class($this).
"::PaymentIntent failed to insert paymentintent with id=".$paymentintent->id.
" into database.", LOG_ERR);
686 $_SESSION[
"stripe_payment_intent"] = $paymentintent;
689 dol_syslog(get_class($this).
"::getPaymentIntent create paymentintent did not returned a Stripe\PaymentIntent object", LOG_ERR);
693 $this->error = $e->getMessage();
694 $this->code = $e->getStripeCode();
695 $this->declinecode = $e->getDeclineCode();
704 $this->error = $e->getMessage();
706 $this->declinecode =
'';
710 dol_syslog(get_class($this).
"::getPaymentIntent return error=".$error.
" this->error=".$this->error, LOG_INFO, -1);
713 return $paymentintent;
737 public function getSetupIntent($description,
$object, $customer, $key, $servicestatus, $usethirdpartyemailforreceiptemail = 0, $confirmnow =
false)
741 $noidempotency_key = 1;
747 if (empty($servicestatus)) {
748 $service =
'StripeTest';
750 $service =
'StripeLive';
755 if (empty($setupintent)) {
757 $metadata = array(
'dol_version' => DOL_VERSION,
'dol_entity' =>
$conf->entity,
'ipaddress' => $ipaddress,
'dol_noidempotency' => (
int) $noidempotency_key);
759 $metadata[
'dol_type'] =
$object->element;
760 $metadata[
'dol_id'] =
$object->id;
761 if (is_object(
$object->thirdparty) &&
$object->thirdparty->id > 0) {
762 $metadata[
'dol_thirdparty_id'] =
$object->thirdparty->id;
767 $paymentmethodtypes = array(
"card");
769 $paymentmethodtypes[] =
"sepa_debit";
772 $paymentmethodtypes[] =
"bancontact";
775 $paymentmethodtypes[] =
"ideal";
779 $paymentmethodtypes[] =
"sofort";
784 $descriptioninsetupintent = $description;
786 $dataforintent = array(
787 "confirm" => $confirmnow,
788 "payment_method_types" => $paymentmethodtypes,
796 "usage" =>
"off_session",
797 "metadata" => $metadata
799 if (!is_null($customer)) {
800 $dataforintent[
"customer"] = $customer;
802 if (!is_null($description)) {
803 $dataforintent[
"description"] = $descriptioninsetupintent;
809 if ($usethirdpartyemailforreceiptemail && is_object(
$object) &&
$object->thirdparty->email) {
810 $dataforintent[
"receipt_email"] =
$object->thirdparty->email;
815 global $stripearrayofkeysbyenv;
816 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
818 dol_syslog(get_class($this).
"::getSetupIntent ".$stripearrayofkeysbyenv[$servicestatus][
'publishable_key'], LOG_DEBUG);
824 $setupintent = \Stripe\SetupIntent::create($dataforintent, array());
827 $setupintent = \Stripe\SetupIntent::create($dataforintent, array(
"stripe_account" => $key));
880 $this->error = $e->getMessage();
885 dol_syslog(
"getSetupIntent ".(is_object($setupintent) ? $setupintent->id :
''), LOG_INFO, -1);
888 dol_syslog(
"getSetupIntent return error=".$error, LOG_INFO, -1);
906 global
$conf, $langs;
910 $sql =
"SELECT sa.stripe_card_ref, sa.proprio as owner_name, sa.exp_date_month, sa.exp_date_year, sa.number, sa.cvn";
911 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as sa";
912 $sql .=
" WHERE sa.rowid = ".((int)
$object->id);
913 $sql .=
" AND sa.type = 'card'";
915 dol_syslog(get_class($this).
"::cardStripe search stripe card id for paymentmode id=".
$object->id.
", stripeacc=".$stripeacc.
", status=".$status.
", createifnotlinkedtostripe=".$createifnotlinkedtostripe, LOG_DEBUG);
916 $resql = $this->db->query($sql);
918 $num = $this->db->num_rows($resql);
920 $obj = $this->db->fetch_object($resql);
921 $cardref = $obj->stripe_card_ref;
922 dol_syslog(get_class($this).
"::cardStripe cardref=".$cardref);
925 if (empty($stripeacc)) {
926 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
927 $card = $cu->sources->retrieve($cardref);
929 $card = \Stripe\PaymentMethod::retrieve($cardref);
932 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
934 $card = $cu->sources->retrieve($cardref);
937 $card = \Stripe\PaymentMethod::retrieve($cardref);
941 $this->error = $e->getMessage();
944 } elseif ($createifnotlinkedtostripe) {
946 $exp_date_month = $obj->exp_date_month;
947 $exp_date_year = $obj->exp_date_year;
948 $number = $obj->number;
950 $cardholdername = $obj->owner_name;
954 $dataforcard = array(
957 'exp_month' => $exp_date_month,
958 'exp_year' => $exp_date_year,
961 'name' => $cardholdername
964 'dol_type' =>
$object->element,
966 'dol_version' => DOL_VERSION,
967 'dol_entity' =>
$conf->entity,
968 'ipaddress' => $ipaddress
976 if (empty($stripeacc)) {
979 $card = $cu->sources->create($dataforcard);
981 $this->error =
'Creation of card on Stripe has failed';
985 if (!empty($stripeacc)) {
986 $connect = $stripeacc.
'/';
988 $url =
'https://dashboard.stripe.com/'.$connect.
'test/customers/'.$cu->id;
990 $url =
'https://dashboard.stripe.com/'.$connect.
'customers/'.$cu->id;
992 $urtoswitchonstripe =
'<a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe'),
'globe').
'</a>';
995 $this->error = str_replace(
'{s1}', $urtoswitchonstripe, $langs->trans(
'CreationOfPaymentModeMustBeDoneFromStripeInterface',
'{s1}'));
1000 $card = $cu->sources->create($dataforcard, array(
"stripe_account" => $stripeacc));
1002 $this->error =
'Creation of card on Stripe has failed';
1006 if (!empty($stripeacc)) {
1007 $connect = $stripeacc.
'/';
1009 $url =
'https://dashboard.stripe.com/'.$connect.
'test/customers/'.$cu->id;
1011 $url =
'https://dashboard.stripe.com/'.$connect.
'customers/'.$cu->id;
1013 $urtoswitchonstripe =
'<a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe'),
'globe').
'</a>';
1016 $this->error = str_replace(
'{s1}', $urtoswitchonstripe, $langs->trans(
'CreationOfPaymentModeMustBeDoneFromStripeInterface',
'{s1}'));
1021 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib";
1022 $sql .=
" SET stripe_card_ref = '".$this->db->escape($card->id).
"', card_type = '".$this->db->escape($card->brand).
"',";
1023 $sql .=
" country_code = '".$this->db->escape($card->country).
"',";
1024 $sql .=
" approved = ".($card->cvc_check ==
'pass' ? 1 : 0);
1025 $sql .=
" WHERE rowid = ".((int)
$object->id);
1026 $sql .=
" AND type = 'card'";
1027 $resql = $this->db->query($sql);
1029 $this->error = $this->db->lasterror();
1033 $this->error = $e->getMessage();
1061 $sql =
"SELECT sa.stripe_card_ref, sa.proprio, sa.iban_prefix as iban, sa.rum";
1062 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as sa";
1063 $sql .=
" WHERE sa.rowid = ".((int)
$object->id);
1064 $sql .=
" AND sa.type = 'ban'";
1066 $soc =
new Societe($this->db);
1069 dol_syslog(get_class($this).
"::sepaStripe search stripe ban id for paymentmode id=".
$object->id.
", stripeacc=".$stripeacc.
", status=".$status.
", createifnotlinkedtostripe=".$createifnotlinkedtostripe, LOG_DEBUG);
1070 $resql = $this->db->query($sql);
1072 $num = $this->db->num_rows($resql);
1074 $obj = $this->db->fetch_object($resql);
1075 $cardref = $obj->stripe_card_ref;
1077 dol_syslog(get_class($this).
"::sepaStripe paymentmode=".$cardref);
1081 if (empty($stripeacc)) {
1082 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
1083 $sepa = $cu->sources->retrieve($cardref);
1085 $sepa = \Stripe\PaymentMethod::retrieve($cardref);
1088 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
1090 $sepa = $cu->sources->retrieve($cardref);
1093 $sepa = \Stripe\PaymentMethod::retrieve($cardref);
1097 $this->error = $e->getMessage();
1100 } elseif ($createifnotlinkedtostripe) {
1103 $metadata = array(
'dol_version' => DOL_VERSION,
'dol_entity' =>
$conf->entity,
'ipaddress' => $ipaddress);
1105 $metadata[
'dol_type'] =
$object->element;
1106 $metadata[
'dol_id'] =
$object->id;
1107 $metadata[
'dol_thirdparty_id'] = $soc->id;
1110 $description =
'SEPA for IBAN '.$iban;
1112 $dataforcard = array(
1113 'type' =>
'sepa_debit',
1114 "sepa_debit" => array(
'iban' => $iban),
1115 'billing_details' => array(
1116 'name' => $soc->name,
1117 'email' => !empty($soc->email) ? $soc->email :
"",
1119 "metadata" => $metadata
1122 if (!empty($soc->town)) {
1123 $dataforcard[
'billing_details'][
'address'][
'city'] = $soc->town;
1125 if (!empty($soc->country_code)) {
1126 $dataforcard[
'billing_details'][
'address'][
'country'] = $soc->country_code;
1128 if (!empty($soc->address)) {
1129 $dataforcard[
'billing_details'][
'address'][
'line1'] = $soc->address;
1131 if (!empty($soc->zip)) {
1132 $dataforcard[
'billing_details'][
'address'][
'postal_code'] = $soc->zip;
1134 if (!empty($soc->state)) {
1135 $dataforcard[
'billing_details'][
'address'][
'state'] = $soc->state;
1143 $service =
'StripeTest';
1146 $service =
'StripeLive';
1150 global $stripearrayofkeysbyenv;
1151 $stripeacc = $stripearrayofkeysbyenv[$servicestatus][
'secret_key'];
1155 $s = new \Stripe\StripeClient($stripeacc);
1159 $sepa = $s->paymentMethods->create($dataforcard);
1161 $this->error =
'Creation of payment method sepa_debit on Stripe has failed';
1166 $dataforintent = array(0 => [
'description' => $description,
'payment_method_types' => [
'sepa_debit'],
'customer' => $cu->id,
'payment_method' => $sepa->id],
'metadata' => $metadata);
1168 $cs = $s->setupIntents->create($dataforintent);
1172 $this->error =
'Link SEPA <-> setupIntent->create failed';
1177 $cs2 = $s->setupIntents->confirm($cs->id, [
'mandate_data' => [
'customer_acceptance' => [
'type' =>
'offline']]]);
1179 $this->error =
'Link SEPA <-> setupIntent->confirm failed';
1185 dol_syslog(
"Update the payment mode of the customer");
1190 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib";
1191 $sql .=
" SET stripe_card_ref = '".$this->db->escape($sepa->id).
"',";
1192 $sql .=
" card_type = 'sepa_debit',";
1193 $sql .=
" stripe_account= '" . $this->db->escape($cu->id .
"@" . $stripeacc) .
"',";
1194 $sql .=
" ext_payment_site = '".$this->db->escape($service).
"'";
1195 if (!empty($cs->mandate)) {
1196 $mandateservice = new \Stripe\Mandate($stripeacc);
1197 $mandate = $mandateservice->retrieve($cs->mandate);
1198 if (is_object($mandate) && is_object($mandate->payment_method_details) && is_object($mandate->payment_method_details->sepa_debit)) {
1199 $refmandate = $mandate->payment_method_details->sepa_debit->reference;
1201 $sql .=
", rum = '".$this->db->escape($refmandate).
"'";
1203 $sql .=
", comment = '".$this->db->escape($cs->mandate).
"'";
1204 $sql .=
", date_rum = '".$this->db->idate(
dol_now()).
"'";
1206 $sql .=
" WHERE rowid = ".((int)
$object->id);
1207 $sql .=
" AND type = 'ban'";
1208 $resql = $this->db->query($sql);
1210 $this->error = $this->db->lasterror();
1216 $this->error =
'Stripe error: '.$e->getMessage().
'. Check the BAN information.';
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class for CompanyPaymentMode.
Class for SocieteAccount.
Class to manage third parties objects (customers, suppliers, prospects...)
Stripe class @TODO No reason to extend CommonObject.
convertAmount($amount, $currency_code, $direction=0)
Convert an amount in Stripe format into an amount into standard amount.
getPaymentMethodStripe($paymentmethod, $key='', $status=0)
Get the Stripe payment method Object from its ID.
sepaStripe($cu, CompanyPaymentMode $object, $stripeacc='', $status=0, $createifnotlinkedtostripe=0)
Get the Stripe SEPA of a company payment mode (create it if it doesn't exists and $createifnotlinkedt...
customerStripe($object, $key='', $status=0, $createifnotlinkedtostripe=0)
Get the Stripe customer of a thirdparty (with option to create it in Stripe if not linked yet).
getStripeCustomerAccount($id, $status=0, $site_account='')
getStripeCustomerAccount
cardStripe($cu, CompanyPaymentMode $object, $stripeacc='', $status=0, $createifnotlinkedtostripe=0)
Get the Stripe card of a company payment mode (option to create it on Stripe if not linked yet is no ...
__construct($db)
Constructor.
getPaymentIntent($amount, $currency_code, $tag, $description='', $object=null, $customer=null, $key=null, $servicestatus=0, $usethirdpartyemailforreceiptemail=0, $mode='automatic', $confirmnow=false, $payment_method=null, $off_session=0, $noidempotency_key=1, $did=0)
Get the Stripe payment intent.
getStripeAccount($mode='StripeTest', $fk_soc=0, $entity=-1)
Return main company OAuth Connect stripe account.
getSetupIntent($description, $object, $customer, $key, $servicestatus, $usethirdpartyemailforreceiptemail=0, $confirmnow=false)
Get the Stripe payment intent.
getSelectedReader($reader, $key='', $status=0)
Get the Stripe reader Object from its ID.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) formatLogObject($data)
Return a string serialized to be output on log with dol_syslog() An option allow to output log in one...
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.