Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds compiled submitted evidence endpoint. Update Hosted Payment Request #105

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions disputes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
103 changes: 103 additions & 0 deletions disputes/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
11 changes: 11 additions & 0 deletions disputes/disputes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
disputes = "disputes"
accept = "accept"
evidence = "evidence"
submitted = "submitted"
files = "files"
schemeFiles = "schemefiles"
)
Expand Down Expand Up @@ -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 {
Expand Down
47 changes: 24 additions & 23 deletions payments/hosted/hosted.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
51 changes: 45 additions & 6 deletions test/disputes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Loading