payjp 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4894124d5ba9c96bcf0d10613cb90b7b6ee33927
4
- data.tar.gz: 612f883bc15553c9c2551fed5df636e7d936f78d
3
+ metadata.gz: ebc7ca3b834edcac9e21591f4276ab0565f2737b
4
+ data.tar.gz: a33c549105cf8879e36f2138b2c25c354e470960
5
5
  SHA512:
6
- metadata.gz: ec9130790d73529bfe759c9198b3613db623f0fb5df87cfece9e6ea9aeb78356bd3a88bd7b7b1e6fcf15e20325c1b40e64a29c803d6cadab794052588b189267
7
- data.tar.gz: 7f89a815d3a03162c94fb2bab7a797367f9c9323f1f737243494d1666cd76de9f1854b924e924c163adaff9bd63b4ad0a8ab4c720af2fd35fc7d1a32f3df9aca
6
+ metadata.gz: 3eee26dfe4f02da8e58681cfa911e0366684d2331ef277ce42ef9f1b639026799b1a155897c6612301e106d0ace91757350ff123060e57fb799fb6a4fbf46d43
7
+ data.tar.gz: baa39ffbea0e3be47a2dfcc6b671461ecfef2f57f299fa09ac78f126cfd5ee98b4f963ae4562255616c810753a4ece35e7302aeaf33a440259d6b7a1ad31ef10
@@ -1,13 +1,13 @@
1
1
  module Payjp
2
2
  module APIOperations
3
3
  module Update
4
- def save(params = {})
4
+ def save(params = {}, opts = {})
5
5
  values = self.class.serialize_params(self).merge(params)
6
6
 
7
7
  if values.length > 0
8
8
  values.delete(:id)
9
9
 
10
- response, opts = request(:post, url, values)
10
+ response, opts = request(:post, url, values, opts)
11
11
  refresh_from(response, opts)
12
12
  end
13
13
  self
@@ -14,6 +14,11 @@ module Payjp
14
14
  refresh_from(response, opts)
15
15
  end
16
16
 
17
+ def reauth(params = {}, opts = {})
18
+ response, opts = request(:post, reauth_url, params, opts)
19
+ refresh_from(response, opts)
20
+ end
21
+
17
22
  private
18
23
 
19
24
  def refund_url
@@ -23,5 +28,9 @@ module Payjp
23
28
  def capture_url
24
29
  url + '/capture'
25
30
  end
31
+
32
+ def reauth_url
33
+ url + '/reauth'
34
+ end
26
35
  end
27
36
  end
@@ -129,7 +129,7 @@ module Payjp
129
129
  # remove keys at the server, but not known locally
130
130
  if @original_values.include?(key)
131
131
  keys_to_unset = @original_values[key].keys - new_keys
132
- keys_to_unset.each { |key| update[key] = '' }
132
+ keys_to_unset.each { |unset_key| update[unset_key] = '' }
133
133
  end
134
134
 
135
135
  update
@@ -62,7 +62,16 @@ module Payjp
62
62
  end
63
63
 
64
64
  def self.url_encode(key)
65
- URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
65
+ # URI.escape is obsolete, so just use the code fragment in URI library
66
+ # (from URI::RFC2396_Parser#escape)
67
+ key.to_s.gsub(Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) do
68
+ us = $&
69
+ tmp = ''
70
+ us.each_byte do |uc|
71
+ tmp << sprintf('%%%02X', uc)
72
+ end
73
+ tmp
74
+ end.force_encoding(Encoding::US_ASCII)
66
75
  end
67
76
 
68
77
  def self.flatten_params(params, parent_key = nil)
@@ -1,3 +1,3 @@
1
1
  module Payjp
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_development_dependency('mocha', '~> 1.2.1')
18
18
  s.add_development_dependency('activesupport', ['< 5.0', '~> 4.2.7'])
19
- s.add_development_dependency('shoulda', '~> 3.3.2')
20
19
  s.add_development_dependency('test-unit', '~> 3.2.2')
21
20
  s.add_development_dependency('rake', '~> 11.3.0')
22
21
  s.add_development_dependency('bundler', '>= 1.7.6')
@@ -79,5 +79,17 @@ module Payjp
79
79
  })
80
80
  assert c.paid
81
81
  end
82
+
83
+ should "charges should be reauthable" do
84
+ now = Time.now.localtime("+09:00")
85
+ expired_at = now + 60 * 60 * 24 * 6
86
+ expired_at = Time.new(expired_at.year, expired_at.mon, expired_at.day, 23, 59, 59, now.utc_offset)
87
+ @mock.expects(:get).never
88
+ @mock.expects(:post).once.returns(test_response({ :id => "ch_test_charge", :expired_at => expired_at.to_i }))
89
+
90
+ c = Payjp::Charge.new("test_charge")
91
+ c.reauth
92
+ assert_equal expired_at.to_i, c.expired_at
93
+ end
82
94
  end
83
95
  end
@@ -30,5 +30,17 @@ module Payjp
30
30
  assert_raise { Payjp::Util.normalize_opts(nil) }
31
31
  assert_raise { Payjp::Util.normalize_opts(:api_key => nil) }
32
32
  end
33
+
34
+ should "url_encode should escape only UNRESERVED characters" do
35
+ unreserved = %q|!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~|
36
+ (0..255).each do |c|
37
+ s = [c].pack("C")
38
+ if unreserved.include?(s)
39
+ assert_equal(s, Payjp::Util.url_encode(s))
40
+ else
41
+ assert_equal("%"+sprintf("%02X", c), Payjp::Util.url_encode(s))
42
+ end
43
+ end
44
+ end
33
45
  end
34
46
  end
@@ -2,7 +2,6 @@ require 'payjp'
2
2
  require 'test/unit'
3
3
  require 'mocha/setup'
4
4
  require 'stringio'
5
- require 'shoulda'
6
5
  require File.expand_path('../test_data', __FILE__)
7
6
 
8
7
  # monkeypatch request methods
@@ -11,6 +10,7 @@ module Payjp
11
10
 
12
11
  class << self
13
12
  attr_writer :mock_rest_client
13
+ remove_method :execute_request
14
14
  end
15
15
 
16
16
  def self.execute_request(opts)
@@ -28,6 +28,11 @@ class Test::Unit::TestCase
28
28
  include Payjp::TestData
29
29
  include Mocha
30
30
 
31
+ class << self
32
+ alias_method :context, :sub_test_case
33
+ alias_method :should, :test
34
+ end
35
+
31
36
  def encode_credentials(user_name)
32
37
  "Basic #{Base64.strict_encode64("#{user_name}:")}"
33
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payjp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - PAY.JP
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-18 00:00:00.000000000 Z
11
+ date: 2017-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -58,20 +58,6 @@ dependencies:
58
58
  - - ~>
59
59
  - !ruby/object:Gem::Version
60
60
  version: 4.2.7
61
- - !ruby/object:Gem::Dependency
62
- name: shoulda
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ~>
66
- - !ruby/object:Gem::Version
67
- version: 3.3.2
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ~>
73
- - !ruby/object:Gem::Version
74
- version: 3.3.2
75
61
  - !ruby/object:Gem::Dependency
76
62
  name: test-unit
77
63
  requirement: !ruby/object:Gem::Requirement