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
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"`
}
6 changes: 3 additions & 3 deletions bank_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ type BankAccount struct {
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"`
}

// 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
17 changes: 8 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,7 +35,6 @@ 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"`
Expand Down
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
4 changes: 4 additions & 0 deletions internal/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ const (
API Endpoint = "https://api.omise.co"
Vault Endpoint = "https://vault.omise.co"
)

const (
Version string = "2019-05-29"
)
34 changes: 33 additions & 1 deletion operations/charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@ import (
"github.com/omise/omise-go/internal"
)

type TransactionIndicator string

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

type RecurringReason string

const (
Blank RecurringReason = "blank"
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"`
Amount int32 `json:"amount,omitempty"`
Percentage float32 `json:"percantage,omitempty"`
}

// Example:
//
// charges, list := &omise.ChargeList{}, &ListCharges{
Expand Down Expand Up @@ -56,7 +83,6 @@ type CreateCharge struct {
Source string `json:"source,omitempty"`
Amount int64 `json:"amount"`
Currency string `json:"currency"`
Offsite omise.OffsiteTypes `json:"offsite,omitempty"`
Description string `json:"description,omitempty"`
DontCapture bool `json:"-"` // inverse, since `capture` defaults to true
ReturnURI string `json:"return_uri,omitempty"`
Expand All @@ -65,6 +91,12 @@ type CreateCharge struct {
ZeroInterestInstallments *bool `json:"zero_interest_installments,omitempty"`
AuthorizationType omise.AuthorizationType `json:"authorization_type,omitempty"`
WebhookEndpoints []string `json:"webhook_endpoints,omitempty"`
Ip string `json:"ip,omitempty"`
TransactionIndicator TransactionIndicator `json:"transaction_indicator,omitempty"`
RecurringReason RecurringReason `json:"recurring_reason,omitempty"`
LinkedAccount string `json:"linked_account,omitempty"`
FirstCharge string `json:"first_charge,omitempty"`
PlatformFee PlatformFee `json:"platform_fee,dive,omitempty"`
}

func (req *CreateCharge) MarshalJSON() ([]byte, error) {
Expand Down
14 changes: 7 additions & 7 deletions operations/charge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ func TestCreateChargeMarshal(t *testing.T) {
Amount: 10000,
Currency: "thb",
},
`{"amount":10000,"currency":"thb"}`,
`{"amount":10000,"currency":"thb","platform_fee":{}}`,
},
{
&CreateCharge{
Amount: 10000,
Currency: "thb",
DontCapture: true,
},
`{"amount":10000,"currency":"thb","capture":false}`,
`{"amount":10000,"currency":"thb","platform_fee":{},"capture":false}`,
},
{
&CreateCharge{
Expand All @@ -38,7 +38,7 @@ func TestCreateChargeMarshal(t *testing.T) {
DontCapture: true,
AuthorizationType: omise.PreAuth,
},
`{"amount":10000,"currency":"thb","authorization_type":"pre_auth","capture":false}`,
`{"amount":10000,"currency":"thb","authorization_type":"pre_auth","platform_fee":{},"capture":false}`,
},
{
&CreateCharge{
Expand All @@ -47,15 +47,15 @@ func TestCreateChargeMarshal(t *testing.T) {
DontCapture: true,
AuthorizationType: omise.FinalAuth,
},
`{"amount":10000,"currency":"thb","authorization_type":"final_auth","capture":false}`,
`{"amount":10000,"currency":"thb","authorization_type":"final_auth","platform_fee":{},"capture":false}`,
},
{
&CreateCharge{
Amount: 10000,
Currency: "thb",
WebhookEndpoints: []string{"https://docs.opn.ooo/api-webhooks"},
},
`{"amount":10000,"currency":"thb","webhook_endpoints":["https://docs.opn.ooo/api-webhooks"]}`,
`{"amount":10000,"currency":"thb","webhook_endpoints":["https://docs.opn.ooo/api-webhooks"],"platform_fee":{}}`,
},
}
for _, td := range testdata {
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestCreateChargeMarshal_WithMetadata(t *testing.T) {
},
}

expected := `{"customer":"customer_id","amount":100000,"currency":"thb","metadata":{"color":"red"}}`
expected := `{"customer":"customer_id","amount":100000,"currency":"thb","metadata":{"color":"red"},"platform_fee":{}}`

b, err := json.Marshal(req)
r.Nil(t, err, "error should be nothing")
Expand All @@ -264,7 +264,7 @@ func TestCreateChargeMarshal_WithoutMetadata(t *testing.T) {
Currency: "thb",
}

expected := `{"customer":"customer_id","amount":100000,"currency":"thb"}`
expected := `{"customer":"customer_id","amount":100000,"currency":"thb","platform_fee":{}}`

b, err := json.Marshal(req)
r.Nil(t, err, "err should be nothing")
Expand Down
54 changes: 25 additions & 29 deletions operations/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
// }
//
// fmt.Println("# of new customers in the last hour:", len(customers.Data))
//
type ListCustomers struct {
List
}
Expand All @@ -43,12 +42,12 @@ func (req *ListCustomers) Describe() *internal.Description {
// }
//
// fmt.Printf("created customer: %#v\n", customer)
//
type CreateCustomer struct {
Email string `json:"email,omitempty"`
Description string `json:"description,omitempty"`
Card string `json:"card,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Email string `json:"email,omitempty"`
Description string `json:"description,omitempty"`
Card string `json:"card,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
LinkedAccount string `json:"linked_account,omitempty"`
}

func (req *CreateCustomer) Describe() *internal.Description {
Expand All @@ -68,7 +67,6 @@ func (req *CreateCustomer) Describe() *internal.Description {
// }
//
// fmt.Printf("cust_123: %#v\n", cust)
//
type RetrieveCustomer struct {
CustomerID string `json:"-"`
}
Expand All @@ -93,14 +91,14 @@ func (req *RetrieveCustomer) Describe() *internal.Description {
// }
//
// fmt.Printf("updated customer: %#v\n", cust)
//
type UpdateCustomer struct {
CustomerID string `json:"-"`
Email string `json:"email,omitempty"`
Description string `json:"description,omitempty"`
Card string `json:"card,omitempty"`
DefaultCard string `json:"default_card,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
CustomerID string `json:"-"`
Email string `json:"email,omitempty"`
Description string `json:"description,omitempty"`
Card string `json:"card,omitempty"`
DefaultCard string `json:"default_card,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
LinkedAccount string `json:"linked_account,omitempty"`
}

func (req *UpdateCustomer) Describe() *internal.Description {
Expand All @@ -122,7 +120,6 @@ func (req *UpdateCustomer) Describe() *internal.Description {
// }
//
// fmt.Println("destroyed customer:", del.ID)
//
type DestroyCustomer struct {
CustomerID string `json:"-"`
}
Expand All @@ -140,20 +137,19 @@ func (req *DestroyCustomer) Describe() *internal.Description {
//
// Example:
//
// var schds omise.ScheduleList
// list := ListCustomerChargeSchedules{
// CustomerID: "cust_123"
// List: List{
// Limit: 100,
// From: time.Now().Add(-1 * time.Hour),
// },
// }
// if e := client.Do(&schds, &list); e != nil {
// panic(e)
// }
//
// fmt.Println("# of schedules made in the last hour:", len(schds.Data))
//
// var schds omise.ScheduleList
// list := ListCustomerChargeSchedules{
// CustomerID: "cust_123"
// List: List{
// Limit: 100,
// From: time.Now().Add(-1 * time.Hour),
// },
// }
// if e := client.Do(&schds, &list); e != nil {
// panic(e)
// }
//
// fmt.Println("# of schedules made in the last hour:", len(schds.Data))
type ListCustomerChargeSchedules struct {
CustomerID string
List
Expand Down
2 changes: 1 addition & 1 deletion operations/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type CreateLink struct {
Currency string `json:"currency"`
Title string `json:"title"`
Description string `json:"description"`
Multiple bool `json:"multiple"`
Multiple bool `json:"multiple,omitempty"`
}

func (req *CreateLink) Describe() *internal.Description {
Expand Down
Loading