mirror of
https://github.com/valitydev/capi-pcidss-v2.git
synced 2024-11-06 01:35:24 +00:00
IMP-226: Add resourceToken (#30)
This commit is contained in:
parent
2014ece85d
commit
ee449bf65a
@ -2,7 +2,7 @@
|
||||
|
||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||
|
||||
-export([decode_disposable_payment_resource/3]).
|
||||
-export([decode_disposable_payment_resource/4]).
|
||||
|
||||
-export([decode_last_digits/1]).
|
||||
-export([decode_masked_pan/2]).
|
||||
@ -78,13 +78,15 @@ mask_phone_number(PhoneNumber) ->
|
||||
-spec decode_disposable_payment_resource(
|
||||
capi_handler_encoder:encode_data(),
|
||||
encrypted_token(),
|
||||
encrypted_token(),
|
||||
capi_utils:deadline()
|
||||
) -> decode_data().
|
||||
decode_disposable_payment_resource(Resource, EncryptedToken, TokenValidUntil) ->
|
||||
decode_disposable_payment_resource(Resource, EncryptedToken, EncryptedTokenData, TokenValidUntil) ->
|
||||
#domain_DisposablePaymentResource{payment_tool = PaymentTool, payment_session_id = SessionID} = Resource,
|
||||
ClientInfo = Resource#domain_DisposablePaymentResource.client_info,
|
||||
genlib_map:compact(#{
|
||||
<<"paymentToolToken">> => EncryptedToken,
|
||||
<<"paymentToolToken">> => EncryptedTokenData,
|
||||
<<"resourceToken">> => EncryptedToken,
|
||||
<<"paymentSession">> => capi_handler_utils:wrap_payment_session(decode_client_info_ext(ClientInfo), SessionID),
|
||||
<<"paymentToolDetails">> => decode_payment_tool_details(PaymentTool),
|
||||
<<"clientInfo">> => decode_client_info(ClientInfo),
|
||||
|
@ -101,20 +101,25 @@ process_request('CreatePaymentResource', Req, Context, Resolution) ->
|
||||
ClientUrl = get_client_url(ClientInfo1),
|
||||
ClientInfo = maps:put(<<"url">>, ClientUrl, ClientInfo1),
|
||||
Data = maps:get(<<"paymentTool">>, Params),
|
||||
{PaymentTool, PaymentSessionID, PaymentToolDeadline} =
|
||||
{Token, PaymentTool, PaymentSessionID, PaymentToolDeadline} =
|
||||
case Data of
|
||||
#{<<"paymentToolType">> := <<"CardData">>} ->
|
||||
erlang:append_element(process_card_data(Data, Context), undefined);
|
||||
{T, PT, S} = process_card_data(Data, Context),
|
||||
{T, PT, S, undefined};
|
||||
#{<<"paymentToolType">> := <<"PaymentTerminalData">>} ->
|
||||
{process_payment_terminal_data(Data), <<>>, undefined};
|
||||
TD = process_payment_terminal_data(Data),
|
||||
{TD, TD, <<>>, undefined};
|
||||
#{<<"paymentToolType">> := <<"DigitalWalletData">>} ->
|
||||
{process_digital_wallet_data(Data, Context), <<>>, undefined};
|
||||
{T, DW} = process_digital_wallet_data(Data, Context),
|
||||
{T, DW, <<>>, undefined};
|
||||
#{<<"paymentToolType">> := <<"TokenizedCardData">>} ->
|
||||
process_tokenized_card_data(Data, Context);
|
||||
#{<<"paymentToolType">> := <<"CryptoWalletData">>} ->
|
||||
{process_crypto_wallet_data(Data), <<>>, undefined};
|
||||
WD = process_crypto_wallet_data(Data),
|
||||
{WD, WD, <<>>, undefined};
|
||||
#{<<"paymentToolType">> := <<"MobileCommerceData">>} ->
|
||||
{process_mobile_commerce_data(Data, Context), <<>>, undefined}
|
||||
MCD = process_mobile_commerce_data(Data, Context),
|
||||
{MCD, MCD, <<>>, undefined}
|
||||
end,
|
||||
TokenData = #{
|
||||
payment_tool => PaymentTool,
|
||||
@ -129,6 +134,7 @@ process_request('CreatePaymentResource', Req, Context, Resolution) ->
|
||||
{201, #{},
|
||||
capi_handler_decoder:decode_disposable_payment_resource(
|
||||
PaymentResource,
|
||||
base64:encode(erlang:term_to_binary(Token)),
|
||||
capi_crypto:encode_token(TokenData),
|
||||
maps:get(valid_until, TokenData)
|
||||
)}}
|
||||
@ -207,7 +213,7 @@ process_card_data(Data, Context) ->
|
||||
ok ->
|
||||
{Token, SessionID} = put_card_data_to_cds(CardData, SessionData, Context),
|
||||
BankCard = construct_bank_card(Token, CardData, SessionData),
|
||||
{{bank_card, enrich_bank_card(BankCard, BankInfo)}, SessionID};
|
||||
{Token, {bank_card, enrich_bank_card(BankCard, BankInfo)}, SessionID};
|
||||
{error, Error} ->
|
||||
throw({ok, validation_error(Error)})
|
||||
end.
|
||||
@ -384,13 +390,14 @@ process_digital_wallet_data(Data, Context) ->
|
||||
Ref = encode_payment_service_ref(maps:get(<<"provider">>, Data)),
|
||||
case validate_payment_service_ref(Ref) of
|
||||
{ok, _} ->
|
||||
Token = maps:get(<<"token">>, Data, undefined),
|
||||
Token0 = maps:get(<<"token">>, Data, undefined),
|
||||
Token1 = capi_utils:maybe(Token0, fun(T) -> store_token_in_tds(T, Context) end),
|
||||
DigitalWallet = #domain_DigitalWallet{
|
||||
id = maps:get(<<"id">>, Data),
|
||||
payment_service = encode_payment_service_ref(maps:get(<<"provider">>, Data)),
|
||||
token = capi_utils:maybe(Token, fun(T) -> store_token_in_tds(T, Context) end)
|
||||
token = Token1
|
||||
},
|
||||
{digital_wallet, DigitalWallet};
|
||||
{Token1, {digital_wallet, DigitalWallet}};
|
||||
{error, object_not_found} ->
|
||||
throw({ok, logic_error(invalidRequest, <<"Digital wallet provider is invalid">>)})
|
||||
end.
|
||||
@ -410,7 +417,7 @@ process_tokenized_card_data(Data, Context) ->
|
||||
ok ->
|
||||
{Token, SessionID} = put_card_data_to_cds(CardData, SessionData, Context),
|
||||
{BankCard, Deadline} = construct_tokenized_bank_card(Token, CardData, SessionData, UnwrappedPaymentTool),
|
||||
{{bank_card, enrich_bank_card(BankCard, BankInfo)}, SessionID, Deadline};
|
||||
{Token, {bank_card, enrich_bank_card(BankCard, BankInfo)}, SessionID, Deadline};
|
||||
{error, Error} ->
|
||||
throw({ok, validation_error(Error)})
|
||||
end.
|
||||
|
@ -227,7 +227,8 @@ create_visa_payment_resource_ok_test(Config) ->
|
||||
<<"last4">> := <<"1111">>,
|
||||
<<"first6">> := <<"411111">>,
|
||||
<<"cardNumberMask">> := <<"411111******1111">>
|
||||
}
|
||||
},
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
<<"paymentToolType">> => <<"CardData">>,
|
||||
@ -378,7 +379,9 @@ create_payment_resource_invalid_cardholder_test(Config) ->
|
||||
Config
|
||||
),
|
||||
PaymentTool = ?SWAG_BANK_CARD(<<"4111111111111111">>),
|
||||
{ok, _} = capi_client_tokens:create_payment_resource(
|
||||
{ok, #{
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} = capi_client_tokens:create_payment_resource(
|
||||
?config(context, Config),
|
||||
#{
|
||||
<<"paymentTool">> => PaymentTool#{<<"cardHolder">> => <<"Вася Иванов"/utf8>>},
|
||||
@ -428,7 +431,8 @@ create_visa_with_empty_cvc_ok_test(Config) ->
|
||||
<<"last4">> := <<"1111">>,
|
||||
<<"first6">> := <<"411111">>,
|
||||
<<"cardNumberMask">> := <<"411111******1111">>
|
||||
}
|
||||
},
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
<<"paymentToolType">> => <<"CardData">>,
|
||||
@ -517,7 +521,8 @@ create_nspkmir_payment_resource_ok_test(Config) ->
|
||||
<<"cardNumberMask">> := <<"220220******8454">>,
|
||||
<<"last4">> := <<"8454">>,
|
||||
<<"first6">> := <<"220220">>
|
||||
}
|
||||
},
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
<<"paymentToolType">> => <<"CardData">>,
|
||||
@ -536,7 +541,8 @@ create_euroset_payment_resource_ok_test(Config) ->
|
||||
<<"paymentToolDetails">> := #{
|
||||
<<"detailsType">> := <<"PaymentToolDetailsPaymentTerminal">>,
|
||||
<<"provider">> := <<"euroset">>
|
||||
}
|
||||
},
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
<<"paymentToolType">> => <<"PaymentTerminalData">>,
|
||||
@ -556,7 +562,8 @@ create_euroset_no_metadata_payment_resource_ok_test(Config) ->
|
||||
<<"paymentToolDetails">> := #{
|
||||
<<"detailsType">> := <<"PaymentToolDetailsPaymentTerminal">>,
|
||||
<<"provider">> := <<"euroset">>
|
||||
}
|
||||
},
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
<<"paymentToolType">> => <<"PaymentTerminalData">>,
|
||||
@ -610,7 +617,8 @@ create_qw_payment_resource_ok_test(Config) ->
|
||||
<<"paymentToolDetails">> := #{
|
||||
<<"detailsType">> := <<"PaymentToolDetailsDigitalWallet">>,
|
||||
<<"provider">> := <<"qiwi">>
|
||||
}
|
||||
},
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
<<"paymentToolType">> => <<"DigitalWalletData">>,
|
||||
@ -648,9 +656,16 @@ create_qw_payment_resource_with_access_token_generates_different_payment_token(C
|
||||
},
|
||||
Result0 = capi_client_tokens:create_payment_resource(?config(context, Config), PaymentParams0),
|
||||
Result1 = capi_client_tokens:create_payment_resource(?config(context, Config), PaymentParams1),
|
||||
{ok, #{<<"paymentToolToken">> := Token0}} = Result0,
|
||||
{ok, #{<<"paymentToolToken">> := Token1}} = Result1,
|
||||
?assertNotEqual(Token0, Token1).
|
||||
{ok, #{
|
||||
<<"paymentToolToken">> := Token0,
|
||||
<<"resourceToken">> := ResourceToken0
|
||||
}} = Result0,
|
||||
{ok, #{
|
||||
<<"paymentToolToken">> := Token1,
|
||||
<<"resourceToken">> := ResourceToken1
|
||||
}} = Result1,
|
||||
?assertNotEqual(Token0, Token1),
|
||||
?assertNotEqual(ResourceToken0, ResourceToken1).
|
||||
|
||||
-spec create_nonexistent_provider_payment_resource_fails_test(_) -> _.
|
||||
create_nonexistent_provider_payment_resource_fails_test(Config) ->
|
||||
@ -705,7 +720,8 @@ create_applepay_tokenized_payment_resource_ok_test(Config) ->
|
||||
<<"tokenProvider">> := <<"APPLE PAY">>,
|
||||
<<"cardNumberMask">> := <<"************7892">>,
|
||||
<<"last4">> := <<"7892">>
|
||||
}
|
||||
},
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} =
|
||||
capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
@ -749,7 +765,8 @@ create_googlepay_tokenized_payment_resource_ok_test(Config) ->
|
||||
<<"tokenProvider">> := <<"GOOGLE PAY">>,
|
||||
<<"cardNumberMask">> := <<"************7892">>,
|
||||
<<"last4">> := <<"7892">>
|
||||
}
|
||||
},
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} =
|
||||
capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
@ -800,7 +817,8 @@ create_googlepay_plain_payment_resource_ok_test(Config) ->
|
||||
<<"cardNumberMask">> := <<"532130******7892">>,
|
||||
<<"first6">> := <<"532130">>,
|
||||
<<"last4">> := <<"7892">>
|
||||
}
|
||||
},
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} =
|
||||
capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
@ -847,7 +865,8 @@ create_yandexpay_tokenized_payment_resource_ok_test(Config) ->
|
||||
<<"tokenProvider">> := <<"YANDEX PAY">>,
|
||||
<<"cardNumberMask">> := <<"************7892">>,
|
||||
<<"last4">> := <<"7892">>
|
||||
}
|
||||
},
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} =
|
||||
capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
@ -1004,7 +1023,8 @@ authorization_error_wrong_token_type_test(_Config) ->
|
||||
payment_token_valid_until_test(Config) ->
|
||||
{ok, #{
|
||||
<<"paymentToolToken">> := PaymentToolToken,
|
||||
<<"validUntil">> := ValidUntil
|
||||
<<"validUntil">> := ValidUntil,
|
||||
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
|
||||
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
|
||||
<<"paymentTool">> => #{
|
||||
<<"paymentToolType">> => <<"CryptoWalletData">>,
|
||||
|
@ -124,11 +124,11 @@
|
||||
{<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.6">>},1},
|
||||
{<<"swag_client">>,
|
||||
{git,"https://github.com/valitydev/swag-payments.git",
|
||||
{ref,"a05918d1038958186e62f54cd62fe1d812f242e0"}},
|
||||
{ref,"e57e247b1bc505c9d38005f2f7a58d8292604cc2"}},
|
||||
0},
|
||||
{<<"swag_server">>,
|
||||
{git,"https://github.com/valitydev/swag-payments.git",
|
||||
{ref,"5e355455f1a2cb0735d1ceead4e981712ebe4a92"}},
|
||||
{ref,"1af122ed1842ec986bcd2edd2a93530c6b3959a0"}},
|
||||
0},
|
||||
{<<"tds_proto">>,
|
||||
{git,"https://github.com/valitydev/tds-proto.git",
|
||||
|
Loading…
Reference in New Issue
Block a user