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)
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";
493 $paymentmethodtypes[] =
"klarna";
496 $paymentmethodtypes[] =
"bancontact";
499 $paymentmethodtypes[] =
"ideal";
502 $paymentmethodtypes[] =
"giropay";
505 $paymentmethodtypes[] =
"sofort";
507 if ($mode ==
'terminal') {
509 $paymentmethodtypes = array(
"card_present");
511 $stripemode =
'manual';
516 $descriptioninpaymentintent = $description;
518 $dataforintent = array(
519 "confirm" => $confirmnow,
520 "confirmation_method" => $stripemode,
521 "amount" => $stripeamount,
522 "currency" => $currency_code,
523 "payment_method_types" => $paymentmethodtypes,
531 "description" => $descriptioninpaymentintent,
533 "setup_future_usage" =>
"on_session",
534 "metadata" => $metadata
537 $dataforintent[
"statement_descriptor_suffix"] = $descriptor;
538 $dataforintent[
"statement_descriptor"] = $descriptor;
540 if (!is_null($customer)) {
541 $dataforintent[
"customer"] = $customer;
547 unset($dataforintent[
'setup_future_usage']);
551 $dataforintent[
"off_session"] =
true;
554 unset($dataforintent[
'setup_future_usage']);
557 unset($dataforintent[
'setup_future_usage']);
560 unset($dataforintent[
'setup_future_usage']);
561 $dataforintent[
"capture_method"] =
"manual";
562 $dataforintent[
"confirmation_method"] =
"manual";
564 if (!is_null($payment_method)) {
565 $dataforintent[
"payment_method"] = $payment_method;
566 $description .=
' - '.$payment_method;
569 if ($conf->entity !=
getDolGlobalInt(
'STRIPECONNECT_PRINCIPAL') && $stripefee > 0) {
570 $dataforintent[
"application_fee_amount"] = $stripefee;
572 if ($usethirdpartyemailforreceiptemail && is_object(
$object) &&
$object->thirdparty->email) {
573 $dataforintent[
"receipt_email"] =
$object->thirdparty->email;
578 global $stripearrayofkeysbyenv;
579 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
581 $arrayofoptions = array();
582 if (empty($noidempotency_key)) {
583 $arrayofoptions[
"idempotency_key"] = $descriptioninpaymentintent;
587 $arrayofoptions[
"stripe_account"] = $key;
590 dol_syslog(get_class($this).
"::getPaymentIntent ".$stripearrayofkeysbyenv[$servicestatus][
'publishable_key'], LOG_DEBUG);
591 dol_syslog(get_class($this).
"::getPaymentIntent dataforintent to create paymentintent = ".var_export($dataforintent,
true));
593 $paymentintent = \Stripe\PaymentIntent::create($dataforintent, $arrayofoptions);
595 if ($paymentintent instanceof \
Stripe\PaymentIntent) {
596 dol_syslog(get_class($this).
"::getPaymentIntent paymentintent is a defined object");
600 $paymentintentalreadyexists = 0;
603 $customerid = $paymentintent->customer;
605 if (isset($stripearrayofkeysbyenv[$servicestatus][
'publishable_key'])) {
606 $pkey = $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
609 $LONGTRANSACTIONID = $paymentintent->id.
':'.$customerid.
'@'.$pkey;
614 dol_syslog(get_class($this).
"::getPaymentIntent search if payment intent already in prelevement_demande", LOG_DEBUG);
616 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande SET";
617 $sql .=
" ext_payment_site = '".$this->db->escape($service).
"',";
618 $sql .=
" ext_payment_id = '".$this->db->escape($paymentintent->id).
"'";
619 $sql .=
" WHERE rowid = ".((int) $did);
621 $resql = $this->db->query($sql);
623 $paymentintentalreadyexists++;
630 dol_syslog(get_class($this).
"::getPaymentIntent search if payment intent already in prelevement_demande", LOG_DEBUG);
632 $sql =
"SELECT pi.rowid";
633 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pi";
634 $sql .=
" WHERE pi.entity IN (".getEntity(
'societe').
")";
635 $sql .=
" AND pi.ext_payment_site = '".$this->db->escape($service).
"'";
636 $sql .=
" AND (pi.ext_payment_id = '".$this->db->escape($paymentintent->id).
"' OR pi.ext_payment_id = '".$this->db->escape($LONGTRANSACTIONID).
"')";
638 $resql = $this->db->query($sql);
640 $num = $this->db->num_rows($resql);
642 $obj = $this->db->fetch_object($resql);
644 $paymentintentalreadyexists++;
654 if (!$error && !$paymentintentalreadyexists) {
656 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_demande (date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site, amount)";
658 $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).
")";
659 $resql = $this->db->query($sql);
662 $this->error = $this->db->lasterror();
663 dol_syslog(get_class($this).
"::PaymentIntent failed to insert paymentintent with id=".$paymentintent->id.
" into database.", LOG_ERR);
667 $_SESSION[
"stripe_payment_intent"] = $paymentintent;
670 dol_syslog(get_class($this).
"::getPaymentIntent create paymentintent did not returned a Stripe\PaymentIntent object", LOG_ERR);
674 $this->error = $e->getMessage();
675 $this->code = $e->getStripeCode();
676 $this->declinecode = $e->getDeclineCode();
685 $this->error = $e->getMessage();
687 $this->declinecode =
'';
691 dol_syslog(get_class($this).
"::getPaymentIntent return error=".$error.
" this->error=".$this->error, LOG_INFO, -1);
694 return $paymentintent;
718 public function getSetupIntent($description,
$object, $customer, $key, $servicestatus, $usethirdpartyemailforreceiptemail = 0, $confirmnow =
false)
722 $noidempotency_key = 1;
724 dol_syslog(
"getSetupIntent description=".$description.
' confirmnow='.json_encode($confirmnow), LOG_INFO, 1);
728 if (empty($servicestatus)) {
729 $service =
'StripeTest';
731 $service =
'StripeLive';
736 if (empty($setupintent)) {
738 $metadata = array(
'dol_version' => DOL_VERSION,
'dol_entity' => $conf->entity,
'ipaddress' => $ipaddress,
'dol_noidempotency' => (
int) $noidempotency_key);
740 $metadata[
'dol_type'] =
$object->element;
741 $metadata[
'dol_id'] =
$object->id;
742 if (is_object(
$object->thirdparty) &&
$object->thirdparty->id > 0) {
743 $metadata[
'dol_thirdparty_id'] =
$object->thirdparty->id;
748 $paymentmethodtypes = array(
"card");
750 $paymentmethodtypes[] =
"sepa_debit";
753 $paymentmethodtypes[] =
"bancontact";
756 $paymentmethodtypes[] =
"ideal";
760 $paymentmethodtypes[] =
"sofort";
765 $descriptioninsetupintent = $description;
767 $dataforintent = array(
768 "confirm" => $confirmnow,
769 "payment_method_types" => $paymentmethodtypes,
777 "usage" =>
"off_session",
778 "metadata" => $metadata
780 if (!is_null($customer)) {
781 $dataforintent[
"customer"] = $customer;
783 if (!is_null($description)) {
784 $dataforintent[
"description"] = $descriptioninsetupintent;
790 if ($usethirdpartyemailforreceiptemail && is_object(
$object) &&
$object->thirdparty->email) {
791 $dataforintent[
"receipt_email"] =
$object->thirdparty->email;
796 global $stripearrayofkeysbyenv;
797 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
799 dol_syslog(get_class($this).
"::getSetupIntent ".$stripearrayofkeysbyenv[$servicestatus][
'publishable_key'], LOG_DEBUG);
800 dol_syslog(get_class($this).
"::getSetupIntent dataforintent to create setupintent = ".var_export($dataforintent,
true));
805 $setupintent = \Stripe\SetupIntent::create($dataforintent, array());
808 $setupintent = \Stripe\SetupIntent::create($dataforintent, array(
"stripe_account" => $key));
861 $this->error = $e->getMessage();
866 dol_syslog(
"getSetupIntent ".(is_object($setupintent) ? $setupintent->id :
''), LOG_INFO, -1);
869 dol_syslog(
"getSetupIntent return error=".$error, LOG_INFO, -1);
887 global $conf, $langs;
891 $sql =
"SELECT sa.stripe_card_ref, sa.proprio as owner_name, sa.exp_date_month, sa.exp_date_year, sa.number, sa.cvn";
892 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as sa";
893 $sql .=
" WHERE sa.rowid = ".((int)
$object->id);
894 $sql .=
" AND sa.type = 'card'";
896 dol_syslog(get_class($this).
"::cardStripe search stripe card id for paymentmode id=".
$object->id.
", stripeacc=".$stripeacc.
", status=".$status.
", createifnotlinkedtostripe=".$createifnotlinkedtostripe, LOG_DEBUG);
897 $resql = $this->db->query($sql);
899 $num = $this->db->num_rows($resql);
901 $obj = $this->db->fetch_object($resql);
902 $cardref = $obj->stripe_card_ref;
903 dol_syslog(get_class($this).
"::cardStripe cardref=".$cardref);
906 if (empty($stripeacc)) {
907 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
908 $card = $cu->sources->retrieve($cardref);
910 $card = \Stripe\PaymentMethod::retrieve($cardref);
913 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
915 $card = $cu->sources->retrieve($cardref);
918 $card = \Stripe\PaymentMethod::retrieve($cardref);
922 $this->error = $e->getMessage();
925 } elseif ($createifnotlinkedtostripe) {
927 $exp_date_month = $obj->exp_date_month;
928 $exp_date_year = $obj->exp_date_year;
929 $number = $obj->number;
931 $cardholdername = $obj->owner_name;
935 $dataforcard = array(
938 'exp_month' => $exp_date_month,
939 'exp_year' => $exp_date_year,
942 'name' => $cardholdername
945 'dol_type' =>
$object->element,
947 'dol_version' => DOL_VERSION,
948 'dol_entity' => $conf->entity,
949 'ipaddress' => $ipaddress
957 if (empty($stripeacc)) {
959 dol_syslog(
"Try to create card with dataforcard = ".json_encode($dataforcard));
960 $card = $cu->sources->create($dataforcard);
962 $this->error =
'Creation of card on Stripe has failed';
966 if (!empty($stripeacc)) {
967 $connect = $stripeacc.
'/';
969 $url =
'https://dashboard.stripe.com/'.$connect.
'test/customers/'.$cu->id;
971 $url =
'https://dashboard.stripe.com/'.$connect.
'customers/'.$cu->id;
973 $urtoswitchonstripe =
'<a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe'),
'globe').
'</a>';
976 $this->error = str_replace(
'{s1}', $urtoswitchonstripe, $langs->trans(
'CreationOfPaymentModeMustBeDoneFromStripeInterface',
'{s1}'));
980 dol_syslog(
"Try to create card with dataforcard = ".json_encode($dataforcard));
981 $card = $cu->sources->create($dataforcard, array(
"stripe_account" => $stripeacc));
983 $this->error =
'Creation of card on Stripe has failed';
987 if (!empty($stripeacc)) {
988 $connect = $stripeacc.
'/';
990 $url =
'https://dashboard.stripe.com/'.$connect.
'test/customers/'.$cu->id;
992 $url =
'https://dashboard.stripe.com/'.$connect.
'customers/'.$cu->id;
994 $urtoswitchonstripe =
'<a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe'),
'globe').
'</a>';
997 $this->error = str_replace(
'{s1}', $urtoswitchonstripe, $langs->trans(
'CreationOfPaymentModeMustBeDoneFromStripeInterface',
'{s1}'));
1002 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib";
1003 $sql .=
" SET stripe_card_ref = '".$this->db->escape($card->id).
"', card_type = '".$this->db->escape($card->brand).
"',";
1004 $sql .=
" country_code = '".$this->db->escape($card->country).
"',";
1005 $sql .=
" approved = ".($card->cvc_check ==
'pass' ? 1 : 0);
1006 $sql .=
" WHERE rowid = ".((int)
$object->id);
1007 $sql .=
" AND type = 'card'";
1008 $resql = $this->db->query($sql);
1010 $this->error = $this->db->lasterror();
1014 $this->error = $e->getMessage();
1042 $sql =
"SELECT sa.stripe_card_ref, sa.proprio, sa.iban_prefix as iban, sa.rum";
1043 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as sa";
1044 $sql .=
" WHERE sa.rowid = ".((int)
$object->id);
1045 $sql .=
" AND sa.type = 'ban'";
1047 $soc =
new Societe($this->db);
1050 dol_syslog(get_class($this).
"::sepaStripe search stripe ban id for paymentmode id=".
$object->id.
", stripeacc=".$stripeacc.
", status=".$status.
", createifnotlinkedtostripe=".$createifnotlinkedtostripe, LOG_DEBUG);
1051 $resql = $this->db->query($sql);
1053 $num = $this->db->num_rows($resql);
1055 $obj = $this->db->fetch_object($resql);
1056 $cardref = $obj->stripe_card_ref;
1058 dol_syslog(get_class($this).
"::sepaStripe paymentmode=".$cardref);
1062 if (empty($stripeacc)) {
1063 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
1064 $sepa = $cu->sources->retrieve($cardref);
1066 $sepa = \Stripe\PaymentMethod::retrieve($cardref);
1069 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
1071 $sepa = $cu->sources->retrieve($cardref);
1074 $sepa = \Stripe\PaymentMethod::retrieve($cardref);
1078 $this->error = $e->getMessage();
1081 } elseif ($createifnotlinkedtostripe) {
1084 $metadata = array(
'dol_version' => DOL_VERSION,
'dol_entity' => $conf->entity,
'ipaddress' => $ipaddress);
1086 $metadata[
'dol_type'] =
$object->element;
1087 $metadata[
'dol_id'] =
$object->id;
1088 $metadata[
'dol_thirdparty_id'] = $soc->id;
1091 $description =
'SEPA for IBAN '.$iban;
1093 $dataforcard = array(
1094 'type' =>
'sepa_debit',
1095 "sepa_debit" => array(
'iban' => $iban),
1096 'billing_details' => array(
1097 'name' => $soc->name,
1098 'email' => !empty($soc->email) ? $soc->email :
"",
1100 "metadata" => $metadata
1103 if (!empty($soc->town)) {
1104 $dataforcard[
'billing_details'][
'address'][
'city'] = $soc->town;
1106 if (!empty($soc->country_code)) {
1107 $dataforcard[
'billing_details'][
'address'][
'country'] = $soc->country_code;
1109 if (!empty($soc->address)) {
1110 $dataforcard[
'billing_details'][
'address'][
'line1'] = $soc->address;
1112 if (!empty($soc->zip)) {
1113 $dataforcard[
'billing_details'][
'address'][
'postal_code'] = $soc->zip;
1115 if (!empty($soc->state)) {
1116 $dataforcard[
'billing_details'][
'address'][
'state'] = $soc->state;
1124 $service =
'StripeTest';
1127 $service =
'StripeLive';
1131 global $stripearrayofkeysbyenv;
1132 $stripeacc = $stripearrayofkeysbyenv[$servicestatus][
'secret_key'];
1134 dol_syslog(
"Try to create sepa_debit with data = ".json_encode($dataforcard));
1136 $s = new \Stripe\StripeClient($stripeacc);
1140 $sepa = $s->paymentMethods->create($dataforcard);
1142 $this->error =
'Creation of payment method sepa_debit on Stripe has failed';
1147 $dataforintent = array(0 => [
'description' => $description,
'payment_method_types' => [
'sepa_debit'],
'customer' => $cu->id,
'payment_method' => $sepa->id],
'metadata' => $metadata);
1149 $cs = $s->setupIntents->create($dataforintent);
1151 $cs = $s->setupIntents->confirm($cs->id, [
'mandate_data' => [
'customer_acceptance' => [
'type' =>
'offline']]]);
1155 $this->error =
'Link SEPA <-> Customer failed';
1158 dol_syslog(
"Update the payment mode of the customer");
1163 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib";
1164 $sql .=
" SET stripe_card_ref = '".$this->db->escape($sepa->id).
"',";
1165 $sql .=
" card_type = 'sepa_debit',";
1166 $sql .=
" stripe_account= '" . $this->db->escape($cu->id .
"@" . $stripeacc) .
"',";
1167 $sql .=
" ext_payment_site = '".$this->db->escape($service).
"'";
1168 if (!empty($cs->mandate)) {
1169 $mandateservice = new \Stripe\Mandate($stripeacc);
1170 $mandate = $mandateservice->retrieve($cs->mandate);
1171 if (is_object($mandate) && is_object($mandate->payment_method_details) && is_object($mandate->payment_method_details->sepa_debit)) {
1172 $refmandate = $mandate->payment_method_details->sepa_debit->reference;
1174 $sql .=
", rum = '".$this->db->escape($refmandate).
"'";
1176 $sql .=
", comment = '".$this->db->escape($cs->mandate).
"'";
1177 $sql .=
", date_rum = '".$this->db->idate(
dol_now()).
"'";
1179 $sql .=
" WHERE rowid = ".((int)
$object->id);
1180 $sql .=
" AND type = 'ban'";
1181 $resql = $this->db->query($sql);
1183 $this->error = $this->db->lasterror();
1189 $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.
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='')
Decode a string with a symmetric encryption.