shopify_api 4.13.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef057d0e70073f7c63a076b7f878c1c3afd062d0
4
- data.tar.gz: 477cf304d0a68dc7e68cfac7e39c9af5617611c5
3
+ metadata.gz: 55a5fb52fc6aa176717a301e7a52d015b54a7128
4
+ data.tar.gz: 7318df185fd7cfe2272a3b5078900beea9831eb4
5
5
  SHA512:
6
- metadata.gz: c24fa3742f763e0f798a4e2d0eccd37ff2db06ba21e08e09d5853584550398db112354f39b9fd6edc55af2cc8e438f5d04b8e3ade7e704c81e2eda2a8236338f
7
- data.tar.gz: 9886ecfff88b5b9e7dac1e1e1948fbe3ea3a0c69cbc9f13f601c413dead928bdfc68678f81d06ad74f277631f8048628252f390a37717bf17d9c1b6c4c3e016b
6
+ metadata.gz: 8b0eeef0481961159424da00239ac3f9bfbc4709ccc169f592bdd4a385c15ea27a1efe2cd083737c5a36a13d2be8a6687cd5b44b4ad0d69903a1cbcf34440414
7
+ data.tar.gz: 2b0c63f6db528a3c721c2ddf9e30ed5e79976e8570c0ec7a9f03bfde173c90230e5af3979b16f7a49a001ab9ce90ad4d68920d03e291487340215506c9d70653
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ == Version 5.0.0
2
+
3
+ * Added `ShopifyAPI::AbandonedCheckout`
4
+ * Added support for X-Shopify-Checkout-Version header on `ShopifyAPI::Checkout`
5
+ * Added `ShopifyAPI::ShippingRate`
6
+ * Added support for Checkout::complete endpoint
7
+
1
8
  == Version 4.12.0
2
9
 
3
10
  * Added support for the GraphQL API
data/README.md CHANGED
@@ -10,6 +10,13 @@ The Shopify API gem allows Ruby developers to programmatically access the admin
10
10
 
11
11
  The API is implemented as JSON over HTTP using all four verbs (GET/POST/PUT/DELETE). Each resource, like Order, Product, or Collection, has its own URL and is manipulated in isolation. In other words, we’ve tried to make the API follow the REST principles as much as possible.
12
12
 
13
+ ## ⚠️ Breaking change notice for version 5.0.0 ⚠️
14
+ The [Abandoned Checkout API](https://help.shopify.com/en/api/reference/orders/abandoned_checkouts) is now accessed through the `ShopifyAPI::AbandonedCheckout` resource. If you were previously accessing the Abandoned Checkout API through the `ShopifyAPI::Checkout` resource, you will need to update your code after upgrading from version 4.x.x or earlier.
15
+
16
+ Going forward, the `ShopifyAPI::Checkout` resource is used to access the [Checkout API](https://help.shopify.com/en/api/reference/sales_channels/checkout), which can be used to create new checkouts.
17
+
18
+ For more details, [please see this issue](https://github.com/Shopify/shopify_api/issues/471).
19
+
13
20
  ## Usage
14
21
 
15
22
  ### Requirements
@@ -262,9 +269,8 @@ bundle exec rake test
262
269
 
263
270
  ## Additional Resources
264
271
 
265
- API Reference: https://help.shopify.com/api/reference
266
-
267
- Ask questions on the forums: http://ecommerce.shopify.com/c/shopify-apis-and-technology
272
+ * [API Reference](https://help.shopify.com/api/reference)
273
+ * [Ask questions on the forums](http://ecommerce.shopify.com/c/shopify-apis-and-technology)
268
274
 
269
275
  ## Copyright
270
276
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShopifyAPI
4
+ class AbandonedCheckout < Base
5
+ self.element_name = "checkout"
6
+ end
7
+ end
@@ -1,4 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ShopifyAPI
2
4
  class Checkout < Base
5
+ self.primary_key = :token
6
+ headers['X-Shopify-Checkout-Version'] = '2016-09-06'
7
+
8
+ def complete
9
+ post(:complete)
10
+ end
11
+
12
+ def ready?
13
+ return false unless persisted?
14
+
15
+ reload
16
+ [200, 201].include?(ShopifyAPI::Base.connection.response.code.to_i)
17
+ end
18
+
19
+ def payments
20
+ Payment.find(:all, params: { checkout_id: id })
21
+ end
22
+
23
+ def shipping_rates
24
+ ShippingRate.find(:all, params: { checkout_id: id })
25
+ end
3
26
  end
4
- end
27
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShopifyAPI
4
+ class Payment < Base
5
+ self.prefix = '/admin/checkouts/:checkout_id/'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShopifyAPI
4
+ class ShippingRate < Base
5
+ self.prefix = '/admin/checkouts/:checkout_id/'
6
+ end
7
+ end
@@ -51,7 +51,7 @@ module ShopifyAPI
51
51
  end
52
52
 
53
53
  def validate_signature(params)
54
- params = params.with_indifferent_access
54
+ params = (params.respond_to?(:to_unsafe_hash) ? params.to_unsafe_hash : params).with_indifferent_access
55
55
  return false unless signature = params[:hmac]
56
56
 
57
57
  calculated_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new(), secret, encoded_params_for_signature(params))
@@ -1,3 +1,3 @@
1
1
  module ShopifyAPI
2
- VERSION = "4.13.0"
2
+ VERSION = "5.0.0"
3
3
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class AbandonedCheckoutsTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+
8
+ @expected_checkouts = JSON.parse(load_fixture('abandoned_checkouts'))['checkouts']
9
+ @expected_checkout_id = JSON.parse(load_fixture('abandoned_checkout'))['checkout']['id']
10
+ end
11
+
12
+ test ":create creates a checkout" do
13
+ fake 'checkouts', method: :post, status: 201, body: load_fixture('abandoned_checkout')
14
+
15
+ checkout = ShopifyAPI::AbandonedCheckout.create
16
+
17
+ assert_equal @expected_checkout_id, checkout.id
18
+ assert_equal true, checkout.attributes.include?(:abandoned_checkout_url)
19
+ end
20
+
21
+ test "get all checkouts indexed by token" do
22
+ fake 'checkouts', method: :get, status: 200, body: load_fixture('abandoned_checkouts')
23
+
24
+ checkouts = ShopifyAPI::AbandonedCheckout.all
25
+
26
+ assert_equal @expected_checkout_id, checkouts.first.id
27
+ assert_equal @expected_checkouts.size, checkouts.size
28
+ end
29
+ end
@@ -1,9 +1,72 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class CheckoutsTest < Test::Unit::TestCase
4
- test "get all should get all orders" do
5
- fake 'checkouts', :method => :get, :status => 200, :body => load_fixture('checkouts')
6
- checkout = ShopifyAPI::Checkout.all
7
- assert_equal 450789469, checkout.first.id
5
+ def setup
6
+ super
7
+
8
+ @expected_checkouts = JSON.parse(load_fixture('checkouts'))['checkouts']
9
+ @expected_checkout_id = JSON.parse(load_fixture('checkout'))['checkout']['token']
10
+ end
11
+
12
+ test ":create creates a checkout" do
13
+ fake 'checkouts', method: :post, status: 201, body: load_fixture('checkout')
14
+
15
+ checkout = ShopifyAPI::Checkout.create
16
+
17
+ assert_equal @expected_checkout_id, checkout.id
18
+ end
19
+
20
+ test "get all checkouts indexed by token" do
21
+ fake 'checkouts', method: :get, status: 200, body: load_fixture('checkouts')
22
+
23
+ checkouts = ShopifyAPI::Checkout.all
24
+
25
+ assert_equal @expected_checkout_id, checkouts.first.id
26
+ assert_equal @expected_checkouts.size, checkouts.size
27
+ end
28
+
29
+ test ":complete completes a checkout" do
30
+ fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
31
+
32
+ checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
33
+
34
+ fake "checkouts/#{@expected_checkout_id}/complete", method: :post, status: 200, body: load_fixture('checkouts')
35
+
36
+ checkout.complete
37
+ end
38
+
39
+ test ":ready? returns true when status is 201" do
40
+ fake "checkouts/#{@expected_checkout_id}", method: :get, status: 201, body: load_fixture('checkout')
41
+ checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
42
+
43
+ assert_predicate checkout, :ready?
44
+ end
45
+
46
+ test ":ready? returns false when status is 202" do
47
+ fake "checkouts/#{@expected_checkout_id}", method: :get, status: 202, body: load_fixture('checkout')
48
+ checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
49
+
50
+ refute_predicate checkout, :ready?
51
+ end
52
+
53
+ test ":payments returns payments for a checkout" do
54
+ fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
55
+ checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
56
+
57
+ fake "checkouts/#{@expected_checkout_id}/payments", method: :get, status: 202, body: load_fixture('payments')
58
+
59
+ assert_equal 10.00, checkout.payments.first.amount
60
+ end
61
+
62
+ test ":shipping_rates returns shipping rates for a checkout" do
63
+ fake "checkouts/#{@expected_checkout_id}", method: :get, status: 200, body: load_fixture('checkout')
64
+ checkout = ShopifyAPI::Checkout.find(@expected_checkout_id)
65
+
66
+ fake("checkouts/#{@expected_checkout_id}/shipping_rates",
67
+ method: :get,
68
+ status: 202,
69
+ body: load_fixture('shipping_rates'))
70
+ assert_equal "canada_post-INT.TP.BOGUS-4.00", checkout.shipping_rates.first.id
8
71
  end
9
72
  end
@@ -8,6 +8,7 @@ class LogSubscriberTest < Test::Unit::TestCase
8
8
  super
9
9
  @page = { :page => { :id => 1, :title => 'Shopify API' } }.to_json
10
10
  @ua_header = "\"User-Agent\"=>\"ShopifyAPI/#{ShopifyAPI::VERSION} ActiveResource/#{ActiveResource::VERSION::STRING} Ruby/#{RUBY_VERSION}\""
11
+ @ver_header = "\"X-Shopify-Checkout-Version\"=>\"2016-09-06\""
11
12
 
12
13
  ShopifyAPI::Base.clear_session
13
14
  ShopifyAPI::Base.site = "https://this-is-my-test-shop.myshopify.com/admin"
@@ -28,7 +29,7 @@ class LogSubscriberTest < Test::Unit::TestCase
28
29
  assert_equal 4, @logger.logged(:info).size
29
30
  assert_equal "GET https://this-is-my-test-shop.myshopify.com:443/admin/pages/1.json", @logger.logged(:info)[0]
30
31
  assert_match /\-\-\> 200/, @logger.logged(:info)[1]
31
- assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}}", @logger.logged(:info)[2]
32
+ assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}, #{@ver_header}}", @logger.logged(:info)[2]
32
33
  assert_match /Response:\n\{\"page\"\:\{((\"id\"\:1)|(\"title\"\:\"Shopify API\")),((\"id\"\:1)|(\"title\"\:\"Shopify API\"))\}\}/, @logger.logged(:info)[3]
33
34
 
34
35
  end
@@ -43,7 +44,7 @@ class LogSubscriberTest < Test::Unit::TestCase
43
44
  assert_equal 4, @logger.logged(:info).size
44
45
  assert_equal "GET https://this-is-my-test-shop.myshopify.com:443/admin/pages/2.json", @logger.logged(:info)[0]
45
46
  assert_match /\-\-\> 404/, @logger.logged(:info)[1]
46
- assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}}", @logger.logged(:info)[2]
47
+ assert_equal "Headers: {\"Accept\"=>\"application/json\", #{@ua_header}, #{@ver_header}}", @logger.logged(:info)[2]
47
48
  assert_equal "Response:", @logger.logged(:info)[3]
48
49
  end
49
50
  end
@@ -0,0 +1,184 @@
1
+ {
2
+ "checkout": {
3
+ "buyer_accepts_marketing": false,
4
+ "cart_token": "68778783ad298f1c80c3bafcddeea02f",
5
+ "closed_at": null,
6
+ "completed_at": null,
7
+ "created_at": "2012-10-12T07:05:27-04:00",
8
+ "currency": "USD",
9
+ "email": "bob.norman@hostmail.com",
10
+ "gateway": null,
11
+ "id": 450789469,
12
+ "landing_site": null,
13
+ "note": null,
14
+ "referring_site": null,
15
+ "shipping_lines": [
16
+ {
17
+ "title": "Free Shipping",
18
+ "price": "0.00",
19
+ "code": "Free Shipping",
20
+ "source": "shopify"
21
+ }
22
+ ],
23
+ "source": null,
24
+ "source_identifier": null,
25
+ "source_name": "web",
26
+ "source_url": null,
27
+ "subtotal_price": "398.00",
28
+ "taxes_included": false,
29
+ "token": "2a1ace52255252df566af0faaedfbfa7",
30
+ "total_discounts": "0.00",
31
+ "total_line_items_price": "398.00",
32
+ "total_price": "409.94",
33
+ "total_tax": "11.94",
34
+ "total_weight": 400,
35
+ "updated_at": "2012-10-12T07:05:27-04:00",
36
+ "line_items": [
37
+ {
38
+ "applied_discounts": [
39
+
40
+ ],
41
+ "compare_at_price": null,
42
+ "fulfillment_service": "manual",
43
+ "gift_card": false,
44
+ "grams": 200,
45
+ "id": 49148385,
46
+ "line_price": "199.00",
47
+ "price": "199.00",
48
+ "product_id": 632910392,
49
+ "properties": null,
50
+ "quantity": 1,
51
+ "requires_shipping": true,
52
+ "sku": "IPOD2008RED",
53
+ "tax_lines": [
54
+
55
+ ],
56
+ "taxable": true,
57
+ "title": "IPod Nano - 8GB",
58
+ "variant_id": 49148385,
59
+ "variant_title": "Red",
60
+ "vendor": "Apple"
61
+ },
62
+ {
63
+ "applied_discounts": [
64
+
65
+ ],
66
+ "compare_at_price": null,
67
+ "fulfillment_service": "manual",
68
+ "gift_card": false,
69
+ "grams": 200,
70
+ "id": 808950810,
71
+ "line_price": "199.00",
72
+ "price": "199.00",
73
+ "product_id": 632910392,
74
+ "properties": null,
75
+ "quantity": 1,
76
+ "requires_shipping": true,
77
+ "sku": "IPOD2008PINK",
78
+ "tax_lines": [
79
+
80
+ ],
81
+ "taxable": true,
82
+ "title": "IPod Nano - 8GB",
83
+ "variant_id": 808950810,
84
+ "variant_title": "Pink",
85
+ "vendor": "Apple"
86
+ }
87
+ ],
88
+ "name": "#450789469",
89
+ "note_attributes": [
90
+ {
91
+ "name": "custom engraving",
92
+ "value": "Happy Birthday"
93
+ },
94
+ {
95
+ "name": "colour",
96
+ "value": "green"
97
+ }
98
+ ],
99
+ "discount_codes": [
100
+ {
101
+ "code": "TENOFF",
102
+ "amount": "10.00"
103
+ }
104
+ ],
105
+ "abandoned_checkout_url": "https://checkout.local/orders/690933842/2a1ace52255252df566af0faaedfbfa7?recovered=1",
106
+ "tax_lines": [
107
+ {
108
+ "price": "11.94",
109
+ "rate": 0.06,
110
+ "title": "State Tax"
111
+ }
112
+ ],
113
+ "billing_address": {
114
+ "address1": "Chestnut Street 92",
115
+ "address2": "",
116
+ "city": "Louisville",
117
+ "company": null,
118
+ "country": "United States",
119
+ "first_name": "Bob",
120
+ "last_name": "Norman",
121
+ "latitude": "45.41634",
122
+ "longitude": "-75.6868",
123
+ "phone": "555-625-1199",
124
+ "province": "Kentucky",
125
+ "zip": "40202",
126
+ "name": "Bob Norman",
127
+ "country_code": "US",
128
+ "province_code": "KY"
129
+ },
130
+ "shipping_address": {
131
+ "address1": "Chestnut Street 92",
132
+ "address2": "",
133
+ "city": "Louisville",
134
+ "company": null,
135
+ "country": "United States",
136
+ "first_name": "Bob",
137
+ "last_name": "Norman",
138
+ "latitude": "45.41634",
139
+ "longitude": "-75.6868",
140
+ "phone": "555-625-1199",
141
+ "province": "Kentucky",
142
+ "zip": "40202",
143
+ "name": "Bob Norman",
144
+ "country_code": "US",
145
+ "province_code": "KY"
146
+ },
147
+ "customer": {
148
+ "accepts_marketing": false,
149
+ "created_at": "2014-03-07T16:12:37-05:00",
150
+ "email": "bob.norman@hostmail.com",
151
+ "first_name": "Bob",
152
+ "id": 207119551,
153
+ "last_name": "Norman",
154
+ "last_order_id": null,
155
+ "multipass_identifier": null,
156
+ "note": null,
157
+ "orders_count": 0,
158
+ "state": "disabled",
159
+ "total_spent": "0.00",
160
+ "updated_at": "2014-03-07T16:12:37-05:00",
161
+ "verified_email": true,
162
+ "tags": "",
163
+ "last_order_name": null,
164
+ "default_address": {
165
+ "address1": "Chestnut Street 92",
166
+ "address2": "",
167
+ "city": "Louisville",
168
+ "company": null,
169
+ "country": "United States",
170
+ "first_name": null,
171
+ "id": 207119551,
172
+ "last_name": null,
173
+ "phone": "555-625-1199",
174
+ "province": "Kentucky",
175
+ "zip": "40202",
176
+ "name": null,
177
+ "province_code": "KY",
178
+ "country_code": "US",
179
+ "country_name": "United States",
180
+ "default": true
181
+ }
182
+ }
183
+ }
184
+ }
@@ -0,0 +1,186 @@
1
+ {
2
+ "checkouts": [
3
+ {
4
+ "buyer_accepts_marketing": false,
5
+ "cart_token": "68778783ad298f1c80c3bafcddeea02f",
6
+ "closed_at": null,
7
+ "completed_at": null,
8
+ "created_at": "2012-10-12T07:05:27-04:00",
9
+ "currency": "USD",
10
+ "email": "bob.norman@hostmail.com",
11
+ "gateway": null,
12
+ "id": 450789469,
13
+ "landing_site": null,
14
+ "note": null,
15
+ "referring_site": null,
16
+ "shipping_lines": [
17
+ {
18
+ "title": "Free Shipping",
19
+ "price": "0.00",
20
+ "code": "Free Shipping",
21
+ "source": "shopify"
22
+ }
23
+ ],
24
+ "source": null,
25
+ "source_identifier": null,
26
+ "source_name": "web",
27
+ "source_url": null,
28
+ "subtotal_price": "398.00",
29
+ "taxes_included": false,
30
+ "token": "2a1ace52255252df566af0faaedfbfa7",
31
+ "total_discounts": "0.00",
32
+ "total_line_items_price": "398.00",
33
+ "total_price": "409.94",
34
+ "total_tax": "11.94",
35
+ "total_weight": 400,
36
+ "updated_at": "2012-10-12T07:05:27-04:00",
37
+ "line_items": [
38
+ {
39
+ "applied_discounts": [
40
+
41
+ ],
42
+ "compare_at_price": null,
43
+ "fulfillment_service": "manual",
44
+ "gift_card": false,
45
+ "grams": 200,
46
+ "id": 49148385,
47
+ "line_price": "199.00",
48
+ "price": "199.00",
49
+ "product_id": 632910392,
50
+ "properties": null,
51
+ "quantity": 1,
52
+ "requires_shipping": true,
53
+ "sku": "IPOD2008RED",
54
+ "tax_lines": [
55
+
56
+ ],
57
+ "taxable": true,
58
+ "title": "IPod Nano - 8GB",
59
+ "variant_id": 49148385,
60
+ "variant_title": "Red",
61
+ "vendor": "Apple"
62
+ },
63
+ {
64
+ "applied_discounts": [
65
+
66
+ ],
67
+ "compare_at_price": null,
68
+ "fulfillment_service": "manual",
69
+ "gift_card": false,
70
+ "grams": 200,
71
+ "id": 808950810,
72
+ "line_price": "199.00",
73
+ "price": "199.00",
74
+ "product_id": 632910392,
75
+ "properties": null,
76
+ "quantity": 1,
77
+ "requires_shipping": true,
78
+ "sku": "IPOD2008PINK",
79
+ "tax_lines": [
80
+
81
+ ],
82
+ "taxable": true,
83
+ "title": "IPod Nano - 8GB",
84
+ "variant_id": 808950810,
85
+ "variant_title": "Pink",
86
+ "vendor": "Apple"
87
+ }
88
+ ],
89
+ "name": "#450789469",
90
+ "note_attributes": [
91
+ {
92
+ "name": "custom engraving",
93
+ "value": "Happy Birthday"
94
+ },
95
+ {
96
+ "name": "colour",
97
+ "value": "green"
98
+ }
99
+ ],
100
+ "discount_codes": [
101
+ {
102
+ "code": "TENOFF",
103
+ "amount": "10.00"
104
+ }
105
+ ],
106
+ "abandoned_checkout_url": "https://checkout.local/orders/690933842/2a1ace52255252df566af0faaedfbfa7?recovered=1",
107
+ "tax_lines": [
108
+ {
109
+ "price": "11.94",
110
+ "rate": 0.06,
111
+ "title": "State Tax"
112
+ }
113
+ ],
114
+ "billing_address": {
115
+ "address1": "Chestnut Street 92",
116
+ "address2": "",
117
+ "city": "Louisville",
118
+ "company": null,
119
+ "country": "United States",
120
+ "first_name": "Bob",
121
+ "last_name": "Norman",
122
+ "latitude": "45.41634",
123
+ "longitude": "-75.6868",
124
+ "phone": "555-625-1199",
125
+ "province": "Kentucky",
126
+ "zip": "40202",
127
+ "name": "Bob Norman",
128
+ "country_code": "US",
129
+ "province_code": "KY"
130
+ },
131
+ "shipping_address": {
132
+ "address1": "Chestnut Street 92",
133
+ "address2": "",
134
+ "city": "Louisville",
135
+ "company": null,
136
+ "country": "United States",
137
+ "first_name": "Bob",
138
+ "last_name": "Norman",
139
+ "latitude": "45.41634",
140
+ "longitude": "-75.6868",
141
+ "phone": "555-625-1199",
142
+ "province": "Kentucky",
143
+ "zip": "40202",
144
+ "name": "Bob Norman",
145
+ "country_code": "US",
146
+ "province_code": "KY"
147
+ },
148
+ "customer": {
149
+ "accepts_marketing": false,
150
+ "created_at": "2014-03-07T16:12:37-05:00",
151
+ "email": "bob.norman@hostmail.com",
152
+ "first_name": "Bob",
153
+ "id": 207119551,
154
+ "last_name": "Norman",
155
+ "last_order_id": null,
156
+ "multipass_identifier": null,
157
+ "note": null,
158
+ "orders_count": 0,
159
+ "state": "disabled",
160
+ "total_spent": "0.00",
161
+ "updated_at": "2014-03-07T16:12:37-05:00",
162
+ "verified_email": true,
163
+ "tags": "",
164
+ "last_order_name": null,
165
+ "default_address": {
166
+ "address1": "Chestnut Street 92",
167
+ "address2": "",
168
+ "city": "Louisville",
169
+ "company": null,
170
+ "country": "United States",
171
+ "first_name": null,
172
+ "id": 207119551,
173
+ "last_name": null,
174
+ "phone": "555-625-1199",
175
+ "province": "Kentucky",
176
+ "zip": "40202",
177
+ "name": null,
178
+ "province_code": "KY",
179
+ "country_code": "US",
180
+ "country_name": "United States",
181
+ "default": true
182
+ }
183
+ }
184
+ }
185
+ ]
186
+ }
@@ -0,0 +1,160 @@
1
+ {
2
+ "checkout": {
3
+ "applied_discount": "0.00",
4
+ "clone_url": "",
5
+ "completed_at": null,
6
+ "created_at": "2012-10-12T07:05:27-04:00",
7
+ "credit_card": null,
8
+ "currency": "USD",
9
+ "presentment_currency": "USD",
10
+ "email": "bob.norman@hostmail.com",
11
+ "note": null,
12
+ "shipping_line": [
13
+ {
14
+ "title": "Free Shipping",
15
+ "price": "0.00",
16
+ "code": "Free Shipping",
17
+ "source": "shopify"
18
+ }
19
+ ],
20
+ "shipping_rates": [
21
+ {
22
+ "id": "canada_post-INT.TP.BOGUS-4.00",
23
+ "price": "4.00",
24
+ "title": "Small Packet International Air Bogus"
25
+ },
26
+ {
27
+ "id": "canada_post-INT.TP.BOGUS-8.00",
28
+ "price": "8.00",
29
+ "title": "Medium Packet International Air Bogus"
30
+ }
31
+ ],
32
+ "source_identifier": null,
33
+ "source_name": "web",
34
+ "source_url": null,
35
+ "subtotal_price": "398.00",
36
+ "shipping_policy_url": null,
37
+ "taxes_included": false,
38
+ "token": "2a1ace52255252df566af0faaedfbfa7",
39
+ "total_line_items_price": "398.00",
40
+ "total_price": "409.94",
41
+ "total_tax": "11.94",
42
+ "updated_at": "2012-10-12T07:05:27-04:00",
43
+ "line_items": [
44
+ {
45
+ "applied_discounts": [
46
+
47
+ ],
48
+ "compare_at_price": null,
49
+ "fulfillment_service": "manual",
50
+ "gift_card": false,
51
+ "grams": 200,
52
+ "id": 49148385,
53
+ "line_price": "199.00",
54
+ "price": "199.00",
55
+ "product_id": 632910392,
56
+ "properties": null,
57
+ "quantity": 1,
58
+ "requires_shipping": true,
59
+ "sku": "IPOD2008RED",
60
+ "tax_lines": [
61
+
62
+ ],
63
+ "taxable": true,
64
+ "title": "IPod Nano - 8GB",
65
+ "variant_id": 49148385,
66
+ "variant_title": "Red",
67
+ "vendor": "Apple"
68
+ },
69
+ {
70
+ "applied_discounts": [
71
+
72
+ ],
73
+ "compare_at_price": null,
74
+ "fulfillment_service": "manual",
75
+ "gift_card": false,
76
+ "grams": 200,
77
+ "id": 808950810,
78
+ "line_price": "199.00",
79
+ "price": "199.00",
80
+ "product_id": 632910392,
81
+ "properties": null,
82
+ "quantity": 1,
83
+ "requires_shipping": true,
84
+ "sku": "IPOD2008PINK",
85
+ "tax_lines": [
86
+
87
+ ],
88
+ "taxable": true,
89
+ "title": "IPod Nano - 8GB",
90
+ "variant_id": 808950810,
91
+ "variant_title": "Pink",
92
+ "vendor": "Apple"
93
+ }
94
+ ],
95
+ "name": "#450789469",
96
+ "note_attributes": [
97
+ {
98
+ "name": "custom engraving",
99
+ "value": "Happy Birthday"
100
+ },
101
+ {
102
+ "name": "colour",
103
+ "value": "green"
104
+ }
105
+ ],
106
+ "discount_code": [
107
+ {
108
+ "code": "TENOFF",
109
+ "amount": "10.00"
110
+ }
111
+ ],
112
+ "tax_lines": [
113
+ {
114
+ "price": "11.94",
115
+ "rate": 0.06,
116
+ "title": "State Tax"
117
+ }
118
+ ],
119
+ "billing_address": {
120
+ "address1": "Chestnut Street 92",
121
+ "address2": "",
122
+ "city": "Louisville",
123
+ "company": null,
124
+ "country": "United States",
125
+ "first_name": "Bob",
126
+ "last_name": "Norman",
127
+ "latitude": "45.41634",
128
+ "longitude": "-75.6868",
129
+ "phone": "555-625-1199",
130
+ "province": "Kentucky",
131
+ "zip": "40202",
132
+ "name": "Bob Norman",
133
+ "country_code": "US",
134
+ "province_code": "KY"
135
+ },
136
+ "shipping_address": {
137
+ "address1": "Chestnut Street 92",
138
+ "address2": "",
139
+ "city": "Louisville",
140
+ "company": null,
141
+ "country": "United States",
142
+ "first_name": "Bob",
143
+ "last_name": "Norman",
144
+ "latitude": "45.41634",
145
+ "longitude": "-75.6868",
146
+ "phone": "555-625-1199",
147
+ "province": "Kentucky",
148
+ "zip": "40202",
149
+ "name": "Bob Norman",
150
+ "country_code": "US",
151
+ "province_code": "KY"
152
+ },
153
+ "customer_id": null,
154
+ "customer_locale": "en-CA",
155
+ "device_id": "12",
156
+ "order": null,
157
+ "order_id": null,
158
+ "order_status_url": ""
159
+ }
160
+ }
@@ -1,19 +1,16 @@
1
1
  {
2
2
  "checkouts": [
3
3
  {
4
- "buyer_accepts_marketing": false,
5
- "cart_token": "68778783ad298f1c80c3bafcddeea02f",
6
- "closed_at": null,
4
+ "applied_discount": "0.00",
5
+ "clone_url": "",
7
6
  "completed_at": null,
8
7
  "created_at": "2012-10-12T07:05:27-04:00",
8
+ "credit_card": null,
9
9
  "currency": "USD",
10
+ "presentment_currency": "USD",
10
11
  "email": "bob.norman@hostmail.com",
11
- "gateway": null,
12
- "id": 450789469,
13
- "landing_site": null,
14
12
  "note": null,
15
- "referring_site": null,
16
- "shipping_lines": [
13
+ "shipping_line": [
17
14
  {
18
15
  "title": "Free Shipping",
19
16
  "price": "0.00",
@@ -21,18 +18,28 @@
21
18
  "source": "shopify"
22
19
  }
23
20
  ],
24
- "source": null,
21
+ "shipping_rates": [
22
+ {
23
+ "id": "canada_post-INT.TP.BOGUS-4.00",
24
+ "price": "4.00",
25
+ "title": "Small Packet International Air Bogus"
26
+ },
27
+ {
28
+ "id": "canada_post-INT.TP.BOGUS-8.00",
29
+ "price": "8.00",
30
+ "title": "Medium Packet International Air Bogus"
31
+ }
32
+ ],
25
33
  "source_identifier": null,
26
34
  "source_name": "web",
27
35
  "source_url": null,
28
36
  "subtotal_price": "398.00",
37
+ "shipping_policy_url": null,
29
38
  "taxes_included": false,
30
39
  "token": "2a1ace52255252df566af0faaedfbfa7",
31
- "total_discounts": "0.00",
32
40
  "total_line_items_price": "398.00",
33
41
  "total_price": "409.94",
34
42
  "total_tax": "11.94",
35
- "total_weight": 400,
36
43
  "updated_at": "2012-10-12T07:05:27-04:00",
37
44
  "line_items": [
38
45
  {
@@ -97,13 +104,12 @@
97
104
  "value": "green"
98
105
  }
99
106
  ],
100
- "discount_codes": [
107
+ "discount_code": [
101
108
  {
102
109
  "code": "TENOFF",
103
110
  "amount": "10.00"
104
111
  }
105
112
  ],
106
- "abandoned_checkout_url": "https://checkout.local/orders/690933842/2a1ace52255252df566af0faaedfbfa7?recovered=1",
107
113
  "tax_lines": [
108
114
  {
109
115
  "price": "11.94",
@@ -145,42 +151,12 @@
145
151
  "country_code": "US",
146
152
  "province_code": "KY"
147
153
  },
148
- "customer": {
149
- "accepts_marketing": false,
150
- "created_at": "2014-03-07T16:12:37-05:00",
151
- "email": "bob.norman@hostmail.com",
152
- "first_name": "Bob",
153
- "id": 207119551,
154
- "last_name": "Norman",
155
- "last_order_id": null,
156
- "multipass_identifier": null,
157
- "note": null,
158
- "orders_count": 0,
159
- "state": "disabled",
160
- "total_spent": "0.00",
161
- "updated_at": "2014-03-07T16:12:37-05:00",
162
- "verified_email": true,
163
- "tags": "",
164
- "last_order_name": null,
165
- "default_address": {
166
- "address1": "Chestnut Street 92",
167
- "address2": "",
168
- "city": "Louisville",
169
- "company": null,
170
- "country": "United States",
171
- "first_name": null,
172
- "id": 207119551,
173
- "last_name": null,
174
- "phone": "555-625-1199",
175
- "province": "Kentucky",
176
- "zip": "40202",
177
- "name": null,
178
- "province_code": "KY",
179
- "country_code": "US",
180
- "country_name": "United States",
181
- "default": true
182
- }
183
- }
154
+ "customer_id": null,
155
+ "customer_locale": "en-CA",
156
+ "device_id": "12",
157
+ "order": null,
158
+ "order_id": null,
159
+ "order_status_url": ""
184
160
  }
185
161
  ]
186
162
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "payment" : {
3
+ "amount": 10.00,
4
+ "session_id": "east-44a400ef20b36e38f10b882cb7260796",
5
+ "unique_token": "my-client-generated-idempotency-token"
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "payments" : [
3
+ {
4
+ "amount": 10.00,
5
+ "session_id": "east-44a400ef20b36e38f10b882cb7260796",
6
+ "unique_token": "my-client-generated-idempotency-token"
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "id": "canada_post-INT.TP.BOGUS-4.00",
4
+ "price": "4.00",
5
+ "title": "Small Packet International Air Bogus"
6
+ },
7
+ {
8
+ "id": "canada_post-INT.TP.BOGUS-8.00",
9
+ "price": "8.00",
10
+ "title": "Medium Packet International Air Bogus"
11
+ }
12
+ ]
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class PaymentTest < Test::Unit::TestCase
5
+ def setup
6
+ super
7
+
8
+ @checkout_id = JSON.parse(load_fixture('checkout'))['checkout']['token']
9
+ @expected_payment = JSON.parse(load_fixture('payment'))['payment']
10
+ end
11
+
12
+ test ":create creates a new payment" do
13
+ fake "checkouts/#{@checkout_id}/payments", method: :post, status: 201, body: load_fixture('payment')
14
+
15
+ new_payment = ShopifyAPI::Payment.create(checkout_id: @checkout_id)
16
+
17
+ assert_equal @expected_payment['unique_token'], new_payment.attributes['unique_token']
18
+ end
19
+ end
@@ -214,33 +214,33 @@ class SessionTest < Test::Unit::TestCase
214
214
  end
215
215
 
216
216
  test "return true when the signature is valid and the keys of params are strings" do
217
- params = {"code" => "any-code", "timestamp" => Time.now}
218
- params["hmac"] = generate_signature(params)
217
+ params = { 'code' => 'any-code', 'timestamp' => Time.now }
218
+ params[:hmac] = generate_signature(params)
219
219
  assert_equal true, ShopifyAPI::Session.validate_signature(params)
220
220
  end
221
221
 
222
222
  test "return true when validating signature of params with ampersand and equal sign characters" do
223
223
  ShopifyAPI::Session.secret = 'secret'
224
- params = {'a' => '1&b=2', 'c=3&d' => '4'}
225
- to_sign = "a=1%26b=2&c%3D3%26d=4"
226
- params['hmac'] = generate_signature(to_sign)
227
-
224
+ params = { 'a' => '1&b=2', 'c=3&d' => '4' }
225
+ to_sign = 'a=1%26b=2&c%3D3%26d=4'
226
+ params[:hmac] = generate_signature(to_sign)
228
227
  assert_equal true, ShopifyAPI::Session.validate_signature(params)
229
228
  end
230
229
 
231
230
  test "return true when validating signature of params with percent sign characters" do
232
231
  ShopifyAPI::Session.secret = 'secret'
233
- params = {'a%3D1%26b' => '2%26c%3D3'}
234
- to_sign = "a%253D1%2526b=2%2526c%253D3"
235
- params['hmac'] = generate_signature(to_sign)
236
-
232
+ params = { 'a%3D1%26b' => '2%26c%3D3' }
233
+ to_sign = 'a%253D1%2526b=2%2526c%253D3'
234
+ params[:hmac] = generate_signature(to_sign)
237
235
  assert_equal true, ShopifyAPI::Session.validate_signature(params)
238
236
  end
239
237
 
240
238
  private
241
239
 
242
240
  def make_sorted_params(params)
243
- sorted_params = params.with_indifferent_access.except(:signature, :hmac, :action, :controller).collect{|k,v|"#{k}=#{v}"}.sort.join('&')
241
+ params.with_indifferent_access.except(
242
+ :signature, :hmac, :action, :controller
243
+ ).collect { |k, v| "#{k}=#{v}" }.sort.join('&')
244
244
  end
245
245
 
246
246
  def generate_signature(params)
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class ShippingRateTest < Test::Unit::TestCase
6
+ test ":get lists all shipping rates for a given checkout" do
7
+ fake 'checkouts', method: :get, status: 200, body: load_fixture('checkouts')
8
+ checkouts = ShopifyAPI::Checkout.all
9
+
10
+ fake "checkouts/#{checkouts.first.id}/shipping_rates",
11
+ method: :get, status: 200, body: load_fixture('checkouts')
12
+ shipping_rates = ShopifyAPI::ShippingRate.find(:all, params: { checkout_id: checkouts.first.id })
13
+
14
+ assert_equal 2, shipping_rates.first.shipping_rates.length
15
+ assert_equal 'canada_post-INT.TP.BOGUS-4.00', shipping_rates.first.shipping_rates.first.id
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.13.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-30 00:00:00.000000000 Z
11
+ date: 2018-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -166,6 +166,7 @@ files:
166
166
  - lib/shopify_api/limits.rb
167
167
  - lib/shopify_api/metafields.rb
168
168
  - lib/shopify_api/resources.rb
169
+ - lib/shopify_api/resources/abandoned_checkout.rb
169
170
  - lib/shopify_api/resources/access_scope.rb
170
171
  - lib/shopify_api/resources/access_token.rb
171
172
  - lib/shopify_api/resources/address.rb
@@ -213,6 +214,7 @@ files:
213
214
  - lib/shopify_api/resources/order.rb
214
215
  - lib/shopify_api/resources/order_risk.rb
215
216
  - lib/shopify_api/resources/page.rb
217
+ - lib/shopify_api/resources/payment.rb
216
218
  - lib/shopify_api/resources/payment_details.rb
217
219
  - lib/shopify_api/resources/ping.rb
218
220
  - lib/shopify_api/resources/ping/conversation.rb
@@ -232,6 +234,7 @@ files:
232
234
  - lib/shopify_api/resources/script_tag.rb
233
235
  - lib/shopify_api/resources/shipping_address.rb
234
236
  - lib/shopify_api/resources/shipping_line.rb
237
+ - lib/shopify_api/resources/shipping_rate.rb
235
238
  - lib/shopify_api/resources/shipping_zone.rb
236
239
  - lib/shopify_api/resources/shop.rb
237
240
  - lib/shopify_api/resources/smart_collection.rb
@@ -248,6 +251,7 @@ files:
248
251
  - lib/shopify_api/version.rb
249
252
  - shipit.rubygems.yml
250
253
  - shopify_api.gemspec
254
+ - test/abandoned_checkouts_test.rb
251
255
  - test/access_token_test.rb
252
256
  - test/active_resource/json_errors_test.rb
253
257
  - test/api_permission_test.rb
@@ -269,6 +273,8 @@ files:
269
273
  - test/detailed_log_subscriber_test.rb
270
274
  - test/discount_code_test.rb
271
275
  - test/draft_order_test.rb
276
+ - test/fixtures/abandoned_checkout.json
277
+ - test/fixtures/abandoned_checkouts.json
272
278
  - test/fixtures/access_token_delegate.json
273
279
  - test/fixtures/application_charge.json
274
280
  - test/fixtures/application_charges.json
@@ -283,6 +289,7 @@ files:
283
289
  - test/fixtures/blogs.json
284
290
  - test/fixtures/carrier_service.json
285
291
  - test/fixtures/carts.json
292
+ - test/fixtures/checkout.json
286
293
  - test/fixtures/checkouts.json
287
294
  - test/fixtures/collect.json
288
295
  - test/fixtures/collection_listing.json
@@ -323,6 +330,8 @@ files:
323
330
  - test/fixtures/order_risks.json
324
331
  - test/fixtures/order_with_properties.json
325
332
  - test/fixtures/orders.json
333
+ - test/fixtures/payment.json
334
+ - test/fixtures/payments.json
326
335
  - test/fixtures/ping/conversation.json
327
336
  - test/fixtures/ping/message.json
328
337
  - test/fixtures/policies.json
@@ -341,6 +350,7 @@ files:
341
350
  - test/fixtures/reports.json
342
351
  - test/fixtures/script_tag.json
343
352
  - test/fixtures/script_tags.json
353
+ - test/fixtures/shipping_rates.json
344
354
  - test/fixtures/shipping_zones.json
345
355
  - test/fixtures/shop.json
346
356
  - test/fixtures/smart_collection.json
@@ -371,6 +381,7 @@ files:
371
381
  - test/o_auth_test.rb
372
382
  - test/order_risk_test.rb
373
383
  - test/order_test.rb
384
+ - test/payment_test.rb
374
385
  - test/ping/conversation_test.rb
375
386
  - test/policy_test.rb
376
387
  - test/price_rule_test.rb
@@ -383,6 +394,7 @@ files:
383
394
  - test/resource_feedback_test.rb
384
395
  - test/script_tag_test.rb
385
396
  - test/session_test.rb
397
+ - test/shipping_rate_test.rb
386
398
  - test/shipping_zone_test.rb
387
399
  - test/shop_test.rb
388
400
  - test/smart_collection_test.rb