SudoSOS Back-end API / stripe/terminal-payment / TerminalPaymentService
Class: TerminalPaymentService ​
Extends ​
Constructors ​
Constructor ​
new TerminalPaymentService(manager?): TerminalPaymentService;Parameters ​
| Parameter | Type |
|---|---|
manager? | EntityManager |
Returns ​
TerminalPaymentService
Overrides ​
Properties ​
| Property | Modifier | Type | Inherited from |
|---|---|---|---|
manager | protected | EntityManager | WithManager.manager |
Methods ​
cancelTerminalPayment() ​
cancelTerminalPayment(id, sendStripeCancellation?): Promise<TerminalPayment>;Cancel a CREATED or PROCESSING terminal payment. Removes the temporary transaction.
Parameters ​
| Parameter | Type | Default value | Description |
|---|---|---|---|
id | number | undefined | ID of the TerminalPayment |
sendStripeCancellation | boolean | true | Whether 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() ​
protected configureLogger(logger): void;Parameters ​
| Parameter | Type |
|---|---|
logger | Logger |
Returns ​
void
Inherited from ​
createTerminalPayment() ​
createTerminalPayment(params, context): Promise<TerminalPayment>;Create a new TerminalPayment. Save the transaction as a temporary, immutable record to the database.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
params | CreateTerminalPaymentRequest | - |
context | TransactionContext | Transaction context returned by the transaction validator. |
Returns ​
Promise<TerminalPayment>
getRelation() ​
getRelation(id, userId): Promise<"all" | "own">;Determine whether the given user is connected to the TerminalPayment with the given ID:
ownif they created it, or are the buyer or creator of its transactionallotherwise, and when the TerminalPayment does not exist
Parameters ​
| Parameter | Type | Description |
|---|---|---|
id | number | ID of the TerminalPayment. |
userId | number | ID of the user whose relation to it is being determined. |
Returns ​
Promise<"all" | "own">
getTerminalPayment() ​
getTerminalPayment(id): Promise<TerminalPayment>;Find the TerminalPayment with the given ID
Parameters ​
| Parameter | Type |
|---|---|
id | number |
Returns ​
Promise<TerminalPayment>
The TerminalPayment if found. Null if not found.
getTerminalPaymentByPaymentIntentId() ​
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 ​
| Parameter | Type | Description |
|---|---|---|
paymentIntentId | number | The database ID of the StripePaymentIntent. |
Returns ​
Promise<TerminalPayment>
The TerminalPayment if found. Null if not found.
handleTerminalPaymentSuccess() ​
handleTerminalPaymentSuccess(paymentIntent): Promise<TerminalPayment>;Create the transaction and corresponding transfer in the database
Parameters ​
| Parameter | Type | Description |
|---|---|---|
paymentIntent | StripePaymentIntent | PaymentIntent that has been paid |
Returns ​
Promise<TerminalPayment>
startTerminalPayment() ​
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 ​
| Parameter | Type | Description |
|---|---|---|
id | number | ID of the TerminalPayment to process. |
params | ProcessTerminalPaymentRequest | Request holding the Stripe terminal ID to process with. |
Returns ​
Promise<TerminalPayment>
The updated TerminalPayment.
verifyTerminalPaymentRequest() ​
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 ​
| Parameter | Type | Description |
|---|---|---|
params | CreateTerminalPaymentRequest | - |
Returns ​
Promise<{ context?: TransactionContext; valid: boolean; }>
asTerminalPaymentResponse() ​
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 ​
| Parameter | Type | Description |
|---|---|---|
tp | TerminalPayment | The entity to convert. |
context? | TransactionContext | Optional transaction context to reuse when building the embedded transaction response. |
Returns ​
Promise<TerminalPaymentResponse>