Skip to content

Commit

Permalink
[fix] #144
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Aug 15, 2022
1 parent 64216e6 commit a9555d7
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 226 deletions.
7 changes: 0 additions & 7 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ func AdminRestAPI() {
//
v1.POST("/group/:id/payment/subscribe", payment.PostAdminSubscribeGettingURL)
v1.GET("/group/:id/payment", payment.GetAdminBillingPortalURL)
// Delete
v1.DELETE("/payment/:id", payment.DeleteByAdmin)
v1.POST("/payment/:id/refund", payment.RefundByAdmin)
// Update
//v1.PUT("/service/:id", service.UpdateByAdmin)
v1.GET("/payment", payment.GetAllByAdmin)
//v1.GET("/service/:id", service.GetByAdmin)

//
// JPNIC ByAdmin
Expand Down
86 changes: 0 additions & 86 deletions pkg/api/core/payment/v0/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import (
auth "github.com/homenoc/dsbd-backend/pkg/api/core/auth/v0"
"github.com/homenoc/dsbd-backend/pkg/api/core/common"
"github.com/homenoc/dsbd-backend/pkg/api/core/group"
"github.com/homenoc/dsbd-backend/pkg/api/core/notice"
"github.com/homenoc/dsbd-backend/pkg/api/core/payment"
"github.com/homenoc/dsbd-backend/pkg/api/core/tool/config"
dbGroup "github.com/homenoc/dsbd-backend/pkg/api/store/group/v0"
dbPayment "github.com/homenoc/dsbd-backend/pkg/api/store/payment/v0"
"github.com/stripe/stripe-go/v73"
billingSession "github.com/stripe/stripe-go/v73/billingportal/session"
"github.com/stripe/stripe-go/v73/checkout/session"
"github.com/stripe/stripe-go/v73/customer"
"github.com/stripe/stripe-go/v73/refund"
"gorm.io/gorm"
"log"
"net/http"
Expand Down Expand Up @@ -166,86 +163,3 @@ func GetAdminBillingPortalURL(c *gin.Context) {

c.JSON(http.StatusOK, map[string]string{"url": s.URL})
}

func DeleteByAdmin(c *gin.Context) {
resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN"))
if resultAdmin.Err != nil {
c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()})
return
}

id, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()})
return
}

if err = dbPayment.Delete(&core.Payment{Model: gorm.Model{ID: uint(id)}}); err != nil {
c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()})
return
}
c.JSON(http.StatusOK, notice.Result{})
}

func GetByAdmin(c *gin.Context) {
resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN"))
if resultAdmin.Err != nil {
c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()})
return
}
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()})
return
}

result, err := dbPayment.Get(payment.ID, core.Payment{Model: gorm.Model{ID: uint(id)}})
if err != nil {
c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()})
return
}
c.JSON(http.StatusOK, payment.ResultByAdmin{Payment: result})
}

func GetAllByAdmin(c *gin.Context) {
resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN"))
if resultAdmin.Err != nil {
c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()})
return
}

if result, err := dbPayment.GetAll(); err != nil {
c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()})
} else {
c.JSON(http.StatusOK, payment.ResultByAdmin{Payment: result})
}
}

func RefundByAdmin(c *gin.Context) {
resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN"))
if resultAdmin.Err != nil {
c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()})
return
}

id, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()})
return
}

result, err := dbPayment.Get(payment.ID, core.Payment{Model: gorm.Model{ID: uint(id)}})
if err != nil {
c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()})
return
}

_, err = refund.New(&stripe.RefundParams{
PaymentIntent: stripe.String(result[0].PaymentIntentID),
})
if err != nil {
c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()})
return
}
c.JSON(http.StatusOK, common.Result{})
}
16 changes: 0 additions & 16 deletions pkg/api/core/payment/v0/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/homenoc/dsbd-backend/pkg/api/core/group"
"github.com/homenoc/dsbd-backend/pkg/api/core/tool/config"
dbGroup "github.com/homenoc/dsbd-backend/pkg/api/store/group/v0"
dbPayment "github.com/homenoc/dsbd-backend/pkg/api/store/payment/v0"
"github.com/stripe/stripe-go/v73"
"github.com/stripe/stripe-go/v73/webhook"
"gorm.io/gorm"
Expand Down Expand Up @@ -62,28 +61,13 @@ func GetStripeWebHook(c *gin.Context) {
name := event.Data.Object["metadata"].(map[string]interface{})["name"].(string)
groupIDStr := event.Data.Object["metadata"].(map[string]interface{})["group_id"].(string)
etc := "GroupID: " + groupIDStr + ", UserName: " + name
groupID, _ := strconv.Atoi(groupIDStr)

// stripe standard data
amountTotal := event.Data.Object["amount_total"].(float64)
paymentIntent := event.Data.Object["payment_intent"].(string)
if dataType == "donate" {
dbPayment.Create(&core.Payment{
Type: core.PaymentDonate,
GroupID: nil,
Refund: &[]bool{false}[0],
PaymentIntentID: paymentIntent,
Fee: uint(amountTotal),
})
etc += "UserName: " + name
} else if dataType == "membership" {
dbPayment.Create(&core.Payment{
Type: core.PaymentMembership,
GroupID: &[]uint{uint(groupID)}[0],
Refund: &[]bool{false}[0],
PaymentIntentID: paymentIntent,
Fee: uint(amountTotal),
})
etc += "GroupID: " + groupIDStr
break
}
Expand Down
117 changes: 0 additions & 117 deletions pkg/api/store/payment/v0/payment.go

This file was deleted.

0 comments on commit a9555d7

Please sign in to comment.