001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016
017package com.echothree.model.control.payment.server.transfer;
018
019import javax.inject.Inject;
020import com.echothree.model.control.contact.server.control.ContactControl;
021import static com.echothree.model.control.customer.common.workflow.CustomerCreditCardContactMechanismConstants.Workflow_CUSTOMER_CREDIT_CARD_CONTACT_MECHANISM;
022import com.echothree.model.control.payment.common.PaymentMethodTypes;
023import com.echothree.model.control.payment.common.transfer.PartyPaymentMethodContactMechanismTransfer;
024import com.echothree.model.control.payment.server.control.PartyPaymentMethodControl;
025import com.echothree.model.control.workflow.common.transfer.WorkflowEntityStatusTransfer;
026import com.echothree.model.control.workflow.server.control.WorkflowControl;
027import com.echothree.model.data.payment.server.entity.PartyPaymentMethodContactMechanism;
028import com.echothree.model.data.user.server.entity.UserVisit;
029import javax.enterprise.context.RequestScoped;
030
031@RequestScoped
032public class PartyPaymentMethodContactMechanismTransferCache
033        extends BasePaymentTransferCache<PartyPaymentMethodContactMechanism, PartyPaymentMethodContactMechanismTransfer> {
034
035    @Inject
036    ContactControl contactControl;
037
038    @Inject
039    PartyPaymentMethodControl partyPaymentMethodControl;
040
041    @Inject
042    WorkflowControl workflowControl;
043    
044    /** Creates a new instance of PartyPaymentMethodContactMechanismTransferCache */
045    protected PartyPaymentMethodContactMechanismTransferCache() {
046        super();
047    }
048
049    @Override
050    public PartyPaymentMethodContactMechanismTransfer getTransfer(UserVisit userVisit, PartyPaymentMethodContactMechanism partyPaymentMethodContactMechanism) {
051        var partyPaymentMethodContactMechanismTransfer = get(partyPaymentMethodContactMechanism);
052        
053        if(partyPaymentMethodContactMechanismTransfer == null) {
054            var partyPaymentMethod = partyPaymentMethodContactMechanism.getPartyPaymentMethod();
055            var partyPaymentMethodTransfer = partyPaymentMethodControl.getPartyPaymentMethodTransfer(userVisit, partyPaymentMethod);
056            var partyContactMechanismPurposeTransfer = contactControl.getPartyContactMechanismPurposeTransfer(userVisit, partyPaymentMethodContactMechanism.getPartyContactMechanismPurpose());
057            WorkflowEntityStatusTransfer partyPaymentMethodContactMechanismStatusTransfer = null;
058
059            var paymentMethodTypeName = partyPaymentMethod.getLastDetail().getPaymentMethod().getLastDetail().getPaymentMethodType().getLastDetail().getPaymentMethodTypeName();
060            var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(partyPaymentMethodContactMechanism.getPrimaryKey());
061            if(paymentMethodTypeName.equals(PaymentMethodTypes.CREDIT_CARD.name())) {
062                    partyPaymentMethodContactMechanismStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit,
063                            Workflow_CUSTOMER_CREDIT_CARD_CONTACT_MECHANISM, entityInstance);
064            }
065            
066            partyPaymentMethodContactMechanismTransfer = new PartyPaymentMethodContactMechanismTransfer(partyPaymentMethodTransfer,
067                    partyContactMechanismPurposeTransfer, partyPaymentMethodContactMechanismStatusTransfer);
068            put(userVisit, partyPaymentMethodContactMechanism, partyPaymentMethodContactMechanismTransfer);
069        }
070        return partyPaymentMethodContactMechanismTransfer;
071    }
072    
073}