26require
'../../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/includes/OAuth/bootstrap.php';
28use OAuth\Common\Storage\DoliStorage;
29use OAuth\Common\Consumer\Credentials;
32$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
33$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
37$action =
GETPOST(
'action',
'aZ09');
38$backtourl =
GETPOST(
'backtourl',
'alpha');
39$keyforprovider =
GETPOST(
'keyforprovider',
'aZ09');
40if (empty($keyforprovider) && !empty($_SESSION[
"oauthkeyforproviderbeforeoauthjump"]) && (
GETPOST(
'code') || $action ==
'delete')) {
41 $keyforprovider = $_SESSION[
"oauthkeyforproviderbeforeoauthjump"];
51$currentUri =
$uriFactory->createFromAbsolute($urlwithroot.
'/core/modules/oauth/stripetest_oauthcallback.php');
59$serviceFactory = new \OAuth\ServiceFactory();
60$httpClient = new \OAuth\Common\Http\Client\CurlClient();
64$serviceFactory->setHttpClient($httpClient);
67$storage =
new DoliStorage($db, $conf, $keyforprovider);
70$keyforparamid =
'OAUTH_STRIPETEST'.($keyforprovider ?
'-'.$keyforprovider :
'').
'_ID';
71$keyforparamsecret =
'OAUTH_STRIPETEST'.($keyforprovider ?
'-'.$keyforprovider :
'').
'_SECRET';
72$credentials =
new Credentials(
75 $currentUri->getAbsoluteUri()
78$requestedpermissionsarray = array();
80 $requestedpermissionsarray = explode(
',',
GETPOST(
'state'));
92$servicesuffix = ($keyforprovider ?
'-'.$keyforprovider :
'');
93$sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"oauth_token SET service = 'StripeTest".$db->escape($servicesuffix).
"', entity = ".((int) $conf->entity);
102 accessforbidden(
'Setup of service is not complete. Customer ID is missing');
105 accessforbidden(
'Setup of service is not complete. Secret key is missing');
114if ($action ==
'delete') {
115 $storage->clearToken(
'StripeTest');
119 header(
'Location: '.$backtourl);
135 $token = $apiService->requestAccessToken(
GETPOST(
'code'));
140 $backtourl = $_SESSION[
"backtourlsavedbeforeoauthjump"];
141 unset($_SESSION[
"backtourlsavedbeforeoauthjump"]);
143 if (empty($backtourl)) {
144 $backtourl = DOL_URL_ROOT.
'/';
147 header(
'Location: '.$backtourl);
150 print $e->getMessage();
153 $_SESSION[
"backtourlsavedbeforeoauthjump"] = $backtourl;
154 $_SESSION[
"oauthkeyforproviderbeforeoauthjump"] = $keyforprovider;
155 $_SESSION[
'oauthstateanticsrf'] = $state;
160 $url = $apiService->getAuthorizationUri(array(
'state'=>
GETPOST(
'state')));
164 $url =
'https://connect.stripe.com/oauth/authorize?response_type=code&client_id=' .
getDolGlobalString($keyforparamid).
'&scope=read_write';
168 $url = DOL_URL_ROOT.
'/';
172 header(
'Location: '.$url);
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.