Options
All
  • Public
  • Public/Protected
  • All
Menu

@sourceallies/payment-gateway - v0.4.0

Index

Type aliases

AccountType

AccountType: "checking" | "savings" | "businessChecking"

Variables

Const AUTH_CAPTURE_TRANSACTION

AUTH_CAPTURE_TRANSACTION: "authCaptureTransaction" = "authCaptureTransaction"

Const NUMBERS_REGEX

NUMBERS_REGEX: RegExp = /^[0-9]+$/

Const chance

chance: Chance = new Chance()

Functions

buildApplePayTransactionRequestData

  • Creates the TransactionData object with the correct fields. paymentData is derived from the argument of the function you define for Apple Pay's applePaySession.onpaymentauthorized function. Apple Pay will pass in an event to the function you defined. This event will have a property called payment. event.payment is what needs to be passed as the paymentData argument of this function.

    If you do not specify the billTo parameter, the following fields are required for paymentData (Apple Pay may not set these values in event.payment):

    • paymentData.billingContact
    • paymentData.billingContact.givenName
    • paymentData.billingContact.familyName Leaving these fields out may cause unexpected behavior. See Apple Pay Web Reference for more details.

    If the lineItems parameter is not passed in, the following one will be added as a line item:

     listItems = [
         {
             itemId: 'invoice',
             name: 'Invoice Payment',
             unitPrice: parseFloat(requestData.amount),
             quantity: 1
         }
     ];

    This requires amount to be able to be parsed to a float. If it is not, null is returned.

    Return Value

    The return value is then used in processTransaction.

    Parameters

    • paymentData: ApplePayPayment | null | undefined
       The argument passed into Apple's `applePaySession.onpaymentauthorized`
       function.
    • gatewayData: GatewayData
       Your Payment Gateway partner information.
    • amount: string
       The monetary value of the transaction being processed. This must be in
       the form of a number.
    • customer: Customer
       An object containing customer email.
    • order: Order
       An object containing the order description and invoice number.
    • Optional lineItems: LineItemSingle[]
       Line items you want included in the transaction.
    • Optional billTo: BillTo
       Bill to information for the paying user. This parameter is optional. If
       it is not specified, the bill to information will be built from
       paymentData.

    Returns TransactionData | null

     Transaction data ready to be called with `processTransaction` if paymentData is not null,
     or returns null if amount is not a number or paymentData is null.

buildApplePayValidationRequestData

  • buildApplePayValidationRequestData(event: ApplePayValidateMerchantEvent | null | undefined, gatewayData: GatewayData, clientCanonicalName: string, context: string): ValidationData | null
  • Builds the ValidationData object. This function should be called in the applepaysession.onvalidatemerchant function you define. The argument passed in to applepaysession.onvalidatemerchant should be passed in as the event parameter.

    Example Usage

    applepaysession.onvalidatemerchant = (event) => {
        const validationData = paymentGateway.buildApplePayValidationRequestData(
            event,
            gatewayData,
            clientCanonicalName,
            context
        );
        paymentGateway.validateApplePayRequest(callback, validationData, environment);
    }

    Return Value

    The return value is then used in validateApplePayRequest.

    Parameters

    • event: ApplePayValidateMerchantEvent | null | undefined
       The event paramenter passed in to the applepaysession.onvalidatemerchant
       callback.
    • gatewayData: GatewayData
       Your Payment Gateway partner information.
    • clientCanonicalName: string
       The client canonical name you use for Apple Pay.
    • context: string
       The hostname of your website.

    Returns ValidationData | null

     If event is null or missing property validationURL, null is returned.

buildGooglePayTransactionRequestData

  • Creates the TransactionData object with the correct fields. paymentData is generated from Google's paymentsClient.loadPaymentData().

    If you do not specify the billTo parameter, the following properties are required for paymentData (Google Pay may not set these properties):

    • paymentData.paymentMethodData.info
    • paymentData.paymentMethodData.info.billingAddress
    • paymentData.paymentMethodData.info.billingAddress.name Leaving these fields out may cause unexpected behavior. Make sure billingAddressRequired is set to true in your card parameters if you are not passing in the billTo parameter. See Google Pay Web Reference for more details.

    If the lineItems parameter is not passed in, the following one will be added as a line item:

     lineItems = [
         {
             itemId: 'invoice',
             name: 'Invoice Payment',
             unitPrice: parseFloat(requestData.amount),
             quantity: 1
         }
     ];

    This requires amount to be able to be parsed to a float. If it is not, null is returned.

    Return Value

    The return value is then used in processTransaction.

    Parameters

    • paymentData: PaymentData | null | undefined
       The object returned from Google's `paymentsClient.loadPaymentData()`.
    • gatewayData: GatewayData
       Your Payment Gateway partner information.
    • amount: string
       The monetary value of the transaction being processed. This must be in
       the form of a number.
    • customer: Customer
       An object containing customer email.
    • order: Order
       An object containing the order description and invoice number.
    • Optional lineItems: LineItemSingle[]
       Line items you want included in the transaction. This parameter is
       optional. If it is not specified, the default `lineItems` will be used.
    • Optional billTo: BillTo
       Bill to information for the paying user. This parameter is optional. If
       it is not specified, the bill to information will be built from
       paymentData.

    Returns TransactionData | null

     Transaction data ready to be called with `processTransaction` if paymentData is not null,
     or returns null if amount is not a number or paymentData is null.

buildRequestData

  • Builds the RequestData object to be used in buildTransactionRequestData or buildSubscriptionRequestData. The only fields required for parament billTo are firstName and lastName. The paremeter customer is not required but must have a value passed in (i.e. null if you do not want to use it). The parameter order is only needed for a recurring transaction. Although these are optional, we highly recommend including all of them in all payments. *NOTE: If you are using this in a TypeScript node project, all the paremeters will be required except for the optional ones in the parameter billTo.

    Return Value

    The return value is then used in buildTransactionRequestData or buildSubscriptionRequestData

    Parameters

    • response: any
       The response body as JavaScript object from the call to AcceptJS.
    • amount: string
       The amount to be payed.
    • billTo: BillTo
       The payee's billing information.
    • customer: Customer
       The payee's customer information.
    • order: Order
       The order description and invoice number.
    • Optional shipTo: ShipTo
       The shipping information for the payment.

    Returns RequestData | null

     If response is null or it does not contain opaqueData, null is
     returned.

buildSubscriptionRequestData

  • Creates the SubscriptionData object containing the correct fields. requestData can be generated by calling buildRequestData.

    If the lineItems` parameter is not passed in, the following one will be added as a line item:

     listItems = [
         {
             itemCode: 'invoice',
             name: 'Invoice Payment',
             amount: parseFloat(requestData.amount),
             description: 'invoice payment'
         }
     ];

    This requires requestData.amount to be able to be parsed to a float. If it is not, null is returned.

    Return Value

    The return value is then used in processSubscription.

    Parameters

    • requestData: RequestData | null
       The data needed to make the request.
    • gatewayData: GatewayData
       Your Payment Gateway partner information.
    • paymentSchedule: PaymentSchedule
       The schedule of the recurring payment.
    • Optional lineItems: LineItemsRecurring[]
       Line items you want included in the transaction.

    Returns SubscriptionData | null

     If requestData is null, null is returned.

buildTransactionRequestData

  • Creates the TransactionData object containing the correct fields. requestData can be generated by calling buildRequestData. If the lineItems parameter is not passed in, the following one will be added as a line item:

     lineItems = [
         {
             itemId: 'invoice',
             name: 'Invoice Payment',
             unitPrice: parseFloat(requestData.amount),
             quantity: 1
         }
     ];

    Return Value

    The returned value is then used in processTransaction.

    Parameters

    • requestData: RequestData | null
       The data needed to make the request.
    • gatewayData: GatewayData
       Your Payment Gateway partner information.
    • Optional lineItems: LineItemSingle[]
       Line items you want included in the transaction.

    Returns TransactionData | null

     If requestData is null, null is returned.

encryptPaymentData

  • Creates the correct payment object to be used in the call to AcceptJS to encrypt the payment data. The paremeter response is the response body of getMerchantDetails.

    Parameters

    • response: any | void
       The response body as a JavaScript object from HTTP request in
       `getMerchantDetails`.
    • authorizeNetApiKey: string
       Your Authorize.NET API key.
    • paymentData: CardData | BankData
       The card or bank payment data that will be used for the request.

    Returns SecureData | null

     If response is void or does not have publicClientKey, null is
     returned.

getMerchantDetails

  • getMerchantDetails(callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void, gatewayData: GatewayData, env: Environment): void
  • Makes an HTTP request to get the merchant details from Payment Gateway. When the response is received, callbackFunction is called with the XMLHttpRequest object as the parameter. The body of the HTTP request can then be parsed to JSON and used in encryptPaymentData.

    Parameters

    • callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void
       The function to be called when a response is received.
        • (xmlHttpRequest: XMLHttpRequest): void
        • Parameters

          • xmlHttpRequest: XMLHttpRequest

          Returns void

    • gatewayData: GatewayData
       The gateway data for your Payment Gateway account.
    • env: Environment
       The environment of Payment Gateway you want the request sent to.

    Returns void

isBankDataValid

  • isBankDataValid(bankData: BankData): boolean
  • Checks if bank data could possibly be valid by doing basic validation of the account number and routing number. This function uses the Luhn Algorithm to check the account number and routing number.

    NOTE: this function does not check that the account is actually valid, only that it could be valid.

    Parameters

    • bankData: BankData

      The card data to check.

    Returns boolean

    True if the bank could be valid, false if not.

isCardDataValid

  • isCardDataValid(cardData: CardData): boolean
  • Checks if a credit card could possibly be valid by doing basic validation of the card number, CSC, and expiration date. This function uses the Luhn Algorithm to check the card number.

    NOTE: this function does not check that the card is actually valid, only that it could be valid.

    Parameters

    • cardData: CardData

      The card data to check.

    Returns boolean

    True if the card could be valid, false if not.

passesLuhnAlgorithm

  • passesLuhnAlgorithm(number: string): boolean
  • Checks if a number could possibly be valid by using the Luhn Algorithm. The number string passed in must contain only number characters. If there is a non-number character, there may be unexpected behaviors.

    Parameters

    • number: string

      The number to check as a string.

    Returns boolean

    True if the card number could be valid, false if not.

processApplePayTransactionRequest

  • processApplePayTransactionRequest(callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void, paymentData: ApplePayPayment | null | undefined, gatewayData: GatewayData, amount: string, customer: Customer, order: Order, env: Environment, lineItems?: LineItemSingle[], billTo?: BillTo): void
  • Wrapper function that calls buildApplePayTransactionRequestData then processTransaction. See those functions for additional information. This function calls processTransaction even if the return value from buildTransactionRequestData is null. All error handling must be done in the callbackFunction parameter.

    Parameters

    • callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void
       The function to be called when a response is received.
        • (xmlHttpRequest: XMLHttpRequest): void
        • Parameters

          • xmlHttpRequest: XMLHttpRequest

          Returns void

    • paymentData: ApplePayPayment | null | undefined
       The argument passed into Apple's `applePaySession.onpaymentauthorized`
       function.
    • gatewayData: GatewayData
       Your Payment Gateway partner information.
    • amount: string
       The monetary value of the transaction being processed. This must be in
       the form of a number.
    • customer: Customer
       An object containing customer email.
    • order: Order
       An object containing the order description and invoice number.
    • env: Environment
       The environment of Payment Gateway you want the request sent to.
    • Optional lineItems: LineItemSingle[]
       Line items you want included in the transaction.
    • Optional billTo: BillTo
       Bill to information for the paying user. This parameter is optional. If
       it is not specified, the bill to information will be built from
       paymentData.

    Returns void

processApplePayValidationRequest

  • processApplePayValidationRequest(callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void, event: ApplePayValidateMerchantEvent | null | undefined, gatewayData: GatewayData, clientCanonicalName: string, context: string, environment: Environment): void
  • Wrapper function that calls buildApplePayValidationRequestData then validateApplePayRequest. See those functions for additional information. This function calls validateApplePayRequest even if the return value from buildApplePayValidationRequestData is null. All error handling must be done in the callbackFunction parameter.

    Example Usage

    applepaysession.onvalidatemerchant = (event) => {
        paymentGateway.processApplePayValidationRequest(
            callbackFunction,
            event,
            gatewayData,
            clientCanonicalName,
            context,
            environment
        );
    }

    Parameters

    • callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void
       The function to be called when a response is received.
        • (xmlHttpRequest: XMLHttpRequest): void
        • Parameters

          • xmlHttpRequest: XMLHttpRequest

          Returns void

    • event: ApplePayValidateMerchantEvent | null | undefined
       The event paramenter passed in to the applepaysession.onvalidatemerchant
       callback.
    • gatewayData: GatewayData
       Your Payment Gateway partner information.
    • clientCanonicalName: string
       The client canonical name you use for Apple Pay.
    • context: string
       The hostname of your website.
    • environment: Environment
       The environment of Payment Gateway that you want the request set to.

    Returns void

processGooglePayTransactionRequest

  • processGooglePayTransactionRequest(callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void, paymentData: PaymentData | null | undefined, gatewayData: GatewayData, amount: string, customer: Customer, order: Order, env: Environment, lineItems?: LineItemSingle[], billTo?: BillTo): void
  • Wrapper function that calls buildGooglePayTransactionRequestData then processTransaction. See those functions for additional information. This function calls processTransaction even if the return value from buildGooglePayTransactionRequestData is null. All error handling must be done in the callbackFunction parameter.

    Parameters

    • callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void
        • (xmlHttpRequest: XMLHttpRequest): void
        • Parameters

          • xmlHttpRequest: XMLHttpRequest

          Returns void

    • paymentData: PaymentData | null | undefined
       The object returned from Google's `paymentsClient.loadPaymentData()`.
    • gatewayData: GatewayData
       Your Payment Gateway partner information.
    • amount: string
       The monetary value of the transaction being processed. This must be in
       the form of a number.
    • customer: Customer
       An object containing customer email.
    • order: Order
       An object containing the order description and invoice number.
    • env: Environment
       The environment of Payment Gateway you want the request sent to.
    • Optional lineItems: LineItemSingle[]
       Line items you want included in the transaction. This parameter is
       optional. If it is not specified, the default `lineItems` will be used.
    • Optional billTo: BillTo
       Bill to information for the paying user. This parameter is optional. If
       it is not specified, the bill to information will be built from
       paymentData.

    Returns void

processSubscription

  • processSubscription(callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void, subscriptionData: SubscriptionData | null, env: Environment): void
  • Makes an HTTP request to process the subscription with Payment Gateway. When the response is received, callbackFunction is called with the XMLHttpRequest object as the parameter. The parameter transactionData can be generated by calling buildSubscriptionRequestData.

    Parameters

    • callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void
       The function to be called when a response is received.
        • (xmlHttpRequest: XMLHttpRequest): void
        • Parameters

          • xmlHttpRequest: XMLHttpRequest

          Returns void

    • subscriptionData: SubscriptionData | null
       The subscription data.
    • env: Environment
       The environment of Payment Gateway you want the request sent to.

    Returns void

processSubscriptionRequest

processTransaction

  • processTransaction(callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void, transactionData: TransactionData | null, environment: Environment): void
  • Makes an HTTP request to proccess the transaction with Payment Gateway. When the response is received, callbackFunction is called with the XMLHttpRequest object as the parameter. The parameter transactionData can be generated by calling buildTransactionRequestData.

    Parameters

    • callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void
       The function to be called when a response is received.
        • (xmlHttpRequest: XMLHttpRequest): void
        • Parameters

          • xmlHttpRequest: XMLHttpRequest

          Returns void

    • transactionData: TransactionData | null
       The transaction data.
    • environment: Environment
       The environment of Payment Gateway you want the request sent to.

    Returns void

processTransactionRequest

  • Wrapper function that calls buildTransactionRequestData then processTransaction. See those functions for additional information. This function calls processTransaction even if the return value from buildTransactionRequestData is null. All error handling must be done in the callbackFunction parameter.

    Parameters

    • callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void
       The function to be called when a response is received.
        • (xmlHttpRequest: XMLHttpRequest): void
        • Parameters

          • xmlHttpRequest: XMLHttpRequest

          Returns void

    • requestData: RequestData | null
       The data needed to make the request.
    • gatewayData: GatewayData
       Your Payment Gateway partner information.
    • env: Environment
       The environment of Payment Gateway you want the request sent to.
    • Optional lineItems: LineItemSingle[]
       Line items you want included in the transaction.

    Returns void

validateApplePayRequest

  • validateApplePayRequest(callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void, validationData: ValidationData | null, environment: Environment): void
  • Validates the ValidationData that's generated via the buildApplePayValidationRequestData function by making a HTTP request to Payment Gateway. When the response is received, callbackFunction is called with the XMLHttpRequest object as the parameter. This function should be called in the applepaysession.onvalidatemerchant function that you define.

    Example Usage

    applepaysession.onvalidatemerchant = (event) => {
        const validationData = paymentGateway.buildApplePayValidationRequestData(
            event,
            gatewayData,
            clientCanonicalName,
            context
        );
        paymentGateway.validateApplePayRequest(callbackFunction, validationData, environment);
    }

    Parameters

    • callbackFunction: (xmlHttpRequest: XMLHttpRequest) => void
       The function to be called when a response is received.
        • (xmlHttpRequest: XMLHttpRequest): void
        • Parameters

          • xmlHttpRequest: XMLHttpRequest

          Returns void

    • validationData: ValidationData | null
       The validation data.
    • environment: Environment
       The environment of Payment Gateway that you want the request set to.

    Returns void

Generated using TypeDoc, the 7/23/2020 at 11:27:31 AM