import TransaccionCompleta from '.' ; import Options from '../../common/options' ; import InstallmentDetail from '../common/installments_detail' ; import TransaccionCompletaCommitDetail from './common/commit_detail' ; import TransactionDetail from '../common/transaction_detail' ; import BaseTransaction from '../../common/base_transaction' ; import { InstallmentsRequest , MallCommitRequest , MallCreateRequest , MallRefundRequest , StatusRequest } from './requests' ; import RequestService from '../../common/request_service' ; import MallCaptureRequest from './requests/mall_capture_request' ; 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 MallTransaction extends BaseTransaction { param options constructor ( options ) { options = options || TransaccionCompleta . getDefaultOptions ( ) || new Options ( IntegrationCommerceCodes . TRANSACCION_COMPLETA_MALL , IntegrationApiKeys . WEBPAY , Environment . Integration ) ; super ( options ) ; } param buyOrder param sessionId param cardNumber param cardExpirationDate param details Child transactions details, see  TransactionDetail for more information.
     *  param cvv async create ( buyOrder , sessionId , cardNumber , cardExpirationDate , details , cvv ) { 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" ) ; ValidationUtil . hasElements ( details , "details" ) ; for ( let i = 0 ; i < details . length ; i ++ ) { let item = details [ i ] ; ValidationUtil . hasTextWithMaxLength ( item . commerceCode , ApiConstants . COMMERCE_CODE_LENGTH , "details.commerceCode" ) ; ValidationUtil . hasTextWithMaxLength ( item . buyOrder , ApiConstants . BUY_ORDER_LENGTH , "details.buyOrder" ) ; } let createRequest = new MallCreateRequest ( buyOrder , sessionId , cvv , cardNumber . replace ( /\s/g , '' ) , cardExpirationDate . replace ( /\s/g , '' ) , details ) ; return RequestService . perform ( createRequest , this . options ) ; } param token param details Child transactions details, see  InstallmentDetail for more information.
      async installments ( token , details ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; let response = [ ] ; for ( let detail of details ) { let installmentsRequest = new InstallmentsRequest ( token , detail . installmentsNumber , detail . commerceCode , detail . buyOrder ) ; response . push ( await RequestService . perform ( installmentsRequest , this . options ) ) ; } return response ; } param token param details Child transactions details, see  CommitDetail for more information.
      async commit ( token , details ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; return RequestService . perform ( new MallCommitRequest ( token , details ) , this . options ) ; } param token param buyOrder param childCommerceCode param amount async refund ( token , buyOrder , childCommerceCode , amount ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; ValidationUtil . hasTextWithMaxLength ( childCommerceCode , ApiConstants . COMMERCE_CODE_LENGTH , "childCommerceCode" ) ; ValidationUtil . hasTextWithMaxLength ( buyOrder , ApiConstants . BUY_ORDER_LENGTH , "buyOrder" ) ; let refundRequest = new MallRefundRequest ( token , buyOrder , childCommerceCode , amount ) ; return RequestService . perform ( refundRequest , 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 commerceCode param buyOrder param authorizationCode param captureAmount async capture ( token , commerceCode , buyOrder , authorizationCode , captureAmount ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; ValidationUtil . hasTextWithMaxLength ( commerceCode , ApiConstants . COMMERCE_CODE_LENGTH , "commerceCode" ) ; ValidationUtil . hasTextWithMaxLength ( buyOrder , ApiConstants . BUY_ORDER_LENGTH , "buyOrder" ) ; ValidationUtil . hasTextWithMaxLength ( authorizationCode , ApiConstants . AUTHORIZATION_CODE_LENGTH , "authorizationCode" ) ; let captureRequest = new MallCaptureRequest ( token , commerceCode , buyOrder , authorizationCode , captureAmount ) ; return RequestService . perform ( captureRequest , this . options ) ; } } ; export default MallTransaction ;