import Oneclick from '.' ; import Options from '../../common/options' ; import TransactionDetail from '../common/transaction_detail' ; import BaseTransaction from '../../common/base_transaction' ; import RequestService from '../../common/request_service' ; import { AuthorizeRequest , CaptureRequest , RefundRequest , StatusRequest } from './requests' ; import ValidationUtil from '../../common/validation_util' ; import ApiConstants from '../../common/api_constants' ; import IntegrationCommerceCodes from '../../common/integration_commerce_codes' ; import IntegrationApiKeys from '../../common/integration_api_keys' ; import Environment from '../common/environment' ; class MallTransaction extends BaseTransaction { param options constructor ( options ) { options = options || Oneclick . getDefaultOptions ( ) || new Options ( IntegrationCommerceCodes . ONECLICK_MALL , IntegrationApiKeys . WEBPAY , Environment . Integration ) ; super ( options ) ; } param username param tbkUser param parentBuyOrder param details Child transactions details, see  TransactionDetail for more information.
      async authorize ( username , tbkUser , parentBuyOrder , details ) { ValidationUtil . hasTextWithMaxLength ( username , ApiConstants . USER_NAME_LENGTH , "username" ) ; ValidationUtil . hasTextWithMaxLength ( tbkUser , ApiConstants . TBK_USER_LENGTH , "tbkUser" ) ; ValidationUtil . hasTextWithMaxLength ( parentBuyOrder , ApiConstants . BUY_ORDER_LENGTH , "parentBuyOrder" ) ; 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 authorizeRequest = new AuthorizeRequest ( username , tbkUser , parentBuyOrder , details ) ; return RequestService . perform ( authorizeRequest , this . options ) ; } param buyOrder async status ( buyOrder ) { ValidationUtil . hasTextWithMaxLength ( buyOrder , ApiConstants . BUY_ORDER_LENGTH , "buyOrder" ) ; return RequestService . perform ( new StatusRequest ( buyOrder ) , this . options ) ; } param buyOrder param childCommerceCode param childBuyOrder param amount async refund ( buyOrder , childCommerceCode , childBuyOrder , amount ) { ValidationUtil . hasTextWithMaxLength ( childCommerceCode , ApiConstants . COMMERCE_CODE_LENGTH , "childCommerceCode" ) ; ValidationUtil . hasTextWithMaxLength ( buyOrder , ApiConstants . BUY_ORDER_LENGTH , "buyOrder" ) ; ValidationUtil . hasTextWithMaxLength ( childBuyOrder , ApiConstants . BUY_ORDER_LENGTH , "childBuyOrder" ) ; let refundRequest = new RefundRequest ( buyOrder , childCommerceCode , childBuyOrder , amount ) ; return RequestService . perform ( refundRequest , this . options ) ; } param childCommerceCode param childBuyOrder param authorizationCode param captureAmount async capture ( childCommerceCode , childBuyOrder , authorizationCode , captureAmount ) { ValidationUtil . hasTextWithMaxLength ( childCommerceCode , ApiConstants . COMMERCE_CODE_LENGTH , "childCommerceCode" ) ; ValidationUtil . hasTextWithMaxLength ( childBuyOrder , ApiConstants . BUY_ORDER_LENGTH , "childBuyOrder" ) ; ValidationUtil . hasTextWithMaxLength ( authorizationCode , ApiConstants . AUTHORIZATION_CODE_LENGTH , "authorizationCode" ) ; let captureRequest = new CaptureRequest ( childCommerceCode , childBuyOrder , captureAmount , authorizationCode ) ; return RequestService . perform ( captureRequest , this . options ) ; } } ; export default MallTransaction ;