#irfanz4951
1 messages · Page 1 of 1 (latest)
Can you share more code
Why are you updating the amount? Need more code and more context here
I'm trying to change the payment amount on the pay button on the payment sheet. The button still says, "Pay $10.99", default value.
This is in test mode
This is the code for the update method in Kotlin:
fun updatePaymentAmount(id: String, updatedSubTotal: Double) {
dispatchers?.let {
viewModelScope.launch(it.io) {
_checkoutLoad.value = CheckoutLoadingEvent.Loading
when (val checkoutResponse = checkoutRepo.updatePaymentIntent(id)) {
is Resource.Error -> checkoutResponse.errorMsg?.let {
CheckoutLoadingEvent.Failure(
it
)
}
is Resource.Success -> {
checkoutResponse.data?.amount = (updatedSubTotal * 100).toInt()
_checkoutLoad.value = CheckoutLoadingEvent.Success("${ checkoutResponse.data?.amount}")
Log.d("CheckOutViewModel", checkoutResponse.data?.amount.toString())
}
}
}
}
}
checkoutResponse.data?.amount represent the 'amount' key in the payment intent
Hey there, what flow are you following for this?
It looks like you're trying to change the value of the checkoutResponse object, which i don't think would work or do anything, what are you trying to do here?
What should happen in this code, is that I pass into this function as parameters, id and an updated value. The updated value would be assigned to checkoutResponse.data?.amount.
and I thought it would be saved in the server with the new value.
Why would it do that, it looks like the local response value
Are you seeing this suggested somewhere in our docs/guides?
This is what my data class looks like:
package com.tritongames.shoppingwishlist.data.models.checkout
data class StripePaymentIntent(
var amount: Int,
val amount_capturable: Int,
val amount_details: AmountDetails,
val amount_received: Int,
val application: Any,
val application_fee_amount: Any,
val automatic_payment_methods: Any,
val canceled_at: Any,
val cancellation_reason: Any,
val capture_method: String,
val client_secret: String,
val confirmation_method: String,
val created: Int,
val currency: String,
val customer: Any,
val description: String,
val id: String,
val invoice: Any,
val last_payment_error: Any,
val latest_charge: Any,
val livemode: Boolean,
val metadata: Metadata,
val next_action: Any,
val object: String,
val on_behalf_of: Any,
val payment_method: Any,
val payment_method_configuration_details: Any,
val payment_method_options: PaymentMethodOptions,
val payment_method_types: List<String>,
val processing: Any,
val receipt_email: Any,
val redaction: Any,
val review: Any,
val setup_future_usage: Any,
val shipping: Any,
val statement_descriptor: Any,
val statement_descriptor_suffix: Any,
val status: String,
val transfer_data: Any,
val transfer_group: Any
)
So I'm trying to assign value to this amount
My interface looks like this:
interface StripeInterface {
@GET("/v1/payment_intents/{:id}")
suspend fun getPaymentIntent(id : String) : Response<StripePaymentIntent>
@GET("/v1/payment_intents/")
suspend fun getAllPaymentIntents() : Response<List<StripePaymentIntent>>
@POST("/v1/payment_intents/{:id}")
suspend fun updatePaymentIntent(id : String) : Response<StripePaymentIntent>
@POST("/v1/payment_intents/{:id}/confirm")
suspend fun confirmPaymentIntent(id : String) : Response<StripePaymentIntent>
@POST("/v1/payment_intents/{:id}/cancel")
suspend fun cancelPaymentIntent(id : String) : Response<StripePaymentIntent>
My Default respository looks like this:
override suspend fun updatePaymentIntent(id: String): Resource<StripePaymentIntent> {
return try {
val response = apiCheckout.updatePaymentIntent(id)
val result = response.body()
if (response.isSuccessful && result != null) {
Resource.Success(result)
}
else {
Resource.Error ("Unknown Error")
}
}catch (e: Exception) {
Resource.Error(e.message ?: "Unknown Error")
}
}
My viewmodel code for the update is the first code that I've posted
Right, but it looks as though you're trying to update the response value, no? Or I could be reading that wrong
I'm actually accessing the data class with the 'checkoutResponse.data' part. I know this because when I hover my mouse over the checkoutResponse, it shows Resource<StripePaymentIntent>. Then when I hover over the data part, it shows 'data: T', which is the StripePaymentIntent. Now I hover over the amount part, I get 'amount: Int'
Is checkoutRepo.updatePaymentIntent your own method? I don't see anything in our SDK for that. WHat does it do?