skrill_payments 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -28,18 +28,18 @@ With following content.
28
28
 
29
29
  ## Usage
30
30
 
31
- ### SEND MONEY USING AN HTTPS REQUEST
31
+ ### SEND MONEY USING AN HTTPS REQUEST
32
32
 
33
- Put this code into your Payment class.
33
+ Put this code into your Payment class.
34
34
 
35
35
  include SkrillPayment
36
36
 
37
- Your payment class must contain all attributes/methods which is required for transfer money.
37
+ Your payment class must contain all attributes/methods which is required for transfer money.
38
38
 
39
39
  [:amount, :currency, :recipient_email, :subject, :note, :reference_id]
40
40
  # :reference_id is optional attribute
41
41
 
42
- For example:
42
+ For example:
43
43
 
44
44
  class Payment
45
45
 
@@ -76,7 +76,21 @@ With following content.
76
76
  def pay_for_service
77
77
  payment = Payment.find(params[:id])
78
78
  begin
79
- SkrillPayments.pay!(payment)
79
+ payment.pay!
80
+ rescue SkrillPaymentsException => e
81
+ # do stuff
82
+ end
83
+ redirect_to payments_path
84
+ end
85
+
86
+ ### SEND MONEY FROM DIFFERENT SKRILL ACCOUNT
87
+
88
+ If you want to send money from different Skrill account (different email and password than from the config). Just add following params in pay! method.
89
+
90
+ def pay_for_service
91
+ payment = Payment.find(params[:id])
92
+ begin
93
+ payment.pay!(email: 'account_2@macejko.sk', password: 'sadnuasndasdasd')
80
94
  rescue SkrillPaymentsException => e
81
95
  # do stuff
82
96
  end
@@ -1,13 +1,5 @@
1
1
  module SkrillPayments
2
2
 
3
- def self.pay!(payment)
4
- prepare_transfer = PrepareTransfer.new(payment).call
5
-
6
- payment.sid = prepare_transfer['sid'][0]
7
-
8
- !!ExecuteTransfer.new(payment).call
9
- end
10
-
11
3
  class << self
12
4
  attr_writer :configuration
13
5
  end
@@ -1,8 +1,8 @@
1
- module Api
1
+ class Api
2
2
 
3
3
  BASE_URL = 'https://www.moneybookers.com/app/pay.pl'
4
4
 
5
- attr_reader :payment
5
+ attr_reader :payment, :account
6
6
 
7
7
  def call
8
8
  response = connection.get '', params.merge(default_params)
@@ -27,8 +27,8 @@ module Api
27
27
 
28
28
  def default_params
29
29
  {
30
- email: SkrillPayments.configuration.email,
31
- password: SkrillPayments.configuration.password
30
+ email: account[:email] || SkrillPayments.configuration.email,
31
+ password: account[:password] || SkrillPayments.configuration.password
32
32
  }
33
33
  end
34
34
 
@@ -1,11 +1,10 @@
1
- class ExecuteTransfer
2
-
3
- include Api
1
+ class ExecuteTransfer < Api
4
2
 
5
3
  ATTRIBUTES = [:sid]
6
4
 
7
- def initialize(payment)
5
+ def initialize(payment, account = {})
8
6
  @payment = payment
7
+ @account = account
9
8
  end
10
9
 
11
10
  def params
@@ -1,11 +1,10 @@
1
- class PrepareTransfer
2
-
3
- include Api
1
+ class PrepareTransfer < Api
4
2
 
5
3
  ATTRIBUTES = [:amount, :currency, :bnf_email, :subject, :note, :frn_trn_id]
6
4
 
7
- def initialize(payment)
5
+ def initialize(payment, account = {})
8
6
  @payment = payment
7
+ @account = account
9
8
  end
10
9
 
11
10
  def params
@@ -10,4 +10,12 @@ module SkrillPayment
10
10
  reference_id
11
11
  end
12
12
 
13
+ def pay!(account = {})
14
+ prepare_transfer = PrepareTransfer.new(self, account).call
15
+
16
+ self.sid = prepare_transfer['sid'][0]
17
+
18
+ !!ExecuteTransfer.new(self, account).call
19
+ end
20
+
13
21
  end
@@ -1,3 +1,3 @@
1
1
  module SkrillPayments
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,7 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- class Dummie
4
- include Api
3
+ class Dummie < Api;
4
+
5
+ def initialize(payment, account = {})
6
+ @payment = payment
7
+ @account = account
8
+ end
9
+
5
10
  end
6
11
 
7
12
  describe Api do
@@ -10,14 +15,15 @@ describe Api do
10
15
 
11
16
  object = double('Payment', currency: 'CZK', amount: 10, user_id: 20)
12
17
  attributes = [:currency, :amount]
13
- params = Dummie.new.send(:params, object, attributes)
18
+ dummie = Dummie.new(Payment.new)
19
+ params = dummie.send(:params, object, attributes)
14
20
 
15
21
  expect(params).to eq({ currency: 'CZK', amount: 10 })
16
22
  end
17
23
 
18
24
  it 'creates default params from config' do
19
25
 
20
- params = Dummie.new.send(:default_params)
26
+ params = Dummie.new(Payment.new).send(:default_params)
21
27
 
22
28
  expect(params).to eq(
23
29
  {
@@ -26,4 +32,17 @@ describe Api do
26
32
  }
27
33
  )
28
34
  end
35
+
36
+ it 'creates default params from account parameter' do
37
+
38
+ account = { email: 'michal@macejko.sk', password: 'stefan' }
39
+ params = Dummie.new(Payment.new, account).send(:default_params)
40
+
41
+ expect(params).to eq(
42
+ {
43
+ email: 'michal@macejko.sk',
44
+ password: 'stefan'
45
+ }
46
+ )
47
+ end
29
48
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe SkrillPayments do
3
+ describe SkrillPayment do
4
4
 
5
5
  before do
6
6
  @payment = Payment.new
@@ -17,7 +17,7 @@ describe SkrillPayments do
17
17
  '<response><error><error_msg>M_AMOUNT</error_msg></error></response>'
18
18
  end
19
19
 
20
- describe '.pay!' do
20
+ describe '#pay!' do
21
21
 
22
22
  it 'raise error -> Prepare transfer error' do
23
23
 
@@ -25,7 +25,7 @@ describe SkrillPayments do
25
25
  with(headers: { 'Accept'=>'*/*' }).
26
26
  to_return(status: 200, body: @prepare_error_response, headers: {})
27
27
 
28
- expect{ SkrillPayments.pay!(@payment) }.to raise_error(SkrillPaymentsException)
28
+ expect{ @payment.pay! }.to raise_error(SkrillPaymentsException)
29
29
  end
30
30
 
31
31
  it 'raise error -> Execute transfer error' do
@@ -38,7 +38,7 @@ describe SkrillPayments do
38
38
  with(headers: { 'Accept'=>'*/*' }).
39
39
  to_return(status: 200, body: @execute_error_response, headers: {})
40
40
 
41
- expect{ SkrillPayments.pay!(@payment) }.to raise_error(SkrillPaymentsException)
41
+ expect{ @payment.pay! }.to raise_error(SkrillPaymentsException)
42
42
  end
43
43
 
44
44
  context 'success responses' do
@@ -55,12 +55,12 @@ describe SkrillPayments do
55
55
  end
56
56
 
57
57
  it 'returns true' do
58
- expect(SkrillPayments.pay!(@payment)).to eq true
58
+ expect(@payment.pay!).to eq true
59
59
  end
60
60
 
61
61
  it 'set attribute sid for payment' do
62
62
 
63
- SkrillPayments.pay!(@payment)
63
+ @payment.pay!
64
64
 
65
65
  expect(@payment.sid).to_not eq nil
66
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skrill_payments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: