1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_PAYMENTS_PAYMENTS_WINDOW_MANAGER_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_PAYMENTS_PAYMENTS_WINDOW_MANAGER_H_
#include <optional>
#include <string>
#include "base/functional/callback.h"
#include "components/autofill/core/browser/data_model/payments/bnpl_issuer.h"
#include "components/autofill/core/browser/data_model/payments/credit_card.h"
#include "components/autofill/core/browser/payments/card_unmask_challenge_option.h"
#include "url/gurl.h"
namespace autofill::payments {
// Interface for objects that manage popup-related redirect flows for payments
// autofill, with different implementations meant to handle different operating
// systems.
class PaymentsWindowManager {
public:
using RedirectCompletionResult =
base::StrongAlias<class RedirectCompletionResultTag, std::string>;
// The result of the VCN 3DS authentication.
enum class Vcn3dsAuthenticationResult {
// The authentication was a success.
kSuccess = 0,
// The authentication was a failure. If the authentication failed inside of
// the pop-up, the reason for the failure is unknown to Chrome, and can be
// due to any of several possible reasons. Some reasons can be that the user
// failed to authenticate, or there is a server error. This can also mean
// the authentication failed during the Payments server call to retrieve the
// card after the pop-up has closed.
kAuthenticationFailed = 1,
// The authentication did not complete. This occurs if the user closes the
// pop-up before finishing the authentication, and there are no query
// params. This can also occur if the user cancels any of the dialogs during
// the flow.
kAuthenticationNotCompleted = 2,
};
// The response fields for a VCN 3DS authentication, created once the flow is
// complete and a response to the caller is required.
struct Vcn3dsAuthenticationResponse {
Vcn3dsAuthenticationResponse();
Vcn3dsAuthenticationResponse(const Vcn3dsAuthenticationResponse&);
Vcn3dsAuthenticationResponse(Vcn3dsAuthenticationResponse&&);
Vcn3dsAuthenticationResponse& operator=(
const Vcn3dsAuthenticationResponse&);
Vcn3dsAuthenticationResponse& operator=(Vcn3dsAuthenticationResponse&&);
~Vcn3dsAuthenticationResponse();
// The result of the VCN 3DS authentication.
Vcn3dsAuthenticationResult result;
// CreditCard representation of the data returned in the response of the
// UnmaskCardRequest after a VCN 3DS authentication has completed. Only
// present if `result` is a success.
std::optional<CreditCard> card;
};
// The current status inside the BNPL pop-up.
enum class BnplPopupStatus {
// The user successfully finished the flow inside of the pop-up.
kSuccess = 0,
// The user failed the flow inside of the pop-up.
kFailure = 1,
// The user has not yet finished the flow inside of the pop-up.
kNotFinished = 2,
};
// The result of the BNPL flow, which will be sent to the caller that
// initiated the flow.
//
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
//
// LINT.IfChange(BnplFlowResult)
enum class BnplFlowResult {
// The BNPL flow was successful.
kSuccess = 0,
// The BNPL flow failed.
kFailure = 1,
// The user closed the pop-up which ended the BNPL flow.
kUserClosed = 2,
kMaxValue = kUserClosed,
};
// LINT.ThenChange(/tools/metrics/histograms/metadata/autofill/enums.xml:BnplPopupWindowResult)
using OnVcn3dsAuthenticationCompleteCallback =
base::OnceCallback<void(Vcn3dsAuthenticationResponse)>;
using OnBnplPopupClosedCallback =
base::OnceCallback<void(BnplFlowResult, GURL)>;
// The contextual data required for the VCN 3DS flow.
struct Vcn3dsContext {
Vcn3dsContext();
Vcn3dsContext(Vcn3dsContext&&);
Vcn3dsContext& operator=(Vcn3dsContext&&);
~Vcn3dsContext();
// The virtual card that is currently being authenticated with a VCN 3DS
// authentication flow.
CreditCard card;
// The context token that was returned from the Payments Server for the
// ongoing VCN authentication flow.
std::string context_token;
// The risk data that must be sent to the Payments Server during a VCN 3DS
// card unmask request.
std::string risk_data;
// The challenge option that was returned from the server which contains
// details required for the VCN 3DS authentication flow.
CardUnmaskChallengeOption challenge_option;
// Callback that will be run when the VCN 3DS authentication completed.
OnVcn3dsAuthenticationCompleteCallback completion_callback;
// Boolean that denotes whether the user already provided consent for the
// VCN 3DS authentication pop-up. If false, user consent must be achieved
// before triggering a VCN 3DS authentication pop-up.
bool user_consent_already_given = false;
};
// The contextual data required for the BNPL flow.
struct BnplContext {
BnplContext();
BnplContext(BnplContext&&);
BnplContext& operator=(BnplContext&&);
~BnplContext();
// The ID of the issuer for the BNPL flow.
autofill::BnplIssuer::IssuerId issuer_id;
// The starting location of the BNPL flow, which is an initial URL to
// open inside of the pop-up.
GURL initial_url;
// The URL prefix that denotes the user successfully finished the flow
// inside of the pop-up. This parameter will be used to match against each
// URL navigation inside of the pop-up, and if the window manager observes
// `success_url_prefix` inside of the pop-up, it will close the pop-up
// automatically.
GURL success_url_prefix;
// The URL prefix that denotes the user failed the flow inside of the
// pop-up. This parameter will be used to match against each URL navigation
// inside of the pop-up, and if the window manager observes the
// `failure_url_prefix` inside of the pop-up, it will close the pop-up
// automatically.
GURL failure_url_prefix;
// The callback to run to notify the caller that the flow inside of the
// pop-up was finished, with the result.
OnBnplPopupClosedCallback completion_callback;
};
virtual ~PaymentsWindowManager() = default;
// Initiates the VCN 3DS auth flow. All fields in `context` must be valid and
// non-empty.
virtual void InitVcn3dsAuthentication(Vcn3dsContext context) = 0;
// Initiates the BNPL flow. All fields in `context` must be valid and
// non-empty.
virtual void InitBnplFlow(BnplContext context) = 0;
};
} // namespace autofill::payments
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PAYMENTS_PAYMENTS_WINDOW_MANAGER_H_
|