29if (!defined(
'NOTOKENRENEWAL')) {
30 define(
'NOTOKENRENEWAL',
'1');
32if (!defined(
'NOREQUIREMENU')) {
33 define(
'NOREQUIREMENU',
'1');
35if (!defined(
'NOREQUIREHTML')) {
36 define(
'NOREQUIREHTML',
'1');
38if (!defined(
'NOREQUIREAJAX')) {
39 define(
'NOREQUIREAJAX',
'1');
41if (!defined(
'NOBROWSERNOTIF')) {
42 define(
'NOBROWSERNOTIF',
'1');
46require
'../../main.inc.php';
47require_once DOL_DOCUMENT_ROOT.
'/includes/stripe/stripe-php/init.php';
48require_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
51$action =
GETPOST(
'action',
'aZ09');
52$location =
GETPOST(
'location',
'alphanohtml');
53$stripeacc =
GETPOST(
'stripeacc',
'alphanohtml');
57if (!$user->hasRight(
'takepos',
'run')) {
62if (! $usestripeterminals) {
73if ($action ==
'getConnexionToken') {
77 global $stripearrayofkeysbyenv;
78 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
82 if (isset($location) && !empty($location)) {
83 $array[
'location'] = $location;
85 if (empty($stripeacc)) {
86 $connectionToken = \Stripe\Terminal\ConnectionToken::create($array);
88 $connectionToken = \Stripe\Terminal\ConnectionToken::create($array, array(
"stripe_account" => $stripeacc));
90 echo json_encode(array(
'secret' => $connectionToken->secret));
92 http_response_code(500);
93 echo json_encode([
'error' => $e->getMessage()]);
95} elseif ($action ==
'createPaymentIntent') {
97 $json_str = file_get_contents(
'php://input');
98 $json_obj = json_decode($json_str);
103 $object->fetch($json_obj->invoiceid);
106 $fulltag =
'INV='.$object->id.
'.CUS='.
$object->thirdparty->id;
110 $stripe =
new Stripe($db);
111 $customer = $stripe->customerStripe(
$object->thirdparty, $stripeacc, $servicestatus, 1);
113 $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);
115 echo json_encode(array(
'client_secret' => $intent->client_secret));
117 http_response_code(500);
118 echo json_encode([
'error' => $e->getMessage()]);
120} elseif ($action ==
'capturePaymentIntent') {
123 $json_str = file_get_contents(
'php://input');
124 $json_obj = json_decode($json_str);
125 if (empty($stripeacc)) {
126 $intent = \Stripe\PaymentIntent::retrieve($json_obj->id);
128 $intent = \Stripe\PaymentIntent::retrieve($json_obj->id, array(
"stripe_account" => $stripeacc));
130 $intent = $intent->capture();
132 echo json_encode($intent);
134 http_response_code(500);
135 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.