@@ -1050,6 +1050,11 @@ impl BreezSdk {
10501050 "Token identifier can't be provided for this payment request: spark sats payment" . to_string ( ) ,
10511051 ) ) ;
10521052 }
1053+ if sats_payment_details. amount . is_some ( ) && request. amount . is_some ( ) {
1054+ return Err ( SdkError :: InvalidInput (
1055+ "Amount can't be provided for this payment request: spark invoice defines amount" . to_string ( ) ,
1056+ ) ) ;
1057+ }
10531058 sats_payment_details. amount
10541059 }
10551060 spark_wallet:: SparkAddressPaymentType :: TokensPayment (
@@ -1060,6 +1065,11 @@ impl BreezSdk {
10601065 "Token identifier is required for this payment request: spark tokens payment" . to_string ( ) ,
10611066 ) ) ;
10621067 }
1068+ if tokens_payment_details. amount . is_some ( ) && request. amount . is_some ( ) {
1069+ return Err ( SdkError :: InvalidInput (
1070+ "Amount can't be provided for this payment request: spark invoice defines amount" . to_string ( ) ,
1071+ ) ) ;
1072+ }
10631073 tokens_payment_details. amount
10641074 }
10651075 }
@@ -1171,34 +1181,12 @@ impl BreezSdk {
11711181 . map_err ( |_| SdkError :: InvalidInput ( "Invalid spark address" . to_string ( ) ) ) ?;
11721182
11731183 let payment = if let Some ( identifier) = token_identifier {
1174- let tx_hash = self
1175- . spark_wallet
1176- . transfer_tokens ( vec ! [ TransferTokenOutput {
1177- token_id: identifier,
1178- amount: u128 :: from( request. prepare_response. amount) ,
1179- receiver_address: spark_address,
1180- } ] )
1181- . await ?;
1182- let tx = self
1183- . spark_wallet
1184- . list_token_transactions ( ListTokenTransactionsRequest {
1185- token_transaction_hashes : vec ! [ tx_hash] ,
1186- paging : None ,
1187- ..Default :: default ( )
1188- } )
1189- . await ?
1190- . first ( )
1191- . ok_or ( SdkError :: Generic (
1192- "Token transaction not found after being started" . to_string ( ) ,
1193- ) ) ?
1194- . clone ( ) ;
1195- self . token_transaction_to_payments ( & tx, true )
1196- . await ?
1197- . first ( )
1198- . ok_or ( SdkError :: Generic (
1199- "No payment found in started token transaction" . to_string ( ) ,
1200- ) ) ?
1201- . clone ( )
1184+ self . send_spark_token_payment (
1185+ identifier,
1186+ request. prepare_response . amount . into ( ) ,
1187+ spark_address,
1188+ )
1189+ . await ?
12021190 } else {
12031191 let transfer = self
12041192 . spark_wallet
@@ -1465,6 +1453,45 @@ impl BreezSdk {
14651453 }
14661454}
14671455
1456+ impl BreezSdk {
1457+ async fn send_spark_token_payment (
1458+ & self ,
1459+ token_identifier : String ,
1460+ amount : u128 ,
1461+ receiver_address : SparkAddress ,
1462+ ) -> Result < Payment , SdkError > {
1463+ let tx_hash = self
1464+ . spark_wallet
1465+ . transfer_tokens ( vec ! [ TransferTokenOutput {
1466+ token_id: token_identifier,
1467+ amount,
1468+ receiver_address,
1469+ } ] )
1470+ . await ?;
1471+ let tx = self
1472+ . spark_wallet
1473+ . list_token_transactions ( ListTokenTransactionsRequest {
1474+ token_transaction_hashes : vec ! [ tx_hash] ,
1475+ paging : None ,
1476+ ..Default :: default ( )
1477+ } )
1478+ . await ?
1479+ . first ( )
1480+ . ok_or ( SdkError :: Generic (
1481+ "Token transaction not found after being started" . to_string ( ) ,
1482+ ) ) ?
1483+ . clone ( ) ;
1484+ Ok ( self
1485+ . token_transaction_to_payments ( & tx, true )
1486+ . await ?
1487+ . first ( )
1488+ . ok_or ( SdkError :: Generic (
1489+ "No payment found in started token transaction" . to_string ( ) ,
1490+ ) ) ?
1491+ . clone ( ) )
1492+ }
1493+ }
1494+
14681495fn process_success_action (
14691496 payment : & Payment ,
14701497 success_action : Option < & SuccessAction > ,
0 commit comments