import Options from '../../common/options' ; import BaseTransaction from '../../common/base_transaction' ; import WebpayPlusModal from './' ; import { ModalCreateRequest } from './requests' ; import RequestService from '../../common/request_service' ; import { CommitRequest , RefundRequest , StatusRequest } from '../webpay_plus/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' ; /**
 * Contains methods to interact with WebpayPlus API
 */ class Transaction extends BaseTransaction { param options constructor ( options ) { options = options || WebpayPlusModal . getDefaultOptions ( ) || new Options ( IntegrationCommerceCodes . WEBPAY_PLUS_MODAL , IntegrationApiKeys . WEBPAY , Environment . Integration ) ; super ( options ) ; } param buyOrder param sessionId param amount async create ( buyOrder , sessionId , amount ) { ValidationUtil . hasTextWithMaxLength ( buyOrder , ApiConstants . BUY_ORDER_LENGTH , "buyOrder" ) ; ValidationUtil . hasTextWithMaxLength ( sessionId , ApiConstants . SESSION_ID_LENGTH , "sessionId" ) ; let createRequest = new ModalCreateRequest ( buyOrder , sessionId , amount ) ; return RequestService . perform ( createRequest , 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 amount async refund ( token , amount ) { ValidationUtil . hasTextWithMaxLength ( token , ApiConstants . TOKEN_LENGTH , "token" ) ; return RequestService . perform ( new RefundRequest ( token , amount ) , this . options ) ; } } export default Transaction ;