diff --git a/src/main/java/school/hei/klioba/model/psp/Psp.java b/src/main/java/school/hei/klioba/model/psp/Psp.java index d6e33af..54f73dd 100644 --- a/src/main/java/school/hei/klioba/model/psp/Psp.java +++ b/src/main/java/school/hei/klioba/model/psp/Psp.java @@ -3,7 +3,7 @@ import school.hei.klioba.model.Payment; public interface Psp { - Payment create(String kliobaId, PspType pspType, String pspId, String email); + Payment create(String kliobaId, PspType pspType, String pspId, String email, String scope); Payment get(String kliobaId, PspType pspType, String pspId, String email); } diff --git a/src/main/java/school/hei/klioba/model/psp/vola/VolaPsp.java b/src/main/java/school/hei/klioba/model/psp/vola/VolaPsp.java index 87ba484..ff234ab 100644 --- a/src/main/java/school/hei/klioba/model/psp/vola/VolaPsp.java +++ b/src/main/java/school/hei/klioba/model/psp/vola/VolaPsp.java @@ -18,8 +18,9 @@ public class VolaPsp implements Psp { private final VolaClient volaClient; @Override - public Payment create(String kliobaId, PspType pspType, String pspId, String email) { - var volaPayment = volaClient.create(pspType, pspId, email); + public Payment create( + String kliobaId, PspType pspType, String pspId, String email, String scope) { + var volaPayment = volaClient.create(pspType, pspId, email, scope); return toPayment(kliobaId, volaPayment); } diff --git a/src/main/java/school/hei/klioba/model/psp/vola/api/VolaClient.java b/src/main/java/school/hei/klioba/model/psp/vola/api/VolaClient.java index f76b43a..022d468 100644 --- a/src/main/java/school/hei/klioba/model/psp/vola/api/VolaClient.java +++ b/src/main/java/school/hei/klioba/model/psp/vola/api/VolaClient.java @@ -16,8 +16,8 @@ public VolaClient(String baseUrl, String apiKey) { this.paymentControllerApi = new PaymentControllerApi(apiClient); } - public Payment create(PspType pspType, String pspId, String email) { - return paymentControllerApi.createPayment(apiKey, email, pspType.toString(), pspId); + public Payment create(PspType pspType, String pspId, String email, String scope) { + return paymentControllerApi.createPayment(apiKey, email, pspType.toString(), pspId, scope); } public Payment get(PspType pspType, String pspId, String email) { diff --git a/src/main/java/school/hei/klioba/model/psp/vola/api/gen/client/api/PaymentControllerApi.java b/src/main/java/school/hei/klioba/model/psp/vola/api/gen/client/api/PaymentControllerApi.java index 9b6428d..516672b 100644 --- a/src/main/java/school/hei/klioba/model/psp/vola/api/gen/client/api/PaymentControllerApi.java +++ b/src/main/java/school/hei/klioba/model/psp/vola/api/gen/client/api/PaymentControllerApi.java @@ -49,9 +49,9 @@ public void setApiClient(ApiClient apiClient) { * @throws RestClientException if an error occurs while attempting to invoke the API */ public Payment createPayment( - String apiKey, String payerEmail, String pspType, String pspPaymentId) + String apiKey, String payerEmail, String pspType, String pspPaymentId, String scope) throws RestClientException { - return createPaymentWithHttpInfo(apiKey, payerEmail, pspType, pspPaymentId).getBody(); + return createPaymentWithHttpInfo(apiKey, payerEmail, pspType, pspPaymentId, scope).getBody(); } /** @@ -61,11 +61,12 @@ public Payment createPayment( * @param payerEmail (required) * @param pspType (required) * @param pspPaymentId (required) + * @param scope (optional) * @return ResponseEntity<Payment> * @throws RestClientException if an error occurs while attempting to invoke the API */ public ResponseEntity createPaymentWithHttpInfo( - String apiKey, String payerEmail, String pspType, String pspPaymentId) + String apiKey, String payerEmail, String pspType, String pspPaymentId, String scope) throws RestClientException { Object postBody = null; // verify the required parameter 'apiKey' is set @@ -101,6 +102,9 @@ public ResponseEntity createPaymentWithHttpInfo( queryParams.putAll(apiClient.parameterToMultiValueMap(null, "payerEmail", payerEmail)); queryParams.putAll(apiClient.parameterToMultiValueMap(null, "pspType", pspType)); queryParams.putAll(apiClient.parameterToMultiValueMap(null, "pspPaymentId", pspPaymentId)); + if (scope != null) { + queryParams.putAll(apiClient.parameterToMultiValueMap(null, "scope", scope)); + } final String[] accepts = {"*/*"}; final List accept = apiClient.selectHeaderAccept(accepts); diff --git a/src/main/java/school/hei/klioba/service/MembershipFeeCreationFormConsumer.java b/src/main/java/school/hei/klioba/service/MembershipFeeCreationFormConsumer.java index 48b3a26..f7d1d99 100644 --- a/src/main/java/school/hei/klioba/service/MembershipFeeCreationFormConsumer.java +++ b/src/main/java/school/hei/klioba/service/MembershipFeeCreationFormConsumer.java @@ -39,15 +39,19 @@ public void accept( throw new IllegalArgumentException("pspId format incorrect format"); } - var paymentCreatedInVola = - volaPsp.create( - randomUUID().toString(), pspType(), membershipFeeCreationForm.pspId(), email); - var payment = paymentRepository.save(paymentCreatedInVola); - var user = userFrom(membershipFeeCreationForm, email); var club = clubRepository .findById(clubId) .orElseThrow(() -> new NoSuchElementException("Club not found: " + clubId)); + var paymentCreatedInVola = + volaPsp.create( + randomUUID().toString(), + pspType(), + membershipFeeCreationForm.pspId(), + email, + club.getName()); + var payment = paymentRepository.save(paymentCreatedInVola); + var user = userFrom(membershipFeeCreationForm, email); eventRepository.save(Event.from(randomUUID().toString(), payment, user, club, now(), "")); assignUserToClub(user, clubId); } diff --git a/src/test/java/school/hei/klioba/service/EventServiceIT.java b/src/test/java/school/hei/klioba/service/EventServiceIT.java index 32b2b7a..081c28e 100644 --- a/src/test/java/school/hei/klioba/service/EventServiceIT.java +++ b/src/test/java/school/hei/klioba/service/EventServiceIT.java @@ -49,7 +49,7 @@ void create_then_confirm() { var ref1 = generateValidPspId(); var newEmail = randomUUID() + "@cute.dev"; - when(volaClientMock.create(any(), eq(ref1), eq(newEmail))) + when(volaClientMock.create(any(), eq(ref1), eq(newEmail), any())) .thenReturn(VolaTestUtils.aVolaPayment(VERIFYING)); membershipCreationFormConsumer.accept( new MembershipFeeCreationForm("Lou", "Andria", ref1), newEmail, "cuisine"); diff --git a/src/test/java/school/hei/klioba/service/MembershipFeeCreationFormConsumerIT.java b/src/test/java/school/hei/klioba/service/MembershipFeeCreationFormConsumerIT.java index 2a25eef..d7c2bbd 100644 --- a/src/test/java/school/hei/klioba/service/MembershipFeeCreationFormConsumerIT.java +++ b/src/test/java/school/hei/klioba/service/MembershipFeeCreationFormConsumerIT.java @@ -49,9 +49,9 @@ void payFee_then_read_fees() { var ref2 = generateValidPspId(); var newEmail = randomUUID() + "@cute.dev"; - when(volaClientMock.create(any(), eq(ref1), eq(newEmail))) + when(volaClientMock.create(any(), eq(ref1), eq(newEmail), any())) .thenReturn(VolaTestUtils.aVolaPayment(VerificationStatusEnum.VERIFYING, null, ref1)); - when(volaClientMock.create(any(), eq(ref2), eq(newEmail))) + when(volaClientMock.create(any(), eq(ref2), eq(newEmail), any())) .thenReturn(VolaTestUtils.aVolaPayment(VerificationStatusEnum.VERIFYING, null, ref2)); membershipCreationFormConsumer.accept( @@ -86,7 +86,7 @@ void payFee_then_read_fees() { void fees_cannot_have_same_pspId() { String pspId = generateValidPspId(); - when(volaClientMock.create(any(), any(), any())) + when(volaClientMock.create(any(), any(), any(), any())) .thenReturn(VolaTestUtils.aVolaPayment(VerificationStatusEnum.VERIFYING, null, pspId)); membershipCreationFormConsumer.accept(