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);
}
Aggregations