# Virtual Cards diagrams

The following sequence diagrams show how a user, Google, and the Payment
Integrator interact to provide the following
[Virtual Cards](https://developers.google.com/pay/virtual-cards-v1/support/faq#expandable-1)
functionalities:

- [Enrollment](https://developers.google.com/pay/virtual-cards-v1/reference/vcn-sequence-diagrams#enrollment)
- [Retrieval](https://developers.google.com/pay/virtual-cards-v1/reference/vcn-sequence-diagrams#retrieval)
- [Unenrollment](https://developers.google.com/pay/virtual-cards-v1/reference/vcn-sequence-diagrams#unenrollment)
- [Transaction management](https://developers.google.com/pay/virtual-cards-v1/reference/vcn-sequence-diagrams#transaction_management)

> [!NOTE]
> **Note:** The end-to-end process flow of a payment transaction using virtual card numbers is detailed on the [FAQ](https://developers.google.com/pay/virtual-cards-v1/support/faq#expandable-20).

## Enrollment

![Enrollment sequence diagram](https://developers.google.com/pay/virtual-cards-v1/images/sequence_diagrams/vcn_enrollment_chrome_android.png)

[Virtual Cards enrollment](https://developers.google.com/pay/virtual-cards-v1/support/faq#expandable-5)
is executed only once during the lifetime of a virtual card number (VCN). The
enrollment can be initiated in different ways: when (i) user saves the payment
information during checkout for the first time (upstream enrollment), (ii) user
makes a purchase online with a non-virtual card (downstream enrollment) or
(iii) user enables the virtual card number at
[pay.google.com](http://pay.google.com).

After the enrollment is initiated by the user, Google Pay Autofill returns
the Terms of Service (ToS) and asks the user for consent to proceed. If consent
is obtained, Google calls the
[`enroll`](https://developers.google.com/pay/virtual-cards-v1/payment-integrator-virtual-cards-api/enroll) API,
including `requestId`, `cardToEnroll` and `riskSignals` so that the
[Integrator can decide](https://developers.google.com/pay/virtual-cards-v1/payment-integrator-virtual-cards-api/enroll#response-body)
on whether or not to allow the enrollment. If the enrollment succeeds, a virtual
card number option is shown in Google Pay Autofill during checkout.

## Retrieval

After the
[enrollment](https://developers.google.com/pay/virtual-cards-v1/reference/vcn-sequence-diagrams#enrollment),
whenever the user selects a virtual card number in Google Pay Autofill the
[retrieval](https://developers.google.com/pay/virtual-cards-v1/reference/vcn-sequence-diagrams#retrieval)
flow is initiated as illustrated below
(****green path****).

![Retrieval sequence diagram Green Path](https://developers.google.com/pay/virtual-cards-v1/images/sequence_diagrams/vcn_retrieval_with_green_path.png)

As illustrated, after the virtual card selection, Google calls the
[`retrieveVirtualCardNumber`](https://developers.google.com/pay/virtual-cards-v1/payment-integrator-virtual-cards-api/retrieveVirtualCardNumber)
API including `enrollmentRequestId` (equal to `requestId` sent in the
enrollment), `merchantDetails` and `riskSignals` so that the Integrator can
assess the context of the virtual card number request and decide to:

- **accept (**green path**)**, by returning the virtual card number (diagram above),
- **step up (**yellow path**)**, using an available Identity \& Verification (ID\&V) method, or
- **decline (**red path**)** the request.

> [!NOTE]
> **Note:** Google does not store retrieved virtual cards number for subsequent checkouts; a new [retrieval](https://developers.google.com/pay/virtual-cards-v1/reference/vcn-sequence-diagrams#retrieval) flow is executed. Further details on the [FAQ page](https://developers.google.com/pay/virtual-cards-v1/support/faq#expandable-22).

> [!NOTE]
> **Note:** The Integrator controls the scope of the returned virtual card number, for instance, single-use, multiple-use or merchant-bound Virtual Cards.

****Yellow**** and
****red**** path flows are shown in the
next sections.

### Yellow path retrieval

> [!NOTE]
> **Note:** The **Platform Authenticator** ID\&V method has priority over other returned ID\&V methods.

****Yellow path**** retrieval flow
adopting the **Platform Authenticator** ID\&V method is illustrated in the next
sequence diagram. In this example, given the Integrator returns both
`platformAuthentication` and `smsOtp` as
[`challengeOptions`](https://developers.google.com/pay/virtual-cards-v1/payment-integrator-virtual-cards-api/retrieveVirtualCardNumber#challengerequireddeclinedresult),
Google prioritizes `platformAuthentication` and, consequently, does not show
ID\&V selector UI.

![Retrieval sequence diagram Platform Auth](https://developers.google.com/pay/virtual-cards-v1/images/sequence_diagrams/vcn_retrieval_with_plat_sms_idv.png)

****Yellow path**** with **SMS OTP** ID\&V
method is shown below. Note that in this case Google calls the
[`sendOtp`](https://developers.google.com/pay/virtual-cards-v1/payment-integrator-virtual-cards-api/sendOtp)
API to request the Integrator to send an OTP to the user. The OTP delivery
happens 'out of band' from Google perspective. Once the user receives the OTP
from the Integrator, it can enter its value in Google Pay Autofill.

![Retrieval sequence diagram OTP](https://developers.google.com/pay/virtual-cards-v1/images/sequence_diagrams/vcn_retrieval_with_sms_idv.png)

### Red path retrieval

****Red path**** retrieval flow is
represented below. In this case the Integrator decides to decline the virtual
card number request.

![Retrieval sequence diagram Red Path](https://developers.google.com/pay/virtual-cards-v1/images/sequence_diagrams/vcn_retrieval_with_red_path.png)

## Unenrollment

Enrolled Virtual Cards can be unenrolled as illustrated in the diagram
below. Google calls the
[`unenroll`](https://developers.google.com/pay/virtual-cards-v1/payment-integrator-virtual-cards-api/unenroll)
API including `enrollmentRequestId` whose value is equal to `requestId` sent in
the corresponding enrollment.

![Unenrollment sequence diagram](https://developers.google.com/pay/virtual-cards-v1/images/sequence_diagrams/vcn_unenrollment_chrome_android.png)

## Transaction management

[Virtual Cards transactions](https://developers.google.com/pay/virtual-cards-v1/support/faq#expandable-8)
are also provided by the Integrator as shown by the following diagram:

![Transaction sequence diagram](https://developers.google.com/pay/virtual-cards-v1/images/sequence_diagrams/vcn_transaction_management.png)

Initially, the Integrator notifies Google using the
[`transactionEventNotification`](https://developers.google.com/pay/virtual-cards-v1/google-virtual-cards-api/transactionEventNotification)
API, indicating that a transaction event occurred for an enrolled virtual card.
In turn, Google calls
[`getTransactions`](https://developers.google.com/pay/virtual-cards-v1/payment-integrator-virtual-cards-api/getTransactions)
to retrieve a list of transactions for the given virtual card number.

The `transactionListContinuationToken` field can be provided to limit the
returned transactions to those that have been added or updated since the request
represented by this token. If the token is not provided, the response should
include all transactions for the maximum period prior to the request.