Skip to content

Commit

Permalink
Merge branch 'v2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadv184 committed Dec 30, 2021
2 parents e6135fc + e37f99f commit 396cef2
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 38 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ In order to pay the invoice, we need the payment transactionId.
We purchase the invoice to retrieve transaction id:
```go
// Configure the Gateway Driver
gateway:=&payping.Driver{
Gateway:=&payping.Driver{
Callback: "http://example.test/callback",
Description: "test",
Token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
// Create new Payment.
payment := gopayment.NewPayment(gateway)
payment := gopayment.NewPayment(Gateway)
// Set Invoice Amount.
err := payment.Amount(amountInt)
if err != nil {
Expand All @@ -93,13 +93,13 @@ After purchasing the invoice, we can redirect the user to the bank payment page:
func pay() gin.HandlerFunc {
return func(c *gin.Context) {
// Configure the Gateway Driver
gateway:=&payping.Driver{
Gateway:=&payping.Driver{
Callback: "http://example.test/callback",
Description: "test",
Token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
// Create new Payment.
payment := gopayment.NewPayment(gateway)
payment := gopayment.NewPayment(Gateway)
// Set Invoice Amount.
err := payment.Amount(amountInt)
if err != nil {
Expand All @@ -113,7 +113,7 @@ func pay() gin.HandlerFunc {
// Get Transaction ID
transactionID := payment.GetTransactionID()
// Redirect the user to the bank payment page.
payUrl := payment.PayUrl()
payUrl := payment.PayURL()
c.Redirect(http.StatusFound, payUrl)
}
}
Expand All @@ -124,7 +124,7 @@ func pay() gin.HandlerFunc {
When user has completed the payment, the bank redirects them to your website, then you need to **verify your payment** to make sure that the payment is valid.:
```go
// Configure the Gateway Driver
gateway:=&payping.Driver{
Gateway:=&payping.Driver{
Callback: "http://example.test/callback",
Description: "test",
Token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
Expand Down
6 changes: 3 additions & 3 deletions drivers/driver.go → gateway/driver.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package drivers
package gateway

import (
"github.com/mohammadv184/gopayment/invoice"
Expand All @@ -9,8 +9,8 @@ import (
type Driver interface {
// Purchase sends a purchase request to the driver's gateway.
Purchase(invoice *invoice.Invoice) (string, error)
// PayUrl returns the url to redirect the user to for payment.
PayUrl(invoice *invoice.Invoice) string
// PayURL returns the url to redirect the user to for payment.
PayURL(invoice *invoice.Invoice) string
// GetDriverName returns the name of the driver.
GetDriverName() string
// Verify checks the payment status of the invoice.
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions drivers/payping/purchase.go → gateway/payping/purchase.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (d *Driver) Purchase(invoice *invoice.Invoice) (string, error) {
return res["code"].(string), nil
}

// PayUrl return pay url
func (d *Driver) PayUrl(invoice *invoice.Invoice) string {
// PayURL return pay url
func (d *Driver) PayURL(invoice *invoice.Invoice) string {
return ApiPaymentUrl + invoice.GetTransactionID()
}

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions drivers/zarinpal/purchase.go → gateway/zarinpal/purchase.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (d *Driver) Purchase(invoice *invoice.Invoice) (string, error) {
return res["data"].(map[string]interface{})["authority"].(string), nil
}

// PayUrl returns the url to redirect the user to in order to pay the invoice.
func (d *Driver) PayUrl(invoice *invoice.Invoice) string {
// PayURL returns the url to redirect the user to in order to pay the invoice.
func (d *Driver) PayURL(invoice *invoice.Invoice) string {
return ApiPaymentUrl + invoice.GetTransactionID()
}

Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions gopayment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package gopayment

import (
"github.com/mohammadv184/gopayment/drivers"
"github.com/mohammadv184/gopayment/gateway"
"github.com/mohammadv184/gopayment/invoice"
_ "github.com/mohammadv184/gopayment/pkg/http"
)
Expand All @@ -12,7 +12,7 @@ const Version = "v1.1.0"

// Payment is the payment main struct of gopayment
type Payment struct {
driver drivers.Driver
driver gateway.Driver
invoice *invoice.Invoice
}

Expand All @@ -35,9 +35,9 @@ func (p *Payment) Purchase() error {
return nil
}

// PayUrl return the payment url
func (p *Payment) PayUrl() string {
return p.driver.PayUrl(p.invoice)
// PayURL return the payment URL
func (p *Payment) PayURL() string {
return p.driver.PayURL(p.invoice)
}

// PayMethod returns the Request Method to be used to pay the invoice.
Expand All @@ -56,7 +56,7 @@ func (p *Payment) GetTransactionID() string {
}

// NewPayment create a new payment
func NewPayment(driver drivers.Driver) *Payment {
func NewPayment(driver gateway.Driver) *Payment {
return &Payment{
driver: driver,
invoice: invoice.NewInvoice(),
Expand Down
4 changes: 2 additions & 2 deletions invoice/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package invoice
import (
"fmt"
"github.com/google/uuid"
"github.com/mohammadv184/gopayment/traits"
"github.com/mohammadv184/gopayment/trait"
)

// Invoice is a struct that holds the invoice data
type Invoice struct {
uUID string
amount uint32
transactionID string
traits.HasDetail
trait.HasDetail
}

// NewInvoice creates a new invoice
Expand Down
4 changes: 2 additions & 2 deletions receipt/receipt.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package receipt

import (
"github.com/mohammadv184/gopayment/traits"
"github.com/mohammadv184/gopayment/trait"
"time"
)

Expand All @@ -10,7 +10,7 @@ type Receipt struct {
referenceID string
date time.Time
driver string
traits.HasDetail
trait.HasDetail
}

// NewReceipt creates a new receipt
Expand Down
24 changes: 12 additions & 12 deletions test/gopayment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package test

import (
"github.com/mohammadv184/gopayment"
"github.com/mohammadv184/gopayment/drivers"
"github.com/mohammadv184/gopayment/errors"
"github.com/mohammadv184/gopayment/gateway"
"github.com/mohammadv184/gopayment/invoice"
"github.com/mohammadv184/gopayment/receipt"
"github.com/stretchr/testify/suite"
Expand All @@ -12,11 +12,11 @@ import (

type GoPaymentTestSuite struct {
suite.Suite
Gateway drivers.Driver
Gateway gateway.Driver
}

func (s *GoPaymentTestSuite) SetupTest() {
s.Gateway = &gateway{}
s.Gateway = &Gateway{}
}
func (s *GoPaymentTestSuite) TestCreatePayment() {
payment := gopayment.NewPayment(s.Gateway)
Expand All @@ -37,34 +37,34 @@ func (s *GoPaymentTestSuite) TestCreatePayment() {

s.Equal(payment.GetTransactionID(), payment.GetInvoice().GetTransactionID())
s.Equal("GET", payment.PayMethod())
s.Equal("gateway.com/"+payment.GetTransactionID(), payment.PayUrl())
s.Equal("Gateway.com/"+payment.GetTransactionID(), payment.PayURL())

}
func TestGoPaymentTestSuite(t *testing.T) {
suite.Run(t, new(GoPaymentTestSuite))
}

// gateway driver mock
type gateway struct {
// Gateway driver mock
type Gateway struct {
}

func (g gateway) GetDriverName() string {
func (g Gateway) GetDriverName() string {
return "MockGateway"
}
func (g *gateway) Purchase(invoice *invoice.Invoice) (string, error) {
func (g *Gateway) Purchase(invoice *invoice.Invoice) (string, error) {
if invoice.GetAmount() < 100 {
return "", errors.ErrPurchaseFailed{
Message: "amount is less than 100",
}
}
return invoice.GetUUID(), nil
}
func (g *gateway) PayUrl(invoice *invoice.Invoice) string {
return "gateway.com/" + invoice.GetTransactionID()
func (g *Gateway) PayURL(invoice *invoice.Invoice) string {
return "Gateway.com/" + invoice.GetTransactionID()
}
func (g *gateway) Verify(interface{}) (*receipt.Receipt, error) {
func (g *Gateway) Verify(interface{}) (*receipt.Receipt, error) {
return receipt.NewReceipt("test", g.GetDriverName()), nil
}
func (g *gateway) PayMethod() string {
func (g *Gateway) PayMethod() string {
return "GET"
}
4 changes: 2 additions & 2 deletions test/traits_detail_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package test

import (
"github.com/mohammadv184/gopayment/traits"
"github.com/mohammadv184/gopayment/trait"
"github.com/stretchr/testify/suite"
"testing"
)

type TraitsDetailTestSuite struct {
suite.Suite
ExampleObj struct {
traits.HasDetail
trait.HasDetail
}
}

Expand Down
2 changes: 1 addition & 1 deletion traits/detail.go → trait/detail.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package traits
package trait

import "fmt"

Expand Down

0 comments on commit 396cef2

Please sign in to comment.