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.CartItem
|
||||||
import com.alya.ecommerce_serang.data.api.dto.CityResponse
|
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.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.CourierCostRequest
|
||||||
import com.alya.ecommerce_serang.data.api.dto.CreateAddressRequest
|
import com.alya.ecommerce_serang.data.api.dto.CreateAddressRequest
|
||||||
import com.alya.ecommerce_serang.data.api.dto.FcmReq
|
import com.alya.ecommerce_serang.data.api.dto.FcmReq
|
||||||
@ -337,22 +339,14 @@ interface ApiService {
|
|||||||
@Body confirmOrder : CompletedOrderRequest
|
@Body confirmOrder : CompletedOrderRequest
|
||||||
): Response<CompletedOrderResponse>
|
): 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")
|
@PUT("store/payment/update")
|
||||||
suspend fun confirmPayment(
|
suspend fun confirmPayment(
|
||||||
@Part("order_id") orderId: Int?,
|
@Body confirmPayment : ConfirmPaymentRequest
|
||||||
@Part("status") status: String
|
|
||||||
): Response<GenericResponse>
|
): Response<GenericResponse>
|
||||||
|
|
||||||
@PUT("store/shipping/receiptnum")
|
@PUT("store/shipping/receiptnum")
|
||||||
suspend fun confirmShipment(
|
suspend fun confirmShipment(
|
||||||
@Part("receipt_num") receiptNum: String,
|
@Body confirmShipment: ConfirmShipmentRequest
|
||||||
@Part("order_id") orderId: Int?
|
|
||||||
): Response<GenericResponse>
|
): Response<GenericResponse>
|
||||||
|
|
||||||
@Multipart
|
@Multipart
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.alya.ecommerce_serang.data.repository
|
package com.alya.ecommerce_serang.data.repository
|
||||||
|
|
||||||
import android.util.Log
|
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.dto.PaymentConfirmRequest
|
||||||
import com.alya.ecommerce_serang.data.api.response.store.GenericResponse
|
import com.alya.ecommerce_serang.data.api.response.store.GenericResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.store.sells.OrderDetailResponse
|
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 {
|
return try {
|
||||||
Log.d("SellsRepository", "Calling confirmPayment with orderId=$orderId, status=$status")
|
Log.d("SellsRepository", "Calling confirmPayment with orderId=${request.orderId}, status=${request.status}")
|
||||||
apiService.confirmPayment(orderId, status)
|
apiService.confirmPayment(request)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("SellsRepository", "Error during confirmPayment", e)
|
Log.e("SellsRepository", "Error during confirmPayment", e)
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun confirmShipment(orderId: Int, receiptNum: String): Response<GenericResponse> {
|
suspend fun confirmShipment(request: ConfirmShipmentRequest): Response<GenericResponse> {
|
||||||
return try {
|
return try {
|
||||||
apiService.confirmShipment(
|
Log.d("SellsRepository", "Calling confirmShipment with orderId=${request.orderId}, receipt num=${request.receiptNum}")
|
||||||
receiptNum = receiptNum,
|
apiService.confirmShipment(request)
|
||||||
orderId = orderId
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
@ -71,11 +71,11 @@ class ProfileFragment : Fragment() {
|
|||||||
Log.d("Profile Fragment", "Check store $hasStore")
|
Log.d("Profile Fragment", "Check store $hasStore")
|
||||||
|
|
||||||
if (hasStore == true){
|
if (hasStore == true){
|
||||||
binding.tvBukaToko.text = "Buka Toko Saya"
|
binding.tvBukaToko.text = "Lihat Toko Saya"
|
||||||
val intentBuka = Intent(requireContext(), MyStoreActivity::class.java)
|
val intentBuka = Intent(requireContext(), MyStoreActivity::class.java)
|
||||||
startActivity(intentBuka)
|
startActivity(intentBuka)
|
||||||
} else {
|
} else {
|
||||||
binding.tvBukaToko.text = "Daftar Toko Saya"
|
binding.tvBukaToko.text = "Buka Toko"
|
||||||
val intentBuka = Intent(requireContext(), RegisterStoreActivity::class.java)
|
val intentBuka = Intent(requireContext(), RegisterStoreActivity::class.java)
|
||||||
startActivity(intentBuka)
|
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
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
viewModel.loadMyStoreProducts()
|
viewModel.loadMyStoreProducts()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
@ -58,7 +57,7 @@ class ProductActivity : AppCompatActivity() {
|
|||||||
binding.progressBar.visibility = View.GONE
|
binding.progressBar.visibility = View.GONE
|
||||||
val products = result.data
|
val products = result.data
|
||||||
binding.rvStoreProduct.adapter = ProductAdapter(products) {
|
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 -> {
|
is Result.Error -> {
|
||||||
|
@ -45,9 +45,9 @@ class ProductAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val imageUrl = if (product.image.startsWith("/")) {
|
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 {
|
} else {
|
||||||
product.image // Use as is if it's already a full URL
|
product.image
|
||||||
}
|
}
|
||||||
Glide.with(itemView.context)
|
Glide.with(itemView.context)
|
||||||
.load(imageUrl)
|
.load(imageUrl)
|
||||||
|
@ -5,6 +5,7 @@ import android.app.AlertDialog
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -177,7 +178,7 @@ class DetailStoreProfileActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
viewModel.errorMessage.observe(this) {
|
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.Locale
|
||||||
import java.util.TimeZone
|
import java.util.TimeZone
|
||||||
import androidx.core.graphics.drawable.toDrawable
|
import androidx.core.graphics.drawable.toDrawable
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import com.alya.ecommerce_serang.ui.profile.mystore.sells.DetailSellsActivity
|
||||||
|
|
||||||
class DetailPaymentActivity : AppCompatActivity() {
|
class DetailPaymentActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@ -67,6 +69,12 @@ class DetailPaymentActivity : AppCompatActivity() {
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
productAdapter = SellsProductAdapter()
|
||||||
|
binding.rvProductItems.apply {
|
||||||
|
adapter = productAdapter
|
||||||
|
layoutManager = LinearLayoutManager(this@DetailPaymentActivity)
|
||||||
|
}
|
||||||
|
|
||||||
val sellsJson = intent.getStringExtra("sells_data")
|
val sellsJson = intent.getStringExtra("sells_data")
|
||||||
if (sellsJson != null) {
|
if (sellsJson != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -5,15 +5,15 @@ import androidx.lifecycle.LiveData
|
|||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
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.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.Orders
|
||||||
import com.alya.ecommerce_serang.data.api.response.store.sells.OrdersItem
|
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.api.response.store.sells.PaymentConfirmationResponse
|
||||||
import com.alya.ecommerce_serang.data.repository.Result
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
import com.alya.ecommerce_serang.data.repository.SellsRepository
|
import com.alya.ecommerce_serang.data.repository.SellsRepository
|
||||||
import com.alya.ecommerce_serang.ui.order.address.ViewState
|
import com.alya.ecommerce_serang.ui.order.address.ViewState
|
||||||
import com.alya.ecommerce_serang.ui.order.history.HistoryViewModel
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
||||||
@ -175,7 +175,8 @@ class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
|||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
val response = repository.confirmPayment(orderId, status)
|
val request = ConfirmPaymentRequest(orderId, status)
|
||||||
|
val response = repository.confirmPayment(request)
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val body = response.body()
|
val body = response.body()
|
||||||
Log.d(TAG, "confirmPayment success: ${body?.message}")
|
Log.d(TAG, "confirmPayment success: ${body?.message}")
|
||||||
@ -201,7 +202,8 @@ class SellsViewModel(private val repository: SellsRepository) : ViewModel() {
|
|||||||
_isLoading.value = true
|
_isLoading.value = true
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
val response = repository.confirmShipment(orderId, receiptNum)
|
val request = ConfirmShipmentRequest(receiptNum, orderId)
|
||||||
|
val response = repository.confirmShipment(request)
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
_message.value = response.body()?.message ?: "Berhasil mengonfirmasi pengiriman"
|
_message.value = response.body()?.message ?: "Berhasil mengonfirmasi pengiriman"
|
||||||
_isSuccess.value = true
|
_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