Open Journal Systems  3.3.0
vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php
1 <?php
2 
3 namespace Omnipay\PayPal\Message;
4 
8 
12 class ExpressAuthorizeRequest extends AbstractRequest
13 {
14 
15  const DEFAULT_CALLBACK_TIMEOUT = 5;
16 
17  public function setCallback($callback)
18  {
19  return $this->setParameter('callback', $callback);
20  }
21 
22  public function getCallback()
23  {
24  return $this->getParameter('callback');
25  }
26 
27  public function setCallbackTimeout($callbackTimeout)
28  {
29  return $this->setParameter('callbackTimeout', $callbackTimeout);
30  }
31 
32  public function getCallbackTimeout()
33  {
34  return $this->getParameter('callbackTimeout');
35  }
36 
40  public function setShippingOptions($data)
41  {
42  $this->setParameter('shippingOptions', $data);
43  }
44 
48  public function getShippingOptions()
49  {
50  return $this->getParameter('shippingOptions');
51  }
52 
56  public function setBillingAgreement($data)
57  {
58  $this->setParameter('billingAgreement', $data);
59  }
60 
64  public function getBillingAgreement()
65  {
66  return $this->getParameter('billingAgreement');
67  }
68 
69  protected function validateCallback()
70  {
71  $callback = $this->getCallback();
72 
73  if (!empty($callback)) {
74  $shippingOptions = $this->getShippingOptions();
75 
76  if (empty($shippingOptions)) {
77  throw new InvalidRequestException(
78  'When setting a callback for the Instant Update API you must set shipping options'
79  );
80  } else {
81  $hasDefault = false;
82  foreach ($shippingOptions as $shippingOption) {
83  if ($shippingOption->isDefault()) {
84  $hasDefault = true;
85  continue;
86  }
87  }
88 
89  if (!$hasDefault) {
90  throw new InvalidRequestException(
91  'One of the supplied shipping options must be set as default'
92  );
93  }
94  }
95  }
96  }
97 
98  public function getData()
99  {
100  $this->validate('amount', 'returnUrl', 'cancelUrl');
101  $this->validateCallback();
102 
103  $data = $this->getBaseData();
104  $data['METHOD'] = 'SetExpressCheckout';
105  $data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Authorization';
106  $data['PAYMENTREQUEST_0_AMT'] = $this->getAmount();
107  $data['PAYMENTREQUEST_0_CURRENCYCODE'] = $this->getCurrency();
108  $data['PAYMENTREQUEST_0_INVNUM'] = $this->getTransactionId();
109  $data['PAYMENTREQUEST_0_DESC'] = $this->getDescription();
110 
111  // pp express specific fields
112  $data['SOLUTIONTYPE'] = $this->getSolutionType();
113  $data['LANDINGPAGE'] = $this->getLandingPage();
114  $data['RETURNURL'] = $this->getReturnUrl();
115  $data['CANCELURL'] = $this->getCancelUrl();
116  $data['HDRIMG'] = $this->getHeaderImageUrl();
117  $data['BRANDNAME'] = $this->getBrandName();
118  $data['NOSHIPPING'] = $this->getNoShipping();
119  $data['ALLOWNOTE'] = $this->getAllowNote();
120  $data['ADDROVERRIDE'] = $this->getAddressOverride();
121  $data['LOGOIMG'] = $this->getLogoImageUrl();
122  $data['CARTBORDERCOLOR'] = $this->getBorderColor();
123  $data['LOCALECODE'] = $this->getLocaleCode();
124  $data['CUSTOMERSERVICENUMBER'] = $this->getCustomerServiceNumber();
125 
126  $callback = $this->getCallback();
127 
128  if (!empty($callback)) {
129  $data['CALLBACK'] = $callback;
130  // callback timeout MUST be included and > 0
131  $timeout = $this->getCallbackTimeout();
132 
133  $data['CALLBACKTIMEOUT'] = $timeout > 0 ? $timeout : self::DEFAULT_CALLBACK_TIMEOUT;
134 
135  // if you're using a callback you MUST set shipping option(s)
136  $shippingOptions = $this->getShippingOptions();
137 
138  if (!empty($shippingOptions)) {
139  foreach ($shippingOptions as $index => $shipping) {
140  $data['L_SHIPPINGOPTIONNAME' . $index] = $shipping->getName();
141  $data['L_SHIPPINGOPTIONAMOUNT' . $index] = number_format($shipping->getAmount(), 2);
142  $data['L_SHIPPINGOPTIONISDEFAULT' . $index] = $shipping->isDefault() ? '1' : '0';
143 
144  if ($shipping->hasLabel()) {
145  $data['L_SHIPPINGOPTIONLABEL' . $index] = $shipping->getLabel();
146  }
147  }
148  }
149  }
150 
151  $data['MAXAMT'] = $this->getMaxAmount();
152  $data['PAYMENTREQUEST_0_TAXAMT'] = $this->getTaxAmount();
153  $data['PAYMENTREQUEST_0_SHIPPINGAMT'] = $this->getShippingAmount();
154  $data['PAYMENTREQUEST_0_HANDLINGAMT'] = $this->getHandlingAmount();
155  $data['PAYMENTREQUEST_0_SHIPDISCAMT'] = $this->getShippingDiscount();
156  $data['PAYMENTREQUEST_0_INSURANCEAMT'] = $this->getInsuranceAmount();
157  $data['PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID'] = $this->getSellerPaypalAccountId();
158 
159  $card = $this->getCard();
160  if ($card) {
161  $data['PAYMENTREQUEST_0_SHIPTONAME'] = $card->getName();
162  $data['PAYMENTREQUEST_0_SHIPTOSTREET'] = $card->getAddress1();
163  $data['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $card->getAddress2();
164  $data['PAYMENTREQUEST_0_SHIPTOCITY'] = $card->getCity();
165  $data['PAYMENTREQUEST_0_SHIPTOSTATE'] = $card->getState();
166  $data['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $card->getCountry();
167  $data['PAYMENTREQUEST_0_SHIPTOZIP'] = $card->getPostcode();
168  $data['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $card->getPhone();
169  $data['EMAIL'] = $card->getEmail();
170  }
171 
172  $billingAgreement = $this->getBillingAgreement();
173  if ($billingAgreement) {
174  $data['L_BILLINGTYPE0'] = $billingAgreement->getType();
175  $data['L_BILLINGAGREEMENTDESCRIPTION0'] = $billingAgreement->getDescription();
176 
177  if ($billingAgreement->hasPaymentType()) {
178  $data['L_PAYMENTTYPE0'] = $billingAgreement->getPaymentType();
179  }
180 
181  if ($billingAgreement->hasCustomAnnotation()) {
182  $data['L_BILLINGAGREEMENTCUSTOM0'] = $billingAgreement->getCustomAnnotation();
183  }
184  }
185 
186  $data = array_merge($data, $this->getItemData());
187 
188  return $data;
189  }
190 
191  protected function createResponse($data)
192  {
193  return $this->response = new ExpressAuthorizeResponse($this, $data);
194  }
195 }
Omnipay\PayPal\Message\AbstractRequest\getCustomerServiceNumber
getCustomerServiceNumber()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:254
Omnipay\PayPal\Message\AbstractRequest\getShippingAmount
getShippingAmount()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:192
Omnipay\PayPal\Message\AbstractRequest\getShippingDiscount
getShippingDiscount()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:212
Omnipay\PayPal\Message\AbstractRequest\getHandlingAmount
getHandlingAmount()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:202
Omnipay\Common\Message\AbstractRequest\getParameter
getParameter($key)
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:172
Omnipay\Common\Message\AbstractRequest\setParameter
setParameter($key, $value)
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:185
Omnipay\Common\Message\AbstractRequest\getCurrency
getCurrency()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:391
Omnipay\PayPal\Message\ExpressAuthorizeRequest\setBillingAgreement
setBillingAgreement($data)
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:56
Omnipay\PayPal\Message\AbstractRequest\getItemData
getItemData()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:298
Omnipay\PayPal\Message\AbstractRequest\getHeaderImageUrl
getHeaderImageUrl()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:102
Omnipay\PayPal\Message\AbstractRequest\getBrandName
getBrandName()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:132
Omnipay\Common\Message\AbstractRequest\getDescription
getDescription()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:461
Omnipay\PayPal\Message\AbstractRequest\getMaxAmount
getMaxAmount()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:172
Omnipay\PayPal\Message\ExpressAuthorizeRequest\getData
getData()
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:98
Omnipay\PayPal\Message\AbstractRequest\getSellerPaypalAccountId
getSellerPaypalAccountId()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:264
Omnipay\PayPal\Message\AbstractRequest\getInsuranceAmount
getInsuranceAmount()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:222
Omnipay\PayPal\Support\InstantUpdateApi\BillingAgreement
Definition: lib/vendor/omnipay/paypal/src/Support/InstantUpdateApi/BillingAgreement.php:7
Omnipay\Common\Exception\InvalidRequestException
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Exception/InvalidRequestException.php:10
Omnipay\PayPal\Message\AbstractRequest\getLandingPage
getLandingPage()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:92
Omnipay\PayPal\Message\ExpressAuthorizeRequest\validateCallback
validateCallback()
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:69
Omnipay\PayPal\Message\ExpressAuthorizeRequest\DEFAULT_CALLBACK_TIMEOUT
const DEFAULT_CALLBACK_TIMEOUT
Definition: lib/vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:15
Omnipay\Common\Message\AbstractRequest\getCancelUrl
getCancelUrl()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:596
Omnipay\PayPal\Message\AbstractRequest\getBorderColor
getBorderColor()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:122
Omnipay\PayPal\Message\ExpressAuthorizeRequest\getShippingOptions
getShippingOptions()
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:48
Omnipay\PayPal\Message\ExpressAuthorizeResponse
Definition: lib/vendor/omnipay/paypal/src/Message/ExpressAuthorizeResponse.php:10
Omnipay\PayPal\Message\ExpressAuthorizeRequest\getCallback
getCallback()
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:22
Omnipay\PayPal\Message\ExpressAuthorizeRequest\createResponse
createResponse($data)
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:191
Omnipay\PayPal\Message\AbstractRequest\getLocaleCode
getLocaleCode()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:232
Omnipay\PayPal\Message\AbstractRequest\getNoShipping
getNoShipping()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:142
Omnipay\PayPal\Message\AbstractRequest\getAddressOverride
getAddressOverride()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:162
Omnipay\Common\Message\AbstractRequest\validate
validate()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:226
Omnipay\PayPal\Message\ExpressAuthorizeRequest\getCallbackTimeout
getCallbackTimeout()
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:32
Omnipay\PayPal\Message\ExpressAuthorizeRequest\setCallback
setCallback($callback)
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:17
Omnipay\PayPal\Message\AbstractRequest\getTaxAmount
getTaxAmount()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:182
Omnipay\Common\Message\AbstractRequest\getCard
getCard()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:241
Omnipay\PayPal\Message\AbstractRequest\getLogoImageUrl
getLogoImageUrl()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:112
Omnipay\PayPal\Support\InstantUpdateApi\ShippingOption
Definition: lib/vendor/omnipay/paypal/src/Support/InstantUpdateApi/ShippingOption.php:5
Omnipay\PayPal\Message\ExpressAuthorizeRequest\setCallbackTimeout
setCallbackTimeout($callbackTimeout)
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:27
Omnipay\PayPal\Message\AbstractRequest\getAllowNote
getAllowNote()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:152
Omnipay\PayPal\Message\ExpressAuthorizeRequest\getBillingAgreement
getBillingAgreement()
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:64
Omnipay\PayPal\Message\AbstractRequest\getBaseData
getBaseData()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:282
Omnipay\PayPal\Message\ExpressAuthorizeRequest\setShippingOptions
setShippingOptions($data)
Definition: vendor/omnipay/paypal/src/Message/ExpressAuthorizeRequest.php:40
Omnipay\PayPal\Message\AbstractRequest\getSolutionType
getSolutionType()
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:82
Omnipay\PayPal\Message
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:6
Omnipay\Common\Message\AbstractRequest\getReturnUrl
getReturnUrl()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:575
Omnipay\Common\Message\AbstractRequest\getTransactionId
getTransactionId()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:484
Omnipay\Common\Message\AbstractRequest\getAmount
getAmount()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:327