Search in sources :

Example 6 with PaypalTransaction

use of org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction in project openolat by klemens.

the class PaypalManagerImpl method updateTransactionByNotification.

@Override
public void updateTransactionByNotification(Map<String, String> values, boolean verified) {
    if (verified) {
        // CREATED - The payment request was received; funds will be transferred
        // COMPLETED - The payment was successful
        // INCOMPLETE - Some transfers succeeded and some failed for a parallel payment or, for a delayed chained payment, secondary receivers have not been paid
        // ERROR - The payment failed and all attempted transfers failed or all
        // REVERSALERROR - One or more transfers failed when attempting to
        // PROCESSING - The payment is in progress
        // PENDING - The payment is awaiting processing
        // String status = values.get("status");
        // if("COMPLETED".equals(status))
        String invoiceId = values.get("transaction[0].invoiceId");
        PaypalTransaction trx = loadTransactionByInvoiceId(invoiceId);
        if (trx != null) {
            completeTransaction(trx, values);
        } else {
            log.error("Paypal IPN Transaction not found: " + values, null);
        }
    } else {
        String invoiceId = values.get("transaction[0].invoiceId");
        log.error("Paypal IPN Transaction not verified: " + invoiceId + " raw values: " + values, null);
    }
}
Also used : PaypalTransaction(org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction)

Example 7 with PaypalTransaction

use of org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction in project openolat by klemens.

the class PaypalManagerImpl method request.

public PayResponse request(Identity delivery, OfferAccess offerAccess, String mapperUri, String sessionId) {
    StringBuilder url = new StringBuilder();
    url.append(Settings.createServerURI()).append(mapperUri);
    Offer offer = offerAccess.getOffer();
    Price amount = offer.getPrice();
    Order order = orderManager.saveOneClick(delivery, offerAccess, OrderStatus.PREPAYMENT);
    PaypalTransaction trx = createAndPersistTransaction(amount, order, order.getParts().get(0), offerAccess.getMethod());
    // !!!! make a trace of the process
    dbInstance.commit();
    ReceiverList list = new ReceiverList();
    Receiver rec1 = new Receiver();
    rec1.setAmount(amount.getAmount().doubleValue());
    rec1.setEmail(paypalModule.getPaypalFirstReceiverEmailAddress());
    rec1.setInvoiceId(order.getOrderNr());
    list.getReceiver().add(rec1);
    String returnURL = url.toString() + "/" + trx.getSecureSuccessUUID() + ".html;jsessionid=" + sessionId + "?status=success";
    String cancelURL = url.toString() + "/" + trx.getSecureCancelUUID() + ".html;jsessionid=" + sessionId + "?status=cancel";
    PayRequest payRequest = new PayRequest();
    payRequest.setCancelUrl(cancelURL);
    payRequest.setReturnUrl(returnURL);
    payRequest.setTrackingId(order.getOrderNr());
    payRequest.setCurrencyCode(amount.getCurrencyCode());
    payRequest.setClientDetails(getAppDetails());
    payRequest.setReceiverList(list);
    payRequest.setRequestEnvelope(getAppRequestEnvelope());
    payRequest.setActionType("PAY");
    payRequest.setIpnNotificationUrl(Settings.getServerContextPathURI() + "/paypal/ipn");
    PayResponse payResp = null;
    try {
        AdaptivePaymentsService ap = new AdaptivePaymentsService(getAccountProperties());
        payResp = ap.pay(payRequest);
        log.audit("Paypal send PayRequest: " + (payResp == null ? "no response" : payResp.getPayKey() + "/" + payResp.getPaymentExecStatus()));
        return payResp;
    } catch (SSLConfigurationException e) {
        log.error("Paypal error", e);
    } catch (InvalidCredentialException e) {
        log.error("Paypal error", e);
    } catch (UnsupportedEncodingException e) {
        log.error("Paypal error", e);
    } catch (HttpErrorException e) {
        log.error("Paypal error", e);
    } catch (InvalidResponseDataException e) {
        log.error("Paypal error", e);
    } catch (ClientActionRequiredException e) {
        log.error("Paypal error", e);
    } catch (MissingCredentialException e) {
        log.error("Paypal error", e);
    } catch (OAuthException e) {
        log.error("Paypal error", e);
    } catch (IOException | InterruptedException e) {
        log.error("Paypal error", e);
    } catch (Exception e) {
        log.error("Paypal error", e);
    } finally {
        if (payResp == null) {
            updateTransaction(trx, PaypalTransactionStatus.ERROR);
        } else {
            updateTransaction(payResp, trx);
        }
    }
    return null;
}
Also used : Order(org.olat.resource.accesscontrol.Order) ClientActionRequiredException(com.paypal.exception.ClientActionRequiredException) AdaptivePaymentsService(com.paypal.svcs.services.AdaptivePaymentsService) OAuthException(com.paypal.sdk.exceptions.OAuthException) Receiver(com.paypal.svcs.types.ap.Receiver) InvalidCredentialException(com.paypal.exception.InvalidCredentialException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ReceiverList(com.paypal.svcs.types.ap.ReceiverList) IOException(java.io.IOException) OAuthException(com.paypal.sdk.exceptions.OAuthException) SSLConfigurationException(com.paypal.exception.SSLConfigurationException) InvalidResponseDataException(com.paypal.exception.InvalidResponseDataException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidCredentialException(com.paypal.exception.InvalidCredentialException) HttpErrorException(com.paypal.exception.HttpErrorException) MissingCredentialException(com.paypal.exception.MissingCredentialException) IOException(java.io.IOException) ClientActionRequiredException(com.paypal.exception.ClientActionRequiredException) PayRequest(com.paypal.svcs.types.ap.PayRequest) PaypalTransaction(org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction) Offer(org.olat.resource.accesscontrol.Offer) Price(org.olat.resource.accesscontrol.Price) SSLConfigurationException(com.paypal.exception.SSLConfigurationException) MissingCredentialException(com.paypal.exception.MissingCredentialException) InvalidResponseDataException(com.paypal.exception.InvalidResponseDataException) PayResponse(com.paypal.svcs.types.ap.PayResponse) HttpErrorException(com.paypal.exception.HttpErrorException)

Example 8 with PaypalTransaction

use of org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction in project openolat by klemens.

the class PaypalTransactionStatusRenderer method render.

@Override
public void render(Renderer renderer, StringOutput sb, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
    if (cellValue instanceof PaypalTransaction) {
        PaypalTransaction trx = (PaypalTransaction) cellValue;
        PaypalMergedState mState = PaypalMergedState.value(trx);
        sb.append("<i class='o_icon o_icon-fw ").append(mState.cssClass()).append("'> </i>");
    }
}
Also used : PaypalTransaction(org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction)

Example 9 with PaypalTransaction

use of org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction in project openolat by klemens.

the class PaypalTransactionsController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == backLink) {
        if (detailsController != null) {
            flc.remove(detailsController.getInitialComponent());
            removeAsListenerAndDispose(detailsController);
        }
        addSearchToHistory(ureq);
    } else if (source == tableEl) {
        if (event instanceof SelectionEvent) {
            SelectionEvent se = (SelectionEvent) event;
            PaypalTransaction row = dataModel.getObject(se.getIndex());
            if (CMD_SELECT.equals(se.getCommand())) {
                doSelectTransaction(ureq, row);
            }
        } else if (event instanceof FlexiTableSearchEvent) {
            FlexiTableSearchEvent se = (FlexiTableSearchEvent) event;
            doSearch(ureq, se.getSearch());
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : PaypalTransaction(org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction) SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) FlexiTableSearchEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent)

Example 10 with PaypalTransaction

use of org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction in project openolat by klemens.

the class PaypalTransactionsController method activate.

@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (state instanceof StateMapped) {
        StateMapped map = (StateMapped) state;
        String transactionId = map.getDelegate().get("transactionId");
        if (StringHelper.containsNonWhitespace(transactionId)) {
            tableEl.quickSearch(ureq, transactionId);
        }
    }
    if (entries == null || entries.isEmpty())
        return;
    Long trxId = entries.get(0).getOLATResourceable().getResourceableId();
    PaypalTransaction trx = dataModel.getTransaction(trxId);
    if (trx != null) {
        doSelectTransaction(ureq, trx);
    }
}
Also used : PaypalTransaction(org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction) StateMapped(org.olat.core.id.context.StateMapped)

Aggregations

PaypalTransaction (org.olat.resource.accesscontrol.provider.paypal.model.PaypalTransaction)20 Price (org.olat.resource.accesscontrol.Price)4 ClientActionRequiredException (com.paypal.exception.ClientActionRequiredException)2 HttpErrorException (com.paypal.exception.HttpErrorException)2 InvalidCredentialException (com.paypal.exception.InvalidCredentialException)2 InvalidResponseDataException (com.paypal.exception.InvalidResponseDataException)2 MissingCredentialException (com.paypal.exception.MissingCredentialException)2 SSLConfigurationException (com.paypal.exception.SSLConfigurationException)2 OAuthException (com.paypal.sdk.exceptions.OAuthException)2 AdaptivePaymentsService (com.paypal.svcs.services.AdaptivePaymentsService)2 PayRequest (com.paypal.svcs.types.ap.PayRequest)2 PayResponse (com.paypal.svcs.types.ap.PayResponse)2 Receiver (com.paypal.svcs.types.ap.Receiver)2 ReceiverList (com.paypal.svcs.types.ap.ReceiverList)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 FlexiTableSearchEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent)2 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)2