Skip to content

Commit

Permalink
IMP-226: Fix resourceToken implementation (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndiezel0 authored May 16, 2024
1 parent ee449bf commit 33f1fdc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
8 changes: 4 additions & 4 deletions apps/capi/src/capi_handler_tokens.erl
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ process_request('CreatePaymentResource', Req, Context, Resolution) ->
{T, PT, S, undefined};
#{<<"paymentToolType">> := <<"PaymentTerminalData">>} ->
TD = process_payment_terminal_data(Data),
{TD, TD, <<>>, undefined};
{undefined, TD, <<>>, undefined};
#{<<"paymentToolType">> := <<"DigitalWalletData">>} ->
{T, DW} = process_digital_wallet_data(Data, Context),
{T, DW, <<>>, undefined};
#{<<"paymentToolType">> := <<"TokenizedCardData">>} ->
process_tokenized_card_data(Data, Context);
#{<<"paymentToolType">> := <<"CryptoWalletData">>} ->
WD = process_crypto_wallet_data(Data),
{WD, WD, <<>>, undefined};
{undefined, WD, <<>>, undefined};
#{<<"paymentToolType">> := <<"MobileCommerceData">>} ->
MCD = process_mobile_commerce_data(Data, Context),
{MCD, MCD, <<>>, undefined}
{undefined, MCD, <<>>, undefined}
end,
TokenData = #{
payment_tool => PaymentTool,
Expand All @@ -134,7 +134,7 @@ process_request('CreatePaymentResource', Req, Context, Resolution) ->
{201, #{},
capi_handler_decoder:decode_disposable_payment_resource(
PaymentResource,
base64:encode(erlang:term_to_binary(Token)),
Token,
capi_crypto:encode_token(TokenData),
maps:get(valid_until, TokenData)
)}}
Expand Down
36 changes: 15 additions & 21 deletions apps/capi/test/capi_payment_resources_tests_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ create_visa_payment_resource_ok_test(Config) ->
<<"first6">> := <<"411111">>,
<<"cardNumberMask">> := <<"411111******1111">>
},
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
<<"resourceToken">> := ?STRING
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
<<"paymentTool">> => #{
<<"paymentToolType">> => <<"CardData">>,
Expand Down Expand Up @@ -380,7 +380,7 @@ create_payment_resource_invalid_cardholder_test(Config) ->
),
PaymentTool = ?SWAG_BANK_CARD(<<"4111111111111111">>),
{ok, #{
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
<<"resourceToken">> := ?STRING
}} = capi_client_tokens:create_payment_resource(
?config(context, Config),
#{
Expand Down Expand Up @@ -432,7 +432,7 @@ create_visa_with_empty_cvc_ok_test(Config) ->
<<"first6">> := <<"411111">>,
<<"cardNumberMask">> := <<"411111******1111">>
},
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
<<"resourceToken">> := ?STRING
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
<<"paymentTool">> => #{
<<"paymentToolType">> => <<"CardData">>,
Expand Down Expand Up @@ -522,7 +522,7 @@ create_nspkmir_payment_resource_ok_test(Config) ->
<<"last4">> := <<"8454">>,
<<"first6">> := <<"220220">>
},
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
<<"resourceToken">> := ?STRING
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
<<"paymentTool">> => #{
<<"paymentToolType">> => <<"CardData">>,
Expand All @@ -541,8 +541,7 @@ 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">>,
Expand All @@ -562,8 +561,7 @@ 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">>,
Expand Down Expand Up @@ -617,8 +615,7 @@ 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">>,
Expand Down Expand Up @@ -657,15 +654,13 @@ 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,
<<"resourceToken">> := ResourceToken0
<<"paymentToolToken">> := Token0
}} = Result0,
{ok, #{
<<"paymentToolToken">> := Token1,
<<"resourceToken">> := ResourceToken1
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
}} = Result1,
?assertNotEqual(Token0, Token1),
?assertNotEqual(ResourceToken0, ResourceToken1).
?assertNotEqual(Token0, Token1).

-spec create_nonexistent_provider_payment_resource_fails_test(_) -> _.
create_nonexistent_provider_payment_resource_fails_test(Config) ->
Expand Down Expand Up @@ -721,7 +716,7 @@ create_applepay_tokenized_payment_resource_ok_test(Config) ->
<<"cardNumberMask">> := <<"************7892">>,
<<"last4">> := <<"7892">>
},
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
<<"resourceToken">> := ?STRING
}} =
capi_client_tokens:create_payment_resource(?config(context, Config), #{
<<"paymentTool">> => #{
Expand Down Expand Up @@ -766,7 +761,7 @@ create_googlepay_tokenized_payment_resource_ok_test(Config) ->
<<"cardNumberMask">> := <<"************7892">>,
<<"last4">> := <<"7892">>
},
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
<<"resourceToken">> := ?STRING
}} =
capi_client_tokens:create_payment_resource(?config(context, Config), #{
<<"paymentTool">> => #{
Expand Down Expand Up @@ -818,7 +813,7 @@ create_googlepay_plain_payment_resource_ok_test(Config) ->
<<"first6">> := <<"532130">>,
<<"last4">> := <<"7892">>
},
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
<<"resourceToken">> := ?STRING
}} =
capi_client_tokens:create_payment_resource(?config(context, Config), #{
<<"paymentTool">> => #{
Expand Down Expand Up @@ -866,7 +861,7 @@ create_yandexpay_tokenized_payment_resource_ok_test(Config) ->
<<"cardNumberMask">> := <<"************7892">>,
<<"last4">> := <<"7892">>
},
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
<<"resourceToken">> := ?STRING
}} =
capi_client_tokens:create_payment_resource(?config(context, Config), #{
<<"paymentTool">> => #{
Expand Down Expand Up @@ -1023,8 +1018,7 @@ authorization_error_wrong_token_type_test(_Config) ->
payment_token_valid_until_test(Config) ->
{ok, #{
<<"paymentToolToken">> := PaymentToolToken,
<<"validUntil">> := ValidUntil,
<<"resourceToken">> := <<_H:1/binary, _T/binary>>
<<"validUntil">> := ValidUntil
}} = capi_client_tokens:create_payment_resource(?config(context, Config), #{
<<"paymentTool">> => #{
<<"paymentToolType">> => <<"CryptoWalletData">>,
Expand Down

0 comments on commit 33f1fdc

Please sign in to comment.