Skip to content

SudoSOS Back-end API / stripe/terminal-payment / TerminalPaymentService

Class: TerminalPaymentService ​

Extends ​

Constructors ​

Constructor ​

ts
new TerminalPaymentService(manager?): TerminalPaymentService;

Parameters ​

ParameterType
manager?EntityManager

Returns ​

TerminalPaymentService

Overrides ​

WithManager.constructor

Properties ​

PropertyModifierTypeInherited from
managerprotectedEntityManagerWithManager.manager

Methods ​

cancelTerminalPayment() ​

ts
cancelTerminalPayment(id, sendStripeCancellation?): Promise<TerminalPayment>;

Cancel a CREATED or PROCESSING terminal payment. Removes the temporary transaction.

Parameters ​

ParameterTypeDefault valueDescription
idnumberundefinedID of the TerminalPayment
sendStripeCancellationbooleantrueWhether the corresponding PaymentIntent must also be cancelled at Stripe. Defaults to true, but should be false when Stripe is cancelling the terminalPayment.

Returns ​

Promise<TerminalPayment>

The cancelled TerminalPayment.


configureLogger() ​

ts
protected configureLogger(logger): void;

Parameters ​

ParameterType
loggerLogger

Returns ​

void

Inherited from ​

WithManager.configureLogger


createTerminalPayment() ​

ts
createTerminalPayment(params, context): Promise<TerminalPayment>;

Create a new TerminalPayment. Save the transaction as a temporary, immutable record to the database.

Parameters ​

ParameterTypeDescription
paramsCreateTerminalPaymentRequest-
contextTransactionContextTransaction context returned by the transaction validator.

Returns ​

Promise<TerminalPayment>


getRelation() ​

ts
getRelation(id, userId): Promise<"all" | "own">;

Determine whether the given user is connected to the TerminalPayment with the given ID:

  • own if they created it, or are the buyer or creator of its transaction
  • all otherwise, and when the TerminalPayment does not exist

Parameters ​

ParameterTypeDescription
idnumberID of the TerminalPayment.
userIdnumberID of the user whose relation to it is being determined.

Returns ​

Promise<"all" | "own">


getTerminalPayment() ​

ts
getTerminalPayment(id): Promise<TerminalPayment>;

Find the TerminalPayment with the given ID

Parameters ​

ParameterType
idnumber

Returns ​

Promise<TerminalPayment>

The TerminalPayment if found. Null if not found.


getTerminalPaymentByPaymentIntentId() ​

ts
getTerminalPaymentByPaymentIntentId(paymentIntentId): Promise<TerminalPayment>;

Find the TerminalPayment belonging to the given Stripe payment intent. Used after a webhook has been processed, to report the payment's new state to subscribers.

Parameters ​

ParameterTypeDescription
paymentIntentIdnumberThe database ID of the StripePaymentIntent.

Returns ​

Promise<TerminalPayment>

The TerminalPayment if found. Null if not found.


handleTerminalPaymentSuccess() ​

ts
handleTerminalPaymentSuccess(paymentIntent): Promise<TerminalPayment>;

Create the transaction and corresponding transfer in the database

Parameters ​

ParameterTypeDescription
paymentIntentStripePaymentIntentPaymentIntent that has been paid

Returns ​

Promise<TerminalPayment>


startTerminalPayment() ​

ts
startTerminalPayment(id, params): Promise<TerminalPayment>;

Send the payment to the terminal: record which reader is handling it and instruct Stripe to start collecting the payment.

Parameters ​

ParameterTypeDescription
idnumberID of the TerminalPayment to process.
paramsProcessTerminalPaymentRequestRequest holding the Stripe terminal ID to process with.

Returns ​

Promise<TerminalPayment>

The updated TerminalPayment.


verifyTerminalPaymentRequest() ​

ts
verifyTerminalPaymentRequest(params): Promise<{
  context?: TransactionContext;
  valid: boolean;
}>;

Verify whether the given terminal payment request object is valid. Primarily checks whether the transaction is OK.

Parameters ​

ParameterTypeDescription
paramsCreateTerminalPaymentRequest-

Returns ​

Promise<{ context?: TransactionContext; valid: boolean; }>


asTerminalPaymentResponse() ​

ts
static asTerminalPaymentResponse(tp, context?): Promise<TerminalPaymentResponse>;

Convert a TerminalPayment entity into its API response shape. The embedded transaction is taken from the final transaction when the payment has succeeded, otherwise from the temporary transaction (if any).

Parameters ​

ParameterTypeDescription
tpTerminalPaymentThe entity to convert.
context?TransactionContextOptional transaction context to reuse when building the embedded transaction response.

Returns ​

Promise<TerminalPaymentResponse>