wizypay-api-client 0.2.2 → 0.2.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 +4 -4
- data/lib/wizypay/card.rb +29 -1
- data/lib/wizypay/refund.rb +10 -0
- data/lib/wizypay/vdc_operation.rb +8 -0
- data/lib/wizypay/version.rb +1 -1
- data/lib/wizypay.rb +2 -3
- data/spec/card/card_all_spec.rb +44 -0
- data/spec/card/card_show_spec.rb +40 -0
- data/spec/card/card_url_spec.rb +4 -2
- data/spec/merchant_category/merchant_category_spec.rb +1 -1
- data/spec/merchant_version/merchant_version_spec.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bca630ae75a36db5e41f3cb75ee501d9cf14add
|
4
|
+
data.tar.gz: bf3964e81428eba7194195083f42cfffadfc746d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df0f6ab6adfb7f945e6abccc97d484489b5f8299f67a84b910a3d2c9d8b5545679b5cd01caf0b3f447f7560362e83577335e7a3195ae62322c07d11fd5c1686b
|
7
|
+
data.tar.gz: 61306abd6fde64bffb67a71fecded4ec07ac6a578a5cb788a2f30ac9275e5741e025afd972b8380faa6d7b71327a1aeb86c6c437078340d8c46c1a4caeb4b0ef
|
data/lib/wizypay/card.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
module Wizypay
|
2
2
|
class Card < Resource
|
3
|
+
include SimpleHmac::Helper
|
4
|
+
|
5
|
+
def self.where(q)
|
6
|
+
raw = Client.get('/cards', q)
|
7
|
+
Collection.new(self, raw[:data], raw[:meta])
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.all(q = {})
|
11
|
+
where(q)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.find(id)
|
15
|
+
new(Client.get("/cards/#{id}")[:data])
|
16
|
+
end
|
17
|
+
|
3
18
|
def self.create(reference, amount, currency, merchant_id, user)
|
4
19
|
user = user.to_json if user.is_a?(Hash)
|
5
20
|
new(amount: amount, currency: currency, merchant_id: merchant_id, reference: reference, user: user).tap do |card|
|
@@ -21,7 +36,7 @@ module Wizypay
|
|
21
36
|
|
22
37
|
def url
|
23
38
|
timestamp = Time.now.utc.httpdate
|
24
|
-
security =
|
39
|
+
security = sign_string("#{reference}\n#{timestamp}", Client.api_secret)
|
25
40
|
query_string = {
|
26
41
|
key: Client.api_key,
|
27
42
|
timestamp: timestamp,
|
@@ -34,5 +49,18 @@ module Wizypay
|
|
34
49
|
def save
|
35
50
|
reinitialize Client.post('/cards', to_h)
|
36
51
|
end
|
52
|
+
|
53
|
+
def created_at
|
54
|
+
return nil unless super.present?
|
55
|
+
Time.parse(super)
|
56
|
+
end
|
57
|
+
|
58
|
+
def operations
|
59
|
+
Collection.new(VdcOperation, super['data'], super['meta'])
|
60
|
+
end
|
61
|
+
|
62
|
+
def refunds
|
63
|
+
Collection.new(Refund, super['data'], super['meta'])
|
64
|
+
end
|
37
65
|
end
|
38
66
|
end
|
data/lib/wizypay/version.rb
CHANGED
data/lib/wizypay.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
require 'time'
|
2
|
-
require 'base64'
|
3
|
-
require 'openssl'
|
4
|
-
require 'securerandom'
|
5
2
|
require 'rest-client'
|
6
3
|
require 'simple-hmac'
|
7
4
|
require 'json'
|
@@ -9,6 +6,8 @@ require_relative 'wizypay/client'
|
|
9
6
|
require_relative 'wizypay/resource'
|
10
7
|
require_relative 'wizypay/collection'
|
11
8
|
require_relative 'wizypay/card'
|
9
|
+
require_relative 'wizypay/vdc_operation'
|
10
|
+
require_relative 'wizypay/refund'
|
12
11
|
require_relative 'wizypay/ad'
|
13
12
|
require_relative 'wizypay/merchant_category'
|
14
13
|
require_relative 'wizypay/merchant'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Wizypay
|
4
|
+
RSpec.describe Card do
|
5
|
+
let(:api_key) { 'key' }
|
6
|
+
let(:api_secret) { 'secret' }
|
7
|
+
let(:api_endpoint) { 'https://api.wizypay.com' }
|
8
|
+
let(:all_cards_request) { stub_request(:get, "#{api_endpoint}/cards").
|
9
|
+
with(headers: { 'Accept' => 'application/json',
|
10
|
+
'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
|
11
|
+
let(:where_cards_request) { stub_request(:get, "#{api_endpoint}/cards?beneficiary=john").
|
12
|
+
with(headers: { 'Accept' => 'application/json',
|
13
|
+
'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
|
14
|
+
before do
|
15
|
+
Wizypay.setup(api_key, api_secret, api_endpoint)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'all' do
|
19
|
+
it 'returns empty body' do
|
20
|
+
request = all_cards_request.to_return(status: 200, body: '{"data": []}')
|
21
|
+
response = Card.all
|
22
|
+
expect(request).to have_been_made
|
23
|
+
expect(response).to be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'is a collection' do
|
27
|
+
all_cards_request.to_return(status: 200, body: '{"data": [{"id": 1, "partial_number": "XXXX-1234"}]}')
|
28
|
+
response = Card.all
|
29
|
+
expect(response).to be_a(Collection)
|
30
|
+
expect(response.first).to be_a(Card)
|
31
|
+
expect(response.first.partial_number).to eq 'XXXX-1234'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'where' do
|
36
|
+
it 'returns empty body' do
|
37
|
+
request = where_cards_request.to_return(status: 200, body: '{"data": []}')
|
38
|
+
response = Card.where(beneficiary: 'john')
|
39
|
+
expect(request).to have_been_made
|
40
|
+
expect(response).to be_empty
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Wizypay
|
4
|
+
RSpec.describe Card do
|
5
|
+
let(:api_key) { 'key' }
|
6
|
+
let(:api_secret) { 'secret' }
|
7
|
+
let(:api_endpoint) { 'https://api.wizypay.com' }
|
8
|
+
let(:card_id) { 1 }
|
9
|
+
let(:card_request) { stub_request(:get, "#{api_endpoint}/cards/#{card_id}").
|
10
|
+
with(headers: { 'Accept' => 'application/json',
|
11
|
+
'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
|
12
|
+
before do
|
13
|
+
Wizypay.setup(api_key, api_secret, api_endpoint)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'is a card' do
|
17
|
+
request = card_request.to_return(status: 200, body: '{"data": {"id": 1, "partial_number": "XXXX-1234"}}')
|
18
|
+
response = Card.find(card_id)
|
19
|
+
expect(request).to have_been_made
|
20
|
+
expect(response).to be_a(Card)
|
21
|
+
expect(response.partial_number).to eq 'XXXX-1234'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has operations' do
|
25
|
+
card_request.to_return(status: 200, body: '{"data": {"operations": {"data": [{"id": 1}]}}}')
|
26
|
+
response = Card.find(card_id)
|
27
|
+
expect(response.operations).to be_a(Collection)
|
28
|
+
expect(response.operations.first).to be_a(VdcOperation)
|
29
|
+
expect(response.operations.first.id).to eq 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'has refunds' do
|
33
|
+
card_request.to_return(status: 200, body: '{"data": {"refunds": {"data": [{"id": 1}]}}}')
|
34
|
+
response = Card.find(card_id)
|
35
|
+
expect(response.refunds).to be_a(Collection)
|
36
|
+
expect(response.refunds.first).to be_a(Refund)
|
37
|
+
expect(response.refunds.first.id).to eq 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/card/card_url_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'time'
|
|
3
3
|
|
4
4
|
module Wizypay
|
5
5
|
RSpec.describe 'Card#url' do
|
6
|
+
include SimpleHmac::Helper
|
6
7
|
|
7
8
|
let(:api_key) { 'key' }
|
8
9
|
let(:api_secret) { 'secret' }
|
@@ -14,13 +15,14 @@ module Wizypay
|
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'returns' do
|
17
|
-
t = Time.new(
|
18
|
+
t = Time.new(2015, 1, 1, 0, 0, 0, "+01:00")
|
18
19
|
Timecop.freeze(t) do
|
19
20
|
url = Card.new(reference: reference).url
|
21
|
+
expected_security = sign_string("#{reference}\n#{t.httpdate}", api_secret)
|
20
22
|
expect(url).to eq("#{api_endpoint}/widget?key=#{URI::encode_www_form_component api_key}"+
|
21
23
|
"×tamp=#{URI::encode_www_form_component t.httpdate}" +
|
22
24
|
"&reference=#{URI::encode_www_form_component reference}"+
|
23
|
-
"&security
|
25
|
+
"&security=#{URI::encode_www_form_component expected_security}")
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wizypay-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chaker Nakhli
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-01
|
13
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: simple-hmac
|
@@ -157,9 +157,13 @@ files:
|
|
157
157
|
- lib/wizypay/merchant.rb
|
158
158
|
- lib/wizypay/merchant_category.rb
|
159
159
|
- lib/wizypay/merchant_version.rb
|
160
|
+
- lib/wizypay/refund.rb
|
160
161
|
- lib/wizypay/resource.rb
|
162
|
+
- lib/wizypay/vdc_operation.rb
|
161
163
|
- lib/wizypay/version.rb
|
162
164
|
- spec/card/cancel_card_spec.rb
|
165
|
+
- spec/card/card_all_spec.rb
|
166
|
+
- spec/card/card_show_spec.rb
|
163
167
|
- spec/card/card_url_spec.rb
|
164
168
|
- spec/card/create_card_spec.rb
|
165
169
|
- spec/merchant/merchant_spec.rb
|
@@ -193,6 +197,8 @@ specification_version: 4
|
|
193
197
|
summary: Programmatic API to access Wizypay's API.
|
194
198
|
test_files:
|
195
199
|
- spec/card/cancel_card_spec.rb
|
200
|
+
- spec/card/card_all_spec.rb
|
201
|
+
- spec/card/card_show_spec.rb
|
196
202
|
- spec/card/card_url_spec.rb
|
197
203
|
- spec/card/create_card_spec.rb
|
198
204
|
- spec/merchant/merchant_spec.rb
|