-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Final Commit for basic working of E-Commerce
- Loading branch information
Showing
25 changed files
with
317 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
package devs.redfox.local_e_commerce.activity | ||
|
||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.lifecycle.lifecycleScope | ||
import com.google.firebase.firestore.ktx.firestore | ||
import com.google.firebase.ktx.Firebase | ||
import com.razorpay.Checkout | ||
import com.razorpay.PaymentResultListener | ||
import devs.redfox.local_e_commerce.MainActivity | ||
import devs.redfox.local_e_commerce.R | ||
import devs.redfox.local_e_commerce.database.AppDatabase | ||
import devs.redfox.local_e_commerce.database.ProductModel | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import org.json.JSONObject | ||
|
||
|
||
|
@@ -18,13 +27,15 @@ class CheckoutActivity : AppCompatActivity(), PaymentResultListener { | |
val checkout = Checkout() | ||
checkout.setKeyID("rzp_test_CsJK0mxcTnqyKp") | ||
|
||
val price = intent.getStringExtra("totalCost") | ||
|
||
try { | ||
val options = JSONObject() | ||
options.put("name", "PassKiDukaan") | ||
options.put("image", "https://s3.amazonaws.com/rzp-mobile/images/rzp.png") | ||
options.put("theme.color", "#3399cc") | ||
options.put("currency", "INR") | ||
options.put("amount", "50000") //pass amount in currency subunits | ||
options.put("amount", (price!!.toInt()*100)) //pass amount in currency subunits | ||
options.put("prefill.email", "[email protected]") | ||
options.put("prefill.contact", "7098910064") | ||
checkout.open(this, options) | ||
|
@@ -35,6 +46,52 @@ class CheckoutActivity : AppCompatActivity(), PaymentResultListener { | |
|
||
override fun onPaymentSuccess(p0: String?) { | ||
Toast.makeText(this, "Payment Success", Toast.LENGTH_SHORT).show() | ||
uploadData() | ||
} | ||
|
||
private fun uploadData() { | ||
val id = intent.getStringArrayListExtra("productIds") | ||
for(currentId in id!!){ | ||
fetchData(currentId) | ||
} | ||
} | ||
|
||
private fun fetchData(productId: String?) { | ||
|
||
val dao = AppDatabase.getInstance(this).productDao() | ||
|
||
Firebase.firestore.collection("products") | ||
.document(productId!!).get().addOnSuccessListener { | ||
|
||
lifecycleScope.launch(Dispatchers.IO) { | ||
dao.deleteProduct(ProductModel(productId)) | ||
} | ||
|
||
saveData(it.getString("productName"), it.getString("productSp"), productId) | ||
} | ||
} | ||
|
||
private fun saveData(name: String?, price: String?, productId: String) { | ||
|
||
val preferences = this.getSharedPreferences("user", MODE_PRIVATE) | ||
val data = hashMapOf<String, Any>() | ||
data["name"] = name!! | ||
data["price"] = price!! | ||
data["productId"] = productId | ||
data["status"] = "Ordered" | ||
data["userId"] = preferences.getString("number", "")!! | ||
|
||
val firestore = Firebase.firestore.collection("allOrders") | ||
val key = firestore.document().id | ||
data["orderId"] = key | ||
|
||
firestore.document(key).set(data).addOnSuccessListener { | ||
Toast.makeText(this, "Order Placed", Toast.LENGTH_SHORT).show() | ||
startActivity(Intent(this, ConfirmationActivity::class.java)) | ||
}.addOnFailureListener { | ||
Toast.makeText(this, "Something went wrong, order not placed", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
} | ||
|
||
override fun onPaymentError(p0: Int, p1: String?) { | ||
|
12 changes: 12 additions & 0 deletions
12
app/src/main/java/devs/redfox/local_e_commerce/activity/ConfirmationActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package devs.redfox.local_e_commerce.activity | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import devs.redfox.local_e_commerce.R | ||
|
||
class ConfirmationActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_confirmation) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/src/main/java/devs/redfox/local_e_commerce/adapter/AllOrderAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package devs.redfox.local_e_commerce.adapter | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View.GONE | ||
import android.view.ViewGroup | ||
import android.widget.Toast | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.google.firebase.firestore.ktx.firestore | ||
import com.google.firebase.ktx.Firebase | ||
import devs.redfox.local_e_commerce.databinding.AllOrderItemLayoutBinding | ||
import devs.redfox.local_e_commerce.model.AllOrderModel | ||
|
||
|
||
class AllOrderAdapter(val list: ArrayList<AllOrderModel>, val context: Context) : | ||
RecyclerView.Adapter<AllOrderAdapter.AllOrderViewHolder>() { | ||
|
||
inner class AllOrderViewHolder(val binding: AllOrderItemLayoutBinding) : | ||
RecyclerView.ViewHolder(binding.root) | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AllOrderViewHolder { | ||
return AllOrderViewHolder( | ||
AllOrderItemLayoutBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
) | ||
} | ||
|
||
override fun onBindViewHolder(holder: AllOrderViewHolder, position: Int) { | ||
holder.binding.productTitle.text = list[position].name | ||
holder.binding.productPrice.text = list[position].price | ||
|
||
|
||
|
||
when (list[position].status) { | ||
"Ordered" -> { | ||
holder.binding.productStatus.text = "Order Status: Ordered" | ||
|
||
} | ||
"Dispatched" -> { | ||
holder.binding.productStatus.text = "Order Status: Dispatched" | ||
|
||
} | ||
"Delivered" -> { | ||
holder.binding.productStatus.text = "Order Status: Delivered" | ||
|
||
} | ||
"Canceled" -> { | ||
holder.binding.productStatus.text = "Order Status: Cancelled" | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
override fun getItemCount(): Int { | ||
return list.size | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.