OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.payments; | 5 package org.chromium.chrome.browser.payments; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.ComponentName; | 8 import android.content.ComponentName; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.DialogInterface; | 10 import android.content.DialogInterface; |
(...skipping 19 matching lines...) Expand all Loading... | |
30 import org.chromium.content_public.browser.WebContents; | 30 import org.chromium.content_public.browser.WebContents; |
31 import org.chromium.payments.mojom.PaymentCurrencyAmount; | 31 import org.chromium.payments.mojom.PaymentCurrencyAmount; |
32 import org.chromium.payments.mojom.PaymentDetailsModifier; | 32 import org.chromium.payments.mojom.PaymentDetailsModifier; |
33 import org.chromium.payments.mojom.PaymentItem; | 33 import org.chromium.payments.mojom.PaymentItem; |
34 import org.chromium.payments.mojom.PaymentMethodData; | 34 import org.chromium.payments.mojom.PaymentMethodData; |
35 import org.chromium.ui.base.WindowAndroid; | 35 import org.chromium.ui.base.WindowAndroid; |
36 | 36 |
37 import java.io.IOException; | 37 import java.io.IOException; |
38 import java.io.StringWriter; | 38 import java.io.StringWriter; |
39 import java.util.ArrayList; | 39 import java.util.ArrayList; |
40 import java.util.Collection; | |
40 import java.util.Collections; | 41 import java.util.Collections; |
41 import java.util.HashSet; | 42 import java.util.HashSet; |
42 import java.util.List; | 43 import java.util.List; |
43 import java.util.Map; | 44 import java.util.Map; |
44 import java.util.Set; | 45 import java.util.Set; |
45 | 46 |
46 import javax.annotation.Nullable; | 47 import javax.annotation.Nullable; |
47 | 48 |
48 /** | 49 /** |
49 * The point of interaction with a locally installed 3rd party native Android pa yment app. | 50 * The point of interaction with a locally installed 3rd party native Android pa yment app. |
(...skipping 22 matching lines...) Expand all Loading... | |
72 | 73 |
73 // Freshest parameters sent to the payment app. | 74 // Freshest parameters sent to the payment app. |
74 private static final String EXTRA_CERTIFICATE = "certificate"; | 75 private static final String EXTRA_CERTIFICATE = "certificate"; |
75 private static final String EXTRA_MERCHANT_NAME = "merchantName"; | 76 private static final String EXTRA_MERCHANT_NAME = "merchantName"; |
76 private static final String EXTRA_METHOD_DATA = "methodData"; | 77 private static final String EXTRA_METHOD_DATA = "methodData"; |
77 private static final String EXTRA_METHOD_NAMES = "methodNames"; | 78 private static final String EXTRA_METHOD_NAMES = "methodNames"; |
78 private static final String EXTRA_PAYMENT_REQUEST_ID = "paymentRequestId"; | 79 private static final String EXTRA_PAYMENT_REQUEST_ID = "paymentRequestId"; |
79 private static final String EXTRA_PAYMENT_REQUEST_ORIGIN = "paymentRequestOr igin"; | 80 private static final String EXTRA_PAYMENT_REQUEST_ORIGIN = "paymentRequestOr igin"; |
80 private static final String EXTRA_TOP_LEVEL_CERTIFICATE_CHAIN = "topLevelCer tificateChain"; | 81 private static final String EXTRA_TOP_LEVEL_CERTIFICATE_CHAIN = "topLevelCer tificateChain"; |
81 private static final String EXTRA_TOP_LEVEL_ORIGIN = "topLevelOrigin"; | 82 private static final String EXTRA_TOP_LEVEL_ORIGIN = "topLevelOrigin"; |
83 private static final String EXTRA_MODIFIERS = "modifiers"; | |
82 private static final String EXTRA_TOTAL = "total"; | 84 private static final String EXTRA_TOTAL = "total"; |
83 | 85 |
84 // Response from the payment app. | 86 // Response from the payment app. |
85 private static final String EXTRA_DEPRECATED_RESPONSE_INSTRUMENT_DETAILS = " instrumentDetails"; | 87 private static final String EXTRA_DEPRECATED_RESPONSE_INSTRUMENT_DETAILS = " instrumentDetails"; |
86 private static final String EXTRA_RESPONSE_DETAILS = "details"; | 88 private static final String EXTRA_RESPONSE_DETAILS = "details"; |
87 private static final String EXTRA_RESPONSE_METHOD_NAME = "methodName"; | 89 private static final String EXTRA_RESPONSE_METHOD_NAME = "methodName"; |
88 | 90 |
89 private static final String EMPTY_JSON_DATA = "{}"; | 91 private static final String EMPTY_JSON_DATA = "{}"; |
90 | 92 |
91 private final Handler mHandler; | 93 private final Handler mHandler; |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 extras.putStringArrayList(EXTRA_METHOD_NAMES, new ArrayList<>(methodData Map.keySet())); | 364 extras.putStringArrayList(EXTRA_METHOD_NAMES, new ArrayList<>(methodData Map.keySet())); |
363 | 365 |
364 Bundle methodDataBundle = new Bundle(); | 366 Bundle methodDataBundle = new Bundle(); |
365 for (Map.Entry<String, PaymentMethodData> methodData : methodDataMap.ent rySet()) { | 367 for (Map.Entry<String, PaymentMethodData> methodData : methodDataMap.ent rySet()) { |
366 methodDataBundle.putString(methodData.getKey(), | 368 methodDataBundle.putString(methodData.getKey(), |
367 methodData.getValue() == null ? EMPTY_JSON_DATA | 369 methodData.getValue() == null ? EMPTY_JSON_DATA |
368 : methodData.getValue().string ifiedData); | 370 : methodData.getValue().string ifiedData); |
369 } | 371 } |
370 extras.putParcelable(EXTRA_METHOD_DATA, methodDataBundle); | 372 extras.putParcelable(EXTRA_METHOD_DATA, methodDataBundle); |
371 | 373 |
374 if (modifiers != null) { | |
375 extras.putStringArrayList(EXTRA_MODIFIERS, buildModifierList(modifie rs.values())); | |
376 } | |
377 | |
372 String serializedTotalAmount = serializeTotalAmount(total.amount); | 378 String serializedTotalAmount = serializeTotalAmount(total.amount); |
373 extras.putString(EXTRA_TOTAL, | 379 extras.putString(EXTRA_TOTAL, |
374 serializedTotalAmount == null ? EMPTY_JSON_DATA : serializedTota lAmount); | 380 serializedTotalAmount == null ? EMPTY_JSON_DATA : serializedTota lAmount); |
375 | 381 |
376 return addDeprecatedExtras(id, origin, iframeOrigin, serializedCertifica teChain, | 382 return addDeprecatedExtras(id, origin, iframeOrigin, serializedCertifica teChain, |
377 methodDataMap, methodDataBundle, total, displayItems, extras); | 383 methodDataMap, methodDataBundle, total, displayItems, extras); |
378 } | 384 } |
379 | 385 |
380 private static Bundle addDeprecatedExtras(@Nullable String id, String origin , | 386 private static Bundle addDeprecatedExtras(@Nullable String id, String origin , |
381 String iframeOrigin, @Nullable Parcelable[] serializedCertificateCha in, | 387 String iframeOrigin, @Nullable Parcelable[] serializedCertificateCha in, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 json.name("amount").beginObject(); | 489 json.name("amount").beginObject(); |
484 json.name("currency").value(item.amount.currency); | 490 json.name("currency").value(item.amount.currency); |
485 json.name("value").value(item.amount.value); | 491 json.name("value").value(item.amount.value); |
486 json.endObject(); | 492 json.endObject(); |
487 // }}} amount | 493 // }}} amount |
488 | 494 |
489 json.endObject(); | 495 json.endObject(); |
490 // }}} item | 496 // }}} item |
491 } | 497 } |
492 | 498 |
499 private static ArrayList<String> buildModifierList( | |
gogerald1
2017/05/16 20:36:59
We are supposed to serialize all modifiers in to a
please use gerrit instead
2017/05/17 13:02:32
Also, please filter out modifiers whose "supported
wuandy1
2017/05/17 16:24:27
Done.
wuandy1
2017/05/17 16:24:27
Done.
| |
500 Collection<PaymentDetailsModifier> modifiers) { | |
501 ArrayList<String> result = new ArrayList<>(); | |
502 for (PaymentDetailsModifier modifier : modifiers) { | |
503 String modifierString = serializeModifier(modifier); | |
504 result.add(modifierString == null ? EMPTY_JSON_DATA : modifierString ); | |
505 } | |
506 return result; | |
507 } | |
508 | |
509 private static String serializeModifier(PaymentDetailsModifier modifier) { | |
510 StringWriter stringWriter = new StringWriter(); | |
511 JsonWriter json = new JsonWriter(stringWriter); | |
512 try { | |
513 // {{{ | |
514 json.beginObject(); | |
515 | |
516 // total {{{ | |
517 json.name("total"); | |
518 serializePaymentItem(modifier.total, json); | |
519 // }}} total | |
520 | |
521 // supportedMethods {{{ | |
522 json.name("supportedMethods").beginArray(); | |
523 for (String method : modifier.methodData.supportedMethods) { | |
524 json.value(method); | |
525 } | |
526 json.endArray(); | |
527 // }}} supportedMethods | |
528 | |
529 json.endObject(); | |
530 // }}} | |
531 } catch (IOException e) { | |
532 return null; | |
533 } | |
534 return stringWriter.toString(); | |
535 } | |
536 | |
493 @Override | 537 @Override |
494 public void onIntentCompleted(WindowAndroid window, int resultCode, Intent d ata) { | 538 public void onIntentCompleted(WindowAndroid window, int resultCode, Intent d ata) { |
495 ThreadUtils.assertOnUiThread(); | 539 ThreadUtils.assertOnUiThread(); |
496 window.removeIntentCallback(this); | 540 window.removeIntentCallback(this); |
497 if (data == null || data.getExtras() == null || resultCode != Activity.R ESULT_OK) { | 541 if (data == null || data.getExtras() == null || resultCode != Activity.R ESULT_OK) { |
498 mInstrumentDetailsCallback.onInstrumentDetailsError(); | 542 mInstrumentDetailsCallback.onInstrumentDetailsError(); |
499 } else { | 543 } else { |
500 String details = data.getExtras().getString(EXTRA_RESPONSE_DETAILS); | 544 String details = data.getExtras().getString(EXTRA_RESPONSE_DETAILS); |
501 if (details == null) { | 545 if (details == null) { |
502 details = data.getExtras().getString(EXTRA_DEPRECATED_RESPONSE_I NSTRUMENT_DETAILS); | 546 details = data.getExtras().getString(EXTRA_DEPRECATED_RESPONSE_I NSTRUMENT_DETAILS); |
503 } | 547 } |
504 if (details == null) { | 548 if (details == null) { |
505 details = EMPTY_JSON_DATA; | 549 details = EMPTY_JSON_DATA; |
506 } | 550 } |
507 mInstrumentDetailsCallback.onInstrumentDetailsReady( | 551 mInstrumentDetailsCallback.onInstrumentDetailsReady( |
508 data.getExtras().getString(EXTRA_RESPONSE_METHOD_NAME), deta ils); | 552 data.getExtras().getString(EXTRA_RESPONSE_METHOD_NAME), deta ils); |
509 } | 553 } |
510 mInstrumentDetailsCallback = null; | 554 mInstrumentDetailsCallback = null; |
511 } | 555 } |
512 | 556 |
513 @Override | 557 @Override |
514 public void dismissInstrument() {} | 558 public void dismissInstrument() {} |
515 } | 559 } |
OLD | NEW |