30if (!defined(
'NOTOKENRENEWAL')) {
31 define(
'NOTOKENRENEWAL',
'1');
33if (!defined(
'NOREQUIREMENU')) {
34 define(
'NOREQUIREMENU',
'1');
36if (!defined(
'NOREQUIREHTML')) {
37 define(
'NOREQUIREHTML',
'1');
39if (!defined(
'NOREQUIREAJAX')) {
40 define(
'NOREQUIREAJAX',
'1');
42if (!defined(
'NOBROWSERNOTIF')) {
43 define(
'NOBROWSERNOTIF',
'1');
47require
'../../main.inc.php';
48require_once DOL_DOCUMENT_ROOT.
'/includes/stripe/stripe-php/init.php';
49require_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
60$action =
GETPOST(
'action',
'aZ09');
61$location =
GETPOST(
'location',
'alphanohtml');
62$stripeacc =
GETPOST(
'stripeacc',
'alphanohtml');
66if (!$user->hasRight(
'takepos',
'run')) {
71if (! $usestripeterminals) {
82if ($action ==
'getConnexionToken') {
86 global $stripearrayofkeysbyenv;
87 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
91 if (isset($location) && !empty($location)) {
92 $array[
'location'] = $location;
94 if (empty($stripeacc)) {
95 $connectionToken = \Stripe\Terminal\ConnectionToken::create($array);
97 $connectionToken = \Stripe\Terminal\ConnectionToken::create($array, array(
"stripe_account" => $stripeacc));
99 echo json_encode(array(
'secret' => $connectionToken->secret));
101 http_response_code(500);
102 echo json_encode([
'error' => $e->getMessage()]);
104} elseif ($action ==
'createPaymentIntent') {
106 $json_str = file_get_contents(
'php://input');
107 $json_obj = json_decode($json_str);
112 $object->fetch($json_obj->invoiceid);
115 $fulltag =
'INV='.$object->id.
'.CUS='.
$object->thirdparty->id;
119 $stripe =
new Stripe($db);
120 $customer = $stripe->customerStripe(
$object->thirdparty, $stripeacc, $servicestatus, 1);
122 $intent = $stripe->getPaymentIntent($json_obj->amount,
$object->multicurrency_code,
'',
'Stripe payment: '.$fulltag.(is_object(
$object) ?
' ref='.$object->ref :
''),
$object, $customer, $stripeacc, $servicestatus, 1,
'terminal', false, null, 0, 1);
124 echo json_encode(array(
'client_secret' => $intent->client_secret));
126 http_response_code(500);
127 echo json_encode([
'error' => $e->getMessage()]);
129} elseif ($action ==
'capturePaymentIntent') {
132 $json_str = file_get_contents(
'php://input');
133 $json_obj = json_decode($json_str);
134 if (empty($stripeacc)) {
135 $intent = \Stripe\PaymentIntent::retrieve($json_obj->id);
137 $intent = \Stripe\PaymentIntent::retrieve($json_obj->id, array(
"stripe_account" => $stripeacc));
139 $intent = $intent->capture();
141 echo json_encode($intent);
143 http_response_code(500);
144 echo json_encode([
'error' => $e->getMessage()]);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage invoices.
Stripe class @TODO No reason to extends CommonObject.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.