feat: notify supplier and client after payment is done
This commit is contained in:
@@ -25,10 +25,11 @@ func NewOrderHandler(walletAddress string, orderSrv *services.Order, conversor *
|
||||
}
|
||||
|
||||
type orderReq struct {
|
||||
OrderID string `json:"order_id"`
|
||||
ClientID string `json:"client_id"`
|
||||
Amount float64 `json:"amount"`
|
||||
Currency domain.FiatCurrency `json:"currency"`
|
||||
OrderID string `json:"order_id"`
|
||||
ClientID string `json:"client_id"`
|
||||
Amount float64 `json:"amount"`
|
||||
Currency domain.FiatCurrency `json:"currency"`
|
||||
ClientEmail string `json:"client_email"`
|
||||
}
|
||||
|
||||
func (hdl *OrderHandler) Post(c *fiber.Ctx) error {
|
||||
@@ -42,7 +43,7 @@ func (hdl *OrderHandler) Post(c *fiber.Ctx) error {
|
||||
return RenderError(c, fmt.Errorf("hdl.conversor.UsdToBtc %w", err), "")
|
||||
}
|
||||
|
||||
order, err := hdl.orderSrv.NewOrder(c.Context(), req.OrderID, req.ClientID, btcAmount)
|
||||
order, err := hdl.orderSrv.NewOrder(c.Context(), req.OrderID, req.ClientID, req.ClientEmail, btcAmount)
|
||||
if err != nil {
|
||||
return RenderError(c, fmt.Errorf("hdl.orderSrv.NewOrder %w", err), "")
|
||||
}
|
||||
|
||||
@@ -102,18 +102,22 @@ func (s *RestServer) onNotification(ctx context.Context, notifChan chan domain.N
|
||||
|
||||
order.Block = notif.BlockHash
|
||||
order.Tx = notif.Tx
|
||||
|
||||
if err := s.orderSrv.OrderCompleted(ctx, order); err != nil {
|
||||
order, err = s.orderSrv.OrderCompleted(ctx, order)
|
||||
if err != nil {
|
||||
log.Println("OrderCompleted:", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Send email to client and provider
|
||||
if err := s.mailSrv.SendProviderConfirm(mail.SendOK{
|
||||
TxID: order.Tx,
|
||||
BlockHash: order.Block,
|
||||
DocHash: "",
|
||||
To: "doc.Email",
|
||||
Tx: order.Tx,
|
||||
Block: order.Block,
|
||||
Amount: order.Amount,
|
||||
ExplorerUrl: s.btcService.Explorer(order.Tx),
|
||||
CustomerID: order.ClientID,
|
||||
OrderID: order.OrderID,
|
||||
Timestamp: order.PaidAt,
|
||||
To: order.Email,
|
||||
}); err != nil {
|
||||
log.Println("error while send confirm email:", err)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user