chromium/chromeos/components/payments/mojom/payment_app_types.mojom

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module chromeos.payments.mojom;

import "mojo/public/mojom/base/unguessable_token.mojom";

// These types are used by PaymentAppInstance methods. ARC implements
// PaymentAppInstance and invokes payments apps. Ash exposes a
// PaymentAppInstance over Crosapi, forwarding all requests to ARC.

// After the browser calls IsPaymentImplemented(), ARC sends back this result
// if there are no errors.
[Stable]
struct IsPaymentImplementedValidResult {
  // The list of activities with intent filter for
  // org.chromium.intent.action.PAY action and "https://play.google.com/billing"
  // in either "org.chromium.default_payment_method_name" or
  // "org.chromium.payment_method_names" metadata. Other payment methods are
  // ignored for now.
  // Example activity name: "com.example.app.PaymentActivity".
  array<string> activity_names;

  // The list of services with intent filter for
  // org.chromium.intent.action.IS_READY_TO_PAY. Example service name:
  // "com.example.app.IsReadyToPayService".
  array<string> service_names;
};

// After the browser calls IsPaymentImplemented(), ARC sends back this result.
[Stable]
union IsPaymentImplementedResult {
  IsPaymentImplementedValidResult valid;
  string error;
};

// The common payment parameters for the browser to pass from Lacros or Ash
// to ARC in both PaymentAppInstance.IsReadyToPayService() and
// PaymentAppInstance.InvokePaymentApp() Mojo methods. ARC will forward this
// data to either WebPaymentIntentHelper.createIsReadyToPayIntent() or
// WebPaymentIntentHelper.createPayIntent(), depending on which method of
// PaymentApp Mojo IPC service was invoked.
//
// WebPaymentIntentHelper in ARC should be used only with the
// "https://play.google.com/billing" payment method identifier at this time.
[Stable]
struct PaymentParameters {
  // The TWA package name, e.g., "com.example.app". This is the "String
  // packageName" parameter to createIsReadyToPayIntent() and createPayIntent()
  // methods.
  string package_name;

  // The name of the IS_READY_TO_PAY service to query or PAY activity to invoke,
  // depending on whether this struct is passed into IsReadyToPay() or
  // InvokePaymentApp() method. For example,
  // "com.example.app.IsReadyToPayService" or "com.example.app.PaymentActivity".
  // This is the "String serviceName" parameter to createIsReadyToPayIntent() or
  // "String activityName" parameter to createPayIntent().
  string activity_or_service_name;

  // The JSON serialization of the JavaScript object "data" in the
  // PaymentRequest API. For example:
  //
  //  {"productId": "test_product_id"}
  //
  // This string is serialized in Blink and is parsed in the TWA. The browser
  // does not parse this string. This string goes into the value of the
  // "methodDataMap" parameter of createIsReadyToPayIntent() and
  // createPayIntent() methods, i.e.:
  //
  //  methodDataMap.put("https://play.google.com/billing",
  //                    new PaymentMethodData("https://play.google.com/billing",
  //                                          stringified_method_data));
  string stringified_method_data;

  // (Host, optional port) tuple that cannot be an opaque origin. For example:
  // "shop.com". This is the "String schemelessOrigin" parameter to
  // createIsReadyToPayIntent() and createPayIntent() methods.
  string top_level_origin;

  // (Host, optional port) tuple that cannot be an opaque origin. For
  // example: "payment-service-provider.com". This is the "String
  // schemelessIframeOrigin" parameter to createIsReadyToPayIntent() and
  // createPayIntent() methods.
  string payment_request_origin;

  // The free-form identifier for this pending transaction as set either by the
  // merchant website in PaymentRequest() constructor in JavaScript, or (more
  // commonly) a browser-generated GUID string. This is the "String id"
  // parameter to createPayIntent() method. The createIsReadyToPayIntent() does
  // not currently need this parameter.
  [MinVersion=2]
  string? payment_request_id;

  // Opaque, browser-generated identifier for this payment request. Used to
  // identify a particular request across calls.
  [MinVersion=3]
  string? request_token;

  // Opaque app instance identifier for this payment request. Used to
  // identify which TWA instance made this request so that we can attach
  // the payment dialog to the correct window. This value should only be
  // created in Lacros and used in Ash. It is expected for ARC to
  // receive a null twa_instance_identifier. If the Ash side receives a
  // null twa_instance_identifier, the payment app would not be
  // invoked because we will not be able to find an app window to attach
  // the payment dialog to.
  // Please see chromeos/components/payments/mojom/payment_app.mojom for
  // explanation of relationship between Lacros, Ash and ARC for payment
  // interfaces.
  [MinVersion=4]
  mojo_base.mojom.UnguessableToken? twa_instance_identifier;
};

// After the browser calls IsReadyToPay(), ARC sends back this result.
[Stable]
union IsReadyToPayResult {
  bool response;
  string error;
};

// After the browser calls InvokePaymentApp(), ARC sends back this result, if
// there are no errors.
[Stable]
struct InvokePaymentAppValidResult {
  // Whether the intent return status is Activity.RESULT_OK.
  bool is_activity_result_ok;

  // The JSON serialization of a JavaScript object that's the response to
  // PaymentRequest API. For example:
  //
  //  {"receiptIdentifier": "test_receipt_identifier"}
  //
  // This string is serialized in TWA and is parsed in Blink. The browser does
  // not parse this string.
  string stringified_details;
};

// After the browser calls InvokePaymentApp(), ARC sends back this result.
[Stable]
union InvokePaymentAppResult {
  InvokePaymentAppValidResult valid;
  string error;
};