import WebpayPlus from '.' ; import Options from '../../common/options' ; import TransactionDetail from '../common/transaction_detail' ; import BaseTransaction from '../../common/base_transaction' ; import { CommitRequest , MallCreateRequest , MallRefundRequest , StatusRequest } from './requests' ; import RequestService from '../../common/request_service' ; import MallCaptureRequest from '../transaccion_completa/requests/mall_capture_request' ; import IntegrationCommerceCodes from '../../common/integration_commerce_codes' ; import IntegrationApiKeys from '../../common/integration_api_keys' ; import Environment from '../common/environment' ; import ValidationUtil from '../../common/validation_util' ; import ApiConstants from '../../common/api_constants' ; class MallTransaction extends BaseTransaction { param options constructor ( options ) { options = options || WebpayPlus . getDefaultOptions ( ) || new Options ( IntegrationCommerceCodes . WEBPAY_PLUS_MALL , IntegrationApiKeys . WEBPAY , Environment . Integration ) ; super ( options ) ; } param buyOrder param sessionId param returnUrl param details Child transactions details, see  TransactionDetail for more information.
      async create ( buyOrder , sessionId , returnUrl , details ) { ValidationUtil . hasTextWithMaxLength ( buyOrder , ApiConstants . BUY_ORDER_LENGTH , "buyOrder" ) ; ValidationUtil . hasTextWithMaxLength ( sessionId , ApiConstants . SESSION_ID_LENGTH , "sessionId" ) ; ValidationUtil . hasTextWithMaxLength ( returnUrl , ApiConstants . RETURN_URL_LENGTH , "returnUrl" ) ; 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" ) ; } return RequestService . perform ( new MallCreateRequest ( buyOrder , sessionId , returnUrl , details ) , this . options ) ; } param token async commit ( token ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; return RequestService . perform ( new CommitRequest ( token ) , 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 buyOrder param childCommerceCode param amount param options 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" ) ; return RequestService . perform ( new MallRefundRequest ( token , buyOrder , childCommerceCode , amount ) , this . options ) ; } param childCommerceCode param token param buyOrder param authorizationCode param captureAmount async capture ( childCommerceCode , token , buyOrder , authorizationCode , captureAmount ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; ValidationUtil . hasTextWithMaxLength ( childCommerceCode , ApiConstants . COMMERCE_CODE_LENGTH , "childCommerceCode" ) ; ValidationUtil . hasTextWithMaxLength ( buyOrder , ApiConstants . BUY_ORDER_LENGTH , "buyOrder" ) ; ValidationUtil . hasTextWithMaxLength ( authorizationCode , ApiConstants . AUTHORIZATION_CODE_LENGTH , "authorizationCode" ) ; return RequestService . perform ( new MallCaptureRequest ( token , childCommerceCode , buyOrder , authorizationCode , captureAmount ) , this . options ) ; } } ; export default MallTransaction ;