Table of Contents

Class PaymentRequest

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The Payment Request API's PaymentRequest interface is the primary access point into the API, and lets web content and apps accept payments from the end user on behalf of the operator of the site or the publisher of the app.

[Value("PaymentRequest")]
public class PaymentRequest : EventTarget
Inheritance
PaymentRequest
Inherited Members

Remarks

Constructors

PaymentRequest()

public PaymentRequest()

PaymentRequest(List<PaymentMethodData>, PaymentDetailsInit, PaymentOptions)

The PaymentRequest() constructor
creates a new PaymentRequest object which will be used to handle the
process of generating, validating, and submitting a payment request.

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

Parameters

methodData List<PaymentMethodData>
details PaymentDetailsInit
options PaymentOptions

Remarks

Properties

Id

The id read-only attribute of the
PaymentRequest interface returns a unique identifier for a particular
PaymentRequest instance.

[Value("id")]
public string Id { get; }

Property Value

string

A string.

Remarks

When constructing an instance of the PaymentRequest, you are able to
supply an custom id. If none is provided, the browser automatically sets the id value to a UUID.

See also on MDN

Onpaymentmethodchange

[Value("onpaymentmethodchange")]
public EventHandlerNonNull Onpaymentmethodchange { get; set; }

Property Value

EventHandlerNonNull

Onshippingaddresschange

[Value("onshippingaddresschange")]
public EventHandlerNonNull Onshippingaddresschange { get; set; }

Property Value

EventHandlerNonNull

Onshippingoptionchange

[Value("onshippingoptionchange")]
public EventHandlerNonNull Onshippingoptionchange { get; set; }

Property Value

EventHandlerNonNull

ShippingAddress

IMPORTANT
Deprecated
The shippingAddress read-only property of
the 'PaymentRequest' interface returns the shipping address provided by the
user. It is null by default.
[Value("shippingAddress")]
public ContactAddress? ShippingAddress { get; }

Property Value

ContactAddress

A 'PaymentAddress' object or null.

Remarks

ShippingOption

IMPORTANT
Deprecated
The shippingOption read-only attribute of the 'PaymentRequest' interface returns either the id of a selected shipping option, null (if no shipping option was set to be selected) or a shipping option selected by the user.
It is initially null by when no &quot;selected&quot; shipping options are provided.
[Value("shippingOption")]
public string? ShippingOption { get; }

Property Value

string

An object or null.

Remarks

This attribute is only populated if the constructor is called with the requestShipping flag set to true.
If requestShipping was false (or missing), shippingOption returns null, even the developer provides a selected a shipping option.

See also on MDN

ShippingType

IMPORTANT
Deprecated
The shippingType read-only property of the
PaymentRequest interface returns one of &quot;shipping&quot;,
&quot;delivery&quot;, &quot;pickup&quot;, or null if one was not
provided by the constructor.
[Value("shippingType")]
public PaymentShippingType? ShippingType { get; }

Property Value

PaymentShippingType?

One of &quot;shipping&quot;, &quot;delivery&quot;, &quot;pickup&quot;, or
null.

Remarks

Methods

Abort()

The PaymentRequest.abort() method of the 'PaymentRequest'
interface causes the user agent to end the payment request and to remove any user
interface that might be shown.

[Value("abort")]
public Task<GlobalObject.Undefined> Abort()

Returns

Task<GlobalObject.Undefined>

None ('undefined').

Remarks

CanMakePayment()

The PaymentRequest method
canMakePayment() determines whether or not the request
is configured in a way that is compatible with at least one payment method supported
by the user agent.

[Value("canMakePayment")]
public Task<bool> CanMakePayment()

Returns

Task<bool>

A Promise to a boolean value that resolves to true
if the user agent supports any of the payment methods supplied when instantiating the
request using the 'PaymentRequest.PaymentRequest'
constructor. If the payment can&apos;t be processed, the promise receives a value of
false.

NOTE
If you call this too often, the browser may reject the
returned promise with a DOMException.

Remarks

You can call this before calling
Show(Task<PaymentDetailsUpdate>) to provide a streamlined user experience
when the user&apos;s browser can&apos;t handle any of the payment methods you accept.

For instance, you might call canMakePayment() to determine if the browser
will let the user pay using Payment Request API, and if it won&apos;t, you could fall back to
another payment method, or offer a list of methods that aren&apos;t handled by Payment
Request API (or even provide instructions for paying by mail or by phone).

-'PaymentRequest.Show'

See also on MDN

IsSecurePaymentConfirmationAvailable()

[Value("isSecurePaymentConfirmationAvailable")]
public static Task<bool> IsSecurePaymentConfirmationAvailable()

Returns

Task<bool>

Show(Task<PaymentDetailsUpdate>)

The 'PaymentRequest' interface&apos;s
show() method instructs the user agent to begin the
process of showing and handling the user interface for the payment request to the
user.

[Value("show")]
public Task<PaymentResponse> Show(Task<PaymentDetailsUpdate> detailsPromise = null)

Parameters

detailsPromise Task<PaymentDetailsUpdate>

Returns

Task<PaymentResponse>

A {{jsxref("Promise")}} that eventually resolves with a PaymentResponse.
The promise is resolved when the user accepts the payment request (such as by clicking a
&quot;Pay&quot; button in the browser&apos;s payment sheet).

Remarks

Only one payment request can be in the process of being handled at once, across all
documents. Once one PaymentRequest&apos;s show() method has been
called, any other call to show() will by rejected with an
AbortError until the returned promise has been concluded, either by being
fulfilled with a PaymentResponse indicating the results of the payment
request, or by being rejected with an error.

NOTE

In reality, despite the fact that the specification says this
can&apos;t be done, some browsers, including Firefox, support multiple active payment
requests at a time.

If your architecture doesn&apos;t necessarily have all of the data ready to go at the moment
it instantiates the payment interface by calling show(), specify the
detailsPromise parameter, providing a Promise that is
fulfilled once the data is ready. If this is provided, show() will not
allow the user to interact with the payment interface until the promise is fulfilled, so
that data can be updated prior to the user engaging with the payment process.

Processing the result and, if necessary, calling Retry(PaymentValidationErrors)
to retry a failed payment can all be done either asynchronously or synchronously,
depending on your needs. For the best user experience, asynchronous solutions are
typically the best way to go. Most examples on MDN and elsewhere use
async/await
to wait asynchronously while results are validated and so forth.

-Payment Request API
-Using the Payment Request API
-'PaymentRequest.Abort'
-PaymentResponse
-Retry(PaymentValidationErrors)
-Complete(PaymentComplete, PaymentCompleteDetails)

See also on MDN