$request = new GetAccessTokenRequest();
$request->requestEnvelope = $requestEnvelope;
/*
 * (Required) The request token from the response to RequestPermissions. 
 */
$request->token = $_REQUEST['Requesttoken'];
/*
 * (Required) The verification code returned in the redirect from PayPal to the return URL. 
 */
$request->verifier = $_REQUEST['Verifier'];
/*
 * 	 ## Creating service wrapper object
Creating service wrapper object to make API call and loading
Configuration::getAcctAndConfig() returns array that contains credential and config parameters
*/
$service = new PermissionsService(Configuration::getAcctAndConfig());
try {
    /* wrap API method calls on the service object with a try catch */
    $response = $service->GetAccessToken($request);
} catch (Exception $ex) {
    require 'Error.php';
    exit;
}
/* Display the API response back to the browser. */
$ack = strtoupper($response->responseEnvelope->ack);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
	<title>GetAccessToken - Response</title>
Пример #2
0
    $serverPort = $_SERVER['SERVER_PORT'];
    $url = dirname('http://' . $serverName . ':' . $serverPort . $_SERVER['REQUEST_URI']);
    $returnURL = $url . "/GetAccessToken.php";
    $cancelURL = $url . "/RequestPermissions.php";
    if (isset($_POST['chkScope'])) {
        $i = 0;
        foreach ($_POST['chkScope'] as $value) {
            $scope[$i] = $value;
            $i++;
        }
    }
    $requestEnvelope = new RequestEnvelope();
    $requestEnvelope->errorLanguage = "en_US";
    $request = new RequestPermissionsRequest($scope, $returnURL);
    $request->requestEnvelope = $requestEnvelope;
    $permissions = new PermissionsService('Permissions');
    $response = $permissions->RequestPermissions($request);
    /* Display the API response back to the browser.
    	 If the response from PayPal was a success, display the response parameters'
    	 If the response was an error, display the errors received using APIError.php.
    	 */
    $ack = strtoupper($response->responseEnvelope->ack);
    session_start();
    if ($ack != "SUCCESS") {
        $_SESSION['reshash'] = $response;
        $location = "APIError.php";
        header("Location: {$location}");
    }
} catch (Exception $ex) {
    throw new Exception('Error occurred in GetPermissions method: ' . $ex->getMessage());
}
Пример #3
0
/********************************************
 GetAccessTokenReceipt.php
 Called by GetAccessToken.php
 ********************************************/
$path = '../lib';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'services/Permissions/PermissionsService.php';
session_start();
try {
    $requestEnvelope = new RequestEnvelope();
    $requestEnvelope->errorLanguage = "en_US";
    $request = new GetAccessTokenRequest();
    $request->requestEnvelope = $requestEnvelope;
    $request->token = $_REQUEST['Requesttoken'];
    $request->verifier = $_REQUEST['Verifier'];
    $permissions = new PermissionsService('Permissions');
    $response = $permissions->GetAccessToken($request);
    /* Display the API response back to the browser.
    	 If the response from PayPal was a success, display the response parameters'
    	 If the response was an error, display the errors received using APIError.php.
    	 */
    $ack = strtoupper($response->responseEnvelope->ack);
    if ($ack != "SUCCESS") {
        $_SESSION['reshash'] = $response;
        $location = "APIError.php";
        header("Location: {$location}");
    }
} catch (Exception $ex) {
    throw new Exception('Error occurred in GetAccessTokenReceipt method');
}
?>
$serverName = $_SERVER['SERVER_NAME'];
$serverPort = $_SERVER['SERVER_PORT'];
$url = dirname('http://' . $serverName . ':' . $serverPort . $_SERVER['REQUEST_URI']);
$returnURL = $url . "/GetAccessToken.php";
$cancelURL = $url . "/RequestPermissions.php";
$scope = array();
if (isset($_POST['chkScope'])) {
    $i = 0;
    foreach ($_POST['chkScope'] as $value) {
        $scope[$i++] = $value;
    }
}
$requestEnvelope = new RequestEnvelope("en_US");
$request = new RequestPermissionsRequest($scope, $returnURL);
$request->requestEnvelope = $requestEnvelope;
$service = new PermissionsService('Permissions');
try {
    $response = $service->RequestPermissions($request);
} catch (Exception $ex) {
    require 'Error.php';
    exit;
}
/* Display the API response back to the browser.
 If the response from PayPal was a success, display the response parameters'
 If the response was an error, display the errors received using APIError.php.
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<div id="request_form">
 public function requestPerm()
 {
     $logger = new PPLoggingManager('GetAccessToken');
     // ##RequestPermissionsRequest
     // `Scope`, which can take at least 1 of the following permission
     // categories:
     //
     // * EXPRESS_CHECKOUT
     // * DIRECT_PAYMENT
     // * AUTH_CAPTURE
     // * AIR_TRAVEL
     // * TRANSACTION_SEARCH
     // * RECURRING_PAYMENTS
     // * ACCOUNT_BALANCE
     // * ENCRYPTED_WEBSITE_PAYMENTS
     // * REFUND
     // * BILLING_AGREEMENT
     // * REFERENCE_TRANSACTION
     // * MASS_PAY
     // * TRANSACTION_DETAILS
     // * NON_REFERENCED_CREDIT
     // * SETTLEMENT_CONSOLIDATION
     // * SETTLEMENT_REPORTING
     // * BUTTON_MANAGER
     // * MANAGE_PENDING_TRANSACTION_STATUS
     // * RECURRING_PAYMENT_REPORT
     // * EXTENDED_PRO_PROCESSING_REPORT
     // * EXCEPTION_PROCESSING_REPORT
     // * ACCOUNT_MANAGEMENT_PERMISSION
     // * INVOICING
     // * ACCESS_BASIC_PERSONAL_DATA
     // * ACCESS_ADVANCED_PERSONAL_DATA
     $scopeList = array();
     $scopeList[0] = "INVOICING";
     $scopeList[1] = "EXPRESS_CHECKOUT";
     // Create RequestPermissionsRequest object which takes mandatory params:
     //
     // * `Scope`
     // * `Callback` - Your callback function that specifies actions to take
     // after the account holder grants or denies the request.
     $requestPermissionsRequest = new RequestPermissionsRequest($scopeList, "http://localhost/callback");
     // ## Creating service wrapper object
     // Creating service wrapper object to make API call and loading
     // configuration file for your credentials and endpoint
     $service = new PermissionsService();
     try {
         // ## Making API call
         // Invoke the appropriate method corresponding to API in service
         // wrapper object
         $response = $service->RequestPermissions($requestPermissionsRequest);
     } catch (Exception $ex) {
         $logger->error("Error Message : " . $ex->getMessage());
     }
     // ## Accessing response parameters
     // You can access the response parameters using variables in
     // response object as shown below
     // ### Success values
     if ($response->responseEnvelope->ack == "Success") {
         // ###Redirecting to PayPal
         // Once you get the success response, user needs to redirect to
         // paypal to authorize. Construct the `redirectUrl` as follows,
         // `redirectURL=https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_grant-permission&request_token="+$response->token;`
         // Once you are done with authorization, you will be returning
         // back to `callback` url mentioned in your request. While
         // returning, PayPal will send two parameters in request:
         //
         // * `request_token`
         // * `token_verifier`
         // You have to use these values in `GetAccessToken` API call to
         // generate `AccessToken` and `TokenSecret`
         // A token from PayPal that enables the request to obtain permissions.
         $logger->log("Request_token : " . $response->token);
     } else {
         $logger->error("API Error Message : " . $response->error[0]->message);
     }
     return $response;
 }