Skip to content

Commit

Permalink
Merge pull request #10 from netkicorp/integrate_async_flow
Browse files Browse the repository at this point in the history
Integrating endpoints to support async methods
  • Loading branch information
alan10fm authored Nov 9, 2020
2 parents 920a3e5 + 81963c9 commit 21c8823
Show file tree
Hide file tree
Showing 10 changed files with 431 additions and 64 deletions.
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Also you can implement your own clients to connect to the API.

## General Usage

## Synchronous flow

### Initial invoice request

Endpoint: `/initial-invoice-request`
Expand Down Expand Up @@ -97,7 +99,60 @@ Description: `Send a payment binary to this endpoint and receive a paymentAck bi
Verb: `POST`
Params:
- payment: `Binary containing payment`
Response: `Binary containing paymentAck`
Response: `Binary containing paymentAck`

## Asynchronous flow

### Initial invoice request

Endpoint: `/async/initial-invoice-request`
Description: `If you want to test your full flow with getting an invoiceRequest object at your correct endpoint use the POST as described and it will send the binary object to that URL.`
Verb: `POST`
Params:
- url: `URL to post invoiceRequest`
Response: `HttpStatus 202 or error code`

If you want to change the notificationUrl for the InvoiceRequest that will be sent, you can do it in `TransactIdService.NOTIFICATION_URL`

### Initial invoice request Encrypted

Endpoint: `/async/initial-invoice-request-encrypted`
Verb: `POST`
Description: `If you want to test your full flow with getting an invoiceRequest object at your correct endpoint use the POST as described and it will send the binary object to that URL.`
Params:
- url: `URL to post invoice-request`
Response: `HttpStatus 202 or error code`

If you want to change the notificationUrl for the InvoiceRequest that will be sent, you can do it in `TransactIdService.NOTIFICATION_URL`

### Invoice request

Endpoint: `/async/invoice-request`
Description: `This endpoint receives an invoiceRequest binary and gives a 202 in return. Asynchronously you will receive a PaymentRequest binary in your NotificationUrl defined in your invoiceRequest`
Verb: `POST`
Params:
- invoiceRequest: `Binary containing invoiceRequest`
Response: `HttpStatus 202 or error code`

If you want to change the paymentUrl for the PaymentRequest that will be sent, you can do it in `TransactIdService.PAYMENT_URL`

### Payment request

Endpoint: `/async/payment-request`
Description: `This endpoint receives a paymentRequest binary and gives a 202 in return. Asynchronousluy you will receive a Payment binary in your PaymentUrl defined in your paymentRequest.`
Verb: `POST`
Params:
- paymentRequest: `Binary containing paymentRequest`
Response: `HttpStatus 202 or error code`

### Payment

Endpoint: `/async/payment`
Description: `Send a payment binary to this endpoint and receive a paymentAck binary in return.`
Verb: `POST`
Params:
- payment: `Binary containing payment`
Response: `Binary containing paymentAck`

### Encryption
You can generate EncryptedMessages to test this functionality. Once you start the service you can fetch a set of ECDSA keys to use in your ProtocolMessages.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
}

dependencies {
implementation("com.netki:transactid:1.0.0-beta2")
implementation("com.netki:transactid:1.0.1-beta2")

implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import com.netki.transactidlibraryjavademo.util.KeyGenerator.Keys.generateKeyPai
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import java.security.AlgorithmParameters
import java.security.KeyPair
import java.security.KeyPairGenerator
import java.security.SecureRandom
import java.security.spec.ECGenParameterSpec
import java.security.spec.ECParameterSpec
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import java.util.concurrent.Executor


@SpringBootApplication
@Configuration
@EnableAsync
class TransactidLibraryJavaDemoApplication {

@Bean
Expand All @@ -27,6 +28,11 @@ class TransactidLibraryJavaDemoApplication {
CryptoModule.objectToPublicKeyPem(recipientKeys.public)
)
}

@Bean(name = ["threadPoolTaskExecutor"])
fun threadPoolTaskExecutor(): Executor {
return ThreadPoolTaskExecutor()
}
}

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package com.netki.transactidlibraryjavademo.controller

import com.netki.transactidlibraryjavademo.model.InvoiceRequestUrl
import com.netki.transactidlibraryjavademo.service.TransactIdService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
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.tags.Tag
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController

@RestController
@Tag(name = "TransactId-Async", description = "The TransactId API async")
@RequestMapping("/async")
class TransactIdAsyncController {

@Autowired
private lateinit var transactIdService: TransactIdService

@Operation(
summary = "Send invoiceRequest binary",
description = "Send an invoiceRequest binary to an specific URL"
)
@ApiResponse(
responseCode = "202",
description = "Indicates that the request has been accepted for processing.",
content = [Content()]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/initial-invoice-request"],
produces = [MediaType.APPLICATION_JSON_VALUE],
consumes = [MediaType.APPLICATION_JSON_VALUE]
)
fun sendInitialInvoiceRequest(
@Parameter(description = "Url where the InvoiceRequest will be send")
@RequestBody invoiceRequestUrl: InvoiceRequestUrl
): ResponseEntity<Any> {
transactIdService.sendInitialInvoiceRequest(invoiceRequestUrl.url)
return ResponseEntity(HttpStatus.ACCEPTED)
}

@Operation(
summary = "Send invoiceRequest binary encrypted",
description = "Send an invoiceRequest binary encrypted to an specific URL"
)
@ApiResponse(
responseCode = "202",
description = "Indicates that the request has been accepted for processing.",
content = [Content()]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/initial-invoice-request-encrypted"],
produces = [MediaType.APPLICATION_JSON_VALUE],
consumes = [MediaType.APPLICATION_JSON_VALUE]
)
fun sendInitialInvoiceRequestEncrypted(
@Parameter(description = "Url where the InvoiceRequest will be send")
@RequestBody invoiceRequestUrl: InvoiceRequestUrl
): ResponseEntity<Any> {
transactIdService.sendInitialInvoiceRequestEncrypted(invoiceRequestUrl.url)
return ResponseEntity(HttpStatus.ACCEPTED)
}

@Operation(
summary = "Post an invoiceRequest binary with no sync response",
description = "This endpoint receives an invoiceRequest binary and gives a 202 in return. Asynchronous you will receive a PaymentRequest binary in your NotificationUrl defined in your invoiceRequest."
)
@ApiResponse(
responseCode = "202",
description = "Indicates that the request has been accepted for processing.",
content = [Content()]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/invoice-request"],
consumes = [MediaType.APPLICATION_OCTET_STREAM_VALUE],
produces = [MediaType.APPLICATION_OCTET_STREAM_VALUE]
)
fun postInvoiceRequest(
@Parameter(description = "Binary containing invoiceRequest")
@RequestBody invoiceRequest: ByteArray
): ResponseEntity<Any> {
return try {
transactIdService.postInvoiceRequestAsync(invoiceRequest)
ResponseEntity(HttpStatus.ACCEPTED)
} catch (exception: Exception) {
ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exception.message)
}
}

@Operation(
summary = "Post a paymentRequest binary with no sync response.",
description = "This endpoint receives a paymentRequest binary and gives a 202 in return. Asynchronous you will receive a Payment binary in your PaymentUrl defined in your paymentRequest."
)
@ApiResponse(
responseCode = "202",
description = "Indicates that the request has been accepted for processing.",
content = [Content()]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/payment-request"],
consumes = [MediaType.APPLICATION_OCTET_STREAM_VALUE],
produces = [MediaType.APPLICATION_OCTET_STREAM_VALUE]
)

fun postPaymentRequest(
@Parameter(description = "Binary containing paymentRequest")
@RequestBody paymentRequest: ByteArray
): ResponseEntity<Any> {
return try {
transactIdService.postPaymentRequestAsync(paymentRequest)
ResponseEntity(HttpStatus.ACCEPTED)
} catch (exception: Exception) {
ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exception.message)
}
}

@Operation(
summary = "Post a payment binary",
description = "This endpoint receives a payment binary and gives a paymentAck binary in return."
)
@ApiResponse(
responseCode = "200",
description = "PaymentAck binary.",
content = [
Content(
mediaType = MediaType.APPLICATION_OCTET_STREAM_VALUE,
schema = Schema(implementation = ByteArray::class)
)
]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/payment"],
consumes = [MediaType.APPLICATION_OCTET_STREAM_VALUE],
produces = [MediaType.APPLICATION_OCTET_STREAM_VALUE]
)
fun postPayment(
@Parameter(description = "Binary containing payment")
@RequestBody payment: ByteArray
): ResponseEntity<Any> {
return try {
val paymentAck = transactIdService.postPayment(payment)
ResponseEntity.ok(paymentAck)
} catch (exception: Exception) {
ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exception.message)
}
}
}
Loading

0 comments on commit 21c8823

Please sign in to comment.