From ae2bc3da2a5c0f7db9a9d89c5bb3b768a987fbbb Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 20 Mar 2017 08:00:18 -0700 Subject: [PATCH] paymentrequest: Deprecate. Now provided by '--lib dom' (#14784) --- paymentrequest/index.d.ts | 108 ----------------------- paymentrequest/paymentrequest-tests.ts | 116 ------------------------- paymentrequest/tsconfig.json | 24 ----- 3 files changed, 248 deletions(-) delete mode 100644 paymentrequest/index.d.ts delete mode 100644 paymentrequest/paymentrequest-tests.ts delete mode 100644 paymentrequest/tsconfig.json diff --git a/paymentrequest/index.d.ts b/paymentrequest/index.d.ts deleted file mode 100644 index 5231f53bc3..0000000000 --- a/paymentrequest/index.d.ts +++ /dev/null @@ -1,108 +0,0 @@ -// Type definitions for PaymentRequest -// Project: https://www.w3.org/TR/payment-request/ -// Definitions by: Adam Cmiel , Eiji Kitamura -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -interface PaymentRequest extends EventTarget { - new (methodData: PaymentMethodData[], details: PaymentDetails, options?: PaymentOptions): PaymentRequest; - show(): PromiseLike; - abort(): PromiseLike; - canMakePayment(): Promise; - readonly paymentRequestID: string; - readonly shippingAddress?: PaymentAddress; - readonly shippingOption?: string; - readonly shippingType?: string; - onshippingaddresschange: PaymentUpdateEventListener; - onshippingoptionchange: PaymentUpdateEventListener; -} - -interface PaymentMethodData { - supportedMethods: string[]; - data?: { - supportedNetworks: string[]; - supportedTypes: string[]; - }; -} - -interface PaymentCurrencyAmount { - currency: string; - value: string; - currencySystem?:string; -} - -interface PaymentDetails { - total: PaymentItem; - displayItems?: PaymentItem[]; - shippingOptions?: PaymentShippingOption[]; - modifiers?: PaymentDetailsModifier[]; - error?: string; -} - -interface PaymentDetailsModifier { - supportedMethods: string[]; - total?: PaymentItem; - additionalDisplayItems?: PaymentItem[]; - data?: Object; -} - -interface PaymentOptions { - requestShipping?: boolean; - requestPayerEmail?: boolean; - requestPayerPhone?: boolean; - requestPayerName?: boolean; - shippingType?: 'shipping' | 'delivery' | 'pickup'; -} - -interface PaymentItem { - label: string; - amount: PaymentCurrencyAmount; - pending?: boolean; -} - -interface PaymentAddress { - readonly country: string; - readonly addressLine: string[]; - readonly region: string; - readonly city: string; - readonly dependentLocality: string; - readonly postalCode: string; - readonly sortingCode: string; - readonly languageCode: string; - readonly organization: string; - readonly recipient: string; - readonly phone: string; -} - -interface PaymentShippingOption { - id: string; - label: string; - amount: PaymentCurrencyAmount; - selected?: boolean; -} - -interface PaymentResponse { - readonly paymentRequestID: string; - readonly methodName: string; - readonly details: Object; - readonly shippingAddress?: PaymentAddress; - readonly shippingOption?: string; - readonly payerEmail?: string; - readonly payerPhone?: string; - readonly payerName?: string; - - complete(result?: '' | 'success' | 'fail'): PromiseLike; - toJSON(): Object; -} - -interface PaymentUpdateEventListener extends EventListener { - (evt: PaymentRequestUpdateEvent): void; -} - -interface PaymentRequestUpdateEvent extends Event { - updateWith(d: PromiseLike): void; -} - -interface Window { - PaymentRequest?: PaymentRequest; -} - diff --git a/paymentrequest/paymentrequest-tests.ts b/paymentrequest/paymentrequest-tests.ts deleted file mode 100644 index c8772b115c..0000000000 --- a/paymentrequest/paymentrequest-tests.ts +++ /dev/null @@ -1,116 +0,0 @@ -/// Code examples derived from -/// https://developers.google.com/web/fundamentals/discovery-and-monetization/payment-request/ - -async function makeRequest() { - if (!window.PaymentRequest) { - return Promise.reject(new Error("PaymentRequest not available")) - } - - const methodData = [ - { - supportedMethods: ["visa", "mastercard"] - } - ] - - const details: PaymentDetails = { - displayItems: [ - { - label: "Original donation amount", - amount: { currency: "USD", value : "65.00" }, // US$65.00 - }, - { - label: "Friends and family discount", - amount: { currency: "USD", value : "-10.00" }, // -US$10.00 - } - ], - total: { - label: "Total", - amount: { currency: "USD", value : "55.00" }, // US$55.00 - } - } - - const options: PaymentOptions = { - requestShipping: true, - requestPayerEmail: true, - requestPayerPhone: true, - requestPayerName: true, - shippingType: 'delivery' - } - - const request = new window.PaymentRequest(methodData, details, options) - request.addEventListener("shippingaddresschange", (e: any) => { - e.updateWith(((details, addr) => { - if (addr.country === 'US') { - var shippingOption = { - id: '', - label: '', - amount: {currency: 'USD', value: '0.00'}, - selected: true - }; - if (addr.region === 'US') { - shippingOption.id = 'us'; - shippingOption.label = 'Standard shipping in US'; - shippingOption.amount.value = '0.00'; - details.total.amount.value = '55.00'; - } else { - shippingOption.id = 'others'; - shippingOption.label = 'International shipping'; - shippingOption.amount.value = '10.00'; - details.total.amount.value = '65.00'; - } - if (details.displayItems.length === 2) { - details.displayItems.splice(1, 0, shippingOption); - } else { - details.displayItems.splice(1, 1, shippingOption); - } - - details.shippingOptions = [shippingOption]; - } else { - details.shippingOptions = []; - } - return Promise.resolve(details); - })(details, request.shippingAddress)); - }) - - let canMakePayment = await request.canMakePayment() - if (canMakePayment) { - return request.show() - } else { - throw 'can not make payment on this environment.' - } -} - -async function processPayment(): Promise { - let paymentResponse: PaymentResponse; - try { - paymentResponse = await makeRequest() - } catch (error) { - location.href = '/checkout'; - return; - } - - var paymentData = { - // payment method string - method: paymentResponse.methodName, - // payment details as you requested - details: paymentResponse.details, - // shipping address information - address: paymentResponse.shippingAddress, - // shipping option - shippingOption: paymentResponse.shippingOption - } - - // make call to backend to process payment data - const ok = await Promise.resolve(true) - - if (ok) { - paymentResponse.complete("success") - } else { - paymentResponse.complete("fail") - } -} - -function onShippingAddressChange(e: any) { -} - -document.querySelector("#pay").addEventListener("click", processPayment) diff --git a/paymentrequest/tsconfig.json b/paymentrequest/tsconfig.json deleted file mode 100644 index e5754a139a..0000000000 --- a/paymentrequest/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6", - "dom" - ], - "target": "es6", - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "paymentrequest-tests.ts" - ] -} \ No newline at end of file