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';
109 $entity =
$conf->entity;
112 $sql =
"SELECT tokenstring";
113 $sql .=
" FROM ".MAIN_DB_PREFIX.
"oauth_token";
114 $sql .=
" WHERE service = '".$this->db->escape($mode).
"'";
115 $sql .=
" AND entity = ".((int) $entity);
117 $sql .=
" AND fk_soc = ".((int) $fk_soc);
119 $sql .=
" AND fk_soc IS NULL";
121 $sql .=
" AND fk_user IS NULL AND fk_adherent IS NULL";
123 dol_syslog(get_class($this).
"::getStripeAccount", LOG_DEBUG);
125 $result = $this->db->query($sql);
127 if ($this->db->num_rows($result)) {
128 $obj = $this->db->fetch_object($result);
129 $tokenstring = $obj->tokenstring;
132 $tmparray = json_decode($tokenstring);
133 $key = empty($tmparray->stripe_user_id) ?
'' : $tmparray->stripe_user_id;
142 dol_syslog(
"No dedicated Stripe Connect account available for entity ".
$conf->entity);
157 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societeaccount.class.php';
159 return $societeaccount->getCustomerAccount($id,
'stripe', $status, $site_account);
178 dol_syslog(
"customerStripe is called with the parameter object that is not loaded");
185 global $stripearrayofkeysbyenv;
186 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
188 $sql =
"SELECT sa.key_account as key_account, sa.entity";
189 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_account as sa";
190 $sql .=
" WHERE sa.fk_soc = ".((int)
$object->id);
191 $sql .=
" AND sa.entity IN (".getEntity(
'societe').
")";
192 $sql .=
" AND sa.site = 'stripe' AND sa.status = ".((int) $status);
193 $sql .=
" AND (sa.site_account IS NULL OR sa.site_account = '' OR sa.site_account = '".$this->db->escape($stripearrayofkeysbyenv[$status][
'publishable_key']).
"')";
194 $sql .=
" AND sa.key_account IS NOT NULL AND sa.key_account <> ''";
195 $sql .=
" ORDER BY sa.site_account DESC, sa.rowid DESC";
197 dol_syslog(get_class($this).
"::customerStripe search stripe customer id for thirdparty id=".
$object->id, LOG_DEBUG);
198 $resql = $this->db->query($sql);
200 $num = $this->db->num_rows($resql);
202 $obj = $this->db->fetch_object($resql);
203 $tiers = $obj->key_account;
205 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']);
210 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$tiers",
'expand[]' =>
'sources'));
213 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$tiers",
'expand[]' =>
'sources'), array(
"stripe_account" => $key));
217 $this->error = $e->getMessage();
219 } elseif ($createifnotlinkedtostripe) {
222 $dataforcustomer = array(
224 "description" =>
$object->name,
225 "metadata" => array(
'dol_id' =>
$object->id,
'dol_version' => DOL_VERSION,
'dol_entity' =>
$conf->entity,
'ipaddress' => $ipaddress)
245 global $stripearrayofkeysbyenv;
246 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
249 $customer = \Stripe\Customer::create($dataforcustomer);
251 $customer = \Stripe\Customer::create($dataforcustomer, array(
"stripe_account" => $key));
256 if (!empty($vatcleaned)) {
258 if (
$object->country_code && $isineec) {
260 $customer->createTaxId($customer->id, array(
'type' =>
'eu_vat',
'value' => $vatcleaned));
266 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
267 $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).
")";
268 $resql = $this->db->query($sql);
270 $this->error = $this->db->lasterror();
273 $this->error = $e->getMessage();
293 $stripepaymentmethod =
null;
297 global $stripearrayofkeysbyenv;
298 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
300 $stripepaymentmethod = \Stripe\PaymentMethod::retrieve((
string) $paymentmethod->id);
302 $stripepaymentmethod = \Stripe\PaymentMethod::retrieve((
string) $paymentmethod->id, array(
"stripe_account" => $key));
305 $this->error = $e->getMessage();
308 return $stripepaymentmethod;
321 $selectedreader =
null;
325 global $stripearrayofkeysbyenv;
326 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
328 $selectedreader = \Stripe\Terminal\Reader::retrieve((
string) $reader);
330 $stripepaymentmethod = \Stripe\Terminal\Reader::retrieve((
string) $reader, array(
"stripe_account" => $key));
333 $this->error = $e->getMessage();
336 return $selectedreader;
365 public function getPaymentIntent($amount, $currency_code, $tag, $description =
'',
$object =
null, $customer =
null, $key =
null, $status = 0, $usethirdpartyemailforreceiptemail = 0, $mode =
'automatic', $confirmnow =
false, $payment_method =
null, $off_session = 0, $noidempotency_key = 1, $did = 0)
369 dol_syslog(get_class($this).
"::getPaymentIntent description=".$description, LOG_INFO, 1);
373 if (empty($status)) {
374 $service =
'StripeTest';
376 $service =
'StripeLive';
379 $arrayzerounitcurrency = array(
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF');
380 if (!in_array($currency_code, $arrayzerounitcurrency)) {
381 $stripeamount = $amount * 100;
383 $stripeamount = $amount;
395 if (!in_array($currency_code, $arrayzerounitcurrency)) {
396 $stripefee = round($fee * 100);
398 $stripefee = round($fee);
401 $paymentintent =
null;
410 $sql =
"SELECT pi.ext_payment_id, pi.entity, pi.fk_facture, pi.sourcetype, pi.ext_payment_site";
411 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pi";
412 $sql .=
" WHERE pi.fk_facture = ".((int)
$object->id);
413 $sql .=
" AND pi.sourcetype = '".$this->db->escape(
$object->element).
"'";
414 $sql .=
" AND pi.entity IN (".getEntity(
'societe').
")";
415 $sql .=
" AND pi.ext_payment_site = '".$this->db->escape($service).
"'";
417 dol_syslog(get_class($this).
"::getPaymentIntent search stripe payment intent for object id = ".
$object->id, LOG_DEBUG);
418 $resql = $this->db->query($sql);
420 $num = $this->db->num_rows($resql);
422 $obj = $this->db->fetch_object($resql);
423 $intent = $obj->ext_payment_id;
425 dol_syslog(get_class($this).
"::getPaymentIntent found existing payment intent record");
428 global $stripearrayofkeysbyenv;
429 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
433 $paymentintent = \Stripe\PaymentIntent::retrieve($intent);
435 $paymentintent = \Stripe\PaymentIntent::retrieve($intent, array(
"stripe_account" => $key));
439 $this->error = $e->getMessage();
445 if (empty($paymentintent)) {
448 $metadata = array(
'dol_version' => DOL_VERSION,
'dol_entity' =>
$conf->entity,
'ipaddress' => $ipaddress,
'dol_noidempotency' => (
int) $noidempotency_key);
450 $metadata[
'dol_type'] =
$object->element;
451 $metadata[
'dol_id'] =
$object->id;
452 if (is_object(
$object->thirdparty) &&
$object->thirdparty->id > 0) {
453 $metadata[
'dol_thirdparty_id'] =
$object->thirdparty->id;
460 $paymentmethodtypes = array(
"card");
461 $descriptor =
dol_trunc($tag, 10,
'right',
'UTF-8', 1);
463 $paymentmethodtypes[] =
"sepa_debit";
467 $paymentmethodtypes[] =
"klarna";
470 $paymentmethodtypes[] =
"bancontact";
473 $paymentmethodtypes[] =
"ideal";
476 $paymentmethodtypes[] =
"giropay";
479 $paymentmethodtypes[] =
"sofort";
481 if ($mode ==
'terminal') {
483 $paymentmethodtypes = array(
"card_present");
485 $stripemode =
'manual';
490 $descriptioninpaymentintent = $description;
492 $dataforintent = array(
493 "confirm" => $confirmnow,
494 "confirmation_method" => $stripemode,
495 "amount" => $stripeamount,
496 "currency" => $currency_code,
497 "payment_method_types" => $paymentmethodtypes,
505 "description" => $descriptioninpaymentintent,
507 "setup_future_usage" =>
"on_session",
508 "metadata" => $metadata
511 $dataforintent[
"statement_descriptor_suffix"] = $descriptor;
512 $dataforintent[
"statement_descriptor"] = $descriptor;
514 if (!is_null($customer)) {
515 $dataforintent[
"customer"] = $customer;
521 unset($dataforintent[
'setup_future_usage']);
525 $dataforintent[
"off_session"] =
true;
528 unset($dataforintent[
'setup_future_usage']);
531 unset($dataforintent[
'setup_future_usage']);
534 unset($dataforintent[
'setup_future_usage']);
535 $dataforintent[
"capture_method"] =
"manual";
536 $dataforintent[
"confirmation_method"] =
"manual";
538 if (!is_null($payment_method)) {
539 $dataforintent[
"payment_method"] = $payment_method;
540 $description .=
' - '.$payment_method;
544 $dataforintent[
"application_fee_amount"] = $stripefee;
546 if ($usethirdpartyemailforreceiptemail && is_object(
$object) &&
$object->thirdparty->email) {
547 $dataforintent[
"receipt_email"] =
$object->thirdparty->email;
552 global $stripearrayofkeysbyenv;
553 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
555 $arrayofoptions = array();
556 if (empty($noidempotency_key)) {
557 $arrayofoptions[
"idempotency_key"] = $descriptioninpaymentintent;
561 $arrayofoptions[
"stripe_account"] = $key;
564 dol_syslog(get_class($this).
"::getPaymentIntent ".$stripearrayofkeysbyenv[$status][
'publishable_key'], LOG_DEBUG);
565 dol_syslog(get_class($this).
"::getPaymentIntent dataforintent to create paymentintent = ".var_export($dataforintent,
true));
567 $paymentintent = \Stripe\PaymentIntent::create($dataforintent, $arrayofoptions);
571 $paymentintentalreadyexists = 0;
575 dol_syslog(get_class($this).
"::getPaymentIntent search if payment intent already in prelevement_demande", LOG_DEBUG);
577 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande SET";
578 $sql .=
" ext_payment_site = '".$this->db->escape($service).
"',";
579 $sql .=
" ext_payment_id = '".$this->db->escape($paymentintent->id).
"'";
580 $sql .=
" WHERE rowid = ".((int) $did);
582 $resql = $this->db->query($sql);
584 $paymentintentalreadyexists++;
591 dol_syslog(get_class($this).
"::getPaymentIntent search if payment intent already in prelevement_demande", LOG_DEBUG);
593 $sql =
"SELECT pi.rowid";
594 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pi";
595 $sql .=
" WHERE pi.entity IN (".getEntity(
'societe').
")";
596 $sql .=
" AND pi.ext_payment_site = '".$this->db->escape($service).
"'";
597 $sql .=
" AND pi.ext_payment_id = '".$this->db->escape($paymentintent->id).
"'";
599 $resql = $this->db->query($sql);
601 $num = $this->db->num_rows($resql);
603 $obj = $this->db->fetch_object($resql);
605 $paymentintentalreadyexists++;
615 if (!$error && !$paymentintentalreadyexists) {
617 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_demande (date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site, amount)";
618 $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).
")";
619 $resql = $this->db->query($sql);
622 $this->error = $this->db->lasterror();
623 dol_syslog(get_class($this).
"::PaymentIntent failed to insert paymentintent with id=".$paymentintent->id.
" into database.", LOG_ERR);
627 $_SESSION[
"stripe_payment_intent"] = $paymentintent;
631 $this->error = $e->getMessage();
632 $this->code = $e->getStripeCode();
633 $this->declinecode = $e->getDeclineCode();
642 $this->error = $e->getMessage();
644 $this->declinecode =
'';
648 dol_syslog(get_class($this).
"::getPaymentIntent return error=".$error.
" this->error=".$this->error, LOG_INFO, -1);
651 return $paymentintent;
675 public function getSetupIntent($description,
$object, $customer, $key, $status, $usethirdpartyemailforreceiptemail = 0, $confirmnow =
false)
679 $noidempotency_key = 1;
681 dol_syslog(
"getSetupIntent description=".$description.
' confirmnow='.json_encode($confirmnow), LOG_INFO, 1);
685 if (empty($status)) {
686 $service =
'StripeTest';
688 $service =
'StripeLive';
693 if (empty($setupintent)) {
695 $metadata = array(
'dol_version' => DOL_VERSION,
'dol_entity' =>
$conf->entity,
'ipaddress' => $ipaddress,
'dol_noidempotency' => (
int) $noidempotency_key);
697 $metadata[
'dol_type'] =
$object->element;
698 $metadata[
'dol_id'] =
$object->id;
699 if (is_object(
$object->thirdparty) &&
$object->thirdparty->id > 0) {
700 $metadata[
'dol_thirdparty_id'] =
$object->thirdparty->id;
705 $paymentmethodtypes = array(
"card");
707 $paymentmethodtypes[] =
"sepa_debit";
710 $paymentmethodtypes[] =
"bancontact";
713 $paymentmethodtypes[] =
"ideal";
717 $paymentmethodtypes[] =
"sofort";
722 $descriptioninsetupintent = $description;
724 $dataforintent = array(
725 "confirm" => $confirmnow,
726 "payment_method_types" => $paymentmethodtypes,
734 "usage" =>
"off_session",
735 "metadata" => $metadata
737 if (!is_null($customer)) {
738 $dataforintent[
"customer"] = $customer;
740 if (!is_null($description)) {
741 $dataforintent[
"description"] = $descriptioninsetupintent;
747 if ($usethirdpartyemailforreceiptemail && is_object(
$object) &&
$object->thirdparty->email) {
748 $dataforintent[
"receipt_email"] =
$object->thirdparty->email;
753 global $stripearrayofkeysbyenv;
754 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status][
'secret_key']);
756 dol_syslog(get_class($this).
"::getSetupIntent ".$stripearrayofkeysbyenv[$status][
'publishable_key'], LOG_DEBUG);
757 dol_syslog(get_class($this).
"::getSetupIntent dataforintent to create setupintent = ".var_export($dataforintent,
true));
762 $setupintent = \Stripe\SetupIntent::create($dataforintent, array());
765 $setupintent = \Stripe\SetupIntent::create($dataforintent, array(
"stripe_account" => $key));
818 $this->error = $e->getMessage();
823 dol_syslog(
"getSetupIntent ".(is_object($setupintent) ? $setupintent->id :
''), LOG_INFO, -1);
826 dol_syslog(
"getSetupIntent return error=".$error, LOG_INFO, -1);
844 global
$conf, $user, $langs;
848 $sql =
"SELECT sa.stripe_card_ref, sa.proprio as owner_name, sa.exp_date_month, sa.exp_date_year, sa.number, sa.cvn";
849 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as sa";
850 $sql .=
" WHERE sa.rowid = ".((int)
$object->id);
851 $sql .=
" AND sa.type = 'card'";
853 dol_syslog(get_class($this).
"::cardStripe search stripe card id for paymentmode id=".
$object->id.
", stripeacc=".$stripeacc.
", status=".$status.
", createifnotlinkedtostripe=".$createifnotlinkedtostripe, LOG_DEBUG);
854 $resql = $this->db->query($sql);
856 $num = $this->db->num_rows($resql);
858 $obj = $this->db->fetch_object($resql);
859 $cardref = $obj->stripe_card_ref;
860 dol_syslog(get_class($this).
"::cardStripe cardref=".$cardref);
863 if (empty($stripeacc)) {
864 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
865 $card = $cu->sources->retrieve($cardref);
867 $card = \Stripe\PaymentMethod::retrieve($cardref);
870 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
872 $card = $cu->sources->retrieve($cardref);
875 $card = \Stripe\PaymentMethod::retrieve($cardref);
879 $this->error = $e->getMessage();
882 } elseif ($createifnotlinkedtostripe) {
884 $exp_date_month = $obj->exp_date_month;
885 $exp_date_year = $obj->exp_date_year;
886 $number = $obj->number;
888 $cardholdername = $obj->owner_name;
892 $dataforcard = array(
895 'exp_month' => $exp_date_month,
896 'exp_year' => $exp_date_year,
899 'name' => $cardholdername
902 'dol_type' =>
$object->element,
904 'dol_version' => DOL_VERSION,
905 'dol_entity' =>
$conf->entity,
906 'ipaddress' => $ipaddress
914 if (empty($stripeacc)) {
916 dol_syslog(
"Try to create card with dataforcard = ".json_encode($dataforcard));
917 $card = $cu->sources->create($dataforcard);
919 $this->error =
'Creation of card on Stripe has failed';
923 if (!empty($stripeacc)) {
924 $connect = $stripeacc.
'/';
926 $url =
'https://dashboard.stripe.com/'.$connect.
'test/customers/'.$cu->id;
928 $url =
'https://dashboard.stripe.com/'.$connect.
'customers/'.$cu->id;
930 $urtoswitchonstripe =
'<a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe'),
'globe').
'</a>';
933 $this->error = str_replace(
'{s1}', $urtoswitchonstripe, $langs->trans(
'CreationOfPaymentModeMustBeDoneFromStripeInterface',
'{s1}'));
937 dol_syslog(
"Try to create card with dataforcard = ".json_encode($dataforcard));
938 $card = $cu->sources->create($dataforcard, array(
"stripe_account" => $stripeacc));
940 $this->error =
'Creation of card on Stripe has failed';
944 if (!empty($stripeacc)) {
945 $connect = $stripeacc.
'/';
947 $url =
'https://dashboard.stripe.com/'.$connect.
'test/customers/'.$cu->id;
949 $url =
'https://dashboard.stripe.com/'.$connect.
'customers/'.$cu->id;
951 $urtoswitchonstripe =
'<a href="'.$url.
'" target="_stripe">'.
img_picto($langs->trans(
'ShowInStripe'),
'globe').
'</a>';
954 $this->error = str_replace(
'{s1}', $urtoswitchonstripe, $langs->trans(
'CreationOfPaymentModeMustBeDoneFromStripeInterface',
'{s1}'));
959 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib";
960 $sql .=
" SET stripe_card_ref = '".$this->db->escape($card->id).
"', card_type = '".$this->db->escape($card->brand).
"',";
961 $sql .=
" country_code = '".$this->db->escape($card->country).
"',";
962 $sql .=
" approved = ".($card->cvc_check ==
'pass' ? 1 : 0);
963 $sql .=
" WHERE rowid = ".((int)
$object->id);
964 $sql .=
" AND type = 'card'";
965 $resql = $this->db->query($sql);
967 $this->error = $this->db->lasterror();
971 $this->error = $e->getMessage();
999 $sql =
"SELECT sa.stripe_card_ref, sa.proprio, sa.iban_prefix as iban, sa.rum";
1000 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as sa";
1001 $sql .=
" WHERE sa.rowid = ".((int)
$object->id);
1002 $sql .=
" AND sa.type = 'ban'";
1004 $soc =
new Societe($this->db);
1007 dol_syslog(get_class($this).
"::sepaStripe search stripe ban id for paymentmode id=".
$object->id.
", stripeacc=".$stripeacc.
", status=".$status.
", createifnotlinkedtostripe=".$createifnotlinkedtostripe, LOG_DEBUG);
1008 $resql = $this->db->query($sql);
1010 $num = $this->db->num_rows($resql);
1012 $obj = $this->db->fetch_object($resql);
1013 $cardref = $obj->stripe_card_ref;
1015 dol_syslog(get_class($this).
"::sepaStripe paymentmode=".$cardref);
1019 if (empty($stripeacc)) {
1020 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
1021 $sepa = $cu->sources->retrieve($cardref);
1023 $sepa = \Stripe\PaymentMethod::retrieve($cardref);
1026 if (!preg_match(
'/^pm_/', $cardref) && !empty($cu->sources)) {
1028 $sepa = $cu->sources->retrieve($cardref);
1031 $sepa = \Stripe\PaymentMethod::retrieve($cardref);
1035 $this->error = $e->getMessage();
1038 } elseif ($createifnotlinkedtostripe) {
1041 $metadata = array(
'dol_version' => DOL_VERSION,
'dol_entity' =>
$conf->entity,
'ipaddress' => $ipaddress);
1043 $metadata[
'dol_type'] =
$object->element;
1044 $metadata[
'dol_id'] =
$object->id;
1045 $metadata[
'dol_thirdparty_id'] = $soc->id;
1048 $description =
'SEPA for IBAN '.$iban;
1050 $dataforcard = array(
1051 'type' =>
'sepa_debit',
1052 "sepa_debit" => array(
'iban' => $iban),
1053 'billing_details' => array(
1054 'name' => $soc->name,
1055 'email' => !empty($soc->email) ? $soc->email :
"",
1057 "metadata" => $metadata
1060 if (!empty($soc->town)) {
1061 $dataforcard[
'billing_details'][
'address'][
'city'] = $soc->town;
1063 if (!empty($soc->country_code)) {
1064 $dataforcard[
'billing_details'][
'address'][
'country'] = $soc->country_code;
1066 if (!empty($soc->address)) {
1067 $dataforcard[
'billing_details'][
'address'][
'line1'] = $soc->address;
1069 if (!empty($soc->zip)) {
1070 $dataforcard[
'billing_details'][
'address'][
'postal_code'] = $soc->zip;
1072 if (!empty($soc->state)) {
1073 $dataforcard[
'billing_details'][
'address'][
'state'] = $soc->state;
1081 $service =
'StripeTest';
1084 $service =
'StripeLive';
1088 global $stripearrayofkeysbyenv;
1089 $stripeacc = $stripearrayofkeysbyenv[$servicestatus][
'secret_key'];
1091 dol_syslog(
"Try to create sepa_debit with data = ".json_encode($dataforcard));
1093 $s = new \Stripe\StripeClient($stripeacc);
1097 $sepa = $s->paymentMethods->create($dataforcard);
1099 $this->error =
'Creation of payment method sepa_debit on Stripe has failed';
1104 $dataforintent = array(0 => [
'description' => $description,
'payment_method_types' => [
'sepa_debit'],
'customer' => $cu->id,
'payment_method' => $sepa->id],
'metadata' => $metadata);
1106 $cs = $s->setupIntents->create($dataforintent);
1108 $cs = $s->setupIntents->confirm($cs->id, [
'mandate_data' => [
'customer_acceptance' => [
'type' =>
'offline']]]);
1112 $this->error =
'Link SEPA <-> Customer failed';
1115 dol_syslog(
"Update the payment mode of the customer");
1120 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib";
1121 $sql .=
" SET stripe_card_ref = '".$this->db->escape($sepa->id).
"',";
1122 $sql .=
" card_type = 'sepa_debit',";
1123 $sql .=
" stripe_account= '" . $this->db->escape($cu->id .
"@" . $stripeacc) .
"',";
1124 $sql .=
" ext_payment_site = '".$this->db->escape($service).
"'";
1125 if (!empty($cs->mandate)) {
1126 $mandateservice = new \Stripe\Mandate($stripeacc);
1127 $mandate = $mandateservice->retrieve($cs->mandate);
1128 if (is_object($mandate) && is_object($mandate->payment_method_details) && is_object($mandate->payment_method_details->sepa_debit)) {
1129 $refmandate = $mandate->payment_method_details->sepa_debit->reference;
1131 $sql .=
", rum = '".$this->db->escape($refmandate).
"'";
1133 $sql .=
", comment = '".$this->db->escape($cs->mandate).
"'";
1134 $sql .=
", date_rum = '".$this->db->idate(
dol_now()).
"'";
1136 $sql .=
" WHERE rowid = ".((int)
$object->id);
1137 $sql .=
" AND type = 'ban'";
1138 $resql = $this->db->query($sql);
1140 $this->error = $this->db->lasterror();
1146 $this->error =
'Stripe error: '.$e->getMessage().
'. Check the BAN information.';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
getSetupIntent($description, $object, $customer, $key, $status, $usethirdpartyemailforreceiptemail=0, $confirmnow=false)
Get the Stripe payment intent.
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).
getPaymentIntent($amount, $currency_code, $tag, $description='', $object=null, $customer=null, $key=null, $status=0, $usethirdpartyemailforreceiptemail=0, $mode='automatic', $confirmnow=false, $payment_method=null, $off_session=0, $noidempotency_key=1, $did=0)
Get the Stripe payment intent.
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.
getStripeAccount($mode='StripeTest', $fk_soc=0, $entity=-1)
Return main company OAuth Connect stripe account.
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)
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)
dol_now($mode='auto')
Return date for now.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.