Skip to content

Commit

Permalink
Fixed an issue with adding a customer (2600hz#1878)
Browse files Browse the repository at this point in the history
* Fixed an issue with adding a customer

When someone needed to add a customer without having their credit card braintree send an error that make_default(undefined) clause is not defined in braintree_card.erl. now we can add a new customer in braintree by just having using his info and adding a card is not needed.

* Updated specs and changed undefined to catch all method

* fixed braintree for use case where credit card info is not present

* changed get_binary_value to get_value
  • Loading branch information
tsromana authored and jamesaimonetti committed May 6, 2016
1 parent c3c5ed5 commit 2655301
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 0 additions & 1 deletion core/braintree/src/braintree_card.erl
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ record_to_xml(#bt_card{}=Card, ToString) ->
%% @end
%%--------------------------------------------------------------------
-spec json_to_record(api_object()) -> bt_card().
json_to_record('undefined') -> 'undefined';
json_to_record(JObj) ->
#bt_card{token = create_or_get_json_id(JObj)
,cardholder_name = kz_json:get_binary_value(<<"cardholder_name">>, JObj)
Expand Down
9 changes: 8 additions & 1 deletion core/braintree/src/braintree_customer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,16 @@ json_to_record(JObj) ->
,phone = kz_json:get_binary_value(<<"phone">>, JObj)
,fax = kz_json:get_binary_value(<<"fax">>, JObj)
,website = kz_json:get_binary_value(<<"website">>, JObj)
,credit_cards = [braintree_card:json_to_record(kz_json:get_value(<<"credit_card">>, JObj))]
,credit_cards = maybe_add_credit_card(JObj)
}.

-spec maybe_add_credit_card(api_object()) -> bt_cards().
maybe_add_credit_card(JObj) ->
case kz_json:get_value(<<"credit_card">>, JObj) of
'undefined' -> [];
Card -> [braintree_card:json_to_record(Card)]
end.

%%--------------------------------------------------------------------
%% @public
%% @doc
Expand Down

0 comments on commit 2655301

Please sign in to comment.