Index: chrome/android/java/src/org/chromium/chrome/browser/payments/AndroidPaymentApp.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/AndroidPaymentApp.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/AndroidPaymentApp.java |
index efaf9f0b4fe6c32aa96d0cfb9d90073f5dbc2bc8..0d6bceb83b9e0c4e4860148c7765525b9bfd52b2 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/AndroidPaymentApp.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/AndroidPaymentApp.java |
@@ -37,6 +37,7 @@ import org.chromium.ui.base.WindowAndroid; |
import java.io.IOException; |
import java.io.StringWriter; |
import java.util.ArrayList; |
+import java.util.Collection; |
import java.util.Collections; |
import java.util.HashSet; |
import java.util.List; |
@@ -79,6 +80,7 @@ public class AndroidPaymentApp |
private static final String EXTRA_PAYMENT_REQUEST_ORIGIN = "paymentRequestOrigin"; |
private static final String EXTRA_TOP_LEVEL_CERTIFICATE_CHAIN = "topLevelCertificateChain"; |
private static final String EXTRA_TOP_LEVEL_ORIGIN = "topLevelOrigin"; |
+ private static final String EXTRA_MODIFIERS = "modifiers"; |
gogerald1
2017/05/17 19:11:46
You can move it under EXTRA_CERTIFICATE to list in
wuandy1
2017/05/18 20:12:29
Done.
|
private static final String EXTRA_TOTAL = "total"; |
// Response from the payment app. |
@@ -337,8 +339,8 @@ public class AndroidPaymentApp |
} |
} |
- private static Bundle buildExtras(@Nullable String id, @Nullable String merchantName, |
- String origin, String iframeOrigin, @Nullable byte[][] certificateChain, |
+ private Bundle buildExtras(@Nullable String id, @Nullable String merchantName, String origin, |
+ String iframeOrigin, @Nullable byte[][] certificateChain, |
Map<String, PaymentMethodData> methodDataMap, PaymentItem total, |
@Nullable List<PaymentItem> displayItems, |
@Nullable Map<String, PaymentDetailsModifier> modifiers) { |
@@ -369,6 +371,10 @@ public class AndroidPaymentApp |
} |
extras.putParcelable(EXTRA_METHOD_DATA, methodDataBundle); |
+ if (modifiers != null) { |
+ extras.putString(EXTRA_MODIFIERS, buildModifierListString(modifiers.values())); |
gogerald1
2017/05/17 19:11:47
Do not put 'null' value to EXTRA_MODIFIERS
gogerald1
2017/05/17 19:11:47
You can name it "serializeModifiers" or "serialize
wuandy1
2017/05/18 20:12:29
Done.
wuandy1
2017/05/18 20:12:29
Done.
|
+ } |
+ |
String serializedTotalAmount = serializeTotalAmount(total.amount); |
extras.putString(EXTRA_TOTAL, |
serializedTotalAmount == null ? EMPTY_JSON_DATA : serializedTotalAmount); |
@@ -490,6 +496,48 @@ public class AndroidPaymentApp |
// }}} item |
} |
+ private String buildModifierListString(Collection<PaymentDetailsModifier> modifiers) { |
gogerald1
2017/05/17 19:11:47
annotate @Nullable
wuandy1
2017/05/18 20:12:28
changed to return empty json instead.
gogerald1
2017/05/18 21:57:33
even better,
|
+ StringWriter stringWriter = new StringWriter(); |
+ JsonWriter json = new JsonWriter(stringWriter); |
+ try { |
+ json.beginArray(); |
+ for (PaymentDetailsModifier modifier : modifiers) { |
+ for (String supported : modifier.methodData.supportedMethods) { |
+ if (mMethodNames.contains(supported)) { |
gogerald1
2017/05/17 19:11:47
You no need to do this again here since we already
wuandy1
2017/05/18 20:12:29
Done.
|
+ serializeModifier(modifier, json); |
+ break; |
+ } |
+ } |
+ } |
+ json.endArray(); |
+ } catch (IOException e) { |
+ return null; |
+ } |
+ return stringWriter.toString(); |
+ } |
+ |
+ private static void serializeModifier(PaymentDetailsModifier modifier, JsonWriter json) |
+ throws IOException { |
+ // {{{ |
+ json.beginObject(); |
+ |
+ // total {{{ |
+ json.name("total"); |
+ serializePaymentItem(modifier.total, json); |
gogerald1
2017/05/17 19:11:47
total could be null in modifier
wuandy1
2017/05/18 20:12:29
Done.
|
+ // }}} total |
+ |
+ // supportedMethods {{{ |
+ json.name("supportedMethods").beginArray(); |
+ for (String method : modifier.methodData.supportedMethods) { |
+ json.value(method); |
+ } |
+ json.endArray(); |
+ // }}} supportedMethods |
+ |
+ json.endObject(); |
+ // }}} |
+ } |
+ |
@Override |
public void onIntentCompleted(WindowAndroid window, int resultCode, Intent data) { |
ThreadUtils.assertOnUiThread(); |