diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index e8b3162..5eefcfd 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -8,13 +8,14 @@ - + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 89a0b7b..eab6608 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + @@ -10,4 +11,11 @@ + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 587a7c7..9680c8a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,7 +65,6 @@ dependencies { implementation 'androidx.cardview:cardview:1.0.0' implementation group: 'com.cloudinary', name: 'cloudinary-android', version: '1.24.0' implementation 'com.google.android.material:material:1.4.0' // Use the latest version - - + implementation 'com.razorpay:checkout:1.6.33' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0740ce9..1aa0952 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,9 +6,12 @@ tools:ignore="ScopedStorage" /> - + + + + @@ -34,6 +37,18 @@ tools:replace="android:fullBackupContent" tools:targetApi="31" tools:ignore="CustomPermissionTypo"> + + + + @@ -42,7 +57,7 @@ android:exported="true" /> + android:exported="true" /> diff --git a/app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java b/app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java index 21b6d1b..0adf983 100644 --- a/app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java +++ b/app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java @@ -173,7 +173,6 @@ public void onClick(View v) { String filteredList = null; Log.d("Exception",filteredList); } - }); //Drawer and Navigation bar layout view find diff --git a/app/src/main/java/com/BugBazaar/ui/TestActivity.java b/app/src/main/java/com/BugBazaar/ui/TestActivity.java index 506f855..7912154 100644 --- a/app/src/main/java/com/BugBazaar/ui/TestActivity.java +++ b/app/src/main/java/com/BugBazaar/ui/TestActivity.java @@ -1,8 +1,10 @@ package com.BugBazaar.ui; - -import androidx.appcompat.app.AppCompatActivity; - import android.os.Bundle; +import android.view.View; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.Toast; +import androidx.appcompat.app.AppCompatActivity; import com.BugBazaar.R; @@ -12,5 +14,27 @@ public class TestActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); + + RadioGroup radioGroup = findViewById(R.id.radioGroup); + RadioButton radioButton1 = findViewById(R.id.radioButton1); + RadioButton radioButton2 = findViewById(R.id.radioButton2); + + // Set OnClickListener for the first RadioButton + radioButton1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // Show a toast when the first RadioButton is clicked + Toast.makeText(TestActivity.this, "First Clicked", Toast.LENGTH_SHORT).show(); + } + }); + + // Set OnClickListener for the second RadioButton + radioButton2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // Show a toast when the second RadioButton is clicked + Toast.makeText(TestActivity.this, "Second Clicked", Toast.LENGTH_SHORT).show(); + } + }); } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/BugBazaar/ui/cart/Cart.java b/app/src/main/java/com/BugBazaar/ui/cart/Cart.java index 1216f9c..35296a4 100644 --- a/app/src/main/java/com/BugBazaar/ui/cart/Cart.java +++ b/app/src/main/java/com/BugBazaar/ui/cart/Cart.java @@ -22,7 +22,6 @@ public Cart() { private SQLiteDatabase database; - public long addCartItem(CartItem cartItem) { ContentValues values = new ContentValues(); if (cartItems.containsKey(cartItem)) { diff --git a/app/src/main/java/com/BugBazaar/ui/cart/CartActivity.java b/app/src/main/java/com/BugBazaar/ui/cart/CartActivity.java index 1de3d8c..ed721fe 100644 --- a/app/src/main/java/com/BugBazaar/ui/cart/CartActivity.java +++ b/app/src/main/java/com/BugBazaar/ui/cart/CartActivity.java @@ -1,4 +1,5 @@ package com.BugBazaar.ui.cart; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; @@ -12,6 +13,8 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.BugBazaar.R; +import com.BugBazaar.ui.payment.OrderSummary; + import java.util.List; import java.util.Locale; @@ -93,7 +96,9 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onClick(View v) { // Perform the checkout action here - Toast.makeText(CartActivity.this, "Checkout clicked", Toast.LENGTH_SHORT).show(); + Intent intentz=new Intent(CartActivity.this, OrderSummary.class); + intentz.putExtra("totalPrice",totalCost); + startActivity(intentz); } }); } diff --git a/app/src/main/java/com/BugBazaar/ui/cart/CartDatabaseHelper.java b/app/src/main/java/com/BugBazaar/ui/cart/CartDatabaseHelper.java index 1b4be14..98c4d13 100644 --- a/app/src/main/java/com/BugBazaar/ui/cart/CartDatabaseHelper.java +++ b/app/src/main/java/com/BugBazaar/ui/cart/CartDatabaseHelper.java @@ -75,6 +75,8 @@ public long addCartItem(CartItem cartItem) { return recordId; } + + //To Debug public void removeCartItem(CartItem cartItem) { SQLiteDatabase db = this.getWritableDatabase(); Log.d("removeid",String.valueOf(cartItem.getId())); diff --git a/app/src/main/java/com/BugBazaar/ui/cart/CartItemDBModel.java b/app/src/main/java/com/BugBazaar/ui/cart/CartItemDBModel.java index 9ba9f78..699dda0 100644 --- a/app/src/main/java/com/BugBazaar/ui/cart/CartItemDBModel.java +++ b/app/src/main/java/com/BugBazaar/ui/cart/CartItemDBModel.java @@ -2,6 +2,7 @@ import android.provider.BaseColumns; + public final class CartItemDBModel { // To prevent someone from accidentally instantiating the contract class, // make the constructor private. diff --git a/app/src/main/java/com/BugBazaar/ui/payment/OrderHistory.java b/app/src/main/java/com/BugBazaar/ui/payment/OrderHistory.java new file mode 100644 index 0000000..272d05d --- /dev/null +++ b/app/src/main/java/com/BugBazaar/ui/payment/OrderHistory.java @@ -0,0 +1,16 @@ +package com.BugBazaar.ui.payment; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; + +import com.BugBazaar.R; + +public class OrderHistory extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_order_history); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/BugBazaar/ui/payment/OrderSummary.java b/app/src/main/java/com/BugBazaar/ui/payment/OrderSummary.java new file mode 100644 index 0000000..bbb5ef5 --- /dev/null +++ b/app/src/main/java/com/BugBazaar/ui/payment/OrderSummary.java @@ -0,0 +1,192 @@ +package com.BugBazaar.ui.payment; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.TextView; +import android.widget.Toast; + +import com.BugBazaar.R; +import com.BugBazaar.ui.cart.CartDatabaseHelper; +import com.BugBazaar.ui.cart.CartItem; +import com.BugBazaar.ui.cart.CartItemDBModel; +import com.razorpay.Checkout; +import com.razorpay.PaymentResultListener; + +import org.json.JSONObject; + +import java.util.List; + +public class OrderSummary extends AppCompatActivity { + private List cartItems; + private TextView txtProdQuantityOS; + private TextView txtTotalCostOS; + private TextView txtFinalCostOS; + private RadioGroup rbGroupPaymentOptions; + private RadioButton rbPayViaWallet; + private RadioButton rbPayViaRazorpay; + Button btnProceedPaymentOS; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_order_summary); + // Toolbar title set + TextView toolbarTitle = findViewById(R.id.toolbarTitle); + toolbarTitle.setText("Order Summary"); + txtProdQuantityOS = findViewById(R.id.txtProdQuantityOS); + txtTotalCostOS = findViewById(R.id.txtTotalCostOS); + txtFinalCostOS = findViewById(R.id.txtFinalCostOS); + btnProceedPaymentOS = findViewById(R.id.btnProceedPaymentOS); + + // Initialize the RadioGroup and RadioButton elements + rbGroupPaymentOptions = findViewById(R.id.rbGroupPaymentOptions); + rbPayViaWallet = findViewById(R.id.rbPayViaWallet); + rbPayViaRazorpay = findViewById(R.id.rbPayViaRazorpay); + + // Initialize Razorpay with your API key + Checkout.preload(getApplicationContext()); + Checkout checkout = new Checkout(); + checkout.setKeyID("rzp_test_YEExgm42Uvy0u1"); + + // Initialize your CartDatabaseHelper + CartDatabaseHelper cartDBHelper = new CartDatabaseHelper(this, "cart.db", null, 1); + // Initialize your cartItems list and populate it with all items from the database + cartItems = cartDBHelper.getAllRecords(); + // Initialize prodQuantity to store the product quantity + int prodQuantity = 0; + // Iterate through the list of cart items and retrieve the product_quantity from the database + for (CartItem cartItem : cartItems) { + // Retrieve the product name for each item + String productName = cartItem.getProductName(); + + // Retrieve the product quantity from the database using a query + int quantity = getProductQuantityFromDatabase(cartDBHelper, productName); + + // Add the quantity to prodQuantity + prodQuantity += quantity; + } + // Set the product quantity + txtProdQuantityOS.setText(String.valueOf(prodQuantity)); + + + Intent intent = getIntent(); + int totalCost = intent.getIntExtra("totalPrice", 0); + // Format the totalCost and set it in the TextView + String formattedTotalCost = formatPrice(totalCost); + txtTotalCostOS.setText(formattedTotalCost); + + int deliveryCharges = 536; + + // Final Cost to be sent to Razorpay or wallet + int finalCost = totalCost + deliveryCharges; + String formattedFinalCost = formatPrice(finalCost); + txtFinalCostOS.setText(formattedFinalCost); + + // Set an OnClickListener to the "Proceed to Payment" button + btnProceedPaymentOS.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // Check which radio button is selected + int selectedRadioButtonId = rbGroupPaymentOptions.getCheckedRadioButtonId(); + + if (selectedRadioButtonId == R.id.rbPayViaWallet) { + // Handle payment via wallet (if applicable) + } else if (selectedRadioButtonId == R.id.rbPayViaRazorpay) { + int amountInPaise=finalCost*100; + + try { + // You need to pass a JSONObject with payment details to Razorpay + JSONObject options = new JSONObject(); + options.put("name", "BugBazaar Private Limited"); // Replace with your company name + options.put("description", "Order Payment"); + options.put("currency", "INR"); // Replace with the appropriate currency code + options.put("amount", amountInPaise); // Amount should be in paise + options.put("prefill.email", "customer@example.com"); + options.put("prefill.contact", "1234567890"); + + // Callback URL (optional, can be used for handling payment success or failure) + // options.put("callback_url", "your_callback_url"); + checkout.open(OrderSummary.this,options); + + } catch (Exception e) { + e.printStackTrace(); + } + // Open Razorpay payment dialog + } + } + }); + } + public void onPaymentSuccess(String s) { + Toast.makeText(this,"Payment Successful",Toast.LENGTH_SHORT).show(); + + //Move to Order History Activity + //Clear All Cart Items + } + + public void onPaymentError(int code, String response) { + // Handle payment error + // This method is called when there is a payment error + + // Log the error code and response for debugging + Log.e("Razorpay Error", "Error Code: " + code); + Log.e("Razorpay Error", "Error Response: " + response); + + // You can display an error message to the user or take appropriate action based on the error code and response + // For example, you can show a Toast message with the error details: + // Toast.makeText(this, "Payment Error: " + response, Toast.LENGTH_SHORT).show(); + + // You can also perform additional error handling based on the error code if needed + switch (code) { + case Checkout.NETWORK_ERROR: + Toast.makeText(this, "Network Error: Please check the internet connection.", Toast.LENGTH_LONG).show(); + break; + case Checkout.INVALID_OPTIONS: + // Handle invalid payment options + break; + case Checkout.PAYMENT_CANCELED: + Toast.makeText(this, "Payment Error: Payment Canceled by user.", Toast.LENGTH_LONG).show(); + break; + // Add more cases for specific error codes as needed + } + } + + // Define a method to retrieve product_quantity from the database based on product name + private int getProductQuantityFromDatabase(CartDatabaseHelper dbHelper, String productName) { + int quantity = 0; + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query( + CartItemDBModel.CartItemEntry.TABLE_NAME, // Table name + new String[]{CartItemDBModel.CartItemEntry.COLUMN_QUANTITY}, // Columns to retrieve + CartItemDBModel.CartItemEntry.COLUMN_PRODUCT_NAME + "=?", // Selection criteria + new String[]{productName}, // Selection arguments + null, // Group by + null, // Having + null // Order by + ); + + if (cursor != null && cursor.moveToFirst()) { + quantity = cursor.getInt(cursor.getColumnIndexOrThrow(CartItemDBModel.CartItemEntry.COLUMN_QUANTITY)); + cursor.close(); + } + + return quantity; + } + + private String formatPrice(int price) { + return String.format("₹%,d", price); + } + + // Code to handle back button + public void onBackButtonClick(View view) { + onBackPressed(); // Navigate back to the previous activity + } +} diff --git a/app/src/main/java/com/BugBazaar/ui/payment/TestRazorPay.java b/app/src/main/java/com/BugBazaar/ui/payment/TestRazorPay.java new file mode 100644 index 0000000..7bc04ba --- /dev/null +++ b/app/src/main/java/com/BugBazaar/ui/payment/TestRazorPay.java @@ -0,0 +1,91 @@ +package com.BugBazaar.ui.payment; + +import androidx.appcompat.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; + +import com.razorpay.Checkout; +import com.razorpay.PaymentResultListener; // Import the PaymentResultListener +import com.BugBazaar.R; +import org.json.JSONException; +import org.json.JSONObject; + +public class TestRazorPay extends AppCompatActivity implements PaymentResultListener { // Implement the interface + private Button btnProceedPayment; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_test_razor_pay); + btnProceedPayment = findViewById(R.id.btnProceedPayment); + + // Initialize Razorpay with your API key + Checkout.preload(getApplicationContext()); + Checkout checkout = new Checkout(); + checkout.setKeyID("rzp_test_YEExgm42Uvy0u1"); + + btnProceedPayment.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + // Create payment options + JSONObject options = new JSONObject(); + try { + options.put("name", "BugBazaar Retailers"); + options.put("description", "Purchase Description"); + //options.put("image", "YOUR_LOGO_URL"); + options.put("currency", "INR"); // Change to your currency code + options.put("amount", "10000"); // Change to the actual amount in paise + //options.put("order_id", "23287827788382387231923921392173123123213"); // The order ID received from your server + options.put("prefill.email", "customer@example.com"); + options.put("prefill.contact", "1234567890"); + } catch (JSONException e) { + e.printStackTrace(); + // Handle JSON exception here + } + + // Open Razorpay payment dialog + try { + checkout.open(TestRazorPay.this, options); + } catch (Exception e) { + e.printStackTrace(); + // Handle any exceptions that may occur while opening the payment dialog + } + } + }); + } + + public void onPaymentSuccess(String s) { + Toast.makeText(this,"Payment Successful",Toast.LENGTH_SHORT).show(); + } + + @Override + public void onPaymentError(int code, String response) { + // Handle payment error + // This method is called when there is a payment error + + // Log the error code and response for debugging + Log.e("Razorpay Error", "Error Code: " + code); + Log.e("Razorpay Error", "Error Response: " + response); + + // You can display an error message to the user or take appropriate action based on the error code and response + // For example, you can show a Toast message with the error details: + Toast.makeText(this, "Payment Error: " + response, Toast.LENGTH_SHORT).show(); + + // You can also perform additional error handling based on the error code if needed + switch (code) { + case Checkout.NETWORK_ERROR: + // Handle network-related errors + break; + case Checkout.INVALID_OPTIONS: + // Handle invalid payment options + break; + case Checkout.PAYMENT_CANCELED: + // Handle payment cancellation by the user + break; + // Add more cases for specific error codes as needed + } + } +} diff --git a/app/src/main/res/drawable/icon_razorpay.png b/app/src/main/res/drawable/icon_razorpay.png new file mode 100644 index 0000000..465275c Binary files /dev/null and b/app/src/main/res/drawable/icon_razorpay.png differ diff --git a/app/src/main/res/drawable/icon_wallet.png b/app/src/main/res/drawable/icon_wallet.png new file mode 100644 index 0000000..010a136 Binary files /dev/null and b/app/src/main/res/drawable/icon_wallet.png differ diff --git a/app/src/main/res/drawable/icon_wallet2.png b/app/src/main/res/drawable/icon_wallet2.png new file mode 100644 index 0000000..dfd002e Binary files /dev/null and b/app/src/main/res/drawable/icon_wallet2.png differ diff --git a/app/src/main/res/drawable/icon_wallet3.png b/app/src/main/res/drawable/icon_wallet3.png new file mode 100644 index 0000000..fffc6cd Binary files /dev/null and b/app/src/main/res/drawable/icon_wallet3.png differ diff --git a/app/src/main/res/drawable/icon_wallet4.png b/app/src/main/res/drawable/icon_wallet4.png new file mode 100644 index 0000000..b1f8bb4 Binary files /dev/null and b/app/src/main/res/drawable/icon_wallet4.png differ diff --git a/app/src/main/res/drawable/summary_box.xml b/app/src/main/res/drawable/summary_box.xml new file mode 100644 index 0000000..8de0b56 --- /dev/null +++ b/app/src/main/res/drawable/summary_box.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/summary_box_rounded_corner.xml b/app/src/main/res/drawable/summary_box_rounded_corner.xml new file mode 100644 index 0000000..7c40b35 --- /dev/null +++ b/app/src/main/res/drawable/summary_box_rounded_corner.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_maincart.xml b/app/src/main/res/layout/activity_maincart.xml index 2f179cd..87eaaed 100644 --- a/app/src/main/res/layout/activity_maincart.xml +++ b/app/src/main/res/layout/activity_maincart.xml @@ -95,7 +95,7 @@ android:layout_width="match_parent" android:id="@+id/checkoutButton" android:layout_width="match_parent" android:layout_height="60dp" - android:text="Proceed to Payment" + android:text="Checkout" android:textSize="18dp" android:layout_gravity="bottom" android:background="@drawable/sharp_button_corners"/> diff --git a/app/src/main/res/layout/activity_order_history.xml b/app/src/main/res/layout/activity_order_history.xml new file mode 100644 index 0000000..8967322 --- /dev/null +++ b/app/src/main/res/layout/activity_order_history.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_order_summary.xml b/app/src/main/res/layout/activity_order_summary.xml new file mode 100644 index 0000000..47a8b31 --- /dev/null +++ b/app/src/main/res/layout/activity_order_summary.xml @@ -0,0 +1,298 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + android:id="@+id/radioGroup"> + + + + + + + + + diff --git a/app/src/main/res/layout/activity_test_razor_pay.xml b/app/src/main/res/layout/activity_test_razor_pay.xml new file mode 100644 index 0000000..0a34b7c --- /dev/null +++ b/app/src/main/res/layout/activity_test_razor_pay.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 17c5be4..fd66b72 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -14,5 +14,6 @@ #4CAF50 #2196F3 #AAB4B9 + #774E94C4 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 9a70c89..0397b21 100644 --- a/build.gradle +++ b/build.gradle @@ -5,12 +5,11 @@ buildscript { } dependencies { classpath 'com.google.gms:google-services:4.3.15' + } }// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.0.0' apply false - id 'com.android.library' version '8.0.0' apply false - - + id 'com.android.application' version '8.1.0' apply false + id 'com.android.library' version '8.1.0' apply false }