import TransaccionCompleta from '.' ; import Options from '../../common/options' ; import BaseTransaction from '../../common/base_transaction' ; import { CaptureRequest , CommitRequest , CreateRequest , InstallmentsRequest , RefundRequest , StatusRequest } from './requests' ; import RequestService from '../../common/request_service' ; import Environment from '../common/environment' ; import IntegrationCommerceCodes from '../../common/integration_commerce_codes' ; import IntegrationApiKeys from '../../common/integration_api_keys' ; import ValidationUtil from '../../common/validation_util' ; import ApiConstants from '../../common/api_constants' ; class Transaction extends BaseTransaction { param options constructor ( options ) { options = options || TransaccionCompleta . getDefaultOptions ( ) || new Options ( IntegrationCommerceCodes . TRANSACCION_COMPLETA , IntegrationApiKeys . WEBPAY , Environment . Integration ) ; super ( options ) ; } param buyOrder param sessionId param amount param cvv param cardNumber param cardExpirationDate async create ( buyOrder , sessionId , amount , cvv , cardNumber , cardExpirationDate ) { ValidationUtil . hasTextWithMaxLength ( buyOrder , ApiConstants . BUY_ORDER_LENGTH , "buyOrder" ) ; ValidationUtil . hasTextWithMaxLength ( sessionId , ApiConstants . SESSION_ID_LENGTH , "sessionId" ) ; ValidationUtil . hasTextWithMaxLength ( cardNumber , ApiConstants . CARD_NUMBER_LENGTH , "cardNumber" ) ; ValidationUtil . hasTextWithMaxLength ( cardExpirationDate , ApiConstants . CARD_EXPIRATION_DATE_LENGTH , "cardExpirationDate" ) ; let createRequest = new CreateRequest ( buyOrder , sessionId , amount , cvv , cardNumber . replace ( /\s/g , '' ) , cardExpirationDate . replace ( /\s/g , '' ) ) ; return RequestService . perform ( createRequest , this . options ) ; } param token param installmentsNumber async installments ( token , installmentsNumber ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; return RequestService . perform ( new InstallmentsRequest ( token , installmentsNumber ) , this . options ) ; } param token param idQueryInstallments param deferredPeriodIndex param gracePeriod async commit ( token , idQueryInstallments = undefined , deferredPeriodIndex = undefined , gracePeriod = undefined ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; let commitRequest = new CommitRequest ( token , idQueryInstallments , deferredPeriodIndex , gracePeriod ) ; return RequestService . perform ( commitRequest , this . options ) ; } param token async status ( token ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; return RequestService . perform ( new StatusRequest ( token ) , this . options ) ; } param token param amount async refund ( token , amount ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; let refundRequest = new RefundRequest ( token , amount ) ; return RequestService . perform ( refundRequest , this . options ) ; } param token param buyOrder param authorizationCode param captureAmount async capture ( token , buyOrder , authorizationCode , captureAmount ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; ValidationUtil . hasTextWithMaxLength ( buyOrder , ApiConstants . BUY_ORDER_LENGTH , "buyOrder" ) ; ValidationUtil . hasTextWithMaxLength ( authorizationCode , ApiConstants . AUTHORIZATION_CODE_LENGTH , "authorizationCode" ) ; let captureRequest = new CaptureRequest ( token , buyOrder , authorizationCode , captureAmount ) ; return RequestService . perform ( captureRequest , this . options ) ; } } ; export default Transaction ;