@@ -32,49 +32,74 @@ public function createGold()
3232
3333 public function updateSponsorBronze (Request $ request )
3434 {
35- $ sponsorships = Sponsorship::where ('name ' , 'Bronze ' )->first ();
36- foreach ($ request ->apartments as $ apartment ) {
37- $ apartment = Apartment::find ($ apartment );
38- $ apartment ->sponsorships ()->attach ($ sponsorships );
39- }
4035
41- $ superId = Auth::user ()->id ;
42- $ apartments = Apartment::where ('user_id ' , $ superId )->with ('sponsorships ' )->get ();
43- return view ('apartments.index ' , compact ('apartments ' , 'superId ' ));
36+ // gestiamo il pagamento con braintree
37+ $ payment = new PaymentController ();
38+ $ response = $ payment ->checkout ($ request );
39+ if ($ response ->getStatusCode () != 200 ) {
40+ return redirect ()->back ()->with ('error ' , 'Errore durante il pagamento ' );
41+ } else {
42+ $ sponsorships = Sponsorship::where ('name ' , 'Bronze ' )->first ();
43+ $ decodedApartments = json_decode ($ request ->apartments , true );
44+ foreach ($ decodedApartments as $ apartment ) {
45+ $ apartment = Apartment::find ($ apartment ['id ' ]);
46+ $ apartment ->sponsorships ()->attach ($ sponsorships );
47+ }
48+
49+ $ superId = Auth::user ()->id ;
50+ $ apartments = Apartment::where ('user_id ' , $ superId )->with ('sponsorships ' )->get ();
51+ $ successPayment = 'Pagamento effettuato! ' ;
52+ return view ('apartments.index ' , compact ('apartments ' , 'superId ' , 'successPayment ' ));
53+ }
4454 }
4555
4656 public function updateSponsorSilver (Request $ request )
4757 {
48- $ sponsorships = Sponsorship::where ('name ' , 'Silver ' )->first ();
49- foreach ($ request ->apartments as $ apartment ) {
58+ $ payment = new PaymentController ();
59+ $ response = $ payment ->checkout ($ request );
60+ if ($ response ->getStatusCode () != 200 ) {
61+ return redirect ()->back ()->with ('error ' , 'Errore durante il pagamento ' );
62+ } else {
63+ $ sponsorships = Sponsorship::where ('name ' , 'Silver ' )->first ();
64+ foreach ($ request ->apartments as $ apartment ) {
5065 $ apartment = Apartment::find ($ apartment );
51- $ apartment ->sponsorships ()->attach ($ sponsorships );
52- }
66+ $ apartment ->sponsorships ()->attach ($ sponsorships );
67+ }
5368
54- $ superId = Auth::user ()->id ;
55- $ apartments = Apartment::where ('user_id ' , $ superId )->with ('sponsorships ' )->get ();
56- return view ('apartments.index ' , compact ('apartments ' , 'superId ' ));
69+ $ superId = Auth::user ()->id ;
70+ $ apartments = Apartment::where ('user_id ' , $ superId )->with ('sponsorships ' )->get ();
71+ $ successPayment = 'Pagamento effettuato! ' ;
72+ return view ('apartments.index ' , compact ('apartments ' , 'superId ' , 'successPayment ' ));
73+ }
5774 }
5875
5976 public function updateSponsorGold (Request $ request )
6077 {
61- $ sponsorships = Sponsorship::where ('name ' , 'Gold ' )->first ();
62- foreach ($ request ->apartments as $ apartment ) {
78+ $ payment = new PaymentController ();
79+ $ response = $ payment ->checkout ($ request );
80+ if ($ response ->getStatusCode () != 200 ) {
81+ return redirect ()->back ()->with ('error ' , 'Errore durante il pagamento ' );
82+ } else {
83+ $ sponsorships = Sponsorship::where ('name ' , 'Gold ' )->first ();
84+ foreach ($ request ->apartments as $ apartment ) {
6385 $ apartment = Apartment::find ($ apartment );
6486 $ apartment ->sponsorships ()->attach ($ sponsorships );
6587 }
6688
6789 $ superId = Auth::user ()->id ;
68- $ apartments = Apartment::where ('user_id ' , $ superId )->with ('sponsorships ' )->get ();
69- return view ('apartments.index ' , compact ('apartments ' , 'superId ' ));
90+ $ apartments = Apartment::where ('user_id ' , $ superId )->with ('sponsorships ' )->get ();
91+ $ successPayment = 'Pagamento effettuato! ' ;
92+ return view ('apartments.index ' , compact ('apartments ' , 'superId ' , 'successPayment ' ));
93+ }
7094 }
7195
7296 public function showPaymentPage (Request $ request )
7397 {
7498 // Recupera gli appartamenti selezionati e il prezzo totale dalla richiesta
7599 $ selectedApartments = Apartment::whereIn ('id ' , $ request ->input ('apartments ' , []))->get ();
76100 $ totalPrice = $ request ->input ('totalPrice ' , 0 );
101+ $ sponsorshipType = $ request ->input ('sponsorshipType ' , 'Bronze ' );
77102
78- return view ('sponsors.payment ' , compact ('selectedApartments ' , 'totalPrice ' ));
103+ return view ('sponsors.payment ' , compact ('selectedApartments ' , 'totalPrice ' , ' sponsorshipType ' ));
79104 }
80105}
0 commit comments