-
Notifications
You must be signed in to change notification settings - Fork 0
/
soapbilling.erl
76 lines (63 loc) · 2.71 KB
/
soapbilling.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
-module(soapbilling).
-export([handler/4]).
-include("billingserver.hrl"). % .hrl file generated by erlsom
handler(_Header,
[#'p:ReserveAmount'{'AccountNumber' = AccountNumber, 'Amount' = Amount}],
_Action,
_SessionValue) ->
{ok, undefined, reserve_amount(AccountNumber, Amount)};
handler(_Header,
[#'p:ChargeAmount'{'AccountNumber' = AccountNumber, 'Amount' = Amount}],
_Action,
_SessionValue) ->
{ok, undefined, charge_amount(AccountNumber, Amount)};
handler(_Header,
[#'p:RefillAmount'{'AccountNumber' = AccountNumber, 'Amount' = Amount}],
_Action,
_SessionValue) ->
{ok, undefined, refill_amount(AccountNumber, Amount)};
handler(_Header,
[#'p:ConfirmTransaction'{'TransactionId' = TransactionId}],
_Action,
_SessionValue) ->
{ok, undefined, confirm_transaction(TransactionId)};
handler(_Header,
[#'p:CancelTransaction'{'TransactionId' = TransactionId}],
_Action,
_SessionValue) ->
{ok, undefined, cancel_transaction(TransactionId)}
.
marshall2soap(Data) when is_binary(Data) ->
uuid:to_string(Data);
marshall2soap(Data) when is_atom(Data) ->
atom_to_list(Data).
charge_amount(AccountNumber, Amount) ->
Result = billingserver:charge_amount(AccountNumber, Amount),
Response = #'p:ChargeAmountResponse'{anyAttribs = [],
'Result' = marshall2soap(Result)
},
[Response].
reserve_amount(AccountNumber, Amount) ->
Result = billingserver:reserve_amount(AccountNumber, Amount),
Response = #'p:ReserveAmountResponse'{anyAttribs = [],
'Result' = marshall2soap(Result)
},
[Response].
refill_amount(AccountNumber, Amount) ->
Result = billingserver:refill_amount(AccountNumber, Amount),
Response = #'p:RefillAmountResponse'{anyAttribs = [],
'Result' = marshall2soap(Result)
},
[Response].
confirm_transaction(TransactionId) ->
Result = billingserver:confirm_transaction(uuid:to_binary(TransactionId)),
Response = #'p:ConfirmTransactionResponse'{anyAttribs = [],
'Result' = marshall2soap(Result)
},
[Response].
cancel_transaction(TransactionId) ->
Result = billingserver:cancel_transaction(uuid:to_binary(TransactionId)),
Response = #'p:CancelTransactionResponse'{anyAttribs = [],
'Result' = marshall2soap(Result)
},
[Response].