@@ -441,8 +441,19 @@ impl FakeWallet {
441441 async fn custom_outgoing_amount (
442442 & self ,
443443 unit : & CurrencyUnit ,
444+ amount : Option < & Amount < CurrencyUnit > > ,
444445 extra_json : & Option < String > ,
445446 ) -> Result < Amount < CurrencyUnit > , Error > {
447+ if let Some ( amount) = amount {
448+ return convert_currency_amount (
449+ amount. value ( ) ,
450+ amount. unit ( ) ,
451+ unit,
452+ & self . exchange_rate_cache ,
453+ )
454+ . await ;
455+ }
456+
446457 #[ derive( Deserialize ) ]
447458 struct CustomAmountField {
448459 amount : Option < u64 > ,
@@ -587,7 +598,11 @@ impl MintPayment for FakeWallet {
587598 self . ensure_custom_method_supported ( & custom_options. method ) ?;
588599
589600 let amount = self
590- . custom_outgoing_amount ( unit, & custom_options. extra_json )
601+ . custom_outgoing_amount (
602+ unit,
603+ custom_options. amount . as_ref ( ) ,
604+ & custom_options. extra_json ,
605+ )
591606 . await ?;
592607
593608 return Ok ( PaymentQuoteResponse {
@@ -768,7 +783,11 @@ impl MintPayment for FakeWallet {
768783 self . ensure_custom_method_supported ( & custom_options. method ) ?;
769784
770785 let total_spent = self
771- . custom_outgoing_amount ( unit, & custom_options. extra_json )
786+ . custom_outgoing_amount (
787+ unit,
788+ custom_options. amount . as_ref ( ) ,
789+ & custom_options. extra_json ,
790+ )
772791 . await ?;
773792
774793 Ok ( MakePaymentResponse {
@@ -1070,8 +1089,8 @@ fn fake_secret_key(seed: &str) -> SecretKey {
10701089#[ cfg( test) ]
10711090mod tests {
10721091 use cdk_common:: payment:: {
1073- CustomIncomingPaymentOptions , IncomingPaymentOptions , MintPayment ,
1074- OnchainOutgoingPaymentOptions , OutgoingPaymentOptions , PaymentIdentifier ,
1092+ CustomIncomingPaymentOptions , CustomOutgoingPaymentOptions , IncomingPaymentOptions ,
1093+ MintPayment , OnchainOutgoingPaymentOptions , OutgoingPaymentOptions , PaymentIdentifier ,
10751094 } ;
10761095
10771096 use super :: * ;
@@ -1093,6 +1112,22 @@ mod tests {
10931112 test_wallet_with_delay ( 0 )
10941113 }
10951114
1115+ fn custom_outgoing_options (
1116+ amount : Option < Amount < CurrencyUnit > > ,
1117+ extra_json : Option < String > ,
1118+ ) -> OutgoingPaymentOptions {
1119+ OutgoingPaymentOptions :: Custom ( Box :: new ( CustomOutgoingPaymentOptions {
1120+ method : "venmo" . to_string ( ) ,
1121+ request : "test-payment-request" . to_string ( ) ,
1122+ amount,
1123+ max_fee_amount : None ,
1124+ timeout_secs : None ,
1125+ melt_options : None ,
1126+ extra_json,
1127+ quote_id : cdk_common:: QuoteId :: new ( ) ,
1128+ } ) )
1129+ }
1130+
10961131 #[ tokio:: test]
10971132 async fn custom_payment_methods_are_configurable ( ) {
10981133 let settings = test_wallet ( )
@@ -1177,4 +1212,58 @@ mod tests {
11771212 ) ;
11781213 assert_eq ! ( response. status, MeltQuoteState :: Paid ) ;
11791214 }
1215+
1216+ #[ tokio:: test]
1217+ async fn custom_outgoing_quote_prefers_typed_amount ( ) {
1218+ let wallet = test_wallet ( )
1219+ . with_custom_payment_methods ( HashMap :: from ( [ ( "venmo" . to_string ( ) , "{}" . to_string ( ) ) ] ) ) ;
1220+
1221+ let response = wallet
1222+ . get_payment_quote (
1223+ & CurrencyUnit :: Sat ,
1224+ custom_outgoing_options (
1225+ Some ( Amount :: new ( 20 , CurrencyUnit :: Sat ) ) ,
1226+ Some ( r#"{"amount":30}"# . to_string ( ) ) ,
1227+ ) ,
1228+ )
1229+ . await
1230+ . expect ( "configured custom method should quote outgoing payment" ) ;
1231+
1232+ assert_eq ! ( response. amount, Amount :: new( 20 , CurrencyUnit :: Sat ) ) ;
1233+ }
1234+
1235+ #[ tokio:: test]
1236+ async fn custom_outgoing_payment_prefers_typed_amount ( ) {
1237+ let wallet = test_wallet ( )
1238+ . with_custom_payment_methods ( HashMap :: from ( [ ( "venmo" . to_string ( ) , "{}" . to_string ( ) ) ] ) ) ;
1239+
1240+ let response = wallet
1241+ . make_payment (
1242+ & CurrencyUnit :: Sat ,
1243+ custom_outgoing_options (
1244+ Some ( Amount :: new ( 20 , CurrencyUnit :: Sat ) ) ,
1245+ Some ( r#"{"amount":30}"# . to_string ( ) ) ,
1246+ ) ,
1247+ )
1248+ . await
1249+ . expect ( "configured custom method should make outgoing payment" ) ;
1250+
1251+ assert_eq ! ( response. total_spent, Amount :: new( 21 , CurrencyUnit :: Sat ) ) ;
1252+ }
1253+
1254+ #[ tokio:: test]
1255+ async fn custom_outgoing_amount_falls_back_to_extra_json ( ) {
1256+ let wallet = test_wallet ( )
1257+ . with_custom_payment_methods ( HashMap :: from ( [ ( "venmo" . to_string ( ) , "{}" . to_string ( ) ) ] ) ) ;
1258+
1259+ let response = wallet
1260+ . get_payment_quote (
1261+ & CurrencyUnit :: Sat ,
1262+ custom_outgoing_options ( None , Some ( r#"{"amount":30}"# . to_string ( ) ) ) ,
1263+ )
1264+ . await
1265+ . expect ( "configured custom method should quote outgoing payment" ) ;
1266+
1267+ assert_eq ! ( response. amount, Amount :: new( 30 , CurrencyUnit :: Sat ) ) ;
1268+ }
11801269}
0 commit comments