Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mellat provider not using client transporter #54

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions providers/mellat/mellat.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ func (m *Mellat) CreateTransaction(ctx context.Context, req *paymentRequest) (*P
if err != nil {
return nil, err
}
return request[*PaymentResponse]("POST", m.url, payload)
return request[*PaymentResponse](m.client, http.MethodPost, m.url, payload)
}

func (m *Mellat) VerifyTransaction(ctx context.Context, req *verifyRequest) (*VerifyResponse, error) {
payload, err := req.raw(m.username, m.password)
if err != nil {
return nil, err
}
return request[*VerifyResponse]("POST", m.url, payload)
return request[*VerifyResponse](m.client, http.MethodPost, m.url, payload)
}
func request[Rs response](
clientTransporter client.Transporter,
method, url string,
body []byte,
) (
Expand All @@ -60,7 +61,7 @@ func request[Rs response](
}
request.Header.Set("Content-Type", "text/xml")
request.Header.Set("charset", "utf-8")
resp, err := http.DefaultClient.Do(request)
resp, err := clientTransporter.GetClient().Do(request)
if err != nil {
return response, err
}
Expand All @@ -73,7 +74,10 @@ func request[Rs response](
return response, fmt.Errorf("error raw response: %v", string(responseBody))
}
if resp.StatusCode != http.StatusOK|http.StatusCreated {
return response, status.New(response.ResponseCode(), http.StatusFailedDependency, codes.OK, fmt.Sprintf("response code %v", response.ResponseCode()))
return response, status.New(
response.ResponseCode(), http.StatusFailedDependency, codes.OK,
fmt.Sprintf("response code %v", response.ResponseCode()),
)
}
if err := response.modifyResponse(); err != nil {
return response, err
Expand Down
Loading