-
Notifications
You must be signed in to change notification settings - Fork 0
PAYM-95 - Create Invoice #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vitorsob
wants to merge
3
commits into
main
Choose a base branch
from
PAYM-95
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
src/main/java/com/cross/chain/payment/controller/invoice/InvoiceApiController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package com.cross.chain.payment.controller.invoice; | ||
|
|
||
| import com.cross.chain.payment.exception.InvoiceRequestNotFound; | ||
| import com.cross.chain.payment.model.InvoiceConfirmationRequest; | ||
| import com.cross.chain.payment.model.InvoiceRequest; | ||
| import com.cross.chain.payment.model.InvoiceResponse; | ||
| import com.cross.chain.payment.model.Transaction; | ||
| import com.cross.chain.payment.model.enums.InvoiceType; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
|
|
||
|
|
||
| @Tag(name = "invoices", description = "Invoice Operations") | ||
| public interface InvoiceApiController { | ||
|
|
||
| String INVOICE = "/invoice"; | ||
| String INVOICE_HASH = "/invoice/{invoiceHash}"; | ||
| String INVOICE_HASH_TRANSACTION = "/invoice/{invoiceHash}/transaction"; | ||
| String INVOICE_HASH_CONFIRMATION = "/invoice/{invoiceHash}/confirmation"; | ||
| String INVOICE_HASH_CANCELLATION = "/invoice/{invoiceHash}/cancellation"; | ||
| String INVOICE_FIND_BY_USER_ADDRESS = "/invoice/findByUserAddress"; | ||
|
|
||
| @Operation(summary = "create a invoice", tags={ "invoices" }) | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "201", description = "successful operation", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = InvoiceRequest.class))), | ||
| @ApiResponse(responseCode = "400", description = "Invalid data supplied"), | ||
| @ApiResponse(responseCode = "404", description = "User not found") }) | ||
| ResponseEntity<InvoiceResponse> createInvoice(@Parameter(in = ParameterIn.DEFAULT, description = "Created invoice object", schema=@Schema()) @RequestBody InvoiceRequest body); | ||
|
|
||
|
|
||
| @Operation(summary = "get all invoices with filter", description = "", tags={ "invoices" }) | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "201", description = "successful operation", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = InvoiceRequest.class))), | ||
| @ApiResponse(responseCode = "400", description = "Invalid data supplied")}) | ||
| ResponseEntity<InvoiceRequest> invoiceByHash(@Parameter(in = ParameterIn.PATH, description = "hash that identify the invoice" ,schema=@Schema())@PathVariable(value = "invoiceHash") String invoiceHash) throws InvoiceRequestNotFound; | ||
|
|
||
| @Operation(summary = "get all transaction with filter", description = "", tags={ "invoices" }) | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "201", description = "successful operation", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = InvoiceRequest.class))), | ||
| @ApiResponse(responseCode = "400", description = "Invalid data supplied")}) | ||
| ResponseEntity<List<Transaction>> transactionByInvoiceHash(@Parameter(in = ParameterIn.PATH, description = "hash that identify the invoice" ,schema=@Schema())@PathVariable(value = "invoiceHash") String invoiceHash) throws InvoiceRequestNotFound; | ||
|
|
||
| @Operation(summary = "Update invoice given a hash", description = "", tags={ "invoices" }) | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "201", description = "successful operation", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = InvoiceRequest.class))), | ||
| @ApiResponse(responseCode = "400", description = "Invalid data supplied"), | ||
| @ApiResponse(responseCode = "404", description = "Invoice not found") }) | ||
| ResponseEntity<InvoiceRequest> updateInvoiceByHash(@Parameter(in = ParameterIn.PATH, description = "hash that identify the invoice" ,schema=@Schema()) @PathVariable(value = "invoiceHash") String invoiceHash, @RequestBody InvoiceRequest body) throws InvoiceRequestNotFound; | ||
|
|
||
| @Operation(summary = "Invoice confirmation", description = "", tags={ "invoices" }) | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "201", description = "successful operation", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = InvoiceRequest.class))), | ||
| @ApiResponse(responseCode = "400", description = "Invalid data supplied"), | ||
| @ApiResponse(responseCode = "404", description = "User not found") }) | ||
| ResponseEntity invoiceConfirmation(@Parameter(in = ParameterIn.PATH, description = "hash that identify the invoice" ,schema=@Schema())@PathVariable(value = "invoiceHash") String invoiceHash, | ||
| @Parameter(in = ParameterIn.DEFAULT, description = "Created invoice object", schema=@Schema()) @RequestBody InvoiceConfirmationRequest body) throws InvoiceRequestNotFound; | ||
|
|
||
| @Operation(summary = "Invoice cancellation", description = "", tags={ "invoices" }) | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "201", description = "successful operation", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = InvoiceRequest.class))), | ||
| @ApiResponse(responseCode = "400", description = "Invalid data supplied"), | ||
| @ApiResponse(responseCode = "404", description = "User not found") }) | ||
| ResponseEntity invoiceCancellation(@Parameter(in = ParameterIn.PATH, description = "hash that identify the invoice" ,schema=@Schema())@PathVariable(value = "invoiceHash") String invoiceHash) throws InvoiceRequestNotFound; | ||
|
|
||
| @Operation(summary = "get all invoices with filter", description = "(INTERNAL USAGE ONLY)", tags={ "invoices" }) | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "201", description = "successful operation", content = @Content(mediaType = APPLICATION_JSON_VALUE, schema = @Schema(implementation = InvoiceRequest.class))), | ||
| @ApiResponse(responseCode = "400", description = "Invalid data supplied"), | ||
| @ApiResponse(responseCode = "404", description = "User not found") }) | ||
| ResponseEntity<InvoiceRequest> getAllInvoice(@Parameter(in = ParameterIn.QUERY, description = "accountId that belongs the invoices" ,schema=@Schema())@RequestParam(value = "accountId", required = false) String accountId, @Parameter(in = ParameterIn.QUERY, description = "Invoice type that need to be considered for filter" ,schema=@Schema()) InvoiceType invoiceType); | ||
|
|
||
|
|
||
| @Operation(summary = "get a invoice by User Address", tags={ "invoices" }) | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "201", description = "successful operation", content = @Content(mediaType = "application/json", schema = @Schema(implementation = InvoiceRequest.class))), | ||
| @ApiResponse(responseCode = "400", description = "Invalid data supplied"), | ||
| @ApiResponse(responseCode = "404", description = "User not found") }) | ||
| ResponseEntity<List<InvoiceRequest>> getAllInvoiceGivenUserAddressAndFilters(@Parameter(in = ParameterIn.QUERY, description = "User address that owns the invoices" ,required=true,schema=@Schema()) String accountId, @Parameter(in = ParameterIn.QUERY, description = "Invoice type that need to be considered for filter" ,schema=@Schema()) InvoiceType invoiceType); | ||
|
|
||
| } | ||
|
|
78 changes: 78 additions & 0 deletions
78
src/main/java/com/cross/chain/payment/controller/invoice/InvoiceApiControllerImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package com.cross.chain.payment.controller.invoice; | ||
|
|
||
| import com.cross.chain.payment.exception.InvoiceRequestNotFound; | ||
| import com.cross.chain.payment.model.InvoiceConfirmationRequest; | ||
| import com.cross.chain.payment.model.InvoiceRequest; | ||
| import com.cross.chain.payment.model.InvoiceResponse; | ||
| import com.cross.chain.payment.model.Transaction; | ||
| import com.cross.chain.payment.model.enums.InvoiceType; | ||
| import com.cross.chain.payment.service.invoice.InvoiceProcessorService; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import javax.validation.Valid; | ||
| import javax.validation.constraints.NotNull; | ||
| import java.util.List; | ||
|
|
||
| import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| @RequestMapping(value = "/api/v1") | ||
| public class InvoiceApiControllerImpl implements InvoiceApiController { | ||
|
|
||
| @Autowired | ||
| private InvoiceProcessorService invoiceProcessorService; | ||
| @Override | ||
| @PostMapping(value = INVOICE, produces = { APPLICATION_JSON_VALUE }, consumes = { APPLICATION_JSON_VALUE }) | ||
| public ResponseEntity<InvoiceResponse> createInvoice(@Valid @RequestBody InvoiceRequest body) { | ||
| return ResponseEntity.ok(invoiceProcessorService.processInvoiceRequest(body)); | ||
| } | ||
|
|
||
| @Override | ||
| @GetMapping(value = INVOICE_HASH, produces = { APPLICATION_JSON_VALUE }) | ||
| public ResponseEntity<InvoiceRequest> invoiceByHash(@PathVariable("invoiceHash") String invoiceHash) throws InvoiceRequestNotFound { | ||
| return ResponseEntity.ok(invoiceProcessorService.retrieveInvoiceRequest(invoiceHash)); | ||
| } | ||
|
|
||
| @Override | ||
| @GetMapping(value = INVOICE_HASH_TRANSACTION, produces = { APPLICATION_JSON_VALUE }) | ||
| public ResponseEntity<List<Transaction>> transactionByInvoiceHash(String invoiceHash) throws InvoiceRequestNotFound { | ||
| return ResponseEntity.ok(invoiceProcessorService.retrieveInvoiceTransactions(invoiceHash)); | ||
| } | ||
|
|
||
| @Override | ||
| @PatchMapping(value = INVOICE_HASH, produces = { APPLICATION_JSON_VALUE }) | ||
| public ResponseEntity<InvoiceRequest> updateInvoiceByHash(@PathVariable("invoiceHash") String invoiceHash, @Valid @RequestBody InvoiceRequest body) throws InvoiceRequestNotFound { | ||
| return ResponseEntity.ok(invoiceProcessorService.updateInvoiceRequest(invoiceHash, body)); | ||
| } | ||
|
|
||
| @Override | ||
| @PostMapping(value = INVOICE_HASH_CONFIRMATION, consumes = { APPLICATION_JSON_VALUE }) | ||
| public ResponseEntity invoiceConfirmation(@PathVariable("invoiceHash") String invoiceHash, @Valid @RequestBody InvoiceConfirmationRequest body) throws InvoiceRequestNotFound { | ||
| invoiceProcessorService.invoiceConfirmation(invoiceHash, body); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
|
|
||
| @Override | ||
| @PostMapping(value = INVOICE_HASH_CANCELLATION) | ||
| public ResponseEntity invoiceCancellation(@PathVariable("invoiceHash") String invoiceHash) throws InvoiceRequestNotFound { | ||
| invoiceProcessorService.invoiceCancellation(invoiceHash); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
|
|
||
| @Override | ||
| @GetMapping(value = INVOICE, produces = { APPLICATION_JSON_VALUE }) | ||
| public ResponseEntity<InvoiceRequest> getAllInvoice(@Valid @RequestParam(value = "accountId", required = false) String accountId, @Valid @RequestParam(value = "invoiceType", required = false) InvoiceType invoiceType) { | ||
| return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); | ||
| } | ||
| @Override | ||
| @GetMapping(value = INVOICE_FIND_BY_USER_ADDRESS, produces = { APPLICATION_JSON_VALUE }) | ||
| public ResponseEntity<List<InvoiceRequest>> getAllInvoiceGivenUserAddressAndFilters(@NotNull @Valid @RequestParam(value = "address") String address, @Valid @RequestParam(value = "invoiceType", required = false) InvoiceType invoiceType) { | ||
| return ResponseEntity.ok(invoiceProcessorService.retrieveByUserAddress(address)); | ||
| } | ||
|
|
||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/cross/chain/payment/exception/InvoiceLinkCreationException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.cross.chain.payment.exception; | ||
|
|
||
| public class InvoiceLinkCreationException extends RuntimeException { | ||
| public InvoiceLinkCreationException(Exception exception){ | ||
| super(exception); | ||
| } | ||
|
|
||
| } |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/cross/chain/payment/exception/InvoiceProcessorException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.cross.chain.payment.exception; | ||
|
|
||
| public class InvoiceProcessorException extends RuntimeException{ | ||
|
|
||
| } |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/cross/chain/payment/exception/InvoiceRequestNotFound.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.cross.chain.payment.exception; | ||
|
|
||
| public class InvoiceRequestNotFound extends Exception { | ||
|
|
||
| } |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/cross/chain/payment/mapper/InvoiceRequestMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.cross.chain.payment.mapper; | ||
|
|
||
| import com.cross.chain.payment.model.InvoiceConfirmationDTO; | ||
| import com.cross.chain.payment.model.InvoiceConfirmationRequest; | ||
| import com.cross.chain.payment.model.InvoiceRequest; | ||
| import com.cross.chain.payment.model.InvoiceRequestDTO; | ||
| import org.bson.BsonBinarySubType; | ||
| import org.bson.types.Binary; | ||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.Mapping; | ||
|
|
||
| @Mapper(componentModel = "spring") | ||
| public interface InvoiceRequestMapper { | ||
|
|
||
| InvoiceRequestDTO map(InvoiceRequest invoiceRequest); | ||
| @Mapping(source = "createdAt", target = "createdAt", dateFormat = "dd/MM/yyyy HH:mm:ss") | ||
| InvoiceRequest map(InvoiceRequestDTO invoiceRequest); | ||
|
|
||
| InvoiceConfirmationDTO map(InvoiceConfirmationRequest invoiceConfirmationDTO); | ||
|
|
||
| default Binary map(byte[] value){ | ||
| if(value == null){ | ||
| return null; | ||
| } | ||
| return new Binary(BsonBinarySubType.BINARY, value); | ||
| } | ||
| default byte[] map(Binary value){ | ||
| if(value == null){ | ||
| return null; | ||
| } | ||
| return value.getData(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/cross/chain/payment/model/InvoiceConfirmationDTO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.cross.chain.payment.model; | ||
|
|
||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * PaymentConfirmation | ||
| */ | ||
| @Data | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class InvoiceConfirmationDTO { | ||
| private TransactionDetailsDTO transactionDetails; | ||
| private BigDecimal amount; | ||
| private List<ProductPaymentRequest> products; | ||
| private CustomerInfoDTO customerInfoDTO; | ||
| } |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/cross/chain/payment/model/InvoiceConfirmationRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package com.cross.chain.payment.model; | ||
|
|
||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
| import org.springframework.validation.annotation.Validated; | ||
|
|
||
| import javax.validation.Valid; | ||
| import java.math.BigDecimal; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * PaymentConfirmation | ||
| */ | ||
| @Data | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| @Validated | ||
| public class InvoiceConfirmationRequest { | ||
|
|
||
| @Valid | ||
| @JsonProperty("transactionDetails") | ||
| private TransactionDetails transactionDetails; | ||
|
|
||
| @Valid | ||
| @JsonProperty("amountPaid") | ||
| private BigDecimal amount; | ||
|
|
||
| @Valid | ||
| @JsonProperty("products") | ||
| private List<ProductPaymentRequest> products; | ||
|
|
||
| @Valid | ||
| @JsonProperty("customerInfo") | ||
| private CustomerInfoDTO customerInfoDTO; | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clearly an copy and past, fix here :)