Skip to main content
Skip to main content

PaymentProviderService

Helps retrieve payment providers

Constructors

constructor

**new PaymentProviderService**(container)

Parameters

containerInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
container_InjectedDependenciesRequired
customerService_CustomerServiceRequired
featureFlagRouter_FlagRouterRequired
logger_LoggerRequired
manager_EntityManagerRequired
paymentProviderRepository_Repository<PaymentProvider>Required
paymentRepository_Repository<Payment>Required
paymentSessionRepository_Repository<PaymentSession>Required
refundRepository_Repository<Refund>Required
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

paymentService_

Protected get**paymentService_**(): [PaymentService](/references/services/classes/PaymentService)

Returns

PaymentService

defaultPaymentServiceRequired

Methods

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

TResultobjectRequired
TErrorobjectRequired

Parameters

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

authorizePayment

**authorizePayment**(paymentSession, context): Promise&#60;undefined \| [PaymentSession](/references/services/classes/PaymentSession)&#62;

Parameters

paymentSessionPaymentSessionRequired
A Payment Session is created when a Customer initilizes the checkout flow, and can be used to hold the state of a payment flow. Each Payment Session is controlled by a Payment Provider, which is responsible for the communication with external payment services. Authorized Payment Sessions will eventually get promoted to Payments to indicate that they are authorized for payment processing such as capture or refund. Payment sessions can also be used as part of payment collections.
contextRecord<string, unknown>Required

Returns

Promise<undefined | PaymentSession>

PromisePromise<undefined | PaymentSession>Required

buildPaymentProcessorContext

Protected **buildPaymentProcessorContext**(cartOrData): [Cart](/references/services/classes/Cart) & [PaymentContext](/references/services/types/PaymentContext)

Build the create session context for both legacy and new API

Parameters

cartOrDataCart | PaymentSessionInputRequired

Returns

Cart & PaymentContext

Cart & PaymentContextCart & PaymentContext

cancelPayment

**cancelPayment**(paymentObj): Promise&#60;[Payment](/references/services/classes/Payment)&#62;

Parameters

paymentObjPartial<Payment> & &#123; id: string &#125;Required

Returns

Promise<Payment>

PromisePromise<Payment>Required

capturePayment

**capturePayment**(paymentObj): Promise&#60;[Payment](/references/services/classes/Payment)&#62;

Parameters

paymentObjPartial<Payment> & &#123; id: string &#125;Required

Returns

Promise<Payment>

PromisePromise<Payment>Required

createPayment

**createPayment**(data): Promise&#60;[Payment](/references/services/classes/Payment)&#62;

Parameters

dataCreatePaymentInputRequired

Returns

Promise<Payment>

PromisePromise<Payment>Required

createSession

**createSession**(providerId, cart): Promise&#60;[PaymentSession](/references/services/classes/PaymentSession)&#62;

Parameters

providerIdstringRequired
cartCartRequired

Returns

Promise<PaymentSession>

PromisePromise<PaymentSession>Required

Deprecated

**createSession**(sessionInput): Promise&#60;[PaymentSession](/references/services/classes/PaymentSession)&#62;

Creates a payment session with the given provider.

Parameters

sessionInputPaymentSessionInputRequired

Returns

Promise<PaymentSession>

PromisePromise<PaymentSession>Required

deleteSession

**deleteSession**(paymentSession): Promise&#60;undefined \| [PaymentSession](/references/services/classes/PaymentSession)&#62;

Parameters

paymentSessionPaymentSessionRequired
A Payment Session is created when a Customer initilizes the checkout flow, and can be used to hold the state of a payment flow. Each Payment Session is controlled by a Payment Provider, which is responsible for the communication with external payment services. Authorized Payment Sessions will eventually get promoted to Payments to indicate that they are authorized for payment processing such as capture or refund. Payment sessions can also be used as part of payment collections.

Returns

Promise<undefined | PaymentSession>

PromisePromise<undefined | PaymentSession>Required

getStatus

**getStatus**(payment): Promise&#60;[PaymentSessionStatus](/references/services/enums/PaymentSessionStatus)&#62;

Parameters

paymentPaymentRequired
A payment is originally created from a payment session. Once a payment session is authorized, the payment is created to represent the authorized amount with a given payment method. Payments can be captured, canceled or refunded. Payments can be made towards orders, swaps, order edits, or other resources.

Returns

Promise<PaymentSessionStatus>

PromisePromise<PaymentSessionStatus>Required

list

**list**(): Promise&#60;[PaymentProvider](/references/services/classes/PaymentProvider)[]&#62;

Returns

Promise<PaymentProvider[]>

PromisePromise<PaymentProvider[]>Required

listPayments

**listPayments**(selector, config?): Promise&#60;[Payment](/references/services/classes/Payment)[]&#62;

List all the payments according to the given selector and config.

Parameters

selectorSelector<Payment>Required
configFindConfig<Payment>Required

Returns

Promise<Payment[]>

PromisePromise<Payment[]>Required

processUpdateRequestsData

Protected **processUpdateRequestsData**(data?, paymentResponse): Promise&#60;void&#62;

Process the collected data. Can be used every time we need to process some collected data returned by the provider

Parameters

dataobjectRequired

Default: {}

data.customerobject
data.customer.idstring
paymentResponseRecord<string, unknown> | PaymentSessionResponseRequired

Returns

Promise<void>

PromisePromise<void>Required

refreshSession

**refreshSession**(paymentSession, sessionInput): Promise&#60;[PaymentSession](/references/services/classes/PaymentSession)&#62;

Refreshes a payment session with the given provider. This means, that we delete the current one and create a new.

Parameters

paymentSessionobjectRequired
the payment session object to update
paymentSession.dataRecord<string, unknown>Required
paymentSession.idstringRequired
paymentSession.provider_idstringRequired
sessionInputPaymentSessionInputRequired

Returns

Promise<PaymentSession>

PromisePromise<PaymentSession>Required
the payment session

refundFromPayment

**refundFromPayment**(payment, amount, reason, note?): Promise&#60;[Refund](/references/services/classes/Refund)&#62;

Parameters

paymentPaymentRequired
A payment is originally created from a payment session. Once a payment session is authorized, the payment is created to represent the authorized amount with a given payment method. Payments can be captured, canceled or refunded. Payments can be made towards orders, swaps, order edits, or other resources.
amountnumberRequired
reasonstringRequired
notestring

Returns

Promise<Refund>

PromisePromise<Refund>Required

refundPayment

**refundPayment**(payObjs, amount, reason, note?): Promise&#60;[Refund](/references/services/classes/Refund)&#62;

Parameters

payObjsPayment[]Required
amountnumberRequired
reasonstringRequired
notestring

Returns

Promise<Refund>

PromisePromise<Refund>Required

registerInstalledProviders

**registerInstalledProviders**(providerIds): Promise&#60;void&#62;

Parameters

providerIdsstring[]Required

Returns

Promise<void>

PromisePromise<void>Required

retrievePayment

**retrievePayment**(paymentId, relations?): Promise&#60;[Payment](/references/services/classes/Payment)&#62;

Retrieve a payment entity with the given id.

Parameters

paymentIdstringRequired
relationsstring[]Required

Default: []

Returns

Promise<Payment>

PromisePromise<Payment>Required

retrieveProvider

**retrieveProvider**<TypeParameter TProvider>(providerId): TProvider extends [AbstractPaymentService](/references/services/classes/AbstractPaymentService) ? [AbstractPaymentService](/references/services/classes/AbstractPaymentService) : TProvider extends [AbstractPaymentProcessor](/references/services/classes/AbstractPaymentProcessor) ? [AbstractPaymentProcessor](/references/services/classes/AbstractPaymentProcessor) : any

Finds a provider given an id

TProviderunknownRequired

Parameters

providerIdstringRequired
the id of the provider to get

Returns

TProvider extends AbstractPaymentService ? AbstractPaymentService : TProvider extends AbstractPaymentProcessor ? AbstractPaymentProcessor : any

TProvider extends AbstractPaymentService ? AbstractPaymentService : TProvider extends AbstractPaymentProcessor ? AbstractPaymentProcessor : anyTProvider extends AbstractPaymentService ? AbstractPaymentService : TProvider extends AbstractPaymentProcessor ? AbstractPaymentProcessor : any
the payment provider

retrieveRefund

**retrieveRefund**(id, config?): Promise&#60;[Refund](/references/services/classes/Refund)&#62;

Parameters

idstringRequired
configFindConfig<Refund>Required

Default: {}

Returns

Promise<Refund>

PromisePromise<Refund>Required

retrieveSession

**retrieveSession**(paymentSessionId, relations?): Promise&#60;[PaymentSession](/references/services/classes/PaymentSession)&#62;

Return the payment session for the given id.

Parameters

paymentSessionIdstringRequired
relationsstring[]Required

Default: []

Returns

Promise<PaymentSession>

PromisePromise<PaymentSession>Required

saveSession

Protected **saveSession**(providerId, data): Promise&#60;[PaymentSession](/references/services/classes/PaymentSession)&#62;

Create or update a Payment session data.

Parameters

providerIdstringRequired
dataobjectRequired
data.amountnumber
data.cartIdstring
data.isInitiatedboolean
data.isSelectedboolean
data.payment_session_idstring
data.sessionDataRecord<string, unknown>Required

Returns

Promise<PaymentSession>

PromisePromise<PaymentSession>Required

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

errRecord<string, unknown> | &#123; code: string &#125;Required

Returns

boolean

booleanboolean

throwFromPaymentProcessorError

Private **throwFromPaymentProcessorError**(errObj): void

Parameters

errObjPaymentProcessorErrorRequired

Returns

void

voidvoid

updatePayment

**updatePayment**(paymentId, data): Promise&#60;[Payment](/references/services/classes/Payment)&#62;

Parameters

paymentIdstringRequired
dataobjectRequired
data.order_idstring
data.swap_idstring

Returns

Promise<Payment>

PromisePromise<Payment>Required

updateSession

**updateSession**(paymentSession, sessionInput): Promise&#60;[PaymentSession](/references/services/classes/PaymentSession)&#62;

Update a payment session with the given provider.

Parameters

paymentSessionobjectRequired
The paymentSession to update
paymentSession.dataRecord<string, unknown>Required
paymentSession.idstringRequired
paymentSession.provider_idstringRequired
sessionInputCart | PaymentSessionInputRequired

Returns

Promise<PaymentSession>

PromisePromise<PaymentSession>Required
the payment session

updateSessionData

**updateSessionData**(paymentSession, data): Promise&#60;[PaymentSession](/references/services/classes/PaymentSession)&#62;

Parameters

paymentSessionPaymentSessionRequired
A Payment Session is created when a Customer initilizes the checkout flow, and can be used to hold the state of a payment flow. Each Payment Session is controlled by a Payment Provider, which is responsible for the communication with external payment services. Authorized Payment Sessions will eventually get promoted to Payments to indicate that they are authorized for payment processing such as capture or refund. Payment sessions can also be used as part of payment collections.
dataRecord<string, unknown>Required

Returns

Promise<PaymentSession>

PromisePromise<PaymentSession>Required

withTransaction

**withTransaction**(transactionManager?): [PaymentProviderService](/references/services/classes/PaymentProviderService)

Parameters

transactionManagerEntityManager

Returns

PaymentProviderService

defaultPaymentProviderServiceRequired
Was this section helpful?