Skip to content

SudoSOS Back-end API / stripe / StripeService

Class: StripeService ​

Extends ​

Constructors ​

Constructor ​

ts
new StripeService(manager?): StripeService;

Parameters ​

ParameterType
manager?EntityManager

Returns ​

StripeService

Overrides ​

WithManager.constructor

Properties ​

PropertyModifierTypeInherited from
managerprotectedEntityManagerWithManager.manager

Methods ​

cancelPaymentIntent() ​

ts
cancelPaymentIntent(paymentIntent): Promise<StripePaymentIntent>;

Cancel a payment intent on Stripe. Note that this will trigger a webhook by Stripe, which should be handled correctly to prevent infinite loops.

Parameters ​

ParameterTypeDescription
paymentIntentStripePaymentIntent-

Returns ​

Promise<StripePaymentIntent>


cancelTerminalAction() ​

ts
cancelTerminalAction(readerId): Promise<Response<Reader>>;

Cancel the in-progress action (e.g. a payment being collected) on a Stripe Terminal reader, freeing it up for a new payment.

Parameters ​

ParameterTypeDescription
readerIdstringThe Stripe reader ID whose current action should be cancelled.

Returns ​

Promise<Response<Reader>>

The updated Stripe reader.


configureLogger() ​

ts
protected configureLogger(logger): void;

Parameters ​

ParameterType
loggerLogger

Returns ​

void

Inherited from ​

WithManager.configureLogger


createStripeDeposit() ​

ts
createStripeDeposit(
   user, 
   amount, 
   metadata?): Promise<{
  clientSecret: string;
  deposit: StripeDeposit;
}>;

Create deposit with a payment intent and save it to the database

Parameters ​

ParameterTypeDescription
userUserUser that wants to deposit some money into their account
amountDineroThe amount to be deposited
metadata?Record<string, any>Optional metadata to attach to the payment intent

Returns ​

Promise<{ clientSecret: string; deposit: StripeDeposit; }>

The created deposit entity and the Stripe client secret


createStripePaymentIntent() ​

ts
createStripePaymentIntent(
   user, 
   amount, 
   paymentMethod, 
   metadata?): Promise<{
  clientSecret: string;
  stripePaymentIntent: StripePaymentIntent;
}>;

Create a Stripe Payment Intent and save it to the database

Parameters ​

ParameterTypeDescription
userUserFor whom the payment intent is for
amountDineroThe amount to be deposited/paid using Stripe
paymentMethod"digital" | "terminal"The payment method to use: 'digital' for an online deposit (automatic payment methods) or 'terminal' for a card-present payment captured automatically by a Stripe Terminal.
metadata?Record<string, any>Optional extra metadata to attach to the payment intent

Returns ​

Promise<{ clientSecret: string; stripePaymentIntent: StripePaymentIntent; }>

The saved StripePaymentIntent and the Stripe client secret (null when Stripe does not return one).


getPaymentIntent() ​

ts
getPaymentIntent(stripeId): Promise<StripePaymentIntent>;

Get a payment intent with the given ID, if it exists

Parameters ​

ParameterTypeDescription
stripeIdstring-

Returns ​

Promise<StripePaymentIntent>


getSingleTerminal() ​

ts
getSingleTerminal(id): Promise<StripePaymentTerminal>;

Get the Stripe Payment Terminal with the given ID

Parameters ​

ParameterType
idstring

Returns ​

Promise<StripePaymentTerminal>


getTerminals() ​

ts
getTerminals(): Promise<StripePaymentTerminal[]>;

Get all Stripe Payment Terminals available in Stripe

Returns ​

Promise<StripePaymentTerminal[]>


handleStripeDepositPaid() ​

ts
handleStripeDepositPaid(paymentIntent): Promise<void>;

Create the transfer that belongs to the now paid paymentIntent

Parameters ​

ParameterTypeDescription
paymentIntentStripePaymentIntentStripe PaymentIntent that has been successfully paid

Returns ​

Promise<void>


startTerminalPayment() ​

ts
startTerminalPayment(terminalId, paymentIntent): Promise<void>;

Instruct a Stripe Terminal reader to start collecting payment for the given payment intent. WATCH OUT: when a terminal is already processing a payment, this "new" payment will silently override the existing payment! Only call this method when you are sure that the reader is available.

Parameters ​

ParameterTypeDescription
terminalIdstringThe Stripe reader ID that should process the payment.
paymentIntentstringThe Stripe ID of the payment intent to collect.

Returns ​

Promise<void>


asStripeDepositResponse() ​

ts
static asStripeDepositResponse(deposit): StripeDepositResponse;

Parameters ​

ParameterType
depositStripeDeposit

Returns ​

StripeDepositResponse


asStripePaymentTerminalResponse() ​

ts
static asStripePaymentTerminalResponse(terminal): StripePaymentTerminalResponse;

Convert an internal StripePaymentTerminal into its API response shape.

Parameters ​

ParameterTypeDescription
terminalStripePaymentTerminal-

Returns ​

StripePaymentTerminalResponse


getProcessingStripeDepositsFromUser() ​

ts
static getProcessingStripeDepositsFromUser(userId): Promise<StripeDeposit[]>;

Parameters ​

ParameterType
userIdnumber

Returns ​

Promise<StripeDeposit[]>


getStripeDeposit() ​

ts
static getStripeDeposit(id, relations?): Promise<StripeDeposit>;

Parameters ​

ParameterType
idnumber
relationsFindOptionsRelations<StripeDeposit>

Returns ​

Promise<StripeDeposit>


validateStripeRequestMaximumAmount() ​

ts
static validateStripeRequestMaximumAmount(balance, request): boolean;

Topup should be at most 150 euros minus user's positive balance or user's negative balance.

Parameters ​

ParameterTypeDescription
balanceBalanceResponse-
requestStripeRequest-

Returns ​

boolean


validateStripeRequestMinimumAmount() ​

ts
static validateStripeRequestMinimumAmount(balance, request): boolean;

Topup should be at least 10 euros or the user's negative balance.

Parameters ​

ParameterTypeDescription
balanceBalanceResponse-
requestStripeRequest-

Returns ​

boolean