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
methodDataList<PaymentMethodData>detailsPaymentDetailsInitoptionsPaymentOptions
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.
Onpaymentmethodchange
[Value("onpaymentmethodchange")]
public EventHandlerNonNull Onpaymentmethodchange { get; set; }
Property Value
Onshippingaddresschange
[Value("onshippingaddresschange")]
public EventHandlerNonNull Onshippingaddresschange { get; set; }
Property Value
Onshippingoptionchange
[Value("onshippingoptionchange")]
public EventHandlerNonNull Onshippingoptionchange { get; set; }
Property Value
ShippingAddress
IMPORTANT
DeprecatedshippingAddress read-only property ofthe '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
DeprecatedshippingOption 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 "selected" 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.
ShippingType
IMPORTANT
DeprecatedshippingType read-only property of thePaymentRequest interface returns one of
"shipping","delivery", "pickup", or null if one was notprovided by the constructor.
[Value("shippingType")]
public PaymentShippingType? ShippingType { get; }
Property Value
- PaymentShippingType?
One of
"shipping","delivery","pickup", ornull.
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 methodcanMakePayment() 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't be processed, the promise receives a value offalse.NOTE
If you call this too often, the browser may reject the
returned promise with aDOMException.
Remarks
You can call this before calling
Show(Task<PaymentDetailsUpdate>) to provide a streamlined user experience
when the user's browser can'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't, you could fall back to
another payment method, or offer a list of methods that aren't handled by Payment
Request API (or even provide instructions for paying by mail or by phone).
-'PaymentRequest.Show'
IsSecurePaymentConfirmationAvailable()
[Value("isSecurePaymentConfirmationAvailable")]
public static Task<bool> IsSecurePaymentConfirmationAvailable()
Returns
Show(Task<PaymentDetailsUpdate>)
The 'PaymentRequest' interface'sshow() 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
detailsPromiseTask<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
"Pay" button in the browser's payment sheet).
Remarks
Only one payment request can be in the process of being handled at once, across all
documents. Once one PaymentRequest's show() method has been
called, any other call to show() will by rejected with anAbortError 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't be done, some browsers, including Firefox, support multiple active payment
requests at a time.
If your architecture doesn't necessarily have all of the data ready to go at the moment
it instantiates the payment interface by calling show(), specify thedetailsPromise 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 useasync/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)