Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
elhmn committed May 23, 2023
1 parent 2ef29b0 commit 9e2e545
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
63 changes: 62 additions & 1 deletion backend/internal/handlers/opencollective_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type WebhookPayload struct {
Group string `json:"group"`
Amount int `json:"amount"`
IsDebt bool `json:"isDebt"`
OrderID int `json:"OrderId"`
OrderID int64 `json:"OrderId"`
Currency string `json:"currency"`
IsRefund bool `json:"isRefund"`
ExpenseID interface{} `json:"ExpenseId"`
Expand Down Expand Up @@ -79,6 +79,49 @@ func OpenCollectiveWebhook(c *gin.Context) {
return
}

paymentClient, err := server.GetDefaultPaymentClient()
if err != nil {
log.Error(err)
c.JSON(http.StatusInternalServerError,
gin.H{"error": "could not create payment client"})
return
}
fmt.Printf("payload.Data.Transation.OrderID: %+v\n", payload.Data.Transaction.OrderID) // Debug
response, err := paymentClient.GetOrder(payload.Data.Transaction.OrderID)
if err != nil {
log.Error(err)
c.JSON(http.StatusInternalServerError,
gin.H{"error": "could not create payment client"})
return
}

fmt.Printf("Order.Tier.legacyID: %d\n", response.Order.Tier.LegacyID) // Debug

db, err := server.GetDefaultDBClient()
if err != nil {
log.Error(err)
c.JSON(http.StatusInternalServerError,
gin.H{"error": "failed to get db client"})
return
}

tierID := response.Order.Tier.LegacyID
paymentRecord, err := db.GetPaymentRecordByID(tierID)
if err != nil {
log.Error(err)
c.JSON(http.StatusInternalServerError,
gin.H{"error": "failed to get payment record"})
return
}
fmt.Printf("paymentRecord: %+v\n", paymentRecord) // Debug

if err := paymentClient.DeleteTier(tierID); err != nil {
log.Error(err)
c.JSON(http.StatusInternalServerError,
gin.H{"error": "failed to delete tier"})
return
}

log.Info("OpenCollectiveWebhook was triggered!")
}

Expand Down Expand Up @@ -108,6 +151,24 @@ func GetOrderID(c *gin.Context) {
return
}

db, err := server.GetDefaultDBClient()
if err != nil {
log.Error(err)
c.JSON(http.StatusInternalServerError,
gin.H{"error": "failed to get db client"})
return
}

tierID := response.Order.Tier.LegacyID
paymentRecord, err := db.GetPaymentRecordByID(tierID)
if err != nil {
log.Error(err)
c.JSON(http.StatusInternalServerError,
gin.H{"error": "failed to get payment record"})
return
}
fmt.Printf("paymentRecord: %+v\n", paymentRecord)

fmt.Printf("legacyID: %d\n", response.Order.Tier.LegacyID)
log.Info("GetOrders was triggered!")
}
2 changes: 1 addition & 1 deletion backend/internal/payment/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ type GetOrderResponse struct {
LegacyID int `json:"legacyId"`
Tier struct {
ID string `json:"id"`
LegacyID int `json:"legacyId"`
LegacyID int64 `json:"legacyId"`
Slug string `json:"slug"`
Name string `json:"name"`
Description string `json:"description"`
Expand Down
11 changes: 11 additions & 0 deletions backend/internal/storage/payment_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@ import "github.com/osscameroon/jobsika/pkg/models/v1beta"
func (db *DB) CreatePaymentRecord(record *v1beta.PaymentRecord) error {
return db.c.Create(record).Error
}

// GetPaymentRecordByID get salary by `id`
func (db DB) GetPaymentRecordByID(id int64) (v1beta.PaymentRecord, error) {
paymentRecord := v1beta.PaymentRecord{}
ret := db.c.First(&paymentRecord, "legacy_id = ?", id)
if ret.Error != nil {
return paymentRecord, ret.Error
}

return paymentRecord, nil
}

0 comments on commit 9e2e545

Please sign in to comment.