1 <?php
2
3 namespace PayPal\Common;
4
5 use PayPal\Rest\ApiContext;
6 use PayPal\Rest\IResource;
7 use PayPal\Transport\PayPalRestCall;
8
9 10 11 12 13 14 15
16 class PayPalResourceModel extends PayPalModel implements IResource
17 {
18
19 20 21 22 23 24 25
26 public function setLinks($links)
27 {
28 $this->links = $links;
29 return $this;
30 }
31
32 33 34 35 36
37 public function getLinks()
38 {
39 return $this->links;
40 }
41
42 public function getLink($rel)
43 {
44 if (is_array($this->links)) {
45 foreach ($this->links as $link) {
46 if ($link->getRel() == $rel) {
47 return $link->getHref();
48 }
49 }
50 }
51 return null;
52 }
53
54 55 56 57 58 59
60 public function addLink($links)
61 {
62 if (!$this->getLinks()) {
63 return $this->setLinks(array($links));
64 } else {
65 return $this->setLinks(
66 array_merge($this->getLinks(), array($links))
67 );
68 }
69 }
70
71 72 73 74 75 76
77 public function removeLink($links)
78 {
79 return $this->setLinks(
80 array_diff($this->getLinks(), array($links))
81 );
82 }
83
84
85 86 87 88 89 90 91 92 93 94 95 96
97 protected static function executeCall($url, $method, $payLoad, $headers = array(), $apiContext = null, $restCall = null, $handlers = array('PayPal\Handler\RestHandler'))
98 {
99
100 $apiContext = $apiContext ? $apiContext : new ApiContext(self::$credential);
101 $restCall = $restCall ? $restCall : new PayPalRestCall($apiContext);
102
103
104 $json = $restCall->execute($handlers, $url, $method, $payLoad, $headers);
105 return $json;
106 }
107
108 109 110 111 112 113 114
115 public function updateAccessToken($refreshToken, $apiContext)
116 {
117 $apiContext = $apiContext ? $apiContext : new ApiContext(self::$credential);
118 $apiContext->getCredential()->updateAccessToken($apiContext->getConfig(), $refreshToken);
119 }
120 }
121