28if (!defined(
'NOTOKENRENEWAL')) {
29 define(
'NOTOKENRENEWAL',
'1');
31if (!defined(
'NOREQUIREMENU')) {
32 define(
'NOREQUIREMENU',
'1');
34if (!defined(
'NOREQUIREHTML')) {
35 define(
'NOREQUIREHTML',
'1');
37if (!defined(
'NOREQUIREAJAX')) {
38 define(
'NOREQUIREAJAX',
'1');
40if (!defined(
'NOBROWSERNOTIF')) {
41 define(
'NOBROWSERNOTIF',
'1');
45require
'../../main.inc.php';
46require_once DOL_DOCUMENT_ROOT.
'/includes/stripe/stripe-php/init.php';
47require_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
50$action =
GETPOST(
'action',
'aZ09');
51$location =
GETPOST(
'location',
'alphanohtml');
52$stripeacc =
GETPOST(
'stripeacc',
'alphanohtml');
56if (!$user->hasRight(
'takepos',
'run')) {
61if (! $usestripeterminals) {
72if ($action ==
'getConnexionToken') {
76 global $stripearrayofkeysbyenv;
77 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
81 if (isset($location) && !empty($location)) {
82 $array[
'location'] = $location;
84 if (empty($stripeacc)) {
85 $connectionToken = \Stripe\Terminal\ConnectionToken::create($array);
87 $connectionToken = \Stripe\Terminal\ConnectionToken::create($array, array(
"stripe_account" => $stripeacc));
89 echo json_encode(array(
'secret' => $connectionToken->secret));
91 http_response_code(500);
92 echo json_encode([
'error' => $e->getMessage()]);
94} elseif ($action ==
'createPaymentIntent') {
96 $json_str = file_get_contents(
'php://input');
97 $json_obj = json_decode($json_str);
102 $object->fetch($json_obj->invoiceid);
105 $fulltag=
'INV='.$object->id.
'.CUS='.
$object->thirdparty->id;
109 $stripe =
new Stripe($db);
110 $customer = $stripe->customerStripe(
$object->thirdparty, $stripeacc, $servicestatus, 1);
112 $intent = $stripe->getPaymentIntent($json_obj->amount,
$object->multicurrency_code,
null,
'Stripe payment: '.$fulltag.(is_object(
$object) ?
' ref='.$object->ref :
''),
$object, $customer, $stripeacc, $servicestatus, 1,
'terminal', false, null, 0, 1);
114 echo json_encode(array(
'client_secret' => $intent->client_secret));
116 http_response_code(500);
117 echo json_encode([
'error' => $e->getMessage()]);
119} elseif ($action ==
'capturePaymentIntent') {
122 $json_str = file_get_contents(
'php://input');
123 $json_obj = json_decode($json_str);
124 if (empty($stripeacc)) {
125 $intent = \Stripe\PaymentIntent::retrieve($json_obj->id);
127 $intent = \Stripe\PaymentIntent::retrieve($json_obj->id, array(
"stripe_account" => $stripeacc));
129 $intent = $intent->capture();
131 echo json_encode($intent);
133 http_response_code(500);
134 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 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.