Added stripe payment (pricing table)

This commit is contained in:
Adrien Bouvais 2024-05-22 11:05:05 +02:00
parent 3dcf557e49
commit 0cb115e560
7 changed files with 154 additions and 88 deletions

38
Chat.go
View File

@ -214,6 +214,44 @@ func generateWelcomeChatHTML() string {
return htmlString return htmlString
} }
func generatePricingTableChatHTML() string {
stripeTable := `
<stripe-pricing-table pricing-table-id="prctbl_1PJAxDP2nW0okNQyY0Q3mbg4"
publishable-key="pk_live_51OxXuWP2nW0okNQyme1qdwbL535jbMmM1uIUi6U5zcvEUUwKraktmpCzudXNdPSTxlHpw2FbCtxpwbyFFcasQ7aj000tJJGpWW">
</stripe-pricing-table>`
closeBtn := `
<div class="is-flex is-justify-content-flex-end">
<a class="button is-primary is-small" hx-get="/loadChat" hx-target="#chat-container" hx-swap="outerHTML"
hx-trigger="click">
Close
</a>
</div>`
htmlString := "<div class='columns is-centered' id='chat-container'><div class='column is-12-mobile is-8-tablet is-6-desktop' id='chat-messages'>"
NextMessages := []TemplateMessage{}
nextMsg := TemplateMessage{
Icon: "icons/bouvai2.png", // Assuming Icon is a field you want to include from Message
Content: "<br>" + stripeTable + closeBtn,
Hidden: false, // Assuming Hidden is a field you want to include from Message
Id: "0",
Name: "JADE",
}
NextMessages = append(NextMessages, nextMsg)
botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true, "notFlex": true})
if err != nil {
panic(err)
}
htmlString += botOut
htmlString += "<div style='height: 10px;'></div>"
htmlString += "</div></div>"
// Render the HTML template with the messages
return htmlString
}
func generateEnterKeyChatHTML() string { func generateEnterKeyChatHTML() string {
welcomeMessage := `To start using JADE, please enter at least one key in the settings.` welcomeMessage := `To start using JADE, please enter at least one key in the settings.`

7
Stripe.go Normal file
View File

@ -0,0 +1,7 @@
package main
import "github.com/gofiber/fiber/v2"
func PricingTableHandler(c *fiber.Ctx) error {
return c.SendString(generatePricingTableChatHTML())
}

View File

@ -64,6 +64,7 @@ func main() {
// Main routes // Main routes
app.Get("/", ChatPageHandler) app.Get("/", ChatPageHandler)
app.Get("/loadChat", LoadChatHandler) app.Get("/loadChat", LoadChatHandler)
app.Get("/pricingTable", PricingTableHandler)
// Chat routes // Chat routes
app.Post("/deleteMessage", DeleteMessageHandler) app.Post("/deleteMessage", DeleteMessageHandler)

View File

@ -14,6 +14,8 @@
<script src="https://unpkg.com/htmx.org@1.9.11"></script> <script src="https://unpkg.com/htmx.org@1.9.11"></script>
<script src="https://unpkg.com/htmx.org@1.9.12/dist/ext/sse.js"></script> <script src="https://unpkg.com/htmx.org@1.9.12/dist/ext/sse.js"></script>
<script async src="https://js.stripe.com/v3/pricing-table.js"></script>
</head> </head>
<body hx-ext="sse" sse-connect="/sse"> <body hx-ext="sse" sse-connect="/sse">

View File

@ -23,7 +23,7 @@
<div class="column" id="content-column"> <div class="column" id="content-column">
{% if not IsPlaceholder %} {% if not IsPlaceholder %}
<div class="is-flex is-align-items-start"> <div class="{% if not notFlex%} is-flex {% endif %} is-align-items-start">
<div class="message-content" id="content-{{ ConversationAreaId }}"> <div class="message-content" id="content-{{ ConversationAreaId }}">
{% for message in Messages %} {% for message in Messages %}
{% if not message.Hidden %} {% if not message.Hidden %}

View File

@ -17,6 +17,17 @@
<span>{{ LLM.Name }}</span> <span>{{ LLM.Name }}</span>
</div> </div>
{% endfor %} {% endfor %}
<div class="is-flex is-justify-content-flex-end">
<button class="button is-small is-primary is-outlined mr-2">
<span class="icon">
<i class="fa-solid fa-pen"></i>
</span>
</button>
<button class="button is-small is-success is-outlined">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -82,6 +82,13 @@
</form> </form>
<p id="api-keys-status"></p> <p id="api-keys-status"></p>
</div> </div>
<a class="button is-small mt-1" hx-get="/pricingTable" hx-target="#chat-container" hx-swap="outerHTML"
hx-trigger="click">
<span class="icon is-small">
<i class="fa-solid fa-heart"></i>
</span>
<span>Subscribe to JADE</span>
</a>
<a class="button is-small mt-1" href="/signout"> <a class="button is-small mt-1" href="/signout">
<span class="icon is-small"> <span class="icon is-small">
<i class="fa-solid fa-right-from-bracket"></i> <i class="fa-solid fa-right-from-bracket"></i>