Skip to content

Commit

Permalink
add notification email payment
Browse files Browse the repository at this point in the history
  • Loading branch information
masnann committed Dec 25, 2023
1 parent f7eb786 commit 4f6e67d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 38 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require (
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/longrunning v0.5.4 // indirect
cloud.google.com/go/storage v1.35.1 // indirect
github.com/bxcodec/faker/v3 v3.8.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/creasty/defaults v1.5.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bxcodec/faker/v3 v3.8.1 h1:qO/Xq19V6uHt2xujwpaetgKhraGCapqY2CRWGD/SqcM=
github.com/bxcodec/faker/v3 v3.8.1/go.mod h1:DdSDccxF5msjFo5aO4vrobRQ8nIApg8kq3QWPEQD6+o=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down
4 changes: 2 additions & 2 deletions module/feature/order/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type RepositoryOrderInterface interface {
GetOrderById(orderID string) (*entities.OrderModels, error)
CreateOrder(newOrder *entities.OrderModels) (*entities.OrderModels, error)
ConfirmPayment(orderID string, orderStatus, paymentStatus string) error
ProcessGatewayPayment(totalAmountPaid uint64, orderID string, paymentMethod string) (interface{}, error)
ProcessGatewayPayment(totalAmountPaid uint64, orderID string, paymentMethod, name, email string) (interface{}, error)
CheckTransaction(orderID string) (dto.Status, error)
UpdateOrderStatus(req *dto.UpdateOrderStatus) error
GetAllOrdersByUserID(userID uint64) ([]*entities.OrderModels, error)
Expand Down Expand Up @@ -72,7 +72,7 @@ type ServiceOrderInterface interface {
GetOrderByDateRangeAndPaymentStatus(filterType, status string, page, perPage int) ([]*entities.OrderModels, int64, error)
GetOrderByPaymentStatus(orderStatus string, page, perPage int) ([]*entities.OrderModels, int64, error)
ProcessManualPayment(orderID string) (*entities.OrderModels, error)
ProcessGatewayPayment(totalAmountPaid uint64, orderID string, paymentMethod string) (interface{}, error)
ProcessGatewayPayment(totalAmountPaid uint64, orderID string, paymentMethod, name, email string) (interface{}, error)
SendNotificationOrder(request dto.SendNotificationOrderRequest) (string, error)
SendNotificationPayment(request dto.SendNotificationPaymentRequest) (string, error)
}
Expand Down
4 changes: 2 additions & 2 deletions module/feature/order/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (r *OrderRepository) ConfirmPayment(orderID, orderStatus, paymentStatus str
return nil
}

func (r *OrderRepository) ProcessGatewayPayment(totalAmountPaid uint64, orderID string, paymentMethod string) (interface{}, error) {
func (r *OrderRepository) ProcessGatewayPayment(totalAmountPaid uint64, orderID string, paymentMethod, name, email string) (interface{}, error) {
var paymentType coreapi.CoreapiPaymentType

switch paymentMethod {
Expand All @@ -138,7 +138,7 @@ func (r *OrderRepository) ProcessGatewayPayment(totalAmountPaid uint64, orderID
}

coreClient := r.coreClient
resp, err := payment.CreateCoreAPIPaymentRequest(coreClient, orderID, int64(totalAmountPaid), paymentType)
resp, err := payment.CreateCoreAPIPaymentRequest(coreClient, orderID, int64(totalAmountPaid), paymentType, name, email)
if err != nil {
logrus.Error(err)
return nil, errors.New("gagal membuat permintaan pembayaran")
Expand Down
8 changes: 4 additions & 4 deletions module/feature/order/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (s *OrderService) CreateOrder(userID uint64, request *dto.CreateOrderReques
case "whatsapp", "telegram":
return s.ProcessManualPayment(orderID)
case "qris", "bank_transfer", "gopay", "shopepay":
return s.ProcessGatewayPayment(totalAmountPaid, createdOrder.ID, request.PaymentMethod)
return s.ProcessGatewayPayment(totalAmountPaid, createdOrder.ID, request.PaymentMethod, user.Name, user.Email)
default:
return nil, errors.New("jenis pembayaran tidak valid")
}
Expand Down Expand Up @@ -421,7 +421,7 @@ func (s *OrderService) CreateOrderFromCart(userID uint64, request *dto.CreateOrd
case "whatsapp", "telegram":
return s.ProcessManualPayment(orderID)
case "qris", "bank_transfer", "gopay", "shopepay":
return s.ProcessGatewayPayment(totalAmountPaid, createdOrder.ID, request.PaymentMethod)
return s.ProcessGatewayPayment(totalAmountPaid, createdOrder.ID, request.PaymentMethod, user.Name, user.Email)
default:
return nil, errors.New("jenis pembayaran tidak valid")
}
Expand All @@ -435,8 +435,8 @@ func (s *OrderService) ProcessManualPayment(orderID string) (*entities.OrderMode
return result, nil
}

func (s *OrderService) ProcessGatewayPayment(totalAmountPaid uint64, orderID string, paymentMethod string) (interface{}, error) {
result, err := s.repo.ProcessGatewayPayment(totalAmountPaid, orderID, paymentMethod)
func (s *OrderService) ProcessGatewayPayment(totalAmountPaid uint64, orderID string, paymentMethod, name, email string) (interface{}, error) {
result, err := s.repo.ProcessGatewayPayment(totalAmountPaid, orderID, paymentMethod, name, email)
if err != nil {
return nil, err
}
Expand Down
36 changes: 9 additions & 27 deletions utils/payment/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,35 @@ import (
"github.com/midtrans/midtrans-go/coreapi"
)

func CreateCoreAPIPaymentRequest(coreClient coreapi.Client, orderID string, totalAmountPaid int64, paymentType coreapi.CoreapiPaymentType) (*coreapi.ChargeResponse, error) {
func CreateCoreAPIPaymentRequest(coreClient coreapi.Client, orderID string, totalAmountPaid int64, paymentType coreapi.CoreapiPaymentType, name string, email string) (*coreapi.ChargeResponse, error) {
var paymentRequest *coreapi.ChargeReq

switch paymentType {
case coreapi.PaymentTypeQris:
case coreapi.PaymentTypeQris, coreapi.PaymentTypeBankTransfer, coreapi.PaymentTypeGopay, coreapi.PaymentTypeShopeepay:
paymentRequest = &coreapi.ChargeReq{
PaymentType: paymentType,
TransactionDetails: midtrans.TransactionDetails{
OrderID: orderID,
GrossAmt: totalAmountPaid,
},
}
case coreapi.PaymentTypeBankTransfer:
paymentRequest = &coreapi.ChargeReq{
PaymentType: paymentType,
TransactionDetails: midtrans.TransactionDetails{
OrderID: orderID,
GrossAmt: totalAmountPaid,
},
}
case coreapi.PaymentTypeGopay:
paymentRequest = &coreapi.ChargeReq{
PaymentType: paymentType,
TransactionDetails: midtrans.TransactionDetails{
OrderID: orderID,
GrossAmt: totalAmountPaid,
},
}
case coreapi.PaymentTypeShopeepay:
paymentRequest = &coreapi.ChargeReq{
PaymentType: paymentType,
TransactionDetails: midtrans.TransactionDetails{
OrderID: orderID,
GrossAmt: totalAmountPaid,
},
}

default:
return nil, errors.New("Jenis pembayaran tidak valid")
}

paymentRequest.CustomerDetails = &midtrans.CustomerDetails{
FName: name,
Email: email,
}

resp, err := coreClient.ChargeTransaction(paymentRequest)
if err != nil {
fmt.Println("Error creating payment request:", err.GetMessage())
return nil, err
}

fmt.Println("Menyimpan data pembayaran: OrderID=", orderID, " Name=", name, " Email=", email)
fmt.Println("Payment request created successfully:", resp)

return resp, nil
}

0 comments on commit 4f6e67d

Please sign in to comment.