|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * eWAY Rapid Direct Abstract Request |
| 4 | + */ |
| 5 | + |
| 6 | +namespace Omnipay\Eway\Message; |
| 7 | + |
| 8 | +/** |
| 9 | + * eWAY Rapid Direct Abstract Request |
| 10 | + * |
| 11 | + * This class forms the base class for eWAY Rapid Direct requests. |
| 12 | + * |
| 13 | + * @link https://eway.io/api-v3/#direct-connection |
| 14 | + */ |
| 15 | +abstract class RapidDirectAbstractRequest extends AbstractRequest |
| 16 | +{ |
| 17 | + public function getEncryptedCardNumber() |
| 18 | + { |
| 19 | + return $this->getParameter('encryptedCardNumber'); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Sets the encrypted card number, for use when submitting card data |
| 24 | + * encrypted using eWAY's client side encryption. |
| 25 | + * |
| 26 | + * @param string $value |
| 27 | + * @return RapidDirectAbstractRequest |
| 28 | + */ |
| 29 | + public function setEncryptedCardNumber($value) |
| 30 | + { |
| 31 | + return $this->setParameter('encryptedCardNumber', $value); |
| 32 | + } |
| 33 | + |
| 34 | + public function getEncryptedCardCvv() |
| 35 | + { |
| 36 | + return $this->getParameter('encryptedCardCvv'); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Sets the encrypted card cvv, for use when submitting card data |
| 41 | + * encrypted using eWAY's client side encryption. |
| 42 | + * |
| 43 | + * @param string $value |
| 44 | + * @return RapidDirectAbstractRequest |
| 45 | + */ |
| 46 | + public function setEncryptedCardCvv($value) |
| 47 | + { |
| 48 | + return $this->setParameter('encryptedCardCvv', $value); |
| 49 | + } |
| 50 | + |
| 51 | + protected function getBaseData() |
| 52 | + { |
| 53 | + |
| 54 | + $data = parent::getBaseData(); |
| 55 | + $data['TransactionType'] = $this->getTransactionType(); |
| 56 | + |
| 57 | + if ($this->getCardReference()) { |
| 58 | + $data['Customer']['TokenCustomerID'] = $this->getCardReference(); |
| 59 | + } else { |
| 60 | + $this->validate('card'); |
| 61 | + } |
| 62 | + |
| 63 | + if ($this->getCard()) { |
| 64 | + $data['Customer']['CardDetails'] = array(); |
| 65 | + $data['Customer']['CardDetails']['Name'] = $this->getCard()->getName(); |
| 66 | + $data['Customer']['CardDetails']['ExpiryMonth'] = $this->getCard()->getExpiryDate('m'); |
| 67 | + $data['Customer']['CardDetails']['ExpiryYear'] = $this->getCard()->getExpiryDate('y'); |
| 68 | + $data['Customer']['CardDetails']['CVN'] = $this->getCard()->getCvv(); |
| 69 | + |
| 70 | + if ($this->getEncryptedCardNumber()) { |
| 71 | + $data['Customer']['CardDetails']['Number'] = $this->getEncryptedCardNumber(); |
| 72 | + } else { |
| 73 | + $data['Customer']['CardDetails']['Number'] = $this->getCard()->getNumber(); |
| 74 | + } |
| 75 | + |
| 76 | + if ($this->getEncryptedCardCvv()) { |
| 77 | + $data['Customer']['CardDetails']['CVN'] = $this->getEncryptedCardCvv(); |
| 78 | + } else { |
| 79 | + $data['Customer']['CardDetails']['CVN'] = $this->getCard()->getCvv(); |
| 80 | + } |
| 81 | + |
| 82 | + if ($this->getCard()->getStartMonth() and $this->getCard()->getStartYear()) { |
| 83 | + $data['Customer']['CardDetails']['StartMonth'] = $this->getCard()->getStartDate('m'); |
| 84 | + $data['Customer']['CardDetails']['StartYear'] = $this->getCard()->getStartDate('y'); |
| 85 | + } |
| 86 | + |
| 87 | + if ($this->getCard()->getIssueNumber()) { |
| 88 | + $data['Customer']['CardDetails']['IssueNumber'] = $this->getCard()->getIssueNumber(); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + if ($this->getItems()) { |
| 93 | + $data['Items'] = $this->getItemData(); |
| 94 | + } |
| 95 | + |
| 96 | + return $data; |
| 97 | + } |
| 98 | + |
| 99 | + public function sendData($data) |
| 100 | + { |
| 101 | + $httpResponse = $this->httpClient->post($this->getEndpoint(), null, json_encode($data)) |
| 102 | + ->setAuth($this->getApiKey(), $this->getPassword()) |
| 103 | + ->send(); |
| 104 | + |
| 105 | + return $this->response = new RapidResponse($this, $httpResponse->json()); |
| 106 | + } |
| 107 | +} |
0 commit comments