22
33namespace Omnipay \Payware \Message ;
44
5- use Omnipay \Common \Message \AbstractRequest ;
5+ use Omnipay \Common \Exception \InvalidRequestException ;
6+ use Omnipay \Common \Exception \InvalidResponseException ;
67use Omnipay \Common \Message \NotificationInterface ;
78use Omnipay \Payware \Support \Helper ;
89use Omnipay \Payware \Traits \HasBooking ;
10+ use Omnipay \Payware \Traits \HasCreditCard ;
11+ use Omnipay \Payware \Traits \HasCVS ;
912use Omnipay \Payware \Traits \HasMerchant ;
1013
1114class CompletePurchaseRequest extends AbstractRequest implements NotificationInterface
1215{
1316 use HasMerchant;
1417 use HasBooking;
18+ use HasCreditCard;
19+ use HasCVS;
1520
1621 /**
1722 * @param int $authAmount
@@ -81,6 +86,23 @@ public function getPaymentDate()
8186 return $ this ->getParameter ('PaymentDate ' );
8287 }
8388
89+ /**
90+ * @param $transferOutAccount
91+ * @return CompletePurchaseRequest
92+ */
93+ public function setTransferOutAccount ($ transferOutAccount )
94+ {
95+ return $ this ->setParameter ('TransferOutAccount ' , $ transferOutAccount );
96+ }
97+
98+ /**
99+ * @return string
100+ */
101+ public function getTransferOutAccount ()
102+ {
103+ return $ this ->getParameter ('TransferOutAccount ' );
104+ }
105+
84106 /**
85107 * @param string $checkMacValue
86108 * @return CompletePurchaseRequest
@@ -98,22 +120,29 @@ public function getCheckMacValue()
98120 return $ this ->getParameter ('CheckMacValue ' );
99121 }
100122
123+ /**
124+ * @throws InvalidRequestException
125+ * @throws InvalidResponseException
126+ */
101127 public function getData ()
102128 {
103- return [
129+ return $ this -> checkMacValue (Helper:: filterEmpty ( [
104130 'MerchantId ' => $ this ->getMerchantId (),
105131 'TerminalId ' => $ this ->getTerminalId (),
106132 'PayType ' => $ this ->getPayType (),
107- 'Amount ' => (int ) $ this ->getAmount (),
108- 'AuthAmount ' => (int ) $ this ->getAuthAmount (),
109133 'BookingId ' => $ this ->getTransactionReference (),
110134 'CustOrderNo ' => $ this ->getTransactionId (),
135+ 'Amount ' => (int ) $ this ->getAmount (),
136+ 'AuthAmount ' => (int ) $ this ->getAuthAmount (),
111137 'RtnCode ' => $ this ->getRtnCode (),
138+ 'Card4no ' => $ this ->getCard4No (),
139+ 'Payment_no ' => $ this ->getPaymentNo (),
112140 'RtnMsg ' => $ this ->getRtnMsg (),
113141 'PaymentDate ' => Helper::parseDate ($ this ->getPaymentDate ()),
114- 'CheckMacValue ' => $ this ->getCheckMacValue (),
142+ 'TransferOutAccount ' => $ this ->getTransferOutAccount (),
115143 'SendType ' => $ this ->getSendType (),
116- ];
144+ 'CheckMacValue ' => $ this ->getCheckMacValue (),
145+ ]));
117146 }
118147
119148 /**
@@ -142,4 +171,32 @@ private function getNotification()
142171 {
143172 return ! $ this ->response ? $ this ->send () : $ this ->response ;
144173 }
174+
175+ /**
176+ * @return array
177+ * @throws InvalidResponseException
178+ */
179+ private function checkMacValue ($ data )
180+ {
181+ $ checkMacValue = $ this ->getCheckMacValue ();
182+ if (! $ checkMacValue || ! hash_equals ($ checkMacValue , $ this ->makeHash ($ data ))) {
183+ throw new InvalidResponseException ();
184+ }
185+
186+ return $ data ;
187+ }
188+
189+ /**
190+ * @param $data
191+ * @return false|string
192+ */
193+ private function makeHash ($ data )
194+ {
195+ $ keys = ['MerchantId ' , 'TerminalId ' , 'PayType ' , 'BookingId ' , 'CustOrderNo ' , 'Amount ' , 'RtnCode ' ];
196+ $ values = array_reduce ($ keys , static function ($ acc , $ key ) use ($ data ) {
197+ return $ acc .(array_key_exists ($ key , $ data ) ? $ data [$ key ] : '' );
198+ }, '' );
199+
200+ return hash_hmac ('sha1 ' , $ values , $ this ->getValidateKey ());
201+ }
145202}
0 commit comments