shoppe-easypost 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +98 -1
- data/config/locales/en.yml +9 -0
- data/lib/shoppe/easypost.rb +54 -24
- data/lib/shoppe/easypost/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08604d7c5dcdb600e395f6b0b860c2ce91bd4c93
|
4
|
+
data.tar.gz: a5417938da4d1facf26d55425d47d0fad2627aa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55e9db8fa4e61d1c353435fce2a16b4d4f370dcc52a93517779adceb87883f9de8027b924b58f3fb50c76b292bc338fa5eeeff277d63171c9a0e956ea7c29f24
|
7
|
+
data.tar.gz: 338170fdbddbc28e74a333fc655db75391db61ebf68518cf762844f7c947e54a1595022f0bb0a546eedbd5cd6a3e75ba5227eaa2fc987f0a17185336a427fb1c
|
data/README.md
CHANGED
@@ -1,2 +1,99 @@
|
|
1
|
-
#
|
1
|
+
# shoppe-easypost
|
2
2
|
|
3
|
+
## How to use this.
|
4
|
+
|
5
|
+
This Shoppe module make it easy for a customer to have and use their own EasyPost API key and give the developer a sane way to access it in production.
|
6
|
+
|
7
|
+
Just add ```gem 'shoppe-easypost'``` to your gemfile and then ```bundle install```
|
8
|
+
|
9
|
+
It provides option fields within the standard Settings tab of Shoppe.
|
10
|
+
|
11
|
+
![Screenshot of settings with EasyPost options.](/../screenshots/screenshots/menu.png?raw=true "Screenshot showing EasyPost settings in Shoppe.")
|
12
|
+
|
13
|
+
**Given the example in the above screenshot, here's the methods made available.**
|
14
|
+
|
15
|
+
These all return a string, as that's how the Shoppe settings hash system works.
|
16
|
+
|
17
|
+
```
|
18
|
+
irb > Shoppe.settings.easypost_api_key
|
19
|
+
=> "asdfasdfasdfasdfasdfasdfasdfasdfasdf"
|
20
|
+
|
21
|
+
irb > Shoppe.settings.handling_cost
|
22
|
+
=> "2.99"
|
23
|
+
|
24
|
+
irb > Shoppe.settings.from_street_1
|
25
|
+
=> "123 Average Place"
|
26
|
+
|
27
|
+
irb > Shoppe.settings.from_street_2
|
28
|
+
=> "Unit 42"
|
29
|
+
|
30
|
+
irb > Shoppe.settings.from_city
|
31
|
+
=> "Ocala"
|
32
|
+
|
33
|
+
irb > Shoppe.settings.from_state
|
34
|
+
=> "FL"
|
35
|
+
|
36
|
+
irb > Shoppe.settings.from_zipcode
|
37
|
+
=> "34471"
|
38
|
+
|
39
|
+
irb > Shoppe.settings.from_phone
|
40
|
+
=> "352-123-4567"
|
41
|
+
```
|
42
|
+
|
43
|
+
**Using the data from the above Shoppe settings that are returned, you can call a handy method I've built into this Gem to create an EasyPost shipment object.**
|
44
|
+
|
45
|
+
```Shoppe::Easypost::create_shipment``` can be used to create a shipment with a single call, as seen in the EasyPost getting started docs. Here's the code from the gem.:
|
46
|
+
|
47
|
+
```
|
48
|
+
def create_shipment(to_address, parcel)
|
49
|
+
EasyPost.api_key = self.api_key
|
50
|
+
|
51
|
+
EasyPost::Shipment.create(
|
52
|
+
{
|
53
|
+
to_address: to_address,
|
54
|
+
from_address: {company: Shoppe.settings.store_name,
|
55
|
+
street1: Shoppe.settings.from_street_1,
|
56
|
+
street2: Shoppe.settings.from_street_2,
|
57
|
+
city: Shoppe.settings.from_city,
|
58
|
+
state: Shoppe.settings.from_state,
|
59
|
+
zip: Shoppe.settings.from_zipcode,
|
60
|
+
phone: Shoppe.settings.from_phone},
|
61
|
+
parcel: parcel
|
62
|
+
}
|
63
|
+
)
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
You'll need to provide a ```to_address``` and a ```parcel``` as arguments into the ```create_shipment``` method. They are just a simple Ruby hash, as the call to EasyPost just passes it as JSON. Using the example from EasyPost's Getting Started page, a call to this method would look like this:
|
68
|
+
|
69
|
+
```
|
70
|
+
buyer_address = {
|
71
|
+
name: 'George Costanza',
|
72
|
+
company: 'Vandelay Industries',
|
73
|
+
street1: '1 E 161st St.',
|
74
|
+
city: 'Bronx',
|
75
|
+
state: 'NY',
|
76
|
+
zip: '10451'
|
77
|
+
}
|
78
|
+
|
79
|
+
parcel = {
|
80
|
+
length: 9,
|
81
|
+
width: 6,
|
82
|
+
height: 2,
|
83
|
+
weight: 10
|
84
|
+
}
|
85
|
+
|
86
|
+
shipment = Shoppe::Easypost::create_shipment(buyer_address, parcel)
|
87
|
+
```
|
88
|
+
|
89
|
+
You can then use that ```shipment``` object to get rates and such, as in the EasyPost Docs.
|
90
|
+
|
91
|
+
(Seriously, the EasyPost docs are awesome. [Read up here.](https://www.easypost.com/getting-started?lang=ruby))
|
92
|
+
|
93
|
+
**I hope you find this gem to be useful. It is currently following Shoppe's convention in that in provides access to data, but does not dictate how you utilize this data on the frontend of your store.**
|
94
|
+
|
95
|
+
I'm considering options to make this a bit more opinionated, with options to override the default shipping system in Shoppe. If you have any suggestion, please drop me a line.
|
96
|
+
|
97
|
+
Currently, I'd suggest making a generic Shipping item in Shoppe, then use the data you get back from EasyPost to override things like the price of the shipping object in Shoppe. You should be able to inject this into the checkout workflow before they get to payment, so you can show an accurate price. I've done this for a client project, however, I'm not permitted to divulge that code at present.
|
98
|
+
|
99
|
+
If you have questions specific to your project, how to implement it in your project, and you'd like me to take a look and make some suggestions, feel free to drop me a line at jared@apogeezenith.com or ping me on twitter [@shepbook](https://www.twitter.com/shepbook). I've worked with Shoppe and EasyPost pretty extensively over the last year and would be happy to help.
|
data/config/locales/en.yml
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
en:
|
2
2
|
shoppe:
|
3
|
+
navigation:
|
4
|
+
admin_primary:
|
5
|
+
easypost: EasyPost Options
|
3
6
|
settings:
|
4
7
|
easypost: EasyPost
|
5
8
|
labels:
|
6
9
|
easypost_api_key: Live Secret API Key
|
7
10
|
easypost_shipping_options: Offered Shipping Options
|
8
11
|
handling_cost: Packaging and Handling Cost
|
12
|
+
from_street_1: From Address Street 1
|
13
|
+
from_street_2: From Address Street 2
|
14
|
+
from_city: From Address City
|
15
|
+
from_state: From Address State (2 digits)
|
16
|
+
from_zipcode: From Address Zipcode
|
17
|
+
from_phone: From Address Phone Number
|
9
18
|
|
10
19
|
help:
|
11
20
|
easypost_api_key: This is the Live Secret API key from https://www.easypost.com/account/keys.
|
data/lib/shoppe/easypost.rb
CHANGED
@@ -1,58 +1,88 @@
|
|
1
1
|
require "shoppe/easypost/version"
|
2
2
|
require "shoppe/easypost/engine"
|
3
3
|
|
4
|
+
require 'shoppe/navigation_manager'
|
5
|
+
|
4
6
|
require "EasyPost"
|
5
7
|
|
6
8
|
module Shoppe
|
7
9
|
module Easypost
|
8
10
|
|
11
|
+
# Add easypost shipping tab to shoppe
|
12
|
+
# Shoppe::NavigationManager.build(:admin_primary) do
|
13
|
+
# add_item :orders
|
14
|
+
# add_item :products
|
15
|
+
# add_item :product_categories
|
16
|
+
# add_item :delivery_services
|
17
|
+
# add_item :tax_rates
|
18
|
+
# add_item :users
|
19
|
+
# add_item :countries
|
20
|
+
# add_item :settings
|
21
|
+
# add_item :easypost
|
22
|
+
# end
|
23
|
+
|
9
24
|
class << self
|
10
25
|
|
11
26
|
def api_key
|
12
27
|
Shoppe.settings.easypost_api_key
|
13
28
|
end
|
14
29
|
|
15
|
-
def create_shipment(to_address,
|
30
|
+
def create_shipment(to_address, parcel)
|
16
31
|
EasyPost.api_key = self.api_key
|
17
32
|
|
18
33
|
EasyPost::Shipment.create(
|
19
34
|
{
|
20
35
|
to_address: to_address,
|
21
|
-
from_address:
|
36
|
+
from_address: {company: Shoppe.settings.store_name,
|
37
|
+
street1: Shoppe.settings.from_street_1,
|
38
|
+
street2: Shoppe.settings.from_street_2,
|
39
|
+
city: Shoppe.settings.from_city,
|
40
|
+
state: Shoppe.settings.from_state,
|
41
|
+
zip: Shoppe.settings.from_zipcode,
|
42
|
+
phone: Shoppe.settings.from_phone},
|
22
43
|
parcel: parcel
|
23
44
|
}
|
24
45
|
)
|
25
46
|
end
|
26
47
|
|
27
|
-
def allowed_shipping_options
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
48
|
+
# def allowed_shipping_options
|
49
|
+
# option_codes = []
|
50
|
+
# Shoppe::DeliveryService.all.each do |ds|
|
51
|
+
# option_codes << ds.code
|
52
|
+
# end
|
32
53
|
|
33
|
-
|
34
|
-
end
|
54
|
+
# option_codes
|
55
|
+
# end
|
35
56
|
|
36
|
-
def available_options_and_rates(shipment)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
57
|
+
# def available_options_and_rates(shipment)
|
58
|
+
# available_rates = []
|
59
|
+
# shipment.rates.each do |rate|
|
60
|
+
# if self.allowed_shipping_options.include? rate.service
|
61
|
+
# available_rates << rate
|
62
|
+
# end
|
63
|
+
# end
|
43
64
|
|
44
|
-
|
45
|
-
end
|
65
|
+
# available_rates
|
66
|
+
# end
|
46
67
|
|
47
|
-
def shipping_and_handling_costs(rates)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
68
|
+
# def shipping_and_handling_costs(rates)
|
69
|
+
# rates.each do |rate|
|
70
|
+
# puts rate.rate.to_f + Shoppe.settings.handling_cost.to_f
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
|
74
|
+
# def easypost_delivery_service_prices(shipment)
|
75
|
+
# if delivery_required?
|
76
|
+
# end
|
77
|
+
# end
|
52
78
|
|
53
79
|
def setup
|
54
80
|
# Setup configuration with API key. Shipping options separated by commas.
|
55
|
-
Shoppe.add_settings_group :easypost, [:easypost_api_key, :handling_cost]
|
81
|
+
Shoppe.add_settings_group :easypost, [:easypost_api_key, :handling_cost, :from_street_1, :from_street_2, :from_city, :from_state, :from_zipcode, :from_phone]
|
82
|
+
|
83
|
+
Shoppe::Order.before_confirmation do
|
84
|
+
|
85
|
+
end
|
56
86
|
end
|
57
87
|
end
|
58
88
|
end
|
metadata
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoppe-easypost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared Koumentis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoppe
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.0.3
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '2'
|
@@ -24,9 +24,9 @@ dependencies:
|
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.0.3
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2'
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
85
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.4.5
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: EasyPost integration for Shoppe backend.
|