mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 02:57:33 -05:00 
			
		
		
		
	Improve error handling with Checkout Payment Gateway
This commit is contained in:
		
							parent
							
								
									f6ab1c0f0f
								
							
						
					
					
						commit
						e43d638d10
					
				@ -130,13 +130,38 @@ class CreditCard implements MethodInterface
 | 
				
			|||||||
            $http_status_code = $e->http_status_code;
 | 
					            $http_status_code = $e->http_status_code;
 | 
				
			||||||
            $error_details = $e->error_details;
 | 
					            $error_details = $e->error_details;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            throw new PaymentFailed($e->getMessage());
 | 
					            if(is_array($error_details)) {
 | 
				
			||||||
 | 
					                $error_details = end($e->error_details['error_codes']);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $human_exception = $error_details ? new \Exception($error_details, 400) : $e;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            throw new PaymentFailed($human_exception);
 | 
				
			||||||
        } catch (CheckoutArgumentException $e) {
 | 
					        } catch (CheckoutArgumentException $e) {
 | 
				
			||||||
            // Bad arguments
 | 
					            // Bad arguments
 | 
				
			||||||
            throw new PaymentFailed($e->getMessage());
 | 
					
 | 
				
			||||||
 | 
					            $error_details = $e->error_details;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if(is_array($error_details)) {
 | 
				
			||||||
 | 
					                $error_details = end($e->error_details['error_codes']);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $human_exception = $error_details ? new \Exception($error_details, 400) : $e;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            throw new PaymentFailed($human_exception);
 | 
				
			||||||
        } catch (CheckoutAuthorizationException $e) {
 | 
					        } catch (CheckoutAuthorizationException $e) {
 | 
				
			||||||
            // Bad Invalid authorization
 | 
					            // Bad Invalid authorization
 | 
				
			||||||
            throw new PaymentFailed($e->getMessage());
 | 
					  
 | 
				
			||||||
 | 
					            $error_details = $e->error_details;
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					             if(is_array($error_details)) {
 | 
				
			||||||
 | 
					                $error_details = end($e->error_details['error_codes']);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $human_exception = $error_details ? new \Exception($error_details, 400) : $e;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            throw new PaymentFailed($human_exception);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -230,7 +255,6 @@ class CreditCard implements MethodInterface
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            // $response = $this->checkout->gateway->payments()->request($payment);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $response = $this->checkout->gateway->getPaymentsClient()->requestPayment($paymentRequest);
 | 
					            $response = $this->checkout->gateway->getPaymentsClient()->requestPayment($paymentRequest);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -265,21 +289,71 @@ class CreditCard implements MethodInterface
 | 
				
			|||||||
            $http_status_code = $e->http_status_code;
 | 
					            $http_status_code = $e->http_status_code;
 | 
				
			||||||
            $error_details = $e->error_details;
 | 
					            $error_details = $e->error_details;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if(is_array($error_details)) {
 | 
				
			||||||
 | 
					                $error_details = end($e->error_details['error_codes']);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $this->checkout->unWindGatewayFees($this->checkout->payment_hash);
 | 
					            $this->checkout->unWindGatewayFees($this->checkout->payment_hash);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return $this->checkout->processInternallyFailedPayment($this->checkout, $e);
 | 
					            $human_exception = $error_details ? new \Exception($error_details, 400) : $e;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                SystemLogger::dispatch(
 | 
				
			||||||
 | 
					                    $human_exception->getMessage(),
 | 
				
			||||||
 | 
					                    SystemLog::CATEGORY_GATEWAY_RESPONSE,
 | 
				
			||||||
 | 
					                    SystemLog::EVENT_GATEWAY_ERROR,
 | 
				
			||||||
 | 
					                    SystemLog::TYPE_CHECKOUT,
 | 
				
			||||||
 | 
					                    $this->checkout->client,
 | 
				
			||||||
 | 
					                    $this->checkout->client->company,
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return $this->checkout->processInternallyFailedPayment($this->checkout, $human_exception);
 | 
				
			||||||
        } catch (CheckoutArgumentException $e) {
 | 
					        } catch (CheckoutArgumentException $e) {
 | 
				
			||||||
            // Bad arguments
 | 
					            // Bad arguments
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            $error_details = $e->error_details;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if(is_array($error_details)) {
 | 
				
			||||||
 | 
					                $error_details = end($e->error_details['error_codes']);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $this->checkout->unWindGatewayFees($this->checkout->payment_hash);
 | 
					            $this->checkout->unWindGatewayFees($this->checkout->payment_hash);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return $this->checkout->processInternallyFailedPayment($this->checkout, $e);
 | 
					            $human_exception = $error_details ? new \Exception($error_details, 400) : $e;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                SystemLogger::dispatch(
 | 
				
			||||||
 | 
					                    $human_exception->getMessage(),
 | 
				
			||||||
 | 
					                    SystemLog::CATEGORY_GATEWAY_RESPONSE,
 | 
				
			||||||
 | 
					                    SystemLog::EVENT_GATEWAY_ERROR,
 | 
				
			||||||
 | 
					                    SystemLog::TYPE_CHECKOUT,
 | 
				
			||||||
 | 
					                    $this->checkout->client,
 | 
				
			||||||
 | 
					                    $this->checkout->client->company,
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return $this->checkout->processInternallyFailedPayment($this->checkout, $human_exception);
 | 
				
			||||||
        } catch (CheckoutAuthorizationException $e) {
 | 
					        } catch (CheckoutAuthorizationException $e) {
 | 
				
			||||||
            // Bad Invalid authorization
 | 
					            // Bad Invalid authorization
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $error_details = $e->error_details;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if(is_array($error_details)) {
 | 
				
			||||||
 | 
					                $error_details = end($e->error_details['error_codes']);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $this->checkout->unWindGatewayFees($this->checkout->payment_hash);
 | 
					            $this->checkout->unWindGatewayFees($this->checkout->payment_hash);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return $this->checkout->processInternallyFailedPayment($this->checkout, $e);
 | 
					            $human_exception = $error_details ? new \Exception($error_details, 400) : $e;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                SystemLogger::dispatch(
 | 
				
			||||||
 | 
					                    $human_exception->getMessage(),
 | 
				
			||||||
 | 
					                    SystemLog::CATEGORY_GATEWAY_RESPONSE,
 | 
				
			||||||
 | 
					                    SystemLog::EVENT_GATEWAY_ERROR,
 | 
				
			||||||
 | 
					                    SystemLog::TYPE_CHECKOUT,
 | 
				
			||||||
 | 
					                    $this->checkout->client,
 | 
				
			||||||
 | 
					                    $this->checkout->client->company,
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return $this->checkout->processInternallyFailedPayment($this->checkout, $human_exception);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -84,10 +84,11 @@ trait Utilities
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function processUnsuccessfulPayment($_payment, $throw_exception = true)
 | 
					    public function processUnsuccessfulPayment($_payment, $throw_exception = true)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $error_message = '';
 | 
					        $error_message = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (array_key_exists('response_summary', $_payment)) {
 | 
					        if (array_key_exists('actions', $_payment) && array_key_exists('response_summary', end($_payment['actions']))) {
 | 
				
			||||||
            $error_message = $_payment['response_summary'];
 | 
					            $error_message = end($_payment['actions'])['response_summary'];
 | 
				
			||||||
        } elseif (array_key_exists('status', $_payment)) {
 | 
					        } elseif (array_key_exists('status', $_payment)) {
 | 
				
			||||||
            $error_message = $_payment['status'];
 | 
					            $error_message = $_payment['status'];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -401,8 +401,13 @@ class CheckoutComPaymentDriver extends BaseDriver
 | 
				
			|||||||
            $this->unWindGatewayFees($payment_hash);
 | 
					            $this->unWindGatewayFees($payment_hash);
 | 
				
			||||||
            $message = $e->getMessage();
 | 
					            $message = $e->getMessage();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $error_details = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if(property_exists($e, 'error_details'))
 | 
				
			||||||
 | 
					                $error_details = $e->error_details;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $data = [
 | 
					            $data = [
 | 
				
			||||||
                'status' => '',
 | 
					                'status' => $e->error_details,
 | 
				
			||||||
                'error_type' => '',
 | 
					                'error_type' => '',
 | 
				
			||||||
                'error_code' => $e->getCode(),
 | 
					                'error_code' => $e->getCode(),
 | 
				
			||||||
                'param' => '',
 | 
					                'param' => '',
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user