-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Represent PaymentIntent confirmationMethod and captureMethod as enums (…
- Loading branch information
1 parent
ac5aab8
commit ddc0ef7
Showing
5 changed files
with
144 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,7 @@ package com.stripe.android.model | |
import android.net.Uri | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFailsWith | ||
import kotlin.test.assertNotNull | ||
import kotlin.test.assertNull | ||
import kotlin.test.assertTrue | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
|
@@ -18,73 +14,92 @@ class PaymentIntentTest { | |
fun parseIdFromClientSecret_parsesCorrectly() { | ||
val clientSecret = "pi_1CkiBMLENEVhOs7YMtUehLau_secret_s4O8SDh7s6spSmHDw1VaYPGZA" | ||
val paymentIntentId = PaymentIntent.ClientSecret(clientSecret).paymentIntentId | ||
assertEquals("pi_1CkiBMLENEVhOs7YMtUehLau", paymentIntentId) | ||
assertThat(paymentIntentId) | ||
.isEqualTo("pi_1CkiBMLENEVhOs7YMtUehLau") | ||
} | ||
|
||
@Test | ||
fun parsePaymentIntentWithPaymentMethods() { | ||
val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_MASTERCARD_3DS2 | ||
assertTrue(paymentIntent.requiresAction()) | ||
assertEquals("card", paymentIntent.paymentMethodTypes[0]) | ||
assertEquals(0, paymentIntent.canceledAt) | ||
assertEquals("automatic", paymentIntent.captureMethod) | ||
assertEquals("manual", paymentIntent.confirmationMethod) | ||
assertNotNull(paymentIntent.nextAction) | ||
assertEquals("[email protected]", paymentIntent.receiptEmail) | ||
assertNull(paymentIntent.cancellationReason) | ||
assertThat(paymentIntent.requiresAction()) | ||
.isTrue() | ||
assertThat(paymentIntent.paymentMethodTypes) | ||
.containsExactly("card") | ||
assertThat(paymentIntent.canceledAt) | ||
.isEqualTo(0) | ||
assertThat(paymentIntent.captureMethod) | ||
.isEqualTo(PaymentIntent.CaptureMethod.Automatic) | ||
assertThat(paymentIntent.confirmationMethod) | ||
.isEqualTo(PaymentIntent.ConfirmationMethod.Manual) | ||
assertThat(paymentIntent.nextAction) | ||
.isNotNull() | ||
assertThat(paymentIntent.receiptEmail) | ||
.isEqualTo("[email protected]") | ||
assertThat(paymentIntent.cancellationReason) | ||
.isNull() | ||
} | ||
|
||
@Test | ||
fun getNextActionData_whenUseStripeSdkWith3ds2() { | ||
val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_MASTERCARD_3DS2 | ||
assertTrue(paymentIntent.nextActionData is StripeIntent.NextActionData.SdkData.Use3DS2) | ||
val sdkData = paymentIntent.nextActionData as StripeIntent.NextActionData.SdkData.Use3DS2 | ||
assertEquals("mastercard", sdkData.serverName) | ||
assertThat(paymentIntent.nextActionData) | ||
.isInstanceOf(StripeIntent.NextActionData.SdkData.Use3DS2::class.java) | ||
val sdkData = | ||
paymentIntent.nextActionData as StripeIntent.NextActionData.SdkData.Use3DS2 | ||
assertThat(sdkData.serverName) | ||
.isEqualTo("mastercard") | ||
} | ||
|
||
@Test | ||
fun getNextActionData_whenUseStripeSdkWith3ds1() { | ||
val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_3DS1 | ||
assertTrue(paymentIntent.nextActionData is StripeIntent.NextActionData.SdkData.Use3DS1) | ||
assertThat(paymentIntent.nextActionData) | ||
.isInstanceOf(StripeIntent.NextActionData.SdkData.Use3DS1::class.java) | ||
val sdkData = paymentIntent.nextActionData as StripeIntent.NextActionData.SdkData.Use3DS1 | ||
assertThat(sdkData.url).isNotEmpty() | ||
assertThat(sdkData.url) | ||
.isNotEmpty() | ||
} | ||
|
||
@Test | ||
fun getNextActionData_whenRedirectToUrl() { | ||
val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_REDIRECT | ||
assertTrue(paymentIntent.nextActionData is StripeIntent.NextActionData.RedirectToUrl) | ||
assertThat(paymentIntent.nextActionData) | ||
.isInstanceOf(StripeIntent.NextActionData.RedirectToUrl::class.java) | ||
val redirectData = paymentIntent.nextActionData as StripeIntent.NextActionData.RedirectToUrl | ||
assertEquals(Uri.parse("https://hooks.stripe.com/3d_secure_2_eap/begin_test/src_1Ecaz6CRMbs6FrXfuYKBRSUG/src_client_secret_F6octeOshkgxT47dr0ZxSZiv"), | ||
redirectData.url) | ||
assertEquals(redirectData.returnUrl, "stripe://deeplink") | ||
assertThat(redirectData.url) | ||
.isEqualTo( | ||
Uri.parse("https://hooks.stripe.com/3d_secure_2_eap/begin_test/src_1Ecaz6CRMbs6FrXfuYKBRSUG/src_client_secret_F6octeOshkgxT47dr0ZxSZiv") | ||
) | ||
assertThat(redirectData.returnUrl) | ||
.isEqualTo("stripe://deeplink") | ||
} | ||
|
||
@Test | ||
fun getLastPaymentError_parsesCorrectly() { | ||
val lastPaymentError = | ||
requireNotNull(PaymentIntentFixtures.PI_WITH_LAST_PAYMENT_ERROR.lastPaymentError) | ||
assertEquals("pm_1F7J1bCRMbs6FrXfQKsYwO3U", lastPaymentError.paymentMethod?.id) | ||
assertEquals("payment_intent_authentication_failure", lastPaymentError.code) | ||
assertEquals(PaymentIntent.Error.Type.InvalidRequestError, lastPaymentError.type) | ||
assertEquals( | ||
"https://stripe.com/docs/error-codes/payment-intent-authentication-failure", | ||
lastPaymentError.docUrl | ||
) | ||
assertEquals( | ||
"The provided PaymentMethod has failed authentication. You can provide payment_method_data or a new PaymentMethod to attempt to fulfill this PaymentIntent again.", | ||
lastPaymentError.message | ||
) | ||
assertThat(lastPaymentError.paymentMethod?.id) | ||
.isEqualTo("pm_1F7J1bCRMbs6FrXfQKsYwO3U") | ||
assertThat(lastPaymentError.code) | ||
.isEqualTo("payment_intent_authentication_failure") | ||
assertThat(lastPaymentError.type) | ||
.isEqualTo(PaymentIntent.Error.Type.InvalidRequestError) | ||
assertThat(lastPaymentError.docUrl) | ||
.isEqualTo("https://stripe.com/docs/error-codes/payment-intent-authentication-failure") | ||
assertThat(lastPaymentError.message) | ||
.isEqualTo( | ||
"The provided PaymentMethod has failed authentication. You can provide payment_method_data or a new PaymentMethod to attempt to fulfill this PaymentIntent again." | ||
) | ||
} | ||
|
||
@Test | ||
fun testCanceled() { | ||
assertEquals(StripeIntent.Status.Canceled, | ||
PaymentIntentFixtures.CANCELLED.status) | ||
assertEquals(PaymentIntent.CancellationReason.Abandoned, | ||
PaymentIntentFixtures.CANCELLED.cancellationReason) | ||
assertEquals(1567091866L, | ||
PaymentIntentFixtures.CANCELLED.canceledAt) | ||
assertThat(PaymentIntentFixtures.CANCELLED.status) | ||
.isEqualTo(StripeIntent.Status.Canceled) | ||
assertThat(PaymentIntentFixtures.CANCELLED.cancellationReason) | ||
.isEquivalentAccordingToCompareTo(PaymentIntent.CancellationReason.Abandoned) | ||
assertThat(PaymentIntentFixtures.CANCELLED.canceledAt) | ||
.isEqualTo(1567091866L) | ||
} | ||
|
||
@Test | ||
|
@@ -112,9 +127,7 @@ class PaymentIntentTest { | |
|
||
@Test | ||
fun clientSecret_withValidKeys_succeeds() { | ||
assertEquals( | ||
"pi_a1b2c3_secret_x7y8z9", | ||
PaymentIntent.ClientSecret("pi_a1b2c3_secret_x7y8z9").value | ||
) | ||
assertThat(PaymentIntent.ClientSecret("pi_a1b2c3_secret_x7y8z9").value) | ||
.isEqualTo("pi_a1b2c3_secret_x7y8z9") | ||
} | ||
} |