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

Pass Accept-Language header in API requests #1701

Merged
merged 1 commit into from
Oct 15, 2019
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
7 changes: 1 addition & 6 deletions stripe/src/main/java/com/stripe/android/ApiRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ internal class ApiRequest internal constructor(
mapOf("Stripe-Account" to it)
}.orEmpty()
).plus(
(languageTag.takeIf { SHOULD_INCLUDE_ACCEPT_LANGUAGE_HEADER })?.let {
mapOf("Accept-Language" to it)
}.orEmpty()
languageTag?.let { mapOf("Accept-Language" to it) }.orEmpty()
)
}

Expand Down Expand Up @@ -137,9 +135,6 @@ internal class ApiRequest internal constructor(
// this is the default user agent set by the system
private const val PROP_USER_AGENT = "http.agent"

// TODO(mshafrir-stripe) - enable in next major version
private const val SHOULD_INCLUDE_ACCEPT_LANGUAGE_HEADER = false

@JvmStatic
fun createGet(
url: String,
Expand Down
4 changes: 3 additions & 1 deletion stripe/src/test/java/com/stripe/android/ApiRequestTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ internal class ApiRequestTest {

@Test
fun getHeaders_withAllRequestOptions_properlyMapsRequestOptions() {
Locale.setDefault(Locale.US)

val stripeAccount = "acct_123abc"
val headers = ApiRequest.createGet(StripeApiRepository.sourcesUrl,
ApiRequest.Options.create(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY,
Expand All @@ -41,7 +43,7 @@ internal class ApiRequestTest {
)
assertEquals(ApiVersion.get().code, headers["Stripe-Version"])
assertEquals(stripeAccount, headers["Stripe-Account"])
assertFalse(headers.contains("Accept-Language"))
assertEquals("en-US", headers["Accept-Language"])
}

@Test
Expand Down
19 changes: 19 additions & 0 deletions stripe/src/test/java/com/stripe/android/StripeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.stripe.android.exception.AuthenticationException;
import com.stripe.android.exception.CardException;
import com.stripe.android.exception.InvalidRequestException;
import com.stripe.android.exception.StripeException;
import com.stripe.android.model.AccountParams;
import com.stripe.android.model.Address;
Expand All @@ -31,6 +32,7 @@
import java.util.concurrent.Executor;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -1039,6 +1041,23 @@ public void run() throws Throwable {
assertEquals("Your card number is incorrect.", cardException.getMessage());
}

@Ignore("enable after bumping version to v12.0.0")
public void retrievePaymentIntent_withInvalidClientSecretInGermanyLocale_shouldReturnLocalizedMessage() {
Locale.setDefault(Locale.GERMANY);

// This card is missing quite a few numbers.
final Stripe stripe = createStripe();
final InvalidRequestException exception = assertThrows(
InvalidRequestException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
stripe.retrievePaymentIntentSynchronous("invalid");
}
});
assertEquals("Keine solche payment_intent: invalid", exception.getStripeError().getMessage());
}

@Test
public void createTokenSynchronous_withExpiredCard_throwsCardException() {
// This card is missing quite a few numbers.
Expand Down