Skip to content

Commit

Permalink
Modify struct names and gateways to be compatible with other Adyen libs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhutik committed Apr 5, 2017
1 parent b9f3679 commit fe9a3cb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 61 deletions.
11 changes: 8 additions & 3 deletions adyen.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ func (a *Adyen) execute(method string, requestEntity interface{}) (*http.Respons
return resp, nil
}

// Transaction - returns TransactionGateway
func (a *Adyen) Transaction() *TransactionGateway {
return &TransactionGateway{a}
// Payment - returns PaymentGateway
func (a *Adyen) Payment() *PaymentGateway {
return &PaymentGateway{a}
}

// Modification - returns ModificationGateway
func (a *Adyen) Modification() *ModificationGateway {
return &ModificationGateway{a}
}
15 changes: 15 additions & 0 deletions capture.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package adyen

// Capture structure for Capture request
type Capture struct {
ModificationAmount *Amount `json:"modificationAmount"`
Reference string `json:"reference"`
MerchantAccount string `json:"merchantAccount"`
OriginalReference string `json:"originalReference"`
}

// CaptureResponse is a response structure for Adyen capture
type CaptureResponse struct {
PspReference string `json:"pspReference"`
Response string `json:"response"`
}
4 changes: 2 additions & 2 deletions example/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func performPayment(w http.ResponseWriter, r *http.Request) {
Reference: "DE-100" + randomString(6),
}

g, err := instance.Transaction().Authorise(req)
g, err := instance.Payment().Authorise(req)

if err == nil {
fmt.Fprintf(w, "<h1>Success!</h1><code><pre>"+g.AuthCode+" "+g.PspReference+"</pre></code>")
Expand Down Expand Up @@ -113,7 +113,7 @@ func performCapture(w http.ResponseWriter, r *http.Request) {
OriginalReference: r.Form.Get("original-reference"),
}

g, err := instance.Transaction().Capture(req)
g, err := instance.Modification().Capture(req)

if err == nil {
fmt.Fprintf(w, "<h1>Success!</h1><code><pre>"+g.PspReference+" "+g.Response+"</pre></code>")
Expand Down
25 changes: 25 additions & 0 deletions modification_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package adyen

import "encoding/json"

// CaptureType - capture type request, @TODO: move to enums
const CaptureType = "capture"

// ModificationGateway - Adyen modification transaction logic, capture, cancel, refunds and e.t.c
type ModificationGateway struct {
*Adyen
}

// Capture - Perform capture payment in Adyen
func (a *ModificationGateway) Capture(req *Capture) (*CaptureResponse, error) {
resp, err := a.execute(CaptureType, req)

if err != nil {
return nil, err
}

var val CaptureResponse
json.NewDecoder(resp.Body).Decode(&val)

return &val, nil
}
14 changes: 0 additions & 14 deletions transaction.go → payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,3 @@ type AuthoriseResponse struct {
type AdditionalData struct {
Content string `json:"card.encrypted.json"`
}

// Capture structure for Capture request
type Capture struct {
ModificationAmount *Amount `json:"modificationAmount"`
Reference string `json:"reference"`
MerchantAccount string `json:"merchantAccount"`
OriginalReference string `json:"originalReference"`
}

// CaptureResponse is a response structure for Adyen capture
type CaptureResponse struct {
PspReference string `json:"pspReference"`
Response string `json:"response"`
}
25 changes: 25 additions & 0 deletions payment_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package adyen

import "encoding/json"

// PaymentGateway - Adyen payment transaction logic
type PaymentGateway struct {
*Adyen
}

// AuthoriseType - authorise type request, @TODO: move to enums
const AuthoriseType = "authorise"

// Authorise - Perform authorise payment in Adyen
func (a *PaymentGateway) Authorise(req *Authorise) (*AuthoriseResponse, error) {
resp, err := a.execute(AuthoriseType, req)

if err != nil {
return nil, err
}

var val AuthoriseResponse
json.NewDecoder(resp.Body).Decode(&val)

return &val, nil
}
42 changes: 0 additions & 42 deletions transaction_gateway.go

This file was deleted.

0 comments on commit fe9a3cb

Please sign in to comment.