@@ -69,7 +69,7 @@ private function init_payment_settings(): array {
6969
7070 if (property_exists ($ this , $ k ))
7171 $ this ->$ k = $ s [$ k ];
72- }
72+ }
7373
7474 $ s ['is_direct ' ] = $ s ['payment_method ' ] == 'direct ' ;
7575 $ s ['gate ' ] = $ s ['sandbox ' ] ? $ s ['sandbox_url ' ] : $ s ['live_url ' ];
@@ -96,7 +96,8 @@ public function process_payment($order_id): ?array {
9696
9797 $ sale = $ this ->make_sale ();
9898
99- $ this ->order ->update_status ('pending ' , __ ('Payment link generated: ' , 'wc-payneteasy ' ).$ sale ['redirect-url ' ] ?: '' );
99+ if (isset ($ sale ['redirect-url ' ]))
100+ $ this ->order ->update_status ('pending ' , __ ('Payment link generated: ' , 'wc-payneteasy ' ).$ sale ['redirect-url ' ]);
100101
101102 return $ this ->api ->is_direct ()
102103 ? [ 'result ' => 'success ' , 'redirect ' => home_url ("?wc-api= {$ this ->id }_return&orderId= $ order_id " ) ]
@@ -110,6 +111,7 @@ public function process_payment($order_id): ?array {
110111
111112 private function make_sale (): array {
112113 [ $ order_id , $ email , $ total ] = [ $ this ->order ->get_id (), $ this ->order ->get_billing_email (), $ this ->order ->get_total () ];
114+
113115 $ return_url = home_url ("?wc-api= {$ this ->id }_return&orderId= $ order_id " );
114116
115117 $ response = $ this ->api ->sale ([
@@ -150,7 +152,7 @@ private static function form_cell(?array $cell, string $class): string {
150152 ? "<div class='form-row- $ class'><label> {$ cell [0 ]} <span class='required'>*</span></label> "
151153 ."<input id=' {$ cell [1 ]}' name=' {$ cell [1 ]}' type='text' "
152154 .($ cell [2 ] ? " autocomplete=' {$ cell [2 ]}' " : '' )
153- ." { $ cell [3 ]} ></div> "
155+ .' ' .( $ cell [3 ] ?? '' ). ' ></div> '
154156 : '' ;
155157 }
156158
@@ -202,12 +204,13 @@ public function return_handler(): void {
202204 $ this ->set_order ($ order_id );
203205 $ this ->change_payment_status ($ payment_status = $ this ->get_payment_status ($ three_d_html ));
204206
207+ WC ()->cart ->empty_cart (); # иначе продолжает слать всё тот же ордер_ид, и гейт отдаёт один и тот же запрос
208+
205209 switch ($ payment_status ) {
206210 case 'sale/processing ' :
207211 echo $ three_d_html ;
208212 die ();
209213 case 'sale/approved ' :
210- WC ()->cart ->empty_cart ();
211214 echo '<div style="width: 100%; text-align: center"><div><h1>Your payment was approved. Thank you.</h1></div><div><a href=" ' .get_site_url ().'">Return homepage</a></div></div> ' ;
212215 die ();
213216 case 'sale/error ' :
@@ -216,6 +219,9 @@ public function return_handler(): void {
216219 case 'sale/declined ' :
217220 echo '<div style="width: 100%; text-align: center"><div><h1>Your payment was declined. Could you try again.</h1></div><div><a href=" ' .get_site_url ().'">Return homepage</a></div></div> ' ;
218221 die ();
222+ default :
223+ echo '<div style="width: 100%; text-align: center"><div><h1>Transaction is declined but something went wrong, please inform your account manager, final status</h1></div><div><a href=" ' .get_site_url ().'">Return homepage</a></div></div> ' ;
224+ die ();
219225 }
220226 }
221227 catch (\Exception | PayneteasyException $ e )
@@ -390,7 +396,7 @@ private function get_payment_status(&$three_d_html = null): string {
390396
391397 $ response = $ this ->api ->status ([ 'client_orderid ' => $ this ->order ->get_id (), 'orderid ' => $ paynet_order_id ]);
392398
393- $ three_d_html = $ response ['html ' ];
399+ $ three_d_html = $ response ['html ' ] ?? null ;
394400 return "{$ response ['transaction-type ' ]}/ {$ response ['status ' ]}" ;
395401 }
396402 }
0 commit comments