I just got bit by a nasty bug and I'm trying to figure out how this error snuck through my checks. The top-level call:
my $respCodes = $processor->delayedCapture( CCTYPE => $row->{debitacct}, + ORIGID => $row->{auth_code}, CURRENCY_TYPE_ID => $row->{currency_type_id} ); croak "Failed authorization for TXID $row->{txid} " unless ( $respCodes->{SUCCESS} == 1 );
I'm performing an equality test, so I would think that if  $responseCode doesn't equal 1, this routine would  croak

But it gets slightly more complicated. The called routine ( processPayment() ) performs a similar hashref key comparison when building up its return value.

return { SUCCESS => $response->{RESULT} == 0, MESSAGE => $response->{RESPMSG}, AUTHCODE => $response->{AUTHCODE}, PNREF => $response->{PNREF}, CC_TYPE => $params{CCTYPE}, TOTAL_PAYMENT => $params{AMOUNT}, CHECK_DETAILS => $checkInfo, };
If $response is still a scalar (meaning that nothing happened to it after declaring it in the subroutine), shouldn't the value of $response->{SUCCESS} be  undef (due to autovivification) rather than having  $response->{SUCCESS} == 0 evaluate to true?

I see where the caller ( the first calls listed in this entry ) would make the mistake with the hashkey comparison since the error was introduced in  $processor->delayedCapture(). But how can  $foo->{bar} == 0 evaluate to true?

I don't know if my solution is the best one, but I've added a  defined check in the creation of the return value of  delayedCapture():

return { SUCCESS => ( defined $response->{RESULT} && $response->{RE +SULT} == 0 ), ....

In reply to hashref value comparison by geektron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.