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
}