SudoSOS Back-end API / stripe / StripeService
Class: StripeService ​
Extends ​
Constructors ​
Constructor ​
new StripeService(manager?): StripeService;Parameters ​
| Parameter | Type |
|---|---|
manager? | EntityManager |
Returns ​
StripeService
Overrides ​
Properties ​
| Property | Modifier | Type | Inherited from |
|---|---|---|---|
manager | protected | EntityManager | WithManager.manager |
Methods ​
cancelPaymentIntent() ​
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 ​
| Parameter | Type | Description |
|---|---|---|
paymentIntent | StripePaymentIntent | - |
Returns ​
Promise<StripePaymentIntent>
cancelTerminalAction() ​
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 ​
| Parameter | Type | Description |
|---|---|---|
readerId | string | The Stripe reader ID whose current action should be cancelled. |
Returns ​
Promise<Response<Reader>>
The updated Stripe reader.
configureLogger() ​
protected configureLogger(logger): void;Parameters ​
| Parameter | Type |
|---|---|
logger | Logger |
Returns ​
void
Inherited from ​
createStripeDeposit() ​
createStripeDeposit(
user,
amount,
metadata?): Promise<{
clientSecret: string;
deposit: StripeDeposit;
}>;Create deposit with a payment intent and save it to the database
Parameters ​
| Parameter | Type | Description |
|---|---|---|
user | User | User that wants to deposit some money into their account |
amount | Dinero | The 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() ​
createStripePaymentIntent(
user,
amount,
paymentMethod,
metadata?): Promise<{
clientSecret: string;
stripePaymentIntent: StripePaymentIntent;
}>;Create a Stripe Payment Intent and save it to the database
Parameters ​
| Parameter | Type | Description |
|---|---|---|
user | User | For whom the payment intent is for |
amount | Dinero | The 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() ​
getPaymentIntent(stripeId): Promise<StripePaymentIntent>;Get a payment intent with the given ID, if it exists
Parameters ​
| Parameter | Type | Description |
|---|---|---|
stripeId | string | - |
Returns ​
Promise<StripePaymentIntent>
getSingleTerminal() ​
getSingleTerminal(id): Promise<StripePaymentTerminal>;Get the Stripe Payment Terminal with the given ID
Parameters ​
| Parameter | Type |
|---|---|
id | string |
Returns ​
Promise<StripePaymentTerminal>
getTerminals() ​
getTerminals(): Promise<StripePaymentTerminal[]>;Get all Stripe Payment Terminals available in Stripe
Returns ​
Promise<StripePaymentTerminal[]>
handleStripeDepositPaid() ​
handleStripeDepositPaid(paymentIntent): Promise<void>;Create the transfer that belongs to the now paid paymentIntent
Parameters ​
| Parameter | Type | Description |
|---|---|---|
paymentIntent | StripePaymentIntent | Stripe PaymentIntent that has been successfully paid |
Returns ​
Promise<void>
startTerminalPayment() ​
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 ​
| Parameter | Type | Description |
|---|---|---|
terminalId | string | The Stripe reader ID that should process the payment. |
paymentIntent | string | The Stripe ID of the payment intent to collect. |
Returns ​
Promise<void>
asStripeDepositResponse() ​
static asStripeDepositResponse(deposit): StripeDepositResponse;Parameters ​
| Parameter | Type |
|---|---|
deposit | StripeDeposit |
Returns ​
asStripePaymentTerminalResponse() ​
static asStripePaymentTerminalResponse(terminal): StripePaymentTerminalResponse;Convert an internal StripePaymentTerminal into its API response shape.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
terminal | StripePaymentTerminal | - |
Returns ​
getProcessingStripeDepositsFromUser() ​
static getProcessingStripeDepositsFromUser(userId): Promise<StripeDeposit[]>;Parameters ​
| Parameter | Type |
|---|---|
userId | number |
Returns ​
Promise<StripeDeposit[]>
getStripeDeposit() ​
static getStripeDeposit(id, relations?): Promise<StripeDeposit>;Parameters ​
| Parameter | Type |
|---|---|
id | number |
relations | FindOptionsRelations<StripeDeposit> |
Returns ​
Promise<StripeDeposit>
validateStripeRequestMaximumAmount() ​
static validateStripeRequestMaximumAmount(balance, request): boolean;Topup should be at most 150 euros minus user's positive balance or user's negative balance.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
balance | BalanceResponse | - |
request | StripeRequest | - |
Returns ​
boolean
validateStripeRequestMinimumAmount() ​
static validateStripeRequestMinimumAmount(balance, request): boolean;Topup should be at least 10 euros or the user's negative balance.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
balance | BalanceResponse | - |
request | StripeRequest | - |
Returns ​
boolean