Skip to content

Commit

Permalink
Add all new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe committed Nov 4, 2024
1 parent 58d67e0 commit 07f5c36
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ internal class DefaultLinkAccountManager @Inject constructor(
}

override suspend fun updatePaymentDetails(updateParams: ConsumerPaymentDetailsUpdateParams): Result<ConsumerPaymentDetails> {
linkRepository.consumerSignUp()
TODO("Not yet implemented")
val clientSecret = linkAccount.value?.clientSecret ?: return Result.failure(Throwable("no link account found"))
return linkRepository.updatePaymentDetails(
updateParams = updateParams,
consumerSessionClientSecret = clientSecret,
consumerPublishableKey = consumerPublishableKey
)
}

override suspend fun deletePaymentDetails(paymentDetailsId: String): Result<Unit> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,37 @@ internal class LinkApiRepository @Inject constructor(
consumerSessionClientSecret: String,
consumerPublishableKey: String?
): Result<Unit> {
return stripeRepository.deletePaymentDetails(
clientSecret = consumerSessionClientSecret,
paymentDetailsId = paymentDetailsId,
requestOptions = consumerPublishableKey?.let {
ApiRequest.Options(it)
} ?: ApiRequest.Options(
publishableKeyProvider(),
stripeAccountIdProvider()
return runCatching {
stripeRepository.deletePaymentDetails(
clientSecret = consumerSessionClientSecret,
paymentDetailsId = paymentDetailsId,
requestOptions = consumerPublishableKey?.let {
ApiRequest.Options(it)
} ?: ApiRequest.Options(
publishableKeyProvider(),
stripeAccountIdProvider()
)
)
).runCatching { }
}
}

override suspend fun updatePaymentDetails(
updateParams: ConsumerPaymentDetailsUpdateParams,
consumerSessionClientSecret: String,
consumerPublishableKey: String?
): Result<ConsumerPaymentDetails> {
TODO("Not yet implemented")
return requireNotNull(
stripeRepository.updatePaymentDetails(
consumerSessionClientSecret,
updateParams,
consumerPublishableKey?.let {
ApiRequest.Options(it)
} ?: ApiRequest.Options(
publishableKeyProvider(),
stripeAccountIdProvider()
)
)
)
}

private fun buildRequestOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import com.stripe.android.model.ConfirmSetupIntentParams
import com.stripe.android.model.ConfirmStripeIntentParams
import com.stripe.android.model.ConfirmStripeIntentParams.Companion.PARAM_CLIENT_SECRET
import com.stripe.android.model.ConsumerPaymentDetails
import com.stripe.android.model.ConsumerPaymentDetailsUpdateParams
import com.stripe.android.model.ConsumerSession
import com.stripe.android.model.CreateFinancialConnectionsSessionForDeferredPaymentParams
import com.stripe.android.model.CreateFinancialConnectionsSessionParams
Expand Down Expand Up @@ -1462,8 +1463,8 @@ class StripeApiRepository @JvmOverloads internal constructor(
clientSecret: String,
paymentDetailsId: String,
requestOptions: ApiRequest.Options
) {
makeApiRequest(
): Result<Unit> {
return makeApiRequest(
apiRequestFactory.createDelete(
getConsumerPaymentDetailsUrl(paymentDetailsId),
requestOptions,
Expand All @@ -1473,8 +1474,35 @@ class StripeApiRepository @JvmOverloads internal constructor(
"consumer_session_client_secret" to clientSecret
)
)
)
) {}
),
onResponse = {}
).runCatching {
// no-op
}
}

override suspend fun updatePaymentDetails(
clientSecret: String,
paymentDetailsUpdateParams: ConsumerPaymentDetailsUpdateParams,
requestOptions: ApiRequest.Options
): Result<ConsumerPaymentDetails> {
return fetchStripeModelResult(
apiRequestFactory.createPost(
getConsumerPaymentDetailsUrl(paymentDetailsUpdateParams.id),
requestOptions,
mapOf(
"request_surface" to "android_payment_element",
"credentials" to mapOf(
"consumer_session_client_secret" to clientSecret
)
).plus(
paymentDetailsUpdateParams.toParamMap()
)
),
ConsumerPaymentDetailsJsonParser
) {
// no-op
}
}

private suspend fun retrieveElementsSession(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.stripe.android.model.CardMetadata
import com.stripe.android.model.ConfirmPaymentIntentParams
import com.stripe.android.model.ConfirmSetupIntentParams
import com.stripe.android.model.ConsumerPaymentDetails
import com.stripe.android.model.ConsumerPaymentDetailsUpdateParams
import com.stripe.android.model.ConsumerSession
import com.stripe.android.model.CreateFinancialConnectionsSessionForDeferredPaymentParams
import com.stripe.android.model.CreateFinancialConnectionsSessionParams
Expand Down Expand Up @@ -395,7 +396,14 @@ interface StripeRepository {
clientSecret: String,
paymentDetailsId: String,
requestOptions: ApiRequest.Options
)
): Result<Unit>

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
suspend fun updatePaymentDetails(
clientSecret: String,
paymentDetailsUpdateParams: ConsumerPaymentDetailsUpdateParams,
requestOptions: ApiRequest.Options
): Result<ConsumerPaymentDetails>

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
fun buildPaymentUserAgent(attribution: Set<String> = emptySet()): String
Expand Down
1 change: 0 additions & 1 deletion payments-model/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ android {

dependencies {
implementation project(":stripe-core")
implementation project(":payments-core")
implementation libs.androidx.appCompat
implementation libs.androidx.coreKtx
implementation libs.kotlin.serialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ package com.stripe.android.model
import android.os.Parcelable
import androidx.annotation.RestrictTo
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.RawValue

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Parcelize
class ConsumerPaymentDetailsUpdateParams(
val id: String,
val isDefault: Boolean? = null,
val cardPaymentMethodCreateParams: PaymentMethodCreateParams? = null
val cardPaymentMethodCreateParamsMap: Map<String, @RawValue Any>? = null
) : StripeParamsModel, Parcelable {

override fun toParamMap(): Map<String, Any> {
val params: MutableMap<String, Any> = mutableMapOf()

isDefault?.let { params["is_default"] = it }

cardPaymentMethodCreateParams?.toParamMap()?.let { map ->
cardPaymentMethodCreateParamsMap?.let { map ->
(map["card"] as? Map<*, *>)?.let { card ->
card["exp_month"]?.let { params["exp_month"] = it }
card["exp_year"]?.let { params["exp_year"] = it }
Expand Down

0 comments on commit 07f5c36

Please sign in to comment.