Skip to content

Commit

Permalink
Merge pull request #5 from fanchann/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
zakirkun authored May 11, 2024
2 parents 8509ffc + f2bf494 commit 5fa7bac
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 80 deletions.
163 changes: 162 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,162 @@
## Tripay Go
# Tripay Go (SDK tripay written in go)
## installation
```sh
go get github.com/zakirkun/go-tripay
```
## How To Use?

### register client
```go
c := client.Client{
MerchantCode: "T14302",
ApiKey: "your_api_key_here",
PrivateKey: "your_private_key_here",
Mode: utils.MODE_DEVELOPMENT,
}
```

### payment instruction
[docs](https://tripay.co.id/developer?tab=payment-instruction)
```go
req := client.InstructionRequestParam{
ChannelCode: utils.CHANNEL_BRIVA,
PayCode: "",
Amount: "10000",
AllowHtml: "",
}

response, err := c.Instruction(req)
if err != nil {
// do something
}
// do something
```

### payment channel
[docs](https://tripay.co.id/developer?tab=merchant-payment-channel)
```go
response, err := c.MerchantPay()
if err != nil {
// do something
}
// do something
```

### fee calculation
[docs](https://tripay.co.id/developer?tab=merchant-fee-calculator)
```go

feeCalcParam := client.FeeCalcParam{
Amount: 100000,
Code: utils.CHANNEL_ALFAMIDI,
}

response, err := c.FeeCalc(feeCalcParam)
if err != nil {
// do something
}
// do something
```

### list transactions
[docs](https://tripay.co.id/developer?tab=merchant-transactions)
```go
merchanTransactionParam := client.MerchantTransactionsParam{
Page: 1,
PerPage: 10,
Sort: "asc", // asc or desc
Reference: "reference",
MerchantRef: "merchant_ref",
Method: utils.CHANNEL_BCAVA,
Status: "status",
}

response, err := c.MerchantTransactions(merchanTransactionParam)
if err != nil {
// do something
}
// do something
```

## close payment
### request transaction
[docs](https://tripay.co.id/developer?tab=transaction-create)
```go
signStr := utils.Signature{
Amount: 50000,
PrivateKey: "your_private_key_here",
MerchantCode: "T14302",
MerchanReff: "INV345675",
}

c.SetSignature(signStr)

bodyReq := client.ClosePaymentBodyRequest{
Method: utils.CHANNEL_QRIS_SHOPEEPAY,
MerchantRef: "INV345675",
Amount: 50000,
CustomerName: "Farda Ayu Nurfatika",
CustomerEmail: "[email protected]",
CustomerPhone: "6285111990223",
ReturnURL: "https://thisisreturnurl.com/redirect",
ExpiredTime: client.SetTripayExpiredTime(24), // 24 Hour
Signature: c.GetSignature(),
OrderItems: []client.OrderItemClosePaymentRequest{
{
SKU: "Produk1",
Name: "nama produk 1",
Price: 50000,
Quantity: 1,
ProductURL: "https://producturl.com",
ImageURL: "https://imageurl.com",
},
},
}

response, err := c.ClosePaymentRequestTransaction(bodyReq)
if err != nil {
// do something
}
// do something
```
### get detail transaction
[docs](https://tripay.co.id/developer?tab=transaction-detail)
```go
signStr := utils.Signature{
Amount: 50000,
PrivateKey: "your_private_key_here",
MerchantCode: "T14302",
MerchanReff: "INV345675",
}

c.SetSignature(signStr)

referenceId := "your_reference_id"
response, err := c.ClosePaymentTransactionGetDetail(referenceId)
if err != nil {
// do something
}
// do something
```

## open payment
```go
c.SetSignature(utils.Signature{
MerchantCode: "T14302",
Channel: "BCAVA",
MerchanReff: "INV345675",
})

payment := client.OpenPaymentRequest{
Method: "BCAVA",
MerchatReff: "INV345675",
CustomerName: "Fulan Fulan",
Signature: c.GetSignature(),
}

response, err := c.OpenPaymentTransaction(payment)
if err != nil {
// do something
}
// do something
```
5 changes: 3 additions & 2 deletions client/merchant_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"

"github.com/zakirkun/go-tripay/internal/requester"
"github.com/zakirkun/go-tripay/utils"
)

type (
Expand All @@ -16,7 +17,7 @@ type (
Sort string
Reference string
MerchantRef string
Method string
Method utils.TRIPAY_CHANNEL
Status string
}
)
Expand Down Expand Up @@ -62,7 +63,7 @@ func merchantTransactions(c Client, ctx context.Context, p ...MerchantTransactio
urlParam.Set("sort", merchatsParams.Sort)
urlParam.Set("reference", merchatsParams.Reference)
urlParam.Set("merchant_ref", merchatsParams.MerchantRef)
urlParam.Set("method", merchatsParams.Method)
urlParam.Set("method", string(merchatsParams.Method))
urlParam.Set("status", merchatsParams.Status)

paramReq := requester.IRequesterParams{
Expand Down
93 changes: 17 additions & 76 deletions client/open_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,6 @@ type OpenPaymentRequest struct {
Signature string `json:"signature"`
}

type OpenPaymentResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
OpenPaymentData struct {
UUID string `json:"uuid"`
MerchantRef string `json:"merchant_ref"`
CustomerName string `json:"customer_name"`
PaymentName string `json:"payment_name"`
PaymentMethod string `json:"payment_method"`
PayCode string `json:"pay_code"`
QRString string `json:"qr_string"`
QRURL string `json:"qr_url"`
} `json:"data"`
}

type OpenPaymentDetailResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
OpenPaymentDetailData struct {
UUID string `json:"uuid"`
MerchantRef string `json:"merchant_ref"`
CustomerName string `json:"customer_name"`
PaymentName string `json:"payment_name"`
PaymentMethod string `json:"payment_method"`
PayCode string `json:"pay_code"`
QRString string `json:"qr_string,omitempty"`
QRURL string `json:"qr_url,omitempty"`
} `json:"data"`
}

type OpenPaymentListParams struct {
Page int
PerPage int
Expand All @@ -56,82 +26,53 @@ type OpenPaymentListParams struct {
Status string
}

type OpenPaymentListResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
OpenPaymentTransaction []struct {
Reference string `json:"reference"`
MerchantRef string `json:"merchant_ref"`
PaymentMethod string `json:"payment_method"`
PaymentName string `json:"payment_name"`
CustomerName string `json:"customer_name"`
Amount int `json:"amount"`
FeeMerchant int `json:"fee_merchant"`
FeeCustomer int `json:"fee_customer"`
TotalFee int `json:"total_fee"`
AmountReceived int `json:"amount_received"`
CheckoutURL string `json:"checkout_url"`
Status string `json:"status"`
PaidAt int64 `json:"paid_at"`
} `json:"data"`
Pagination struct {
Total int `json:"total"`
DataFrom int `json:"data_from"`
DataTo int `json:"data_to"`
PerPage int `json:"per_page"`
CurrentPage int `json:"current_page"`
LastPage int `json:"last_page"`
NextPage *int `json:"next_page"`
} `json:"pagination"`
}

/*
is used to retrieve the list of payments entered in the open payment. this method only work in production!
*/
func (c Client) OpenPaymentDetail(uuid string) (*OpenPaymentDetailResponse, error) {
func (c Client) OpenPaymentDetail(uuid string) (tripayResponses[openPaymentDetailResponse], error) {
return openPaymentDetail(c, uuid, nil)
}

/*
is used to retrieve the list of payments entered in the open payment. this method only work in production!
*/
func (c Client) OpenPaymentDetailWithContext(uuid string, ctx context.Context) (*OpenPaymentDetailResponse, error) {
func (c Client) OpenPaymentDetailWithContext(uuid string, ctx context.Context) (tripayResponses[openPaymentDetailResponse], error) {
return openPaymentDetail(c, uuid, ctx)
}

/*
Used to create a new transaction or generate a payment code for Open Payment type. this method only work in production!
*/
func (c Client) OpenPaymentTransaction(p OpenPaymentRequest) (*OpenPaymentResponse, error) {
func (c Client) OpenPaymentTransaction(p OpenPaymentRequest) (tripayResponses[openPaymentDataResponse], error) {
return openPayment(c, p, nil)
}

/*
Used to create a new transaction or generate a payment code for Open Payment type. this method only work in production!
*/
func (c Client) OpenPaymentTransactionWithContext(p OpenPaymentRequest, ctx context.Context) (*OpenPaymentResponse, error) {
func (c Client) OpenPaymentTransactionWithContext(p OpenPaymentRequest, ctx context.Context) (tripayResponses[openPaymentDataResponse], error) {
return openPayment(c, p, ctx)
}

/*
used to retrieve details of open payment transactions that have been made. this method only work in production!
*/
func (c Client) OpenPaymentList(uuid string, p ...OpenPaymentListParams) (*OpenPaymentListResponse, error) {
func (c Client) OpenPaymentList(uuid string, p ...OpenPaymentListParams) (*openPaymentListResponse, error) {
return openPaymentList(c, uuid, nil, p...)
}

/*
used to retrieve details of open payment transactions that have been made. this method only work in production!
*/
func (c Client) OpenPaymentListWithContext(uuid string, ctx context.Context, p ...OpenPaymentListParams) (*OpenPaymentListResponse, error) {
func (c Client) OpenPaymentListWithContext(uuid string, ctx context.Context, p ...OpenPaymentListParams) (*openPaymentListResponse, error) {
return openPaymentList(c, uuid, ctx, p...)
}

func openPayment(c Client, p OpenPaymentRequest, ctx context.Context) (*OpenPaymentResponse, error) {
func openPayment(c Client, p OpenPaymentRequest, ctx context.Context) (tripayResponses[openPaymentDataResponse], error) {

payloadBody, err := json.Marshal(&p)
if err != nil {
return nil, err
return tripayResponses[openPaymentDataResponse]{}, err
}

paramReq := requester.IRequesterParams{
Expand All @@ -151,15 +92,15 @@ func openPayment(c Client, p OpenPaymentRequest, ctx context.Context) (*OpenPaym
}

if errReq != nil {
return nil, errReq
return tripayResponses[openPaymentDataResponse]{}, errReq
}

var successResponse OpenPaymentResponse
var successResponse tripayResponses[openPaymentDataResponse]
json.Unmarshal(bodyReq.ResponseBody, &successResponse)
return &successResponse, nil
return successResponse, nil
}

func openPaymentDetail(c Client, uuid string, ctx context.Context) (*OpenPaymentDetailResponse, error) {
func openPaymentDetail(c Client, uuid string, ctx context.Context) (tripayResponses[openPaymentDetailResponse], error) {

paramReq := requester.IRequesterParams{
Url: c.BaseUrl() + "open-payment/" + uuid + "/detail",
Expand All @@ -178,15 +119,15 @@ func openPaymentDetail(c Client, uuid string, ctx context.Context) (*OpenPayment
}

if errReq != nil {
return nil, errReq
return tripayResponses[openPaymentDetailResponse]{}, errReq
}

var successResponse OpenPaymentDetailResponse
var successResponse tripayResponses[openPaymentDetailResponse]
json.Unmarshal(bodyReq.ResponseBody, &successResponse)
return &successResponse, nil
return successResponse, nil
}

func openPaymentList(c Client, uuid string, ctx context.Context, p ...OpenPaymentListParams) (*OpenPaymentListResponse, error) {
func openPaymentList(c Client, uuid string, ctx context.Context, p ...OpenPaymentListParams) (*openPaymentListResponse, error) {

var paymentParams OpenPaymentListParams
for _, m := range p {
Expand Down Expand Up @@ -222,7 +163,7 @@ func openPaymentList(c Client, uuid string, ctx context.Context, p ...OpenPaymen
return nil, errReq
}

var response OpenPaymentListResponse
var response openPaymentListResponse
json.Unmarshal(bodyReq.ResponseBody, &response)
return &response, nil

Expand Down
Loading

0 comments on commit 5fa7bac

Please sign in to comment.