wizypay-api-client 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wizypay/beneficiary.rb +1 -1
- data/lib/wizypay/card_methods.rb +89 -0
- data/lib/wizypay/debit_card.rb +7 -0
- data/lib/wizypay/gift_card.rb +7 -0
- data/lib/wizypay/version.rb +1 -1
- data/lib/wizypay.rb +3 -1
- data/spec/beneficiary/beneficiary_spec.rb +1 -1
- data/spec/debit_card/cancel_card_spec.rb +57 -0
- data/spec/debit_card/card_all_spec.rb +44 -0
- data/spec/debit_card/card_show_spec.rb +40 -0
- data/spec/debit_card/card_url_spec.rb +37 -0
- data/spec/debit_card/create_card_spec.rb +69 -0
- data/spec/{card → debit_card}/refund_card_spec.rb +5 -5
- data/spec/{card → gift_card}/cancel_card_spec.rb +7 -7
- data/spec/{card → gift_card}/card_all_spec.rb +7 -7
- data/spec/{card → gift_card}/card_show_spec.rb +6 -6
- data/spec/{card → gift_card}/card_url_spec.rb +4 -4
- data/spec/{card → gift_card}/create_card_spec.rb +12 -6
- metadata +27 -15
- data/lib/wizypay/card.rb +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f231d484040d7bc2ae1cf08f4b411ece9d4abab4
|
4
|
+
data.tar.gz: dfdff5327ad0b6994e10e48c4a661067753a0d7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f49f63f9bd69cac1a3a3f26eda501e804beb8e69abcb92cd5799cbf537ccb8b18301ab6c8724a6d1dc737f35b797b357aec458aa6cd40634109c32e917dad7b
|
7
|
+
data.tar.gz: cf1196d81d131d6e71ad8c5dc53b8ff903846493c9a519b95b0057c8e4a01111fb8bf21c3df75a0652986e3c0f3cd7cb0eaad82900a31a5c2249d0d50ad3ca24
|
data/lib/wizypay/beneficiary.rb
CHANGED
@@ -0,0 +1,89 @@
|
|
1
|
+
module Wizypay
|
2
|
+
module CardMethods
|
3
|
+
include SimpleHmac::Helper
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
attr_accessor :base_path
|
7
|
+
|
8
|
+
def where(q)
|
9
|
+
raw = ApiClient.get(base_path, q)
|
10
|
+
Collection.new(self, raw[:data], raw[:meta])
|
11
|
+
end
|
12
|
+
|
13
|
+
def all(q = {})
|
14
|
+
where(q)
|
15
|
+
end
|
16
|
+
|
17
|
+
def find(id)
|
18
|
+
new(ApiClient.get("#{base_path}/#{id}")[:data])
|
19
|
+
end
|
20
|
+
|
21
|
+
def create(reference, amount, currency, merchant_id, user)
|
22
|
+
user = user.to_json if user.is_a?(Hash)
|
23
|
+
new(amount: amount, currency: currency, merchant_id: merchant_id, reference: reference, user: user).tap do |card|
|
24
|
+
card.save
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def cancel(reference)
|
29
|
+
new(reference: reference).cancel
|
30
|
+
end
|
31
|
+
|
32
|
+
def refund(reference, amount)
|
33
|
+
new(reference: reference).refund(amount)
|
34
|
+
end
|
35
|
+
|
36
|
+
def url(reference)
|
37
|
+
new(reference: reference).url
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def base_path
|
42
|
+
self.class.base_path
|
43
|
+
end
|
44
|
+
|
45
|
+
def cancel
|
46
|
+
ApiClient.post("#{base_path}/#{URI::encode_www_form_component reference}/cancel")
|
47
|
+
end
|
48
|
+
|
49
|
+
def refund(amount)
|
50
|
+
ApiClient.post("#{base_path}/#{URI::encode_www_form_component reference}/refund", amount: amount)
|
51
|
+
end
|
52
|
+
|
53
|
+
def url
|
54
|
+
timestamp = Time.now.utc.httpdate
|
55
|
+
security = sign_string("#{reference}\n#{timestamp}", ApiClient.api_secret)
|
56
|
+
query_string = {
|
57
|
+
key: ApiClient.api_key,
|
58
|
+
timestamp: timestamp,
|
59
|
+
reference: reference,
|
60
|
+
security: security
|
61
|
+
}.map { |k, v| "#{k}=#{URI::encode_www_form_component(v)}" }.join('&')
|
62
|
+
"#{ApiClient.api_endpoint}/widget?#{query_string}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def save
|
66
|
+
reinitialize ApiClient.post(base_path, to_h)
|
67
|
+
rescue => e
|
68
|
+
begin
|
69
|
+
cancel
|
70
|
+
rescue RestClient::Exception
|
71
|
+
#no-op
|
72
|
+
end
|
73
|
+
raise e
|
74
|
+
end
|
75
|
+
|
76
|
+
def created_at
|
77
|
+
return nil unless super.present?
|
78
|
+
Time.parse(super)
|
79
|
+
end
|
80
|
+
|
81
|
+
def operations
|
82
|
+
Collection.new(VdcOperation, super['data'], super['meta'])
|
83
|
+
end
|
84
|
+
|
85
|
+
def refunds
|
86
|
+
Collection.new(Refund, super['data'], super['meta'])
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/wizypay/version.rb
CHANGED
data/lib/wizypay.rb
CHANGED
@@ -5,7 +5,9 @@ require 'json'
|
|
5
5
|
require_relative 'wizypay/api_client'
|
6
6
|
require_relative 'wizypay/resource'
|
7
7
|
require_relative 'wizypay/collection'
|
8
|
-
require_relative 'wizypay/
|
8
|
+
require_relative 'wizypay/card_methods'
|
9
|
+
require_relative 'wizypay/debit_card'
|
10
|
+
require_relative 'wizypay/gift_card'
|
9
11
|
require_relative 'wizypay/vdc_operation'
|
10
12
|
require_relative 'wizypay/refund'
|
11
13
|
require_relative 'wizypay/ad'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Wizypay
|
4
|
+
RSpec.describe 'DebitCard#cancel' do
|
5
|
+
|
6
|
+
let(:api_key) { 'key' }
|
7
|
+
let(:api_secret) { 'secret' }
|
8
|
+
let(:api_endpoint) { 'https://api.wizypay.com' }
|
9
|
+
let(:reference) { '85fb584c-72cb-4f35-b307-ac5442ef7153' }
|
10
|
+
let(:cancel_request) { stub_request(:post, "#{api_endpoint}/debit_cards/#{reference}/cancel").
|
11
|
+
with(headers: { 'Accept' => 'application/json',
|
12
|
+
'Authorization' => /WIZYPAY #{api_key}:.*/,
|
13
|
+
'Content-Type' => 'application/x-www-form-urlencoded' }) }
|
14
|
+
before do
|
15
|
+
Wizypay.setup(api_key, api_secret, api_endpoint)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'success' do
|
19
|
+
it 'returns empty body' do
|
20
|
+
request = cancel_request.to_return(status: 200, body: '')
|
21
|
+
response = DebitCard.new(reference: reference).cancel
|
22
|
+
expect(request).to have_been_made
|
23
|
+
expect(response).to be_empty
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.cancel' do
|
28
|
+
it 'delegates to an instance' do
|
29
|
+
expect(DebitCard).to receive(:new).with(reference: reference).and_return(card = double('card'))
|
30
|
+
expect(card).to receive(:cancel)
|
31
|
+
DebitCard.cancel(reference)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'failure' do
|
36
|
+
context '4XX' do
|
37
|
+
it "throws #{RestClient::Exception}" do
|
38
|
+
request = cancel_request.to_return(status: 401, body: { errors: { base: ['authentication_failed'] } }.to_json)
|
39
|
+
expect do
|
40
|
+
DebitCard.cancel(reference)
|
41
|
+
end.to raise_error(RestClient::Exception)
|
42
|
+
expect(request).to have_been_made
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'timeout' do
|
47
|
+
it "throws #{RestClient::Exception}" do
|
48
|
+
request = cancel_request.to_timeout
|
49
|
+
expect do
|
50
|
+
DebitCard.cancel(reference)
|
51
|
+
end.to raise_error(RestClient::Exception)
|
52
|
+
expect(request).to have_been_made
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Wizypay
|
4
|
+
RSpec.describe DebitCard 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}/debit_cards").
|
9
|
+
with(headers: { 'Accept' => 'application/json',
|
10
|
+
'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
|
11
|
+
let(:where_cards_request) { stub_request(:get, "#{api_endpoint}/debit_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 = DebitCard.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 = DebitCard.all
|
29
|
+
expect(response).to be_a(Collection)
|
30
|
+
expect(response.first).to be_a(DebitCard)
|
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 = DebitCard.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 DebitCard 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}/debit_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 = DebitCard.find(card_id)
|
19
|
+
expect(request).to have_been_made
|
20
|
+
expect(response).to be_a(DebitCard)
|
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 = DebitCard.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 = DebitCard.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
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module Wizypay
|
5
|
+
RSpec.describe 'DebitCard#url' do
|
6
|
+
include SimpleHmac::Helper
|
7
|
+
|
8
|
+
let(:api_key) { 'key' }
|
9
|
+
let(:api_secret) { 'secret' }
|
10
|
+
let(:api_endpoint) { 'https://api.wizypay.com' }
|
11
|
+
let(:reference) { '85fb584c-72cb-4f35-b307-ac5442ef7153' }
|
12
|
+
|
13
|
+
before do
|
14
|
+
Wizypay.setup(api_key, api_secret, api_endpoint)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns' do
|
18
|
+
t = Time.new(2015, 1, 1, 0, 0, 0, "+01:00")
|
19
|
+
Timecop.freeze(t) do
|
20
|
+
url = DebitCard.new(reference: reference).url
|
21
|
+
expected_security = sign_string("#{reference}\n#{t.httpdate}", api_secret)
|
22
|
+
expect(url).to eq("#{api_endpoint}/widget?key=#{URI::encode_www_form_component api_key}"+
|
23
|
+
"×tamp=#{URI::encode_www_form_component t.httpdate}" +
|
24
|
+
"&reference=#{URI::encode_www_form_component reference}"+
|
25
|
+
"&security=#{URI::encode_www_form_component expected_security}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.url' do
|
30
|
+
it 'delegates to an instance' do
|
31
|
+
expect(DebitCard).to receive(:new).with(reference: reference).and_return(card = double('card'))
|
32
|
+
expect(card).to receive(:url)
|
33
|
+
DebitCard.url(reference)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Wizypay
|
4
|
+
RSpec.describe 'DebitCard.create' do
|
5
|
+
let(:api_key) { 'key' }
|
6
|
+
let(:api_secret) { 'secret' }
|
7
|
+
let(:api_endpoint) { 'https://api.wizypay.com' }
|
8
|
+
let(:user) { { id: 33, first_name: 'Nicolas', last_name: 'Cage' } }
|
9
|
+
let(:reference) { '85fb584c-72cb-4f35-b307-ac5442ef7153' }
|
10
|
+
let(:merchant_id) { '91' }
|
11
|
+
let(:amount) { '5000' }
|
12
|
+
let(:currency) { 'EUR' }
|
13
|
+
let(:create_request) { stub_request(:post, "#{api_endpoint}/debit_cards").
|
14
|
+
with(body: { amount: amount, currency: currency, merchant_id: merchant_id,
|
15
|
+
reference: reference, user: user.to_json },
|
16
|
+
headers: { 'Accept' => 'application/json',
|
17
|
+
'Authorization' => /WIZYPAY #{api_key}:.*/,
|
18
|
+
'Content-Type' => 'application/x-www-form-urlencoded' }) }
|
19
|
+
let!(:cancel_request) { stub_request(:post, "#{api_endpoint}/debit_cards/#{reference}/cancel").
|
20
|
+
with(headers: { 'Accept' => 'application/json',
|
21
|
+
'Authorization' => /WIZYPAY #{api_key}:.*/,
|
22
|
+
'Content-Type' => 'application/x-www-form-urlencoded' }) }
|
23
|
+
before do
|
24
|
+
Wizypay.setup(api_key, api_secret, api_endpoint)
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'success' do
|
28
|
+
it 'returns a Card with correct data' do
|
29
|
+
response_body = {
|
30
|
+
reference: reference,
|
31
|
+
type: 'Mastercard',
|
32
|
+
amount: amount,
|
33
|
+
currency: currency,
|
34
|
+
merchant_id: merchant_id,
|
35
|
+
user_id: user[:id]
|
36
|
+
}
|
37
|
+
request = create_request.to_return(status: 200, body: response_body.to_json)
|
38
|
+
response = DebitCard.create(reference, amount, currency, merchant_id, user)
|
39
|
+
expect(request).to have_been_made
|
40
|
+
expect(response).to be_a(DebitCard)
|
41
|
+
expect(response.to_h).to match(response_body)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'failure' do
|
46
|
+
context '4XX' do
|
47
|
+
it "throws #{RestClient::Exception}" do
|
48
|
+
request = create_request.to_return(status: 401, body: { errors: { base: ['authentication_failed'] } }.to_json)
|
49
|
+
expect do
|
50
|
+
DebitCard.create(reference, amount, currency, merchant_id, user)
|
51
|
+
end.to raise_error(RestClient::Exception)
|
52
|
+
expect(request).to have_been_made
|
53
|
+
expect(cancel_request).to have_been_made
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'timeout' do
|
58
|
+
it "throws #{RestClient::Exception}" do
|
59
|
+
request = create_request.to_timeout
|
60
|
+
expect do
|
61
|
+
DebitCard.create(reference, amount, currency, merchant_id, user)
|
62
|
+
end.to raise_error(RestClient::Exception)
|
63
|
+
expect(request).to have_been_made
|
64
|
+
expect(cancel_request).to have_been_made
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Wizypay
|
4
|
-
RSpec.describe '
|
4
|
+
RSpec.describe 'DebitCard#refun' do
|
5
5
|
|
6
6
|
let(:api_key) { 'key' }
|
7
7
|
let(:api_secret) { 'secret' }
|
8
8
|
let(:api_endpoint) { 'https://api.wizypay.com' }
|
9
9
|
let(:reference) { '85fb584c-72cb-4f35-b307-ac5442ef7153' }
|
10
10
|
let(:amount) { 2000 }
|
11
|
-
let(:refund_request) { stub_request(:post, "#{api_endpoint}/
|
11
|
+
let(:refund_request) { stub_request(:post, "#{api_endpoint}/debit_cards/#{reference}/refund").
|
12
12
|
with(body: { 'amount' => amount.to_s },
|
13
13
|
headers: { 'Accept' => 'application/json',
|
14
14
|
'Authorization' => /WIZYPAY #{api_key}:.*/,
|
@@ -20,7 +20,7 @@ module Wizypay
|
|
20
20
|
context 'success' do
|
21
21
|
it 'returns empty body' do
|
22
22
|
request = refund_request.to_return(status: 200, body: '')
|
23
|
-
response =
|
23
|
+
response = DebitCard.new(reference: reference).refund(amount)
|
24
24
|
expect(request).to have_been_made
|
25
25
|
expect(response).to be_empty
|
26
26
|
end
|
@@ -28,9 +28,9 @@ module Wizypay
|
|
28
28
|
|
29
29
|
describe '.refund' do
|
30
30
|
it 'delegates to an instance' do
|
31
|
-
expect(
|
31
|
+
expect(DebitCard).to receive(:new).with(reference: reference).and_return(card = double('card'))
|
32
32
|
expect(card).to receive(:refund).with(amount)
|
33
|
-
|
33
|
+
DebitCard.refund(reference, amount)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Wizypay
|
4
|
-
RSpec.describe '
|
4
|
+
RSpec.describe 'GiftCard#cancel' do
|
5
5
|
|
6
6
|
let(:api_key) { 'key' }
|
7
7
|
let(:api_secret) { 'secret' }
|
8
8
|
let(:api_endpoint) { 'https://api.wizypay.com' }
|
9
9
|
let(:reference) { '85fb584c-72cb-4f35-b307-ac5442ef7153' }
|
10
|
-
let(:cancel_request) { stub_request(:post, "#{api_endpoint}/
|
10
|
+
let(:cancel_request) { stub_request(:post, "#{api_endpoint}/gift_cards/#{reference}/cancel").
|
11
11
|
with(headers: { 'Accept' => 'application/json',
|
12
12
|
'Authorization' => /WIZYPAY #{api_key}:.*/,
|
13
13
|
'Content-Type' => 'application/x-www-form-urlencoded' }) }
|
@@ -18,7 +18,7 @@ module Wizypay
|
|
18
18
|
context 'success' do
|
19
19
|
it 'returns empty body' do
|
20
20
|
request = cancel_request.to_return(status: 200, body: '')
|
21
|
-
response =
|
21
|
+
response = GiftCard.new(reference: reference).cancel
|
22
22
|
expect(request).to have_been_made
|
23
23
|
expect(response).to be_empty
|
24
24
|
end
|
@@ -26,9 +26,9 @@ module Wizypay
|
|
26
26
|
|
27
27
|
describe '.cancel' do
|
28
28
|
it 'delegates to an instance' do
|
29
|
-
expect(
|
29
|
+
expect(GiftCard).to receive(:new).with(reference: reference).and_return(card = double('card'))
|
30
30
|
expect(card).to receive(:cancel)
|
31
|
-
|
31
|
+
GiftCard.cancel(reference)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -37,7 +37,7 @@ module Wizypay
|
|
37
37
|
it "throws #{RestClient::Exception}" do
|
38
38
|
request = cancel_request.to_return(status: 401, body: { errors: { base: ['authentication_failed'] } }.to_json)
|
39
39
|
expect do
|
40
|
-
|
40
|
+
GiftCard.cancel(reference)
|
41
41
|
end.to raise_error(RestClient::Exception)
|
42
42
|
expect(request).to have_been_made
|
43
43
|
end
|
@@ -47,7 +47,7 @@ module Wizypay
|
|
47
47
|
it "throws #{RestClient::Exception}" do
|
48
48
|
request = cancel_request.to_timeout
|
49
49
|
expect do
|
50
|
-
|
50
|
+
GiftCard.cancel(reference)
|
51
51
|
end.to raise_error(RestClient::Exception)
|
52
52
|
expect(request).to have_been_made
|
53
53
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Wizypay
|
4
|
-
RSpec.describe
|
4
|
+
RSpec.describe GiftCard do
|
5
5
|
let(:api_key) { 'key' }
|
6
6
|
let(:api_secret) { 'secret' }
|
7
7
|
let(:api_endpoint) { 'https://api.wizypay.com' }
|
8
|
-
let(:all_cards_request) { stub_request(:get, "#{api_endpoint}/
|
8
|
+
let(:all_cards_request) { stub_request(:get, "#{api_endpoint}/gift_cards").
|
9
9
|
with(headers: { 'Accept' => 'application/json',
|
10
10
|
'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
|
11
|
-
let(:where_cards_request) { stub_request(:get, "#{api_endpoint}/
|
11
|
+
let(:where_cards_request) { stub_request(:get, "#{api_endpoint}/gift_cards?beneficiary=john").
|
12
12
|
with(headers: { 'Accept' => 'application/json',
|
13
13
|
'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
|
14
14
|
before do
|
@@ -18,16 +18,16 @@ module Wizypay
|
|
18
18
|
context 'all' do
|
19
19
|
it 'returns empty body' do
|
20
20
|
request = all_cards_request.to_return(status: 200, body: '{"data": []}')
|
21
|
-
response =
|
21
|
+
response = GiftCard.all
|
22
22
|
expect(request).to have_been_made
|
23
23
|
expect(response).to be_empty
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'is a collection' do
|
27
27
|
all_cards_request.to_return(status: 200, body: '{"data": [{"id": 1, "partial_number": "XXXX-1234"}]}')
|
28
|
-
response =
|
28
|
+
response = GiftCard.all
|
29
29
|
expect(response).to be_a(Collection)
|
30
|
-
expect(response.first).to be_a(
|
30
|
+
expect(response.first).to be_a(GiftCard)
|
31
31
|
expect(response.first.partial_number).to eq 'XXXX-1234'
|
32
32
|
end
|
33
33
|
end
|
@@ -35,7 +35,7 @@ module Wizypay
|
|
35
35
|
context 'where' do
|
36
36
|
it 'returns empty body' do
|
37
37
|
request = where_cards_request.to_return(status: 200, body: '{"data": []}')
|
38
|
-
response =
|
38
|
+
response = GiftCard.where(beneficiary: 'john')
|
39
39
|
expect(request).to have_been_made
|
40
40
|
expect(response).to be_empty
|
41
41
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Wizypay
|
4
|
-
RSpec.describe
|
4
|
+
RSpec.describe GiftCard do
|
5
5
|
let(:api_key) { 'key' }
|
6
6
|
let(:api_secret) { 'secret' }
|
7
7
|
let(:api_endpoint) { 'https://api.wizypay.com' }
|
8
8
|
let(:card_id) { 1 }
|
9
|
-
let(:card_request) { stub_request(:get, "#{api_endpoint}/
|
9
|
+
let(:card_request) { stub_request(:get, "#{api_endpoint}/gift_cards/#{card_id}").
|
10
10
|
with(headers: { 'Accept' => 'application/json',
|
11
11
|
'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
|
12
12
|
before do
|
@@ -15,15 +15,15 @@ module Wizypay
|
|
15
15
|
|
16
16
|
it 'is a card' do
|
17
17
|
request = card_request.to_return(status: 200, body: '{"data": {"id": 1, "partial_number": "XXXX-1234"}}')
|
18
|
-
response =
|
18
|
+
response = GiftCard.find(card_id)
|
19
19
|
expect(request).to have_been_made
|
20
|
-
expect(response).to be_a(
|
20
|
+
expect(response).to be_a(GiftCard)
|
21
21
|
expect(response.partial_number).to eq 'XXXX-1234'
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'has operations' do
|
25
25
|
card_request.to_return(status: 200, body: '{"data": {"operations": {"data": [{"id": 1}]}}}')
|
26
|
-
response =
|
26
|
+
response = GiftCard.find(card_id)
|
27
27
|
expect(response.operations).to be_a(Collection)
|
28
28
|
expect(response.operations.first).to be_a(VdcOperation)
|
29
29
|
expect(response.operations.first.id).to eq 1
|
@@ -31,7 +31,7 @@ module Wizypay
|
|
31
31
|
|
32
32
|
it 'has refunds' do
|
33
33
|
card_request.to_return(status: 200, body: '{"data": {"refunds": {"data": [{"id": 1}]}}}')
|
34
|
-
response =
|
34
|
+
response = GiftCard.find(card_id)
|
35
35
|
expect(response.refunds).to be_a(Collection)
|
36
36
|
expect(response.refunds.first).to be_a(Refund)
|
37
37
|
expect(response.refunds.first.id).to eq 1
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'time'
|
3
3
|
|
4
4
|
module Wizypay
|
5
|
-
RSpec.describe '
|
5
|
+
RSpec.describe 'GiftCard#url' do
|
6
6
|
include SimpleHmac::Helper
|
7
7
|
|
8
8
|
let(:api_key) { 'key' }
|
@@ -17,7 +17,7 @@ module Wizypay
|
|
17
17
|
it 'returns' do
|
18
18
|
t = Time.new(2015, 1, 1, 0, 0, 0, "+01:00")
|
19
19
|
Timecop.freeze(t) do
|
20
|
-
url =
|
20
|
+
url = GiftCard.new(reference: reference).url
|
21
21
|
expected_security = sign_string("#{reference}\n#{t.httpdate}", api_secret)
|
22
22
|
expect(url).to eq("#{api_endpoint}/widget?key=#{URI::encode_www_form_component api_key}"+
|
23
23
|
"×tamp=#{URI::encode_www_form_component t.httpdate}" +
|
@@ -28,9 +28,9 @@ module Wizypay
|
|
28
28
|
|
29
29
|
describe '.url' do
|
30
30
|
it 'delegates to an instance' do
|
31
|
-
expect(
|
31
|
+
expect(GiftCard).to receive(:new).with(reference: reference).and_return(card = double('card'))
|
32
32
|
expect(card).to receive(:url)
|
33
|
-
|
33
|
+
GiftCard.url(reference)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Wizypay
|
4
|
-
RSpec.describe '
|
4
|
+
RSpec.describe 'GiftCard.create' do
|
5
5
|
let(:api_key) { 'key' }
|
6
6
|
let(:api_secret) { 'secret' }
|
7
7
|
let(:api_endpoint) { 'https://api.wizypay.com' }
|
@@ -10,12 +10,16 @@ module Wizypay
|
|
10
10
|
let(:merchant_id) { '91' }
|
11
11
|
let(:amount) { '5000' }
|
12
12
|
let(:currency) { 'EUR' }
|
13
|
-
let(:create_request) { stub_request(:post, "#{api_endpoint}/
|
13
|
+
let(:create_request) { stub_request(:post, "#{api_endpoint}/gift_cards").
|
14
14
|
with(body: { amount: amount, currency: currency, merchant_id: merchant_id,
|
15
15
|
reference: reference, user: user.to_json },
|
16
16
|
headers: { 'Accept' => 'application/json',
|
17
17
|
'Authorization' => /WIZYPAY #{api_key}:.*/,
|
18
18
|
'Content-Type' => 'application/x-www-form-urlencoded' }) }
|
19
|
+
let!(:cancel_request) { stub_request(:post, "#{api_endpoint}/gift_cards/#{reference}/cancel").
|
20
|
+
with(headers: { 'Accept' => 'application/json',
|
21
|
+
'Authorization' => /WIZYPAY #{api_key}:.*/,
|
22
|
+
'Content-Type' => 'application/x-www-form-urlencoded' }) }
|
19
23
|
before do
|
20
24
|
Wizypay.setup(api_key, api_secret, api_endpoint)
|
21
25
|
end
|
@@ -31,9 +35,9 @@ module Wizypay
|
|
31
35
|
user_id: user[:id]
|
32
36
|
}
|
33
37
|
request = create_request.to_return(status: 200, body: response_body.to_json)
|
34
|
-
response =
|
38
|
+
response = GiftCard.create(reference, amount, currency, merchant_id, user)
|
35
39
|
expect(request).to have_been_made
|
36
|
-
expect(response).to be_a(
|
40
|
+
expect(response).to be_a(GiftCard)
|
37
41
|
expect(response.to_h).to match(response_body)
|
38
42
|
end
|
39
43
|
end
|
@@ -43,9 +47,10 @@ module Wizypay
|
|
43
47
|
it "throws #{RestClient::Exception}" do
|
44
48
|
request = create_request.to_return(status: 401, body: { errors: { base: ['authentication_failed'] } }.to_json)
|
45
49
|
expect do
|
46
|
-
|
50
|
+
GiftCard.create(reference, amount, currency, merchant_id, user)
|
47
51
|
end.to raise_error(RestClient::Exception)
|
48
52
|
expect(request).to have_been_made
|
53
|
+
expect(cancel_request).to have_been_made
|
49
54
|
end
|
50
55
|
end
|
51
56
|
|
@@ -53,9 +58,10 @@ module Wizypay
|
|
53
58
|
it "throws #{RestClient::Exception}" do
|
54
59
|
request = create_request.to_timeout
|
55
60
|
expect do
|
56
|
-
|
61
|
+
GiftCard.create(reference, amount, currency, merchant_id, user)
|
57
62
|
end.to raise_error(RestClient::Exception)
|
58
63
|
expect(request).to have_been_made
|
64
|
+
expect(cancel_request).to have_been_made
|
59
65
|
end
|
60
66
|
end
|
61
67
|
end
|
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.
|
4
|
+
version: 0.3.0
|
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-02-
|
13
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: simple-hmac
|
@@ -153,8 +153,10 @@ files:
|
|
153
153
|
- lib/wizypay/ad.rb
|
154
154
|
- lib/wizypay/api_client.rb
|
155
155
|
- lib/wizypay/beneficiary.rb
|
156
|
-
- lib/wizypay/
|
156
|
+
- lib/wizypay/card_methods.rb
|
157
157
|
- lib/wizypay/collection.rb
|
158
|
+
- lib/wizypay/debit_card.rb
|
159
|
+
- lib/wizypay/gift_card.rb
|
158
160
|
- lib/wizypay/merchant.rb
|
159
161
|
- lib/wizypay/merchant_category.rb
|
160
162
|
- lib/wizypay/merchant_version.rb
|
@@ -163,12 +165,17 @@ files:
|
|
163
165
|
- lib/wizypay/vdc_operation.rb
|
164
166
|
- lib/wizypay/version.rb
|
165
167
|
- spec/beneficiary/beneficiary_spec.rb
|
166
|
-
- spec/
|
167
|
-
- spec/
|
168
|
-
- spec/
|
169
|
-
- spec/
|
170
|
-
- spec/
|
171
|
-
- spec/
|
168
|
+
- spec/debit_card/cancel_card_spec.rb
|
169
|
+
- spec/debit_card/card_all_spec.rb
|
170
|
+
- spec/debit_card/card_show_spec.rb
|
171
|
+
- spec/debit_card/card_url_spec.rb
|
172
|
+
- spec/debit_card/create_card_spec.rb
|
173
|
+
- spec/debit_card/refund_card_spec.rb
|
174
|
+
- spec/gift_card/cancel_card_spec.rb
|
175
|
+
- spec/gift_card/card_all_spec.rb
|
176
|
+
- spec/gift_card/card_show_spec.rb
|
177
|
+
- spec/gift_card/card_url_spec.rb
|
178
|
+
- spec/gift_card/create_card_spec.rb
|
172
179
|
- spec/merchant/merchant_spec.rb
|
173
180
|
- spec/merchant_category/merchant_category_spec.rb
|
174
181
|
- spec/merchant_version/merchant_version_spec.rb
|
@@ -200,12 +207,17 @@ specification_version: 4
|
|
200
207
|
summary: Programmatic API to access Wizypay's API.
|
201
208
|
test_files:
|
202
209
|
- spec/beneficiary/beneficiary_spec.rb
|
203
|
-
- spec/
|
204
|
-
- spec/
|
205
|
-
- spec/
|
206
|
-
- spec/
|
207
|
-
- spec/
|
208
|
-
- spec/
|
210
|
+
- spec/debit_card/cancel_card_spec.rb
|
211
|
+
- spec/debit_card/card_all_spec.rb
|
212
|
+
- spec/debit_card/card_show_spec.rb
|
213
|
+
- spec/debit_card/card_url_spec.rb
|
214
|
+
- spec/debit_card/create_card_spec.rb
|
215
|
+
- spec/debit_card/refund_card_spec.rb
|
216
|
+
- spec/gift_card/cancel_card_spec.rb
|
217
|
+
- spec/gift_card/card_all_spec.rb
|
218
|
+
- spec/gift_card/card_show_spec.rb
|
219
|
+
- spec/gift_card/card_url_spec.rb
|
220
|
+
- spec/gift_card/create_card_spec.rb
|
209
221
|
- spec/merchant/merchant_spec.rb
|
210
222
|
- spec/merchant_category/merchant_category_spec.rb
|
211
223
|
- spec/merchant_version/merchant_version_spec.rb
|
data/lib/wizypay/card.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
module Wizypay
|
2
|
-
class Card < Resource
|
3
|
-
include SimpleHmac::Helper
|
4
|
-
|
5
|
-
def self.where(q)
|
6
|
-
raw = ApiClient.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(ApiClient.get("/cards/#{id}")[:data])
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.create(reference, amount, currency, merchant_id, user)
|
19
|
-
user = user.to_json if user.is_a?(Hash)
|
20
|
-
new(amount: amount, currency: currency, merchant_id: merchant_id, reference: reference, user: user).tap do |card|
|
21
|
-
card.save
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.cancel(reference)
|
26
|
-
new(reference: reference).cancel
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.refund(reference, amount)
|
30
|
-
new(reference: reference).refund(amount)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.url(reference)
|
34
|
-
new(reference: reference).url
|
35
|
-
end
|
36
|
-
|
37
|
-
def cancel
|
38
|
-
ApiClient.post("/cards/#{URI::encode_www_form_component reference}/cancel")
|
39
|
-
end
|
40
|
-
|
41
|
-
def refund(amount)
|
42
|
-
ApiClient.post("/cards/#{URI::encode_www_form_component reference}/refund", amount: amount)
|
43
|
-
end
|
44
|
-
|
45
|
-
def url
|
46
|
-
timestamp = Time.now.utc.httpdate
|
47
|
-
security = sign_string("#{reference}\n#{timestamp}", ApiClient.api_secret)
|
48
|
-
query_string = {
|
49
|
-
key: ApiClient.api_key,
|
50
|
-
timestamp: timestamp,
|
51
|
-
reference: reference,
|
52
|
-
security: security
|
53
|
-
}.map { |k, v| "#{k}=#{URI::encode_www_form_component(v)}" }.join('&')
|
54
|
-
"#{ApiClient.api_endpoint}/widget?#{query_string}"
|
55
|
-
end
|
56
|
-
|
57
|
-
def save
|
58
|
-
reinitialize ApiClient.post('/cards', to_h)
|
59
|
-
end
|
60
|
-
|
61
|
-
def created_at
|
62
|
-
return nil unless super.present?
|
63
|
-
Time.parse(super)
|
64
|
-
end
|
65
|
-
|
66
|
-
def operations
|
67
|
-
Collection.new(VdcOperation, super['data'], super['meta'])
|
68
|
-
end
|
69
|
-
|
70
|
-
def refunds
|
71
|
-
Collection.new(Refund, super['data'], super['meta'])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|