mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-14 22:10:30 +00:00
Merge pull request #30921 from mateusz-g/master
[braintree-web] Use of promises + additional improvements
This commit is contained in:
Vendored
+21
-15
@@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/braintree/braintree-web
|
||||
// Definitions by: Guy Shahine <https://github.com/chlela>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
/**
|
||||
* @module braintree-web/american-express
|
||||
@@ -359,7 +360,8 @@ declare namespace braintree {
|
||||
* });
|
||||
* @static
|
||||
*/
|
||||
create: (options: { authorization: string }, callback: callback) => void;
|
||||
create(options: { authorization: string }): Promise<Client>;
|
||||
create(options: { authorization: string }, callback: callback): void;
|
||||
|
||||
/**
|
||||
* @description The current version of the SDK, i.e. `3.0.2`.
|
||||
@@ -439,7 +441,8 @@ declare namespace braintree {
|
||||
* @param {callback} callback The second argument, `data`, is the {@link DataCollector} instance.
|
||||
* @returns {void}
|
||||
*/
|
||||
create: (options: { client: Client, kount: boolean, paypal: boolean }, callback: callback) => void;
|
||||
create(options: { client: Client, kount: boolean, paypal: boolean }): Promise<DataCollector>;
|
||||
create(options: { client: Client, kount: boolean, paypal: boolean }, callback: callback): void;
|
||||
|
||||
/**
|
||||
* @description The current version of the SDK, i.e. `3.0.2`.
|
||||
@@ -591,18 +594,15 @@ declare namespace braintree {
|
||||
* @property {?HostedFields~hostedFieldsFieldData} fields.expirationYear {@link HostedFields~hostedFieldsFieldData|hostedFieldsFieldData} for the expiration year field, if it is present.
|
||||
* @property {?HostedFields~hostedFieldsFieldData} fields.postalCode {@link HostedFields~hostedFieldsFieldData|hostedFieldsFieldData} for the postal code field, if it is present.
|
||||
*/
|
||||
interface HostedFieldsFieldDataFields {
|
||||
number: HostedFieldsHostedFieldsFieldData;
|
||||
cvv: HostedFieldsHostedFieldsFieldData;
|
||||
expirationDate: HostedFieldsHostedFieldsFieldData;
|
||||
expirationMonth: HostedFieldsHostedFieldsFieldData;
|
||||
expirationYear: HostedFieldsHostedFieldsFieldData;
|
||||
postalCode: HostedFieldsHostedFieldsFieldData;
|
||||
}
|
||||
type HostedFieldsHostedFieldsFieldName = 'number' | 'cvv' | 'expirationDate' | 'expirationMonth' | 'expirationYear' | 'postalCode';
|
||||
|
||||
type HostedFieldsFieldDataFields = {
|
||||
[key in HostedFieldsHostedFieldsFieldName]: HostedFieldsHostedFieldsFieldData;
|
||||
};
|
||||
|
||||
interface HostedFieldsStateObject {
|
||||
cards: HostedFieldsHostedFieldsCard[];
|
||||
emittedBy: string;
|
||||
emittedBy: HostedFieldsHostedFieldsFieldName;
|
||||
fields: HostedFieldsFieldDataFields;
|
||||
}
|
||||
|
||||
@@ -666,7 +666,8 @@ declare namespace braintree {
|
||||
* }
|
||||
* }, callback);
|
||||
*/
|
||||
create: (options: { client: Client, fields: HostedFieldFieldOptions, styles: any }, callback: callback) => void;
|
||||
create(options: { client: Client, fields: HostedFieldFieldOptions, styles: any }): Promise<HostedFields>;
|
||||
create(options: { client: Client, fields: HostedFieldFieldOptions, styles: any }, callback: callback): void;
|
||||
|
||||
|
||||
/**
|
||||
@@ -726,7 +727,7 @@ declare namespace braintree {
|
||||
* });
|
||||
* @returns {void}
|
||||
*/
|
||||
on(event: string, handler: ((event: any) => any)): void;
|
||||
on(event: string, handler: ((event: HostedFieldsStateObject) => void)): void;
|
||||
|
||||
/**
|
||||
* Cleanly tear down anything set up by {@link module:braintree-web/hosted-fields.create|create}
|
||||
@@ -785,7 +786,9 @@ declare namespace braintree {
|
||||
* });
|
||||
* @returns {void}
|
||||
*/
|
||||
tokenize(options?: { vault: boolean }, callback?: callback): void;
|
||||
tokenize(options?: { vault?: boolean, cardholderName?: string, billingAddress?: any }): Promise<HostedFieldsTokenizePayload>;
|
||||
tokenize(options: { vault?: boolean, cardholderName?: string, billingAddress?: any }, callback: callback): void;
|
||||
tokenize(callback: callback): void;
|
||||
|
||||
/**
|
||||
* Add a class to a {@link module:braintree-web/hosted-fields~field field}. Useful for updating field styles when events occur elsewhere in your checkout.
|
||||
@@ -1138,7 +1141,8 @@ declare namespace braintree {
|
||||
* client: client
|
||||
* }, callback);
|
||||
*/
|
||||
create: (options: { client: Client }, callback: callback) => void;
|
||||
create(options: { client: Client }): Promise<ThreeDSecure>;
|
||||
create(options: { client: Client }, callback: callback): void;
|
||||
|
||||
/**
|
||||
* @description The current version of the SDK, i.e. `3.0.2`.
|
||||
@@ -1207,6 +1211,7 @@ declare namespace braintree {
|
||||
* }
|
||||
* });
|
||||
*/
|
||||
verifyCard(options: { nonce: string, amount: number, addFrame: (err?: BraintreeError, iframe?: HTMLIFrameElement) => void, removeFrame?: () => void }): Promise<ThreeDSecureVerifyPayload>;
|
||||
verifyCard(options: { nonce: string, amount: number, addFrame: (err?: BraintreeError, iframe?: HTMLIFrameElement) => void, removeFrame: () => void }, callback: callback): void;
|
||||
|
||||
/**
|
||||
@@ -1751,3 +1756,4 @@ declare namespace braintree {
|
||||
|
||||
export = braintree;
|
||||
export as namespace braintree;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ let clientToken: string = "eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiO
|
||||
|
||||
braintree.client.create({
|
||||
authorization: clientToken
|
||||
}, function (error: braintree.BraintreeError, clientInstance: any) {
|
||||
}, function (error: braintree.BraintreeError, clientInstance: braintree.Client) {
|
||||
|
||||
var form: HTMLFormElement = document.getElementById('my-form-id') as HTMLFormElement;
|
||||
var data: { creditCard: braintree.CreditCardInfo } = {
|
||||
@@ -396,7 +396,7 @@ let submitNonceToServer: (nonce: string) => void;
|
||||
|
||||
braintree.threeDSecure.verifyCard({
|
||||
nonce: existingNonce,
|
||||
amount: 123.45,
|
||||
amount: 123.45, // $ExpectType number
|
||||
addFrame: function (err, iframe) {
|
||||
// Set up your UI and add the iframe.
|
||||
let my3DSContainer = document.createElement('div');
|
||||
@@ -437,4 +437,4 @@ braintree.threeDSecure.cancelVerifyCard(function (err: braintree.BraintreeError,
|
||||
verifyPayload.nonce; // The nonce returned from the 3ds lookup call
|
||||
verifyPayload.liabilityShifted; // boolean
|
||||
verifyPayload.liabilityShiftPossible; // boolean
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,13 @@
|
||||
import { ApplePay } from "..";
|
||||
import * as braintree from "..";
|
||||
|
||||
let version: string = braintree.VERSION;
|
||||
|
||||
let clientToken: string = "eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiI0YjlhYzVmYmI4ZTNkYzQzMmFkZjJhNzBlNjZlMWNjY2M5ODRkYzE4ZTM4YmY4NjYzZTM5NjM3NWZjYmQzY2U5fGNyZWF0ZWRfYXQ9MjAxNi0wOS0wOFQwNTowMzo0MC4xNjk1NTUwMzUrMDAwMFx1MDAyNm1lcmNoYW50X2lkPTM0OHBrOWNnZjNiZ3l3MmJcdTAwMjZwdWJsaWNfa2V5PTJuMjQ3ZHY4OWJxOXZtcHIiLCJjb25maWdVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvMzQ4cGs5Y2dmM2JneXcyYi9jbGllbnRfYXBpL3YxL2NvbmZpZ3VyYXRpb24iLCJjaGFsbGVuZ2VzIjpbXSwiZW52aXJvbm1lbnQiOiJzYW5kYm94IiwiY2xpZW50QXBpVXJsIjoiaHR0cHM6Ly9hcGkuc2FuZGJveC5icmFpbnRyZWVnYXRld2F5LmNvbTo0NDMvbWVyY2hhbnRzLzM0OHBrOWNnZjNiZ3l3MmIvY2xpZW50X2FwaSIsImFzc2V0c1VybCI6Imh0dHBzOi8vYXNzZXRzLmJyYWludHJlZWdhdGV3YXkuY29tIiwiYXV0aFVybCI6Imh0dHBzOi8vYXV0aC52ZW5tby5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tIiwiYW5hbHl0aWNzIjp7InVybCI6Imh0dHBzOi8vY2xpZW50LWFuYWx5dGljcy5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tLzM0OHBrOWNnZjNiZ3l3MmIifSwidGhyZWVEU2VjdXJlRW5hYmxlZCI6dHJ1ZSwicGF5cGFsRW5hYmxlZCI6dHJ1ZSwicGF5cGFsIjp7ImRpc3BsYXlOYW1lIjoiQWNtZSBXaWRnZXRzLCBMdGQuIChTYW5kYm94KSIsImNsaWVudElkIjpudWxsLCJwcml2YWN5VXJsIjoiaHR0cDovL2V4YW1wbGUuY29tL3BwIiwidXNlckFncmVlbWVudFVybCI6Imh0dHA6Ly9leGFtcGxlLmNvbS90b3MiLCJiYXNlVXJsIjoiaHR0cHM6Ly9hc3NldHMuYnJhaW50cmVlZ2F0ZXdheS5jb20iLCJhc3NldHNVcmwiOiJodHRwczovL2NoZWNrb3V0LnBheXBhbC5jb20iLCJkaXJlY3RCYXNlVXJsIjpudWxsLCJhbGxvd0h0dHAiOnRydWUsImVudmlyb25tZW50Tm9OZXR3b3JrIjp0cnVlLCJlbnZpcm9ubWVudCI6Im9mZmxpbmUiLCJ1bnZldHRlZE1lcmNoYW50IjpmYWxzZSwiYnJhaW50cmVlQ2xpZW50SWQiOiJtYXN0ZXJjbGllbnQzIiwiYmlsbGluZ0FncmVlbWVudHNFbmFibGVkIjp0cnVlLCJtZXJjaGFudEFjY291bnRJZCI6ImFjbWV3aWRnZXRzbHRkc2FuZGJveCIsImN1cnJlbmN5SXNvQ29kZSI6IlVTRCJ9LCJjb2luYmFzZUVuYWJsZWQiOmZhbHNlLCJtZXJjaGFudElkIjoiMzQ4cGs5Y2dmM2JneXcyYiIsInZlbm1vIjoib2ZmIn0=";
|
||||
|
||||
braintree.client.create({
|
||||
authorization: clientToken
|
||||
}, function (error: braintree.BraintreeError, clientInstance: any) {
|
||||
}, function (error: braintree.BraintreeError, clientInstance: braintree.Client) {
|
||||
|
||||
var form: HTMLFormElement = document.getElementById('my-form-id') as HTMLFormElement;
|
||||
var data: { creditCard: braintree.CreditCardInfo } = {
|
||||
@@ -62,7 +65,7 @@ braintree.client.create({
|
||||
select: true
|
||||
}
|
||||
}
|
||||
}, function (hostedFieldsErr?: braintree.BraintreeError, hostedFieldsInstance?: any) {
|
||||
}, function (hostedFieldsErr?: braintree.BraintreeError, hostedFieldsInstance?: braintree.HostedFields) {
|
||||
|
||||
if (hostedFieldsErr) {
|
||||
// Handle error in Hosted Fields creation
|
||||
@@ -178,7 +181,7 @@ braintree.client.create({
|
||||
});
|
||||
});
|
||||
|
||||
braintree.applePay.create({ client: clientInstance }, function (createErr?: braintree.BraintreeError, applePayInstance?: any) {
|
||||
braintree.applePay.create({ client: clientInstance }, function (createErr?: braintree.BraintreeError, applePayInstance?: ApplePay) {
|
||||
if (createErr) {
|
||||
// Handle error in client creation
|
||||
console.log(`Error Code: ${error.code}, Type: ${error.type}, Message: ${error.message}, Details: ${error.details}`);
|
||||
@@ -194,7 +197,7 @@ braintree.client.create({
|
||||
total: { label: 'Your Label', amount: '10.00' },
|
||||
};
|
||||
|
||||
var paymentRequest = braintree.applePay.createPaymentRequest(request);
|
||||
var paymentRequest = applePayInstance.createPaymentRequest(request);
|
||||
|
||||
console.log(paymentRequest);
|
||||
// { total: { }, countryCode: 'US', currencyCode: 'USD', merchantCapabilities: [ ], supportedNetworks: [ ] }
|
||||
@@ -394,7 +397,7 @@ let submitNonceToServer: (nonce: string) => void;
|
||||
|
||||
braintree.threeDSecure.verifyCard({
|
||||
nonce: existingNonce,
|
||||
amount: 123.45,
|
||||
amount: 123.45, // $ExpectType number
|
||||
addFrame: function (err, iframe) {
|
||||
// Set up your UI and add the iframe.
|
||||
let my3DSContainer = document.createElement('div');
|
||||
|
||||
Reference in New Issue
Block a user