skrill-payment 0.3.3

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.
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order random
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Envato
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # Skrill::Payment
2
+
3
+ Skrill::Payment is a Ruby library that uses Skrills (formerly Moneybookers) Automated Payments Interface to perform payments.
4
+
5
+ ## Usage
6
+
7
+ #### Configure
8
+
9
+ ``` ruby
10
+ Skrill::Payment.configure do |config|
11
+ config.merchant_email = 'your_email'
12
+ config.merchant_password = 'your_api_password'
13
+ config.subject = 'Payment'
14
+ config.note = 'Your monthly payment'
15
+ config.currency = 'USD'
16
+ config.http_proxy = 'http://user:pass@hostname:port'
17
+ end
18
+ ```
19
+
20
+ #### Make A Payment
21
+
22
+ ``` ruby
23
+ payment = Skrill::Payment.new do |payee|
24
+ payee.email = 'customer@example.com'
25
+ payee.amount = 10.00
26
+
27
+ # optional
28
+ payee.identifier = 123
29
+ end
30
+
31
+ request = payment.deliver
32
+
33
+ request.successful?
34
+ # => true/false
35
+
36
+ request.error_message
37
+ # => Error message/nil
38
+
39
+ request.status_id
40
+ # => transaction status id in Skrill (1 = transaction scheduled, 2 = transaction processed)
41
+
42
+ request.status_message
43
+ # => transaction status message in Skrill
44
+
45
+ request.transation_id
46
+ # => transaction id
47
+ ```
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,78 @@
1
+ require 'skrill/payment/version'
2
+ require 'skrill/payment/utils'
3
+ require 'skrill/payment/configuration'
4
+ require 'skrill/payment/request'
5
+
6
+ require 'active_support/core_ext'
7
+
8
+ module Skrill
9
+ class Payment
10
+ include Utils
11
+
12
+ OPTIONS = [:email, :amount, :identifier]
13
+
14
+ attr_accessor *OPTIONS
15
+
16
+ # Prepares a new payment using the configuration attributes when provided
17
+ # and the payment attributes. The configuration attributes can be
18
+ # overwritten by using in the same Hash keys or methods. Attributes can
19
+ # be passed in by using a block or a Hash.
20
+ #
21
+ # @example Prepare a new payment using a block.
22
+ # Skrill::Payment.new do |payee|
23
+ # payee.email = 'customer@example.com'
24
+ # payee.amount = 10.00
25
+ # end
26
+ #
27
+ # @example Prepare a new payment using a Hash.
28
+ # Skrill::Payment.new(email: 'customer@example.com', amount: 10.00)
29
+ #
30
+ # @return [ Skrill::Payment ] The payment object.
31
+ #
32
+ # @since 0.1.0
33
+ def initialize(payment_data = {}, &block)
34
+ assign_attirbutes(payment_data)
35
+
36
+ yield(self) if block_given?
37
+ end
38
+
39
+ # Sends a payment request to Skrill. Use the `successful?` method to
40
+ # check if the Skrill was able to process the payment successfully.
41
+ #
42
+ # @return [ Request ] The request object.
43
+ #
44
+ # @since 0.1.0
45
+ def deliver
46
+ @request = Skrill::Payment::Request.post(config_data, payment_data)
47
+ end
48
+
49
+ # Checks if the payment has been delivered and was successful.
50
+ #
51
+ # @return [ true, false ] The payment success status.
52
+ #
53
+ # @since 0.1.0
54
+ def successful?
55
+ !!@request && @request.successful?
56
+ end
57
+
58
+ # Returns the error message from Skrill or nil when the payment was
59
+ # successful.
60
+ #
61
+ # @return [ String, nil ] The error message or nil.
62
+ #
63
+ # @since 0.2.0
64
+ def error_message
65
+ @request.error_message
66
+ end
67
+
68
+ private
69
+
70
+ def config_data
71
+ Configuration.serialized_data
72
+ end
73
+
74
+ def payment_data
75
+ serialize_arguments(OPTIONS)
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,42 @@
1
+ module Skrill
2
+ class Payment::Configuration
3
+ OPTIONS = [:merchant_email, :merchant_password, :currency, :subject, :note, :http_proxy]
4
+
5
+ class << self
6
+ include Skrill::Payment::Utils
7
+
8
+ attr_accessor *OPTIONS
9
+
10
+ # Sets the Skrill::Payment::Configuration options. Attributes can be
11
+ # passed in by using a block or a Hash. The Skrill API expects the
12
+ # merchant password to be a MD5 hash generated from the password
13
+ # entered in the Skrill developer settings page.
14
+ #
15
+ # @example Set a configuration option.
16
+ # Skrill::Payment::Configuration.configure do |config|
17
+ # config.merchant_email = 'merchant@example.com'
18
+ # config.merchant_password = '7813258ef8c6b632dde8cc80f6bda62f'
19
+ # end
20
+ #
21
+ # @return [ Configuration ] The configuration object.
22
+ #
23
+ # @since 0.1.0
24
+ def configure(options = {}, &block)
25
+ Skrill::Payment::Configuration.tap do |config|
26
+ options.each { |option, value| config.public_send("#{option}=", value) }
27
+
28
+ yield(config) if block_given?
29
+ end
30
+ end
31
+
32
+ # Returns all Skrill::Payment::Configuration options in a Hash.
33
+ #
34
+ # @return [ Hash ] The configuration options.
35
+ #
36
+ # @since 0.1.0
37
+ def serialized_data
38
+ serialize_arguments(OPTIONS)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,115 @@
1
+ require 'faraday'
2
+
3
+ module Skrill
4
+ class Payment::Request
5
+ API_HOST = 'https://www.moneybookers.com'
6
+ API_PATH = '/app/pay.pl'
7
+
8
+ OPTIONS_MAPPING = {
9
+ amount: :amount,
10
+ currency: :currency,
11
+ email: :bnf_email,
12
+ identifier: :frn_trn_id,
13
+ merchant_email: :email,
14
+ merchant_password: :password,
15
+ note: :note,
16
+ subject: :subject,
17
+ }
18
+
19
+ def self.post(*data)
20
+ new(*data).post
21
+ end
22
+
23
+ attr_reader :request_data, :error_message, :status_id, :status_message, :transation_id
24
+
25
+ def initialize(config_data, payment_data)
26
+ @http_proxy = config_data.delete(:http_proxy)
27
+ @request_data = map_data(config_data.merge(payment_data))
28
+ end
29
+
30
+ def post
31
+ self.tap do
32
+ response = send_payment_preparation
33
+ session_identifier = response['sid']
34
+
35
+ if session_identifier.present?
36
+ response = send_payment_confirmation(session_identifier)
37
+ check_payment_status(response)
38
+ else
39
+ save_error(response)
40
+ end
41
+ end
42
+ end
43
+
44
+ # Checks if the request has been delivered and was successful.
45
+ #
46
+ # @return [ true, false ] The payment success status.
47
+ #
48
+ # @since 0.2.1
49
+ def successful?
50
+ error_message.nil?
51
+ end
52
+
53
+ private
54
+
55
+ def map_data(input_data)
56
+ input_data.tap do |data|
57
+ OPTIONS_MAPPING.each do |given_key, api_key|
58
+ value = data.delete(given_key)
59
+ data[api_key] = value if value
60
+ end
61
+ end
62
+ end
63
+
64
+ def send_payment_preparation
65
+ preparation_data = request_data.merge(action: 'prepare')
66
+ raw_response = connection.post(API_PATH, preparation_data)
67
+ parse_response(raw_response)
68
+ end
69
+
70
+ def send_payment_confirmation(session_identifier)
71
+ confirmation_data = {sid: session_identifier, action: 'transfer'}
72
+ raw_response = connection.post(API_PATH, confirmation_data)
73
+ parse_response(raw_response)
74
+ end
75
+
76
+ def parse_response(response)
77
+ Hash.from_xml(response.body)['response']
78
+ end
79
+
80
+ def check_payment_status(response)
81
+ transaction = response['transaction']
82
+
83
+ if transaction.blank?
84
+ save_error(response)
85
+ else
86
+ save_transation_details(transaction)
87
+ end
88
+ end
89
+
90
+ def save_transation_details(transaction)
91
+ @status_id = transaction['status'].to_i
92
+ @status_message = transaction['status_msg']
93
+ @transation_id = transaction['id'].to_i
94
+ end
95
+
96
+ def save_error(response)
97
+ @error_message = response['error']['error_msg']
98
+ end
99
+
100
+ def connection
101
+ @connection ||= Faraday.new(API_HOST, connection_params) do |con|
102
+ con.use(Faraday::Request::UrlEncoded)
103
+ con.use(Faraday::Adapter::NetHttp)
104
+ end
105
+ end
106
+
107
+ def connection_params
108
+ if @http_proxy.present?
109
+ { :proxy => @http_proxy }
110
+ else
111
+ {}
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,17 @@
1
+ module Skrill
2
+ class Payment
3
+ module Utils
4
+ def assign_attirbutes(attributes)
5
+ attributes.each { |attribute, value| public_send("#{attribute}=", value) }
6
+ end
7
+
8
+ def serialize_arguments(arguments)
9
+ arguments.inject({}) do |serialized_data, argument|
10
+ value = public_send(argument)
11
+ serialized_data[argument] = value if value
12
+ serialized_data
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Skrill
2
+ class Payment
3
+ VERSION = '0.3.' + (ENV['BUILD_VERSION'] || '0')
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'skrill/payment/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'skrill-payment'
8
+ gem.version = Skrill::Payment::VERSION
9
+ gem.authors = ['Martin Jagusch', 'Shervin Aflatooni']
10
+ gem.email = ['_@mj.io', 'shervinaflatooni@gmail.com']
11
+ gem.description = 'Making payments via Skrill (formerly Moneybookers)'
12
+ gem.summary = "skrill-payment-#{Skrill::Payment::VERSION}"
13
+ gem.homepage = 'https://github.com/envato/skrill-payment'
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files -z`.split("\x0")
17
+ gem.test_files = gem.files.grep(%r{^spec/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'activesupport', '>= 2.3'
21
+ gem.add_dependency 'faraday', '~> 0.9'
22
+
23
+ gem.add_development_dependency 'rake', '~> 10.0'
24
+ gem.add_development_dependency 'rspec', '~> 3.0.0.beta2'
25
+ gem.add_development_dependency 'webmock', '~> 1.17'
26
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'performing a payment' do
4
+ let(:prepare_payment_response) { load_response(:successful_payment_prepare) }
5
+ let(:comfirm_payment_response) { load_response(:successful_payment_confirmaton) }
6
+
7
+ let(:api_uri) { [Skrill::Payment::Request::API_HOST, Skrill::Payment::Request::API_PATH].join }
8
+
9
+ let(:payment_preparation_data) do
10
+ {
11
+ action: 'prepare',
12
+ email: 'bacon@email.com',
13
+ password: 'secretbacon',
14
+ currency: 'USD',
15
+ subject: 'You will get paid!',
16
+ note: 'a note!',
17
+ bnf_email: 'customer@example.com',
18
+ amount: '10.0',
19
+ frn_trn_id: '1234'
20
+ }
21
+ end
22
+
23
+ let(:payment_finalize_data) do
24
+ {
25
+ action: 'transfer',
26
+ sid: 'f1c08339b7c6b2084c8c83183045b0a1'
27
+ }
28
+ end
29
+
30
+ before do
31
+ stub_request(:post, api_uri).with(body: payment_preparation_data).to_return(body: prepare_payment_response)
32
+ stub_request(:post, api_uri).with(body: payment_finalize_data).to_return(body: comfirm_payment_response)
33
+
34
+ Skrill::Payment::Configuration.configure do |config|
35
+ config.merchant_email = 'bacon@email.com'
36
+ config.merchant_password = 'secretbacon'
37
+ config.currency = 'USD'
38
+ config.subject = 'You will get paid!'
39
+ config.note = 'a note!'
40
+ end
41
+ end
42
+
43
+ context 'Providing details via a block' do
44
+ let(:payment) do
45
+ Skrill::Payment.new do |payee|
46
+ payee.email = 'customer@example.com'
47
+ payee.amount = 10.00
48
+ payee.identifier = 1234
49
+ end
50
+ end
51
+
52
+ context 'when the payment was successful' do
53
+ it 'sends the correct data to Skrill and is successful' do
54
+ payment.deliver
55
+ expect(payment).to be_successful
56
+ end
57
+
58
+ it 'has no error' do
59
+ payment.deliver
60
+ expect(payment.error_message).to be_nil
61
+ end
62
+ end
63
+
64
+ context 'when the prepare payment was not successful' do
65
+ let(:prepare_payment_response) { load_response(:unsuccessful_payment_prepare) }
66
+
67
+ it 'it is not successful' do
68
+ payment.deliver
69
+ expect(payment).to_not be_successful
70
+ end
71
+
72
+ it 'has an error' do
73
+ payment.deliver
74
+ expect(payment.error_message).to_not be_nil
75
+ end
76
+ end
77
+
78
+ context 'when the comfirm payment was not successful' do
79
+ let(:comfirm_payment_response) { load_response(:unsuccessful_payment_confirmaton) }
80
+
81
+ it 'it is not successful' do
82
+ payment.deliver
83
+ expect(payment).to_not be_successful
84
+ end
85
+
86
+ it 'has an error' do
87
+ payment.deliver
88
+ expect(payment.error_message).to_not be_nil
89
+ end
90
+ end
91
+ end
92
+
93
+ context 'Providing details via a Hash' do
94
+ let(:payment) { Skrill::Payment.new(email: 'customer@example.com', amount: 10.00, identifier: 1234) }
95
+
96
+ context 'when the payment was successful' do
97
+ it 'sends the correct data to skrill and is successful' do
98
+ payment.deliver
99
+ expect(payment).to be_successful
100
+ end
101
+
102
+ it 'has no error' do
103
+ payment.deliver
104
+ expect(payment.error_message).to be_nil
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Skrill::Payment::Configuration do
4
+ shared_examples_for 'an option' do
5
+ after do
6
+ Skrill::Payment::Configuration.configure do |config|
7
+ config.public_send("#{option}=", nil)
8
+ end
9
+ end
10
+
11
+ context 'when a Hash is given' do
12
+ before do
13
+ Skrill::Payment::Configuration.configure(option => value)
14
+ end
15
+
16
+ specify { expect(Skrill::Payment::Configuration.public_send(option)).to eq(value) }
17
+ end
18
+
19
+ context 'when a block is given' do
20
+ before do
21
+ Skrill::Payment::Configuration.configure do |config|
22
+ config.public_send("#{option}=", value)
23
+ end
24
+ end
25
+
26
+ specify { expect(Skrill::Payment::Configuration.public_send(option)).to eq(value) }
27
+ end
28
+
29
+ context 'when value is not defined' do
30
+ let(:value) { nil }
31
+ specify { expect(Skrill::Payment::Configuration.public_send(option)).to eq(nil) }
32
+ end
33
+ end
34
+
35
+ describe '.merchant_email' do
36
+ it_should_behave_like 'an option' do
37
+ let(:option) { :merchant_email }
38
+ let(:value) { 'merchant@example.com' }
39
+ end
40
+ end
41
+
42
+ describe '.merchant_password' do
43
+ it_should_behave_like 'an option' do
44
+ let(:option) { :merchant_password }
45
+ let(:value) { '7813258ef8c6b632dde8cc80f6bda62f' }
46
+ end
47
+ end
48
+
49
+ describe '.currency' do
50
+ it_should_behave_like 'an option' do
51
+ let(:option) { :currency }
52
+ let(:value) { 'AUD' }
53
+ end
54
+ end
55
+
56
+ describe '.subject' do
57
+ it_should_behave_like 'an option' do
58
+ let(:option) { :subject }
59
+ let(:value) { 'Your bacon is ready' }
60
+ end
61
+ end
62
+
63
+ describe '.note' do
64
+ it_should_behave_like 'an option' do
65
+ let(:option) { :note }
66
+ let(:value) { 'More bacon is available on our website.' }
67
+ end
68
+ end
69
+
70
+ describe '.http_proxy' do
71
+ it_should_behave_like 'an option' do
72
+ let(:option) { :http_proxy }
73
+ let(:value) { 'More proxy' }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe Skrill::Payment::Request do
4
+ describe '.post' do
5
+ let(:api_uri) { [described_class::API_HOST, described_class::API_PATH].join }
6
+ let(:config_data) { {} }
7
+
8
+ after do
9
+ WebMock.reset!
10
+ end
11
+
12
+ context 'when sending a valid payment' do
13
+ before do
14
+ stub_request(:post, api_uri).with(body: {action: 'prepare', bacon: 'such taste'}).to_return(body: load_response(:successful_payment_prepare))
15
+ stub_request(:post, api_uri).with(body: {action: 'transfer', sid: 'f1c08339b7c6b2084c8c83183045b0a1'}).to_return(body: load_response(:successful_payment_confirmaton))
16
+ end
17
+
18
+ it 'returns the payment trasaction status id' do
19
+ expect(Skrill::Payment::Request.post(config_data, bacon: 'such taste').status_id).to eq(2)
20
+ end
21
+
22
+ it 'returns the payment trasaction status message' do
23
+ expect(Skrill::Payment::Request.post(config_data, bacon: 'such taste').status_message).to eq('processed')
24
+ end
25
+
26
+ it 'returns the payment trasaction id' do
27
+ expect(Skrill::Payment::Request.post(config_data, bacon: 'such taste').transation_id).to eq(1136226461)
28
+ end
29
+
30
+ it 'has no error message' do
31
+ expect(Skrill::Payment::Request.post(config_data, bacon: 'such taste').error_message).to eq(nil)
32
+ end
33
+
34
+ it 'prepares the payment' do
35
+ Skrill::Payment::Request.post(config_data, bacon: 'such taste')
36
+
37
+ expect(WebMock).to have_requested(:post, api_uri).with(body: {action: 'prepare', bacon: 'such taste'}).once
38
+ end
39
+
40
+ it 'confirms the payment' do
41
+ Skrill::Payment::Request.post(config_data, bacon: 'such taste')
42
+
43
+ expect(WebMock).to have_requested(:post, api_uri).with(body: {action: 'transfer', sid: 'f1c08339b7c6b2084c8c83183045b0a1'}).once
44
+ end
45
+
46
+ it 'is successful' do
47
+ expect(Skrill::Payment::Request.post(config_data, bacon: 'such taste')).to be_successful
48
+ end
49
+
50
+ context 'when the given option names are used' do
51
+ let(:config_data) { {merchant_email: 'merchant@example.com'} }
52
+ let(:reqest_data) { {email: 'customer@example.com', identifier: '123'} }
53
+
54
+ before do
55
+ stub_request(:post, api_uri).with(body: {action: 'prepare', email: 'merchant@example.com', bnf_email: 'customer@example.com', frn_trn_id: '123'}).to_return(body: load_response(:successful_payment_prepare))
56
+ end
57
+
58
+ it 'maps the given option name to the API options' do
59
+ Skrill::Payment::Request.post(config_data, reqest_data)
60
+
61
+ expect(WebMock).to have_requested(:post, api_uri).with(body: {action: 'prepare', email: 'merchant@example.com', bnf_email: 'customer@example.com', frn_trn_id: '123'}).once
62
+ end
63
+ end
64
+
65
+ context 'when config options are set' do
66
+ let(:config_data) { {secret: 'such chunky'} }
67
+
68
+ before do
69
+ stub_request(:post, api_uri).with(body: {action: 'prepare', bacon: 'such taste', secret: 'such chunky'}).to_return(body: load_response(:successful_payment_prepare))
70
+ stub_request(:post, api_uri).with(body: {action: 'prepare', secret: 'foul chunky'}).to_return(body: load_response(:successful_payment_prepare))
71
+ end
72
+
73
+ it 'includes the config options' do
74
+ Skrill::Payment::Request.post(config_data, bacon: 'such taste')
75
+
76
+ expect(WebMock).to have_requested(:post, api_uri).with(body: {action: 'prepare', bacon: 'such taste', secret: 'such chunky'}).once
77
+ end
78
+
79
+ it 'overrides the config options' do
80
+ Skrill::Payment::Request.post(config_data, secret: 'foul chunky')
81
+
82
+ expect(WebMock).to have_requested(:post, api_uri).with(body: {action: 'prepare', secret: 'foul chunky'}).once
83
+ end
84
+ end
85
+ end
86
+
87
+ context 'when the prepare request is invalid' do
88
+ before do
89
+ stub_request(:post, api_uri).with(body: {action: 'prepare', bacon: 'such taste'}).to_return(body: load_response(:unsuccessful_payment_prepare))
90
+ end
91
+
92
+ it 'has an error message' do
93
+ expect(Skrill::Payment::Request.post(config_data, bacon: 'such taste').error_message).to eq('MISSING_AMOUNT')
94
+ end
95
+
96
+ it 'is not successful' do
97
+ expect(Skrill::Payment::Request.post(config_data, bacon: 'such taste')).to_not be_successful
98
+ end
99
+ end
100
+
101
+ context 'when the confirm request is invalid' do
102
+ before do
103
+ stub_request(:post, api_uri).with(body: {action: 'prepare', bacon: 'such taste'}).to_return(body: load_response(:successful_payment_prepare))
104
+ stub_request(:post, api_uri).with(body: {action: 'transfer', sid: 'f1c08339b7c6b2084c8c83183045b0a1'}).to_return(body: load_response(:unsuccessful_payment_confirmaton))
105
+ end
106
+
107
+ it 'has an error message' do
108
+ expect(Skrill::Payment::Request.post(config_data, bacon: 'such taste').error_message).to eq('SESSION_EXPIRED')
109
+ end
110
+
111
+ it 'is not successful' do
112
+ expect(Skrill::Payment::Request.post(config_data, bacon: 'such taste')).to_not be_successful
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Skrill::Payment do
4
+ let(:payment) do
5
+ Skrill::Payment.new do |payee|
6
+ payee.email = 'customer@example.com'
7
+ end
8
+ end
9
+
10
+ let(:request) { double(error_message: error_message, successful?: successful) }
11
+ let(:error_message) { nil }
12
+ let(:successful) { true }
13
+
14
+ before do
15
+ allow(Skrill::Payment::Request).to receive(:post).and_return(request)
16
+ allow(Skrill::Payment::Configuration).to receive(:serialized_data).and_return(subject: 'Bacon Coins')
17
+ end
18
+
19
+ describe '#deliver' do
20
+ context 'when providing a block' do
21
+ it 'sends a payment request' do
22
+ expect(Skrill::Payment::Request).to receive(:post).with({subject: 'Bacon Coins'}, {email: 'customer@example.com'})
23
+
24
+ payment.deliver
25
+ end
26
+ end
27
+
28
+ context 'when providing a Hash' do
29
+ let(:payment) { Skrill::Payment.new(email: 'customer@example.com') }
30
+
31
+ it 'sends a payment request' do
32
+ expect(Skrill::Payment::Request).to receive(:post).with({subject: 'Bacon Coins'}, {email: 'customer@example.com'})
33
+
34
+ payment.deliver
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '#successful?' do
40
+ context 'when the payment was successful' do
41
+ it 'returns true' do
42
+ payment.deliver
43
+
44
+ expect(payment).to be_successful
45
+ end
46
+ end
47
+
48
+ context 'when the payment was not successful' do
49
+ let(:error_message) { 'bacon not found' }
50
+ let(:successful) { false }
51
+
52
+ it 'returns false' do
53
+ payment.deliver
54
+
55
+ expect(payment).to_not be_successful
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '#error' do
61
+ context 'when the payment was successful' do
62
+ it 'returns nil' do
63
+ payment.deliver
64
+
65
+ expect(payment.error_message).to be_nil
66
+ end
67
+ end
68
+
69
+ context 'when the payment was not successful' do
70
+ let(:error_message) { 'bacon not found' }
71
+ let(:successful) { false }
72
+
73
+ it 'returns an error message' do
74
+ payment.deliver
75
+
76
+ expect(payment.error_message).to eq('bacon not found')
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <response>
3
+ <transaction>
4
+ <amount>25.00</amount>
5
+ <currency>USD</currency>
6
+ <id>1136226461</id>
7
+ <status>2</status>
8
+ <status_msg>processed</status_msg>
9
+ </transaction>
10
+ </response>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <response>
3
+ <sid>f1c08339b7c6b2084c8c83183045b0a1</sid>
4
+ </response>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <response>
3
+ <error>
4
+ <error_msg>SESSION_EXPIRED</error_msg>
5
+ </error>
6
+ </response>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <response>
3
+ <error>
4
+ <error_msg>MISSING_AMOUNT</error_msg>
5
+ </error>
6
+ </response>
@@ -0,0 +1,11 @@
1
+ lib = File.expand_path('../../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'skrill/payment'
5
+ require 'webmock/rspec'
6
+ require 'rspec'
7
+
8
+ def load_response(file_name)
9
+ path = File.expand_path "./skrill/support", File.dirname(__FILE__)
10
+ open("#{path}/#{file_name}.xml", &:read)
11
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: skrill-payment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Martin Jagusch
9
+ - Shervin Aflatooni
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-09-09 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '2.3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '2.3'
31
+ - !ruby/object:Gem::Dependency
32
+ name: faraday
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '0.9'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '0.9'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 3.0.0.beta2
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 3.0.0.beta2
79
+ - !ruby/object:Gem::Dependency
80
+ name: webmock
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: '1.17'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '1.17'
95
+ description: Making payments via Skrill (formerly Moneybookers)
96
+ email:
97
+ - _@mj.io
98
+ - shervinaflatooni@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - .rspec
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/skrill/payment.rb
110
+ - lib/skrill/payment/configuration.rb
111
+ - lib/skrill/payment/request.rb
112
+ - lib/skrill/payment/utils.rb
113
+ - lib/skrill/payment/version.rb
114
+ - skrill-payment.gemspec
115
+ - spec/skrill/integration/payment_spec.rb
116
+ - spec/skrill/payment/configuration_spec.rb
117
+ - spec/skrill/payment/request_spec.rb
118
+ - spec/skrill/payment_spec.rb
119
+ - spec/skrill/support/successful_payment_confirmaton.xml
120
+ - spec/skrill/support/successful_payment_prepare.xml
121
+ - spec/skrill/support/unsuccessful_payment_confirmaton.xml
122
+ - spec/skrill/support/unsuccessful_payment_prepare.xml
123
+ - spec/spec_helper.rb
124
+ homepage: https://github.com/envato/skrill-payment
125
+ licenses:
126
+ - MIT
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 1.8.21
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: skrill-payment-0.3.3
149
+ test_files:
150
+ - spec/skrill/integration/payment_spec.rb
151
+ - spec/skrill/payment/configuration_spec.rb
152
+ - spec/skrill/payment/request_spec.rb
153
+ - spec/skrill/payment_spec.rb
154
+ - spec/skrill/support/successful_payment_confirmaton.xml
155
+ - spec/skrill/support/successful_payment_prepare.xml
156
+ - spec/skrill/support/unsuccessful_payment_confirmaton.xml
157
+ - spec/skrill/support/unsuccessful_payment_prepare.xml
158
+ - spec/spec_helper.rb