22
33namespace Payfast \Payfast \Controller \Notify ;
44
5- /**
6- * Copyright (c) 2024 Payfast (Pty) Ltd
7- * You (being anyone who is not Payfast (Pty) Ltd) may download and use this plugin / code in your own website
8- * in conjunction with a registered and active Payfast account. If your Payfast account is terminated for any reason,
9- * you may not use this plugin / code or part thereof.
10- * Except as expressly indicated in this licence, you may not use, copy, modify or distribute this plugin / code or
11- * part thereof in any way.
12- */
13-
145use Exception ;
156use LogicException ;
167use Magento \Framework \App \Action \HttpPostActionInterface ;
2718use Payfast \Payfast \Model \Config as PayfastConfig ;
2819use Payfast \Payfast \Model \Info ;
2920use Magento \Framework \Controller \ResultFactory ;
30- use Payfast \PayfastCommon \PayfastCommon ;
21+ use Payfast \PayfastCommon \Aggregator \ Request \ PaymentRequest ;
3122
32- /**
33- * Index class
34- */
3523class Index extends AbstractPayfast implements CsrfAwareActionInterface, HttpPostActionInterface
3624{
3725
@@ -42,14 +30,14 @@ class Index extends AbstractPayfast implements CsrfAwareActionInterface, HttpPos
4230 */
4331 public function execute (): ResultInterface
4432 {
45- $ debugMode = $ this ->getConfigData ('debug ' );
46- $ payfastCommon = new PayfastCommon ((bool )$ debugMode );
33+ $ debugMode = $ this ->getConfigData ('debug ' );
34+ $ paymentRequest = new PaymentRequest ((bool )$ debugMode );
4735
4836 $ moduleInfo = [
49- 'pfSoftwareName ' => 'Magento ' ,
50- 'pfSoftwareVer ' => '2.4.7 ' ,
37+ 'pfSoftwareName ' => 'Magento ' ,
38+ 'pfSoftwareVer ' => '2.4.7 ' ,
5139 'pfSoftwareModuleName ' => 'Payfast-Magento ' ,
52- 'pfModuleVer ' => '2.6 .0 '
40+ 'pfModuleVer ' => '2.7 .0 '
5341 ];
5442
5543 $ this ->_logger ->debug ('Notify: ' . json_encode ($ this ->request ->getPostValue ()));
@@ -65,9 +53,9 @@ public function execute(): ResultInterface
6553
6654 $ pfHost = $ this ->paymentMethod ->getPayfastHost ($ serverMode );
6755
68- $ payfastCommon ->pflog (' Payfast ITN call received ' );
56+ $ paymentRequest ->pflog (' Payfast ITN call received ' );
6957
70- $ payfastCommon ->pflog ('Server = ' . $ pfHost );
58+ $ paymentRequest ->pflog ('Server = ' . $ pfHost );
7159
7260 //// Notify Payfast that information has been received
7361 $ resultRaw = $ this ->resultFactory ->create (ResultFactory::TYPE_RAW );
@@ -87,58 +75,58 @@ public function execute(): ResultInterface
8775
8876 //// Get data sent by Payfast
8977 // Posted variables from ITN
90- $ pfData = PayfastCommon:: pfGetData ();
78+ $ pfData = $ paymentRequest -> pfGetData ();
9179
9280 if (empty ($ pfData )) {
9381 $ pfError = true ;
94- $ pfErrMsg = PayfastCommon ::PF_ERR_BAD_ACCESS ;
82+ $ pfErrMsg = $ paymentRequest ::PF_ERR_BAD_ACCESS ;
9583 }
9684
9785 //// Verify security signature
9886 if (!$ pfError ) {
99- $ payfastCommon ->pflog ('Verify security signature ' );
87+ $ paymentRequest ->pflog ('Verify security signature ' );
10088
10189 // If signature different, log for debugging
102- if (!$ payfastCommon ->pfValidSignature (
90+ if (!$ paymentRequest ->pfValidSignature (
10391 $ pfData ,
10492 $ pfParamString ,
10593 $ passPhrase
10694 )) {
10795 $ pfError = true ;
108- $ pfErrMsg = PayfastCommon ::PF_ERR_INVALID_SIGNATURE ;
96+ $ pfErrMsg = $ paymentRequest ::PF_ERR_INVALID_SIGNATURE ;
10997 }
11098 }
11199
112100 //// Get internal order and verify it hasn't already been processed
113101 if (!$ pfError ) {
114- $ payfastCommon ->pflog ("Check order hasn't been processed " );
102+ $ paymentRequest ->pflog ("Check order hasn't been processed " );
115103
116104 // Load order
117105 $ orderId = $ pfData [Info::M_PAYMENT_ID ];
118106
119107 $ this ->_order = $ this ->orderFactory ->create ()->loadByIncrementId ($ orderId );
120108
121- $ payfastCommon ->pflog ('order status is : ' . $ this ->_order ->getStatus ());
109+ $ paymentRequest ->pflog ('order status is : ' . $ this ->_order ->getStatus ());
122110
123111 // Check order is in "pending payment" state
124112 if ($ this ->_order ->getState () !== Order::STATE_PENDING_PAYMENT ) {
125- $ pfErrMsg = PayfastCommon ::PF_ERR_ORDER_PROCESSED ;
113+ $ pfErrMsg = $ paymentRequest ::PF_ERR_ORDER_PROCESSED ;
126114 }
127115 }
128116
129117 //// Verify data received
130118 if (!$ pfError ) {
131- $ payfastCommon ->pflog ('Verify data received ' );
119+ $ paymentRequest ->pflog ('Verify data received ' );
132120
133- if (!$ payfastCommon ->pfValidData ($ moduleInfo , $ pfHost , $ pfParamString )) {
121+ if (!$ paymentRequest ->pfValidData ($ moduleInfo , $ pfHost , $ pfParamString )) {
134122 $ pfError = true ;
135- $ pfErrMsg = PayfastCommon ::PF_ERR_BAD_ACCESS ;
123+ $ pfErrMsg = $ paymentRequest ::PF_ERR_BAD_ACCESS ;
136124 }
137125 }
138126
139127 //// Check status and update order
140128 if (!$ pfError ) {
141- $ payfastCommon ->pflog ('Check status and update order ' );
129+ $ paymentRequest ->pflog ('Check status and update order ' );
142130
143131 // Successful
144132 if ($ pfData [Info::PAYMENT_STATUS ] === 'COMPLETE ' ) {
@@ -155,7 +143,7 @@ public function execute(): ResultInterface
155143
156144 // If an error occurred
157145 if ($ pfError ) {
158- $ payfastCommon ->pflog ('Error occurred: ' . $ pfErrMsg );
146+ $ paymentRequest ->pflog ('Error occurred: ' . $ pfErrMsg );
159147 $ this ->_logger ->critical ($ pre . 'Error occured : ' . $ pfErrMsg );
160148
161149 return $ this ->rawResult
@@ -278,11 +266,11 @@ protected function saveInvoice(): void
278266 */
279267 private function setPaymentAdditionalInformation (array $ pfData ): void
280268 {
281- $ debugMode = $ this ->getConfigData ('debug ' );
282- $ payfastCommon = new PayfastCommon ((bool )$ debugMode );
269+ $ debugMode = $ this ->getConfigData ('debug ' );
270+ $ paymentRequest = new PaymentRequest ((bool )$ debugMode );
283271
284- $ payfastCommon ->pflog (__METHOD__ . ' : bof ' );
285- $ payfastCommon ->pflog ('Order complete ' );
272+ $ paymentRequest ->pflog (__METHOD__ . ' : bof ' );
273+ $ paymentRequest ->pflog ('Order complete ' );
286274
287275 try {
288276 // Update order additional payment information
0 commit comments