4 use PayPal\Common\PPModel;
5 use PayPal\Rest\IResource;
7 use PayPal\Rest\ApiContext;
8 use PayPal\Api\Payment;
9 use PayPal\Api\PaymentHistory;
10 use PayPal\Transport\PPRestCall;
12 class Payment extends PPModel implements IResource {
14 private static $credential;
18 * @deprecated. Pass ApiContext to create/get methods instead
20 public static function setCredential($credential) {
21 self::$credential = $credential;
25 * Identifier of the payment resource created.
28 public function setId($id) {
34 * Identifier of the payment resource created.
37 public function getId() {
43 * Time the resource was created.
44 * @param string $create_time
46 public function setCreateTime($create_time) {
47 $this->create_time = $create_time;
52 * Time the resource was created.
55 public function getCreateTime() {
56 return $this->create_time;
60 * Time the resource was created.
61 * @param string $create_time
62 * @deprecated. Instead use setCreateTime
64 public function setCreate_time($create_time) {
65 $this->create_time = $create_time;
69 * Time the resource was created.
71 * @deprecated. Instead use getCreateTime
73 public function getCreate_time() {
74 return $this->create_time;
78 * Time the resource was last updated.
79 * @param string $update_time
81 public function setUpdateTime($update_time) {
82 $this->update_time = $update_time;
87 * Time the resource was last updated.
90 public function getUpdateTime() {
91 return $this->update_time;
95 * Time the resource was last updated.
96 * @param string $update_time
97 * @deprecated. Instead use setUpdateTime
99 public function setUpdate_time($update_time) {
100 $this->update_time = $update_time;
104 * Time the resource was last updated.
106 * @deprecated. Instead use getUpdateTime
108 public function getUpdate_time() {
109 return $this->update_time;
113 * Intent of the payment - Sale or Authorization or Order.
114 * @param string $intent
116 public function setIntent($intent) {
117 $this->intent = $intent;
122 * Intent of the payment - Sale or Authorization or Order.
125 public function getIntent() {
126 return $this->intent;
131 * Source of the funds for this payment represented by a PayPal account or a direct credit card.
132 * @param PayPal\Api\Payer $payer
134 public function setPayer($payer) {
135 $this->payer = $payer;
140 * Source of the funds for this payment represented by a PayPal account or a direct credit card.
141 * @return PayPal\Api\Payer
143 public function getPayer() {
149 * A payment can have more than one transaction, with each transaction establishing a contract between the payer and a payee
151 * @param PayPal\Api\Transaction $transactions
153 public function setTransactions($transactions) {
154 $this->transactions = $transactions;
159 * A payment can have more than one transaction, with each transaction establishing a contract between the payer and a payee
160 * @return PayPal\Api\Transaction
162 public function getTransactions() {
163 return $this->transactions;
168 * state of the payment
169 * @param string $state
171 public function setState($state) {
172 $this->state = $state;
177 * state of the payment
180 public function getState() {
186 * Redirect urls required only when using payment_method as PayPal - the only settings supported are return and cancel urls.
187 * @param PayPal\Api\RedirectUrls $redirect_urls
189 public function setRedirectUrls($redirect_urls) {
190 $this->redirect_urls = $redirect_urls;
195 * Redirect urls required only when using payment_method as PayPal - the only settings supported are return and cancel urls.
196 * @return PayPal\Api\RedirectUrls
198 public function getRedirectUrls() {
199 return $this->redirect_urls;
203 * Redirect urls required only when using payment_method as PayPal - the only settings supported are return and cancel urls.
204 * @param PayPal\Api\RedirectUrls $redirect_urls
205 * @deprecated. Instead use setRedirectUrls
207 public function setRedirect_urls($redirect_urls) {
208 $this->redirect_urls = $redirect_urls;
212 * Redirect urls required only when using payment_method as PayPal - the only settings supported are return and cancel urls.
213 * @return PayPal\Api\RedirectUrls
214 * @deprecated. Instead use getRedirectUrls
216 public function getRedirect_urls() {
217 return $this->redirect_urls;
223 * @param PayPal\Api\Links $links
225 public function setLinks($links) {
226 $this->links = $links;
232 * @return PayPal\Api\Links
234 public function getLinks() {
240 public function create($apiContext = null) {
241 $payLoad = $this->toJSON();
242 if ($apiContext == null) {
243 $apiContext = new ApiContext(self::$credential);
245 $call = new PPRestCall($apiContext);
246 $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment", "POST", $payLoad);
247 $this->fromJson($json);
251 public static function get($paymentId, $apiContext = null) {
252 if (($paymentId == null) || (strlen($paymentId) <= 0)) {
253 throw new \InvalidArgumentException("paymentId cannot be null or empty");
256 if ($apiContext == null) {
257 $apiContext = new ApiContext(self::$credential);
259 $call = new PPRestCall($apiContext);
260 $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment/$paymentId", "GET", $payLoad);
261 $ret = new Payment();
262 $ret->fromJson($json);
266 public function execute($paymentExecution, $apiContext = null) {
267 if ($this->getId() == null) {
268 throw new \InvalidArgumentException("Id cannot be null");
270 if (($paymentExecution == null)) {
271 throw new \InvalidArgumentException("paymentExecution cannot be null or empty");
273 $payLoad = $paymentExecution->toJSON();
274 if ($apiContext == null) {
275 $apiContext = new ApiContext(self::$credential);
277 $call = new PPRestCall($apiContext);
278 $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment/{$this->getId()}/execute", "POST", $payLoad);
279 $ret = new Payment();
280 $ret->fromJson($json);
284 public static function all($params, $apiContext = null) {
285 if (($params == null)) {
286 throw new \InvalidArgumentException("params cannot be null or empty");
289 $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, );
290 if ($apiContext == null) {
291 $apiContext = new ApiContext(self::$credential);
293 $call = new PPRestCall($apiContext);
294 $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)), "GET", $payLoad);
295 $ret = new PaymentHistory();
296 $ret->fromJson($json);