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

Upgrade library to API version 2019-05-29. #84

Merged
merged 9 commits into from
Sep 10, 2024
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
examples/.env
examples/.DS_Store
6 changes: 3 additions & 3 deletions balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package omise
// See https://www.omise.co/balance-api for more information.
type Balance struct {
Base
Available int64 `json:"available"`
Total int64 `json:"total"`
Currency string `json:"currency"`
Transferable int64 `json:"transferable"`
Total int64 `json:"total"`
Currency string `json:"currency"`
}
21 changes: 17 additions & 4 deletions bank_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@ package omise

// BankAccount represents Omise's bank account object.
// See https://www.omise.co/bank-account-api for more information.
type BankAccountRequest struct {
Base
Brand string `json:"brand"`
LastDigits string `json:"last_digits"`
Name string `json:"name"`

// for Omise Japan
BankCode string `json:"bank_code"`
BranchCode string `json:"branch_code"`
Type BankAccountType `json:"type"`
Number string `json:"number"`
}

type BankAccount struct {
Base
Brand string `json:"brand"`
Number string `json:"number"`
LastDigits string `json:"last_digits"`
Name string `json:"name"`

// for Omise Japan
BankCode string `json:"bank_code"`
BranchCode string `json:"branch_code"`
AccountType BankAccountType `json:"account_type"`
BankCode string `json:"bank_code"`
BranchCode string `json:"branch_code"`
Type BankAccountType `json:"type"`
AccountNumber string `json:"account_number"`
}

// BankAccountType BankAccount an enumeration of possible types of BackAccount(s) which can be
Expand Down
10 changes: 5 additions & 5 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import "time"
// Base structure contains fields that are common to objects returned by the Omise's REST
// API.
type Base struct {
Object string `json:"object"`
ID string `json:"id"`
Live bool `json:"livemode"`
Location *string `json:"location"`
Created time.Time `json:"created"`
Object string `json:"object"`
ID string `json:"id"`
Live bool `json:"livemode"`
Location *string `json:"location"`
CreatedAt time.Time `json:"created_at"`
}

// Deletion struct is used to receive deletion responses from delete operations.
Expand Down
44 changes: 35 additions & 9 deletions charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import "time"
// See https://www.omise.co/charges-api for more information.
type Charge struct {
Base
Status ChargeStatus `json:"status"`
Amount int64 `json:"amount"`
AuthorizationType AuthorizationType `json:"authorization_type"`
AuthorizedAmount int64 `json:"authorized_amount"`
CapturedAmount int64 `json:"captured_amount"`
Currency string `json:"currency"`
Description *string `json:"description"`
Status ChargeStatus `json:"status"`
Amount int64 `json:"amount"`
AuthorizationType AuthorizationType `json:"authorization_type"`
AuthorizedAmount int64 `json:"authorized_amount"`
CapturedAmount int64 `json:"captured_amount"`
Currency string `json:"currency"`
Description *string `json:"description"`

Capture bool `json:"capture"`
Authorized bool `json:"authorized"`
Expand All @@ -22,7 +22,7 @@ type Charge struct {
Transaction string `json:"transaction"`
Card *Card `json:"card"`

Refunded int64 `json:"refunded"`
RefundedAmount int64 `json:"refunded_amount"`
Refunds *RefundList `json:"refunds"`
FailureCode *string `json:"failure_code"`
FailureMessage *string `json:"failure_message"`
Expand All @@ -35,9 +35,35 @@ type Charge struct {
AuthorizeURI string `json:"authorize_uri"`

SourceOfFund SourceOfFunds `json:"source_of_fund"`
Offsite OffsiteTypes `json:"offsite"`

Source *Source `json:"source"`
Metadata map[string]interface{} `json:"metadata"`
ExpiresAt time.Time `json:"expires_at"`
}

type TransactionIndicator string

const (
MIT TransactionIndicator = "MIT"
CIT TransactionIndicator = "CIT"
)

type RecurringReason string

const (
Blank RecurringReason = ""
Unscheduled RecurringReason = "unscheduled"
StandingOrder RecurringReason = "standing_order"
Subscription RecurringReason = "subscription"
Installment RecurringReason = "installment"
PartialShipment RecurringReason = "partial_shipment"
DelayedCharge RecurringReason = "delayed_charge"
NoShow RecurringReason = "no_show"
Resubmission RecurringReason = "resubmission"
)

type PlatformFee struct {
Fixed int32 `json:"fixed,omitempty"`
Percentage float32 `json:"percentage,omitempty"`
Amount int64 `json:"Amount,omitempty"`
}
5 changes: 1 addition & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type Client struct {
Endpoints map[internal.Endpoint]string

// configuration
APIVersion string
GoVersion string
customHeaders map[string]string
ctx context.Context
Expand Down Expand Up @@ -138,9 +137,7 @@ func (c *Client) setRequestHeaders(req *http.Request, desc *internal.Description
}

req.Header.Add("User-Agent", strings.TrimSpace(ua))
if c.APIVersion != "" {
req.Header.Add("Omise-Version", c.APIVersion)
}
req.Header.Add("Omise-Version", internal.Version)

// setting custom headers passed from the caller
for k, v := range c.customHeaders {
Expand Down
4 changes: 1 addition & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ func TestClient_Request(t *testing.T) {
r.Contains(t, req.Header.Get("User-Agent"), "OmiseGo/")
r.Contains(t, req.Header.Get("User-Agent"), "Go/go")
r.Contains(t, req.Header.Get("X-Header-ABC"), "ABC")
r.Empty(t, req.Header.Get("Omise-Version"), "Omise-Version header sent when APIVersion is not specified.")
r.Equal(t, req.Header.Get("Omise-Version"), internal.Version)

client.GoVersion = "RANDOMXXXVERSION"
client.APIVersion = "yadda"
req, err = client.Request(desc)
r.NoError(t, err)
r.Contains(t, req.Header.Get("User-Agent"), "Go/RANDOMXXXVERSION")
r.Equal(t, req.Header.Get("Omise-Version"), "yadda")

client.WithUserAgent("OmiseShopify/2.0.0 CheckoutPage/1.0.0")
req, err = client.Request(desc)
Expand Down
2 changes: 2 additions & 0 deletions examples/env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PUBLIC_KEY=****
SECRET_KEY=****
10 changes: 10 additions & 0 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/omise/omise-go/examples

go 1.21.3

require (
github.com/joho/godotenv v1.5.1 // indirect
github.com/omise/omise-go v1.5.0 // indirect
)

replace github.com/omise/omise-go => /Users/aashish/go/src/github.com/omise/omise-go
16 changes: 16 additions & 0 deletions examples/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/omise/omise-go v1.5.0 h1:LVkNDMWVI3HdChugA6QmZuyTk63R00Army+TbZzxh/c=
github.com/omise/omise-go v1.5.0/go.mod h1:P2sXynkJeQOAe46sk1krS/v2irWUxuI+cKoQgm5Ayp4=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
93 changes: 93 additions & 0 deletions examples/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package main

import (
"log"
"os"
"time"

"github.com/joho/godotenv"
"github.com/omise/omise-go"
"github.com/omise/omise-go/examples/src"
)

func main() {
err := godotenv.Load()

if err != nil {
log.Fatalf("Error loading .env file")
}

client, _ := omise.NewClient(
os.Getenv("PUBLIC_KEY"),
os.Getenv("SECRET_KEY"),
)

// client.SetDebug(true)

/**
* Start: Create charge with QR
*/
chargeQR, err := src.CreateChargeQR(client)

if err != nil {
log.Println(err)
}

src.CustomLog(chargeQR)

// Calling Sleep method
time.Sleep(1 * time.Second)

/**
* Start: Create charge with card
*/
chargeCard, err := src.CreateChargeCard(client)

if err != nil {
log.Println(err)
}

src.CustomLog(chargeCard)

// Calling Sleep method
time.Sleep(1 * time.Second)

// /**
// * Start: Create recipient
// */
recipient, err := src.CreateRecipient(client)

if err != nil {
log.Println(err)
}

src.CustomLog(recipient)

// Calling Sleep method
time.Sleep(1 * time.Second)

// /**
// * Start: Create charge schedule
// */
chargeSchedule, err := src.CreateChargeSchedule(client)

if err != nil {
log.Println(err)
}

src.CustomLog(chargeSchedule)

// Calling Sleep method
time.Sleep(1 * time.Second)

// /**
// * Start: Create transfer schedule
// */
transferSchedule, err := src.CreateTransferSchedule(client)

if err != nil {
log.Println(err)
}

src.CustomLog(transferSchedule)
}
18 changes: 18 additions & 0 deletions examples/src/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package src

import (
"github.com/omise/omise-go"
"github.com/omise/omise-go/operations"
)

func GetAccount(client *omise.Client) (*omise.Account, error) {
account := &omise.Account{}

err := client.Do(account, &operations.RetrieveAccount{})

if err != nil {
return nil, err
}

return account, nil
}
18 changes: 18 additions & 0 deletions examples/src/capability.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package src

import (
"github.com/omise/omise-go"
"github.com/omise/omise-go/operations"
)

func GetCapabilities(client *omise.Client) (*omise.Capability, error) {
capability := &omise.Capability{}

err := client.Do(capability, &operations.RetrieveCapability{})

if err != nil {
return nil, err
}

return capability, nil
}
Loading
Loading