more fixes for extra stripe one-time donation
parent
8eb27016ff
commit
9b7661117a
|
@ -120,8 +120,10 @@ object Plan extends LilaController {
|
|||
}
|
||||
|
||||
def thanks = Open { implicit ctx =>
|
||||
ctx.me ?? Env.plan.api.userPatron map { patron =>
|
||||
Ok(html.plan.thanks(patron))
|
||||
ctx.me ?? Env.plan.api.userPatron flatMap { patron =>
|
||||
patron ?? Env.plan.api.patronCustomer map { customer =>
|
||||
Ok(html.plan.thanks(patron, customer))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@(patron: Option[lila.plan.Patron])(implicit ctx: Context)
|
||||
@(patron: Option[lila.plan.Patron], customer: Option[lila.plan.StripeCustomer])(implicit ctx: Context)
|
||||
|
||||
@base.layout(
|
||||
moreCss = cssTag("page.css"),
|
||||
|
@ -26,6 +26,15 @@ title = "Thank you for your support!") {
|
|||
}
|
||||
</p>
|
||||
} else {
|
||||
@if(customer.??(_.renew)) {
|
||||
<p>
|
||||
Note that your <a href="@routes.Plan.index">Patron page</a> only shows
|
||||
invoices for your monthly subscription.
|
||||
</p>
|
||||
<p>
|
||||
But worry not, we received your donation! Thanks again!
|
||||
</p>
|
||||
} else {
|
||||
<p>
|
||||
You are now a lichess Patron for one month!<br />
|
||||
@ctx.me.map { me =>
|
||||
|
@ -42,6 +51,7 @@ title = "Thank you for your support!") {
|
|||
</p>
|
||||
}
|
||||
}
|
||||
}
|
||||
<p>
|
||||
Success! <a href="@routes.Lobby.home">Return to lichess homepage</a>.
|
||||
</p>
|
||||
|
|
|
@ -293,7 +293,7 @@ final class PlanApi(
|
|||
// user has a monthly going on and is making an extra one-time
|
||||
// let's not change the user plan to one-time, or else
|
||||
// it would only cancel the monthly
|
||||
if (customer.renew && !data.freq.renew) stripeClient.addOneTime(user, customer, data)
|
||||
if (customer.renew && !data.freq.renew) stripeClient.addOneTime(customer, data.amount)
|
||||
// or else, set this new plan to the customer
|
||||
else setCustomerPlan(customer, plan, data.source) flatMap { sub =>
|
||||
saveStripePatron(user, customer.id, data.freq) inject sub
|
||||
|
@ -348,6 +348,9 @@ final class PlanApi(
|
|||
_ ?? stripeClient.getCustomer
|
||||
}
|
||||
|
||||
def patronCustomer(patron: Patron): Fu[Option[StripeCustomer]] =
|
||||
patron.stripe.map(_.customerId) ?? stripeClient.getCustomer
|
||||
|
||||
private def customerIdPatron(id: CustomerId): Fu[Option[Patron]] =
|
||||
patronColl.uno[Patron]($doc("stripe.customerId" -> id))
|
||||
|
||||
|
|
|
@ -79,14 +79,13 @@ private final class StripeClient(config: StripeClient.Config) {
|
|||
// 'receipt_email -> data.email).void
|
||||
|
||||
// charge without changing the customer plan
|
||||
def addOneTime(user: User, customer: StripeCustomer, data: Checkout): Funit =
|
||||
postOne[StripePlan]("charges",
|
||||
def addOneTime(customer: StripeCustomer, amount: Cents): Funit =
|
||||
postOne[StripeCharge]("charges",
|
||||
'customer -> customer.id.value,
|
||||
'amount -> data.amount.value,
|
||||
'amount -> amount.value,
|
||||
'currency -> "usd",
|
||||
'source -> data.token.value,
|
||||
'description -> "Monthly customer adds a one-time",
|
||||
'receipt_email -> data.email).void
|
||||
'receipt_email -> customer.email).void
|
||||
|
||||
private def getOne[A: Reads](url: String, queryString: (Symbol, Any)*): Fu[Option[A]] =
|
||||
get[A](url, queryString) map Some.apply recover {
|
||||
|
|
Loading…
Reference in New Issue