forked from veritrans/go-midtrans
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fada1c
commit e74c4b5
Showing
5 changed files
with
186 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package midtrans | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
"strings" | ||
) | ||
|
||
// IrisGateway struct | ||
type IrisGateway struct { | ||
Client Client | ||
} | ||
|
||
// Call : base method to call Core API | ||
func (gateway *IrisGateway) Call(method, path string, body io.Reader, v interface{}) error { | ||
if !strings.HasPrefix(path, "/") { | ||
path = "/" + path | ||
} | ||
|
||
path = gateway.Client.APIEnvType.IrisURL() + path | ||
req, err := gateway.Client.NewRequest(method, path, body, gateway.Client.ApproverKey) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return gateway.Client.ExecuteRequest(req, v) | ||
} | ||
|
||
// CreateBeneficiaries : Perform transaction using ChargeReq | ||
func (gateway *IrisGateway) CreateBeneficiaries(req *BeneficiariesReq) (interface{}, error) { | ||
resp := make(map[string]interface{}) | ||
jsonReq, _ := json.Marshal(req) | ||
|
||
err := gateway.Call("POST", "api/v1/beneficiaries", bytes.NewBuffer(jsonReq), &resp) | ||
if err != nil { | ||
gateway.Client.Logger.Println("Error create beneficiaries: ", err) | ||
return resp, err | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
// ValidateBankAccount : get order status using order ID | ||
func (gateway *IrisGateway) ValidateBankAccount(bankName string, account string) (ValidateBankAcount, error) { | ||
resp := ValidateBankAcount{} | ||
|
||
err := gateway.Call("GET", "api/v1/account_validation?bank="+bankName+"&account="+account, nil, &resp) | ||
if err != nil { | ||
gateway.Client.Logger.Println("Error approving: ", err) | ||
return resp, err | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
// CaptureCard : Capture an authorized transaction for card payment | ||
func (gateway *IrisGateway) CaptureCard(req *CaptureReq) (Response, error) { | ||
resp := Response{} | ||
jsonReq, _ := json.Marshal(req) | ||
|
||
err := gateway.Call("POST", "v2/capture", bytes.NewBuffer(jsonReq), &resp) | ||
if err != nil { | ||
gateway.Client.Logger.Println("Error capturing: ", err) | ||
return resp, err | ||
} | ||
|
||
if resp.StatusMessage != "" { | ||
gateway.Client.Logger.Println(resp.StatusMessage) | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
// Approve : Approve order using order ID | ||
func (gateway *IrisGateway) Approve(orderID string) (Response, error) { | ||
resp := Response{} | ||
|
||
err := gateway.Call("POST", "v2/"+orderID+"/approve", nil, &resp) | ||
if err != nil { | ||
gateway.Client.Logger.Println("Error approving: ", err) | ||
return resp, err | ||
} | ||
|
||
if resp.StatusMessage != "" { | ||
gateway.Client.Logger.Println(resp.StatusMessage) | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
// Cancel : Cancel order using order ID | ||
func (gateway *IrisGateway) Cancel(orderID string) (Response, error) { | ||
resp := Response{} | ||
|
||
err := gateway.Call("POST", "v2/"+orderID+"/cancel", nil, &resp) | ||
if err != nil { | ||
gateway.Client.Logger.Println("Error approving: ", err) | ||
return resp, err | ||
} | ||
|
||
if resp.StatusMessage != "" { | ||
gateway.Client.Logger.Println(resp.StatusMessage) | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
// Expire : change order status to expired using order ID | ||
func (gateway *IrisGateway) Expire(orderID string) (Response, error) { | ||
resp := Response{} | ||
|
||
err := gateway.Call("POST", "v2/"+orderID+"/expire", nil, &resp) | ||
if err != nil { | ||
gateway.Client.Logger.Println("Error approving: ", err) | ||
return resp, err | ||
} | ||
|
||
if resp.StatusMessage != "" { | ||
gateway.Client.Logger.Println(resp.StatusMessage) | ||
} | ||
|
||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters