Skip to content

Commit

Permalink
Add expand argument to various methods on Stripe (#5938)
Browse files Browse the repository at this point in the history
* Add optional expand argument to several methods

* Update changelog

* Update API

* Update tests

* Tweak changelog message
  • Loading branch information
tillh-stripe authored Dec 12, 2022
1 parent 74a014e commit b416061
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## XX.XX.XX - 2022-XX-XX

### Payments
* [CHANGED][5938](https://github.com/stripe/stripe-android/pull/5938) Methods on `Stripe` for retrieving and confirming intents now accept an optional `expand` argument to expand fields in the response.

### PaymentSheet
* [FIXED][5910](https://github.com/stripe/stripe-android/pull/5910) PaymentSheet now fails gracefully when launched with invalid arguments.

Expand Down
24 changes: 14 additions & 10 deletions payments-core/api/payments-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -950,16 +950,20 @@ public final class com/stripe/android/Stripe {
public final fun onSetupResult (ILandroid/content/Intent;Lcom/stripe/android/ApiResultCallback;)Z
public final fun retrievePaymentIntent (Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;)V
public final fun retrievePaymentIntent (Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;)V
public static synthetic fun retrievePaymentIntent$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;ILjava/lang/Object;)V
public final fun retrievePaymentIntent (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lcom/stripe/android/ApiResultCallback;)V
public static synthetic fun retrievePaymentIntent$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lcom/stripe/android/ApiResultCallback;ILjava/lang/Object;)V
public final fun retrievePaymentIntentSynchronous (Ljava/lang/String;)Lcom/stripe/android/model/PaymentIntent;
public final fun retrievePaymentIntentSynchronous (Ljava/lang/String;Ljava/lang/String;)Lcom/stripe/android/model/PaymentIntent;
public static synthetic fun retrievePaymentIntentSynchronous$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentIntent;
public final fun retrievePaymentIntentSynchronous (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)Lcom/stripe/android/model/PaymentIntent;
public static synthetic fun retrievePaymentIntentSynchronous$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentIntent;
public final fun retrieveSetupIntent (Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;)V
public final fun retrieveSetupIntent (Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;)V
public static synthetic fun retrieveSetupIntent$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;ILjava/lang/Object;)V
public final fun retrieveSetupIntent (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lcom/stripe/android/ApiResultCallback;)V
public static synthetic fun retrieveSetupIntent$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lcom/stripe/android/ApiResultCallback;ILjava/lang/Object;)V
public final fun retrieveSetupIntentSynchronous (Ljava/lang/String;)Lcom/stripe/android/model/SetupIntent;
public final fun retrieveSetupIntentSynchronous (Ljava/lang/String;Ljava/lang/String;)Lcom/stripe/android/model/SetupIntent;
public static synthetic fun retrieveSetupIntentSynchronous$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/model/SetupIntent;
public final fun retrieveSetupIntentSynchronous (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)Lcom/stripe/android/model/SetupIntent;
public static synthetic fun retrieveSetupIntentSynchronous$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ILjava/lang/Object;)Lcom/stripe/android/model/SetupIntent;
public final fun retrieveSource (Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;)V
public final fun retrieveSource (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;)V
public static synthetic fun retrieveSource$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;ILjava/lang/Object;)V
Expand Down Expand Up @@ -1017,8 +1021,8 @@ public final class com/stripe/android/StripeKtxKt {
public static synthetic fun confirmAlipayPayment$default (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmPaymentIntentParams;Lcom/stripe/android/AlipayAuthenticator;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun confirmPaymentIntent (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmPaymentIntentParams;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun confirmPaymentIntent$default (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmPaymentIntentParams;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun confirmSetupIntent (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmSetupIntentParams;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun confirmSetupIntent$default (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmSetupIntentParams;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun confirmSetupIntent (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmSetupIntentParams;Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun confirmSetupIntent$default (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmSetupIntentParams;Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun confirmWeChatPayPayment (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmPaymentIntentParams;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun confirmWeChatPayPayment$default (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmPaymentIntentParams;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun createAccountToken (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/AccountParams;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand All @@ -1043,10 +1047,10 @@ public final class com/stripe/android/StripeKtxKt {
public static final fun getAuthenticateSourceResult (Lcom/stripe/android/Stripe;ILandroid/content/Intent;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun getPaymentIntentResult (Lcom/stripe/android/Stripe;ILandroid/content/Intent;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun getSetupIntentResult (Lcom/stripe/android/Stripe;ILandroid/content/Intent;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun retrievePaymentIntent (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun retrievePaymentIntent$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun retrieveSetupIntent (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun retrieveSetupIntent$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun retrievePaymentIntent (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun retrievePaymentIntent$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun retrieveSetupIntent (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun retrieveSetupIntent$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun retrieveSource (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun retrieveSource$default (Lcom/stripe/android/Stripe;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun verifyPaymentIntentWithMicrodeposits (Lcom/stripe/android/Stripe;Ljava/lang/String;IILkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
26 changes: 20 additions & 6 deletions payments-core/src/main/java/com/stripe/android/Stripe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,15 @@ class Stripe internal constructor(
* @param clientSecret the client_secret with which to retrieve the [PaymentIntent]
* @param stripeAccountId Optional, the Connect account to associate with this request.
* By default, will use the Connect account that was used to instantiate the `Stripe` object, if specified.
* @param expand Optional, a list of keys to expand on the returned `PaymentIntent` object.
* @param callback a [ApiResultCallback] to receive the result or error
*/
@UiThread
@JvmOverloads
fun retrievePaymentIntent(
clientSecret: String,
stripeAccountId: String? = this.stripeAccountId,
expand: List<String> = emptyList(),
callback: ApiResultCallback<PaymentIntent>
) {
executeAsync(callback) {
Expand All @@ -416,7 +418,8 @@ class Stripe internal constructor(
ApiRequest.Options(
apiKey = publishableKey,
stripeAccount = stripeAccountId
)
),
expand,
)
}
}
Expand All @@ -431,6 +434,7 @@ class Stripe internal constructor(
* @param clientSecret the client_secret with which to retrieve the [PaymentIntent]
* @param stripeAccountId Optional, the Connect account to associate with this request.
* By default, will use the Connect account that was used to instantiate the `Stripe` object, if specified.
* @param expand Optional, a list of keys to expand on the returned `PaymentIntent` object.
* @return a [PaymentIntent] or `null` if a problem occurred
*/
@Throws(
Expand All @@ -443,15 +447,17 @@ class Stripe internal constructor(
@JvmOverloads
fun retrievePaymentIntentSynchronous(
clientSecret: String,
stripeAccountId: String? = this.stripeAccountId
stripeAccountId: String? = this.stripeAccountId,
expand: List<String> = emptyList(),
): PaymentIntent? {
return runBlocking {
stripeRepository.retrievePaymentIntent(
PaymentIntent.ClientSecret(clientSecret).value,
ApiRequest.Options(
apiKey = publishableKey,
stripeAccount = stripeAccountId
)
),
expand,
)
}
}
Expand Down Expand Up @@ -517,6 +523,7 @@ class Stripe internal constructor(
* | Custom return_url | WebView | WebView | WebView |
*
* @param activity the `Activity` that is launching the payment authentication flow
* @param confirmSetupIntentParams a set of params with which to confirm the Setup Intent
* @param stripeAccountId Optional, the Connect account to associate with this request.
* By default, will use the Connect account that was used to instantiate the `Stripe` object, if specified.
*/
Expand Down Expand Up @@ -558,6 +565,7 @@ class Stripe internal constructor(
* | Custom return_url | WebView | WebView | WebView |
*
* @param fragment the `Fragment` that is launching the payment authentication flow
* @param confirmSetupIntentParams a set of params with which to confirm the Setup Intent
* @param stripeAccountId Optional, the Connect account to associate with this request.
* By default, will use the Connect account that was used to instantiate the `Stripe` object, if specified.
*/
Expand Down Expand Up @@ -683,6 +691,7 @@ class Stripe internal constructor(
* @param clientSecret the client_secret with which to retrieve the [SetupIntent]
* @param stripeAccountId Optional, the Connect account to associate with this request.
* By default, will use the Connect account that was used to instantiate the `Stripe` object, if specified.
* @param expand Optional, a list of keys to expand on the returned `SetupIntent` object.
* @param callback a [ApiResultCallback] to receive the result or error
*/
@Throws(
Expand All @@ -696,6 +705,7 @@ class Stripe internal constructor(
fun retrieveSetupIntent(
clientSecret: String,
stripeAccountId: String? = this.stripeAccountId,
expand: List<String> = emptyList(),
callback: ApiResultCallback<SetupIntent>
) {
executeAsync(callback) {
Expand All @@ -704,7 +714,8 @@ class Stripe internal constructor(
ApiRequest.Options(
apiKey = publishableKey,
stripeAccount = stripeAccountId
)
),
expand,
)
}
}
Expand All @@ -719,6 +730,7 @@ class Stripe internal constructor(
* @param clientSecret client_secret of the [SetupIntent] to retrieve
* @param stripeAccountId Optional, the Connect account to associate with this request.
* By default, will use the Connect account that was used to instantiate the `Stripe` object, if specified.
* @param expand Optional, a list of keys to expand on the returned `SetupIntent` object.
* @return a [SetupIntent] or `null` if a problem occurred
*/
@Throws(
Expand All @@ -731,15 +743,17 @@ class Stripe internal constructor(
@JvmOverloads
fun retrieveSetupIntentSynchronous(
clientSecret: String,
stripeAccountId: String? = this.stripeAccountId
stripeAccountId: String? = this.stripeAccountId,
expand: List<String> = emptyList(),
): SetupIntent? {
return runBlocking {
stripeRepository.retrieveSetupIntent(
SetupIntent.ClientSecret(clientSecret).value,
ApiRequest.Options(
apiKey = publishableKey,
stripeAccount = stripeAccountId
)
),
expand,
)
}
}
Expand Down
21 changes: 15 additions & 6 deletions payments-core/src/main/java/com/stripe/android/StripeKtx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ suspend fun Stripe.createRadarSession(): RadarSession {
* @param clientSecret the client_secret with which to retrieve the [PaymentIntent]
* @param stripeAccountId Optional, the Connect account to associate with this request.
* By default, will use the Connect account that was used to instantiate the `Stripe` object, if specified.
* @param expand Optional, a list of keys to expand on the returned `PaymentIntent` object.
*
* @return a [PaymentIntent] object
*
Expand All @@ -477,14 +478,16 @@ suspend fun Stripe.createRadarSession(): RadarSession {
)
suspend fun Stripe.retrievePaymentIntent(
clientSecret: String,
stripeAccountId: String? = this.stripeAccountId
stripeAccountId: String? = this.stripeAccountId,
expand: List<String> = emptyList(),
): PaymentIntent = runApiRequest {
stripeRepository.retrievePaymentIntent(
clientSecret,
ApiRequest.Options(
apiKey = publishableKey,
stripeAccount = stripeAccountId
)
),
expand,
)
}

Expand All @@ -497,6 +500,7 @@ suspend fun Stripe.retrievePaymentIntent(
* @param clientSecret the client_secret with which to retrieve the [SetupIntent]
* @param stripeAccountId Optional, the Connect account to associate with this request.
* By default, will use the Connect account that was used to instantiate the `Stripe` object, if specified.
* @param expand Optional, a list of keys to expand on the returned `SetupIntent` object.
*
* @return a [SetupIntent] object
*
Expand All @@ -513,14 +517,16 @@ suspend fun Stripe.retrievePaymentIntent(
)
suspend fun Stripe.retrieveSetupIntent(
clientSecret: String,
stripeAccountId: String? = this.stripeAccountId
stripeAccountId: String? = this.stripeAccountId,
expand: List<String> = emptyList(),
): SetupIntent = runApiRequest {
stripeRepository.retrieveSetupIntent(
clientSecret,
ApiRequest.Options(
apiKey = publishableKey,
stripeAccount = stripeAccountId
)
),
expand,
)
}

Expand Down Expand Up @@ -571,6 +577,7 @@ suspend fun Stripe.retrieveSource(
*
* @param confirmSetupIntentParams a set of params with which to confirm the Setup Intent
* @param idempotencyKey optional, see [Idempotent Requests](https://stripe.com/docs/api/idempotent_requests)
* @param expand Optional, a list of keys to expand on the returned `SetupIntent` object.
*
* @return a [SetupIntent] object
*
Expand All @@ -587,15 +594,17 @@ suspend fun Stripe.retrieveSource(
)
suspend fun Stripe.confirmSetupIntent(
confirmSetupIntentParams: ConfirmSetupIntentParams,
idempotencyKey: String? = null
idempotencyKey: String? = null,
expand: List<String> = emptyList(),
): SetupIntent = runApiRequest {
stripeRepository.confirmSetupIntent(
confirmSetupIntentParams,
ApiRequest.Options(
apiKey = publishableKey,
stripeAccount = stripeAccountId,
idempotencyKey = idempotencyKey
)
),
expand,
)
}

Expand Down
Loading

0 comments on commit b416061

Please sign in to comment.