Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Commit

Permalink
Merge pull request #58 from nathanfallet/feature/stripe-payment
Browse files Browse the repository at this point in the history
feat: stripe payments
  • Loading branch information
nathanfallet authored Feb 24, 2024
2 parents c0505c0 + 9337c91 commit 1eb0a47
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ fun Application.configureKoin() {
get(named<StripeAccountInAssociation>())
)
}
single<ICreateCheckoutSessionUseCase> {
CreateCheckoutSessionUseCase(
get(),
get(named<StripeAccountInAssociation>())
)
}

// Auth
single<IHashPasswordUseCase> { HashPasswordUseCase() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.nathanfallet.suitebde.services.stripe

import com.stripe.model.Account
import com.stripe.model.AccountLink
import com.stripe.model.checkout.Session
import com.stripe.param.AccountLinkCreateParams
import me.nathanfallet.suitebde.models.associations.Association

Expand All @@ -12,4 +13,6 @@ interface IStripeService {

suspend fun createAccountLink(accountId: String, type: AccountLinkCreateParams.Type, returnUrl: String): AccountLink

suspend fun createCheckoutSession(accountId: String, name: String, amount: Long, returnUrl: String): Session

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package me.nathanfallet.suitebde.services.stripe
import com.stripe.Stripe
import com.stripe.model.Account
import com.stripe.model.AccountLink
import com.stripe.model.checkout.Session
import com.stripe.net.RequestOptions
import com.stripe.param.AccountCreateParams
import com.stripe.param.AccountLinkCreateParams
import com.stripe.param.checkout.SessionCreateParams
import me.nathanfallet.suitebde.models.associations.Association

class StripeService(
Expand All @@ -29,6 +32,20 @@ class StripeService(
.setName(association.name)
.build()
)
.setCapabilities(
AccountCreateParams.Capabilities.builder()
.setCardPayments(
AccountCreateParams.Capabilities.CardPayments.builder()
.setRequested(true)
.build()
)
.setTransfers(
AccountCreateParams.Capabilities.Transfers.builder()
.setRequested(true)
.build()
)
.build()
)
.build()
)

Expand All @@ -46,4 +63,41 @@ class StripeService(
.build()
)

override suspend fun createCheckoutSession(
accountId: String,
name: String,
amount: Long,
returnUrl: String,
): Session =
Session.create(
SessionCreateParams.builder()
.addLineItem(
SessionCreateParams.LineItem.builder()
.setPriceData(
SessionCreateParams.LineItem.PriceData.builder()
.setCurrency("eur")
.setProductData(
SessionCreateParams.LineItem.PriceData.ProductData.builder()
.setName(name)
.build()
)
.setUnitAmount(amount)
.build()
)
.setQuantity(1)
.build()
)
.setPaymentIntentData(
SessionCreateParams.PaymentIntentData.builder()
.setApplicationFeeAmount((amount * 0.05).toLong())
.build()
)
.setMode(SessionCreateParams.Mode.PAYMENT)
.setSuccessUrl(returnUrl)
.build(),
RequestOptions.builder()
.setStripeAccount(accountId)
.build()
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.nathanfallet.suitebde.usecases.associations

import com.stripe.model.checkout.Session
import me.nathanfallet.suitebde.models.associations.Association
import me.nathanfallet.suitebde.models.associations.StripeAccountInAssociation
import me.nathanfallet.suitebde.services.stripe.IStripeService
import me.nathanfallet.usecases.models.list.IListChildModelSuspendUseCase

class CreateCheckoutSessionUseCase(
private val stripeService: IStripeService,
private val listStripeAccountsInAssociationsUseCase: IListChildModelSuspendUseCase<StripeAccountInAssociation, String>,
) : ICreateCheckoutSessionUseCase {

override suspend fun invoke(input1: Association, input2: String, input3: Long, input4: String): Session? {
val account = listStripeAccountsInAssociationsUseCase(input1.id).firstOrNull { it.chargesEnabled }
?: return null
return stripeService.createCheckoutSession(
account.accountId,
input2,
input3,
input4
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.nathanfallet.suitebde.usecases.associations

import com.stripe.model.checkout.Session
import me.nathanfallet.suitebde.models.associations.Association
import me.nathanfallet.usecases.base.IQuadSuspendUseCase

interface ICreateCheckoutSessionUseCase : IQuadSuspendUseCase<Association, String, Long, String, Session?>

0 comments on commit 1eb0a47

Please sign in to comment.