ED-72: Pass payment_tool_provider.PaymentDetails through metadata (#106)

* Make mock data a bit more realistic
* Bump to rbkmoney/swag@6d9dd1c
This commit is contained in:
Andrew Mayorov 2021-03-05 18:12:38 +03:00 committed by GitHub
parent 6019b730ee
commit fe5d9e18cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 27 deletions

View File

@ -18,6 +18,8 @@
-include_lib("binbase_proto/include/binbase_binbase_thrift.hrl").
-include_lib("cds_proto/include/cds_proto_storage_thrift.hrl").
-define(META_NS, <<"com.rbkmoney.binbase">>).
-export([lookup_bank_info/2]).
-export([validate/5]).
-export([payment_system/1]).
@ -28,7 +30,7 @@
bank_name := binary(),
issuer_country := dmsl_domain_thrift:'Residence'() | undefined,
category := binary() | undefined,
metadata := map()
metadata := {_MetaNS :: binary(), map()}
}.
-type lookup_error() ::
@ -80,9 +82,7 @@ decode_bank_info(#'binbase_ResponseData'{bin_data = BinData, version = Version})
bank_name => BinData#binbase_BinData.bank_name,
issuer_country => decode_issuer_country(BinData#binbase_BinData.iso_country_code),
category => BinData#binbase_BinData.category,
metadata => #{
<<"version">> => Version
}
metadata => {?META_NS, #{<<"version">> => Version}}
}}
catch
{invalid, What} ->

View File

@ -12,7 +12,6 @@
-import(capi_handler_utils, [logic_error/2, validation_error/1]).
-define(CAPI_NS, <<"com.rbkmoney.capi">>).
-define(DEFAULT_PAYMENT_TOOL_TOKEN_LIFETIME, <<"64m">>).
-spec process_request(
@ -219,11 +218,11 @@ expand_card_info(
bank_name := BankName,
issuer_country := IssuerCountry,
category := Category,
metadata := Metadata
metadata := {NS, Metadata}
},
HaveCVV
) ->
#domain_BankCard{
BankCard1 = #domain_BankCard{
token = BankCard#cds_BankCard.token,
bin = BankCard#cds_BankCard.bin,
last_digits = BankCard#cds_BankCard.last_digits,
@ -231,9 +230,9 @@ expand_card_info(
issuer_country = IssuerCountry,
category = Category,
bank_name = BankName,
metadata = #{?CAPI_NS => capi_msgp_marshalling:marshal(Metadata)},
is_cvv_empty = HaveCVV
}.
},
add_metadata(NS, Metadata, BankCard1).
%% Seems to fit within PCIDSS requirments for all PAN lengths
get_first6(CardNumber) ->
@ -368,18 +367,18 @@ process_tokenized_card_data_result(
}
) ->
TokenProvider = get_payment_token_provider(PaymentDetails, PaymentData),
{
{bank_card, BankCard#domain_BankCard{
bin = get_tokenized_bin(PaymentData),
payment_system = PaymentSystem,
last_digits = get_tokenized_pan(Last4, PaymentData),
token_provider = TokenProvider,
is_cvv_empty = set_is_empty_cvv(TokenProvider, BankCard),
exp_date = encode_exp_date(genlib_map:get(exp_date, ExtraCardData)),
cardholder_name = genlib_map:get(cardholder, ExtraCardData)
}},
SessionID
}.
{NS, ProviderMetadata} = extract_payment_tool_provider_metadata(PaymentDetails),
BankCard1 = BankCard#domain_BankCard{
bin = get_tokenized_bin(PaymentData),
payment_system = PaymentSystem,
last_digits = get_tokenized_pan(Last4, PaymentData),
token_provider = TokenProvider,
is_cvv_empty = set_is_empty_cvv(TokenProvider, BankCard),
exp_date = encode_exp_date(genlib_map:get(exp_date, ExtraCardData)),
cardholder_name = genlib_map:get(cardholder, ExtraCardData)
},
BankCard2 = add_metadata(NS, ProviderMetadata, BankCard1),
{{bank_card, BankCard2}, SessionID}.
get_tokenized_bin({card, #paytoolprv_Card{pan = PAN}}) ->
get_first6(PAN);
@ -422,6 +421,44 @@ get_payment_token_provider({google, _}, _PaymentData) ->
get_payment_token_provider({samsung, _}, _PaymentData) ->
samsungpay.
%% TODO
%% All this stuff deserves its own module I believe. These super-long names are quite strong hints.
-define(PAYMENT_TOOL_PROVIDER_META_NS, <<"com.rbkmoney.payment-tool-provider">>).
extract_payment_tool_provider_metadata({_Provider, Details}) ->
{?PAYMENT_TOOL_PROVIDER_META_NS, #{
<<"details">> => extract_payment_details_metadata(Details)
}}.
extract_payment_details_metadata(#paytoolprv_ApplePayDetails{
transaction_id = TransactionID,
device_id = DeviceID
}) ->
#{
<<"transaction_id">> => TransactionID,
<<"device_id">> => DeviceID
};
extract_payment_details_metadata(#paytoolprv_SamsungPayDetails{
device_id = DeviceID
}) ->
#{
<<"device_id">> => DeviceID
};
extract_payment_details_metadata(#paytoolprv_GooglePayDetails{
message_id = MessageID
}) ->
#{
<<"message_id">> => MessageID
};
extract_payment_details_metadata(#paytoolprv_YandexPayDetails{
message_id = MessageID
}) ->
#{
<<"message_id">> => MessageID
}.
%%
encode_tokenized_card_data(#paytoolprv_UnwrappedPaymentTool{
payment_data =
{tokenized_card, #paytoolprv_TokenizedCard{
@ -545,3 +582,11 @@ get_bank_info(CardDataPan, Context) ->
{error, _Reason} ->
throw({ok, logic_error(invalidRequest, <<"Unsupported card">>)})
end.
add_metadata(NS, Metadata, BankCard = #domain_BankCard{metadata = Acc = #{}}) ->
undefined = maps:get(NS, Acc, undefined),
BankCard#domain_BankCard{
metadata = Acc#{NS => capi_msgp_marshalling:marshal(Metadata)}
};
add_metadata(NS, Metadata, BankCard = #domain_BankCard{metadata = undefined}) ->
add_metadata(NS, Metadata, BankCard#domain_BankCard{metadata = #{}}).

View File

@ -8,11 +8,13 @@
last_digits = <<"7892">>
}).
-define(BANK_NAME, <<"SAVINGS BANK OF THE GLORIOUS RUSSIAN FEDERATION">>).
-define(BINBASE_LOOKUP_RESULT, ?BINBASE_LOOKUP_RESULT(<<"MASTERCARD">>)).
-define(BINBASE_LOOKUP_RESULT(PaymentSystem), #'binbase_ResponseData'{
bin_data = #'binbase_BinData'{
payment_system = PaymentSystem,
bank_name = ?STRING,
bank_name = ?BANK_NAME,
iso_country_code = <<"KAZ">>,
card_type = debit,
bin_data_id = {i, ?INTEGER}
@ -59,6 +61,11 @@
session_id = ?STRING
}).
-define(MESSAGE_ID, <<
"27FBD553651896F61FF58EBA63091A33FACDE10C662807FF4C1835A1EE89198917D4AB"
"6A56A1F250983A8EA287E3E4CE65E4782006937142857475861835A10158FDE54B52B5"
>>).
-define(APPLE_PAY_DETAILS,
{apple, #paytoolprv_ApplePayDetails{
transaction_id = ?STRING,
@ -70,14 +77,14 @@
-define(GOOGLE_PAY_DETAILS,
{google, #paytoolprv_GooglePayDetails{
message_id = ?STRING,
message_id = ?MESSAGE_ID,
message_expiration = ?TIMESTAMP
}}
).
-define(YANDEX_PAY_DETAILS,
{yandex, #paytoolprv_YandexPayDetails{
message_id = ?STRING,
message_id = ?MESSAGE_ID,
message_expiration = ?TIMESTAMP
}}
).

View File

@ -819,7 +819,7 @@ create_googlepay_tokenized_payment_resource_ok_test(Config) ->
},
<<"clientInfo">> => ClientInfo
}),
false = maps:is_key(<<"first6">>, Details).
?assertEqual(error, maps:find(<<"first6">>, Details)).
-spec create_googlepay_plain_payment_resource_ok_test(_) -> _.
create_googlepay_plain_payment_resource_ok_test(Config) ->
@ -894,6 +894,7 @@ create_yandexpay_tokenized_payment_resource_ok_test(Config) ->
),
ClientInfo = #{<<"fingerprint">> => <<"test fingerprint">>},
{ok, #{
<<"paymentToolToken">> := EncryptedToken,
<<"paymentToolDetails">> := Details = #{
<<"paymentSystem">> := <<"mastercard">>,
<<"tokenProvider">> := <<"yandexpay">>,
@ -910,7 +911,22 @@ create_yandexpay_tokenized_payment_resource_ok_test(Config) ->
},
<<"clientInfo">> => ClientInfo
}),
false = maps:is_key(<<"first6">>, Details).
?assertEqual(error, maps:find(<<"first6">>, Details)),
{ok, {PaymentTool, _Deadline}} = capi_crypto:decrypt_payment_tool_token(EncryptedToken),
?assertMatch(
{bank_card, #domain_BankCard{
metadata = #{
<<"com.rbkmoney.payment-tool-provider">> :=
{obj, #{
{str, <<"details">>} :=
{obj, #{
{str, <<"message_id">>} := {str, ?MESSAGE_ID}
}}
}}
}
}},
PaymentTool
).
%%

@ -1 +1 @@
Subproject commit af70b3cd1dc740a4b541e58e5dd97e7224e032a8
Subproject commit 6666a375574ce1399c5b865344281247194cb5ab