Skip to content

Commit

Permalink
updates to payment gateway to enable BitCoin
Browse files Browse the repository at this point in the history
  • Loading branch information
KenWilliamson committed May 21, 2021
1 parent 1ecc33b commit 902ba18
Show file tree
Hide file tree
Showing 9 changed files with 826 additions and 769 deletions.
1,522 changes: 763 additions & 759 deletions coverage.out

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/Ulbora/six910-mysql

go 1.14
go 1.16

require (
github.com/Ulbora/Level_Logger v1.0.2
github.com/Ulbora/dbinterface v1.0.5
github.com/Ulbora/dbinterface_mysql v1.0.7
github.com/Ulbora/six910-database-interface v1.0.37
github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/Ulbora/six910-database-interface v1.0.38
github.com/go-sql-driver/mysql v1.6.0 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ github.com/Ulbora/six910-database-interface v1.0.36 h1:SgidSG+F282G3ufQ4qDhtg5Rz
github.com/Ulbora/six910-database-interface v1.0.36/go.mod h1:OGqZQ5ETgqxsHB636qmivSR36NzQxhV4T+ATsIUJSLM=
github.com/Ulbora/six910-database-interface v1.0.37 h1:QmLF7xsqU8DVos97zA8tE8UHoVbtPfmt645jKXTrEx8=
github.com/Ulbora/six910-database-interface v1.0.37/go.mod h1:OGqZQ5ETgqxsHB636qmivSR36NzQxhV4T+ATsIUJSLM=
github.com/Ulbora/six910-database-interface v1.0.38 h1:4G+XIgQ0OUCjYt08XBb71lun84muPa2p5xZVwPJd894=
github.com/Ulbora/six910-database-interface v1.0.38/go.mod h1:xKoESfGA7CV8kFeZwMtwnBAezrBFzTdtrSRaeUn0QBQ=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
5 changes: 5 additions & 0 deletions mockDbMeths.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,11 @@ func (d *MockSix910Mysql) GetPaymentGateway(id int64) *mdb.PaymentGateway {
return d.MockPaymentGateway
}

//GetPaymentGatewayByName GetPaymentGatewayByName
func (d *MockSix910Mysql) GetPaymentGatewayByName(name string) *mdb.PaymentGateway {
return d.MockPaymentGateway
}

//GetPaymentGateways GetPaymentGateways
func (d *MockSix910Mysql) GetPaymentGateways(storeID int64) *[]mdb.PaymentGateway {
return d.MockPaymentGatewayList
Expand Down
6 changes: 6 additions & 0 deletions mockDb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,12 @@ func TestMockSix910Mysql_Mocks(t *testing.T) {
if fpgw.CheckoutURL != pgw.CheckoutURL {
t.Fail()
}

fpgw2 := si.GetPaymentGatewayByName("test")
if fpgw2.CheckoutURL != pgw.CheckoutURL {
t.Fail()
}

var pgwlst []sdbi.PaymentGateway
pgwlst = append(pgwlst, pgw)

Expand Down
18 changes: 16 additions & 2 deletions paymentGateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (d *Six910Mysql) AddPaymentGateway(pgw *mdb.PaymentGateway) (bool, int64) {
}
var a []interface{}
a = append(a, pgw.StorePluginsID, pgw.CheckoutURL, pgw.PostOrderURL, pgw.LogoURL, pgw.ClientID,
pgw.ClientKey)
pgw.ClientKey, pgw.Name, pgw.Token)
suc, id := d.DB.Insert(insertPaymentGateway, a...)
d.Log.Debug("suc in add PaymentGateway", suc)
d.Log.Debug("id in add PaymentGateway", id)
Expand All @@ -49,7 +49,7 @@ func (d *Six910Mysql) UpdatePaymentGateway(pgw *mdb.PaymentGateway) bool {
}
var a []interface{}
a = append(a, pgw.CheckoutURL, pgw.PostOrderURL, pgw.LogoURL, pgw.ClientID,
pgw.ClientKey, pgw.ID)
pgw.ClientKey, pgw.Token, pgw.ID)
suc := d.DB.Update(updatePaymentGateway, a...)
return suc
}
Expand All @@ -66,6 +66,18 @@ func (d *Six910Mysql) GetPaymentGateway(id int64) *mdb.PaymentGateway {
return rtn
}

//GetPaymentGatewayByName GetPaymentGatewayByName
func (d *Six910Mysql) GetPaymentGatewayByName(name string) *mdb.PaymentGateway {
if !d.testConnection() {
d.DB.Connect()
}
var a []interface{}
a = append(a, name)
row := d.DB.Get(getPaymentGatewayByName, a...)
rtn := d.parsePaymentGatewayRow(&row.Row)
return rtn
}

//GetPaymentGateways GetPaymentGateways
func (d *Six910Mysql) GetPaymentGateways(storeID int64) *[]mdb.PaymentGateway {
if !d.testConnection() {
Expand Down Expand Up @@ -113,6 +125,8 @@ func (d *Six910Mysql) parsePaymentGatewayRow(foundRow *[]string) *mdb.PaymentGat
rtn.LogoURL = (*foundRow)[4]
rtn.ClientID = (*foundRow)[5]
rtn.ClientKey = (*foundRow)[6]
rtn.Name = (*foundRow)[7]
rtn.Token = (*foundRow)[8]
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions paymentGateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestSix910Mysql_AddPaymentGateway(t *testing.T) {

pisuc, piid := si.AddPlugin(&pi)
if !pisuc || piid == 0 {
fmt.Println("failing add plugin-------------------")
t.Fail()
}

Expand All @@ -64,6 +65,7 @@ func TestSix910Mysql_AddPaymentGateway(t *testing.T) {
str.Enabled = false
suc, sid := si.AddStore(&str)
if !suc || sid == 0 {
fmt.Println("failing add store-------------------")
t.Fail()
}

Expand All @@ -85,6 +87,7 @@ func TestSix910Mysql_AddPaymentGateway(t *testing.T) {

spisuc, spiid := si.AddStorePlugin(&spi)
if !spisuc || spiid == 0 {
fmt.Println("failing add store plugin-------------------")
t.Fail()
}

Expand All @@ -95,10 +98,13 @@ func TestSix910Mysql_AddPaymentGateway(t *testing.T) {
pgw.LogoURL = "/login"
pgw.PostOrderURL = "/post"
pgw.StorePluginsID = spiid
pgw.Token = "token"
pgw.Name = "BTC Test"

dbi.Close()
pgwsuc, pgwid := si.AddPaymentGateway(&pgw)
if !pgwsuc || pgwid == 0 {
fmt.Println("failing add payment gw-------------------")
t.Fail()
}

Expand All @@ -108,24 +114,36 @@ func TestSix910Mysql_AddPaymentGateway(t *testing.T) {
pgw.ClientKey = "56165162"
pgw.LogoURL = "/login2"
pgw.PostOrderURL = "/post2"
pgw.Token = "token2"

dbi.Close()
upgwsuc := si.UpdatePaymentGateway(&pgw)
if !upgwsuc {
fmt.Println("failing update payment gw-------------------")
t.Fail()
}

dbi.Close()
fpgw := si.GetPaymentGateway(pgwid)
fmt.Println("fpgw: ", fpgw)
if fpgw.ClientID != pgw.ClientID {
fmt.Println("failing get payment gw-------------------")
t.Fail()
}

dbi.Close()
fpgw2 := si.GetPaymentGatewayByName("BTC Test")
fmt.Println("fpgw2: ", fpgw)
if fpgw2.ClientID != pgw.ClientID || fpgw2.Name != "BTC Test" || fpgw2.Token != "token2" {
fmt.Println("failing get payment gw by name-------------------")
t.Fail()
}

dbi.Close()
fpgwliststr := si.GetPaymentGateways(sid)
fmt.Println("fpgw list: ", fpgwliststr)
if len(*fpgwliststr) != 1 {
fmt.Println("failing get payment gw list-------------------")
t.Fail()
}

Expand Down
15 changes: 10 additions & 5 deletions queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,20 +572,25 @@ const (
deleteStorePlugin = "DELETE FROM store_plugins WHERE id = ? "

insertPaymentGateway = "INSERT into payment_gateway(store_plugins_id, checkout_url, post_order_url, logo_url, " +
" client_id, client_key) " +
" values(?,?,?,?,?,?)"
" client_id, client_key, name, token) " +
" values(?,?,?,?,?,?,?,?)"

updatePaymentGateway = "UPDATE payment_gateway SET checkout_url = ?, post_order_url = ?, logo_url = ?, " +
" client_id = ?, client_key = ? " +
" client_id = ?, client_key = ?, token = ? " +
" WHERE id = ? "

getPaymentGateway = "SELECT id, store_plugins_id, checkout_url, post_order_url, logo_url, " +
" client_id, client_key " +
" client_id, client_key, name, token " +
" FROM payment_gateway " +
" WHERE id = ? "

getPaymentGatewayByName = "SELECT id, store_plugins_id, checkout_url, post_order_url, logo_url, " +
" client_id, client_key, name, token " +
" FROM payment_gateway " +
" WHERE name = ? "

getPaymentGatewayByStore = " SELECT g.id, g.store_plugins_id, g.checkout_url, " +
" g.post_order_url, g.logo_url, g.client_id, g.client_key " +
" g.post_order_url, g.logo_url, g.client_id, g.client_key, g.name, g.token " +
" FROM payment_gateway g " +
" inner join store_plugins sp " +
" on sp.id = g.store_plugins_id " +
Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go test -coverprofile=coverage.out

0 comments on commit 902ba18

Please sign in to comment.