ashmont 0.11.0 → 0.11.1

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: 2f6ca58a042c682e1897e0c7036a559cba64d843
4
- data.tar.gz: 43f0ec1f2702b8f5878e7da24744cba7b047440d
3
+ metadata.gz: c90dea55b8adcbac2014088d175f82e2a0a385a5
4
+ data.tar.gz: 3a6953e23e57801dd221bec59fbde18e2cb57e73
5
5
  SHA512:
6
- metadata.gz: 01c453adb9c23b7f08f46e5bcdfc65b09305b1992b22ff587b36ff9dc9834177db83e17490571352dcd381f62ce8c2f16926c87dab083cd7123d43b89705db52
7
- data.tar.gz: cc9d490e0004ae7fce9d7e12f7a4149d8d3238ca4e65e37f3893de43e86ff267e227c32c81c0cccdb041219a7864b514d7c65a6c92ec03fee6bcc9bd0c771faa
6
+ metadata.gz: 320322cb4bd27c2ad4661f8003d227d5ff15985974f14b0d61a844aefcaf55f0d5e3d1c3c292b46347fd6d936a37a6c272c4f254e10c22ade16bd5e12292be6f
7
+ data.tar.gz: 3539cd26e86cd6300c804e4e0d988781f38a9de3225b8b55abf7897832268bb0108c91f5beec676d952efa7053fd3bd534d34eaad7153e8cb7f9406c076f2cc3
@@ -1,3 +1,6 @@
1
+ ##v0.11.1
2
+ * ADDED: #primary_payment_account to Customer to get the first primary_payment_method
3
+
1
4
  ## v0.11.0
2
5
  * ADDED: #primary_payment_method to Customer to choose between credit cards and paypal
3
6
 
@@ -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
- primary_payment_method[]
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?
@@ -1,3 +1,3 @@
1
1
  module Ashmont
2
- VERSION = "0.11.0"
2
+ VERSION = "0.11.1"
3
3
  end
@@ -2,27 +2,83 @@ require 'spec_helper'
2
2
  require 'ashmont/customer'
3
3
 
4
4
  describe Ashmont::Customer do
5
-
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)
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
- result = Ashmont::Customer.new(token).primary_payment_method
11
+ result = Ashmont::Customer.new(token).primary_payment_method
12
12
 
13
- expect(Braintree::Customer).to have_received(:find).with(token)
14
- expect(result).to eq(["first", "second"])
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
- 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)
35
+ result = Ashmont::Customer.new(token).primary_payment_account
21
36
 
22
- result = Ashmont::Customer.new(token).primary_payment_method
37
+ expect(Braintree::Customer).to have_received(:find).with(token)
38
+ expect(result).to eq("first")
39
+ end
23
40
 
24
- expect(Braintree::Customer).to have_received(:find).with(token)
25
- expect(result).to eq(["first", "second"])
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ashmont
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot