Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nikp.payment.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -9,8 +10,8 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.beans.factory.annotation.Value;

import com.nikp.captcha.CaptchaService;
import com.nikp.eventbus.api.EventBus;
import com.nikp.eventbus.domain.Event;
import com.nikp.payment.domain.Payment;
Expand All @@ -28,6 +29,9 @@ public class MVCController {

@Autowired
private PaymentRepository paymentRepository;

@Autowired
private CaptchaService captchaService;


@Value("${harness.build}" )
Expand All @@ -44,10 +48,10 @@ private void init() {
private EventBus eventBus;

@RequestMapping("/")
public String indexView(@RequestParam(name = "number", required = false, defaultValue = "")
public String indexView(@RequestParam(name = "number", required = false, defaultValue = "")
String number, @RequestParam(name = "sename", required = false, defaultValue = "")
String sename, Model model) {
System.out.println("Notification: all payments listed");
System.out.println("all payments executed");
model.addAttribute("list", paymentRepository.findAll());
model.addAttribute("number",buildNumber );
model.addAttribute("sename", seName);
Expand All @@ -56,28 +60,72 @@ public String indexView(@RequestParam(name = "number", required = false, default


@PostMapping("/mvc/payment")
public String paymentSubmit(@ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "")
public String paymentSubmit(@ModelAttribute PaymentDto paymentDto,@RequestParam(value="g-recaptcha-response") String response,@RequestParam(name = "number", required = false, defaultValue = "")
String number, @RequestParam(name = "sename", required = false, defaultValue = "")
String sename, Model model) {



if(paymentDto.getBankValidation().isEmpty())
{
try {
captchaService.processResponse(response);
}catch(BankValidationException e) {

model.addAttribute(paymentDto);
model.addAttribute("response",response);

return "bankError";
}catch(ReCaptchaInvalidException re)
{
return "captchaError";
}catch(ReCaptchaUnavailableException reU) {
return "captchaError";
}
}
paymentRepository.save(new Payment(paymentDto.getUserId(), paymentDto.getAccountFrom(), paymentDto.getAccountTo(), paymentDto.getAmount()));
eventBus.publish(new Event("SAVE", "Save payment" + paymentDto));
System.out.println("Notification: added payment from user "+paymentDto.getUserId());
model.addAttribute("list", paymentRepository.findAll());
model.addAttribute("number",buildNumber );
model.addAttribute("sename", seName);



return "allPayments";
}

@GetMapping("/mvc/createPayment")
public String paymentForm( @ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "")
String number, @RequestParam(name = "sename", required = false, defaultValue = "")
String sename, Model model) {
System.out.println("Notification: creating payment using the main form");

model.addAttribute("paymentDto", new PaymentDto());
model.addAttribute("number",buildNumber );
model.addAttribute("sename", seName);
;

return "create";


return "createOriginal";
}

@PostMapping("/mvc/payment/bank")
public String paymentSubmitBank(@ModelAttribute PaymentDto paymentDto,@RequestParam(name = "number", required = false, defaultValue = "")
String number, @RequestParam(name = "sename", required = false, defaultValue = "")
String sename, Model model) {



paymentRepository.save(new Payment(paymentDto.getUserId(), paymentDto.getAccountFrom(), paymentDto.getAccountTo(), paymentDto.getAmount()));
eventBus.publish(new Event("SAVE", "Save payment" + paymentDto));
model.addAttribute("list", paymentRepository.findAll());
model.addAttribute("number",buildNumber );
model.addAttribute("sename", seName);



return "allPayments";


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ public void shouldPostNewPayment() throws Exception {
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.sessionAttr("paymentDto", paymentDto)
)
.andExpect(status().isOk());
.andExpect(status().is4xxClientError());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void shouldPostNewPaymentWithCsrf() throws Exception {
.contentType(MediaType.APPLICATION_FORM_URLENCODED).with(csrf())
.sessionAttr("paymentDto", paymentDto)
)
.andExpect(status().isOk());
.andExpect(status().is4xxClientError());
}

@Test
Expand All @@ -111,4 +111,4 @@ public void shouldReturn403IfPostWithoutCsrf() throws Exception {
)
.andExpect(status().is(403));
}
}
}