@@ -142,7 +142,7 @@ public function payment_fields() {
142142 include WC_PAY_BY_PAYNOW_PL_PLUGIN_FILE_PATH . WC_PAY_BY_PAYNOW_PL_PLUGIN_TEMPLATES_PATH . 'payment_processor_info.php ' ;
143143 }
144144
145- public function process_payment ( $ order_id ): array {
145+ public function process_payment ( $ order_id ) {
146146
147147 $ order = wc_get_order ( $ order_id );
148148 $ response = array ();
@@ -176,28 +176,36 @@ public function process_payment( $order_id ): array {
176176 ! empty ( $ payment_method_fingerprint ) ? $ payment_method_fingerprint : null
177177 );
178178 if ( isset ( $ payment_data ['errors ' ] ) ) {
179- $ error_type = null ;
180- $ message = null ;
179+ $ response ['result ' ] = 'failure ' ;
180+ $ error_type = null ;
181+ $ message = null ;
181182 if ( isset ( $ payment_data ['errors ' ] [0 ] ) && $ payment_data ['errors ' ][0 ] instanceof \Paynow \Exception \Error ) {
182183 $ error_type = $ payment_data ['errors ' ][0 ]->getType ();
183184 $ message = $ payment_data ['errors ' ][0 ]->getMessage ();
184185 }
185186 switch ( $ error_type ) {
186187 case 'AUTHORIZATION_CODE_INVALID ' :
187188 wc_add_notice ( __ ( 'Wrong BLIK code ' , 'pay-by-paynow-pl ' ), 'error ' );
189+ $ response ['error ' ] = __ ( 'Wrong BLIK code ' , 'pay-by-paynow-pl ' );
188190 break ;
189191 case 'AUTHORIZATION_CODE_EXPIRED ' :
190192 wc_add_notice ( __ ( 'BLIK code has expired ' , 'pay-by-paynow-pl ' ), 'error ' );
193+ $ response ['error ' ] = __ ( 'BLIK code has expired ' , 'pay-by-paynow-pl ' );
191194 break ;
192195 case 'AUTHORIZATION_CODE_USED ' :
193196 wc_add_notice ( __ ( 'BLIK code already used ' , 'pay-by-paynow-pl ' ), 'error ' );
197+ $ response ['error ' ] = __ ( 'BLIK code already used ' , 'pay-by-paynow-pl ' );
194198 break ;
195199 case 'VALIDATION_ERROR ' :
196200 wc_add_notice ( $ this ->get_validation_errors_message ( $ message ), 'error ' );
201+ $ response ['error ' ] = $ this ->get_validation_errors_message ( $ message );
197202 break ;
198203 default :
199204 wc_add_notice ( __ ( 'An error occurred during the payment process and the payment could not be completed. ' , 'pay-by-paynow-pl ' ), 'error ' );
200205 }
206+ if ( did_action ( 'woocommerce_store_api_checkout_order_processed ' ) ) {
207+ throw new \Exception ( $ response ['error ' ] );
208+ }
201209 return $ response ;
202210 }
203211
0 commit comments