PaymentRequest Class

A payment request (https://w3c.github.io/payment-request/#paymentrequest-interface): the page describes the accepted payment methods and the details of the payment, and PaymentRequest.Show shows the payment sheet of the user agent. The payment handlers and the payment sheet are the ones of the user agent UI backend (BrowsingContextOptions.UserAgentUI, see UserAgentUIBackend.HasPaymentHandlerAsync and UserAgentUIBackend.ShowPaymentSheetAsync): without a backend, no payment method is supported. The constructor throws a SecurityError DomException when the document is not allowed to use the payment feature (its default allowlist is 'self').

public sealed class PaymentRequest : EventTarget
Inheritance
EventTarget PaymentRequest

Constructors

NameDescription
PaymentRequest(Window, IReadOnlyList<PaymentMethodData>, PaymentDetailsInit, PaymentOptions?)Creates a payment request for a window (https://w3c.github.io/payment-request/#constructor): the payment methods are validated (a TypeErrorException when there is none, a RangeErrorException for an invalid or duplicate identifier), their data is serialized to JSON, and the amounts are checked (a RangeErrorException for a currency code that is not well-formed, a TypeErrorException for an invalid or negative total value).
PaymentRequest(IReadOnlyList<PaymentMethodData>, PaymentDetailsInit, PaymentOptions?)Creates a payment request for the current window (https://w3c.github.io/payment-request/#constructor).

PaymentRequest overloads

PaymentRequest(Window, IReadOnlyList<PaymentMethodData>, PaymentDetailsInit, PaymentOptions?)

PaymentRequest.cs

Creates a payment request for a window (https://w3c.github.io/payment-request/#constructor): the payment methods are validated (a TypeErrorException when there is none, a RangeErrorException for an invalid or duplicate identifier), their data is serialized to JSON, and the amounts are checked (a RangeErrorException for a currency code that is not well-formed, a TypeErrorException for an invalid or negative total value).

public PaymentRequest(Window window, IReadOnlyList<PaymentMethodData> methodData, PaymentDetailsInit details, PaymentOptions? options = null)
Parameters
window Window
The window of the request.
methodData IReadOnlyList<PaymentMethodData>
The accepted payment methods.
details PaymentDetailsInit
The details of the payment.
options PaymentOptions?
The information to collect.

PaymentRequest(IReadOnlyList<PaymentMethodData>, PaymentDetailsInit, PaymentOptions?)

PaymentRequest.cs

Creates a payment request for the current window (https://w3c.github.io/payment-request/#constructor).

public PaymentRequest(IReadOnlyList<PaymentMethodData> methodData, PaymentDetailsInit details, PaymentOptions? options = null)

Properties

NameDescription
IdGets the identifier of the request: the one given by the page, or a unique identifier generated by the user agent.
OnPaymentMethodChangeGets or sets the event handler of the paymentmethodchange event.
OnShippingAddressChangeGets or sets the event handler of the shippingaddresschange event.
OnShippingOptionChangeGets or sets the event handler of the shippingoptionchange event.
ShippingAddressGets the shipping address chosen by the user (without the members that identify the recipient while the sheet is shown), or null.
ShippingOptionGets the identifier of the selected shipping option, or null.
ShippingTypeGets the kind of address collected when the request requests shipping, or null.

Gets the identifier of the request: the one given by the page, or a unique identifier generated by the user agent.

public string Id { get; }

OnPaymentMethodChange

PaymentRequest.cs

Gets or sets the event handler of the paymentmethodchange event.

public Action<Event>? OnPaymentMethodChange { get; set; }

OnShippingAddressChange

PaymentRequest.cs

Gets or sets the event handler of the shippingaddresschange event.

public Action<Event>? OnShippingAddressChange { get; set; }

OnShippingOptionChange

PaymentRequest.cs

Gets or sets the event handler of the shippingoptionchange event.

public Action<Event>? OnShippingOptionChange { get; set; }

ShippingAddress

PaymentRequest.cs

Gets the shipping address chosen by the user (without the members that identify the recipient while the sheet is shown), or null.

public ContactAddress? ShippingAddress { get; }

ShippingOption

PaymentRequest.cs

Gets the identifier of the selected shipping option, or null.

public string? ShippingOption { get; }

ShippingType

PaymentRequest.cs

Gets the kind of address collected when the request requests shipping, or null.

public PaymentShippingType? ShippingType { get; }

Methods

NameDescription
Abort()Aborts the request while the payment sheet is shown (https://w3c.github.io/payment-request/#abort-method): the sheet is closed and the task of PaymentRequest.Show fails with an AbortError DomException. The task fails with an InvalidStateError when the request is not shown or a payment is being retried.
CanMakePayment()Returns whether the user agent supports one of the payment methods (https://w3c.github.io/payment-request/#can-make-payment-algorithm), as answered by UserAgentUIBackend.HasPaymentHandlerAsync. The task fails with an InvalidStateError DomException when the request was shown or the document is not fully active.
GetSecurePaymentConfirmationCapabilities()Returns the capabilities of Secure Payment Confirmation (https://w3c.github.io/secure-payment-confirmation/#sctn-secure-payment-confirmation-capabilities), sorted by key: browserBoundKeyHardware is false (the browser bound keys are software keys).
SecurePaymentConfirmationAvailability()Returns whether Secure Payment Confirmation is available in the current document (https://w3c.github.io/secure-payment-confirmation/#sctn-secure-payment-confirmation-available-api): it is not enabled when the backend has no payment handler for secure-payment-confirmation (UserAgentUIBackend.HasPaymentHandlerAsync), and it needs the payment feature and a user-verifying platform authenticator. The availability is unknown in a document that is not fully active.
Show(Task<PaymentDetailsUpdate>?)Shows the payment sheet (https://w3c.github.io/payment-request/#show-method): the task completes with the response of the user once they accept the payment. It fails with a SecurityError DomException when the window has no transient activation (which is consumed), an InvalidStateError when the document is not fully active or the request was already shown, an AbortError when the document is hidden, another payment sheet is shown in the tab, the user dismisses the sheet or the page aborts the request, and a NotSupportedError when the user agent supports none of the payment methods. detailsPromise updates the details once settled.

Aborts the request while the payment sheet is shown (https://w3c.github.io/payment-request/#abort-method): the sheet is closed and the task of PaymentRequest.Show fails with an AbortError DomException. The task fails with an InvalidStateError when the request is not shown or a payment is being retried.

public Task Abort()

CanMakePayment()

PaymentRequest.cs

Returns whether the user agent supports one of the payment methods (https://w3c.github.io/payment-request/#can-make-payment-algorithm), as answered by UserAgentUIBackend.HasPaymentHandlerAsync. The task fails with an InvalidStateError DomException when the request was shown or the document is not fully active.

public Task<bool> CanMakePayment()

GetSecurePaymentConfirmationCapabilities()

PaymentRequest.SecurePaymentConfirmation.cs

Returns the capabilities of Secure Payment Confirmation (https://w3c.github.io/secure-payment-confirmation/#sctn-secure-payment-confirmation-capabilities), sorted by key: browserBoundKeyHardware is false (the browser bound keys are software keys).

public static Task<IReadOnlyList<KeyValuePair<string, bool>>> GetSecurePaymentConfirmationCapabilities()

SecurePaymentConfirmationAvailability()

PaymentRequest.SecurePaymentConfirmation.cs

Returns whether Secure Payment Confirmation is available in the current document (https://w3c.github.io/secure-payment-confirmation/#sctn-secure-payment-confirmation-available-api): it is not enabled when the backend has no payment handler for secure-payment-confirmation (UserAgentUIBackend.HasPaymentHandlerAsync), and it needs the payment feature and a user-verifying platform authenticator. The availability is unknown in a document that is not fully active.

public static Task<SecurePaymentConfirmationAvailability> SecurePaymentConfirmationAvailability()

Show(Task<PaymentDetailsUpdate>?)

PaymentRequest.cs

Shows the payment sheet (https://w3c.github.io/payment-request/#show-method): the task completes with the response of the user once they accept the payment. It fails with a SecurityError DomException when the window has no transient activation (which is consumed), an InvalidStateError when the document is not fully active or the request was already shown, an AbortError when the document is hidden, another payment sheet is shown in the tab, the user dismisses the sheet or the page aborts the request, and a NotSupportedError when the user agent supports none of the payment methods. detailsPromise updates the details once settled.

public Task<PaymentResponse> Show(Task<PaymentDetailsUpdate>? detailsPromise = null)