Changeset 787

Show
Ignore:
Timestamp:
01/19/12 16:04:14 (4 months ago)
Author:
litwan
Message:

fixes issues from changing the parent class

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • resource-types/ipn-listener/src/java/com/litwan/yanel/impl/resources/ipnlistener/IPNListener.java

    r786 r787  
    9797    protected String paypalMessage_invoice; 
    9898     
    99     /** 
    100      * check if the transaction should be executed or not. 
    101      * override in subclass if an other test is wished  
    102      *  
    103      * @param String response.  
    104      * @return boolean. true if the response matches the expectation otherwise false  
    105      */ 
    106     protected boolean checkPreconditions(String response) { 
    107         if (response == null) { 
    108             return false; 
    109         } 
    110          
    111         try { 
    112             double paymentAmount = 0; 
    113             if (paypalMessage_mc_gross != null) { 
    114                 paymentAmount = Double.parseDouble(paypalMessage_mc_gross); 
    115             } 
    116             if (paypalMessage_mc_gross_1 != null) { 
    117                 paymentAmount = Double.parseDouble(paypalMessage_mc_gross_1); 
    118             } 
    119             String expectedRecieverEmail = getResourceConfigProperty("expected-reciever-email"); 
    120             String expectedPaymentCurrency = getResourceConfigProperty("expected-payment-currency"); 
    121              
    122             //check notification validation 
    123             if(response.equals("VERIFIED")) { 
    124                 // check that paymentStatus=Completed 
    125                 if (!paypalMessage_payment_status.equals("Completed")) { 
    126                     if (log.isInfoEnabled()) log.info("IPN Status: not Completed: " + paypalMessage_payment_status); 
    127                     return false; 
    128                 } 
    129                 // check that txnId has not been previously processed 
    130                 if (transactionIdExists(paypalMessage_txn_id)) { 
    131                     log.warn("IPN Status: txnId ("+ paypalMessage_txn_id +") already exists."); 
    132                     return false; 
    133                 } 
    134                 // check that receiverEmail is your Primary PayPal email 
    135                 if (!expectedRecieverEmail.equals(paypalMessage_receiver_email)) { 
    136                     log.warn("IPN Status: our paypal email is not the recivers email."); 
    137                     return false; 
    138                 } 
    139                 // check that paymentAmount/paymentCurrency are correct 
    140                 if (getExpectedPaymentAmount() != paymentAmount) { 
    141                     log.warn("IPN Status: the order total (" + getExpectedPaymentAmount() + ") is not equals the payment amount (" + paymentAmount + ")."); 
    142                     return false; 
    143                 } 
    144                 if (!paypalMessage_mc_currency.equals(expectedPaymentCurrency)) { 
    145                     log.error("IPN Status: the currency (" + paypalMessage_mc_currency + ") is not the expected "+ expectedPaymentCurrency +"."); 
    146                     return false; 
    147                 } 
    148                 //if everthing is ok 
    149                 if (log.isInfoEnabled()) log.info("seems to be alright, executig and setting transaction id as proceded"); 
    150                 return true; 
    151             } 
    152             else if(response.equals("INVALID")) { 
    153                 log.error("PayPal: INVALID ipn request. response was: " + response); 
    154                 return false; 
    155             } 
    156             else { 
    157                 log.error("PayPal: no valid response for ipn verification. response was: " + response); 
    158                 return false; 
    159             }       
    160         } catch (Exception e) { 
    161             log.error(e.getMessage(), e); 
    162             return false; 
    163         } 
    164     } 
    165  
    166     /** 
    167      * check if the transaction id already exists or not. 
    168      * implement in subclass!  
    169      *  
    170      * @param String txnId. the transaction id to check. 
    171      * @return boolean. true if transaction already exits. 
    172      */ 
    173     protected boolean transactionIdExists(String txnId) { 
    174         log.error("not implemented yet. please implement in sublcass"); 
    175         return false; 
    176     } 
    177  
    178     /** 
    179      * method to receive the expected payment amount. 
    180      * implement in subclass! 
    181      *   
    182      * @return double. expected paymend amount 
    183      */ 
    184     protected double getExpectedPaymentAmount() { 
    185         log.error("not implemented yet. please implement in sublcass"); 
    186         return 0.0; 
    187     } 
    188      
    189     /** 
    190      *  
    191      */ 
    192     protected void execute() { 
    193         log.error("not implemented yet. please implement in sublcass"); 
    194     }     
    195      
    196     /** 
    197      * this method allows for example to set the transaction id to exist 
    198      * implement in subclass! 
    199      *  
    200      */ 
    201     protected void postExecute() { 
    202         log.error("not implemented yet. please implement in sublcass"); 
    203     } 
    204      
    205     @Override 
    206     public InputStream getContentXML(String viewID) throws Exception { 
    207         init(); 
    208         if (checkPreconditions(verifyRequest())) { 
    209             execute(); 
    210             postExecute(); 
    211         } 
    212         return super.getContentXML(viewID); 
    213     } 
    214  
     99     
    215100    protected void init() { 
     101 
    216102        //String paymentStatus = getParameterAsString("payment_status"); 
    217103        paypalMessage_receiver_email = getParameterAsString("receiver_email"); 
     
    256142        paypalMessage_verify_sign = getParameterAsString("verify_sign"); 
    257143        paypalMessage_invoice = getParameterAsString("invoice"); 
    258     } 
     144         
     145        if (checkPreconditions(verifyRequest())) { 
     146            execute(); 
     147            postExecute(); 
     148        }         
     149    } 
     150     
     151    /** 
     152     * check if the transaction should be executed or not. 
     153     * override in subclass if an other test is wished  
     154     *  
     155     * @param String response.  
     156     * @return boolean. true if the response matches the expectation otherwise false  
     157     */ 
     158    protected boolean checkPreconditions(String response) { 
     159        if (response == null) { 
     160            return false; 
     161        } 
     162         
     163        try { 
     164            double paymentAmount = 0; 
     165            if (paypalMessage_mc_gross != null) { 
     166                paymentAmount = Double.parseDouble(paypalMessage_mc_gross); 
     167            } 
     168            if (paypalMessage_mc_gross_1 != null) { 
     169                paymentAmount = Double.parseDouble(paypalMessage_mc_gross_1); 
     170            } 
     171            String expectedRecieverEmail = getResourceConfigProperty("expected-reciever-email"); 
     172            String expectedPaymentCurrency = getResourceConfigProperty("expected-payment-currency"); 
     173             
     174            //check notification validation 
     175            if(response.equals("VERIFIED")) { 
     176                // check that paymentStatus=Completed 
     177                if (!paypalMessage_payment_status.equals("Completed")) { 
     178                    if (log.isInfoEnabled()) log.info("IPN Status: not Completed: " + paypalMessage_payment_status); 
     179                    return false; 
     180                } 
     181                // check that txnId has not been previously processed 
     182                if (transactionIdExists(paypalMessage_txn_id)) { 
     183                    log.warn("IPN Status: txnId ("+ paypalMessage_txn_id +") already exists."); 
     184                    return false; 
     185                } 
     186                // check that receiverEmail is your Primary PayPal email 
     187                if (!expectedRecieverEmail.equals(paypalMessage_receiver_email)) { 
     188                    log.warn("IPN Status: our paypal email is not the recivers email."); 
     189                    return false; 
     190                } 
     191                // check that paymentAmount/paymentCurrency are correct 
     192                if (getExpectedPaymentAmount() != paymentAmount) { 
     193                    log.warn("IPN Status: the order total (" + getExpectedPaymentAmount() + ") is not equals the payment amount (" + paymentAmount + ")."); 
     194                    return false; 
     195                } 
     196                if (!paypalMessage_mc_currency.equals(expectedPaymentCurrency)) { 
     197                    log.error("IPN Status: the currency (" + paypalMessage_mc_currency + ") is not the expected "+ expectedPaymentCurrency +"."); 
     198                    return false; 
     199                } 
     200                //if everthing is ok 
     201                if (log.isInfoEnabled()) log.info("seems to be alright, executig and setting transaction id as proceded"); 
     202                return true; 
     203            } 
     204            else if(response.equals("INVALID")) { 
     205                log.error("PayPal: INVALID ipn request. response was: " + response); 
     206                return false; 
     207            } 
     208            else { 
     209                log.error("PayPal: no valid response for ipn verification. response was: " + response); 
     210                return false; 
     211            }       
     212        } catch (Exception e) { 
     213            log.error(e.getMessage(), e); 
     214            return false; 
     215        } 
     216    } 
     217 
     218    /** 
     219     * check if the transaction id already exists or not. 
     220     * implement in subclass!  
     221     *  
     222     * @param String txnId. the transaction id to check. 
     223     * @return boolean. true if transaction already exits. 
     224     */ 
     225    protected boolean transactionIdExists(String txnId) { 
     226        log.error("not implemented yet. please implement in sublcass"); 
     227        return false; 
     228    } 
     229 
     230    /** 
     231     * method to receive the expected payment amount. 
     232     * implement in subclass! 
     233     *   
     234     * @return double. expected paymend amount 
     235     */ 
     236    protected double getExpectedPaymentAmount() { 
     237        log.error("not implemented yet. please implement in sublcass"); 
     238        return 0.0; 
     239    } 
     240     
     241    /** 
     242     *  
     243     */ 
     244    protected void execute() { 
     245        log.error("not implemented yet. please implement in sublcass"); 
     246    }     
     247     
     248    /** 
     249     * this method allows for example to set the transaction id to exist 
     250     * implement in subclass! 
     251     *  
     252     */ 
     253    protected void postExecute() { 
     254        log.error("not implemented yet. please implement in sublcass"); 
     255    } 
     256     
     257//    @Override 
     258//    public InputStream getContentXML(String viewID) throws Exception { 
     259//        init(); 
     260//        return super.getContentXML(viewID); 
     261//    } 
     262 
     263  
    259264     
    260265    /**