23 if (!defined(
'NOTOKENRENEWAL')) {
24 define(
'NOTOKENRENEWAL',
'1');
26 if (!defined(
'NOREQUIREMENU')) {
27 define(
'NOREQUIREMENU',
'1');
29 if (!defined(
'NOREQUIREHTML')) {
30 define(
'NOREQUIREHTML',
'1');
32 if (!defined(
'NOREQUIREAJAX')) {
33 define(
'NOREQUIREAJAX',
'1');
35 if (!defined(
'NOBROWSERNOTIF')) {
36 define(
'NOBROWSERNOTIF',
'1');
40 require
'../../main.inc.php';
41 require_once DOL_DOCUMENT_ROOT.
'/includes/stripe/stripe-php/init.php';
42 require_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
45 $action =
GETPOST(
'action',
'aZ09');
46 $location =
GETPOST(
'location',
'alphanohtml');
47 $stripeacc =
GETPOST(
'stripeacc',
'alphanohtml');
48 $servicestatus =
GETPOST(
'servicestatus',
'int');
49 $amount =
GETPOST(
'amount',
'int');
51 if (empty($user->rights->takepos->run)) {
62 if ($action ==
'getConnexionToken') {
66 global $stripearrayofkeysbyenv;
67 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
71 if (isset($location) && !empty($location)) $array[
'location'] = $location;
72 if (empty($stripeacc)) {
73 $connectionToken = \Stripe\Terminal\ConnectionToken::create($array);
75 $connectionToken = \Stripe\Terminal\ConnectionToken::create($array, array(
"stripe_account" => $stripeacc));
77 echo json_encode(array(
'secret' => $connectionToken->secret));
79 http_response_code(500);
80 echo json_encode([
'error' => $e->getMessage()]);
82 } elseif ($action ==
'createPaymentIntent') {
84 $json_str = file_get_contents(
'php://input');
85 $json_obj = json_decode($json_str);
90 $object->fetch($json_obj->invoiceid);
91 $object->fetch_thirdparty();
93 $fulltag=
'INV='.$object->id.
'.CUS='.$object->thirdparty->id;
98 $customer = $stripe->customerStripe($object->thirdparty, $stripeacc, $servicestatus, 1);
100 $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);
102 echo json_encode(array(
'client_secret' => $intent->client_secret));
104 http_response_code(500);
105 echo json_encode([
'error' => $e->getMessage()]);
107 } elseif ($action ==
'capturePaymentIntent') {
110 $json_str = file_get_contents(
'php://input');
111 $json_obj = json_decode($json_str);
112 if (empty($stripeacc)) {
113 $intent = \Stripe\PaymentIntent::retrieve($json_obj->id);
115 $intent = \Stripe\PaymentIntent::retrieve($json_obj->id, array(
"stripe_account" => $stripeacc));
117 $intent = $intent->capture();
119 echo json_encode($intent);
121 http_response_code(500);
122 echo json_encode([
'error' => $e->getMessage()]);
Class to manage invoices.
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.
if(!defined('NOREQUIREMENU')) 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.