Implemented charge up
This commit is contained in:
parent
41155c8bff
commit
71303ef351
2
main.go
2
main.go
@ -159,7 +159,7 @@ func configure(app *aero.Application) *aero.Application {
|
|||||||
// PayPal
|
// PayPal
|
||||||
app.Ajax("/paypal/success", paypal.Success)
|
app.Ajax("/paypal/success", paypal.Success)
|
||||||
app.Ajax("/paypal/cancel", paypal.Cancel)
|
app.Ajax("/paypal/cancel", paypal.Cancel)
|
||||||
app.Get("/api/paypal/payment/create", paypal.CreatePayment)
|
app.Post("/api/paypal/payment/create", paypal.CreatePayment)
|
||||||
|
|
||||||
// Assets
|
// Assets
|
||||||
configureAssets(app)
|
configureAssets(app)
|
||||||
|
@ -101,6 +101,12 @@
|
|||||||
opacity 0.7
|
opacity 0.7
|
||||||
margin-top 0.5rem
|
margin-top 0.5rem
|
||||||
|
|
||||||
|
&.mountable
|
||||||
|
opacity 0 !important
|
||||||
|
|
||||||
|
&.mounted
|
||||||
|
opacity 0.7 !important
|
||||||
|
|
||||||
.relations
|
.relations
|
||||||
horizontal-wrap
|
horizontal-wrap
|
||||||
|
|
||||||
|
@ -1,3 +1,29 @@
|
|||||||
component Charge(user *arn.User)
|
component Charge(user *arn.User)
|
||||||
ShopTabs(user)
|
ShopTabs(user)
|
||||||
p Coming soon.
|
|
||||||
|
h1.mountable Charge up
|
||||||
|
|
||||||
|
p.text-center.mountable You can charge up your balance via PayPal. 1 USD equals 100 gems.
|
||||||
|
|
||||||
|
.buttons
|
||||||
|
button.action.mountable(data-trigger="click", data-action="chargeUp", data-amount=1000)
|
||||||
|
Icon("diamond")
|
||||||
|
span 1000
|
||||||
|
|
||||||
|
button.action.mountable(data-trigger="click", data-action="chargeUp", data-amount=2000)
|
||||||
|
Icon("diamond")
|
||||||
|
span 2000
|
||||||
|
|
||||||
|
button.action.mountable(data-trigger="click", data-action="chargeUp", data-amount=3000)
|
||||||
|
Icon("diamond")
|
||||||
|
span 3000
|
||||||
|
|
||||||
|
button.action.mountable(data-trigger="click", data-action="chargeUp", data-amount=6000)
|
||||||
|
Icon("diamond")
|
||||||
|
span 6000
|
||||||
|
|
||||||
|
button.action.mountable(data-trigger="click", data-action="chargeUp", data-amount=12000)
|
||||||
|
Icon("diamond")
|
||||||
|
span 12000
|
||||||
|
|
||||||
|
.footer.text-center.mountable You need to enable popup windows in your browser.
|
@ -17,12 +17,24 @@ func CreatePayment(ctx *aero.Context) string {
|
|||||||
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
|
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amount := string(ctx.RequestBody())
|
||||||
|
|
||||||
|
// Verify amount
|
||||||
|
switch amount {
|
||||||
|
case "1000", "2000", "3000", "6000", "12000":
|
||||||
|
// OK
|
||||||
|
default:
|
||||||
|
return ctx.Error(http.StatusBadRequest, "Incorrect amount", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initiate PayPal client
|
||||||
c, err := arn.PayPal()
|
c, err := arn.PayPal()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.Error(http.StatusInternalServerError, "Could not initiate PayPal client", err)
|
return ctx.Error(http.StatusInternalServerError, "Could not initiate PayPal client", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get access token
|
||||||
_, err = c.GetAccessToken()
|
_, err = c.GetAccessToken()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -55,6 +67,9 @@ func CreatePayment(ctx *aero.Context) string {
|
|||||||
// return ctx.Error(http.StatusInternalServerError, "Could not create PayPal web profile", err)
|
// return ctx.Error(http.StatusInternalServerError, "Could not create PayPal web profile", err)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
total := amount[:len(amount)-2] + "." + amount[len(amount)-2:]
|
||||||
|
|
||||||
|
// Create payment
|
||||||
p := paypalsdk.Payment{
|
p := paypalsdk.Payment{
|
||||||
Intent: "sale",
|
Intent: "sale",
|
||||||
Payer: &paypalsdk.Payer{
|
Payer: &paypalsdk.Payer{
|
||||||
@ -63,7 +78,7 @@ func CreatePayment(ctx *aero.Context) string {
|
|||||||
Transactions: []paypalsdk.Transaction{paypalsdk.Transaction{
|
Transactions: []paypalsdk.Transaction{paypalsdk.Transaction{
|
||||||
Amount: &paypalsdk.Amount{
|
Amount: &paypalsdk.Amount{
|
||||||
Currency: "USD",
|
Currency: "USD",
|
||||||
Total: "10.00",
|
Total: total,
|
||||||
},
|
},
|
||||||
Description: "Top Up Balance",
|
Description: "Top Up Balance",
|
||||||
}},
|
}},
|
||||||
|
@ -302,24 +302,39 @@ export function removeAnimeFromCollection(arn: AnimeNotifier, button: HTMLElemen
|
|||||||
.then(() => arn.loading(false))
|
.then(() => arn.loading(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use item
|
// Charge up
|
||||||
// export function useItem(arn: AnimeNotifier, button: HTMLElement) {
|
export function chargeUp(arn: AnimeNotifier, button: HTMLElement) {
|
||||||
// let slotIndex = ""
|
let amount = button.dataset.amount
|
||||||
// let parent = button
|
|
||||||
|
|
||||||
// while(parent = parent.parentElement) {
|
arn.loading(true)
|
||||||
// if(parent.dataset.index !== undefined) {
|
arn.statusMessage.showInfo("Creating PayPal transaction... This might take a few seconds.")
|
||||||
// slotIndex = parent.dataset.index
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let apiEndpoint = arn.findAPIEndpoint(button)
|
fetch("/api/paypal/payment/create", {
|
||||||
|
method: "POST",
|
||||||
|
body: amount,
|
||||||
|
credentials: "same-origin"
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(payment => {
|
||||||
|
if(!payment || !payment.links) {
|
||||||
|
throw "Error creating PayPal payment"
|
||||||
|
}
|
||||||
|
|
||||||
// arn.post(apiEndpoint + "/use/" + slotIndex, "")
|
console.log(payment)
|
||||||
// .then(() => arn.reloadContent())
|
let link = payment.links.find(link => link.rel === "approval_url")
|
||||||
// .catch(err => arn.statusMessage.showError(err))
|
|
||||||
// }
|
if(!link) {
|
||||||
|
throw "Error finding PayPal payment link"
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = link.href
|
||||||
|
console.log(url)
|
||||||
|
|
||||||
|
window.open(url, "_blank")
|
||||||
|
})
|
||||||
|
.catch(err => arn.statusMessage.showError(err))
|
||||||
|
.then(() => arn.loading(false))
|
||||||
|
}
|
||||||
|
|
||||||
// Chrome extension installation
|
// Chrome extension installation
|
||||||
export function installExtension(arn: AnimeNotifier, button: HTMLElement) {
|
export function installExtension(arn: AnimeNotifier, button: HTMLElement) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user