@@ -257,7 +257,6 @@ pub type BuildGetTxnFeesReqCB = extern fn(command_handle: i32,
257257///
258258/// # Params
259259/// command_handle: command handle to map callback to context
260- /// payment_method: payment method to use
261260/// resp_json: response for Indy request for getting fees
262261///
263262/// # Return
@@ -273,6 +272,47 @@ pub type ParseGetTxnFeesResponseCB = extern fn(command_handle: i32,
273272 err : ErrorCode ,
274273 fees_json : * const c_char ) -> ErrorCode > ) -> ErrorCode ;
275274
275+ /// Builds Indy request for information to verify the receipt
276+ ///
277+ /// # Params
278+ /// command_handle
279+ /// wallet_handle
280+ /// submitter_did
281+ /// receipt -- receipt to verify
282+ ///
283+ /// # Return
284+ /// verify_txn_json -- request to be sent to ledger
285+
286+ pub type BuildVerifyReqCB = extern fn ( command_handle : i32 ,
287+ wallet_handle : i32 ,
288+ submitter_did : * const c_char ,
289+ receipt : * const c_char ,
290+ cb : Option < extern fn ( command_handle_ : i32 ,
291+ err : ErrorCode ,
292+ verify_txn_json : * const c_char ) -> ErrorCode > ) -> ErrorCode ;
293+
294+ /// Parses Indy response with information to verify receipt
295+ ///
296+ /// # Params
297+ /// command_handle
298+ /// resp_json -- response of the ledger for verify txn
299+ ///
300+ /// # Return
301+ /// txn_json: {
302+ /// sources: [<str>, ]
303+ /// receipts: [ {
304+ /// recipient: <str>, // payment address of recipient
305+ /// receipt: <str>, // receipt that can be used for payment referencing and verification
306+ /// amount: <int>, // amount
307+ /// }, ]
308+ /// extra: <str>, //optional data
309+ /// }
310+ pub type ParseVerifyResponseCB = extern fn ( command_handle : i32 ,
311+ resp_json : * const c_char ,
312+ cb : Option < extern fn ( command_handle_ : i32 ,
313+ err : ErrorCode ,
314+ txn_json : * const c_char ) -> ErrorCode > ) -> ErrorCode ;
315+
276316/// Register custom payment implementation.
277317///
278318/// It allows library user to provide custom payment method implementation as set of handlers.
@@ -303,6 +343,8 @@ pub extern fn indy_register_payment_method(command_handle: i32,
303343 build_set_txn_fees_req : Option < BuildSetTxnFeesReqCB > ,
304344 build_get_txn_fees_req : Option < BuildGetTxnFeesReqCB > ,
305345 parse_get_txn_fees_response : Option < ParseGetTxnFeesResponseCB > ,
346+ build_verify_req : Option < BuildVerifyReqCB > ,
347+ parse_verify_response : Option < ParseVerifyResponseCB > ,
306348 cb : Option < extern fn ( command_handle_ : i32 ,
307349 err : ErrorCode ) > ) -> ErrorCode {
308350 trace ! ( "indy_register_payment_method: >>> payment_method: {:?}" , payment_method) ;
@@ -319,7 +361,9 @@ pub extern fn indy_register_payment_method(command_handle: i32,
319361 check_useful_c_callback ! ( build_set_txn_fees_req, ErrorCode :: CommonInvalidParam11 ) ;
320362 check_useful_c_callback ! ( build_get_txn_fees_req, ErrorCode :: CommonInvalidParam12 ) ;
321363 check_useful_c_callback ! ( parse_get_txn_fees_response, ErrorCode :: CommonInvalidParam13 ) ;
322- check_useful_c_callback ! ( cb, ErrorCode :: CommonInvalidParam14 ) ;
364+ check_useful_c_callback ! ( build_verify_req, ErrorCode :: CommonInvalidParam14 ) ;
365+ check_useful_c_callback ! ( parse_verify_response, ErrorCode :: CommonInvalidParam15 ) ;
366+ check_useful_c_callback ! ( cb, ErrorCode :: CommonInvalidParam16 ) ;
323367
324368 trace ! ( "indy_register_payment_method: entities >>> payment_method: {:?}" , payment_method) ;
325369
@@ -334,7 +378,9 @@ pub extern fn indy_register_payment_method(command_handle: i32,
334378 build_mint_req,
335379 build_set_txn_fees_req,
336380 build_get_txn_fees_req,
337- parse_get_txn_fees_response
381+ parse_get_txn_fees_response,
382+ build_verify_req,
383+ parse_verify_response,
338384 ) ;
339385 let result =
340386 CommandExecutor :: instance ( ) . send (
@@ -1014,4 +1060,104 @@ pub extern fn indy_parse_get_txn_fees_response(command_handle: i32,
10141060 trace ! ( "indy_parse_get_txn_fees_response: <<< res: {:?}" , res) ;
10151061
10161062 res
1063+ }
1064+
1065+ /// Builds Indy request for information to verify the receipt
1066+ ///
1067+ /// # Params
1068+ /// command_handle
1069+ /// wallet_handle
1070+ /// submitter_did
1071+ /// receipt -- receipt to verify
1072+ ///
1073+ /// # Return
1074+ /// verify_txn_json -- request to be sent to ledger
1075+ /// payment_method
1076+ #[ no_mangle]
1077+ pub extern fn indy_build_verify_req ( command_handle : i32 ,
1078+ wallet_handle : i32 ,
1079+ submitter_did : * const c_char ,
1080+ receipt : * const c_char ,
1081+ cb : Option < extern fn ( command_handle_ : i32 ,
1082+ err : ErrorCode ,
1083+ verify_txn_json : * const c_char ,
1084+ payment_method : * const c_char ) > ) -> ErrorCode {
1085+ trace ! ( "indy_build_verify_req: >>> wallet_handle {:?}, submitter_did: {:?}, receipt: {:?}" , wallet_handle, submitter_did, receipt) ;
1086+ check_useful_c_str ! ( submitter_did, ErrorCode :: CommonInvalidParam3 ) ;
1087+ check_useful_c_str ! ( receipt, ErrorCode :: CommonInvalidParam4 ) ;
1088+ check_useful_c_callback ! ( cb, ErrorCode :: CommonInvalidParam5 ) ;
1089+
1090+ trace ! ( "indy_build_verify_req: entities >>> wallet_handle {:?}, submitter_did: {:?}, receipt: {:?}" , wallet_handle, submitter_did, receipt) ;
1091+
1092+ let result = CommandExecutor :: instance ( )
1093+ . send ( Command :: Payments (
1094+ PaymentsCommand :: BuildVerifyReq (
1095+ wallet_handle,
1096+ submitter_did,
1097+ receipt,
1098+ Box :: new ( move |result| {
1099+ let ( err, verify_txn_json, payment_method) = result_to_err_code_2 ! ( result, String :: new( ) , String :: new( ) ) ;
1100+ trace ! ( "indy_build_verify_req: verify_txn_json: {:?}, payment_method: {:?}" , verify_txn_json, payment_method) ;
1101+ let verify_txn_json = CStringUtils :: string_to_cstring ( verify_txn_json) ;
1102+ let payment_method = CStringUtils :: string_to_cstring ( payment_method) ;
1103+ cb ( command_handle, err, verify_txn_json. as_ptr ( ) , payment_method. as_ptr ( ) ) ;
1104+ } )
1105+ ) ) ) ;
1106+
1107+ let result = result_to_err_code ! ( result) ;
1108+
1109+ trace ! ( "indy_build_verify_req: <<< result: {:?}" , result) ;
1110+
1111+ result
1112+ }
1113+
1114+ /// Parses Indy response with information to verify receipt
1115+ ///
1116+ /// # Params
1117+ /// command_handle
1118+ /// payment_method
1119+ /// resp_json -- response of the ledger for verify txn
1120+ ///
1121+ /// # Return
1122+ /// txn_json: {
1123+ /// sources: [<str>, ]
1124+ /// receipts: [ {
1125+ /// recipient: <str>, // payment address of recipient
1126+ /// receipt: <str>, // receipt that can be used for payment referencing and verification
1127+ /// amount: <int>, // amount
1128+ /// }, ]
1129+ /// extra: <str>, //optional data
1130+ /// }
1131+ #[ no_mangle]
1132+ pub extern fn indy_parse_verify_response ( command_handle : i32 ,
1133+ payment_method : * const c_char ,
1134+ resp_json : * const c_char ,
1135+ cb : Option < extern fn ( command_handle_ : i32 ,
1136+ err : ErrorCode ,
1137+ txn_json : * const c_char ) > ) -> ErrorCode {
1138+ trace ! ( "indy_parse_payment_response: >>> resp_json: {:?}" , resp_json) ;
1139+ check_useful_c_str ! ( payment_method, ErrorCode :: CommonInvalidParam2 ) ;
1140+ check_useful_c_str ! ( resp_json, ErrorCode :: CommonInvalidParam3 ) ;
1141+ check_useful_c_callback ! ( cb, ErrorCode :: CommonInvalidParam4 ) ;
1142+
1143+ trace ! ( "indy_parse_payment_response: entities >>> resp_json: {:?}" , resp_json) ;
1144+
1145+ let result = CommandExecutor :: instance ( )
1146+ . send ( Command :: Payments (
1147+ PaymentsCommand :: ParseVerifyResponse (
1148+ payment_method,
1149+ resp_json,
1150+ Box :: new ( move |result| {
1151+ let ( err, txn_json) = result_to_err_code_1 ! ( result, String :: new( ) ) ;
1152+ trace ! ( "indy_build_verify_req: txn_json: {:?}" , txn_json) ;
1153+ let txn_json = CStringUtils :: string_to_cstring ( txn_json) ;
1154+ cb ( command_handle, err, txn_json. as_ptr ( ) ) ;
1155+ } )
1156+ ) ) ) ;
1157+
1158+ let result = result_to_err_code ! ( result) ;
1159+
1160+ trace ! ( "indy_parse_payment_response: <<< result: {:?}" , result) ;
1161+
1162+ result
10171163}
0 commit comments