Skip to content

Commit

Permalink
Merged in KAZ-341 (pull request 2600hz#36)
Browse files Browse the repository at this point in the history
[KAZ-341] Fix missing fields in notify_port_request
  • Loading branch information
BorigTheDwarf committed May 26, 2016
2 parents f3da437 + 8d316d7 commit ceb9cd4
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions applications/notify/src/notify_port_request.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,23 @@ handle_req(JObj, _Props) ->
lager:debug("a port change has been requested, sending email notification"),

{'ok', AccountDoc} = notify_util:get_account_doc(JObj),
AccountJObj = wh_doc:public_fields(AccountDoc),

lager:debug("creating port change notice for ~s(~s)", [kz_account:name(AccountJObj)
lager:debug("creating port change notice for ~s(~s)", [kz_account:name(AccountDoc)
,wh_doc:account_id(AccountDoc)
]),

Version = wh_json:get_value(<<"Version">>, JObj),
Props = create_template_props(Version, JObj, AccountJObj),
Props = create_template_props(Version, JObj, AccountDoc),

CustomTxtTemplate = wh_json:get_value([<<"notifications">>, <<"port_request">>, <<"email_text_template">>], AccountJObj),
CustomTxtTemplate = wh_json:get_value([<<"notifications">>, <<"port_request">>, <<"email_text_template">>], AccountDoc),
{'ok', TxtBody} = notify_util:render_template(CustomTxtTemplate, ?DEFAULT_TEXT_TMPL, Props),
lager:debug("txt body: ~s", [TxtBody]),

CustomHtmlTemplate = wh_json:get_value([<<"notifications">>, <<"port_request">>, <<"email_html_template">>], AccountJObj),
CustomHtmlTemplate = wh_json:get_value([<<"notifications">>, <<"port_request">>, <<"email_html_template">>], AccountDoc),
{'ok', HTMLBody} = notify_util:render_template(CustomHtmlTemplate, ?DEFAULT_HTML_TMPL, Props),
lager:debug("html body: ~s", [HTMLBody]),

CustomSubjectTemplate = wh_json:get_value([<<"notifications">>, <<"port_request">>, <<"email_subject_template">>], AccountJObj),
CustomSubjectTemplate = wh_json:get_value([<<"notifications">>, <<"port_request">>, <<"email_subject_template">>], AccountDoc),
{'ok', Subject} = notify_util:render_template(CustomSubjectTemplate, ?DEFAULT_SUBJ_TMPL, Props),
lager:debug("subject: ~s", [Subject]),

Expand Down Expand Up @@ -98,24 +97,17 @@ create_template_props(<<"v2">>, NotifyJObj, AccountJObj) ->

NumberString = wh_util:join_binary([Num || {Num, _} <- Numbers], <<" ">>),

Request = [{<<"port">>
,[{<<"service_provider">>, wh_json:get_value(<<"carrier">>, PortDoc)}
,{<<"billing_name">>, wh_json:get_value([<<"bill">>, <<"name">>], PortDoc)}
,{<<"billing_account_id">>, wh_doc:account_id(PortDoc)}
,{<<"billing_street_address">>, wh_json:get_value([<<"bill">>, <<"address">>], PortDoc)}
,{<<"billing_locality">>, wh_json:get_value([<<"bill">>, <<"locality">>], PortDoc)}
,{<<"billing_postal_code">>, wh_json:get_value([<<"bill">>, <<"postal_code">>], PortDoc)}
,{<<"billing_telephone_number">>, wh_json:get_value([<<"bill">>, <<"phone_number">>], PortDoc)}
,{<<"requested_port_date">>, wh_json:get_value(<<"transfer_date">>, PortDoc)}
,{<<"customer_contact">>, wh_json:get_value([<<"notifications">>, <<"email">>, <<"send_to">>], PortDoc)}
]
}
,{<<"number">>, NumberString}
],
Request = props:delete_keys([<<"uploads">>, <<"numbers">>], PortData),
Request2 = Request ++ [{"number", NumberString}],

% For when things inevitably go wrong again
lager:debug("Notify JObj ~p", [NotifyJObj]),
lager:debug("Request ~p", [Request2]),
lager:debug("Port doc ~p", [PortDoc]),

[{<<"numbers">>, Numbers}
,{<<"number">>, Number}
,{<<"request">>, Request}
,{<<"request">>, Request2}
,{<<"account">>, notify_util:json_to_template_props(AccountJObj)}
,{<<"admin">>, notify_util:json_to_template_props(Admin)}
,{<<"service">>, notify_util:get_service_props(AccountJObj, ?MOD_CONFIG_CAT)}
Expand Down

0 comments on commit ceb9cd4

Please sign in to comment.