elveos

elveos Commit Details

Date:2011-08-29 20:55:23 (1 year 8 months ago)
Author:Frédéric Bertolus
Branch:
Commit:8f9f2cbd885edfb69c145725f5279e14b445901d
Parents: a964f89874ba19b461313573609ad4e7de8e96c9
Message:fix some bugs on mercanet

File differences

main/src/main/java/com/bloatit/web/actions/WebProcess.java
8181    protected synchronized void transmitParameters() {
8282        // Nothing to do
8383    }
84
85    public synchronized void update(final WebProcess subProcess) {
86        if (father != null) {
87            father.update(this);
88        }
89    }
8490}
main/src/main/java/com/bloatit/web/linkable/contribution/ContributeAction.java
5353    @Override
5454    public Url doDoProcessRestricted(final Member me, final Team asTeam) {
5555        try {
56            process.getFeature().addContribution(process.getAmount(), process.getComment());
57            session.notifyGood(Context.tr("Thank you for contributing {0} on this feature.", Context.getLocalizator()
58                                                                                                  .getCurrency(process.getAmount())
59                                                                                                  .getSimpleEuroString()));
60
56            process.doContribute();
6157            final FeaturePageUrl featurePageUrl = new FeaturePageUrl(process.getFeature(), FeatureTabKey.contributions);
6258            process.close();
6359            return featurePageUrl;
60
6461        } catch (final NotEnoughMoneyException e) {
6562            session.notifyWarning(Context.tr("You need to charge your account before you can contribute."));
6663            return new CheckContributePageUrl(process);
67        } catch (final UnauthorizedOperationException e) {
68            session.notifyWarning(Context.tr("For obscure reasons, you are not allowed to contribute on this feature."));
69            return new ContributionProcessUrl(process.getFeature());
7064        } catch (final RuntimeException e) {
7165            process.close();
7266            throw e;
main/src/main/java/com/bloatit/web/linkable/contribution/ContributionProcess.java
2020
2121import javax.mail.IllegalWriteException;
2222
23import com.bloatit.data.exceptions.NotEnoughMoneyException;
24import com.bloatit.framework.exceptions.highlevel.MeanUserException;
25import com.bloatit.framework.exceptions.highlevel.ShallNotPassException;
2326import com.bloatit.framework.webprocessor.annotations.ParamContainer;
2427import com.bloatit.framework.webprocessor.annotations.RequestParam;
2528import com.bloatit.framework.webprocessor.context.Context;
2629import com.bloatit.framework.webprocessor.url.Url;
2730import com.bloatit.model.Feature;
2831import com.bloatit.model.feature.FeatureManager;
32import com.bloatit.model.right.UnauthorizedOperationException;
2933import com.bloatit.web.actions.AccountProcess;
3034import com.bloatit.web.actions.WebProcess;
3135import com.bloatit.web.linkable.invoice.ModifyInvoicingContactProcess;
...... 
4448    private BigDecimal amount = new BigDecimal("0");
4549    private String comment = "";
4650
51    private boolean contributionDone = false;
52
4753    public ContributionProcess(final ContributionProcessUrl url) {
4854        super(url);
4955        feature = url.getFeature();
...... 
101107        }
102108        return null;
103109    }
110
111    public synchronized void doContribute() throws NotEnoughMoneyException {
112        if(contributionDone) {
113            return;
114        }
115
116        try {
117            getFeature().addContribution(getAmount(), getComment());
118            contributionDone = true;
119
120            session.notifyGood(Context.tr("Thank you for contributing {0} on this feature.", Context.getLocalizator()
121                                                                                                    .getCurrency(getAmount())
122                                                                                                    .getSimpleEuroString()));
123        } catch (UnauthorizedOperationException e) {
124            new ShallNotPassException("No right to make a contribution");
125        }
126    }
127
128    @Override
129    public synchronized void update(final WebProcess subProcess) {
130        if (subProcess instanceof PaymentProcess) {
131            final PaymentProcess subPro = (PaymentProcess) subProcess;
132            if(subPro.isSuccessful()) {
133                try {
134                    doContribute();
135                } catch (NotEnoughMoneyException e) {
136                    // Do nothing.
137                }
138            }
139        }
140        super.update(this);
141    }
142
143
104144}
main/src/main/java/com/bloatit/web/linkable/money/PaymentAutoresponseAction.java
7272        Payment.handlePayment(bankTransaction, response);
7373
7474        if (process != null) {
75            //TODO: success = true !
76            return process.close();
75            process.load();
76            process.update(null);
7777        }
7878        return new IndexPageUrl();
7979    }
main/src/main/java/com/bloatit/web/linkable/money/PaymentProcess.java
113113        // Constructing the urls.
114114        final PaymentResponseActionUrl normalReturnActionUrl = new PaymentResponseActionUrl(this);
115115        final PaymentResponseActionUrl cancelReturnActionUrl = new PaymentResponseActionUrl(this);
116
117116
118117        String token = new RandomString(10).nextString();
119118        final PaymentAutoresponseActionUrl autoResponseActionUrl = new PaymentAutoresponseActionUrl(token);
120119        autoResponseActionUrl.setProcess(this);
121
120
122121        SessionManager.storeTemporarySession(token, session);
123122        MercanetTransaction mercanetTransaction;
124123        try {
...... 
161160    }
162161
163162    synchronized void handlePayment(String data) throws UnauthorizedOperationException {
164
163
165164        MercanetResponse response = MercanetAPI.parseResponse(data);
166165
167166        if (response.hasError()) {
...... 
172171        if (!response.check(bankTransaction.getId().toString(), bankTransaction.getAuthor().getId().toString(), mercanetTransactionId)) {
173172            throw new MeanUserException("Data received from transaction do not match the value sent when creating transaction");
174173        }
175
174
176175        Payment.handlePayment(bankTransaction, response);
177176
177        // Flush doesn't reload entities stored into the processes. Hence we
178        // need to reload the process to make sure we don't have references to
179        // old database objects
180        load();
181
178182        if (bankTransaction.getState() == State.VALIDATED) {
179183
180184            success = true;
...... 
183187            session.notifyGood(Context.tr("Payment of {0} accepted.", paidValueStr));
184188        } else {
185189            Log.payment().info("Payment refused. [" + response.getResponseCode().code + ": " + response.getResponseCode().label + "]");
186            session.notifyWarning(Context.tr("Payment canceled. Reason: {0}.",response.getResponseCode().getDisplayName()));
190            session.notifyWarning(Context.tr("Payment canceled. Reason: {0}.", response.getResponseCode().getDisplayName()));
187191        }
188192    }
189193
...... 
202206            return "Reference-not-Found";
203207        }
204208    }
209
210    @Override
211    public synchronized void update(final WebProcess subProcess) {
212        if (bankTransaction.getStateUnprotected() == State.VALIDATED) {
213            success = true;
214        }
215        super.update(this);
216    }
217
205218}

Archive Download the corresponding diff file