Skip to content

Commit

Permalink
Code update for 2024-01
Browse files Browse the repository at this point in the history
* Added Currency and UpdatedAt properties
* Removed Deprecated fields accepts_marketing and accepts_marketing_updated_at from customer object
* Exporting OrderFinancialStatus and OrderFulfillmentStatus from Order
  • Loading branch information
deepsidhu1313 committed Aug 7, 2024
1 parent e0f9e0d commit efec432
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 81 deletions.
46 changes: 22 additions & 24 deletions customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,28 @@ type CustomerServiceOp struct {

// Customer represents a Shopify customer
type Customer struct {
Id uint64 `json:"id,omitempty"`
Email string `json:"email,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
State string `json:"state,omitempty"`
Note string `json:"note,omitempty"`
VerifiedEmail bool `json:"verified_email,omitempty"`
MultipassIdentifier string `json:"multipass_identifier,omitempty"`
OrdersCount int `json:"orders_count,omitempty"`
TaxExempt bool `json:"tax_exempt,omitempty"`
TotalSpent *decimal.Decimal `json:"total_spent,omitempty"`
Phone string `json:"phone,omitempty"`
Tags string `json:"tags,omitempty"`
LastOrderId uint64 `json:"last_order_id,omitempty"`
LastOrderName string `json:"last_order_name,omitempty"`
AcceptsMarketing bool `json:"accepts_marketing,omitempty"`
AcceptsMarketingUpdatedAt *time.Time `json:"accepts_marketing_updated_at,omitempty"`
EmailMarketingConsent *EmailMarketingConsent `json:"email_marketing_consent"`
SMSMarketingConsent *SMSMarketingConsent `json:"sms_marketing_consent"`
DefaultAddress *CustomerAddress `json:"default_address,omitempty"`
Addresses []*CustomerAddress `json:"addresses,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Metafields []Metafield `json:"metafields,omitempty"`
Id uint64 `json:"id,omitempty"`
Email string `json:"email,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
State string `json:"state,omitempty"`
Note string `json:"note,omitempty"`
VerifiedEmail bool `json:"verified_email,omitempty"`
MultipassIdentifier string `json:"multipass_identifier,omitempty"`
OrdersCount int `json:"orders_count,omitempty"`
TaxExempt bool `json:"tax_exempt,omitempty"`
TotalSpent *decimal.Decimal `json:"total_spent,omitempty"`
Phone string `json:"phone,omitempty"`
Tags string `json:"tags,omitempty"`
LastOrderId uint64 `json:"last_order_id,omitempty"`
LastOrderName string `json:"last_order_name,omitempty"`
EmailMarketingConsent *EmailMarketingConsent `json:"email_marketing_consent"`
SMSMarketingConsent *SMSMarketingConsent `json:"sms_marketing_consent"`
DefaultAddress *CustomerAddress `json:"default_address,omitempty"`
Addresses []*CustomerAddress `json:"addresses,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Metafields []Metafield `json:"metafields,omitempty"`
}

// Represents the result from the customers/X.json endpoint
Expand Down
44 changes: 18 additions & 26 deletions customer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,26 +353,24 @@ func TestCustomerGet(t *testing.T) {
}

expectation := &Customer{
Id: 1,
Email: "[email protected]",
FirstName: "Test",
LastName: "Citizen",
AcceptsMarketing: true,
VerifiedEmail: true,
TaxExempt: false,
OrdersCount: 4,
State: "enabled",
TotalSpent: &totalSpent,
LastOrderId: 123,
Note: "",
Phone: "",
AcceptsMarketingUpdatedAt: &updatedAt,
EmailMarketingConsent: &emailMarketingConsent1,
SMSMarketingConsent: &smsMarketingConsent1,
DefaultAddress: address1,
Addresses: []*CustomerAddress{address1},
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Id: 1,
Email: "[email protected]",
FirstName: "Test",
LastName: "Citizen",
VerifiedEmail: true,
TaxExempt: false,
OrdersCount: 4,
State: "enabled",
TotalSpent: &totalSpent,
LastOrderId: 123,
Note: "",
Phone: "",
EmailMarketingConsent: &emailMarketingConsent1,
SMSMarketingConsent: &smsMarketingConsent1,
DefaultAddress: address1,
Addresses: []*CustomerAddress{address1},
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
}

if customer.Id != expectation.Id {
Expand All @@ -387,9 +385,6 @@ func TestCustomerGet(t *testing.T) {
if customer.LastName != expectation.LastName {
t.Errorf("Customer.LastName returned %+v, expected %+v", customer.LastName, expectation.LastName)
}
if customer.AcceptsMarketing != expectation.AcceptsMarketing {
t.Errorf("Customer.AcceptsMarketing returned %+v, expected %+v", customer.AcceptsMarketing, expectation.AcceptsMarketing)
}
if !customer.CreatedAt.Equal(*expectation.CreatedAt) {
t.Errorf("Customer.CreatedAt returned %+v, expected %+v", customer.CreatedAt, expectation.CreatedAt)
}
Expand Down Expand Up @@ -481,9 +476,6 @@ func TestCustomerGet(t *testing.T) {
if len(customer.Addresses) != len(expectation.Addresses) {
t.Errorf("Customer.Addresses count returned %d, expected %d", len(customer.Addresses), len(expectation.Addresses))
}
if !customer.AcceptsMarketingUpdatedAt.Equal(*expectation.AcceptsMarketingUpdatedAt) {
t.Errorf("Customer.AcceptsMarketingUpdatedAt returned %+v, expected %+v", customer.AcceptsMarketingUpdatedAt, expectation.AcceptsMarketingUpdatedAt)
}
if customer.EmailMarketingConsent == nil {
t.Errorf("Customer.EmailMarketingConsent is nil, expected not nil")
} else {
Expand Down
62 changes: 31 additions & 31 deletions order.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,80 +60,80 @@ const (
OrderStatusAny orderStatus = "any"
)

type orderFulfillmentStatus string
type OrderFulfillmentStatus string

// https://shopify.dev/docs/api/admin-rest/2023-07/resources/order#get-orders?status=any
const (
// Show orders that have been shipped.
OrderFulfillmentStatusShipped orderFulfillmentStatus = "shipped"
OrderFulfillmentStatusShipped OrderFulfillmentStatus = "shipped"

// Show partially shipped orders.
OrderFulfillmentStatusPartial orderFulfillmentStatus = "partial"
OrderFulfillmentStatusPartial OrderFulfillmentStatus = "partial"

// Show orders that have not yet been shipped.
OrderFulfillmentStatusUnshipped orderFulfillmentStatus = "unshipped"
OrderFulfillmentStatusUnshipped OrderFulfillmentStatus = "unshipped"

// Show orders of any fulfillment status.
OrderFulfillmentStatusAny orderFulfillmentStatus = "any"
OrderFulfillmentStatusAny OrderFulfillmentStatus = "any"

// Returns orders with fulfillment_status of null or partial.
OrderFulfillmentStatusUnfulfilled orderFulfillmentStatus = "unfulfilled"
OrderFulfillmentStatusUnfulfilled OrderFulfillmentStatus = "unfulfilled"

//"fulfilled" used to be an acceptable value? Was it deprecated? It isn't noted
//in the Shopify docs at the provided URL, but it was used in tests and still
//seems to function.
OrderFulfillmentStatusFulfilled orderFulfillmentStatus = "fulfilled"
OrderFulfillmentStatusFulfilled OrderFulfillmentStatus = "fulfilled"
)

type orderFinancialStatus string
type OrderFinancialStatus string

// https://shopify.dev/docs/api/admin-rest/2023-07/resources/order#get-orders?status=any
const (
// Show only authorized orders.
OrderFinancialStatusAuthorized orderFinancialStatus = "authorized"
OrderFinancialStatusAuthorized OrderFinancialStatus = "authorized"

// Show only pending orders.
OrderFinancialStatusPending orderFinancialStatus = "pending"
OrderFinancialStatusPending OrderFinancialStatus = "pending"

// Show only paid orders.
OrderFinancialStatusPaid orderFinancialStatus = "paid"
OrderFinancialStatusPaid OrderFinancialStatus = "paid"

// Show only partially paid orders.
OrderFinancialStatusPartiallyPaid orderFinancialStatus = "partially_paid"
OrderFinancialStatusPartiallyPaid OrderFinancialStatus = "partially_paid"

// Show only refunded orders.
OrderFinancialStatusRefunded orderFinancialStatus = "refunded"
OrderFinancialStatusRefunded OrderFinancialStatus = "refunded"

// Show only voided orders.
OrderFinancialStatusVoided orderFinancialStatus = "voided"
OrderFinancialStatusVoided OrderFinancialStatus = "voided"

// Show only partially refunded orders.
OrderFinancialStatusPartiallyRefunded orderFinancialStatus = "partially_refunded"
OrderFinancialStatusPartiallyRefunded OrderFinancialStatus = "partially_refunded"

// Show orders of any financial status.
OrderFinancialStatusAny orderFinancialStatus = "any"
OrderFinancialStatusAny OrderFinancialStatus = "any"

// Show authorized and partially paid orders.
OrderFinancialStatusUnpaid orderFinancialStatus = "unpaid"
OrderFinancialStatusUnpaid OrderFinancialStatus = "unpaid"
)

type orderCancelReason string
type OrderCancelReason string

const (
// The customer canceled the order.
OrderCancelReasonCustomer orderCancelReason = "customer"
OrderCancelReasonCustomer OrderCancelReason = "customer"

// The order was fraudulent.
OrderCancelReasonFraud orderCancelReason = "fraud"
OrderCancelReasonFraud OrderCancelReason = "fraud"

// Items in the order were not in inventory.
OrderCancelReasonInventory orderCancelReason = "inventory"
OrderCancelReasonInventory OrderCancelReason = "inventory"

// The payment was declined.
OrderCancelReasonDeclined orderCancelReason = "declined"
OrderCancelReasonDeclined OrderCancelReason = "declined"

// Cancelled for some other reason.
OrderCancelReasonOther orderCancelReason = "other"
OrderCancelReasonOther OrderCancelReason = "other"
)

type discountAllocationMethod string
Expand Down Expand Up @@ -210,17 +210,17 @@ type OrderCountOptions struct {
Order string `url:"order,omitempty"`
Fields string `url:"fields,omitempty"`
Status orderStatus `url:"status,omitempty"`
FinancialStatus orderFinancialStatus `url:"financial_status,omitempty"`
FulfillmentStatus orderFulfillmentStatus `url:"fulfillment_status,omitempty"`
FinancialStatus OrderFinancialStatus `url:"financial_status,omitempty"`
FulfillmentStatus OrderFulfillmentStatus `url:"fulfillment_status,omitempty"`
}

// A struct for all available order list options.
// See: https://help.shopify.com/api/reference/order#index
type OrderListOptions struct {
ListOptions
Status orderStatus `url:"status,omitempty"`
FinancialStatus orderFinancialStatus `url:"financial_status,omitempty"`
FulfillmentStatus orderFulfillmentStatus `url:"fulfillment_status,omitempty"`
FinancialStatus OrderFinancialStatus `url:"financial_status,omitempty"`
FulfillmentStatus OrderFulfillmentStatus `url:"fulfillment_status,omitempty"`
ProcessedAtMin time.Time `url:"processed_at_min,omitempty"`
ProcessedAtMax time.Time `url:"processed_at_max,omitempty"`
Order string `url:"order,omitempty"`
Expand Down Expand Up @@ -283,9 +283,9 @@ type Order struct {
CurrentTotalTaxSet *AmountSet `json:"current_total_tax_set,omitempty"`
TaxLines []TaxLine `json:"tax_lines,omitempty"`
TotalWeight int `json:"total_weight,omitempty"`
FinancialStatus orderFinancialStatus `json:"financial_status,omitempty"`
FinancialStatus OrderFinancialStatus `json:"financial_status,omitempty"`
Fulfillments []Fulfillment `json:"fulfillments,omitempty"`
FulfillmentStatus orderFulfillmentStatus `json:"fulfillment_status,omitempty"`
FulfillmentStatus OrderFulfillmentStatus `json:"fulfillment_status,omitempty"`
Token string `json:"token,omitempty"`
CartToken string `json:"cart_token,omitempty"`
Number int `json:"number,omitempty"`
Expand All @@ -294,7 +294,7 @@ type Order struct {
Test bool `json:"test,omitempty"`
BrowserIp string `json:"browser_ip,omitempty"`
BuyerAcceptsMarketing bool `json:"buyer_accepts_marketing,omitempty"`
CancelReason orderCancelReason `json:"cancel_reason,omitempty"`
CancelReason OrderCancelReason `json:"cancel_reason,omitempty"`
NoteAttributes []NoteAttribute `json:"note_attributes,omitempty"`
DiscountCodes []DiscountCode `json:"discount_codes,omitempty"`
DiscountApplications []DiscountApplication `json:"discount_applications,omitempty"`
Expand Down Expand Up @@ -392,7 +392,7 @@ type LineItem struct {
ProductExists bool `json:"product_exists,omitempty"`
FulfillableQuantity int `json:"fulfillable_quantity,omitempty"`
Grams int `json:"grams,omitempty"`
FulfillmentStatus orderFulfillmentStatus `json:"fulfillment_status,omitempty"`
FulfillmentStatus OrderFulfillmentStatus `json:"fulfillment_status,omitempty"`
TaxLines []TaxLine `json:"tax_lines,omitempty"`

// Deprecated: See 2022-10 release notes: https://shopify.dev/docs/api/release-notes/2022-10
Expand Down
2 changes: 2 additions & 0 deletions usagecharge.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ type UsageCharge struct {
BalanceRemaining *decimal.Decimal `json:"balance_remaining,omitempty"`
BalanceUsed *decimal.Decimal `json:"balance_used,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Description string `json:"description,omitempty"`
Currency string `json:"currency,omitempty"`
Id uint64 `json:"id,omitempty"`
Price *decimal.Decimal `json:"price,omitempty"`
RiskLevel *decimal.Decimal `json:"risk_level,omitempty"`
Expand Down

0 comments on commit efec432

Please sign in to comment.