module TophatterMerchant class Order < Resource # http://merchant-api.tophatter.com/docs/order-schema attr_accessor :order_id, :status, :carrier, :tracking_number, :product_name, :product_identifier, :variation_identifier, :annotation, :customer_id, :customer_name, :address1, :address2, :city, :state, :postal_code, :country, :available_refunds, :refund_amount, :disbursement_amount, :seller_fees_amount, :seller_fees, :paid_at, :created_at class << self # http://merchant-api.tophatter.com/docs/order-list # TophatterMerchant::Order.all(filter: 'unfulfilled') def all(filter: nil, page: 1, per_page: 50) get(url: "#{path}.json", params: { filter: filter, page: page, per_page: per_page }).map do |hash| Order.new(hash) end end # http://merchant-api.tophatter.com/docs/order-retrieve # TophatterMerchant::Order.retrieve(60150685) def retrieve(id) Order.new get(url: "#{path}/retrieve.json", params: { order_id: id }) end # http://merchant-api.tophatter.com/docs/order-acknowledge # TophatterMerchant::Order.acknowledge(60150685).status def acknowledge(id) Order.new post(url: "#{path}/acknowledge.json", params: { order_id: id }) end # http://merchant-api.tophatter.com/docs/order-fulfill # TophatterMerchant::Order.fulfill(417953232, carrier: 'other', tracking_number: 'ABC123') def fulfill(id, carrier:, tracking_number:) Order.new post(url: "#{path}/fulfill.json", params: { order_id: id, carrier: carrier, tracking_number: tracking_number }) end # http://merchant-api.tophatter.com/docs/order-refund # TophatterMerchant::Order.refund(417953232, type: 'full', reason: 'delay_in_shipping') # TophatterMerchant::Order.refund(417953232, type: 'partial', reason: 'other', fees: ['shipping_fee']) def refund(id, type:, reason:, fees: []) Order.new post(url: "#{path}/refund.json", params: { order_id: id, type: type, reason: reason, fees: fees }) end # http://merchant-api.tophatter.com/docs/order-annotate # TophatterMerchant::Order.annotate(60157972, 'Testing...').annotation def annotate(id, annotation) Order.new post(url: "#{path}/annotate.json", params: { order_id: id, annotation: annotation }) end protected def path super + '/orders' end end end end