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

omise-go v2 (codegen) #42

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
66 changes: 40 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ of clean APIs that helps merchants of any size accept credit cards online.

This library offers GO integration to the Omise API.

Install with:
## Installation

### Using `v1`

* [documentation][3]

```go
go get github.com/omise/omise-go
```

# COMPLIANCE WARNING
### Using `v2`

* [documentation][0]

```go
go get github.com/omise/omise-go/v2
```

## COMPLIANCE WARNING

Card data should never transit through your server. This library provides means to create
tokens on the server side but should only be used for testing or **only if you currently
Expand All @@ -30,7 +42,7 @@ Auditor.**
Instead we recommend that you follow our guide on how to safely
[collect credit information](https://www.omise.co/collecting-card-information).

# USAGE
## USAGE

See [godoc.org][0] in tandem with the [Omise API Documentation][1] for usage instruction.

Expand All @@ -42,14 +54,13 @@ package main
import (
"log"

"github.com/omise/omise-go"
"github.com/omise/omise-go/operations"
"github.com/omise/omise-go/v2"
)

const (
// Read these from environment variables or configuration files!
OmisePublicKey = "pkey_test_521w1g1t7w4x4rd22z0"
OmiseSecretKey = "skey_test_521w1g1t6yh7sx4pu8n"
OmisePublicKey = "pkey_test_key"
OmiseSecretKey = "skey_test_key"
)

func main() {
Expand All @@ -58,30 +69,32 @@ func main() {
log.Fatal(e)
}

/** Retrieve a token from a request
* A token should be created from a client side by using our client-side libraries
* https://www.omise.co/libraries#client-side-libraries
* More information:
* - https://www.omise.co/collecting-card-information
* - https://www.omise.co/security-best-practices
**/
// Retrieve a token from a request
//
// A token should be created from a client side by using our client-side libraries
// https://www.omise.co/libraries#client-side-libraries
// More information:
// - https://www.omise.co/collecting-card-information
// - https://www.omise.co/security-best-practices
token := "tokn_xxxxxxxxxxxxx"

// Creates a charge from the token
charge, createCharge := &omise.Charge{}, &operations.CreateCharge{
Amount: 100000, // ฿ 1,000.00
Currency: "thb",
Card: token.ID,
}
if e := client.Do(charge, createCharge); e != nil {
charge, err := client.Charge().Create(context.Background(), &omise.CreateChargeParams{
Amount: 100000,
Currency: "THB",
Description: "initial charge.",
Card: token,
})

if err != nil {
log.Fatal(e)
}

log.Printf("charge: %s amount: %s %d\n", charge.ID, charge.Currency, charge.Amount)
log.Printf("charge: %s amount: %s %d\n", charge.ID, charge.Currency, charge.Amount)
}
```

# API VERSION
## API VERSION

You can choose which API version to use with Omise. Each new API version has new features
and might not be compatible with previous versions. You can change the default version by
Expand All @@ -91,18 +104,19 @@ The version configured here will have higher priority than the version set in yo
account. This is useful if you have multiple environments with different API versions for
testing. (e.g. Development on the latest version but production is on an older version).

```
client.APIVersion = "2015-11-06"
```go
client.APIVersion = "2019-05-29"
```

It is highly recommended to set this version to the current version you're using. You can
learn more about this feature in our [versioning
guide](https://www.omise.co/api-versioning).

# LICENSE
## LICENSE

See [LICENSE][2] file.

[0]: https://godoc.org/github.com/omise/omise-go
[0]: https://godoc.org/github.com/omise/omise-go/v2
[1]: https://www.omise.co/docs
[2]: https://raw.githubusercontent.com/omise/omise-go/master/LICENSE
[3]: https://godoc.org/github.com/omise/omise-go
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ perform() {
check go "needs go from http://golang.org"
check $GOPATH/bin/gometalinter "needs gometalinter from https://github.com/alecthomas/gometalinter"

# v1
echo "v1"
perform generators go generate . ./operations
perform builds go install . ./operations
perform linters gometalinter --fast --aggregate
perform tests go test $(go list ./... | grep -v v2/)

# v2
echo "v2"
cd ./v2
perform builds go install . ./operations
perform linters gometalinter --fast --aggregate
perform tests go test ./...

echo "\x1B[38;5;2msuccess.\x1B[0m"
115 changes: 115 additions & 0 deletions v2/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package omise

import (
"github.com/omise/omise-go/v2/internal"
"context"
)

// Account represents Account object.
// See https://www.omise.co/account-api for more information.
type Account struct {
Base
APIVersion string `json:"api_version"`
AutoActivateRecipients bool `json:"auto_activate_recipients"`
ChainEnabled bool `json:"chain_enabled"`
ChainReturnURI string `json:"chain_return_uri"`
Country string `json:"country"`
Currency string `json:"currency"`
Email string `json:"email"`
Location string `json:"location"`
MetadataExportKeys map[string]interface{} `json:"metadata_export_keys"`
SupportedCurrencies []string `json:"supported_currencies"`
Team string `json:"team"`
WebhookURI string `json:"webhook_uri"`
ZeroInterestInstallments bool `json:"zero_interest_installments"`
}

// AccountService represents resource service.
type AccountService struct {
*Client
}

// Account defines resource service.
func (c *Client) Account() *AccountService {
return &AccountService{c}
}

// Retrieve retrieves account
//
// Example:
//
// account, err := client.Account().Retrieve(ctx, &RetrieveAccountParams{
// })
// if err != nil {
// panic(e)
// }
//
// fmt.Printf("account: %#v\n", account)
//
func (s *AccountService) Retrieve(ctx context.Context, params *RetrieveAccountParams) (*Account, error) {
result := &Account{}
err := s.Do(ctx, result, params)

return result, err
}

// RetrieveAccountParams params object.
type RetrieveAccountParams struct {
}

// Describe describes structure of request
func (req *RetrieveAccountParams) Describe() *internal.Description {
return &internal.Description{
Endpoint: internal.API,
Method: "GET",
Path: "/account",
ContentType: "application/json",
}
}

// Update updates account
//
// Example:
//
// account, err := client.Account().Update(ctx, &UpdateAccountParams{
// })
// if err != nil {
// panic(e)
// }
//
// fmt.Printf("account: %#v\n", account)
//
func (s *AccountService) Update(ctx context.Context, params *UpdateAccountParams) (*Account, error) {
result := &Account{}
err := s.Do(ctx, result, params)

return result, err
}

// UpdateAccountParams params object.
type UpdateAccountParams struct {
ChainEnabled bool `json:"chain_enabled,omitempty"`
ChainReturnURI string `json:"chain_return_uri,omitempty"`
MetadataExportKeys map[string]interface{} `json:"metadata_export_keys,omitempty"`
WebhookURI string `json:"webhook_uri,omitempty"`
ZeroInterestInstallments bool `json:"zero_interest_installments,omitempty"`
}

// MetadataExportKeysParams params object.
type MetadataExportKeysParams struct {
Charge []interface{} `json:"charge,omitempty"`
Dispute []interface{} `json:"dispute,omitempty"`
Refund []interface{} `json:"refund,omitempty"`
Transfer []interface{} `json:"transfer,omitempty"`
}

// Describe describes structure of request
func (req *UpdateAccountParams) Describe() *internal.Description {
return &internal.Description{
Endpoint: internal.API,
Method: "PATCH",
Path: "/account",
ContentType: "application/json",
}
}

61 changes: 61 additions & 0 deletions v2/balance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package omise

import (
"github.com/omise/omise-go/v2/internal"
"context"
)

// Balance represents Balance object.
// See https://www.omise.co/balance-api for more information.
type Balance struct {
Base
Currency string `json:"currency"`
Location string `json:"location"`
Reserve int64 `json:"reserve"`
Total int64 `json:"total"`
Transferable int64 `json:"transferable"`
}

// BalanceService represents resource service.
type BalanceService struct {
*Client
}

// Balance defines resource service.
func (c *Client) Balance() *BalanceService {
return &BalanceService{c}
}

// Retrieve retrieves balance
//
// Example:
//
// balance, err := client.Balance().Retrieve(ctx, &RetrieveBalanceParams{
// })
// if err != nil {
// panic(e)
// }
//
// fmt.Printf("balance: %#v\n", balance)
//
func (s *BalanceService) Retrieve(ctx context.Context, params *RetrieveBalanceParams) (*Balance, error) {
result := &Balance{}
err := s.Do(ctx, result, params)

return result, err
}

// RetrieveBalanceParams params object.
type RetrieveBalanceParams struct {
}

// Describe describes structure of request
func (req *RetrieveBalanceParams) Describe() *internal.Description {
return &internal.Description{
Endpoint: internal.API,
Method: "GET",
Path: "/balance",
ContentType: "application/json",
}
}

24 changes: 24 additions & 0 deletions v2/bank_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package omise

// BankAccount represents Bank Account object.
// See https://www.omise.co/bank-account-api for more information.
type BankAccount struct {
Base
BankCode string `json:"bank_code"`
BranchCode string `json:"branch_code"`
Brand string `json:"brand"`
LastDigits string `json:"last_digits"`
Name string `json:"name"`
Type BankAccountType `json:"type"`
}

// BankAccountService represents resource service.
type BankAccountService struct {
*Client
}

// BankAccount defines resource service.
func (c *Client) BankAccount() *BankAccountService {
return &BankAccountService{c}
}

11 changes: 11 additions & 0 deletions v2/bank_account_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package omise

// BankAccountType represents an enumeration of possible values for BankAccount.
type BankAccountType string

// BankAccountType can be one of the following list of constants:
const (
BankAccountCurrent BankAccountType = "current"
BankAccountNormal BankAccountType = "normal"
)

19 changes: 19 additions & 0 deletions v2/barcode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package omise

// Barcode represents resource object.
type Barcode struct {
Base
Image *Document `json:"image"`
Type string `json:"type"`
}

// BarcodeService represents resource service.
type BarcodeService struct {
*Client
}

// Barcode defines resource service.
func (c *Client) Barcode() *BarcodeService {
return &BarcodeService{c}
}

Loading