From 78694b59a45be162a274433a55e3b109b9b1a373 Mon Sep 17 00:00:00 2001 From: fanchann Date: Thu, 9 May 2024 18:36:40 +0700 Subject: [PATCH 1/8] add: implement close payment, but got invalid signature --- client/close_payment_transaction.go | 123 +++++++++++++++++++++++ client/close_payment_transaction_test.go | 52 ++++++++++ utils/signature.go | 2 +- 3 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 client/close_payment_transaction.go create mode 100644 client/close_payment_transaction_test.go diff --git a/client/close_payment_transaction.go b/client/close_payment_transaction.go new file mode 100644 index 0000000..a31cd86 --- /dev/null +++ b/client/close_payment_transaction.go @@ -0,0 +1,123 @@ +package client + +import ( + "context" + "encoding/json" + "fmt" + "time" + + "github.com/zakirkun/go-tripay/internal/requester" + "github.com/zakirkun/go-tripay/utils" +) + +type TripayExpiredTime int + +type ClosePaymentRequestTransactionResponse struct { + Success bool `json:"success"` + Message string `json:"message"` + Data ClosePaymentTransactionOrder `json:"data"` +} + +type ClosePaymentTransactionOrder struct { + Reference string `json:"reference"` + MerchantRef string `json:"merchant_ref"` + PaymentSelectionType string `json:"payment_selection_type"` + PaymentMethod string `json:"payment_method"` + PaymentName string `json:"payment_name"` + CustomerName string `json:"customer_name"` + CustomerEmail string `json:"customer_email"` + CustomerPhone string `json:"customer_phone"` + CallbackURL string `json:"callback_url"` + ReturnURL string `json:"return_url"` + Amount int `json:"amount"` + FeeMerchant int `json:"fee_merchant"` + FeeCustomer int `json:"fee_customer"` + TotalFee int `json:"total_fee"` + AmountReceived int `json:"amount_received"` + PayCode string `json:"pay_code"` + PayURL interface{} `json:"pay_url"` + CheckoutURL string `json:"checkout_url"` + Status string `json:"status"` + ExpiredTime int `json:"expired_time"` + OrderItems []ClosePaymentTransactionOrderItem `json:"order_items"` + Instructions []Instruction `json:"instructions"` + QRString interface{} `json:"qr_string"` + QRURL interface{} `json:"qr_url"` +} + +type ClosePaymentTransactionOrderItem struct { + SKU string `json:"sku"` + Name string `json:"name"` + Price int `json:"price"` + Quantity int `json:"quantity"` + Subtotal int `json:"subtotal"` + ProductURL string `json:"product_url"` + ImageURL string `json:"image_url"` +} + +type Instruction struct { + Title string `json:"title"` + Steps []string `json:"steps"` +} + +type ClosePaymentBodyRequest struct { + Method utils.TRIPAY_CHANNEL `json:"method"` + MerchantRef string `json:"merchant_ref"` + Amount int `json:"amount"` + CustomerName string `json:"customer_name"` + CustomerEmail string `json:"customer_email"` + CustomerPhone string `json:"customer_phone"` + OrderItems []OrderItemClosePaymentRequest `json:"order_items"` + ReturnURL string `json:"return_url"` + ExpiredTime TripayExpiredTime `json:"expired_time"` + Signature string `json:"signature"` +} + +type OrderItemClosePaymentRequest struct { + SKU string `json:"sku"` + Name string `json:"name"` + Price int `json:"price"` + Quantity int `json:"quantity"` + ProductURL string `json:"product_url"` + ImageURL string `json:"image_url"` +} + +func (c Client) ClosePaymentRequestTransaction(ctx context.Context, req ClosePaymentBodyRequest) (*ClosePaymentRequestTransactionResponse, error) { + return closePaymentRequestTransaction(c, nil, req) +} + +func (c Client) ClosePaymentRequestTransactionWithContext(ctx context.Context, req ClosePaymentBodyRequest) (*ClosePaymentRequestTransactionResponse, error) { + return closePaymentRequestTransaction(c, ctx, req) +} + +func closePaymentRequestTransaction(c Client, ctx context.Context, reqBody ClosePaymentBodyRequest) (*ClosePaymentRequestTransactionResponse, error) { + reqBodyByte, _ := json.Marshal(&reqBody) + paramReq := requester.IRequesterParams{ + Url: c.BaseUrl() + "transaction/create", + Method: "POST", + Body: reqBodyByte, + Header: c.HeaderRequest(), + } + fmt.Printf("reqBodyByte: %v\n", string(reqBodyByte)) + + req := requester.NewRequester(paramReq) + bodyReq := new(requester.IResponseBody) + var errReq error + if ctx != nil { + bodyReq, errReq = req.DOWithContext(ctx) + } else { + bodyReq, errReq = req.DO() + } + + if errReq != nil { + return nil, errReq + } + + var successResponse ClosePaymentRequestTransactionResponse + json.Unmarshal(bodyReq.ResponseBody, &successResponse) + return &successResponse, nil +} + +func SetTripayExpiredTime(hour int) TripayExpiredTime { + return TripayExpiredTime(int(time.Now().Unix()) + (hour * 60 * 60)) +} diff --git a/client/close_payment_transaction_test.go b/client/close_payment_transaction_test.go new file mode 100644 index 0000000..7ed9eed --- /dev/null +++ b/client/close_payment_transaction_test.go @@ -0,0 +1,52 @@ +package client + +import ( + "context" + "testing" + + "github.com/zakirkun/go-tripay/utils" +) + +func TestClosePaymentTransactionRequestSuccess(t *testing.T) { + client := Client{ + MerchantCode: "T14302", + ApiKey: "DEV-ZKIDl5gE3AsCDThj7mWX6yvQ8f42NZWJWlZ7TSzS", + PrivateKey: "J2WTm-93avv-w0PZV-ur1t4-4TCjd", + Mode: utils.MODE_DEVELOPMENT, + } + + s := utils.Signature{ + Amount: 10, + PrivateKey: "J2WTm-93avv-w0PZV-ur1t4-4TCjd", + MerchantCode: "T0001", + MerchanReff: "INV345675", + } + + bodyReq := ClosePaymentBodyRequest{ + Method: utils.CHANNEL_BCAVA, + MerchantRef: "INV345675", + Amount: 50000, + CustomerName: "John Doe", + CustomerEmail: "johndoe@gmail.com", + CustomerPhone: "62891829828", + ReturnURL: "https://thisisreturnurl.com/redirect", + ExpiredTime: SetTripayExpiredTime(24), // 24 Hour + Signature: s.CreateSignature(), + OrderItems: []OrderItemClosePaymentRequest{ + { + SKU: "Produk1", + Name: "nama produk 1", + Price: 50000, + Quantity: 10, + ProductURL: "https://producturl.com", + ImageURL: "https://imageurl.com", + }, + }, + } + reponseOk, responseBad := client.ClosePaymentRequestTransaction(context.Background(), bodyReq) + if responseBad != nil { + t.Errorf("ERROR: %v", responseBad) + } + + t.Log("Success: ", reponseOk) +} diff --git a/utils/signature.go b/utils/signature.go index b13da0c..07e2c8e 100644 --- a/utils/signature.go +++ b/utils/signature.go @@ -22,7 +22,7 @@ type Signature struct { func (s *Signature) CreateSignature() string { var signStr string if s.Amount != 0 { - signStr = s.MerchantCode + s.MerchanReff + fmt.Sprint(s.Amount) + signStr = s.MerchantCode + s.MerchanReff + fmt.Sprintf("%d", s.Amount) } else { signStr = s.MerchantCode + s.Channel + s.MerchanReff } From b27a20d7bd87b1d338ed3dd6cfe3da3e8a04e0eb Mon Sep 17 00:00:00 2001 From: fanchann Date: Thu, 9 May 2024 20:32:08 +0700 Subject: [PATCH 2/8] chore: delete duplicate code --- client/close_payment_transaction_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/close_payment_transaction_test.go b/client/close_payment_transaction_test.go index 7ed9eed..b6b9120 100644 --- a/client/close_payment_transaction_test.go +++ b/client/close_payment_transaction_test.go @@ -37,7 +37,7 @@ func TestClosePaymentTransactionRequestSuccess(t *testing.T) { SKU: "Produk1", Name: "nama produk 1", Price: 50000, - Quantity: 10, + Quantity: 1, ProductURL: "https://producturl.com", ImageURL: "https://imageurl.com", }, From a4511ff98fe92e98daae1cd67d0918e4fb270630 Mon Sep 17 00:00:00 2001 From: fanchann Date: Thu, 9 May 2024 21:48:39 +0700 Subject: [PATCH 3/8] style: make struct readable --- client/close_payment_transaction.go | 171 +++++++++++++++++----------- 1 file changed, 103 insertions(+), 68 deletions(-) diff --git a/client/close_payment_transaction.go b/client/close_payment_transaction.go index a31cd86..78db6d6 100644 --- a/client/close_payment_transaction.go +++ b/client/close_payment_transaction.go @@ -10,76 +10,84 @@ import ( "github.com/zakirkun/go-tripay/utils" ) -type TripayExpiredTime int +type ( + TripayExpiredTime int + ClosePaymentRequestTransactionResponse struct { + Success bool `json:"success"` + Message string `json:"message"` + Data ClosePaymentTransactionOrder `json:"data"` + } -type ClosePaymentRequestTransactionResponse struct { - Success bool `json:"success"` - Message string `json:"message"` - Data ClosePaymentTransactionOrder `json:"data"` -} + ClosePaymentTransactionOrder struct { + Reference string `json:"reference"` + MerchantRef string `json:"merchant_ref"` + PaymentSelectionType string `json:"payment_selection_type"` + PaymentMethod string `json:"payment_method"` + PaymentName string `json:"payment_name"` + CustomerName string `json:"customer_name"` + CustomerEmail string `json:"customer_email"` + CustomerPhone string `json:"customer_phone"` + CallbackURL string `json:"callback_url"` + ReturnURL string `json:"return_url"` + Amount int `json:"amount"` + FeeMerchant int `json:"fee_merchant"` + FeeCustomer int `json:"fee_customer"` + TotalFee int `json:"total_fee"` + AmountReceived int `json:"amount_received"` + PayCode string `json:"pay_code"` + PayURL interface{} `json:"pay_url"` + CheckoutURL string `json:"checkout_url"` + Status string `json:"status"` + ExpiredTime int `json:"expired_time"` + OrderItems []ClosePaymentTransactionOrderItem `json:"order_items"` + Instructions []Instruction `json:"instructions"` + QRString interface{} `json:"qr_string"` + QRURL interface{} `json:"qr_url"` + } -type ClosePaymentTransactionOrder struct { - Reference string `json:"reference"` - MerchantRef string `json:"merchant_ref"` - PaymentSelectionType string `json:"payment_selection_type"` - PaymentMethod string `json:"payment_method"` - PaymentName string `json:"payment_name"` - CustomerName string `json:"customer_name"` - CustomerEmail string `json:"customer_email"` - CustomerPhone string `json:"customer_phone"` - CallbackURL string `json:"callback_url"` - ReturnURL string `json:"return_url"` - Amount int `json:"amount"` - FeeMerchant int `json:"fee_merchant"` - FeeCustomer int `json:"fee_customer"` - TotalFee int `json:"total_fee"` - AmountReceived int `json:"amount_received"` - PayCode string `json:"pay_code"` - PayURL interface{} `json:"pay_url"` - CheckoutURL string `json:"checkout_url"` - Status string `json:"status"` - ExpiredTime int `json:"expired_time"` - OrderItems []ClosePaymentTransactionOrderItem `json:"order_items"` - Instructions []Instruction `json:"instructions"` - QRString interface{} `json:"qr_string"` - QRURL interface{} `json:"qr_url"` -} + ClosePaymentTransactionOrderItem struct { + SKU string `json:"sku"` + Name string `json:"name"` + Price int `json:"price"` + Quantity int `json:"quantity"` + Subtotal int `json:"subtotal"` + ProductURL string `json:"product_url"` + ImageURL string `json:"image_url"` + } -type ClosePaymentTransactionOrderItem struct { - SKU string `json:"sku"` - Name string `json:"name"` - Price int `json:"price"` - Quantity int `json:"quantity"` - Subtotal int `json:"subtotal"` - ProductURL string `json:"product_url"` - ImageURL string `json:"image_url"` -} + Instruction struct { + Title string `json:"title"` + Steps []string `json:"steps"` + } + ClosePaymentBodyRequest struct { + Method utils.TRIPAY_CHANNEL `json:"method"` + MerchantRef string `json:"merchant_ref"` + Amount int `json:"amount"` + CustomerName string `json:"customer_name"` + CustomerEmail string `json:"customer_email"` + CustomerPhone string `json:"customer_phone"` + OrderItems []OrderItemClosePaymentRequest `json:"order_items"` + ReturnURL string `json:"return_url"` + ExpiredTime TripayExpiredTime `json:"expired_time"` + Signature string `json:"signature"` + } -type Instruction struct { - Title string `json:"title"` - Steps []string `json:"steps"` -} + OrderItemClosePaymentRequest struct { + SKU string `json:"sku"` + Name string `json:"name"` + Price int `json:"price"` + Quantity int `json:"quantity"` + ProductURL string `json:"product_url"` + ImageURL string `json:"image_url"` + } -type ClosePaymentBodyRequest struct { - Method utils.TRIPAY_CHANNEL `json:"method"` - MerchantRef string `json:"merchant_ref"` - Amount int `json:"amount"` - CustomerName string `json:"customer_name"` - CustomerEmail string `json:"customer_email"` - CustomerPhone string `json:"customer_phone"` - OrderItems []OrderItemClosePaymentRequest `json:"order_items"` - ReturnURL string `json:"return_url"` - ExpiredTime TripayExpiredTime `json:"expired_time"` - Signature string `json:"signature"` -} + TransactionDetailBodyRequest struct { + Reference string + } +) -type OrderItemClosePaymentRequest struct { - SKU string `json:"sku"` - Name string `json:"name"` - Price int `json:"price"` - Quantity int `json:"quantity"` - ProductURL string `json:"product_url"` - ImageURL string `json:"image_url"` +func SetTripayExpiredTime(hour int) TripayExpiredTime { + return TripayExpiredTime(int(time.Now().Unix()) + (hour * 60 * 60)) } func (c Client) ClosePaymentRequestTransaction(ctx context.Context, req ClosePaymentBodyRequest) (*ClosePaymentRequestTransactionResponse, error) { @@ -98,8 +106,6 @@ func closePaymentRequestTransaction(c Client, ctx context.Context, reqBody Close Body: reqBodyByte, Header: c.HeaderRequest(), } - fmt.Printf("reqBodyByte: %v\n", string(reqBodyByte)) - req := requester.NewRequester(paramReq) bodyReq := new(requester.IResponseBody) var errReq error @@ -118,6 +124,35 @@ func closePaymentRequestTransaction(c Client, ctx context.Context, reqBody Close return &successResponse, nil } -func SetTripayExpiredTime(hour int) TripayExpiredTime { - return TripayExpiredTime(int(time.Now().Unix()) + (hour * 60 * 60)) +func (c Client) ClosePaymentTransactionGetDetail(reference string) (*ClosePaymentRequestTransactionResponse, error) { + return closePaymentTransactionGetDetail(c, nil, reference) +} + +func (c Client) ClosePaymentTransactionGetDetailWithContext(ctx context.Context, reference string) (*ClosePaymentRequestTransactionResponse, error) { + return closePaymentTransactionGetDetail(c, ctx, reference) +} + +func closePaymentTransactionGetDetail(c Client, ctx context.Context, reference string) (*ClosePaymentRequestTransactionResponse, error) { + paramReq := requester.IRequesterParams{ + Url: c.BaseUrl() + "transaction/detail?" + fmt.Sprintf("reference=%s", reference), + Method: "GET", + Body: nil, + Header: c.HeaderRequest(), + } + req := requester.NewRequester(paramReq) + bodyReq := new(requester.IResponseBody) + var errReq error + if ctx != nil { + bodyReq, errReq = req.DOWithContext(ctx) + } else { + bodyReq, errReq = req.DO() + } + + if errReq != nil { + return nil, errReq + } + + var successResponse ClosePaymentRequestTransactionResponse + json.Unmarshal(bodyReq.ResponseBody, &successResponse) + return &successResponse, nil } From 62a6cfc3e59ffd380a19a37bcace209f22526c59 Mon Sep 17 00:00:00 2001 From: fanchann Date: Thu, 9 May 2024 21:49:22 +0700 Subject: [PATCH 4/8] test: unit test close payment --- client/close_payment_transaction_test.go | 38 +++++++++++++++++------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/client/close_payment_transaction_test.go b/client/close_payment_transaction_test.go index b6b9120..2bca0c3 100644 --- a/client/close_payment_transaction_test.go +++ b/client/close_payment_transaction_test.go @@ -7,7 +7,7 @@ import ( "github.com/zakirkun/go-tripay/utils" ) -func TestClosePaymentTransactionRequestSuccess(t *testing.T) { +func TestClosePaymentTransactionRequest(t *testing.T) { client := Client{ MerchantCode: "T14302", ApiKey: "DEV-ZKIDl5gE3AsCDThj7mWX6yvQ8f42NZWJWlZ7TSzS", @@ -15,12 +15,12 @@ func TestClosePaymentTransactionRequestSuccess(t *testing.T) { Mode: utils.MODE_DEVELOPMENT, } - s := utils.Signature{ - Amount: 10, + client.SetSignature(utils.Signature{ + Amount: 50000, PrivateKey: "J2WTm-93avv-w0PZV-ur1t4-4TCjd", - MerchantCode: "T0001", + MerchantCode: "T14302", MerchanReff: "INV345675", - } + }) bodyReq := ClosePaymentBodyRequest{ Method: utils.CHANNEL_BCAVA, @@ -31,7 +31,7 @@ func TestClosePaymentTransactionRequestSuccess(t *testing.T) { CustomerPhone: "62891829828", ReturnURL: "https://thisisreturnurl.com/redirect", ExpiredTime: SetTripayExpiredTime(24), // 24 Hour - Signature: s.CreateSignature(), + Signature: client.GetSignature(), OrderItems: []OrderItemClosePaymentRequest{ { SKU: "Produk1", @@ -43,10 +43,28 @@ func TestClosePaymentTransactionRequestSuccess(t *testing.T) { }, }, } - reponseOk, responseBad := client.ClosePaymentRequestTransaction(context.Background(), bodyReq) - if responseBad != nil { - t.Errorf("ERROR: %v", responseBad) + response, err := client.ClosePaymentRequestTransaction(context.Background(), bodyReq) + if err != nil { + t.Errorf("ERROR: %v", err) + } + + t.Log("Success: ", response) +} + +func TestClosePaymentTransactionGetTransaction(t *testing.T) { + referenceId := "DEV-T14302154794FZ2ZT" + + client := Client{ + MerchantCode: "T14302", + ApiKey: "DEV-ZKIDl5gE3AsCDThj7mWX6yvQ8f42NZWJWlZ7TSzS", + PrivateKey: "J2WTm-93avv-w0PZV-ur1t4-4TCjd", + Mode: utils.MODE_DEVELOPMENT, + } + + response, err := client.ClosePaymentTransactionGetDetail(referenceId) + if err != nil { + t.Errorf("ERROR: %v", err) } - t.Log("Success: ", reponseOk) + t.Log("Success: ", response) } From 3b600db68490fd6facdf6413762bf8e75648868d Mon Sep 17 00:00:00 2001 From: fanchann Date: Fri, 10 May 2024 18:57:20 +0700 Subject: [PATCH 5/8] add: example --- _examples/close_payment.go | 88 +++++++++++++++++++++++++++ _examples/merchant_fee_calc.go | 33 ++++++++++ _examples/merchant_payment_channel.go | 27 ++++++++ _examples/merchant_transactions.go | 52 ++++++++++++++++ _examples/open_payment.go | 16 ++--- 5 files changed, 208 insertions(+), 8 deletions(-) create mode 100644 _examples/close_payment.go create mode 100644 _examples/merchant_fee_calc.go create mode 100644 _examples/merchant_payment_channel.go create mode 100644 _examples/merchant_transactions.go diff --git a/_examples/close_payment.go b/_examples/close_payment.go new file mode 100644 index 0000000..d2f87fc --- /dev/null +++ b/_examples/close_payment.go @@ -0,0 +1,88 @@ +package examples + +import ( + "fmt" + + "github.com/zakirkun/go-tripay/client" + "github.com/zakirkun/go-tripay/utils" +) + +func Example_close_payment_req_transaction() { + c := client.Client{ + MerchantCode: "T14302", + ApiKey: "your_api_key_here", + PrivateKey: "your_private_key_here", + Mode: utils.MODE_DEVELOPMENT, + } + + 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: "fardaayu@gmail.com", + 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 { + panic(err) + } + + fmt.Printf("response: %v\n", response) + /* + response : + &{true {DEV-T14302154834TY1ML INV345675 static QRIS_SHOPEEPAY QRIS Custom by ShopeePay Farda Ayu Nurfatika fardaayu@gmail.com https://thisisreturnurl.com/redirect 50000 1100 0 1100 48900 https://tripay.co.id/checkout/DEV-T14302154834TY1ML UNPAID 1715343068 [{Produk1 nama produk 1 50000 1 50000 https://producturl.com https://imageurl.com}] [{Pembayaran via QRIS [Masuk ke aplikasi dompet digital Anda yang telah mendukung QRIS Pindai/Scan QR Code yang tersedia Akan muncul detail transaksi. Pastikan data transaksi sudah sesuai Selesaikan proses pembayaran Anda Transaksi selesai. Simpan bukti pembayaran Anda]} {Pembayaran via QRIS (Mobile) [Download QR Code pada invoice Masuk ke aplikasi dompet digital Anda yang telah mendukung QRIS Upload QR Code yang telah di download tadi Akan muncul detail transaksi. Pastikan data transaksi sudah sesuai Selesaikan proses pembayaran Anda Transaksi selesai. Simpan bukti pembayaran Anda]}] SANDBOX MODE https://tripay.co.id/qr/DEV-T14302154834TY1ML}} + */ +} + +func Example_close_payment_get_detail_transaction() { + c := client.Client{ + MerchantCode: "T14302", + ApiKey: "your_api_key_here", + PrivateKey: "your_private_key_here", + Mode: utils.MODE_DEVELOPMENT, + } + + signStr := utils.Signature{ + Amount: 50000, + PrivateKey: "your_private_key_here", + MerchantCode: "T14302", + MerchanReff: "INV345675", + } + + c.SetSignature(signStr) + + referenceId := "DEV-T14302154834TY1ML" + response, err := c.ClosePaymentTransactionGetDetail(referenceId) + if err != nil { + panic(err) + } + fmt.Printf("response: %v\n", response) + /* + response : + &{true Transaction found {DEV-T14302154834TY1ML INV345675 static QRIS_SHOPEEPAY QRIS Custom by ShopeePay Farda Ayu Nurfatika fardaayu@gmail.com https://thisisreturnurl.com/redirect 50000 1100 0 1100 48900 https://tripay.co.id/checkout/DEV-T14302154834TY1ML UNPAID 1715343068 [{Produk1 nama produk 1 50000 1 50000 https://producturl.com https://imageurl.com}] [{Pembayaran via QRIS [Masuk ke aplikasi dompet digital Anda yang telah mendukung QRIS Pindai/Scan QR Code yang tersedia Akan muncul detail transaksi. Pastikan data transaksi sudah sesuai Selesaikan proses pembayaran Anda Transaksi selesai. Simpan bukti pembayaran Anda]} {Pembayaran via QRIS (Mobile) [Download QR Code pada invoice Masuk ke aplikasi dompet digital Anda yang telah mendukung QRIS Upload QR Code yang telah di download tadi Akan muncul detail transaksi. Pastikan data transaksi sudah sesuai Selesaikan proses pembayaran Anda Transaksi selesai. Simpan bukti pembayaran Anda]}] SANDBOX MODE https://tripay.co.id/qr/DEV-T14302154834TY1ML}} + */ +} diff --git a/_examples/merchant_fee_calc.go b/_examples/merchant_fee_calc.go new file mode 100644 index 0000000..853bb21 --- /dev/null +++ b/_examples/merchant_fee_calc.go @@ -0,0 +1,33 @@ +package examples + +import ( + "fmt" + + "github.com/zakirkun/go-tripay/client" + "github.com/zakirkun/go-tripay/utils" +) + +func Example_merchant_fee_calculator() { + c := client.Client{ + MerchantCode: "T14302", + ApiKey: "your_api_key_here", + PrivateKey: "your_private_key_here", + Mode: utils.MODE_DEVELOPMENT, + } + + feeCalcParam := client.FeeCalcParam{ + Amount: 100000, + Code: utils.CHANNEL_ALFAMIDI, + } + + response, err := c.FeeCalc(feeCalcParam) + if err != nil { + panic(err) + } + + fmt.Printf("response: %v\n", response) + /* + response: + &{true [{ALFAMIDI Alfamidi {3500 0.00 } {3500 0}}]} + */ +} diff --git a/_examples/merchant_payment_channel.go b/_examples/merchant_payment_channel.go new file mode 100644 index 0000000..0d68552 --- /dev/null +++ b/_examples/merchant_payment_channel.go @@ -0,0 +1,27 @@ +package examples + +import ( + "fmt" + + "github.com/zakirkun/go-tripay/client" + "github.com/zakirkun/go-tripay/utils" +) + +func Example_merchant_payment_channel() { + c := client.Client{ + MerchantCode: "T14302", + ApiKey: "your_api_key_here", + PrivateKey: "your_private_key_here", + Mode: utils.MODE_DEVELOPMENT, + } + + response, err := c.MerchantPay() + if err != nil { + panic(err) + } + fmt.Printf("response: %v\n", response) + /* + response: + &{true Success [{Virtual Account MYBVA Maybank Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/ZT91lrOEad1582929126.png true} {Virtual Account PERMATAVA Permata Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/szezRhAALB1583408731.png true} {Virtual Account BNIVA BNI Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/n22Qsh8jMa1583433577.png true} {Virtual Account BRIVA BRI Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/8WQ3APST5s1579461828.png true} {Virtual Account MANDIRIVA Mandiri Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/T9Z012UE331583531536.png true} {Virtual Account BCAVA BCA Virtual Account direct {5500 0} {0 0} {5500 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/ytBKvaleGy1605201833.png true} {Virtual Account MUAMALATVA Muamalat Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/GGwwcgdYaG1611929720.png true} {Virtual Account CIMBVA CIMB Niaga Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/WtEJwfuphn1614003973.png true} {Virtual Account BSIVA BSI Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/tEclz5Assb1643375216.png true} {Virtual Account OCBCVA OCBC NISP Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/ysiSToLvKl1644244798.png true} {Virtual Account DANAMONVA Danamon Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/F3pGzDOLUz1644245546.png true} {Virtual Account OTHERBANKVA Other Bank Virtual Account direct {4250 0} {0 0} {4250 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/qQYo61sIDa1702995837.png true} {Convenience Store ALFAMART Alfamart direct {3500 0} {0 0} {3500 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/jiGZMKp2RD1583433506.png true} {Convenience Store INDOMARET Indomaret direct {3500 0} {0 0} {3500 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/zNzuO5AuLw1583513974.png true} {Convenience Store ALFAMIDI Alfamidi direct {3500 0} {0 0} {3500 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/aQTdaUC2GO1593660384.png true} {E-Wallet OVO OVO redirect {0 3} {0 0} {0 0} 1000 0 https://assets.tripay.co.id/upload/payment-icon/fH6Y7wDT171586199243.png true} {E-Wallet QRIS QRIS by ShopeePay direct {750 0} {0 0} {750 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/BpE4BPVyIw1605597490.png true} {E-Wallet QRISC QRIS (Customizable) direct {750 0} {0 0} {750 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/m9FtFwaBCg1623157494.png true} {E-Wallet QRIS2 QRIS direct {750 0} {0 0} {750 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/8ewGzP6SWe1649667701.png true} {E-Wallet DANA DANA redirect {0 3} {0 0} {0 0} 1000 0 https://assets.tripay.co.id/upload/payment-icon/sj3UHLu8Tu1655719621.png true} {E-Wallet SHOPEEPAY ShopeePay redirect {0 3} {0 0} {0 0} 1000 0 https://assets.tripay.co.id/upload/payment-icon/d204uajhlS1655719774.png true} {E-Wallet QRIS_SHOPEEPAY QRIS Custom by ShopeePay direct {750 0} {0 0} {750 0} 0 0 https://assets.tripay.co.id/upload/payment-icon/DM8sBd1i9y1681718593.png true}]} + */ +} diff --git a/_examples/merchant_transactions.go b/_examples/merchant_transactions.go new file mode 100644 index 0000000..81c78ec --- /dev/null +++ b/_examples/merchant_transactions.go @@ -0,0 +1,52 @@ +package examples + +import ( + "fmt" + + "github.com/zakirkun/go-tripay/client" + "github.com/zakirkun/go-tripay/utils" +) + +func Example_merchant_transactions() { + c := client.Client{ + MerchantCode: "T14302", + ApiKey: "your_api_key_here", + PrivateKey: "your_private_key_here", + Mode: utils.MODE_DEVELOPMENT, + } + response, err := c.MerchantTransactions() + if err != nil { + panic(err) + } + + fmt.Printf("response: %v\n", response) + /* + response: + &{true Success [{DEV-T14302154789W4DPV INV345675 BCAVA BCA Virtual Account John Doe johndoe@gmail.com https://thisisreturnurl.com/redirect 50000 5500 0 5500 44500 0 https://tripay.co.id/checkout/DEV-T14302154789W4DPV [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715263201 1715349367 } {DEV-T14302154790HPMWS INV345675 BCAVA BCA Virtual Account John Doe johndoe@gmail.com https://thisisreturnurl.com/redirect 50000 5500 0 5500 44500 0 https://tripay.co.id/checkout/DEV-T14302154790HPMWS [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715263347 1715349514 } {DEV-T14302154794FZ2ZT INV345675 BCAVA BCA Virtual Account John Doe johndoe@gmail.com https://thisisreturnurl.com/redirect 50000 5500 0 5500 44500 0 https://tripay.co.id/checkout/DEV-T14302154794FZ2ZT [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715265393 1715351557 } {DEV-T14302154796GC64X INV345675 BCAVA BCA Virtual Account John Doe johndoe@gmail.com https://thisisreturnurl.com/redirect 50000 5500 0 5500 44500 0 https://tripay.co.id/checkout/DEV-T14302154796GC64X [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715266465 1715352865 } {DEV-T14302154833B5XYD INV345675 BCAVA BCA Virtual Account John Doe johndoe@gmail.com https://thisisreturnurl.com/redirect 50000 5500 0 5500 44500 0 https://tripay.co.id/checkout/DEV-T14302154833B5XYD [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715333695 1715420094 } {DEV-T14302154834TY1ML INV345675 QRIS_SHOPEEPAY QRIS Custom by ShopeePay Farda Ayu Nurfatika fardaayu@gmail.com https://thisisreturnurl.com/redirect 50000 1100 0 1100 48900 0 https://tripay.co.id/checkout/DEV-T14302154834TY1ML [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715339528 1715343068 }] {asc {1 6} 1 1 50 6}} + */ +} + +func Example_merchant_transactions_with_param() { + c := client.Client{ + MerchantCode: "T14302", + ApiKey: "your_api_key_here", + PrivateKey: "your_private_key_here", + Mode: utils.MODE_DEVELOPMENT, + } + merchanTransactionParam := client.MerchantTransactionsParam{ + Page: 1, + PerPage: 10, + Sort: "asc", // asc or desc + } + + response, err := c.MerchantTransactions(merchanTransactionParam) + if err != nil { + panic(err) + } + + fmt.Printf("response: %v\n", response) + /* + response: + &{true Success [{DEV-T14302154789W4DPV INV345675 BCAVA BCA Virtual Account John Doe johndoe@gmail.com https://thisisreturnurl.com/redirect 50000 5500 0 5500 44500 0 https://tripay.co.id/checkout/DEV-T14302154789W4DPV [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715263201 1715349367 } {DEV-T14302154790HPMWS INV345675 BCAVA BCA Virtual Account John Doe johndoe@gmail.com https://thisisreturnurl.com/redirect 50000 5500 0 5500 44500 0 https://tripay.co.id/checkout/DEV-T14302154790HPMWS [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715263347 1715349514 } {DEV-T14302154794FZ2ZT INV345675 BCAVA BCA Virtual Account John Doe johndoe@gmail.com https://thisisreturnurl.com/redirect 50000 5500 0 5500 44500 0 https://tripay.co.id/checkout/DEV-T14302154794FZ2ZT [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715265393 1715351557 } {DEV-T14302154796GC64X INV345675 BCAVA BCA Virtual Account John Doe johndoe@gmail.com https://thisisreturnurl.com/redirect 50000 5500 0 5500 44500 0 https://tripay.co.id/checkout/DEV-T14302154796GC64X [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715266465 1715352865 } {DEV-T14302154833B5XYD INV345675 BCAVA BCA Virtual Account John Doe johndoe@gmail.com https://thisisreturnurl.com/redirect 50000 5500 0 5500 44500 0 https://tripay.co.id/checkout/DEV-T14302154833B5XYD [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715333695 1715420094 } {DEV-T14302154834TY1ML INV345675 QRIS_SHOPEEPAY QRIS Custom by ShopeePay Farda Ayu Nurfatika fardaayu@gmail.com https://thisisreturnurl.com/redirect 50000 1100 0 1100 48900 0 https://tripay.co.id/checkout/DEV-T14302154834TY1ML [{Produk1 nama produk 1 50000 1 50000}] UNPAID 1715339528 1715343068 }] {asc {1 6} 1 1 10 6}} + */ +} diff --git a/_examples/open_payment.go b/_examples/open_payment.go index 697e74a..7057848 100644 --- a/_examples/open_payment.go +++ b/_examples/open_payment.go @@ -1,22 +1,22 @@ package examples import ( + "fmt" + "github.com/zakirkun/go-tripay/client" "github.com/zakirkun/go-tripay/utils" - - "fmt" ) func Example_open_payment_create() { - client := client.Client{ + c := client.Client{ MerchantCode: "T14302", - ApiKey: "DEV-ZKIDl5gE3AsCDThj7mWX6yvQ8f42NZWJWlZ7TSzS", - PrivateKey: "J2WTm-93avv-w0PZV-ur1t4-4TCjd", + ApiKey: "your_api_key_here", + PrivateKey: "your_private_key_here", Mode: utils.MODE_DEVELOPMENT, } - client.SetSignature(utils.Signature{ + c.SetSignature(utils.Signature{ MerchantCode: "T14302", Channel: "BCAVA", MerchanReff: "INV345675", @@ -26,10 +26,10 @@ func Example_open_payment_create() { Method: "BCAVA", MerchatReff: "INV345675", CustomerName: "Fulan Fulan", - Signature: client.GetSignature(), + Signature: c.GetSignature(), } - responseOk, responseBad := client.OpenPaymentTransaction(payment) + responseOk, responseBad := c.OpenPaymentTransaction(payment) if responseBad != nil { fmt.Errorf("ERROR: %v", responseBad) } From 7c29da71b72dd6817e0afd734b76dffa22f9ec93 Mon Sep 17 00:00:00 2001 From: fanchann Date: Sat, 11 May 2024 08:52:45 +0700 Subject: [PATCH 6/8] refactor: add generic response & change variabel name --- client/close_payment_transaction.go | 73 ++--------- client/close_payment_transaction_test.go | 3 +- client/fee_calc.go | 41 ++----- client/fee_calc_test.go | 3 + client/instruction.go | 27 +--- client/instruction_test.go | 8 +- client/merchant_pay.go | 39 +----- client/merchant_pay_test.go | 16 +-- client/merchant_transactions.go | 64 +--------- client/merchant_transactions_test.go | 10 +- client/open_payment_test.go | 8 +- client/types.go | 149 +++++++++++++++++++++++ 12 files changed, 212 insertions(+), 229 deletions(-) create mode 100644 client/types.go diff --git a/client/close_payment_transaction.go b/client/close_payment_transaction.go index 78db6d6..b66774d 100644 --- a/client/close_payment_transaction.go +++ b/client/close_payment_transaction.go @@ -11,54 +11,7 @@ import ( ) type ( - TripayExpiredTime int - ClosePaymentRequestTransactionResponse struct { - Success bool `json:"success"` - Message string `json:"message"` - Data ClosePaymentTransactionOrder `json:"data"` - } - - ClosePaymentTransactionOrder struct { - Reference string `json:"reference"` - MerchantRef string `json:"merchant_ref"` - PaymentSelectionType string `json:"payment_selection_type"` - PaymentMethod string `json:"payment_method"` - PaymentName string `json:"payment_name"` - CustomerName string `json:"customer_name"` - CustomerEmail string `json:"customer_email"` - CustomerPhone string `json:"customer_phone"` - CallbackURL string `json:"callback_url"` - ReturnURL string `json:"return_url"` - Amount int `json:"amount"` - FeeMerchant int `json:"fee_merchant"` - FeeCustomer int `json:"fee_customer"` - TotalFee int `json:"total_fee"` - AmountReceived int `json:"amount_received"` - PayCode string `json:"pay_code"` - PayURL interface{} `json:"pay_url"` - CheckoutURL string `json:"checkout_url"` - Status string `json:"status"` - ExpiredTime int `json:"expired_time"` - OrderItems []ClosePaymentTransactionOrderItem `json:"order_items"` - Instructions []Instruction `json:"instructions"` - QRString interface{} `json:"qr_string"` - QRURL interface{} `json:"qr_url"` - } - - ClosePaymentTransactionOrderItem struct { - SKU string `json:"sku"` - Name string `json:"name"` - Price int `json:"price"` - Quantity int `json:"quantity"` - Subtotal int `json:"subtotal"` - ProductURL string `json:"product_url"` - ImageURL string `json:"image_url"` - } - - Instruction struct { - Title string `json:"title"` - Steps []string `json:"steps"` - } + TripayExpiredTime int ClosePaymentBodyRequest struct { Method utils.TRIPAY_CHANNEL `json:"method"` MerchantRef string `json:"merchant_ref"` @@ -90,15 +43,15 @@ func SetTripayExpiredTime(hour int) TripayExpiredTime { return TripayExpiredTime(int(time.Now().Unix()) + (hour * 60 * 60)) } -func (c Client) ClosePaymentRequestTransaction(ctx context.Context, req ClosePaymentBodyRequest) (*ClosePaymentRequestTransactionResponse, error) { +func (c Client) ClosePaymentRequestTransaction(req ClosePaymentBodyRequest) (tripayResponses[closePaymentTransactionOrderResponse], error) { return closePaymentRequestTransaction(c, nil, req) } -func (c Client) ClosePaymentRequestTransactionWithContext(ctx context.Context, req ClosePaymentBodyRequest) (*ClosePaymentRequestTransactionResponse, error) { +func (c Client) ClosePaymentRequestTransactionWithContext(ctx context.Context, req ClosePaymentBodyRequest) (tripayResponses[closePaymentTransactionOrderResponse], error) { return closePaymentRequestTransaction(c, ctx, req) } -func closePaymentRequestTransaction(c Client, ctx context.Context, reqBody ClosePaymentBodyRequest) (*ClosePaymentRequestTransactionResponse, error) { +func closePaymentRequestTransaction(c Client, ctx context.Context, reqBody ClosePaymentBodyRequest) (tripayResponses[closePaymentTransactionOrderResponse], error) { reqBodyByte, _ := json.Marshal(&reqBody) paramReq := requester.IRequesterParams{ Url: c.BaseUrl() + "transaction/create", @@ -116,23 +69,23 @@ func closePaymentRequestTransaction(c Client, ctx context.Context, reqBody Close } if errReq != nil { - return nil, errReq + return tripayResponses[closePaymentTransactionOrderResponse]{}, errReq } - var successResponse ClosePaymentRequestTransactionResponse + var successResponse tripayResponses[closePaymentTransactionOrderResponse] json.Unmarshal(bodyReq.ResponseBody, &successResponse) - return &successResponse, nil + return successResponse, nil } -func (c Client) ClosePaymentTransactionGetDetail(reference string) (*ClosePaymentRequestTransactionResponse, error) { +func (c Client) ClosePaymentTransactionGetDetail(reference string) (tripayResponses[closePaymentTransactionOrderResponse], error) { return closePaymentTransactionGetDetail(c, nil, reference) } -func (c Client) ClosePaymentTransactionGetDetailWithContext(ctx context.Context, reference string) (*ClosePaymentRequestTransactionResponse, error) { +func (c Client) ClosePaymentTransactionGetDetailWithContext(ctx context.Context, reference string) (tripayResponses[closePaymentTransactionOrderResponse], error) { return closePaymentTransactionGetDetail(c, ctx, reference) } -func closePaymentTransactionGetDetail(c Client, ctx context.Context, reference string) (*ClosePaymentRequestTransactionResponse, error) { +func closePaymentTransactionGetDetail(c Client, ctx context.Context, reference string) (tripayResponses[closePaymentTransactionOrderResponse], error) { paramReq := requester.IRequesterParams{ Url: c.BaseUrl() + "transaction/detail?" + fmt.Sprintf("reference=%s", reference), Method: "GET", @@ -149,10 +102,10 @@ func closePaymentTransactionGetDetail(c Client, ctx context.Context, reference s } if errReq != nil { - return nil, errReq + return tripayResponses[closePaymentTransactionOrderResponse]{}, errReq } - var successResponse ClosePaymentRequestTransactionResponse + var successResponse tripayResponses[closePaymentTransactionOrderResponse] json.Unmarshal(bodyReq.ResponseBody, &successResponse) - return &successResponse, nil + return successResponse, nil } diff --git a/client/close_payment_transaction_test.go b/client/close_payment_transaction_test.go index 2bca0c3..e1f6578 100644 --- a/client/close_payment_transaction_test.go +++ b/client/close_payment_transaction_test.go @@ -1,7 +1,6 @@ package client import ( - "context" "testing" "github.com/zakirkun/go-tripay/utils" @@ -43,7 +42,7 @@ func TestClosePaymentTransactionRequest(t *testing.T) { }, }, } - response, err := client.ClosePaymentRequestTransaction(context.Background(), bodyReq) + response, err := client.ClosePaymentRequestTransaction(bodyReq) if err != nil { t.Errorf("ERROR: %v", err) } diff --git a/client/fee_calc.go b/client/fee_calc.go index cc5c17c..af41e3b 100644 --- a/client/fee_calc.go +++ b/client/fee_calc.go @@ -10,41 +10,20 @@ import ( "github.com/zakirkun/go-tripay/utils" ) -type ( - FeeCalcResponse struct { - Success bool `json:"success"` - Message string `json:"message"` - Data []struct { - Code string - Name string - Fee struct { - Flat int `json:"flat"` - Percent string `json:"percent"` - Min interface{} `json:"min"` - Max interface{} `json:"max"` - } `json:"fee"` - TotalFee struct { - Merchant int `json:"merchant"` - Customer int `json:"customer"` - } `json:"total_fee"` - } `json:"data"` - } - - FeeCalcParam struct { - Amount int - Code utils.TRIPAY_CHANNEL - } -) +type FeeCalcParam struct { + Amount int + Code utils.TRIPAY_CHANNEL +} -func (c Client) FeeCalc(p FeeCalcParam) (*FeeCalcResponse, error) { +func (c Client) FeeCalc(p FeeCalcParam) (tripayResponses[[]feeCalcResponse], error) { return feeCalc(c, p, nil) } -func (c Client) FeeCalcWithContext(ctx context.Context, p FeeCalcParam) (*FeeCalcResponse, error) { +func (c Client) FeeCalcWithContext(ctx context.Context, p FeeCalcParam) (tripayResponses[[]feeCalcResponse], error) { return feeCalc(c, p, ctx) } -func feeCalc(c Client, p FeeCalcParam, ctx context.Context) (*FeeCalcResponse, error) { +func feeCalc(c Client, p FeeCalcParam, ctx context.Context) (tripayResponses[[]feeCalcResponse], error) { param := url.Values{} param.Set("code", string(p.Code)) param.Set("amount", fmt.Sprintf("%d", p.Amount)) @@ -67,10 +46,10 @@ func feeCalc(c Client, p FeeCalcParam, ctx context.Context) (*FeeCalcResponse, e } if errReq != nil { - return nil, errReq + return tripayResponses[[]feeCalcResponse]{}, errReq } - var successResponse FeeCalcResponse + var successResponse tripayResponses[[]feeCalcResponse] json.Unmarshal(bodyReq.ResponseBody, &successResponse) - return &successResponse, nil + return successResponse, nil } diff --git a/client/fee_calc_test.go b/client/fee_calc_test.go index fe19611..4792dd6 100644 --- a/client/fee_calc_test.go +++ b/client/fee_calc_test.go @@ -2,6 +2,7 @@ package client import ( "context" + "fmt" "testing" "github.com/zakirkun/go-tripay/utils" @@ -48,4 +49,6 @@ func TestFeeCalcWithContextFail(t *testing.T) { t.FailNow() } + fmt.Printf("response: %v\n", response) + } diff --git a/client/instruction.go b/client/instruction.go index ea7dad2..1db7981 100644 --- a/client/instruction.go +++ b/client/instruction.go @@ -8,21 +8,7 @@ import ( "github.com/zakirkun/go-tripay/internal/requester" ) -type InstructionResponseOk struct { - Success bool `json:"success"` - Message string `json:"message"` - Data []struct { - Title string `json:"title"` - Steps []string `json:"steps"` - } `json:"data"` -} - -type InstructionResponseBad struct { - Success bool `json:"success"` - Message string `json:"message"` -} - -func (c Client) Instruction(channelCode string, payCode string, amount string, allow_html string) (*InstructionResponseOk, *InstructionResponseBad) { +func (c Client) Instruction(channelCode string, payCode string, amount string, allow_html string) (tripayResponses[[]instructionResponse], error) { params := url.Values{} params.Set("code", channelCode) @@ -51,14 +37,11 @@ func (c Client) Instruction(channelCode string, payCode string, amount string, a body, err := requester.DO() if err != nil { - var responseBad InstructionResponseBad - _ = json.Unmarshal(body.ResponseBody, &responseBad) - - return nil, &responseBad + return tripayResponses[[]instructionResponse]{}, err } - var responseOk InstructionResponseOk - _ = json.Unmarshal(body.ResponseBody, &responseOk) + var response tripayResponses[[]instructionResponse] + _ = json.Unmarshal(body.ResponseBody, &response) - return &responseOk, nil + return response, nil } diff --git a/client/instruction_test.go b/client/instruction_test.go index 8cdd36d..2238ed0 100644 --- a/client/instruction_test.go +++ b/client/instruction_test.go @@ -15,10 +15,10 @@ func TestInstruction(t *testing.T) { Mode: utils.MODE_DEVELOPMENT, } - reponseOk, responseBad := client.Instruction("BRIVA", "", "10000", "") - if responseBad != nil { - t.Errorf("ERROR: %v", responseBad) + response, err := client.Instruction("BRIVA", "", "10000", "") + if err != nil { + t.Errorf("ERROR: %v", err) } - t.Log("Success: ", reponseOk) + t.Log("Success: ", response) } diff --git a/client/merchant_pay.go b/client/merchant_pay.go index 1b0bac4..2f6d522 100644 --- a/client/merchant_pay.go +++ b/client/merchant_pay.go @@ -7,42 +7,15 @@ import ( "github.com/zakirkun/go-tripay/internal/requester" ) -type MerchantResponse struct { - Success bool `json:"success"` - Message string `json:"message"` - Data []struct { - Group string `json:"group"` - Code string `json:"code"` - Name string `json:"name"` - Type string `json:"type"` - FeeMerchant struct { - Flat uint `json:"flat"` - Percent uint `json:"percent"` - } `json:"fee_merchant"` - FeeCustomer struct { - Flat uint `json:"flat"` - Percent uint `json:"percent"` - } `json:"fee_customer"` - TotalFee struct { - Flat uint `json:"flat"` - Percent float64 `json:"percent"` - } `json:"total_fee"` - MinimumFee uint `json:"minimum_fee"` - MaximumFee uint `json:"maximum_fee"` - IconURL string `json:"icon_url"` - Active bool `json:"active"` - } `json:"data"` -} - -func (c Client) MerchantPay() (*MerchantResponse, error) { +func (c Client) MerchantPay() (tripayResponses[[]merchantResponse], error) { return merchantPay(c, nil) } -func (c Client) MerchantPayWithContext(ctx context.Context) (*MerchantResponse, error) { +func (c Client) MerchantPayWithContext(ctx context.Context) (tripayResponses[[]merchantResponse], error) { return merchantPay(c, ctx) } -func merchantPay(c Client, ctx context.Context) (*MerchantResponse, error) { +func merchantPay(c Client, ctx context.Context) (tripayResponses[[]merchantResponse], error) { paramReq := requester.IRequesterParams{ Url: c.BaseUrl() + "merchant/payment-channel", Method: "GET", @@ -60,10 +33,10 @@ func merchantPay(c Client, ctx context.Context) (*MerchantResponse, error) { } if errReq != nil { - return nil, errReq + return tripayResponses[[]merchantResponse]{}, errReq } - var successResponse MerchantResponse + var successResponse tripayResponses[[]merchantResponse] json.Unmarshal(bodyReq.ResponseBody, &successResponse) - return &successResponse, nil + return successResponse, nil } diff --git a/client/merchant_pay_test.go b/client/merchant_pay_test.go index 70cdf59..b6ea17d 100644 --- a/client/merchant_pay_test.go +++ b/client/merchant_pay_test.go @@ -16,12 +16,12 @@ func TestMerchantPay(t *testing.T) { Mode: utils.MODE_DEVELOPMENT, } - reponseOk, responseBad := client.MerchantPay() - if responseBad != nil { - t.Errorf("ERROR: %v", responseBad) + response, err := client.MerchantPay() + if err != nil { + t.Errorf("ERROR: %v", err) } - t.Log("Success: ", reponseOk) + t.Log("Success: ", response) } func TestMerchantPayWithCtx(t *testing.T) { @@ -35,10 +35,10 @@ func TestMerchantPayWithCtx(t *testing.T) { ctx, timeout := context.WithTimeout(context.Background(), 5*time.Second) defer timeout() - reponseOk, responseBad := client.MerchantPayWithContext(ctx) - if responseBad != nil { - t.Errorf("ERROR: %v", responseBad) + response, err := client.MerchantPayWithContext(ctx) + if err != nil { + t.Errorf("ERROR: %v", err) } - t.Log("Success: ", reponseOk) + t.Log("Success: ", response) } diff --git a/client/merchant_transactions.go b/client/merchant_transactions.go index c8678bd..61d1309 100644 --- a/client/merchant_transactions.go +++ b/client/merchant_transactions.go @@ -10,62 +10,6 @@ import ( ) type ( - OrderItem struct { - SKU interface{} `json:"sku"` - Name string `json:"name"` - Price int `json:"price"` - Quantity int `json:"quantity"` - Subtotal int `json:"subtotal"` - } - - Data struct { - Reference string `json:"reference"` - MerchantRef string `json:"merchant_ref"` - PaymentSelection string `json:"payment_selection_"` - PaymentMethod string `json:"payment_method"` - PaymentName string `json:"payment_name"` - CustomerName string `json:"customer_name"` - CustomerEmail string `json:"customer_email"` - CustomerPhone interface{} `json:"customer_phone"` - CallbackURL interface{} `json:"callback_url"` - ReturnURL interface{} `json:"return_url"` - Amount int `json:"amount"` - FeeMerchant int `json:"fee_merchant"` - FeeCustomer int `json:"fee_customer"` - TotalFee int `json:"total_fee"` - AmountReceived int `json:"amount_received"` - PayCode int64 `json:"pay_code"` - PayURL interface{} `json:"pay_url"` - CheckoutURL string `json:"checkout_url"` - OrderItems []OrderItem `json:"order_items"` - Status string `json:"status"` - Note interface{} `json:"note"` - CreatedAt int64 `json:"created_at"` - ExpiredAt int64 `json:"expired_at"` - PaidAt interface{} `json:"paid_at"` - } - - Pagination struct { - Sort string `json:"sort"` - Offset struct { - From int `json:"from"` - To int `json:"to"` - } `json:"offset"` - CurrentPage int `json:"current_page"` - PreviousPage interface{} `json:"previous_page"` - NextPage interface{} `json:"next_page"` - LastPage int `json:"last_page"` - PerPage int `json:"per_page"` - TotalRecords int `json:"total_records"` - } - - MerchantTransactionsResponse struct { - Success bool `json:"success"` - Message string `json:"message"` - Data []Data `json:"data"` - Pagination Pagination `json:"pagination"` - } - MerchantTransactionsParam struct { Page int PerPage int @@ -77,15 +21,15 @@ type ( } ) -func (c Client) MerchantTransactions(p ...MerchantTransactionsParam) (*MerchantTransactionsResponse, error) { +func (c Client) MerchantTransactions(p ...MerchantTransactionsParam) (*merchantTransactionsResponse, error) { return merchantTransactions(c, nil, p...) } -func (c Client) MerchantTransactionsWithContext(ctx context.Context, p ...MerchantTransactionsParam) (*MerchantTransactionsResponse, error) { +func (c Client) MerchantTransactionsWithContext(ctx context.Context, p ...MerchantTransactionsParam) (*merchantTransactionsResponse, error) { return merchantTransactions(c, ctx, p...) } -func merchantTransactions(c Client, ctx context.Context, p ...MerchantTransactionsParam) (*MerchantTransactionsResponse, error) { +func merchantTransactions(c Client, ctx context.Context, p ...MerchantTransactionsParam) (*merchantTransactionsResponse, error) { var merchatsParams MerchantTransactionsParam for _, m := range p { @@ -121,7 +65,7 @@ func merchantTransactions(c Client, ctx context.Context, p ...MerchantTransactio return nil, errReq } - var response MerchantTransactionsResponse + var response merchantTransactionsResponse json.Unmarshal(bodyReq.ResponseBody, &response) return &response, nil } diff --git a/client/merchant_transactions_test.go b/client/merchant_transactions_test.go index 712c983..1756da2 100644 --- a/client/merchant_transactions_test.go +++ b/client/merchant_transactions_test.go @@ -19,12 +19,12 @@ func TestMerchantTransactionsWithContextSuccess(t *testing.T) { ctx, timeout := context.WithTimeout(context.Background(), 5*time.Second) defer timeout() - reponseOk, err := client.MerchantTransactionsWithContext(ctx) + response, err := client.MerchantTransactionsWithContext(ctx) if err != nil { t.FailNow() } - t.Log(reponseOk) + t.Log(response) } func TestMerchantTransactionsWithContextFailed(t *testing.T) { @@ -38,9 +38,9 @@ func TestMerchantTransactionsWithContextFailed(t *testing.T) { ctx, timeout := context.WithTimeout(context.Background(), 5*time.Second) defer timeout() - reponseOk, err := client.MerchantTransactionsWithContext(ctx) - if err != nil || reponseOk.Success { - t.Log(reponseOk) + response, err := client.MerchantTransactionsWithContext(ctx) + if err != nil || response.Success { t.FailNow() } + t.Log(response) } diff --git a/client/open_payment_test.go b/client/open_payment_test.go index fb53794..17d8018 100644 --- a/client/open_payment_test.go +++ b/client/open_payment_test.go @@ -27,10 +27,10 @@ func TestOpenPaymentSuccess(t *testing.T) { Signature: client.GetSignature(), } - responseOk, responseBad := client.OpenPaymentTransaction(payment) - if responseBad != nil { - t.Errorf("ERROR: %v", responseBad) + response, err := client.OpenPaymentTransaction(payment) + if err != nil { + t.Errorf("ERROR: %v", err) } - t.Log("Success: ", responseOk) + t.Log("Success: ", response) } diff --git a/client/types.go b/client/types.go new file mode 100644 index 0000000..32c7434 --- /dev/null +++ b/client/types.go @@ -0,0 +1,149 @@ +package client + +type ( + tripayDataResponse interface { + closePaymentTransactionOrderResponse | []feeCalcResponse | []merchantResponse | []instructionResponse + } + + tripayResponses[X tripayDataResponse] struct { + Success bool `json:"success"` + Message string `json:"message"` + Data X `json:"data"` + } + + closePaymentTransactionOrderResponse struct { + Reference string `json:"reference"` + MerchantRef string `json:"merchant_ref"` + PaymentSelectionType string `json:"payment_selection_type"` + PaymentMethod string `json:"payment_method"` + PaymentName string `json:"payment_name"` + CustomerName string `json:"customer_name"` + CustomerEmail string `json:"customer_email"` + CustomerPhone string `json:"customer_phone"` + CallbackURL string `json:"callback_url"` + ReturnURL string `json:"return_url"` + Amount int `json:"amount"` + FeeMerchant int `json:"fee_merchant"` + FeeCustomer int `json:"fee_customer"` + TotalFee int `json:"total_fee"` + AmountReceived int `json:"amount_received"` + PayCode string `json:"pay_code"` + PayURL interface{} `json:"pay_url"` + CheckoutURL string `json:"checkout_url"` + Status string `json:"status"` + ExpiredTime int `json:"expired_time"` + OrderItems []closePaymentTransactionOrderItemResponse `json:"order_items"` + Instructions []instructionResponse `json:"instructions"` + QRString interface{} `json:"qr_string"` + QRURL interface{} `json:"qr_url"` + } + + closePaymentTransactionOrderItemResponse struct { + SKU string `json:"sku"` + Name string `json:"name"` + Price int `json:"price"` + Quantity int `json:"quantity"` + Subtotal int `json:"subtotal"` + ProductURL string `json:"product_url"` + ImageURL string `json:"image_url"` + } + + instructionResponse struct { + Title string `json:"title"` + Steps []string `json:"steps"` + } + + feeCalcResponse struct { + Code string + Name string + Fee struct { + Flat int `json:"flat"` + Percent string `json:"percent"` + Min interface{} `json:"min"` + Max interface{} `json:"max"` + } `json:"fee"` + TotalFee struct { + Merchant int `json:"merchant"` + Customer int `json:"customer"` + } `json:"total_fee"` + } + + merchantResponse struct { + Group string `json:"group"` + Code string `json:"code"` + Name string `json:"name"` + Type string `json:"type"` + FeeMerchant struct { + Flat uint `json:"flat"` + Percent uint `json:"percent"` + } `json:"fee_merchant"` + FeeCustomer struct { + Flat uint `json:"flat"` + Percent uint `json:"percent"` + } `json:"fee_customer"` + TotalFee struct { + Flat uint `json:"flat"` + Percent float64 `json:"percent"` + } `json:"total_fee"` + MinimumFee uint `json:"minimum_fee"` + MaximumFee uint `json:"maximum_fee"` + IconURL string `json:"icon_url"` + Active bool `json:"active"` + } + + merchantTransactionsOrderItemResponse struct { + SKU interface{} `json:"sku"` + Name string `json:"name"` + Price int `json:"price"` + Quantity int `json:"quantity"` + Subtotal int `json:"subtotal"` + } + + merchantTransactionsDataResponse struct { + Reference string `json:"reference"` + MerchantRef string `json:"merchant_ref"` + PaymentSelection string `json:"payment_selection_"` + PaymentMethod string `json:"payment_method"` + PaymentName string `json:"payment_name"` + CustomerName string `json:"customer_name"` + CustomerEmail string `json:"customer_email"` + CustomerPhone interface{} `json:"customer_phone"` + CallbackURL interface{} `json:"callback_url"` + ReturnURL interface{} `json:"return_url"` + Amount int `json:"amount"` + FeeMerchant int `json:"fee_merchant"` + FeeCustomer int `json:"fee_customer"` + TotalFee int `json:"total_fee"` + AmountReceived int `json:"amount_received"` + PayCode int64 `json:"pay_code"` + PayURL interface{} `json:"pay_url"` + CheckoutURL string `json:"checkout_url"` + OrderItems []merchantTransactionsOrderItemResponse `json:"order_items"` + Status string `json:"status"` + Note interface{} `json:"note"` + CreatedAt int64 `json:"created_at"` + ExpiredAt int64 `json:"expired_at"` + PaidAt interface{} `json:"paid_at"` + } + + merchantTransactionsPaginationResponse struct { + Sort string `json:"sort"` + Offset struct { + From int `json:"from"` + To int `json:"to"` + } `json:"offset"` + CurrentPage int `json:"current_page"` + PreviousPage interface{} `json:"previous_page"` + NextPage interface{} `json:"next_page"` + LastPage int `json:"last_page"` + PerPage int `json:"per_page"` + TotalRecords int `json:"total_records"` + } + + merchantTransactionsResponse struct { + Success bool `json:"success"` + Message string `json:"message"` + Data []merchantTransactionsDataResponse `json:"data"` + Pagination merchantTransactionsPaginationResponse `json:"pagination"` + } +) From 63ca2956656be4b62027fae77154def07bce4722 Mon Sep 17 00:00:00 2001 From: fanchann Date: Sat, 11 May 2024 17:06:18 +0700 Subject: [PATCH 7/8] add: example payment instruction --- _examples/payment_instructions.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 _examples/payment_instructions.go diff --git a/_examples/payment_instructions.go b/_examples/payment_instructions.go new file mode 100644 index 0000000..3f07fb5 --- /dev/null +++ b/_examples/payment_instructions.go @@ -0,0 +1,30 @@ +package examples + +import ( + "fmt" + + "github.com/zakirkun/go-tripay/client" + "github.com/zakirkun/go-tripay/utils" +) + +func Example_payment_instructions() { + c := client.Client{ + MerchantCode: "T14302", + ApiKey: "your_api_key_here", + PrivateKey: "your_private_key_here", + Mode: utils.MODE_DEVELOPMENT, + } + + ip := client.InstructionRequestParam{ + ChannelCode: utils.CHANNEL_BRIVA, + PayCode: "", + Amount: "10000", + AllowHtml: "", + } + + response, err := c.Instruction(ip) + if err != nil { + panic(err) + } + fmt.Printf("response: %v\n", response) +} From 6eec099bd55d964112099d4e23c28de51ad115b8 Mon Sep 17 00:00:00 2001 From: fanchann Date: Sat, 11 May 2024 19:31:24 +0700 Subject: [PATCH 8/8] doc: code documentation --- client/close_payment_transaction.go | 96 +++++++++++++++++++++++++++++ client/fee_calc.go | 22 +++++++ client/instruction.go | 35 ++++++++--- client/instruction_test.go | 8 ++- client/merchant_pay.go | 20 ++++++ client/merchant_transactions.go | 20 ++++++ client/open_payment.go | 18 ++++++ 7 files changed, 210 insertions(+), 9 deletions(-) diff --git a/client/close_payment_transaction.go b/client/close_payment_transaction.go index b66774d..93b288e 100644 --- a/client/close_payment_transaction.go +++ b/client/close_payment_transaction.go @@ -39,14 +39,88 @@ type ( } ) +/* +used to make a payment limit within hours. Example: + + hour := 24 // one day + SetTripayExpiredTime(hour) +*/ func SetTripayExpiredTime(hour int) TripayExpiredTime { return TripayExpiredTime(int(time.Now().Unix()) + (hour * 60 * 60)) } +/* +used to create a new transaction or generate a payment code. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + c.SetSignature(utils.Signature{Amount: 50000, PrivateKey: "your_private_key", MerchantCode: "T14302",MerchanReff: "INV345675"}) + + req := ClosePaymentBodyRequest{ + Method: utils.CHANNEL_BCAVA, + MerchantRef: "INV345675", + Amount: 50000, + CustomerName: "John Doe", + CustomerEmail: "johndoe@gmail.com", + CustomerPhone: "62891829828", + ReturnURL: "https://thisisreturnurl.com/redirect", + ExpiredTime: SetTripayExpiredTime(24), // 24 Hour + Signature: client.GetSignature(), + OrderItems: []OrderItemClosePaymentRequest{ + { + SKU: "Produk1", + Name: "nama produk 1", + Price: 50000, + Quantity: 1, + ProductURL: "https://producturl.com", + ImageURL: "https://imageurl.com", + }, + }, + } + + response, err := c.ClosePaymentRequestTransaction(req) + if err != nil { + // do something + } + // do something +*/ func (c Client) ClosePaymentRequestTransaction(req ClosePaymentBodyRequest) (tripayResponses[closePaymentTransactionOrderResponse], error) { return closePaymentRequestTransaction(c, nil, req) } +/* +used to create a new transaction or generate a payment code. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + c.SetSignature(utils.Signature{ Amount: 50000, PrivateKey: "your_private_key", MerchantCode: "T14302",MerchanReff: "INV345675" }) + + req := ClosePaymentBodyRequest{ + Method: utils.CHANNEL_BCAVA, + MerchantRef: "INV345675", + Amount: 50000, + CustomerName: "John Doe", + CustomerEmail: "johndoe@gmail.com", + CustomerPhone: "62891829828", + ReturnURL: "https://thisisreturnurl.com/redirect", + ExpiredTime: SetTripayExpiredTime(24), // 24 Hour + Signature: client.GetSignature(), + OrderItems: []OrderItemClosePaymentRequest{ + { + SKU: "Produk1", + Name: "nama produk 1", + Price: 50000, + Quantity: 1, + ProductURL: "https://producturl.com", + ImageURL: "https://imageurl.com", + }, + }, + } + + response, err := c.ClosePaymentRequestTransactionWithContext(context.Background,req) + if err != nil { + // do something + } + // do something +*/ func (c Client) ClosePaymentRequestTransactionWithContext(ctx context.Context, req ClosePaymentBodyRequest) (tripayResponses[closePaymentTransactionOrderResponse], error) { return closePaymentRequestTransaction(c, ctx, req) } @@ -77,10 +151,32 @@ func closePaymentRequestTransaction(c Client, ctx context.Context, reqBody Close return successResponse, nil } +/* +Used to retrieve details of transactions that have been made. Can also be used to check payment status. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + referenceId := "reference_id" + response, err := c.ClosePaymentTransactionGetDetail(referenceId) + if err != nil { + // do something + } + // do something +*/ func (c Client) ClosePaymentTransactionGetDetail(reference string) (tripayResponses[closePaymentTransactionOrderResponse], error) { return closePaymentTransactionGetDetail(c, nil, reference) } +/* +Used to retrieve details of transactions that have been made. Can also be used to check payment status. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + referenceId := "reference_id" + response, err := c.ClosePaymentTransactionGetDetailWithContext(referenceId) + if err != nil { + // do something + } + // do something +*/ func (c Client) ClosePaymentTransactionGetDetailWithContext(ctx context.Context, reference string) (tripayResponses[closePaymentTransactionOrderResponse], error) { return closePaymentTransactionGetDetail(c, ctx, reference) } diff --git a/client/fee_calc.go b/client/fee_calc.go index af41e3b..718ae66 100644 --- a/client/fee_calc.go +++ b/client/fee_calc.go @@ -15,10 +15,32 @@ type FeeCalcParam struct { Code utils.TRIPAY_CHANNEL } +/* +used to get the details of the transaction fee calculation for each channel based on the nominal specified. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + fcParam := FeeCalcParam{Code: utils.CHANNEL_ALFAMIDI,Amount: 100000} + response, err := client.FeeCalc(fcParam) + if err != nil { + // do something + } + // do something +*/ func (c Client) FeeCalc(p FeeCalcParam) (tripayResponses[[]feeCalcResponse], error) { return feeCalc(c, p, nil) } +/* +used to get the details of the transaction fee calculation for each channel based on the nominal specified. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + fcParam := FeeCalcParam{Code: utils.CHANNEL_ALFAMIDI,Amount: 100000} + response, err := client.FeeCalcWithContext(context.Background(), fcParam) + if err != nil { + // do something + } + // do something +*/ func (c Client) FeeCalcWithContext(ctx context.Context, p FeeCalcParam) (tripayResponses[[]feeCalcResponse], error) { return feeCalc(c, p, ctx) } diff --git a/client/instruction.go b/client/instruction.go index 1db7981..122153c 100644 --- a/client/instruction.go +++ b/client/instruction.go @@ -6,23 +6,42 @@ import ( "net/url" "github.com/zakirkun/go-tripay/internal/requester" + "github.com/zakirkun/go-tripay/utils" ) -func (c Client) Instruction(channelCode string, payCode string, amount string, allow_html string) (tripayResponses[[]instructionResponse], error) { +type InstructionRequestParam struct { + ChannelCode utils.TRIPAY_CHANNEL + PayCode string + Amount string + AllowHtml string +} + +/* +used to retrieve payment instructions from each channel. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + param := InstructionRequestParam{ ChannelCode: utils.CHANNEL_BRIVA, PayCode: "", Amount: "10000", AllowHtml: "" } + response, err := c.Instruction(param) + if err != nil{ + // do something + } + // do something +*/ +func (c Client) Instruction(ip InstructionRequestParam) (tripayResponses[[]instructionResponse], error) { params := url.Values{} - params.Set("code", channelCode) + params.Set("code", string(ip.ChannelCode)) - if payCode != "" { - params.Set("pay_code", payCode) + if ip.PayCode != "" { + params.Set("pay_code", ip.PayCode) } - if amount != "" { - params.Set("amount", amount) + if ip.Amount != "" { + params.Set("amount", ip.Amount) } - if allow_html != "" { - params.Set("allow_html", allow_html) + if ip.AllowHtml != "" { + params.Set("ip.AllowHtml", ip.AllowHtml) } queryString := params.Encode() diff --git a/client/instruction_test.go b/client/instruction_test.go index 2238ed0..cff142c 100644 --- a/client/instruction_test.go +++ b/client/instruction_test.go @@ -15,7 +15,13 @@ func TestInstruction(t *testing.T) { Mode: utils.MODE_DEVELOPMENT, } - response, err := client.Instruction("BRIVA", "", "10000", "") + ip := InstructionRequestParam{ + ChannelCode: utils.CHANNEL_BRIVA, + PayCode: "", + Amount: "10000", + AllowHtml: "", + } + response, err := client.Instruction(ip) if err != nil { t.Errorf("ERROR: %v", err) } diff --git a/client/merchant_pay.go b/client/merchant_pay.go index 2f6d522..48546ce 100644 --- a/client/merchant_pay.go +++ b/client/merchant_pay.go @@ -7,10 +7,30 @@ import ( "github.com/zakirkun/go-tripay/internal/requester" ) +/* +used to get a list of payment channels that are active on your Merchant account along with complete information including transaction fees from each channel. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + response, err := c.MerchantPay() + if err != nil{ + // do something + } + // do something +*/ func (c Client) MerchantPay() (tripayResponses[[]merchantResponse], error) { return merchantPay(c, nil) } +/* +used to get a list of payment channels that are active on your Merchant account along with complete information including transaction fees from each channel. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + response, err := c.MerchantPayWithContext(context.Background()) + if err != nil{ + // do something + } + // do something +*/ func (c Client) MerchantPayWithContext(ctx context.Context) (tripayResponses[[]merchantResponse], error) { return merchantPay(c, ctx) } diff --git a/client/merchant_transactions.go b/client/merchant_transactions.go index 61d1309..f34683d 100644 --- a/client/merchant_transactions.go +++ b/client/merchant_transactions.go @@ -21,10 +21,30 @@ type ( } ) +/* +used to get a list of merchant transactions. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + response, err := c.MerchantTransactions() + if err != nil{ + // do something + } + // do something +*/ func (c Client) MerchantTransactions(p ...MerchantTransactionsParam) (*merchantTransactionsResponse, error) { return merchantTransactions(c, nil, p...) } +/* +used to get a list of merchant transactions. Example: + + c := Client{ MerchantCode: "T14302", ApiKey: "your_api_key", PrivateKey: "your_private_key", Mode: utils.MODE_DEVELOPMENT } + response, err := c.MerchantTransactionsWithContext(context.Background()) + if err != nil{ + // do something + } + // do something +*/ func (c Client) MerchantTransactionsWithContext(ctx context.Context, p ...MerchantTransactionsParam) (*merchantTransactionsResponse, error) { return merchantTransactions(c, ctx, p...) } diff --git a/client/open_payment.go b/client/open_payment.go index 74ce9e6..85bd8c5 100644 --- a/client/open_payment.go +++ b/client/open_payment.go @@ -85,26 +85,44 @@ type OpenPaymentListResponse struct { } `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) { 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) { 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) { 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) { 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) { 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) { return openPaymentList(c, uuid, ctx, p...) }