UNPKG

@banksnussman/venmo

Version:

Interact with Venmo from Typescript

277 lines (272 loc) 7.31 kB
interface FundingInstrumentsGraphQLResponse { profile: Profile; } interface Profile { identity: Identity$1; wallet: Wallet[]; __typename: string; } interface Identity$1 { capabilities: string[]; __typename: string; } interface Wallet { id: string; assets?: Assets; instrumentType: 'balance' | 'debitCard' | 'bank' | 'creditCard'; name: string; fees: any[]; metadata: Metadata; roles: Roles; __typename: string; } interface Assets { logoThumbnail: string; __typename: string; } interface Metadata { availableBalance?: AvailableBalance; __typename: string; bankName?: string; isVerified?: boolean; lastFourDigits?: string; uniqueIdentifier?: string; issuerName?: string; networkName?: string; isVenmoCard?: boolean; expirationDate?: string; expirationStatus?: string; quasiCash?: boolean; } interface AvailableBalance { value: number; transactionType: any; displayString: string; __typename: string; } interface Roles { merchantPayments: string; peerPayments: string; __typename: string; } interface Person { displayName: string; id: string; type: 'personal'; avatar: { url: string; }; handle: string; firstName: string; lastName: string; isFriend: boolean; } interface VenmoCredentials { username: string; password: string; bankAccountNumber: string; } interface Identity { username: string; pictureUrl: string; displayName: string; callToAction: unknown[]; identityType: 'personal' | 'business'; balance: number; numberOfNotifications: number; externalId: string; initials: string; identitySubType?: 'registered_business' | string; profileBackgroundPictureUrl?: string; } interface StoriesResponse { nextId: string; stories: Story[]; } interface Story { amount: string; avatar: string; initials: string; audience: Audience; date: Date; id: string; note: Note; type: Type; attachments: any[]; title: Title; mentions: Mentions; externWalletStatus: null; paymentId: string; likes: Comments; comments: Comments; subType: StorySubType; } declare enum Audience { Friends = "friends", Public = "public" } interface Comments { count: number; userCommentedOrLiked: boolean; } interface Mentions { data: any[]; count: number; } interface Note { type?: string; date?: string; name?: string; lastFour?: string; content?: string; } declare enum StorySubType { None = "none", Standard = "standard" } interface Title { titleType: TitleType; payload: Payload; receiver: Receiver; sender: Receiver; } interface Payload { action: Action; subType: PayloadSubType; } declare enum Action { Charge = "charge", Pay = "pay" } declare enum PayloadSubType { P2P = "p2p" } interface Receiver { id: string; displayName: string; username: string; } declare enum TitleType { Story = "story" } declare enum Type { Payment = "payment" } interface EligibilityOptions { targetType: "user_id"; targetId: string; amountInCents: number; action: "pay" | "request"; note: string; } interface Fee { productUri: string; appliedTo: string; feePercentage: number; baseFeeAmount: number; calculatedFeeAmountInCents: number; feeToken: string; } interface EligibilityResponse { eligible: boolean; eligibilityToken: string; fees: Fee[]; } interface BrokenPaymentOptions { targetUserDetails: TargetUserDetails; amountInCents: number; audience: 'public' | 'private'; note: string; type: "pay" | "request"; fundingSourceID: string; eligibilityToken: string; } interface PaymentOptions { username: string; amount: number; note: string; } interface OldPaymentOptions { funding_source_id: number | string; metadata?: { quasi_cash_disclaimer_viewed?: boolean; }; user_id: number | string; audience: "public" | "private"; amount: number; note: string; } interface TargetUserDetails { userId: string; } declare class Venmo { private credentials; accessToken: string | undefined; csrfToken: string | undefined; csrfCookie: string | undefined; w_fc: string; constructor(credentials: VenmoCredentials); /** * Login gets you a Venmo API autentication token, keeps it in * memory, and returns it. This function does more than just make * one call to the login endpoint. It has to make a few api calls * to get an authentication token. * * @returns {Promise<string>} venmo auth token */ login(): Promise<string>; /** * Get all of the identities for a venmo account. This exists because * one Venmo account can have many identities. For example venmo accounts * can have a business venmo as one of the identities. * * @returns {Promise<Identity[]>} account identities */ getIdentities(): Promise<Identity[]>; /** * This is one way to get a list of venmo transactions * * @param feedType the type of stories you want to see * @param externalId the identity if that comes from `getIdentities` * @returns venmo transactions */ getStories(feedType: 'me' | 'friend', externalId: string): Promise<StoriesResponse>; /** * This is needed to make a Venmo payment because you need the `eligibilityToken` * when you call the `pay` function. Venmo checks all of the csrf bullshit, so * that is all sent here. * * @param eligibilityOptions just look at the typescript type to see what you need to pass * @returns {Promise<EligibilityResponse>} eligibility of possible payment */ getEligibility(eligibilityOptions: EligibilityOptions): Promise<EligibilityResponse>; /** * Use the function to see the payment methods on your account. You will need to * specify the `id` of one of these payment methods when you want to make a payment * with the `pay` function. This uses Venmo's GraphQL api so sorry if the Typescript * types are bad. * * @returns {Promise<FundingInstrumentsGraphQLResponse>} */ getFundingInstruments(): Promise<FundingInstrumentsGraphQLResponse>; /** * Wrapper over the Venmo GraphQL API to get the first user that comes up * in a search query. This function to useful to get the user id of a * venmo user from their venmo username so that you can later make * a payment to them with the `pay` function. * * @param name search query (can be name or username) * @returns the first person that matches the search query */ getPerson(name: string): Promise<Person | undefined>; /** * Used to initiate a payment or payment request. * * @param paymentOptions just look at the typescript type * @returns the actual request because this endpoint returns an empty response? */ brokenPay(paymentOptions: Omit<BrokenPaymentOptions, 'eligibilityToken'>): Promise<Response>; oldPay(paymentOptions: OldPaymentOptions): Promise<Response>; pay(options: PaymentOptions): Promise<number>; } export { Venmo };