bancard 0.0.2 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f13b1d6e7668299a1c551c13d6fac23430b96ce1
4
- data.tar.gz: 7ce02e1a003c4b257522a4570732f96029b357c2
3
+ metadata.gz: 413ea713cbd7c46c069a2a1a8c77704f57dcbbb6
4
+ data.tar.gz: 22239d240080fd002c421f3b9f2c1ca55fb8a14c
5
5
  SHA512:
6
- metadata.gz: a3ac36cc9118564834570421a9582ace87f8a0faaf9085c1fdaef7b02a18247127ed0be4823bf259dcf7b0c0a1084c76b662f94d065710385e0a2f01e5856e4f
7
- data.tar.gz: 69a08d4849ce13aad0e9a6323f389611809ce37ba7f6fd1df893782642c024baa7b2415a156400bcad13f991f3b01e23861a0e25365e92d034ec0f2e0bb230ca
6
+ metadata.gz: b4361ee0426e13da6be0d06b61159c8213f8d7ac44988dd3245fd1fc7de774d028d898f2650f337b6490e088333d67582b2b58067908c82d8ed62e9ba999f1cc
7
+ data.tar.gz: c38f03eec45efe01cf7304bca7aedf2bd9fe8e8e665be7288dcc1b41034817786c9713ae4ea7404f3cc826c32ebfd20806758c9919ee9eef5be4f6af9e0117e9
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.4
1
+ 2.1.5
data/CHANGELOG.md CHANGED
@@ -1,2 +1,5 @@
1
+ # 2014-12-09 - 0.0.3
2
+ - Implement `#rollback` for `Gateway`
3
+
1
4
  # 2014-11-19 - 0.0.2
2
5
  - Rename `Bancard.test=` to `Bancard.sandbox!`
data/lib/bancard.rb CHANGED
@@ -6,6 +6,8 @@ require 'bancard/version'
6
6
  require 'bancard/utils'
7
7
  require 'bancard/single_buy_init'
8
8
  require 'bancard/single_buy_init_response'
9
+ require 'bancard/single_buy_rollback'
10
+ require 'bancard/single_buy_rollback_response'
9
11
  require 'bancard/gateway'
10
12
 
11
13
  module Bancard
@@ -8,22 +8,37 @@ module Bancard
8
8
  end
9
9
 
10
10
  def single_buy(params = {})
11
- init = single_buy_init(params)
11
+ init = build_single_buy_init(params)
12
12
  submit_single_buy_init(init)
13
13
  end
14
14
 
15
+ def rollback(params = {})
16
+ rollback = build_single_buy_rollback(params)
17
+ submit_single_buy_rollback(rollback)
18
+ end
19
+
15
20
  private
16
21
 
17
- def single_buy_init(params = {})
22
+ def build_single_buy_init(params = {})
18
23
  Bancard::SingleBuyInit.new(merge_auth_params(params))
19
24
  end
20
25
 
26
+ def build_single_buy_rollback(params = {})
27
+ Bancard::SingleBuyRollback.new(merge_auth_params(params))
28
+ end
29
+
21
30
  def submit_single_buy_init(init)
22
31
  url = Bancard.vpos_url(Bancard::SingleBuyInit::ENDPOINT)
23
32
  response = Typhoeus.post(url, body: init.request_params.to_json)
24
33
  Bancard::SingleBuyInitResponse.new response
25
34
  end
26
35
 
36
+ def submit_single_buy_rollback(rollback)
37
+ url = Bancard.vpos_url(Bancard::SingleBuyRollback::ENDPOINT)
38
+ response = Typhoeus.post(url, body: rollback.request_params.to_json)
39
+ Bancard::SingleBuyRollbackResponse.new response
40
+ end
41
+
27
42
  def merge_auth_params(hash)
28
43
  hash.merge(public_key: public_key, private_key: private_key)
29
44
  end
@@ -0,0 +1,38 @@
1
+ module Bancard
2
+ class SingleBuyRollback
3
+ include Bancard::Utils
4
+ ENDPOINT = '/vpos/api/0.3/single_buy/rollback'
5
+
6
+ attr_accessor :given_params, :public_key, :private_key
7
+
8
+ def initialize(given_params = {})
9
+ @given_params = stringify_keys(given_params)
10
+ @public_key = @given_params.delete('public_key')
11
+ @private_key = @given_params.delete('private_key')
12
+ end
13
+
14
+ def request_params
15
+ {
16
+ operation: operation_params,
17
+ public_key: public_key,
18
+ }
19
+ end
20
+
21
+ def operation_params
22
+ {
23
+ shop_process_id: shop_process_id,
24
+ token: token,
25
+ }
26
+ end
27
+
28
+ private
29
+
30
+ def shop_process_id
31
+ given_params['shop_process_id']
32
+ end
33
+
34
+ def token
35
+ Digest::MD5.hexdigest [private_key, shop_process_id, 'rollback', '0.00'].join('')
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ # works like ActiveMerchant::Billing::Response to maintain compatibility to
2
+ # active merchant gateways
3
+
4
+ module Bancard
5
+ class SingleBuyRollbackResponse
6
+ attr_reader :body
7
+
8
+ def initialize(response)
9
+ @original_response = response
10
+ @body = JSON.parse(response.body)
11
+ end
12
+
13
+ def success?
14
+ body['status'] == 'success'
15
+ end
16
+
17
+ def params
18
+ body
19
+ end
20
+
21
+ def process_id
22
+ body['process_id']
23
+ end
24
+
25
+ def message
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Bancard
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -30,9 +30,22 @@ describe Bancard::Gateway do
30
30
  end
31
31
 
32
32
  it 'includes the auth params' do
33
- init = gateway.__send__(:single_buy_init)
33
+ init = gateway.__send__(:build_single_buy_init)
34
34
  expect(init.private_key).to eq 'private'
35
35
  expect(init.public_key).to eq 'public'
36
36
  end
37
37
  end
38
+
39
+ describe '#rollback' do
40
+ it 'builds a SingleBuyInit and returns its response' do
41
+ response = gateway.rollback({})
42
+ expect(response).to be_a Bancard::SingleBuyRollbackResponse
43
+ end
44
+
45
+ it 'includes the auth params' do
46
+ rollback = gateway.__send__(:build_single_buy_rollback)
47
+ expect(rollback.private_key).to eq 'private'
48
+ expect(rollback.public_key).to eq 'public'
49
+ end
50
+ end
38
51
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bancard::SingleBuyRollbackResponse do
4
+ let(:body) { { 'status' => 'success', 'process_id' => '123' } }
5
+ let(:typhoeus_response) { Typhoeus::Response.new(body: body.to_json) }
6
+ let(:response) { Bancard::SingleBuyRollbackResponse.new(typhoeus_response) }
7
+
8
+ describe '#initialize' do
9
+ it 'parses and stores the original response body' do
10
+ expect(response.body).to eq body
11
+ end
12
+ end
13
+
14
+ describe '#process_id' do
15
+ it 'reads the process_id from the params' do
16
+ expect(response.process_id).to eq '123'
17
+ end
18
+ end
19
+
20
+ describe '#params' do
21
+ it 'equals the response body, but parsed' do
22
+ expect(response.params).to eq body
23
+ end
24
+ end
25
+
26
+ describe '#message' do
27
+ it 'returns nil' do
28
+ expect(response.message).to be_nil
29
+ end
30
+ end
31
+
32
+ describe '#success?' do
33
+ it 'returns true on success' do
34
+ expect(response).to be_success
35
+ end
36
+
37
+ it 'returns false on failure' do
38
+ body['status'] = 'failure'
39
+ expect(response).not_to be_success
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bancard::SingleBuyRollback do
4
+ let(:rollback) { Bancard::SingleBuyRollback.new(shop_process_id: 123, public_key: 'public') }
5
+
6
+ describe '#operation_params' do
7
+ let(:params) { rollback.operation_params }
8
+
9
+ it 'includes the correct shop_process_id' do
10
+ expect(params[:shop_process_id]).to eq 123
11
+ end
12
+
13
+ it 'includes the md5ed token' do
14
+ expect(params[:token]).to eq '5f048967e46b9de52a4656793c66b802'
15
+ end
16
+ end
17
+
18
+ describe '#request_params' do
19
+ let(:params) { rollback.request_params }
20
+
21
+ it 'includes the correct public_key' do
22
+ expect(params[:public_key]).to eq 'public'
23
+ end
24
+
25
+ it 'includes the operation_params' do
26
+ expect(params[:operation]).to eq rollback.operation_params
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bancard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -115,11 +115,15 @@ files:
115
115
  - lib/bancard/gateway.rb
116
116
  - lib/bancard/single_buy_init.rb
117
117
  - lib/bancard/single_buy_init_response.rb
118
+ - lib/bancard/single_buy_rollback.rb
119
+ - lib/bancard/single_buy_rollback_response.rb
118
120
  - lib/bancard/utils.rb
119
121
  - lib/bancard/version.rb
120
122
  - spec/lib/bancard/gateway_spec.rb
121
123
  - spec/lib/bancard/single_buy_init_response_spec.rb
122
124
  - spec/lib/bancard/single_buy_init_spec.rb
125
+ - spec/lib/bancard/single_buy_rollback_response_spec.rb
126
+ - spec/lib/bancard/single_buy_rollback_spec.rb
123
127
  - spec/lib/bancard_spec.rb
124
128
  - spec/spec_helper.rb
125
129
  homepage: ''
@@ -150,5 +154,7 @@ test_files:
150
154
  - spec/lib/bancard/gateway_spec.rb
151
155
  - spec/lib/bancard/single_buy_init_response_spec.rb
152
156
  - spec/lib/bancard/single_buy_init_spec.rb
157
+ - spec/lib/bancard/single_buy_rollback_response_spec.rb
158
+ - spec/lib/bancard/single_buy_rollback_spec.rb
153
159
  - spec/lib/bancard_spec.rb
154
160
  - spec/spec_helper.rb