Skip to content

Commit

Permalink
Return 403 when test codes are disabled for billing request (#15)
Browse files Browse the repository at this point in the history
Follow up for #11
  • Loading branch information
bokchan authored Aug 27, 2021
1 parent b26a99c commit 534c728
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ docker run --env-file .env -p 5000:5000 -v /tmp/Krankenkassenverzeichnis_DiGA.xm
"transport": "POST",
"xRechnung": "<?xml version=\"1.0\"..."
}

Example error response for billing requests with a diga test code when DISABLE_TESTCODES=true
{
"timestamp": "2021-08-23T09:38:32.385+00:00",
"status": 403,
"error": "Forbidden",
"message": "Testcodes are not allowed",
"path": "/validate/77AAAAAAAAAAAAAX"
}
```

## TODOS
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/dev/gtuk/diga/DigaService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import dev.gtuk.diga.dtos.BillingRequest
import dev.gtuk.diga.dtos.BillingResponse
import dev.gtuk.diga.dtos.ValidationResponse
import dev.gtuk.diga.exceptions.BillingException
import dev.gtuk.diga.exceptions.CodeValidationException
import dev.gtuk.diga.exceptions.TestCodesDisabledException
import dev.gtuk.diga.exceptions.ValidationException
import java.io.FileInputStream
Expand Down Expand Up @@ -101,7 +100,7 @@ class DigaService(private val appConfig: AppConfig) {
)
}

@Throws(BillingException::class)
@Throws(BillingException::class, TestCodesDisabledException::class)
fun bill(billingRequest: BillingRequest): BillingResponse {
val isTestCode = Utils.isTestCode(billingRequest.code)

Expand All @@ -113,13 +112,15 @@ class DigaService(private val appConfig: AppConfig) {

val response: DigaInvoiceResponse = try {
if (isTestCode && appConfig.disableTestcodes) {
throw CodeValidationException("Testcodes are not allowed")
throw TestCodesDisabledException("Testcodes are not allowed")
}
if (isTestCode) {
this.apiClient.sendTestInvoiceRequest(invoice, appConfig.testInsurance)
} else {
this.apiClient.invoiceDiga(invoice)
}
} catch (e: TestCodesDisabledException) {
throw e
} catch (e: Exception) {
logger.error("Billing errors", e)

Expand Down

0 comments on commit 534c728

Please sign in to comment.