/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package gui; import com.codename1.components.SpanLabel; import com.codename1.ui.Button; import com.codename1.ui.Component; import com.codename1.ui.Dialog; import com.codename1.ui.Display; import com.codename1.ui.EncodedImage; import com.codename1.ui.FontImage; import com.codename1.ui.Form; import com.codename1.ui.Graphics; import com.codename1.ui.Image; import com.codename1.ui.Label; import com.codename1.ui.TextArea; import com.codename1.ui.TextField; import com.codename1.ui.URLImage; import com.codename1.ui.layouts.BoxLayout; import com.codename1.ui.plaf.Style; import com.codename1.ui.plaf.UIManager; import entites.Reservation; import java.util.ArrayList; import org.json.JSONArray; import services.ReservationService; /** * * @author mbembli */ public class BitcoinPaymentForm extends Form { // GET BTC ADRESS String addr = new ReservationService().getBTCaddress().toString(); //BitcoinPaymentForm(fname,lname,email,phone,addr,pays,state,city,zipcode,total,userid,act_id,nb_pers,prix_personne) public BitcoinPaymentForm(String fname,String lname,String date_deb,String date_fin,String email,String phone,String address,String pays,String state,String city, String zipcode,double total,int user_id,int act_id,int nb_pers,double prix_personne) { this.setTitle("Payment"); this.setLayout(BoxLayout.y()); Label l = new Label("BITCOIN"); // QR CODE //Create a fresh grey EncodedImage when label doesn't have any icon set initially int deviceWidth = Display.getInstance().getDisplayWidth(); int deviceHeight = Display.getInstance().getDisplayHeight(); Image placeholder = Image.createImage(deviceWidth , deviceWidth/3, 0xbfc9d2); //square image set to 10% of screen width placeholder.scaledHeight(deviceHeight/2); EncodedImage encImage = EncodedImage.createFromImage(placeholder, false); Label label = new Label(); label.setIcon(URLImage.createToStorage(encImage, "Large_" + "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl="+addr, "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl="+addr, URLImage.RESIZE_SCALE)); SpanLabel btcAddr = new SpanLabel(addr); Label titlebtc = new Label("BTC address : "); Label hr = new Label("------------------------------------------"); SpanLabel spl1 = new SpanLabel("1 - Please send "+total+" USD to the following bitcoin address (you can use QR code too)."); SpanLabel spl2 = new SpanLabel("2- Click on the 'Confirm payment' button once the amount has been sent."); // Button confirmPayment = new Button("Confirm payment"); confirmPayment.addActionListener((evt) -> { String montant = new ReservationService().checkPaymentReceived(addr); if (Double.parseDouble(montant) == 0.0 ){ Dialog.show("Alert", "No payment received!", null, "Ok"); // add reservation // send json array to web if (new ReservationService().addReservation(fname,lname,date_deb,date_fin,email,phone,address,pays,state,city,zipcode,total,user_id,act_id,nb_pers,prix_personne).equals("added")){ // redirection to confirmation page new Confirmation().show(); } System.out.println("ok"); } else if (Double.parseDouble(montant) < total){ Dialog.show("Alert", "You need to pay more ("+(total-Double.parseDouble(montant))+")", null, "Ok"); } else { Dialog.show("Alert", "Payment successfully received", null, "Ok"); } }); this.addAll(l,label,titlebtc,btcAddr,hr,spl1,spl2,confirmPayment); // } }