| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 org.chromium.content_public.browser.WebContents; | 7 import org.chromium.content_public.browser.WebContents; |
| 8 import org.chromium.payments.mojom.PaymentDetailsModifier; | 8 import org.chromium.payments.mojom.PaymentDetailsModifier; |
| 9 import org.chromium.payments.mojom.PaymentItem; | 9 import org.chromium.payments.mojom.PaymentItem; |
| 10 import org.chromium.payments.mojom.PaymentMethodData; | 10 import org.chromium.payments.mojom.PaymentMethodData; |
| 11 | 11 |
| 12 import java.util.Collections; | 12 import java.util.Collections; |
| 13 import java.util.HashSet; | 13 import java.util.HashSet; |
| 14 import java.util.List; | 14 import java.util.List; |
| 15 import java.util.Map; | 15 import java.util.Map; |
| 16 import java.util.Set; | 16 import java.util.Set; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * This instrument class represents a single payment option for a service | 19 * This instrument class represents a single payment instrument for a service |
| 20 * worker based payment app. | 20 * worker based payment app. |
| 21 * | 21 * |
| 22 * @see org.chromium.chrome.browser.payments.ServiceWorkerPaymentApp | 22 * @see org.chromium.chrome.browser.payments.ServiceWorkerPaymentApp |
| 23 * | 23 * |
| 24 * @see https://w3c.github.io/webpayments-payment-apps-api/ | 24 * @see https://w3c.github.io/webpayments-payment-handler/ |
| 25 */ | 25 */ |
| 26 public class ServiceWorkerPaymentInstrument extends PaymentInstrument { | 26 public class ServiceWorkerPaymentInstrument extends PaymentInstrument { |
| 27 private final WebContents mWebContents; | 27 private final WebContents mWebContents; |
| 28 private final long mAppRegistrationId; | 28 private final long mSWRegistrationId; |
| 29 private final ServiceWorkerPaymentAppBridge.Option mOption; | 29 private final String mInstrumentId; |
| 30 private final Set<String> mMethodNames; | 30 private final Set<String> mMethodNames; |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Build a service worker based payment instrument based on a single payment
option | 33 * Build a service worker based payment instrument. |
| 34 * of an installed payment app. | |
| 35 * | 34 * |
| 36 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-opti
ons | 35 * @see https://w3c.github.io/webpayments-payment-apps-api/#payment-app-opti
ons |
| 37 * | 36 * |
| 38 * @param webContents The web contents where PaymentRequest was invoke
d. | 37 * @param webContents The web contents where PaymentRequest was invoke
d. |
| 39 * @param appRegistrationId The registration id of the corresponding service
worker payment app. | 38 * @param swRegistrationId The registration id of the corresponding service
worker payment app. |
| 40 * @param option A payment app option from the payment app. | 39 * @param instrumentId The unique id of the payment instrument. |
| 40 * @param label The label of the payment instrument. |
| 41 * @param methodNames A set of payment method names supported by the p
ayment instrument. |
| 41 */ | 42 */ |
| 42 public ServiceWorkerPaymentInstrument(WebContents webContents, long appRegis
trationId, | 43 public ServiceWorkerPaymentInstrument(WebContents webContents, long swRegist
rationId, |
| 43 ServiceWorkerPaymentAppBridge.Option option) { | 44 String instrumentId, String label, Set<String> methodNames) { |
| 44 super(Long.toString(appRegistrationId) + "#" + option.id, option.label,
null /* icon */, | 45 super(Long.toString(swRegistrationId) + "#" + instrumentId, label, null
/* sublabel */, |
| 45 option.icon); | 46 null /* icon */); |
| 46 mWebContents = webContents; | 47 mWebContents = webContents; |
| 47 mAppRegistrationId = appRegistrationId; | 48 mSWRegistrationId = swRegistrationId; |
| 48 mOption = option; | 49 mInstrumentId = instrumentId; |
| 49 | 50 mMethodNames = methodNames; |
| 50 mMethodNames = new HashSet<String>(option.enabledMethods); | |
| 51 } | 51 } |
| 52 | 52 |
| 53 @Override | 53 @Override |
| 54 public Set<String> getInstrumentMethodNames() { | 54 public Set<String> getInstrumentMethodNames() { |
| 55 return Collections.unmodifiableSet(mMethodNames); | 55 return Collections.unmodifiableSet(mMethodNames); |
| 56 } | 56 } |
| 57 | 57 |
| 58 @Override | 58 @Override |
| 59 public void invokePaymentApp(String id, String merchantName, String origin,
String iframeOrigin, | 59 public void invokePaymentApp(String id, String merchantName, String origin,
String iframeOrigin, |
| 60 byte[][] unusedCertificateChain, Map<String, PaymentMethodData> meth
odData, | 60 byte[][] unusedCertificateChain, Map<String, PaymentMethodData> meth
odData, |
| 61 PaymentItem total, List<PaymentItem> displayItems, | 61 PaymentItem total, List<PaymentItem> displayItems, |
| 62 Map<String, PaymentDetailsModifier> modifiers, InstrumentDetailsCall
back callback) { | 62 Map<String, PaymentDetailsModifier> modifiers, InstrumentDetailsCall
back callback) { |
| 63 ServiceWorkerPaymentAppBridge.invokePaymentApp(mWebContents, mAppRegistr
ationId, mOption.id, | 63 ServiceWorkerPaymentAppBridge.invokePaymentApp(mWebContents, mSWRegistra
tionId, |
| 64 origin, iframeOrigin, new HashSet<>(methodData.values()), total,
displayItems, | 64 mInstrumentId, origin, iframeOrigin, new HashSet<>(methodData.va
lues()), total, |
| 65 new HashSet<>(modifiers.values()), callback); | 65 displayItems, new HashSet<>(modifiers.values()), callback); |
| 66 } | 66 } |
| 67 | 67 |
| 68 @Override | 68 @Override |
| 69 public void dismissInstrument() {} | 69 public void dismissInstrument() {} |
| 70 } | 70 } |
| OLD | NEW |