amazon-pay-sdk-php icon indicating copy to clipboard operation
amazon-pay-sdk-php copied to clipboard

Use Exception subclasses or error codes

Open ejegg opened this issue 9 years ago • 5 comments

Users need a better way to determine error categories than parsing error messages. One good solution would be problem-specific Exception types, such as BadMethodCallException for missing parameters or a hypothetical PayWithAmazon\BadSignatureException for an improperly-signed incoming IPN message. Alternatively, the SDK could define a set of integer constants to use as error codes.

ejegg avatar Sep 17 '15 18:09 ejegg

Elliott, thanks for your suggestion. I will review the parsing of the error messages request and get back to you once we discuss in our sprint

shrakuma avatar Sep 18 '15 21:09 shrakuma

I am working with this library and its very hard to handle the errors - have to dig in the arrays to understand why payments get stuck. Please note that not all errors are getting handled with exceptions, such as invalid payment method error that is in some other place in XML.

kailight avatar Dec 28 '15 22:12 kailight

Agreed. I believe I am looking for similar answers. I arrived here in search of the best practice for error handing the API calls. For example, is any sort of specific Exception's thrown or are they all a simple generic Exception class? For example, what if Amazon is down and cannot be communicated with? There's the "service status" API call but if the Amazon API is down that probably defaults the purpose of that call. Looking at the code I saw an invokePost method which looked like the right spot for these cases. If so, is the recommended way to wrap each API call like so?

try {
    $response = $this                                                              
        ->amazonPay                                                                   
        ->setOrderReferenceDetails(array(                                          
            'amazon_order_reference_id' => $order->getAmazonReferenceId(),         
            'seller_order_id' => $order->getAmazonOrderId(),                       
            'amount' => $order->getTotal(),                                        
            'currency_code' => 'USD',                                              
            'seller_note' => 'Hello World.',                               
            'store_name' => 'Our Shop!',                                       
    )); 
} catch (\Exception $e) {
  // Perform error handing here ...
}

bmeynell avatar Feb 02 '16 20:02 bmeynell

@bmeynell This library is a total mess. :smile: It does not throw exceptions at all. You have to "ask" the client if there was an error on an boolean var.

When implementing an Exception Approach it would be nice to wrap them into super classes Like ClientException == 4xx and ServiceException = 5xx

ClientException would then wrap around the response object and extract useful messages and and Error codes from it?

mablae avatar Sep 20 '16 20:09 mablae

frustrated without error code.

the "charge" method returns an exception because of Suspended caused by InvvalidPaymentMethod "The Order Reference is in the Suspended State. It should be in the Draft or Open State"

I want to identify this with the exception error code but currently only the string above.

lotsofbytes avatar Dec 04 '19 19:12 lotsofbytes