<?php

include("includes/header.php"); 
include("includes/sidebar.php"); 

include("paystack/config.php"); 

$currency = "NGN";

 ?>
 
 <div class="main-content app-content">
<div class="container">
                            
                            <!--Modal: order-modal-->
                           
                                <h5 class="text-uppercase">
        Save</h5>
    <div class="row settings mt-3">
       
        <div class="col-xl-12">
            <div id="settingmenuContent">
                
                                <div id="editprofile">
                    <div class="row mb-5">
                        <div class="col-12">
                            <div class="card border-0 box-shadow">
                                <div class="card-body pb-0">
                                    <div class="d-flex align-items-center mb-3">
                                        <h5 class="text-uppercase">Make a Saving</h5>
                                    </div>
                        <form method="POST" action="" id="saveForm">
                                        <input type="hidden" name="_token" value="xzK0d1n2eIf3u6XdzjKWVvVUTx7gOZ9hY40Uw4si">                                        <div class="row">
                                            <div class="form-group col-sm-12">
                                                <label class="form-label">Amount<span
                                                        class="text-danger"> * </span></label>
                                                <input type="number" class="form-control" name="amount" id="amount"
                                                    value=""
                                                    placeholder="Amount" required>

                                            </div>
                                             

                                                                                                                                                                                        <div class="form-group col-md-6">
                                                    
                                                </div>
                                                
                                                                                        <div class="form-group text-end">
                                                                                            <br>
                                                <button
                                                    class="btn btn-secondary  "
                                                     type="submit" name="updateprofile" value="1" >SAVE </button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                

                          
                    </div>
                  
                               

            </div>
        </div>
    </div>
    
    
                        </div>
                    </div>
                </div>
  <?php

include("includes/footer.php"); 

 ?>
 
 <script type="text/javascript">
    
    
    

     const payment_form = document.querySelector("#saveForm")
     payment_form.addEventListener("submit",payWithPaystack,false)
     
     function payWithPaystack(e){
         
     e.preventDefault()
     let amount = $("#amount").val()
     
     let handler = new PaystackPop()
    
  handler.newTransaction({
  key: '<?php echo $public_key; ?>',
  email: 'sample@email.com',
  amount: amount * 100,
  currency: 'NGN',
  userID: <?php echo $id;?>,
  onSuccess: (transaction) => {
    ref = transaction.reference;
    window.location = "https://app.ovohinitiative.com/users/verify-payment?reference=" + ref
  },
  /*onLoad: (response) => {
    alert("onLoad: ", response);
  },*/
  onCancel: () => {
    alert("onCancel");
  },
  onError: (error) => {
    alert("Error: ", error.message);
  }
})
            
   
         
 
    
    }
     
 </script>