diff --git a/types/braintree/braintree-tests.ts b/types/braintree/braintree-tests.ts index 0b24245b28..7cd3811f7d 100644 --- a/types/braintree/braintree-tests.ts +++ b/types/braintree/braintree-tests.ts @@ -1,15 +1,26 @@ import braintree = require('braintree'); -import { BraintreeGateway, Address, AddressCreateRequest, - CreditCard, Customer, PayPalAccount, ApplePayCard, AndroidPayCard, - VisaCheckoutCard, SamsungPayCard, MasterpassCard, PaymentMethod, - PaymentMethodNonce, Transaction +import { + BraintreeGateway, + Address, + AddressCreateRequest, + CreditCard, + Customer, + PayPalAccount, + ApplePayCard, + AndroidPayCard, + VisaCheckoutCard, + SamsungPayCard, + MasterpassCard, + PaymentMethod, + PaymentMethodNonce, + Transaction, } from 'braintree'; /** * Gateway */ const gateway: BraintreeGateway = new braintree.BraintreeGateway({ - environment: 'Sandbox', + environment: braintree.Environment.Sandbox, merchantId: 'abc123', publicKey: 'def456', privateKey: 'xyz789', @@ -23,7 +34,8 @@ const gateway: BraintreeGateway = new braintree.BraintreeGateway({ customerId: '123456', streetAddress: '222 Oak Street', }; - const response = await gateway.address.create(addressRequest); + const response = await gateway.address.create(addressRequest).catch(console.error); + if (!response) return; const { id, customerId }: Address = response.address; })(); @@ -32,13 +44,15 @@ const gateway: BraintreeGateway = new braintree.BraintreeGateway({ cardholderName: 'Johnny Dogood', cvv: '123', }; - const response = await gateway.creditCard.update('abcdef', creditCardRequest); + const response = await gateway.creditCard.update('abcdef', creditCardRequest).catch(console.error); + if (!response) return; const { bin, maskedNumber, last4 }: CreditCard = response.creditCard; })(); (async () => { - const response: Customer = await gateway.customer.find('abcdef'); - const { id, paymentMethods } = response; + const response = await gateway.customer.find('abcdef').catch(console.error); + if (!response) return; + const { id, paymentMethods }: Customer = response; })(); (async () => { @@ -46,7 +60,8 @@ const gateway: BraintreeGateway = new braintree.BraintreeGateway({ customerId: '123456', paymentMethodNonce: 'i-am-a-nonce', }; - const response = await gateway.paymentMethod.create(paymentMethodRequest); + const response = await gateway.paymentMethod.create(paymentMethodRequest).catch(console.error); + if (!response) return; const { token }: PaymentMethod = response.paymentMethod; const applePayCard = response.paymentMethod; const paypalAccount = response.paymentMethod; @@ -59,21 +74,24 @@ const gateway: BraintreeGateway = new braintree.BraintreeGateway({ })(); (async () => { - const response = await gateway.paymentMethodNonce.create('token'); - const nonce = response.paymentMethodNonce.nonce; + const response = await gateway.paymentMethodNonce.create('token').catch(console.error); + if (!response) return; + const nonce: PaymentMethodNonce = response.paymentMethodNonce; })(); (async () => { const transactionRequest = { amount: '128.00', }; - const response = await gateway.transaction.sale(transactionRequest); + const response = await gateway.transaction.sale(transactionRequest).catch(console.error); + if (!response) return; const { amount, billing, id }: Transaction = response.transaction; // Cannot assign to var - await gateway.transaction.cloneTransaction(id, { amount: '100.00' , options: {submitForSettlement: true }}); + await gateway.transaction + .cloneTransaction(id, { amount: '100.00', options: { submitForSettlement: true } }) + .catch(console.error); - const transactions: Transaction[] = await gateway.transaction.search(() => { - return; - }); + const transactions: Transaction[] = []; + gateway.transaction.search(() => true).on('data', transactions.push); })(); diff --git a/types/braintree/index.d.ts b/types/braintree/index.d.ts index 6a8556fd6e..4cbdc77092 100644 --- a/types/braintree/index.d.ts +++ b/types/braintree/index.d.ts @@ -1,11 +1,15 @@ -// Type definitions for braintree 2.16 +// Type definitions for braintree 2.20 // Project: https://github.com/braintree/braintree_node -// Definitions by: Sam Rubin +// Definitions by: Sam Rubin , +// Mohamed Elsharnouby // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 3.6 + +/// export = braintree; export as namespace braintree; +import * as stream from 'stream'; declare namespace braintree { /** @@ -16,11 +20,11 @@ declare namespace braintree { Development = 'Development', Production = 'Production', Qa = 'Qa', - Sandbox = 'Sandbox' + Sandbox = 'Sandbox', } export interface GatewayConfig { - environment: any; + environment: Environment; merchantId: string; publicKey: string; privateKey: string; @@ -78,7 +82,11 @@ declare namespace braintree { create(request: AddressCreateRequest): Promise>; delete(customerId: string, addressId: string): Promise; find(customerId: string, addressId: string): Promise
; - update(customerId: string, addressId: string, updates: AddressUpdateRequest): Promise>; + update( + customerId: string, + addressId: string, + updates: AddressUpdateRequest, + ): Promise>; } interface ClientTokenGateway { @@ -94,14 +102,14 @@ declare namespace braintree { } interface CreditCardVerificationGateway { - search(searchFn: any): Promise; + search(searchFn: any): stream.Readable; } interface CustomerGateway { create(request: CustomerCreateRequest): Promise>; delete(customerId: string): Promise; find(customerId: string): Promise; - search(searchFn: any): Promise; + search(searchFn: any): stream.Readable; update(customerId: string, updates: CustomerUpdateRequest): Promise>; } @@ -111,19 +119,28 @@ declare namespace braintree { interface DisputeGateway { accept(disputeId: string): Promise>; - addFileEvidence(disputeId: string, evidence: { documentId: string, category?: string }): Promise>; - addTextEvidence(disputeId: string, evidence: { content: string, category?: string}): Promise>; + addFileEvidence( + disputeId: string, + evidence: { documentId: string; category?: string }, + ): Promise>; + addTextEvidence( + disputeId: string, + evidence: { content: string; category?: string }, + ): Promise>; finalize(disputeId: string): Promise>; find(disputeId: string): Promise; removeEvidence(disputeId: string, evidenceId: string): Promise>; - search(searchFn: any): Promise; + search(searchFn: any): stream.Readable; } interface MerchantAccountGateway { all(): Promise; create(request: MerchantAccountCreateRequest): Promise>; createForCurrency(currency: string, id?: string): Promise>; - update(merchantAccountId: string, updates: MerchantAccountUpdateRequest): Promise>; + update( + merchantAccountId: string, + updates: MerchantAccountUpdateRequest, + ): Promise>; find(merchantAccountId: string): Promise; } @@ -131,34 +148,41 @@ declare namespace braintree { create(request: PaymentMethodCreateRequest): Promise>; delete(token: string): Promise; find(token: string): Promise; - grant(sharedPaymentMethodToken: string, options: {allowVaulting?: boolean, includeBillingPostalCode?: boolean, revokeAfter?: Date }): Promise>; + grant( + sharedPaymentMethodToken: string, + options: { allowVaulting?: boolean; includeBillingPostalCode?: boolean; revokeAfter?: Date }, + ): Promise>; revoke(sharedPaymentMethodToken: string): Promise; update(token: string, updates: PaymentMethodUpdateRequest): Promise>; } - interface PaymentMethodNonceGateway { + interface PaymentMethodNonceGateway { create(paymentMethodToken: string): Promise>; find(paymentMethodNonce: string): Promise; } - interface PlanGateway { + interface PlanGateway { all(): Promise; } - interface SettlementBatchSummaryGateway { - generate(request: {settlementDate: string, groupByCustomField?: string}): Promise; + interface SettlementBatchSummaryGateway { + generate(request: { settlementDate: string; groupByCustomField?: string }): Promise; } - interface SubscriptionGateway { + interface SubscriptionGateway { cancel(subscriptionId: string): Promise; create(request: SubscriptionRequest): Promise>; find(subscriptionId: string): Promise; - retryCharge(subscriptionId: string, amount?: string, submitForSettlement?: boolean): Promise>; - search(searchFn: any): Promise; + retryCharge( + subscriptionId: string, + amount?: string, + submitForSettlement?: boolean, + ): Promise>; + search(searchFn: any): stream.Readable; update(subscriptionId: string, updates: SubscriptionRequest): Promise>; } - interface TestingGateway { + interface TestingGateway { settle(transactionId: string): Promise>; settlementConfirm(transactionId: string): Promise>; settlementDecline(transactionId: string): Promise>; @@ -166,21 +190,27 @@ declare namespace braintree { settlementPending(transactionId: string): Promise>; } - interface TransactionGateway { + interface TransactionGateway { cancelRelease(transactionId: string): Promise; - cloneTransaction(transactionId: string, options: {amount: string, options: {submitForSettlement: boolean}}): Promise; + cloneTransaction( + transactionId: string, + options: { amount: string; options: { submitForSettlement: boolean } }, + ): Promise; find(transactionId: string): Promise; holdInEscrow(transactionId: string): Promise; refund(transactionId: string, amount?: string): Promise>; releaseFromEscrow(transactionId: string): Promise; sale(request: TransactionRequest): Promise>; - search(searchFn: any): Promise; - submitForPartialSettlement(authorizedTransactionId: string, amount: string): Promise>; + search(searchFn: any): stream.Readable; + submitForPartialSettlement( + authorizedTransactionId: string, + amount: string, + ): Promise>; submitForSettlement(transactionId: string, amount?: string): Promise>; void(transactionId: string): Promise>; } - interface TransactionLineItemGateway { + interface TransactionLineItemGateway { findAll(transactionId: string): Promise; } @@ -375,7 +405,7 @@ declare namespace braintree { streetAddress?: string; options?: { updateExisting?: boolean; - } + }; }; cardholderName?: string; cvv?: string; @@ -665,8 +695,15 @@ declare namespace braintree { */ // Payment method is an instance of one of these types - export type PaymentMethod = AndroidPayCard | ApplePayCard | PayPalAccount | CreditCard | SamsungPayCard | - VenmoAccount | VisaCheckoutCard | MasterpassCard; + export type PaymentMethod = + | AndroidPayCard + | ApplePayCard + | PayPalAccount + | CreditCard + | SamsungPayCard + | VenmoAccount + | VisaCheckoutCard + | MasterpassCard; export interface PaymentMethodCreateRequest { billingAddress?: { @@ -717,8 +754,8 @@ declare namespace braintree { region?: string; streetAddress?: string; options?: { - updateExisting?: boolean - } + updateExisting?: boolean; + }; }; billingAddressId?: string; cardholderName?: string; @@ -768,7 +805,16 @@ declare namespace braintree { lastTwo?: string; } - export type PaymentMethodType = 'AndroidPayCard' | 'ApplePayCard' | 'CreditCard' |'MasterpassCard' | 'PayPalAccount' | 'UsBankAccount' | 'VenmoAccount' | 'VisaCheckoutCard' | 'SamsungPayCard'; + export type PaymentMethodType = + | 'AndroidPayCard' + | 'ApplePayCard' + | 'CreditCard' + | 'MasterpassCard' + | 'PayPalAccount' + | 'UsBankAccount' + | 'VenmoAccount' + | 'VisaCheckoutCard' + | 'SamsungPayCard'; /** * Plan @@ -859,7 +905,7 @@ declare namespace braintree { doNotInheritAddOnsOrDiscounts?: boolean; paypal?: { description?: string; - } + }; startImmediately?: boolean; }; paymentMethodNonce?: string; @@ -892,7 +938,7 @@ declare namespace braintree { amount: string; androidPayCard?: { bin: string; - commercial: Commercial + commercial: Commercial; countryOfIssuance: string; debit: Debit; durbinRegulated: DurbinRegulated; @@ -915,7 +961,7 @@ declare namespace braintree { bin: string; cardType: string; cardholderName: string; - commercial: Commercial + commercial: Commercial; countryOfIssuance: string; debit: Debit; durbinRegulated: DurbinRegulated; @@ -945,7 +991,7 @@ declare namespace braintree { countryName?: string; extendedAddress?: string; firstName?: string; - id?: string + id?: string; lastName?: string; locality?: string; postalCode?: string; @@ -1094,7 +1140,7 @@ declare namespace braintree { countryName?: string; extendedAddress?: string; firstName?: string; - id?: string + id?: string; lastName?: string; locality?: string; postalCode?: string; @@ -1149,7 +1195,7 @@ declare namespace braintree { } interface ClientToken { - clientToken: string; + clientToken: string; } export interface TransactionRequest { @@ -1177,7 +1223,7 @@ declare namespace braintree { expirationMonth?: string; expirationYear?: string; number?: string; - token?: string + token?: string; }; customer?: { company?: string; @@ -1208,7 +1254,7 @@ declare namespace braintree { paypal?: { customField?: string; description?: string; - } + }; skipAdvancedFraudChecking?: boolean; skipAvs?: boolean; skipCvv?: boolean; @@ -1217,11 +1263,11 @@ declare namespace braintree { storeShippingAddressInVault?: boolean; submitForSettlement?: boolean; threeDSecure?: { - required?: boolean - } + required?: boolean; + }; venmo?: { profileId?: string; - } + }; }; orderId?: string; paymentMethodNonce?: string; @@ -1301,14 +1347,31 @@ declare namespace braintree { sourcePaymentMethodToken: string; } - export type GatewayRejectionReason = 'application_incomplete' | 'avs' | 'avs_and_cvv' | 'cvv' | 'duplicate' | 'fraud' | 'risk_threshold' | 'three_d_secure' | 'token_issuance'; + export type GatewayRejectionReason = + | 'application_incomplete' + | 'avs' + | 'avs_and_cvv' + | 'cvv' + | 'duplicate' + | 'fraud' + | 'risk_threshold' + | 'three_d_secure' + | 'token_issuance'; - export type PaymentInstrumentType = 'android_pay_card' | 'apple_pay_card' | 'credit_card' | 'masterpass_card' | 'paypal_account' | 'samsung_pay_card' | 'venmo_account' | 'visa_checkout_card'; + export type PaymentInstrumentType = + | 'android_pay_card' + | 'apple_pay_card' + | 'credit_card' + | 'masterpass_card' + | 'paypal_account' + | 'samsung_pay_card' + | 'venmo_account' + | 'visa_checkout_card'; export type TransactionProcessorResponseType = 'approved' | 'soft_declined' | 'hard_declined'; export enum TransactionRequestSource { - recurring = 'recurring', + recurring = 'recurring', unscheduled = 'unscheduled', recurring_first = 'recurring_first', moto = 'moto', @@ -1321,8 +1384,19 @@ declare namespace braintree { id: string; } - export type TransactionStatus = 'authorization_expired' | 'authorized' | 'authorizing' | 'settlement_pending' | 'settlement_declined' | - 'failed' | 'gateway_rejected' | 'processor_declined' | 'settled' | 'settling' | 'submitted_for_settlement' | 'voided'; + export type TransactionStatus = + | 'authorization_expired' + | 'authorized' + | 'authorizing' + | 'settlement_pending' + | 'settlement_declined' + | 'failed' + | 'gateway_rejected' + | 'processor_declined' + | 'settled' + | 'settling' + | 'submitted_for_settlement' + | 'voided'; export interface TransactionStatusHistory { amount: string;