Braintree: fix merchant account member and types, add gateway… (#42552)

* 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>
This commit is contained in:
Sanders DeNardi
2020-02-24 16:11:14 -08:00
committed by GitHub
co-authored by Sanders DeNardi
parent 7da30d6637
commit 232d19d1dd
2 changed files with 70 additions and 14 deletions
+38
View File
@@ -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;
})();
+32 -14
View File
@@ -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 <https://github.com/smrubin>,
// Mohamed Elsharnouby <https://github.com/sharno>,
// Aaron Rose <https://github.com/acdr>
// Sanders DeNardi <https://github.com/sedenardi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.6
// TypeScript Version: 3.7
/// <reference types="node" />
@@ -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<T> {
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;