-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds payment reporting adapter as initial
- Loading branch information
Alican Akkus
authored and
Alican Akkus
committed
Jul 27, 2022
1 parent
3c98135
commit 6a3d428
Showing
11 changed files
with
222 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package adapter | ||
|
||
import ( | ||
"craftgate-go-client/adapter/rest" | ||
"craftgate-go-client/model" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type PaymentReportingApi struct { | ||
Opts model.RequestOptions | ||
} | ||
|
||
type SearchPaymentsRequest struct { | ||
Page int | ||
Size int | ||
PaymentId int64 | ||
PaymentTransactionId int64 | ||
BuyerMemberId int64 | ||
SubMerchantMemberId int64 | ||
ConversationId string | ||
ExternalId string | ||
OrderId string | ||
PaymentType model.PaymentType | ||
PaymentProvider model.PaymentProvider | ||
PaymentStatus model.PaymentStatus | ||
PaymentSource model.PaymentSource | ||
PaymentChannel string | ||
BinNumber string | ||
LastFourDigits string | ||
Currency model.Currency | ||
MinPaidPrice float64 | ||
MaxPaidPrice float64 | ||
Installment int | ||
IsThreeDS bool | ||
MinCreatedDate time.Time | ||
MaxCreatedDate time.Time | ||
} | ||
|
||
type ReportingPaymentResponse struct { | ||
Id int64 `json:"id"` | ||
//CreatedDate time.Time `json:"createdDate"` | ||
OrderId string `json:"orderId"` | ||
Price float64 `json:"price"` | ||
PaidPrice float64 `json:"paidPrice"` | ||
WalletPrice float64 `json:"walletPrice"` | ||
Currency model.Currency `json:"currency"` | ||
} | ||
|
||
func (api *PaymentReportingApi) SearchPayments(request SearchPaymentsRequest) (*model.Response[ReportingPaymentResponse], error) { | ||
req, _ := http.NewRequest("GET", fmt.Sprintf("%s/payment-reporting/v1/payments?", api.Opts.BaseURL), nil) | ||
|
||
q := req.URL.Query() | ||
//q.Add("currency", string(request.Currency)) | ||
|
||
//t := reflect.TypeOf(request) | ||
//for i := 0; i < t.NumField(); i++ { | ||
// field := t.Field(i) | ||
// value := reflect.ValueOf(field) | ||
// fmt.Println(field, value) | ||
// | ||
// //q.Add(field.Name, string(field.)) | ||
//} | ||
|
||
req.URL.RawQuery = q.Encode() | ||
|
||
res := model.Response[ReportingPaymentResponse]{} | ||
resErr := rest.SendRequest(req, &res, api.Opts) | ||
return &res, resErr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,24 @@ | ||
package main | ||
|
||
const ( | ||
ApiKeyHeaderName = "x-api-key" | ||
RandomHeaderName = "x-rnd-key" | ||
AuthVersionHeaderName = "x-auth-version" | ||
ClientVersionHeaderName = "x-client-version" | ||
SignatureHeaderName = "x-signature" | ||
import ( | ||
"craftgate-go-client/adapter" | ||
"craftgate-go-client/model" | ||
) | ||
|
||
type Response[T any] struct { | ||
DataResponse DataResponse[T] `json:"data"` | ||
Errors ErrorResponse `json:"errors"` | ||
} | ||
|
||
type ErrorResponse struct { | ||
ErrorGroup string `json:"errorGroup"` | ||
ErrorDescription string `json:"errorDescription"` | ||
ErrorCode string `json:"errorCode"` | ||
} | ||
|
||
type DataResponse[T any] struct { | ||
Items []T `json:"items"` | ||
} | ||
|
||
type Client struct { | ||
Installment InstallmentApi | ||
Installment InstallmentApi | ||
PaymentReporting adapter.PaymentReportingApi | ||
} | ||
|
||
func CraftgateClient(apiKey, secretKey, baseURL string) *Client { | ||
options := model.RequestOptions{ | ||
ApiKey: apiKey, | ||
SecretKey: secretKey, | ||
BaseURL: baseURL, | ||
} | ||
|
||
return &Client{ | ||
Installment: InstallmentApi{ | ||
Opts: RequestOptions{ | ||
ApiKey: apiKey, | ||
SecretKey: secretKey, | ||
BaseURL: baseURL, | ||
}, | ||
}, | ||
Installment: InstallmentApi{Opts: options}, | ||
PaymentReporting: adapter.PaymentReportingApi{Opts: options}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
package main | ||
|
||
import "fmt" | ||
import ( | ||
"craftgate-go-client/adapter" | ||
"craftgate-go-client/model" | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
baseURL := "https://sandbox-api.craftgate.io" | ||
apiKey := "sandbox-YEhueLgomBjqsnvBlWVVuFsVhlvJlMHE" | ||
secretKey := "sandbox-tBdcdKVGmGupzfaWcULcwDLMoglZZvTz" | ||
Craftgate := CraftgateClient(apiKey, secretKey, baseURL) | ||
res, _ := Craftgate.Installment.SearchInstallments(SearchInstallmentRequest{BinNumber: "487074", Price: 100.00}) | ||
fmt.Println(res) | ||
|
||
//res, _ := Craftgate.Installment.SearchInstallments(SearchInstallmentRequest{BinNumber: "487074", Price: 100.00}) | ||
//fmt.Println(res) | ||
|
||
resPaymentSearch, _ := Craftgate.PaymentReporting.SearchPayments(adapter.SearchPaymentsRequest{Currency: model.TRY}) | ||
fmt.Println(resPaymentSearch) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package model | ||
|
||
type PaymentType string | ||
type PaymentProvider string | ||
type PaymentStatus string | ||
type PaymentSource string | ||
type Currency string | ||
|
||
type RequestOptions struct { | ||
BaseURL string | ||
ApiKey string | ||
SecretKey string | ||
} | ||
|
||
type Response[T any] struct { | ||
DataResponse DataResponse[T] `json:"data"` | ||
Errors ErrorResponse `json:"errors"` | ||
} | ||
|
||
type ErrorResponse struct { | ||
ErrorGroup string `json:"errorGroup"` | ||
ErrorDescription string `json:"errorDescription"` | ||
ErrorCode string `json:"errorCode"` | ||
} | ||
|
||
type DataResponse[T any] struct { | ||
Items []T `json:"items"` | ||
} | ||
|
||
const ( | ||
ApiKeyHeaderName = "x-api-key" | ||
RandomHeaderName = "x-rnd-key" | ||
AuthVersionHeaderName = "x-auth-version" | ||
ClientVersionHeaderName = "x-client-version" | ||
SignatureHeaderName = "x-signature" | ||
AuthVersion = "1" | ||
ClientVersion = "craftgate-go-client:1.0.0" | ||
) | ||
|
||
// payment type declaration | ||
const ( | ||
CARD_PAYMENT PaymentType = "CARD_PAYMENT" | ||
DEPOSIT_PAYMENT PaymentType = "DEPOSIT_PAYMENT" | ||
WALLET_PAYMENT PaymentType = "WALLET_PAYMENT" | ||
CARD_AND_WALLET_PAYMENT PaymentType = "CARD_AND_WALLET_PAYMENT" | ||
BANK_TRANSFER PaymentType = "BANK_TRANSFER" | ||
) | ||
|
||
// payment provider declaration | ||
const ( | ||
BANK PaymentProvider = "BANK" | ||
CG_WALLET PaymentProvider = "CG_WALLET" | ||
MASTERPASS PaymentProvider = "MASTERPASS" | ||
GARANTI_PAY PaymentProvider = "GARANTI_PAY" | ||
) | ||
|
||
// payment status declaration | ||
const ( | ||
FAILURE PaymentStatus = "FAILURE" | ||
SUCCESS PaymentStatus = "SUCCESS" | ||
INIT_THREEDS PaymentStatus = "INIT_THREEDS" | ||
CALLBACK_THREEDS PaymentStatus = "CALLBACK_THREEDS" | ||
WAITING PaymentStatus = "WAITING" | ||
) | ||
|
||
// payment source declaration | ||
const ( | ||
API PaymentSource = "API" | ||
CHECKOUT_FORM PaymentSource = "CHECKOUT_FORM" | ||
PAY_BY_LINK PaymentSource = "PAY_BY_LINK" | ||
) | ||
|
||
// currency declaration | ||
const ( | ||
TRY Currency = "TRY" | ||
USD Currency = "USD" | ||
EUR Currency = "EUR" | ||
GBP Currency = "GBP" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters