Skip to content

Commit

Permalink
Fix http request panic nil pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
awang-jakpat committed Jan 15, 2024
1 parent afba2de commit 4c22d2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 5 additions & 6 deletions payment/goldpay/goldpay.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ func NewGoldpayPayment(config *GoldpayConfig) payment.Payment {

// Pay will invoke goldpay API to make a transfer transaction from user to upstore wallet
func (gp *goldPay) Pay(amount float64) (payment.PaymentInfo, error) {
helper := httphelper.HttpHelper{}
helper := httphelper.NewHttpHelper(&http.Client{}, &httphelper.HttpConfig{})

httpReq := helper.Request(http.MethodPost, gp.config.GoldpayApiUrl, map[string]any{
"weight": amount,
})

httpReq.SetHeaderFn(func(req *http.Request) error {
helper.SetHeaderFn(func(req *http.Request) error {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", gp.config.AuthenticatedUserToken))
return nil
})
httpReq := helper.Request(http.MethodPost, gp.config.GoldpayApiUrl, map[string]any{
"weight": amount,
})

var response goldpayApiResponse
if err := httpReq.Decode(&response); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions payment/nicepay/nicepay.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ func (np *nicepay) Pay(amount float64) (payment.PaymentInfo, error) {
return payment.PaymentInfo{}, err
}

helper := httphelper.HttpHelper{}
helper := httphelper.NewHttpHelper(&http.Client{}, &httphelper.HttpConfig{})
helper.SetHeaderFn(func(req *http.Request) error {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))
return nil
})
httpReq := helper.Request(
http.MethodPost,
fmt.Sprintf("%s/payments/%s", np.config.ImpAPIUrl, np.config.ImpUid),
map[string]any{},
)
httpReq.SetHeaderFn(func(req *http.Request) error {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))
return nil
})

var result nicepayApiResponse
if err := httpReq.Decode(&result); err != nil {
Expand Down

0 comments on commit 4c22d2d

Please sign in to comment.