active_payment 0.0.8 → 0.9.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: c4f56028a3c36cad165bf1c617ef183a3818d502
4
- data.tar.gz: 82c5dd80c4e2a4649d783e47023d07679e83308d
3
+ metadata.gz: 752928e70a64e010c888df7e33e60a8acde5bfb5
4
+ data.tar.gz: 9a43f17688e5da7a8d3b6eb1743afee92acf3d24
5
5
  SHA512:
6
- metadata.gz: 66fa5109b7a33754581e29ba9f2d1eb8e20085a4869a023d6a7299ae5e75db80bfa2309cba69dcb824f824cb14cff9d6431bf0f39b441f1bce877500f5e97790
7
- data.tar.gz: 66c78b1e0ecd774065de7a8ab92f0dee0585f43e3fd1f2465cb9875d18bb5eab6fab79622035257630abb7e35eb7b66229c33ac44f5c143ae27cf3d6f062ccf4
6
+ metadata.gz: 65b4a9cd247f3edb1938646140741e5cf1ecec83390aad6d5aea0e166c1d8208f1b006b314ea029b8400db310cb085b5151227c05fcf6ed5969c3532e7d74bfa
7
+ data.tar.gz: 598ce55e9ab77b2c0553df607bd122a2f6b17b83fea2377e125983b232bbbfc8a4549d76b254635e9e0a38e6259b1b4156486013c35984ff6dd36c20c56a2096
@@ -8,11 +8,10 @@ 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/payable'
12
- require 'active_payment/models/concerns/payee'
13
- require 'active_payment/models/concerns/payer'
11
+ require 'active_payment/models/payee'
14
12
  require 'active_payment/models/sale'
15
13
  require 'active_payment/models/sales'
14
+ require 'active_payment/models/payable'
16
15
 
17
16
  module ActivePayment
18
17
  attr_accessor :configuration
@@ -86,9 +86,9 @@ module ActivePayment
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 ? sale.payable.id : nil,
90
- payable_type: sale.payable ? sale.payable.class.to_s : nil,
91
- reference_number: sale.payable.reference,
89
+ payable_id: sale.payable.reference ? sale.payable.reference.id : nil,
90
+ payable_type: sale.payable.reference ? sale.payable.reference.class.to_s : nil,
91
+ reference_number: sale.payable.reference_number,
92
92
  external_id: @purchase_token,
93
93
  metadata: { description: sale.payable.description }
94
94
  })
@@ -0,0 +1,27 @@
1
+ module ActivePayment
2
+ module Models
3
+ class Payable
4
+ attr_accessor :description, :amount, :reference,
5
+ :reference_number, :external_id, :shipping, :tax,
6
+ :number, :quantity
7
+
8
+ def initialize(params = {})
9
+ @tax = 0
10
+ @shipping = 0
11
+ @number = 1
12
+ @quantity = 1
13
+
14
+ params.each { |key, value| send "#{key}=", value }
15
+ 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
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ module ActivePayment
2
+ module Models
3
+ class Payee
4
+ attr_accessor :identifier, :primary
5
+
6
+ def initialize(identifier:, primary: false)
7
+ @identifier = identifier
8
+ @primary = primary
9
+ end
10
+
11
+ def to_paypal_hash
12
+ {
13
+ email: @identifier,
14
+ primary: @primary
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -31,7 +31,7 @@ module ActivePayment
31
31
 
32
32
  def paypal_recipient
33
33
  {
34
- email: payee.paypal_identifier,
34
+ email: payee.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.paypal_identifier
54
+ email: @payee.identifier
55
55
  }
56
56
  }
57
57
  end
@@ -1,3 +1,3 @@
1
1
  module ActivePayment
2
- VERSION = '0.0.8'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -20,7 +20,7 @@ RSpec.describe ActivePayment::PaypalExpressCheckoutCallbackController, type: :co
20
20
  describe 'success' do
21
21
  let!(:transaction) { create(:transaction) }
22
22
 
23
- it 'should riase NoTransactionError if no token is passed' do
23
+ it 'should raise NoTransactionError if no token is passed' do
24
24
  expect {
25
25
  get :success
26
26
  }.to raise_error(ActivePayment::NoTransactionError)
@@ -43,9 +43,9 @@ describe ActivePayment::Gateway do
43
43
  end
44
44
 
45
45
  it 'set correct transactions' do
46
- payer = Payer.new
47
- payee = Payee.new
48
- payable = Payable.new
46
+ payer = PayerObj.new
47
+ payee = PayeeObj.new
48
+ payable = PayableObj.new.to_payable
49
49
  sale = ActivePayment::Models::Sale.new(payable: payable, payer: payer, payee: payee)
50
50
  sales = ActivePayment::Models::Sales.new([sale])
51
51
  gateway = ActivePayment::Gateway.new('paypal_adaptive_payment')
@@ -63,7 +63,7 @@ describe ActivePayment::Gateway do
63
63
  expect(gateway.transactions.first.payer_id).to eq(2)
64
64
  expect(gateway.transactions.first.payable_id).to eq(3)
65
65
  expect(gateway.transactions.first.reference_number).to eq('3')
66
- expect(gateway.transactions.first.payable_type).to eq('Payable')
66
+ expect(gateway.transactions.first.payable_type).to eq('PayableObj')
67
67
  expect(gateway.transactions.first.gateway).to eq('ActivePayment::Gateways::PaypalAdaptivePayment')
68
68
  expect(gateway.transactions.first.ip_address).to eq('127.0.0.1')
69
69
  expect(gateway.transactions.first.state).to eq('pending')
@@ -2,16 +2,16 @@ require 'helper'
2
2
 
3
3
  describe ActivePayment::Gateways::PaypalAdaptivePayment do
4
4
  before(:each) do
5
- @payer = Payer.new
6
- @payee = Payee.new
7
- @payable = Payable.new
8
- @sale = ActivePayment::Models::Sale.new(payable: @payable, payer: @payer, payee: @payee)
9
- @payee2 = Payee.new
10
- @payee2.paypal_identifier = 'test2@paypal.com'
11
- @payee3 = Payee.new
12
- @payee3.paypal_identifier = 'test3@paypal.com'
13
- @sale2 = ActivePayment::Models::Sale.new(payable: @payable, payer: @payer, payee: @payee2)
14
- @sale3 = ActivePayment::Models::Sale.new(payable: @payable, payer: @payer, payee: @payee3)
5
+ @payer = PayerObj.new
6
+ @payee = PayeeObj.new
7
+ @payable = PayableObj.new
8
+ @sale = ActivePayment::Models::Sale.new(payable: @payable.to_payable, payer: @payer, payee: @payee.to_payee)
9
+ @payee2 = PayeeObj.new
10
+ @payee2.paypal = 'test2@paypal.com'
11
+ @payee3 = PayeeObj.new
12
+ @payee3.paypal = 'test3@paypal.com'
13
+ @sale2 = ActivePayment::Models::Sale.new(payable: @payable.to_payable, payer: @payer, payee: @payee2.to_payee)
14
+ @sale3 = ActivePayment::Models::Sale.new(payable: @payable.to_payable, payer: @payer, payee: @payee3.to_payee)
15
15
 
16
16
  @sales = ActivePayment::Models::Sales.new([@sale, @sale2, @sale3])
17
17
  @gateway = ActivePayment::Gateways::PaypalAdaptivePayment.new
@@ -37,7 +37,7 @@ describe ActivePayment::Gateways::PaypalAdaptivePayment do
37
37
  true
38
38
  end
39
39
  def [](request)
40
- "pay_key"
40
+ 'pay_key'
41
41
  end
42
42
  end
43
43
  @success_gateway_response = SuccessMockResponse.new
@@ -2,47 +2,16 @@ require 'helper'
2
2
 
3
3
  describe ActivePayment::Gateways::PaypalExpressCheckout do
4
4
  before(:each) do
5
- class Payee
6
- include ActivePayment::Models::Payee
7
- attr_accessor :paypal_identifier
8
-
9
- def paypal_identifier
10
- "test@paypal.com"
11
- end
12
- end
13
- class Payer
14
- include ActivePayment::Models::Payer
15
- end
16
- class Payable
17
- include ActivePayment::Models::Payable
18
-
19
- def amount
20
- 100
21
- end
22
-
23
- def description
24
- "description"
25
- end
26
-
27
- def tax
28
- 10
29
- end
30
-
31
- def shipping
32
- 20
33
- end
34
- end
35
-
36
- @payer = Payer.new
37
- @payee = Payee.new
38
- @payable = Payable.new
39
- @sale = ActivePayment::Models::Sale.new(payable: @payable, payer: @payer, payee: @payee)
40
- @payee2 = Payee.new
41
- @payee2.paypal_identifier = "test2@paypal.com"
42
- @payee3 = Payee.new
43
- @payee3.paypal_identifier = "test3@paypal.com"
44
- @sale2 = ActivePayment::Models::Sale.new(payable: @payable, payer: @payer, payee: @payee2)
45
- @sale3 = ActivePayment::Models::Sale.new(payable: @payable, payer: @payer, payee: @payee3)
5
+ @payer = PayerObj.new
6
+ @payee = PayeeObj.new
7
+ @payable = PayableObj.new
8
+ @sale = ActivePayment::Models::Sale.new(payable: @payable.to_payable, payer: @payer, payee: @payee)
9
+ @payee2 = PayeeObj.new
10
+ @payee2.paypal = 'test2@paypal.com'
11
+ @payee3 = PayeeObj.new
12
+ @payee3.paypal = 'test3@paypal.com'
13
+ @sale2 = ActivePayment::Models::Sale.new(payable: @payable.to_payable, payer: @payer, payee: @payee2.to_payee)
14
+ @sale3 = ActivePayment::Models::Sale.new(payable: @payable.to_payable, payer: @payer, payee: @payee3.to_payee)
46
15
 
47
16
  @sales = ActivePayment::Models::Sales.new([@sale, @sale2, @sale3])
48
17
  @gateway = ActivePayment::Gateways::PaypalExpressCheckout.new
@@ -0,0 +1,100 @@
1
+ require 'helper'
2
+
3
+ describe ActivePayment::Models::Payable do
4
+ describe 'initialize' do
5
+ it 'should not raise any error if calling initialize without any parameter' do
6
+ expect { ActivePayment::Models::Payable.new }.not_to raise_error
7
+ end
8
+
9
+ it 'should set attributes when passing a hash' do
10
+ service = ActivePayment::Models::Payable.new({
11
+ description: 'desc',
12
+ amount: 1000,
13
+ reference: 200,
14
+ reference_number: 'ABC123',
15
+ number: 999,
16
+ quantity: 300,
17
+ external_id: '100',
18
+ tax: 123,
19
+ shipping: 456
20
+ })
21
+
22
+ expect(service.description).to eq('desc')
23
+ expect(service.amount).to eq(1000)
24
+ expect(service.reference).to eq(200)
25
+ expect(service.reference_number).to eq('ABC123')
26
+ expect(service.external_id).to eq('100')
27
+ expect(service.tax).to eq(123)
28
+ expect(service.shipping).to eq(456)
29
+ expect(service.number).to eq(999)
30
+ expect(service.quantity).to eq(300)
31
+ end
32
+
33
+ it 'should set default tax value to 0 if not set' do
34
+ service = ActivePayment::Models::Payable.new({
35
+ description: 'desc',
36
+ amount: 1000,
37
+ reference: 200,
38
+ reference_number: 'ABC123',
39
+ external_id: '100',
40
+ shipping: 456
41
+ })
42
+ expect(service.tax).to eq(0)
43
+ end
44
+
45
+ it 'should set default shipping value to 0 if not set' do
46
+ service = ActivePayment::Models::Payable.new({
47
+ description: 'desc',
48
+ amount: 1000,
49
+ reference: 200,
50
+ reference_number: 'ABC123',
51
+ external_id: '100',
52
+ tax: 123
53
+ })
54
+ expect(service.shipping).to eq(0)
55
+ end
56
+ end
57
+
58
+ it 'should set default number value to 1 if not set' do
59
+ service = ActivePayment::Models::Payable.new({
60
+ description: 'desc',
61
+ amount: 1000,
62
+ reference: 200,
63
+ reference_number: 'ABC123',
64
+ external_id: '100',
65
+ shipping: 456
66
+ })
67
+ expect(service.number).to eq(1)
68
+ end
69
+
70
+ it 'should set default quantity value to 1 if not set' do
71
+ service = ActivePayment::Models::Payable.new({
72
+ description: 'desc',
73
+ amount: 1000,
74
+ reference: 200,
75
+ reference_number: 'ABC123',
76
+ external_id: '100',
77
+ shipping: 456
78
+ })
79
+ expect(service.quantity).to eq(1)
80
+ end
81
+
82
+ describe 'to_paypal_hash' do
83
+ it 'should returns expect value' do
84
+ service = ActivePayment::Models::Payable.new({
85
+ description: 'desc',
86
+ amount: 1000,
87
+ reference: 200,
88
+ reference_number: 'ABC123',
89
+ external_id: '100',
90
+ tax: 123,
91
+ shipping: 456
92
+ })
93
+ expect(service.to_paypal_hash.class).to eq(Hash)
94
+ expect(service.to_paypal_hash[:name]).to eq('desc')
95
+ expect(service.to_paypal_hash[:amount]).to eq(1000)
96
+ expect(service.to_paypal_hash[:number]).to eq(1)
97
+ expect(service.to_paypal_hash[:quantity]).to eq(1)
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ describe ActivePayment::Models::Payee do
4
+ describe 'initialize' do
5
+ it 'should raise error if trying to initialize without any parameters' do
6
+ expect { ActivePayment::Models::Payee.new }.to raise_error(ArgumentError)
7
+ end
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
11
+ end
12
+
13
+ it 'should set primary default value to false' do
14
+ service = ActivePayment::Models::Payee.new(identifier: 'test@test.com')
15
+ expect(service.primary).to eq(false)
16
+ end
17
+
18
+ it 'should allow to set primary value' do
19
+ service = ActivePayment::Models::Payee.new(identifier: 'test@test.com', primary: true)
20
+ expect(service.primary).to eq(true)
21
+ end
22
+ end
23
+
24
+ describe 'to_paypal_hash' do
25
+ it 'should returns expect value' do
26
+ service = ActivePayment::Models::Payee.new(identifier: 'test@test.com')
27
+ expect(service.to_paypal_hash.class).to eq(Hash)
28
+ expect(service.to_paypal_hash[:email]).to eq('test@test.com')
29
+ expect(service.to_paypal_hash[:primary]).to eq(false)
30
+ end
31
+ end
32
+ end
@@ -2,39 +2,12 @@ require 'helper'
2
2
 
3
3
  describe ActivePayment::Models::Sale do
4
4
  before(:each) do
5
- class Payee
6
- include ActivePayment::Models::Payee
7
-
8
- def paypal_identifier
9
- "test@paypal.com"
10
- end
11
- end
12
- class Payer
13
- include ActivePayment::Models::Payer
14
- end
15
- class Payable
16
- include ActivePayment::Models::Payable
17
-
18
- def amount
19
- 100
20
- end
21
-
22
- def description
23
- "description"
24
- end
25
-
26
- def tax
27
- 10
28
- end
29
-
30
- def shipping
31
- 20
32
- end
33
- end
34
-
35
- @payer = Payer.new
36
- @payee = Payee.new
37
- @payable = Payable.new
5
+ @payer = PayerObj.new
6
+ # @payer = payer_obj.to_payer
7
+ payee_obj = PayeeObj.new
8
+ @payee = payee_obj.to_payee
9
+ payable_obj = PayableObj.new
10
+ @payable = payable_obj.to_payable
38
11
  @sale = ActivePayment::Models::Sale.new(payable: @payable, payer: @payer, payee: @payee)
39
12
  end
40
13
 
@@ -60,13 +33,13 @@ describe ActivePayment::Models::Sale do
60
33
 
61
34
  describe 'description' do
62
35
  it 'displays the payable description' do
63
- expect(@sale.description).to eq(@payable.description)
36
+ expect(@sale.description).to eq(@sale.payable.description)
64
37
  end
65
38
  end
66
39
 
67
40
  describe 'shipping' do
68
41
  it 'displays the payable shipping value' do
69
- expect(@sale.shipping).to eq(@payable.shipping)
42
+ expect(@sale.shipping).to eq(@sale.payable.shipping)
70
43
  end
71
44
  end
72
45
 
@@ -79,7 +52,7 @@ describe ActivePayment::Models::Sale do
79
52
  describe 'paypal_recipient' do
80
53
  it 'displays the paypal_recipient hash with correct values' do
81
54
  expect(@sale.paypal_recipient).to eq({
82
- email: @payee.paypal_identifier,
55
+ email: @sale.payee.identifier,
83
56
  amount: 1,
84
57
  primary: false
85
58
  })
@@ -89,19 +62,19 @@ describe ActivePayment::Models::Sale do
89
62
  describe 'paypal_hash' do
90
63
  it 'displays the paypal_hash with correct values' do
91
64
  expect(@sale.paypal_hash).to eq({
92
- description: @payable.description,
65
+ description: @sale.payable.description,
93
66
  invoice_data: {
94
67
  item: [{
95
- name: @payable.description,
68
+ name: @sale.payable.description,
96
69
  item_count: 1,
97
70
  item_price: 1,
98
71
  price: 1
99
72
  }],
100
- total_shipping: @payable.shipping,
101
- total_tax: @payable.tax
73
+ total_shipping: @sale.payable.shipping,
74
+ total_tax: @sale.payable.tax
102
75
  },
103
76
  receiver: {
104
- email: @payee.paypal_identifier
77
+ email: @sale.payee.identifier
105
78
  }
106
79
  })
107
80
  end