Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support wechatpay #3653

Merged
merged 5 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion stripe/api/stripe.api
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,9 @@ public final class com/stripe/android/Stripe {
public final fun confirmSetupIntentSynchronous (Lcom/stripe/android/model/ConfirmSetupIntentParams;)Lcom/stripe/android/model/SetupIntent;
public final fun confirmSetupIntentSynchronous (Lcom/stripe/android/model/ConfirmSetupIntentParams;Ljava/lang/String;)Lcom/stripe/android/model/SetupIntent;
public static synthetic fun confirmSetupIntentSynchronous$default (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmSetupIntentParams;Ljava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/model/SetupIntent;
public final fun confirmWeChatPayPayment (Lcom/stripe/android/model/ConfirmPaymentIntentParams;Lcom/stripe/android/ApiResultCallback;)V
public final fun confirmWeChatPayPayment (Lcom/stripe/android/model/ConfirmPaymentIntentParams;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;)V
public static synthetic fun confirmWeChatPayPayment$default (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/ConfirmPaymentIntentParams;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;ILjava/lang/Object;)V
public final fun createAccountToken (Lcom/stripe/android/model/AccountParams;Lcom/stripe/android/ApiResultCallback;)V
public final fun createAccountToken (Lcom/stripe/android/model/AccountParams;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;)V
public final fun createAccountToken (Lcom/stripe/android/model/AccountParams;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/ApiResultCallback;)V
Expand Down Expand Up @@ -857,7 +860,7 @@ public final class com/stripe/android/Stripe$Companion {
}

public final class com/stripe/android/StripeApiBeta : java/lang/Enum {
public static final field WechatPayV1 Lcom/stripe/android/StripeApiBeta;
public static final field WeChatPayV1 Lcom/stripe/android/StripeApiBeta;
public final fun getCode ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Lcom/stripe/android/StripeApiBeta;
public static fun values ()[Lcom/stripe/android/StripeApiBeta;
Expand Down Expand Up @@ -926,6 +929,8 @@ public final class com/stripe/android/StripeKtxKt {
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 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;
public static synthetic fun createAccountToken$default (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/AccountParams;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun createBankAccountToken (Lcom/stripe/android/Stripe;Lcom/stripe/android/model/BankAccountTokenParams;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down Expand Up @@ -3011,6 +3016,7 @@ public final class com/stripe/android/model/PaymentMethod$Type : java/lang/Enum,
public static final field SepaDebit Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Sofort Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Upi Lcom/stripe/android/model/PaymentMethod$Type;
public static final field WeChatPay Lcom/stripe/android/model/PaymentMethod$Type;
public final field code Ljava/lang/String;
public final field isReusable Z
public fun describeContents ()I
Expand Down Expand Up @@ -3115,6 +3121,9 @@ public final class com/stripe/android/model/PaymentMethodCreateParams : android/
public static final fun createP24 (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createPayPal ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createPayPal (Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createWeChatPay ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createWeChatPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createWeChatPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getTypeCode ()Ljava/lang/String;
Expand Down Expand Up @@ -3284,6 +3293,10 @@ public final class com/stripe/android/model/PaymentMethodCreateParams$Companion
public final fun createPayPal ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createPayPal (Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createPayPal$default (Lcom/stripe/android/model/PaymentMethodCreateParams$Companion;Ljava/util/Map;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createWeChatPay ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createWeChatPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createWeChatPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createWeChatPay$default (Lcom/stripe/android/model/PaymentMethodCreateParams$Companion;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
}

public class com/stripe/android/model/PaymentMethodCreateParams$Creator : android/os/Parcelable$Creator {
Expand Down Expand Up @@ -3509,6 +3522,32 @@ public class com/stripe/android/model/PaymentMethodOptionsParams$Card$Creator :
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/model/PaymentMethodOptionsParams$WeChatPay : com/stripe/android/model/PaymentMethodOptionsParams {
public static final field CREATOR Landroid/os/Parcelable$Creator;
public static final field Companion Lcom/stripe/android/model/PaymentMethodOptionsParams$WeChatPay$Companion;
public static final field PARAM_APP_ID Ljava/lang/String;
public static final field PARAM_CLIENT Ljava/lang/String;
public fun <init> (Ljava/lang/String;)V
public final fun component1 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;)Lcom/stripe/android/model/PaymentMethodOptionsParams$WeChatPay;
public static synthetic fun copy$default (Lcom/stripe/android/model/PaymentMethodOptionsParams$WeChatPay;Ljava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodOptionsParams$WeChatPay;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getAppId ()Ljava/lang/String;
public fun hashCode ()I
public final fun setAppId (Ljava/lang/String;)V
public fun toString ()Ljava/lang/String;
public fun writeToParcel (Landroid/os/Parcel;I)V
}

public class com/stripe/android/model/PaymentMethodOptionsParams$WeChatPay$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/model/PaymentMethodOptionsParams$WeChatPay;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/model/PaymentMethodOptionsParams$WeChatPay;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/model/PersonTokenParams : com/stripe/android/model/TokenParams {
public static final field CREATOR Landroid/os/Parcelable$Creator;
public fun <init> ()V
Expand Down Expand Up @@ -4860,6 +4899,7 @@ public final class com/stripe/android/model/StripeIntent$NextActionType : java/l
public static final field DisplayOxxoDetails Lcom/stripe/android/model/StripeIntent$NextActionType;
public static final field RedirectToUrl Lcom/stripe/android/model/StripeIntent$NextActionType;
public static final field UseStripeSdk Lcom/stripe/android/model/StripeIntent$NextActionType;
public static final field WeChatPayRedirect Lcom/stripe/android/model/StripeIntent$NextActionType;
public final fun getCode ()Ljava/lang/String;
public fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Lcom/stripe/android/model/StripeIntent$NextActionType;
Expand Down Expand Up @@ -5010,6 +5050,29 @@ public class com/stripe/android/model/WeChat$Creator : android/os/Parcelable$Cre
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/model/WeChatPayNextAction : com/stripe/android/model/StripeModel {
public static final field CREATOR Landroid/os/Parcelable$Creator;
public final fun component1 ()Lcom/stripe/android/model/PaymentIntent;
public final fun component2 ()Lcom/stripe/android/model/WeChat;
public final fun copy (Lcom/stripe/android/model/PaymentIntent;Lcom/stripe/android/model/WeChat;)Lcom/stripe/android/model/WeChatPayNextAction;
public static synthetic fun copy$default (Lcom/stripe/android/model/WeChatPayNextAction;Lcom/stripe/android/model/PaymentIntent;Lcom/stripe/android/model/WeChat;ILjava/lang/Object;)Lcom/stripe/android/model/WeChatPayNextAction;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getPaymentIntent ()Lcom/stripe/android/model/PaymentIntent;
public final fun getWeChat ()Lcom/stripe/android/model/WeChat;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public fun writeToParcel (Landroid/os/Parcel;I)V
}

public class com/stripe/android/model/WeChatPayNextAction$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/model/WeChatPayNextAction;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/model/WeChatPayNextAction;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public abstract class com/stripe/android/model/wallets/Wallet : com/stripe/android/model/StripeModel {
public synthetic fun <init> (Lcom/stripe/android/model/wallets/Wallet$Type;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
}
Expand Down
27 changes: 27 additions & 0 deletions stripe/src/main/java/com/stripe/android/PaymentController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.stripe.android.model.ConfirmStripeIntentParams
import com.stripe.android.model.PaymentIntent
import com.stripe.android.model.Source
import com.stripe.android.model.StripeIntent
import com.stripe.android.model.WeChat
import com.stripe.android.model.WeChatPayNextAction
import com.stripe.android.networking.ApiRequest
import com.stripe.android.view.AuthActivityStarter

Expand Down Expand Up @@ -52,6 +54,31 @@ internal interface PaymentController {
requestOptions: ApiRequest.Options
): PaymentIntentResult

/**
* Confirm the Stripe Intent for WeChat Pay, return WeChat Pay params from intent's next action
*
* @param confirmPaymentIntentParams params to confirm the intent
* @param requestOptions options for [ApiRequest]
* @return the [WeChatPayNextAction] object encapsulating [PaymentIntent] and [WeChat]
*
* @throws AuthenticationException failure to properly authenticate yourself (check your key)
* @throws InvalidRequestException your request has invalid parameters
* @throws APIConnectionException failure to connect to Stripe's API
* @throws APIException any other type of problem (for instance, a temporary issue with Stripe's servers)
* @throws IllegalArgumentException if the payment intent's next action data is not for WeChat Pay
*/
@Throws(
AuthenticationException::class,
InvalidRequestException::class,
APIConnectionException::class,
APIException::class,
IllegalArgumentException::class
)
suspend fun confirmWeChatPay(
confirmPaymentIntentParams: ConfirmPaymentIntentParams,
requestOptions: ApiRequest.Options
): WeChatPayNextAction

suspend fun startAuth(
host: AuthActivityStarter.Host,
clientSecret: String,
Expand Down
37 changes: 37 additions & 0 deletions stripe/src/main/java/com/stripe/android/Stripe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.stripe.android.model.StripeFileParams
import com.stripe.android.model.StripeModel
import com.stripe.android.model.Token
import com.stripe.android.model.TokenParams
import com.stripe.android.model.WeChatPayNextAction
import com.stripe.android.networking.ApiRequest
import com.stripe.android.networking.StripeApiRepository
import com.stripe.android.networking.StripeRepository
Expand Down Expand Up @@ -197,6 +198,42 @@ class Stripe internal constructor(
}
}

/**
* Confirm a [PaymentIntent] for WeChat Pay. Extract params from [WeChatPayNextAction] to pass to WeChat Pay SDK.
* @see <a href="https://pay.weixin.qq.com/index.php/public/wechatpay">WeChat Pay Documentation</a>
*
* WeChat Pay API is still in beta, create a [Stripe] instance with [StripeApiBeta.WeChatPayV1] to enable this API.
*
* @param confirmPaymentIntentParams [ConfirmPaymentIntentParams] used to confirm 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 callback a [ApiResultCallback] to receive the result or error
*
* Possible callback errors:
* [AuthenticationException] failure to properly authenticate yourself (check your key)
* [InvalidRequestException] your request has invalid parameters
* [APIConnectionException] failure to connect to Stripe's API
* [APIException] any other type of problem (for instance, a temporary issue with Stripe's servers)
* [InvalidRequestException] if the payment intent's next action data is not for WeChat Pay
*/
@JvmOverloads
fun confirmWeChatPayPayment(
confirmPaymentIntentParams: ConfirmPaymentIntentParams,
stripeAccountId: String? = this.stripeAccountId,
callback: ApiResultCallback<WeChatPayNextAction>
) {
executeAsync(callback) {
paymentController.confirmWeChatPay(
confirmPaymentIntentParams,
ApiRequest.Options(
apiKey = publishableKey,
stripeAccount = stripeAccountId
)
)
}
}

/**
* Confirm and, if necessary, authenticate a [PaymentIntent].
* Used for [automatic confirmation](https://stripe.com/docs/payments/payment-intents/quickstart#automatic-confirmation-flow) flow.
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/StripeApiBeta.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package com.stripe.android
* Enums of beta headers allowed to be override when initializing [Stripe].
*/
enum class StripeApiBeta(val code: String) {
WechatPayV1("wechat_pay_beta=v1");
WeChatPayV1("wechat_pay_beta=v1");
}
34 changes: 34 additions & 0 deletions stripe/src/main/java/com/stripe/android/StripeKtx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.stripe.android.model.StripeFile
import com.stripe.android.model.StripeFileParams
import com.stripe.android.model.StripeModel
import com.stripe.android.model.Token
import com.stripe.android.model.WeChatPayNextAction
import com.stripe.android.networking.ApiRequest

/**
Expand Down Expand Up @@ -568,6 +569,39 @@ suspend fun Stripe.confirmSetupIntent(
)
}

/**
* Suspend function to confirm a [PaymentIntent] for WeChat Pay. Extract params from [WeChatPayNextAction] to pass to WeChat Pay SDK.
* @see <a href="https://pay.weixin.qq.com/index.php/public/wechatpay">WeChat Pay Documentation</a>
*
* WeChat Pay API is still in beta, create a [Stripe] instance with [StripeApiBeta.WeChatPayV1] to enable this API.
*
* @param confirmPaymentIntentParams [ConfirmPaymentIntentParams] used to confirm 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.
*
* @throws AuthenticationException failure to properly authenticate yourself (check your key)
* @throws InvalidRequestException your request has invalid parameters
* @throws APIConnectionException failure to connect to Stripe's API
* @throws APIException any other type of problem (for instance, a temporary issue with Stripe's servers)
*/
suspend fun Stripe.confirmWeChatPayPayment(
confirmPaymentIntentParams: ConfirmPaymentIntentParams,
stripeAccountId: String? = this.stripeAccountId,
): WeChatPayNextAction {
return runCatching {
paymentController.confirmWeChatPay(
confirmPaymentIntentParams,
ApiRequest.Options(
apiKey = publishableKey,
stripeAccount = stripeAccountId
)
)
}.getOrElse {
throw StripeException.create(it)
}
}

/**
* Suspend function to confirm a [PaymentIntent] object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.stripe.android.model.Stripe3ds2AuthParams
import com.stripe.android.model.Stripe3ds2AuthResult
import com.stripe.android.model.Stripe3ds2Fingerprint
import com.stripe.android.model.StripeIntent
import com.stripe.android.model.WeChatPayNextAction
import com.stripe.android.networking.AlipayRepository
import com.stripe.android.networking.AnalyticsRequestExecutor
import com.stripe.android.networking.AnalyticsRequestFactory
Expand Down Expand Up @@ -193,6 +194,24 @@ internal class StripePaymentController internal constructor(
)
}

override suspend fun confirmWeChatPay(
confirmPaymentIntentParams: ConfirmPaymentIntentParams,
requestOptions: ApiRequest.Options
): WeChatPayNextAction {
confirmPaymentIntent(
confirmPaymentIntentParams,
requestOptions
).let { paymentIntent ->
require(paymentIntent.nextActionData is StripeIntent.NextActionData.WeChatPayRedirect) {
"Unable to confirm Payment Intent with WeChatPay SDK"
}
return WeChatPayNextAction(
paymentIntent,
paymentIntent.nextActionData.weChat,
)
}
}

private suspend fun confirmPaymentIntent(
confirmStripeIntentParams: ConfirmPaymentIntentParams,
requestOptions: ApiRequest.Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ data class PaymentMethod internal constructor(
PayPal("paypal", isReusable = false),
AfterpayClearpay("afterpay_clearpay", isReusable = false),
Netbanking("netbanking", isReusable = false),
Blik("blik", isReusable = false);
Blik("blik", isReusable = false),
WeChatPay("wechat_pay", isReusable = false);

override fun toString(): String {
return code
Expand Down
Loading