ashmont 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/ashmont/customer.rb +10 -9
- data/lib/ashmont/version.rb +1 -1
- data/spec/ashmont/customer_spec.rb +72 -16
- 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: c90dea55b8adcbac2014088d175f82e2a0a385a5
|
4
|
+
data.tar.gz: 3a6953e23e57801dd221bec59fbde18e2cb57e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 320322cb4bd27c2ad4661f8003d227d5ff15985974f14b0d61a844aefcaf55f0d5e3d1c3c292b46347fd6d936a37a6c272c4f254e10c22ade16bd5e12292be6f
|
7
|
+
data.tar.gz: 3539cd26e86cd6300c804e4e0d988781f38a9de3225b8b55abf7897832268bb0108c91f5beec676d952efa7053fd3bd534d34eaad7153e8cb7f9406c076f2cc3
|
data/CHANGELOG.md
CHANGED
data/lib/ashmont/customer.rb
CHANGED
@@ -12,7 +12,9 @@ module Ashmont
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def credit_card
|
15
|
+
# old way
|
15
16
|
credit_cards[0]
|
17
|
+
# primary_payment_account # too general
|
16
18
|
end
|
17
19
|
|
18
20
|
def credit_cards
|
@@ -37,19 +39,18 @@ module Ashmont
|
|
37
39
|
|
38
40
|
def primary_payment_method
|
39
41
|
#currently, usually there is only one payment method, paypal or credit_card
|
40
|
-
payment_methods = { credit_cards.count => :credit_cards,
|
41
|
-
paypal_accounts.count => :paypal_accounts }
|
42
|
-
chosen_method = (payment_methods[payment_methods.keys.max])
|
43
|
-
remote_customer.send(chosen_method)
|
44
|
-
end
|
45
|
-
|
46
|
-
def primary_payment_account
|
47
42
|
if persisted?
|
48
|
-
|
43
|
+
payment_methods = { credit_cards.count => :credit_cards,
|
44
|
+
paypal_accounts.count => :paypal_accounts }
|
45
|
+
chosen_method = (payment_methods[payment_methods.keys.max])
|
46
|
+
remote_customer.send(chosen_method)
|
49
47
|
else
|
50
48
|
[]
|
51
49
|
end
|
52
|
-
|
50
|
+
end
|
51
|
+
|
52
|
+
def primary_payment_account
|
53
|
+
primary_payment_method[0]
|
53
54
|
end
|
54
55
|
|
55
56
|
def has_billing_info?
|
data/lib/ashmont/version.rb
CHANGED
@@ -2,27 +2,83 @@ require 'spec_helper'
|
|
2
2
|
require 'ashmont/customer'
|
3
3
|
|
4
4
|
describe Ashmont::Customer do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
describe '#primaray_payment_method' do
|
6
|
+
it 'chooses paypal_accounts as the primary_payment_method when the customer does' do
|
7
|
+
token = "xyz"
|
8
|
+
remote_customer = stub("customer", :paypal_accounts => ["first", "second"], :credit_cards => [])
|
9
|
+
Braintree::Customer.stubs(:find => remote_customer)
|
10
10
|
|
11
|
-
|
11
|
+
result = Ashmont::Customer.new(token).primary_payment_method
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
expect(Braintree::Customer).to have_received(:find).with(token)
|
14
|
+
expect(result).to eq(["first", "second"])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'chooses credit_cards as the primary_payment_method when the customer does' do
|
18
|
+
token = "xyz"
|
19
|
+
remote_customer = stub("customer", :paypal_accounts => [], :credit_cards => ["first", "second"])
|
20
|
+
Braintree::Customer.stubs(:find => remote_customer)
|
21
|
+
|
22
|
+
result = Ashmont::Customer.new(token).primary_payment_method
|
23
|
+
|
24
|
+
expect(Braintree::Customer).to have_received(:find).with(token)
|
25
|
+
expect(result).to eq(["first", "second"])
|
26
|
+
end
|
15
27
|
end
|
28
|
+
|
29
|
+
describe '#primary_payment_account' do
|
30
|
+
it 'returns the first account of the primary_payment_method when it is paypal' do
|
31
|
+
token = "xyz"
|
32
|
+
remote_customer = stub("customer", :paypal_accounts => ["first", "second"], :credit_cards => [])
|
33
|
+
Braintree::Customer.stubs(:find => remote_customer)
|
16
34
|
|
17
|
-
|
18
|
-
token = "xyz"
|
19
|
-
remote_customer = stub("customer", :paypal_accounts => [], :credit_cards => ["first", "second"])
|
20
|
-
Braintree::Customer.stubs(:find => remote_customer)
|
35
|
+
result = Ashmont::Customer.new(token).primary_payment_account
|
21
36
|
|
22
|
-
|
37
|
+
expect(Braintree::Customer).to have_received(:find).with(token)
|
38
|
+
expect(result).to eq("first")
|
39
|
+
end
|
23
40
|
|
24
|
-
|
25
|
-
|
41
|
+
it 'returns the first account of the primary_payment_method when it is a credit card' do
|
42
|
+
token = "xyz"
|
43
|
+
remote_customer = stub("customer", :paypal_accounts => [], :credit_cards => ["first", "second"])
|
44
|
+
Braintree::Customer.stubs(:find => remote_customer)
|
45
|
+
|
46
|
+
result = Ashmont::Customer.new(token).primary_payment_account
|
47
|
+
|
48
|
+
expect(Braintree::Customer).to have_received(:find).with(token)
|
49
|
+
expect(result).to eq("first")
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'when the payment account is a credit card, it returns credit card attributes' do
|
53
|
+
token = "xyz"
|
54
|
+
first_credit_card_attributes = { token: "3328xj",
|
55
|
+
billing_address: nil,
|
56
|
+
bin: "411111",
|
57
|
+
card_type: "Visa",
|
58
|
+
cardholder_name: nil,
|
59
|
+
customer_id: "898484653",
|
60
|
+
expiration_month: "12",
|
61
|
+
expiration_year: "2021",
|
62
|
+
last_4: "1111",
|
63
|
+
prepaid: "Unknown",
|
64
|
+
payroll: "Unknown",
|
65
|
+
product_id: "Unknown",
|
66
|
+
commercial: "Unknown",
|
67
|
+
debit: "Unknown",
|
68
|
+
durbin_regulated: "Unknown",
|
69
|
+
healthcare: "Unknown",
|
70
|
+
country_of_issuance: "Unknown",
|
71
|
+
issuing_bank: "Unknown",
|
72
|
+
image_url: "https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox"
|
73
|
+
}
|
74
|
+
remote_customer = stub("customer", :paypal_accounts => [], :credit_cards => [first_credit_card_attributes, "second"])
|
75
|
+
Braintree::Customer.stubs(:find => remote_customer)
|
76
|
+
|
77
|
+
result = Ashmont::Customer.new(token).primary_payment_account
|
78
|
+
|
79
|
+
expect(Braintree::Customer).to have_received(:find).with(token)
|
80
|
+
expect(result).to eq(first_credit_card_attributes)
|
81
|
+
end
|
26
82
|
end
|
27
83
|
|
28
84
|
it "returns all paypal accounts" do
|
@@ -51,7 +107,7 @@ describe Ashmont::Customer do
|
|
51
107
|
|
52
108
|
it "returns its first credit card" do
|
53
109
|
token = "xyz"
|
54
|
-
remote_customer = stub("customer", :credit_cards => ["first", "second"])
|
110
|
+
remote_customer = stub("customer", :credit_cards => ["first", "second"], :paypal_accounts => [])
|
55
111
|
Braintree::Customer.stubs(:find => remote_customer)
|
56
112
|
|
57
113
|
result = Ashmont::Customer.new(token).credit_card
|