|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\DataCash\Message; |
| 4 | + |
| 5 | +use DOMDocument; |
| 6 | +use SimpleXMLElement; |
| 7 | +use Omnipay\Common\Message\AbstractRequest; |
| 8 | + |
| 9 | +/** |
| 10 | + * DataCash Purchase Request |
| 11 | + */ |
| 12 | +class PurchaseRequest extends AbstractRequest |
| 13 | +{ |
| 14 | + protected $liveEndpoint = 'https://mars.transaction.datacash.com/Transaction'; |
| 15 | + protected $testEndpoint = 'https://testserver.datacash.com/Transaction'; |
| 16 | + |
| 17 | + public function getMerchantId() |
| 18 | + { |
| 19 | + return $this->getParameter('merchantId'); |
| 20 | + } |
| 21 | + |
| 22 | + public function setMerchantId($value) |
| 23 | + { |
| 24 | + return $this->setParameter('merchantId', $value); |
| 25 | + } |
| 26 | + |
| 27 | + public function getPassword() |
| 28 | + { |
| 29 | + return $this->getParameter('password'); |
| 30 | + } |
| 31 | + |
| 32 | + public function setPassword($value) |
| 33 | + { |
| 34 | + return $this->setParameter('password', $value); |
| 35 | + } |
| 36 | + |
| 37 | + public function getData() |
| 38 | + { |
| 39 | + $this->validate('amount', 'card', 'transactionId'); |
| 40 | + $this->getCard()->validate(); |
| 41 | + |
| 42 | + $data = new SimpleXMLElement('<Request/>'); |
| 43 | + |
| 44 | + $data->Authentication->client = $this->getMerchantId(); |
| 45 | + $data->Authentication->password = $this->getPassword(); |
| 46 | + |
| 47 | + $data->Transaction->TxnDetails->amount = $this->getAmount(); |
| 48 | + $data->Transaction->TxnDetails->amount->addAttribute('currency', $this->getCurrency()); |
| 49 | + $data->Transaction->TxnDetails->merchantreference = $this->getTransactionId(); |
| 50 | + |
| 51 | + $data->Transaction->CardTxn->Card->pan = $this->getCard()->getNumber(); |
| 52 | + $data->Transaction->CardTxn->Card->expirydate = $this->getCard()->getExpiryDate('m') . '/' . $this->getCard()->getExpiryDate('y'); |
| 53 | + |
| 54 | + $data->Transaction->CardTxn->method = 'auth'; |
| 55 | + |
| 56 | + return $data; |
| 57 | + } |
| 58 | + |
| 59 | + public function getEndpoint() |
| 60 | + { |
| 61 | + return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @param SimpleXMLElement $data |
| 66 | + * @return \Omnipay\Common\Message\ResponseInterface|Response |
| 67 | + */ |
| 68 | + public function sendData($data) |
| 69 | + { |
| 70 | + // post to DataCash |
| 71 | + $xml = $data->saveXML(); |
| 72 | + $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $xml)->send(); |
| 73 | + |
| 74 | + return $this->response = new Response($this, $httpResponse->getBody()); |
| 75 | + } |
| 76 | +} |
0 commit comments