This commit is contained in:
aditya.siregar
2024-10-27 19:48:10 +07:00
parent 758df918ae
commit 081a1aa27b
13 changed files with 190 additions and 35 deletions
+44
View File
@@ -227,3 +227,47 @@ func cleanString(s string) string {
reg := regexp.MustCompile("[^a-zA-Z0-9]+")
return strings.ToLower(reg.ReplaceAllString(s, ""))
}
func (s *LinkQuService) CheckPaymentStatus(partnerReff string) (*entity.LinkQuCheckStatusResponse, error) {
path := "/transaction/payment/checkstatus"
method := "GET"
url := fmt.Sprintf("%s%s%s?username=%s&partnerreff=%s",
s.config.LinkQuBaseURL(), "/linkqu-partner", path, s.config.LinkQuUsername(), partnerReff)
httpReq, err := http.NewRequest(method, url, nil)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("client-id", s.config.LinkQuClientID())
httpReq.Header.Set("client-secret", s.config.LinkQuClientSecret())
resp, err := s.client.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("failed to send request: %w", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d, body: %s", resp.StatusCode, string(body))
}
// Parse response
var checkStatusResp entity.LinkQuCheckStatusResponse
if err := json.Unmarshal(body, &checkStatusResp); err != nil {
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
}
if checkStatusResp.ResponseCode != "00" {
return nil, fmt.Errorf("error when checking payment status, status code %s", checkStatusResp.ResponseCode)
}
return &checkStatusResp, nil
}
+5 -1
View File
@@ -6,6 +6,7 @@ import (
"furtuna-be/internal/common/mycontext"
"furtuna-be/internal/repository/brevo"
"furtuna-be/internal/repository/license"
"furtuna-be/internal/repository/linkqu"
mdtrns "furtuna-be/internal/repository/midtrans"
"furtuna-be/internal/repository/orders"
"furtuna-be/internal/repository/oss"
@@ -49,6 +50,7 @@ type RepoManagerImpl struct {
License License
Transaction TransactionRepository
PG PaymentGateway
LinkQu LinkQu
}
func NewRepoManagerImpl(db *gorm.DB, cfg *config.Config) *RepoManagerImpl {
@@ -71,6 +73,7 @@ func NewRepoManagerImpl(db *gorm.DB, cfg *config.Config) *RepoManagerImpl {
License: license.NewLicenseRepository(db),
Transaction: transactions.NewTransactionRepository(db),
PG: pg.NewPaymentGatewayRepo(&cfg.Midtrans, &cfg.LinkQu),
LinkQu: linkqu.NewLinkQuService(&cfg.LinkQu),
}
}
@@ -218,9 +221,10 @@ type TransactionRepository interface {
Update(ctx context.Context, trx *gorm.DB, transaction *entity.Transaction) (*entity.Transaction, error)
}
type LinQu interface {
type LinkQu interface {
CreateQrisPayment(linkQuRequest entity.LinkQuRequest) (*entity.LinkQuQRISResponse, error)
CreatePaymentVA(linkQuRequest entity.LinkQuRequest) (*entity.LinkQuPaymentVAResponse, error)
CheckPaymentStatus(partnerReff string) (*entity.LinkQuCheckStatusResponse, error)
}
type PaymentGateway interface {