Skip to content
Merged
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
13 changes: 11 additions & 2 deletions types/braintree-web/american-express.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,14 @@ export interface AmericanExpress {
getExpressCheckoutProfile(options: { nonce: string }, callback: callback): void;
}

export function create(options: { client: Client }): Promise<AmericanExpress>;
export function create(options: { client: Client }, callback: callback<AmericanExpress>): void;
export function create(options: {
client?: Client | undefined;
authorization?: string | undefined;
}): Promise<AmericanExpress>;
export function create(
options: {
client?: Client | undefined;
authorization?: string | undefined;
},
callback: callback<AmericanExpress>,
): void;
40 changes: 36 additions & 4 deletions types/braintree-web/apple-pay.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,15 @@ export class ApplePaySession {
static readonly STATUS_PIN_REQUIRED: number;
}

export type ApplePayPaymentRequestResult = ApplePayPaymentRequest | Promise<ApplePayPaymentRequest>;

export type ApplePay = ApplePayBase<ApplePayPaymentRequest>;
export type ApplePayDeferred = ApplePayBase<Promise<ApplePayPaymentRequest>>;

/**
* @description Accept Apple Pay on the Web. *This component is currently in beta and is subject to change.*
*/
export interface ApplePay {
export interface ApplePayBase<T extends ApplePayPaymentRequestResult> {
/**
* @description A special merchant ID which represents the merchant association with Braintree. Required when using ApplePaySession.canMakePaymentsWithActiveCard.
*/
Expand Down Expand Up @@ -347,7 +352,7 @@ export interface ApplePay {
"countryCode" | "currencyCode" | "merchantCapabilities" | "supportedNetworks"
>
>,
): ApplePayPaymentRequest;
): T;

/**
* Validates the merchant website, as required by ApplePaySession before payment can be authorized. * - The canonical name for your store.
Expand Down Expand Up @@ -430,5 +435,32 @@ export interface ApplePay {
teardown(): Promise<void>;
}

export function create(options: { client: Client }): Promise<ApplePay>;
export function create(options: { client: Client }, callback?: callback<ApplePay>): void;
export function create(options: {
client?: Client | undefined;
authorization?: string | undefined;
useDeferredClient?: false | undefined;
}): Promise<ApplePay>;

export function create(options: {
client?: Client | undefined;
authorization?: string | undefined;
useDeferredClient: true;
}): Promise<ApplePayDeferred>;

export function create(
options: {
client?: Client | undefined;
authorization?: string | undefined;
useDeferredClient?: false | undefined;
},
callback: callback<ApplePay>,
): void;

export function create(
options: {
client?: Client | undefined;
authorization?: string | undefined;
useDeferredClient: true;
},
callback: callback<ApplePayDeferred>,
): void;
48 changes: 43 additions & 5 deletions types/braintree-web/data-collector.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Client } from "./client";
import { callback } from "./core";

export interface DataCollector {
deviceData: string;
// We don't want to export DataCollectorBase
export {};

rawDeviceData: object;
type MakeUndefinedIf<T, Condition> = Condition extends true ? T | undefined : T;

interface DataCollectorBase<IsDeferred> {
deviceData: MakeUndefinedIf<string, IsDeferred>;

rawDeviceData: MakeUndefinedIf<object, IsDeferred>;

getDeviceData(options?: { raw: boolean }): Promise<string | object>;
getDeviceData(options: { raw: boolean }, callback: callback<void>): void;
Expand All @@ -13,18 +18,51 @@ export interface DataCollector {
teardown(callback: callback): void;
}

export type DataCollector = DataCollectorBase<false>;
export type DataCollectorDeferred = DataCollectorBase<true>;

export function create(options: {
client: Client;
client?: Client;
authorization?: string | undefined;
useDeferredClient?: false | undefined;
kount?: boolean | undefined;
paypal?: boolean | undefined;
riskCorrelationId?: string | undefined;
cb1?: string | undefined;
}): Promise<DataCollector>;

export function create(options: {
client?: Client;
authorization?: string | undefined;
useDeferredClient: true;
kount?: boolean | undefined;
paypal?: boolean | undefined;
riskCorrelationId?: string | undefined;
cb1?: string | undefined;
}): Promise<DataCollectorDeferred>;

export function create(
options: {
client: Client;
client?: Client;
authorization?: string | undefined;
useDeferredClient?: false | undefined;
kount?: boolean | undefined;
paypal?: boolean | undefined;
riskCorrelationId?: string | undefined;
cb1?: string | undefined;
},
callback: callback<DataCollector>,
): void;

export function create(
options: {
client?: Client;
authorization?: string | undefined;
useDeferredClient: true;
kount?: boolean | undefined;
paypal?: boolean | undefined;
riskCorrelationId?: string | undefined;
cb1?: string | undefined;
},
callback: callback<DataCollectorDeferred>,
): void;
98 changes: 89 additions & 9 deletions types/braintree-web/hosted-fields.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface HostedFieldsField {
container?: string | HTMLElement | undefined;
placeholder?: string | undefined;
type?: string | undefined;
iframeTitle?: string | undefined;
internalLabel?: string | undefined;
formatInput?: boolean | undefined;
maskInput?: boolean | HostedFieldsFieldMaskInput | undefined;
select?: boolean | { options: string[] } | undefined;
Expand Down Expand Up @@ -189,11 +191,30 @@ export interface HostedFieldsAccountDetails {
lastFour: string;
}

export type HostedFieldsTokenizeValues = "Yes" | "No" | "Unknown";

export interface HostedFieldsBinData {
commercial: HostedFieldsTokenizeValues;
countryOfIssuance: string;
debit: HostedFieldsTokenizeValues;
durbinRegulated: HostedFieldsTokenizeValues;
healthcare: HostedFieldsTokenizeValues;
issuingBank: string;
payroll: HostedFieldsTokenizeValues;
prepaid: HostedFieldsTokenizeValues;
productId: string;
business: HostedFieldsTokenizeValues;
consumer: HostedFieldsTokenizeValues;
purchase: HostedFieldsTokenizeValues;
corporate: HostedFieldsTokenizeValues;
}

export interface HostedFieldsTokenizePayload {
nonce: string;
details: HostedFieldsAccountDetails;
type: string;
description: string;
binData: HostedFieldsBinData;
/**
* Provides details about regulatory environment.
* See https://developer.paypal.com/braintree/docs/guides/3d-secure/migration/javascript/v3#authentication-insight.
Expand Down Expand Up @@ -337,13 +358,15 @@ export interface HostedFields {
*/
tokenize(options?: {
vault?: boolean | undefined;
authenticationInsight?: { merchantAccountId: string } | undefined;
fieldsToTokenize?: Array<TokenizationFields> | undefined;
cardholderName?: string | undefined;
billingAddress?: HostedFieldsBillingAddress | undefined;
}): Promise<HostedFieldsTokenizePayload>;
tokenize(
options: {
vault?: boolean | undefined;
authenticationInsight?: { merchantAccountId: string } | undefined;
fieldsToTokenize?: Array<TokenizationFields> | undefined;
cardholderName?: string | undefined;
billingAddress?: HostedFieldsBillingAddress | undefined;
Expand All @@ -361,7 +384,8 @@ export interface HostedFields {
* }
* });
*/
addClass(field: string, classname: string, callback?: callback): void;
addClass(field: HostedFieldsHostedFieldsFieldName, classname: string): Promise<void>;
addClass(field: HostedFieldsHostedFieldsFieldName, classname: string, callback: callback<void>): void;

/**
* Removes a class to a {@link module:braintree-web/hosted-fields~field field}. Useful for updating field styles when events occur elsewhere in your checkout. *
Expand All @@ -376,7 +400,8 @@ export interface HostedFields {
* hostedFieldsInstance.removeClass('number', 'custom-class');
* });
*/
removeClass(field: string, classname: string, callback?: callback): void;
removeClass(field: HostedFieldsHostedFieldsFieldName, classname: string): Promise<void>;
removeClass(field: HostedFieldsHostedFieldsFieldName, classname: string, callback: callback): void;

/**
* Sets the placeholder of a {@link module:braintree-web/hosted-fields~field field}. *
Expand All @@ -400,7 +425,8 @@ export interface HostedFields {
* }
* });
*/
setPlaceholder(field: string, placeholder: string, callback?: callback): void;
setPlaceholder(field: HostedFieldsHostedFieldsFieldName, placeholder: string): Promise<void>;
setPlaceholder(field: HostedFieldsHostedFieldsFieldName, placeholder: string, callback: callback<void>): void;

/**
* @example
Expand All @@ -415,7 +441,8 @@ export interface HostedFields {
* hostedFieldsInstance.clear('cvv');
* hostedFieldsInstance.clear('expirationDate');
*/
clear(field: string, callback?: callback): void;
clear(field: HostedFieldsHostedFieldsFieldName): Promise<void>;
clear(field: HostedFieldsHostedFieldsFieldName, callback: callback<void>): void;

/**
* Returns an {@link HostedFields~stateObject|object} that includes the state of all fields and possible card types.
Expand All @@ -437,7 +464,28 @@ export interface HostedFields {
* }
* });
*/
focus(field: HostedFieldsHostedFieldsFieldName, callback?: callback): void;
focus(field: HostedFieldsHostedFieldsFieldName): Promise<void>;
focus(field: HostedFieldsHostedFieldsFieldName, callback: callback<void>): void;

/**
* Get card verification challenges, such as requirements for cvv and postal code.
* @example
* hostedFieldsInstance.getChallenges().then(function (challenges) {
* challenges // ['cvv', 'postal_code']
* });
*/
getChallenges(): Promise<string[]>;
getChallenges(callback: callback<string[]>): void;

/**
* Get supported card types configured in the Braintree Control Panel
* @example
* hostedFieldsInstance.getSupportedCardTypes().then(function (cardTypes) {
* cardTypes // ['Visa', 'American Express', 'Mastercard']
* });
*/
getSupportedCardTypes(): Promise<string[]>;
getSupportedCardTypes(callback: callback<string[]>): void;

/**
* Sets an attribute of a {@link module:braintree-web/hosted-fields~field field}.
Expand Down Expand Up @@ -473,7 +521,8 @@ export interface HostedFields {
*
* @returns Returns a promise if no callback is provided.
*/
setAttribute(options: HostedFieldAttributeOptions, callback?: callback): void;
setAttribute(options: HostedFieldAttributeOptions): Promise<void>;
setAttribute(options: HostedFieldAttributeOptions, callback: callback<void>): void;

/**
* Removes a supported attribute from a {@link module:braintree-web/hosted-fields~field field}.
Expand All @@ -495,7 +544,8 @@ export interface HostedFields {
*
* @returns Returns a promise if no callback is provided.
*/
removeAttribute(options: HostedFieldAttributeOptions, callback?: callback): void;
removeAttribute(options: HostedFieldAttributeOptions): Promise<void>;
removeAttribute(options: HostedFieldAttributeOptions, callback: callback<void>): void;

/**
* Sets a visually hidden message (for screen readers) on a {@link module:braintree-web/hosted-fields~field field}.
Expand All @@ -517,6 +567,30 @@ export interface HostedFields {
* });
*/
setMessage(options: HostedFieldMessageOptions): void;

/**
* Sets the month options for the expiration month field when presented as a select element.
*
* @param options An array of 12 entries corresponding to the 12 months.
*
* @example <caption>Update the month options to spanish</caption>
* hostedFieldsInstance.setMonthOptions([
* '01 - enero',
* '02 - febrero',
* '03 - marzo',
* '04 - abril',
* '05 - mayo',
* '06 - junio',
* '07 - julio',
* '08 - agosto',
* '09 - septiembre',
* '10 - octubre',
* '11 - noviembre',
* '12 - diciembre'
* ]);
*/
setMonthOptions(options: ReadonlyArray<string>): Promise<void>;
setMonthOptions(options: ReadonlyArray<string>, callback: callback<void>): void;
}

/**
Expand Down Expand Up @@ -551,14 +625,20 @@ export function create(options: {
client?: Client | undefined;
authorization?: string | undefined;
fields: HostedFieldFieldOptions;
styles?: any;
styles?: Record<string, string | Record<string, string>> | undefined;
preventAutofill?: boolean | undefined;
binVerificationLength?: 6 | 8 | undefined;
sessionId?: string | undefined;
}): Promise<HostedFields>;
export function create(
options: {
client?: Client | undefined;
authorization?: string | undefined;
fields: HostedFieldFieldOptions;
styles?: any;
styles?: Record<string, string | Record<string, string>> | undefined;
preventAutofill?: boolean | undefined;
binVerificationLength?: 6 | 8 | undefined;
sessionId?: string | undefined;
},
callback: callback<HostedFields>,
): void;
13 changes: 11 additions & 2 deletions types/braintree-web/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AmericanExpress, create as americanExpressCreate } from "./american-express";
import {
ApplePay,
ApplePayDeferred,
ApplePayDetails,
ApplePayLineItem,
ApplePayLineItemType,
Expand All @@ -15,8 +16,13 @@ import {
} from "./apple-pay";
import { Client, create as clientCreate, CreditCardInfo } from "./client";
import { BraintreeError, callback, VERSION } from "./core";
import { create as dataCollectorCreate, DataCollector } from "./data-collector";
import { create as googlePaymentCreate, GooglePayment, GooglePaymentTokenizePayload } from "./google-payment";
import { create as dataCollectorCreate, DataCollector, DataCollectorDeferred } from "./data-collector";
import {
create as googlePaymentCreate,
GooglePayment,
GooglePaymentDeferred,
GooglePaymentTokenizePayload,
} from "./google-payment";
import {
create as hostedFieldsCreate,
HostedFieldFieldOptions,
Expand Down Expand Up @@ -68,6 +74,7 @@ export const venmo: PaymentClient<typeof venmoCreate>;
export {
AmericanExpress,
ApplePay,
ApplePayDeferred,
ApplePayDetails,
ApplePayLineItem,
ApplePayLineItemType,
Expand All @@ -83,8 +90,10 @@ export {
Client,
CreditCardInfo,
DataCollector,
DataCollectorDeferred,
FetchPaymentMethodsPayload,
GooglePayment,
GooglePaymentDeferred,
GooglePaymentTokenizePayload,
HostedFieldFieldOptions,
HostedFields,
Expand Down
Loading