Skip to content

Commit

Permalink
wallet with time
Browse files Browse the repository at this point in the history
  • Loading branch information
reywyn committed Jul 27, 2022
1 parent 8d6955e commit 80954d5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
18 changes: 18 additions & 0 deletions adapter/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,28 @@ package adapter

import (
"net/url"
"time"

"github.com/gorilla/schema"
)

const (
TimeLayout = "\"2006-01-02T15:04:05\""
)

type Time struct {
time.Time
}

func (t *Time) UnmarshalJSON(b []byte) error {
parse, err := time.Parse(TimeLayout, string(b))
if err != nil {
return err
}
t.Time = parse
return nil
}

var encoder = schema.NewEncoder()

func QueryParams(req interface{}) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions adapter/installment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type SearchInstallmentRequest struct {
DistinctCardBrandsWithLowestCommissions bool `schema:"distinctCardBrandsWithLowestCommissions"`
}

type InstallmentResponse struct {
type SearchInstallmentResponse struct {
BinNumber string `json:"binNumber"`
Price float64 `json:"price"`
CardType string `json:"cardType"`
Expand Down Expand Up @@ -60,7 +60,7 @@ func (api *Installment) SearchInstallments(request SearchInstallmentRequest) (in
request.Currency = "TRY"
req.URL.RawQuery, _ = QueryParams(request)

res := model.Response[model.DataResponse[InstallmentResponse]]{}
res := model.Response[model.DataResponse[SearchInstallmentResponse]]{}
resErr := rest.SendRequest(req, &res, api.Opts)
return &res, resErr
}
Expand Down
33 changes: 33 additions & 0 deletions adapter/wallet.go
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
package adapter

import (
"craftgate-go-client/adapter/rest"
"craftgate-go-client/model"
"fmt"
"net/http"
)

type Wallet struct {
Opts model.RequestOptions
}

type RetrieveMemberWalletRequest struct {
MemberId int64 `schema:"memberId"`
}

type RetrieveMemberWalletResponse struct {
Id int64 `schema:"id"`
CreatedDate Time `schema:"createdDate"`
UpdatedDate Time `schema:"updatedDate"`
Amount float64 `schema:"amount"`
WithdrawalAmount float64 `schema:"withdrawalAmount"`
Currency model.Currency `schema:"currency"`
MemberId int64 `schema:"memberId"`
}

func (api *Wallet) RetrieveMemberWallet(request RetrieveMemberWalletRequest) (interface{}, error) {
req, _ := http.NewRequest("GET", fmt.Sprintf("%s/wallet/v1/members/%d/wallet", api.Opts.BaseURL, request.MemberId), nil)

res := model.Response[RetrieveMemberWalletResponse]{}
resErr := rest.SendRequest(req, &res, api.Opts)
return &res, resErr
}
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Client struct {
Installment adapter.Installment
PaymentReporting adapter.PaymentReporting
Wallet adapter.Wallet
}

func CraftgateClient(apiKey, secretKey, baseURL string) *Client {
Expand All @@ -20,5 +21,6 @@ func CraftgateClient(apiKey, secretKey, baseURL string) *Client {
return &Client{
Installment: adapter.Installment{Opts: options},
PaymentReporting: adapter.PaymentReporting{Opts: options},
Wallet: adapter.Wallet{Opts: options},
}
}

0 comments on commit 80954d5

Please sign in to comment.