diff --git a/apps/ff_transfer/src/ff_adapter_withdrawal.erl b/apps/ff_transfer/src/ff_adapter_withdrawal.erl index 18a1865..d2782cd 100644 --- a/apps/ff_transfer/src/ff_adapter_withdrawal.erl +++ b/apps/ff_transfer/src/ff_adapter_withdrawal.erl @@ -55,7 +55,8 @@ external_id => binary(), currency_from := ff_currency:id(), currency_to := ff_currency:id(), - body := cash() + body := cash(), + resource => resource() }. -type quote() :: quote(quote_data()). diff --git a/apps/ff_transfer/src/ff_adapter_withdrawal_codec.erl b/apps/ff_transfer/src/ff_adapter_withdrawal_codec.erl index 51f1c2d..c78a8dd 100644 --- a/apps/ff_transfer/src/ff_adapter_withdrawal_codec.erl +++ b/apps/ff_transfer/src/ff_adapter_withdrawal_codec.erl @@ -164,10 +164,12 @@ marshal( } = Params ) -> ExternalID = maps:get(external_id, Params, undefined), + Resource = maps:get(resource, Params, undefined), {ok, CurrencyFrom} = ff_currency:get(CurrencyIDFrom), {ok, CurrencyTo} = ff_currency:get(CurrencyIDTo), #wthd_provider_GetQuoteParams{ idempotency_id = ExternalID, + destination = maybe_marshal(resource, Resource), currency_from = marshal(currency, CurrencyFrom), currency_to = marshal(currency, CurrencyTo), exchange_cash = marshal(body, Body) diff --git a/apps/ff_transfer/src/ff_withdrawal.erl b/apps/ff_transfer/src/ff_withdrawal.erl index cc1f6fb..404e405 100644 --- a/apps/ff_transfer/src/ff_withdrawal.erl +++ b/apps/ff_transfer/src/ff_withdrawal.erl @@ -1231,12 +1231,15 @@ construct_payment_tool( get_quote(Params = #{destination_id := DestinationID, body := Body, wallet_id := WalletID}) -> do(fun() -> Destination = unwrap(destination, get_destination(DestinationID)), - Resource = unwrap(destination_resource, ff_resource:create_resource(ff_destination:resource(Destination))), Wallet = unwrap(wallet, get_wallet(WalletID)), Identity = get_wallet_identity(Wallet), PartyID = ff_identity:party(Identity), DomainRevision = ff_domain_config:head(), {ok, PartyRevision} = ff_party:get_revision(PartyID), + Resource = unwrap( + destination_resource, + create_resource(ff_destination:resource(Destination), undefined, Identity, DomainRevision) + ), VarsetParams = genlib_map:compact(#{ body => Body, wallet_id => WalletID, @@ -1254,7 +1257,6 @@ get_quote(Params = #{destination_id := DestinationID, body := Body, wallet_id := domain_revision => DomainRevision, varset => PartyVarset }), - valid = unwrap(validate_withdrawal_creation(Terms, Body, Wallet, Destination, Resource)), GetQuoteParams = #{ base_params => Params, @@ -1317,7 +1319,8 @@ get_quote_(Params) -> external_id => maps:get(external_id, Params, undefined), currency_from => CurrencyFrom, currency_to => CurrencyTo, - body => Body + body => Body, + resource => Resource }, {ok, Quote} = ff_adapter_withdrawal:get_quote(Adapter, GetQuoteParams, AdapterOpts), genlib_map:compact(#{ diff --git a/apps/ff_transfer/test/ff_withdrawal_SUITE.erl b/apps/ff_transfer/test/ff_withdrawal_SUITE.erl index c4a544d..37788bb 100644 --- a/apps/ff_transfer/test/ff_withdrawal_SUITE.erl +++ b/apps/ff_transfer/test/ff_withdrawal_SUITE.erl @@ -38,8 +38,9 @@ -export([create_wallet_notfound_test/1]). -export([create_ok_test/1]). -export([create_with_generic_ok_test/1]). --export([quota_ok_test/1]). --export([crypto_quota_ok_test/1]). +-export([quote_ok_test/1]). +-export([crypto_quote_ok_test/1]). +-export([quote_with_destination_ok_test/1]). -export([preserve_revisions_test/1]). -export([use_quote_revisions_test/1]). -export([unknown_test/1]). @@ -108,8 +109,9 @@ groups() -> create_wallet_notfound_test, create_ok_test, create_with_generic_ok_test, - quota_ok_test, - crypto_quota_ok_test, + quote_ok_test, + crypto_quote_ok_test, + quote_with_destination_ok_test, preserve_revisions_test, unknown_test, provider_callback_test, @@ -527,8 +529,8 @@ create_with_generic_ok_test(C) -> ?assertEqual(Cash, ff_withdrawal:body(Withdrawal)), ?assertEqual(WithdrawalID, ff_withdrawal:external_id(Withdrawal)). --spec quota_ok_test(config()) -> test_return(). -quota_ok_test(C) -> +-spec quote_ok_test(config()) -> test_return(). +quote_ok_test(C) -> Cash = {100, <<"RUB">>}, #{ wallet_id := WalletID, @@ -553,8 +555,8 @@ quota_ok_test(C) -> ok = ff_withdrawal_machine:create(WithdrawalParams, ff_entity_context:new()), ?assertEqual(succeeded, await_final_withdrawal_status(WithdrawalID)). --spec crypto_quota_ok_test(config()) -> test_return(). -crypto_quota_ok_test(C) -> +-spec crypto_quote_ok_test(config()) -> test_return(). +crypto_quote_ok_test(C) -> Currency = <<"RUB">>, Cash = {100, Currency}, Party = create_party(C), @@ -571,6 +573,22 @@ crypto_quota_ok_test(C) -> }, {ok, _Quote} = ff_withdrawal:get_quote(Params). +-spec quote_with_destination_ok_test(config()) -> test_return(). +quote_with_destination_ok_test(C) -> + Cash = {100, <<"RUB">>}, + #{ + wallet_id := WalletID, + destination_id := DestinationID + } = prepare_standard_environment(Cash, C), + Params = #{ + wallet_id => WalletID, + currency_from => <<"RUB">>, + currency_to => <<"USD">>, + body => Cash, + destination_id => DestinationID + }, + {ok, #{quote_data := #{<<"destination">> := <<"bank_card">>}}} = ff_withdrawal:get_quote(Params). + -spec preserve_revisions_test(config()) -> test_return(). preserve_revisions_test(C) -> Cash = {100, <<"RUB">>}, diff --git a/apps/fistful/test/ff_ct_provider.erl b/apps/fistful/test/ff_ct_provider.erl index 0c3f2e1..6108aac 100644 --- a/apps/fistful/test/ff_ct_provider.erl +++ b/apps/fistful/test/ff_ct_provider.erl @@ -104,6 +104,26 @@ process_withdrawal(_Withdrawal, State, _Options) -> -dialyzer({nowarn_function, get_quote/2}). -spec get_quote(quote_params(), map()) -> {ok, quote()}. +get_quote( + #{ + currency_from := CurrencyFrom, + currency_to := CurrencyTo, + exchange_cash := #wthd_provider_Cash{amount = Amount, currency = Currency}, + destination := {DestinationName, _} + }, + _Options +) -> + {ok, #{ + cash_from => calc_cash(CurrencyFrom, Currency, Amount), + cash_to => calc_cash(CurrencyTo, Currency, Amount), + created_at => ff_time:to_rfc3339(ff_time:now()), + expires_on => ff_time:to_rfc3339(ff_time:now() + 15 * 3600 * 1000), + quote_data => + {obj, #{ + {str, <<"test">>} => {str, <<"test">>}, + {str, <<"destination">>} => {str, erlang:atom_to_binary(DestinationName)} + }} + }}; get_quote( #{ currency_from := CurrencyFrom, diff --git a/apps/fistful/test/ff_ct_provider_handler.erl b/apps/fistful/test/ff_ct_provider_handler.erl index d35228b..16e631c 100644 --- a/apps/fistful/test/ff_ct_provider_handler.erl +++ b/apps/fistful/test/ff_ct_provider_handler.erl @@ -76,14 +76,16 @@ decode_quote_params(#wthd_provider_GetQuoteParams{ idempotency_id = IdempotencyID, currency_from = CurrencyFrom, currency_to = CurrencyTo, - exchange_cash = Cash + exchange_cash = Cash, + destination = Destination }) -> - #{ + genlib_map:compact(#{ idempotency_id => IdempotencyID, currency_from => CurrencyFrom, currency_to => CurrencyTo, - exchange_cash => Cash - }. + exchange_cash => Cash, + destination => Destination + }). decode_options(Options) -> Options. diff --git a/rebar.lock b/rebar.lock index 55b073b..6a954ff 100644 --- a/rebar.lock +++ b/rebar.lock @@ -25,7 +25,7 @@ {<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2}, {<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"f718741970470474efcd32800daf885cb8d75584"}}, + {ref,"3df747ff446bdaac8f136faeb75aa3da65281171"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/valitydev/dmt_client.git",