@@ -9,6 +9,7 @@ defmodule Algora.Contracts do
99 alias Algora.FeeTier
1010 alias Algora.MoneyUtils
1111 alias Algora.Payments
12+ alias Algora.Payments.Account
1213 alias Algora.Payments.Transaction
1314 alias Algora.Repo
1415 alias Algora.Stripe
@@ -479,16 +480,17 @@ defmodule Algora.Contracts do
479480
480481 # TODO: do we need to lock the transactions here?
481482 defp transfer_funds ( contract , % Transaction { type: :transfer } = transaction ) when transaction . status != :succeeded do
482- case Stripe.Transfer . create ( % {
483- amount: MoneyUtils . to_minor_units ( transaction . net_amount ) ,
484- currency: to_string ( transaction . net_amount . currency ) ,
485- destination: transaction . user_id
486- } ) do
487- { :ok , stripe_transfer } ->
488- update_transaction_status ( transaction , stripe_transfer , :succeeded )
489- mark_contract_as_paid ( contract )
490- { :ok , stripe_transfer }
491-
483+ with { :ok , account } <- Repo . fetch_by ( Account , user_id: transaction . user_id ) ,
484+ { :ok , stripe_transfer } <-
485+ Stripe.Transfer . create ( % {
486+ amount: MoneyUtils . to_minor_units ( transaction . net_amount ) ,
487+ currency: to_string ( transaction . net_amount . currency ) ,
488+ destination: account . provider_id
489+ } ) do
490+ update_transaction_status ( transaction , stripe_transfer , :succeeded )
491+ mark_contract_as_paid ( contract )
492+ { :ok , stripe_transfer }
493+ else
492494 { :error , error } ->
493495 update_transaction_status ( transaction , { :error , error } )
494496 Activities . insert ( contract , % { type: :contract_prepayment_failed } )
0 commit comments