mirror of
https://github.com/valitydev/fistful-server.git
synced 2024-11-06 02:35:18 +00:00
TD-234: Add currency ref (#21)
* updated proto, removed legacy eunit, removed deprecated bankcard payment system * added crypto currency ref * fixed tests * fixed * reverted old migration and tests, fixed * removed part of old tests * fixed linter * fixed code cover? * fixed
This commit is contained in:
parent
4278ab139e
commit
74ff230d75
2
Makefile
2
Makefile
@ -28,7 +28,7 @@ dev-image: .image.dev
|
||||
|
||||
.image.dev: Dockerfile.dev .env
|
||||
env $(DOTENV) $(DOCKERCOMPOSE_W_ENV) build $(TEST_CONTAINER_NAME)
|
||||
$(DOCKER) image ls -q -f "reference=$(DEV_IMAGE_ID)" | head -n1 > $@
|
||||
$(DOCKER) image ls -q -f "reference=$(DEV_IMAGE_TAG)" | head -n1 > $@
|
||||
|
||||
clean-dev-image:
|
||||
ifneq ($(DEV_IMAGE_ID),)
|
||||
|
@ -72,7 +72,6 @@
|
||||
last_digits = <<>>,
|
||||
bank_name = BankName,
|
||||
payment_system = #domain_PaymentSystemRef{id = <<"VISA">>},
|
||||
payment_system_deprecated = visa,
|
||||
issuer_country = rus
|
||||
}}
|
||||
).
|
||||
|
@ -486,7 +486,7 @@ domain_config(Options) ->
|
||||
{condition,
|
||||
{payment_tool,
|
||||
{crypto_currency, #domain_CryptoCurrencyCondition{
|
||||
definition = {crypto_currency_is_deprecated, litecoin}
|
||||
definition = {crypto_currency_is, ?crptcur(<<"Litecoin">>)}
|
||||
}}}},
|
||||
?ruleset(?PAYINST2_ROUTING_POLICIES + 1)
|
||||
),
|
||||
@ -728,12 +728,12 @@ domain_config(Options) ->
|
||||
|
||||
ct_domain:category(?cat(1), <<"Generic Store">>, live),
|
||||
|
||||
ct_domain:payment_method(?pmt(bank_card_deprecated, visa)),
|
||||
ct_domain:payment_method(?pmt(bank_card_deprecated, mastercard)),
|
||||
ct_domain:payment_method(?pmt(?PAYMENT_METHOD_BANK_CARD(<<"VISA">>))),
|
||||
ct_domain:payment_method(?pmt(?PAYMENT_METHOD_GENERIC(<<"IND">>))),
|
||||
ct_domain:payment_method(?pmt(?PAYMENT_METHOD_DIGITAL_WALLET(<<"webmoney">>))),
|
||||
ct_domain:payment_method(?pmt(?PAYMENT_METHOD_CRYPTO_CURRENCY(<<"Litecoin">>))),
|
||||
ct_domain:payment_method(?pmt(?PAYMENT_METHOD_CRYPTO_CURRENCY(<<"bitcoin_cash">>))),
|
||||
ct_domain:payment_method(?pmt(?PAYMENT_METHOD_CRYPTO_CURRENCY(<<"ripple">>))),
|
||||
|
||||
ct_domain:payment_system(?pmtsys(<<"VISA">>), <<"VISA">>),
|
||||
ct_domain:payment_system(?pmtsys(<<"NSPK MIR">>), <<"NSPK MIR">>),
|
||||
@ -741,7 +741,9 @@ domain_config(Options) ->
|
||||
ct_domain:payment_service(?pmtsrv(<<"webmoney">>), <<"Webmoney">>),
|
||||
ct_domain:payment_service(?pmtsrv(<<"qiwi">>), <<"Qiwi">>),
|
||||
ct_domain:payment_service(?pmtsrv(<<"IND">>), <<"INDbank">>),
|
||||
ct_domain:crypto_currency(?crptcur(<<"Litecoin">>), <<"Litecoin">>)
|
||||
ct_domain:crypto_currency(?crptcur(<<"Litecoin">>), <<"Litecoin">>),
|
||||
ct_domain:crypto_currency(?crptcur(<<"bitcoin_cash">>), <<"bitcoin_cash">>),
|
||||
ct_domain:crypto_currency(?crptcur(<<"ripple">>), <<"ripple">>)
|
||||
],
|
||||
maps:get(domain_config, Options, Default).
|
||||
|
||||
@ -809,7 +811,9 @@ default_termset(Options) ->
|
||||
?pmt(?PAYMENT_METHOD_BANK_CARD(<<"VISA">>)),
|
||||
?pmt(?PAYMENT_METHOD_GENERIC(<<"IND">>)),
|
||||
?pmt(?PAYMENT_METHOD_DIGITAL_WALLET(<<"webmoney">>)),
|
||||
?pmt(?PAYMENT_METHOD_CRYPTO_CURRENCY(<<"Litecoin">>))
|
||||
?pmt(?PAYMENT_METHOD_CRYPTO_CURRENCY(<<"Litecoin">>)),
|
||||
?pmt(?PAYMENT_METHOD_CRYPTO_CURRENCY(<<"bitcoin_cash">>)),
|
||||
?pmt(?PAYMENT_METHOD_CRYPTO_CURRENCY(<<"ripple">>))
|
||||
])},
|
||||
cash_flow =
|
||||
{decisions, [
|
||||
@ -832,7 +836,9 @@ default_termset(Options) ->
|
||||
{bank_card, #domain_BankCardCondition{
|
||||
definition =
|
||||
{payment_system, #domain_PaymentSystemCondition{
|
||||
payment_system_is_deprecated = visa
|
||||
payment_system_is = #domain_PaymentSystemRef{
|
||||
id = <<"VISA">>
|
||||
}
|
||||
}}
|
||||
}}}}
|
||||
])},
|
||||
@ -865,7 +871,9 @@ default_termset(Options) ->
|
||||
{bank_card, #domain_BankCardCondition{
|
||||
definition =
|
||||
{payment_system, #domain_PaymentSystemCondition{
|
||||
payment_system_is_deprecated = visa
|
||||
payment_system_is = #domain_PaymentSystemRef{
|
||||
id = <<"VISA">>
|
||||
}
|
||||
}}
|
||||
}}}}
|
||||
])},
|
||||
@ -898,7 +906,9 @@ default_termset(Options) ->
|
||||
{bank_card, #domain_BankCardCondition{
|
||||
definition =
|
||||
{payment_system, #domain_PaymentSystemCondition{
|
||||
payment_system_is_deprecated = visa
|
||||
payment_system_is = #domain_PaymentSystemRef{
|
||||
id = <<"VISA">>
|
||||
}
|
||||
}}
|
||||
}}}}
|
||||
])},
|
||||
|
@ -70,7 +70,7 @@ marshal(withdrawal_method, #{id := {generic, #{payment_service := PaymentService
|
||||
marshal(withdrawal_method, #{id := {digital_wallet, PaymentService}}) ->
|
||||
{digital_wallet, marshal(payment_service, PaymentService)};
|
||||
marshal(withdrawal_method, #{id := {crypto_currency, CryptoCurrencyRef}}) ->
|
||||
{crypto_currency, marshal(crypto_currency_ref, CryptoCurrencyRef)};
|
||||
{crypto_currency, marshal(crypto_currency, CryptoCurrencyRef)};
|
||||
marshal(withdrawal_method, #{id := {bank_card, #{payment_system := PaymentSystem}}}) ->
|
||||
{bank_card, #'fistful_BankCardWithdrawalMethod'{
|
||||
payment_system = marshal(payment_system, PaymentSystem)
|
||||
@ -152,22 +152,20 @@ marshal(resource_descriptor, {bank_card, BinDataID}) ->
|
||||
}};
|
||||
marshal(bank_card, BankCard = #{token := Token}) ->
|
||||
Bin = maps:get(bin, BankCard, undefined),
|
||||
PaymentSystem = maps:get(payment_system, BankCard, undefined),
|
||||
PaymentSystemDeprecated = maps:get(payment_system_deprecated, BankCard, undefined),
|
||||
MaskedPan = maps:get(masked_pan, BankCard, undefined),
|
||||
BankName = maps:get(bank_name, BankCard, undefined),
|
||||
IssuerCountry = maps:get(issuer_country, BankCard, undefined),
|
||||
CardType = maps:get(card_type, BankCard, undefined),
|
||||
ExpDate = maps:get(exp_date, BankCard, undefined),
|
||||
CardholderName = maps:get(cardholder_name, BankCard, undefined),
|
||||
BinDataID = maps:get(bin_data_id, BankCard, undefined),
|
||||
PaymentSystem = ff_resource:payment_system(BankCard),
|
||||
MaskedPan = ff_resource:masked_pan(BankCard),
|
||||
BankName = ff_resource:bank_name(BankCard),
|
||||
IssuerCountry = ff_resource:issuer_country(BankCard),
|
||||
CardType = ff_resource:card_type(BankCard),
|
||||
ExpDate = ff_resource:exp_date(BankCard),
|
||||
CardholderName = ff_resource:cardholder_name(BankCard),
|
||||
BinDataID = ff_resource:bin_data_id(BankCard),
|
||||
#'fistful_base_BankCard'{
|
||||
token = marshal(string, Token),
|
||||
bin = marshal(string, Bin),
|
||||
masked_pan = marshal(string, MaskedPan),
|
||||
bank_name = marshal(string, BankName),
|
||||
payment_system = maybe_marshal(payment_system, PaymentSystem),
|
||||
payment_system_deprecated = maybe_marshal(payment_system_deprecated, PaymentSystemDeprecated),
|
||||
issuer_country = maybe_marshal(issuer_country, IssuerCountry),
|
||||
card_type = maybe_marshal(card_type, CardType),
|
||||
exp_date = maybe_marshal(exp_date, ExpDate),
|
||||
@ -178,11 +176,11 @@ marshal(bank_card_auth_data, {session, #{session_id := ID}}) ->
|
||||
{session_data, #'fistful_base_SessionAuthData'{
|
||||
id = marshal(string, ID)
|
||||
}};
|
||||
marshal(crypto_wallet, #{id := ID, currency := Currency}) ->
|
||||
marshal(crypto_wallet, CryptoWallet = #{id := ID, currency := Currency}) ->
|
||||
#'fistful_base_CryptoWallet'{
|
||||
id = marshal(string, ID),
|
||||
currency = marshal(crypto_currency, Currency),
|
||||
data = marshal(crypto_data, Currency)
|
||||
tag = maybe_marshal(string, maps:get(tag, CryptoWallet, undefined))
|
||||
};
|
||||
marshal(digital_wallet, Wallet = #{id := ID, payment_service := PaymentService}) ->
|
||||
#'fistful_base_DigitalWallet'{
|
||||
@ -200,24 +198,10 @@ marshal(exp_date, {Month, Year}) ->
|
||||
month = marshal(integer, Month),
|
||||
year = marshal(integer, Year)
|
||||
};
|
||||
marshal(crypto_currency, {Currency, _}) ->
|
||||
Currency;
|
||||
marshal(crypto_data, {bitcoin, #{}}) ->
|
||||
{bitcoin, #'fistful_base_CryptoDataBitcoin'{}};
|
||||
marshal(crypto_data, {litecoin, #{}}) ->
|
||||
{litecoin, #'fistful_base_CryptoDataLitecoin'{}};
|
||||
marshal(crypto_data, {bitcoin_cash, #{}}) ->
|
||||
{bitcoin_cash, #'fistful_base_CryptoDataBitcoinCash'{}};
|
||||
marshal(crypto_data, {ethereum, #{}}) ->
|
||||
{ethereum, #'fistful_base_CryptoDataEthereum'{}};
|
||||
marshal(crypto_data, {zcash, #{}}) ->
|
||||
{zcash, #'fistful_base_CryptoDataZcash'{}};
|
||||
marshal(crypto_data, {usdt, #{}}) ->
|
||||
{usdt, #'fistful_base_CryptoDataUSDT'{}};
|
||||
marshal(crypto_data, {ripple, Data}) ->
|
||||
{ripple, #'fistful_base_CryptoDataRipple'{
|
||||
tag = maybe_marshal(string, maps:get(tag, Data, undefined))
|
||||
}};
|
||||
marshal(crypto_currency, #{id := Ref}) when is_binary(Ref) ->
|
||||
#'fistful_base_CryptoCurrencyRef'{
|
||||
id = Ref
|
||||
};
|
||||
marshal(payment_service, #{id := Ref}) when is_binary(Ref) ->
|
||||
#'fistful_base_PaymentServiceRef'{
|
||||
id = Ref
|
||||
@ -226,12 +210,6 @@ marshal(payment_system, #{id := Ref}) when is_binary(Ref) ->
|
||||
#'fistful_base_PaymentSystemRef'{
|
||||
id = Ref
|
||||
};
|
||||
marshal(crypto_currency_ref, #{id := Ref}) ->
|
||||
#'fistful_base_CryptoCurrencyRef'{
|
||||
id = Ref
|
||||
};
|
||||
marshal(payment_system_deprecated, V) when is_atom(V) ->
|
||||
V;
|
||||
marshal(issuer_country, V) when is_atom(V) ->
|
||||
V;
|
||||
marshal(card_type, V) when is_atom(V) ->
|
||||
@ -447,7 +425,6 @@ unmarshal(bank_card, #'fistful_base_BankCard'{
|
||||
masked_pan = MaskedPan,
|
||||
bank_name = BankName,
|
||||
payment_system = PaymentSystem,
|
||||
payment_system_deprecated = PaymentSystemDeprecated,
|
||||
issuer_country = IssuerCountry,
|
||||
card_type = CardType,
|
||||
bin_data_id = BinDataID,
|
||||
@ -457,7 +434,6 @@ unmarshal(bank_card, #'fistful_base_BankCard'{
|
||||
genlib_map:compact(#{
|
||||
token => unmarshal(string, Token),
|
||||
payment_system => maybe_unmarshal(payment_system, PaymentSystem),
|
||||
payment_system_deprecated => maybe_unmarshal(payment_system_deprecated, PaymentSystemDeprecated),
|
||||
bin => maybe_unmarshal(string, Bin),
|
||||
masked_pan => maybe_unmarshal(string, MaskedPan),
|
||||
bank_name => maybe_unmarshal(string, BankName),
|
||||
@ -476,27 +452,20 @@ unmarshal(payment_system, #'fistful_base_PaymentSystemRef'{id = Ref}) when is_bi
|
||||
#{
|
||||
id => Ref
|
||||
};
|
||||
unmarshal(payment_system_deprecated, V) when is_atom(V) ->
|
||||
V;
|
||||
unmarshal(issuer_country, V) when is_atom(V) ->
|
||||
V;
|
||||
unmarshal(card_type, V) when is_atom(V) ->
|
||||
V;
|
||||
unmarshal(crypto_wallet, #'fistful_base_CryptoWallet'{
|
||||
id = CryptoWalletID,
|
||||
currency = CryptoWalletCurrency,
|
||||
data = Data
|
||||
currency = Currency,
|
||||
tag = Tag
|
||||
}) ->
|
||||
genlib_map:compact(#{
|
||||
id => unmarshal(string, CryptoWalletID),
|
||||
currency => {CryptoWalletCurrency, unmarshal(crypto_data, Data)}
|
||||
});
|
||||
unmarshal(crypto_data, {ripple, #'fistful_base_CryptoDataRipple'{tag = Tag}}) ->
|
||||
genlib_map:compact(#{
|
||||
currency => unmarshal(crypto_currency, Currency),
|
||||
tag => maybe_unmarshal(string, Tag)
|
||||
});
|
||||
unmarshal(crypto_data, _) ->
|
||||
#{};
|
||||
unmarshal(digital_wallet, #'fistful_base_DigitalWallet'{id = ID, payment_service = PaymentService, token = Token}) ->
|
||||
genlib_map:compact(#{
|
||||
id => unmarshal(string, ID),
|
||||
@ -517,6 +486,10 @@ unmarshal(payment_service, #'fistful_base_PaymentServiceRef'{id = Ref}) when is_
|
||||
#{
|
||||
id => Ref
|
||||
};
|
||||
unmarshal(crypto_currency, #'fistful_base_CryptoCurrencyRef'{id = Ref}) when is_binary(Ref) ->
|
||||
#{
|
||||
id => Ref
|
||||
};
|
||||
unmarshal(cash, #'fistful_base_Cash'{
|
||||
amount = Amount,
|
||||
currency = CurrencyRef
|
||||
@ -622,7 +595,6 @@ bank_card_codec_test() ->
|
||||
BankCard = #{
|
||||
token => <<"token">>,
|
||||
payment_system => #{id => <<"foo">>},
|
||||
payment_system_deprecated => visa,
|
||||
bin => <<"12345">>,
|
||||
masked_pan => <<"7890">>,
|
||||
bank_name => <<"bank">>,
|
||||
@ -632,26 +604,37 @@ bank_card_codec_test() ->
|
||||
cardholder_name => <<"name">>,
|
||||
bin_data_id => #{<<"foo">> => 1}
|
||||
},
|
||||
Type = {struct, struct, {ff_proto_base_thrift, 'BankCard'}},
|
||||
Binary = ff_proto_utils:serialize(Type, marshal(bank_card, BankCard)),
|
||||
ResourceBankCard =
|
||||
{bank_card, #{
|
||||
bank_card => BankCard,
|
||||
auth_data => {session, #{session_id => <<"session_id">>}}
|
||||
}},
|
||||
{bank_card, MarshalledResourceBankCard} = marshal(resource, ResourceBankCard),
|
||||
Type = {struct, struct, {ff_proto_base_thrift, 'ResourceBankCard'}},
|
||||
Binary = ff_proto_utils:serialize(Type, MarshalledResourceBankCard),
|
||||
Decoded = ff_proto_utils:deserialize(Type, Binary),
|
||||
?assertEqual(
|
||||
Decoded,
|
||||
#'fistful_base_BankCard'{
|
||||
token = <<"token">>,
|
||||
payment_system = #'fistful_base_PaymentSystemRef'{id = <<"foo">>},
|
||||
payment_system_deprecated = visa,
|
||||
bin = <<"12345">>,
|
||||
masked_pan = <<"7890">>,
|
||||
bank_name = <<"bank">>,
|
||||
issuer_country = zmb,
|
||||
card_type = credit_or_debit,
|
||||
exp_date = #'fistful_base_BankCardExpDate'{month = 12, year = 3456},
|
||||
cardholder_name = <<"name">>,
|
||||
bin_data_id = {obj, #{{str, <<"foo">>} => {i, 1}}}
|
||||
#fistful_base_ResourceBankCard{
|
||||
bank_card = #'fistful_base_BankCard'{
|
||||
token = <<"token">>,
|
||||
payment_system = #'fistful_base_PaymentSystemRef'{id = <<"foo">>},
|
||||
bin = <<"12345">>,
|
||||
masked_pan = <<"7890">>,
|
||||
bank_name = <<"bank">>,
|
||||
issuer_country = zmb,
|
||||
card_type = credit_or_debit,
|
||||
exp_date = #'fistful_base_BankCardExpDate'{month = 12, year = 3456},
|
||||
cardholder_name = <<"name">>,
|
||||
bin_data_id = {obj, #{{str, <<"foo">>} => {i, 1}}}
|
||||
},
|
||||
auth_data =
|
||||
{session_data, #'fistful_base_SessionAuthData'{
|
||||
id = <<"session_id">>
|
||||
}}
|
||||
}
|
||||
),
|
||||
?assertEqual(BankCard, unmarshal(bank_card, Decoded)).
|
||||
?assertEqual(ResourceBankCard, unmarshal(resource, {bank_card, Decoded})).
|
||||
|
||||
-spec generic_resource_codec_test() -> _.
|
||||
generic_resource_codec_test() ->
|
||||
|
@ -179,7 +179,7 @@ crypto_wallet_resource_test() ->
|
||||
{crypto_wallet, #{
|
||||
crypto_wallet => #{
|
||||
id => <<"9e6245a7a6e15f75769a4d87183b090a">>,
|
||||
currency => {bitcoin, #{}}
|
||||
currency => #{id => <<"bitcoin">>}
|
||||
}
|
||||
}},
|
||||
?assertEqual(Resource, unmarshal(resource, marshal(resource, Resource))).
|
||||
|
@ -121,7 +121,7 @@ created_v0_0_decoding_test() ->
|
||||
{crypto_wallet, #{
|
||||
crypto_wallet => #{
|
||||
id => <<"kek">>,
|
||||
currency => {bitcoin, #{}}
|
||||
currency => #{id => <<"bitcoin">>}
|
||||
}
|
||||
}},
|
||||
Destination = #{
|
||||
@ -143,9 +143,10 @@ created_v0_0_decoding_test() ->
|
||||
{obj, #{
|
||||
{str, <<"currency">>} =>
|
||||
{arr, [
|
||||
{str, <<"tup">>},
|
||||
{str, <<"bitcoin">>},
|
||||
{arr, [{str, <<"map">>}, {obj, #{}}]}
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"id">>} => {bin, <<"bitcoin">>}
|
||||
}}
|
||||
]},
|
||||
{str, <<"id">>} => {bin, <<"kek">>}
|
||||
}}
|
||||
@ -349,38 +350,6 @@ status_v0_decoding_test() ->
|
||||
Decoded = unmarshal({event, ?CURRENT_EVENT_FORMAT_VERSION}, ModernizedBinary),
|
||||
?assertEqual(Event, Decoded).
|
||||
|
||||
-spec created_v1_3_decoding_test() -> _.
|
||||
created_v1_3_decoding_test() ->
|
||||
Resource =
|
||||
{crypto_wallet, #{
|
||||
crypto_wallet => #{
|
||||
id => <<"kek">>,
|
||||
currency => {bitcoin, #{}}
|
||||
}
|
||||
}},
|
||||
Destination = #{
|
||||
version => 3,
|
||||
resource => Resource,
|
||||
name => <<"name">>,
|
||||
created_at => 1590434350293,
|
||||
external_id => <<"external_id">>
|
||||
},
|
||||
Change = {created, Destination},
|
||||
Event = {ev, {{{2020, 5, 25}, {19, 19, 10}}, 293305}, Change},
|
||||
|
||||
LegacyEvent =
|
||||
{bin,
|
||||
base64:decode(<<
|
||||
"CwABAAAAGzIwMjAtMDUtMjVUMTk6MTk6MTAuMjkzMzA1WgwAAgwAAQsAAQAAAARuYW1lDAA"
|
||||
"CDAACDAABCwABAAAAA2tlawwAAwwAAQAACAACAAAAAAAAAAsAAwAAAAtleHRlcm5hbF9pZA"
|
||||
"sABwAAABgyMDIwLTA1LTI1VDE5OjE5OjEwLjI5M1oAAAA="
|
||||
>>)},
|
||||
|
||||
DecodedLegacy = unmarshal({event, 1}, LegacyEvent),
|
||||
ModernizedBinary = marshal({event, ?CURRENT_EVENT_FORMAT_VERSION}, DecodedLegacy),
|
||||
Decoded = unmarshal({event, ?CURRENT_EVENT_FORMAT_VERSION}, ModernizedBinary),
|
||||
?assertEqual(Event, Decoded).
|
||||
|
||||
-spec account_v1_decoding_test() -> _.
|
||||
account_v1_decoding_test() ->
|
||||
Change =
|
||||
|
@ -276,7 +276,7 @@ try_get_full_resource(ResourceParams, Context) ->
|
||||
% it looks like we have met unsupported card
|
||||
% let's construct some dummy resource
|
||||
{bank_card, Card} = ResourceParams,
|
||||
{bank_card, maps:merge(#{payment_system_deprecated => visa, bin_data_id => nil}, Card)}
|
||||
{bank_card, maps:merge(#{payment_system => #{id => <<"visa">>}, bin_data_id => nil}, Card)}
|
||||
end
|
||||
end.
|
||||
|
||||
@ -445,7 +445,7 @@ created_with_broken_withdrawal_id_test() ->
|
||||
bank_card => #{
|
||||
token => <<"token">>,
|
||||
bin_data_id => {binary, <<"bin">>},
|
||||
payment_system_deprecated => visa
|
||||
payment_system => #{id => <<"visa">>}
|
||||
}
|
||||
}},
|
||||
Quote = #{
|
||||
@ -496,7 +496,13 @@ created_with_broken_withdrawal_id_test() ->
|
||||
{bin, <<"bin">>}
|
||||
]},
|
||||
{str, <<"token">>} => {bin, <<"token">>},
|
||||
{str, <<"payment_system_deprecated">>} => {str, <<"visa">>}
|
||||
{str, <<"payment_system">>} =>
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"id">>} => {bin, <<"visa">>}
|
||||
}}
|
||||
]}
|
||||
}}
|
||||
]}
|
||||
}}
|
||||
@ -582,7 +588,7 @@ created_v0_3_decoding_test() ->
|
||||
bank_card => #{
|
||||
token => <<"token">>,
|
||||
bin_data_id => {binary, <<"bin">>},
|
||||
payment_system_deprecated => visa
|
||||
payment_system => #{id => <<"visa">>}
|
||||
}
|
||||
}},
|
||||
Quote = #{
|
||||
@ -632,7 +638,13 @@ created_v0_3_decoding_test() ->
|
||||
{bin, <<"bin">>}
|
||||
]},
|
||||
{str, <<"token">>} => {bin, <<"token">>},
|
||||
{str, <<"payment_system_deprecated">>} => {str, <<"visa">>}
|
||||
{str, <<"payment_system">>} =>
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"id">>} => {bin, <<"visa">>}
|
||||
}}
|
||||
]}
|
||||
}}
|
||||
]}
|
||||
}}
|
||||
@ -733,7 +745,7 @@ created_v0_unknown_with_binary_provider_decoding_test() ->
|
||||
bank_card => #{
|
||||
bin => <<"123456">>,
|
||||
masked_pan => <<"1234">>,
|
||||
payment_system_deprecated => visa,
|
||||
payment_system => #{id => <<"visa">>},
|
||||
token => <<"token">>
|
||||
}
|
||||
}}
|
||||
@ -784,7 +796,13 @@ created_v0_unknown_with_binary_provider_decoding_test() ->
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{bin, <<"payment_system_deprecated">>} => {bin, <<"Card">>},
|
||||
{str, <<"payment_system">>} =>
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"id">>} => {bin, <<"Card">>}
|
||||
}}
|
||||
]},
|
||||
{bin, <<"timer_timeout">>} => {bin, <<"10">>}
|
||||
}}
|
||||
]}
|
||||
@ -826,8 +844,13 @@ created_v0_unknown_with_binary_provider_decoding_test() ->
|
||||
{obj, #{
|
||||
{str, <<"bin">>} => {bin, <<"123456">>},
|
||||
{str, <<"masked_pan">>} => {bin, <<"1234">>},
|
||||
{str, <<"payment_system_deprecated">>} =>
|
||||
{str, <<"visa">>},
|
||||
{str, <<"payment_system">>} =>
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"id">>} => {bin, <<"visa">>}
|
||||
}}
|
||||
]},
|
||||
{str, <<"token">>} => {bin, <<"token">>}
|
||||
}}
|
||||
]}
|
||||
@ -895,7 +918,7 @@ created_v0_unknown_without_provider_decoding_test() ->
|
||||
bank_card => #{
|
||||
bin => <<"123456">>,
|
||||
masked_pan => <<"1234">>,
|
||||
payment_system_deprecated => visa,
|
||||
payment_system => #{id => <<"visa">>},
|
||||
token => <<"token">>
|
||||
}
|
||||
}}
|
||||
@ -969,8 +992,13 @@ created_v0_unknown_without_provider_decoding_test() ->
|
||||
{obj, #{
|
||||
{str, <<"bin">>} => {bin, <<"123456">>},
|
||||
{str, <<"masked_pan">>} => {bin, <<"1234">>},
|
||||
{str, <<"payment_system_deprecated">>} =>
|
||||
{str, <<"visa">>},
|
||||
{str, <<"payment_system">>} =>
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"id">>} => {bin, <<"visa">>}
|
||||
}}
|
||||
]},
|
||||
{str, <<"token">>} => {bin, <<"token">>}
|
||||
}}
|
||||
]}
|
||||
@ -1082,63 +1110,6 @@ finished_v0_decoding_test() ->
|
||||
Decoded = unmarshal({event, ?CURRENT_EVENT_FORMAT_VERSION}, ModernizedBinary),
|
||||
?assertEqual(Event, Decoded).
|
||||
|
||||
-spec created_v1_decoding_test() -> _.
|
||||
created_v1_decoding_test() ->
|
||||
Resource =
|
||||
{bank_card, #{
|
||||
bank_card => #{
|
||||
token => <<"token">>,
|
||||
bin_data_id => {binary, <<"bin">>},
|
||||
payment_system_deprecated => visa
|
||||
}
|
||||
}},
|
||||
Quote = #{
|
||||
cash_from => {123, <<"RUB">>},
|
||||
cash_to => {123, <<"RUB">>},
|
||||
created_at => <<"some timestamp">>,
|
||||
expires_on => <<"some timestamp">>,
|
||||
quote_data => [1, nil, #{}]
|
||||
},
|
||||
Identity = #{
|
||||
id => <<"ID">>
|
||||
},
|
||||
Withdrawal = #{
|
||||
id => <<"id">>,
|
||||
session_id => <<"session_id">>,
|
||||
resource => Resource,
|
||||
cash => {123, <<"RUB">>},
|
||||
sender => Identity,
|
||||
receiver => Identity,
|
||||
quote => Quote
|
||||
},
|
||||
Session = #{
|
||||
version => 5,
|
||||
id => <<"id">>,
|
||||
status => active,
|
||||
withdrawal => Withdrawal,
|
||||
route => #{provider_id => 1},
|
||||
|
||||
% Deprecated. Remove after MSPF-560 finish
|
||||
provider_legacy => <<"-299">>
|
||||
},
|
||||
Change = {created, Session},
|
||||
Event = {ev, {{{2020, 5, 25}, {19, 19, 10}}, 293305}, Change},
|
||||
LegacyEvent =
|
||||
{bin,
|
||||
base64:decode(<<
|
||||
"CwABAAAAGzIwMjAtMDUtMjVUMTk6MTk6MTAuMjkzMzA1WgwAAgwAAQsAAQAAAAJpZAwAAwsAAQAAAAJp"
|
||||
"ZAwAAgwAAQwAAQsAAQAAAAV0b2tlbggAAgAAAAAMABULAAYAAAADYmluAAAAAAwAAwoAAQAAAAAAAAB7"
|
||||
"DAACCwABAAAAA1JVQgAADAAICwABAAAAAklEAAwACQsAAQAAAAJJRAALAAYAAAAKc2Vzc2lvbl9pZAwA"
|
||||
"BwwAAQoAAQAAAAAAAAB7DAACCwABAAAAA1JVQgAADAACCgABAAAAAAAAAHsMAAILAAEAAAADUlVCAAAL"
|
||||
"AAMAAAAOc29tZSB0aW1lc3RhbXALAAQAAAAOc29tZSB0aW1lc3RhbXAMAAYPAAgMAAAAAwoAAwAAAAAA"
|
||||
"AAABAAwAAQAADQAHDAwAAAAAAAANAAULDAAAAAAAAAwABggAAQAAAAEADAACDAABAAALAAQAAAAELTI5"
|
||||
"OQAAAA=="
|
||||
>>)},
|
||||
DecodedLegacy = unmarshal({event, 1}, LegacyEvent),
|
||||
ModernizedBinary = marshal({event, ?CURRENT_EVENT_FORMAT_VERSION}, DecodedLegacy),
|
||||
Decoded = unmarshal({event, ?CURRENT_EVENT_FORMAT_VERSION}, ModernizedBinary),
|
||||
?assertEqual(Event, Decoded).
|
||||
|
||||
-spec next_state_v1_decoding_test() -> _.
|
||||
next_state_v1_decoding_test() ->
|
||||
Change = {next_state, <<"next_state">>},
|
||||
|
@ -92,8 +92,7 @@ create_crypto_wallet_destination_ok(C) ->
|
||||
{crypto_wallet, #'fistful_base_ResourceCryptoWallet'{
|
||||
crypto_wallet = #'fistful_base_CryptoWallet'{
|
||||
id = <<"f195298af836f41d072cb390ee62bee8">>,
|
||||
currency = bitcoin_cash,
|
||||
data = {bitcoin_cash, #'fistful_base_CryptoDataBitcoinCash'{}}
|
||||
currency = #'fistful_base_CryptoCurrencyRef'{id = <<"bitcoin_cash">>}
|
||||
}
|
||||
}},
|
||||
create_destination_ok(Resource, C).
|
||||
@ -104,8 +103,7 @@ create_ripple_wallet_destination_ok(C) ->
|
||||
{crypto_wallet, #'fistful_base_ResourceCryptoWallet'{
|
||||
crypto_wallet = #'fistful_base_CryptoWallet'{
|
||||
id = <<"ab843336bf7738dc697522fbb90508de">>,
|
||||
currency = ripple,
|
||||
data = {ripple, #'fistful_base_CryptoDataRipple'{tag = undefined}}
|
||||
currency = #'fistful_base_CryptoCurrencyRef'{id = <<"ripple">>}
|
||||
}
|
||||
}},
|
||||
create_destination_ok(Resource, C).
|
||||
|
@ -110,6 +110,8 @@ get_withdrawal_methods_ok(_C) ->
|
||||
{ok, [
|
||||
{bank_card, _},
|
||||
{crypto_currency, _},
|
||||
{crypto_currency, _},
|
||||
{crypto_currency, _},
|
||||
{digital_wallet, _},
|
||||
{generic, _}
|
||||
]} = call_api('GetWithdrawalMethods', {ID}).
|
||||
|
@ -177,12 +177,10 @@ marshal(
|
||||
CardHolderName = maps:get(cardholder_name, BankCard, undefined),
|
||||
ExpDate = maps:get(exp_date, BankCard, undefined),
|
||||
PaymentSystem = maps:get(payment_system, BankCard, undefined),
|
||||
PaymentSystemDeprecated = maps:get(payment_system_deprecated, BankCard, undefined),
|
||||
IssuerCountry = maps:get(issuer_country, BankCard, undefined),
|
||||
{bank_card, #domain_BankCard{
|
||||
token = Token,
|
||||
payment_system = maybe_marshal(payment_system, PaymentSystem),
|
||||
payment_system_deprecated = PaymentSystemDeprecated,
|
||||
issuer_country = IssuerCountry,
|
||||
bin = BIN,
|
||||
last_digits = LastDigits,
|
||||
@ -192,16 +190,16 @@ marshal(
|
||||
marshal(
|
||||
resource,
|
||||
{crypto_wallet, #{
|
||||
crypto_wallet := #{
|
||||
crypto_wallet := CryptoWallet = #{
|
||||
id := CryptoWalletID,
|
||||
currency := {Currency, Data}
|
||||
currency := Currency
|
||||
}
|
||||
}}
|
||||
) ->
|
||||
{crypto_wallet, #domain_CryptoWallet{
|
||||
id = CryptoWalletID,
|
||||
crypto_currency_deprecated = Currency,
|
||||
destination_tag = maps:get(tag, Data, undefined)
|
||||
crypto_currency = ff_dmsl_codec:marshal(crypto_currency, Currency),
|
||||
destination_tag = maps:get(tag, CryptoWallet, undefined)
|
||||
}};
|
||||
marshal(
|
||||
resource,
|
||||
|
@ -227,11 +227,10 @@ apply_event({account, Ev}, Destination) ->
|
||||
-spec maybe_migrate(event() | legacy_event(), ff_machine:migrate_params()) -> event().
|
||||
maybe_migrate(Event = {created, #{version := ?ACTUAL_FORMAT_VERSION}}, _MigrateParams) ->
|
||||
Event;
|
||||
maybe_migrate({created, Destination = #{version := 4, resource := Resource}}, MigrateParams) ->
|
||||
maybe_migrate({created, Destination = #{version := 4}}, MigrateParams) ->
|
||||
maybe_migrate(
|
||||
{created, Destination#{
|
||||
version => 5,
|
||||
resource => maybe_migrate_payment_system(Resource)
|
||||
version => 5
|
||||
}},
|
||||
MigrateParams
|
||||
);
|
||||
@ -296,48 +295,9 @@ maybe_migrate_resource({bank_card, #{token := _Token} = BankCard}) ->
|
||||
maybe_migrate_resource(Resource) ->
|
||||
Resource.
|
||||
|
||||
maybe_migrate_payment_system({bank_card, #{bank_card := BankCard}}) ->
|
||||
PaymentSystem = get_payment_system(BankCard),
|
||||
PaymentSystemDeprecated = get_payment_system_deprecated(BankCard),
|
||||
{bank_card, #{
|
||||
bank_card => genlib_map:compact(BankCard#{
|
||||
payment_system_deprecated => PaymentSystemDeprecated,
|
||||
payment_system => PaymentSystem
|
||||
})
|
||||
}};
|
||||
maybe_migrate_payment_system(Resource) ->
|
||||
Resource.
|
||||
|
||||
maybe_migrate_name(Name) ->
|
||||
re:replace(Name, "\\d{12,19}", <<"">>, [global, {return, binary}]).
|
||||
|
||||
get_payment_system_deprecated(BankCard) ->
|
||||
case maps:get(payment_system, BankCard, undefined) of
|
||||
PS when is_map(PS) ->
|
||||
%% It looks like BankCard is new structure where
|
||||
%% payment_system set to reference (map), so return
|
||||
%% payment_system_deprecated's value if any
|
||||
maps:get(payment_system_deprecated, BankCard, undefined);
|
||||
PS when is_atom(PS) ->
|
||||
%% It looks like BankCard is old data structure
|
||||
%% so just return value (i.e. migrate structure
|
||||
%% to new one).
|
||||
PS
|
||||
end.
|
||||
|
||||
get_payment_system(BankCard) ->
|
||||
case maps:get(payment_system, BankCard, undefined) of
|
||||
PS when is_map(PS) ->
|
||||
%% It looks like BankCard is new data structure, no
|
||||
%% need to modify payment_system
|
||||
PS;
|
||||
_ ->
|
||||
%% It looks like BankCard is old data structure,
|
||||
%% so remove payment_system's value (i.e. migrate
|
||||
%% structure to new one)
|
||||
undefined
|
||||
end.
|
||||
|
||||
%% Tests
|
||||
|
||||
-ifdef(TEST).
|
||||
@ -385,42 +345,11 @@ v2_created_migration_test() ->
|
||||
?assertEqual(5, Version),
|
||||
?assertEqual(#{<<"some key">> => <<"some val">>}, Metadata).
|
||||
|
||||
-spec v4_created_migration_old_test() -> _.
|
||||
v4_created_migration_old_test() ->
|
||||
CreatedAt = ff_time:now(),
|
||||
BankCard = #{
|
||||
token => <<"token">>,
|
||||
payment_system => visa,
|
||||
bin => <<"12345">>,
|
||||
masked_pan => <<"7890">>,
|
||||
bank_name => <<"bank">>,
|
||||
issuer_country => zmb,
|
||||
card_type => credit_or_debit,
|
||||
exp_date => {12, 3456},
|
||||
cardholder_name => <<"name">>,
|
||||
bin_data_id => #{<<"foo">> => 1}
|
||||
},
|
||||
LegacyEvent =
|
||||
{created, #{
|
||||
version => 4,
|
||||
resource => {bank_card, #{bank_card => BankCard}},
|
||||
name => <<"some name">>,
|
||||
external_id => genlib:unique(),
|
||||
created_at => CreatedAt
|
||||
}},
|
||||
{created, #{version := Version, resource := {bank_card, #{bank_card := NewBankCard}}}} = maybe_migrate(
|
||||
LegacyEvent, #{}
|
||||
),
|
||||
?assertEqual(5, Version),
|
||||
?assertEqual(visa, maps:get(payment_system_deprecated, NewBankCard)),
|
||||
?assertError({badkey, payment_system}, maps:get(payment_system, NewBankCard)).
|
||||
|
||||
-spec v4_created_migration_new_test() -> _.
|
||||
v4_created_migration_new_test() ->
|
||||
CreatedAt = ff_time:now(),
|
||||
BankCard = #{
|
||||
token => <<"token">>,
|
||||
payment_system_deprecated => visa,
|
||||
payment_system => #{id => <<"VISA">>},
|
||||
bin => <<"12345">>,
|
||||
masked_pan => <<"7890">>,
|
||||
@ -443,37 +372,6 @@ v4_created_migration_new_test() ->
|
||||
LegacyEvent, #{}
|
||||
),
|
||||
?assertEqual(5, Version),
|
||||
?assertEqual(visa, maps:get(payment_system_deprecated, NewBankCard)),
|
||||
?assertEqual(#{id => <<"VISA">>}, maps:get(payment_system, NewBankCard)).
|
||||
|
||||
-spec v4_created_migration_test() -> _.
|
||||
v4_created_migration_test() ->
|
||||
CreatedAt = ff_time:now(),
|
||||
BankCard = #{
|
||||
token => <<"token">>,
|
||||
payment_system => #{id => <<"VISA">>},
|
||||
bin => <<"12345">>,
|
||||
masked_pan => <<"7890">>,
|
||||
bank_name => <<"bank">>,
|
||||
issuer_country => zmb,
|
||||
card_type => credit_or_debit,
|
||||
exp_date => {12, 3456},
|
||||
cardholder_name => <<"name">>,
|
||||
bin_data_id => #{<<"foo">> => 1}
|
||||
},
|
||||
LegacyEvent =
|
||||
{created, #{
|
||||
version => 4,
|
||||
resource => {bank_card, #{bank_card => BankCard}},
|
||||
name => <<"some name">>,
|
||||
external_id => genlib:unique(),
|
||||
created_at => CreatedAt
|
||||
}},
|
||||
{created, #{version := Version, resource := {bank_card, #{bank_card := NewBankCard}}}} = maybe_migrate(
|
||||
LegacyEvent, #{}
|
||||
),
|
||||
?assertEqual(5, Version),
|
||||
?assertError({badkey, payment_system_deprecated}, maps:get(payment_system_deprecated, NewBankCard)),
|
||||
?assertEqual(#{id => <<"VISA">>}, maps:get(payment_system, NewBankCard)).
|
||||
|
||||
-spec name_migration_test() -> _.
|
||||
|
@ -415,11 +415,11 @@ create(Params) ->
|
||||
Identity = get_wallet_identity(Wallet),
|
||||
Destination = unwrap(destination, get_destination(DestinationID)),
|
||||
ResourceParams = ff_destination:resource(Destination),
|
||||
valid = ff_resource:check_resource(DomainRevision, ResourceParams),
|
||||
Resource = unwrap(
|
||||
destination_resource,
|
||||
create_resource(ResourceParams, ResourceDescriptor, Identity, DomainRevision)
|
||||
),
|
||||
valid = ff_resource:check_resource(DomainRevision, Resource),
|
||||
PartyID = ff_identity:party(Identity),
|
||||
VarsetParams = genlib_map:compact(#{
|
||||
body => Body,
|
||||
@ -1135,12 +1135,11 @@ construct_payment_tool({bank_card, #{bank_card := ResourceBankCard}}) ->
|
||||
bin = maps:get(bin, ResourceBankCard),
|
||||
last_digits = maps:get(masked_pan, ResourceBankCard),
|
||||
payment_system = ff_dmsl_codec:marshal(payment_system, PaymentSystem),
|
||||
payment_system_deprecated = maps:get(payment_system_deprecated, ResourceBankCard, undefined),
|
||||
issuer_country = maps:get(issuer_country, ResourceBankCard, undefined),
|
||||
bank_name = maps:get(bank_name, ResourceBankCard, undefined)
|
||||
}};
|
||||
construct_payment_tool({crypto_wallet, #{crypto_wallet := #{currency := {Currency, _}}}}) ->
|
||||
{crypto_currency_deprecated, Currency};
|
||||
construct_payment_tool({crypto_wallet, #{crypto_wallet := #{currency := Currency}}}) ->
|
||||
{crypto_currency, ff_dmsl_codec:marshal(crypto_currency, Currency)};
|
||||
construct_payment_tool(Resource = {generic, _}) ->
|
||||
ff_dmsl_codec:marshal(payment_tool, Resource);
|
||||
construct_payment_tool(
|
||||
|
@ -521,7 +521,7 @@ create_crypto_destination(IID, _C) ->
|
||||
{crypto_wallet, #{
|
||||
crypto_wallet => #{
|
||||
id => <<"a30e277c07400c9940628828949efd48">>,
|
||||
currency => {litecoin, #{}}
|
||||
currency => #{id => <<"Litecoin">>}
|
||||
}
|
||||
}},
|
||||
DestID = create_destination(IID, <<"CryptoDestination">>, <<"RUB">>, Resource),
|
||||
|
@ -936,7 +936,7 @@ create_crypto_destination(IID, _C) ->
|
||||
{crypto_wallet, #{
|
||||
crypto_wallet => #{
|
||||
id => <<"a30e277c07400c9940628828949efd48">>,
|
||||
currency => {litecoin, #{}}
|
||||
currency => #{id => <<"Litecoin">>}
|
||||
}
|
||||
}},
|
||||
Params = #{id => ID, identity => IID, name => <<"CryptoDestination">>, currency => <<"RUB">>, resource => Resource},
|
||||
@ -1074,7 +1074,9 @@ withdrawal_misconfig_termset_fixture() ->
|
||||
{bank_card, #domain_BankCardCondition{
|
||||
definition =
|
||||
{payment_system, #domain_PaymentSystemCondition{
|
||||
payment_system_is_deprecated = visa
|
||||
payment_system_is = #domain_PaymentSystemRef{
|
||||
id = <<"VISA">>
|
||||
}
|
||||
}}
|
||||
}}}}
|
||||
])},
|
||||
|
@ -6,14 +6,12 @@
|
||||
-type token() :: binary().
|
||||
-type issuer_country() :: atom().
|
||||
-type payment_system() :: binary().
|
||||
-type payment_system_deprecated() :: atom().
|
||||
|
||||
-type response_data() :: binbase_binbase_thrift:'ResponseData'().
|
||||
-type bin_data() :: #{
|
||||
token := token(),
|
||||
id := bin_data_id(),
|
||||
payment_system := payment_system(),
|
||||
payment_system_deprecated => payment_system_deprecated(),
|
||||
bank_name => binary(),
|
||||
issuer_country => issuer_country(),
|
||||
card_type => charge_card | credit | debit | credit_or_debit,
|
||||
@ -42,7 +40,6 @@
|
||||
-export_type([bin_data_error/0]).
|
||||
-export_type([issuer_country/0]).
|
||||
-export_type([payment_system/0]).
|
||||
-export_type([payment_system_deprecated/0]).
|
||||
|
||||
-export([get/2]).
|
||||
-export([id/1]).
|
||||
@ -110,7 +107,6 @@ decode_result(Token, #'binbase_ResponseData'{bin_data = Bindata, version = Versi
|
||||
token => Token,
|
||||
id => decode_msgpack(BinDataID),
|
||||
payment_system => unwrap(decode_payment_system(PaymentSystem)),
|
||||
payment_system_deprecated => decode_payment_system_deprecated(PaymentSystem),
|
||||
bank_name => BankName,
|
||||
issuer_country => unwrap(decode_residence(IsoCountryCode)),
|
||||
card_type => decode_card_type(CardType),
|
||||
@ -140,25 +136,6 @@ decode_msgpack({obj, V}) when is_map(V) ->
|
||||
decode_payment_system(PaymentSystem) when is_binary(PaymentSystem) ->
|
||||
{ok, PaymentSystem}.
|
||||
|
||||
decode_payment_system_deprecated(<<"VISA">>) -> visa;
|
||||
decode_payment_system_deprecated(<<"VISA/DANKORT">>) -> visa;
|
||||
decode_payment_system_deprecated(<<"MASTERCARD">>) -> mastercard;
|
||||
decode_payment_system_deprecated(<<"MAESTRO">>) -> maestro;
|
||||
decode_payment_system_deprecated(<<"DANKORT">>) -> dankort;
|
||||
decode_payment_system_deprecated(<<"AMERICAN EXPRESS">>) -> amex;
|
||||
decode_payment_system_deprecated(<<"DINERS CLUB INTERNATIONAL">>) -> dinersclub;
|
||||
decode_payment_system_deprecated(<<"DISCOVER">>) -> discover;
|
||||
decode_payment_system_deprecated(<<"UNIONPAY">>) -> unionpay;
|
||||
decode_payment_system_deprecated(<<"CHINA UNION PAY">>) -> unionpay;
|
||||
decode_payment_system_deprecated(<<"JCB">>) -> jcb;
|
||||
decode_payment_system_deprecated(<<"NSPK MIR">>) -> nspkmir;
|
||||
decode_payment_system_deprecated(<<"ELO">>) -> elo;
|
||||
decode_payment_system_deprecated(<<"RUPAY">>) -> rupay;
|
||||
decode_payment_system_deprecated(<<"EBT">>) -> ebt;
|
||||
decode_payment_system_deprecated(<<"DUMMY">>) -> dummy;
|
||||
decode_payment_system_deprecated(<<"UZCARD">>) -> uzcard;
|
||||
decode_payment_system_deprecated(_) -> undefined.
|
||||
|
||||
decode_card_type(undefined) ->
|
||||
undefined;
|
||||
decode_card_type(Type) ->
|
||||
|
@ -146,7 +146,6 @@ unmarshal(
|
||||
{bank_card, #domain_BankCard{
|
||||
token = Token,
|
||||
payment_system = PaymentSystem,
|
||||
payment_system_deprecated = PaymentSystemDeprecated,
|
||||
issuer_country = IssuerCountry,
|
||||
bin = Bin,
|
||||
last_digits = LastDigits,
|
||||
@ -168,7 +167,6 @@ unmarshal(
|
||||
bank_card => #{
|
||||
token => Token,
|
||||
payment_system => maybe_unmarshal(payment_system, PaymentSystem),
|
||||
payment_system_deprecated => PaymentSystemDeprecated,
|
||||
issuer_country => maybe_unmarshal(issuer_country, IssuerCountry),
|
||||
bin => Bin,
|
||||
masked_pan => LastDigits,
|
||||
@ -292,7 +290,6 @@ marshal(bank_card, BankCard) ->
|
||||
bin = ff_resource:bin(BankCard),
|
||||
last_digits = ff_resource:masked_pan(BankCard),
|
||||
payment_system = maybe_marshal(payment_system, PaymentSystem),
|
||||
payment_system_deprecated = ff_resource:payment_system_deprecated(BankCard),
|
||||
issuer_country = ff_resource:issuer_country(BankCard),
|
||||
bank_name = ff_resource:bank_name(BankCard),
|
||||
exp_date = maybe_marshal(exp_date, ExpDate),
|
||||
|
@ -50,7 +50,8 @@
|
||||
|
||||
-type crypto_wallet_params() :: #{
|
||||
id := binary(),
|
||||
currency := crypto_currency()
|
||||
currency := crypto_currency(),
|
||||
tag => binary()
|
||||
}.
|
||||
|
||||
-type resource_digital_wallet_params() :: #{
|
||||
@ -73,7 +74,6 @@
|
||||
token := token(),
|
||||
bin => bin(),
|
||||
payment_system => payment_system(),
|
||||
payment_system_deprecated => payment_system_deprecated(),
|
||||
masked_pan => masked_pan(),
|
||||
bank_name => bank_name(),
|
||||
issuer_country => issuer_country(),
|
||||
@ -92,13 +92,16 @@
|
||||
-type payment_service() :: #{
|
||||
id := binary()
|
||||
}.
|
||||
-type crypto_currency() :: #{
|
||||
id := binary()
|
||||
}.
|
||||
|
||||
-type method() ::
|
||||
{bank_card, {payment_system, payment_system()}}
|
||||
| {digital_wallet, {payment_service, payment_service()}}
|
||||
| {generic, {payment_service, payment_service()}}.
|
||||
{bank_card, #{payment_system := payment_system()}}
|
||||
| {digital_wallet, payment_service()}
|
||||
| {crypto_currency, crypto_currency()}
|
||||
| {generic, #{payment_service := payment_service()}}.
|
||||
|
||||
-type payment_system_deprecated() :: ff_bin_data:payment_system_deprecated().
|
||||
-type masked_pan() :: binary().
|
||||
-type bank_name() :: binary().
|
||||
-type issuer_country() :: ff_bin_data:issuer_country().
|
||||
@ -123,18 +126,10 @@
|
||||
|
||||
-type crypto_wallet() :: #{
|
||||
id := binary(),
|
||||
currency := crypto_currency()
|
||||
currency := crypto_currency(),
|
||||
tag => binary()
|
||||
}.
|
||||
|
||||
-type crypto_currency() ::
|
||||
{bitcoin, #{}}
|
||||
| {bitcoin_cash, #{}}
|
||||
| {litecoin, #{}}
|
||||
| {ethereum, #{}}
|
||||
| {zcash, #{}}
|
||||
| {usdt, #{}}
|
||||
| {ripple, #{tag => binary()}}.
|
||||
|
||||
-type digital_wallet() :: #{
|
||||
id := binary(),
|
||||
payment_service := payment_service(),
|
||||
@ -163,7 +158,6 @@
|
||||
-export_type([token/0]).
|
||||
-export_type([bin/0]).
|
||||
-export_type([payment_system/0]).
|
||||
-export_type([payment_system_deprecated/0]).
|
||||
-export_type([masked_pan/0]).
|
||||
-export_type([bank_name/0]).
|
||||
-export_type([issuer_country/0]).
|
||||
@ -181,11 +175,11 @@
|
||||
-export([token/1]).
|
||||
-export([masked_pan/1]).
|
||||
-export([payment_system/1]).
|
||||
-export([payment_system_deprecated/1]).
|
||||
-export([issuer_country/1]).
|
||||
-export([category/1]).
|
||||
-export([bank_name/1]).
|
||||
-export([exp_date/1]).
|
||||
-export([card_type/1]).
|
||||
-export([cardholder_name/1]).
|
||||
-export([resource_descriptor/1]).
|
||||
-export([method/1]).
|
||||
@ -196,64 +190,65 @@
|
||||
token(#{token := Token}) ->
|
||||
Token.
|
||||
|
||||
-spec bin(bank_card()) -> bin().
|
||||
-spec bin(bank_card()) -> ff_maybe:maybe(bin()).
|
||||
bin(BankCard) ->
|
||||
maps:get(bin, BankCard, undefined).
|
||||
|
||||
-spec bin_data_id(bank_card()) -> bin_data_id().
|
||||
bin_data_id(#{bin_data_id := BinDataID}) ->
|
||||
BinDataID.
|
||||
-spec bin_data_id(bank_card()) -> ff_maybe:maybe(bin_data_id()).
|
||||
bin_data_id(BankCard) ->
|
||||
maps:get(bin_data_id, BankCard, undefined).
|
||||
|
||||
-spec masked_pan(bank_card()) -> masked_pan().
|
||||
-spec masked_pan(bank_card()) -> ff_maybe:maybe(masked_pan()).
|
||||
masked_pan(BankCard) ->
|
||||
maps:get(masked_pan, BankCard, undefined).
|
||||
|
||||
-spec payment_system(bank_card()) -> payment_system().
|
||||
-spec payment_system(bank_card()) -> ff_maybe:maybe(payment_system()).
|
||||
payment_system(BankCard) ->
|
||||
maps:get(payment_system, BankCard, undefined).
|
||||
|
||||
-spec payment_system_deprecated(bank_card()) -> payment_system_deprecated().
|
||||
payment_system_deprecated(BankCard) ->
|
||||
maps:get(payment_system_deprecated, BankCard, undefined).
|
||||
|
||||
-spec issuer_country(bank_card()) -> issuer_country().
|
||||
-spec issuer_country(bank_card()) -> ff_maybe:maybe(issuer_country()).
|
||||
issuer_country(BankCard) ->
|
||||
maps:get(issuer_country, BankCard, undefined).
|
||||
|
||||
-spec category(bank_card()) -> category().
|
||||
-spec category(bank_card()) -> ff_maybe:maybe(category()).
|
||||
category(BankCard) ->
|
||||
maps:get(category, BankCard, undefined).
|
||||
|
||||
-spec bank_name(bank_card()) -> bank_name().
|
||||
-spec bank_name(bank_card()) -> ff_maybe:maybe(bank_name()).
|
||||
bank_name(BankCard) ->
|
||||
maps:get(bank_name, BankCard, undefined).
|
||||
|
||||
-spec exp_date(bank_card()) -> exp_date().
|
||||
-spec exp_date(bank_card()) -> ff_maybe:maybe(exp_date()).
|
||||
exp_date(BankCard) ->
|
||||
maps:get(exp_date, BankCard, undefined).
|
||||
|
||||
-spec cardholder_name(bank_card()) -> cardholder_name().
|
||||
-spec card_type(bank_card()) -> ff_maybe:maybe(card_type()).
|
||||
card_type(BankCard) ->
|
||||
maps:get(card_type, BankCard, undefined).
|
||||
|
||||
-spec cardholder_name(bank_card()) -> ff_maybe:maybe(cardholder_name()).
|
||||
cardholder_name(BankCard) ->
|
||||
maps:get(cardholder_name, BankCard, undefined).
|
||||
|
||||
-spec resource_descriptor(resource() | undefined) -> resource_descriptor() | undefined.
|
||||
-spec resource_descriptor(ff_maybe:maybe(resource())) -> ff_maybe:maybe(resource_descriptor()).
|
||||
resource_descriptor({bank_card, #{bank_card := #{bin_data_id := ID}}}) ->
|
||||
{bank_card, ID};
|
||||
resource_descriptor(_) ->
|
||||
undefined.
|
||||
|
||||
-spec method(resource()) ->
|
||||
method() | undefined.
|
||||
-spec method(resource()) -> ff_maybe:maybe(method()).
|
||||
method({bank_card, #{bank_card := #{payment_system := PaymentSystem}}}) ->
|
||||
{bank_card, #{payment_system => PaymentSystem}};
|
||||
method({digital_wallet, #{digital_wallet := #{payment_service := PaymentService}}}) ->
|
||||
{digital_wallet, PaymentService};
|
||||
method({crypto_wallet, #{crypto_wallet := #{currency := CryptoCurrency}}}) ->
|
||||
{crypto_currency, CryptoCurrency};
|
||||
method({generic, #{generic := #{provider := PaymentService}}}) ->
|
||||
{generic, #{payment_service => PaymentService}};
|
||||
method(_) ->
|
||||
undefined.
|
||||
|
||||
-spec get_bin_data(binary(), resource_descriptor() | undefined) ->
|
||||
-spec get_bin_data(binary(), ff_maybe:maybe(resource_descriptor())) ->
|
||||
{ok, bin_data()}
|
||||
| {error, bin_data_error()}.
|
||||
get_bin_data(Token, undefined) ->
|
||||
@ -272,10 +267,19 @@ check_resource(Revision, {digital_wallet, #{digital_wallet := #{payment_service
|
||||
MarshalledPaymentService = ff_dmsl_codec:marshal(payment_service, PaymentService),
|
||||
{ok, _} = ff_domain_config:object(Revision, {payment_service, MarshalledPaymentService}),
|
||||
valid;
|
||||
check_resource(Revision, {crypto_wallet, #{crypto_wallet := #{currency := CryptoCurrency}}}) ->
|
||||
MarshalledCryptoCurrency = ff_dmsl_codec:marshal(crypto_currency, CryptoCurrency),
|
||||
{ok, _} = ff_domain_config:object(Revision, {crypto_currency, MarshalledCryptoCurrency}),
|
||||
valid;
|
||||
check_resource(Revision, {generic, #{generic := #{provider := PaymentService}}}) ->
|
||||
MarshalledPaymentService = ff_dmsl_codec:marshal(payment_service, PaymentService),
|
||||
{ok, _} = ff_domain_config:object(Revision, {payment_service, MarshalledPaymentService}),
|
||||
valid;
|
||||
check_resource(Revision, {bank_card, #{bank_card := #{payment_system := PaymentSystem}}}) ->
|
||||
MarshalledPaymentSystem = ff_dmsl_codec:marshal(payment_system, PaymentSystem),
|
||||
{ok, _} = ff_domain_config:object(Revision, {payment_system, MarshalledPaymentSystem}),
|
||||
valid;
|
||||
%% For bank cards struct with token only
|
||||
check_resource(_, _) ->
|
||||
valid.
|
||||
|
||||
@ -310,7 +314,7 @@ create_bank_card(#{bank_card := #{token := Token}} = ResourceBankCardParams, Res
|
||||
|
||||
-spec create_bank_card_basic(resource_bank_card_params(), bin_data(), payment_system() | undefined) -> {ok, resource()}.
|
||||
create_bank_card_basic(#{bank_card := BankCardParams0} = ResourceBankCardParams, BinData, PaymentSystem) ->
|
||||
KeyList = [payment_system_deprecated, bank_name, issuer_country, card_type, category],
|
||||
KeyList = [bank_name, issuer_country, card_type, category],
|
||||
ExtendData0 = maps:with(KeyList, BinData),
|
||||
ExtendData1 = ExtendData0#{bin_data_id => ff_bin_data:id(BinData)},
|
||||
BankCardParams1 = genlib_map:compact(BankCardParams0#{payment_system => PaymentSystem}),
|
||||
@ -323,17 +327,18 @@ create_bank_card_basic(#{bank_card := BankCardParams0} = ResourceBankCardParams,
|
||||
|
||||
-spec create_crypto_wallet(resource_crypto_wallet_params()) -> {ok, resource()}.
|
||||
create_crypto_wallet(#{
|
||||
crypto_wallet := #{
|
||||
crypto_wallet := CryptoWallet = #{
|
||||
id := ID,
|
||||
currency := Currency
|
||||
}
|
||||
}) ->
|
||||
{ok,
|
||||
{crypto_wallet, #{
|
||||
crypto_wallet => #{
|
||||
crypto_wallet => genlib_map:compact(#{
|
||||
id => ID,
|
||||
currency => Currency
|
||||
}
|
||||
currency => Currency,
|
||||
tag => maps:get(tag, CryptoWallet, undefined)
|
||||
})
|
||||
}}}.
|
||||
|
||||
-spec create_digital_wallet(resource_digital_wallet_params()) -> {ok, resource()}.
|
||||
|
@ -55,13 +55,13 @@ encode_contract_terms_varset(Varset) ->
|
||||
dmsl_domain_thrift:'PaymentMethodRef'() | undefined.
|
||||
encode_payment_method(undefined) ->
|
||||
undefined;
|
||||
encode_payment_method({bank_card, #domain_BankCard{payment_system_deprecated = PaymentSystem}}) ->
|
||||
encode_payment_method({bank_card, #domain_BankCard{payment_system = PaymentSystem}}) ->
|
||||
#domain_PaymentMethodRef{
|
||||
id = {bank_card_deprecated, PaymentSystem}
|
||||
id = {bank_card, #domain_BankCardPaymentMethod{payment_system = PaymentSystem}}
|
||||
};
|
||||
encode_payment_method({crypto_currency_deprecated, CryptoCurrency}) ->
|
||||
encode_payment_method({crypto_currency, CryptoCurrency}) ->
|
||||
#domain_PaymentMethodRef{
|
||||
id = {crypto_currency_deprecated, CryptoCurrency}
|
||||
id = {crypto_currency, CryptoCurrency}
|
||||
};
|
||||
encode_payment_method({digital_wallet, #domain_DigitalWallet{payment_service = PaymentService}}) ->
|
||||
#domain_PaymentMethodRef{
|
||||
|
@ -38,7 +38,7 @@
|
||||
0},
|
||||
{<<"fistful_proto">>,
|
||||
{git,"https://github.com/valitydev/fistful-proto.git",
|
||||
{ref,"543f7814b2ce34c530f277fd2035e441afa86273"}},
|
||||
{ref,"c45166d018d36a75452c3007f704e8fd3ad1056c"}},
|
||||
0},
|
||||
{<<"genlib">>,
|
||||
{git,"https://github.com/valitydev/genlib.git",
|
||||
|
Loading…
Reference in New Issue
Block a user