@@ -254,7 +254,6 @@ pub type BuildGetTxnFeesReqCB = extern fn(command_handle: i32,
254254///
255255/// # Params
256256/// command_handle: command handle to map callback to context
257- /// payment_method: payment method to use
258257/// resp_json: response for Indy request for getting fees
259258///
260259/// # Return
@@ -270,6 +269,47 @@ pub type ParseGetTxnFeesResponseCB = extern fn(command_handle: i32,
270269 err : ErrorCode ,
271270 fees_json : * const c_char ) -> ErrorCode > ) -> ErrorCode ;
272271
272+ /// Builds Indy request for information to verify the receipt
273+ ///
274+ /// # Params
275+ /// command_handle
276+ /// wallet_handle
277+ /// submitter_did
278+ /// receipt -- receipt to verify
279+ ///
280+ /// # Return
281+ /// verify_txn_json -- request to be sent to ledger
282+
283+ pub type BuildVerifyReqCB = extern fn ( command_handle : i32 ,
284+ wallet_handle : i32 ,
285+ submitter_did : * const c_char ,
286+ receipt : * const c_char ,
287+ cb : Option < extern fn ( command_handle_ : i32 ,
288+ err : ErrorCode ,
289+ verify_txn_json : * const c_char ) -> ErrorCode > ) -> ErrorCode ;
290+
291+ /// Parses Indy response with information to verify receipt
292+ ///
293+ /// # Params
294+ /// command_handle
295+ /// resp_json -- response of the ledger for verify txn
296+ ///
297+ /// # Return
298+ /// txn_json: {
299+ /// sources: [<str>, ]
300+ /// receipts: [ {
301+ /// recipient: <str>, // payment address of recipient
302+ /// receipt: <str>, // receipt that can be used for payment referencing and verification
303+ /// amount: <int>, // amount
304+ /// }, ]
305+ /// extra: <str>, //optional data
306+ /// }
307+ pub type ParseVerifyResponseCB = extern fn ( command_handle : i32 ,
308+ resp_json : * const c_char ,
309+ cb : Option < extern fn ( command_handle_ : i32 ,
310+ err : ErrorCode ,
311+ txn_json : * const c_char ) -> ErrorCode > ) -> ErrorCode ;
312+
273313/// Register custom payment implementation.
274314///
275315/// It allows library user to provide custom payment method implementation as set of handlers.
@@ -300,6 +340,8 @@ pub extern fn indy_register_payment_method(command_handle: i32,
300340 build_set_txn_fees_req : Option < BuildSetTxnFeesReqCB > ,
301341 build_get_txn_fees_req : Option < BuildGetTxnFeesReqCB > ,
302342 parse_get_txn_fees_response : Option < ParseGetTxnFeesResponseCB > ,
343+ build_verify_req : Option < BuildVerifyReqCB > ,
344+ parse_verify_response : Option < ParseVerifyResponseCB > ,
303345 cb : Option < extern fn ( command_handle_ : i32 ,
304346 err : ErrorCode ) > ) -> ErrorCode {
305347 trace ! ( "indy_register_payment_method: >>> payment_method: {:?}" , payment_method) ;
@@ -316,7 +358,9 @@ pub extern fn indy_register_payment_method(command_handle: i32,
316358 check_useful_c_callback ! ( build_set_txn_fees_req, ErrorCode :: CommonInvalidParam11 ) ;
317359 check_useful_c_callback ! ( build_get_txn_fees_req, ErrorCode :: CommonInvalidParam12 ) ;
318360 check_useful_c_callback ! ( parse_get_txn_fees_response, ErrorCode :: CommonInvalidParam13 ) ;
319- check_useful_c_callback ! ( cb, ErrorCode :: CommonInvalidParam14 ) ;
361+ check_useful_c_callback ! ( build_verify_req, ErrorCode :: CommonInvalidParam14 ) ;
362+ check_useful_c_callback ! ( parse_verify_response, ErrorCode :: CommonInvalidParam15 ) ;
363+ check_useful_c_callback ! ( cb, ErrorCode :: CommonInvalidParam16 ) ;
320364
321365 trace ! ( "indy_register_payment_method: entities >>> payment_method: {:?}" , payment_method) ;
322366
@@ -331,7 +375,9 @@ pub extern fn indy_register_payment_method(command_handle: i32,
331375 build_mint_req,
332376 build_set_txn_fees_req,
333377 build_get_txn_fees_req,
334- parse_get_txn_fees_response
378+ parse_get_txn_fees_response,
379+ build_verify_req,
380+ parse_verify_response,
335381 ) ;
336382 let result =
337383 CommandExecutor :: instance ( ) . send (
@@ -998,4 +1044,104 @@ pub extern fn indy_parse_get_txn_fees_response(command_handle: i32,
9981044 trace ! ( "indy_parse_get_txn_fees_response: <<< res: {:?}" , res) ;
9991045
10001046 res
1047+ }
1048+
1049+ /// Builds Indy request for information to verify the receipt
1050+ ///
1051+ /// # Params
1052+ /// command_handle
1053+ /// wallet_handle
1054+ /// submitter_did
1055+ /// receipt -- receipt to verify
1056+ ///
1057+ /// # Return
1058+ /// verify_txn_json -- request to be sent to ledger
1059+ /// payment_method
1060+ #[ no_mangle]
1061+ pub extern fn indy_build_verify_req ( command_handle : i32 ,
1062+ wallet_handle : i32 ,
1063+ submitter_did : * const c_char ,
1064+ receipt : * const c_char ,
1065+ cb : Option < extern fn ( command_handle_ : i32 ,
1066+ err : ErrorCode ,
1067+ verify_txn_json : * const c_char ,
1068+ payment_method : * const c_char ) > ) -> ErrorCode {
1069+ trace ! ( "indy_build_verify_req: >>> wallet_handle {:?}, submitter_did: {:?}, receipt: {:?}" , wallet_handle, submitter_did, receipt) ;
1070+ check_useful_c_str ! ( submitter_did, ErrorCode :: CommonInvalidParam3 ) ;
1071+ check_useful_c_str ! ( receipt, ErrorCode :: CommonInvalidParam4 ) ;
1072+ check_useful_c_callback ! ( cb, ErrorCode :: CommonInvalidParam5 ) ;
1073+
1074+ trace ! ( "indy_build_verify_req: entities >>> wallet_handle {:?}, submitter_did: {:?}, receipt: {:?}" , wallet_handle, submitter_did, receipt) ;
1075+
1076+ let result = CommandExecutor :: instance ( )
1077+ . send ( Command :: Payments (
1078+ PaymentsCommand :: BuildVerifyReq (
1079+ wallet_handle,
1080+ submitter_did,
1081+ receipt,
1082+ Box :: new ( move |result| {
1083+ let ( err, verify_txn_json, payment_method) = result_to_err_code_2 ! ( result, String :: new( ) , String :: new( ) ) ;
1084+ trace ! ( "indy_build_verify_req: verify_txn_json: {:?}, payment_method: {:?}" , verify_txn_json, payment_method) ;
1085+ let verify_txn_json = CStringUtils :: string_to_cstring ( verify_txn_json) ;
1086+ let payment_method = CStringUtils :: string_to_cstring ( payment_method) ;
1087+ cb ( command_handle, err, verify_txn_json. as_ptr ( ) , payment_method. as_ptr ( ) ) ;
1088+ } )
1089+ ) ) ) ;
1090+
1091+ let result = result_to_err_code ! ( result) ;
1092+
1093+ trace ! ( "indy_build_verify_req: <<< result: {:?}" , result) ;
1094+
1095+ result
1096+ }
1097+
1098+ /// Parses Indy response with information to verify receipt
1099+ ///
1100+ /// # Params
1101+ /// command_handle
1102+ /// payment_method
1103+ /// resp_json -- response of the ledger for verify txn
1104+ ///
1105+ /// # Return
1106+ /// txn_json: {
1107+ /// sources: [<str>, ]
1108+ /// receipts: [ {
1109+ /// recipient: <str>, // payment address of recipient
1110+ /// receipt: <str>, // receipt that can be used for payment referencing and verification
1111+ /// amount: <int>, // amount
1112+ /// }, ]
1113+ /// extra: <str>, //optional data
1114+ /// }
1115+ #[ no_mangle]
1116+ pub extern fn indy_parse_verify_response ( command_handle : i32 ,
1117+ payment_method : * const c_char ,
1118+ resp_json : * const c_char ,
1119+ cb : Option < extern fn ( command_handle_ : i32 ,
1120+ err : ErrorCode ,
1121+ txn_json : * const c_char ) > ) -> ErrorCode {
1122+ trace ! ( "indy_parse_payment_response: >>> resp_json: {:?}" , resp_json) ;
1123+ check_useful_c_str ! ( payment_method, ErrorCode :: CommonInvalidParam2 ) ;
1124+ check_useful_c_str ! ( resp_json, ErrorCode :: CommonInvalidParam3 ) ;
1125+ check_useful_c_callback ! ( cb, ErrorCode :: CommonInvalidParam4 ) ;
1126+
1127+ trace ! ( "indy_parse_payment_response: entities >>> resp_json: {:?}" , resp_json) ;
1128+
1129+ let result = CommandExecutor :: instance ( )
1130+ . send ( Command :: Payments (
1131+ PaymentsCommand :: ParseVerifyResponse (
1132+ payment_method,
1133+ resp_json,
1134+ Box :: new ( move |result| {
1135+ let ( err, txn_json) = result_to_err_code_1 ! ( result, String :: new( ) ) ;
1136+ trace ! ( "indy_build_verify_req: txn_json: {:?}" , txn_json) ;
1137+ let txn_json = CStringUtils :: string_to_cstring ( txn_json) ;
1138+ cb ( command_handle, err, txn_json. as_ptr ( ) ) ;
1139+ } )
1140+ ) ) ) ;
1141+
1142+ let result = result_to_err_code ! ( result) ;
1143+
1144+ trace ! ( "indy_parse_payment_response: <<< result: {:?}" , result) ;
1145+
1146+ result
10011147}
0 commit comments