Skip to content

Commit

Permalink
Added support for IP field on source creation. (#77)
Browse files Browse the repository at this point in the history
## Description

Added support for IP field on source creation.

Sample code
```
package main

import (
	"log"

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

const (
	// Read these from environment variables or configuration files!
	OmisePublicKey = "<PKEY>"
	OmiseSecretKey = "<SKEY>"
)

func main() {
	client, e := omise.NewClient(OmisePublicKey, OmiseSecretKey)
	if e != nil {
		log.Fatal(e)
	}

	// Creates a source from the token
	source, createSource := &omise.Source{}, &operations.CreateSource{
		Amount:   100000, // ฿ 1,000.00
		Currency: "thb",
		Type:     "wechat_pay",
		Ip:       "192.168.1.1",
	}
	if e := client.Do(source, createSource); e != nil {
		log.Fatal(e)
	}

	log.Printf("source: %s  amount: %s %d\n", source.ID, source.Currency, source.Amount)
	log.Printf("IP: %s\n", source.Ip)
}
```
 
## Rollback procedure

`default rollback procedure`

---------

Co-authored-by: Aashish <[email protected]>
  • Loading branch information
aashishgurung and Aashish authored Mar 29, 2024
1 parent d891b6d commit a73b37f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
3 changes: 1 addition & 2 deletions operations/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
// }
//
// fmt.Println("created source:", source.ID)
//
type CreateSource struct {
Type string `json:"type"`
Amount int64 `json:"amount"`
Expand All @@ -32,6 +31,7 @@ type CreateSource struct {
TerminalID string `json:"terminal_id,omitempty"`
ZeroInterestInstallments bool `json:"zero_interest_installments,omitempty"`
PlatformType string `json:"platform_type,omitempty"`
Ip string `json:"ip,omitempty"`
}

func (req *CreateSource) Describe() *internal.Description {
Expand All @@ -52,7 +52,6 @@ func (req *CreateSource) Describe() *internal.Description {
// }
//
// fmt.Printf("source #123: %#v\n", source)
//
type RetrieveSource struct {
SourceID string `json:"-"`
}
Expand Down
19 changes: 19 additions & 0 deletions operations/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,22 @@ func TestCreateSourceWithPlatformType(t *testing.T) {
client.MustDo(exampleSource, createSource)
r.Equal(t, SourceID, exampleSource.ID)
}

func TestCreateSourceWithIP(t *testing.T) {
const (
SourceID = "src_test_5mygxph6d55vvy8nn9i"
Ip = "192.168.1.1"
)
client := testutil.NewFixedClient(t)

exampleSource, createSource := &omise.Source{}, &operations.CreateSource{
Type: "wechat_pay",
Amount: 20000,
Currency: "thb",
Ip: Ip,
}

client.MustDo(exampleSource, createSource)
r.Equal(t, SourceID, exampleSource.ID)
r.Equal(t, Ip, exampleSource.Ip)
}
1 change: 1 addition & 0 deletions source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ type Source struct {
References *References `json:"references"`
ZeroInterestInstallments bool `json:"zero_interest_installments"`
PlatformType string `json:"platform_type"`
Ip string `json:"ip"`
}
1 change: 1 addition & 0 deletions testdata/fixtures/api.omise.co/sources-post.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"currency": "MYR",
"email": "[email protected]",
"flow": "redirect",
"ip": "192.168.1.1",
"installment_term": null,
"name": null,
"mobile_number": null,
Expand Down

0 comments on commit a73b37f

Please sign in to comment.