mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-10 09:22:21 +00:00
payment and shipment confirmation
This commit is contained in:
@ -0,0 +1,11 @@
|
||||
package com.alya.ecommerce_serang.data.api.dto
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class ConfirmPaymentRequest(
|
||||
@SerializedName("order_id")
|
||||
val orderId: Int,
|
||||
|
||||
@SerializedName("status")
|
||||
val status: String
|
||||
)
|
@ -0,0 +1,11 @@
|
||||
package com.alya.ecommerce_serang.data.api.dto
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class ConfirmShipmentRequest(
|
||||
@SerializedName("receipt_num")
|
||||
val receiptNum: String,
|
||||
|
||||
@SerializedName("order_id")
|
||||
val orderId: Int
|
||||
)
|
@ -7,6 +7,8 @@ import com.alya.ecommerce_serang.data.api.dto.CancelOrderReq
|
||||
import com.alya.ecommerce_serang.data.api.dto.CartItem
|
||||
import com.alya.ecommerce_serang.data.api.dto.CityResponse
|
||||
import com.alya.ecommerce_serang.data.api.dto.CompletedOrderRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.ConfirmPaymentRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.ConfirmShipmentRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.CourierCostRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.CreateAddressRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.FcmReq
|
||||
@ -337,22 +339,14 @@ interface ApiService {
|
||||
@Body confirmOrder : CompletedOrderRequest
|
||||
): Response<CompletedOrderResponse>
|
||||
|
||||
@PUT("store/order/update")
|
||||
suspend fun updateOrder(
|
||||
@Part("order_id") orderId: Int?,
|
||||
@Part("status") status: String
|
||||
): Response<com.alya.ecommerce_serang.data.api.response.store.sells.UpdateOrderItemResponse>
|
||||
|
||||
@PUT("store/payment/update")
|
||||
suspend fun confirmPayment(
|
||||
@Part("order_id") orderId: Int?,
|
||||
@Part("status") status: String
|
||||
@Body confirmPayment : ConfirmPaymentRequest
|
||||
): Response<GenericResponse>
|
||||
|
||||
@PUT("store/shipping/receiptnum")
|
||||
suspend fun confirmShipment(
|
||||
@Part("receipt_num") receiptNum: String,
|
||||
@Part("order_id") orderId: Int?
|
||||
@Body confirmShipment: ConfirmShipmentRequest
|
||||
): Response<GenericResponse>
|
||||
|
||||
@Multipart
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.alya.ecommerce_serang.data.repository
|
||||
|
||||
import android.util.Log
|
||||
import com.alya.ecommerce_serang.data.api.dto.ConfirmPaymentRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.ConfirmShipmentRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.PaymentConfirmRequest
|
||||
import com.alya.ecommerce_serang.data.api.response.store.GenericResponse
|
||||
import com.alya.ecommerce_serang.data.api.response.store.sells.OrderDetailResponse
|
||||
@ -45,22 +47,20 @@ class SellsRepository(private val apiService: ApiService) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun confirmPayment(orderId: Int, status: String): Response<GenericResponse> {
|
||||
suspend fun confirmPayment(request: ConfirmPaymentRequest): Response<GenericResponse> {
|
||||
return try {
|
||||
Log.d("SellsRepository", "Calling confirmPayment with orderId=$orderId, status=$status")
|
||||
apiService.confirmPayment(orderId, status)
|
||||
Log.d("SellsRepository", "Calling confirmPayment with orderId=${request.orderId}, status=${request.status}")
|
||||
apiService.confirmPayment(request)
|
||||
} catch (e: Exception) {
|
||||
Log.e("SellsRepository", "Error during confirmPayment", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun confirmShipment(orderId: Int, receiptNum: String): Response<GenericResponse> {
|
||||
suspend fun confirmShipment(request: ConfirmShipmentRequest): Response<GenericResponse> {
|
||||
return try {
|
||||
apiService.confirmShipment(
|
||||
receiptNum = receiptNum,
|
||||
orderId = orderId
|
||||
)
|
||||
Log.d("SellsRepository", "Calling confirmShipment with orderId=${request.orderId}, receipt num=${request.receiptNum}")
|
||||
apiService.confirmShipment(request)
|
||||
} catch (e: Exception) {
|
||||
throw e
|
||||
}
|
||||
|
@ -71,11 +71,11 @@ class ProfileFragment : Fragment() {
|
||||
Log.d("Profile Fragment", "Check store $hasStore")
|
||||
|
||||
if (hasStore == true){
|
||||
binding.tvBukaToko.text = "Buka Toko Saya"
|
||||
binding.tvBukaToko.text = "Lihat Toko Saya"
|
||||
val intentBuka = Intent(requireContext(), MyStoreActivity::class.java)
|
||||
startActivity(intentBuka)
|
||||
} else {
|
||||
binding.tvBukaToko.text = "Daftar Toko Saya"
|
||||
binding.tvBukaToko.text = "Buka Toko"
|
||||
val intentBuka = Intent(requireContext(), RegisterStoreActivity::class.java)
|
||||
startActivity(intentBuka)
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
package com.alya.ecommerce_serang.ui.profile.mystore.product
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.alya.ecommerce_serang.R
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private const val ARG_PARAM1 = "param1"
|
||||
private const val ARG_PARAM2 = "param2"
|
||||
|
||||
/**
|
||||
* A simple [Fragment] subclass.
|
||||
* Use the [ChangePriceBottomSheetFragment.newInstance] factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
class ChangePriceBottomSheetFragment : Fragment() {
|
||||
// TODO: Rename and change types of parameters
|
||||
private var param1: String? = null
|
||||
private var param2: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
param1 = it.getString(ARG_PARAM1)
|
||||
param2 = it.getString(ARG_PARAM2)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_change_price_bottom_sheet, container, false)
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment ChangePriceBottomSheetFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
@JvmStatic
|
||||
fun newInstance(param1: String, param2: String) =
|
||||
ChangePriceBottomSheetFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(ARG_PARAM1, param1)
|
||||
putString(ARG_PARAM2, param2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -40,7 +40,6 @@ class ProductActivity : AppCompatActivity() {
|
||||
|
||||
binding.progressBar.visibility = View.VISIBLE
|
||||
viewModel.loadMyStoreProducts()
|
||||
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@ -58,7 +57,7 @@ class ProductActivity : AppCompatActivity() {
|
||||
binding.progressBar.visibility = View.GONE
|
||||
val products = result.data
|
||||
binding.rvStoreProduct.adapter = ProductAdapter(products) {
|
||||
Toast.makeText(this, "Clicked: ${it.name}", Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this, "Produk: ${it.name}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
is Result.Error -> {
|
||||
|
@ -45,9 +45,9 @@ class ProductAdapter(
|
||||
}
|
||||
|
||||
val imageUrl = if (product.image.startsWith("/")) {
|
||||
BASE_URL + product.image.removePrefix("/") // Append base URL if the path starts with "/"
|
||||
BASE_URL + product.image.removePrefix("/")
|
||||
} else {
|
||||
product.image // Use as is if it's already a full URL
|
||||
product.image
|
||||
}
|
||||
Glide.with(itemView.context)
|
||||
.load(imageUrl)
|
||||
|
@ -5,6 +5,7 @@ import android.app.AlertDialog
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -177,7 +178,7 @@ class DetailStoreProfileActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
viewModel.errorMessage.observe(this) {
|
||||
Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
|
||||
Log.e("DetailStoreProfileActivity", "Error: $it")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,8 @@ import java.util.Calendar
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.alya.ecommerce_serang.ui.profile.mystore.sells.DetailSellsActivity
|
||||
|
||||
class DetailPaymentActivity : AppCompatActivity() {
|
||||
|
||||
@ -67,6 +69,12 @@ class DetailPaymentActivity : AppCompatActivity() {
|
||||
finish()
|
||||
}
|
||||
|
||||
productAdapter = SellsProductAdapter()
|
||||
binding.rvProductItems.apply {
|
||||
adapter = productAdapter
|
||||
layoutManager = LinearLayoutManager(this@DetailPaymentActivity)
|
||||
}
|
||||
|
||||
val sellsJson = intent.getStringExtra("sells_data")
|
||||
if (sellsJson != null) {
|
||||
try {
|
||||
|
@ -5,15 +5,15 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.alya.ecommerce_serang.data.api.dto.ConfirmPaymentRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.ConfirmShipmentRequest
|
||||
import com.alya.ecommerce_serang.data.api.dto.OrderItemsItem
|
||||
import com.alya.ecommerce_serang.data.api.dto.PaymentConfirmRequest
|
||||
import com.alya.ecommerce_serang.data.api.response.store.sells.Orders
|
||||
import com.alya.ecommerce_serang.data.api.response.store.sells.OrdersItem
|
||||
import com.alya.ecommerce_serang.data.api.response.store.sells.PaymentConfirmationResponse
|
||||
import com.alya.ecommerce_serang.data.repository.Result
|
||||
import com.alya.ecommerce_serang.data.repository.SellsRepository
|
||||
import com.alya.ecommerce_serang.ui.order.address.ViewState
|
||||
import com.alya.ecommerce_serang.ui.order.history.HistoryViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
||||
@ -175,7 +175,8 @@ class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
||||
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val response = repository.confirmPayment(orderId, status)
|
||||
val request = ConfirmPaymentRequest(orderId, status)
|
||||
val response = repository.confirmPayment(request)
|
||||
if (response.isSuccessful) {
|
||||
val body = response.body()
|
||||
Log.d(TAG, "confirmPayment success: ${body?.message}")
|
||||
@ -201,7 +202,8 @@ class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
||||
_isLoading.value = true
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val response = repository.confirmShipment(orderId, receiptNum)
|
||||
val request = ConfirmShipmentRequest(receiptNum, orderId)
|
||||
val response = repository.confirmShipment(request)
|
||||
if (response.isSuccessful) {
|
||||
_message.value = response.body()?.message ?: "Berhasil mengonfirmasi pengiriman"
|
||||
_isSuccess.value = true
|
||||
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.profile.mystore.product.ChangePriceBottomSheetFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
|
||||
</FrameLayout>
|
Reference in New Issue
Block a user