28require
'../../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
39use OAuth\Common\Storage\DoliStorage;
40use OAuth\Common\Consumer\Credentials;
43$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
44$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
48$action =
GETPOST(
'action',
'aZ09');
49$backtourl =
GETPOST(
'backtourl',
'alpha');
50$keyforprovider =
GETPOST(
'keyforprovider',
'aZ09');
51if (empty($keyforprovider) && !empty($_SESSION[
"oauthkeyforproviderbeforeoauthjump"]) && (
GETPOST(
'code') || $action ==
'delete')) {
52 $keyforprovider = $_SESSION[
"oauthkeyforproviderbeforeoauthjump"];
62$currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/stripelive_oauthcallback.php');
70$serviceFactory = new \OAuth\ServiceFactory();
71$httpClient = new \OAuth\Common\Http\Client\CurlClient();
75$serviceFactory->setHttpClient($httpClient);
78$storage =
new DoliStorage($db,
$conf, $keyforprovider);
81$keyforparamid =
'OAUTH_STRIPELIVE'.($keyforprovider ?
'-'.$keyforprovider :
'').
'_ID';
82$keyforparamsecret =
'OAUTH_STRIPELIVE'.($keyforprovider ?
'-'.$keyforprovider :
'').
'_SECRET';
83$credentials =
new Credentials(
86 $currentUri->getAbsoluteUri()
89$requestedpermissionsarray = array();
91 $requestedpermissionsarray = explode(
',',
GETPOST(
'state'));
105$servicesuffix = ($keyforprovider ?
'-'.$keyforprovider :
'');
106$sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"oauth_token SET service = 'StripeLive".$db->escape($servicesuffix).
"', entity = ".((int)
$conf->entity);
112$langs->load(
"oauth");
115 accessforbidden(
'Setup of service is not complete. Customer ID is missing');
118 accessforbidden(
'Setup of service is not complete. Secret key is missing');
126if ($action ==
'delete' && (!empty($user->admin) || $user->id ==
GETPOSTINT(
'userid'))) {
128 $storage->clearToken(
'StripeLive');
132 if (empty($backtourl)) {
133 $backtourl = DOL_URL_ROOT.
'/';
136 header(
'Location: '.$backtourl);
147 if ($apiService ===
null) {
150 '@phan-var-force OAuth\OAuth2\Service\AbstractService|OAuth\OAuth1\Service\AbstractService $apiService';
156 $token = $apiService->requestAccessToken(
GETPOST(
'code'));
161 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
162 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
164 header(
'Location: '.$backtourl);
167 print $e->getMessage();
171 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
172 $_SESSION[
"oauthkeyforproviderbeforeoauthjump"] = $keyforprovider;
173 $_SESSION[
'oauthstateanticsrf'] = $state;
178 if ($apiService ===
null) {
181 '@phan-var-force OAuth\OAuth2\Service\AbstractService|OAuth\OAuth1\Service\AbstractService $apiService';
182 $url = $apiService->getAuthorizationUri(array(
'state' =>
GETPOST(
'state')));
187 $url =
'https://connect.stripe.com/oauth/authorize?response_type=code&client_id=' .
getDolGlobalString($keyforparamid).
'&scope=read_write';
191 $url = DOL_URL_ROOT.
'/';
195 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.