shoppe-easypost 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/locales/en.yml +12 -0
- data/lib/shoppe/easypost.rb +42 -4
- data/lib/shoppe/easypost/engine.rb +4 -1
- data/lib/shoppe/easypost/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71894acc752c63b9406e211a34567193821f9f58
|
4
|
+
data.tar.gz: 2bc77b9845cebd6933e7514f828629e0d8291cba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a8e52bba6ef26f699525152a39c0649f8d26b9a08cd2d70e3f3dc238d5b4674d0bfdce3bcf83b4d2c62baa567dcb537965b3a2ae5a111c498f89157a488f684
|
7
|
+
data.tar.gz: 31bfc39c5a235edc9eb949f058715682eec27397e1ad7b63e1cc4645303b02eb6e58e84c4222f11a45fb377cf7ae3b9d048d2a8cbacef5eae62fce90aebc6214
|
data/config/locales/en.yml
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
en:
|
2
|
+
shoppe:
|
3
|
+
settings:
|
4
|
+
easypost: EasyPost
|
5
|
+
labels:
|
6
|
+
easypost_api_key: Live Secret API Key
|
7
|
+
easypost_shipping_options: Offered Shipping Options
|
8
|
+
handling_cost: Packaging and Handling Cost
|
9
|
+
|
10
|
+
help:
|
11
|
+
easypost_api_key: This is the Live Secret API key from https://www.easypost.com/account/keys.
|
12
|
+
easypost_shipping_options: This is a comma separated list of shipping options you'd like to be available to your customers. Use the service levels listed at https://www.easypost.com/service-levels-and-parcels.
|
data/lib/shoppe/easypost.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "shoppe/easypost/version"
|
2
2
|
require "shoppe/easypost/engine"
|
3
3
|
|
4
|
+
require "EasyPost"
|
5
|
+
|
4
6
|
module Shoppe
|
5
7
|
module Easypost
|
6
8
|
|
@@ -10,12 +12,48 @@ module Shoppe
|
|
10
12
|
Shoppe.settings.easypost_api_key
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
15
|
+
def create_shipment(to_address, from_address, parcel)
|
16
|
+
EasyPost.api_key = self.api_key
|
17
|
+
|
18
|
+
EasyPost::Shipment.create(
|
19
|
+
{
|
20
|
+
to_address: to_address,
|
21
|
+
from_address: from_address,
|
22
|
+
parcel: parcel
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def allowed_shipping_options
|
28
|
+
option_codes = []
|
29
|
+
Shoppe::DeliveryService.all.each do |ds|
|
30
|
+
option_codes << ds.code
|
31
|
+
end
|
32
|
+
|
33
|
+
option_codes
|
34
|
+
end
|
35
|
+
|
36
|
+
def available_options_and_rates(shipment)
|
37
|
+
available_rates = []
|
38
|
+
shipment.rates.each do |rate|
|
39
|
+
if self.allowed_shipping_options.include? rate.service
|
40
|
+
available_rates << rate
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
available_rates
|
45
|
+
end
|
16
46
|
|
17
|
-
|
47
|
+
def shipping_and_handling_costs(rates)
|
48
|
+
rates.each do |rate|
|
49
|
+
puts rate.rate.to_f + Shoppe.settings.handling_cost.to_f
|
50
|
+
end
|
18
51
|
end
|
19
52
|
|
53
|
+
def setup
|
54
|
+
# Setup configuration with API key. Shipping options separated by commas.
|
55
|
+
Shoppe.add_settings_group :easypost, [:easypost_api_key, :handling_cost]
|
56
|
+
end
|
57
|
+
end
|
20
58
|
end
|
21
59
|
end
|