diff --git a/CHANGELOG.md b/CHANGELOG.md index b2985eb..990792f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## Next Release + +- Add new claim-related functions: `CreateClaim`, `GetClaim`, `ListClaims`, `GetNextClaimPage` and `CancelClaim` + ## v4.4.0 (2024-07-16) - Adds new `EstimateDeliveryDateForZipPair`, `RecommendShipDateForShipment` and `RecommendShipDateForZipPair` diff --git a/claim.go b/claim.go new file mode 100644 index 0000000..823c145 --- /dev/null +++ b/claim.go @@ -0,0 +1,151 @@ +package easypost + +import ( + "context" + "net/http" +) + +type ClaimHistoryEntry struct { + Status string `json:"status,omitempty"` + StatusDetail string `json:"status_detail,omitempty"` + StatusTimestamp string `json:"status_timestamp,omitempty"` +} + +// A Claim object represents a claim against insurance on a package. +type Claim struct { + ID string `json:"id,omitempty"` + Object string `json:"object,omitempty"` + Mode string `json:"mode,omitempty"` + CreatedAt *DateTime `json:"created_at,omitempty"` + UpdatedAt *DateTime `json:"updated_at,omitempty"` + ApprovedAmount string `json:"approved_amount,omitempty"` + Attachments []string `json:"attachments,omitempty"` + CheckDeliveryAddress string `json:"check_delivery_address,omitempty"` + ContactEmail string `json:"contact_email,omitempty"` + Description string `json:"description,omitempty"` + History []ClaimHistoryEntry `json:"history,omitempty"` + InsuranceAmount string `json:"insurance_amount,omitempty"` + InsuranceId string `json:"insurance_id,omitempty"` + PaymentMethod string `json:"payment_method,omitempty"` + RecipientName string `json:"recipient_name,omitempty"` + RequestedAmount string `json:"requested_amount,omitempty"` + SalvageValue string `json:"salvage_value,omitempty"` + ShipmentId string `json:"shipment_id,omitempty"` + Status string `json:"status,omitempty"` + StatusDetail string `json:"status_detail,omitempty"` + StatusTimestamp string `json:"status_timestamp,omitempty"` + TrackingCode string `json:"tracking_code,omitempty"` + Type string `json:"type,omitempty"` +} + +// CreateClaimParameters is used to specify parameters for creating a claim. +type CreateClaimParameters struct { + TrackingCode string `json:"tracking_code,omitempty"` + Type string `json:"type,omitempty"` + Amount float64 `json:"amount,omitempty"` + EmailEvidenceAttachments []string `json:"email_evidence_attachments,omitempty"` + InvoiceAttachments []string `json:"invoice_attachments,omitempty"` + SupportingDocumentationAttachments []string `json:"supporting_documentation_attachments,omitempty"` + Description string `json:"description,omitempty"` + RecipientName string `json:"recipient_name,omitempty"` + ContactEmail string `json:"contact_email,omitempty"` + PaymentMethod string `json:"payment_method,omitempty"` +} + +// ListClaimsParameters is used to specify query parameters for listing claims. +type ListClaimsParameters struct { + BeforeID string `url:"before_id,omitempty"` + AfterID string `url:"after_id,omitempty"` + StartDateTime *DateTime `url:"start_datetime,omitempty"` + EndDateTime *DateTime `url:"end_datetime,omitempty"` + PageSize int `url:"page_size,omitempty"` + Type string `url:"type,omitempty"` + Status string `url:"status,omitempty"` +} + +// ListClaimsResult holds the results from the list claims API. +type ListClaimsResult struct { + Claims []*Claim `json:"claims,omitempty"` + Parameters ListClaimsParameters + PaginatedCollection +} + +// CreateClaim creates a Claim object for insurance purchased through EasyPost. +func (c *Client) CreateClaim(in *CreateClaimParameters) (out *Claim, err error) { + return c.CreateClaimWithContext(context.Background(), in) +} + +// CreateClaimWithContext performs the same operation as CreateClaim, but allows specifying a context that can interrupt the request. +func (c *Client) CreateClaimWithContext(ctx context.Context, in *CreateClaimParameters) (out *Claim, err error) { + err = c.post(ctx, "claims", in, &out) + return +} + +// ListClaims provides a paginated result of Claim objects. +func (c *Client) ListClaims(opts *ListClaimsParameters) (out *ListClaimsResult, err error) { + return c.ListClaimsWithContext(context.Background(), opts) +} + +// ListClaimsWithContext performs the same operation as ListClaims, but allows specifying a context that can interrupt the request. +func (c *Client) ListClaimsWithContext(ctx context.Context, opts *ListClaimsParameters) (out *ListClaimsResult, err error) { + err = c.do(ctx, http.MethodGet, "claims", c.convertOptsToURLValues(opts), &out) + // Store the original query parameters for reuse when getting the next page + out.Parameters = *opts + return +} + +// GetNextClaimPage returns the next page of claims +func (c *Client) GetNextClaimPage(collection *ListClaimsResult) (out *ListClaimsResult, err error) { + return c.GetNextClaimPageWithContext(context.Background(), collection) +} + +// GetNextClaimPageWithPageSize returns the next page of claims with a specific page size +func (c *Client) GetNextClaimPageWithPageSize(collection *ListClaimsResult, pageSize int) (out *ListClaimsResult, err error) { + return c.GetNextClaimPageWithPageSizeWithContext(context.Background(), collection, pageSize) +} + +// GetNextClaimPageWithContext performs the same operation as GetNextClaimPage, but allows specifying a context that can interrupt the request. +func (c *Client) GetNextClaimPageWithContext(ctx context.Context, collection *ListClaimsResult) (out *ListClaimsResult, err error) { + return c.GetNextClaimPageWithPageSizeWithContext(ctx, collection, 0) +} + +// GetNextClaimPageWithPageSizeWithContext performs the same operation as GetNextClaimPageWithPageSize, but allows specifying a context that can interrupt the request. +func (c *Client) GetNextClaimPageWithPageSizeWithContext(ctx context.Context, collection *ListClaimsResult, pageSize int) (out *ListClaimsResult, err error) { + if len(collection.Claims) == 0 { + err = EndOfPaginationError + return + } + lastID := collection.Claims[len(collection.Claims)-1].ID + params, err := nextPageParameters(collection.HasMore, lastID, pageSize) + if err != nil { + return + } + claimParams := &collection.Parameters + claimParams.BeforeID = params.BeforeID + if pageSize > 0 { + claimParams.PageSize = pageSize + } + return c.ListClaimsWithContext(ctx, claimParams) +} + +// GetClaim returns the Claim object with the given ID or reference. +func (c *Client) GetClaim(claimID string) (out *Claim, err error) { + return c.GetClaimWithContext(context.Background(), claimID) +} + +// GetClaimWithContext performs the same operation as GetClaim, but allows specifying a context that can interrupt the request. +func (c *Client) GetClaimWithContext(ctx context.Context, claimID string) (out *Claim, err error) { + err = c.get(ctx, "claims/"+claimID, &out) + return +} + +// CancelClaim refunds the Claim object with the given ID. +func (c *Client) CancelClaim(claimID string) (out *Claim, err error) { + return c.CancelClaimWithContext(context.Background(), claimID) +} + +// CancelClaimWithContext performs the same operation as CancelClaim, but allows specifying a context that can interrupt the request. +func (c *Client) CancelClaimWithContext(ctx context.Context, claimID string) (out *Claim, err error) { + err = c.post(ctx, "claims/"+claimID+"/cancel", nil, &out) + return +} diff --git a/datetime.go b/datetime.go index daed6ab..9e46e8b 100644 --- a/datetime.go +++ b/datetime.go @@ -88,6 +88,14 @@ func DateTimeFromString(s string) (dt DateTime, err error) { return } + // try to parse + // 2006-01-02T15:04:05 + t, err = time.Parse(`"2006-01-02T15:04:05"`, s) + if err == nil { + dt = DateTime(t) + return + } + // try to parse // 2006-01-02T15:04:05Z t, err = time.Parse(`"2006-01-02T15:04:05Z"`, s) diff --git a/examples b/examples index b9fde9b..b1f3d75 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit b9fde9bead7750256bc986802841ce7576eee0a4 +Subproject commit b1f3d75c324c2894a6d5c622ee0b31bcc6e1acb3 diff --git a/tests/cassettes/TestClaimAll.yaml b/tests/cassettes/TestClaimAll.yaml new file mode 100644 index 0000000..32dd418 --- /dev/null +++ b/tests/cassettes/TestClaimAll.yaml @@ -0,0 +1,62 @@ +--- +version: 1 +interactions: +- request: + body: page_size=5 + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/x-www-form-urlencoded + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/claims + method: GET + response: + body: '{"claims":[{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/c44df5462b774c0c977f87e3b60d2b01.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/80738b455dea42658a66a250c40d9aba.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/ee68a27ae3854ca5bd17f0752fa81ddf.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:28:59","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:28:59"}],"id":"clm_097e5796aa404ad4992781722224dcea","insurance_amount":"100.00","insurance_id":"ins_b004dab680bb4251abe5888de3bc4d07","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_ec517502568a4cb79d4af314dd16faa1","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:28:59","tracking_code":"9400100110368066408089","type":"damage","updated_at":"2024-07-23T20:28:59"},{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/2170a351b74540d38ad04ba465d6daf9.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/4ae21037c02f4e0f90e3e6bf0511c429.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/c910f338b6c9465f8023780002296673.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:28:57","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:28:57"}],"id":"clm_097e3dc1ade44a61b22c27e85d377fec","insurance_amount":"100.00","insurance_id":"ins_a82753192b544bd79ee19d0c22dabff6","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_f9de24018a77456e95a1e5efcbb050fb","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:28:57","tracking_code":"9400100110368066408065","type":"damage","updated_at":"2024-07-23T20:28:57"},{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/9d36dfc0ae1b408893c33aa3fb76baeb.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/03390ff136a14600bf90a01aeed7482b.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/1666429034d24286aa46862ec3379c55.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:28:55","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:28:55"}],"id":"clm_097e083764974c80ab79ff8dbad6f337","insurance_amount":"100.00","insurance_id":"ins_98ffb9130f2945ebbeb57051a54aae5b","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_eceec0522e8244c68ca3ae686e21c244","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:28:55","tracking_code":"9400100110368066408058","type":"damage","updated_at":"2024-07-23T20:28:55"}],"has_more":false}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015a8f42f248c0023095f + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb36nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.044919" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" diff --git a/tests/cassettes/TestClaimCancel.yaml b/tests/cassettes/TestClaimCancel.yaml new file mode 100644 index 0000000..bb4ace7 --- /dev/null +++ b/tests/cassettes/TestClaimCancel.yaml @@ -0,0 +1,259 @@ +--- +version: 1 +interactions: +- request: + body: '{"shipment":{"customs_info":{"contents_type":"merchandise","customs_certify":true,"customs_items":[{"description":"Sweet + shirts","hs_tariff_number":"654321","origin_country":"US","quantity":2,"weight":11}],"customs_signer":"Steve + Brule","eel_pfc":"NOEEI 30.37(a)","non_delivery_option":"return","restriction_type":"none"},"from_address":{"city":"San + Francisco","country":"US","email":"REDACTED","name":"Jack Sparrow","phone":"REDACTED","state":"CA","street1":"388 + Townsend St","street2":"Apt 20","zip":"94107"},"options":{"invoice_number":"123","label_format":"PNG"},"parcel":{"height":4,"length":10,"weight":15.4,"width":8},"reference":"123","to_address":{"city":"Redondo + Beach","country":"US","email":"REDACTED","name":"Elizabeth Swan","phone":"REDACTED","state":"CA","street1":"179 + N Harbor Dr","zip":"90277"}}}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/shipments + method: POST + response: + body: '{"batch_id":null,"batch_message":null,"batch_status":null,"buyer_address":{"carrier_facility":null,"city":"Redondo + Beach","company":null,"country":"US","created_at":"2024-07-23T20:42:16+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0c6aff87493411ef8ab4ac1f6bc539aa","mode":"test","name":"Elizabeth + Swan","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"179 + N Harbor Dr","street2":null,"updated_at":"2024-07-23T20:42:16+00:00","verifications":{},"zip":"90277"},"created_at":"2024-07-23T20:42:16Z","customs_info":{"contents_explanation":null,"contents_type":"merchandise","created_at":"2024-07-23T20:42:16Z","customs_certify":true,"customs_items":[{"code":null,"created_at":"2024-07-23T20:42:16Z","currency":null,"description":"Sweet + shirts","eccn":null,"hs_tariff_number":"654321","id":"cstitem_fab3bc6bfaa74935971d426234a7c331","manufacturer":null,"mode":"test","object":"CustomsItem","origin_country":"US","printed_commodity_identifier":null,"quantity":2,"updated_at":"2024-07-23T20:42:16Z","value":null,"weight":11}],"customs_signer":"Steve + Brule","declaration":null,"eel_pfc":"NOEEI 30.37(a)","id":"cstinfo_39a57ccd0d9a479c8b2f2523350d0762","mode":"test","non_delivery_option":"return","object":"CustomsInfo","restriction_comments":null,"restriction_type":"none","updated_at":"2024-07-23T20:42:16Z"},"fees":[],"forms":[],"from_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:16+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0c7358b4493411ef903bac1f6bc539ae","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:16+00:00","verifications":{},"zip":"94107"},"id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","insurance":null,"is_return":false,"messages":[{"carrier":"DhlEcs","carrier_account_id":"ca_1fefcb0d0a9f4e5db5e5a1c360958484","message":"shipment.customs_info.customs_items.0.value: + field required and shipment.customs_info.customs_items.0.code: field required","type":"rate_error"}],"mode":"test","object":"Shipment","options":{"currency":"USD","date_advance":0,"invoice_number":"123","label_format":"PNG","payment":{"type":"SENDER"}},"order_id":null,"parcel":{"created_at":"2024-07-23T20:42:16Z","height":4,"id":"prcl_181d074b6555405d94296d97074c945b","length":10,"mode":"test","object":"Parcel","predefined_package":null,"updated_at":"2024-07-23T20:42:16Z","weight":15.4,"width":8},"postage_label":null,"rates":[{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:17Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_4bf3466e2a5f44179d08f5a1d37d972e","list_currency":"USD","list_rate":"8.25","mode":"test","object":"Rate","rate":"6.90","retail_currency":"USD","retail_rate":"9.80","service":"Priority","shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","updated_at":"2024-07-23T20:42:17Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:17Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":3,"est_delivery_days":3,"id":"rate_c7c2e3e3eb814cb4a183a0bf3235030a","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","updated_at":"2024-07-23T20:42:17Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:17Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_eb6d8819fcd34b6ca7324b3842edca08","list_currency":"USD","list_rate":"33.10","mode":"test","object":"Rate","rate":"33.10","retail_currency":"USD","retail_rate":"37.90","service":"Express","shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","updated_at":"2024-07-23T20:42:17Z"}],"reference":"123","refund_status":null,"return_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:16+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0c7358b4493411ef903bac1f6bc539ae","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:16+00:00","verifications":{},"zip":"94107"},"scan_form":null,"selected_rate":null,"status":"unknown","to_address":{"carrier_facility":null,"city":"Redondo + Beach","company":null,"country":"US","created_at":"2024-07-23T20:42:16+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0c6aff87493411ef8ab4ac1f6bc539aa","mode":"test","name":"Elizabeth + Swan","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"179 + N Harbor Dr","street2":null,"updated_at":"2024-07-23T20:42:16+00:00","verifications":{},"zip":"90277"},"tracker":null,"tracking_code":null,"updated_at":"2024-07-23T20:42:17Z","usps_zone":4}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Location: + - /api/v2/shipments/shp_6cc7b5a55ea94a19a47a3acf7d160d27 + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015a8f42f248c00230971 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb40nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.360183" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 201 Created + code: 201 + duration: "" +- request: + body: '{"insurance":"100.00","rate":{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:17Z","currency":"USD","delivery_days":3,"est_delivery_days":3,"id":"rate_c7c2e3e3eb814cb4a183a0bf3235030a","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","updated_at":"2024-07-23T20:42:17Z"}}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/shipments/shp_6cc7b5a55ea94a19a47a3acf7d160d27/buy + method: POST + response: + body: '{"batch_id":null,"batch_message":null,"batch_status":null,"buyer_address":{"carrier_facility":null,"city":"REDONDO + BEACH","company":null,"country":"US","created_at":"2024-07-23T20:42:16+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0c6aff87493411ef8ab4ac1f6bc539aa","mode":"test","name":"ELIZABETH + SWAN","object":"Address","phone":"REDACTED","residential":false,"state":"CA","state_tax_id":null,"street1":"179 + N HARBOR DR","street2":"","updated_at":"2024-07-23T20:42:17+00:00","verifications":{"delivery":{"details":{"latitude":33.8436,"longitude":-118.39177,"time_zone":"America/Los_Angeles"},"errors":[],"success":true},"zip4":{"details":null,"errors":[],"success":true}},"zip":"90277-2506"},"created_at":"2024-07-23T20:42:16Z","customs_info":{"contents_explanation":null,"contents_type":"merchandise","created_at":"2024-07-23T20:42:16Z","customs_certify":true,"customs_items":[{"code":null,"created_at":"2024-07-23T20:42:16Z","currency":null,"description":"Sweet + shirts","eccn":null,"hs_tariff_number":"654321","id":"cstitem_fab3bc6bfaa74935971d426234a7c331","manufacturer":null,"mode":"test","object":"CustomsItem","origin_country":"US","printed_commodity_identifier":null,"quantity":2,"updated_at":"2024-07-23T20:42:16Z","value":null,"weight":11}],"customs_signer":"Steve + Brule","declaration":null,"eel_pfc":"NOEEI 30.37(a)","id":"cstinfo_39a57ccd0d9a479c8b2f2523350d0762","mode":"test","non_delivery_option":"return","object":"CustomsInfo","restriction_comments":null,"restriction_type":"none","updated_at":"2024-07-23T20:42:16Z"},"fees":[{"amount":"0.00000","charged":true,"object":"Fee","refunded":false,"type":"LabelFee"},{"amount":"5.93000","charged":true,"object":"Fee","refunded":false,"type":"PostageFee"},{"amount":"1.00000","charged":true,"object":"Fee","refunded":false,"type":"InsuranceFee"}],"forms":[],"from_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:16+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0c7358b4493411ef903bac1f6bc539ae","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:16+00:00","verifications":{},"zip":"94107"},"id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","insurance":"100.00","is_return":false,"messages":[{"carrier":"DhlEcs","carrier_account_id":"ca_1fefcb0d0a9f4e5db5e5a1c360958484","message":"shipment.customs_info.customs_items.0.value: + field required and shipment.customs_info.customs_items.0.code: field required","type":"rate_error"}],"mode":"test","object":"Shipment","options":{"currency":"USD","date_advance":0,"invoice_number":"123","label_format":"PNG","payment":{"type":"SENDER"}},"order_id":null,"parcel":{"created_at":"2024-07-23T20:42:16Z","height":4,"id":"prcl_181d074b6555405d94296d97074c945b","length":10,"mode":"test","object":"Parcel","predefined_package":null,"updated_at":"2024-07-23T20:42:16Z","weight":15.4,"width":8},"postage_label":{"created_at":"2024-07-23T20:42:17Z","date_advance":0,"id":"pl_8f1501c36fec439583286c9cab21538a","integrated_form":"none","label_date":"2024-07-23T20:42:17Z","label_epl2_url":null,"label_file":null,"label_file_type":"image/png","label_pdf_url":null,"label_resolution":300,"label_size":"4x6","label_type":"default","label_url":"https://easypost-files.s3.us-west-2.amazonaws.com/files/postage_label/20240723/e80273009a826a4c758887c13bef845ee7.png","label_zpl_url":null,"object":"PostageLabel","updated_at":"2024-07-23T20:42:18Z"},"rates":[{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:17Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_4bf3466e2a5f44179d08f5a1d37d972e","list_currency":"USD","list_rate":"8.25","mode":"test","object":"Rate","rate":"6.90","retail_currency":"USD","retail_rate":"9.80","service":"Priority","shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","updated_at":"2024-07-23T20:42:17Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:17Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":3,"est_delivery_days":3,"id":"rate_c7c2e3e3eb814cb4a183a0bf3235030a","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","updated_at":"2024-07-23T20:42:17Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:17Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_eb6d8819fcd34b6ca7324b3842edca08","list_currency":"USD","list_rate":"33.10","mode":"test","object":"Rate","rate":"33.10","retail_currency":"USD","retail_rate":"37.90","service":"Express","shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","updated_at":"2024-07-23T20:42:17Z"}],"reference":"123","refund_status":null,"return_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:16+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0c7358b4493411ef903bac1f6bc539ae","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:16+00:00","verifications":{},"zip":"94107"},"scan_form":null,"selected_rate":{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:17Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":3,"est_delivery_days":3,"id":"rate_c7c2e3e3eb814cb4a183a0bf3235030a","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","updated_at":"2024-07-23T20:42:17Z"},"status":"unknown","to_address":{"carrier_facility":null,"city":"REDONDO + BEACH","company":null,"country":"US","created_at":"2024-07-23T20:42:16+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0c6aff87493411ef8ab4ac1f6bc539aa","mode":"test","name":"ELIZABETH + SWAN","object":"Address","phone":"REDACTED","residential":false,"state":"CA","state_tax_id":null,"street1":"179 + N HARBOR DR","street2":"","updated_at":"2024-07-23T20:42:17+00:00","verifications":{"delivery":{"details":{"latitude":33.8436,"longitude":-118.39177,"time_zone":"America/Los_Angeles"},"errors":[],"success":true},"zip4":{"details":null,"errors":[],"success":true}},"zip":"90277-2506"},"tracker":{"carrier":"USPS","carrier_detail":null,"created_at":"2024-07-23T20:42:18Z","est_delivery_date":null,"fees":[],"id":"trk_18cb4d9e1bf843fa9f9d22d30dac259f","mode":"test","object":"Tracker","public_url":"https://track.easypost.com/djE6dHJrXzE4Y2I0ZDllMWJmODQzZmE5ZjlkMjJkMzBkYWMyNTlm","shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","signed_by":null,"status":"unknown","status_detail":"unknown","tracking_code":"9400100110368066410129","tracking_details":[],"updated_at":"2024-07-23T20:42:18Z","weight":null},"tracking_code":"9400100110368066410129","updated_at":"2024-07-23T20:42:18Z","usps_zone":4}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015a9f42f248c002309e3 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb39nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "1.138500" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"amount":100,"contact_email":"test@example.com","description":"Test description","email_evidence_attachments":["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAeUlEQVR42mP8//8/AwAI/AL+4Q7AIAAAAABJRU5ErkJggg=="],"invoice_attachments":["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAeUlEQVR42mP8//8/AwAI/AL+4Q7AIAAAAABJRU5ErkJggg=="],"supporting_documentation_attachments":["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAeUlEQVR42mP8//8/AwAI/AL+4Q7AIAAAAABJRU5ErkJggg=="],"tracking_code":"9400100110368066410129","type":"damage"}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/claims + method: POST + response: + body: '{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/79703f7be53b412e82a59101887bebaa.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/16db67ee17154987a987e515a649d392.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/4e05074680644ed19fae211480b8a6e6.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:42:18","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:42:18"}],"id":"clm_097ef26a6fdd4253bdce2853c61ad62a","insurance_amount":"100.00","insurance_id":"ins_7c76fd3ec3d543b0b6fd70e194a80dc0","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:42:18","tracking_code":"9400100110368066410129","type":"damage","updated_at":"2024-07-23T20:42:18"}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Canary: + - direct + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015aaf42f248c00230af7 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb43nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.837222" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 201 Created + code: 201 + duration: "" +- request: + body: "" + form: {} + headers: + Authorization: + - REDACTED + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/claims/clm_097ef26a6fdd4253bdce2853c61ad62a/cancel + method: POST + response: + body: '{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/79703f7be53b412e82a59101887bebaa.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/16db67ee17154987a987e515a649d392.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/4e05074680644ed19fae211480b8a6e6.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:42:18","description":"Test + description","history":[{"status":"cancelled","status_detail":"Claim cancellation + was requested.","timestamp":"2024-07-23T20:42:19"},{"status":"submitted","status_detail":"Claim + was created.","timestamp":"2024-07-23T20:42:18"}],"id":"clm_097ef26a6fdd4253bdce2853c61ad62a","insurance_amount":"100.00","insurance_id":"ins_7c76fd3ec3d543b0b6fd70e194a80dc0","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","status":"cancelled","status_detail":"Claim + cancellation was requested.","status_timestamp":"2024-07-23T20:42:19","tracking_code":"9400100110368066410129","type":"damage","updated_at":"2024-07-23T20:42:19"}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015abf42f248c00230bcc + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb38nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb3nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.043492" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" diff --git a/tests/cassettes/TestClaimCreate.yaml b/tests/cassettes/TestClaimCreate.yaml new file mode 100644 index 0000000..abfdc84 --- /dev/null +++ b/tests/cassettes/TestClaimCreate.yaml @@ -0,0 +1,204 @@ +--- +version: 1 +interactions: +- request: + body: '{"shipment":{"customs_info":{"contents_type":"merchandise","customs_certify":true,"customs_items":[{"description":"Sweet + shirts","hs_tariff_number":"654321","origin_country":"US","quantity":2,"weight":11}],"customs_signer":"Steve + Brule","eel_pfc":"NOEEI 30.37(a)","non_delivery_option":"return","restriction_type":"none"},"from_address":{"city":"San + Francisco","country":"US","email":"REDACTED","name":"Jack Sparrow","phone":"REDACTED","state":"CA","street1":"388 + Townsend St","street2":"Apt 20","zip":"94107"},"options":{"invoice_number":"123","label_format":"PNG"},"parcel":{"height":4,"length":10,"weight":15.4,"width":8},"reference":"123","to_address":{"city":"Redondo + Beach","country":"US","email":"REDACTED","name":"Elizabeth Swan","phone":"REDACTED","state":"CA","street1":"179 + N Harbor Dr","zip":"90277"}}}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/shipments + method: POST + response: + body: '{"batch_id":null,"batch_message":null,"batch_status":null,"buyer_address":{"carrier_facility":null,"city":"Redondo + Beach","company":null,"country":"US","created_at":"2024-07-23T20:42:19+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0defefdb493411ef8537ac1f6bc53342","mode":"test","name":"Elizabeth + Swan","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"179 + N Harbor Dr","street2":null,"updated_at":"2024-07-23T20:42:19+00:00","verifications":{},"zip":"90277"},"created_at":"2024-07-23T20:42:19Z","customs_info":{"contents_explanation":null,"contents_type":"merchandise","created_at":"2024-07-23T20:42:19Z","customs_certify":true,"customs_items":[{"code":null,"created_at":"2024-07-23T20:42:19Z","currency":null,"description":"Sweet + shirts","eccn":null,"hs_tariff_number":"654321","id":"cstitem_e21dfec76f5e4d3788be429d14e82fdf","manufacturer":null,"mode":"test","object":"CustomsItem","origin_country":"US","printed_commodity_identifier":null,"quantity":2,"updated_at":"2024-07-23T20:42:19Z","value":null,"weight":11}],"customs_signer":"Steve + Brule","declaration":null,"eel_pfc":"NOEEI 30.37(a)","id":"cstinfo_ae9d12d6a5bd433ab4a93b124ae954a9","mode":"test","non_delivery_option":"return","object":"CustomsInfo","restriction_comments":null,"restriction_type":"none","updated_at":"2024-07-23T20:42:19Z"},"fees":[],"forms":[],"from_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:19+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0df23eb7493411ef8b5cac1f6bc539aa","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:19+00:00","verifications":{},"zip":"94107"},"id":"shp_e9185d362b37476db2b7631f9324384f","insurance":null,"is_return":false,"messages":[{"carrier":"DhlEcs","carrier_account_id":"ca_1fefcb0d0a9f4e5db5e5a1c360958484","message":"shipment.customs_info.customs_items.0.value: + field required and shipment.customs_info.customs_items.0.code: field required","type":"rate_error"}],"mode":"test","object":"Shipment","options":{"currency":"USD","date_advance":0,"invoice_number":"123","label_format":"PNG","payment":{"type":"SENDER"}},"order_id":null,"parcel":{"created_at":"2024-07-23T20:42:19Z","height":4,"id":"prcl_3ce027fbcb1d41bda5a26bf6602a3611","length":10,"mode":"test","object":"Parcel","predefined_package":null,"updated_at":"2024-07-23T20:42:19Z","weight":15.4,"width":8},"postage_label":null,"rates":[{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:19Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":3,"est_delivery_days":3,"id":"rate_3405664615754d1dbd4f595097b41353","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_e9185d362b37476db2b7631f9324384f","updated_at":"2024-07-23T20:42:19Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:19Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_5bd506fef55548c0a32b89c3470ab96d","list_currency":"USD","list_rate":"33.10","mode":"test","object":"Rate","rate":"33.10","retail_currency":"USD","retail_rate":"37.90","service":"Express","shipment_id":"shp_e9185d362b37476db2b7631f9324384f","updated_at":"2024-07-23T20:42:19Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:19Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_05b9f2eba0e5464e927f7a9ef9e577bf","list_currency":"USD","list_rate":"8.25","mode":"test","object":"Rate","rate":"6.90","retail_currency":"USD","retail_rate":"9.80","service":"Priority","shipment_id":"shp_e9185d362b37476db2b7631f9324384f","updated_at":"2024-07-23T20:42:19Z"}],"reference":"123","refund_status":null,"return_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:19+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0df23eb7493411ef8b5cac1f6bc539aa","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:19+00:00","verifications":{},"zip":"94107"},"scan_form":null,"selected_rate":null,"status":"unknown","to_address":{"carrier_facility":null,"city":"Redondo + Beach","company":null,"country":"US","created_at":"2024-07-23T20:42:19+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0defefdb493411ef8537ac1f6bc53342","mode":"test","name":"Elizabeth + Swan","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"179 + N Harbor Dr","street2":null,"updated_at":"2024-07-23T20:42:19+00:00","verifications":{},"zip":"90277"},"tracker":null,"tracking_code":null,"updated_at":"2024-07-23T20:42:19Z","usps_zone":4}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Location: + - /api/v2/shipments/shp_e9185d362b37476db2b7631f9324384f + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015abf42f248c00230bdd + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb39nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.321032" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 201 Created + code: 201 + duration: "" +- request: + body: '{"insurance":"100.00","rate":{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:19Z","currency":"USD","delivery_days":3,"est_delivery_days":3,"id":"rate_3405664615754d1dbd4f595097b41353","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_e9185d362b37476db2b7631f9324384f","updated_at":"2024-07-23T20:42:19Z"}}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/shipments/shp_e9185d362b37476db2b7631f9324384f/buy + method: POST + response: + body: '{"batch_id":null,"batch_message":null,"batch_status":null,"buyer_address":{"carrier_facility":null,"city":"REDONDO + BEACH","company":null,"country":"US","created_at":"2024-07-23T20:42:19+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0defefdb493411ef8537ac1f6bc53342","mode":"test","name":"ELIZABETH + SWAN","object":"Address","phone":"REDACTED","residential":false,"state":"CA","state_tax_id":null,"street1":"179 + N HARBOR DR","street2":"","updated_at":"2024-07-23T20:42:19+00:00","verifications":{"delivery":{"details":{"latitude":33.8436,"longitude":-118.39177,"time_zone":"America/Los_Angeles"},"errors":[],"success":true},"zip4":{"details":null,"errors":[],"success":true}},"zip":"90277-2506"},"created_at":"2024-07-23T20:42:19Z","customs_info":{"contents_explanation":null,"contents_type":"merchandise","created_at":"2024-07-23T20:42:19Z","customs_certify":true,"customs_items":[{"code":null,"created_at":"2024-07-23T20:42:19Z","currency":null,"description":"Sweet + shirts","eccn":null,"hs_tariff_number":"654321","id":"cstitem_e21dfec76f5e4d3788be429d14e82fdf","manufacturer":null,"mode":"test","object":"CustomsItem","origin_country":"US","printed_commodity_identifier":null,"quantity":2,"updated_at":"2024-07-23T20:42:19Z","value":null,"weight":11}],"customs_signer":"Steve + Brule","declaration":null,"eel_pfc":"NOEEI 30.37(a)","id":"cstinfo_ae9d12d6a5bd433ab4a93b124ae954a9","mode":"test","non_delivery_option":"return","object":"CustomsInfo","restriction_comments":null,"restriction_type":"none","updated_at":"2024-07-23T20:42:19Z"},"fees":[{"amount":"0.00000","charged":true,"object":"Fee","refunded":false,"type":"LabelFee"},{"amount":"5.93000","charged":true,"object":"Fee","refunded":false,"type":"PostageFee"},{"amount":"1.00000","charged":true,"object":"Fee","refunded":false,"type":"InsuranceFee"}],"forms":[],"from_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:19+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0df23eb7493411ef8b5cac1f6bc539aa","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:19+00:00","verifications":{},"zip":"94107"},"id":"shp_e9185d362b37476db2b7631f9324384f","insurance":"100.00","is_return":false,"messages":[{"carrier":"DhlEcs","carrier_account_id":"ca_1fefcb0d0a9f4e5db5e5a1c360958484","message":"shipment.customs_info.customs_items.0.value: + field required and shipment.customs_info.customs_items.0.code: field required","type":"rate_error"}],"mode":"test","object":"Shipment","options":{"currency":"USD","date_advance":0,"invoice_number":"123","label_format":"PNG","payment":{"type":"SENDER"}},"order_id":null,"parcel":{"created_at":"2024-07-23T20:42:19Z","height":4,"id":"prcl_3ce027fbcb1d41bda5a26bf6602a3611","length":10,"mode":"test","object":"Parcel","predefined_package":null,"updated_at":"2024-07-23T20:42:19Z","weight":15.4,"width":8},"postage_label":{"created_at":"2024-07-23T20:42:20Z","date_advance":0,"id":"pl_64ecd438e8e44506a00dd5b3458f4d25","integrated_form":"none","label_date":"2024-07-23T20:42:20Z","label_epl2_url":null,"label_file":null,"label_file_type":"image/png","label_pdf_url":null,"label_resolution":300,"label_size":"4x6","label_type":"default","label_url":"https://easypost-files.s3.us-west-2.amazonaws.com/files/postage_label/20240723/e89bdbac2a1573427785f43408fb3747ff.png","label_zpl_url":null,"object":"PostageLabel","updated_at":"2024-07-23T20:42:20Z"},"rates":[{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:19Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":3,"est_delivery_days":3,"id":"rate_3405664615754d1dbd4f595097b41353","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_e9185d362b37476db2b7631f9324384f","updated_at":"2024-07-23T20:42:19Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:19Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_5bd506fef55548c0a32b89c3470ab96d","list_currency":"USD","list_rate":"33.10","mode":"test","object":"Rate","rate":"33.10","retail_currency":"USD","retail_rate":"37.90","service":"Express","shipment_id":"shp_e9185d362b37476db2b7631f9324384f","updated_at":"2024-07-23T20:42:19Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:19Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_05b9f2eba0e5464e927f7a9ef9e577bf","list_currency":"USD","list_rate":"8.25","mode":"test","object":"Rate","rate":"6.90","retail_currency":"USD","retail_rate":"9.80","service":"Priority","shipment_id":"shp_e9185d362b37476db2b7631f9324384f","updated_at":"2024-07-23T20:42:19Z"}],"reference":"123","refund_status":null,"return_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:19+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0df23eb7493411ef8b5cac1f6bc539aa","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:19+00:00","verifications":{},"zip":"94107"},"scan_form":null,"selected_rate":{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:20Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":3,"est_delivery_days":3,"id":"rate_3405664615754d1dbd4f595097b41353","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_e9185d362b37476db2b7631f9324384f","updated_at":"2024-07-23T20:42:20Z"},"status":"unknown","to_address":{"carrier_facility":null,"city":"REDONDO + BEACH","company":null,"country":"US","created_at":"2024-07-23T20:42:19+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0defefdb493411ef8537ac1f6bc53342","mode":"test","name":"ELIZABETH + SWAN","object":"Address","phone":"REDACTED","residential":false,"state":"CA","state_tax_id":null,"street1":"179 + N HARBOR DR","street2":"","updated_at":"2024-07-23T20:42:19+00:00","verifications":{"delivery":{"details":{"latitude":33.8436,"longitude":-118.39177,"time_zone":"America/Los_Angeles"},"errors":[],"success":true},"zip4":{"details":null,"errors":[],"success":true}},"zip":"90277-2506"},"tracker":{"carrier":"USPS","carrier_detail":null,"created_at":"2024-07-23T20:42:20Z","est_delivery_date":null,"fees":[],"id":"trk_cfb101ec4b5749c1a396668725ff264f","mode":"test","object":"Tracker","public_url":"https://track.easypost.com/djE6dHJrX2NmYjEwMWVjNGI1NzQ5YzFhMzk2NjY4NzI1ZmYyNjRm","shipment_id":"shp_e9185d362b37476db2b7631f9324384f","signed_by":null,"status":"unknown","status_detail":"unknown","tracking_code":"9400100110368066410143","tracking_details":[],"updated_at":"2024-07-23T20:42:20Z","weight":null},"tracking_code":"9400100110368066410143","updated_at":"2024-07-23T20:42:20Z","usps_zone":4}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015abf42f248c00230c36 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb41nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.988077" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"amount":100,"contact_email":"test@example.com","description":"Test description","email_evidence_attachments":["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAeUlEQVR42mP8//8/AwAI/AL+4Q7AIAAAAABJRU5ErkJggg=="],"invoice_attachments":["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAeUlEQVR42mP8//8/AwAI/AL+4Q7AIAAAAABJRU5ErkJggg=="],"supporting_documentation_attachments":["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAeUlEQVR42mP8//8/AwAI/AL+4Q7AIAAAAABJRU5ErkJggg=="],"tracking_code":"9400100110368066410143","type":"damage"}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/claims + method: POST + response: + body: '{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/8127cfe6e9854efd8c1aad5a2f7a2fb4.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/2767b29020094c5d8db6467c0948aff8.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/4efc841619c94902ab7d7e60a616df42.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:42:20","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:42:20"}],"id":"clm_097ecf98b9d44601971f2a57e34457f6","insurance_amount":"100.00","insurance_id":"ins_431ead6b13a6488789161935a18811b9","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_e9185d362b37476db2b7631f9324384f","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:42:20","tracking_code":"9400100110368066410143","type":"damage","updated_at":"2024-07-23T20:42:20"}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Canary: + - direct + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015acf42f248c00230d25 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb43nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.815223" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 201 Created + code: 201 + duration: "" diff --git a/tests/cassettes/TestClaimGetNextPage.yaml b/tests/cassettes/TestClaimGetNextPage.yaml new file mode 100644 index 0000000..d2ede2e --- /dev/null +++ b/tests/cassettes/TestClaimGetNextPage.yaml @@ -0,0 +1,68 @@ +--- +version: 1 +interactions: +- request: + body: page_size=5 + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/x-www-form-urlencoded + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/claims + method: GET + response: + body: '{"claims":[{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/8127cfe6e9854efd8c1aad5a2f7a2fb4.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/2767b29020094c5d8db6467c0948aff8.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/4efc841619c94902ab7d7e60a616df42.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:42:20","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:42:20"}],"id":"clm_097ecf98b9d44601971f2a57e34457f6","insurance_amount":"100.00","insurance_id":"ins_431ead6b13a6488789161935a18811b9","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_e9185d362b37476db2b7631f9324384f","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:42:20","tracking_code":"9400100110368066410143","type":"damage","updated_at":"2024-07-23T20:42:20"},{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/79703f7be53b412e82a59101887bebaa.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/16db67ee17154987a987e515a649d392.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/4e05074680644ed19fae211480b8a6e6.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:42:18","description":"Test + description","history":[{"status":"cancelled","status_detail":"Claim cancellation + was requested.","timestamp":"2024-07-23T20:42:19"},{"status":"submitted","status_detail":"Claim + was created.","timestamp":"2024-07-23T20:42:18"}],"id":"clm_097ef26a6fdd4253bdce2853c61ad62a","insurance_amount":"100.00","insurance_id":"ins_7c76fd3ec3d543b0b6fd70e194a80dc0","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_6cc7b5a55ea94a19a47a3acf7d160d27","status":"cancelled","status_detail":"Claim + cancellation was requested.","status_timestamp":"2024-07-23T20:42:19","tracking_code":"9400100110368066410129","type":"damage","updated_at":"2024-07-23T20:42:19"},{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/c44df5462b774c0c977f87e3b60d2b01.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/80738b455dea42658a66a250c40d9aba.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/ee68a27ae3854ca5bd17f0752fa81ddf.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:28:59","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:28:59"}],"id":"clm_097e5796aa404ad4992781722224dcea","insurance_amount":"100.00","insurance_id":"ins_b004dab680bb4251abe5888de3bc4d07","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_ec517502568a4cb79d4af314dd16faa1","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:28:59","tracking_code":"9400100110368066408089","type":"damage","updated_at":"2024-07-23T20:28:59"},{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/2170a351b74540d38ad04ba465d6daf9.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/4ae21037c02f4e0f90e3e6bf0511c429.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/c910f338b6c9465f8023780002296673.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:28:57","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:28:57"}],"id":"clm_097e3dc1ade44a61b22c27e85d377fec","insurance_amount":"100.00","insurance_id":"ins_a82753192b544bd79ee19d0c22dabff6","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_f9de24018a77456e95a1e5efcbb050fb","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:28:57","tracking_code":"9400100110368066408065","type":"damage","updated_at":"2024-07-23T20:28:57"},{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/9d36dfc0ae1b408893c33aa3fb76baeb.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/03390ff136a14600bf90a01aeed7482b.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/1666429034d24286aa46862ec3379c55.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:28:55","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:28:55"}],"id":"clm_097e083764974c80ab79ff8dbad6f337","insurance_amount":"100.00","insurance_id":"ins_98ffb9130f2945ebbeb57051a54aae5b","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_eceec0522e8244c68ca3ae686e21c244","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:28:55","tracking_code":"9400100110368066408058","type":"damage","updated_at":"2024-07-23T20:28:55"}],"has_more":false}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015adf42f248c00230dc6 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb35nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.049707" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" diff --git a/tests/cassettes/TestClaimRetrieve.yaml b/tests/cassettes/TestClaimRetrieve.yaml new file mode 100644 index 0000000..278dc1d --- /dev/null +++ b/tests/cassettes/TestClaimRetrieve.yaml @@ -0,0 +1,257 @@ +--- +version: 1 +interactions: +- request: + body: '{"shipment":{"customs_info":{"contents_type":"merchandise","customs_certify":true,"customs_items":[{"description":"Sweet + shirts","hs_tariff_number":"654321","origin_country":"US","quantity":2,"weight":11}],"customs_signer":"Steve + Brule","eel_pfc":"NOEEI 30.37(a)","non_delivery_option":"return","restriction_type":"none"},"from_address":{"city":"San + Francisco","country":"US","email":"REDACTED","name":"Jack Sparrow","phone":"REDACTED","state":"CA","street1":"388 + Townsend St","street2":"Apt 20","zip":"94107"},"options":{"invoice_number":"123","label_format":"PNG"},"parcel":{"height":4,"length":10,"weight":15.4,"width":8},"reference":"123","to_address":{"city":"Redondo + Beach","country":"US","email":"REDACTED","name":"Elizabeth Swan","phone":"REDACTED","state":"CA","street1":"179 + N Harbor Dr","zip":"90277"}}}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/shipments + method: POST + response: + body: '{"batch_id":null,"batch_message":null,"batch_status":null,"buyer_address":{"carrier_facility":null,"city":"Redondo + Beach","company":null,"country":"US","created_at":"2024-07-23T20:42:21+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0f58de86493411ef85b3ac1f6bc53342","mode":"test","name":"Elizabeth + Swan","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"179 + N Harbor Dr","street2":null,"updated_at":"2024-07-23T20:42:21+00:00","verifications":{},"zip":"90277"},"created_at":"2024-07-23T20:42:21Z","customs_info":{"contents_explanation":null,"contents_type":"merchandise","created_at":"2024-07-23T20:42:21Z","customs_certify":true,"customs_items":[{"code":null,"created_at":"2024-07-23T20:42:21Z","currency":null,"description":"Sweet + shirts","eccn":null,"hs_tariff_number":"654321","id":"cstitem_9e25f535cfe84252bf8d120c692c5cbe","manufacturer":null,"mode":"test","object":"CustomsItem","origin_country":"US","printed_commodity_identifier":null,"quantity":2,"updated_at":"2024-07-23T20:42:21Z","value":null,"weight":11}],"customs_signer":"Steve + Brule","declaration":null,"eel_pfc":"NOEEI 30.37(a)","id":"cstinfo_c2848f5bd0b4452f814b428b07d16533","mode":"test","non_delivery_option":"return","object":"CustomsInfo","restriction_comments":null,"restriction_type":"none","updated_at":"2024-07-23T20:42:21Z"},"fees":[],"forms":[],"from_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:21+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0f5a9f28493411efbc613cecef1b359e","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:21+00:00","verifications":{},"zip":"94107"},"id":"shp_9fa021a939f742f49192af14edbfbe5c","insurance":null,"is_return":false,"messages":[{"carrier":"DhlEcs","carrier_account_id":"ca_1fefcb0d0a9f4e5db5e5a1c360958484","message":"shipment.customs_info.customs_items.0.value: + field required and shipment.customs_info.customs_items.0.code: field required","type":"rate_error"}],"mode":"test","object":"Shipment","options":{"currency":"USD","date_advance":0,"invoice_number":"123","label_format":"PNG","payment":{"type":"SENDER"}},"order_id":null,"parcel":{"created_at":"2024-07-23T20:42:21Z","height":4,"id":"prcl_b7339d9ca8d141039d8da7953ce95557","length":10,"mode":"test","object":"Parcel","predefined_package":null,"updated_at":"2024-07-23T20:42:21Z","weight":15.4,"width":8},"postage_label":null,"rates":[{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:21Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_dcb3f4b5be4a46d2ad42a9be4ca8f2bb","list_currency":"USD","list_rate":"33.10","mode":"test","object":"Rate","rate":"33.10","retail_currency":"USD","retail_rate":"37.90","service":"Express","shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","updated_at":"2024-07-23T20:42:21Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:21Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_44b0d2c8bc214819adc7da90ffdc0824","list_currency":"USD","list_rate":"8.25","mode":"test","object":"Rate","rate":"6.90","retail_currency":"USD","retail_rate":"9.80","service":"Priority","shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","updated_at":"2024-07-23T20:42:21Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:21Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":3,"est_delivery_days":3,"id":"rate_30779544ad514ffaa9365b3d186c5c18","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","updated_at":"2024-07-23T20:42:21Z"}],"reference":"123","refund_status":null,"return_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:21+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0f5a9f28493411efbc613cecef1b359e","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:21+00:00","verifications":{},"zip":"94107"},"scan_form":null,"selected_rate":null,"status":"unknown","to_address":{"carrier_facility":null,"city":"Redondo + Beach","company":null,"country":"US","created_at":"2024-07-23T20:42:21+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0f58de86493411ef85b3ac1f6bc53342","mode":"test","name":"Elizabeth + Swan","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"179 + N Harbor Dr","street2":null,"updated_at":"2024-07-23T20:42:21+00:00","verifications":{},"zip":"90277"},"tracker":null,"tracking_code":null,"updated_at":"2024-07-23T20:42:21Z","usps_zone":4}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Location: + - /api/v2/shipments/shp_9fa021a939f742f49192af14edbfbe5c + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015adf42f248c00230dde + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb41nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb3nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.301259" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 201 Created + code: 201 + duration: "" +- request: + body: '{"insurance":"100.00","rate":{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:21Z","currency":"USD","delivery_days":3,"est_delivery_days":3,"id":"rate_30779544ad514ffaa9365b3d186c5c18","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","updated_at":"2024-07-23T20:42:21Z"}}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/shipments/shp_9fa021a939f742f49192af14edbfbe5c/buy + method: POST + response: + body: '{"batch_id":null,"batch_message":null,"batch_status":null,"buyer_address":{"carrier_facility":null,"city":"REDONDO + BEACH","company":null,"country":"US","created_at":"2024-07-23T20:42:21+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0f58de86493411ef85b3ac1f6bc53342","mode":"test","name":"ELIZABETH + SWAN","object":"Address","phone":"REDACTED","residential":false,"state":"CA","state_tax_id":null,"street1":"179 + N HARBOR DR","street2":"","updated_at":"2024-07-23T20:42:22+00:00","verifications":{"delivery":{"details":{"latitude":33.8436,"longitude":-118.39177,"time_zone":"America/Los_Angeles"},"errors":[],"success":true},"zip4":{"details":null,"errors":[],"success":true}},"zip":"90277-2506"},"created_at":"2024-07-23T20:42:21Z","customs_info":{"contents_explanation":null,"contents_type":"merchandise","created_at":"2024-07-23T20:42:21Z","customs_certify":true,"customs_items":[{"code":null,"created_at":"2024-07-23T20:42:21Z","currency":null,"description":"Sweet + shirts","eccn":null,"hs_tariff_number":"654321","id":"cstitem_9e25f535cfe84252bf8d120c692c5cbe","manufacturer":null,"mode":"test","object":"CustomsItem","origin_country":"US","printed_commodity_identifier":null,"quantity":2,"updated_at":"2024-07-23T20:42:21Z","value":null,"weight":11}],"customs_signer":"Steve + Brule","declaration":null,"eel_pfc":"NOEEI 30.37(a)","id":"cstinfo_c2848f5bd0b4452f814b428b07d16533","mode":"test","non_delivery_option":"return","object":"CustomsInfo","restriction_comments":null,"restriction_type":"none","updated_at":"2024-07-23T20:42:21Z"},"fees":[{"amount":"0.00000","charged":true,"object":"Fee","refunded":false,"type":"LabelFee"},{"amount":"5.93000","charged":true,"object":"Fee","refunded":false,"type":"PostageFee"},{"amount":"1.00000","charged":true,"object":"Fee","refunded":false,"type":"InsuranceFee"}],"forms":[],"from_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:21+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0f5a9f28493411efbc613cecef1b359e","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:21+00:00","verifications":{},"zip":"94107"},"id":"shp_9fa021a939f742f49192af14edbfbe5c","insurance":"100.00","is_return":false,"messages":[{"carrier":"DhlEcs","carrier_account_id":"ca_1fefcb0d0a9f4e5db5e5a1c360958484","message":"shipment.customs_info.customs_items.0.value: + field required and shipment.customs_info.customs_items.0.code: field required","type":"rate_error"}],"mode":"test","object":"Shipment","options":{"currency":"USD","date_advance":0,"invoice_number":"123","label_format":"PNG","payment":{"type":"SENDER"}},"order_id":null,"parcel":{"created_at":"2024-07-23T20:42:21Z","height":4,"id":"prcl_b7339d9ca8d141039d8da7953ce95557","length":10,"mode":"test","object":"Parcel","predefined_package":null,"updated_at":"2024-07-23T20:42:21Z","weight":15.4,"width":8},"postage_label":{"created_at":"2024-07-23T20:42:22Z","date_advance":0,"id":"pl_50111bc1aba54d71ae1f1837eed17cf1","integrated_form":"none","label_date":"2024-07-23T20:42:22Z","label_epl2_url":null,"label_file":null,"label_file_type":"image/png","label_pdf_url":null,"label_resolution":300,"label_size":"4x6","label_type":"default","label_url":"https://easypost-files.s3.us-west-2.amazonaws.com/files/postage_label/20240723/e874523393f1b24e998fbe774fbd5a48f8.png","label_zpl_url":null,"object":"PostageLabel","updated_at":"2024-07-23T20:42:22Z"},"rates":[{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:21Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_dcb3f4b5be4a46d2ad42a9be4ca8f2bb","list_currency":"USD","list_rate":"33.10","mode":"test","object":"Rate","rate":"33.10","retail_currency":"USD","retail_rate":"37.90","service":"Express","shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","updated_at":"2024-07-23T20:42:21Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:21Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":2,"est_delivery_days":2,"id":"rate_44b0d2c8bc214819adc7da90ffdc0824","list_currency":"USD","list_rate":"8.25","mode":"test","object":"Rate","rate":"6.90","retail_currency":"USD","retail_rate":"9.80","service":"Priority","shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","updated_at":"2024-07-23T20:42:21Z"},{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:21Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":3,"est_delivery_days":3,"id":"rate_30779544ad514ffaa9365b3d186c5c18","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","updated_at":"2024-07-23T20:42:21Z"}],"reference":"123","refund_status":null,"return_address":{"carrier_facility":null,"city":"San + Francisco","company":null,"country":"US","created_at":"2024-07-23T20:42:21+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0f5a9f28493411efbc613cecef1b359e","mode":"test","name":"Jack + Sparrow","object":"Address","phone":"REDACTED","residential":null,"state":"CA","state_tax_id":null,"street1":"388 + Townsend St","street2":"Apt 20","updated_at":"2024-07-23T20:42:21+00:00","verifications":{},"zip":"94107"},"scan_form":null,"selected_rate":{"billing_type":"easypost","carrier":"USPS","carrier_account_id":"ca_e606176ddb314afe896733636dba2f3b","created_at":"2024-07-23T20:42:22Z","currency":"USD","delivery_date":null,"delivery_date_guaranteed":false,"delivery_days":3,"est_delivery_days":3,"id":"rate_30779544ad514ffaa9365b3d186c5c18","list_currency":"USD","list_rate":"6.40","mode":"test","object":"Rate","rate":"5.93","retail_currency":"USD","retail_rate":"8.45","service":"GroundAdvantage","shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","updated_at":"2024-07-23T20:42:22Z"},"status":"unknown","to_address":{"carrier_facility":null,"city":"REDONDO + BEACH","company":null,"country":"US","created_at":"2024-07-23T20:42:21+00:00","email":"REDACTED","federal_tax_id":null,"id":"adr_0f58de86493411ef85b3ac1f6bc53342","mode":"test","name":"ELIZABETH + SWAN","object":"Address","phone":"REDACTED","residential":false,"state":"CA","state_tax_id":null,"street1":"179 + N HARBOR DR","street2":"","updated_at":"2024-07-23T20:42:22+00:00","verifications":{"delivery":{"details":{"latitude":33.8436,"longitude":-118.39177,"time_zone":"America/Los_Angeles"},"errors":[],"success":true},"zip4":{"details":null,"errors":[],"success":true}},"zip":"90277-2506"},"tracker":{"carrier":"USPS","carrier_detail":null,"created_at":"2024-07-23T20:42:22Z","est_delivery_date":null,"fees":[],"id":"trk_685d45b64d6c425990496424f6fb59bd","mode":"test","object":"Tracker","public_url":"https://track.easypost.com/djE6dHJrXzY4NWQ0NWI2NGQ2YzQyNTk5MDQ5NjQyNGY2ZmI1OWJk","shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","signed_by":null,"status":"unknown","status_detail":"unknown","tracking_code":"9400100110368066410150","tracking_details":[],"updated_at":"2024-07-23T20:42:22Z","weight":null},"tracking_code":"9400100110368066410150","updated_at":"2024-07-23T20:42:22Z","usps_zone":4}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015adf42f248c00230e31 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb35nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb3nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.898736" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"amount":100,"contact_email":"test@example.com","description":"Test description","email_evidence_attachments":["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAeUlEQVR42mP8//8/AwAI/AL+4Q7AIAAAAABJRU5ErkJggg=="],"invoice_attachments":["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAeUlEQVR42mP8//8/AwAI/AL+4Q7AIAAAAABJRU5ErkJggg=="],"supporting_documentation_attachments":["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAeUlEQVR42mP8//8/AwAI/AL+4Q7AIAAAAABJRU5ErkJggg=="],"tracking_code":"9400100110368066410150","type":"damage"}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/claims + method: POST + response: + body: '{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/a286dceba155434d9c8236be77041569.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/f5e694f03dec4b95be379d716f5cb5cb.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/c75f8f4d64a548aa8891724d4eb27d11.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:42:22","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:42:22"}],"id":"clm_097e094345d74d319a9f252c072e824d","insurance_amount":"100.00","insurance_id":"ins_d25fcb11efcf4f44a1120b527c7c360b","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:42:22","tracking_code":"9400100110368066410150","type":"damage","updated_at":"2024-07-23T20:42:22"}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015aef42f248c00230f31 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb39nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.752850" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 201 Created + code: 201 + duration: "" +- request: + body: "" + form: {} + headers: + Authorization: + - REDACTED + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/claims/clm_097e094345d74d319a9f252c072e824d + method: GET + response: + body: '{"approved_amount":null,"attachments":["https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/a286dceba155434d9c8236be77041569.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/f5e694f03dec4b95be379d716f5cb5cb.png","https://easypost-files.s3-us-west-2.amazonaws.com/insurance/20240723/c75f8f4d64a548aa8891724d4eb27d11.png"],"check_delivery_address":null,"contact_email":"test@example.com","created_at":"2024-07-23T20:42:22","description":"Test + description","history":[{"status":"submitted","status_detail":"Claim was created.","timestamp":"2024-07-23T20:42:22"}],"id":"clm_097e094345d74d319a9f252c072e824d","insurance_amount":"100.00","insurance_id":"ins_d25fcb11efcf4f44a1120b527c7c360b","mode":"test","object":"Claim","payment_method":"easypost_wallet","recipient_name":null,"requested_amount":"100.00","salvage_value":null,"shipment_id":"shp_9fa021a939f742f49192af14edbfbe5c","status":"submitted","status_detail":"Claim + was created.","status_timestamp":"2024-07-23T20:42:22","tracking_code":"9400100110368066410150","type":"damage","updated_at":"2024-07-23T20:42:22"}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Canary: + - direct + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 98f5faea66a015aff42f248c0023100a + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb32nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq c0f5e722d1 + - extlb1nuq fa152d4755 + X-Runtime: + - "0.034222" + X-Version-Label: + - easypost-202407231832-14d334dc13-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" diff --git a/tests/claim_test.go b/tests/claim_test.go new file mode 100644 index 0000000..cb8afaf --- /dev/null +++ b/tests/claim_test.go @@ -0,0 +1,145 @@ +package easypost_test + +import ( + "reflect" + "strconv" + "strings" + + "github.com/EasyPost/easypost-go/v4" +) + +func prepareInsuredShipment(client *easypost.Client, shipmentCreateParams *easypost.Shipment, claimAmount float64) *easypost.Shipment { + shipment, err := client.CreateShipment(shipmentCreateParams) + if err != nil { + panic(err) + } + rate, err := client.LowestShipmentRate(shipment) + if err != nil { + panic(err) + } + claimAmountStr := strconv.FormatFloat(claimAmount, 'f', 2, 64) + purchasedShipment, err := client.BuyShipment(shipment.ID, &rate, claimAmountStr) + if err != nil { + panic(err) + } + + return purchasedShipment +} + +func (c *ClientTests) TestClaimCreate() { + client := c.TestClient() + assert, require := c.Assert(), c.Require() + + claimAmount := 100.0 + claimAmountStr := strconv.FormatFloat(claimAmount, 'f', 2, 64) + + createShipmentParams := c.fixture.FullShipment() + insuredShipment := prepareInsuredShipment(client, createShipmentParams, claimAmount) + + createClaimParams := c.fixture.BasicClaim() + createClaimParams.TrackingCode = insuredShipment.TrackingCode + createClaimParams.Amount = claimAmount + + claim, err := client.CreateClaim(createClaimParams) + require.NoError(err) + + assert.Equal(reflect.TypeOf(&easypost.Claim{}), reflect.TypeOf(claim)) + assert.True(strings.HasPrefix(claim.ID, "clm_")) + assert.Equal(createClaimParams.TrackingCode, claim.TrackingCode) + assert.Equal(claimAmountStr, claim.RequestedAmount) +} + +func (c *ClientTests) TestClaimRetrieve() { + client := c.TestClient() + assert, require := c.Assert(), c.Require() + + claimAmount := 100.0 + + createShipmentParams := c.fixture.FullShipment() + insuredShipment := prepareInsuredShipment(client, createShipmentParams, claimAmount) + + createClaimParams := c.fixture.BasicClaim() + createClaimParams.TrackingCode = insuredShipment.TrackingCode + createClaimParams.Amount = claimAmount + + claim, err := client.CreateClaim(createClaimParams) + require.NoError(err) + + retrievedClaim, err := client.GetClaim(claim.ID) + require.NoError(err) + + assert.Equal(reflect.TypeOf(&easypost.Claim{}), reflect.TypeOf(retrievedClaim)) + assert.Equal(claim.ID, retrievedClaim.ID) +} + +func (c *ClientTests) TestClaimAll() { + client := c.TestClient() + assert, require := c.Assert(), c.Require() + + listClaimsParams := &easypost.ListClaimsParameters{ + PageSize: c.fixture.pageSize(), + } + + claims, err := client.ListClaims(listClaimsParams) + require.NoError(err) + + claimsList := claims.Claims + + assert.LessOrEqual(len(claimsList), c.fixture.pageSize()) + assert.NotNil(claims.HasMore) + for _, claim := range claimsList { + assert.Equal(reflect.TypeOf(&easypost.Claim{}), reflect.TypeOf(claim)) + } +} + +func (c *ClientTests) TestClaimGetNextPage() { + client := c.TestClient() + assert, require := c.Assert(), c.Require() + + listClaimsParams := &easypost.ListClaimsParameters{ + PageSize: c.fixture.pageSize(), + } + + firstPage, err := client.ListClaims(listClaimsParams) + require.NoError(err) + + nextPage, err := client.GetNextClaimPageWithPageSize(firstPage, c.fixture.pageSize()) + defer func() { + if err == nil { + assert.True(len(nextPage.Claims) <= c.fixture.pageSize()) + + lastIDOfFirstPage := firstPage.Claims[len(firstPage.Claims)-1].ID + firstIdOfSecondPage := nextPage.Claims[0].ID + + assert.NotEqual(lastIDOfFirstPage, firstIdOfSecondPage) + } + }() + if err != nil { + assert.Equal(err.Error(), easypost.EndOfPaginationError.Error()) + return + } +} + +func (c *ClientTests) TestClaimCancel() { + client := c.TestClient() + assert, require := c.Assert(), c.Require() + + claimAmount := 100.0 + + createShipmentParams := c.fixture.FullShipment() + insuredShipment := prepareInsuredShipment(client, createShipmentParams, claimAmount) + + createClaimParams := c.fixture.BasicClaim() + createClaimParams.TrackingCode = insuredShipment.TrackingCode + createClaimParams.Amount = claimAmount + + claim, err := client.CreateClaim(createClaimParams) + require.NoError(err) + + cancelledClaim, err := client.CancelClaim(claim.ID) + require.NoError(err) + + assert.Equal(reflect.TypeOf(&easypost.Claim{}), reflect.TypeOf(cancelledClaim)) + assert.True(strings.HasPrefix(cancelledClaim.ID, "clm_")) + assert.Equal("cancelled", cancelledClaim.Status) +} diff --git a/tests/fixture_test.go b/tests/fixture_test.go index eae0ba9..00fc8da 100644 --- a/tests/fixture_test.go +++ b/tests/fixture_test.go @@ -13,24 +13,25 @@ import ( ) type Fixture struct { - Addresses map[string]*easypost.Address `json:"addresses,omitempty"` - CarrierAccounts map[string]*easypost.CarrierAccount `json:"carrier_accounts,omitempty"` - CarrierStrings map[string]string `json:"carrier_strings,omitempty"` - CustomsInfos map[string]*easypost.CustomsInfo `json:"customs_infos,omitempty"` - CustomsItems map[string]*easypost.CustomsItem `json:"customs_items,omitempty"` - CreditCards map[string]*easypost.CreditCardOptions `json:"credit_cards,omitempty"` - FormOptions map[string]map[string]interface{} `json:"form_options,omitempty"` - Insurances map[string]*easypost.Insurance `json:"insurances,omitempty"` - Orders map[string]*easypost.Order `json:"orders,omitempty"` - PageSizes map[string]int `json:"page_sizes,omitempty"` - Parcels map[string]*easypost.Parcel `json:"parcels,omitempty"` - Pickups map[string]*easypost.Pickup `json:"pickups,omitempty"` - ReportTypes map[string]string `json:"report_types,omitempty"` - ServiceNames map[string]map[string]string `json:"service_names,omitempty"` - Shipments map[string]*easypost.Shipment `json:"shipments,omitempty"` - TaxIdentifiers map[string]*easypost.TaxIdentifier `json:"tax_identifiers,omitempty"` - Users map[string]*easypost.UserOptions `json:"users,omitempty"` - WebhookURL string `json:"webhook_url,omitempty"` + Addresses map[string]*easypost.Address `json:"addresses,omitempty"` + CarrierAccounts map[string]*easypost.CarrierAccount `json:"carrier_accounts,omitempty"` + CarrierStrings map[string]string `json:"carrier_strings,omitempty"` + Claims map[string]*easypost.CreateClaimParameters `json:"claims,omitempty"` + CustomsInfos map[string]*easypost.CustomsInfo `json:"customs_infos,omitempty"` + CustomsItems map[string]*easypost.CustomsItem `json:"customs_items,omitempty"` + CreditCards map[string]*easypost.CreditCardOptions `json:"credit_cards,omitempty"` + FormOptions map[string]map[string]interface{} `json:"form_options,omitempty"` + Insurances map[string]*easypost.Insurance `json:"insurances,omitempty"` + Orders map[string]*easypost.Order `json:"orders,omitempty"` + PageSizes map[string]int `json:"page_sizes,omitempty"` + Parcels map[string]*easypost.Parcel `json:"parcels,omitempty"` + Pickups map[string]*easypost.Pickup `json:"pickups,omitempty"` + ReportTypes map[string]string `json:"report_types,omitempty"` + ServiceNames map[string]map[string]string `json:"service_names,omitempty"` + Shipments map[string]*easypost.Shipment `json:"shipments,omitempty"` + TaxIdentifiers map[string]*easypost.TaxIdentifier `json:"tax_identifiers,omitempty"` + Users map[string]*easypost.UserOptions `json:"users,omitempty"` + WebhookURL string `json:"webhook_url,omitempty"` } // Reads fixture data from the fixtures JSON file @@ -177,6 +178,11 @@ func (fixture *Fixture) BasicInsurance() *easypost.Insurance { return readFixtureData().Insurances["basic"] } +// This fixture will require you to add a `tracking_code` key with a tracking code from a shipment and an `amount` key with a float value +func (fixture *Fixture) BasicClaim() *easypost.CreateClaimParameters { + return readFixtureData().Claims["basic"] +} + func (fixture *Fixture) BasicOrder() *easypost.Order { return readFixtureData().Orders["basic"] }