This repository has been archived on 2026-04-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PayPal-PHP-SDK/lib/PayPal/Common/PayPalResourceModel.php
japatel f090642fae Helper Function to Retrieve Specific Link from Model Object
- Helper Methods in Payment and Agreement to get ApprovalLink
- Fixes #195
2014-12-18 15:41:11 -06:00

125 lines
2.9 KiB
PHP

<?php
namespace PayPal\Common;
use PayPal\Handler\IPayPalHandler;
use PayPal\Rest\ApiContext;
use PayPal\Rest\IResource;
use PayPal\Transport\PayPalRestCall;
/**
* Class PayPalResourceModel
* An Executable PayPalModel Class
*
* @property \PayPal\Api\Links[] links
* @package PayPal\Common
*/
class PayPalResourceModel extends PayPalModel implements IResource
{
/**
* OAuth Credentials to use for this call
*
* @var \PayPal\Auth\OAuthTokenCredential $credential
*/
protected static $credential;
/**
* Sets Credential
*
* @deprecated Pass ApiContext to create/get methods instead
* @param \PayPal\Auth\OAuthTokenCredential $credential
*/
public static function setCredential($credential)
{
self::$credential = $credential;
}
/**
* Sets Links
*
* @param \PayPal\Api\Links[] $links
*
* @return $this
*/
public function setLinks($links)
{
$this->links = $links;
return $this;
}
/**
* Gets Links
*
* @return \PayPal\Api\Links[]
*/
public function getLinks()
{
return $this->links;
}
public function getLink($rel)
{
foreach ($this->links as $link) {
if ($link->getRel() == $rel) {
return $link->getHref();
}
}
return null;
}
/**
* Append Links to the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function addLink($links)
{
if (!$this->getLinks()) {
return $this->setLinks(array($links));
} else {
return $this->setLinks(
array_merge($this->getLinks(), array($links))
);
}
}
/**
* Remove Links from the list.
*
* @param \PayPal\Api\Links $links
* @return $this
*/
public function removeLink($links)
{
return $this->setLinks(
array_diff($this->getLinks(), array($links))
);
}
/**
* Execute SDK Call to Paypal services
*
* @param string $url
* @param string $method
* @param string $payLoad
* @param array $headers
* @param ApiContext $apiContext
* @param PayPalRestCall $restCall
* @param array $handlers
* @return string json response of the object
*/
protected static function executeCall($url, $method, $payLoad, $headers = array(), $apiContext = null, $restCall = null, $handlers = array('PayPal\Handler\RestHandler'))
{
//Initialize the context and rest call object if not provided explicitly
$apiContext = $apiContext ? $apiContext : new ApiContext(self::$credential);
$restCall = $restCall ? $restCall : new PayPalRestCall($apiContext);
//Make the execution call
$json = $restCall->execute($handlers, $url, $method, $payLoad, $headers);
return $json;
}
}