-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple App Store accounts handled on a single yaak …
…instance
- Loading branch information
1 parent
cbcae19
commit 6cf8e40
Showing
6 changed files
with
133 additions
and
116 deletions.
There are no files selected for viewing
40 changes: 23 additions & 17 deletions
40
src/main/kotlin/com/dietmap/yaak/api/appstore/receipt/ReceiptController.kt
This file contains 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 |
---|---|---|
@@ -1,33 +1,39 @@ | ||
package com.dietmap.yaak.api.appstore.receipt | ||
|
||
import com.dietmap.yaak.domain.appstore.AppStoreClient | ||
import com.dietmap.yaak.api.config.ApiCommons.TENANT_HEADER | ||
import com.dietmap.yaak.domain.appstore.AppStoreSubscriptionService | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import org.springframework.web.bind.annotation.* | ||
import javax.validation.Valid | ||
|
||
|
||
@ConditionalOnProperty("yaak.app-store.enabled", havingValue = "true") | ||
@RestController | ||
@RequestMapping("/api/appstore/receipts") | ||
class ReceiptController(private val appStoreClient : AppStoreClient) { | ||
class ReceiptController(private val subscriptionService: AppStoreSubscriptionService) { | ||
|
||
@PostMapping | ||
fun verify(@RequestBody @Valid receiptRequest: ReceiptRequest) : ResponseEntity<String> { | ||
val receiptResponse = appStoreClient.verifyReceipt(receiptRequest) | ||
|
||
return if (receiptResponse.isValid()) ResponseEntity.ok("VALID") | ||
else ResponseEntity.ok("NOT_VALID") | ||
companion object { | ||
private const val VALID = "VALID" | ||
private const val NOT_VALID = "NOT_VALID" | ||
} | ||
|
||
@PostMapping | ||
fun verify( | ||
@RequestBody @Valid receiptRequest: ReceiptRequest, | ||
@RequestHeader(TENANT_HEADER, required = false) tenant: String? | ||
): ResponseEntity<String> = | ||
if (subscriptionService.verifyReceipt(tenant, receiptRequest).isValid()) ResponseEntity.ok(VALID) else ResponseEntity.ok(NOT_VALID) | ||
|
||
@PostMapping("/verify") | ||
fun verifyWithResponse(@RequestBody @Valid receiptRequest: ReceiptRequest) : ResponseEntity<ReceiptValidationResponse> { | ||
val receiptResponse = appStoreClient.verifyReceipt(receiptRequest) | ||
fun verifyWithResponse( | ||
@RequestBody @Valid receiptRequest: ReceiptRequest, | ||
@RequestHeader(TENANT_HEADER, required = false) tenant: String? | ||
): ResponseEntity<ReceiptValidationResponse> = | ||
subscriptionService.verifyReceipt(tenant, receiptRequest) | ||
.let { | ||
if (it.isValid()) ResponseEntity.ok(ReceiptValidationResponse(it, VALID)) | ||
else ResponseEntity.ok(ReceiptValidationResponse(it, NOT_VALID)) | ||
} | ||
|
||
return if (receiptResponse.isValid()) ResponseEntity.ok(ReceiptValidationResponse(receiptResponse, "VALID")) | ||
else ResponseEntity.ok(ReceiptValidationResponse(receiptResponse, "NOT_VALID")) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.