Package pl.com.bottega.ecommerce.sales.domain.payment

Source Code of pl.com.bottega.ecommerce.sales.domain.payment.Payment

/*
* Copyright 2011-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pl.com.bottega.ecommerce.sales.domain.payment;

import javax.inject.Inject;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Transient;

import pl.com.bottega.ddd.annotations.domain.AggregateRoot;
import pl.com.bottega.ddd.support.domain.BaseAggregateRoot;
import pl.com.bottega.ecommerce.canonicalmodel.events.PaymentRolledBackEvent;
import pl.com.bottega.ecommerce.canonicalmodel.publishedlanguage.AggregateId;
import pl.com.bottega.ecommerce.canonicalmodel.publishedlanguage.ClientData;
import pl.com.bottega.ecommerce.sharedkernel.Money;

/**
*
* @author Slawek
*
*/
@AggregateRoot
@Entity
public class Payment extends BaseAggregateRoot{

  @Embedded
  private ClientData clientData;
 
  @Embedded
  private Money amount;
 
  @Transient
  @Inject
  private PaymentFactory paymentFactory;
 
  @SuppressWarnings("unused")
  private Payment(){}
 
  Payment(AggregateId aggregateId, ClientData clientData, Money amount) {
    this.aggregateId = aggregateId;
    this.clientData = clientData;
    this.amount = amount;
  }

  public Payment rollBack(){
    //TODO explore domain rules
    eventPublisher.publish(new PaymentRolledBackEvent(getAggregateId()));
    return paymentFactory.createPayment(clientData, amount.multiplyBy(-1));
  }
}
TOP

Related Classes of pl.com.bottega.ecommerce.sales.domain.payment.Payment

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.