This repository has been archived by the owner on Feb 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from nathanfallet/feature/stripe-setup
feat: stripe onboarding
- Loading branch information
Showing
30 changed files
with
563 additions
and
136 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,9 @@ cloudflare: | |
account: '' | ||
token: '' | ||
|
||
stripe: | ||
key: '' | ||
|
||
# MySQL configuration | ||
|
||
mysql: | ||
|
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
24 changes: 23 additions & 1 deletion
24
...c/commonMain/kotlin/me/nathanfallet/suitebde/controllers/dashboard/DashboardController.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,7 +1,29 @@ | ||
package me.nathanfallet.suitebde.controllers.dashboard | ||
|
||
class DashboardController : IDashboardController { | ||
import io.ktor.server.application.* | ||
import io.ktor.server.request.* | ||
import me.nathanfallet.ktorx.models.responses.RedirectResponse | ||
import me.nathanfallet.suitebde.usecases.associations.ICreateStripeAccountLinkUseCase | ||
import me.nathanfallet.suitebde.usecases.associations.IRefreshStripeAccountUseCase | ||
import me.nathanfallet.suitebde.usecases.associations.IRequireAssociationForCallUseCase | ||
|
||
class DashboardController( | ||
private val requireAssociationForCallUseCase: IRequireAssociationForCallUseCase, | ||
private val refreshStripeAccountUseCase: IRefreshStripeAccountUseCase, | ||
private val createStripeAccountLinkUseCase: ICreateStripeAccountLinkUseCase, | ||
) : IDashboardController { | ||
|
||
override suspend fun dashboard() {} | ||
|
||
override suspend fun settings(call: ApplicationCall) { | ||
val association = requireAssociationForCallUseCase(call) | ||
refreshStripeAccountUseCase(association) | ||
} | ||
|
||
override suspend fun settingsStripe(call: ApplicationCall): RedirectResponse { | ||
val association = requireAssociationForCallUseCase(call) | ||
val returnUrl = "https://${call.request.host()}/admin/settings" | ||
return RedirectResponse(createStripeAccountLinkUseCase(association, returnUrl) ?: returnUrl) | ||
} | ||
|
||
} |
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
20 changes: 17 additions & 3 deletions
20
.../commonMain/kotlin/me/nathanfallet/suitebde/controllers/dashboard/IDashboardController.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,13 +1,27 @@ | ||
package me.nathanfallet.suitebde.controllers.dashboard | ||
|
||
import me.nathanfallet.ktorx.controllers.IUnitController | ||
import io.ktor.server.application.* | ||
import me.nathanfallet.ktorx.controllers.IModelController | ||
import me.nathanfallet.ktorx.models.annotations.AdminTemplateMapping | ||
import me.nathanfallet.ktorx.models.annotations.Path | ||
import me.nathanfallet.ktorx.models.responses.RedirectResponse | ||
import me.nathanfallet.suitebde.models.associations.Association | ||
import me.nathanfallet.suitebde.models.associations.CreateAssociationPayload | ||
import me.nathanfallet.suitebde.models.associations.UpdateAssociationPayload | ||
|
||
interface IDashboardController : IUnitController { | ||
interface IDashboardController : | ||
IModelController<Association, String, CreateAssociationPayload, UpdateAssociationPayload> { | ||
|
||
@AdminTemplateMapping("admin/dashboard.ftl") | ||
@AdminTemplateMapping("admin/dashboard/dashboard.ftl") | ||
@Path("GET", "/") | ||
suspend fun dashboard() | ||
|
||
@AdminTemplateMapping("admin/dashboard/settings.ftl") | ||
@Path("GET", "/settings") | ||
suspend fun settings(call: ApplicationCall) | ||
|
||
@AdminTemplateMapping("admin/dashboard/settings.ftl") | ||
@Path("GET", "/settings/stripe") | ||
suspend fun settingsStripe(call: ApplicationCall): RedirectResponse | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...ain/kotlin/me/nathanfallet/suitebde/database/associations/StripeAccountsInAssociations.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package me.nathanfallet.suitebde.database.associations | ||
|
||
import me.nathanfallet.suitebde.models.associations.StripeAccountInAssociation | ||
import org.jetbrains.exposed.sql.ResultRow | ||
import org.jetbrains.exposed.sql.Table | ||
|
||
object StripeAccountsInAssociations : Table() { | ||
|
||
val associationId = varchar("association_id", 32).index() | ||
val accountId = varchar("account_id", 255).index() | ||
val chargesEnabled = bool("charges_enabled") | ||
|
||
override val primaryKey = PrimaryKey(associationId, accountId) | ||
|
||
fun toStripeAccountInAssociation( | ||
row: ResultRow, | ||
) = StripeAccountInAssociation( | ||
row[associationId], | ||
row[accountId], | ||
row[chargesEnabled] | ||
) | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...anfallet/suitebde/database/associations/StripeAccountsInAssociationsDatabaseRepository.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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package me.nathanfallet.suitebde.database.associations | ||
|
||
import me.nathanfallet.suitebde.models.associations.CreateStripeAccountInAssociationPayload | ||
import me.nathanfallet.suitebde.models.associations.StripeAccountInAssociation | ||
import me.nathanfallet.suitebde.models.associations.UpdateStripeAccountInAssociationPayload | ||
import me.nathanfallet.suitebde.repositories.associations.IStripeAccountsInAssociationsRepository | ||
import me.nathanfallet.surexposed.database.IDatabase | ||
import me.nathanfallet.usecases.context.IContext | ||
import org.jetbrains.exposed.sql.* | ||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq | ||
|
||
class StripeAccountsInAssociationsDatabaseRepository( | ||
private val database: IDatabase, | ||
) : IStripeAccountsInAssociationsRepository { | ||
|
||
init { | ||
database.transaction { | ||
SchemaUtils.create(StripeAccountsInAssociations) | ||
} | ||
} | ||
|
||
override suspend fun list(parentId: String, context: IContext?): List<StripeAccountInAssociation> = | ||
database.suspendedTransaction { | ||
StripeAccountsInAssociations | ||
.selectAll() | ||
.where { StripeAccountsInAssociations.associationId eq parentId } | ||
.map(StripeAccountsInAssociations::toStripeAccountInAssociation) | ||
} | ||
|
||
override suspend fun create( | ||
payload: CreateStripeAccountInAssociationPayload, | ||
parentId: String, | ||
context: IContext?, | ||
): StripeAccountInAssociation? = | ||
database.suspendedTransaction { | ||
StripeAccountsInAssociations.insert { | ||
it[associationId] = parentId | ||
it[accountId] = payload.accountId | ||
it[chargesEnabled] = payload.chargesEnabled | ||
}.resultedValues?.map(StripeAccountsInAssociations::toStripeAccountInAssociation)?.singleOrNull() | ||
} | ||
|
||
override suspend fun get(id: String, parentId: String, context: IContext?): StripeAccountInAssociation? = | ||
database.suspendedTransaction { | ||
StripeAccountsInAssociations | ||
.selectAll() | ||
.where { | ||
StripeAccountsInAssociations.accountId eq id and (StripeAccountsInAssociations.associationId eq parentId) | ||
} | ||
.map(StripeAccountsInAssociations::toStripeAccountInAssociation) | ||
.singleOrNull() | ||
} | ||
|
||
override suspend fun update( | ||
id: String, | ||
payload: UpdateStripeAccountInAssociationPayload, | ||
parentId: String, | ||
context: IContext?, | ||
): Boolean = | ||
database.suspendedTransaction { | ||
StripeAccountsInAssociations.update({ StripeAccountsInAssociations.accountId eq id and (StripeAccountsInAssociations.associationId eq parentId) }) { | ||
it[chargesEnabled] = payload.chargesEnabled | ||
} == 1 | ||
} | ||
|
||
override suspend fun delete(id: String, parentId: String, context: IContext?): Boolean = | ||
database.suspendedTransaction { | ||
StripeAccountsInAssociations.deleteWhere { | ||
StripeAccountsInAssociations.accountId eq id and (StripeAccountsInAssociations.associationId eq parentId) | ||
} == 1 | ||
} | ||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
...athanfallet/suitebde/repositories/associations/IStripeAccountsInAssociationsRepository.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.nathanfallet.suitebde.repositories.associations | ||
|
||
import me.nathanfallet.suitebde.models.associations.CreateStripeAccountInAssociationPayload | ||
import me.nathanfallet.suitebde.models.associations.StripeAccountInAssociation | ||
import me.nathanfallet.suitebde.models.associations.UpdateStripeAccountInAssociationPayload | ||
import me.nathanfallet.usecases.models.repositories.IChildModelSuspendRepository | ||
|
||
interface IStripeAccountsInAssociationsRepository : | ||
IChildModelSuspendRepository<StripeAccountInAssociation, String, CreateStripeAccountInAssociationPayload, UpdateStripeAccountInAssociationPayload, String> |
15 changes: 15 additions & 0 deletions
15
...-backend/src/commonMain/kotlin/me/nathanfallet/suitebde/services/stripe/IStripeService.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package me.nathanfallet.suitebde.services.stripe | ||
|
||
import com.stripe.model.Account | ||
import com.stripe.model.AccountLink | ||
import com.stripe.param.AccountLinkCreateParams | ||
import me.nathanfallet.suitebde.models.associations.Association | ||
|
||
interface IStripeService { | ||
|
||
suspend fun getAccount(accountId: String): Account? | ||
suspend fun createAccount(association: Association): Account | ||
|
||
suspend fun createAccountLink(accountId: String, type: AccountLinkCreateParams.Type, returnUrl: String): AccountLink | ||
|
||
} |
Oops, something went wrong.