@@ -25,7 +25,12 @@ class PagHiperController extends Controller
2525 public function actionIndex ()
2626 {
2727 Yii::log (print_r ($ _POST , true ), 'error ' );
28- $ filter = "payment_method = 'paghiper' " ;
28+
29+ if (isset ($ _POST ['transaction_id ' ])) {
30+ $ filter = "payment_method = 'paghiperpix' " ;
31+ } else {
32+ $ filter = "payment_method = 'paghiper' " ;
33+ }
2934 $ params = array ();
3035
3136 if (isset ($ _GET ['id_agent ' ])) {
@@ -48,10 +53,58 @@ public function actionIndex()
4853 $ idUser = $ modelMethodpay ->idUser ->id_user ;
4954 $ token = $ modelMethodpay ->pagseguro_TOKEN ;
5055
56+ $ apiKey = $ modelMethodpay ->client_id ;
57+
5158 if (count ($ _POST ) > 0 ) {
5259 // POST recebido, indica que é a requisição do NPI.
5360
54- $ transacaoID = isset ($ _POST ['idTransacao ' ]) ? $ _POST ['idTransacao ' ] : '' ;
61+ if (isset ($ _POST ['transaction_id ' ])) {
62+
63+ $ ch = curl_init ();
64+ curl_setopt ($ ch , CURLOPT_URL , "https://pix.paghiper.com/invoice/notification/ " );
65+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
66+ curl_setopt ($ ch , CURLOPT_HEADER , false );
67+ curl_setopt ($ ch , CURLOPT_POST , true );
68+
69+ $ requestBody = json_encode ([
70+ "apiKey " => $ apiKey ,
71+ "transaction_id " => $ _POST ['transaction_id ' ],
72+ "notification_id " => $ _POST ['notification_id ' ],
73+ "token " => $ token ,
74+ ]);
75+
76+ Yii::log (print_r ($ requestBody , true ), 'error ' );
77+
78+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ requestBody );
79+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , [
80+ "Content-Type: application/json " ,
81+ "Accept: application/json " ,
82+ ]);
83+
84+ $ result = curl_exec ($ ch );
85+
86+ $ result = json_decode ($ result );
87+ Yii::log (print_r ($ result , true ), 'error ' );
88+ if (isset ($ result ->status_request ->status ) && $ result ->status_request ->status == 'paid ' ) {
89+ // code...
90+
91+ $ modelRefill = Refill::model ()->find ('description LIKE :key AND payment = 0 ' , [':key ' => '% ' . $ _POST ['transaction_id ' ] . '% ' ]);
92+ if (isset ($ modelRefill ->id )) {
93+ $ modelRefill ->payment = 1 ;
94+ $ modelRefill ->description = preg_replace ('/pendente/ ' , 'confirmado ' , $ modelRefill ->description );
95+ $ modelRefill ->save ();
96+
97+ UserCreditManager::releaseUserCredit ($ modelRefill ->id_user , $ modelRefill ->credit , 'PIX ' , 2 , $ _POST ['transaction_id ' ]);
98+ header ("HTTP/1.1 200 OK " );
99+ exit ;
100+ }
101+ } else {
102+ exit ;
103+ }
104+ }
105+
106+ $ transacaoID = isset ($ _POST ['idTransacao ' ]) ? $ _POST ['idTransacao ' ] : '' ;
107+
55108 $ status = $ _POST ['status ' ];
56109 $ codRetorno = $ _POST ['codRetorno ' ];
57110 $ valorOriginal = $ _POST ['valorOriginal ' ];
@@ -110,11 +163,13 @@ public function actionIndex()
110163 UserCreditManager::releaseUserCredit ($ modelUser ->id , $ monto , $ description , 1 , $ transacaoID );
111164 }
112165 }
166+ header ("HTTP/1.1 200 OK " );
113167 } else {
114168 echo 'error ' ;
115169 }
116170 } else {
117171 echo '<h3>Obrigado por efetuar a compra.</h3> ' ;
172+ header ("HTTP/1.1 200 OK " );
118173 }
119174 }
120175}
0 commit comments