@@ -141,7 +141,7 @@ private function make_sale(): array {
141141 'notify_url ' => sprintf ($ this ->notify_url , $ order_id ) ]);
142142
143143 global $ wpdb ;
144- $ wpdb ->insert ($ wpdb ->prefix . ' payneteasy_payments ' ,
144+ $ wpdb ->insert ("{ $ wpdb ->prefix } payneteasy_payments " ,
145145 [ 'paynet_order_id ' => $ response ['paynet-order-id ' ], 'merchant_order_id ' => $ response ['merchant-order-id ' ] ]);
146146
147147 return $ response ;
@@ -225,11 +225,11 @@ public function return_handler(): void {
225225 }
226226 }
227227 catch (\Exception | PayneteasyException $ e )
228- { wp_die ($ e ->getMessage ()); }
228+ { wp_die ( $ e ->getMessage () ); }
229229 }
230230
231231 public function webhook_handler (): void {
232- [ $ order_id , $ type ] = [ $ _GET ['client_orderid ' ], $ _GET ['type ' ] ];
232+ [ $ order_id , $ type, $ paynet_id ] = [ $ _GET ['client_orderid ' ], $ _GET ['type ' ], $ _GET [ ' orderid ' ] ];
233233
234234 try {
235235 if (empty ($ order_id ))
@@ -240,12 +240,12 @@ public function webhook_handler(): void {
240240 if ($ this ->order ->get_status () === $ type )
241241 die ('OK ' );
242242
243- $ this ->change_payment_status ($ this ->get_payment_status () );
243+ $ this ->change_payment_status ( $ this ->get_payment_status ($ dummy , $ paynet_id ) );
244244
245245 exit ;
246246 }
247247 catch (\Exception | PayneteasyException $ e )
248- { wp_die ($ e ->getMessage ()); }
248+ { wp_die ( $ e ->getMessage () ); }
249249 }
250250
251251 private function change_payment_status (string $ payment_status ): void {
@@ -302,10 +302,7 @@ private function make_chargeback(): array { # XXX result not used ever
302302 $ amount = self ::parse_amount ($ amount );
303303 $ email = $ this ->order ->get_billing_email ();
304304
305- global $ wpdb ;
306- $ paynet_order_id = $ wpdb ->get_var ("SELECT paynet_order_id FROM {$ wpdb ->prefix }payneteasy_payments WHERE (merchant_order_id= $ order_id) " );
307-
308- return $ this ->api ->return ([ 'client_orderid ' => $ order_id , 'orderid ' => $ paynet_order_id , 'comment ' => 'Order cancel ' ]);
305+ return $ this ->api ->return ([ 'client_orderid ' => $ order_id , 'orderid ' => $ this ->paynet_order_id (), 'comment ' => 'Order cancel ' ]);
309306 }
310307
311308 private function preparing_items_for_refunds (array $ items ): array { # XXX function not used ever ?
@@ -388,16 +385,16 @@ private function actions_for_partially_refunded_order(): void {
388385 wc_add_notice (__ ('The payment was partial refunded. ' , 'wc-payneteasy ' ), 'notice ' );
389386 }
390387
391- private function get_payment_status (&$ three_d_html = null ): string {
392- global $ wpdb ;
393-
394- $ paynet_order_id = $ wpdb ->get_var ("SELECT paynet_order_id FROM {$ wpdb ->prefix }payneteasy_payments "
395- ." WHERE (merchant_order_id = ' " .$ this ->order ->get_id ()."') " );
396-
397- $ response = $ this ->api ->status ([ 'client_orderid ' => $ this ->order ->get_id (), 'orderid ' => $ paynet_order_id ]);
388+ private function get_payment_status (&$ three_d_html = null , $ paynet_id = null ): string {
389+ $ response = $ this ->api ->status ([ 'client_orderid ' => $ this ->order ->get_id (), 'orderid ' => $ paynet_id ?: $ this ->paynet_order_id () ]);
398390
399391 $ three_d_html = $ response ['html ' ] ?? null ;
400392 return "{$ response ['transaction-type ' ]}/ {$ response ['status ' ]}" ;
401393 }
394+
395+ private function paynet_order_id (): string {
396+ global $ wpdb ;
397+ return $ wpdb ->get_var ("SELECT paynet_order_id FROM {$ wpdb ->prefix }payneteasy_payments WHERE (merchant_order_id=' " .$ this ->order ->get_id ()."') " );
398+ }
402399 }
403400}
0 commit comments