Skip to content

Commit

Permalink
RazorPay Integration Done.
Browse files Browse the repository at this point in the history
  • Loading branch information
debz-g committed Aug 1, 2022
1 parent fc3756f commit 89255cc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ dependencies {

//Coroutines
implementation('org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.3')
implementation 'com.razorpay:checkout:1.6.19'
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ class AddressActivity : AppCompatActivity() {
.document(preferences.getString("number","")!!)
.update(map).addOnSuccessListener {

startActivity(Intent(this,CheckoutActivity::class.java))
val intent = Intent(this, CheckoutActivity::class.java)
intent.putExtra("productIds", intent.getStringArrayExtra("productIds"))
startActivity(intent)
}
.addOnFailureListener {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_SHORT).show()
Expand All @@ -82,7 +84,7 @@ class AddressActivity : AppCompatActivity() {
Firebase.firestore.collection("users").document(preferences.getString("number","")!!)
.get().addOnSuccessListener {
binding.userName.setText(it.getString("userName"))
binding.userNumber.setText(it.getString("userNumber"))
binding.userNumber.setText(it.getString("userPhoneNumber"))
binding.userAddress.setText(it.getString("address"))
binding.userCity.setText(it.getString("city"))
binding.userState.setText(it.getString("state"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
package devs.redfox.local_e_commerce.activity

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.razorpay.Checkout
import com.razorpay.PaymentResultListener
import devs.redfox.local_e_commerce.R
import org.json.JSONObject

class CheckoutActivity : AppCompatActivity() {

class CheckoutActivity : AppCompatActivity(), PaymentResultListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_checkout)

val checkout = Checkout()
checkout.setKeyID("rzp_test_CsJK0mxcTnqyKp")

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("prefill.email", "[email protected]")
options.put("prefill.contact", "7098910064")
checkout.open(this, options)
} catch (e: Exception) {
Toast.makeText(this, "Something Went Wrong", Toast.LENGTH_SHORT).show()
}
}

override fun onPaymentSuccess(p0: String?) {
Toast.makeText(this, "Payment Success", Toast.LENGTH_SHORT).show()
}

override fun onPaymentError(p0: Int, p1: String?) {
Toast.makeText(this, "Payment Error", Toast.LENGTH_SHORT).show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
import devs.redfox.local_e_commerce.MainActivity
import devs.redfox.local_e_commerce.R
import devs.redfox.local_e_commerce.databinding.ActivityRegisterBinding
import devs.redfox.local_e_commerce.model.UserModel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CartFragment : Fragment() {
private var _binding: FragmentCartBinding? = null
private val binding
get() = _binding!!
private lateinit var list : ArrayList<String>
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -35,11 +36,17 @@ class CartFragment : Fragment() {

val dao = AppDatabase.getInstance(requireContext()).productDao()

list = ArrayList()

dao.getAllProducts().observe(requireActivity()){
binding.rvCartFragment.adapter = CartAdapter(requireContext(),
it as ArrayList<ProductModel>
)

list.clear()
for(data in it){
list.add(data.productId )
}
totalCost(it)
}

Expand All @@ -58,6 +65,7 @@ class CartFragment : Fragment() {
binding.checkout.setOnClickListener {
val intent = Intent(context, AddressActivity::class.java)
intent.putExtra("totalCost", total)
intent.putExtra("productIds", list)
startActivity(intent)
}
}
Expand Down

0 comments on commit 89255cc

Please sign in to comment.