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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
rename
ccen-stripe committed Apr 29, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 38d7dd2985bf82ebd44425f024d3e3b36cc25b70
10 changes: 5 additions & 5 deletions stripe/src/main/java/com/stripe/android/PaymentController.kt
Original file line number Diff line number Diff line change
@@ -54,17 +54,17 @@ internal interface PaymentController {
): PaymentIntentResult

/**
* Confirm the Stripe Intent for Wechat Pay, return Wechat Pay params from intent's next action
* 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]
* @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 IllegalArgumentException if the payment intent's next action data is not for WeChat Pay
*/
@Throws(
AuthenticationException::class,
@@ -73,10 +73,10 @@ internal interface PaymentController {
APIException::class,
IllegalArgumentException::class
)
suspend fun confirmWechatPay(
suspend fun confirmWeChatPay(
confirmPaymentIntentParams: ConfirmPaymentIntentParams,
requestOptions: ApiRequest.Options
): WechatPayNextAction
): WeChatPayNextAction

suspend fun startAuth(
host: AuthActivityStarter.Host,
14 changes: 7 additions & 7 deletions stripe/src/main/java/com/stripe/android/Stripe.kt
Original file line number Diff line number Diff line change
@@ -198,10 +198,10 @@ 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>
* 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.
* 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]
@@ -214,16 +214,16 @@ class Stripe internal constructor(
* [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
* [InvalidRequestException] if the payment intent's next action data is not for WeChat Pay
*/
@JvmOverloads
fun confirmWechatPayPayment(
fun confirmWeChatPayPayment(
confirmPaymentIntentParams: ConfirmPaymentIntentParams,
stripeAccountId: String? = this.stripeAccountId,
callback: ApiResultCallback<WechatPayNextAction>
callback: ApiResultCallback<WeChatPayNextAction>
) {
executeAsync(callback) {
paymentController.confirmWechatPay(
paymentController.confirmWeChatPay(
confirmPaymentIntentParams,
ApiRequest.Options(
apiKey = publishableKey,
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
@@ -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");
}
12 changes: 6 additions & 6 deletions stripe/src/main/java/com/stripe/android/StripeKtx.kt
Original file line number Diff line number Diff line change
@@ -569,10 +569,10 @@ 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>
* 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.
* 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]
@@ -584,12 +584,12 @@ suspend fun Stripe.confirmSetupIntent(
* @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(
suspend fun Stripe.confirmWeChatPayPayment(
confirmPaymentIntentParams: ConfirmPaymentIntentParams,
stripeAccountId: String? = this.stripeAccountId,
): WechatPayNextAction {
): WeChatPayNextAction {
return runCatching {
paymentController.confirmWechatPay(
paymentController.confirmWeChatPay(
confirmPaymentIntentParams,
ApiRequest.Options(
apiKey = publishableKey,
Original file line number Diff line number Diff line change
@@ -193,18 +193,18 @@ internal class StripePaymentController internal constructor(
)
}

override suspend fun confirmWechatPay(
override suspend fun confirmWeChatPay(
confirmPaymentIntentParams: ConfirmPaymentIntentParams,
requestOptions: ApiRequest.Options
): WechatPayNextAction {
): WeChatPayNextAction {
confirmPaymentIntent(
confirmPaymentIntentParams,
requestOptions
).let { paymentIntent ->
require(paymentIntent.nextActionData is StripeIntent.NextActionData.WechatPayRedirect) {
"Unable to confirm Payment Intent with WechatPay SDK"
require(paymentIntent.nextActionData is StripeIntent.NextActionData.WeChatPayRedirect) {
"Unable to confirm Payment Intent with WeChatPay SDK"
}
return WechatPayNextAction(
return WeChatPayNextAction(
paymentIntent,
paymentIntent.nextActionData.weChat,
)
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import com.stripe.android.model.WeChat
import kotlinx.parcelize.Parcelize

@Parcelize
data class WechatPayNextAction internal constructor(
val intent: PaymentIntent,
val wechat: WeChat,
data class WeChatPayNextAction internal constructor(
val paymentIntent: PaymentIntent,
val weChat: WeChat,
) : StripeModel
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ data class PaymentMethod internal constructor(
AfterpayClearpay("afterpay_clearpay", isReusable = false),
Netbanking("netbanking", isReusable = false),
Blik("blik", isReusable = false),
WechatPay("wechat_pay", isReusable = false);
WeChatPay("wechat_pay", isReusable = false);

override fun toString(): String {
return code
Original file line number Diff line number Diff line change
@@ -204,7 +204,7 @@ data class PaymentMethodCreateParams internal constructor(
Upi("upi"),
Netbanking("netbanking"),
Blik("blik"),
WechatPay("wechat_pay")
WeChatPay("wechat_pay")
}

@Parcelize
@@ -773,12 +773,12 @@ data class PaymentMethodCreateParams internal constructor(

@JvmStatic
@JvmOverloads
fun createWechatPay(
fun createWeChatPay(
billingDetails: PaymentMethod.BillingDetails? = null,
metadata: Map<String, String>? = null
): PaymentMethodCreateParams {
return PaymentMethodCreateParams(
type = Type.WechatPay,
type = Type.WeChatPay,
billingDetails = billingDetails,
metadata = metadata
)
Original file line number Diff line number Diff line change
@@ -56,9 +56,9 @@ sealed class PaymentMethodOptionsParams(
}

@Parcelize
data class WechatPay(
data class WeChatPay(
var appId: String,
) : PaymentMethodOptionsParams(PaymentMethod.Type.WechatPay) {
) : PaymentMethodOptionsParams(PaymentMethod.Type.WeChatPay) {
override fun createTypeParams(): List<Pair<String, Any?>> {
return listOf(
PARAM_CLIENT to "android",
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ interface StripeIntent : StripeModel {
DisplayOxxoDetails("oxxo_display_details"),
AlipayRedirect("alipay_handle_redirect"),
BlikAuthorize("blik_authorize"),
WechatPayRedirect("wechat_pay_redirect_to_android_app");
WeChatPayRedirect("wechat_pay_redirect_to_android_app");

override fun toString(): String {
return code
@@ -240,6 +240,6 @@ interface StripeIntent : StripeModel {
}

@Parcelize
internal data class WechatPayRedirect(val weChat: WeChat) : NextActionData()
internal data class WeChatPayRedirect(val weChat: WeChat) : NextActionData()
}
}
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ internal class NextActionDataParser : ModelJsonParser<StripeIntent.NextActionDat
StripeIntent.NextActionType.UseStripeSdk -> SdkDataJsonParser()
StripeIntent.NextActionType.AlipayRedirect -> AlipayRedirectParser()
StripeIntent.NextActionType.BlikAuthorize -> BlikAuthorizeParser()
StripeIntent.NextActionType.WechatPayRedirect -> WechatPayRedirectParser()
StripeIntent.NextActionType.WeChatPayRedirect -> WeChatPayRedirectParser()
else -> return null
}
return parser.parse(json.optJSONObject(nextActionType.code) ?: JSONObject())
@@ -152,10 +152,10 @@ internal class NextActionDataParser : ModelJsonParser<StripeIntent.NextActionDat
}
}

internal class WechatPayRedirectParser :
ModelJsonParser<StripeIntent.NextActionData.WechatPayRedirect> {
override fun parse(json: JSONObject): StripeIntent.NextActionData.WechatPayRedirect {
return StripeIntent.NextActionData.WechatPayRedirect(
internal class WeChatPayRedirectParser :
ModelJsonParser<StripeIntent.NextActionData.WeChatPayRedirect> {
override fun parse(json: JSONObject): StripeIntent.NextActionData.WeChatPayRedirect {
return StripeIntent.NextActionData.WeChatPayRedirect(
WeChat(
appId = json.optString(APP_ID),
nonce = json.optString(NONCE_STR),
4 changes: 2 additions & 2 deletions stripe/src/test/java/com/stripe/android/ApiVersionTest.kt
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ class ApiVersionTest {

@Test
fun `single beta header should have correct code`() {
assertThat(ApiVersion(setOf(StripeApiBeta.WechatPayV1)).code)
.isEqualTo("$API_VERSION_CODE;${StripeApiBeta.WechatPayV1.code}")
assertThat(ApiVersion(setOf(StripeApiBeta.WeChatPayV1)).code)
.isEqualTo("$API_VERSION_CODE;${StripeApiBeta.WeChatPayV1.code}")
}
}
Original file line number Diff line number Diff line change
@@ -326,16 +326,16 @@ internal class PaymentMethodEndToEndTest {
}

@Test
fun createPaymentMethod_withWechatPay_shouldCreateObject() {
val params = PaymentMethodCreateParams.createWechatPay()
fun createPaymentMethod_withWeChatPay_shouldCreateObject() {
val params = PaymentMethodCreateParams.createWeChatPay()
val paymentMethod =
Stripe(
context,
ApiKeyFixtures.WECHAT_PAY_PUBLISHABLE_KEY,
betas = setOf(StripeApiBeta.WechatPayV1)
betas = setOf(StripeApiBeta.WeChatPayV1)
)
.createPaymentMethodSynchronous(params)
assertThat(paymentMethod?.type)
.isEqualTo(PaymentMethod.Type.WechatPay)
.isEqualTo(PaymentMethod.Type.WeChatPay)
}
}
18 changes: 9 additions & 9 deletions stripe/src/test/java/com/stripe/android/StripeKtxTest.kt
Original file line number Diff line number Diff line change
@@ -519,13 +519,13 @@ internal class StripeKtxTest {
@Test
fun `When controller returns correct value then confirmWeChatPayPayment should succeed`(): Unit =
testDispatcher.runBlockingTest {
val expectedApiObj = mock<WechatPayNextAction>()
val expectedApiObj = mock<WeChatPayNextAction>()

whenever(
mockPaymentController.confirmWechatPay(any(), any())
mockPaymentController.confirmWeChatPay(any(), any())
).thenReturn(expectedApiObj)

val actualObj = stripe.confirmWechatPayPayment(
val actualObj = stripe.confirmWeChatPayPayment(
mock(),
TEST_STRIPE_ACCOUNT_ID
)
@@ -537,28 +537,28 @@ internal class StripeKtxTest {
fun `When controller throws exception then confirmWeChatPayPayment should throw same exception`(): Unit =
testDispatcher.runBlockingTest {
whenever(
mockPaymentController.confirmWechatPay(any(), any())
mockPaymentController.confirmWeChatPay(any(), any())
).thenThrow(mock<AuthenticationException>())

assertFailsWith<AuthenticationException> {
stripe.confirmWechatPayPayment(
stripe.confirmWeChatPayPayment(
mock(),
TEST_STRIPE_ACCOUNT_ID
)
}
}

@Test
fun `When nextAction is not for Wechatpay then should throw InvalidRequestException`(): Unit =
// when nextAction is not for Wechatpay, mockPaymentController fails in `require` and
fun `When nextAction is not for WeChatPay then should throw InvalidRequestException`(): Unit =
// when nextAction is not for WeChatPay, mockPaymentController fails in `require` and
// throws an IllegalArgumentException
testDispatcher.runBlockingTest {
whenever(
mockPaymentController.confirmWechatPay(any(), any())
mockPaymentController.confirmWeChatPay(any(), any())
).thenThrow(mock<IllegalArgumentException>())

assertFailsWith<InvalidRequestException> {
stripe.confirmWechatPayPayment(
stripe.confirmWeChatPayPayment(
mock(),
TEST_STRIPE_ACCOUNT_ID
)
Original file line number Diff line number Diff line change
@@ -383,12 +383,12 @@ class ConfirmPaymentIntentParamsTest {
}

@Test
fun toParamMap_withWechatPayPaymentMethodOptions_shouldCreateExpectedMap() {
fun toParamMap_withWeChatPayPaymentMethodOptions_shouldCreateExpectedMap() {
val appId = "appId123456"
assertThat(
ConfirmPaymentIntentParams(
paymentMethodId = "pm_123",
paymentMethodOptions = PaymentMethodOptionsParams.WechatPay(
paymentMethodOptions = PaymentMethodOptionsParams.WeChatPay(
appId = appId
),
clientSecret = CLIENT_SECRET
@@ -397,9 +397,9 @@ class ConfirmPaymentIntentParamsTest {
mapOf(
"payment_method" to "pm_123",
"payment_method_options" to mapOf(
PaymentMethod.Type.WechatPay.code to mapOf(
PaymentMethodOptionsParams.WechatPay.PARAM_CLIENT to "android",
PaymentMethodOptionsParams.WechatPay.PARAM_APP_ID to appId,
PaymentMethod.Type.WeChatPay.code to mapOf(
PaymentMethodOptionsParams.WeChatPay.PARAM_CLIENT to "android",
PaymentMethodOptionsParams.WeChatPay.PARAM_APP_ID to appId,
)
),
"client_secret" to CLIENT_SECRET,
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ class PaymentIntentTest {
}

@Test
fun parsePaymentIntentWithWechatPayPaymentMethods() {
fun parsePaymentIntentWithWeChatPayPaymentMethods() {
val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_WECHAT_PAY_AUTHORIZE
assertThat(paymentIntent.requiresAction())
.isTrue()
@@ -100,12 +100,12 @@ class PaymentIntentTest {
}

@Test
fun getNextActionData_whenWechatPay() {
fun getNextActionData_whenWeChatPay() {
val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_WECHAT_PAY_AUTHORIZE
assertThat(paymentIntent.nextActionData)
.isInstanceOf(StripeIntent.NextActionData.WechatPayRedirect::class.java)
.isInstanceOf(StripeIntent.NextActionData.WeChatPayRedirect::class.java)
val weChat =
(paymentIntent.nextActionData as StripeIntent.NextActionData.WechatPayRedirect).weChat
(paymentIntent.nextActionData as StripeIntent.NextActionData.WeChatPayRedirect).weChat
assertThat(weChat).isEqualTo(
WeChat(
appId = "wx65997d6307c3827d",