@@ -18,7 +18,7 @@ defmodule AlgoraWeb.ContractLive do
18
18
19
19
require Logger
20
20
21
- defp tip_options , do: [ { "None" , 0 } , { "10%" , 10 } , { "20%" , 20 } , { "50%" , 50 } ]
21
+ # defp tip_options, do: [{"None", 0}, {"10%", 10}, {"20%", 20}, {"50%", 50}]
22
22
23
23
defmodule RewardBountyForm do
24
24
@ moduledoc false
@@ -109,7 +109,7 @@ defmodule AlgoraWeb.ContractLive do
109
109
ticket_body_html = Algora.Markdown . render ( bounty . ticket . description )
110
110
111
111
reward_changeset =
112
- RewardBountyForm . changeset ( % RewardBountyForm { } , % { tip_percentage: 0 } )
112
+ RewardBountyForm . changeset ( % RewardBountyForm { } , % { amount: bounty . amount } )
113
113
114
114
{ :ok , thread } = Chat . get_or_create_bounty_thread ( bounty )
115
115
messages = thread . id |> Chat . list_messages ( ) |> Repo . preload ( :sender )
@@ -233,6 +233,18 @@ defmodule AlgoraWeb.ContractLive do
233
233
end
234
234
end
235
235
236
+ @ impl true
237
+ def handle_event ( "authorize_with_stripe" , _params , socket ) do
238
+ case authorize_payment ( socket , socket . assigns . bounty ) do
239
+ { :ok , session_url } ->
240
+ { :noreply , redirect ( socket , external: session_url ) }
241
+
242
+ { :error , reason } ->
243
+ Logger . error ( "Failed to create payment session: #{ inspect ( reason ) } " )
244
+ { :noreply , put_flash ( socket , :error , "Something went wrong" ) }
245
+ end
246
+ end
247
+
236
248
@ impl true
237
249
def handle_event ( _event , _params , socket ) do
238
250
{ :noreply , socket }
@@ -508,13 +520,13 @@ defmodule AlgoraWeb.ContractLive do
508
520
509
521
< . drawer :if = { @ current_user } show = { @ show_reward_modal } on_cancel = "close_drawer " >
510
522
< . drawer_header >
511
- < . drawer_title > Pay Contract </ . drawer_title >
523
+ < . drawer_title > Authorize payment </ . drawer_title >
512
524
< . drawer_description >
513
- You can pay any amount at any time .
525
+ You will be charged once { @ contractor . name } accepts the contract .
514
526
</ . drawer_description >
515
527
</ . drawer_header >
516
528
< . drawer_content class = "mt-4 " >
517
- < . form for = { @ reward_form } phx-change = "validate_reward " phx-submit = "pay_with_stripe " >
529
+ < . form for = { @ reward_form } phx-change = "validate_reward " phx-submit = "authorize_with_stripe " >
518
530
< div class = "flex flex-col gap-8 " >
519
531
< div class = "grid grid-cols-2 gap-8 " >
520
532
< . card >
@@ -527,9 +539,10 @@ defmodule AlgoraWeb.ContractLive do
527
539
label = "Amount "
528
540
icon = "tabler-currency-dollar "
529
541
field = { @ reward_form [ :amount ] }
542
+ disabled
530
543
/>
531
544
532
- < div >
545
+ <%!-- < div>
533
546
<.label>Tip</.label>
534
547
<div class="mt-2">
535
548
<.radio_group
@@ -538,7 +551,7 @@ defmodule AlgoraWeb.ContractLive do
538
551
options={tip_options()}
539
552
/>
540
553
</div>
541
- </ div >
554
+ </div> --%>
542
555
</ div >
543
556
</ . card_content >
544
557
</ . card >
@@ -590,7 +603,7 @@ defmodule AlgoraWeb.ContractLive do
590
603
Cancel
591
604
</ . button >
592
605
< . button type = "submit " >
593
- Pay with Stripe < . icon name = "tabler-arrow-right " class = "-mr-1 ml-2 h-4 w-4 " />
606
+ Authorize with Stripe < . icon name = "tabler-arrow-right " class = "-mr-1 ml-2 h-4 w-4 " />
594
607
</ . button >
595
608
</ div >
596
609
</ div >
@@ -625,6 +638,14 @@ defmodule AlgoraWeb.ContractLive do
625
638
)
626
639
end
627
640
641
+ defp authorize_payment ( socket , bounty ) do
642
+ Bounties . authorize_payment (
643
+ % { owner: bounty . owner , amount: bounty . amount , bounty: bounty , claims: [ ] } ,
644
+ ticket_ref: socket . assigns . ticket_ref ,
645
+ recipient: socket . assigns . contractor
646
+ )
647
+ end
648
+
628
649
defp calculate_final_amount ( data_or_changeset ) do
629
650
tip_percentage = get_field ( data_or_changeset , :tip_percentage ) || Decimal . new ( 0 )
630
651
amount = get_field ( data_or_changeset , :amount ) || Money . zero ( :USD , no_fraction_if_integer: true )
0 commit comments