-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_payment_buckaroo.erl
86 lines (74 loc) · 2.87 KB
/
mod_payment_buckaroo.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
77
78
79
80
81
82
83
84
85
86
%% @author Marc Worrell <marc@worrell.nl>
%% @copyright 2020-2021 Driebit BV
%% @doc Payment PSP module for Buckaroo
%% Copyright 2020-2021 Driebit BV
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
-module(mod_payment_buckaroo).
-mod_title("Payments using Buckaroo").
-mod_description("Payments using Payment Service Provider Buckaroo").
-mod_author("Driebit").
-mod_depends([ mod_payment ]).
-author("Driebit <tech@driebit.nl>").
-export([
init/1,
observe_payment_psp_request/2,
observe_payment_psp_view_url/2,
observe_payment_psp_status_sync/2
]).
-include_lib("mod_payment/include/payment.hrl").
init(Context) ->
lists:map(
fun({K, V}) ->
case m_config:get_value(?MODULE, K, Context) of
undefined ->
m_config:set_value(?MODULE, K, V, Context);
_ ->
ok
end
end,
[
{is_live, <<>>},
{website_key, <<>>},
{secret_key, <<>>},
{webhook_host, <<>>},
{invoice_nr_prefix, <<"INV">>}
]).
%% @doc Payment request, make new payment with Buckaroo, return
%% payment (buckaroo) details and a redirect uri for the user
%% to handle the payment.
observe_payment_psp_request(#payment_psp_request{ payment_id = PaymentId, currency = <<"EUR">> }, Context) ->
m_payment_buckaroo_api:create(PaymentId, Context);
observe_payment_psp_request(#payment_psp_request{}, _Context) ->
undefined.
observe_payment_psp_view_url(#payment_psp_view_url{ psp_module = ?MODULE, psp_external_id = BuckarooId }, _Context) ->
{ok, m_payment_buckaroo_api:payment_url(BuckarooId)};
observe_payment_psp_view_url(#payment_psp_view_url{}, _Context) ->
undefined.
observe_payment_psp_status_sync(#payment_psp_status_sync{
payment_id = PaymentId,
psp_module = ?MODULE,
psp_external_id = BuckarooId
}, Context) ->
case m_payment_buckaroo_api:transaction_status(BuckarooId, Context) of
{ok, {Code, DT}} ->
m_payment_buckaroo_api:update_payment_status(PaymentId, Code, DT, Context),
ok;
{error, 404} = Error ->
lager:warning("[buckaroo] unknown payment id ~p", [ PaymentId ]),
Error;
{error, _} = Error ->
Error
end;
observe_payment_psp_status_sync(#payment_psp_status_sync{}, _Context) ->
undefined.