Jump to content

Api Issue - Errors With 'addcc' And 'optional' Fields.


EmptyMind

Recommended Posts

I'm using the 'blesta api' class as '$this->blesta'

 

here is a quick 'cut' of the code at play:

 


function savenewcc($vars) {

    print_r($vars);

    $response = $this->blesta->post('Accounts','addCc',array('vars' => $vars));

    print_r($response);


}

 

Here is the output showing the $vars going in and the response object after the call. 

 

Array

(

    [contact_id] => 1

    [first_name] => asdf

    [last_name] => asdf

    [number] => 4111111111111111

    [cvv] => 123

    [expiration] => 201401

)

BlestaResponse Object

(

    [raw:BlestaResponse:private] => {"message":"An unexpected error occured.","response":"Undefined property: stdClass::$address1"}

    [response_code:BlestaResponse:private] => 500

)

 

Adding the optional fields suppresses this error and the card is saved. 

 

I'm not submitting anything that relates to 'address1' in this case.

 

The only reference to 'address1' that I can find in the logic path is:

 

app/models/accounts.php ~ line 492



$fields = array( "contact_id", "first_name", "last_name", "address1", "address2", "city",

"state", "zip", "country", "number", "expiration", "last4", "type", "gateway_id", "client_reference_id", "reference_id"

);

$this->Record->insert("accounts_cc", $vars, $fields);


---

 

Perhaps with the record insert code not being able to find the matching indexes in the vars, if they were not sent. As in my code example above. Can't say for sure. Although the 'contacts' add code looks the same and doesn't give the same error performing the same function the same way.


 

this is with Blesta 3.0.6.

 

Additionally (this maybe SHOULD be a separate report but since im here, and its sorta related) 

 

There is a minor flaw in the 'optional field' logic. ( I believe this affects the 'contacts' as well. )

 

The 'country' and 'state' fields are listed as optional.  The country field DEFAULTS to 'US' if its not set to anything (Don't get me started on THAT.), the problem is that the 'state' rule is only optional if the COUNTRY is blank. As soon as 'country' is set it REQUIRES that the 'state' be set to an acceptable state (as per the ISO check you make). This compounds so that if no country is set, its set to US by default.. which then REQUIRES that the state be filled in.. by default. 

 

I believe my solution to this when I was working in 'contacts' was to 'trim out' ('unset()') the 'blank' fields before sending the $vars to the api. Thus 'non-existent' is seemingly not the same as 'blank' there. However this same workaround appears to have negative effects here, and I'm scratching my head as to why.

 

At any rate, the addCc function should not be outputting an error when the cc as defined above is submitted.

 

(Sorry, you got me started. Defaulting an 'optional' field to a setting such as 'US' is a bit.. wonky.. I mean.. if you are allowing to NOT set an address.. why would you FORCE a country to be set? makes no sense, especially given that not everyone lives in the 'US' (surprising.. I know). Either force an address to be entered, or don't. Anything else is just silly.) 

 

 

Link to comment
Share on other sites

I've added CORE-895 to look into the 'address1' error. I think that field is actually required, in which case the documentation will be updated.

 

The country/state issue sounds like another documentation error as well.

 

Stating a field is 'optional' means it can or cannot be given; not that it can be given, but as an empty string. So in some instances, I can see unsetting a variable may be necessary. Likewise for the country field, it can or cannot be given when calling the method. The country field is actually required by the system, but optional when you call the method, only because it defaults to a value. But as you said, it seems silly to require a country but not an address, but I think the address is actually required. We'll take a look next week.

Link to comment
Share on other sites

  • 3 weeks later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...