ashmont 0.10.1 → 0.11.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: 6a7cfc4170ed969c9b0f588c3c8865423f6a934e
4
- data.tar.gz: dca7956754612e0acc726d26f656bd92cd853022
3
+ metadata.gz: 2f6ca58a042c682e1897e0c7036a559cba64d843
4
+ data.tar.gz: 43f0ec1f2702b8f5878e7da24744cba7b047440d
5
5
  SHA512:
6
- metadata.gz: 66e08c07c6a81d8b4e3ba90df0e2996cf569aacb66bfb229a24f9bb499e6b4f6f0b5497b886542c138b36b5a822d503be79ac40143586bf072f5789b24321630
7
- data.tar.gz: 81f158042cc378817224eafda369f6b05162ba24874e2a9e9bea6e5702f26f8c37ff62201db84d3750c27783583b942b33695bca6a20bd85b2b1d46ae4d96587
6
+ metadata.gz: 01c453adb9c23b7f08f46e5bcdfc65b09305b1992b22ff587b36ff9dc9834177db83e17490571352dcd381f62ce8c2f16926c87dab083cd7123d43b89705db52
7
+ data.tar.gz: cc9d490e0004ae7fce9d7e12f7a4149d8d3238ca4e65e37f3893de43e86ff267e227c32c81c0cccdb041219a7864b514d7c65a6c92ec03fee6bcc9bd0c771faa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## v0.11.0
2
+ * ADDED: #primary_payment_method to Customer to choose between credit cards and paypal
3
+
1
4
  ## v0.10.1
2
5
  * ADDED: #paypal_account to Customer
3
6
 
@@ -35,6 +35,23 @@ module Ashmont
35
35
  end
36
36
  end
37
37
 
38
+ def primary_payment_method
39
+ #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
+ if persisted?
48
+ primary_payment_method[]
49
+ else
50
+ []
51
+ end
52
+
53
+ end
54
+
38
55
  def has_billing_info?
39
56
  credit_card.present?
40
57
  end
@@ -1,3 +1,3 @@
1
1
  module Ashmont
2
- VERSION = "0.10.1"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -2,6 +2,29 @@ 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)
10
+
11
+ result = Ashmont::Customer.new(token).primary_payment_method
12
+
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
27
+
5
28
  it "returns all paypal accounts" do
6
29
  token = "xyz"
7
30
  remote_customer = stub("customer", :paypal_accounts => ["first", "second"])
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.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoughtbot
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-04-27 00:00:00.000000000 Z
12
+ date: 2017-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: braintree