Commit 854935d9 authored by gogerald's avatar gogerald Committed by Commit Bot

[Payments] Do not check supported card type for modifier if unspecified

Bug: 751226
Change-Id: I84b42c04c16d3b5662ed6a5bf5d491b031b3c84a
Reviewed-on: https://chromium-review.googlesource.com/597014Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491369}
parent d80d541a
......@@ -133,7 +133,7 @@ public class AutofillPaymentApp implements PaymentApp {
result.add(CardType.UNKNOWN);
Map<Integer, Integer> cardTypes = getCardTypes();
if (data == null || data.supportedTypes == null || data.supportedTypes.length == 0) {
if (!isBasicCardTypeSpecified(data)) {
// Merchant website supports all card types.
result.addAll(cardTypes.values());
} else {
......@@ -147,6 +147,11 @@ public class AutofillPaymentApp implements PaymentApp {
return result;
}
/** @return True if supported card type is specified in data for "basic-card" method. */
public static boolean isBasicCardTypeSpecified(PaymentMethodData data) {
return data != null && data.supportedTypes != null && data.supportedTypes.length != 0;
}
private static Map<Integer, String> getNetworks() {
Map<Integer, String> networks = new HashMap<>();
networks.put(BasicCardNetwork.AMEX, "amex");
......
......@@ -892,10 +892,13 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
for (String methodName : methodNames) {
PaymentDetailsModifier modifier = mModifiers.get(methodName);
Set<Integer> targetCardTypes =
AutofillPaymentApp.convertBasicCardToTypes(modifier.methodData);
targetCardTypes.remove(CardType.UNKNOWN);
if (targetCardTypes.size() > 0 && !targetCardTypes.contains(cardType)) continue;
if (AutofillPaymentApp.isBasicCardTypeSpecified(modifier.methodData)) {
Set<Integer> targetCardTypes =
AutofillPaymentApp.convertBasicCardToTypes(modifier.methodData);
targetCardTypes.remove(CardType.UNKNOWN);
assert targetCardTypes.size() > 0;
if (!targetCardTypes.contains(cardType)) continue;
}
Set<String> targetCardNetworks =
AutofillPaymentApp.convertBasicCardToNetworks(modifier.methodData);
......
......@@ -221,13 +221,62 @@ public class PaymentRequestPaymentAppAndBasicCardWithModifiersTest {
"Mastercard"));
assertEquals("USD $4.00", mPaymentRequestTestRule.getOrderSummaryTotal());
// select the other visa card with unknow type and verify modifier is not applied.
// select the other visa card with unknown type and verify modifier is not applied.
mPaymentRequestTestRule.clickOnPaymentMethodSuggestionOptionAndWait(
1, mPaymentRequestTestRule.getReadyForInput());
assertTrue(mPaymentRequestTestRule.getSelectedPaymentInstrumentLabel().startsWith("Visa"));
assertEquals("USD $5.00", mPaymentRequestTestRule.getOrderSummaryTotal());
}
/**
* Verify modifier for mastercard (any card type) is applied for mastercard.
*/
@Test
@MediumTest
@Feature({"Payments"})
public void testUpdateTotalAndInstrumentLabelWithMastercardModifiers()
throws InterruptedException, ExecutionException, TimeoutException {
// Mastercard card with complete set of information and unknown type.
String guid = mHelper.setCreditCard(new CreditCard("", "https://example.com",
true /* isLocal */, true /* isCached */, "Jon Doe", "5555555555554444",
"" /* obfuscatedNumber */, "12", "2050", "mastercard", R.drawable.mc_card,
CardType.UNKNOWN, mBillingAddressId, "" /* serverId */));
mHelper.setCreditCardUseStatsForTesting(guid, 1000, 5000);
// Credit mastercard with complete set of information.
mHelper.addServerCreditCard(new CreditCard("guid_1", "https://example.com",
false /* isLocal */, true /* isCached */, "Jon Doe", "5200828282828210",
"" /* obfuscatedNumber */, "12", "2050", "mastercard", R.drawable.mc_card,
CardType.CREDIT, mBillingAddressId, "server-id-1"));
mHelper.setCreditCardUseStatsForTesting("guid_1", 100, 5000);
// Visa card with complete set of information and unknown type.
mHelper.addServerCreditCard(new CreditCard("guid_2", "https://example.com",
false /* isLocal */, true /* isCached */, "Jon Doe", "4111111111111111",
"" /* obfuscatedNumber */, "12", "2050", "mastercard", R.drawable.mc_card,
CardType.UNKNOWN, mBillingAddressId, "server-id-2"));
mHelper.setCreditCardUseStatsForTesting("guid_2", 1, 5000);
mPaymentRequestTestRule.triggerUIAndWait(
"mastercard_any_supported_type", mPaymentRequestTestRule.getReadyToPay());
assertTrue(mPaymentRequestTestRule.getSelectedPaymentInstrumentLabel().startsWith(
"Mastercard"));
assertEquals("USD $4.00", mPaymentRequestTestRule.getOrderSummaryTotal());
// select the other credit Mastercard and verify modifier is applied.
mPaymentRequestTestRule.clickOnPaymentMethodSuggestionOptionAndWait(
1, mPaymentRequestTestRule.getReadyForInput());
assertTrue(mPaymentRequestTestRule.getSelectedPaymentInstrumentLabel().startsWith(
"Mastercard"));
assertEquals("USD $4.00", mPaymentRequestTestRule.getOrderSummaryTotal());
// select the other visa card with unknown type and verify modifier is not applied.
mPaymentRequestTestRule.clickOnPaymentMethodSuggestionOptionAndWait(
2, mPaymentRequestTestRule.getReadyForInput());
assertTrue(mPaymentRequestTestRule.getSelectedPaymentInstrumentLabel().startsWith("Visa"));
assertEquals("USD $5.00", mPaymentRequestTestRule.getOrderSummaryTotal());
}
/**
* Verify native app can pay as expected when modifier is applied.
*/
......
......@@ -32,9 +32,7 @@ function buy() { // eslint-disable-line no-unused-vars
.then(function(resp) {
resp.complete('success')
.then(function() {
print(
resp.methodName + '<br>' +
JSON.stringify(resp.details, undefined, 2));
print(JSON.stringify(resp, undefined, 2));
})
.catch(function(error) {
print(error.message);
......@@ -75,9 +73,7 @@ function buyWithBobPayDiscount() { // eslint-disable-line no-unused-vars
.then(function(resp) {
resp.complete('success')
.then(function() {
print(
resp.methodName + '<br>' +
JSON.stringify(resp.details, undefined, 2));
print(JSON.stringify(resp, undefined, 2));
})
.catch(function(error) {
print(error.message);
......@@ -120,9 +116,7 @@ function creditSupportedType() { // eslint-disable-line no-unused-vars
.then(function(resp) {
resp.complete('success')
.then(function() {
print(
resp.methodName + '<br>' +
JSON.stringify(resp.details, undefined, 2));
print(JSON.stringify(resp, undefined, 2));
})
.catch(function(error) {
print(error.message);
......@@ -165,9 +159,7 @@ function debitSupportedType() { // eslint-disable-line no-unused-vars
.then(function(resp) {
resp.complete('success')
.then(function() {
print(
resp.methodName + '<br>' +
JSON.stringify(resp.details, undefined, 2));
print(JSON.stringify(resp, undefined, 2));
})
.catch(function(error) {
print(error.message);
......@@ -211,9 +203,7 @@ function visaSupportedNetwork() { // eslint-disable-line no-unused-vars
.then(function(resp) {
resp.complete('success')
.then(function() {
print(
resp.methodName + '<br>' +
JSON.stringify(resp.details, undefined, 2));
print(JSON.stringify(resp, undefined, 2));
})
.catch(function(error) {
print(error.message);
......@@ -258,9 +248,50 @@ function mastercardSupportedNetwork() { // eslint-disable-line no-unused-vars
.then(function(resp) {
resp.complete('success')
.then(function() {
print(
resp.methodName + '<br>' +
JSON.stringify(resp.details, undefined, 2));
print(JSON.stringify(resp, undefined, 2));
})
.catch(function(error) {
print(error.message);
});
})
.catch(function(error) {
print(error.message);
});
} catch (error) {
print(error.message);
}
}
/**
* Launches the PaymentRequest UI with Bob Pay and basic-card as payment
* methods and a modifier for basic-card with "mastercard" network.
*/
function mastercardAnySupportedType() { // eslint-disable-line no-unused-vars
try {
new PaymentRequest(
[{supportedMethods: ['https://bobpay.com', 'basic-card']}], {
total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}},
modifiers: [{
supportedMethods: ['basic-card'],
total: {
label: 'Total',
amount: {currency: 'USD', value: '4.00'},
},
additionalDisplayItems: [{
label: 'basic-card discount',
amount: {currency: 'USD', value: '-1.00'},
}],
data: {
discountProgramParticipantId: '86328764873265',
supportedNetworks: ['mastercard'],
},
}],
})
.show()
.then(function(resp) {
resp.complete('success')
.then(function() {
print(JSON.stringify(resp, undefined, 2));
})
.catch(function(error) {
print(error.message);
......
......@@ -16,8 +16,9 @@ found in the LICENSE file.
<button onclick="buyWithBobPayDiscount()" id="buy_with_bobpay_discount">Bob Pay and Basic-Card with Bob Pay modifiers Test</button>
<button onclick="creditSupportedType()" id="credit_supported_type">Bob Pay and Basic-Card with Basic-Card modifiers Test with credit supported type</button>
<button onclick="debitSupportedType()" id="debit_supported_type">Bob Pay and Basic-Card with Basic-Card modifiers Test with debit supported type</button>
<button onclick="visaSupportedNetwork()" id="visa_supported_network">Bob Pay and Basic-Card with Basic-Card modifiers Test with visa supported network</button>
<button onclick="mastercardSupportedNetwork()" id="mastercard_supported_network">Bob Pay and Basic-Card with Basic-Card modifiers Test with mastercard supported network</button>
<button onclick="visaSupportedNetwork()" id="visa_supported_network">Bob Pay and Basic-Card with Basic-Card modifiers Test with visa supported network and credit supported type</button>
<button onclick="mastercardSupportedNetwork()" id="mastercard_supported_network">Bob Pay and Basic-Card with Basic-Card modifiers Test with mastercard supported network and credit supported type</button>
<button onclick="mastercardAnySupportedType()" id="mastercard_any_supported_type">Bob Pay and Basic-Card with Basic-Card modifiers Test with mastercard supported network and any supported type</button>
<pre id="result"></pre>
<script src="util.js"></script>
<script src="bobpay_and_basic_card_with_modifiers.js"></script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment