5fb1284ed862936c1198c9d3a631d592a6d50ac8
[WP-Plugins/glm-member-db.git] /
1 <?php
2 namespace PayPal\Api;
3
4 use PayPal\Common\PPModel;
5 use PayPal\Rest\IResource;
6 use PayPal\Rest\Call;
7 use PayPal\Rest\ApiContext;
8 use PayPal\Api\Sale;
9 use PayPal\Api\Refund;
10 use PayPal\Transport\PPRestCall;
11
12 class Sale extends PPModel implements IResource {
13
14         private static $credential;
15
16         /**
17          *
18          * @deprecated. Pass ApiContext to create/get methods instead
19          */
20         public static function setCredential($credential) {
21                 self::$credential = $credential;
22         }
23
24         /**
25          * Identifier of the authorization transaction.
26          * @param string $id
27          */
28         public function setId($id) {
29                 $this->id = $id;
30                 return $this;
31         }
32
33         /**
34          * Identifier of the authorization transaction.
35          * @return string
36          */
37         public function getId() {
38                 return $this->id;
39         }
40
41
42         /**
43          * Time the resource was created.
44          * @param string $create_time
45          */
46         public function setCreateTime($create_time) {
47                 $this->create_time = $create_time;
48                 return $this;
49         }
50
51         /**
52          * Time the resource was created.
53          * @return string
54          */
55         public function getCreateTime() {
56                 return $this->create_time;
57         }
58
59         /**
60          * Time the resource was created.
61          * @param string $create_time
62          * @deprecated. Instead use setCreateTime
63          */
64         public function setCreate_time($create_time) {
65                 $this->create_time = $create_time;
66                 return $this;
67         }
68         /**
69          * Time the resource was created.
70          * @return string
71          * @deprecated. Instead use getCreateTime
72          */
73         public function getCreate_time() {
74                 return $this->create_time;
75         }
76
77         /**
78          * Time the resource was last updated.
79          * @param string $update_time
80          */
81         public function setUpdateTime($update_time) {
82                 $this->update_time = $update_time;
83                 return $this;
84         }
85
86         /**
87          * Time the resource was last updated.
88          * @return string
89          */
90         public function getUpdateTime() {
91                 return $this->update_time;
92         }
93
94         /**
95          * Time the resource was last updated.
96          * @param string $update_time
97          * @deprecated. Instead use setUpdateTime
98          */
99         public function setUpdate_time($update_time) {
100                 $this->update_time = $update_time;
101                 return $this;
102         }
103         /**
104          * Time the resource was last updated.
105          * @return string
106          * @deprecated. Instead use getUpdateTime
107          */
108         public function getUpdate_time() {
109                 return $this->update_time;
110         }
111
112         /**
113          * Amount being collected.
114          * @param PayPal\Api\Amount $amount
115          */
116         public function setAmount($amount) {
117                 $this->amount = $amount;
118                 return $this;
119         }
120
121         /**
122          * Amount being collected.
123          * @return PayPal\Api\Amount
124          */
125         public function getAmount() {
126                 return $this->amount;
127         }
128
129
130         /**
131          * State of the sale transaction.
132          * @param string $state
133          */
134         public function setState($state) {
135                 $this->state = $state;
136                 return $this;
137         }
138
139         /**
140          * State of the sale transaction.
141          * @return string
142          */
143         public function getState() {
144                 return $this->state;
145         }
146
147
148         /**
149          * ID of the Payment resource that this transaction is based on.
150          * @param string $parent_payment
151          */
152         public function setParentPayment($parent_payment) {
153                 $this->parent_payment = $parent_payment;
154                 return $this;
155         }
156
157         /**
158          * ID of the Payment resource that this transaction is based on.
159          * @return string
160          */
161         public function getParentPayment() {
162                 return $this->parent_payment;
163         }
164
165         /**
166          * ID of the Payment resource that this transaction is based on.
167          * @param string $parent_payment
168          * @deprecated. Instead use setParentPayment
169          */
170         public function setParent_payment($parent_payment) {
171                 $this->parent_payment = $parent_payment;
172                 return $this;
173         }
174         /**
175          * ID of the Payment resource that this transaction is based on.
176          * @return string
177          * @deprecated. Instead use getParentPayment
178          */
179         public function getParent_payment() {
180                 return $this->parent_payment;
181         }
182
183         /**
184          * 
185          * @array
186          * @param PayPal\Api\Links $links
187          */
188         public function setLinks($links) {
189                 $this->links = $links;
190                 return $this;
191         }
192
193         /**
194          * 
195          * @return PayPal\Api\Links
196          */
197         public function getLinks() {
198                 return $this->links;
199         }
200
201
202
203         public static function get($saleId, $apiContext = null) {
204                 if (($saleId == null) || (strlen($saleId) <= 0)) {
205                         throw new \InvalidArgumentException("saleId cannot be null or empty");
206                 }
207                 $payLoad = "";
208                 if ($apiContext == null) {
209                         $apiContext = new ApiContext(self::$credential);
210                 }
211                 $call = new PPRestCall($apiContext);
212                 $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/sale/$saleId", "GET", $payLoad);
213                 $ret = new Sale();
214                 $ret->fromJson($json);
215                 return $ret;
216         }
217
218         public function refund($refund, $apiContext = null) {
219                 if ($this->getId() == null) {
220                         throw new \InvalidArgumentException("Id cannot be null");
221                 }
222                 if (($refund == null)) {
223                         throw new \InvalidArgumentException("refund cannot be null or empty");
224                 }
225                 $payLoad = $refund->toJSON();
226                 if ($apiContext == null) {
227                         $apiContext = new ApiContext(self::$credential);
228                 }
229                 $call = new PPRestCall($apiContext);
230                 $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/sale/{$this->getId()}/refund", "POST", $payLoad);
231                 $ret = new Refund();
232                 $ret->fromJson($json);
233                 return $ret;
234         }
235 }