Skip to content

Add Payment Request types #937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 63 additions & 6 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ interface AddEventListenerOptions extends EventListenerOptions {
passive?: boolean;
}

interface AddressErrors {
addressLine?: string;
city?: string;
country?: string;
dependentLocality?: string;
organization?: string;
phone?: string;
postalCode?: string;
recipient?: string;
region?: string;
sortingCode?: string;
}

interface AesCbcParams extends Algorithm {
iv: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer;
}
Expand Down Expand Up @@ -940,9 +953,14 @@ interface PannerOptions extends AudioNodeOptions {
rolloffFactor?: number;
}

interface PayerErrors {
email?: string;
name?: string;
phone?: string;
}

interface PaymentCurrencyAmount {
currency: string;
currencySystem?: string;
value: string;
}

Expand All @@ -966,6 +984,9 @@ interface PaymentDetailsModifier {

interface PaymentDetailsUpdate extends PaymentDetailsBase {
error?: string;
payerErrors?: PayerErrors;
paymentMethodErrors?: any;
shippingAddressErrors?: AddressErrors;
total?: PaymentItem;
}

Expand All @@ -975,17 +996,23 @@ interface PaymentItem {
pending?: boolean;
}

interface PaymentMethodChangeEventInit extends PaymentRequestUpdateEventInit {
methodDetails?: any;
methodName?: string;
}

interface PaymentMethodData {
data?: any;
supportedMethods: string | string[];
}

interface PaymentOptions {
requestBillingAddress?: boolean;
requestPayerEmail?: boolean;
requestPayerName?: boolean;
requestPayerPhone?: boolean;
requestShipping?: boolean;
shippingType?: string;
shippingType?: PaymentShippingType;
}

interface PaymentRequestUpdateEventInit extends EventInit {
Expand All @@ -998,6 +1025,13 @@ interface PaymentShippingOption {
selected?: boolean;
}

interface PaymentValidationErrors {
error?: string;
payer?: PayerErrors;
paymentMethod?: any;
shippingAddress?: AddressErrors;
}

interface Pbkdf2Params extends Algorithm {
hash: HashAlgorithmIdentifier;
iterations: number;
Expand Down Expand Up @@ -4668,6 +4702,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad
createEvent(eventInterface: "OfflineAudioCompletionEvent"): OfflineAudioCompletionEvent;
createEvent(eventInterface: "OverflowEvent"): OverflowEvent;
createEvent(eventInterface: "PageTransitionEvent"): PageTransitionEvent;
createEvent(eventInterface: "PaymentMethodChangeEvent"): PaymentMethodChangeEvent;
createEvent(eventInterface: "PaymentRequestUpdateEvent"): PaymentRequestUpdateEvent;
createEvent(eventInterface: "PermissionRequestedEvent"): PermissionRequestedEvent;
createEvent(eventInterface: "PointerEvent"): PointerEvent;
Expand Down Expand Up @@ -4918,6 +4953,7 @@ interface DocumentEvent {
createEvent(eventInterface: "OfflineAudioCompletionEvent"): OfflineAudioCompletionEvent;
createEvent(eventInterface: "OverflowEvent"): OverflowEvent;
createEvent(eventInterface: "PageTransitionEvent"): PageTransitionEvent;
createEvent(eventInterface: "PaymentMethodChangeEvent"): PaymentMethodChangeEvent;
createEvent(eventInterface: "PaymentRequestUpdateEvent"): PaymentRequestUpdateEvent;
createEvent(eventInterface: "PermissionRequestedEvent"): PermissionRequestedEvent;
createEvent(eventInterface: "PointerEvent"): PointerEvent;
Expand Down Expand Up @@ -11378,11 +11414,10 @@ declare var Path2D: {

/** This Payment Request API interface is used to store shipping or payment address information. */
interface PaymentAddress {
readonly addressLine: string[];
readonly addressLine: ReadonlyArray<string>;
readonly city: string;
readonly country: string;
readonly dependentLocality: string;
readonly languageCode: string;
readonly organization: string;
readonly phone: string;
readonly postalCode: string;
Expand All @@ -11397,22 +11432,34 @@ declare var PaymentAddress: {
new(): PaymentAddress;
};

interface PaymentMethodChangeEvent extends PaymentRequestUpdateEvent {
readonly methodDetails: any;
readonly methodName: string;
}

declare var PaymentMethodChangeEvent: {
prototype: PaymentMethodChangeEvent;
new(type: string, eventInitDict?: PaymentMethodChangeEventInit): PaymentMethodChangeEvent;
};

interface PaymentRequestEventMap {
"paymentmethodchange": Event;
"shippingaddresschange": Event;
"shippingoptionchange": Event;
}

/** This Payment Request API interface is the primary access point into the API, and lets web content and apps accept payments from the end user. */
interface PaymentRequest extends EventTarget {
readonly id: string;
onpaymentmethodchange: ((this: PaymentRequest, ev: Event) => any) | null;
onshippingaddresschange: ((this: PaymentRequest, ev: Event) => any) | null;
onshippingoptionchange: ((this: PaymentRequest, ev: Event) => any) | null;
readonly shippingAddress: PaymentAddress | null;
readonly shippingOption: string | null;
readonly shippingType: PaymentShippingType | null;
abort(): Promise<void>;
canMakePayment(): Promise<boolean>;
show(): Promise<PaymentResponse>;
show(detailsPromise: PaymentDetailsUpdate | Promise<PaymentDetailsUpdate>): Promise<PaymentResponse>;
addEventListener<K extends keyof PaymentRequestEventMap>(type: K, listener: (this: PaymentRequest, ev: PaymentRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof PaymentRequestEventMap>(type: K, listener: (this: PaymentRequest, ev: PaymentRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
Expand All @@ -11434,18 +11481,28 @@ declare var PaymentRequestUpdateEvent: {
new(type: string, eventInitDict?: PaymentRequestUpdateEventInit): PaymentRequestUpdateEvent;
};

interface PaymentResponseEventMap {
"payerdetailchange": Event;
}

/** This Payment Request API interface is returned after a user selects a payment method and approves a payment request. */
interface PaymentResponse {
interface PaymentResponse extends EventTarget {
readonly details: any;
readonly methodName: string;
onpayerdetailchange: ((this: PaymentResponse, ev: Event) => any) | null;
readonly payerEmail: string | null;
readonly payerName: string | null;
readonly payerPhone: string | null;
readonly requestId: string;
readonly shippingAddress: PaymentAddress | null;
readonly shippingOption: string | null;
complete(result?: PaymentComplete): Promise<void>;
retry(errorFields?: PaymentValidationErrors): Promise<void>;
toJSON(): any;
addEventListener<K extends keyof PaymentResponseEventMap>(type: K, listener: (this: PaymentResponse, ev: PaymentResponseEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof PaymentResponseEventMap>(type: K, listener: (this: PaymentResponse, ev: PaymentResponseEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}

declare var PaymentResponse: {
Expand Down
188 changes: 188 additions & 0 deletions inputfiles/idl/Payment Request.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
[SecureContext, Exposed=Window]
interface PaymentRequest : EventTarget {
constructor(
sequence<PaymentMethodData> methodData,
PaymentDetailsInit details,
optional PaymentOptions options = {}
);
[NewObject]
Promise<PaymentResponse> show(optional Promise<PaymentDetailsUpdate> detailsPromise);
[NewObject]
Promise<undefined> abort();
[NewObject]
Promise<boolean> canMakePayment();

readonly attribute DOMString id;
readonly attribute PaymentAddress? shippingAddress;
readonly attribute DOMString? shippingOption;
readonly attribute PaymentShippingType? shippingType;

attribute EventHandler onshippingaddresschange;
attribute EventHandler onshippingoptionchange;
attribute EventHandler onpaymentmethodchange;
};

dictionary PaymentMethodData {
required DOMString supportedMethods;
object data;
};

dictionary PaymentCurrencyAmount {
required DOMString currency;
required DOMString value;
};

dictionary PaymentDetailsBase {
sequence<PaymentItem> displayItems;
sequence<PaymentShippingOption> shippingOptions;
sequence<PaymentDetailsModifier> modifiers;
};

dictionary PaymentDetailsInit : PaymentDetailsBase {
DOMString id;
required PaymentItem total;
};

dictionary PaymentDetailsUpdate : PaymentDetailsBase {
DOMString error;
PaymentItem total;
AddressErrors shippingAddressErrors;
PayerErrors payerErrors;
object paymentMethodErrors;
};

dictionary PaymentDetailsModifier {
required DOMString supportedMethods;
PaymentItem total;
sequence<PaymentItem> additionalDisplayItems;
object data;
};

enum PaymentShippingType {
"shipping",
"delivery",
"pickup"
};

dictionary PaymentOptions {
boolean requestPayerName = false;
boolean requestBillingAddress = false;
boolean requestPayerEmail = false;
boolean requestPayerPhone = false;
boolean requestShipping = false;
PaymentShippingType shippingType = "shipping";
};

dictionary PaymentItem {
required DOMString label;
required PaymentCurrencyAmount amount;
boolean pending = false;
};

[SecureContext, Exposed=(Window)]
interface PaymentAddress {
[Default] object toJSON();
readonly attribute DOMString city;
readonly attribute DOMString country;
readonly attribute DOMString dependentLocality;
readonly attribute DOMString organization;
readonly attribute DOMString phone;
readonly attribute DOMString postalCode;
readonly attribute DOMString recipient;
readonly attribute DOMString region;
readonly attribute DOMString sortingCode;
readonly attribute FrozenArray<DOMString> addressLine;
};

dictionary AddressInit {
DOMString country = "";
sequence<DOMString> addressLine = [];
DOMString region = "";
DOMString city = "";
DOMString dependentLocality = "";
DOMString postalCode = "";
DOMString sortingCode = "";
DOMString organization = "";
DOMString recipient = "";
DOMString phone = "";
};

dictionary AddressErrors {
DOMString addressLine;
DOMString city;
DOMString country;
DOMString dependentLocality;
DOMString organization;
DOMString phone;
DOMString postalCode;
DOMString recipient;
DOMString region;
DOMString sortingCode;
};

dictionary PaymentShippingOption {
required DOMString id;
required DOMString label;
required PaymentCurrencyAmount amount;
boolean selected = false;
};

enum PaymentComplete {
"fail",
"success",
"unknown"
};

[SecureContext, Exposed=Window]
interface PaymentResponse : EventTarget {
[Default] object toJSON();

readonly attribute DOMString requestId;
readonly attribute DOMString methodName;
readonly attribute object details;
readonly attribute PaymentAddress? shippingAddress;
readonly attribute DOMString? shippingOption;
readonly attribute DOMString? payerName;
readonly attribute DOMString? payerEmail;
readonly attribute DOMString? payerPhone;

[NewObject]
Promise<undefined> complete(optional PaymentComplete result = "unknown");
[NewObject]
Promise<undefined> retry(optional PaymentValidationErrors errorFields = {});

attribute EventHandler onpayerdetailchange;
};

dictionary PaymentValidationErrors {
PayerErrors payer;
AddressErrors shippingAddress;
DOMString error;
object paymentMethod;
};

dictionary PayerErrors {
DOMString email;
DOMString name;
DOMString phone;
};

[SecureContext, Exposed=Window]
interface PaymentMethodChangeEvent : PaymentRequestUpdateEvent {
constructor(DOMString type, optional PaymentMethodChangeEventInit eventInitDict = {});
readonly attribute DOMString methodName;
readonly attribute object? methodDetails;
};

dictionary PaymentMethodChangeEventInit : PaymentRequestUpdateEventInit {
DOMString methodName = "";
object? methodDetails = null;
};

[SecureContext, Exposed=Window]
interface PaymentRequestUpdateEvent : Event {
constructor(DOMString type, optional PaymentRequestUpdateEventInit eventInitDict = {});
undefined updateWith(Promise<PaymentDetailsUpdate> detailsPromise);
};

dictionary PaymentRequestUpdateEventInit : EventInit {};
4 changes: 4 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@
"url": "https://www.w3.org/TR/push-api/",
"title": "Push"
},
{
"url": "https://w3c.github.io/payment-request/",
"title": "Payment Request"
},
{
"url": "https://www.w3.org/TR/referrer-policy/",
"title": "Referrer Policy"
Expand Down