execute() public method

public execute ( array $handlers, string $path, string $method, string $data = '', array $headers = [] )
$handlers array array of handlers
$path string Resource path relative to base service endpoint
$method string HTTP method - one of GET, POST, PUT, DELETE, PATCH etc
$data string Request payload
$headers array HTTP headers
 /**
  * returns user details
  *
  * @path /v1/identity/openidconnect/userinfo
  * @method GET
  * @param array $params (allowed values are access_token)
  * 					access_token - access token from the createFromAuthorizationCode / createFromRefreshToken calls  
  * @param PPApiContext $apiContext Optional API Context
  * @return PPOpenIdUserinfo
  */
 public static function getUserinfo($params, $apiContext = null)
 {
     static $allowedParams = array('schema' => 1);
     if (is_null($apiContext)) {
         $apiContext = new PPApiContext();
     }
     if (!array_key_exists('schema', $params)) {
         $params['schema'] = 'openid';
     }
     $requestUrl = "/v1/identity/openidconnect/userinfo?" . http_build_query(array_intersect_key($params, $allowedParams));
     $call = new PPRestCall($apiContext);
     $ret = new PPOpenIdUserinfo();
     $ret->fromJson($call->execute(array(new PPOpenIdHandler($apiContext)), $requestUrl, "GET", "", array('Authorization' => "Bearer " . $params['access_token'], 'Content-Type' => 'x-www-form-urlencoded')));
     return $ret;
 }
Beispiel #2
0
 public static function get($refundId, $apiContext = null)
 {
     if ($refundId == null || strlen($refundId) <= 0) {
         throw new \InvalidArgumentException("refundId cannot be null or empty");
     }
     $payLoad = "";
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PPRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/payments/refund/{$refundId}", "GET", $payLoad);
     $ret = new Refund();
     $ret->fromJson($json);
     return $ret;
 }
 /**
  * Creates an Access Token from an Refresh Token.
  *
  * @path /v1/identity/openidconnect/tokenservice
  * @method POST
  *
  * @param array      $params     (allowed values are grant_type and scope)
  *                               (required) client_id from developer portal
  *                               (required) client_secret from developer portal
  *                               (optional) refresh_token refresh token. If one is not passed, refresh token from the current object is used.
  *                               (optional) grant_type is the Token grant type. Defaults to refresh_token
  *                               (optional) scope is an array that either the same or a subset of the scope passed to the authorization request
  * @param APIContext $apiContext Optional API Context
  *
  * @return PPOpenIdTokeninfo
  */
 public function createFromRefreshToken($params, $apiContext = null)
 {
     static $allowedParams = array('grant_type' => 1, 'refresh_token' => 1, 'scope' => 1);
     if (is_null($apiContext)) {
         $apiContext = new PPApiContext();
     }
     if (!array_key_exists('grant_type', $params)) {
         $params['grant_type'] = 'refresh_token';
     }
     if (!array_key_exists('refresh_token', $params)) {
         $params['refresh_token'] = $this->getRefreshToken();
     }
     $call = new PPRestCall($apiContext);
     $this->fromJson($call->execute(array(new PPOpenIdHandler()), "/v1/identity/openidconnect/tokenservice", "POST", http_build_query(array_intersect_key($params, $allowedParams)), array('Content-Type' => 'application/x-www-form-urlencoded', 'Authorization' => 'Basic ' . base64_encode($params['client_id'] . ":" . $params['client_secret']))));
     return $this;
 }
 /**
  * All
  *
  * @param array                        $params
  * @param \PayPal\Rest\ApiContext|null $apiContext
  *
  * @return PaymentHistory
  * @throws \InvalidArgumentException
  */
 public static function all($params, $apiContext = null)
 {
     if ($params == null) {
         throw new \InvalidArgumentException("params cannot be null or empty");
     }
     $payLoad = "";
     $allowedParams = array('count' => 1, 'start_id' => 1, 'start_index' => 1, 'start_time' => 1, 'end_time' => 1, 'payee_id' => 1, 'sort_by' => 1, 'sort_order' => 1);
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PPRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)), "GET", $payLoad);
     $ret = new PaymentHistory();
     $ret->fromJson($json);
     return $ret;
 }
Beispiel #5
0
 /**
  * Refund
  *
  * @param \Paypal\Api\Refund           $refund
  * @param \PayPal\Rest\ApiContext|null $apiContext
  *
  * @return Refund
  * @throws \InvalidArgumentException
  */
 public function refund($refund, $apiContext = null)
 {
     if ($this->getId() == null) {
         throw new \InvalidArgumentException("Id cannot be null");
     }
     if ($refund == null) {
         throw new \InvalidArgumentException("refund cannot be null or empty");
     }
     $payLoad = $refund->toJSON();
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PPRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/payments/sale/{$this->getId()}/refund", "POST", $payLoad);
     $ret = new Refund();
     $ret->fromJson($json);
     return $ret;
 }
Beispiel #6
0
 public function delete($apiContext = null)
 {
     if ($this->getId() == null) {
         throw new \InvalidArgumentException("Id cannot be null");
     }
     $payLoad = "";
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PPRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/vault/credit-card/{$this->getId()}", "DELETE", $payLoad);
     return true;
 }
 /**
  * Reauthorize
  *
  * @param \PayPal\Rest\ApiContext|null $apiContext
  *
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function reauthorize($apiContext = null)
 {
     if ($this->getId() == null) {
         throw new \InvalidArgumentException("Id cannot be null");
     }
     $payLoad = $this->toJSON();
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PPRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/payments/authorization/{$this->getId()}/reauthorize", "POST", $payLoad);
     $this->fromJson($json);
     return $this;
 }