xpost 0.1.4 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/.DS_Store +0 -0
  3. data/.gitignore +1 -2
  4. data/.rspec +0 -0
  5. data/Gemfile +0 -0
  6. data/LICENSE +0 -0
  7. data/README.md +0 -0
  8. data/TODO.md +1 -28
  9. data/lib/xpost.rb +6 -8
  10. data/lib/xpost/authentication.rb +0 -5
  11. data/lib/xpost/configuration.rb +0 -15
  12. data/lib/xpost/models.rb +5 -0
  13. data/lib/xpost/models/address.rb +38 -0
  14. data/lib/xpost/models/item.rb +31 -0
  15. data/lib/xpost/models/order.rb +54 -0
  16. data/lib/xpost/orders.rb +16 -57
  17. data/lib/xpost/version.rb +1 -1
  18. data/spec/{order/address/address_spec.rb → address_spec.rb} +0 -0
  19. data/spec/factories/addresses.rb +28 -46
  20. data/spec/factories/items.rb +10 -10
  21. data/spec/factories/orders.rb +16 -39
  22. data/spec/helpers.rb +0 -0
  23. data/spec/{order/items/item_spec.rb → item_spec.rb} +5 -5
  24. data/spec/line_item_spec.rb +16 -0
  25. data/spec/orders/order_create_spec.rb +46 -0
  26. data/spec/orders/order_for_pickup_spec.rb +17 -0
  27. data/spec/orders/{find_spec.rb → orders_find_spec.rb} +2 -3
  28. data/spec/orders/{track_spec.rb → orders_track_spec.rb} +2 -2
  29. data/spec/spec_helper.rb +0 -1
  30. data/spec/xpost_spec.rb +0 -27
  31. data/xpost.gemspec +2 -6
  32. metadata +17 -68
  33. data/lib/.DS_Store +0 -0
  34. data/lib/xpost/.DS_Store +0 -0
  35. data/lib/xpost/address.rb +0 -77
  36. data/lib/xpost/item.rb +0 -44
  37. data/lib/xpost/order.rb +0 -135
  38. data/lib/xpost/statuses.rb +0 -29
  39. data/sample/sample_essential_order_details.json +0 -63
  40. data/sample/sample_xpost_order-confirmed.json +0 -317
  41. data/sample/sample_xpost_order-for-pickup.json +0 -379
  42. data/sample/sample_xpost_order-pending.json +0 -306
  43. data/sample/webhook_sample.json +0 -105
  44. data/spec/order/cancel_spec.rb +0 -37
  45. data/spec/order/confirm_spec.rb +0 -38
  46. data/spec/order/create_spec.rb +0 -97
  47. data/spec/order/for_pickup_spec.rb +0 -42
  48. data/spec/order/get_shipping_label_spec.rb +0 -60
  49. data/spec/order/order_spec.rb +0 -96
data/lib/.DS_Store DELETED
Binary file
data/lib/xpost/.DS_Store DELETED
Binary file
data/lib/xpost/address.rb DELETED
@@ -1,77 +0,0 @@
1
- require 'active_model'
2
- require 'set'
3
-
4
- module Xpost
5
- class Address
6
- include ActiveModel::Model
7
-
8
- REQUIRED_ADDRESS_PARAMETERS = Set[:name, :line_1, :city, :state, :postal_code, :country]
9
- OPTIONAL_ADDRESS_PARAMETERS = Set[:company, :title, :email, :phone_number, :mobile_number, :fax_number,
10
- :district, :line_2, :remarks]
11
-
12
- attr_accessor :name, :line_1, :city, :state, :postal_code, :country
13
- attr_accessor :company, :title, :email, :phone_number, :mobile_number, :fax_number, :district, :line_2, :remarks
14
-
15
- validates_presence_of :name, :line_1, :city, :state, :postal_code, :country
16
-
17
- def initialize(options = {})
18
- # (?) Mr., Mrs., Ms., etc.
19
- @title = options[:title]
20
- @name = options[:name]
21
- @email = options[:email]
22
- @phone_number = options[:phone_number]
23
- @mobile_number = options[:mobile_number]
24
- @fax_number = options[:fax_number]
25
- @company = options[:company]
26
-
27
- # Address Line 1
28
- @line_1 = options[:line_1]
29
- # Address Line 1
30
- @line_2 = options[:line_2]
31
- # City
32
- @city = options[:city]
33
- # District (NCR's Four Districts) (Optional)
34
- @district = options[:district]
35
- # State / Province
36
- @state = options[:state]
37
- # Postal Code / ZIP Code
38
- @postal_code = options[:postal_code]
39
- # Country
40
- @country = options[:country]
41
-
42
- @remarks = options[:remarks]
43
- end
44
-
45
- def attributes
46
- {
47
- title: self.title,
48
- name: self.name,
49
- email: self.email,
50
- phone_number: self.phone_number,
51
- mobile_number: self.mobile_number,
52
- fax_number: self.fax_number,
53
- company: self.company,
54
- line_1: self.line_1,
55
- line_2: self.line_2,
56
- city: self.city,
57
- district: self.district,
58
- state: self.state,
59
- postal_code: self.postal_code,
60
- country: self.country,
61
- remarks: self.remarks
62
- }
63
- end
64
-
65
- def self.sample_address
66
- address = Xpost::Address.new(
67
- name: "Bobby Axelrod",
68
- line_1: "EDSA Shangri-La",
69
- city: "Mandaluyong",
70
- state: "Metro Manila",
71
- postal_code: "1650",
72
- country: "PH"
73
- )
74
- address
75
- end
76
- end
77
- end
data/lib/xpost/item.rb DELETED
@@ -1,44 +0,0 @@
1
- require 'active_model'
2
- require 'set'
3
-
4
- module Xpost
5
- class Item
6
- include ActiveModel::Model
7
-
8
- ITEM_TYPES = Set[:product, :shipping, :tax, :fee, :insurance, :discount]
9
-
10
- attr_accessor :product_type, :description, :amount, :quantity, :metadata
11
-
12
- validates_presence_of :product_type, :description, :amount
13
- validate :check_item_type
14
-
15
- def initialize(options = {})
16
- # Product Type
17
- @product_type = options.key?(:product_type) ? options[:product_type] : "product"
18
- # Product Description
19
- @description = options[:description]
20
- # (Single) Product Amount
21
- @amount = options[:amount]
22
- # Product Quantity
23
- @quantity = options.key?(:quantity) ? options[:quantity].to_i : 1
24
- # Additional Product Data (For third-party purposes)
25
- @metadata = options[:metadata]
26
- end
27
-
28
- def check_item_type
29
- if self.product_type.present? && !ITEM_TYPES.include?(self.product_type.to_sym)
30
- errors.add(:type, "wrong item type")
31
- end
32
- end
33
-
34
- def attributes
35
- {
36
- type: self.product_type,
37
- description: self.description,
38
- amount: self.amount,
39
- quantity: self.quantity,
40
- metadata: self.metadata
41
- }
42
- end
43
- end
44
- end
data/lib/xpost/order.rb DELETED
@@ -1,135 +0,0 @@
1
- require 'active_model'
2
- require 'json'
3
- require 'set'
4
-
5
- module Xpost
6
- class Order
7
- include ActiveModel::Model
8
-
9
- CONFIRMABLE_PARAMETERS = Set[:status, :email, :buyer_name, :contact_number, :delivery_address, :items,
10
- :shipment, :total, :currency, :payment_method, :payment_provider]
11
- FOR_PICKUP_PARAMETERS = Set[:pickup_address]
12
-
13
- attr_accessor :email, :buyer_name, :contact_number, :reference_id
14
- attr_accessor :total, :currency, :payment_method, :payment_provider
15
- attr_accessor :delivery_address, :pickup_address
16
- attr_accessor :status, :items, :shipment
17
-
18
- validates_presence_of :email, :buyer_name, :contact_number
19
- validates_presence_of :delivery_address
20
-
21
- def initialize(options = {})
22
- @status = options[:status] || "pending"
23
- @reference_id = options[:reference_id]
24
- @email = options[:email]
25
- @buyer_name = options[:buyer_name]
26
- @contact_number = options[:contact_number]
27
- @delivery_address = options[:delivery_address]
28
- @items = options[:items] || []
29
- @shipment = options[:shipment]
30
- @total = options[:total]
31
- @currency = options[:currency]
32
- @payment_method = options[:payment_method]
33
- @payment_provider = options[:payment_provider]
34
- @pickup_address = options[:pickup_address]
35
- end
36
-
37
- def self.sample_order
38
- o = Xpost::Order.new
39
- o.email = "john@me.com"
40
- o.buyer_name = "John Doe"
41
- o.contact_number = "+6391712345678"
42
- o.shipment = "small-pouch"
43
- o.total = 1000
44
- o.currency = "PHP"
45
- o.payment_method = "cod"
46
- o.payment_provider = "lbcx"
47
- o.add_item(Xpost::Item.new(
48
- type: "product",
49
- description: "red shirt",
50
- amount: 1000,
51
- quantity: 1,
52
- metadata: "Small"
53
- ))
54
- o.delivery_address = Xpost::Address.new(
55
- name: "Bobby Axelrod",
56
- line_1: "BGC Corporate Centre",
57
- line_2: "5th floor",
58
- city: "Taguig",
59
- state: "Metro Manila",
60
- postal_code: "1634",
61
- country: "PH",
62
- company: "Axe Capital",
63
- title: "CEO",
64
- email: "bobby@axe.com",
65
- phone_number: "12345678",
66
- mobile_number: "091712345678",
67
- fax_number: "12345678",
68
- district: "BGC",
69
- remarks: "Send ASAP"
70
- )
71
- o
72
- end
73
-
74
- def confirmable?
75
- self.valid? && self.has_delivery_address? && self.has_payment_method? && self.has_items?
76
- end
77
-
78
- # https://docs.quadx.xyz/#5f38afd0-66bb-468f-ab4e-993d4745a257
79
- # Sets the order status to canceled. An order can be canceled provided they have not passed the cutoff date and time as specified in the contract.
80
- def cancellable?
81
- true
82
- end
83
-
84
- # https://docs.quadx.xyz/#c831dc25-2de4-36c5-c321-8e9db0fc2105
85
- # The following fields can be updated provided they have not passed the cutoff date and time as specified in the contract.
86
- def updatable?
87
- true
88
- end
89
-
90
- def has_delivery_address?
91
- self.delivery_address.present?
92
- end
93
-
94
- def has_payment_method?
95
- self.total.present? && self.currency.present? && self.payment_method.present? && self.payment_provider.present?
96
- end
97
-
98
- def has_items?
99
- self.items.present? ? self.items.count > 0 : false
100
- end
101
-
102
- def add_item(item)
103
- self.items << item if item.valid?
104
- end
105
-
106
- def order_items
107
- items = []
108
- self.items.each do |item|
109
- items << item.attributes
110
- end
111
- items
112
- end
113
-
114
- def attributes
115
- {
116
- reference_id: self.reference_id,
117
- email: self.email,
118
- buyer_name: self.buyer_name,
119
- contact_number: self.contact_number,
120
- shipment: self.shipment,
121
- total: self.total,
122
- currency: self.currency,
123
- payment_method: self.payment_method,
124
- payment_provider: self.payment_provider,
125
- items: self.order_items,
126
- delivery_address: self.delivery_address.attributes,
127
- pickup_address: self.pickup_address.nil? ? nil : self.pickup_address.attributes,
128
- }
129
- end
130
-
131
- def to_json
132
- self.attributes.to_json
133
- end
134
- end
135
- end
@@ -1,29 +0,0 @@
1
- require 'json'
2
- require 'set'
3
- require 'typhoeus'
4
-
5
- module Xpost
6
- class Statuses
7
- def self.all(auth_token)
8
- get_url("orders/statuses", headers: auth_header(auth_token))
9
- end
10
-
11
- private
12
-
13
- def self.base_url
14
- Xpost.configuration.production_url
15
- end
16
-
17
- def self.auth_header(auth_token)
18
- {"Authorization" => "Bearer #{auth_token}"}
19
- end
20
-
21
- def self.get_url(url, options = {})
22
- req_url = "#{base_url}/#{url}"
23
- req_options = {headers: options[:headers]}
24
-
25
- res = Typhoeus::Request.get(req_url, req_options).body
26
- res = JSON.parse(res, symbolize_names: true)
27
- end
28
- end
29
- end
@@ -1,63 +0,0 @@
1
- {
2
- "currency": "PHP",
3
- "total": "1750.00",
4
- "payment_method": "cod",
5
- "status" : "for_pickup",
6
- "payment_provider": "lbcx",
7
- "shipment": "box",
8
- "service": "next_day",
9
- "buyer_name": "Thea Lizardo",
10
- "buyer_id": "12345",
11
- "parcel": {
12
- "dimensions": {
13
- "uom": "cm",
14
- "length": 22,
15
- "width": 22,
16
- "height": 22
17
- },
18
- "weight": {
19
- "uom": "kg",
20
- "value": "22"
21
- }
22
- },
23
- "metadata": {"key_1":"value_1","key_2":"value_2"},
24
- "pickup_address": {
25
- "name": "Thea Lizardo",
26
- "company": "xpanse",
27
- "phone_number": "",
28
- "mobile_number": "+639171234567",
29
- "line_1": "Payless Warehouse",
30
- "line_2": "",
31
- "city": "Paranaque City",
32
- "state": "Metro Manila",
33
- "postal_code": "1634",
34
- "country": "PH",
35
- "remarks": "Optional notes / remarks go here."
36
- },
37
- "delivery_address": {
38
- "name": "Thea Lizardo",
39
- "company": "",
40
- "phone_number": "",
41
- "mobile_number": "+639171234567",
42
- "line_1": "Payless Warehouse",
43
- "line_2": "",
44
- "city": "Paranaque City",
45
- "state": "Metro Manila",
46
- "postal_code": "1634",
47
- "country": "PH",
48
- "remarks": "Optional notes / remarks go here."
49
- },
50
- "preferred_pickup_time": "morning",
51
- "preferred_delivery_time": "3pm - 5pm",
52
- "email": "thealizardo@gmail.com",
53
- "contact_number": "+639176788488",
54
- "items": [
55
- {
56
- "type": "product",
57
- "description": "Women's Abby Pointed Sling",
58
- "amount": 1750,
59
- "quantity": 1,
60
- "metadata": {"size":"7","color":"Floral", "width": "Regular", "sku":"FSRI-174290070"}
61
- }
62
- ]
63
- }
@@ -1,317 +0,0 @@
1
- {
2
- "id": 789566,
3
- "party_id": 6191,
4
- "service_id": 6191,
5
- "currency": "PHP",
6
- "reference_id": "2309174223312",
7
- "tracking_number": "0078-9566-ABLV",
8
- "payment_method": "cod",
9
- "payment_provider": "lbcx",
10
- "service": "next_day",
11
- "status": "confirmed",
12
- "status_updated_at": "2018-08-13 11:55:20.723494+00",
13
- "buyer_name": "Thea Lizardo",
14
- "email": "thealizardo@gmail.com",
15
- "contact_number": "+639176788488",
16
- "subtotal": "1750.00",
17
- "tax": "0.00",
18
- "fee": "0.00",
19
- "insurance": "0.00",
20
- "discount": "0.00",
21
- "shipping": "0.00",
22
- "total": "1750.00",
23
- "transaction_fee": "61.25",
24
- "insurance_fee": "17.50",
25
- "shipping_fee": "240.00",
26
- "metadata": {
27
- "key_1": "value_1",
28
- "key_2": "value_2"
29
- },
30
- "preferred_pickup_time": "morning",
31
- "preferred_delivery_time": "3pm - 5pm",
32
- "created_at": "2018-08-13 11:52:15+00",
33
- "tat": {
34
- "confirmed": 1534161320,
35
- "for_pickup": 1534161135
36
- },
37
- "shipment": "box",
38
- "remarks": null,
39
- "buyer_id": "12345",
40
- "parcel": {
41
- "weight": {
42
- "uom": "kg",
43
- "value": "4"
44
- },
45
- "dimensions": {
46
- "uom": "cm",
47
- "width": 22,
48
- "height": 22,
49
- "length": 22
50
- }
51
- },
52
- "updated_at": "2018-08-13 11:55:20.723494+00",
53
- "client": "Xpanse",
54
- "organization": {
55
- "party_id": 6191,
56
- "name": "Xpanse",
57
- "external_id": null
58
- },
59
- "pickup_address": {
60
- "id": 1600969,
61
- "code": null,
62
- "name": "Thea Lizardo",
63
- "title": null,
64
- "email": null,
65
- "phone_number": "",
66
- "mobile_number": "+639171234567",
67
- "fax_number": null,
68
- "company": "xpanse",
69
- "line_1": "Payless Warehouse",
70
- "line_2": "",
71
- "district": null,
72
- "city": "Paranaque City",
73
- "state": "Metro Manila",
74
- "postal_code": "1634",
75
- "region": "Mmb",
76
- "country": {
77
- "code": "PH",
78
- "name": "Philippines"
79
- },
80
- "city_approximation": "Paranaque City",
81
- "branch_code": null
82
- },
83
- "delivery_address": {
84
- "id": 1600609,
85
- "code": null,
86
- "name": "Thea Lizardo",
87
- "title": null,
88
- "email": null,
89
- "phone_number": "",
90
- "mobile_number": "+639171234567",
91
- "fax_number": null,
92
- "company": "",
93
- "line_1": "Payless Warehouse",
94
- "line_2": "",
95
- "district": null,
96
- "city": "Paranaque City",
97
- "state": "Metro Manila",
98
- "postal_code": "1634",
99
- "region": "Mmb",
100
- "country": {
101
- "code": "PH",
102
- "name": "Philippines"
103
- },
104
- "city_approximation": "Paranaque City"
105
- },
106
- "return_address": {
107
- "id": null,
108
- "code": null,
109
- "name": null,
110
- "title": null,
111
- "email": null,
112
- "phone_number": null,
113
- "mobile_number": null,
114
- "fax_number": null,
115
- "company": null,
116
- "line_1": null,
117
- "line_2": null,
118
- "district": null,
119
- "city": null,
120
- "state": null,
121
- "postal_code": null,
122
- "region": null,
123
- "country": {
124
- "code": null,
125
- "name": null
126
- }
127
- },
128
- "dropoff_address": {
129
- "id": null,
130
- "code": null,
131
- "name": null,
132
- "title": null,
133
- "email": null,
134
- "phone_number": null,
135
- "mobile_number": null,
136
- "fax_number": null,
137
- "company": null,
138
- "line_1": null,
139
- "line_2": null,
140
- "district": null,
141
- "city": null,
142
- "state": null,
143
- "postal_code": null,
144
- "region": null,
145
- "country": {
146
- "code": null,
147
- "name": null
148
- }
149
- },
150
- "charge": {
151
- "order_id": 789566,
152
- "status": "pending",
153
- "reference_id": "71001373530487",
154
- "total_amount": "1750.00",
155
- "tendered_amount": "0.00",
156
- "change_amount": "0.00",
157
- "remarks": null,
158
- "created_at": "2018-08-13 11:52:15+00",
159
- "updated_at": "2018-08-13 11:52:16+00"
160
- },
161
- "claim": {
162
- "status": null,
163
- "amount": null,
164
- "shipping_fee_flag": null,
165
- "insurance_fee_flag": null,
166
- "transaction_fee_flag": null,
167
- "assets": null,
168
- "reason": null,
169
- "remarks": null,
170
- "created_at": null,
171
- "updated_at": null,
172
- "tat": null,
173
- "reference_id": null
174
- },
175
- "buyer_name_parsed": {
176
- "first_name": "Thea Lizardo",
177
- "middle_name": null,
178
- "last_name": null
179
- },
180
- "items": [
181
- {
182
- "type": "product",
183
- "description": "Women's Abby Pointed Sling",
184
- "amount": "1750.00",
185
- "quantity": 1,
186
- "total": "1750.00",
187
- "metadata": {
188
- "sku": "FSRI-174290070",
189
- "size": "7",
190
- "color": "Floral",
191
- "width": "Regular"
192
- },
193
- "insured_value": null
194
- }
195
- ],
196
- "segments": [
197
- {
198
- "courier": "South Hub",
199
- "type": "pick_up",
200
- "barcode_format": "qr",
201
- "tat": {
202
- "end_date": null,
203
- "start_date": null
204
- },
205
- "shipping_type": "land",
206
- "currency": null,
207
- "amount": null,
208
- "reference_id": "0078-9566-ABLV",
209
- "active": true,
210
- "pickup_address": {
211
- "name": "Thea Lizardo",
212
- "title": null,
213
- "email": null,
214
- "phone_number": "",
215
- "mobile_number": "+639171234567",
216
- "fax_number": null,
217
- "company": "xpanse",
218
- "line_1": "Payless Warehouse",
219
- "line_2": "",
220
- "district": null,
221
- "city": "Paranaque City",
222
- "state": "Metro Manila",
223
- "postal_code": "1634",
224
- "region": "Mmb",
225
- "country": {
226
- "code": "PH",
227
- "name": "Philippines"
228
- }
229
- },
230
- "delivery_address": {
231
- "name": "South Hub",
232
- "title": null,
233
- "email": null,
234
- "phone_number": null,
235
- "mobile_number": null,
236
- "fax_number": null,
237
- "company": null,
238
- "line_1": "",
239
- "line_2": null,
240
- "district": "",
241
- "city": "Manila City",
242
- "state": "Metro Manila",
243
- "postal_code": "",
244
- "region": "MMB",
245
- "country": {
246
- "code": "PH",
247
- "name": "Philippines"
248
- }
249
- }
250
- },
251
- {
252
- "courier": "South Hub",
253
- "type": "delivery",
254
- "barcode_format": "qr",
255
- "tat": {
256
- "end_date": null,
257
- "start_date": null
258
- },
259
- "shipping_type": "land",
260
- "currency": null,
261
- "amount": null,
262
- "reference_id": "71001373530487",
263
- "active": false,
264
- "pickup_address": {
265
- "name": "South Hub",
266
- "title": null,
267
- "email": null,
268
- "phone_number": null,
269
- "mobile_number": null,
270
- "fax_number": null,
271
- "company": null,
272
- "line_1": "",
273
- "line_2": null,
274
- "district": "",
275
- "city": "Manila City",
276
- "state": "Metro Manila",
277
- "postal_code": "",
278
- "region": "MMB",
279
- "country": {
280
- "code": "PH",
281
- "name": "Philippines"
282
- }
283
- },
284
- "delivery_address": {
285
- "name": "Thea Lizardo",
286
- "title": null,
287
- "email": null,
288
- "phone_number": "",
289
- "mobile_number": "+639171234567",
290
- "fax_number": null,
291
- "company": "",
292
- "line_1": "Payless Warehouse",
293
- "line_2": "",
294
- "district": null,
295
- "city": "Paranaque City",
296
- "state": "Metro Manila",
297
- "postal_code": "1634",
298
- "region": "Mmb",
299
- "country": {
300
- "code": "PH",
301
- "name": "Philippines"
302
- }
303
- }
304
- }
305
- ],
306
- "events": [
307
- {
308
- "id": 2197070,
309
- "status": "confirmed",
310
- "created_at": "2018-08-13 11:55:20.723494+00",
311
- "remarks": null,
312
- "status_updated_at": "2018-08-13 11:55:20.723494+00",
313
- "status_name": "Confirmed"
314
- }
315
- ],
316
- "children": []
317
- }