Open Monograph Press  3.3.0
vendor/omnipay/paypal/src/Message/RestAuthorizeResponse.php
1 <?php
6 namespace Omnipay\PayPal\Message;
7 
9 
13 class RestAuthorizeResponse extends RestResponse implements RedirectResponseInterface
14 {
15  public function isSuccessful()
16  {
17  return empty($this->data['error']) && $this->getCode() == 201;
18  }
19 
20  public function isRedirect()
21  {
22  return $this->getRedirectUrl() !== null;
23  }
24 
25  public function getRedirectUrl()
26  {
27  if (isset($this->data['links']) && is_array($this->data['links'])) {
28  foreach ($this->data['links'] as $key => $value) {
29  if ($value['rel'] == 'approval_url') {
30  return $value['href'];
31  }
32  }
33  }
34 
35  return null;
36  }
37 
46  public function getCompleteUrl()
47  {
48  if (isset($this->data['links']) && is_array($this->data['links'])) {
49  foreach ($this->data['links'] as $key => $value) {
50  if ($value['rel'] == 'execute') {
51  return $value['href'];
52  }
53  }
54  }
55 
56  return null;
57  }
58 
59  public function getTransactionReference()
60  {
61  // The transaction reference for a paypal purchase request or for a
62  // paypal create subscription request ends up in the execute URL
63  // in the links section of the response.
64  $completeUrl = $this->getCompleteUrl();
65  if (empty($completeUrl)) {
66  return parent::getTransactionReference();
67  }
68 
69  $urlParts = explode('/', $completeUrl);
70 
71  // The last element of the URL should be "execute"
72  $execute = end($urlParts);
73  if (!in_array($execute, array('execute', 'agreement-execute'))) {
74  return parent::getTransactionReference();
75  }
76 
77  // The penultimate element should be the transaction reference
78  return prev($urlParts);
79  }
80 
86  public function getRedirectMethod()
87  {
88  return 'GET';
89  }
90 
96  public function getRedirectData()
97  {
98  return null;
99  }
100 }
Omnipay\PayPal\Message\RestAuthorizeResponse\isSuccessful
isSuccessful()
Definition: vendor/omnipay/paypal/src/Message/RestAuthorizeResponse.php:15
Omnipay\Common\Message\RedirectResponseInterface
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/RedirectResponseInterface.php:18
Omnipay\PayPal\Message\RestAuthorizeResponse\getRedirectUrl
getRedirectUrl()
Definition: lib/vendor/omnipay/paypal/src/Message/RestAuthorizeResponse.php:25
Omnipay\PayPal\Message\RestAuthorizeResponse\isRedirect
isRedirect()
Definition: vendor/omnipay/paypal/src/Message/RestAuthorizeResponse.php:20
Omnipay\PayPal\Message\RestAuthorizeResponse\getRedirectMethod
getRedirectMethod()
Definition: vendor/omnipay/paypal/src/Message/RestAuthorizeResponse.php:86
Omnipay\PayPal\Message\RestAuthorizeResponse\getCompleteUrl
getCompleteUrl()
Definition: vendor/omnipay/paypal/src/Message/RestAuthorizeResponse.php:46
Omnipay\PayPal\Message\RestResponse\getCode
getCode()
Definition: lib/vendor/omnipay/paypal/src/Message/RestResponse.php:61
Omnipay\PayPal\Message\RestAuthorizeResponse\getRedirectData
getRedirectData()
Definition: vendor/omnipay/paypal/src/Message/RestAuthorizeResponse.php:96
Omnipay\PayPal\Message
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:6
Omnipay\PayPal\Message\RestAuthorizeResponse\getTransactionReference
getTransactionReference()
Definition: vendor/omnipay/paypal/src/Message/RestAuthorizeResponse.php:59