Example usage for org.apache.commons.lang SerializationUtils clone

List of usage examples for org.apache.commons.lang SerializationUtils clone

Introduction

In this page you can find the example usage for org.apache.commons.lang SerializationUtils clone.

Prototype

public static Object clone(Serializable object) 

Source Link

Document

Deep clone an Object using serialization.

This is many times slower than writing clone methods by hand on all objects in your object graph.

Usage

From source file:org.yes.cart.payment.impl.LiqPayNoRefundPaymentGatewayImpl.java

/** {@inheritDoc} */
@Override// ww  w  . ja  v a  2 s .com
public Payment refund(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(REFUND);
    payment.setTransactionReferenceId(UUID.randomUUID().toString());
    payment.setTransactionAuthorizationCode(UUID.randomUUID().toString());
    payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_MANUAL_PROCESSING_REQUIRED);
    payment.setPaymentProcessorBatchSettlement(false);
    return payment;
}

From source file:org.yes.cart.payment.impl.PayflowPaymentGatewayImpl.java

/**
 * {@inheritDoc}/*from   w ww. j av a 2  s  .  c o  m*/
 */
public Payment authorize(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(AUTH);
    configurePayFlowSystem();

    final String transRequestId = paypal.payflow.PayflowUtility.getRequestId();
    payment.setTransactionReferenceId(transRequestId);

    paypal.payflow.Invoice inv = createInvoice(paymentIn);
    paypal.payflow.PayflowConnectionData connection = new paypal.payflow.PayflowConnectionData();
    paypal.payflow.AuthorizationTransaction trans = new paypal.payflow.AuthorizationTransaction(
            createUserInfo(), connection, inv, new paypal.payflow.CardTender(createCreditCard(paymentIn)),
            transRequestId

    );

    runTransaction(payment, trans, false);

    return payment;
}

From source file:org.yes.cart.payment.impl.PayflowPaymentGatewayImpl.java

/**
 * {@inheritDoc}//from  www.j  av a  2s. c o m
 */
public Payment authorizeCapture(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(AUTH_CAPTURE);
    configurePayFlowSystem();

    final String transRequestId = paypal.payflow.PayflowUtility.getRequestId();
    payment.setTransactionReferenceId(transRequestId);

    paypal.payflow.Invoice inv = createInvoice(paymentIn);
    paypal.payflow.PayflowConnectionData connection = new paypal.payflow.PayflowConnectionData();
    paypal.payflow.SaleTransaction trans = new paypal.payflow.SaleTransaction(createUserInfo(), connection, inv,
            new paypal.payflow.CardTender(createCreditCard(paymentIn)), transRequestId

    );

    runTransaction(payment, trans, true);

    return payment;

}

From source file:org.yes.cart.payment.impl.PayflowPaymentGatewayImpl.java

/**
 * {@inheritDoc}//from   w  w w . jav  a  2 s .  co  m
 */
public Payment reverseAuthorization(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(REVERSE_AUTH);
    configurePayFlowSystem();

    final String transRequestId = paypal.payflow.PayflowUtility.getRequestId();
    payment.setTransactionReferenceId(transRequestId);

    paypal.payflow.PayflowConnectionData connection = new paypal.payflow.PayflowConnectionData();
    paypal.payflow.VoidTransaction trans = new paypal.payflow.VoidTransaction(
            payment.getTransactionAuthorizationCode(), createUserInfo(), connection, transRequestId);

    runTransaction(payment, trans, true);

    return payment;
}

From source file:org.yes.cart.payment.impl.PayflowPaymentGatewayImpl.java

/**
 * {@inheritDoc}//from  ww w .  j  a  v a 2  s  . c  om
 */
public Payment capture(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(CAPTURE);
    configurePayFlowSystem();

    final String transRequestId = paypal.payflow.PayflowUtility.getRequestId();
    payment.setTransactionReferenceId(transRequestId);

    paypal.payflow.PayflowConnectionData connection = new paypal.payflow.PayflowConnectionData();
    paypal.payflow.CaptureTransaction trans = new paypal.payflow.CaptureTransaction(
            payment.getTransactionAuthorizationCode(), createUserInfo(), connection, transRequestId);

    runTransaction(payment, trans, false);

    return payment;

}

From source file:org.yes.cart.payment.impl.PayflowPaymentGatewayImpl.java

/**
 * {@inheritDoc}/*from  www  . j a v  a 2  s . co m*/
 */
public Payment voidCapture(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(VOID_CAPTURE);
    configurePayFlowSystem();

    final String transRequestId = paypal.payflow.PayflowUtility.getRequestId();
    payment.setTransactionReferenceId(transRequestId);

    paypal.payflow.PayflowConnectionData connection = new paypal.payflow.PayflowConnectionData();
    paypal.payflow.VoidTransaction trans = new paypal.payflow.VoidTransaction(
            payment.getTransactionAuthorizationCode(), createUserInfo(), connection, transRequestId);

    runTransaction(payment, trans, true);

    return payment;

}

From source file:org.yes.cart.payment.impl.PayflowPaymentGatewayImpl.java

/**
 * {@inheritDoc}/*from   www.jav  a  2 s .  c om*/
 */
public Payment refund(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(REFUND);
    configurePayFlowSystem();

    final String transRequestId = paypal.payflow.PayflowUtility.getRequestId();
    payment.setTransactionReferenceId(transRequestId);

    paypal.payflow.PayflowConnectionData connection = new paypal.payflow.PayflowConnectionData();
    paypal.payflow.CreditTransaction trans = new paypal.payflow.CreditTransaction(
            payment.getTransactionAuthorizationCode(), createUserInfo(),
            connection, /*here can be invoice to change amount from original transaction */
            transRequestId);

    runTransaction(payment, trans, true);

    return payment;

}

From source file:org.yes.cart.payment.impl.PaymentProcessorSurrogate.java

/**
 * Create list of payment to authorize.//w ww .j av a2 s  .c  o m
 *
 * @param order                order
 * @param params
 * @param transactionOperation operation in term of payment processor
 * @param forceSinglePaymentIn flag is true for authCapture operation, when payment gateway not supports several payments per
 *                             order
 * @return list of  payments with details
 */
public List<Payment> createPaymentsToAuthorize(final CustomerOrder order, final boolean forceSinglePaymentIn,
        final Map params, final String transactionOperation) {

    Assert.notNull(order, "Customer order expected");

    final boolean forceSinglePayment = forceSinglePaymentIn || params.containsKey("forceSinglePayment");

    final Payment templatePayment = fillPaymentPrototype(order,
            getPaymentGateway().createPaymentPrototype(params), transactionOperation,
            getPaymentGateway().getLabel());

    final List<Payment> rez = new ArrayList<Payment>();
    if (forceSinglePayment
            || !getPaymentGateway().getPaymentGatewayFeatures().isSupportAuthorizePerShipment()) {
        Payment payment = (Payment) SerializationUtils.clone(templatePayment);
        for (CustomerOrderDelivery delivery : order.getDelivery()) {
            fillPayment(order, delivery, payment, true);
        }
        rez.add(payment);

    } else {
        for (CustomerOrderDelivery delivery : order.getDelivery()) {
            Payment payment = (Payment) SerializationUtils.clone(templatePayment);
            fillPayment(order, delivery, payment, false);
            rez.add(payment);
        }
    }
    return rez;
}

From source file:org.yes.cart.payment.impl.PayPalExpressCheckoutPaymentGatewayImpl.java

/**
 * {@inheritDoc}//from  ww  w.ja  v a  2 s .  c  o m
 */
public Payment authorizeCapture(final Payment paymentIn) {

    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);

    payment.setTransactionOperation(AUTH_CAPTURE);

    try {
        final Map<String, String> paymentResult = doDoExpressCheckoutPayment(
                payment.getTransactionRequestToken(), payment.getTransactionReferenceId(),
                payment.getPaymentAmount(), payment.getOrderCurrency());
        final CallbackResult res = getExternalCallbackResult(paymentResult);
        payment.setPaymentProcessorResult(res.getStatus());
        payment.setPaymentProcessorBatchSettlement(res.isSettled());

    } catch (IOException e) {
        payment.setPaymentProcessorResult(Payment.PAYMENT_STATUS_FAILED);
        payment.setPaymentProcessorBatchSettlement(false);
        ShopCodeContext.getLog(this).error(e.getMessage(), e);
    }
    return payment;
}

From source file:org.yes.cart.payment.impl.PayPalNvpPaymentGatewayImpl.java

/**
 * {@inheritDoc}//from w w w .  j a  v a2  s  .c o m
 */
public Payment authorize(final Payment paymentIn) {
    final Payment payment = (Payment) SerializationUtils.clone(paymentIn);
    payment.setTransactionOperation(AUTH);
    final NVPEncoder encoder = createAuthRequest(payment, "Authorization");
    return runTransaction(encoder, payment, AUTH);
}