From 8875ea857b6a2a3f68caa3fd0f780522202aaee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:11:49 +0100 Subject: [PATCH 1/2] Add disabled_payment_methods --- payments/hosted/hosted.go | 47 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/payments/hosted/hosted.go b/payments/hosted/hosted.go index 9ea74f7..9234f9b 100644 --- a/payments/hosted/hosted.go +++ b/payments/hosted/hosted.go @@ -19,29 +19,30 @@ const ( type ( HostedPaymentRequest struct { - Amount int `json:"amount,omitempty"` - Currency common.Currency `json:"currency,omitempty"` - PaymentType payments.PaymentType `json:"payment_type,omitempty,omitempty"` - PaymentIp string `json:"payment_ip,omitempty"` - BillingDescriptor *payments.BillingDescriptor `json:"billing_descriptor,omitempty"` - Reference string `json:"reference,omitempty"` - Description string `json:"description,omitempty"` - Customer *common.CustomerRequest `json:"customer,omitempty"` - Shipping *payments.ShippingDetails `json:"shipping,omitempty"` - Billing *payments.BillingInformation `json:"billing,omitempty"` - Recipient *payments.PaymentRecipient `json:"recipient,omitempty"` - Processing *payments.ProcessingSettings `json:"processing,omitempty"` - AllowPaymentMethods []payments.SourceType `json:"allow_payment_methods,omitempty"` - Products []payments.Product `json:"products,omitempty"` - Risk *payments.RiskRequest `json:"risk,omitempty"` - SuccessUrl string `json:"success_url,omitempty"` - CancelUrl string `json:"cancel_url,omitempty"` - FailureUrl string `json:"failure_url,omitempty"` - Metadata map[string]interface{} `json:"metadata,omitempty"` - Locale string `json:"locale,omitempty"` - ThreeDs *payments.ThreeDsRequest `json:"3ds,omitempty"` - Capture bool `json:"capture,omitempty"` - CaptureOn *time.Time `json:"capture_on,omitempty"` + Amount int `json:"amount,omitempty"` + Currency common.Currency `json:"currency,omitempty"` + PaymentType payments.PaymentType `json:"payment_type,omitempty,omitempty"` + PaymentIp string `json:"payment_ip,omitempty"` + BillingDescriptor *payments.BillingDescriptor `json:"billing_descriptor,omitempty"` + Reference string `json:"reference,omitempty"` + Description string `json:"description,omitempty"` + Customer *common.CustomerRequest `json:"customer,omitempty"` + Shipping *payments.ShippingDetails `json:"shipping,omitempty"` + Billing *payments.BillingInformation `json:"billing,omitempty"` + Recipient *payments.PaymentRecipient `json:"recipient,omitempty"` + Processing *payments.ProcessingSettings `json:"processing,omitempty"` + AllowPaymentMethods []payments.SourceType `json:"allow_payment_methods,omitempty"` + DisabledPaymentMethods []payments.SourceType `json:"disabled_payment_methods,omitempty"` + Products []payments.Product `json:"products,omitempty"` + Risk *payments.RiskRequest `json:"risk,omitempty"` + SuccessUrl string `json:"success_url,omitempty"` + CancelUrl string `json:"cancel_url,omitempty"` + FailureUrl string `json:"failure_url,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty"` + Locale string `json:"locale,omitempty"` + ThreeDs *payments.ThreeDsRequest `json:"3ds,omitempty"` + Capture bool `json:"capture,omitempty"` + CaptureOn *time.Time `json:"capture_on,omitempty"` //Not available on previous ProcessingChannelId string `json:"processing_channel_id,omitempty"` AmountAllocations []common.AmountAllocations `json:"amount_allocations,omitempty"` From e18469301cb798925dd5059a12042ff3c64f091e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:32:13 +0100 Subject: [PATCH 2/2] Add compiled submitted evidence endpoint to disputes --- disputes/client.go | 15 ++++++ disputes/client_test.go | 103 ++++++++++++++++++++++++++++++++++++++++ disputes/disputes.go | 11 +++++ test/disputes_test.go | 51 +++++++++++++++++--- 4 files changed, 174 insertions(+), 6 deletions(-) diff --git a/disputes/client.go b/disputes/client.go index fdd2fc8..47385dd 100644 --- a/disputes/client.go +++ b/disputes/client.go @@ -131,6 +131,21 @@ func (c *Client) SubmitEvidence(disputeId string) (*common.MetadataResponse, err return &response, nil } +func (c *Client) GetCompiledSubmittedEvidence(disputeId string) (*DisputeCompiledSubmittedEvidenceResponse, error) { + auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) + if err != nil { + return nil, err + } + + var response DisputeCompiledSubmittedEvidenceResponse + err = c.apiClient.Get(common.BuildPath(disputes, disputeId, evidence, submitted), auth, &response) + if err != nil { + return nil, err + } + + return &response, nil +} + func (c *Client) UploadFile(file common.File) (*common.IdResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { diff --git a/disputes/client_test.go b/disputes/client_test.go index a2a0cf7..4c9fc5c 100644 --- a/disputes/client_test.go +++ b/disputes/client_test.go @@ -638,6 +638,109 @@ func TestSubmitEvidence(t *testing.T) { } } +func TestGetCompiledSubmittedEvidence(t *testing.T) { + var ( + compiledSubmittedEvidenceResponse = DisputeCompiledSubmittedEvidenceResponse{ + HttpMetadata: mocks.HttpMetadataStatusOk, + FileId: "file_iweu3nxyt6zund3gwhg7wo4fhq", + Links: map[string]common.Link{ + "self": { + HRef: &[]string{"https://api.checkout.com/disputes/dsp_f28bcafe073z72ad4a18/evidence/submitted"}[0], + }, + }, + } + ) + + cases := []struct { + name string + disputeId string + getAuthorization func(*mock.Mock) mock.Call + apiGet func(*mock.Mock) mock.Call + checker func(*DisputeCompiledSubmittedEvidenceResponse, error) + }{ + { + name: "when disputeId is correct then return a file", + disputeId: disputeId, + getAuthorization: func(m *mock.Mock) mock.Call { + return *m.On("GetAuthorization", mock.Anything). + Return(&configuration.SdkAuthorization{}, nil) + }, + apiGet: func(m *mock.Mock) mock.Call { + return *m.On("Get", mock.Anything, mock.Anything, mock.Anything). + Return(nil). + Run(func(args mock.Arguments) { + respMapping := args.Get(2).(*DisputeCompiledSubmittedEvidenceResponse) + *respMapping = compiledSubmittedEvidenceResponse + }) + }, + checker: func(response *DisputeCompiledSubmittedEvidenceResponse, err error) { + assert.Nil(t, err) + assert.NotNil(t, response) + assert.Equal(t, http.StatusOK, response.HttpMetadata.StatusCode) + assert.Equal(t, compiledSubmittedEvidenceResponse.FileId, response.FileId) + assert.Equal(t, compiledSubmittedEvidenceResponse.Links["self"].HRef, response.Links["self"].HRef) + + }, + }, + { + name: "when credentials invalid then return error", + getAuthorization: func(m *mock.Mock) mock.Call { + return *m.On("GetAuthorization", mock.Anything). + Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) + }, + apiGet: func(m *mock.Mock) mock.Call { + return *m.On("Get", mock.Anything, mock.Anything, mock.Anything). + Return(nil) + }, + checker: func(response *DisputeCompiledSubmittedEvidenceResponse, err error) { + assert.Nil(t, response) + assert.NotNil(t, err) + chkErr := err.(errors.CheckoutAuthorizationError) + assert.Equal(t, "Invalid authorization type", chkErr.Error()) + }, + }, + { + name: "when dispute not found then return error", + disputeId: "not_found", + getAuthorization: func(m *mock.Mock) mock.Call { + return *m.On("GetAuthorization", mock.Anything). + Return(&configuration.SdkAuthorization{}, nil) + }, + apiGet: func(m *mock.Mock) mock.Call { + return *m.On("Get", mock.Anything, mock.Anything, mock.Anything). + Return( + errors.CheckoutAPIError{ + StatusCode: http.StatusNotFound, + Status: "404 Not Found", + }) + }, + checker: func(response *DisputeCompiledSubmittedEvidenceResponse, err error) { + assert.Nil(t, response) + assert.NotNil(t, err) + chkErr := err.(errors.CheckoutAPIError) + assert.Equal(t, http.StatusNotFound, chkErr.StatusCode) + assert.Equal(t, "404 Not Found", chkErr.Status) + }, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + apiClient := new(mocks.ApiClientMock) + credentials := new(mocks.CredentialsMock) + environment := new(mocks.EnvironmentMock) + + tc.getAuthorization(&credentials.Mock) + tc.apiGet(&apiClient.Mock) + + configuration := configuration.NewConfiguration(credentials, environment, &http.Client{}, nil) + client := NewClient(configuration, apiClient) + + tc.checker(client.GetCompiledSubmittedEvidence(tc.disputeId)) + }) + } +} + func TestGetDisputeSchemeFiles(t *testing.T) { var ( schemeFilesResponse = SchemeFilesResponse{ diff --git a/disputes/disputes.go b/disputes/disputes.go index 6d9bc67..38208ff 100644 --- a/disputes/disputes.go +++ b/disputes/disputes.go @@ -10,6 +10,7 @@ const ( disputes = "disputes" accept = "accept" evidence = "evidence" + submitted = "submitted" files = "files" schemeFiles = "schemefiles" ) @@ -161,6 +162,16 @@ type ( } ) +// Submitted + +type ( + DisputeCompiledSubmittedEvidenceResponse struct { + HttpMetadata common.HttpMetadata + FileId string `json:"file_id,omitempty"` + Links map[string]common.Link `json:"_links,omitempty"` + } +) + // Files type ( SchemeFilesResponse struct { diff --git a/test/disputes_test.go b/test/disputes_test.go index 382d850..792bae3 100644 --- a/test/disputes_test.go +++ b/test/disputes_test.go @@ -28,7 +28,7 @@ var ( ) func TestSetupDefault(t *testing.T) { - t.Skip("Skipping tests because this suite is unstable") + t.Skip("Due the time to expect the dispute, just run as needed") var ( cardToken = RequestCardToken(t) payment = getPaymentRequest(t, cardToken.Token) @@ -92,7 +92,7 @@ func TestQuery(t *testing.T) { } func TestGetDisputeDetails(t *testing.T) { - t.Skip("Skipping tests because this suite is unstable") + t.Skip("Due the time to expect the dispute, just run as needed") cases := []struct { name string disputeId string @@ -132,7 +132,7 @@ func TestGetDisputeDetails(t *testing.T) { } func TestPutEvidence(t *testing.T) { - t.Skip("Skipping tests because this suite is unstable") + t.Skip("Due the time to expect the dispute, just run as needed") cases := []struct { name string @@ -206,7 +206,7 @@ func TestPutEvidence(t *testing.T) { } func TestSubmitEvidence(t *testing.T) { - t.Skip("Skipping tests because this suite is unstable") + t.Skip("Due the time to expect the dispute, just run as needed") cases := []struct { name string @@ -246,7 +246,7 @@ func TestSubmitEvidence(t *testing.T) { } func TestGetEvidence(t *testing.T) { - t.Skip("Skipping tests because this suite is unstable") + t.Skip("Due the time to expect the dispute, just run as needed") cases := []struct { name string disputeId string @@ -397,8 +397,47 @@ func TestGetFileDetails(t *testing.T) { } } +func TestGetCompiledSubmittedEvidence(t *testing.T) { + t.Skip("Due the time to expect the dispute, just run as needed") + dispute := getDisputes(t).Data[0] + + cases := []struct { + name string + disputeId string + checker func(*disputes.DisputeCompiledSubmittedEvidenceResponse, error) + }{ + { + name: "when dispute has a compiled submitted evidence then return the file", + disputeId: dispute.Id, + checker: func(response *disputes.DisputeCompiledSubmittedEvidenceResponse, err error) { + assert.Nil(t, err) + assert.NotNil(t, response) + assert.NotEmpty(t, response.FileId) + }, + }, + { + name: "when dispute does not have a compiled submitted evidence then return error", + disputeId: "not_found", + checker: func(response *disputes.DisputeCompiledSubmittedEvidenceResponse, err error) { + assert.Nil(t, response) + assert.NotNil(t, err) + chkErr := err.(errors.CheckoutAPIError) + assert.Equal(t, http.StatusNotFound, chkErr.StatusCode) + }, + }, + } + + client := DefaultApi().Disputes + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + tc.checker(client.GetCompiledSubmittedEvidence(tc.disputeId)) + }) + } +} + func TestGetDisputeSchemeFiles(t *testing.T) { - t.Skip("not available") + t.Skip("Due the time to expect the dispute, just run as needed") dispute := getDisputes(t).Data[0] cases := []struct {