import { CommercetoolsAPI, UpdateResource } from './api.type'; import { Logger } from '../../logger'; import { CustomFieldsDraft, PaymentMethod, PaymentMethodPagedQueryResponse, PaymentMethodUpdateAction } from '@commercetools/platform-sdk'; export type PaymentMethodServiceOptions = { ctAPI: CommercetoolsAPI; logger: Logger; }; export type FindPaymentMethod = { customerId: string; paymentInterface: string; interfaceAccount?: string; }; export type GetPaymentMethod = { customerId: string; id: string; paymentInterface: string; interfaceAccount?: string; }; export type GetByTokenValuePaymentMethod = { customerId: string; tokenValue: string; paymentInterface: string; interfaceAccount?: string; }; export type DoesTokenBelongToCustomer = { customerId: string; tokenValue: string; paymentInterface: string; interfaceAccount?: string; }; export type DeletePaymentMethod = { customerId: string; id: string; version: number; }; export type UpdatePaymentMethod = { customerId: string; resource: UpdateResource; actions: PaymentMethodUpdateAction[]; }; export type SavePaymentMethodDraft = { customerId: string; token: string; paymentInterface: string; interfaceAccount?: string; method: string; customFields?: CustomFieldsDraft; }; /** * Payment methods service interface exposes methods to interact with the commercetools platform API. */ export interface PaymentMethodService { /** * Finds all of the payment-methods that match with the given parameters. * * @param opts the parameters to search by * * @returns a paged list of payment-methods */ find(opts: FindPaymentMethod): Promise; /** * Returns a payment-method by the given ID which must belong to the given customerId. * * @param opts * * @returns the payment-method */ get(opts: GetPaymentMethod): Promise; /** * Returns a payment-method by the given tokenValue which must belong to the given customerId and must be unique. * * @param opts * * @returns the payment-method */ getByTokenValue(opts: GetByTokenValuePaymentMethod): Promise; /** * Returns true if the given token belongs to the given customer for any payment-method. * * @param opts * * @returns true if the given token belongs to the customer for any payment method, false otherwise. */ doesTokenBelongsToCustomer(opts: DoesTokenBelongToCustomer): Promise; /** * Saves a new payment-method given the draft payload. The customer attribute is mandatory. * * @param opts the payment-method draft * * @returns the newly created payment-method */ save(opts: SavePaymentMethodDraft): Promise; /** * Updates an existing payment-method with the given list of update actions. The payment-method must belong to the given customerId. * * @param opts the list of update actions to apply * * @returns the updated payment-method */ update(opts: UpdatePaymentMethod): Promise; /** * Deletes the given payment-method * * @param opts the payment-method to delete * * @returns returns the final state of the payment-method before it's deleted */ delete(opts: DeletePaymentMethod): Promise; }