skrill_payments 0.0.3 → 0.0.4

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.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [WIP] SkrillPayments
1
+ # SkrillPayments
2
2
 
3
3
  ## Installation
4
4
 
@@ -14,47 +14,47 @@ Or install it yourself as:
14
14
 
15
15
  $ gem install skrill_payments
16
16
 
17
- Create a configuration file for Scrill Payments.
17
+ Create a configuration file for Skrill Payments.
18
18
 
19
- $ touch config/initializers/scrill_payments.rb
19
+ $ touch config/initializers/skrill_payments.rb
20
20
 
21
- ```ruby
22
- Rails.configuration.scrill_payments_email = 'michal.macejko1@gmail.com'
23
- Rails.configuration.scrill_payments_password = '3427342378427834782347832' # MD5
24
- ```
21
+ With following content.
22
+
23
+ SkrillPayments.configure do |config|
24
+ config.email = 'michal.macejko1@gmail.com'
25
+ config.password = '2347237842346234623476276'
26
+ # your password in MD5
27
+ end
25
28
 
26
29
  ## Usage
27
30
 
31
+ ### SEND MONEY USING AN HTTPS REQUEST
32
+
28
33
  Put this code into your Payment class.
29
34
 
30
- ```ruby
31
- include ScrillPayment
32
- ```
35
+ include SkrillPayment
33
36
 
34
37
  Your payment class must contain all attributes/methods which is required for transfer money.
35
38
 
36
- ```ruby
37
- [:amount, :currency, :recipient_email, :subject, :note, :reference_id]
38
- # :reference_id is optional attribute
39
- ```
39
+ [:amount, :currency, :recipient_email, :subject, :note, :reference_id]
40
+ # :reference_id is optional attribute
40
41
 
41
42
  For example:
42
43
 
43
- ```ruby
44
44
  class Payment
45
45
 
46
- include ScrillPayment
46
+ include SkrillPayment
47
47
 
48
48
  def amount
49
49
  price + fees
50
50
  end
51
51
 
52
52
  def currency
53
- bank.czech? 'CZK' : 'ENG'
53
+ bank.czech? ? 'CZK' : 'ENG'
54
54
  end
55
55
 
56
56
  def recipient_email
57
- client.user
57
+ client.email
58
58
  end
59
59
 
60
60
  def subject
@@ -70,21 +70,18 @@ Create a configuration file for Scrill Payments.
70
70
  end
71
71
 
72
72
  end
73
- ```
74
73
 
75
74
  And in your controller just put the following code:
76
75
 
77
- ```ruby
78
76
  def pay_for_service
79
77
  payment = Payment.find(params[:id])
80
78
  begin
81
- ScrillPayment.pay!(payment)
82
- rescue => e
79
+ SkrillPayments.pay!(payment)
80
+ rescue SkrillPaymentsException => e
83
81
  # do stuff
84
82
  end
85
83
  redirect_to payments_path
86
84
  end
87
- ```
88
85
 
89
86
  ## Contributing
90
87
 
@@ -1,18 +1,16 @@
1
- class Api
1
+ module Api
2
2
 
3
3
  BASE_URL = 'https://www.moneybookers.com/app/pay.pl'
4
4
 
5
- attr_reader :conection, :payment
6
-
7
- def initialize
8
- @conection = Faraday.new(url: BASE_URL)
9
- end
5
+ attr_reader :payment
10
6
 
11
7
  def call
12
- response = conection.get '', params
8
+ response = connection.get '', params.merge(default_params)
13
9
  data = XmlSimple.xml_in(response.body)
14
10
 
15
- raise data['error'].inspect if data['error']
11
+ if data['error']
12
+ raise SkrillPaymentsException, data['error']
13
+ end
16
14
 
17
15
  data
18
16
  end
@@ -24,7 +22,7 @@ class Api
24
22
  attributes.each do |attribute|
25
23
  request_params[attribute] = object.send(attribute)
26
24
  end
27
- request_params.merge(default_params)
25
+ request_params
28
26
  end
29
27
 
30
28
  def default_params
@@ -34,4 +32,10 @@ class Api
34
32
  }
35
33
  end
36
34
 
35
+ private
36
+
37
+ def connection
38
+ Faraday.new(url: BASE_URL)
39
+ end
40
+
37
41
  end
@@ -1,10 +1,11 @@
1
- class ExecuteTransfer < Api
1
+ class ExecuteTransfer
2
+
3
+ include Api
2
4
 
3
5
  ATTRIBUTES = [:sid]
4
6
 
5
7
  def initialize(payment)
6
8
  @payment = payment
7
- super()
8
9
  end
9
10
 
10
11
  def params
@@ -1,10 +1,11 @@
1
- class PrepareTransfer < Api
1
+ class PrepareTransfer
2
+
3
+ include Api
2
4
 
3
5
  ATTRIBUTES = [:amount, :currency, :bnf_email, :subject, :note, :frn_trn_id]
4
6
 
5
7
  def initialize(payment)
6
8
  @payment = payment
7
- super()
8
9
  end
9
10
 
10
11
  def params
@@ -1,4 +1,4 @@
1
- module ScrillPayment
1
+ module SkrillPayment
2
2
 
3
3
  attr_accessor :sid
4
4
 
@@ -0,0 +1,2 @@
1
+ class SkrillPaymentsException < StandardError
2
+ end
@@ -1,3 +1,3 @@
1
1
  module SkrillPayments
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,11 +1,11 @@
1
1
  module SkrillPayments
2
2
 
3
3
  def self.pay!(payment)
4
- prepare_transfer = PrepareTransfer.new(payment).call
5
- payment.sid = prepare_transfer['sid'][0]
6
- execute_transfer = ExecuteTransfer.new(payment).call
4
+ prepare_transfer = PrepareTransfer.new(payment).call
7
5
 
8
- execute_transfer['transaction'][0]['status_msg'][0] == 'processed'
6
+ payment.sid = prepare_transfer['sid'][0]
7
+
8
+ !!ExecuteTransfer.new(payment).call
9
9
  end
10
10
 
11
11
  class << self
@@ -27,9 +27,10 @@ require 'skrill_payments/version'
27
27
 
28
28
  # GEM CLASS
29
29
  require 'skrill_payments/api'
30
- require 'skrill_payments/scrill_payment'
30
+ require 'skrill_payments/skrill_payment'
31
31
  require 'skrill_payments/prepare_transfer'
32
32
  require 'skrill_payments/execute_transfer'
33
+ require 'skrill_payments/skrill_payments_exception'
33
34
  require 'skrill_payments/configuration'
34
35
 
35
36
  # GEMS
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.3'
22
22
  spec.add_development_dependency 'rake'
23
23
  spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'webmock'
24
25
 
25
26
  spec.add_dependency('faraday')
26
27
  spec.add_dependency('xml-simple')
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ class Dummie
4
+ include Api
5
+ end
6
+
7
+ describe Api do
8
+
9
+ it 'creates params -> values from object, keys from attributes' do
10
+
11
+ object = double('Payment', currency: 'CZK', amount: 10, user_id: 20)
12
+ attributes = [:currency, :amount]
13
+ params = Dummie.new.send(:params, object, attributes)
14
+
15
+ expect(params).to eq({ currency: 'CZK', amount: 10 })
16
+ end
17
+
18
+ it 'creates default params from config' do
19
+
20
+ params = Dummie.new.send(:default_params)
21
+
22
+ expect(params).to eq(
23
+ {
24
+ email: 'michal.macejko1@gmail.com',
25
+ password: '2347237842346234623476276'
26
+ }
27
+ )
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe ExecuteTransfer do
4
+
5
+ before do
6
+ @payment = Payment.new
7
+ @payment.sid = '4234278347827823487'
8
+ @prepare_transfer = ExecuteTransfer.new(@payment)
9
+ end
10
+
11
+ it 'returns all required params' do
12
+
13
+ params = @prepare_transfer.params
14
+
15
+ ExecuteTransfer::ATTRIBUTES.each do |attribute|
16
+ expect(params.include?(attribute)).to eq true
17
+ end
18
+ end
19
+
20
+ it 'merge parent default params' do
21
+
22
+ expect(@prepare_transfer.default_params.include?(:email)).to eq true
23
+ end
24
+
25
+ it 'must contain specified attributes' do
26
+
27
+ expect(ExecuteTransfer::ATTRIBUTES).to_not eq nil
28
+ end
29
+ end
@@ -9,8 +9,20 @@ describe PrepareTransfer do
9
9
 
10
10
  it 'returns all required params' do
11
11
 
12
- @prepare_transfer.params
12
+ params = @prepare_transfer.params
13
13
 
14
+ PrepareTransfer::ATTRIBUTES.each do |attribute|
15
+ expect(params.include?(attribute)).to eq true
16
+ end
14
17
  end
15
18
 
19
+ it 'merge parent default params' do
20
+
21
+ expect(@prepare_transfer.default_params.include?(:email)).to eq true
22
+ end
23
+
24
+ it 'must contain specified attributes' do
25
+
26
+ expect(PrepareTransfer::ATTRIBUTES).to_not eq nil
27
+ end
16
28
  end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe SkrillPayments do
4
+
5
+ before do
6
+ @payment = Payment.new
7
+
8
+ @prepare_success_response = '<?xml version="1.0" encoding="UTF-8"?>' \
9
+ '<response><sid>5e281d1376d92ba789ca7f0583e045d4</sid> </response>'
10
+ @prepare_error_response = '<?xml version="1.0" encoding="UTF-8"?> ' \
11
+ '<response><error><error_msg>M_AMOUNT</error_msg></error></response>'
12
+ @execute_success_response = '<?xml version="1.0" encoding="UTF-8"?> ' \
13
+ '<response> <transaction><amount>1.20</amount> <currency>EUR</currency>' \
14
+ '<id>497029</id><status>2</status> <status_msg>processed</status_msg> ' \
15
+ '</transaction></response>'
16
+ @execute_error_response = '<?xml version="1.0" encoding="UTF-8"?> ' \
17
+ '<response><error><error_msg>M_AMOUNT</error_msg></error></response>'
18
+ end
19
+
20
+ describe '.pay!' do
21
+
22
+ it 'raise error -> Prepare transfer error' do
23
+
24
+ stub_request(:get, /action=prepare/).
25
+ with(headers: { 'Accept'=>'*/*' }).
26
+ to_return(status: 200, body: @prepare_error_response, headers: {})
27
+
28
+ expect{ SkrillPayments.pay!(@payment) }.to raise_error(SkrillPaymentsException)
29
+ end
30
+
31
+ it 'raise error -> Execute transfer error' do
32
+
33
+ stub_request(:get, /action=prepare/).
34
+ with(headers: { 'Accept'=>'*/*' }).
35
+ to_return(status: 200, body: @prepare_success_response, headers: {})
36
+
37
+ stub_request(:get, /action=transfer/).
38
+ with(headers: { 'Accept'=>'*/*' }).
39
+ to_return(status: 200, body: @execute_error_response, headers: {})
40
+
41
+ expect{ SkrillPayments.pay!(@payment) }.to raise_error(SkrillPaymentsException)
42
+ end
43
+
44
+ context 'success responses' do
45
+
46
+ before do
47
+
48
+ stub_request(:get, /action=prepare/).
49
+ with(headers: { 'Accept'=>'*/*' }).
50
+ to_return(status: 200, body: @prepare_success_response, headers: {})
51
+
52
+ stub_request(:get, /action=transfer/).
53
+ with(headers: { 'Accept'=>'*/*' }).
54
+ to_return(status: 200, body: @execute_success_response, headers: {})
55
+ end
56
+
57
+ it 'returns true' do
58
+ expect(SkrillPayments.pay!(@payment)).to eq true
59
+ end
60
+
61
+ it 'set attribute sid for payment' do
62
+
63
+ SkrillPayments.pay!(@payment)
64
+
65
+ expect(@payment.sid).to_not eq nil
66
+ end
67
+ end
68
+ end
69
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
4
  require 'skrill_payments'
5
+ require 'webmock/rspec'
5
6
 
6
7
  RSpec.configure do |config|
7
8
  end
@@ -10,4 +11,5 @@ end
10
11
  require File.expand_path('../support/config.rb', __FILE__)
11
12
  require File.expand_path('../support/payment.rb', __FILE__)
12
13
 
14
+ WebMock.disable_net_connect!(allow_localhost: true)
13
15
 
@@ -1,5 +1,5 @@
1
1
  class Payment
2
- include ScrillPayment
2
+ include SkrillPayment
3
3
 
4
4
  def amount
5
5
  10
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-25 00:00:00.000000000 Z
12
+ date: 2014-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: webmock
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: faraday
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -108,10 +124,14 @@ files:
108
124
  - lib/skrill_payments/configuration.rb
109
125
  - lib/skrill_payments/execute_transfer.rb
110
126
  - lib/skrill_payments/prepare_transfer.rb
111
- - lib/skrill_payments/scrill_payment.rb
127
+ - lib/skrill_payments/skrill_payment.rb
128
+ - lib/skrill_payments/skrill_payments_exception.rb
112
129
  - lib/skrill_payments/version.rb
113
130
  - skrill_payments.gemspec
131
+ - spec/models/api_spec.rb
132
+ - spec/models/execute_transfer_spec.rb
114
133
  - spec/models/prepare_transfer_spec.rb
134
+ - spec/models/skrill_payments_spec.rb
115
135
  - spec/spec_helper.rb
116
136
  - spec/support/config.rb
117
137
  - spec/support/payment.rb
@@ -141,7 +161,10 @@ signing_key:
141
161
  specification_version: 3
142
162
  summary: Skrill payments
143
163
  test_files:
164
+ - spec/models/api_spec.rb
165
+ - spec/models/execute_transfer_spec.rb
144
166
  - spec/models/prepare_transfer_spec.rb
167
+ - spec/models/skrill_payments_spec.rb
145
168
  - spec/spec_helper.rb
146
169
  - spec/support/config.rb
147
170
  - spec/support/payment.rb