From 8c81e77bba994dac74af898aa0197b4d7ec88a07 Mon Sep 17 00:00:00 2001 From: Dave Brudner <32269552+dbrudner@users.noreply.github.com> Date: Fri, 10 Jul 2020 12:10:01 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#45675=20Updates=20?= =?UTF-8?q?types=20for=20Recurly.js=20v4.13.0=20by=20@dbrudner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: dbrudner --- types/recurly__recurly-js/index.d.ts | 3 +- .../recurly__recurly-js/lib/bank-account.d.ts | 12 +-- types/recurly__recurly-js/lib/emitter.d.ts | 3 +- types/recurly__recurly-js/test/3d-secure.ts | 4 +- types/recurly__recurly-js/test/adyen.ts | 4 +- types/recurly__recurly-js/test/apple-pay.ts | 2 +- .../recurly__recurly-js/test/bank-account.ts | 57 +++++++++++- types/recurly__recurly-js/test/configure.ts | 2 +- types/recurly__recurly-js/test/elements.ts | 20 ++--- types/recurly__recurly-js/test/paypal.ts | 1 - .../test/pricing/checkout.ts | 89 ++++++++++++++++--- .../test/pricing/subscription.ts | 64 ++++++++++--- .../test/token/hosted-field.ts | 48 +++++----- 13 files changed, 234 insertions(+), 75 deletions(-) diff --git a/types/recurly__recurly-js/index.d.ts b/types/recurly__recurly-js/index.d.ts index 346f63fc74..d1185267f4 100644 --- a/types/recurly__recurly-js/index.d.ts +++ b/types/recurly__recurly-js/index.d.ts @@ -1,10 +1,9 @@ -// Type definitions for non-npm package recurly__recurly-js 4.12 +// Type definitions for non-npm package recurly__recurly-js 4.13 // Project: https://github.com/recurly/recurly-js // Definitions by: Dave Brudner // Chris Rogers // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.1 - import { Recurly } from './lib/recurly'; declare global { diff --git a/types/recurly__recurly-js/lib/bank-account.d.ts b/types/recurly__recurly-js/lib/bank-account.d.ts index 7f462028a7..6fdf027db1 100644 --- a/types/recurly__recurly-js/lib/bank-account.d.ts +++ b/types/recurly__recurly-js/lib/bank-account.d.ts @@ -2,12 +2,14 @@ import { RecurlyError } from './error'; import { TokenHandler } from './token'; export type BillingInfo = { - routing_number: string; - account_number: string; - account_number_confirmation: string; - account_type: string; - iban?: string; name_on_account: string; + routing_number?: string; + account_number?: string; + account_number_confirmation?: string; + account_type?: string; + sort_code?: string; + type?: string; + iban?: string; address1?: string; address2?: string; city?: string; diff --git a/types/recurly__recurly-js/lib/emitter.d.ts b/types/recurly__recurly-js/lib/emitter.d.ts index 6c9213a40c..133c047c5a 100644 --- a/types/recurly__recurly-js/lib/emitter.d.ts +++ b/types/recurly__recurly-js/lib/emitter.d.ts @@ -1,4 +1,5 @@ type Listener = (...args: any[]) => void; + interface Emitter { on(event: Event, listener: Listener): Emitter; once(event: Event, listener: Listener): Emitter; @@ -9,5 +10,5 @@ interface Emitter { } export { - Emitter + Emitter }; diff --git a/types/recurly__recurly-js/test/3d-secure.ts b/types/recurly__recurly-js/test/3d-secure.ts index bd81843db1..48909f29bd 100644 --- a/types/recurly__recurly-js/test/3d-secure.ts +++ b/types/recurly__recurly-js/test/3d-secure.ts @@ -1,9 +1,11 @@ export default function threeDSecure() { const risk = window.recurly.Risk(); const threeDSecure = risk.ThreeDSecure({ - actionTokenId: 'token', + actionTokenId: 'token' }); + // $ExpectError + threeDSecure.on('fake-event', () => {}); threeDSecure.on('token', () => {}); threeDSecure.on('error', () => {}); diff --git a/types/recurly__recurly-js/test/adyen.ts b/types/recurly__recurly-js/test/adyen.ts index 64f829e387..65fb10a306 100644 --- a/types/recurly__recurly-js/test/adyen.ts +++ b/types/recurly__recurly-js/test/adyen.ts @@ -1,13 +1,15 @@ export default function adyen() { const adyen = window.recurly.Adyen(); + // $ExpectError + adyen.on('fake-event', () => {}); adyen.on('token', () => {}); adyen.start({ invoiceUuid: 'invoice-uuid' }); adyen.start({ invoiceUuid: 'invoice-uuid', skinCode: 'skin-code', countryCode: 'PL', - shopperLocale: 'en_PL', + shopperLocale: 'en_PL' }); // $ExpectError diff --git a/types/recurly__recurly-js/test/apple-pay.ts b/types/recurly__recurly-js/test/apple-pay.ts index 75513adf8c..08072f63be 100644 --- a/types/recurly__recurly-js/test/apple-pay.ts +++ b/types/recurly__recurly-js/test/apple-pay.ts @@ -4,7 +4,7 @@ export default function applePay() { currency: 'USD', label: 'My Subscription', total: '29.00', - pricing: window.recurly.Pricing.Checkout(), + pricing: window.recurly.Pricing.Checkout() }); applePay.ready(() => {}); diff --git a/types/recurly__recurly-js/test/bank-account.ts b/types/recurly__recurly-js/test/bank-account.ts index 80ee77e490..17a08eed6f 100644 --- a/types/recurly__recurly-js/test/bank-account.ts +++ b/types/recurly__recurly-js/test/bank-account.ts @@ -13,16 +13,29 @@ export default function bankAccount() { } }); - window.recurly.bankAccount.token(formEl, (err, token) => { + const billingInfo = { + routing_number: '123456780', + account_number: '111111111', + account_number_confirmation: '111111111', + account_type: 'checking', + iban: '123', + name_on_account: 'Pat Smith', + address1: '123 Main St.', + address2: 'Unit 1', + city: 'Hope', + state: 'WA', + postal_code: '98552', + country: 'US', + vat_number: 'SE0000', + }; + + window.recurly.bankAccount.token(billingInfo, (err, token) => { if (err) { err.message; err.code; } else { token.id; token.type; - - // $ExpectError - token.fake; } }); @@ -47,4 +60,40 @@ export default function bankAccount() { token.type; } }); + + const minimalBacsBillingInfo = { + type: 'bacs', + account_number: "1234", + account_number_confirmation: "1234", + sort_code: "1234", + name_on_account: "1234" + }; + + window.recurly.bankAccount.token(minimalBacsBillingInfo, (err, token) => { + if (err) { + err.message; + err.code; + } else { + token.id; + token.type; + } + }); + + const missingNameOnAccountBacsBillingInfo = { + type: 'bacs', + account_number: "1234", + account_number_confirmation: "1234", + sort_code: "1234", + }; + + // $ExpectError + window.recurly.bankAccount.token(missingNameOnAccountBacsBillingInfo, (err, token) => { + if (err) { + err.message; + err.code; + } else { + token.id; + token.type; + } + }); } diff --git a/types/recurly__recurly-js/test/configure.ts b/types/recurly__recurly-js/test/configure.ts index 4e619217f8..e0338d8742 100644 --- a/types/recurly__recurly-js/test/configure.ts +++ b/types/recurly__recurly-js/test/configure.ts @@ -1,5 +1,5 @@ export default function configure() { - window.recurly.configure('ewr1-BrfKUWEllwCxdpRZvZloaJ'); + window.recurly.configure('my-public-key'); window.recurly.configure({ cors: true, currency: 'USD', diff --git a/types/recurly__recurly-js/test/elements.ts b/types/recurly__recurly-js/test/elements.ts index cd4a1245cc..af319ca16a 100644 --- a/types/recurly__recurly-js/test/elements.ts +++ b/types/recurly__recurly-js/test/elements.ts @@ -10,16 +10,16 @@ export default function elements() { fontWeight: 'bold', content: { number: 'Card number', - cvv: 'CVC', - }, + cvv: 'CVC' + } }, invalid: { - fontColor: 'red', - }, - }, + fontColor: 'red' + } + } }); - const elementStyle = { + const elementOptions = { format: true, inputType: 'text', tabIndex: '1', @@ -39,10 +39,10 @@ export default function elements() { } [ - elements.CardNumberElement(elementStyle), - elements.CardMonthElement(elementStyle), - elements.CardYearElement(elementStyle), - elements.CardCvvElement(elementStyle), + elements.CardNumberElement(elementOptions), + elements.CardMonthElement(elementOptions), + elements.CardYearElement(elementOptions), + elements.CardCvvElement(elementOptions) ].forEach(element => { element.attach('#recurly-elements'); element.on('attach', () => {}); diff --git a/types/recurly__recurly-js/test/paypal.ts b/types/recurly__recurly-js/test/paypal.ts index f46913ae26..f699eff97f 100644 --- a/types/recurly__recurly-js/test/paypal.ts +++ b/types/recurly__recurly-js/test/paypal.ts @@ -27,6 +27,5 @@ export default function paypal() { description: "description" } }); - paypal.destroy(); } diff --git a/types/recurly__recurly-js/test/pricing/checkout.ts b/types/recurly__recurly-js/test/pricing/checkout.ts index 05c331aea5..80f2348a91 100644 --- a/types/recurly__recurly-js/test/pricing/checkout.ts +++ b/types/recurly__recurly-js/test/pricing/checkout.ts @@ -4,7 +4,7 @@ export default function subscriptionPricing() { const el = document.querySelector('div'); if (el) { - checkoutPricing.attach(el); + checkoutPricing.attach(el); } checkoutPricing.attach('#my-pricing-form'); @@ -12,7 +12,7 @@ export default function subscriptionPricing() { checkoutPricing .address({ first_name: 'dave', - last_name: 'b', + last_name: 'b' }) .address({ first_name: 'dave', @@ -24,25 +24,25 @@ export default function subscriptionPricing() { postal_code: 'postal_code', country: 'country', phone: 'phone', - vat_number: 'vat_number', + vat_number: 'vat_number' }) .adjustment({ id: '0', amount: 1, quantity: 1, taxExempt: true, - taxCode: 'my-tax-code', + taxCode: 'my-tax-code' }) .adjustment({ itemCode: 'item', - quantity: 1, + quantity: 1 }) .coupon('my-coupon-code') .currency('USD') .giftCard('my-gift-card-code') .shippingAddress({ first_name: 'dave', - last_name: 'b', + last_name: 'b' }) .shippingAddress({ first_name: 'dave', @@ -54,18 +54,18 @@ export default function subscriptionPricing() { postal_code: 'postal_code', country: 'country', phone: 'phone', - vat_number: 'vat_number', + vat_number: 'vat_number' }) .tax({ - tax_code: 'tax_code', + tax_code: 'tax_code' }) .tax({ tax_code: 'tax_code', vat_number: 'vat_number', amounts: { now: 'now', - next: 'next', - }, + next: 'next' + } }) .then(x => x) .catch(e => { @@ -76,7 +76,7 @@ export default function subscriptionPricing() { }) .shippingAddress({ first_name: 'dave', - last_name: 'b', + last_name: 'b' }) .shippingAddress({ first_name: 'dave', @@ -88,18 +88,79 @@ export default function subscriptionPricing() { postal_code: 'postal_code', country: 'country', phone: 'phone', - vat_number: 'vat_number', + vat_number: 'vat_number' }) .tax({ - tax_code: 'digital', + tax_code: 'digital' }) .subscription( window.recurly.Pricing.Subscription() .plan('basic', { quantity: 1 }) - .done(), + .done() ) .then(x => x) .done(pricing => { + // $ExpectType string + pricing.price.now.items[0].addons; + // $ExpectType string + pricing.price.now.items[0].amount; + // $ExpectType string + pricing.price.now.items[0].id; + // $ExpectType string + pricing.price.now.items[0].plan; + // $ExpectType string + pricing.price.now.items[0].setupFee; + // $ExpectType string + pricing.price.now.items[0].type; + // $ExpectType string + pricing.price.now.subscriptions; + // $ExpectType string + pricing.price.now.adjustments; + // $ExpectType string + pricing.price.now.discount; + // $ExpectType string + pricing.price.now.subtotal; + // $ExpectType string + pricing.price.now.taxes; + // $ExpectType string + pricing.price.now.giftCard; + // $ExpectType string pricing.price.now.total; + // $ExpectType string + pricing.price.next.items[0].addons; + // $ExpectType string + pricing.price.next.items[0].amount; + // $ExpectType string + pricing.price.next.items[0].id; + // $ExpectType string + pricing.price.next.items[0].plan; + // $ExpectType string + pricing.price.next.items[0].setupFee; + // $ExpectType string + pricing.price.next.items[0].type; + // $ExpectType string + pricing.price.next.subscriptions; + // $ExpectType string + pricing.price.next.adjustments; + // $ExpectType string + pricing.price.next.discount; + // $ExpectType string + pricing.price.next.subtotal; + // $ExpectType string + pricing.price.next.taxes; + // $ExpectType string + pricing.price.next.giftCard; + // $ExpectType string + pricing.price.next.total; + // $ExpectType string + pricing.price.currency.code; + // $ExpectType string + pricing.price.currency.symbol; + // $ExpectType string + pricing.price.taxes[0].rate; + // $ExpectType string + pricing.price.taxes[0].region; + // $ExpectType string + pricing.price.taxes[0].tax_type; }); } diff --git a/types/recurly__recurly-js/test/pricing/subscription.ts b/types/recurly__recurly-js/test/pricing/subscription.ts index 5208a504e4..add42b677c 100644 --- a/types/recurly__recurly-js/test/pricing/subscription.ts +++ b/types/recurly__recurly-js/test/pricing/subscription.ts @@ -1,11 +1,11 @@ -export default function checkoutPricing() { +export default function subscriptionPricing() { window.recurly.Pricing.Subscription() .plan('basic', { quantity: 1 }) .then(x => x) .addon('addon1', { quantity: 2 }) .address({ first_name: 'dave', - last_name: 'b', + last_name: 'b' }) .address({ first_name: 'dave', @@ -17,11 +17,11 @@ export default function checkoutPricing() { postal_code: 'postal_code', country: 'country', phone: 'phone', - vat_number: 'vat_number', + vat_number: 'vat_number' }) .shippingAddress({ first_name: 'dave', - last_name: 'b', + last_name: 'b' }) .shippingAddress({ first_name: 'dave', @@ -33,34 +33,76 @@ export default function checkoutPricing() { postal_code: 'postal_code', country: 'country', phone: 'phone', - vat_number: 'vat_number', + vat_number: 'vat_number' }) .coupon('coupon') .currency('USD') .giftcard('giftcard') .tax({ - tax_code: 'tax_code', + tax_code: 'tax_code' }) .tax({ tax_code: 'tax_code', vat_number: 'vat_number', amounts: { now: 'now', - next: 'next', - }, + next: 'next' + } }) .catch(e => { e.code; e.classification; e.message; e.name; - - // $ExpectError - e.fake; }) .done(pricing => { if (pricing) { + // $ExpectType string + pricing.price.now.subtotal; + // $ExpectType string + pricing.price.now.plan; + // $ExpectType string + pricing.price.now.addons; + // $ExpectType string + pricing.price.now.setup_fee; + // $ExpectType string + pricing.price.now.discount; + // $ExpectType string + pricing.price.now.tax; + // $ExpectType string pricing.price.now.total; + // $ExpectType string + pricing.price.next.subtotal; + // $ExpectType string + pricing.price.next.plan; + // $ExpectType string + pricing.price.next.addons; + // $ExpectType string + pricing.price.next.setup_fee; + // $ExpectType string + pricing.price.next.discount; + // $ExpectType string + pricing.price.next.tax; + // $ExpectType string + pricing.price.next.total; + // $ExpectType string + pricing.price.base.plan.unit; + // $ExpectType string + pricing.price.base.plan.setup_fee; + // $ExpectType string + pricing.price.base.addons.myAddon; + // $ExpectType string + pricing.price.addons.myAddon; + // $ExpectType string + pricing.price.currency.code; + // $ExpectType string + pricing.price.currency.symbol; + // $ExpectType string + pricing.price.taxes[0].rate; + // $ExpectType string + pricing.price.taxes[0].region; + // $ExpectType string + pricing.price.taxes[0].tax_type; } }); } diff --git a/types/recurly__recurly-js/test/token/hosted-field.ts b/types/recurly__recurly-js/test/token/hosted-field.ts index 4b2ad080ae..b3f35645ae 100644 --- a/types/recurly__recurly-js/test/token/hosted-field.ts +++ b/types/recurly__recurly-js/test/token/hosted-field.ts @@ -1,27 +1,29 @@ export default function hostedFieldToken() { - window.recurly.token(document.querySelector('form') as HTMLFormElement, (err, token) => { - if (err) { - err.message; - err.code; - } else { - token.id; - token.type; - // $ExpectError - token.fake; - } - }); + const form = document.querySelector('form'); - // $ExpectError - window.recurly.token(document.querySelector('div'), () => {}); - - // $ExpectError - window.recurly.token((err, token) => { - if (err) { - err.message; - err.code; - } else { - token.id; - token.type; - } + if (form) { + window.recurly.token(form, (err, token) => { + if (err) { + err.message; + err.code; + } else { + token.id; + token.type; + } }); + } + + // $ExpectError + window.recurly.token(document.querySelector('div'), () => {}); + + // $ExpectError + window.recurly.token((err, token) => { + if (err) { + err.message; + err.code; + } else { + token.id; + token.type; + } + }); }