Skip to content

Commit

Permalink
ChromeOS Payments: move types to chromeos/components
Browse files Browse the repository at this point in the history
The various mojom types used by PaymentAppInstance are now
defined in chromeos/components, so they can be used by Crosapi.

The structs and unions are now declared as stable. They are otherwise
unchanged.

Design doc:
https://bit.ly/3W0jIgp

Bug: 1385989
Change-Id: I2ac3d287abaff9582101b0b7d406fe9e0a4a2b84
Test: With additional CLs, payment request from Lacros is passed to ARC via Ash, and launches ARC popup.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4167440
Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Zentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1102805}
  • Loading branch information
ericwilligers authored and Chromium LUCI CQ committed Feb 8, 2023
1 parent c73310c commit b0cafa1
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 188 deletions.
1 change: 1 addition & 0 deletions ash/components/arc/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+chromeos/components/payments",
"+chromeos/version",
# TODO(b/129295708): Remove after move is complete.
"+components/arc",
Expand Down
1 change: 1 addition & 0 deletions ash/components/arc/mojom/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ mojom("mojom") {
"//ash/components/arc/mojom:media",
"//ash/components/arc/mojom:notifications",
"//ash/components/arc/mojom:oemcrypto",
"//chromeos/components/payments/mojom",
"//chromeos/components/sensors/mojom:mojom",
"//components/digital_goods/mojom",
"//components/payments/mojom:mojom",
Expand Down
124 changes: 6 additions & 118 deletions ash/components/arc/mojom/payment_app.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -6,119 +6,7 @@

module arc.mojom;

// After the browser calls IsPaymentImplemented(), ARC sends back this result
// if there are no errors.
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.
union IsPaymentImplementedResult {
IsPaymentImplementedValidResult valid;
string error;
};

// The common payment parameters for the browser to pass 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.
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;
};

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

// After the browser calls InvokePaymentApp(), ARC sends back this result, if
// there are no errors.
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.
union InvokePaymentAppResult {
InvokePaymentAppValidResult valid;
string error;
};
import "chromeos/components/payments/mojom/payment_app_types.mojom";

// The service that runs in ARC and allows the browser to invoke the TWA payment
// app that is installed in ARC, if it implements payment intents as described
Expand Down Expand Up @@ -149,15 +37,15 @@ interface PaymentAppInstance {
// services, because this method may be invoked when off the record, e.g.,
// incognito mode or guest mode.
IsPaymentImplemented@0(string package_name)
=> (IsPaymentImplementedResult response);
=> (chromeos.payments.mojom.IsPaymentImplementedResult response);

// Forwards the request to IsReadyToPayServiceHelper.query(), which queries
// the payment app. The payment app should return true if payments can be
// made. This should not be invoked when off the record, e.g., incognito mode
// or guest mode.
[MinVersion=1]
IsReadyToPay@1(PaymentParameters parameters)
=> (IsReadyToPayResult response);
IsReadyToPay@1(chromeos.payments.mojom.PaymentParameters parameters)
=> (chromeos.payments.mojom.IsReadyToPayResult response);

// Forwards the request to WebPaymentIntentHelper.createPayIntent() and fires
// the resulting intent. This invokes the payment flow.
Expand All @@ -168,8 +56,8 @@ interface PaymentAppInstance {
// The total amount for createPayIntent() should always be "0" with currency
// "ZZZ".
[MinVersion=2]
InvokePaymentApp@2(PaymentParameters parameters)
=> (InvokePaymentAppResult response);
InvokePaymentApp@2(chromeos.payments.mojom.PaymentParameters parameters)
=> (chromeos.payments.mojom.InvokePaymentAppResult response);

// Requests to abort a previous payment flow (identified by |request_token|)
// which was opened with InvokePaymentApp().
Expand Down
18 changes: 11 additions & 7 deletions ash/components/arc/pay/arc_payment_app_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,39 @@ void ArcPaymentAppBridge::IsPaymentImplemented(
mojom::PaymentAppInstance* payment_app = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->payment_app(), IsPaymentImplemented);
if (!payment_app) {
std::move(callback).Run(mojom::IsPaymentImplementedResult::NewError(
kUnableToConnectErrorMessage));
std::move(callback).Run(
chromeos::payments::mojom::IsPaymentImplementedResult::NewError(
kUnableToConnectErrorMessage));
return;
}

payment_app->IsPaymentImplemented(package_name, std::move(callback));
}

void ArcPaymentAppBridge::IsReadyToPay(mojom::PaymentParametersPtr parameters,
IsReadyToPayCallback callback) {
void ArcPaymentAppBridge::IsReadyToPay(
chromeos::payments::mojom::PaymentParametersPtr parameters,
IsReadyToPayCallback callback) {
mojom::PaymentAppInstance* payment_app = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->payment_app(), IsReadyToPay);
if (!payment_app) {
std::move(callback).Run(
mojom::IsReadyToPayResult::NewError(kUnableToConnectErrorMessage));
chromeos::payments::mojom::IsReadyToPayResult::NewError(
kUnableToConnectErrorMessage));
return;
}

payment_app->IsReadyToPay(std::move(parameters), std::move(callback));
}

void ArcPaymentAppBridge::InvokePaymentApp(
mojom::PaymentParametersPtr parameters,
chromeos::payments::mojom::PaymentParametersPtr parameters,
InvokePaymentAppCallback callback) {
mojom::PaymentAppInstance* payment_app = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->payment_app(), InvokePaymentApp);
if (!payment_app) {
std::move(callback).Run(
mojom::InvokePaymentAppResult::NewError(kUnableToConnectErrorMessage));
chromeos::payments::mojom::InvokePaymentAppResult::NewError(
kUnableToConnectErrorMessage));
return;
}

Expand Down
20 changes: 11 additions & 9 deletions ash/components/arc/pay/arc_payment_app_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "ash/components/arc/mojom/payment_app.mojom.h"
#include "base/functional/callback_forward.h"
#include "chromeos/components/payments/mojom/payment_app_types.mojom.h"
#include "components/keyed_service/core/keyed_service.h"

namespace content {
Expand All @@ -22,12 +23,12 @@ class ArcBridgeService;
// Invokes the TWA payment app.
class ArcPaymentAppBridge : public KeyedService {
public:
using IsPaymentImplementedCallback =
base::OnceCallback<void(mojom::IsPaymentImplementedResultPtr)>;
using IsReadyToPayCallback =
base::OnceCallback<void(mojom::IsReadyToPayResultPtr)>;
using InvokePaymentAppCallback =
base::OnceCallback<void(mojom::InvokePaymentAppResultPtr)>;
using IsPaymentImplementedCallback = base::OnceCallback<void(
chromeos::payments::mojom::IsPaymentImplementedResultPtr)>;
using IsReadyToPayCallback = base::OnceCallback<void(
chromeos::payments::mojom::IsReadyToPayResultPtr)>;
using InvokePaymentAppCallback = base::OnceCallback<void(
chromeos::payments::mojom::InvokePaymentAppResultPtr)>;
using AbortPaymentAppCallback = base::OnceCallback<void(bool)>;

// Returns the instance owned by the given BrowserContext, or nullptr if the
Expand All @@ -54,12 +55,13 @@ class ArcPaymentAppBridge : public KeyedService {

// Queries the TWA payment app whether it is able to perform a payment. Should
// not be invoked when off the record, e.g., incognito mode or guest mode.
void IsReadyToPay(mojom::PaymentParametersPtr parameters,
void IsReadyToPay(chromeos::payments::mojom::PaymentParametersPtr parameters,
IsReadyToPayCallback callback);

// Invokes the TWA payment app flow.
void InvokePaymentApp(mojom::PaymentParametersPtr parameters,
InvokePaymentAppCallback callback);
void InvokePaymentApp(
chromeos::payments::mojom::PaymentParametersPtr parameters,
InvokePaymentAppCallback callback);

// Aborts an existing TWA payment app flow.
void AbortPaymentApp(const std::string& request_token,
Expand Down

0 comments on commit b0cafa1

Please sign in to comment.