Skip to content

Commit

Permalink
KAZOO-6064: [master] ask bookkeepers for early running recurring char…
Browse files Browse the repository at this point in the history
…ges (2600hz#5585)

* KAZOO-6064: ask bookkeepers for early running recurring charges

* make apis and fix typo

* ZOO-6064: is last/current month collected?

* KAZOO-6064: better time reporting in log

* KAZOO-6064: how they did not formatted?

* KAZOO-6064: add due-timestamp to recurring req

* fix date, specs and publishing message
  • Loading branch information
icehess authored and k-anderson committed Mar 21, 2019
1 parent 73453b1 commit c42aaf5
Show file tree
Hide file tree
Showing 8 changed files with 753 additions and 203 deletions.
37 changes: 37 additions & 0 deletions applications/braintree/src/braintree_collect_recurring_req.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%%%-----------------------------------------------------------------------------
%%% @copyright (C) 2013-2019, 2600Hz
%%% @doc
%%% @end
%%%-----------------------------------------------------------------------------
-module(braintree_collect_recurring_req).

-export([handle_req/2]).

-include("braintree.hrl").

%%------------------------------------------------------------------------------
%% @doc
%% @end
%%------------------------------------------------------------------------------
-spec handle_req(kz_json:object(), kz_term:proplist()) -> 'ok'.
handle_req(JObj, _Props) ->
'true' = kapi_bookkeepers:collect_recurring_req_v(JObj),
Response = kz_json:from_list(
[{<<"Account-ID">>, kz_json:get_ne_binary_value(<<"Account-ID">>, JObj)}
,{<<"Bookkeeper-ID">>, kz_json:get_ne_binary_value(<<"Bookkeeper-ID">>, JObj)}
,{<<"Bookkeeper-Type">>, kz_json:get_ne_binary_value(<<"Bookkeeper-Type">>, JObj)}
,{<<"Message">>, <<"Braintree performs recurring charges automatically">>}
,{<<"Msg-ID">>, kz_json:get_value(<<"Msg-ID">>, JObj)}
,{<<"Status">>, kz_services_recurring:status_good()}
] ++ kz_api:default_headers(?APP_NAME, ?APP_VERSION)
),
RespQ = kz_json:get_ne_binary_value(<<"Server-ID">>, JObj),

PublishFun = fun(P) -> kapi_bookkeepers:publish_collect_recurring_resp(RespQ, P) end,

case kz_json:get_ne_binary_value(<<"Bookkeeper-Type">>, JObj) =:= ?APP_NAME of
'false' ->
lager:debug("skipping collect recurring for another bookkeeper");
'true' ->
kz_amqp_worker:cast(Response, PublishFun)
end.
5 changes: 4 additions & 1 deletion applications/braintree/src/braintree_shared_listener.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
-define(BINDINGS, [{'bookkeepers', []}
,{'self', []}
]).
-define(RESPONDERS, [{'braintree_sale'
-define(RESPONDERS, [{'braintree_collect_recurring_req'
,[{<<"bookkeepers">>, <<"collect_recurring_req">>}]
}
,{'braintree_sale'
,[{<<"bookkeepers">>, <<"sale_req">>}]
}
,{'braintree_refund'
Expand Down
93 changes: 93 additions & 0 deletions applications/crossbar/priv/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8939,6 +8939,99 @@
],
"type": "object"
},
"kapi.bookkeepers.collect_recurring_req_definition": {
"description": "AMQP API for bookkeepers.collect_recurring_req_definition",
"properties": {
"Account-ID": {
"type": "string"
},
"Audit-Log": {
"type": "string"
},
"Bookkeeper-ID": {
"type": "string"
},
"Bookkeeper-Type": {
"type": "string"
},
"Due-Timestamp": {
"type": "string"
},
"Event-Category": {
"enum": [
"bookkeepers"
],
"type": "string"
},
"Event-Name": {
"enum": [
"collect_recurring_req"
],
"type": "string"
},
"Vendor-ID": {
"type": "string"
}
},
"required": [
"Account-ID",
"Bookkeeper-ID",
"Bookkeeper-Type",
"Vendor-ID"
],
"type": "object"
},
"kapi.bookkeepers.collect_recurring_resp_definition": {
"description": "AMQP API for bookkeepers.collect_recurring_resp_definition",
"properties": {
"Account-ID": {
"type": "string"
},
"Bookkeeper-ID": {
"type": "string"
},
"Bookkeeper-Type": {
"type": "string"
},
"Details": {
"type": "string"
},
"Event-Category": {
"enum": [
"bookkeepers"
],
"type": "string"
},
"Event-Name": {
"enum": [
"collect_recurring_resp"
],
"type": "string"
},
"Message": {
"type": "string"
},
"Reason": {
"type": "string"
},
"Status": {
"type": "string"
},
"Transaction-DB": {
"type": "string"
},
"Transaction-ID": {
"type": "string"
}
},
"required": [
"Account-ID",
"Bookkeeper-ID",
"Bookkeeper-Type",
"Status"
],
"type": "object"
},
"kapi.bookkeepers.refund_req_definition": {
"description": "AMQP API for bookkeepers.refund_req_definition",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"_id": "kapi.bookkeepers.collect_recurring_req_definition",
"description": "AMQP API for bookkeepers.collect_recurring_req_definition",
"properties": {
"Account-ID": {
"type": "string"
},
"Audit-Log": {
"type": "string"
},
"Bookkeeper-ID": {
"type": "string"
},
"Bookkeeper-Type": {
"type": "string"
},
"Due-Timestamp": {
"type": "string"
},
"Event-Category": {
"enum": [
"bookkeepers"
],
"type": "string"
},
"Event-Name": {
"enum": [
"collect_recurring_req"
],
"type": "string"
},
"Vendor-ID": {
"type": "string"
}
},
"required": [
"Account-ID",
"Bookkeeper-ID",
"Bookkeeper-Type",
"Vendor-ID"
],
"type": "object"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"_id": "kapi.bookkeepers.collect_recurring_resp_definition",
"description": "AMQP API for bookkeepers.collect_recurring_resp_definition",
"properties": {
"Account-ID": {
"type": "string"
},
"Bookkeeper-ID": {
"type": "string"
},
"Bookkeeper-Type": {
"type": "string"
},
"Details": {
"type": "string"
},
"Event-Category": {
"enum": [
"bookkeepers"
],
"type": "string"
},
"Event-Name": {
"enum": [
"collect_recurring_resp"
],
"type": "string"
},
"Message": {
"type": "string"
},
"Reason": {
"type": "string"
},
"Status": {
"type": "string"
},
"Transaction-DB": {
"type": "string"
},
"Transaction-ID": {
"type": "string"
}
},
"required": [
"Account-ID",
"Bookkeeper-ID",
"Bookkeeper-Type",
"Status"
],
"type": "object"
}
Loading

0 comments on commit c42aaf5

Please sign in to comment.