|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\FirstData\Message; |
| 4 | + |
| 5 | +/** |
| 6 | + * First Data Abstract Request |
| 7 | + */ |
| 8 | +abstract class GlobalAbstractRequest extends \Omnipay\Common\Message\AbstractRequest |
| 9 | +{ |
| 10 | + const API_VERSION = 'v11'; |
| 11 | + |
| 12 | + protected $liveEndpoint = 'https://api.globalgatewaye4.firstdata.com/transaction/'; |
| 13 | + protected $testEndpoint = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/'; |
| 14 | + |
| 15 | + /** |
| 16 | + * @var int - api transaction type |
| 17 | + */ |
| 18 | + protected $transactionType = '00'; |
| 19 | + /** |
| 20 | + * Transaction types |
| 21 | + */ |
| 22 | + const TRAN_PURCHASE = '00'; |
| 23 | + const TRAN_PREAUTH = '01'; |
| 24 | + const TRAN_PREAUTHCOMPLETE = '02'; |
| 25 | + const TRAN_FORCEDPOST = '03'; |
| 26 | + const TRAN_REFUND = '04'; |
| 27 | + const TRAN_PREAUTHONLY = '05'; |
| 28 | + const TRAN_PAYPALORDER = '07'; |
| 29 | + const TRAN_VOID = '13'; |
| 30 | + const TRAN_TAGGEDPREAUTHCOMPLETE = '32'; |
| 31 | + const TRAN_TAGGEDVOID = '33'; |
| 32 | + const TRAN_TAGGEDREFUND = '34'; |
| 33 | + const TRAN_CASHOUT = '83'; |
| 34 | + const TRAN_ACTIVATION = '85'; |
| 35 | + const TRAN_BALANCEINQUIRY = '86'; |
| 36 | + const TRAN_RELOAD = '88'; |
| 37 | + const TRAN_DEACTIVATION = '89'; |
| 38 | + |
| 39 | + protected static $cardTypes = array( |
| 40 | + 'visa' => 'Visa', |
| 41 | + 'mastercard' => 'Mastercard', |
| 42 | + 'discover' => 'Discover', |
| 43 | + 'amex' => 'American Express', |
| 44 | + 'diners_club' => 'Diners Club', |
| 45 | + 'jcb' => 'JCB', |
| 46 | + ); |
| 47 | + |
| 48 | + public function getGatewayid() |
| 49 | + { |
| 50 | + return $this->getParameter('gatewayid'); |
| 51 | + } |
| 52 | + |
| 53 | + public function setGatewayID($value) |
| 54 | + { |
| 55 | + return $this->setParameter('gatewayid', $value); |
| 56 | + } |
| 57 | + |
| 58 | + public function getPassword() |
| 59 | + { |
| 60 | + return $this->getParameter('password'); |
| 61 | + } |
| 62 | + |
| 63 | + public function setPassword($value) |
| 64 | + { |
| 65 | + return $this->setParameter('password', $value); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Set transaction type |
| 70 | + * @param int $transactionType |
| 71 | + * @return object |
| 72 | + */ |
| 73 | + public function setTransactionType($transactionType) |
| 74 | + { |
| 75 | + $this->transactionType = $transactionType; |
| 76 | + return $this; |
| 77 | + } |
| 78 | + /** |
| 79 | + * Return transaction type |
| 80 | + * @return int |
| 81 | + */ |
| 82 | + public function getTransactionType() |
| 83 | + { |
| 84 | + return $this->transactionType; |
| 85 | + } |
| 86 | + |
| 87 | + protected function getBaseData($method) |
| 88 | + { |
| 89 | + $data = array(); |
| 90 | + $data['gateway_id'] = $this->getGatewayID(); |
| 91 | + $data['password'] = $this->getPassword(); |
| 92 | + $data['transaction_type'] = $this->getTransactionType(); |
| 93 | + |
| 94 | + return $data; |
| 95 | + } |
| 96 | + |
| 97 | + protected function getHeaders() |
| 98 | + { |
| 99 | + return array( |
| 100 | + 'Content-Type: application/json; charset=UTF-8;', |
| 101 | + 'Accept: application/json' |
| 102 | + ); |
| 103 | + } |
| 104 | + |
| 105 | + public function getAVSHash() |
| 106 | + { |
| 107 | + $parts = array(); |
| 108 | + $parts[] = $this->getCard()->getAddress1(); |
| 109 | + $parts[] = $this->getCard()->getPostcode(); |
| 110 | + $parts[] = $this->getCard()->getCity(); |
| 111 | + $parts[] = $this->getCard()->getState(); |
| 112 | + $parts[] = $this->getCard()->getCountry(); |
| 113 | + return implode('|', $parts); |
| 114 | + } |
| 115 | + |
| 116 | + public function getData() |
| 117 | + { |
| 118 | + $this->setTransactionType($this->action); |
| 119 | + $data = $this->getBaseData('DoDirectPayment'); |
| 120 | + |
| 121 | + $this->validate('amount', 'card'); |
| 122 | + |
| 123 | + $data['amount'] = $this->getAmount(); |
| 124 | + $data['currency_code'] = $this->getCurrency(); |
| 125 | + $data['reference_no'] = $this->getTransactionId(); |
| 126 | + |
| 127 | + // add credit card details |
| 128 | + $data['credit_card_type'] = self::getCardType($this->getCard()->getBrand()); |
| 129 | + $data['cc_number'] = $this->getCard()->getNumber(); |
| 130 | + $data['cardholder_name'] = $this->getCard()->getName(); |
| 131 | + $data['cc_expiry'] = $this->getCard()->getExpiryDate('my'); |
| 132 | + $data['cc_verification_str2'] = $this->getCard()->getCvv(); |
| 133 | + $data['cc_verification_str1'] = $this->getAVSHash(); |
| 134 | + $data['cvd_presence_ind'] = 1; |
| 135 | + $data['cvd_code'] = $this->getCard()->getCvv(); |
| 136 | + |
| 137 | + $data['client_ip'] = $this->getClientIp(); |
| 138 | + $data['client_email'] = $this->getCard()->getEmail(); |
| 139 | + $data['language'] = strtoupper($this->getCard()->getCountry()); |
| 140 | + return $data; |
| 141 | + } |
| 142 | + |
| 143 | + public function sendData($data) |
| 144 | + { |
| 145 | + $client = $this->httpClient->post( |
| 146 | + $this->getEndpoint(), |
| 147 | + $this->getHeaders(), |
| 148 | + $data |
| 149 | + ); |
| 150 | + $client->getCurlOptions()->set(CURLOPT_PORT, 443); |
| 151 | + $httpResponse = $client->send(); |
| 152 | + return $this->createResponse($httpResponse->getBody()); |
| 153 | + } |
| 154 | + |
| 155 | + protected function getEndpoint() |
| 156 | + { |
| 157 | + return $this->getTestMode() ? $this->testEndpoint.self::API_VERSION : $this->liveEndpoint.self::API_VERSION; |
| 158 | + } |
| 159 | + |
| 160 | + protected function createResponse($data) |
| 161 | + { |
| 162 | + return $this->response = new GlobalResponse($this, $data); |
| 163 | + } |
| 164 | + |
| 165 | + public static function getCardType($type) |
| 166 | + { |
| 167 | + if (isset(self::$cardTypes[$type])) { |
| 168 | + return self::$cardTypes[$type]; |
| 169 | + } |
| 170 | + return $type; |
| 171 | + } |
| 172 | +} |
0 commit comments