From 383ed08761f7ae243a1e94f1284763af3b5a7302 Mon Sep 17 00:00:00 2001 From: Odetola Taiwo Date: Wed, 5 Jun 2024 01:16:37 +0100 Subject: [PATCH 1/2] Add Recipient and Transactions endpoint --- api/api.go | 9 + api/mock/mock_remote_calls.go | 348 ++++++++++++++++++++++++++++++++++ api/payment.go | 86 +++++++++ main.go | 87 ++++++++- model/model.go | 10 +- model/payment.go | 68 +++++++ 6 files changed, 603 insertions(+), 5 deletions(-) create mode 100644 api/mock/mock_remote_calls.go create mode 100644 api/payment.go create mode 100644 model/payment.go diff --git a/api/api.go b/api/api.go index 26093f8..7cc1c94 100644 --- a/api/api.go +++ b/api/api.go @@ -31,6 +31,15 @@ type RemoteCalls interface { GetBillByID(ctx context.Context, id string) (*model.BillData, error) GetBillByReference(ctx context.Context, reference string) (*model.BillData, error) GetAllBills(ctx context.Context, request model.GetAllBillsRequest) ([]model.BillData, error) + + CreateRecipient(ctx context.Context, request model.CreateRecipientRequest) (*model.RecipientResponse, error) + GetRecipient(ctx context.Context, id string) (*model.RecipientResponse, error) + GetRecipients(ctx context.Context) (*model.RecipientsResponse, error) + + CreateTransaction(ctx context.Context, request model.CreateTransactionRequest) (*model.TransactionResponse, error) + GetTransactionByID(ctx context.Context, id string) (*model.TransactionResponse, error) + GetTransactionByReference(ctx context.Context, reference string) (*model.TransactionResponse, error) + GetTransactions(ctx context.Context) (*model.TransactionsResponse, error) } // Call object diff --git a/api/mock/mock_remote_calls.go b/api/mock/mock_remote_calls.go new file mode 100644 index 0000000..aa5c306 --- /dev/null +++ b/api/mock/mock_remote_calls.go @@ -0,0 +1,348 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: api.go + +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + model "github.com/sendlovebox/go-lenco/model" +) + +// MockRemoteCalls is a mock of RemoteCalls interface. +type MockRemoteCalls struct { + ctrl *gomock.Controller + recorder *MockRemoteCallsMockRecorder +} + +// MockRemoteCallsMockRecorder is the mock recorder for MockRemoteCalls. +type MockRemoteCallsMockRecorder struct { + mock *MockRemoteCalls +} + +// NewMockRemoteCalls creates a new mock instance. +func NewMockRemoteCalls(ctrl *gomock.Controller) *MockRemoteCalls { + mock := &MockRemoteCalls{ctrl: ctrl} + mock.recorder = &MockRemoteCallsMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRemoteCalls) EXPECT() *MockRemoteCallsMockRecorder { + return m.recorder +} + +// CreateBill mocks base method. +func (m *MockRemoteCalls) CreateBill(ctx context.Context, request model.CreateBillRequest) (*model.CreateBillResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateBill", ctx, request) + ret0, _ := ret[0].(*model.CreateBillResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateBill indicates an expected call of CreateBill. +func (mr *MockRemoteCallsMockRecorder) CreateBill(ctx, request interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateBill", reflect.TypeOf((*MockRemoteCalls)(nil).CreateBill), ctx, request) +} + +// CreateRecipient mocks base method. +func (m *MockRemoteCalls) CreateRecipient(ctx context.Context, request model.CreateRecipientRequest) (*model.RecipientResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateRecipient", ctx, request) + ret0, _ := ret[0].(*model.RecipientResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateRecipient indicates an expected call of CreateRecipient. +func (mr *MockRemoteCallsMockRecorder) CreateRecipient(ctx, request interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateRecipient", reflect.TypeOf((*MockRemoteCalls)(nil).CreateRecipient), ctx, request) +} + +// CreateTransaction mocks base method. +func (m *MockRemoteCalls) CreateTransaction(ctx context.Context, request model.CreateTransactionRequest) (*model.TransactionResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateTransaction", ctx, request) + ret0, _ := ret[0].(*model.TransactionResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateTransaction indicates an expected call of CreateTransaction. +func (mr *MockRemoteCallsMockRecorder) CreateTransaction(ctx, request interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateTransaction", reflect.TypeOf((*MockRemoteCalls)(nil).CreateTransaction), ctx, request) +} + +// CreateVirtualAccount mocks base method. +func (m *MockRemoteCalls) CreateVirtualAccount(ctx context.Context, request model.VirtualAccountRequest) (*model.VirtualAccount, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateVirtualAccount", ctx, request) + ret0, _ := ret[0].(*model.VirtualAccount) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateVirtualAccount indicates an expected call of CreateVirtualAccount. +func (mr *MockRemoteCallsMockRecorder) CreateVirtualAccount(ctx, request interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateVirtualAccount", reflect.TypeOf((*MockRemoteCalls)(nil).CreateVirtualAccount), ctx, request) +} + +// GetAllBills mocks base method. +func (m *MockRemoteCalls) GetAllBills(ctx context.Context, request model.GetAllBillsRequest) ([]model.BillData, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllBills", ctx, request) + ret0, _ := ret[0].([]model.BillData) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAllBills indicates an expected call of GetAllBills. +func (mr *MockRemoteCallsMockRecorder) GetAllBills(ctx, request interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllBills", reflect.TypeOf((*MockRemoteCalls)(nil).GetAllBills), ctx, request) +} + +// GetBillByID mocks base method. +func (m *MockRemoteCalls) GetBillByID(ctx context.Context, id string) (*model.BillData, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBillByID", ctx, id) + ret0, _ := ret[0].(*model.BillData) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBillByID indicates an expected call of GetBillByID. +func (mr *MockRemoteCallsMockRecorder) GetBillByID(ctx, id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBillByID", reflect.TypeOf((*MockRemoteCalls)(nil).GetBillByID), ctx, id) +} + +// GetBillByReference mocks base method. +func (m *MockRemoteCalls) GetBillByReference(ctx context.Context, reference string) (*model.BillData, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBillByReference", ctx, reference) + ret0, _ := ret[0].(*model.BillData) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBillByReference indicates an expected call of GetBillByReference. +func (mr *MockRemoteCallsMockRecorder) GetBillByReference(ctx, reference interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBillByReference", reflect.TypeOf((*MockRemoteCalls)(nil).GetBillByReference), ctx, reference) +} + +// GetBillProductByID mocks base method. +func (m *MockRemoteCalls) GetBillProductByID(ctx context.Context, productID string) (*model.Product, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBillProductByID", ctx, productID) + ret0, _ := ret[0].(*model.Product) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBillProductByID indicates an expected call of GetBillProductByID. +func (mr *MockRemoteCallsMockRecorder) GetBillProductByID(ctx, productID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBillProductByID", reflect.TypeOf((*MockRemoteCalls)(nil).GetBillProductByID), ctx, productID) +} + +// GetBillProducts mocks base method. +func (m *MockRemoteCalls) GetBillProducts(ctx context.Context, vendorID *string, category *model.BillCategory) ([]model.Product, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBillProducts", ctx, vendorID, category) + ret0, _ := ret[0].([]model.Product) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBillProducts indicates an expected call of GetBillProducts. +func (mr *MockRemoteCallsMockRecorder) GetBillProducts(ctx, vendorID, category interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBillProducts", reflect.TypeOf((*MockRemoteCalls)(nil).GetBillProducts), ctx, vendorID, category) +} + +// GetBillVendorByID mocks base method. +func (m *MockRemoteCalls) GetBillVendorByID(ctx context.Context, vendorID string) (*model.Vendor, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBillVendorByID", ctx, vendorID) + ret0, _ := ret[0].(*model.Vendor) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBillVendorByID indicates an expected call of GetBillVendorByID. +func (mr *MockRemoteCallsMockRecorder) GetBillVendorByID(ctx, vendorID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBillVendorByID", reflect.TypeOf((*MockRemoteCalls)(nil).GetBillVendorByID), ctx, vendorID) +} + +// GetBillVendors mocks base method. +func (m *MockRemoteCalls) GetBillVendors(ctx context.Context, category model.BillCategory) ([]model.Vendor, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBillVendors", ctx, category) + ret0, _ := ret[0].([]model.Vendor) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetBillVendors indicates an expected call of GetBillVendors. +func (mr *MockRemoteCallsMockRecorder) GetBillVendors(ctx, category interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBillVendors", reflect.TypeOf((*MockRemoteCalls)(nil).GetBillVendors), ctx, category) +} + +// GetRecipient mocks base method. +func (m *MockRemoteCalls) GetRecipient(ctx context.Context, id string) (*model.RecipientResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRecipient", ctx, id) + ret0, _ := ret[0].(*model.RecipientResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRecipient indicates an expected call of GetRecipient. +func (mr *MockRemoteCallsMockRecorder) GetRecipient(ctx, id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRecipient", reflect.TypeOf((*MockRemoteCalls)(nil).GetRecipient), ctx, id) +} + +// GetRecipients mocks base method. +func (m *MockRemoteCalls) GetRecipients(ctx context.Context) (*model.RecipientsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRecipients", ctx) + ret0, _ := ret[0].(*model.RecipientsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRecipients indicates an expected call of GetRecipients. +func (mr *MockRemoteCallsMockRecorder) GetRecipients(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRecipients", reflect.TypeOf((*MockRemoteCalls)(nil).GetRecipients), ctx) +} + +// GetTransactionByID mocks base method. +func (m *MockRemoteCalls) GetTransactionByID(ctx context.Context, id string) (*model.TransactionResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTransactionByID", ctx, id) + ret0, _ := ret[0].(*model.TransactionResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetTransactionByID indicates an expected call of GetTransactionByID. +func (mr *MockRemoteCallsMockRecorder) GetTransactionByID(ctx, id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransactionByID", reflect.TypeOf((*MockRemoteCalls)(nil).GetTransactionByID), ctx, id) +} + +// GetTransactionByReference mocks base method. +func (m *MockRemoteCalls) GetTransactionByReference(ctx context.Context, reference string) (*model.TransactionResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTransactionByReference", ctx, reference) + ret0, _ := ret[0].(*model.TransactionResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetTransactionByReference indicates an expected call of GetTransactionByReference. +func (mr *MockRemoteCallsMockRecorder) GetTransactionByReference(ctx, reference interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransactionByReference", reflect.TypeOf((*MockRemoteCalls)(nil).GetTransactionByReference), ctx, reference) +} + +// GetTransactions mocks base method. +func (m *MockRemoteCalls) GetTransactions(ctx context.Context) (*model.TransactionsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTransactions", ctx) + ret0, _ := ret[0].(*model.TransactionsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetTransactions indicates an expected call of GetTransactions. +func (mr *MockRemoteCallsMockRecorder) GetTransactions(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransactions", reflect.TypeOf((*MockRemoteCalls)(nil).GetTransactions), ctx) +} + +// GetVirtualAccountByBVN mocks base method. +func (m *MockRemoteCalls) GetVirtualAccountByBVN(ctx context.Context, bvn string) (*model.VirtualAccount, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetVirtualAccountByBVN", ctx, bvn) + ret0, _ := ret[0].(*model.VirtualAccount) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetVirtualAccountByBVN indicates an expected call of GetVirtualAccountByBVN. +func (mr *MockRemoteCallsMockRecorder) GetVirtualAccountByBVN(ctx, bvn interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVirtualAccountByBVN", reflect.TypeOf((*MockRemoteCalls)(nil).GetVirtualAccountByBVN), ctx, bvn) +} + +// GetVirtualAccountByRef mocks base method. +func (m *MockRemoteCalls) GetVirtualAccountByRef(ctx context.Context, reference string) (*model.VirtualAccount, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetVirtualAccountByRef", ctx, reference) + ret0, _ := ret[0].(*model.VirtualAccount) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetVirtualAccountByRef indicates an expected call of GetVirtualAccountByRef. +func (mr *MockRemoteCallsMockRecorder) GetVirtualAccountByRef(ctx, reference interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVirtualAccountByRef", reflect.TypeOf((*MockRemoteCalls)(nil).GetVirtualAccountByRef), ctx, reference) +} + +// GetVirtualAccountTransaction mocks base method. +func (m *MockRemoteCalls) GetVirtualAccountTransaction(ctx context.Context, txID string) (*model.Transaction, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetVirtualAccountTransaction", ctx, txID) + ret0, _ := ret[0].(*model.Transaction) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetVirtualAccountTransaction indicates an expected call of GetVirtualAccountTransaction. +func (mr *MockRemoteCallsMockRecorder) GetVirtualAccountTransaction(ctx, txID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVirtualAccountTransaction", reflect.TypeOf((*MockRemoteCalls)(nil).GetVirtualAccountTransaction), ctx, txID) +} + +// RunCustomerLookup mocks base method. +func (m *MockRemoteCalls) RunCustomerLookup(ctx context.Context, customerID, productID string) (*model.CustomerDetails, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RunCustomerLookup", ctx, customerID, productID) + ret0, _ := ret[0].(*model.CustomerDetails) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RunCustomerLookup indicates an expected call of RunCustomerLookup. +func (mr *MockRemoteCallsMockRecorder) RunCustomerLookup(ctx, customerID, productID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RunCustomerLookup", reflect.TypeOf((*MockRemoteCalls)(nil).RunCustomerLookup), ctx, customerID, productID) +} + +// RunInSandboxMode mocks base method. +func (m *MockRemoteCalls) RunInSandboxMode() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RunInSandboxMode") +} + +// RunInSandboxMode indicates an expected call of RunInSandboxMode. +func (mr *MockRemoteCallsMockRecorder) RunInSandboxMode() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RunInSandboxMode", reflect.TypeOf((*MockRemoteCalls)(nil).RunInSandboxMode)) +} diff --git a/api/payment.go b/api/payment.go new file mode 100644 index 0000000..6b12437 --- /dev/null +++ b/api/payment.go @@ -0,0 +1,86 @@ +package api + +import ( + "context" + "fmt" + "net/http" + + "github.com/sendlovebox/go-lenco/model" +) + +// CreateRecipient makes the request to create a recipient on Lenco +func (c *Call) CreateRecipient(ctx context.Context, request model.CreateRecipientRequest) (*model.RecipientResponse, error) { + response := &model.RecipientResponse{} + + err := c.makeRequest(ctx, http.MethodPost, "/recipients", request, response) + if err != nil { + return nil, err + } + return response, err +} + +// GetRecipient makes the request to get a recipient on Lenco +func (c *Call) GetRecipient(ctx context.Context, id string) (*model.RecipientResponse, error) { + response := &model.RecipientResponse{} + + err := c.makeRequest(ctx, http.MethodGet, fmt.Sprintf("/recipient/%s", id), nil, response) + if err != nil { + return nil, err + } + return response, err +} + +// GetRecipients makes the request to get recipients on Lenco +func (c *Call) GetRecipients(ctx context.Context) (*model.RecipientsResponse, error) { + response := &model.RecipientsResponse{} + + err := c.makeRequest(ctx, http.MethodGet, "/recipients", nil, response) + if err != nil { + return nil, err + } + return response, err +} + +// CreateTransaction makes the request to create a transaction on Lenco +func (c *Call) CreateTransaction(ctx context.Context, request model.CreateTransactionRequest) (*model.TransactionResponse, error) { + response := &model.TransactionResponse{} + + err := c.makeRequest(ctx, http.MethodPost, "/transactions", request, response) + if err != nil { + return nil, err + } + return response, err +} + +// GetTransactionByID makes the request to get a transaction on Lenco +func (c *Call) GetTransactionByID(ctx context.Context, id string) (*model.TransactionResponse, error) { + response := &model.TransactionResponse{} + + err := c.makeRequest(ctx, http.MethodGet, fmt.Sprintf("/transaction/%s", id), nil, response) + if err != nil { + return nil, err + } + return response, err +} + +// GetTransactionByReference makes the request to get a transaction by reference on Lenco +func (c *Call) GetTransactionByReference(ctx context.Context, reference string) (*model.TransactionResponse, error) { + response := &model.TransactionResponse{} + + err := c.makeRequest(ctx, http.MethodGet, fmt.Sprintf("/transaction-by-reference/%s", reference), nil, response) + if err != nil { + return nil, err + } + return response, err +} + +// GetTransactions makes the request to get transactions on Lenco +func (c *Call) GetTransactions(ctx context.Context) (*model.TransactionsResponse, error) { + response := &model.TransactionsResponse{} + + err := c.makeRequest(ctx, http.MethodGet, "/transactions", nil, response) + if err != nil { + return nil, err + } + return response, err +} diff --git a/main.go b/main.go index 8f5ecb7..cd85e8e 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( ) func main() { - fmt.Println("Running lenco SDK") + fmt.Println("Running Lenco SDK") _ = os.Setenv("TZ", "Africa/Lagos") logger := zerolog.New(os.Stderr).With().Timestamp().Logger() client := resty.New() @@ -172,4 +172,89 @@ func main() { } logger.Info().Interface("response", virtualAccTrx).Msg("success") */ + + /* + // ---------------CreateRecipient--------------- + recipient, err := api.CreateRecipient(ctx, model.CreateRecipientRequest{ + AccountNumber: "8094656624", + BankCode: "100004", + }) + if err != nil { + logger.Err(err).Msg("failed") + return + } + logger.Info().Interface("response", recipient).Msg("success") + + */ + + /* + // ---------------GetRecipient--------------- + recipient, err := api.GetRecipient(ctx, "d3597405-bfad-4f8c-b277-86355a7c555e") + if err != nil { + logger.Err(err).Msg("failed") + return + } + logger.Info().Interface("response", recipient).Msg("success") + */ + + /* + // ---------------GetRecipients--------------- + recipients, err := api.GetRecipients(ctx) + if err != nil { + logger.Err(err).Msg("failed") + return + } + logger.Info().Interface("response", recipients).Msg("success") + */ + + /* + // ---------------CreateTransaction--------------- + // recipientID := "d3597405-bfad-4f8c-b277-86355a7c555e" + accountNumber := "8094656624" + bankCode := "100004" + transaction, err := api.CreateTransaction(ctx, model.CreateTransactionRequest{ + AccountID: "431827e5-8f9f-4340-ad37-d07185403b8b", + //RecipientID: &recipientID, + AccountNumber: &accountNumber, + BankCode: &bankCode, + Amount: "3000", + Narration: "testing", + Reference: "44497e5-8f9f-4340-ad37-d07185403b8d", + }) + if err != nil { + logger.Err(err).Msg("failed") + return + } + logger.Info().Interface("response", transaction).Msg("success") + */ + + /* + // ---------------GetTransactionByID--------------- + transaction, err := api.GetTransactionByID(ctx, "8f81b7bb-02db-4ce2-9a38-e7fa135cf099") + if err != nil { + logger.Err(err).Msg("failed") + return + } + logger.Info().Interface("response", transaction).Msg("success") + */ + + /* + // ---------------GetTransactionByReference--------------- + transaction2, err := api.GetTransactionByReference(ctx, "44497e5-8f9f-4340-ad37-d07185403b8d") + if err != nil { + logger.Err(err).Msg("failed") + return + } + logger.Info().Interface("response", transaction2).Msg("success") + */ + + /* + // ---------------GetTransactions--------------- + transactions, err := api.GetTransactions(ctx) + if err != nil { + logger.Err(err).Msg("failed") + return + } + logger.Info().Interface("response", transactions).Msg("success") + */ } diff --git a/model/model.go b/model/model.go index 21f361e..965661f 100644 --- a/model/model.go +++ b/model/model.go @@ -11,7 +11,7 @@ const ( // BaseURL to for woven finance BaseURL = "https://sandbox.lenco.co/access/v1" // APIKey for authorization - APIKey = "" + APIKey = "bf307db1fcb4749120b81470eff89961367c8760f904d8dffcfa78d633d23e67" ) var ( @@ -22,8 +22,10 @@ var ( type ( // Response schema for all endpoints Response struct { - Status bool `json:"status"` - Message string `json:"message"` - Data interface{} `json:"data"` + Status bool `json:"status"` + Message string `json:"message"` + ErrorCode *string `json:"errorCode,omitempty"` + Errors interface{} `json:"errors,omitempty"` + Data interface{} `json:"data"` } ) diff --git a/model/payment.go b/model/payment.go new file mode 100644 index 0000000..ab5073a --- /dev/null +++ b/model/payment.go @@ -0,0 +1,68 @@ +package model + +type ( + // CreateRecipientRequest schema + CreateRecipientRequest struct { + AccountNumber string `json:"accountNumber"` + BankCode string `json:"bankCode"` + } + + // RecipientResponse schema + RecipientResponse struct { + ID string `json:"id"` + Name string `json:"name"` + Currency string `json:"currency"` + BankAccount BankAccount `json:"bankAccount"` + } + + // RecipientsResponse schema + RecipientsResponse struct { + Recipients []RecipientResponse `json:"recipients"` + } + + // CreateTransactionRequest schema + CreateTransactionRequest struct { + AccountID string `json:"accountId"` + RecipientID *string `json:"recipientId,omitempty"` + AccountNumber *string `json:"accountNumber,omitempty"` + BankCode *string `json:"bankCode,omitempty"` + Amount string `json:"amount"` + Narration string `json:"narration"` + Reference string `json:"reference"` // Unique client reference. Only -, ., _ and alphanumeric characters allowed. + } + + // TransactionResponse schema + TransactionResponse struct { + ID string `json:"id"` + Amount string `json:"amount"` + Fee string `json:"fee"` + Narration string `json:"narration"` + Type string `json:"type"` + InitiatedAt interface{} `json:"initiatedAt"` + CompletedAt interface{} `json:"completedAt"` + AccountID string `json:"accountId"` + Details *BankAccount `json:"details,omitempty"` + Status string `json:"status"` + FailedAt interface{} `json:"failedAt"` + ReasonForFailure *string `json:"reasonForFailure,omitempty"` + ClientReference *string `json:"clientReference,omitempty"` + TransactionReference string `json:"transactionReference"` + NipSessionID interface{} `json:"nipSessionId"` + } + + // TransactionsResponse schema + TransactionsResponse struct { + Transactions []TransactionResponse `json:"transactions"` + } +) + +const ( + // StatusPending when the status is pending + StatusPending = "pending" + // StatusFailed when the status is failed + StatusFailed = "failed" + // StatusSuccessful when status is successful + StatusSuccessful = "successful" + // StatusDeclined when a status request is declined + StatusDeclined = "declined" +) From 98bae2c2a41a3d93c04dbb86c0c6bb041f5eb44c Mon Sep 17 00:00:00 2001 From: Odetola Taiwo Date: Wed, 5 Jun 2024 01:19:25 +0100 Subject: [PATCH 2/2] udpate --- model/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/model.go b/model/model.go index 965661f..9a0d2c6 100644 --- a/model/model.go +++ b/model/model.go @@ -11,7 +11,7 @@ const ( // BaseURL to for woven finance BaseURL = "https://sandbox.lenco.co/access/v1" // APIKey for authorization - APIKey = "bf307db1fcb4749120b81470eff89961367c8760f904d8dffcfa78d633d23e67" + APIKey = "" ) var (