active_payment 0.9.0 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 752928e70a64e010c888df7e33e60a8acde5bfb5
4
- data.tar.gz: 9a43f17688e5da7a8d3b6eb1743afee92acf3d24
3
+ metadata.gz: aedbd01450926d0d0b744e1b06619e2bf2c0b4c1
4
+ data.tar.gz: 8abe24d2336acf58b71f2eea631d93bb8ee27c02
5
5
  SHA512:
6
- metadata.gz: 65b4a9cd247f3edb1938646140741e5cf1ecec83390aad6d5aea0e166c1d8208f1b006b314ea029b8400db310cb085b5151227c05fcf6ed5969c3532e7d74bfa
7
- data.tar.gz: 598ce55e9ab77b2c0553df607bd122a2f6b17b83fea2377e125983b232bbbfc8a4549d76b254635e9e0a38e6259b1b4156486013c35984ff6dd36c20c56a2096
6
+ metadata.gz: 4007087f5b29cc94ce7a5c248d1b3c6056b80f91aa991601139ab6baf27eb3b00b1393b3b49604496b0ff6f7f5974a80d87f94812552a848db1a483e05687875
7
+ data.tar.gz: 2c149d470c268420b10f6ec7c6089ae238354c5abf128e42ea77d32317117712158c647f9c969932581d5a8a850cdcbcb1df0ad0b5015eb833590562a81ac998
@@ -80,14 +80,14 @@ module ActivePayment
80
80
 
81
81
  @gateway.sales.each do |sale|
82
82
  @transactions << ActivePayment::Transaction.create({
83
- currency: 'USD',
83
+ currency: sale.payable.currency,
84
84
  gateway: @gateway.class.to_s,
85
85
  amount: sale.amount_in_cents,
86
86
  ip_address: ip_address,
87
87
  payee_id: sale.payee.id,
88
88
  payer_id: sale.payer.id,
89
- payable_id: sale.payable.reference ? sale.payable.reference.id : nil,
90
- payable_type: sale.payable.reference ? sale.payable.reference.class.to_s : nil,
89
+ payable_id: sale.payable.id,
90
+ payable_type: sale.payable.class.to_s,
91
91
  reference_number: sale.payable.reference_number,
92
92
  external_id: @purchase_token,
93
93
  metadata: { description: sale.payable.description }
@@ -0,0 +1,16 @@
1
+ module ActivePayment
2
+ module Models
3
+ module PaypalPayable
4
+ extend ActiveSupport::Concern
5
+
6
+ def to_paypal_hash
7
+ {
8
+ name: @description,
9
+ amount: @amount.to_i,
10
+ number: @number.to_i,
11
+ quantity: @quantity.to_i
12
+ }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module ActivePayment
2
+ module Models
3
+ module PaypalPayee
4
+ extend ActiveSupport::Concern
5
+
6
+ def to_paypal_hash
7
+ {
8
+ email: @paypal_identifier,
9
+ primary: @primary
10
+ }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,27 +1,22 @@
1
1
  module ActivePayment
2
2
  module Models
3
3
  class Payable
4
- attr_accessor :description, :amount, :reference,
5
- :reference_number, :external_id, :shipping, :tax,
6
- :number, :quantity
4
+ include ActivePayment::Models::PaypalPayable
5
+
6
+ attr_accessor :id, :class, :description, :amount,
7
+ :reference_number, :external_id,
8
+ :shipping, :tax, :number, :quantity,
9
+ :currency
7
10
 
8
11
  def initialize(params = {})
9
12
  @tax = 0
10
13
  @shipping = 0
11
14
  @number = 1
12
15
  @quantity = 1
16
+ @currency = 'USD'
13
17
 
14
18
  params.each { |key, value| send "#{key}=", value }
15
19
  end
16
-
17
- def to_paypal_hash
18
- {
19
- name: @description,
20
- amount: @amount.to_i,
21
- number: @number.to_i,
22
- quantity: @quantity.to_i
23
- }
24
- end
25
20
  end
26
21
  end
27
22
  end
@@ -1,18 +1,14 @@
1
1
  module ActivePayment
2
2
  module Models
3
3
  class Payee
4
- attr_accessor :identifier, :primary
4
+ include ActivePayment::Models::PaypalPayee
5
5
 
6
- def initialize(identifier:, primary: false)
7
- @identifier = identifier
8
- @primary = primary
9
- end
6
+ attr_accessor :id, :paypal_identifier, :primary
10
7
 
11
- def to_paypal_hash
12
- {
13
- email: @identifier,
14
- primary: @primary
15
- }
8
+ def initialize(id:, paypal_identifier:, primary: false)
9
+ @id = id
10
+ @paypal_identifier = paypal_identifier
11
+ @primary = primary
16
12
  end
17
13
  end
18
14
  end
@@ -31,7 +31,7 @@ module ActivePayment
31
31
 
32
32
  def paypal_recipient
33
33
  {
34
- email: payee.identifier,
34
+ email: payee.paypal_identifier,
35
35
  amount: amount,
36
36
  primary: false
37
37
  }
@@ -51,7 +51,7 @@ module ActivePayment
51
51
  total_tax: payable.tax
52
52
  },
53
53
  receiver: {
54
- email: @payee.identifier
54
+ email: @payee.paypal_identifier
55
55
  }
56
56
  }
57
57
  end
@@ -1,3 +1,3 @@
1
1
  module ActivePayment
2
- VERSION = '0.9.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -8,6 +8,8 @@ require 'active_payment/gateway'
8
8
  require 'active_payment/configuration'
9
9
  require 'active_payment/gateways/paypal_adaptive_payment'
10
10
  require 'active_payment/gateways/paypal_express_checkout'
11
+ require 'active_payment/models/concerns/paypal_payable'
12
+ require 'active_payment/models/concerns/paypal_payee'
11
13
  require 'active_payment/models/payee'
12
14
  require 'active_payment/models/sale'
13
15
  require 'active_payment/models/sales'
@@ -8,9 +8,10 @@ describe ActivePayment::Models::Payable do
8
8
 
9
9
  it 'should set attributes when passing a hash' do
10
10
  service = ActivePayment::Models::Payable.new({
11
+ id: 1,
12
+ class: 'PayableObj',
11
13
  description: 'desc',
12
14
  amount: 1000,
13
- reference: 200,
14
15
  reference_number: 'ABC123',
15
16
  number: 999,
16
17
  quantity: 300,
@@ -19,9 +20,10 @@ describe ActivePayment::Models::Payable do
19
20
  shipping: 456
20
21
  })
21
22
 
23
+ expect(service.id).to eq(1)
24
+ expect(service.class).to eq('PayableObj')
22
25
  expect(service.description).to eq('desc')
23
26
  expect(service.amount).to eq(1000)
24
- expect(service.reference).to eq(200)
25
27
  expect(service.reference_number).to eq('ABC123')
26
28
  expect(service.external_id).to eq('100')
27
29
  expect(service.tax).to eq(123)
@@ -30,11 +32,25 @@ describe ActivePayment::Models::Payable do
30
32
  expect(service.quantity).to eq(300)
31
33
  end
32
34
 
35
+ it 'should set default currency value to USD if not set' do
36
+ service = ActivePayment::Models::Payable.new({
37
+ id: 1,
38
+ class: 'PayableObj',
39
+ description: 'desc',
40
+ amount: 1000,
41
+ reference_number: 'ABC123',
42
+ external_id: '100',
43
+ shipping: 456
44
+ })
45
+ expect(service.currency).to eq('USD')
46
+ end
47
+
33
48
  it 'should set default tax value to 0 if not set' do
34
49
  service = ActivePayment::Models::Payable.new({
50
+ id: 1,
51
+ class: 'PayableObj',
35
52
  description: 'desc',
36
53
  amount: 1000,
37
- reference: 200,
38
54
  reference_number: 'ABC123',
39
55
  external_id: '100',
40
56
  shipping: 456
@@ -44,9 +60,10 @@ describe ActivePayment::Models::Payable do
44
60
 
45
61
  it 'should set default shipping value to 0 if not set' do
46
62
  service = ActivePayment::Models::Payable.new({
63
+ id: 1,
64
+ class: 'PayableObj',
47
65
  description: 'desc',
48
66
  amount: 1000,
49
- reference: 200,
50
67
  reference_number: 'ABC123',
51
68
  external_id: '100',
52
69
  tax: 123
@@ -57,9 +74,10 @@ describe ActivePayment::Models::Payable do
57
74
 
58
75
  it 'should set default number value to 1 if not set' do
59
76
  service = ActivePayment::Models::Payable.new({
77
+ id: 1,
78
+ class: 'PayableObj',
60
79
  description: 'desc',
61
80
  amount: 1000,
62
- reference: 200,
63
81
  reference_number: 'ABC123',
64
82
  external_id: '100',
65
83
  shipping: 456
@@ -69,9 +87,10 @@ describe ActivePayment::Models::Payable do
69
87
 
70
88
  it 'should set default quantity value to 1 if not set' do
71
89
  service = ActivePayment::Models::Payable.new({
90
+ id: 1,
91
+ class: 'PayableObj',
72
92
  description: 'desc',
73
93
  amount: 1000,
74
- reference: 200,
75
94
  reference_number: 'ABC123',
76
95
  external_id: '100',
77
96
  shipping: 456
@@ -82,9 +101,10 @@ describe ActivePayment::Models::Payable do
82
101
  describe 'to_paypal_hash' do
83
102
  it 'should returns expect value' do
84
103
  service = ActivePayment::Models::Payable.new({
104
+ id: 1,
105
+ class: 'PayableObj',
85
106
  description: 'desc',
86
107
  amount: 1000,
87
- reference: 200,
88
108
  reference_number: 'ABC123',
89
109
  external_id: '100',
90
110
  tax: 123,
@@ -6,24 +6,32 @@ describe ActivePayment::Models::Payee do
6
6
  expect { ActivePayment::Models::Payee.new }.to raise_error(ArgumentError)
7
7
  end
8
8
 
9
- it 'should not raise error is using identifier parameter' do
10
- expect { ActivePayment::Models::Payee.new(identifier: 'test@test.com') }.not_to raise_error
9
+ it 'should raise error if trying to initialize without id' do
10
+ expect { ActivePayment::Models::Payee.new(paypal_identifier: 'test@test.com') }.to raise_error(ArgumentError)
11
+ end
12
+
13
+ it 'should raise error if trying to initialize without identifier' do
14
+ expect { ActivePayment::Models::Payee.new(id: 1) }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it 'should not raise error when using id/identifier parameters' do
18
+ expect { ActivePayment::Models::Payee.new(id: 1, paypal_identifier: 'test@test.com') }.not_to raise_error
11
19
  end
12
20
 
13
21
  it 'should set primary default value to false' do
14
- service = ActivePayment::Models::Payee.new(identifier: 'test@test.com')
22
+ service = ActivePayment::Models::Payee.new(id: 1, paypal_identifier: 'test@test.com')
15
23
  expect(service.primary).to eq(false)
16
24
  end
17
25
 
18
26
  it 'should allow to set primary value' do
19
- service = ActivePayment::Models::Payee.new(identifier: 'test@test.com', primary: true)
27
+ service = ActivePayment::Models::Payee.new(id: 1, paypal_identifier: 'test@test.com', primary: true)
20
28
  expect(service.primary).to eq(true)
21
29
  end
22
30
  end
23
31
 
24
32
  describe 'to_paypal_hash' do
25
33
  it 'should returns expect value' do
26
- service = ActivePayment::Models::Payee.new(identifier: 'test@test.com')
34
+ service = ActivePayment::Models::Payee.new(id: 1, paypal_identifier: 'test@test.com')
27
35
  expect(service.to_paypal_hash.class).to eq(Hash)
28
36
  expect(service.to_paypal_hash[:email]).to eq('test@test.com')
29
37
  expect(service.to_paypal_hash[:primary]).to eq(false)
@@ -52,7 +52,7 @@ describe ActivePayment::Models::Sale do
52
52
  describe 'paypal_recipient' do
53
53
  it 'displays the paypal_recipient hash with correct values' do
54
54
  expect(@sale.paypal_recipient).to eq({
55
- email: @sale.payee.identifier,
55
+ email: @sale.payee.paypal_identifier,
56
56
  amount: 1,
57
57
  primary: false
58
58
  })
@@ -74,7 +74,7 @@ describe ActivePayment::Models::Sale do
74
74
  total_tax: @sale.payable.tax
75
75
  },
76
76
  receiver: {
77
- email: @sale.payee.identifier
77
+ email: @sale.payee.paypal_identifier
78
78
  }
79
79
  })
80
80
  end
Binary file