Search in sources :

Example 1 with DoExpressCheckoutPaymentResponseType

use of urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentResponseType in project structr by structr.

the class PayPalPaymentProvider method confirmCheckout.

@Override
public ConfirmCheckoutResponse confirmCheckout(final Payment payment, final String notifyUrl, final String token, final String payerId) throws FrameworkException {
    try {
        final GetExpressCheckoutDetailsResponseType response = PayPalHelper.getExpressCheckoutResponse(token);
        if (AckCodeType.SUCCESS.equals(response.getAck())) {
            // TODO: change currency code
            final GetExpressCheckoutDetailsResponseDetailsType details = response.getGetExpressCheckoutDetailsResponseDetails();
            final CurrencyCodeType currencyCode = CurrencyCodeType.fromValue(payment.getCurrencyCode());
            final DoExpressCheckoutPaymentResponseType confirmationResponse = PayPalHelper.commitExpressCheckout(notifyUrl, currencyCode, payment.getTotal(), token, payerId);
            if (AckCodeType.SUCCESS.equals(confirmationResponse.getAck())) {
                final PayPalConfirmCheckoutResponse checkoutResponse = new PayPalConfirmCheckoutResponse(confirmationResponse);
                final DoExpressCheckoutPaymentResponseDetailsType confirmation = confirmationResponse.getDoExpressCheckoutPaymentResponseDetails();
                final String billingAgreementId = confirmation.getBillingAgreementID();
                final String note = confirmation.getNote();
                // billing address
                final AddressType billingAddress = details.getBillingAddress();
                if (billingAddress != null) {
                    final String billingAddressName = billingAddress.getName();
                    final String billingAddressStreet1 = billingAddress.getStreet1();
                    final String billingAddressStreet2 = billingAddress.getStreet2();
                    final String billingAddressZip = billingAddress.getPostalCode();
                    final String billingAddressCity = billingAddress.getCityName();
                    final String billingAddressCountry = billingAddress.getCountryName();
                    payment.setBillingAddressName(billingAddressName);
                    payment.setBillingAddressStreet1(billingAddressStreet1);
                    payment.setBillingAddressStreet2(billingAddressStreet2);
                    payment.setBillingAddressZip(billingAddressZip);
                    payment.setBillingAddressCity(billingAddressCity);
                    payment.setBillingAddressCountry(billingAddressCountry);
                }
                // payer info
                final PayerInfoType payerInfo = details.getPayerInfo();
                if (payerInfo != null) {
                    payment.setPayer(payerInfo.getPayer());
                    payment.setPayerBusiness(payerInfo.getPayerBusiness());
                    final AddressType payerAddress = payerInfo.getAddress();
                    if (payerAddress != null) {
                        payment.setPayerAddressName(payerAddress.getName());
                        payment.setPayerAddressStreet1(payerAddress.getStreet1());
                        payment.setPayerAddressStreet2(payerAddress.getStreet1());
                        payment.setPayerAddressZip(payerAddress.getPostalCode());
                        payment.setPayerAddressCity(payerAddress.getCityName());
                        payment.setPayerAddressCountry(payerAddress.getCountryName());
                    }
                }
                payment.setBillingAgreementId(billingAgreementId);
                payment.setNote(note);
                payment.setInvoiceId(details.getInvoiceID());
                payment.setPaymentState(PaymentState.completed);
                payment.setToken(null);
                // success
                return checkoutResponse;
            }
        }
    } catch (Throwable t) {
        throw new FrameworkException(422, t.getMessage());
    }
    throw new FrameworkException(422, "Unknown error.");
}
Also used : CurrencyCodeType(urn.ebay.apis.eBLBaseComponents.CurrencyCodeType) GetExpressCheckoutDetailsResponseType(urn.ebay.api.PayPalAPI.GetExpressCheckoutDetailsResponseType) GetExpressCheckoutDetailsResponseDetailsType(urn.ebay.apis.eBLBaseComponents.GetExpressCheckoutDetailsResponseDetailsType) FrameworkException(org.structr.common.error.FrameworkException) DoExpressCheckoutPaymentResponseType(urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentResponseType) DoExpressCheckoutPaymentResponseDetailsType(urn.ebay.apis.eBLBaseComponents.DoExpressCheckoutPaymentResponseDetailsType) AddressType(urn.ebay.apis.eBLBaseComponents.AddressType) PayerInfoType(urn.ebay.apis.eBLBaseComponents.PayerInfoType)

Example 2 with DoExpressCheckoutPaymentResponseType

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

the class PayPalExpressCheckoutPayment method processTransaction.

private Transaction processTransaction(MerchantStore store, Customer customer, List<ShoppingCartItem> items, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    com.salesmanager.core.model.payments.PaypalPayment paypalPayment = (com.salesmanager.core.model.payments.PaypalPayment) payment;
    try {
        String mode = "sandbox";
        String env = configuration.getEnvironment();
        if (Constants.PRODUCTION_ENVIRONMENT.equals(env)) {
            mode = "production";
        }
        // get token from url and return the user to generate a payerid
        GetExpressCheckoutDetailsRequestType getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(paypalPayment.getPaymentToken());
        getExpressCheckoutDetailsRequest.setVersion("104.0");
        GetExpressCheckoutDetailsReq getExpressCheckoutDetailsReq = new GetExpressCheckoutDetailsReq();
        getExpressCheckoutDetailsReq.setGetExpressCheckoutDetailsRequest(getExpressCheckoutDetailsRequest);
        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"));
        PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
        GetExpressCheckoutDetailsResponseType getExpressCheckoutDetailsResponse = service.getExpressCheckoutDetails(getExpressCheckoutDetailsReq);
        String token = getExpressCheckoutDetailsResponse.getGetExpressCheckoutDetailsResponseDetails().getToken();
        String correlationID = getExpressCheckoutDetailsResponse.getCorrelationID();
        String ack = getExpressCheckoutDetailsResponse.getAck().getValue();
        String payerId = getExpressCheckoutDetailsResponse.getGetExpressCheckoutDetailsResponseDetails().getPayerInfo().getPayerID();
        if (!"Success".equals(ack)) {
            LOGGER.error("Wrong value from anthorize and capture transaction " + ack);
            throw new IntegrationException("Wrong paypal ack from init transaction " + ack);
        }
        PaymentDetailsType paymentDetail = new PaymentDetailsType();
        /**
         * IPN *
         */
        // paymentDetail.setNotifyURL("http://replaceIpnUrl.com");
        BasicAmountType orderTotal = new BasicAmountType();
        orderTotal.setValue(pricingService.getStringAmount(amount, store));
        orderTotal.setCurrencyID(urn.ebay.apis.eBLBaseComponents.CurrencyCodeType.fromValue(payment.getCurrency().getCode()));
        paymentDetail.setOrderTotal(orderTotal);
        paymentDetail.setButtonSource("Shopizer_Cart_AP");
        /**
         * sale or pre-auth *
         */
        if (payment.getTransactionType().name().equals(TransactionType.AUTHORIZE.name())) {
            paymentDetail.setPaymentAction(urn.ebay.apis.eBLBaseComponents.PaymentActionCodeType.AUTHORIZATION);
        } else {
            paymentDetail.setPaymentAction(urn.ebay.apis.eBLBaseComponents.PaymentActionCodeType.SALE);
        }
        List<PaymentDetailsType> paymentDetails = new ArrayList<PaymentDetailsType>();
        paymentDetails.add(paymentDetail);
        DoExpressCheckoutPaymentRequestDetailsType doExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
        doExpressCheckoutPaymentRequestDetails.setToken(token);
        doExpressCheckoutPaymentRequestDetails.setPayerID(payerId);
        doExpressCheckoutPaymentRequestDetails.setPaymentDetails(paymentDetails);
        DoExpressCheckoutPaymentRequestType doExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType(doExpressCheckoutPaymentRequestDetails);
        doExpressCheckoutPaymentRequest.setVersion("104.0");
        DoExpressCheckoutPaymentReq doExpressCheckoutPaymentReq = new DoExpressCheckoutPaymentReq();
        doExpressCheckoutPaymentReq.setDoExpressCheckoutPaymentRequest(doExpressCheckoutPaymentRequest);
        DoExpressCheckoutPaymentResponseType doExpressCheckoutPaymentResponse = service.doExpressCheckoutPayment(doExpressCheckoutPaymentReq);
        String commitAck = doExpressCheckoutPaymentResponse.getAck().getValue();
        if (!"Success".equals(commitAck)) {
            LOGGER.error("Wrong value from transaction commit " + ack);
            throw new IntegrationException("Wrong paypal ack from init transaction " + ack);
        }
        List<PaymentInfoType> paymentInfoList = doExpressCheckoutPaymentResponse.getDoExpressCheckoutPaymentResponseDetails().getPaymentInfo();
        String transactionId = null;
        for (PaymentInfoType paymentInfo : paymentInfoList) {
            transactionId = paymentInfo.getTransactionID();
        }
        // TOKEN=EC-90U93956LU4997256&SUCCESSPAGEREDIRECTREQUESTED=false&TIMESTAMP=2014-02-16T15:41:03Z&CORRELATIONID=39d4ab666c1d7&ACK=Success&VERSION=104.0&BUILD=9720069&INSURANCEOPTIONSELECTED=false&SHIPPINGOPTIONISDEFAULT=false&PAYMENTINFO_0_TRANSACTIONID=4YA742984J1256935&PAYMENTINFO_0_TRANSACTIONTYPE=expresscheckout&PAYMENTINFO_0_PAYMENTTYPE=instant&PAYMENTINFO_0_ORDERTIME=2014-02-16T15:41:03Z&PAYMENTINFO_0_AMT=1.00&PAYMENTINFO_0_FEEAMT=0.33&PAYMENTINFO_0_TAXAMT=0.00&PAYMENTINFO_0_CURRENCYCODE=USD&PAYMENTINFO_0_PAYMENTSTATUS=Completed&PAYMENTINFO_0_PENDINGREASON=None&PAYMENTINFO_0_REASONCODE=None&PAYMENTINFO_0_PROTECTIONELIGIBILITY=Eligible&PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE=ItemNotReceivedEligible,UnauthorizedPaymentEligible&PAYMENTINFO_0_SECUREMERCHANTACCOUNTID=TWLK53YN7GDM6&PAYMENTINFO_0_ERRORCODE=0&PAYMENTINFO_0_ACK=Success
        Transaction transaction = new Transaction();
        transaction.setAmount(amount);
        transaction.setTransactionDate(new Date());
        transaction.setTransactionType(payment.getTransactionType());
        transaction.setPaymentType(PaymentType.PAYPAL);
        transaction.getTransactionDetails().put("TOKEN", token);
        transaction.getTransactionDetails().put("PAYERID", payerId);
        transaction.getTransactionDetails().put("TRANSACTIONID", transactionId);
        transaction.getTransactionDetails().put("CORRELATION", correlationID);
        return transaction;
    } catch (Exception e) {
        throw new IntegrationException(e);
    }
}
Also used : HashMap(java.util.HashMap) BasicAmountType(urn.ebay.apis.CoreComponentTypes.BasicAmountType) ArrayList(java.util.ArrayList) GetExpressCheckoutDetailsReq(urn.ebay.api.PayPalAPI.GetExpressCheckoutDetailsReq) GetExpressCheckoutDetailsRequestType(urn.ebay.api.PayPalAPI.GetExpressCheckoutDetailsRequestType) GetExpressCheckoutDetailsResponseType(urn.ebay.api.PayPalAPI.GetExpressCheckoutDetailsResponseType) PaymentInfoType(urn.ebay.apis.eBLBaseComponents.PaymentInfoType) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) DoExpressCheckoutPaymentResponseType(urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentResponseType) PayPalAPIInterfaceServiceService(urn.ebay.api.PayPalAPI.PayPalAPIInterfaceServiceService) Date(java.util.Date) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) DoExpressCheckoutPaymentRequestDetailsType(urn.ebay.apis.eBLBaseComponents.DoExpressCheckoutPaymentRequestDetailsType) Transaction(com.salesmanager.core.model.payments.Transaction) PaymentDetailsType(urn.ebay.apis.eBLBaseComponents.PaymentDetailsType) DoExpressCheckoutPaymentReq(urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentReq) DoExpressCheckoutPaymentRequestType(urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentRequestType)

Aggregations

DoExpressCheckoutPaymentResponseType (urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentResponseType)2 GetExpressCheckoutDetailsResponseType (urn.ebay.api.PayPalAPI.GetExpressCheckoutDetailsResponseType)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Transaction (com.salesmanager.core.model.payments.Transaction)1 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 FrameworkException (org.structr.common.error.FrameworkException)1 DoExpressCheckoutPaymentReq (urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentReq)1 DoExpressCheckoutPaymentRequestType (urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentRequestType)1 GetExpressCheckoutDetailsReq (urn.ebay.api.PayPalAPI.GetExpressCheckoutDetailsReq)1 GetExpressCheckoutDetailsRequestType (urn.ebay.api.PayPalAPI.GetExpressCheckoutDetailsRequestType)1 PayPalAPIInterfaceServiceService (urn.ebay.api.PayPalAPI.PayPalAPIInterfaceServiceService)1 BasicAmountType (urn.ebay.apis.CoreComponentTypes.BasicAmountType)1 AddressType (urn.ebay.apis.eBLBaseComponents.AddressType)1 CurrencyCodeType (urn.ebay.apis.eBLBaseComponents.CurrencyCodeType)1 DoExpressCheckoutPaymentRequestDetailsType (urn.ebay.apis.eBLBaseComponents.DoExpressCheckoutPaymentRequestDetailsType)1 DoExpressCheckoutPaymentResponseDetailsType (urn.ebay.apis.eBLBaseComponents.DoExpressCheckoutPaymentResponseDetailsType)1 GetExpressCheckoutDetailsResponseDetailsType (urn.ebay.apis.eBLBaseComponents.GetExpressCheckoutDetailsResponseDetailsType)1