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

Add support for the Issuing Dispute APIs #1174

Merged
merged 1 commit into from
Sep 2, 2020
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cache:
env:
global:
# If changing this number, please also change it in `testing/testing.go`.
- STRIPE_MOCK_VERSION=0.96.0
- STRIPE_MOCK_VERSION=0.98.0

go:
- "1.10.x"
Expand Down
13 changes: 13 additions & 0 deletions issuing/dispute/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ func (c Client) Get(id string, params *stripe.IssuingDisputeParams) (*stripe.Iss
return dispute, err
}

// Submit dismisses a dispute in the customer's favor.
func Submit(id string, params *stripe.IssuingDisputeSubmitParams) (*stripe.IssuingDispute, error) {
return getC().Submit(id, params)
}

// Submit dismisses a dispute in the customer's favor.
func (c Client) Submit(id string, params *stripe.IssuingDisputeSubmitParams) (*stripe.IssuingDispute, error) {
path := stripe.FormatURLPath("/v1/issuing/disputes/%s/submit", id)
dispute := &stripe.IssuingDispute{}
err := c.B.Call(http.MethodPost, path, c.Key, params, dispute)
return dispute, err
}

// Update updates an issuing dispute.
func Update(id string, params *stripe.IssuingDisputeParams) (*stripe.IssuingDispute, error) {
return getC().Update(id, params)
Expand Down
34 changes: 32 additions & 2 deletions issuing/dispute/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ func TestIssuingDisputeGet(t *testing.T) {
}

func TestIssuingDisputeList(t *testing.T) {
i := List(&stripe.IssuingDisputeListParams{})
params := &stripe.IssuingDisputeListParams{
Status: stripe.String(string(stripe.IssuingDisputeStatusWon)),
Transaction: stripe.String("ipi_123"),
}
i := List(params)

// Verify that we can get at least one dispute
assert.True(t, i.Next())
Expand All @@ -27,7 +31,33 @@ func TestIssuingDisputeList(t *testing.T) {
}

func TestIssuingDisputeNew(t *testing.T) {
dispute, err := New(&stripe.IssuingDisputeParams{})
params := &stripe.IssuingDisputeParams{
Evidence: &stripe.IssuingDisputeEvidenceParams{
Canceled: &stripe.IssuingDisputeEvidenceCanceledParams{
AdditionalDocumentation: stripe.String("file_123"),
CanceledAt: stripe.Int64(1577836800),
CancellationPolicyProvided: stripe.Bool(true),
CancellationReason: stripe.String("reason for cancellation"),
ExpectedAt: stripe.Int64(1577836800),
Explanation: stripe.String("explanation"),
ProductDescription: stripe.String("product description"),
ProductType: stripe.String(string(stripe.IssuingDisputeEvidenceCanceledProductTypeMerchandise)),
ReturnStatus: stripe.String(string(stripe.IssuingDisputeEvidenceCanceledReturnStatusMerchantRejected)),
ReturnedAt: stripe.Int64(1577836800),
},
Reason: stripe.String(string(stripe.IssuingDisputeEvidenceReasonCanceled)),
},
Transaction: stripe.String("ipi_123"),
}
dispute, err := New(params)
assert.Nil(t, err)
assert.NotNil(t, dispute)
assert.Equal(t, "issuing.dispute", dispute.Object)
}

func TestIssuingDisputeSubmit(t *testing.T) {
params := &stripe.IssuingDisputeSubmitParams{}
dispute, err := Submit("idp_123", params)
assert.Nil(t, err)
assert.NotNil(t, dispute)
assert.Equal(t, "issuing.dispute", dispute.Object)
Expand Down
265 changes: 258 additions & 7 deletions issuing_dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,275 @@ package stripe

import "encoding/json"

// IssuingDisputeEvidenceReason is the list of allowed reasons for the evidence on an issuing dispute.
type IssuingDisputeEvidenceReason string

// List of values that IssuingDisputeEvidenceReason can take.
const (
IssuingDisputeEvidenceReasonCanceled IssuingDisputeEvidenceReason = "canceled"
IssuingDisputeEvidenceReasonDuplicate IssuingDisputeEvidenceReason = "duplicate"
IssuingDisputeEvidenceReasonFraudulent IssuingDisputeEvidenceReason = "fraudulent"
IssuingDisputeEvidenceReasonMerchandiseNotAsDescribed IssuingDisputeEvidenceReason = "merchandise_not_as_described"
IssuingDisputeEvidenceReasonNotReceived IssuingDisputeEvidenceReason = "not_received"
IssuingDisputeEvidenceReasonOther IssuingDisputeEvidenceReason = "other"
IssuingDisputeEvidenceReasonServiceNotAsDescribed IssuingDisputeEvidenceReason = "service_not_as_described"
)

// IssuingDisputeEvidenceCanceledProductType is the list of allowed product types on an issuing dispute of type canceled.
type IssuingDisputeEvidenceCanceledProductType string

// List of values that IssuingDisputeEvidenceProductType can take.
const (
IssuingDisputeEvidenceCanceledProductTypeMerchandise IssuingDisputeEvidenceCanceledProductType = "merchandise"
IssuingDisputeEvidenceCanceledProductTypeService IssuingDisputeEvidenceCanceledProductType = "service"
)

// IssuingDisputeEvidenceCanceledReturnStatus is the list of allowed return status on an issuing dispute of type canceled.
type IssuingDisputeEvidenceCanceledReturnStatus string

// List of values that IssuingDisputeEvidenceCanceledReturnStatus can take.
const (
IssuingDisputeEvidenceCanceledReturnStatusMerchantRejected IssuingDisputeEvidenceCanceledReturnStatus = "merchant_rejected"
IssuingDisputeEvidenceCanceledReturnStatusSuccessful IssuingDisputeEvidenceCanceledReturnStatus = "successful"
)

// IssuingDisputeEvidenceMerchandiseNotAsDescribedReturnStatus is the list of allowed return status on an issuing dispute of type merchandise not as described.
type IssuingDisputeEvidenceMerchandiseNotAsDescribedReturnStatus string

// List of values that IssuingDisputeEvidenceMerchandiseNotAsDescribedReturnStatus can take.
const (
IssuingDisputeEvidenceMerchandiseNotAsDescribedReturnStatusMerchantRejected IssuingDisputeEvidenceMerchandiseNotAsDescribedReturnStatus = "merchant_rejected"
IssuingDisputeEvidenceMerchandiseNotAsDescribedReturnStatusSuccessful IssuingDisputeEvidenceMerchandiseNotAsDescribedReturnStatus = "successful"
)

// IssuingDisputeEvidenceNotReceivedProductType is the list of allowed product types on an issuing dispute of type not received.
type IssuingDisputeEvidenceNotReceivedProductType string

// List of values that IssuingDisputeEvidenceNotReceivedProductType can take.
const (
IssuingDisputeEvidenceNotReceivedProductTypeMerchandise IssuingDisputeEvidenceNotReceivedProductType = "merchandise"
IssuingDisputeEvidenceNotReceivedProductTypeService IssuingDisputeEvidenceNotReceivedProductType = "service"
)

// IssuingDisputeEvidenceOtherProductType is the list of allowed product types on an issuing dispute of type other.
type IssuingDisputeEvidenceOtherProductType string

// List of values that IssuingDisputeEvidenceNotReceivedProductType can take.
const (
IssuingDisputeEvidenceOtherProductTypeMerchandise IssuingDisputeEvidenceOtherProductType = "merchandise"
IssuingDisputeEvidenceOtherProductTypeService IssuingDisputeEvidenceOtherProductType = "service"
)

// IssuingDisputeEvidenceServiceNotAsDescribedProductType is the list of allowed product types on an issuing dispute of type service not as described.
type IssuingDisputeEvidenceServiceNotAsDescribedProductType string

// List of values that IssuingDisputeEvidenceServiceNotAsDescribedProductType can take.
const (
IssuingDisputeEvidenceServiceNotAsDescribedProductTypeMerchandise IssuingDisputeEvidenceServiceNotAsDescribedProductType = "merchandise"
IssuingDisputeEvidenceServiceNotAsDescribedProductTypeService IssuingDisputeEvidenceServiceNotAsDescribedProductType = "service"
)

// IssuingDisputeStatus is the list of allowed values for status on an issuing dispute.
type IssuingDisputeStatus string

// List of values that IssuingDisputeStatus can take.
const (
IssuingDisputeStatusExpired IssuingDisputeStatus = "expired"
IssuingDisputeStatusLost IssuingDisputeStatus = "lost"
IssuingDisputeStatusSubmitted IssuingDisputeStatus = "submitted"
IssuingDisputeStatusUnsubmitted IssuingDisputeStatus = "unsubmitted"
IssuingDisputeStatusWon IssuingDisputeStatus = "won"
)

// IssuingDisputeEvidenceCanceledParams is the resource representing the evidence of an issuing dispute with a reason set to canceled.
type IssuingDisputeEvidenceCanceledParams struct {
AdditionalDocumentation *string `form:"additional_documentation"`
CanceledAt *int64 `form:"canceled_at"`
CancellationPolicyProvided *bool `form:"cancellation_policy_provided"`
CancellationReason *string `form:"cancellation_reason"`
ExpectedAt *int64 `form:"expected_at"`
Explanation *string `form:"explanation"`
ProductDescription *string `form:"product_description"`
ProductType *string `form:"product_type"`
ReturnStatus *string `form:"return_status"`
ReturnedAt *int64 `form:"returned_at"`
}

// IssuingDisputeEvidenceDuplicateParams is the resource representing the evidence of an issuing dispute with a reason set to duplicate.
type IssuingDisputeEvidenceDuplicateParams struct {
AdditionalDocumentation *string `form:"additional_documentation"`
CardStatement *string `form:"card_statement"`
CashReceipt *string `form:"cash_receipt"`
CheckImage *string `form:"check_image"`
Explanation *string `form:"explanation"`
OriginalTransaction *string `form:"original_transaction"`
}

// IssuingDisputeEvidenceFraudulentParams is the resource representing the evidence of an issuing dispute with a reason set to fraudulent.
type IssuingDisputeEvidenceFraudulentParams struct {
AdditionalDocumentation *string `form:"additional_documentation"`
Explanation *string `form:"explanation"`
}

// IssuingDisputeEvidenceMerchandiseNotAsDescribedParams is the resource representing the evidence of an issuing dispute with a reason set to merchandise not as described.
type IssuingDisputeEvidenceMerchandiseNotAsDescribedParams struct {
AdditionalDocumentation *string `form:"additional_documentation"`
Explanation *string `form:"explanation"`
ReceivedAt *int64 `form:"received_at"`
ReturnDescription *string `form:"return_description"`
ReturnStatus *string `form:"return_status"`
ReturnedAt *int64 `form:"returned_at"`
}

// IssuingDisputeEvidenceNotReceivedParams is the resource representing the evidence of an issuing dispute with a reason set to not received.
type IssuingDisputeEvidenceNotReceivedParams struct {
AdditionalDocumentation *string `form:"additional_documentation"`
ExpectedAt *int64 `form:"expected_at"`
Explanation *string `form:"explanation"`
ProductDescription *string `form:"product_description"`
ProductType *string `form:"product_type"`
}

// IssuingDisputeEvidenceOtherParams is the resource representing the evidence of an issuing dispute with a reason set to other.
type IssuingDisputeEvidenceOtherParams struct {
AdditionalDocumentation *string `form:"additional_documentation"`
Explanation *string `form:"explanation"`
ProductDescription *string `form:"product_description"`
ProductType *string `form:"product_type"`
}

// IssuingDisputeEvidenceServiceNotAsDescribedParams is the resource representing the evidence of an issuing dispute with a reason set to service not as described.
type IssuingDisputeEvidenceServiceNotAsDescribedParams struct {
AdditionalDocumentation *string `form:"additional_documentation"`
CanceledAt *int64 `form:"canceled_at"`
Explanation *string `form:"explanation"`
ProductDescription *string `form:"product_description"`
ProductType *string `form:"product_type"`
}

// IssuingDisputeEvidenceParams is the set of parameters for the evidence on an issuing dispute
type IssuingDisputeEvidenceParams struct {
Canceled *IssuingDisputeEvidenceCanceledParams `form:"canceled"`
Duplicate *IssuingDisputeEvidenceDuplicateParams `form:"duplicate"`
Fraudulent *IssuingDisputeEvidenceFraudulentParams `form:"fraudulent"`
MerchandiseNotAsDescribed *IssuingDisputeEvidenceMerchandiseNotAsDescribedParams `form:"merchandise_not_as_described"`
NotReceived *IssuingDisputeEvidenceNotReceivedParams `form:"not_received"`
Other *IssuingDisputeEvidenceOtherParams `form:"other"`
Reason *string `form:"reason"`
ServiceNotAsDescribed *IssuingDisputeEvidenceServiceNotAsDescribedParams `form:"service_not_as_described"`
}

// IssuingDisputeParams is the set of parameters that can be used when creating or updating an issuing dispute.
type IssuingDisputeParams struct {
Params `form:"*"`
Params `form:"*"`
Evidence *IssuingDisputeEvidenceParams `form:"evidence"`
Transaction *string `form:"transaction"`
}

// IssuingDisputeListParams is the set of parameters that can be used when listing issuing dispute.
type IssuingDisputeListParams struct {
ListParams `form:"*"`
ListParams `form:"*"`
Status *string `form:"status"`
Transaction *string `form:"transaction"`
}

// IssuingDisputeSubmitParams is the set of parameters that can be used when submitting an issuing dispute.
type IssuingDisputeSubmitParams struct {
Params `form:"*"`
}

// IssuingDisputeEvidenceCanceled is the resource representing the evidence of an issuing dispute with a reason set to canceled.
type IssuingDisputeEvidenceCanceled struct {
AdditionalDocumentation *File `json:"additional_documentation"`
CanceledAt int64 `json:"canceled_at"`
CancellationPolicyProvided bool `json:"cancellation_policy_provided"`
CancellationReason string `json:"cancellation_reason"`
ExpectedAt int64 `json:"expected_at"`
Explanation string `json:"explanation"`
ProductDescription string `json:"product_description"`
ProductType IssuingDisputeEvidenceCanceledProductType `json:"product_type"`
ReturnStatus IssuingDisputeEvidenceCanceledReturnStatus `json:"return_status"`
ReturnedAt int64 `json:"returned_at"`
}

// IssuingDisputeEvidenceDuplicate is the resource representing the evidence of an issuing dispute with a reason set to duplicate.
type IssuingDisputeEvidenceDuplicate struct {
AdditionalDocumentation *File `json:"additional_documentation"`
CardStatement *File `json:"card_statement"`
CashReceipt *File `json:"cash_receipt"`
CheckImage *File `json:"check_image"`
Explanation string `json:"explanation"`
OriginalTransaction string `json:"original_transaction"`
}

// IssuingDisputeEvidenceFraudulent is the resource representing the evidence of an issuing dispute with a reason set to fraudulent.
type IssuingDisputeEvidenceFraudulent struct {
AdditionalDocumentation *File `json:"additional_documentation"`
Explanation string `json:"explanation"`
}

// IssuingDisputeEvidenceMerchandiseNotAsDescribed is the resource representing the evidence of an issuing dispute with a reason set to merchandise not as described.
type IssuingDisputeEvidenceMerchandiseNotAsDescribed struct {
AdditionalDocumentation *File `json:"additional_documentation"`
Explanation string `json:"explanation"`
ReceivedAt int64 `json:"received_at"`
ReturnDescription string `json:"return_description"`
ReturnStatus IssuingDisputeEvidenceMerchandiseNotAsDescribedReturnStatus `json:"return_status"`
ReturnedAt int64 `json:"returned_at"`
}

// IssuingDisputeEvidenceNotReceived is the resource representing the evidence of an issuing dispute with a reason set to not received.
type IssuingDisputeEvidenceNotReceived struct {
AdditionalDocumentation *File `json:"additional_documentation"`
ExpectedAt int64 `json:"expected_at"`
Explanation string `json:"explanation"`
ProductDescription string `json:"product_description"`
ProductType IssuingDisputeEvidenceNotReceivedProductType `json:"product_type"`
}

// IssuingDisputeEvidenceOther is the resource representing the evidence of an issuing dispute with a reason set to other.
type IssuingDisputeEvidenceOther struct {
AdditionalDocumentation *File `json:"additional_documentation"`
Explanation string `json:"explanation"`
ProductDescription string `json:"product_description"`
ProductType IssuingDisputeEvidenceOtherProductType `json:"product_type"`
}

// IssuingDisputeEvidenceServiceNotAsDescribed is the resource representing the evidence of an issuing dispute with a reason set to service not as described.
type IssuingDisputeEvidenceServiceNotAsDescribed struct {
AdditionalDocumentation *File `json:"additional_documentation"`
CanceledAt int64 `json:"canceled_at"`
Explanation string `json:"explanation"`
ProductDescription string `json:"product_description"`
ProductType IssuingDisputeEvidenceServiceNotAsDescribedProductType `json:"product_type"`
}

// IssuingDisputeEvidence is the resource representing the evidence of an issuing dispute.
type IssuingDisputeEvidence struct {
Canceled *IssuingDisputeEvidenceCanceled `json:"canceled"`
Duplicate *IssuingDisputeEvidenceDuplicate `json:"duplicate"`
Fraudulent *IssuingDisputeEvidenceFraudulent `json:"fraudulent"`
MerchandiseNotAsDescribed *IssuingDisputeEvidenceMerchandiseNotAsDescribed `json:"merchandise_not_as_described"`
NotReceived *IssuingDisputeEvidenceNotReceived `json:"not_received"`
Other *IssuingDisputeEvidenceOther `json:"other"`
Reason IssuingDisputeEvidenceReason `json:"reason"`
ServiceNotAsDescribed *IssuingDisputeEvidenceServiceNotAsDescribed `json:"service_not_as_described"`
}

// IssuingDispute is the resource representing an issuing dispute.
type IssuingDispute struct {
APIResource
BalanceTransactions []*BalanceTransaction `json:"balance_transactions"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Object string `json:"object"`
Transaction *IssuingTransaction `json:"transaction"`
Amount int64 `json:"amount"`
BalanceTransactions []*BalanceTransaction `json:"balance_transactions"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Evidence *IssuingDisputeEvidence `json:"evidence"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Object string `json:"object"`
Status *IssuingDisputeStatus `json:"status"`
Transaction *IssuingTransaction `json:"transaction"`
}

// IssuingDisputeList is a list of issuing disputes as retrieved from a list endpoint.
Expand Down
Loading