PayPalApiPayment

Class Payment.

Defined (1)

The class is defined in the following location(s).

/classes/lib/PayPal/Api/Payment.php  
  1. class Payment extends PayPalResourceModel 
  2. /** 
  3. * ID of the created payment, the 'transaction ID' 
  4. * @param string $id 
  5. * @return $this 
  6. */ 
  7. public function setId($id) 
  8. $this->id = $id; 
  9. return $this; 
  10.  
  11. /** 
  12. * ID of the created payment, the 'transaction ID' 
  13. * @return string 
  14. */ 
  15. public function getId() 
  16. return $this->id; 
  17.  
  18. /** 
  19. * Payment intent. 
  20. * Valid Values: ["sale", "authorize", "order"] 
  21. * @param string $intent 
  22. * @return $this 
  23. */ 
  24. public function setIntent($intent) 
  25. $this->intent = $intent; 
  26. return $this; 
  27.  
  28. /** 
  29. * Payment intent. 
  30. * @return string 
  31. */ 
  32. public function getIntent() 
  33. return $this->intent; 
  34.  
  35. /** 
  36. * Source of the funds for this payment represented by a PayPal account or a direct credit card. 
  37. * @param \PayPal\Api\Payer $payer 
  38. * @return $this 
  39. */ 
  40. public function setPayer($payer) 
  41. $this->payer = $payer; 
  42. return $this; 
  43.  
  44. /** 
  45. * Source of the funds for this payment represented by a PayPal account or a direct credit card. 
  46. * @return \PayPal\Api\Payer 
  47. */ 
  48. public function getPayer() 
  49. return $this->payer; 
  50.  
  51. /** 
  52. * Information that the merchant knows about the payer. This information is not definitive and only serves as a hint to the UI or any pre-processing logic. 
  53. * @param \PayPal\Api\PotentialPayerInfo $potential_payer_info 
  54. * @return $this 
  55. */ 
  56. public function setPotentialPayerInfo($potential_payer_info) 
  57. $this->potential_payer_info = $potential_payer_info; 
  58. return $this; 
  59.  
  60. /** 
  61. * Information that the merchant knows about the payer. This information is not definitive and only serves as a hint to the UI or any pre-processing logic. 
  62. * @return \PayPal\Api\PotentialPayerInfo 
  63. */ 
  64. public function getPotentialPayerInfo() 
  65. return $this->potential_payer_info; 
  66.  
  67. /** 
  68. * Receiver of funds for this payment. **Readonly for PayPal external REST payments.** 
  69. * @param \PayPal\Api\Payee $payee 
  70. * @return $this 
  71. */ 
  72. public function setPayee($payee) 
  73. $this->payee = $payee; 
  74. return $this; 
  75.  
  76. /** 
  77. * Receiver of funds for this payment. **Readonly for PayPal external REST payments.** 
  78. * @return \PayPal\Api\Payee 
  79. */ 
  80. public function getPayee() 
  81. return $this->payee; 
  82.  
  83. /** 
  84. * ID of the cart to execute the payment. 
  85. * @deprecated Not publicly available 
  86. * @param string $cart 
  87. * @return $this 
  88. */ 
  89. public function setCart($cart) 
  90. $this->cart = $cart; 
  91. return $this; 
  92.  
  93. /** 
  94. * ID of the cart to execute the payment. 
  95. * @deprecated Not publicly available 
  96. * @return string 
  97. */ 
  98. public function getCart() 
  99. return $this->cart; 
  100.  
  101. /** 
  102. * Transactional details including the amount and item details. 
  103. * @param \PayPal\Api\Transaction[] $transactions 
  104. * @return $this 
  105. */ 
  106. public function setTransactions($transactions) 
  107. $this->transactions = $transactions; 
  108. return $this; 
  109.  
  110. /** 
  111. * Transactional details including the amount and item details. 
  112. * @return \PayPal\Api\Transaction[] 
  113. */ 
  114. public function getTransactions() 
  115. return $this->transactions; 
  116.  
  117. /** 
  118. * Append Transactions to the list. 
  119. * @param \PayPal\Api\Transaction $transaction 
  120. * @return $this 
  121. */ 
  122. public function addTransaction($transaction) 
  123. if (!$this->getTransactions()) { 
  124. return $this->setTransactions(array($transaction)); 
  125. } else { 
  126. return $this->setTransactions( 
  127. array_merge($this->getTransactions(), array($transaction)) 
  128. ); 
  129.  
  130. /** 
  131. * Remove Transactions from the list. 
  132. * @param \PayPal\Api\Transaction $transaction 
  133. * @return $this 
  134. */ 
  135. public function removeTransaction($transaction) 
  136. return $this->setTransactions( 
  137. array_diff($this->getTransactions(), array($transaction)) 
  138. ); 
  139.  
  140. /** 
  141. * Applicable for advanced payments like multi seller payment (MSP) to support partial failures 
  142. * @deprecated Not publicly available 
  143. * @param \PayPal\Api\Error[] $failed_transactions 
  144. * @return $this 
  145. */ 
  146. public function setFailedTransactions($failed_transactions) 
  147. $this->failed_transactions = $failed_transactions; 
  148. return $this; 
  149.  
  150. /** 
  151. * Applicable for advanced payments like multi seller payment (MSP) to support partial failures 
  152. * @deprecated Not publicly available 
  153. * @return \PayPal\Api\Error[] 
  154. */ 
  155. public function getFailedTransactions() 
  156. return $this->failed_transactions; 
  157.  
  158. /** 
  159. * Append FailedTransactions to the list. 
  160. * @deprecated Not publicly available 
  161. * @param \PayPal\Api\Error $error 
  162. * @return $this 
  163. */ 
  164. public function addFailedTransaction($error) 
  165. if (!$this->getFailedTransactions()) { 
  166. return $this->setFailedTransactions(array($error)); 
  167. } else { 
  168. return $this->setFailedTransactions( 
  169. array_merge($this->getFailedTransactions(), array($error)) 
  170. ); 
  171.  
  172. /** 
  173. * Remove FailedTransactions from the list. 
  174. * @deprecated Not publicly available 
  175. * @param \PayPal\Api\Error $error 
  176. * @return $this 
  177. */ 
  178. public function removeFailedTransaction($error) 
  179. return $this->setFailedTransactions( 
  180. array_diff($this->getFailedTransactions(), array($error)) 
  181. ); 
  182.  
  183. /** 
  184. * Collection of PayPal generated billing agreement tokens. 
  185. * @param string[] $billing_agreement_tokens 
  186. * @return $this 
  187. */ 
  188. public function setBillingAgreementTokens($billing_agreement_tokens) 
  189. $this->billing_agreement_tokens = $billing_agreement_tokens; 
  190. return $this; 
  191.  
  192. /** 
  193. * Collection of PayPal generated billing agreement tokens. 
  194. * @return string[] 
  195. */ 
  196. public function getBillingAgreementTokens() 
  197. return $this->billing_agreement_tokens; 
  198.  
  199. /** 
  200. * Append BillingAgreementTokens to the list. 
  201. * @param string $billingAgreementToken 
  202. * @return $this 
  203. */ 
  204. public function addBillingAgreementToken($billingAgreementToken) 
  205. if (!$this->getBillingAgreementTokens()) { 
  206. return $this->setBillingAgreementTokens(array($billingAgreementToken)); 
  207. } else { 
  208. return $this->setBillingAgreementTokens( 
  209. array_merge($this->getBillingAgreementTokens(), array($billingAgreementToken)) 
  210. ); 
  211.  
  212. /** 
  213. * Remove BillingAgreementTokens from the list. 
  214. * @param string $billingAgreementToken 
  215. * @return $this 
  216. */ 
  217. public function removeBillingAgreementToken($billingAgreementToken) 
  218. return $this->setBillingAgreementTokens( 
  219. array_diff($this->getBillingAgreementTokens(), array($billingAgreementToken)) 
  220. ); 
  221.  
  222. /** 
  223. * Credit financing offered to payer on PayPal side. Returned in payment after payer opts-in 
  224. * @deprecated Not publicly available 
  225. * @param \PayPal\Api\CreditFinancingOffered $credit_financing_offered 
  226. * @return $this 
  227. */ 
  228. public function setCreditFinancingOffered($credit_financing_offered) 
  229. $this->credit_financing_offered = $credit_financing_offered; 
  230. return $this; 
  231.  
  232. /** 
  233. * Credit financing offered to payer on PayPal side. Returned in payment after payer opts-in 
  234. * @deprecated Not publicly available 
  235. * @return \PayPal\Api\CreditFinancingOffered 
  236. */ 
  237. public function getCreditFinancingOffered() 
  238. return $this->credit_financing_offered; 
  239.  
  240. /** 
  241. * Instructions for the payer to complete this payment. 
  242. * @param \PayPal\Api\PaymentInstruction $payment_instruction 
  243. * @return $this 
  244. */ 
  245. public function setPaymentInstruction($payment_instruction) 
  246. $this->payment_instruction = $payment_instruction; 
  247. return $this; 
  248.  
  249. /** 
  250. * Instructions for the payer to complete this payment. 
  251. * @return \PayPal\Api\PaymentInstruction 
  252. */ 
  253. public function getPaymentInstruction() 
  254. return $this->payment_instruction; 
  255.  
  256. /** 
  257. * Payment state. 
  258. * Valid Values: ["created", "approved", "failed", "partially_completed", "in_progress"] 
  259. * @param string $state 
  260. * @return $this 
  261. */ 
  262. public function setState($state) 
  263. $this->state = $state; 
  264. return $this; 
  265.  
  266. /** 
  267. * Payment state. 
  268. * @return string 
  269. */ 
  270. public function getState() 
  271. return $this->state; 
  272.  
  273. /** 
  274. * PayPal generated identifier for the merchant's payment experience profile. Refer to [this](https://developer.paypal.com/webapps/developer/docs/api/#payment-experience) link to create experience profile ID. 
  275. * @param string $experience_profile_id 
  276. * @return $this 
  277. */ 
  278. public function setExperienceProfileId($experience_profile_id) 
  279. $this->experience_profile_id = $experience_profile_id; 
  280. return $this; 
  281.  
  282. /** 
  283. * PayPal generated identifier for the merchant's payment experience profile. Refer to [this](https://developer.paypal.com/webapps/developer/docs/api/#payment-experience) link to create experience profile ID. 
  284. * @return string 
  285. */ 
  286. public function getExperienceProfileId() 
  287. return $this->experience_profile_id; 
  288.  
  289. /** 
  290. * free-form field for the use of clients to pass in a message to the payer 
  291. * @param string $note_to_payer 
  292. * @return $this 
  293. */ 
  294. public function setNoteToPayer($note_to_payer) 
  295. $this->note_to_payer = $note_to_payer; 
  296. return $this; 
  297.  
  298. /** 
  299. * free-form field for the use of clients to pass in a message to the payer 
  300. * @return string 
  301. */ 
  302. public function getNoteToPayer() 
  303. return $this->note_to_payer; 
  304.  
  305. /** 
  306. * Set of redirect URLs you provide only for PayPal-based payments. 
  307. * @param \PayPal\Api\RedirectUrls $redirect_urls 
  308. * @return $this 
  309. */ 
  310. public function setRedirectUrls($redirect_urls) 
  311. $this->redirect_urls = $redirect_urls; 
  312. return $this; 
  313.  
  314. /** 
  315. * Set of redirect URLs you provide only for PayPal-based payments. 
  316. * @return \PayPal\Api\RedirectUrls 
  317. */ 
  318. public function getRedirectUrls() 
  319. return $this->redirect_urls; 
  320.  
  321. /** 
  322. * Failure reason code returned when the payment failed for some valid reasons. 
  323. * Valid Values: ["UNABLE_TO_COMPLETE_TRANSACTION", "INVALID_PAYMENT_METHOD", "PAYER_CANNOT_PAY", "CANNOT_PAY_THIS_PAYEE", "REDIRECT_REQUIRED", "PAYEE_FILTER_RESTRICTIONS"] 
  324. * @param string $failure_reason 
  325. * @return $this 
  326. */ 
  327. public function setFailureReason($failure_reason) 
  328. $this->failure_reason = $failure_reason; 
  329. return $this; 
  330.  
  331. /** 
  332. * Failure reason code returned when the payment failed for some valid reasons. 
  333. * @return string 
  334. */ 
  335. public function getFailureReason() 
  336. return $this->failure_reason; 
  337.  
  338. /** 
  339. * Payment creation time as defined in [RFC 3339 Section 5.6](http://tools.ietf.org/html/rfc3339#section-5.6). 
  340. * @param string $create_time 
  341. * @return $this 
  342. */ 
  343. public function setCreateTime($create_time) 
  344. $this->create_time = $create_time; 
  345. return $this; 
  346.  
  347. /** 
  348. * Payment creation time as defined in [RFC 3339 Section 5.6](http://tools.ietf.org/html/rfc3339#section-5.6). 
  349. * @return string 
  350. */ 
  351. public function getCreateTime() 
  352. return $this->create_time; 
  353.  
  354. /** 
  355. * Payment update time as defined in [RFC 3339 Section 5.6](http://tools.ietf.org/html/rfc3339#section-5.6). 
  356. * @param string $update_time 
  357. * @return $this 
  358. */ 
  359. public function setUpdateTime($update_time) 
  360. $this->update_time = $update_time; 
  361. return $this; 
  362.  
  363. /** 
  364. * Payment update time as defined in [RFC 3339 Section 5.6](http://tools.ietf.org/html/rfc3339#section-5.6). 
  365. * @return string 
  366. */ 
  367. public function getUpdateTime() 
  368. return $this->update_time; 
  369.  
  370. /** 
  371. * Get Approval Link 
  372. * @return null|string 
  373. */ 
  374. public function getApprovalLink() 
  375. return $this->getLink(PayPalConstants::APPROVAL_URL); 
  376.  
  377. /** 
  378. * Create and process a payment by passing a payment object that includes the intent, payer, and transactions in the body of the request JSON. For PayPal payments, include redirect URLs in the payment object. 
  379. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. 
  380. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls 
  381. * @return Payment 
  382. */ 
  383. public function create($apiContext = null, $restCall = null) 
  384. $payLoad = $this->toJSON(); 
  385. $json = self::executeCall( 
  386. "/v1/payments/payment",  
  387. "POST",  
  388. $payLoad,  
  389. null,  
  390. $apiContext,  
  391. $restCall 
  392. ); 
  393. $this->fromJson($json); 
  394. return $this; 
  395.  
  396. /** 
  397. * Look up a particular payment resource by passing the payment_id in the request URI. 
  398. * @param string $paymentId 
  399. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. 
  400. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls 
  401. * @return Payment 
  402. */ 
  403. public static function get($paymentId, $apiContext = null, $restCall = null) 
  404. ArgumentValidator::validate($paymentId, 'paymentId'); 
  405. $payLoad = ""; 
  406. $json = self::executeCall( 
  407. "/v1/payments/payment/$paymentId",  
  408. "GET",  
  409. $payLoad,  
  410. null,  
  411. $apiContext,  
  412. $restCall 
  413. ); 
  414. $ret = new Payment(); 
  415. $ret->fromJson($json); 
  416. return $ret; 
  417.  
  418. /** 
  419. * Use this call to partially update the payment resource for the given identifier. Allowed objects are amount, shipping_address, invoice_id and custom. Please note that it is not possible to use patch after execute has been called. 
  420. * @param PatchRequest $patchRequest 
  421. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. 
  422. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls 
  423. * @return boolean 
  424. */ 
  425. public function update($patchRequest, $apiContext = null, $restCall = null) 
  426. ArgumentValidator::validate($this->getId(), "Id"); 
  427. ArgumentValidator::validate($patchRequest, 'patchRequest'); 
  428. $payLoad = $patchRequest->toJSON(); 
  429. self::executeCall( 
  430. "/v1/payments/payment/{$this->getId()}",  
  431. "PATCH",  
  432. $payLoad,  
  433. null,  
  434. $apiContext,  
  435. $restCall 
  436. ); 
  437. return true; 
  438.  
  439. /** 
  440. * Execute (complete) a PayPal payment that has been approved by the payer. Optionally update selective payment information when executing the payment. 
  441. * @param PaymentExecution $paymentExecution 
  442. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. 
  443. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls 
  444. * @return Payment 
  445. */ 
  446. public function execute($paymentExecution, $apiContext = null, $restCall = null) 
  447. ArgumentValidator::validate($this->getId(), "Id"); 
  448. ArgumentValidator::validate($paymentExecution, 'paymentExecution'); 
  449. $payLoad = $paymentExecution->toJSON(); 
  450. $json = self::executeCall( 
  451. "/v1/payments/payment/{$this->getId()}/execute",  
  452. "POST",  
  453. $payLoad,  
  454. null,  
  455. $apiContext,  
  456. $restCall 
  457. ); 
  458. $this->fromJson($json); 
  459. return $this; 
  460.  
  461. /** 
  462. * List payments in any state (created, approved, failed, etc.). Payments returned are the payments made to the merchant issuing the request. 
  463. * @param array $params 
  464. * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. 
  465. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls 
  466. * @return PaymentHistory 
  467. */ 
  468. public static function all($params, $apiContext = null, $restCall = null) 
  469. ArgumentValidator::validate($params, 'params'); 
  470. $payLoad = ""; 
  471. $allowedParams = array( 
  472. 'count' => 1,  
  473. 'start_id' => 1,  
  474. 'start_index' => 1,  
  475. 'start_time' => 1,  
  476. 'end_time' => 1,  
  477. 'payee_id' => 1,  
  478. 'sort_by' => 1,  
  479. 'sort_order' => 1,  
  480. ); 
  481. $json = self::executeCall( 
  482. "/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)),  
  483. "GET",  
  484. $payLoad,  
  485. null,  
  486. $apiContext,  
  487. $restCall 
  488. ); 
  489. $ret = new PaymentHistory(); 
  490. $ret->fromJson($json); 
  491. return $ret; 
  492.