|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\NABTransact\Message; |
| 4 | + |
| 5 | +/** |
| 6 | + * NABTransact Direct Post Authorize Request. |
| 7 | + */ |
| 8 | +class DirectPostAuthorizeRequest extends DirectPostAbstractRequest |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @var string |
| 12 | + */ |
| 13 | + public $txnType = '1'; |
| 14 | + |
| 15 | + /** |
| 16 | + * @return mixed |
| 17 | + */ |
| 18 | + public function getData() |
| 19 | + { |
| 20 | + $this->validate('amount', 'returnUrl', 'card'); |
| 21 | + |
| 22 | + $data = array(); |
| 23 | + $data['EPS_MERCHANT'] = $this->getMerchantId(); |
| 24 | + $data['EPS_TXNTYPE'] = $this->txnType; |
| 25 | + $data['EPS_IP'] = $this->getClientIp(); |
| 26 | + $data['EPS_AMOUNT'] = $this->getAmount(); |
| 27 | + $data['EPS_REFERENCEID'] = $this->getTransactionId(); |
| 28 | + $data['EPS_TIMESTAMP'] = gmdate('YmdHis'); |
| 29 | + $data['EPS_FINGERPRINT'] = $this->generateFingerprint($data); |
| 30 | + $data['EPS_RESULTURL'] = $this->getReturnUrl(); |
| 31 | + $data['EPS_CALLBACKURL'] = $this->getNotifyUrl() ?: $this->getReturnUrl(); |
| 32 | + $data['EPS_REDIRECT'] = 'TRUE'; |
| 33 | + $data['EPS_CURRENCY'] = $this->getCurrency(); |
| 34 | + |
| 35 | + $data = array_replace($data, $this->getCardData()); |
| 36 | + |
| 37 | + return $data; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @param array $data |
| 42 | + */ |
| 43 | + public function generateFingerprint(array $data) |
| 44 | + { |
| 45 | + $hash = implode( |
| 46 | + '|', |
| 47 | + array( |
| 48 | + $data['EPS_MERCHANT'], |
| 49 | + $this->getTransactionPassword(), |
| 50 | + $data['EPS_TXNTYPE'], |
| 51 | + $data['EPS_REFERENCEID'], |
| 52 | + $data['EPS_AMOUNT'], |
| 53 | + $data['EPS_TIMESTAMP'], |
| 54 | + ) |
| 55 | + ); |
| 56 | + |
| 57 | + return sha1($hash); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @param $data |
| 62 | + * |
| 63 | + * @return mixed |
| 64 | + */ |
| 65 | + public function sendData($data) |
| 66 | + { |
| 67 | + return $this->response = new DirectPostAuthorizeResponse($this, $data, $this->getEndpoint()); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @return mixed |
| 72 | + */ |
| 73 | + protected function getCardData() |
| 74 | + { |
| 75 | + $this->getCard()->validate(); |
| 76 | + |
| 77 | + $data = array(); |
| 78 | + |
| 79 | + $data['EPS_CARDNUMBER'] = $this->getCard()->getNumber(); |
| 80 | + $data['EPS_EXPIRYMONTH'] = $this->getCard()->getExpiryMonth(); |
| 81 | + $data['EPS_EXPIRYYEAR'] = $this->getCard()->getExpiryYear(); |
| 82 | + $data['EPS_CCV'] = $this->getCard()->getCvv(); |
| 83 | + |
| 84 | + return $data; |
| 85 | + } |
| 86 | +} |
0 commit comments