UNPKG

@test-org122/hypernet-core

Version:

Hypernet Core. Represents the SDK for running the Hypernet Protocol.

100 lines 7.05 kB
import { IPaymentService } from "@interfaces/business"; import { IAccountsRepository, ILinkRepository, IMerchantConnectorRepository } from "@interfaces/data"; import { IPaymentRepository } from "@interfaces/data/IPaymentRepository"; import { BigNumber, EthereumAddress, Payment, PublicIdentifier, ResultAsync, Result, HexString } from "@interfaces/objects"; import { AcceptPaymentError, CoreUninitializedError, InsufficientBalanceError, InvalidParametersError, LogicalError, MerchantConnectorError, OfferMismatchError, RouterChannelUnknownError, VectorError } from "@interfaces/objects/errors"; import { IConfigProvider, IContextProvider, ILogUtils } from "@interfaces/utilities"; /** * PaymentService uses Vector internally to send payments on the requested channel. * The order of operations for sending funds is as follows: * sendFunds() is called by sender, which creates a Message transfer with Vector, which triggers * offerReceived() on the recipient side, which tosses an event up to the user, who then calls * acceptOffers() to accept the sender's funds, which creates an Insurance transfer with Vector, which triggers * stakePosted() on the sender's side, which finally creates the Parameterized transfer with Vector, which triggers * paymentPosted() on the recipient's side, which finalizes/resolves the vector parameterized transfer. * * Note that the general expected order of operations is mirrored by the ordering of functions within this class. * * @todo we should also finalize the insurance transfer, and maybe finalize the offer transfer */ export declare class PaymentService implements IPaymentService { protected linkRepository: ILinkRepository; protected accountRepository: IAccountsRepository; protected contextProvider: IContextProvider; protected configProvider: IConfigProvider; protected paymentRepository: IPaymentRepository; protected merchantConnectorRepository: IMerchantConnectorRepository; protected logUtils: ILogUtils; /** * Creates an instanceo of the paymentService. */ constructor(linkRepository: ILinkRepository, accountRepository: IAccountsRepository, contextProvider: IContextProvider, configProvider: IConfigProvider, paymentRepository: IPaymentRepository, merchantConnectorRepository: IMerchantConnectorRepository, logUtils: ILogUtils); /** * Authorizes funds to a specified counterparty, with an amount, rate, & expiration date. * @param counterPartyAccount the public identifier of the counterparty to authorize funds to * @param totalAuthorized the total amount the counterparty is allowed to "pull" * @param expirationDate the latest time in which the counterparty can pull funds. This must be after the full maturation date of totalAuthorized, as calculated via deltaAmount and deltaTime. * @param deltaAmount The amount per deltaTime to authorize * @param deltaTime the number of seconds after which deltaAmount will be authorized, up to the limit of totalAuthorized. * @param requiredStake the amount of stake the counterparyt must put up as insurance * @param paymentToken the (Ethereum) address of the payment token * @param merchantUrl the registered URL for the merchant that will resolve any disputes. */ authorizeFunds(counterPartyAccount: PublicIdentifier, totalAuthorized: BigNumber, expirationDate: number, deltaAmount: string, deltaTime: number, requiredStake: BigNumber, paymentToken: EthereumAddress, merchantUrl: string): ResultAsync<Payment, RouterChannelUnknownError | CoreUninitializedError | VectorError | Error>; pullFunds(paymentId: string, amount: BigNumber): ResultAsync<Payment, RouterChannelUnknownError | CoreUninitializedError | VectorError | Error>; /** * Sends a payment to the specified recipient. * Internally, creates a null/message/offer transfer to communicate * with the counterparty and signal a request for a stake. * @param counterPartyAccount the intended recipient * @param amount the amount of payment to send * @param expirationDate the expiration date at which point this payment will revert * @param requiredStake the amount of insurance the counterparty should put up * @param paymentToken the (Ethereum) address of the payment token * @param merchantUrl the registered URL for the merchant that will resolve any disputes. */ sendFunds(counterPartyAccount: PublicIdentifier, amount: string, expirationDate: number, requiredStake: string, paymentToken: EthereumAddress, merchantUrl: string): ResultAsync<Payment, Error>; /** * Called when someone has sent us a payment offer. * Lookup the transfer, and convert it to a payment. * Then, publish an RXJS event to the user. * @param paymentId the paymentId for the offer */ offerReceived(paymentId: string): ResultAsync<void, LogicalError | RouterChannelUnknownError | CoreUninitializedError | VectorError | Error>; /** * For each paymentID provided, attempts to accept funds (ie: provide a stake) for that payment. * @param paymentIds a list of paymentIds for which to accept funds for */ acceptOffers(paymentIds: string[]): ResultAsync<Result<Payment, AcceptPaymentError>[], InsufficientBalanceError | AcceptPaymentError>; /** * Notifies the service that a stake has been posted; if verified, * then provides assets to the counterparty (ie a parameterizedPayment) * @param paymentId the paymentId for the stake */ stakePosted(paymentId: string): ResultAsync<void, CoreUninitializedError | OfferMismatchError | InvalidParametersError>; /** * Notifies the service that the parameterized payment has been created. * Called by the reciever of a parameterized transfer, AFTER they have put up stake, * and after the sender has created the Parameterized transfer * @param paymentId the payment ID to accept/resolve */ paymentPosted(paymentId: string): ResultAsync<void, InvalidParametersError>; /** * Notifies the service that the parameterized payment has been resolved. * @param paymentId the payment id that has been resolved. */ paymentCompleted(paymentId: HexString): ResultAsync<void, InvalidParametersError | RouterChannelUnknownError | CoreUninitializedError | VectorError>; /** * Right now, if the insurance is resolved, all we need to do is generate an update event. * * @param paymentId */ insuranceResolved(paymentId: HexString): ResultAsync<void, InvalidParametersError>; /** * Notifies the service that a pull-payment has been recorded. * @param paymentId the paymentId for the pull-payment */ pullRecorded(paymentId: string): ResultAsync<void, InvalidParametersError>; initiateDispute(paymentId: string): ResultAsync<Payment, InvalidParametersError | CoreUninitializedError | MerchantConnectorError | RouterChannelUnknownError | CoreUninitializedError | VectorError | Error>; } //# sourceMappingURL=PaymentService.d.ts.map