Skip to content

Commit 0451ed2

Browse files
committed
Load access token for invoice request
1 parent 7c1bd29 commit 0451ed2

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

feature-billing/src/wasmJsMain/kotlin/com/mooncloak/website/feature/billing/BillingStateModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public data class BillingStateModel public constructor(
2020
public val paymentStatusDetails: BillingPaymentStatusDetails? = null,
2121
public val selectedPlan: Plan? = null,
2222
public val plans: List<Plan> = emptyList(),
23-
public val token: TransactionToken? = null,
23+
public val transactionToken: TransactionToken? = null,
2424
public val acceptedTerms: Boolean = false,
2525
public val termsAndConditionsText: @Composable () -> AnnotatedString = { AnnotatedString("") },
2626
public val noticeText: String? = null,

feature-billing/src/wasmJsMain/kotlin/com/mooncloak/website/feature/billing/BillingViewModel.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class BillingViewModel public constructor(
6464
isLoading = false,
6565
selectedPlan = selectedPlan,
6666
plans = plans,
67-
token = token,
67+
transactionToken = token,
6868
queryParameters = queryParameters,
6969
startDestination = when (paymentStatus) {
7070
BillingPaymentStatus.Completed -> BillingDestination.Success
@@ -85,7 +85,7 @@ public class BillingViewModel public constructor(
8585
isLoading = false,
8686
selectedPlan = selectedPlan,
8787
plans = plans,
88-
token = token,
88+
transactionToken = token,
8989
queryParameters = queryParameters,
9090
startDestination = when (paymentStatus) {
9191
BillingPaymentStatus.Completed -> BillingDestination.Success
@@ -126,7 +126,8 @@ public class BillingViewModel public constructor(
126126
invoice = getInvoice(
127127
productId = productId,
128128
currencyCode = currentState.selectedCryptoCurrency.currencyCode,
129-
currentInvoices = currentState.invoices
129+
currentInvoices = currentState.invoices,
130+
accessToken = currentState.queryParameters["access_token"]
130131
)
131132
}
132133

@@ -177,7 +178,8 @@ public class BillingViewModel public constructor(
177178
invoice = getInvoice(
178179
productId = productId,
179180
currencyCode = currentState.selectedCryptoCurrency.currencyCode,
180-
currentInvoices = currentState.invoices
181+
currentInvoices = currentState.invoices,
182+
accessToken = currentState.queryParameters["access_token"]
181183
)
182184
}
183185

@@ -291,12 +293,10 @@ public class BillingViewModel public constructor(
291293
.filter { plan -> plan.isAvailable(at = clock.now()) }
292294
.sortedBy { plan -> plan.price.amount }
293295

294-
private suspend fun getPlan(id: String?): Plan? =
295-
id?.let { billingApi.getPlan(id = it) }
296-
297296
private suspend fun getInvoice(
298297
currencyCode: Currency.Code,
299298
productId: String?,
299+
accessToken: String?,
300300
currentInvoices: Map<CryptoCurrency, CryptoInvoice?>
301301
): CryptoInvoice? {
302302
CryptoCurrency[currencyCode]?.let { currentInvoices[it] }?.let { return it }
@@ -305,7 +305,8 @@ public class BillingViewModel public constructor(
305305

306306
return billingApi.getInvoice(
307307
productId = productId,
308-
currencyCode = currencyCode
308+
currencyCode = currencyCode,
309+
accessToken = accessToken
309310
)
310311
}
311312

feature-billing/src/wasmJsMain/kotlin/com/mooncloak/website/feature/billing/api/BillingApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface BillingApi {
1212

1313
public suspend fun getInvoice(
1414
productId: String,
15-
token: String? = null,
15+
accessToken: String? = null,
1616
currencyCode: Currency.Code
1717
): CryptoInvoice
1818

feature-billing/src/wasmJsMain/kotlin/com/mooncloak/website/feature/billing/api/HttpBillingApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ internal class HttpBillingApi internal constructor(
3838
return@withContext response.body<HttpResponseBody<AvailablePlans>>().getOrThrow().plans
3939
}
4040

41-
override suspend fun getInvoice(productId: String, token: String?, currencyCode: Currency.Code): CryptoInvoice =
41+
override suspend fun getInvoice(productId: String, accessToken: String?, currencyCode: Currency.Code): CryptoInvoice =
4242
withContext(Dispatchers.Default) {
4343
val response = httpClient.post(url("/billing/payment/invoice")) {
44-
token?.let { bearerAuth(it) }
44+
accessToken?.let { bearerAuth(it) }
4545

4646
contentType(ContentType.Application.Json)
4747
accept(ContentType.Application.Json)

0 commit comments

Comments
 (0)