From 232d19d1ddbb6445e5d178a10e8f538080d8f479 Mon Sep 17 00:00:00 2001 From: Sanders DeNardi Date: Mon, 24 Feb 2020 19:11:14 -0500 Subject: [PATCH] =?UTF-8?q?Braintree:=20fix=20merchant=20account=20member?= =?UTF-8?q?=20and=20types,=20add=20gateway=E2=80=A6=20(#42552)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: correct merchant gateway field name and create fields * fix: add gateway helper function * remove extraneous field * add separate request and response interfaces for individual and business merchants * remove status from request interfaces * add gateway function helper to tests Co-authored-by: Sanders DeNardi <35534812+sdenardi@users.noreply.github.com> --- types/braintree/braintree-tests.ts | 38 ++++++++++++++++++++++++ types/braintree/index.d.ts | 46 +++++++++++++++++++++--------- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/types/braintree/braintree-tests.ts b/types/braintree/braintree-tests.ts index 1eb48cfa7c..6c25834e57 100644 --- a/types/braintree/braintree-tests.ts +++ b/types/braintree/braintree-tests.ts @@ -15,6 +15,7 @@ import { PaymentMethodNonce, Transaction, WebhookNotificationKind, + MerchantAccountCreateRequest } from 'braintree'; /** @@ -146,3 +147,40 @@ const gateway: BraintreeGateway = new braintree.BraintreeGateway({ const reportUrl = notification.accountUpdaterDailyReport.reportUrl; if (!reportUrl) return; })(); + +/** + * Gateway function helper + */ +const gateway2: BraintreeGateway = braintree.connect({ + environment: braintree.Environment.Sandbox, + merchantId: 'abc123', + publicKey: 'def456', + privateKey: 'xyz789', +}); + +(async () => { + const merchantAccount: MerchantAccountCreateRequest = { + individual: { + address: { + locality: 'New York', + postalCode: '10001', + region: 'New York', + streetAddress: '222 Oak Street' + }, + dateOfBirth: '20200214', + email: 'merchant@example.com', + firstName: 'Jane', + lastName: 'Doe' + }, + funding: { + destination: 'Bank', + accountNumber: '123456789', + routingNumber: '021000021' + }, + masterMerchantAccountId: 'master_merchant', + tosAccepted: true + }; + const response = await gateway2.merchantAccount.create(merchantAccount); + if (!response) return; + const id = response.merchantAccount.masterMerchantAccount?.id; +})(); diff --git a/types/braintree/index.d.ts b/types/braintree/index.d.ts index cd43432c43..9c63615dd6 100644 --- a/types/braintree/index.d.ts +++ b/types/braintree/index.d.ts @@ -1,10 +1,11 @@ -// Type definitions for braintree 2.20 +// Type definitions for braintree 2.22 // Project: https://github.com/braintree/braintree_node // Definitions by: Sam Rubin , // Mohamed Elsharnouby , // Aaron Rose +// Sanders DeNardi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.6 +// TypeScript Version: 3.7 /// @@ -42,7 +43,7 @@ declare namespace braintree { customer: CustomerGateway; discount: DiscountGateway; dispute: DisputeGateway; - merchantAccountGateway: MerchantAccountGateway; + merchantAccount: MerchantAccountGateway; paymentMethod: PaymentMethodGateway; paymentMethodNonce: PaymentMethodNonceGateway; plan: PlanGateway; @@ -55,6 +56,8 @@ declare namespace braintree { webhookTesting: WebhookTestingGateway; } + export function connect(config: GatewayConfig): BraintreeGateway; + interface ValidatedResponse { success: boolean; errors: ValidationErrorsCollection; @@ -634,37 +637,41 @@ declare namespace braintree { */ export class MerchantAccount { - business?: MerchantBusiness; + business?: MerchantBusinessResponse; currencyIsoCode: string; default: boolean; funding: MerchantFunding; id: string; - individual: MerchantIndividual; + individual: MerchantIndividualResponse; masterMerchantAccount?: MerchantAccount; status: MerchantAccountStatus; } export interface MerchantAccountCreateRequest { - business?: MerchantBusiness; + business?: MerchantBusinessRequest; funding: MerchantFunding; - id: string; - individual: MerchantIndividual; + id?: string; + individual: MerchantIndividualRequest; masterMerchantAccountId: string; - status: MerchantAccountStatus; tosAccepted: boolean; } export interface MerchantAccountUpdateRequest { - business?: MerchantBusiness; + business?: MerchantBusinessRequest; funding: MerchantFunding; id: string; - individual: MerchantIndividual; + individual: MerchantIndividualRequest; masterMerchantAccountId: string; - status: MerchantAccountStatus; } - export interface MerchantBusiness { + export interface MerchantBusinessRequest { address?: MerchantAddressDetails; + dbaName?: string; + legalName?: string; + taxId?: string; + } + + export interface MerchantBusinessResponse { addressDetails?: MerchantAddressDetails; dbaName?: string; legalName?: string; @@ -688,7 +695,18 @@ declare namespace braintree { routingNumber?: string; } - export interface MerchantIndividual { + export interface MerchantIndividualRequest { + address: MerchantAddressDetails; + dateOfBirth: string; + email: string; + firstName: string; + lastName: string; + phone?: string; + ssn?: string; + ssnLast4?: string; + } + + export interface MerchantIndividualResponse { addressDetails: MerchantAddressDetails; dateOfBirth: string; email: string;