| main/src/main/java/com/bloatit/web/linkable/contribution/ContributeAction.java |
| 53 | 53 | @Override |
| 54 | 54 | public Url doDoProcessRestricted(final Member me, final Team asTeam) { |
| 55 | 55 | 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(); |
| 61 | 57 | final FeaturePageUrl featurePageUrl = new FeaturePageUrl(process.getFeature(), FeatureTabKey.contributions); |
| 62 | 58 | process.close(); |
| 63 | 59 | return featurePageUrl; |
| 60 | |
| 64 | 61 | } catch (final NotEnoughMoneyException e) { |
| 65 | 62 | session.notifyWarning(Context.tr("You need to charge your account before you can contribute.")); |
| 66 | 63 | 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()); |
| 70 | 64 | } catch (final RuntimeException e) { |
| 71 | 65 | process.close(); |
| 72 | 66 | throw e; |
| main/src/main/java/com/bloatit/web/linkable/contribution/ContributionProcess.java |
| 20 | 20 | |
| 21 | 21 | import javax.mail.IllegalWriteException; |
| 22 | 22 | |
| 23 | import com.bloatit.data.exceptions.NotEnoughMoneyException; |
| 24 | import com.bloatit.framework.exceptions.highlevel.MeanUserException; |
| 25 | import com.bloatit.framework.exceptions.highlevel.ShallNotPassException; |
| 23 | 26 | import com.bloatit.framework.webprocessor.annotations.ParamContainer; |
| 24 | 27 | import com.bloatit.framework.webprocessor.annotations.RequestParam; |
| 25 | 28 | import com.bloatit.framework.webprocessor.context.Context; |
| 26 | 29 | import com.bloatit.framework.webprocessor.url.Url; |
| 27 | 30 | import com.bloatit.model.Feature; |
| 28 | 31 | import com.bloatit.model.feature.FeatureManager; |
| 32 | import com.bloatit.model.right.UnauthorizedOperationException; |
| 29 | 33 | import com.bloatit.web.actions.AccountProcess; |
| 30 | 34 | import com.bloatit.web.actions.WebProcess; |
| 31 | 35 | import com.bloatit.web.linkable.invoice.ModifyInvoicingContactProcess; |
| ... | ... | |
| 44 | 48 | private BigDecimal amount = new BigDecimal("0"); |
| 45 | 49 | private String comment = ""; |
| 46 | 50 | |
| 51 | private boolean contributionDone = false; |
| 52 | |
| 47 | 53 | public ContributionProcess(final ContributionProcessUrl url) { |
| 48 | 54 | super(url); |
| 49 | 55 | feature = url.getFeature(); |
| ... | ... | |
| 101 | 107 | } |
| 102 | 108 | return null; |
| 103 | 109 | } |
| 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 | |
| 104 | 144 | } |
| main/src/main/java/com/bloatit/web/linkable/money/PaymentProcess.java |
| 113 | 113 | // Constructing the urls. |
| 114 | 114 | final PaymentResponseActionUrl normalReturnActionUrl = new PaymentResponseActionUrl(this); |
| 115 | 115 | final PaymentResponseActionUrl cancelReturnActionUrl = new PaymentResponseActionUrl(this); |
| 116 | | |
| 117 | 116 | |
| 118 | 117 | String token = new RandomString(10).nextString(); |
| 119 | 118 | final PaymentAutoresponseActionUrl autoResponseActionUrl = new PaymentAutoresponseActionUrl(token); |
| 120 | 119 | autoResponseActionUrl.setProcess(this); |
| 121 | | |
| 120 | |
| 122 | 121 | SessionManager.storeTemporarySession(token, session); |
| 123 | 122 | MercanetTransaction mercanetTransaction; |
| 124 | 123 | try { |
| ... | ... | |
| 161 | 160 | } |
| 162 | 161 | |
| 163 | 162 | synchronized void handlePayment(String data) throws UnauthorizedOperationException { |
| 164 | | |
| 163 | |
| 165 | 164 | MercanetResponse response = MercanetAPI.parseResponse(data); |
| 166 | 165 | |
| 167 | 166 | if (response.hasError()) { |
| ... | ... | |
| 172 | 171 | if (!response.check(bankTransaction.getId().toString(), bankTransaction.getAuthor().getId().toString(), mercanetTransactionId)) { |
| 173 | 172 | throw new MeanUserException("Data received from transaction do not match the value sent when creating transaction"); |
| 174 | 173 | } |
| 175 | | |
| 174 | |
| 176 | 175 | Payment.handlePayment(bankTransaction, response); |
| 177 | 176 | |
| 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 | |
| 178 | 182 | if (bankTransaction.getState() == State.VALIDATED) { |
| 179 | 183 | |
| 180 | 184 | success = true; |
| ... | ... | |
| 183 | 187 | session.notifyGood(Context.tr("Payment of {0} accepted.", paidValueStr)); |
| 184 | 188 | } else { |
| 185 | 189 | 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())); |
| 187 | 191 | } |
| 188 | 192 | } |
| 189 | 193 | |
| ... | ... | |
| 202 | 206 | return "Reference-not-Found"; |
| 203 | 207 | } |
| 204 | 208 | } |
| 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 | |
| 205 | 218 | } |