27require
'../../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
29use OAuth\Common\Storage\DoliStorage;
30use OAuth\Common\Consumer\Credentials;
33$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
34$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
38$action =
GETPOST(
'action',
'aZ09');
39$backtourl =
GETPOST(
'backtourl',
'alpha');
40$keyforprovider =
GETPOST(
'keyforprovider',
'aZ09');
41if (empty($keyforprovider) && !empty($_SESSION[
"oauthkeyforproviderbeforeoauthjump"]) && (
GETPOST(
'code') || $action ==
'delete')) {
42 $keyforprovider = $_SESSION[
"oauthkeyforproviderbeforeoauthjump"];
52$currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/stripelive_oauthcallback.php');
60$serviceFactory = new \OAuth\ServiceFactory();
61$httpClient = new \OAuth\Common\Http\Client\CurlClient();
65$serviceFactory->setHttpClient($httpClient);
68$storage =
new DoliStorage($db, $conf, $keyforprovider);
71$keyforparamid =
'OAUTH_STRIPELIVE'.($keyforprovider ?
'-'.$keyforprovider :
'').
'_ID';
72$keyforparamsecret =
'OAUTH_STRIPELIVE'.($keyforprovider ?
'-'.$keyforprovider :
'').
'_SECRET';
73$credentials =
new Credentials(
76 $currentUri->getAbsoluteUri()
79$requestedpermissionsarray = array();
81 $requestedpermissionsarray = explode(
',',
GETPOST(
'state'));
95$servicesuffix = ($keyforprovider ?
'-'.$keyforprovider :
'');
96$sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"oauth_token SET service = 'StripeLive".$db->escape($servicesuffix).
"', entity = ".((int) $conf->entity);
102$langs->load(
"oauth");
105 accessforbidden(
'Setup of service is not complete. Customer ID is missing');
108 accessforbidden(
'Setup of service is not complete. Secret key is missing');
116if ($action ==
'delete' && (!empty($user->admin) || $user->id ==
GETPOSTINT(
'userid'))) {
118 $storage->clearToken(
'StripeLive');
122 if (empty($backtourl)) {
123 $backtourl = DOL_URL_ROOT.
'/';
126 header(
'Location: '.$backtourl);
137 if ($apiService ===
null) {
140 '@phan-var-force OAuth\OAuth2\Service\AbstractService|OAuth\OAuth1\Service\AbstractService $apiService';
146 $token = $apiService->requestAccessToken(
GETPOST(
'code'));
151 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
152 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
154 header(
'Location: '.$backtourl);
157 print $e->getMessage();
161 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
162 $_SESSION[
"oauthkeyforproviderbeforeoauthjump"] = $keyforprovider;
163 $_SESSION[
'oauthstateanticsrf'] = $state;
168 if ($apiService ===
null) {
171 '@phan-var-force OAuth\OAuth2\Service\AbstractService|OAuth\OAuth1\Service\AbstractService $apiService';
172 $url = $apiService->getAuthorizationUri(array(
'state' =>
GETPOST(
'state')));
177 $url =
'https://connect.stripe.com/oauth/authorize?response_type=code&client_id=' .
getDolGlobalString($keyforparamid).
'&scope=read_write';
181 $url = DOL_URL_ROOT.
'/';
185 header(
'Location: '.$url);
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
if(empty($keyforprovider) &&!empty($_SESSION["oauthkeyforproviderbeforeoauthjump"]) &&(GETPOST('code')|| $action=='delete')) $uriFactory
Create a new instance of the URI class with the current URI, stripping the query string.