From 85998f21b8e71e23f38db1121743a4f0256639ac Mon Sep 17 00:00:00 2001 From: olegshurmin Date: Mon, 3 Sep 2018 12:24:34 +0300 Subject: [PATCH 01/17] add method in async --- internal/connector/soap.go | 104 +++++++++++++++++++++++++++++++++++++ pkg/client/client.go | 72 +++++++++++++++++-------- 2 files changed, 154 insertions(+), 22 deletions(-) diff --git a/internal/connector/soap.go b/internal/connector/soap.go index 0beabfc..711f640 100644 --- a/internal/connector/soap.go +++ b/internal/connector/soap.go @@ -20,6 +20,10 @@ func NewMultiConnectorService(cli *soap.Client) MultiConnectorService { // MultiConnectorService was auto-generated from WSDL // and defines interface for the remote service. Useful for testing. type MultiConnectorService interface { + // BeginQuery was auto-generated from WSDL. + BeginQuery(parameters *BeginQuery) (*MultiConnectorTicket, error) + // EndQuery was auto-generated from WSDL. + EndQuery(parameters *EndQuery) (*response.ResultResponse, error) // Query was auto-generated from WSDL. Query(parameters *Query) (*response.ResultResponse, error) } @@ -41,6 +45,59 @@ type FailedAuthentication struct { type InProgress struct { } +// BeginQuery was auto-generated from WSDL. +type BeginQuery struct { + Request *request.MultiConnectorRequest `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector request,omitempty" json:"request,omitempty" yaml:"request,omitempty"` +} + +// BeginQueryResponse was auto-generated from WSDL. +type BeginQueryResponse struct { + BeginQueryResult *MultiConnectorTicket `xml:"BeginQueryResult,omitempty" json:"BeginQueryResult,omitempty" yaml:"BeginQueryResult,omitempty"` +} + +// EndQuery was auto-generated from WSDL. +type EndQuery struct { + Ticket *MultiConnectorTicket `xml:"ticket,omitempty" json:"ticket,omitempty" yaml:"ticket,omitempty"` +} + +// EndQueryResponse was auto-generated from WSDL. +type EndQueryResponse struct { + EndQueryResult *response.MultiConnectorResponse `xml:"EndQueryResult,omitempty" json:"EndQueryResult,omitempty" yaml:"EndQueryResult,omitempty"` +} + +// MultiConnectorTicket was auto-generated from WSDL. +type MultiConnectorTicket struct { + MessageId *Guid `xml:"MessageId,omitempty" json:"MessageId,omitempty" yaml:"MessageId,omitempty"` +} + +// Operation wrapper for BeginQuery. +// OperationMultiConnectorService_BeginQuery_InputMessage was auto-generated +// from WSDL. +type OperationMultiConnectorService_BeginQuery_InputMessage struct { + Parameters *BeginQuery `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector BeginQuery,omitempty" json:"BeginQuery,omitempty" yaml:"BeginQuery,omitempty"` +} + +// Operation wrapper for BeginQuery. +// OperationMultiConnectorService_BeginQuery_OutputMessage was +// auto-generated from WSDL. +type OperationMultiConnectorService_BeginQuery_OutputMessage struct { + Parameters *BeginQueryResponse `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector BeginQueryResponse,omitempty" json:"BeginQueryResponse,omitempty" yaml:"BeginQueryResponse,omitempty"` +} + +// Operation wrapper for EndQuery. +// OperationMultiConnectorService_EndQuery_InputMessage was auto-generated +// from WSDL. +type OperationMultiConnectorService_EndQuery_InputMessage struct { + Parameters *EndQuery `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector EndQuery,omitempty" json:"EndQuery,omitempty" yaml:"EndQuery,omitempty"` +} + +// Operation wrapper for EndQuery. +// OperationMultiConnectorService_EndQuery_OutputMessage was auto-generated +// from WSDL. +type OperationMultiConnectorService_EndQuery_OutputMessage struct { + Parameters *EndQueryResponse `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector EndQueryResponse,omitempty" json:"EndQueryResponse,omitempty" yaml:"EndQueryResponse,omitempty"` +} + // Query was auto-generated from WSDL. type Query struct { Request *request.MultiConnectorRequest `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector request,omitempty" json:"request,omitempty" yaml:"request,omitempty"` @@ -96,3 +153,50 @@ func (p *multiConnectorService) Query(parameters *Query) (*response.ResultRespon return out.Parameters.QueryResult.ResponseXml.Response.Connector.Data.Response, nil } + +// BeginQuery was auto-generated from WSDL. +func (p *multiConnectorService) BeginQuery(parameters *BeginQuery) (*MultiConnectorTicket, error) { + input := struct { + OperationMultiConnectorService_BeginQuery_InputMessage `xml:"tns:BeginQuery"` + }{ + OperationMultiConnectorService_BeginQuery_InputMessage{ + parameters, + }, + } + + out := struct { + OperationMultiConnectorService_BeginQuery_OutputMessage `xml:"tns:BeginQueryResponse"` + }{} + if err := p.cli.RoundTripWithAction("http://creditinfo.com/schemas/2012/09/MultiConnector/MultiConnectorService/BeginQuery", input, &out); err != nil { + return nil, err + } + return out.Parameters.BeginQueryResult, nil +} + +// EndQuery was auto-generated from WSDL. +func (p *multiConnectorService) EndQuery(parameters *EndQuery) (*response.ResultResponse, error) { + input := struct { + OperationMultiConnectorService_EndQuery_InputMessage `xml:"tns:EndQuery"` + }{ + OperationMultiConnectorService_EndQuery_InputMessage{ + parameters, + }, + } + + out := struct { + OperationMultiConnectorService_EndQuery_OutputMessage `xml:"tns:EndQueryResponse"` + }{} + if err := p.cli.RoundTripWithAction("http://creditinfo.com/schemas/2012/09/MultiConnector/MultiConnectorService/EndQuery", input, &out); err != nil { + return nil, err + } + + if err := out.Parameters.EndQueryResult.ResponseXml.Response.Connector.Error; err != nil { + return nil, errors.New(err.Message) + } + + if status := out.Parameters.EndQueryResult.ResponseXml.Response.Connector.Data.Response.Status; status != "ok" { + return nil, errors.New(status) + } + + return out.Parameters.EndQueryResult.ResponseXml.Response.Connector.Data.Response, nil +} diff --git a/pkg/client/client.go b/pkg/client/client.go index b806f64..4fb77d6 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -14,6 +14,8 @@ import ( //Soap Client provides an interface for getting data out creditinfo service type Client interface { GetIndividualReport(nationalId *string, phone *string, birthDate *time.Time) (*response.ResultResponse, error) + GetIndividualReportBeginQuery(nationalId *string, phone *string, birthDate *time.Time) (ticket *connector.MultiConnectorTicket, err error) + EndQuery(ticket *connector.MultiConnectorTicket) (*response.ResultResponse, error) } type CreditInfoParams struct { Username string @@ -44,42 +46,68 @@ func NewCreditInfoClient(params CreditInfoParams) Client { } } -func (client creditInfo) GetIndividualReport(nationalId *string, phone *string, birthDate *time.Time) (*response.ResultResponse, error) { +func (client *creditInfo) GetIndividualReport(nationalId *string, phone *string, birthDate *time.Time) (response *response.ResultResponse, err error) { messageId := uuid.NewV4().String() dataId := uuid.NewV4().String() - connectorGuuid := client.params.ConnectorId + var birthDdateFormat string if birthDate != nil { birthDdateFormat = birthDate.Format("2006-01-02") } return client.svc.Query(&connector.Query{ - Request: &request.MultiConnectorRequest{ - MessageId: &messageId, - RequestXml: &request.RequestXml{ - RequestXmlItem: &request.RequestXmlItem{ - Connector: &request.ConnectorRequest{ - Id: &connectorGuuid, - Data: &request.ConnectorDataRequest{ - Id: &dataId, - Request: &request.Request{ - Strategy: &request.Strategy{ - Id: client.params.StrategyId, - }, - Cb5SearchParameters: request.Cb5SearchParameters{ - NationalId: nationalId, - }, - CustomFields: &request.CustomFields{ - MobilePhone: phone, - DateOfBirth: &birthDdateFormat, - }, - Consent: true, + Request: client.getMultiConnectorRequest(messageId, dataId, *nationalId, &request.CustomFields{ + MobilePhone: phone, + DateOfBirth: &birthDdateFormat, + }), + }) +} + +func (client *creditInfo) getMultiConnectorRequest(messageId, dataId, nationalId string, customFields *request.CustomFields) *request.MultiConnectorRequest { + return &request.MultiConnectorRequest{ + MessageId: &messageId, + RequestXml: &request.RequestXml{ + RequestXmlItem: &request.RequestXmlItem{ + Connector: &request.ConnectorRequest{ + Id: &client.params.ConnectorId, + Data: &request.ConnectorDataRequest{ + Id: &dataId, + Request: &request.Request{ + Strategy: &request.Strategy{ + Id: client.params.StrategyId, + }, + Cb5SearchParameters: request.Cb5SearchParameters{ + NationalId: &nationalId, }, + CustomFields: customFields, + Consent: true, }, }, }, }, }, + } +} +func (client *creditInfo) GetIndividualReportBeginQuery(nationalId *string, phone *string, birthDate *time.Time) (ticket *connector.MultiConnectorTicket, err error) { + messageId := uuid.NewV4().String() + dataId := uuid.NewV4().String() + + var birthDdateFormat string + if birthDate != nil { + birthDdateFormat = birthDate.Format("2006-01-02") + } + + return client.svc.BeginQuery(&connector.BeginQuery{ + Request: client.getMultiConnectorRequest(messageId, dataId, *nationalId, &request.CustomFields{ + MobilePhone: phone, + DateOfBirth: &birthDdateFormat, + }), + }) +} + +func (client *creditInfo) EndQuery(ticket *connector.MultiConnectorTicket) (*response.ResultResponse, error) { + return client.svc.EndQuery(&connector.EndQuery{ + Ticket: ticket, }) } From fa9bd9ab5070ed394a2ec89f9b52d5a1c29440b6 Mon Sep 17 00:00:00 2001 From: olegshurmin Date: Wed, 26 Sep 2018 17:07:47 +0300 Subject: [PATCH 02/17] fix type --- pkg/response/response.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/response/response.go b/pkg/response/response.go index 097e7ba..52d5e21 100644 --- a/pkg/response/response.go +++ b/pkg/response/response.go @@ -92,7 +92,7 @@ type BankingData struct { Positive int32 `xml:"Positive,omitempty"` Negative int32 `xml:"Negative,omitempty"` Balance float64 `xml:"Balance,omitempty"` - BalanceAtRisk int32 `xml:"BalanceAtRisk,omitempty"` + BalanceAtRisk float64 `xml:"BalanceAtRisk,omitempty"` } type CurrentContracts struct { From 6a65971d9fe119d9038fe9625975408072bd8666 Mon Sep 17 00:00:00 2001 From: olegshurmin Date: Thu, 27 Sep 2018 10:28:14 +0300 Subject: [PATCH 03/17] change type int to float --- pkg/response/response.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/response/response.go b/pkg/response/response.go index 52d5e21..0bc03bb 100644 --- a/pkg/response/response.go +++ b/pkg/response/response.go @@ -102,16 +102,16 @@ type CurrentContracts struct { } type PastDueInformation struct { - TotalCurrentPastDue int32 `xml:"TotalCurrentPastDue,omitempty"` - TotalCurrentDaysPastDue int32 `xml:"TotalCurrentDaysPastDue,omitempty"` - MonthsWithoutArrearsLast12Months int32 `xml:"MonthsWithoutArrearsLast12Months,omitempty"` - TotalMonthsWithHistoryLast12Months int32 `xml:"TotalMonthsWithHistoryLast12Months,omitempty"` - PercMonthsWithoutArrearsLast12Months int32 `xml:"PercMonthsWithoutArrearsLast12Months,omitempty"` + TotalCurrentPastDue float32 `xml:"TotalCurrentPastDue,omitempty"` + TotalCurrentDaysPastDue int32 `xml:"TotalCurrentDaysPastDue,omitempty"` + MonthsWithoutArrearsLast12Months int32 `xml:"MonthsWithoutArrearsLast12Months,omitempty"` + TotalMonthsWithHistoryLast12Months int32 `xml:"TotalMonthsWithHistoryLast12Months,omitempty"` + PercMonthsWithoutArrearsLast12Months float32 `xml:"PercMonthsWithoutArrearsLast12Months,omitempty"` } type RepaymentInformation struct { - TotalMonthlyPayment int32 `xml:"TotalMonthlyPayment,omitempty"` - ClosedContracts int32 `xml:"ClosedContracts,omitempty"` + TotalMonthlyPayment float32 `xml:"TotalMonthlyPayment,omitempty"` + ClosedContracts int32 `xml:"ClosedContracts,omitempty"` } type KenCb5Data struct { From 711c8153ac7dcf7b489bb5a8968039b9f494c470 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Thu, 27 Sep 2018 12:53:53 +0300 Subject: [PATCH 04/17] add raw requests --- internal/connector/soap.go | 19 +++++++++++++++++++ pkg/client/client.go | 24 ++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/internal/connector/soap.go b/internal/connector/soap.go index 711f640..38a9d97 100644 --- a/internal/connector/soap.go +++ b/internal/connector/soap.go @@ -1,6 +1,7 @@ package connector import ( + "fmt" "time" "github.com/devimteam/creditinfo/pkg/request" @@ -26,6 +27,7 @@ type MultiConnectorService interface { EndQuery(parameters *EndQuery) (*response.ResultResponse, error) // Query was auto-generated from WSDL. Query(parameters *Query) (*response.ResultResponse, error) + RawRequest(parameters []byte) ([]byte, error) } // Char was auto-generated from WSDL. @@ -200,3 +202,20 @@ func (p *multiConnectorService) EndQuery(parameters *EndQuery) (*response.Result return out.Parameters.EndQueryResult.ResponseXml.Response.Connector.Data.Response, nil } + +func (p *multiConnectorService) RawRequest(parameters []byte) ([]byte, error) { + input := struct { + RawInputMessage struct { + RawParams []byte `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector request,omitempty" json:"request,omitempty" yaml:"request,omitempty"` + } `xml:"tns:Query"` + }{ + RawInputMessage: struct{ RawParams []byte }{RawParams: parameters}, + } + var output struct { + RawOutput []byte `xml:"tns:QueryResponse"` + } + if err := p.cli.RoundTripWithAction("http://creditinfo.com/schemas/2012/09/MultiConnector/MultiConnectorService/Query", input, &output); err != nil { + return nil, fmt.Errorf("round trip: %v", err) + } + return output.RawOutput, nil +} diff --git a/pkg/client/client.go b/pkg/client/client.go index 4fb77d6..fb7a6eb 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -1,6 +1,7 @@ package client import ( + "encoding/xml" "time" wsse "github.com/casualcode/soap" @@ -8,7 +9,7 @@ import ( "github.com/devimteam/creditinfo/pkg/request" "github.com/devimteam/creditinfo/pkg/response" "github.com/fiorix/wsdl2go/soap" - "github.com/satori/go.uuid" + "github.com/gofrs/uuid" ) //Soap Client provides an interface for getting data out creditinfo service @@ -47,8 +48,14 @@ func NewCreditInfoClient(params CreditInfoParams) Client { } func (client *creditInfo) GetIndividualReport(nationalId *string, phone *string, birthDate *time.Time) (response *response.ResultResponse, err error) { - messageId := uuid.NewV4().String() - dataId := uuid.NewV4().String() + messageId, err := uuid.NewV4() + if err != nil { + return nil, err + } + dataId, err := uuid.NewV4() + if err != nil { + return nil, err + } var birthDdateFormat string if birthDate != nil { @@ -56,7 +63,7 @@ func (client *creditInfo) GetIndividualReport(nationalId *string, phone *string, } return client.svc.Query(&connector.Query{ - Request: client.getMultiConnectorRequest(messageId, dataId, *nationalId, &request.CustomFields{ + Request: client.getMultiConnectorRequest(messageId.String(), dataId.String(), *nationalId, &request.CustomFields{ MobilePhone: phone, DateOfBirth: &birthDdateFormat, }), @@ -111,6 +118,15 @@ func (client *creditInfo) EndQuery(ticket *connector.MultiConnectorTicket) (*res }) } +func (client *creditInfo) RawRequest(parameters []byte) ([]byte, error) { + return client.svc.RawRequest(parameters) +} + +func (client *creditInfo) GetRawMultiConnectorRequest(messageId, dataId, nationalId string, customFields *request.CustomFields) ([]byte, error) { + x := client.getMultiConnectorRequest(messageId, dataId, nationalId, customFields) + return xml.Marshal(x) +} + func getWsseHeader(username string, password string) *wsse.Header { env := &wsse.Envelope{ XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", From 10d83e193a30576d1baaed26aca8b28c7e88ecff Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Thu, 27 Sep 2018 12:56:19 +0300 Subject: [PATCH 05/17] add raw requests to interface --- pkg/client/client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/client/client.go b/pkg/client/client.go index fb7a6eb..6e28a33 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -17,6 +17,8 @@ type Client interface { GetIndividualReport(nationalId *string, phone *string, birthDate *time.Time) (*response.ResultResponse, error) GetIndividualReportBeginQuery(nationalId *string, phone *string, birthDate *time.Time) (ticket *connector.MultiConnectorTicket, err error) EndQuery(ticket *connector.MultiConnectorTicket) (*response.ResultResponse, error) + RawRequest(parameters []byte) ([]byte, error) + GetRawMultiConnectorRequest(messageId, dataId, nationalId string, customFields *request.CustomFields) ([]byte, error) } type CreditInfoParams struct { Username string From 19e3eb21efdec72ef785e48d7d301759c8c887b9 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Thu, 27 Sep 2018 16:49:22 +0300 Subject: [PATCH 06/17] fix struct tags --- internal/connector/soap.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/connector/soap.go b/internal/connector/soap.go index 38a9d97..70a5114 100644 --- a/internal/connector/soap.go +++ b/internal/connector/soap.go @@ -209,7 +209,9 @@ func (p *multiConnectorService) RawRequest(parameters []byte) ([]byte, error) { RawParams []byte `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector request,omitempty" json:"request,omitempty" yaml:"request,omitempty"` } `xml:"tns:Query"` }{ - RawInputMessage: struct{ RawParams []byte }{RawParams: parameters}, + RawInputMessage: struct { + RawParams []byte `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector request,omitempty" json:"request,omitempty" yaml:"request,omitempty"` + }{RawParams: parameters}, } var output struct { RawOutput []byte `xml:"tns:QueryResponse"` From 4b657ada5111b6b7d8a68f72343eddece596ad8f Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Thu, 27 Sep 2018 17:31:18 +0300 Subject: [PATCH 07/17] fix compilation fails because of uuid lib usage --- pkg/client/client.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 6e28a33..d2893ea 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -98,8 +98,14 @@ func (client *creditInfo) getMultiConnectorRequest(messageId, dataId, nationalId } } func (client *creditInfo) GetIndividualReportBeginQuery(nationalId *string, phone *string, birthDate *time.Time) (ticket *connector.MultiConnectorTicket, err error) { - messageId := uuid.NewV4().String() - dataId := uuid.NewV4().String() + messageId, err := uuid.NewV4() + if err != nil { + return nil, err + } + dataId, err := uuid.NewV4() + if err != nil { + return nil, err + } var birthDdateFormat string if birthDate != nil { @@ -107,7 +113,7 @@ func (client *creditInfo) GetIndividualReportBeginQuery(nationalId *string, phon } return client.svc.BeginQuery(&connector.BeginQuery{ - Request: client.getMultiConnectorRequest(messageId, dataId, *nationalId, &request.CustomFields{ + Request: client.getMultiConnectorRequest(messageId.String(), dataId.String(), *nationalId, &request.CustomFields{ MobilePhone: phone, DateOfBirth: &birthDdateFormat, }), From b26c2206a065f341f62b606119cdca6eac3d04c2 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Fri, 28 Sep 2018 17:00:25 +0300 Subject: [PATCH 08/17] try to fix raw request --- Gopkg.lock | 71 +++++++++++++++++++++++++++++++++++++++++--- pkg/client/client.go | 2 +- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 0a3c91c..5cc12f0 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -3,25 +3,88 @@ [[projects]] branch = "master" + digest = "1:d60fdea623cbe445d3831aed9b1a27f9cff2ba2dcb99c0866d79515b6b1b2e4f" name = "github.com/casualcode/soap" packages = ["."] + pruneopts = "" revision = "44eefde542392077c89292f04065d3e7d8852750" [[projects]] branch = "master" + digest = "1:cbd335c225831a82b1a4397bdf758657f22e7da38a8c574396bc15b5098b3290" name = "github.com/fiorix/wsdl2go" packages = ["soap"] + pruneopts = "" revision = "57713bd6b8f5601000fca5e518a5013c4afbfae0" [[projects]] - name = "github.com/satori/go.uuid" + digest = "1:10c7813de846fa10aad0ea9bca34a3c20815d51250e48ba1a3c3c7572184aea8" + name = "github.com/gofrs/uuid" packages = ["."] - revision = "f58768cc1a7a7e77a3bd49e98cdd21419399b6a3" - version = "v1.2.0" + pruneopts = "" + revision = "370558f003bfe29580cd0f698d8640daccdcc45c" + version = "v3.1.1" + +[[projects]] + digest = "1:a6ddc18062f456217783668182e8c5fa3ff73b279d143a96faae5c13db60dc76" + name = "github.com/l-vitaly/gounit" + packages = [ + ".", + "gounitсonstraint", + ] + pruneopts = "" + revision = "d9d8b2917fdd427061d3dc23ae52fc29a2ed860f" + version = "v1.0.5" + +[[projects]] + digest = "1:9ea83adf8e96d6304f394d40436f2eb44c1dc3250d223b74088cc253a6cd0a1c" + name = "github.com/mattn/go-colorable" + packages = ["."] + pruneopts = "" + revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" + version = "v0.0.9" + +[[projects]] + digest = "1:3140e04675a6a91d2a20ea9d10bdadf6072085502e6def6768361260aee4b967" + name = "github.com/mattn/go-isatty" + packages = ["."] + pruneopts = "" + revision = "6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c" + version = "v0.0.4" + +[[projects]] + branch = "master" + digest = "1:50416da10e189bc201e122e20078fb8e680a439cbdd24aaece06c434b4415b60" + name = "github.com/mgutz/ansi" + packages = ["."] + pruneopts = "" + revision = "9520e82c474b0a04dd04f8a40959027271bab992" + +[[projects]] + digest = "1:7365acd48986e205ccb8652cc746f09c8b7876030d53710ea6ef7d0bd0dcd7ca" + name = "github.com/pkg/errors" + packages = ["."] + pruneopts = "" + revision = "645ef00459ed84a119197bfb8d8205042c6df63d" + version = "v0.8.0" + +[[projects]] + branch = "master" + digest = "1:630da6b685efd0155076e77c082a4fb297a5fd49a722d28fb4c728cd8656e060" + name = "golang.org/x/sys" + packages = ["unix"] + pruneopts = "" + revision = "dad3d9fb7b6e83d0f9ac8f54670f6334c3a287b4" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "f95b140d432b0fec0aa99b2030894d29258b75da4ce45c6d550ec080f8fdab23" + input-imports = [ + "github.com/casualcode/soap", + "github.com/fiorix/wsdl2go/soap", + "github.com/gofrs/uuid", + "github.com/l-vitaly/gounit", + "github.com/pkg/errors", + ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/pkg/client/client.go b/pkg/client/client.go index d2893ea..3a0e77b 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -132,7 +132,7 @@ func (client *creditInfo) RawRequest(parameters []byte) ([]byte, error) { func (client *creditInfo) GetRawMultiConnectorRequest(messageId, dataId, nationalId string, customFields *request.CustomFields) ([]byte, error) { x := client.getMultiConnectorRequest(messageId, dataId, nationalId, customFields) - return xml.Marshal(x) + return xml.Marshal(&connector.Query{Request: x}) } func getWsseHeader(username string, password string) *wsse.Header { From 2b8718b6c2b81821df8d107e6a7607a1c6a3a385 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Mon, 1 Oct 2018 13:18:17 +0300 Subject: [PATCH 09/17] update response by schema --- internal/connector/soap.go | 22 +---- pkg/client/client.go | 31 +++--- pkg/response/response.go | 188 ++++++++++++++++++++++++++----------- 3 files changed, 150 insertions(+), 91 deletions(-) diff --git a/internal/connector/soap.go b/internal/connector/soap.go index 70a5114..00d84de 100644 --- a/internal/connector/soap.go +++ b/internal/connector/soap.go @@ -27,7 +27,6 @@ type MultiConnectorService interface { EndQuery(parameters *EndQuery) (*response.ResultResponse, error) // Query was auto-generated from WSDL. Query(parameters *Query) (*response.ResultResponse, error) - RawRequest(parameters []byte) ([]byte, error) } // Char was auto-generated from WSDL. @@ -150,7 +149,7 @@ func (p *multiConnectorService) Query(parameters *Query) (*response.ResultRespon } if status := out.Parameters.QueryResult.ResponseXml.Response.Connector.Data.Response.Status; status != "ok" { - return nil, errors.New(status) + return nil, fmt.Errorf("status: %s; message: %s", status, out.Parameters.QueryResult.ResponseXml.Response.Connector.Data.Response.Infomsg) } return out.Parameters.QueryResult.ResponseXml.Response.Connector.Data.Response, nil @@ -202,22 +201,3 @@ func (p *multiConnectorService) EndQuery(parameters *EndQuery) (*response.Result return out.Parameters.EndQueryResult.ResponseXml.Response.Connector.Data.Response, nil } - -func (p *multiConnectorService) RawRequest(parameters []byte) ([]byte, error) { - input := struct { - RawInputMessage struct { - RawParams []byte `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector request,omitempty" json:"request,omitempty" yaml:"request,omitempty"` - } `xml:"tns:Query"` - }{ - RawInputMessage: struct { - RawParams []byte `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector request,omitempty" json:"request,omitempty" yaml:"request,omitempty"` - }{RawParams: parameters}, - } - var output struct { - RawOutput []byte `xml:"tns:QueryResponse"` - } - if err := p.cli.RoundTripWithAction("http://creditinfo.com/schemas/2012/09/MultiConnector/MultiConnectorService/Query", input, &output); err != nil { - return nil, fmt.Errorf("round trip: %v", err) - } - return output.RawOutput, nil -} diff --git a/pkg/client/client.go b/pkg/client/client.go index 3a0e77b..7cfc3fc 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -1,7 +1,7 @@ package client import ( - "encoding/xml" + "net/http" "time" wsse "github.com/casualcode/soap" @@ -17,9 +17,8 @@ type Client interface { GetIndividualReport(nationalId *string, phone *string, birthDate *time.Time) (*response.ResultResponse, error) GetIndividualReportBeginQuery(nationalId *string, phone *string, birthDate *time.Time) (ticket *connector.MultiConnectorTicket, err error) EndQuery(ticket *connector.MultiConnectorTicket) (*response.ResultResponse, error) - RawRequest(parameters []byte) ([]byte, error) - GetRawMultiConnectorRequest(messageId, dataId, nationalId string, customFields *request.CustomFields) ([]byte, error) } + type CreditInfoParams struct { Username string Password string @@ -34,13 +33,15 @@ type creditInfo struct { } // NewClient returns a Client interface for given soap api creditinfo -func NewCreditInfoClient(params CreditInfoParams) Client { +func NewCreditInfoClient(params CreditInfoParams, pre func(*http.Request), post func(*http.Response)) *creditInfo { svc := connector.NewMultiConnectorService(&soap.Client{ URL: params.Endpoint, Header: getWsseHeader(params.Username, params.Password), Namespace: connector.Namespace, ExcludeActionNamespace: true, + Pre: pre, + Post: post, }) return &creditInfo{ @@ -65,10 +66,15 @@ func (client *creditInfo) GetIndividualReport(nationalId *string, phone *string, } return client.svc.Query(&connector.Query{ - Request: client.getMultiConnectorRequest(messageId.String(), dataId.String(), *nationalId, &request.CustomFields{ - MobilePhone: phone, - DateOfBirth: &birthDdateFormat, - }), + Request: client.getMultiConnectorRequest( + messageId.String(), + dataId.String(), + *nationalId, + &request.CustomFields{ + MobilePhone: phone, + DateOfBirth: &birthDdateFormat, + }, + ), }) } @@ -126,15 +132,6 @@ func (client *creditInfo) EndQuery(ticket *connector.MultiConnectorTicket) (*res }) } -func (client *creditInfo) RawRequest(parameters []byte) ([]byte, error) { - return client.svc.RawRequest(parameters) -} - -func (client *creditInfo) GetRawMultiConnectorRequest(messageId, dataId, nationalId string, customFields *request.CustomFields) ([]byte, error) { - x := client.getMultiConnectorRequest(messageId, dataId, nationalId, customFields) - return xml.Marshal(&connector.Query{Request: x}) -} - func getWsseHeader(username string, password string) *wsse.Header { env := &wsse.Envelope{ XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", diff --git a/pkg/response/response.go b/pkg/response/response.go index 0bc03bb..6b4bc0e 100644 --- a/pkg/response/response.go +++ b/pkg/response/response.go @@ -1,6 +1,9 @@ package response -import "time" +import ( + "encoding/xml" + "time" +) type MultiConnectorResponse struct { MessageId *string `xml:"MessageId,omitempty" json:"MessageId,omitempty" yaml:"MessageId,omitempty"` @@ -42,32 +45,49 @@ type ResultResponse struct { PolicyRules *PolicyRule `xml:"PolicyRules,omitempty"` KenCb5Data *KenCb5Data `xml:"KenCb5_data,omitempty"` Strategy *StrategyResponse `xml:"Strategy,omitempty"` + Extract *Extract `xml:"Extract,omitempty"` } type GeneralInformation struct { - SubjectIDNumber string `xml:"SubjectIDNumber,omitempty"` - RequestDate time.Time `xml:"RequestDate,omitempty"` - ReferenceNumber string `xml:"ReferenceNumber,omitempty"` - RecommendedDecision string `xml:"RecommendedDecision,omitempty"` - BrokenRules int32 `xml:"BrokenRules,omitempty"` - CreditLimit int32 `xml:"CreditLimit,omitempty"` + SubjectIDNumber *string `xml:"SubjectIDNumber,omitempty"` + RequestDate *time.Time `xml:"RequestDate,omitempty"` + ReferenceNumber *string `xml:"ReferenceNumber,omitempty"` + RecommendedDecision *string `xml:"RecommendedDecision,omitempty"` + BrokenRules *int32 `xml:"BrokenRules,omitempty"` + CreditLimit *int32 `xml:"CreditLimit,omitempty"` } type PersonalInformation struct { - FullName string `xml:"FullName,omitempty"` - DateOfBirth time.Time `xml:"DateOfBirth,omitempty"` - Age uint32 `xml:"Age,omitempty"` - Gender string `xml:"Gender,omitempty"` - MaritalStatus string `xml:"MaritalStatus,omitempty"` - EmploymentStatus string `xml:"EmploymentStatus,omitempty"` + FullName *string `xml:"FullName,omitempty"` + DateOfBirth *time.Time `xml:"DateOfBirth,omitempty"` + Age *int64 `xml:"Age,omitempty"` + Gender *string `xml:"Gender,omitempty"` + MaritalStatus *string `xml:"MaritalStatus,omitempty"` + NumberOfDependents *int64 `xml:"NumberOfDependents,omitempty"` + Education *string `xml:"Education,omitempty"` + EmploymentStatus *string `xml:"EmploymentStatus,omitempty"` + CompanyName *string `xml:"CompanyName,omitempty"` + DateOfEstablishment *string `xml:"DateOfEstablishment,omitempty"` + YearsInOperation *int64 `xml:"YearsInOperation,omitempty"` + LegalForm *string `xml:"LegalForm,omitempty"` } type ScoringAnalysis struct { - CIPScore int32 `xml:"CIPScore,omitempty"` - CIPRiskGrade string `xml:"CIPRiskGrade,omitempty"` - MobileScore int32 `xml:"MobileScore,omitempty"` - MobileScoreRiskGrade string `xml:"MobileScoreRiskGrade,omitempty"` - Conclusion string `xml:"Conclusion,omitempty"` - PolicyRules *PolicyRule `xml:"PolicyRules,omitempty"` + CIPScore *int64 `xml:"CIPScore,omitempty"` + CIPRiskGrade *string `xml:"CIPRiskGrade,omitempty"` + MobileScore *int64 `xml:"MobileScore,omitempty"` + MobileScoreRiskGrade *string `xml:"MobileScoreRiskGrade,omitempty"` + FactorsAffectingScores *FactorsAffectingScores `xml:"FactorsAffectingScores,omitempty"` + Conclusion *string `xml:"Conclusion,omitempty"` + PolicyRules *PolicyRule `xml:"PolicyRules,omitempty"` +} + +type FactorsAffectingScores struct { + Factor []Factor `xml:"Factor,omitempty"` +} + +type Factor struct { + Code string `xml:"code,attr,omitempty"` + Factor string `xml:"Factor,omitempty"` } type RuleItem struct { @@ -81,54 +101,116 @@ type PolicyRule struct { } type InquiriesAnalysis struct { - TotalLast7Days int32 `xml:"TotalLast7Days,omitempty"` - TotalLast1Month int32 `xml:"TotalLast1Month,omitempty"` - NonBankingLast1Month int32 `xml:"NonBankingLast1Month,omitempty"` + TotalLast7Days int64 `xml:"TotalLast7Days,omitempty"` + TotalLast1Month int64 `xml:"TotalLast1Month,omitempty"` + NonBankingLast1Month int64 `xml:"NonBankingLast1Month,omitempty"` PolicyRules *PolicyRule `xml:"PolicyRules,omitempty"` - Conclusion string `xml:"Conclusion,omitempty"` + Conclusion *string `xml:"Conclusion,omitempty"` } -type BankingData struct { - Positive int32 `xml:"Positive,omitempty"` - Negative int32 `xml:"Negative,omitempty"` - Balance float64 `xml:"Balance,omitempty"` - BalanceAtRisk float64 `xml:"BalanceAtRisk,omitempty"` +type CurrentContracts struct { + CurrentBanking *ContractsSummary `xml:"CurrentBanking,omitempty"` + CurrentNonBanking *ContractsSummary `xml:"CurrentNonBanking,omitempty"` + Total *ContractsSummary `xml:"Total,omitempty"` } -type CurrentContracts struct { - CurrentBanking *BankingData `xml:"CurrentBanking,omitempty"` - CurrentNonBanking *BankingData `xml:"CurrentNonBanking,omitempty"` - Total *BankingData `xml:"Total,omitempty"` +type ContractsSummary struct { + Positive int64 `xml:"Positive,omitempty"` + Negative int64 `xml:"Negative,omitempty"` + Balance float64 `xml:"Balance,omitempty"` + BalanceAtRisk float64 `xml:"BalanceAtRisk,omitempty"` } type PastDueInformation struct { - TotalCurrentPastDue float32 `xml:"TotalCurrentPastDue,omitempty"` - TotalCurrentDaysPastDue int32 `xml:"TotalCurrentDaysPastDue,omitempty"` - MonthsWithoutArrearsLast12Months int32 `xml:"MonthsWithoutArrearsLast12Months,omitempty"` - TotalMonthsWithHistoryLast12Months int32 `xml:"TotalMonthsWithHistoryLast12Months,omitempty"` - PercMonthsWithoutArrearsLast12Months float32 `xml:"PercMonthsWithoutArrearsLast12Months,omitempty"` + TotalCurrentPastDue *float64 `xml:"TotalCurrentPastDue,omitempty"` + TotalCurrentDaysPastDue *int64 `xml:"TotalCurrentDaysPastDue,omitempty"` + WorstCurrentPastDue *float64 `xml:"WorstCurrentPastDue,omitempty"` + WorstCurrentDaysPastDue *int64 `xml:"WorstCurrentDaysPastDue,omitempty"` + WorstPastDueLast12Months *float64 `xml:"WorstPastDueLast12Months,omitempty"` + WorstPastDueDaysLast12Months *int64 `xml:"WorstPastDueDaysLast12Months,omitempty"` + MonthsWithoutArrearsLast12Months *int64 `xml:"MonthsWithoutArrearsLast12Months,omitempty"` + TotalMonthsWithHistoryLast12Months *int64 `xml:"TotalMonthsWithHistoryLast12Months,omitempty"` + PercMonthsWithoutArrearsLast12Months *float64 `xml:"PercMonthsWithoutArrearsLast12Months,omitempty"` } type RepaymentInformation struct { - TotalMonthlyPayment float32 `xml:"TotalMonthlyPayment,omitempty"` - ClosedContracts int32 `xml:"ClosedContracts,omitempty"` + TotalMonthlyPayment *float64 `xml:"TotalMonthlyPayment,omitempty"` + NextContractMaturesInMonths *int64 `xml:"NextContractMaturesInMonths,omitempty"` + AllContractsMatureInMonths *int64 `xml:"AllContractsMatureInMonths,omitempty"` + LastContractOpened *Date `xml:"LastContractOpened,omitempty"` + LastContractClosed *Date `xml:"LastContractClosed,omitempty"` + ClosedContracts *int64 `xml:"ClosedContracts,omitempty"` +} + +const xsdDateFormat = "2006-01-02" + +type Date time.Time + +func (d Date) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + t := time.Time(d).Format(xsdDateFormat) + return e.EncodeElement(t, start) +} + +func (d *Date) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error { + var temp string + err := dec.DecodeElement(&temp, &start) + if err != nil { + return err + } + t, err := time.Parse(xsdDateFormat, temp) + if err != nil { + return err + } + *d = Date(t) + return nil } type KenCb5Data struct { - CIP *KenCb5DataCIP `xml:"CIP,omitempty"` - CIQ *KenCb5DataCIQ `xml:"CIQ,omitempty"` - ContractOverview *ContractOverview `xml:"ContractOverview,omitempty"` - ContractSummary *ContractSummary `xml:"ContractSummary,omitempty"` - Contracts *Contracts `xml:"Contracts,omitempty"` - CurrentRelations *CurrentRelations `xml:"CurrentRelations,omitempty"` - Dashboard *Dashboard `xml:"Dashboard,omitempty"` - Disputes *Disputes `xml:"Disputes,omitempty"` - Individual *Individual `xml:"Individual,omitempty"` - Inquiries *Inquiries `xml:"Inquiries,omitempty"` - Parameters *Parameters `xml:"Parameters,omitempty"` - PaymentIncidentList *PaymentIncidentList `xml:"PaymentIncidentList,omitempty"` - ReportInfo *ReportInfo `xml:"ReportInfo,omitempty"` - SubjectInfoHistory *SubjectInfoHistory `xml:"SubjectInfoHistory,omitempty"` + RawData []byte `xml:",innerxml"` +} + +type Extract struct { + NationalId *string `xml:"NationalId,omitempty"` + Date *time.Time `xml:"Date,omitempty"` + Decision *string `xml:"Decision,omitempty"` + CreditLimit *float64 `xml:"CreditLimit,omitempty"` + PotentialCreditLimit *float64 `xml:"PotentialCreditLimit,omitempty"` + MobileScore *float64 `xml:"MobileScore,omitempty"` + MobileGrade *string `xml:"MobileGrade,omitempty"` + CIPScore *float64 `xml:"CIPScore,omitempty"` + CIPGrade *string `xml:"CIPGrade,omitempty"` + SCR1Result *string `xml:"SCR1Result,omitempty"` + SCR1Parameter *string `xml:"SCR1Parameter,omitempty"` + SCR1Value *string `xml:"SCR1Value,omitempty"` + SCR3Result *string `xml:"SCR3Result,omitempty"` + SCR3Parameter *string `xml:"SCR3Parameter,omitempty"` + SCR3Value *string `xml:"SCR3Value,omitempty"` + INQ2Result *string `xml:"INQ2Result,omitempty"` + INQ2Parameter *float64 `xml:"INQ2Parameter,omitempty"` + INQ2Value *float64 `xml:"INQ2Value,omitempty"` + RSK2Result *string `xml:"RSK2Result,omitempty"` + RSK2Parameter *float64 `xml:"RSK2Parameter,omitempty"` + RSK2Value *float64 `xml:"RSK2Value,omitempty"` + RSK3Result *string `xml:"RSK3Result,omitempty"` + RSK3Parameter *float64 `xml:"RSK3Parameter,omitempty"` + RSK3Value *float64 `xml:"RSK3Value,omitempty"` + RSK4Result *string `xml:"RSK4Result,omitempty"` + RSK4Parameter *float64 `xml:"RSK4Parameter,omitempty"` + RSK4Value *float64 `xml:"RSK4Value,omitempty"` + RSK6Result *string `xml:"RSK6Result,omitempty"` + RSK6Parameter *float64 `xml:"RSK6Parameter,omitempty"` + RSK6Value *float64 `xml:"RSK6Value,omitempty"` + RSK7Result *string `xml:"RSK7Result,omitempty"` + RSK7Parameter *float64 `xml:"RSK7Parameter,omitempty"` + RSK7Value *float64 `xml:"RSK7Value,omitempty"` + RSK8Result *string `xml:"RSK8Result,omitempty"` + RSK8Parameter *float64 `xml:"RSK8Parameter,omitempty"` + RSK8Value *float64 `xml:"RSK8Value,omitempty"` + RSK11Result *string `xml:"RSK11Result,omitempty"` + RSK11Parameter *float64 `xml:"RSK11Parameter,omitempty"` + RSK11Value *float64 `xml:"RSK11Value,omitempty"` + RSK12Result *string `xml:"RSK12Result,omitempty"` + MobilePhone *string `xml:"MobilePhone,omitempty"` } type Record struct { From 1e01ea5100a04e029947e8d8fdc2a1f2f9c6a485 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Mon, 1 Oct 2018 14:30:56 +0300 Subject: [PATCH 10/17] changes to soap client (use our forked) --- Gopkg.lock | 9 ++++----- Gopkg.toml | 4 ++-- internal/connector/soap.go | 21 +++++++++++---------- pkg/client/client.go | 23 ++++++++++++----------- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 5cc12f0..108b7cf 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -10,12 +10,11 @@ revision = "44eefde542392077c89292f04065d3e7d8852750" [[projects]] - branch = "master" - digest = "1:cbd335c225831a82b1a4397bdf758657f22e7da38a8c574396bc15b5098b3290" - name = "github.com/fiorix/wsdl2go" + digest = "1:4592dcb5f273a4f6a31e155ddd17520301764b29eb7a3aa472ba960877b61778" + name = "github.com/devimteam/wsdl2go" packages = ["soap"] pruneopts = "" - revision = "57713bd6b8f5601000fca5e518a5013c4afbfae0" + revision = "7ed0da94ff4f278c98478381bdb7af3080d5be03" [[projects]] digest = "1:10c7813de846fa10aad0ea9bca34a3c20815d51250e48ba1a3c3c7572184aea8" @@ -81,7 +80,7 @@ analyzer-version = 1 input-imports = [ "github.com/casualcode/soap", - "github.com/fiorix/wsdl2go/soap", + "github.com/devimteam/wsdl2go/soap", "github.com/gofrs/uuid", "github.com/l-vitaly/gounit", "github.com/pkg/errors", diff --git a/Gopkg.toml b/Gopkg.toml index 7d5dcc1..2cee3ae 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -3,8 +3,8 @@ branch = "master" [[constraint]] - name = "github.com/fiorix/wsdl2go" - branch = "master" + name = "github.com/devimteam/wsdl2go" + revision = "7ed0da94ff4f278c98478381bdb7af3080d5be03" [[constraint]] name = "github.com/satori/go.uuid" diff --git a/internal/connector/soap.go b/internal/connector/soap.go index 00d84de..af9c66d 100644 --- a/internal/connector/soap.go +++ b/internal/connector/soap.go @@ -1,12 +1,13 @@ package connector import ( + "context" "fmt" "time" "github.com/devimteam/creditinfo/pkg/request" "github.com/devimteam/creditinfo/pkg/response" - "github.com/fiorix/wsdl2go/soap" + "github.com/devimteam/wsdl2go/soap" "github.com/pkg/errors" ) @@ -22,11 +23,11 @@ func NewMultiConnectorService(cli *soap.Client) MultiConnectorService { // and defines interface for the remote service. Useful for testing. type MultiConnectorService interface { // BeginQuery was auto-generated from WSDL. - BeginQuery(parameters *BeginQuery) (*MultiConnectorTicket, error) + BeginQuery(ctx context.Context, parameters *BeginQuery) (*MultiConnectorTicket, error) // EndQuery was auto-generated from WSDL. - EndQuery(parameters *EndQuery) (*response.ResultResponse, error) + EndQuery(ctx context.Context, parameters *EndQuery) (*response.ResultResponse, error) // Query was auto-generated from WSDL. - Query(parameters *Query) (*response.ResultResponse, error) + Query(ctx context.Context, parameters *Query) (*response.ResultResponse, error) } // Char was auto-generated from WSDL. @@ -129,7 +130,7 @@ type multiConnectorService struct { } // Query was auto-generated from WSDL. -func (p *multiConnectorService) Query(parameters *Query) (*response.ResultResponse, error) { +func (p *multiConnectorService) Query(ctx context.Context, parameters *Query) (*response.ResultResponse, error) { intput := struct { OperationMultiConnectorService_Query_InputMessage `xml:"tns:Query"` }{ @@ -141,7 +142,7 @@ func (p *multiConnectorService) Query(parameters *Query) (*response.ResultRespon out := struct { OperationMultiConnectorService_Query_OutputMessage `xml:"tns:QueryResponse"` }{} - if err := p.cli.RoundTripWithAction("http://creditinfo.com/schemas/2012/09/MultiConnector/MultiConnectorService/Query", intput, &out); err != nil { + if err := p.cli.RoundTripWithActionContext(ctx, "http://creditinfo.com/schemas/2012/09/MultiConnector/MultiConnectorService/Query", intput, &out); err != nil { return nil, err } if err := out.Parameters.QueryResult.ResponseXml.Response.Connector.Error; err != nil { @@ -156,7 +157,7 @@ func (p *multiConnectorService) Query(parameters *Query) (*response.ResultRespon } // BeginQuery was auto-generated from WSDL. -func (p *multiConnectorService) BeginQuery(parameters *BeginQuery) (*MultiConnectorTicket, error) { +func (p *multiConnectorService) BeginQuery(ctx context.Context, parameters *BeginQuery) (*MultiConnectorTicket, error) { input := struct { OperationMultiConnectorService_BeginQuery_InputMessage `xml:"tns:BeginQuery"` }{ @@ -168,14 +169,14 @@ func (p *multiConnectorService) BeginQuery(parameters *BeginQuery) (*MultiConnec out := struct { OperationMultiConnectorService_BeginQuery_OutputMessage `xml:"tns:BeginQueryResponse"` }{} - if err := p.cli.RoundTripWithAction("http://creditinfo.com/schemas/2012/09/MultiConnector/MultiConnectorService/BeginQuery", input, &out); err != nil { + if err := p.cli.RoundTripWithActionContext(ctx, "http://creditinfo.com/schemas/2012/09/MultiConnector/MultiConnectorService/BeginQuery", input, &out); err != nil { return nil, err } return out.Parameters.BeginQueryResult, nil } // EndQuery was auto-generated from WSDL. -func (p *multiConnectorService) EndQuery(parameters *EndQuery) (*response.ResultResponse, error) { +func (p *multiConnectorService) EndQuery(ctx context.Context, parameters *EndQuery) (*response.ResultResponse, error) { input := struct { OperationMultiConnectorService_EndQuery_InputMessage `xml:"tns:EndQuery"` }{ @@ -187,7 +188,7 @@ func (p *multiConnectorService) EndQuery(parameters *EndQuery) (*response.Result out := struct { OperationMultiConnectorService_EndQuery_OutputMessage `xml:"tns:EndQueryResponse"` }{} - if err := p.cli.RoundTripWithAction("http://creditinfo.com/schemas/2012/09/MultiConnector/MultiConnectorService/EndQuery", input, &out); err != nil { + if err := p.cli.RoundTripWithActionContext(ctx, "http://creditinfo.com/schemas/2012/09/MultiConnector/MultiConnectorService/EndQuery", input, &out); err != nil { return nil, err } diff --git a/pkg/client/client.go b/pkg/client/client.go index 7cfc3fc..bebff95 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -1,6 +1,7 @@ package client import ( + "context" "net/http" "time" @@ -8,15 +9,15 @@ import ( "github.com/devimteam/creditinfo/internal/connector" "github.com/devimteam/creditinfo/pkg/request" "github.com/devimteam/creditinfo/pkg/response" - "github.com/fiorix/wsdl2go/soap" + "github.com/devimteam/wsdl2go/soap" "github.com/gofrs/uuid" ) //Soap Client provides an interface for getting data out creditinfo service type Client interface { - GetIndividualReport(nationalId *string, phone *string, birthDate *time.Time) (*response.ResultResponse, error) - GetIndividualReportBeginQuery(nationalId *string, phone *string, birthDate *time.Time) (ticket *connector.MultiConnectorTicket, err error) - EndQuery(ticket *connector.MultiConnectorTicket) (*response.ResultResponse, error) + GetIndividualReport(ctx context.Context, nationalId *string, phone *string, birthDate *time.Time) (*response.ResultResponse, error) + GetIndividualReportBeginQuery(ctx context.Context, nationalId *string, phone *string, birthDate *time.Time) (ticket *connector.MultiConnectorTicket, err error) + EndQuery(ctx context.Context, ticket *connector.MultiConnectorTicket) (*response.ResultResponse, error) } type CreditInfoParams struct { @@ -33,7 +34,7 @@ type creditInfo struct { } // NewClient returns a Client interface for given soap api creditinfo -func NewCreditInfoClient(params CreditInfoParams, pre func(*http.Request), post func(*http.Response)) *creditInfo { +func NewCreditInfoClient(params CreditInfoParams, pre func(context.Context, *http.Request), post func(context.Context, *http.Response)) *creditInfo { svc := connector.NewMultiConnectorService(&soap.Client{ URL: params.Endpoint, @@ -50,7 +51,7 @@ func NewCreditInfoClient(params CreditInfoParams, pre func(*http.Request), post } } -func (client *creditInfo) GetIndividualReport(nationalId *string, phone *string, birthDate *time.Time) (response *response.ResultResponse, err error) { +func (client *creditInfo) GetIndividualReport(ctx context.Context, nationalId *string, phone *string, birthDate *time.Time) (response *response.ResultResponse, err error) { messageId, err := uuid.NewV4() if err != nil { return nil, err @@ -65,7 +66,7 @@ func (client *creditInfo) GetIndividualReport(nationalId *string, phone *string, birthDdateFormat = birthDate.Format("2006-01-02") } - return client.svc.Query(&connector.Query{ + return client.svc.Query(ctx, &connector.Query{ Request: client.getMultiConnectorRequest( messageId.String(), dataId.String(), @@ -103,7 +104,7 @@ func (client *creditInfo) getMultiConnectorRequest(messageId, dataId, nationalId }, } } -func (client *creditInfo) GetIndividualReportBeginQuery(nationalId *string, phone *string, birthDate *time.Time) (ticket *connector.MultiConnectorTicket, err error) { +func (client *creditInfo) GetIndividualReportBeginQuery(ctx context.Context, nationalId *string, phone *string, birthDate *time.Time) (ticket *connector.MultiConnectorTicket, err error) { messageId, err := uuid.NewV4() if err != nil { return nil, err @@ -118,7 +119,7 @@ func (client *creditInfo) GetIndividualReportBeginQuery(nationalId *string, phon birthDdateFormat = birthDate.Format("2006-01-02") } - return client.svc.BeginQuery(&connector.BeginQuery{ + return client.svc.BeginQuery(ctx, &connector.BeginQuery{ Request: client.getMultiConnectorRequest(messageId.String(), dataId.String(), *nationalId, &request.CustomFields{ MobilePhone: phone, DateOfBirth: &birthDdateFormat, @@ -126,8 +127,8 @@ func (client *creditInfo) GetIndividualReportBeginQuery(nationalId *string, phon }) } -func (client *creditInfo) EndQuery(ticket *connector.MultiConnectorTicket) (*response.ResultResponse, error) { - return client.svc.EndQuery(&connector.EndQuery{ +func (client *creditInfo) EndQuery(ctx context.Context, ticket *connector.MultiConnectorTicket) (*response.ResultResponse, error) { + return client.svc.EndQuery(ctx, &connector.EndQuery{ Ticket: ticket, }) } From 31151d2458d17154153fa6dc444ecd6c006c9cb8 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Mon, 1 Oct 2018 15:04:16 +0300 Subject: [PATCH 11/17] dep ensure: update soap lib --- Gopkg.lock | 4 ++-- Gopkg.toml | 2 +- test/integration/client_test.go | 13 +++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 108b7cf..a6c979e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -10,11 +10,11 @@ revision = "44eefde542392077c89292f04065d3e7d8852750" [[projects]] - digest = "1:4592dcb5f273a4f6a31e155ddd17520301764b29eb7a3aa472ba960877b61778" + digest = "1:5c0fdc3abd05f58604f4faa6123f999a138865da63ccdd77bbae13304c15e122" name = "github.com/devimteam/wsdl2go" packages = ["soap"] pruneopts = "" - revision = "7ed0da94ff4f278c98478381bdb7af3080d5be03" + revision = "5c4e6c7ba9d9355bba952997eb0c639cb90f672e" [[projects]] digest = "1:10c7813de846fa10aad0ea9bca34a3c20815d51250e48ba1a3c3c7572184aea8" diff --git a/Gopkg.toml b/Gopkg.toml index 2cee3ae..6461406 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -4,7 +4,7 @@ [[constraint]] name = "github.com/devimteam/wsdl2go" - revision = "7ed0da94ff4f278c98478381bdb7af3080d5be03" + revision = "5c4e6c7ba9d9355bba952997eb0c639cb90f672e" [[constraint]] name = "github.com/satori/go.uuid" diff --git a/test/integration/client_test.go b/test/integration/client_test.go index 02d99d3..b4d7703 100644 --- a/test/integration/client_test.go +++ b/test/integration/client_test.go @@ -1,7 +1,9 @@ package unit import ( + "context" "testing" + "time" "github.com/devimteam/creditinfo/pkg/client" "github.com/l-vitaly/gounit" @@ -19,12 +21,11 @@ func TestGetIndividualReportSuccess(t *testing.T) { Endpoint: "https://endpoint.example.com", } - creditInfo := client.NewCreditInfoClient(params) + creditInfo := client.NewCreditInfoClient(params, nil, nil) nationalId := "12345678" phone := "25411111111" - response, err := creditInfo.GetIndividualReport(&nationalId, &phone, nil) - - t.Log(response.GeneralInformation.RecommendedDecision) + birthday := time.Now() + response, err := creditInfo.GetIndividualReport(context.Background(), &nationalId, &phone, &birthday) unit.AssertNil(err, "err not nil") unit.AssertEquals(response.Status, "ok", "status not equal 'ok'") @@ -42,10 +43,10 @@ func TestGetIndividualReportFail(t *testing.T) { Endpoint: "https://endpoint.example.com", } - creditInfo := client.NewCreditInfoClient(params) + creditInfo := client.NewCreditInfoClient(params, nil, nil) nationalId := "0" phone := "25411111111" - response, err := creditInfo.GetIndividualReport(&nationalId, &phone, nil) + response, err := creditInfo.GetIndividualReport(context.Background(), &nationalId, &phone, nil) unit.AssertNotNil(err, "err nil") unit.AssertNil(response, "err nil") From f7d671be5419378bd51f7ff54ac38fba5acc55b2 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Tue, 2 Oct 2018 16:14:34 +0300 Subject: [PATCH 12/17] move connector from internal to pkg --- pkg/client/client.go | 2 +- {internal => pkg}/connector/soap.go | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {internal => pkg}/connector/soap.go (100%) diff --git a/pkg/client/client.go b/pkg/client/client.go index bebff95..1473aa8 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -6,7 +6,7 @@ import ( "time" wsse "github.com/casualcode/soap" - "github.com/devimteam/creditinfo/internal/connector" + "github.com/devimteam/creditinfo/pkg/connector" "github.com/devimteam/creditinfo/pkg/request" "github.com/devimteam/creditinfo/pkg/response" "github.com/devimteam/wsdl2go/soap" diff --git a/internal/connector/soap.go b/pkg/connector/soap.go similarity index 100% rename from internal/connector/soap.go rename to pkg/connector/soap.go From 0c93fe6c3495de59ed6895243bbd08c618a22e09 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Wed, 3 Oct 2018 11:21:14 +0300 Subject: [PATCH 13/17] update internal creditinfo fields --- pkg/client/client.go | 14 ++++++++------ pkg/request/request.go | 25 ++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 1473aa8..382f1d0 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -61,9 +61,10 @@ func (client *creditInfo) GetIndividualReport(ctx context.Context, nationalId *s return nil, err } - var birthDdateFormat string + var bdate *request.Date if birthDate != nil { - birthDdateFormat = birthDate.Format("2006-01-02") + t := request.Date(*birthDate) + bdate = &t } return client.svc.Query(ctx, &connector.Query{ @@ -73,7 +74,7 @@ func (client *creditInfo) GetIndividualReport(ctx context.Context, nationalId *s *nationalId, &request.CustomFields{ MobilePhone: phone, - DateOfBirth: &birthDdateFormat, + DateOfBirth: bdate, }, ), }) @@ -114,15 +115,16 @@ func (client *creditInfo) GetIndividualReportBeginQuery(ctx context.Context, nat return nil, err } - var birthDdateFormat string + var bdate *request.Date if birthDate != nil { - birthDdateFormat = birthDate.Format("2006-01-02") + t := request.Date(*birthDate) + bdate = &t } return client.svc.BeginQuery(ctx, &connector.BeginQuery{ Request: client.getMultiConnectorRequest(messageId.String(), dataId.String(), *nationalId, &request.CustomFields{ MobilePhone: phone, - DateOfBirth: &birthDdateFormat, + DateOfBirth: bdate, }), }) } diff --git a/pkg/request/request.go b/pkg/request/request.go index 7ae2e27..127d517 100644 --- a/pkg/request/request.go +++ b/pkg/request/request.go @@ -68,5 +68,28 @@ type Cb5SearchParameters struct { type CustomFields struct { MobilePhone *string `xml:"MobilePhone,omitempty" json:"Timeout,omitempty" yaml:"Timeout,omitempty"` - DateOfBirth *string `xml:"DateOfBirth,omitempty" json:"DateOfBirth,omitempty" yaml:"DateOfBirth,omitempty"` + DateOfBirth *Date `xml:"DateOfBirth,omitempty" json:"DateOfBirth,omitempty" yaml:"DateOfBirth,omitempty"` +} + +const xsdDateFormat = "2006-01-02" + +type Date time.Time + +func (d Date) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + t := time.Time(d).Format(xsdDateFormat) + return e.EncodeElement(t, start) +} + +func (d *Date) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error { + var temp string + err := dec.DecodeElement(&temp, &start) + if err != nil { + return err + } + t, err := time.Parse(xsdDateFormat, temp) + if err != nil { + return err + } + *d = Date(t) + return nil } From 39cc40744891c7d63f0cacca718a9962fb4229b8 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Thu, 15 Nov 2018 12:10:25 +0300 Subject: [PATCH 14/17] change PostalCode type to int32 --- pkg/response/response.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/response/response.go b/pkg/response/response.go index 6b4bc0e..109c207 100644 --- a/pkg/response/response.go +++ b/pkg/response/response.go @@ -422,7 +422,7 @@ type MainAddress struct { District string `xml:"District,omitempty"` Region string `xml:"Region,omitempty"` PlotNumber string `xml:"PlotNumber,omitempty"` - PostalCode int32 `xml:"PostalCode,omitempty"` + PostalCode string `xml:"PostalCode,omitempty"` Street string `xml:"Street,omitempty"` Town string `xml:"Town,omitempty"` } From d9c8f82828bd5344d9fd40a4b6b4f42d9089d58c Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Fri, 16 Nov 2018 11:04:39 +0300 Subject: [PATCH 15/17] implement C# timeout --- pkg/client/client.go | 2 ++ pkg/request/request.go | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 382f1d0..c9c8e49 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -26,6 +26,7 @@ type CreditInfoParams struct { ConnectorId string StrategyId string Endpoint string + Timeout *time.Duration } type creditInfo struct { @@ -83,6 +84,7 @@ func (client *creditInfo) GetIndividualReport(ctx context.Context, nationalId *s func (client *creditInfo) getMultiConnectorRequest(messageId, dataId, nationalId string, customFields *request.CustomFields) *request.MultiConnectorRequest { return &request.MultiConnectorRequest{ MessageId: &messageId, + Timeout: request.NilDuration(client.params.Timeout), RequestXml: &request.RequestXml{ RequestXmlItem: &request.RequestXmlItem{ Connector: &request.ConnectorRequest{ diff --git a/pkg/request/request.go b/pkg/request/request.go index 127d517..eb655fd 100644 --- a/pkg/request/request.go +++ b/pkg/request/request.go @@ -1,20 +1,38 @@ package request import ( + "bytes" "encoding/xml" + "strconv" "time" ) // DateTime in WSDL format. type DateTime string +type Duration time.Duration + +func (d Duration) String() string { + buf := bytes.NewBufferString("PT") + buf.WriteString(strconv.Itoa(int(time.Duration(d).Seconds()))) + buf.WriteString("S") + return buf.String() +} + +func NilDuration(d *time.Duration) *Duration { + if d == nil { + return nil + } + x := Duration(*d) + return &x +} // MultiConnectorRequest was auto-generated from WSDL. type MultiConnectorRequest struct { - MessageId *string `xml:"MessageId,omitempty" json:"MessageId,omitempty" yaml:"MessageId,omitempty"` - OperationCode *string `xml:"OperationCode,omitempty" json:"OperationCode,omitempty" yaml:"OperationCode,omitempty"` - RequestXml *RequestXml `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector RequestXml,omitempty" json:"RequestXml,omitempty" yaml:"RequestXml,omitempty"` - ScheduledTime *DateTime `xml:"ScheduledTime,omitempty" json:"ScheduledTime,omitempty" yaml:"ScheduledTime,omitempty"` - Timeout *time.Duration `xml:"Timeout,omitempty" json:"Timeout,omitempty" yaml:"Timeout,omitempty"` + MessageId *string `xml:"MessageId,omitempty" json:"MessageId,omitempty" yaml:"MessageId,omitempty"` + OperationCode *string `xml:"OperationCode,omitempty" json:"OperationCode,omitempty" yaml:"OperationCode,omitempty"` + RequestXml *RequestXml `xml:"http://creditinfo.com/schemas/2012/09/MultiConnector RequestXml,omitempty" json:"RequestXml,omitempty" yaml:"RequestXml,omitempty"` + ScheduledTime *DateTime `xml:"ScheduledTime,omitempty" json:"ScheduledTime,omitempty" yaml:"ScheduledTime,omitempty"` + Timeout *Duration `xml:"Timeout,omitempty" json:"Timeout,omitempty" yaml:"Timeout,omitempty"` } type RequestXmlItem struct { From 4f376d5f47e2cf63bd36108055cdd4f8fee83048 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Fri, 16 Nov 2018 11:12:56 +0300 Subject: [PATCH 16/17] implement C# timeout: add MarshalXML --- pkg/request/request.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/request/request.go b/pkg/request/request.go index eb655fd..997570e 100644 --- a/pkg/request/request.go +++ b/pkg/request/request.go @@ -26,6 +26,11 @@ func NilDuration(d *time.Duration) *Duration { return &x } +func (d Duration) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + t := time.Duration(d).String() + return e.EncodeElement(t, start) +} + // MultiConnectorRequest was auto-generated from WSDL. type MultiConnectorRequest struct { MessageId *string `xml:"MessageId,omitempty" json:"MessageId,omitempty" yaml:"MessageId,omitempty"` From 2fe1db9f072c0956916a5659aae8433e2f2432f9 Mon Sep 17 00:00:00 2001 From: Artyom Blagov Date: Fri, 16 Nov 2018 11:18:02 +0300 Subject: [PATCH 17/17] fix time.Duration call --- pkg/request/request.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/request/request.go b/pkg/request/request.go index 997570e..c31cd4b 100644 --- a/pkg/request/request.go +++ b/pkg/request/request.go @@ -27,8 +27,7 @@ func NilDuration(d *time.Duration) *Duration { } func (d Duration) MarshalXML(e *xml.Encoder, start xml.StartElement) error { - t := time.Duration(d).String() - return e.EncodeElement(t, start) + return e.EncodeElement(d.String(), start) } // MultiConnectorRequest was auto-generated from WSDL.