Search in sources :

Example 1 with DoCaptureResponseType

use of urn.ebay.api.PayPalAPI.DoCaptureResponseType in project shopizer by shopizer-ecommerce.

the class PayPalExpressCheckoutPayment method capture.

@Override
public Transaction capture(MerchantStore store, Customer customer, Order order, Transaction capturableTransaction, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    try {
        Validate.notNull(capturableTransaction, "Transaction cannot be null");
        Validate.notNull(capturableTransaction.getTransactionDetails().get("TRANSACTIONID"), "Transaction details must contain a TRANSACTIONID");
        Validate.notNull(order, "Order must not be null");
        Validate.notNull(order.getCurrency(), "Order nust contain Currency object");
        String mode = "sandbox";
        String env = configuration.getEnvironment();
        if (Constants.PRODUCTION_ENVIRONMENT.equals(env)) {
            mode = "production";
        }
        Map<String, String> configurationMap = new HashMap<String, String>();
        configurationMap.put("mode", mode);
        configurationMap.put("acct1.UserName", configuration.getIntegrationKeys().get("username"));
        configurationMap.put("acct1.Password", configuration.getIntegrationKeys().get("api"));
        configurationMap.put("acct1.Signature", configuration.getIntegrationKeys().get("signature"));
        DoCaptureReq doCaptureReq = new DoCaptureReq();
        BasicAmountType amount = new BasicAmountType();
        amount.setValue(pricingService.getStringAmount(order.getTotal(), store));
        amount.setCurrencyID(urn.ebay.apis.eBLBaseComponents.CurrencyCodeType.fromValue(order.getCurrency().getCode()));
        // DoCaptureRequest which takes mandatory params:
        // 
        // Authorization ID - Authorization identification number of the
        // payment you want to capture. This is the transaction ID
        DoCaptureRequestType doCaptureRequest = new DoCaptureRequestType(capturableTransaction.getTransactionDetails().get("TRANSACTIONID"), amount, CompleteCodeType.NOTCOMPLETE);
        doCaptureReq.setDoCaptureRequest(doCaptureRequest);
        // ## Creating service wrapper object
        // Creating service wrapper object to make API call and loading
        // configuration file for your credentials and endpoint
        PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
        DoCaptureResponseType doCaptureResponse = null;
        // ## Making API call
        // Invoke the appropriate method corresponding to API in service
        // wrapper object
        doCaptureResponse = service.doCapture(doCaptureReq);
        // ### Success values
        if (!"Success".equals(doCaptureResponse.getAck().getValue())) {
            LOGGER.error("Wrong value from transaction commit " + doCaptureResponse.getAck().getValue());
            throw new IntegrationException("Wrong paypal ack from refund transaction " + doCaptureResponse.getAck().getValue());
        }
        // if (doCaptureResponse.getAck().getValue()
        // .equalsIgnoreCase("success")) {
        // Authorization identification number
        // logger.info("Authorization ID:"
        // + doCaptureResponse.getDoCaptureResponseDetails()
        // .getAuthorizationID());
        // }
        // ### Error Values
        // Access error values from error list using getter methods
        // else {
        // List<ErrorType> errorList = doCaptureResponse.getErrors();
        // logger.severe("API Error Message : "
        // + errorList.get(0).getLongMessage());
        // }
        // String refundAck = refundTransactionResponse.getAck().getValue();
        Transaction newTransaction = new Transaction();
        newTransaction.setAmount(order.getTotal());
        newTransaction.setTransactionDate(new Date());
        newTransaction.setTransactionType(TransactionType.CAPTURE);
        newTransaction.setPaymentType(PaymentType.PAYPAL);
        newTransaction.getTransactionDetails().put("AUTHORIZATIONID", doCaptureResponse.getDoCaptureResponseDetails().getAuthorizationID());
        newTransaction.getTransactionDetails().put("TRANSACTIONID", capturableTransaction.getTransactionDetails().get("TRANSACTIONID"));
        return newTransaction;
    } catch (Exception e) {
        throw new IntegrationException(e);
    }
}
Also used : DoCaptureReq(urn.ebay.api.PayPalAPI.DoCaptureReq) DoCaptureResponseType(urn.ebay.api.PayPalAPI.DoCaptureResponseType) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) Transaction(com.salesmanager.core.model.payments.Transaction) HashMap(java.util.HashMap) DoCaptureRequestType(urn.ebay.api.PayPalAPI.DoCaptureRequestType) BasicAmountType(urn.ebay.apis.CoreComponentTypes.BasicAmountType) PayPalAPIInterfaceServiceService(urn.ebay.api.PayPalAPI.PayPalAPIInterfaceServiceService) Date(java.util.Date) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Transaction (com.salesmanager.core.model.payments.Transaction)1 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 DoCaptureReq (urn.ebay.api.PayPalAPI.DoCaptureReq)1 DoCaptureRequestType (urn.ebay.api.PayPalAPI.DoCaptureRequestType)1 DoCaptureResponseType (urn.ebay.api.PayPalAPI.DoCaptureResponseType)1 PayPalAPIInterfaceServiceService (urn.ebay.api.PayPalAPI.PayPalAPIInterfaceServiceService)1 BasicAmountType (urn.ebay.apis.CoreComponentTypes.BasicAmountType)1