Error Handling

Each Heartland SDK handles the following error types which all inherit from HpsException:

Error Type Meaning
HpsInvalidRequestException handle error for amount less than zero dollars
HpsAuthenticationException handle errors related to your HpsServiceConfig (likely an invalid secret api key)
HpsCreditException handle card-related exceptions: card declined, processing error, etc
HpsGatewayException handle gateway-related exceptions: invalid cc number, gateway-timeout, etc

Error Handler

begin
    charge_service.charge(1.00,"usd", credit_card, card_holder)
rescue Hps::InvalidRequestException => e
    # handle error for amount less than zero dollars
rescue Hps::AuthenticationException => e
     # handle errors related to your Hps configuration
rescue Hps::CardException => e
    # handle card-related exceptions: card declined, processing error, etc
end
try:
    credit_service.charge(-5, 'usd', credit_card, card_holder)
except HpsInvalidRequestException, e:
    # handle error for amount less than zero dollars
except HpsAuthenticationException, e:
    # handle errors related to your HpsServiceConfig
except HpsCreditException, e:
    # handle card-related exceptions: card declined, processing error, etc
try
{
	creditService.Charge(-5.00m, "usd", creditCard, cardHolder);
}
catch (HpsInvalidRequestException e)
{
	// handle error for amount less than zero dollars
}
catch (HpsAuthenticationException e)
{
	// handle errors related to your HpsServiceConfig
}
catch (HpsCreditException e)
{
	// handle card-related exceptions: card declined, processing error, etc
}
catch (HpsGatewayException e)
{
	// handle gateway-related exceptions: invalid cc number, gateway-timeout, etc
}
<?php
try
{
	$chargeService->charge(-5, "usd", $cardOrToken, $cardHolder);
}
catch (HpsInvalidRequestException $e)
{
	// handle error for amount less than zero dollars
}
catch (HpsAuthenticationException $e)
{
	// handle errors related to your HpsServiceConfig
}
catch (HpsCreditException $e)
{
	// handle card-related exceptions: card declined, processing error, etc
}
catch (HpsGatewayException $e)
{
	// handle gateway-related exceptions: invalid cc number, gateway-timeout, etc
}
try
{
	chargeService.charge(new BigDecimal("-5"), "usd", creditCard, cardHolder);
}
catch (HpsInvalidRequestException e)
{
	// handle error for amount less than zero dollars
}
catch (HpsAuthenticationException e)
{
	// handle errors related to your HpsServiceConfig
}
catch (HpsCreditException e)
{
	// handle card-related exceptions: card declined, processing error, etc
}
catch (HpsGatewayException e)
{
	// handle gateway-related exceptions: invalid cc number, gateway-timeout, etc
}
creditService.chargeWithToken(10, "usd", "put single or multi-use token here", cardHolder, false, null, function (err, response) {
  if (err) {
    // handle error here
    return;
  };

  // handle successful response
});