@@ -19,14 +19,18 @@ use crate::{
19
19
} ;
20
20
21
21
pub struct ProxyRequestWrapper ( pub proxy_api_models:: ProxyRequest ) ;
22
+ pub enum ProxyRecord {
23
+ PaymentMethodRecord ( domain:: PaymentMethod ) ,
24
+ TokenizationRecord ( domain:: Tokenization ) ,
25
+ }
22
26
23
27
impl ProxyRequestWrapper {
24
- pub async fn get_vault_id (
28
+ pub async fn get_payment_method_or_tokenization_record (
25
29
& self ,
26
30
state : & SessionState ,
27
31
key_store : & domain:: MerchantKeyStore ,
28
32
storage_scheme : common_enums:: enums:: MerchantStorageScheme ,
29
- ) -> RouterResult < payment_methods :: VaultId > {
33
+ ) -> RouterResult < ProxyRecord > {
30
34
let token = & self . 0 . token ;
31
35
32
36
match self . 0 . token_type {
@@ -39,15 +43,13 @@ impl ProxyRequestWrapper {
39
43
. change_context ( errors:: ApiErrorResponse :: InternalServerError )
40
44
. attach_printable ( "Unable to generate GlobalPaymentMethodId" ) ?;
41
45
42
- state
46
+ let payment_method_record = state
43
47
. store
44
48
. find_payment_method ( & ( ( state) . into ( ) ) , key_store, & pm_id, storage_scheme)
45
49
. await
46
- . change_context ( errors:: ApiErrorResponse :: PaymentMethodNotFound ) ?
47
- . locker_id
48
- . get_required_value ( "vault_id" )
49
- . change_context ( errors:: ApiErrorResponse :: InternalServerError )
50
- . attach_printable ( "Locker id not present in Payment Method Entry" )
50
+ . change_context ( errors:: ApiErrorResponse :: PaymentMethodNotFound ) ?;
51
+ Ok ( ProxyRecord :: PaymentMethodRecord ( payment_method_record) )
52
+
51
53
}
52
54
proxy_api_models:: TokenType :: TokenizationId => {
53
55
Err ( report ! ( errors:: ApiErrorResponse :: NotImplemented {
@@ -112,6 +114,47 @@ impl ProxyRequestWrapper {
112
114
}
113
115
}
114
116
117
+ impl ProxyRecord {
118
+ pub fn get_vault_id (
119
+ & self ,
120
+ ) -> RouterResult < payment_methods:: VaultId > {
121
+
122
+ match self {
123
+ Self :: PaymentMethodRecord ( payment_method) => {
124
+ payment_method. locker_id . clone ( )
125
+ . get_required_value ( "vault_id" )
126
+ . change_context ( errors:: ApiErrorResponse :: InternalServerError )
127
+ . attach_printable ( "Locker id not present in Payment Method Entry" )
128
+
129
+ }
130
+ Self :: TokenizationRecord ( _) => {
131
+ Err ( report ! ( errors:: ApiErrorResponse :: NotImplemented {
132
+ message: NotImplementedMessage :: Reason (
133
+ "Proxy flow using tokenization id" . to_string( ) ,
134
+ ) ,
135
+ } ) )
136
+ }
137
+ }
138
+ }
139
+
140
+ pub fn get_customer_id (
141
+ & self ,
142
+ ) -> RouterResult < id_type:: GlobalCustomerId > {
143
+ match self {
144
+ Self :: PaymentMethodRecord ( payment_method) => {
145
+ Ok ( payment_method. customer_id . clone ( ) )
146
+ }
147
+ Self :: TokenizationRecord ( _) => {
148
+ Err ( report ! ( errors:: ApiErrorResponse :: NotImplemented {
149
+ message: NotImplementedMessage :: Reason (
150
+ "Proxy flow using tokenization id" . to_string( ) ,
151
+ ) ,
152
+ } ) )
153
+ }
154
+ }
155
+ }
156
+ }
157
+
115
158
#[ derive( Debug ) ]
116
159
pub struct TokenReference {
117
160
pub field : String ,
0 commit comments