diff --git a/go.mod b/go.mod index 10fd2a9..cee8183 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 7c87294..adf8d2d 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/module/feature/order/interface.go b/module/feature/order/interface.go index c4bd3c9..01158b6 100644 --- a/module/feature/order/interface.go +++ b/module/feature/order/interface.go @@ -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) @@ -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) } diff --git a/module/feature/order/repository/repository.go b/module/feature/order/repository/repository.go index 9ad4a95..4b51f15 100644 --- a/module/feature/order/repository/repository.go +++ b/module/feature/order/repository/repository.go @@ -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 { @@ -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") diff --git a/module/feature/order/service/service.go b/module/feature/order/service/service.go index cb87d11..5040fec 100644 --- a/module/feature/order/service/service.go +++ b/module/feature/order/service/service.go @@ -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") } @@ -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") } @@ -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 } diff --git a/utils/payment/request.go b/utils/payment/request.go index d1ce2ca..9833f01 100644 --- a/utils/payment/request.go +++ b/utils/payment/request.go @@ -7,11 +7,11 @@ 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{ @@ -19,41 +19,23 @@ func CreateCoreAPIPaymentRequest(coreClient coreapi.Client, orderID string, tota 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 }