webpay 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +13 -0
- data/Rakefile +6 -0
- data/gemfiles/no_doc_gems +9 -0
- data/lib/webpay/client.rb +19 -1
- data/lib/webpay/version.rb +1 -1
- data/lib/webpay/webpay_error.rb +7 -1
- data/spec/resources/account/delete.txt +15 -0
- data/spec/resources/account/retrieve.txt +23 -0
- data/spec/resources/charges/all.txt +102 -0
- data/spec/resources/charges/capture.txt +41 -0
- data/spec/resources/charges/create_with_card.txt +41 -0
- data/spec/resources/charges/create_with_customer.txt +41 -0
- data/spec/resources/charges/refund.txt +41 -0
- data/spec/resources/charges/retrieve.txt +39 -0
- data/spec/resources/charges/retrieve_not_captured.txt +39 -0
- data/spec/resources/customers/all.txt +76 -0
- data/spec/resources/customers/create.txt +31 -0
- data/spec/resources/customers/delete.txt +16 -0
- data/spec/resources/customers/retrieve.txt +31 -0
- data/spec/resources/customers/update.txt +31 -0
- data/spec/resources/errors/bad_request.txt +18 -0
- data/spec/resources/errors/broken_json.txt +16 -0
- data/spec/resources/errors/card_error.txt +19 -0
- data/spec/resources/errors/not_found.txt +18 -0
- data/spec/resources/errors/unauthorized.txt +16 -0
- data/spec/resources/errors/unknown_api_error.txt +17 -0
- data/spec/resources/events/all_with_type.txt +164 -0
- data/spec/resources/events/retrieve.txt +41 -0
- data/spec/resources/tokens/create.txt +30 -0
- data/spec/resources/tokens/retrieve.txt +30 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/webpay/account_spec.rb +24 -0
- data/spec/webpay/charge_spec.rb +115 -0
- data/spec/webpay/customer_spec.rb +94 -0
- data/spec/webpay/event_spec.rb +30 -0
- data/spec/webpay/token_spec.rb +33 -0
- data/spec/webpay/webpay_error_spec.rb +58 -0
- data/webpay.gemspec +2 -0
- metadata +103 -22
@@ -0,0 +1,41 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json; charset=utf-8
|
3
|
+
X-Ua-Compatible: IE=Edge
|
4
|
+
Etag: "82c5b217d10ddfa51f97be68e64e36bf"
|
5
|
+
Cache-Control: max-age=0, private, must-revalidate
|
6
|
+
X-Request-Id: d90b88bc64cc2ebe6c6c5bbdc7c89db4
|
7
|
+
X-Runtime: 0.014599
|
8
|
+
Server: WEBrick/1.3.1 (Ruby/1.9.3/2013-02-22)
|
9
|
+
Date: Wed, 11 Sep 2013 12:28:48 GMT
|
10
|
+
Content-Length: 709
|
11
|
+
Connection: Keep-Alive
|
12
|
+
|
13
|
+
{
|
14
|
+
"id": "evt_39o9oUevb5NCeM1",
|
15
|
+
"object": "event",
|
16
|
+
"livemode": false,
|
17
|
+
"type": "customer.created",
|
18
|
+
"created": 1378823309,
|
19
|
+
"data": {
|
20
|
+
"object": {
|
21
|
+
"id": "cus_39o9oU1N1dRm4LZ",
|
22
|
+
"object": "customer",
|
23
|
+
"livemode": false,
|
24
|
+
"created": 1378823309,
|
25
|
+
"email": "customer@example.com",
|
26
|
+
"description": "Test Customer from Java",
|
27
|
+
"active_card": {
|
28
|
+
"object": "card",
|
29
|
+
"exp_year": 2015,
|
30
|
+
"exp_month": 12,
|
31
|
+
"fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
|
32
|
+
"name": "YUUKO SHIONJI",
|
33
|
+
"country": "JP",
|
34
|
+
"type": "Visa",
|
35
|
+
"cvc_check": "pass",
|
36
|
+
"last4": "4242"
|
37
|
+
}
|
38
|
+
}
|
39
|
+
},
|
40
|
+
"pending_webhooks": 0
|
41
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
HTTP/1.1 201 Created
|
2
|
+
Content-Type: application/json; charset=utf-8
|
3
|
+
X-Ua-Compatible: IE=Edge
|
4
|
+
Etag: "05ec1d26e74ca3aaa0f83f4a592ea069"
|
5
|
+
Cache-Control: max-age=0, private, must-revalidate
|
6
|
+
X-Request-Id: 73e33db3646601c24efd77b0b00ba28d
|
7
|
+
X-Runtime: 0.587596
|
8
|
+
Server: WEBrick/1.3.1 (Ruby/1.9.3/2013-02-22)
|
9
|
+
Date: Wed, 11 Sep 2013 12:03:55 GMT
|
10
|
+
Content-Length: 378
|
11
|
+
Connection: Keep-Alive
|
12
|
+
|
13
|
+
{
|
14
|
+
"id": "tok_3dw2T20rzekM1Kf",
|
15
|
+
"object": "token",
|
16
|
+
"livemode": false,
|
17
|
+
"created": 1378901035,
|
18
|
+
"used": false,
|
19
|
+
"card": {
|
20
|
+
"object": "card",
|
21
|
+
"exp_year": 2015,
|
22
|
+
"exp_month": 12,
|
23
|
+
"fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
|
24
|
+
"name": "YUUKO SHIONJI",
|
25
|
+
"country": "JP",
|
26
|
+
"type": "Visa",
|
27
|
+
"cvc_check": "pass",
|
28
|
+
"last4": "4242"
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/json; charset=utf-8
|
3
|
+
X-Ua-Compatible: IE=Edge
|
4
|
+
Etag: "05ec1d26e74ca3aaa0f83f4a592ea069"
|
5
|
+
Cache-Control: max-age=0, private, must-revalidate
|
6
|
+
X-Request-Id: 0ad1274f865ae7cce5d8187373fa0fa4
|
7
|
+
X-Runtime: 0.013401
|
8
|
+
Server: WEBrick/1.3.1 (Ruby/1.9.3/2013-02-22)
|
9
|
+
Date: Wed, 11 Sep 2013 12:07:10 GMT
|
10
|
+
Content-Length: 378
|
11
|
+
Connection: Keep-Alive
|
12
|
+
|
13
|
+
{
|
14
|
+
"id": "tok_3dw2T20rzekM1Kf",
|
15
|
+
"object": "token",
|
16
|
+
"livemode": false,
|
17
|
+
"created": 1378901035,
|
18
|
+
"used": false,
|
19
|
+
"card": {
|
20
|
+
"object": "card",
|
21
|
+
"exp_year": 2015,
|
22
|
+
"exp_month": 12,
|
23
|
+
"fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
|
24
|
+
"name": "YUUKO SHIONJI",
|
25
|
+
"country": "JP",
|
26
|
+
"type": "Visa",
|
27
|
+
"cvc_check": "pass",
|
28
|
+
"last4": "4242"
|
29
|
+
}
|
30
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
require 'webpay'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
config.filter_run :focus
|
8
|
+
|
9
|
+
config.order = 'random'
|
10
|
+
|
11
|
+
config.before(:each) do
|
12
|
+
WebPay.api_key = 'fake_apikey'
|
13
|
+
WebPay.api_base = 'http://api.example.com'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def stub_get_request(path, file)
|
18
|
+
stub_request(:get, 'http://api.example.com/v1' + path).
|
19
|
+
with(headers: { 'Authorization' => 'Bearer fake_apikey' }).
|
20
|
+
to_return(response_file(file))
|
21
|
+
end
|
22
|
+
|
23
|
+
def stub_post_request(path, file, params = {})
|
24
|
+
stub_request(:post, 'http://api.example.com/v1' + path).
|
25
|
+
with(headers: { 'Authorization' => 'Bearer fake_apikey' }, body: params).
|
26
|
+
to_return(response_file(file))
|
27
|
+
end
|
28
|
+
|
29
|
+
def stub_delete_request(path, file)
|
30
|
+
stub_request(:delete, 'http://api.example.com/v1' + path).
|
31
|
+
with(headers: { 'Authorization' => 'Bearer fake_apikey' }).
|
32
|
+
to_return(response_file(file))
|
33
|
+
end
|
34
|
+
|
35
|
+
def response_file(file)
|
36
|
+
File.new(File.expand_path(File.join(__FILE__, '..', 'resources', file + '.txt')))
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe WebPay::Account do
|
3
|
+
describe '.retrieve' do
|
4
|
+
before do
|
5
|
+
stub_get_request('/account', 'account/retrieve')
|
6
|
+
end
|
7
|
+
|
8
|
+
subject(:account) { described_class.retrieve }
|
9
|
+
its(:object) { should eq 'account' }
|
10
|
+
its(:id) { should eq 'acct_2Cmdexb7J2r78rz' }
|
11
|
+
its(:email) { should eq 'test-me@example.com' }
|
12
|
+
its(:currencies_supported) { should eq ['jpy'] }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.delete_data' do
|
16
|
+
before do
|
17
|
+
stub_delete_request('/account/data', 'account/delete')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should return true' do
|
21
|
+
expect(described_class.delete_data).to eq true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe WebPay::Charge do
|
3
|
+
describe '.create' do
|
4
|
+
subject(:charge) { WebPay::Charge.create(params)}
|
5
|
+
|
6
|
+
describe 'with card' do
|
7
|
+
let(:params) {{
|
8
|
+
:amount=>'1000',
|
9
|
+
:currency=>'jpy',
|
10
|
+
:card=>
|
11
|
+
{:number=>'4242-4242-4242-4242',
|
12
|
+
:exp_month=>'12',
|
13
|
+
:exp_year=>'2015',
|
14
|
+
:cvc=>'123',
|
15
|
+
:name=>'YUUKO SHIONJI'},
|
16
|
+
:description=>'Test Charge from Java'
|
17
|
+
}}
|
18
|
+
before do
|
19
|
+
stub_post_request('/charges', 'charges/create_with_card', params)
|
20
|
+
end
|
21
|
+
|
22
|
+
its(:id) { should eq 'ch_2SS17Oh1r8d2djE' }
|
23
|
+
its(:description) { should eq "Test Charge from Java" }
|
24
|
+
it 'card.name' do
|
25
|
+
expect(charge.card.name).to eq 'YUUKO SHIONJI'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'with customer' do
|
30
|
+
let(:params) {{
|
31
|
+
:amount=>'1000',
|
32
|
+
:currency=>'jpy',
|
33
|
+
:customer => 'cus_fgR4vI92r54I6oK',
|
34
|
+
:description=>'Test Charge from Java'
|
35
|
+
}}
|
36
|
+
before do
|
37
|
+
stub_post_request('/charges', 'charges/create_with_customer', params)
|
38
|
+
end
|
39
|
+
|
40
|
+
its(:id) { should eq 'ch_2SS4fK4IL96535y' }
|
41
|
+
it 'card.name' do
|
42
|
+
expect(charge.card.name).to eq 'KEI KUBO'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.retrieve' do
|
48
|
+
let(:id) { 'ch_bWp5EG9smcCYeEx' }
|
49
|
+
before do
|
50
|
+
stub_get_request("/charges/#{id}", 'charges/retrieve')
|
51
|
+
end
|
52
|
+
|
53
|
+
subject(:charge) { described_class.retrieve(id) }
|
54
|
+
its(:id) { should eq id }
|
55
|
+
it 'card.fingerprint' do
|
56
|
+
expect(charge.card.fingerprint).to eq '215b5b2fe460809b8bb90bae6eeac0e0e0987bd7'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.all' do
|
61
|
+
context 'with craeted[gt]' do
|
62
|
+
before do
|
63
|
+
stub_get_request("/charges?count=3&offset=0&created[gt]=1378000000", 'charges/all')
|
64
|
+
end
|
65
|
+
|
66
|
+
subject(:list) { described_class.all(count: 3, offset: 0, created: { gt: 1378000000 }) }
|
67
|
+
its(:url) { should eq '/v1/charges' }
|
68
|
+
its(:count) { should eq 11 }
|
69
|
+
it 'data.first.description' do
|
70
|
+
expect(list.data.first.description).to eq 'Test Charge from Java'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'with customer' do
|
75
|
+
before do
|
76
|
+
stub_get_request("/charges?customer=cus_fgR4vI92r54I6oK", 'charges/all')
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should respond the list' do
|
80
|
+
list = described_class.all(customer: 'cus_fgR4vI92r54I6oK')
|
81
|
+
expect(list.url).to eq '/v1/charges'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#refund' do
|
87
|
+
let(:id) { 'ch_bWp5EG9smcCYeEx' }
|
88
|
+
before do
|
89
|
+
stub_get_request("/charges/#{id}", 'charges/retrieve')
|
90
|
+
stub_post_request("/charges/#{id}/refund", 'charges/refund', amount: '400')
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should refund the retrieved charge' do
|
94
|
+
charge = described_class.retrieve(id)
|
95
|
+
expect(charge.refunded).to eq false
|
96
|
+
charge.refund(amount: 400)
|
97
|
+
expect(charge.refunded).to eq true
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#capture' do
|
102
|
+
let(:id) { 'ch_2X01NDedxdrRcA3' }
|
103
|
+
before do
|
104
|
+
stub_get_request("/charges/#{id}", 'charges/retrieve_not_captured')
|
105
|
+
stub_post_request("/charges/#{id}/capture", 'charges/capture', amount: '1000')
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should capture the retrieved charge' do
|
109
|
+
charge = described_class.retrieve(id)
|
110
|
+
expect(charge.captured).to eq false
|
111
|
+
charge.capture(amount: 1000)
|
112
|
+
expect(charge.captured).to eq true
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe WebPay::Customer do
|
3
|
+
describe '.create' do
|
4
|
+
let(:params) {{
|
5
|
+
:description => 'Test Customer from Java',
|
6
|
+
:email => 'customer@example.com',
|
7
|
+
:card=>
|
8
|
+
{:number=>'4242-4242-4242-4242',
|
9
|
+
:exp_month=>'12',
|
10
|
+
:exp_year=>'2015',
|
11
|
+
:cvc=>'123',
|
12
|
+
:name=>'YUUKO SHIONJI'}
|
13
|
+
}}
|
14
|
+
before do
|
15
|
+
stub_post_request('/customers', 'customers/create', params)
|
16
|
+
end
|
17
|
+
subject(:customer) { WebPay::Customer.create(params)}
|
18
|
+
|
19
|
+
its(:id) { should eq 'cus_39o4Fv82E1et5Xb' }
|
20
|
+
its(:description) { should eq "Test Customer from Java" }
|
21
|
+
it 'active_card.name' do
|
22
|
+
expect(customer.active_card.name).to eq 'YUUKO SHIONJI'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.retrieve' do
|
27
|
+
let(:id) { 'cus_39o4Fv82E1et5Xb' }
|
28
|
+
before do
|
29
|
+
stub_get_request("/customers/#{id}", 'customers/retrieve')
|
30
|
+
end
|
31
|
+
|
32
|
+
subject(:customer) { described_class.retrieve(id) }
|
33
|
+
its(:id) { should eq id }
|
34
|
+
it 'active_card.fingerprint' do
|
35
|
+
expect(customer.active_card.fingerprint).to eq '215b5b2fe460809b8bb90bae6eeac0e0e0987bd7'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.all' do
|
40
|
+
before do
|
41
|
+
stub_get_request("/customers?count=3&offset=0&created[gt]=1378000000", 'customers/all')
|
42
|
+
end
|
43
|
+
|
44
|
+
subject(:list) { described_class.all(count: 3, offset: 0, created: { gt: 1378000000 }) }
|
45
|
+
its(:url) { should eq '/v1/customers' }
|
46
|
+
its(:count) { should eq 4 }
|
47
|
+
it 'data.first.description' do
|
48
|
+
expect(list.data.first.description).to eq 'Test Customer from Java'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#save' do
|
53
|
+
let(:id) { 'cus_39o4Fv82E1et5Xb' }
|
54
|
+
let(:email) { 'newmail@example.com' }
|
55
|
+
let(:description) { 'New description' }
|
56
|
+
let(:card_info) { {:number=>'4242-4242-4242-4242',
|
57
|
+
:exp_month=>'12',
|
58
|
+
:exp_year=>'2016',
|
59
|
+
:cvc=>'123',
|
60
|
+
:name=>'YUUKO SHIONJI'} }
|
61
|
+
before do
|
62
|
+
stub_get_request("/customers/#{id}", 'customers/retrieve')
|
63
|
+
stub_post_request("/customers/#{id}", 'customers/update',
|
64
|
+
email: email,
|
65
|
+
description: description,
|
66
|
+
card: card_info)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should update information of the retrieved customer' do
|
70
|
+
customer = described_class.retrieve(id)
|
71
|
+
customer.email = email
|
72
|
+
customer.description = description
|
73
|
+
customer.card = card_info
|
74
|
+
customer.save
|
75
|
+
|
76
|
+
expect(customer.email).to eq email
|
77
|
+
expect(customer.description).to eq description
|
78
|
+
expect(customer.active_card.exp_year).to eq 2016
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#delete' do
|
83
|
+
let(:id) { 'cus_39o4Fv82E1et5Xb' }
|
84
|
+
before do
|
85
|
+
stub_get_request("/customers/#{id}", 'customers/retrieve')
|
86
|
+
stub_delete_request("/customers/#{id}", 'customers/delete')
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should delete the retrieved customer' do
|
90
|
+
customer = described_class.retrieve(id)
|
91
|
+
expect(customer.delete).to eq true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe WebPay::Event do
|
3
|
+
describe '.retrieve' do
|
4
|
+
let(:id) { 'evt_39o9oUevb5NCeM1' }
|
5
|
+
before do
|
6
|
+
stub_get_request("/events/#{id}", 'events/retrieve')
|
7
|
+
end
|
8
|
+
|
9
|
+
subject(:event) { described_class.retrieve(id) }
|
10
|
+
its(:id) { should eq id }
|
11
|
+
its(:type) { should eq 'customer.created' }
|
12
|
+
it 'data.object' do
|
13
|
+
expect(event.data.object).to be_instance_of(WebPay::Customer)
|
14
|
+
expect(event.data.object.email).to eq 'customer@example.com'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.all' do
|
19
|
+
before do
|
20
|
+
stub_get_request("/events?type=*.created", 'events/all_with_type')
|
21
|
+
end
|
22
|
+
|
23
|
+
subject(:list) { described_class.all(type: '*.created') }
|
24
|
+
its(:url) { should eq '/v1/events' }
|
25
|
+
its(:count) { should eq 5 }
|
26
|
+
it 'data.first.type' do
|
27
|
+
expect(list.data.first.type).to eq 'customer.created'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe WebPay::Token do
|
3
|
+
describe '.create' do
|
4
|
+
let(:params) {{:number=>'4242-4242-4242-4242',
|
5
|
+
:exp_month=>'12',
|
6
|
+
:exp_year=>'2015',
|
7
|
+
:cvc=>'123',
|
8
|
+
:name=>'YUUKO SHIONJI'}}
|
9
|
+
before do
|
10
|
+
stub_post_request('/tokens', 'tokens/create', params)
|
11
|
+
end
|
12
|
+
subject(:token) { WebPay::Token.create(params)}
|
13
|
+
|
14
|
+
its(:id) { should eq 'tok_3dw2T20rzekM1Kf' }
|
15
|
+
its(:used) { should eq false }
|
16
|
+
it 'card.name' do
|
17
|
+
expect(token.card.name).to eq 'YUUKO SHIONJI'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.retrieve' do
|
22
|
+
let(:id) { 'tok_3dw2T20rzekM1Kf' }
|
23
|
+
before do
|
24
|
+
stub_get_request("/tokens/#{id}", 'tokens/retrieve')
|
25
|
+
end
|
26
|
+
|
27
|
+
subject(:token) { described_class.retrieve(id) }
|
28
|
+
its(:id) { should eq id }
|
29
|
+
it 'card.fingerprint' do
|
30
|
+
expect(token.card.fingerprint).to eq '215b5b2fe460809b8bb90bae6eeac0e0e0987bd7'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|