payments/actions

Methods

(async, static) approvePayment(paymentKey, actionBy) → {Promise.<Payment>}

Source:

Given a paymentKey it does the following:

  1. Gets the last payment for the key and checks tha its pending
  2. Add a new row with approved state with the same info
  3. Request payment to external payment system/s
  4. Add a new roww with requested state

If any of the steps fails it throws an error.

Parameters:
Name Type Description
paymentKey string

Payment key

actionBy string

Action executor

Returns:

The approved payment

Type
Promise.<Payment>

(async, static) batchApprovePayments(paymentKeys, actionBy) → {Promise.<PaymentBatchApprove>}

Source:

Given a list of payment keys it tries to approve them in a sync way. If one fails it logs the

Parameters:
Name Type Description
paymentKeys Array.<string>

Payment keys

actionBy string

Action executor

Returns:

Batch approval response

Type
Promise.<PaymentBatchApprove>

(async, static) countPayments(args, actionBy) → {Promise.<number>}

Source:

Returns the total number of payments based on the args filtering.

This is used for pagination purposes.

Parameters:
Name Type Description
args PaymentFilters

Fitlering parameters

actionBy string

Action executor

Returns:
Type
Promise.<number>

(async, static) createPayment(params, actionBy) → {Promise.<Payment>}

Source:

Creates a new payment with status NEEDS_APPROVAL.

Parameters:
Name Type Description
params PaymentParams

Payment params

actionBy string

Action executor

Returns:

The created payment

Type
Promise.<Payment>

(async, static) denyPayment(paymentKey, reason, actionBy) → {Promise.<Payment>}

Source:

Denies a payment.

Parameters:
Name Type Description
paymentKey string

Payment key

reason string

Reason fo denial

actionBy string

Action executor

Throws:
  • If no payment for the given key are found

    Type
    Error
  • If reason is empty

    Type
    Error
Returns:

The last payment for the given key

Type
Promise.<Payment>

(async, static) getLastPayment(paymentKey, actionBy) → {Promise.<Payment>}

Source:

Given a paymentKey it returns the last unprocessed payment associated with that given key.

Parameters:
Name Type Description
paymentKey string

Payment key

actionBy string

Action executor

Throws:

If no payment for the given key are found

Type
Error
Returns:

The last payment for the given key

Type
Promise.<Payment>

(async, static) getPaymentHistory(paymentKey, actionBy) → {Promise.<Array.<Payment>>}

Source:

Given a paymentKey it returns the history of all payment associated with that given key, ordered by in decreasing order by its additions.

Note that only the unprocessed payments will be returned so that a clean history is kept.

Parameters:
Name Type Description
paymentKey string

Payment key

actionBy string

Action executor

Returns:

History of the payment as a list of payments

Type
Promise.<Array.<Payment>>

(async, static) getPaymentProcessingHistory(paymentKey, processingKey, actionBy) → {Promise.<Array.<Payment>>}

Source:

Given a paymentKey and a processingKey it returns the processing history.

Parameters:
Name Type Description
paymentKey string

Payment key

processingKey string

Payment processing key

actionBy string

Action executor

Throws:

If no payment for the given key are found

Type
Error
Returns:
Type
Promise.<Array.<Payment>>

(async, static) handleEvent(paymentKey, actionBy) → {Promise.<Payment>}

Source:

Handles an external event and process it.

Parameters:
Name Type Description
paymentKey ExternalPaymentEvent

Payment key

actionBy string

Action executor

Returns:

The handled payment

Type
Promise.<Payment>

(async, static) listPayments(args, actionBy) → {Promise.<Array.<Payment>>}

Source:

Returns a list of all the payments with possible filtering based on the args.

Parameters:
Name Type Description
args PaymentFilters | null

Fitlering parameters

actionBy string

Action executor

Returns:
Type
Promise.<Array.<Payment>>

(async, static) processPayment(paymentKey, processingKey, actionBy) → {Promise.<Payment>}

Source:

Marks a payment for a given (paymentKey, processingKey) pair as processed.

Parameters:
Name Type Description
paymentKey string

Payment key

processingKey string

Processing key

actionBy string

Action executor

Throws:

If no unprocessed payment with the requested params is not found.

Type
Error
Returns:

The processed payment

Type
Promise.<Payment>

(async, static) publishPaymentAdded(payment, actionBy) → {Promise.<void>}

Source:

Publishes that a non processed payment has been added.

Parameters:
Name Type Description
payment Payment

Payment ot be published

actionBy string

Action executor

Returns:
Type
Promise.<void>

(async, static) requestPayment(payment, actionBy) → {Promise.<PaymentRequestResponse>}

Source:

Requests the given payment to the messaging system via a req-reply flow.

Currently this is done via NATS to Orchestrator.

Parameters:
Name Type Description
payment Payment

The payment to be requested

actionBy string

The action executor

Returns:

The request response by the external service

Type
Promise.<PaymentRequestResponse>