Skip to content

Commit

Permalink
Remove PaymentMethodOptionsParams.Alipay (#2533)
Browse files Browse the repository at this point in the history
  • Loading branch information
smaskell-stripe authored Jun 1, 2020
1 parent 48c3e8d commit 1eadb29
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.stripe.android.model

import android.content.Context
import android.os.Parcelable
import com.stripe.android.model.ConfirmPaymentIntentParams.SetupFutureUsage
import com.stripe.android.model.ConfirmPaymentIntentParams.SetupFutureUsage.OffSession
Expand All @@ -11,7 +10,6 @@ import com.stripe.android.model.ConfirmStripeIntentParams.Companion.PARAM_PAYMEN
import com.stripe.android.model.ConfirmStripeIntentParams.Companion.PARAM_PAYMENT_METHOD_ID
import com.stripe.android.model.ConfirmStripeIntentParams.Companion.PARAM_RETURN_URL
import com.stripe.android.model.ConfirmStripeIntentParams.Companion.PARAM_USE_STRIPE_SDK
import com.stripe.android.utils.ContextUtils.packageInfo
import kotlinx.android.parcel.Parcelize

/**
Expand Down Expand Up @@ -504,22 +502,21 @@ data class ConfirmPaymentIntentParams internal constructor(
)
}

/**
* Create the parameters necessary for confirming a [PaymentIntent] with Alipay
*
* @param clientSecret client secret from the PaymentIntent that is to be confirmed
* @param returnUrl the URL the customer should be redirected to after the authorization
* process
*/
@JvmStatic
internal fun createAlipay(
context: Context,
clientSecret: String,
returnUrl: String
): ConfirmPaymentIntentParams {
val options = context.packageInfo?.let {
PaymentMethodOptionsParams.Alipay(
it.packageName,
it.versionName
)
}
return ConfirmPaymentIntentParams(
clientSecret = clientSecret,
paymentMethodCreateParams = PaymentMethodCreateParams.createAlipay(),
paymentMethodOptions = options,
returnUrl = returnUrl
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,4 @@ sealed class PaymentMethodOptionsParams(
private const val PARAM_NETWORK = "network"
}
}

@Parcelize
internal data class Alipay(
val appBundleId: String,
val appVersionKey: String
) : PaymentMethodOptionsParams(PaymentMethod.Type.Alipay) {
override fun createTypeParams(): List<Pair<String, Any?>> {
return listOf(
PARAM_APP_BUNDLE_ID to appBundleId,
PARAM_APP_VERSION_KEY to appVersionKey
)
}

private companion object {
private const val PARAM_APP_BUNDLE_ID = "app_bundle_id"
private const val PARAM_APP_VERSION_KEY = "app_version_key"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package com.stripe.android.model

import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import com.google.common.truth.Truth.assertThat
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import kotlin.test.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class ConfirmPaymentIntentParamsTest {

@Test
Expand Down Expand Up @@ -385,33 +377,14 @@ class ConfirmPaymentIntentParamsTest {

@Test
fun toParamMap_withAlipay_shouldCreateExpectedMap() {
val packageInfo = PackageInfo().also {
it.packageName = "package_name"
it.versionName = "version_name"
}
val packageManager = mock<PackageManager>().also {
whenever(it.getPackageInfo("package_name", 0)).thenReturn(packageInfo)
}
val context = mock<Context>().also {
whenever(it.packageName).thenReturn("package_name")
whenever(it.packageManager).thenReturn(packageManager)
}

assertThat(ConfirmPaymentIntentParams.createAlipay(
context,
CLIENT_SECRET,
RETURN_URL
).toParamMap())
.isEqualTo(mapOf(
"client_secret" to CLIENT_SECRET,
"use_stripe_sdk" to false,
"return_url" to RETURN_URL,
"payment_method_options" to mapOf(
"alipay" to mapOf(
"app_bundle_id" to context.packageName,
"app_version_key" to "version_name"
)
),
"payment_method_data" to mapOf(
"type" to "alipay"
)
Expand Down

0 comments on commit 1eadb29

Please sign in to comment.