Skip to content

Commit

Permalink
Update link account manager
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe committed Nov 4, 2024
1 parent a94d865 commit 58d67e0
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,16 @@ internal class DefaultLinkAccountManager @Inject constructor(
}

override suspend fun updatePaymentDetails(updateParams: ConsumerPaymentDetailsUpdateParams): Result<ConsumerPaymentDetails> {
linkRepository.consumerSignUp()
TODO("Not yet implemented")
}

override suspend fun deletePaymentDetails(paymentDetailsId: String): Result<Unit> {
TODO("Not yet implemented")
return linkRepository.deletePaymentDetails(
paymentDetailsId,
"clientSecret",
consumerPublishableKey
)
}

override suspend fun listPaymentDetails(): Result<ConsumerPaymentDetails> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.stripe.android.link.LinkPaymentDetails
import com.stripe.android.model.ConsumerPaymentDetails
import com.stripe.android.model.ConsumerPaymentDetailsCreateParams
import com.stripe.android.model.ConsumerPaymentDetailsCreateParams.Card.Companion.extraConfirmationParams
import com.stripe.android.model.ConsumerPaymentDetailsUpdateParams
import com.stripe.android.model.ConsumerSession
import com.stripe.android.model.ConsumerSessionLookup
import com.stripe.android.model.ConsumerSessionSignup
Expand Down Expand Up @@ -216,6 +217,31 @@ internal class LinkApiRepository @Inject constructor(
)
}

override suspend fun deletePaymentDetails(
paymentDetailsId: String,
consumerSessionClientSecret: String,
consumerPublishableKey: String?
): Result<Unit> {
return 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")
}

private fun buildRequestOptions(
consumerAccountPublishableKey: String? = null,
): ApiRequest.Options {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.stripe.android.link.repositories

import com.stripe.android.link.LinkPaymentDetails
import com.stripe.android.model.ConsumerPaymentDetails
import com.stripe.android.model.ConsumerPaymentDetailsUpdateParams
import com.stripe.android.model.ConsumerSession
import com.stripe.android.model.ConsumerSessionLookup
import com.stripe.android.model.ConsumerSessionSignup
Expand Down Expand Up @@ -80,4 +81,22 @@ internal interface LinkRepository {
consumerSessionClientSecret: String,
consumerPublishableKey: String?
): Result<ConsumerPaymentDetails>

/**
* Delete the payment method from the consumer account.
*/
suspend fun deletePaymentDetails(
paymentDetailsId: String,
consumerSessionClientSecret: String,
consumerPublishableKey: String?
): Result<Unit>

/**
* Update an existing payment method in the consumer account.
*/
suspend fun updatePaymentDetails(
updateParams: ConsumerPaymentDetailsUpdateParams,
consumerSessionClientSecret: String,
consumerPublishableKey: String?
): Result<ConsumerPaymentDetails>
}
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,25 @@ class StripeApiRepository @JvmOverloads internal constructor(
)
}

override suspend fun deletePaymentDetails(
clientSecret: String,
paymentDetailsId: String,
requestOptions: ApiRequest.Options
) {
makeApiRequest(
apiRequestFactory.createDelete(
getConsumerPaymentDetailsUrl(paymentDetailsId),
requestOptions,
mapOf(
"request_surface" to "android_payment_element",
"credentials" to mapOf(
"consumer_session_client_secret" to clientSecret
)
)
)
) {}
}

private suspend fun retrieveElementsSession(
params: ElementsSessionParams,
options: ApiRequest.Options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ interface StripeRepository {
requestOptions: ApiRequest.Options
): Result<ConsumerPaymentDetails>

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
suspend fun deletePaymentDetails(
clientSecret: String,
paymentDetailsId: String,
requestOptions: ApiRequest.Options
)

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
fun buildPaymentUserAgent(attribution: Set<String> = emptySet()): String
}

0 comments on commit 58d67e0

Please sign in to comment.