Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace paymentService

Helper functions for payment handling

import { paymentService } from '@oneblink/apps'

Index

Type aliases

HandlePaymentResult: { receiptItems: PaymentReceiptItem[]; submissionResult: FormSubmissionResult; transaction: { errorMessage: string | undefined | null; isSuccess: boolean } }

Type declaration

  • receiptItems: PaymentReceiptItem[]
  • submissionResult: FormSubmissionResult
  • transaction: { errorMessage: string | undefined | null; isSuccess: boolean }
    • errorMessage: string | undefined | null

      The error message to display if isSuccess is false

    • isSuccess: boolean

      true if the transaction was successful

PaymentReceiptItem: { allowCopyToClipboard: boolean; className?: string; icon?: string; label: string; value: string; valueClassName?: string }

Type declaration

  • allowCopyToClipboard: boolean

    Display a button on the receipt item to copy the value to the clipboard

  • Optional className?: string

    A CSS class to add to the HTML element container

  • Optional icon?: string
  • label: string

    The label to represent the value

  • value: string

    The value to display

  • Optional valueClassName?: string

    A CSS class to add to the HTML element containing the value

Functions

  • Pass in query string parameters after a redirect back to your app after a payment is processed. This function will handle all payment submission events supported by OneBlink. Will return a Transaction and the submission result that was returned from handlePaymentSubmissionEvent() before redirecting to payment.hostedFormUrl.

    Example

    import queryString from 'query-string'

    const query = queryString.parse(window.location.search)
    const { transaction, submissionResult } =
    await paymentService.handlePaymentQuerystring(query)

    Parameters

    • query: Record<string, unknown>

    Returns Promise<HandlePaymentResult>

  • Handle a submission result with a payment submission event. Will throw an error if a transaction has already been made using this submission result. Will return undefined if the submission does not have an amount. Will return the submission result passed in with a payment property if the submission requires processing.

    Example

    const formSubmissionResult = {
    submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',
    submissionTimestamp: '2020-07-29T01:03:26.573Z'
    formsAppId: 1,
    submission: {
    form: 'data',
    goes: 'here',
    amount: 1.50,
    }
    definition: OneBlinkForm,
    payment: null,
    }
    const paymentSubmissionEvent = {
    type: 'CP_PAY',
    configuration: {
    elementId: '12663efc-4c6a-4e72-8505-559edfe3e92e',
    gatewayId: '6658c5c4-e0db-483b-8af7-6a6464fe772c',
    },
    }
    const paymentReceiptUrl = `${window.location.origin}/payment-receipt`
    const paymentSubmissionResult = await paymentService.handlePaymentSubmissionEvent({
    formSubmissionResult,
    paymentSubmissionEvent,
    paymentReceiptUrl,
    })
    if (paymentSubmissionResult) {
    window.location.href = paymentSubmissionResult.payment.hostedFormUrl
    }

    Parameters

    Returns Promise<FormSubmissionResult["payment"]>