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 +19 -5
- data/lib/skrill_payments.rb +0 -8
- data/lib/skrill_payments/api.rb +4 -4
- data/lib/skrill_payments/execute_transfer.rb +3 -4
- data/lib/skrill_payments/prepare_transfer.rb +3 -4
- data/lib/skrill_payments/skrill_payment.rb +8 -0
- data/lib/skrill_payments/version.rb +1 -1
- data/spec/models/api_spec.rb +23 -4
- data/spec/models/skrill_payments_spec.rb +6 -6
- metadata +1 -1
data/README.md
CHANGED
@@ -28,18 +28,18 @@ With following content.
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
-
|
31
|
+
### SEND MONEY USING AN HTTPS REQUEST
|
32
32
|
|
33
|
-
|
33
|
+
Put this code into your Payment class.
|
34
34
|
|
35
35
|
include SkrillPayment
|
36
36
|
|
37
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/skrill_payments.rb
CHANGED
data/lib/skrill_payments/api.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
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 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
|
data/spec/models/api_spec.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class Dummie
|
4
|
-
|
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
|
-
|
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
|
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 '
|
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{
|
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{
|
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(
|
58
|
+
expect(@payment.pay!).to eq true
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'set attribute sid for payment' do
|
62
62
|
|
63
|
-
|
63
|
+
@payment.pay!
|
64
64
|
|
65
65
|
expect(@payment.sid).to_not eq nil
|
66
66
|
end
|