1.8.0 • Published 4 years ago

firstapi-sdk v1.8.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

FirstApiSDK

FirstApiSdk - Typescript client for FirstApiSDK

Payment Gateway API Specification.

  • API version: 6.13.0
  • Package version: 1.8.0

Installation

    npm install @firstdata/first-data-gateway --save --save-exact

Reference Documentation

https://docs.firstdata.com/org/gateway/docs/api

Getting Started

import {AxiosPromise} from "axios";
import {
  Amount,
  PrimaryTransaction,
  PrimaryTransactionParams,
  PaymentMethod,
  TransactionType,
  Card,
  TransactionResponse,
  Context, IContext,
  ICredentials,
  IConfiguration,
  IClientFactory,
  IPaymentApi,
} from "@firstdata/first-data-gateway";

const getPaymentClient = (): IPaymentApi => {
  const credentials: ICredentials = {
    apiKey: "API_KEY_HERE",
    apiSecret: "API_SECRET_HERE",
  };

  const config: IConfiguration {
    basePath: "https://cert.api.firstdata.com/gateway",
    credentials,
  };

  const context: IContext = new Context(config);
  const factory: IClientFactory = context.factory;
  return factory.paymentApi();
};

const getApiParams = (): PrimaryTransactionParams => {
  const amount: Amount = {
    total: 27.00,

    // ISO 4217 currency code
    currency: "USD",
  };

  const card: Card = {
    cardholderName: "Example Name",
    cardNumber: "4242424242424242",
    expDate: "022022", // MMCCYY
    cvv: "123",
  };

  const paymentMethod: PaymentMethod = {
    methodType: PaymentMethod.MethodTypeEnum.Card,
    card,
  };

  const payload: PrimaryTransaction = {
    transactionType: TransactionType.SALE,
    amount,
    paymentMethod,
  };

  return {
    payload,
  };
};

const responsePromise: AxiosPromise<TransactionResponse> =
  getPaymentClient().primaryPaymentTransaction(getApiParams());

Repo Organization

  • src/openapi/: code auto-generated from api specification
  • src/firstdata/: code manually created for simpler API
  • src/firstdata/api/: wrapper classes for each api
  • src/firstdata/context.ts: takes care of object instantiation while still providing flexibility
  • src/firstdata/factory.ts: an instance of this class is exposed on Context instances and provides noarg methods to instantiate each api client
  • src/firstdata/models.ts: exposes models both autogenerated and specific to the wrapper api classes

API Methods/Endpoints

All URIs are relative to https://cert.api.firstdata.com/gateway

InterfaceMethodHTTP requestDescription
IAuthenticationApigetAccessTokenPOST /v2/authentication/access-tokensGenerate an access token for user authentication.
ICardInfoLookupApicardInfoLookupPOST /v2/card-informationCard information lookUp
ICardVerificationApiverifyCardPOST /v2/card-verificationVerify a payment card.
ICurrencyConversionApigetExchangeRatePOST /v2/exchange-ratesGenerate dynamic currency conversion transactions
IFraudDetectApiscoreOnlyPOST /v2/fraud/score-onlyScore a transaction for fraud.
IFraudDetectApiclientRegistrationPOST /v2/fraud/client-registrationClient Registration for fraud detect.
IFraudDetectApipaymentRegistrationPOST /v2/fraud/payment-registrationPayment Registration for fraud detect.
IOrderApiorderInquiryGET /v2/orders/{order-id}Retrieve the state of an order
IOrderApisecondaryTransactionPOST /v2/orders/{order-id}Perform a return or postAuth on an already existing order.
IPaymentApifinalizeSecureTransactionPATCH /v2/payments/{transaction-id}Update a 3DSecure or UnionPay payment and continue processing.
IPaymentApisecondaryTransactionPOST /v2/payments/{transaction-id}Perform a void, postAuth or return secondary transaction.
IPaymentApiprimaryTransactionPOST /v2/paymentsGenerate a primary transaction.
IPaymentApitransactionInquiryGET /v2/payments/{transaction-id}Retrieve the state of a transaction.
IPaymentSchedulesApicancelPaymentScheduleDELETE /v2/payment-schedules/{order-id}Cancel a gateway payment schedule.
IPaymentSchedulesApicreatePaymentSchedulePOST /v2/payment-schedulesUse this to create a gateway payment schedule.
IPaymentSchedulesApiinquiryPaymentScheduleGET /v2/payment-schedules/{order-id}View a gateway payment schedule.
IPaymentSchedulesApiupdatePaymentSchedulePATCH /v2/payment-schedules/{order-id}Update a gateway payment schedule.
IPaymentTokenApicreatePaymentTokenPOST /v2/payment-tokensCreate a payment token from a payment card.
IPaymentTokenApideletePaymentTokenDELETE /v2/payment-tokens/{token-id}Delete a payment token.
IPaymentUrlApicreatePaymentUrlPOST /v2/payment-urlCreate a payment URL.
IPaymentUrlApideletePaymentUrlDELETE /v2/payment-urlDelete a payment URL.
IPaymentUrlApipaymentUrlDetailGET /v2/payment-urlRetrive the state of a payment URL.

Code Overview

Context and Configuration

interface ICredentials {
  apiKey: string;
  apiSecret: string;
}

interface IConfiguration {
  basePath: string;
  credentials: ICredentials;
  storeId?: string;
  region?: string;
  axios?: AxiosInstance;
  factory?: IClientFactory;
}

interface IContext extends IConfiguration {
  readonly axios: AxiosInstance;
  readonly basePath: string;
  readonly credentials: ICredentials
  readonly factory: IClientFactory;
}

class Context implements IContext {
  public constructor(config: IConfiguration) { /*...*/ }
}

IClientFactory

interface IClientFactory {
  authenticationApi(): IAuthenticationApi;
  cardInfoLookupApi(): ICardInfoLookupApi;
  cardVerificationApi(): ICardVerificationApi;
  currencyConversionApi(): ICurrencyConversionApi;
  fraudDetectApi(): IFraudDetectApi;
  orderApi(): IOrderApi;
  paymentApi(): IPaymentApi;
  paymentSchedulesApi(): IPaymentSchedulesApi;
  paymentTokenApi(): IPaymentTokenApi;
  paymentUrlApi(): IPaymentUrlApi;
}

IAuthenticationApi

interface IAuthenticationApi {
  getAccessToken(): AxiosPromise<AccessTokenResponse>;
}

ICardInfoLookupApi

type CardInfoLookupParams = {
  region?: string;
  payload: CardInfoLookupRequest;
};

interface ICardInfoLookupApi {
  cardInfoLookup(params: CardInfoLookupParams): AxiosPromise<CardInfoLookupResponse>;
}

ICardVerificationApi

type VerifyCardParams = {
  region?: string;
  payload: CardVerificationRequest;
};

interface ICardVerificationApi {
  verifyCard(params: VerifyCardParams): AxiosPromise<TransactionResponse>;
}

ICurrencyConversionApi

type ExchangeRateParams = {
  region?: string;
  payload: ExchangeRateRequest;
};

interface ICurrencyConversionApi {
  getExchangeRate(params: ExchangeRateParams): AxiosPromise<ExchangeRateResponse>;
}

IFraudDetectApi

type ScoreOnlyParams = {
  region?: string;
  payload: ScoreOnlyRequest;
};

type ClientRegistrationParams = {
  region?: string;
  payload: ClientRegistration;
};

type PaymentRegistrationParams = {
  region?: string;
  payload: PaymentRegistration;
};

interface IFraudDetectApi {
  scoreOnly(params: ScoreOnlyParams): AxiosPromise<ScoreOnlyResponse>;
  fraudClientRegistrationPost(params: ClientRegistrationParams): AxiosPromise<FraudRegistrationResponse>;
  fraudPaymentRegistrationPost(params: PaymentRegistrationParams): AxiosPromise<FraudRegistrationResponse>;
}

IOrderApi

type OrderParams = {
  region?: string;
  storeId?: string;
  orderId: string;
};

type SecondaryTxOrderParams = OrderParams & {
  payload: SecondaryTransaction;
};

interface IOrderApi {
  orderInquiry(params: OrderParams): AxiosPromise<OrderResponse>;
  orderPostAuth(params: SecondaryTxOrderParams): AxiosPromise<TransactionResponse>;
  orderReturnTransaction(params: SecondaryTxOrderParams): AxiosPromise<TransactionResponse>;
}

IPaymentSchedulesApi

type ExistingPaymentScheduleParams = {
  region?: string;
  storeId?: string;
  orderId: string;
};

type CreatePaymentScheduleParams = {
  region?: string;
  payload: PaymentSchedulesRequest;
};

type UpdatePaymentScheduleParams =
  CreatePaymentScheduleParams & ExistingPaymentScheduleParams;

interface IPaymentSchedulesApi {
  cancelPaymentSchedule(params: ExistingPaymentScheduleParams): AxiosPromise<PaymentSchedulesResponse>;
  createPaymentSchedule(params: CreatePaymentScheduleParams): AxiosPromise<PaymentSchedulesResponse>;
  inquiryPaymentSchedule(params: ExistingPaymentScheduleParams): AxiosPromise<RecurringPaymentDetailsResponse>;
  updatePaymentSchedule(params: UpdatePaymentScheduleParams): AxiosPromise<PaymentSchedulesResponse>;
}

IPaymentTokenApi

type PaymentTokenParams = {
  region?: string;
  authorization?: string;
};

type CreatePaymentTokenParams =
  PaymentTokenParams & {
    payload: PaymentTokenizationRequest;
  };

type DeletePaymentTokenParams =
  PaymentTokenParams & {
    tokenId: string;
    storeId?: string;
  };

interface IPaymentTokenApi {
  createPaymentToken(params: CreatePaymentTokenParams): AxiosPromise<PaymentTokenizationResponse>;
  deletePaymentToken(params: DeletePaymentTokenParams): AxiosPromise<PaymentTokenizationResponse>;
}

IPaymentUrlApi

type CreatePaymentUrlParams = {
  region?: string;
  payload: PaymentUrlRequest;
};

type DeletePaymentUrlParams = {
  region?: string;
  storeId?: string;
  transactionId?: string;
  orderId?: string;
  paymentUrlId?: string;
  transactionTime?; string;
};

type PaymentUrlDetailParams = {
  region?: string;
  storeId?: string;
  fromDate: string;
  toDate: string;
  orderId?: string;
  merchantTransactionId?: string;
  status?: string;
};

interface IPaymentUrlApi {
  createPaymentUrl(params: CreatePaymentUrlParams): AxiosPromise<PaymentUrlResponse>;
  deletePaymentUrl(params: DeletePaymentUrlParams): AxiosPromise<PaymentUrlResponse>;
  paymentUrlDetail(params: PaymentUrlDetailParams): AxiosPromise<PaymentUrlDetailResponse>;
}

IPaymentApi

type PaymentParams = {
  region?: string;
  storeId?: string;
  transactionId: string;
};

type SecondaryTxPaymentParams =
  PaymentParams & {
    payload: SecondaryTransaction;
  };

type PrimaryTransactionParams = {
  region?: string;
  payload: PrimaryTransaction;
};

type FinalizeTransactionParams = {
  region?: string;
  transactionId: string;
  payload: AuthenticationResponseVerificationRequest;
};

interface IPaymentApi {
  finalizeSecureTransaction(params: FinalizeTransactionParams): AxiosPromise<TransactionResponse>;
  performPaymentPostAuthorisation(params: SecondaryTxPaymentParams): AxiosPromise<TransactionResponse>;
  primaryPaymentTransaction(params: PrimaryTransactionParams): AxiosPromise<TransactionResponse>;
  returnTransaction(params: SecondaryTxPaymentParams): AxiosPromise<TransactionResponse>;
  transactionInquiry(params: PaymentParams): AxiosPromise<TransactionResponse>;
  voidTransaction(params: PaymentParams): AxiosPromise<TransactionResponse>;
}