Open Journal Systems  3.3.0
vendor/omnipay/paypal/src/Message/RestAuthorizeRequest.php
1 <?php
6 namespace Omnipay\PayPal\Message;
7 
216 class RestAuthorizeRequest extends AbstractRestRequest
217 {
218  public function getData()
219  {
220  $data = array(
221  'intent' => 'authorize',
222  'payer' => array(
223  'payment_method' => 'credit_card',
224  'funding_instruments' => array()
225  ),
226  'transactions' => array(
227  array(
228  'description' => $this->getDescription(),
229  'amount' => array(
230  'total' => $this->getAmount(),
231  'currency' => $this->getCurrency(),
232  ),
233  'invoice_number' => $this->getTransactionId()
234  )
235  ),
236  'experience_profile_id' => $this->getExperienceProfileId()
237  );
238 
239  $items = $this->getItems();
240  if ($items) {
241  $itemList = array();
242  foreach ($items as $n => $item) {
243  $itemList[] = array(
244  'name' => $item->getName(),
245  'description' => $item->getDescription(),
246  'quantity' => $item->getQuantity(),
247  'price' => $this->formatCurrency($item->getPrice()),
248  'currency' => $this->getCurrency()
249  );
250  }
251  $data['transactions'][0]['item_list']["items"] = $itemList;
252  }
253 
254  if ($this->getCardReference()) {
255  $this->validate('amount');
256 
257  $data['payer']['funding_instruments'][] = array(
258  'credit_card_token' => array(
259  'credit_card_id' => $this->getCardReference(),
260  ),
261  );
262  } elseif ($this->getCard()) {
263  $this->validate('amount', 'card');
264  $this->getCard()->validate();
265 
266  $data['payer']['funding_instruments'][] = array(
267  'credit_card' => array(
268  'number' => $this->getCard()->getNumber(),
269  'type' => $this->getCard()->getBrand(),
270  'expire_month' => $this->getCard()->getExpiryMonth(),
271  'expire_year' => $this->getCard()->getExpiryYear(),
272  'cvv2' => $this->getCard()->getCvv(),
273  'first_name' => $this->getCard()->getFirstName(),
274  'last_name' => $this->getCard()->getLastName(),
275  'billing_address' => array(
276  'line1' => $this->getCard()->getAddress1(),
277  //'line2' => $this->getCard()->getAddress2(),
278  'city' => $this->getCard()->getCity(),
279  'state' => $this->getCard()->getState(),
280  'postal_code' => $this->getCard()->getPostcode(),
281  'country_code' => strtoupper($this->getCard()->getCountry()),
282  )
283  )
284  );
285 
286  // There's currently a quirk with the REST API that requires line2 to be
287  // non-empty if it's present. Jul 14, 2014
288  $line2 = $this->getCard()->getAddress2();
289  if (!empty($line2)) {
290  $data['payer']['funding_instruments'][0]['credit_card']['billing_address']['line2'] = $line2;
291  }
292  } else {
293  $this->validate('amount', 'returnUrl', 'cancelUrl');
294 
295  unset($data['payer']['funding_instruments']);
296 
297  $data['payer']['payment_method'] = 'paypal';
298  $data['redirect_urls'] = array(
299  'return_url' => $this->getReturnUrl(),
300  'cancel_url' => $this->getCancelUrl(),
301  );
302  }
303 
304  return $data;
305  }
306 
312  public function getExperienceProfileId()
313  {
314  return $this->getParameter('experienceProfileId');
315  }
316 
323  public function setExperienceProfileId($value)
324  {
325  return $this->setParameter('experienceProfileId', $value);
326  }
327 
336  public function getDescription()
337  {
338  $id = $this->getTransactionId();
339  $desc = parent::getDescription();
340 
341  if (empty($id)) {
342  return $desc;
343  } elseif (empty($desc)) {
344  return $id;
345  } else {
346  return "$id : $desc";
347  }
348  }
349 
357  protected function getEndpoint()
358  {
359  return parent::getEndpoint() . '/payments/payment';
360  }
361 
362  protected function createResponse($data, $statusCode)
363  {
364  return $this->response = new RestAuthorizeResponse($this, $data, $statusCode);
365  }
366 }
Omnipay\PayPal\Message\RestAuthorizeRequest\getDescription
getDescription()
Definition: lib/vendor/omnipay/paypal/src/Message/RestAuthorizeRequest.php:335
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\Common\Message\AbstractRequest\getItems
getItems()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:529
Omnipay\PayPal\Message\RestAuthorizeRequest\getData
getData()
Definition: vendor/omnipay/paypal/src/Message/RestAuthorizeRequest.php:218
Omnipay\PayPal\Message\RestAuthorizeResponse
Definition: lib/vendor/omnipay/paypal/src/Message/RestAuthorizeResponse.php:13
Omnipay\PayPal\Message\RestAuthorizeRequest\getEndpoint
getEndpoint()
Definition: vendor/omnipay/paypal/src/Message/RestAuthorizeRequest.php:357
Omnipay\Common\Message\AbstractRequest\getCancelUrl
getCancelUrl()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:596
Omnipay\Common\Message\AbstractRequest\getCardReference
getCardReference()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:287
Omnipay\Common\Message\AbstractRequest\validate
validate()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:226
Omnipay\PayPal\Message\RestAuthorizeRequest\getExperienceProfileId
getExperienceProfileId()
Definition: lib/vendor/omnipay/paypal/src/Message/RestAuthorizeRequest.php:311
Omnipay\PayPal\Message\RestAuthorizeRequest\createResponse
createResponse($data, $statusCode)
Definition: vendor/omnipay/paypal/src/Message/RestAuthorizeRequest.php:362
Omnipay\Common\Message\AbstractRequest\getCard
getCard()
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:241
Omnipay\PayPal\Message\RestAuthorizeRequest\setExperienceProfileId
setExperienceProfileId($value)
Definition: vendor/omnipay/paypal/src/Message/RestAuthorizeRequest.php:323
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