@@ -9,6 +9,7 @@ defmodule Algora.Contracts do
9
9
alias Algora.FeeTier
10
10
alias Algora.MoneyUtils
11
11
alias Algora.Payments
12
+ alias Algora.Payments.Account
12
13
alias Algora.Payments.Transaction
13
14
alias Algora.Repo
14
15
alias Algora.Stripe
@@ -479,16 +480,17 @@ defmodule Algora.Contracts do
479
480
480
481
# TODO: do we need to lock the transactions here?
481
482
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
492
494
{ :error , error } ->
493
495
update_transaction_status ( transaction , { :error , error } )
494
496
Activities . insert ( contract , % { type: :contract_prepayment_failed } )
0 commit comments