Search in sources :

Example 1 with PaymentType

use of org.broadleafcommerce.common.payment.PaymentType in project BroadleafCommerce by BroadleafCommerce.

the class OrderPaymentServiceImpl method createOrderPaymentFromCustomerPayment.

@Override
@Transactional(value = TransactionUtils.DEFAULT_TRANSACTION_MANAGER)
public OrderPayment createOrderPaymentFromCustomerPayment(Order order, CustomerPayment customerPayment, Money amount) {
    OrderPayment orderPayment = create();
    orderPayment.setOrder(order);
    orderPayment.setBillingAddress(addressService.copyAddress(customerPayment.getBillingAddress()));
    PaymentGatewayType gatewayType = customerPayment.getPaymentGatewayType();
    PaymentType paymentType = customerPayment.getPaymentType();
    Map<String, String> additionalFields = customerPayment.getAdditionalFields();
    if (gatewayType == null || paymentType == null) {
        if (MapUtils.isEmpty(additionalFields)) {
            additionalFields = new HashMap<>();
        }
        String paymentTypeKey = PaymentAdditionalFieldType.PAYMENT_TYPE.getType();
        if (additionalFields.containsKey(paymentTypeKey)) {
            paymentType = PaymentType.getInstance(additionalFields.get(paymentTypeKey));
        }
        String gatewayTypeKey = PaymentAdditionalFieldType.GATEWAY_TYPE.getType();
        if (additionalFields.containsKey(gatewayTypeKey)) {
            gatewayType = PaymentGatewayType.getInstance(additionalFields.get(gatewayTypeKey));
        }
    }
    orderPayment.setPaymentGatewayType(gatewayType);
    orderPayment.setType(paymentType);
    orderPayment.setAmount(amount);
    PaymentTransaction unconfirmedTransaction = createTransaction();
    unconfirmedTransaction.setAmount(amount);
    unconfirmedTransaction.setType(PaymentTransactionType.UNCONFIRMED);
    unconfirmedTransaction.setOrderPayment(orderPayment);
    unconfirmedTransaction.getAdditionalFields().put(PaymentAdditionalFieldType.TOKEN.getType(), customerPayment.getPaymentToken());
    unconfirmedTransaction.getAdditionalFields().putAll(customerPayment.getAdditionalFields());
    orderPayment.getTransactions().add(unconfirmedTransaction);
    return save(orderPayment);
}
Also used : PaymentTransaction(org.broadleafcommerce.core.payment.domain.PaymentTransaction) PaymentType(org.broadleafcommerce.common.payment.PaymentType) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) PaymentGatewayType(org.broadleafcommerce.common.payment.PaymentGatewayType) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PaymentGatewayType (org.broadleafcommerce.common.payment.PaymentGatewayType)1 PaymentType (org.broadleafcommerce.common.payment.PaymentType)1 OrderPayment (org.broadleafcommerce.core.payment.domain.OrderPayment)1 PaymentTransaction (org.broadleafcommerce.core.payment.domain.PaymentTransaction)1 Transactional (org.springframework.transaction.annotation.Transactional)1